admin
2020-02-23 b59fef5c00b15fdfdfa9d4be26e5bf6b41c75458
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/DynamicInfoServiceImpl.java
@@ -1,10 +1,14 @@
package com.yeshi.fanli.service.impl.dynamic;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
@@ -15,9 +19,11 @@
import org.springframework.stereotype.Service;
import org.yeshi.utils.DateLunarUtil;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.taobao.TbImgUtil;
import com.yeshi.fanli.dao.dynamic.DynamicInfoDao;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.dto.taobao.TaoBaoShopDTO;
import com.yeshi.fanli.entity.bus.activity.ActivityRuleUser;
import com.yeshi.fanli.entity.bus.activity.ActivityUser;
@@ -32,7 +38,7 @@
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.activity.ActivityUserService;
@@ -40,10 +46,10 @@
import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService;
import com.yeshi.fanli.service.inter.dynamic.InviteMaterialService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailV2Service;
import com.yeshi.fanli.service.inter.user.QrCodeService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
@@ -72,7 +78,7 @@
   private RedisManager redisManager;
   @Resource
   private DaTaoKeGoodsService daTaoKeGoodsService;
   private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service;
   @Resource
   private JumpDetailV2Service jumpDetailV2Service;
@@ -145,7 +151,7 @@
         buffer.append("         ");
         buffer.append("早安~\n");
         buffer.append("我的邀请码:【邀请码】\n");
         buffer.append("购物省钱返利券App:【邀请链接】");
         buffer.append("购物省钱板栗快省App:【邀请链接】");
         content = content.replaceAll("\\,", "\\,").replaceAll("\\.", "\\。").replaceAll("\\;", "\\;")
               .replaceAll("\\!", "\\!").replaceAll("\\?", "\\?").replaceAll("\\:", "\\:");
@@ -269,6 +275,9 @@
      if (StringUtil.isNullOrEmpty(shopLink)) {
         taoBaoShop.setShopLink(TaoBaoUtil.getShopLink(taoBaoShop.getId()));
      }
      if(StringUtil.isNullOrEmpty(taoBaoShop.getShopIcon()))
         taoBaoShop.setShopIcon(dynamicShopInfo.getShopIcon());
      DynamicInfo dynamicVO = new DynamicInfo();
      dynamicVO.setId(brandId);
@@ -338,9 +347,9 @@
            count = 4;
         }
         List<DaTaoKeDetail> listDaTaoKe = daTaoKeGoodsService.getGoodsNotInList(subclassId, null, count);
         List<DaTaoKeDetailV2> listDaTaoKe = daTaoKeGoodsDetailV2Service.getGoodsNotInList(subclassId, null, count);
         DaTaoKeDetail daTaoKeDetail = null;
         DaTaoKeDetailV2 daTaoKeDetail = null;
         // 商品列表
         List<GoodsPicture> listPicture = new ArrayList<GoodsPicture>();
         // 商品列表
@@ -349,7 +358,7 @@
         BigDecimal shareMoney = new BigDecimal(0);
         BigDecimal proportion = hongBaoManageService.getFanLiRate();
         for (DaTaoKeDetail daTaoKe : listDaTaoKe) {
         for (DaTaoKeDetailV2 daTaoKe : listDaTaoKe) {
            if (daTaoKeDetail == null) {
               daTaoKeDetail = daTaoKe;
            }
@@ -469,7 +478,7 @@
         }
      }
      // 大淘客数据
      DaTaoKeDetail daTaoKe = daTaoKeGoodsService.getGoodsNotInList(subclassId, listId, 1).get(0);
      DaTaoKeDetailV2 daTaoKe = daTaoKeGoodsDetailV2Service.getGoodsNotInList(subclassId, listId, 1).get(0);
      if (daTaoKe == null) {
         return addSuccess;
      }
@@ -479,23 +488,23 @@
      } catch (Exception e) {
      }
      TaoBaoGoodsBrief taoBaoGoodsBrief = TaoBaoUtil.convert(daTaoKe);
      BigDecimal proportion = hongBaoManageService.getFanLiRate();
      TaoBaoGoodsBriefExtra goodsExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief,
            proportion.toString(), null);
      TaoBaoGoodsBriefExtra goodsExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(),
            null);
      if (!goodsExtra.isCoupon() || (goodsExtra.getState() != null && goodsExtra.getState() == 1)) {
         return addSuccess;  // 已下架 、无券 不加入
         return addSuccess; // 已下架 、无券 不加入
      }
      List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
      listGoods.add(taoBaoGoodsBrief);
      goodsExtra.setTkRate(taoBaoGoodsBrief.getTkRate());
      goodsExtra.setUpdatetime(new Date());
      goodsExtra.setCouponInfo(null);
      GoodsPicture goodsPicture = getGoodsPicture(daTaoKe);
      goodsPicture.setGoods(goodsExtra);
      // 商品列表
@@ -506,7 +515,7 @@
      TaoBaoGoodsBrief taoBaoGoodsBrief2 = TaoKeApiUtil.getSimpleGoodsInfo(daTaoKe.getGoodsId());
      List<String> imgList = taoBaoGoodsBrief2.getImgList();
      List<String> listimgs = new ArrayList<String>();
      String pic = daTaoKe.getPic();
      String pic = daTaoKe.getMainPic();
      listimgs.add(TbImgUtil.getTBSize320Img(pic));
      if (imgList != null && imgList.size() > 0) {
         for (String img : imgList) {
@@ -527,7 +536,7 @@
         }
      }
      goodsExtra.setImgList(imgList);
      // 分享奖金
      BigDecimal shareMoney = taoBaoGoodsBriefService.getShareGoodsUserHongBao(taoBaoGoodsBrief);
      ClientTextStyleVO shareMoneyDesc = new ClientTextStyleVO();
@@ -556,7 +565,7 @@
      // 保存信息
      dynamicInfoDao.insert(dynamicInfo);
      addSuccess = true;
      return addSuccess;
   }
@@ -569,7 +578,7 @@
    * @param subclassId
    * @throws TaobaoGoodsDownException
    */
   public DynamicInfo getDynamicInfo(DaTaoKeDetail daTaoKe, Long classId, Long subclassId) {
   public DynamicInfo getDynamicInfo(DaTaoKeDetailV2 daTaoKe, Long classId, Long subclassId) {
      DynamicInfo dynamicInfo = new DynamicInfo();
      dynamicInfo.setId(UUID.randomUUID().toString().replace("-", ""));
      dynamicInfo.setClassId(classId);
@@ -604,11 +613,11 @@
    * @param daTaoKe
    * @return
    */
   public GoodsPicture getGoodsPicture(DaTaoKeDetail daTaoKe) {
   public GoodsPicture getGoodsPicture(DaTaoKeDetailV2 daTaoKe) {
      GoodsPicture goodsPicture = new GoodsPicture();
      goodsPicture.setH(100);
      goodsPicture.setW(100);
      goodsPicture.setUrl(TbImgUtil.getTBSize320Img(daTaoKe.getPic()));
      goodsPicture.setUrl(TbImgUtil.getTBSize320Img(daTaoKe.getMainPic()));
      goodsPicture.setJumpDetail(jumpDetailV2Service.getByTypeCache("goodsdetail"));
      String goodsId = daTaoKe.getGoodsId().toString();
@@ -708,8 +717,14 @@
            size = inviteInfo.getSize();
         }
         InputStream asInputStream = HttpUtil.getAsInputStream(picUrl);
         int index = picUrl.lastIndexOf("/");
         String newUrl = picUrl.substring(index + 1);
         String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf("."));
         // 图片
         String imgLink = qrCodeService.drawInviteQrCodeNew(picUrl, null, null, pX, pY, size, null);
         String imgLink = qrCodeService.drawInviteQrCodeNew(asInputStream, urlMd5, null, null, pX, pY, size, null);
         GoodsPicture p2 = new GoodsPicture();
         p2.setW(100);
         p2.setH(100);
@@ -915,17 +930,54 @@
      return list;
   }
   private Map<Long, TaoBaoGoodsBrief> getFilterGoodsMap(List<DynamicInfo> list) {
      // 提取过滤商品
      List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
      for (DynamicInfo dynamicInfo : list) {
         List<GoodsPicture> gpList = dynamicInfo.getImgs();
         if (gpList != null)
            for (GoodsPicture gp : gpList) {
               if (gp != null && gp.getGoods() != null) {
                  TaoBaoGoodsBriefExtra newGoods = new TaoBaoGoodsBriefExtra();
                  try {
                     PropertyUtils.copyProperties(newGoods, gp.getGoods());
                     goodsList.add(newGoods);
                  } catch (IllegalAccessException e) {
                     e.printStackTrace();
                  } catch (InvocationTargetException e) {
                     e.printStackTrace();
                  } catch (NoSuchMethodException e) {
                     e.printStackTrace();
                  }
               }
            }
      }
      goodsList = taoBaoGoodsUpdateService.filterImportantTaoBaoGoods(goodsList);
      Map<Long, TaoBaoGoodsBrief> map = new HashMap<>();
      if (goodsList != null)
         for (TaoBaoGoodsBrief goods : goodsList)
            map.put(goods.getAuctionId(), goods);
      return map;
   }
   @Override
   @Cacheable(value = "dynamicCache", key = "'queryV2-'+#platform+'-'+#version+'-'+#start+'-'+#count+'-'+#cid+'-'+#subId")
   public List<DynamicInfo> queryV2(int platform, int version, int start, int count, Long cid, Long subId) {
      List<DynamicInfo> listNew = new ArrayList<DynamicInfo>();
      List<DynamicInfo> list = dynamicInfoDao.query(start, count, cid, subId);
      // 需要更新的商品
      List<TaoBaoGoodsBrief> taoBaoGoodsUpdateList = new ArrayList<>();
      if (list != null && list.size() > 0) {
         // 提取商品
         Map<Long, TaoBaoGoodsBrief> goodsMap = getFilterGoodsMap(list);
         BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
         BigDecimal shareRate = hongBaoManageService.getShareRate();
         for (DynamicInfo dynamicInfo: list) {
          ConfigParamsDTO paramsDTO = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE,hongBaoManageService.getVIPFanLiRate());
         for (DynamicInfo dynamicInfo : list) {
            DynamicInfo dynamicNew = new DynamicInfo();
            try {
               PropertyUtils.copyProperties(dynamicNew, dynamicInfo);
@@ -933,7 +985,7 @@
               e.printStackTrace();
               continue;
            }
            // 店铺信息
            TaoBaoShop shop = dynamicNew.getShop();
            if (shop != null) {
@@ -952,17 +1004,19 @@
               }
               dynamicNew.setShop(shopNew);
            }
            List<GoodsPicture> imgsNew = new ArrayList<GoodsPicture>();
            List<GoodsPicture> imgs = dynamicNew.getImgs();
            if (imgs != null && imgs.size() > 0) {
               for (GoodsPicture goodsPicture: imgs) {
               for (GoodsPicture goodsPicture : imgs) {
                  TaoBaoGoodsBriefExtra goods = goodsPicture.getGoods();
                  if (goods == null) {
                     imgsNew.add(goodsPicture);
                     continue;
                  }
                  taoBaoGoodsUpdateList.add(goods);
                  GoodsPicture goodsNew = new GoodsPicture();
                  try {
                     PropertyUtils.copyProperties(goodsNew, goodsPicture);
@@ -970,19 +1024,27 @@
                     e.printStackTrace();
                     continue;
                  }
                  GoodsDetailVO detailVO = GoodsDetailVOFactory.convertTaoBaoGoodsBriefExtra(goods, fanLiRate, shareRate);
                  // 过滤券信息与资金信息
                  goods.setCouponAmount(goodsMap.get(goods.getAuctionId()).getCouponAmount());
                  goods.setZkPrice(goodsMap.get(goods.getAuctionId()).getZkPrice());
                  goods.setCouponStartFee(goodsMap.get(goods.getAuctionId()).getCouponStartFee());
                  goods.setTkRate(goodsMap.get(goods.getAuctionId()).getTkRate());
                  GoodsDetailVO detailVO = GoodsDetailVOFactory.convertTaoBaoGoodsBriefExtra(goods, paramsDTO);
                  goodsNew.setGoodsVO(detailVO);
                  goodsNew.setGoods(null);
                  JumpDetailV2 jumpDetail = goodsNew.getJumpDetail();
                  if (jumpDetail != null) {
                     JumpDetailV2 jumpDetailV2 = jumpDetailV2Service.getByTypeCache(jumpDetail.getType(), platform, version);
                     JumpDetailV2 jumpDetailV2 = jumpDetailV2Service.getByTypeCache(jumpDetail.getType(),
                           platform, version);
                     if (jumpDetailV2 != null) {
                        goodsNew.setJumpDetail(jumpDetailV2);
                     }
                  }
                  imgsNew.add(goodsNew);
               }
               dynamicNew.setImgs(imgsNew);
@@ -990,7 +1052,7 @@
            listNew.add(dynamicNew);
         }
      }
      // 更新商品信息
      executor.execute(new Runnable() {
         @Override
@@ -998,9 +1060,10 @@
            updateGoodInfo(list);
         }
      });
      taoBaoGoodsUpdateService.addUpdateQueueAsync(taoBaoGoodsUpdateList);
      return listNew;
   }
   /**
    * 更新商品信息
@@ -1013,7 +1076,7 @@
      if (list == null || list.size() == 0) {
         return;
      }
      try {
         BigDecimal proportion = hongBaoManageService.getFanLiRate();
         for (DynamicInfo dynamicInfo : list) {
@@ -1054,10 +1117,10 @@
                  continue;
               }
               Integer state = oldExtra.getState();
               if (state != null && state == 1) {
                  continue;
               }
               /*
                * Integer state = oldExtra.getState(); if (state != null && state == 1) {
                * continue; }
                */
               TaoBaoGoodsBrief goodsBrief = null;
               try {
@@ -1110,16 +1173,16 @@
                     dynamicInfo.setDesc(shareMoneyDesc);
                  }
               }
               // 需要更新信息;
               needUpdate = true;
            }
            // 无效更新信息
            if (!needUpdate) {
               continue;
            }
            // 更新商品信息
            dynamicInfo.setImgs(listPicture);