yujian
2020-06-22 652de4214ebe5efcf3abd30e68c83cb38beb2a23
fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java
@@ -75,7 +75,6 @@
import com.yeshi.fanli.service.manger.goods.ConvertLinkManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.ImageToBase64;
import com.yeshi.fanli.util.ImageUtil;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.RedisKeyEnum;
import com.yeshi.fanli.util.RedisManager;
@@ -177,8 +176,6 @@
   @Resource(name = "taskExecutor")
   private TaskExecutor executor;
   @Override
   public UserCloud getValidByUid(Long uid) {
      return userCloudMapper.getValidByUid(uid);
@@ -194,7 +191,6 @@
      Long count = userCloudMapper.countByUid(uid);
      return count;
   }
   
   @Override
   public List<UserCloud> query(int page, int count,String key, Integer state) {
@@ -223,7 +219,6 @@
         return;
      }
      redisManager.cacheCommonString(key , "true" , 60);
            
      // 更新信息
      UserCloud update = new UserCloud();
@@ -391,7 +386,6 @@
      sendCircleByDynamic(uid, id, UserCloudSendRecord.SEND_WAY_MANUAL);
   }
   
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void autoSendByDynamic(Long uid, String id) {
@@ -411,7 +405,6 @@
         LogHelper.cloudInfo("autoSendByDynamic - [uid:" +uid + " 动态id:"+  id +  "]原因:"+ e.getMsg());
      }
   }
   private void sendCircleByDynamic(Long uid, String id, int way) throws UserCloudException {
      UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
@@ -434,7 +427,6 @@
      if (StringUtil.isNullOrEmpty(relationId))
         throw new UserCloudException(2, "淘宝未授权,请前往\"我的\"绑定淘宝账号");
      
      // 验证是否开通
      UserCloud userCloud = userCloudMapper.getValidByUid(uid);
@@ -463,7 +455,6 @@
      if (listOpen.size() == 0)
         throw new UserCloudException(1005, "请先开启云发单群功能");
      
      // 验证发圈是否可行
      GoodsEvaluate evaluate = goodsEvaluateService.getById(id);
      if (evaluate == null || evaluate.getState() == 0)
@@ -484,7 +475,6 @@
         
         throw new UserCloudException(1003, "微信已掉线,需要重新扫描二维码登录");
      }
      
      boolean hasToken = false;
      List<String> listComment = new ArrayList<>();
@@ -524,7 +514,6 @@
      if (!hasToken)
         throw new UserCloudException(1, "该内容包含可转链口令或链接");
      
      ImgInfo imgVideo = null;
      List<String> listImg = new ArrayList<>();
      
@@ -538,7 +527,6 @@
            listImg.add(imgInfo.getUrl());
         }
      }
      
      // 保存发送记录
      UserCloudSendRecord sendRecord = new UserCloudSendRecord();
@@ -566,18 +554,21 @@
            sendContent.setType(UserCloudSendContent.TYPE_CIRCLE);
            
            if (imgVideo == null) {
               // 发送图文
               String picUrl = "";
               if (listImg.size() > 0) {
                  for (String img: listImg) {
                     picUrl +=  TbImgUtil.getTBSize220Img(img) + ";" ;
                     picUrl += img + ";";
                  }
                  if (picUrl.endsWith(";")) 
                     picUrl = picUrl.substring(0, picUrl.length()-1);
               }
               String picUrlUpload = AitaokerApiUtil.macsendUpload(robotId, picUrl);
               sendContent.setPicUrlUpload(picUrlUpload);
               sendContent.setTitle(title);
               sendContent.setPicUrl(picUrl);
               circleId = AitaokerApiUtil.macsendCircle(robotId, title, picUrl);
               circleId = AitaokerApiUtil.macsendCircle(robotId, title, picUrlUpload);
            } else {
               // 发送视频
               sendContent.setPicUrl(imgVideo.getUrl());
@@ -618,7 +609,8 @@
               for (int i = 0; i < num && i < listImg.size(); i++) {
                  try {
                     String imgBase64 = ImageToBase64.NetImageToBase64(listImg.get(i));
                     boolean macsend = AitaokerApiUtil.macsendImgBase64(robotId, cloudGroup.getGroupId(), imgBase64);
                     boolean macsend = AitaokerApiUtil.macsendImgBase64(robotId, cloudGroup.getGroupId(),
                           imgBase64);
                     if (macsend)
                        sendContent.setPicUrl(listImg.get(i));
                  } catch (Exception e) {
@@ -640,7 +632,6 @@
         userCloudSendContentService.save(sendContent);
      }
   }
   
   @Override
   @Transactional(rollbackFor = Exception.class)
@@ -672,14 +663,15 @@
      
      try {
         // 发送商品
         sendCircleByGoods(uid, cgoods.getGoodsId(), cgoods.getGoodsType(), id, cgoods.getSellerId(), UserCloudSendRecord.SEND_WAY_AUTO);
         sendCircleByGoods(uid, cgoods.getGoodsId(), cgoods.getGoodsType(), id, cgoods.getSellerId(),
               UserCloudSendRecord.SEND_WAY_AUTO);
      } catch (UserCloudException e) {
         LogHelper.cloudInfo("autoSendCustomGoods - [uid:" +uid + " 库id:"+  id +  "]原因:"+ e.getMsg());
      }
   }
   private void sendCircleByGoods(Long uid, Long goodsId, Integer goodsType, Long storeId,
         Long sellerId, int way) throws UserCloudException {
   private void sendCircleByGoods(Long uid, Long goodsId, Integer goodsType, Long storeId, Long sellerId, int way)
         throws UserCloudException {
      // 验证是否授权
      UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
      if (user == null)
@@ -707,7 +699,6 @@
      if (userCloud == null)
         throw new UserCloudException(1001, "云发单已过期");
      // 加入我的备选库
      if (storeId == null) {
         try {
@@ -715,7 +706,8 @@
            if (cloudGoods != null)
               storeId =cloudGoods.getId();
         } catch (UserCloudGoodsException e) {
            LogHelper.cloudInfo("sendCustomGoods - [uid:" +uid + "goodsId:"+  goodsId +  "goodsType" + goodsType +"]原因:"+ e.getMsg());
            LogHelper.cloudInfo("sendCustomGoods - [uid:" + uid + "goodsId:" + goodsId + "goodsType" + goodsType
                  + "]原因:" + e.getMsg());
            throw new UserCloudException(1, "加入云发单备选库失败");
         }
      }
@@ -753,7 +745,6 @@
      
      if (listOpen.size() == 0)
         throw new UserCloudException(1004, "请先开启云发单群功能");
      
      // 检测微信是否登录状态
      if (!AitaokerApiUtil.onlineCheck(robotId)) {
@@ -815,12 +806,11 @@
         }
      }
   
   }
   
   /**
    * 淘宝商品信息处理
    *
    * @param user
    * @param inviteCode
    * @param robotId
@@ -869,9 +859,9 @@
      sendGoods(robotId, wxId, listOpen, recommendText, commentText,  goods.getImgList(), user.getId(), pid);
   }
   
   /**
    * 京东商品云发单
    *
    * @param user
    * @param robotId
    * @param wxId
@@ -886,14 +876,14 @@
      if (jdGoods == null)
         throw new UserCloudException(1, "该商品已下架");
      
      String couponUrl = null;
      JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(jdGoods);
      if (couponInfo != null) {
         couponUrl = couponInfo.getLink();
      }
      String materialId = "https://item.jd.com/" + goodsId + ".html";
      String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "",user.getId() + "");
      String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "",
            user.getId() + "");
      
      boolean coupon = false;
      if (couponInfo != null) {
@@ -929,6 +919,7 @@
   
   /**
    * 京东商品云发单
    *
    * @param user
    * @param robotId
    * @param wxId
@@ -969,7 +960,8 @@
            couponAmount, null);
      
      // 获取评论语
      String zkPrice =  MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100)).setScale(2).toString();
      String zkPrice = MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100))
            .setScale(2).toString();
      String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, zkPrice, quanPrice, 
            ConfigKeyEnum.quickSharePDDCommentText);
      
@@ -982,9 +974,9 @@
      sendGoods(robotId, wxId, listOpen, recommendText, commentText, list, user.getId(), pid );
   }
   
   /**
    * 唯品会商品
    *
    * @param user
    * @param robotId
    * @param wxId
@@ -1000,7 +992,8 @@
      if (goods == null)
         throw new UserCloudException(1, "该商品已下架");
      VIPConvertResultDTO resultDTO = VipShopApiUtil.convertLink(goodsId + "", VipShopUtil.getShareChanTag(user.getId()));
      VIPConvertResultDTO resultDTO = VipShopApiUtil.convertLink(goodsId + "",
            VipShopUtil.getShareChanTag(user.getId()));
      String jumpLink = resultDTO.getUrl();
      
      boolean coupon = false;
@@ -1010,16 +1003,17 @@
      String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getGoodsName(), null,
            couponAmount, null);
      // 获取评论语
      String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, goods.getMarketPrice(),
            quanPrice, ConfigKeyEnum.quickShareVIPCommentText);
      String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink,
            goods.getMarketPrice(), quanPrice, ConfigKeyEnum.quickShareVIPCommentText);
      
      // 云发单
      sendGoods(robotId, wxId, listOpen, recommendText, commentText, goods.getGoodsDetailPictures(), user.getId(), pid);
      sendGoods(robotId, wxId, listOpen, recommendText, commentText, goods.getGoodsDetailPictures(), user.getId(),
            pid);
   }
   
   /**
    * 京东商品云发单
    *
    * @param user
    * @param robotId
    * @param wxId
@@ -1028,17 +1022,15 @@
    * @param listOpen
    * @throws UserCloudException
    */
   private void sendSuNingGoods(UserInfo user, int robotId, String wxId, Long goodsId, Long sellerId, String relationId,
         List<UserCloudGroup> listOpen, String pid) throws UserCloudException {
   private void sendSuNingGoods(UserInfo user, int robotId, String wxId, Long goodsId, Long sellerId,
         String relationId, List<UserCloudGroup> listOpen, String pid) throws UserCloudException {
      SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(goodsId +"", sellerId +"");
      if (goods == null)
         throw new UserCloudException(1, "该商品已下架");
      
      String couponLink = goods.getCouponInfo().getCouponUrl();
      String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(sellerId +"", goodsId +""),
            StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, SuningApiUtil.PID_SHARE, user.getId() + "");
      
      boolean coupon = false;
      String couponAmount = "";
@@ -1049,13 +1041,12 @@
      }  
      
      // 获取推荐语
      String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getCommodityInfo().getCommodityName(), sales,
            couponAmount, null);
      String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon,
            goods.getCommodityInfo().getCommodityName(), sales, couponAmount, null);
      
      // 生成快捷分享内容
      String template = configService.get(ConfigKeyEnum.quickShareSuNingCommentText.getKey());
      String commentText = shareGoodsTextTemplateService.createQuickShareTextSuNing(template, goods, jumpLink);
      
      List<String> imgList = new ArrayList<>();
      for (SuningGoodsImg img : goods.getCommodityInfo().getPictureUrl()) {
@@ -1068,6 +1059,7 @@
   
   /**
    * 发送商品
    *
    * @param robotId
    * @param title
    * @param comment
@@ -1075,8 +1067,8 @@
    * @param wxId
    * @param listOpen
    */
   private void sendGoods(int robotId,String wxId, List<UserCloudGroup> listOpen, String title,
         String comment, List<String> listImg, Long uid, String pid) {
   private void sendGoods(int robotId, String wxId, List<UserCloudGroup> listOpen, String title, String comment,
         List<String> listImg, Long uid, String pid) {
      // 遍历群-朋友圈
      for (UserCloudGroup cloudGroup: listOpen) {
         UserCloudSendContent sendContent = new UserCloudSendContent();
@@ -1092,15 +1084,16 @@
               for (String img: listImg) {
                  picUrl +=  TbImgUtil.getTBSize220Img(img) + ";" ;
               }
            }
            if (picUrl.endsWith(";")) 
               picUrl = picUrl.substring(0, picUrl.length()-1);
            }
            
            String picUrlUpload = AitaokerApiUtil.macsendUpload(robotId, picUrl);
            sendContent.setPicUrlUpload(picUrlUpload);
            sendContent.setTitle(title);
            sendContent.setPicUrl(picUrl);
            // 发圈内容
            String circleId = AitaokerApiUtil.macsendCircle(robotId, title, picUrl);
            String circleId = AitaokerApiUtil.macsendCircle(robotId, title, picUrlUpload);
            // 评论文本
            if (!StringUtil.isNullOrEmpty(circleId)) {
               sendContent.setState(true);
@@ -1131,14 +1124,14 @@
               for (int i = 0; i < num && i < listImg.size(); i++) {
                  try {
                     String imgBase64 = ImageToBase64.NetImageToBase64(listImg.get(i));
                     boolean macsend = AitaokerApiUtil.macsendImgBase64(robotId, cloudGroup.getGroupId(), imgBase64);
                     boolean macsend = AitaokerApiUtil.macsendImgBase64(robotId, cloudGroup.getGroupId(),
                           imgBase64);
                     if (macsend)
                        sendContent.setPicUrl(listImg.get(i));
                  } catch (Exception e) {
                     LogHelper.errorDetailInfo(e);
                  }
               }
            
            // 评论文本
            List<String> list = new ArrayList<>();
@@ -1152,7 +1145,6 @@
         userCloudSendContentService.save(sendContent);
      }
   }
   
   @Override
   public void fixedTimeSend(List<GoodsEvaluate> listActivity, List<GoodsEvaluate> listGoods) {
@@ -1183,7 +1175,8 @@
               // 活动
               if (listActivity != null && listActivity.size() > 0) {
                  for (GoodsEvaluate evaluate: listActivity) {
                     UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid, evaluate.getId());
                     UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid,
                           evaluate.getId());
                     if (record != null) 
                        continue;
                     
@@ -1194,7 +1187,8 @@
               // 单品
               if (StringUtil.isNullOrEmpty(evaluateId) && listGoods != null && listGoods.size() > 0) {
                  for (GoodsEvaluate evaluate: listGoods) {
                     UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid, evaluate.getId());
                     UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid,
                           evaluate.getId());
                     if (record != null) 
                        continue;
                     
@@ -1205,7 +1199,8 @@
            
               if(!StringUtil.isNullOrEmpty(evaluateId)) {
                  UserCloudMQMsg msg = new UserCloudMQMsg(uid, evaluateId, UserCloudMQMsg.TYPE_EVALUATE);
                  Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userCloud, msg);
                  Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userCloud,
                        msg);
                  producer.send(message);
               }
            } catch (Exception e) {