| | |
| | | package com.yeshi.fanli.service.impl.user; |
| | | |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.yeshi.utils.FileUtil; |
| | | import org.yeshi.utils.entity.FileUploadResult; |
| | | import org.yeshi.utils.tencentcloud.COSManager; |
| | | |
| | | import com.google.gson.Gson; |
| | |
| | | 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.ImageUtil; |
| | | 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); |
| | | |
| | | if (type == PreviewEnum.extractRecord || type == PreviewEnum.moneyArrival) { |
| | | return; |
| | | } |
| | | |
| | | // redis缓存 |
| | | if (StringUtil.isNullOrEmpty(content)) { |
| | | removePreview(preUid, type); |
| | | } else { |
| | | adddPreview(preUid, type, content); |
| | | } |
| | | } |
| | | |
| | | // 缓存10分钟 |
| | | private void adddPreview(Long uid, PreviewEnum type, String content) { |
| | | String key = StringUtil.Md5("preview" + uid + "#" + type.name()); |
| | | redisManager.cacheCommonString(key, content, 60 * 10); |
| | | } |
| | | |
| | | // 缓存10分钟 |
| | | private void removePreview(Long uid, PreviewEnum type) { |
| | | String key = StringUtil.Md5("preview" + uid + "#" + type.name()); |
| | | redisManager.removeCommonString(key); |
| | | } |
| | | |
| | | |
| | | @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)); |
| | | } |
| | | |
| | | |
| | |
| | | BindingAccount alipay = bindingAccountService.getBindingAccountByUidAndType(uid, BindingAccount.TYPE_ALIPAY); |
| | | if (alipay == null) |
| | | throw new PreviewInfoException(1, "未绑定提现账号"); |
| | | if (money == null || money.compareTo(BigDecimal.ZERO) <= 0) |
| | | throw new PreviewInfoException(1, "请输入正确的金额"); |
| | | if (StringUtil.isNullOrEmpty(time)) |
| | | throw new PreviewInfoException(1, "提现时间不能为空"); |
| | | if (money.compareTo(BigDecimal.ZERO) <= 0) |
| | | throw new PreviewInfoException(1, "提现金额不能小于0"); |
| | | |
| | | Date parse = TimeUtil.parseDotCommon2(time); |
| | | if (parse == null) |
| | | throw new PreviewInfoException(1, "请输入正确的时间格式,如:2020.01.01 01:01"); |
| | | |
| | | |
| | | Gson gson = new Gson(); |
| | | List<Extract> list = null; |
| | | List<Extract> list = new ArrayList<Extract>(); |
| | | |
| | | Extract extract = new Extract(); |
| | | extract.setName(alipay.getName()); |
| | | extract.setAccount(alipay.getAccount()); |
| | | extract.setMoney(money); |
| | | extract.setReceiveTime(TimeUtil.parseDotCommon(time)); |
| | | extract.setReceiveTime(TimeUtil.parseDotCommon2(time)); |
| | | extract.setId(java.lang.System.currentTimeMillis()); |
| | | |
| | | String id = StringUtil.Md5(uid + "#" + PreviewEnum.extractRecord.name()); |
| | | PreviewInfo previewInfo = previewInfoDao.get(id); |
| | | if (previewInfo == null) { |
| | | list = new ArrayList<Extract>(); |
| | | list.add(extract); |
| | | } else { |
| | | String content = previewInfo.getContent(); |
| | |
| | | Comparator<Extract> cm = new Comparator<Extract>() { |
| | | @Override |
| | | public int compare(Extract o1, Extract o2) { |
| | | return (int) (o2.getReceiveTime().getTime() - o1.getReceiveTime().getTime()); |
| | | if (o2.getReceiveTime().getTime() > o1.getReceiveTime().getTime()) { |
| | | return 1; |
| | | } else { |
| | | return -1; |
| | | } |
| | | } |
| | | }; |
| | | Collections.sort(list, cm); |
| | | } |
| | | } |
| | | save(uid, PreviewEnum.extractRecord, gson.toJson(list)); |
| | | save(uid, uid, PreviewEnum.extractRecord, gson.toJson(list)); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void previewExtractRecord(Long uid) throws PreviewInfoException{ |
| | | String id = StringUtil.Md5(uid + "#" + PreviewEnum.extractRecord.name()); |
| | | PreviewInfo previewInfo = previewInfoDao.get(id); |
| | | if (previewInfo == null) { |
| | | throw new PreviewInfoException(1, "请添加提现记录信息"); |
| | | } |
| | | |
| | | String content = previewInfo.getContent(); |
| | | if (StringUtil.isNullOrEmpty(content)) { |
| | | throw new PreviewInfoException(1, "请添加提现记录信息"); |
| | | } |
| | | |
| | | adddPreview(uid, PreviewEnum.extractRecord, content); |
| | | } |
| | | |
| | | |
| | |
| | | break; |
| | | } |
| | | } |
| | | save(uid, PreviewEnum.extractRecord, gson.toJson(list)); |
| | | |
| | | save(uid, uid, PreviewEnum.extractRecord, gson.toJson(list)); |
| | | |
| | | // 取消预览 |
| | | removePreview(uid, PreviewEnum.extractRecord); |
| | | } |
| | | |
| | | |
| | | |
| | | @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)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String saveMoneyArrival(Long uid, BigDecimal money, String time,String orderNo) throws PreviewInfoException { |
| | | public String saveMoneyArrival(Long uid, BigDecimal money, String time,String orderNo, String platform) |
| | | throws PreviewInfoException,Exception { |
| | | if (uid == null ) |
| | | throw new PreviewInfoException(1, "请先登录"); |
| | | if (money == null ) |
| | | throw new PreviewInfoException(1, "请输入金额"); |
| | | if(StringUtil.isNullOrEmpty(orderNo)) |
| | | throw new PreviewInfoException(1, "请输入订单号"); |
| | | if(StringUtil.isNullOrEmpty(time)) |
| | | throw new PreviewInfoException(1, "请输入创建时间"); |
| | | if(StringUtil.isNullOrEmpty(time)) |
| | | throw new PreviewInfoException(1, "请输入订单号"); |
| | | String content = ""; // TODO |
| | | // save(uid, PreviewEnum.moneyArrival, gson.toJson(infoVO)); |
| | | return content; |
| | | Date date = TimeUtil.parseDotCommon2(time); |
| | | if (date == null) |
| | | throw new PreviewInfoException(1, "请输入正确的时间格式,如:2020.01.01 01:01"); |
| | | |
| | | // 转换格式 |
| | | time = TimeUtil.formatYMDHHMM(date); |
| | | |
| | | InputStream drawStream = null; |
| | | if ("ios".equalsIgnoreCase(platform)) { |
| | | drawStream = ImageUtil.drawAlipayIOS(money, orderNo, time); |
| | | } else { |
| | | drawStream = ImageUtil.drawAlipayAndroid(money, orderNo, time); |
| | | } |
| | | |
| | | if (drawStream == null) |
| | | throw new PreviewInfoException(1, "预览生成失败"); |
| | | |
| | | // 上传文件 |
| | | String uuid = UUID.randomUUID().toString().replace("-", ""); |
| | | String upPath = "/user/img/preview/" + uuid + "_" + System.currentTimeMillis() + ".png"; |
| | | FileUploadResult result = COSManager.getInstance().uploadInputStream(drawStream, upPath); |
| | | if (result == null) { |
| | | throw new PreviewInfoException(1, "预览生成失败"); |
| | | } |
| | | |
| | | // 保存信息 |
| | | save(uid, uid, PreviewEnum.moneyArrival, result.getUrl()); |
| | | |
| | | return result.getUrl(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |