| | |
| | | package com.yeshi.fanli.service.impl.user; |
| | | |
| | | import java.io.InputStream; |
| | | 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.yeshi.utils.entity.FileUploadResult; |
| | | import org.yeshi.utils.tencentcloud.COSManager; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | |
| | | import com.yeshi.fanli.service.inter.money.extract.BindingAccountService; |
| | | import com.yeshi.fanli.service.inter.user.PreviewInfoService; |
| | | 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; |
| | |
| | | @Resource |
| | | private ThreeSaleDetailService threeSaleDetailService; |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | 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(preUid); |
| | |
| | | info.setUpdateTime(new Date()); |
| | | previewInfoDao.save(info); |
| | | |
| | | // 缓存10分钟 |
| | | String key = StringUtil.Md5("preview" + preUid + "#" + type.name()); |
| | | redisManager.cacheCommonString(key, info.getContent(), 60 * 10); |
| | | 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) { |
| | |
| | | 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, 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, uid, PreviewEnum.extractRecord, gson.toJson(list)); |
| | | |
| | | // 取消预览 |
| | | removePreview(uid, PreviewEnum.extractRecord); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | @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(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |