| | |
| | | package com.yeshi.fanli.service.impl.user; |
| | | |
| | | import java.io.File; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.yeshi.utils.FileUtil; |
| | | import org.yeshi.utils.tencentcloud.COSManager; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | |
| | | import com.yeshi.fanli.entity.bus.user.Extract; |
| | | import com.yeshi.fanli.entity.bus.user.PreviewInfo; |
| | | import com.yeshi.fanli.entity.bus.user.PreviewInfo.PreviewEnum; |
| | | import com.yeshi.fanli.entity.bus.user.ThreeSaleDetail; |
| | | import com.yeshi.fanli.exception.user.PreviewInfoException; |
| | | import com.yeshi.fanli.service.inter.money.extract.BindingAccountService; |
| | | import com.yeshi.fanli.service.inter.user.PreviewInfoService; |
| | | import com.yeshi.fanli.util.FilePathEnum; |
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleDetailService; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.TimeUtil; |
| | | import com.yeshi.fanli.vo.money.MoneyStatisticVO; |
| | | import com.yeshi.fanli.vo.user.MineInfoVO; |
| | | |
| | | import net.coobird.thumbnailator.Thumbnails; |
| | | |
| | | @Service |
| | | public class PreviewInfoServiceImpl implements PreviewInfoService { |
| | |
| | | @Resource |
| | | private BindingAccountService bindingAccountService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private ThreeSaleDetailService threeSaleDetailService; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void save(Long uid, PreviewEnum type, String content) { |
| | | String id = StringUtil.Md5(uid + "#" + type.name()); |
| | | public void save(Long createUid, Long preUid, PreviewEnum type, String content) { |
| | | String id = StringUtil.Md5(createUid + "#" + type.name()); |
| | | |
| | | PreviewInfo info = new PreviewInfo(); |
| | | info.setId(id); |
| | | info.setUid(uid); |
| | | info.setUid(preUid); |
| | | info.setCreateUid(createUid); |
| | | info.setContent(content); |
| | | info.setType(type); |
| | | info.setUpdateTime(new Date()); |
| | | previewInfoDao.save(info); |
| | | |
| | | // 缓存10分钟 |
| | | String key = StringUtil.Md5("preview" + preUid + "#" + type.name()); |
| | | redisManager.cacheCommonString(key, info.getContent(), 60 * 10); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String getRedisContent(Long uid, PreviewEnum previewEnum) { |
| | | String key = StringUtil.Md5("preview" + uid + "#" + previewEnum.name()); |
| | | return redisManager.getCommonString(key); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PreviewInfo get(Long uid, PreviewEnum previewEnum) { |
| | |
| | | public void saveMoneyInfo(Long uid, MoneyStatisticVO vo) throws PreviewInfoException { |
| | | if (vo == null) |
| | | throw new PreviewInfoException(1, "请完善页面信息"); |
| | | save(uid, PreviewEnum.moneyInfo, new Gson().toJson(vo)); |
| | | save(uid, uid, PreviewEnum.moneyInfo, new Gson().toJson(vo)); |
| | | } |
| | | |
| | | |
| | |
| | | Collections.sort(list, cm); |
| | | } |
| | | } |
| | | save(uid, PreviewEnum.extractRecord, gson.toJson(list)); |
| | | save(uid, uid, PreviewEnum.extractRecord, gson.toJson(list)); |
| | | } |
| | | |
| | | |
| | |
| | | break; |
| | | } |
| | | } |
| | | save(uid, PreviewEnum.extractRecord, gson.toJson(list)); |
| | | save(uid, uid, PreviewEnum.extractRecord, gson.toJson(list)); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void saveMineInfo(MineInfoVO infoVO, MultipartFile file) throws Exception { |
| | | public void saveMineInfo(MineInfoVO infoVO) throws PreviewInfoException { |
| | | Long uid = infoVO.getUid(); |
| | | if (file != null) { |
| | | // 谷歌压缩图片 |
| | | String targetPath = FileUtil.getCacheDir() + "/preview" + uid + "_" + System.currentTimeMillis()+ ".jpg"; |
| | | Thumbnails.of(file.getInputStream()).size(200, 200).toFile(targetPath); |
| | | // 执行上传 |
| | | String filePath =FilePathEnum.userPreview.getPath() + UUID.randomUUID().toString().replace("-", "") + ".jpg"; |
| | | String fileLink = COSManager.getInstance().uploadFile(new File(targetPath), filePath).getUrl(); |
| | | // 删除本地图片 |
| | | if (new File(targetPath).exists()) { |
| | | new File(targetPath).delete(); |
| | | } |
| | | infoVO.setPortrait(fileLink); |
| | | |
| | | // 删除之前上传图 |
| | | String id = StringUtil.Md5(uid + "#" + PreviewEnum.mineInfo.name()); |
| | | PreviewInfo previewInfo = previewInfoDao.get(id); |
| | | if (previewInfo != null && !StringUtil.isNullOrEmpty(previewInfo.getContent())) { |
| | | MineInfoVO dto = new Gson().fromJson(previewInfo.getContent(), MineInfoVO.class); |
| | | if (dto != null && StringUtil.isNullOrEmpty(dto.getPortrait())); |
| | | COSManager.getInstance().deleteFile(dto.getPortrait()); |
| | | } |
| | | Long preUid = infoVO.getPreUid(); |
| | | if (uid == null || preUid == null) |
| | | throw new PreviewInfoException(1, "请完善所有数据"); |
| | | |
| | | if (uid.longValue() != preUid.longValue()) { |
| | | // preUid 必须是下级 |
| | | ThreeSaleDetail detail = threeSaleDetailService.getByBossUidAndWorkerUid(uid, preUid); |
| | | if (detail == null) |
| | | throw new PreviewInfoException(1, preUid + "不是您的下级"); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(infoVO.getSelfRebate()) || StringUtil.isNullOrEmpty(infoVO.getShareBonus()) |
| | | || StringUtil.isNullOrEmpty(infoVO.getTeamBonus())) { |
| | | throw new PreviewInfoException(1, "请完善所有数据"); |
| | | } |
| | | |
| | | Gson gson = new Gson(); |
| | | save(uid, PreviewEnum.mineInfo, gson.toJson(infoVO)); |
| | | save(uid, preUid, PreviewEnum.mineInfo, gson.toJson(infoVO)); |
| | | } |
| | | |
| | | |