yujian
2020-06-19 dcb37a9df7c41be08d3aed13667e9162382d134a
fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java
@@ -8,6 +8,7 @@
import javax.annotation.Resource;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.BigDecimalUtil;
@@ -32,6 +33,7 @@
import com.yeshi.fanli.entity.bus.user.cloud.UserCloud;
import com.yeshi.fanli.entity.bus.user.cloud.UserCloudGoods;
import com.yeshi.fanli.entity.bus.user.cloud.UserCloudGroup;
import com.yeshi.fanli.entity.bus.user.cloud.UserCloudManage;
import com.yeshi.fanli.entity.bus.user.cloud.UserCloudSendContent;
import com.yeshi.fanli.entity.bus.user.cloud.UserCloudSendRecord;
import com.yeshi.fanli.entity.dynamic.CommentInfo;
@@ -47,19 +49,24 @@
import com.yeshi.fanli.exception.goods.ConvertLinkExceptionException;
import com.yeshi.fanli.exception.share.ShareGoodsException;
import com.yeshi.fanli.exception.user.cloud.UserCloudException;
import com.yeshi.fanli.exception.user.cloud.UserCloudGoodsException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
import com.yeshi.fanli.service.inter.goods.ShareGoodsTextTemplateService;
import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
import com.yeshi.fanli.service.inter.msg.UserSystemMsgService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.service.inter.user.QrCodeService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.cloud.UserCloudGoodsService;
import com.yeshi.fanli.service.inter.user.cloud.UserCloudGroupService;
import com.yeshi.fanli.service.inter.user.cloud.UserCloudManageService;
import com.yeshi.fanli.service.inter.user.cloud.UserCloudSendContentService;
import com.yeshi.fanli.service.inter.user.cloud.UserCloudSendRecordService;
import com.yeshi.fanli.service.inter.user.cloud.UserCloudService;
@@ -68,6 +75,7 @@
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.ImageToBase64;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.RedisKeyEnum;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.aitaoker.AitaokerApiUtil;
@@ -149,8 +157,24 @@
   @Resource
   private UserCloudSendContentService userCloudSendContentService;
   
   @Resource
   private UserCloudManageService userCloudManageService;
   @Resource(name = "producer")
   private Producer producer;
   @Resource
   private UserOtherMsgNotificationService userOtherMsgNotificationService;
   @Resource
   private PushService pushService;
   @Resource
   private UserSystemMsgService userSystemMsgService;
   @Resource(name = "taskExecutor")
   private TaskExecutor executor;
   
   
   @Override
@@ -182,9 +206,6 @@
         count = 0L;
      return count;
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
@@ -193,6 +214,15 @@
      if (userCloud == null)
         throw new UserCloudException(1, "云发单已过期");
      // 检测是否需要更新 - 1分钟间隔
      String key = "cloudLogin_" + uid;
      String result = redisManager.getCommonString(key);
      if (!StringUtil.isNullOrEmpty(result)) {
         return;
      }
      redisManager.cacheCommonString(key , "true" , 60);
      // 更新信息
      UserCloud update = new UserCloud();
      update.setId(userCloud.getId());
@@ -200,7 +230,24 @@
      update.setWxName(wxName);
      update.setWxPortrait(wxPortrait);
      userCloudMapper.updateByPrimaryKeySelective(update);
      try {
         userOtherMsgNotificationService.cloudMsg(uid, "云发单微信账号", "微信账号登录成功", "可以开启你的群发单了");
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
      // 更新提醒状态
      UserCloudManage cloudManage = userCloudManageService.selectForUpdate(uid);
      if (cloudManage == null) {
         userCloudManageService.save(uid, false, false);
      } else {
         UserCloudManage updateManage = new UserCloudManage();
         updateManage.setId(uid);
         updateManage.setOfflineNotice(false);
         userCloudManageService.updateByPrimaryKeySelective(updateManage);
      }
      // 微信号变化-清空群信息
      if (!wxId.equals(userCloud.getWxId())) {
         userCloudGroupService.deleteGroupByUid(uid);
@@ -213,7 +260,6 @@
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void openCloud(Long uid, Long orderId, CloudOrderMenuEnum menuEnum) throws UserCloudException {
      UserCloud existCloud = userCloudMapper.getByOrderId(orderId);
      if (existCloud != null) {
@@ -227,8 +273,8 @@
         if (userCloud.getEndTime().getTime() > java.lang.System.currentTimeMillis())
            renew = true;
         // 验证套餐是否相同
         if (renew && userCloud.getRobotType() != menuEnum.getType()) {
            LogHelper.error("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]已有其他云发单套餐还未结束");
         if (renew && userCloud.getRobotType() != menuEnum.getRobotType()) {
            LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]已有其他云发单套餐还未结束");
            throw new UserCloudException(1, "已有其他云发单套餐还未结束");
         }
      }
@@ -236,39 +282,34 @@
      RobotInfoDTO dto = null;
      if (renew) { // 续费
         dto = AitaokerApiUtil.robotRenewals(userCloud.getRobotId(), menuEnum.getMonth());
      } else {
         dto = AitaokerApiUtil.robotCreate(menuEnum.getMonth(), menuEnum.getType(), "wechatrobot", null);
      } else { // 创建机器人
         dto = AitaokerApiUtil.robotCreate(menuEnum.getMonth(), menuEnum.getRobotType(), "wechatrobot", null);
      }
      if (dto == null) {
         LogHelper.error("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回空值");
         throw new UserCloudException(1, "机器人获取失败");
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 机器人创建失败");
      }
      Integer robotId = dto.getId();
      if (robotId == null) {
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 机器人ID返回为空");
      }
      String endTimeStr = dto.getEndTime();
      if (StringUtil.isNullOrEmpty(endTimeStr)) {
         LogHelper.error("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回时间为空");
         throw new UserCloudException(1, "机器人返回时间为空");
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回时间为空");
      }
      long endTime = 0;
      try {
         endTime = Long.parseLong(endTimeStr);
      } catch (Exception e) {
         LogHelper.error("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回时间格式不正确");
         throw new UserCloudException(1, "机器人返回时间格式不正确");
      }
      Integer robotId = dto.getId();
      if (robotId == null) {
         LogHelper.error("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 机器人ID返回为空");
         throw new UserCloudException(1, "机器人ID返回为空");
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回时间格式不正确");
      }
      Integer groupNum = dto.getGroupNum();
      if (groupNum == null) {
         LogHelper.error("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: groupNum返回为空");
         throw new UserCloudException(1, "groupNum返回为空");
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: groupNum返回为空");
      }
      UserCloud newCloud = new UserCloud();
@@ -276,11 +317,34 @@
      newCloud.setOrderId(orderId);
      newCloud.setGroupNum(groupNum);
      newCloud.setRobotId(robotId);
      newCloud.setRobotType(menuEnum.getType());
      newCloud.setStartTime(new Date());
      newCloud.setRobotType(menuEnum.getRobotType());
      if (renew) {
         newCloud.setWxId(userCloud.getWxId());
         newCloud.setWxName(userCloud.getWxName());
         newCloud.setWxPortrait(userCloud.getPortrait());
         newCloud.setStartTime(userCloud.getStartTime());
      } else {
         newCloud.setStartTime(new Date());
      }
      newCloud.setEndTime(new Date(endTime * 1000)); // Unix 转换 普通时间
      newCloud.setCreateTime(new Date());
      userCloudMapper.insertSelective(newCloud);
      // 开启发圈功能
      userCloudManageService.save(uid, null, null);
      try {
         String item = null;
         if (renew) {
            item = "成功续费" + menuEnum.getDescShow();
         } else {
            item = "成功开通" + menuEnum.getDescShow();
         }
         String desc = "完成充值支付"+ BigDecimal.valueOf(menuEnum.getMoney()).setScale(2, BigDecimal.ROUND_DOWN) +"元";
         userOtherMsgNotificationService.cloudMsg(uid, "云发单充值", item, desc);
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
   }
   @Override
@@ -296,12 +360,27 @@
      List<WeiXinGroupDTO> list = AitaokerApiUtil.getContract(robotId);
      if (list == null || list.size() == 0)
         throw new UserCloudException(1, "未检索到对应群");
      String wxId = userCloud.getWxId();
      for (WeiXinGroupDTO dto : list) {
         userCloudGroupService.addGroup(uid, dto.getGroupId(), dto.getGroupName(), userCloud.getGroupNum());
         String groupId = dto.getGroupId();
         // 检测是否匹配群
         String key =  RedisKeyEnum.cloudMatchGroup.getKey() + StringUtil.Md5(wxId + "_" + groupId);
         String result = redisManager.getCommonString(key);
          if (!StringUtil.isNullOrEmpty(result)) {
            userCloudGroupService.addGroup(uid, dto.getGroupId(), dto.getGroupName(), userCloud.getGroupNum());
         }
      }
   }
   
   @Override
   public void cacheMatchGroup(String wxId, String groupId) {
       if (StringUtil.isNullOrEmpty(wxId) || StringUtil.isNullOrEmpty(groupId))
         return;
      String key =  RedisKeyEnum.cloudMatchGroup.getKey() + StringUtil.Md5(wxId + "_" + groupId);
      redisManager.cacheCommonString(key , "true" , 60*20);
   }
   @Override
   public void sendByDynamic(Long uid, String id) throws UserCloudException{
      sendCircleByDynamic(uid, id, UserCloudSendRecord.SEND_WAY_MANUAL);
@@ -309,7 +388,18 @@
   
   
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void autoSendByDynamic(Long uid, String id) {
      boolean official = false;
      UserCloudManage cloudManage = userCloudManageService.selectByPrimaryKey(uid);
      if (cloudManage != null) {
         if (cloudManage.getOfficial() != null)
            official = cloudManage.getOfficial();
      }
      if (!official)
         return;
      try {
         sendCircleByDynamic(uid, id, UserCloudSendRecord.SEND_WAY_AUTO);
      } catch (UserCloudException e) {
@@ -382,6 +472,14 @@
      if (comments == null || comments.size() == 0)
         throw new UserCloudException(1, "该内容不能转链");
      // 检测微信是否登录状态
      if (!AitaokerApiUtil.onlineCheck(robotId)) {
         // 通知登录微信
         offlineNotification(uid);
         throw new UserCloudException(1003, "微信已掉线,需要重新扫描二维码登录");
      }
      
      boolean hasToken = false;
      List<String> listComment = new ArrayList<>();
@@ -423,7 +521,6 @@
      
      String qrCode = null;
      String cloudPic = null;
      ImgInfo imgVideo = null;
      List<String> listImg = new ArrayList<>();
      
@@ -434,26 +531,7 @@
               imgVideo = imgInfo;
               continue;
            }
            if (imgInfo.getType() == ImgEnum.goods) {
               cloudPic = imgInfo.getUrl();
            }
            listImg.add(imgInfo.getUrl());
            // 取消二维码图
//            GoodsDetailVO goodsVO = imgInfo.getGoodsVO();
//            if (goodsVO == null) {
//               listImg.add(imgInfo.getUrl());
//            } else {
//               String jumpLink = getJumpLink(goodsVO, user, relationId, inviteCode, imgInfo.getUrl());
//               if (!StringUtil.isNullOrEmpty(jumpLink)) {
//                  qrCode = jumpLink;
//               }
//            }
         }
         if (cloudPic == null) {
            cloudPic = imgs.get(0).getUrl();
         }
      }
      
@@ -466,7 +544,7 @@
      sendRecord.setWxId(wxId);
      sendRecord.setRobotId(robotId);
      sendRecord.setSendTime(new Date());
      sendRecord.setSendOrigin(UserCloudSendRecord.ORIGIN_STORE);
      sendRecord.setSendOrigin(UserCloudSendRecord.ORIGIN_EVALUATE);
      UserCloudSendRecord result = userCloudSendRecordService.save(sendRecord);
      String pid = result.getId();
      
@@ -490,9 +568,12 @@
                  
               if (listImg.size() > 0) {
                  for (String img: listImg) {
                     picUrl += "," + img;
                     picUrl +=  img + ";" ;
                  }
               }
               if (picUrl.endsWith(";"))
                  picUrl = picUrl.substring(0, picUrl.length()-1);
               sendContent.setTitle(title);
               sendContent.setPicUrl(picUrl);
               // 发送图文
@@ -527,16 +608,23 @@
            }
            
            // 发送图片
            if (!StringUtil.isNullOrEmpty(cloudPic)) {
               try {
                  String imgBase64 = ImageToBase64.NetImageToBase64(cloudPic);
                  boolean macsend = AitaokerApiUtil.macsendImgBase64(robotId, cloudGroup.getGroupId(), imgBase64);
                  if (macsend)
                     sendContent.setPicUrl(cloudPic);
               } catch (Exception e) {
                  LogHelper.errorDetailInfo(e);
               }
            int num = 1;
            String picNum = configService.get(ConfigKeyEnum.robotCloudGroupPictureNum.getKey());
            if (!StringUtil.isNullOrEmpty(picNum)) {
               num = Integer.parseInt(picNum);
            }
            if (listImg.size() > 0)
               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);
                     if (macsend)
                        sendContent.setPicUrl(listImg.get(i));
                  } catch (Exception e) {
                     LogHelper.errorDetailInfo(e);
                  }
               }
            
            // 评论文本
            List<String> list = new ArrayList<>();
@@ -554,14 +642,26 @@
   }
   
   
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void sendCustomGoods(Long uid, Long goodsId, Integer goodsType, Long sellerId) throws UserCloudException{
      sendCircleByGoods(uid, goodsId, goodsType, null, sellerId);
      sendCircleByGoods(uid, goodsId, goodsType, null, sellerId,  UserCloudSendRecord.SEND_WAY_MANUAL);
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void autoSendCustomGoods(Long uid, Long id) {
      boolean custom = false;
      UserCloudManage cloudManage = userCloudManageService.selectByPrimaryKey(uid);
      if (cloudManage != null) {
         if (cloudManage.getCustom() != null)
            custom = cloudManage.getCustom();
      }
      if (!custom) {
         return;
      }
      UserCloudGoods cloudGoods = userCloudGoodsService.selectByPrimaryKey(id);
      if (cloudGoods == null) {
         return;
@@ -572,19 +672,14 @@
      
      try {
         // 发送商品
         sendCircleByGoods(uid, cgoods.getGoodsId(), cgoods.getGoodsType(), id, cgoods.getSellerId());
         UserCloudGoods record = new UserCloudGoods();
         record.setId(id);
         record.setState(UserCloudGoods.STATE_SHARED);
         record.setUpdateTime(new Date());
         userCloudGoodsService.updateByPrimaryKeySelective(record);
         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) 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)
@@ -612,6 +707,30 @@
      if (userCloud == null)
         throw new UserCloudException(1001, "云发单已过期");
      // 加入我的备选库
      if (storeId == null) {
         try {
            UserCloudGoods cloudGoods = userCloudGoodsService.addGoods(uid, goodsId, goodsType, sellerId);
            if (cloudGoods != null)
               storeId =cloudGoods.getId();
         } catch (UserCloudGoodsException e) {
            LogHelper.cloudInfo("sendCustomGoods - [uid:" +uid + "goodsId:"+  goodsId +  "goodsType" + goodsType +"]原因:"+ e.getMsg());
            throw new UserCloudException(1, "加入云发单备选库失败");
         }
      }
      // 自选库商品是否打开
      boolean custom = false;
      UserCloudManage cloudManage = userCloudManageService.selectByPrimaryKey(uid);
      if (cloudManage != null) {
         if (cloudManage.getCustom() != null)
            custom = cloudManage.getCustom();
      }
      if (!custom) {
         return;
      }
      Integer robotId = userCloud.getRobotId();
      if (robotId == null)
         throw new UserCloudException(1, "云发单机器人不存在");
@@ -635,6 +754,15 @@
      if (listOpen.size() == 0)
         throw new UserCloudException(1004, "请先开启云发单群功能");
      
      // 检测微信是否登录状态
      if (!AitaokerApiUtil.onlineCheck(robotId)) {
         // 通知登录微信
         offlineNotification(uid);
         throw new UserCloudException(1003, "微信已掉线,需要重新扫描二维码登录");
      }
      // 保存发送记录
      UserCloudSendRecord sendRecord = new UserCloudSendRecord();
      sendRecord.setUid(uid);
@@ -652,17 +780,43 @@
      }
      UserCloudSendRecord result = userCloudSendRecordService.save(sendRecord);
      
      if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
         sendTaoBaoGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
      } else if (goodsType == Constant.SOURCE_TYPE_JD) {
         sendJDGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
      } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
         sendPDDGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
      } else if (goodsType == Constant.SOURCE_TYPE_VIP) {
         sendVIPGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
      } else if (goodsType == Constant.SOURCE_TYPE_SUNING) {
         sendSuNingGoods(user, robotId, wxId, goodsId, sellerId, relationId, listOpen, result.getId());
      try {
         if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
            sendTaoBaoGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
         } else if (goodsType == Constant.SOURCE_TYPE_JD) {
            sendJDGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
         } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
            sendPDDGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
         } else if (goodsType == Constant.SOURCE_TYPE_VIP) {
            sendVIPGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
         } else if (goodsType == Constant.SOURCE_TYPE_SUNING) {
            sendSuNingGoods(user, robotId, wxId, goodsId, sellerId, relationId, listOpen, result.getId());
         }
         // 更新发单记录
         if (storeId != null) {
            UserCloudGoods record = new UserCloudGoods();
            record.setId(storeId);
            record.setState(UserCloudGoods.STATE_SHARED);
            record.setSendTime(new Date());
            record.setUpdateTime(new Date());
            userCloudGoodsService.updateByPrimaryKeySelective(record);
         }
      } catch (UserCloudException e) {
         LogHelper.cloudInfo("autoSendCustomGoods - [uid:" +uid + " 库id:"+  storeId +  "]原因:"+ e.getMsg());
         // 更新发单记录
         if (storeId != null) {
            UserCloudGoods record = new UserCloudGoods();
            record.setId(storeId);
            record.setState(UserCloudGoods.STATE_INVALID);
            record.setSendTime(new Date());
            record.setUpdateTime(new Date());
            userCloudGoodsService.updateByPrimaryKeySelective(record);
         }
      }
   }
   
   /**
@@ -857,7 +1011,7 @@
            couponAmount, null);
      // 获取评论语
      String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, goods.getMarketPrice(), 
            quanPrice, ConfigKeyEnum.quickShareJDCommentText);
            quanPrice, ConfigKeyEnum.quickShareVIPCommentText);
      
      // 云发单
      sendGoods(robotId, wxId, listOpen, recommendText, commentText, goods.getGoodsDetailPictures(), user.getId(), pid);
@@ -887,17 +1041,21 @@
      
      
      boolean coupon = false;
      String quanPrice = "";
      String couponAmount = "";
      String sales = null;
      if (goods.getCouponInfo() != null && !StringUtil.isNullOrEmpty(goods.getCouponInfo().getCouponUrl())) {// 有券
         couponAmount = new BigDecimal(goods.getCouponInfo().getCouponValue()).toString();
         coupon = true;
      }
      // 获取推荐语
      String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getCommodityInfo().getCommodityName(), sales, 
            couponAmount, null);
      
      // 获取评论语
      String zkPrice = goods.getCommodityInfo().getCommodityPrice().toString();
      String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, zkPrice, quanPrice,
            ConfigKeyEnum.quickShareJDCommentText);
      // 生成快捷分享内容
      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()) {
@@ -932,9 +1090,12 @@
            String picUrl = "";
            if (listImg.size() > 0) {
               for (String img: listImg) {
                  picUrl += "," + img;
                  picUrl +=  img + ";" ;
               }
            }
            if (picUrl.endsWith(";"))
               picUrl = picUrl.substring(0, picUrl.length()-1);
            sendContent.setTitle(title);
            sendContent.setPicUrl(picUrl);
            
@@ -960,18 +1121,25 @@
            }
            
            // 发送图片
            String picurl = listImg.get(0);
            if (!StringUtil.isNullOrEmpty(picurl)) {
               try {
                  String imgBase64 = ImageToBase64.NetImageToBase64(picurl);
                  boolean macsend = AitaokerApiUtil.macsendImgBase64(robotId, cloudGroup.getGroupId(), imgBase64);
                  if (macsend)
                     sendContent.setPicUrl(picurl);
               } catch (Exception e) {
                  LogHelper.errorDetailInfo(e);
            int num = 1;
            String picNum = configService.get(ConfigKeyEnum.robotCloudGroupPictureNum.getKey());
            if (!StringUtil.isNullOrEmpty(picNum)) {
               num = Integer.parseInt(picNum);
            }
            if (listImg.size() > 0)
               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);
                     if (macsend)
                        sendContent.setPicUrl(listImg.get(i));
                  } catch (Exception e) {
                     LogHelper.errorDetailInfo(e);
                  }
               }
            
            }
            // 评论文本
            List<String> list = new ArrayList<>();
            boolean macsend = AitaokerApiUtil.macsendText(robotId, cloudGroup.getGroupId(), comment);
@@ -985,35 +1153,58 @@
      }
   }
   @Override
   public void fixedTimeSend(String id) {
      if (StringUtil.isNullOrEmpty(id))
   public void fixedTimeSend(List<GoodsEvaluate> listActivity, List<GoodsEvaluate> listGoods) {
      if (listGoods == null && listActivity == null)
         return;
      // 一个小时之前
      long rand = 1000 * 60 * 60 ;
      long time = java.lang.System.currentTimeMillis() - rand;
      Date lastTime =  new Date(time);
      Date lastTime = new Date(java.lang.System.currentTimeMillis() - 1000 * 60 * 60);
      for (int i = 0; i < 1000; i ++) {
         List<Long> list = userCloudMapper.listValidUid((i-1)*1000, 1000);
         if (list == null || list.size() == 0) {
         // 查询哪些用户开通
         List<Long> listUser = userCloudMapper.listValidUid(i*1000, 1000);
         if (listUser == null || listUser.size() == 0) {
            break;
         }
         
         for (Long uid: list) {
            try {
               UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid, id);
               if (record != null)
         // 遍历用户
         for (Long uid: listUser) {
            try {// 判断是否开通官方采集
               UserCloudManage cloudManage = userCloudManageService.selectByPrimaryKey(uid);
               if (cloudManage == null || cloudManage.getOfficial() == null || !cloudManage.getOfficial()) {
                  continue;
               }
               // 是否在一个小时内已发送过
               UserCloudSendRecord last = userCloudSendRecordService.getLastByUid(uid, lastTime);
               if (last != null)
                  continue;
               
               if (!Constant.IS_TEST) {
                  UserCloudMQMsg msg = new UserCloudMQMsg(uid, id, UserCloudMQMsg.TYPE_EVALUATE);
               String evaluateId = null;
               // 活动
               if (listActivity != null && listActivity.size() > 0) {
                  for (GoodsEvaluate evaluate: listActivity) {
                     UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid, evaluate.getId());
                     if (record != null)
                        continue;
                     evaluateId = evaluate.getId();
                     break;
                  }
               }
               // 单品
               if (StringUtil.isNullOrEmpty(evaluateId) && listGoods != null && listGoods.size() > 0) {
                  for (GoodsEvaluate evaluate: listGoods) {
                     UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid, evaluate.getId());
                     if (record != null)
                        continue;
                     evaluateId = evaluate.getId();
                     break;
                  }
               }
               if(!StringUtil.isNullOrEmpty(evaluateId)) {
                  UserCloudMQMsg msg = new UserCloudMQMsg(uid, evaluateId, UserCloudMQMsg.TYPE_EVALUATE);
                  Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userCloud, msg);
                  producer.send(message);
               }
@@ -1022,6 +1213,65 @@
            }
         }
      }
   }
   private void offlineNotification(Long uid) {
      UserCloudManage cloudManage = userCloudManageService.selectForUpdate(uid);
      if (cloudManage == null) {
          return;
      }
      Boolean offlineNotice = cloudManage.getOfflineNotice();
      if (offlineNotice != null && offlineNotice) {
         return;
      }
      try {
         userOtherMsgNotificationService.cloudMsg(uid, "云发单微信账号", "微信账号掉线", "需要你重新扫描二维码登录");
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
      // 站内信通知
      offlineNotificationZNX(uid);
      // 延迟10分钟再次提醒
      if(!Constant.IS_TEST) {
         UserCloudMQMsg msg = new UserCloudMQMsg(uid, UserCloudMQMsg.TYPE_PUSH);
         Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userCloud, msg);
         message.setStartDeliverTime(java.lang.System.currentTimeMillis() + 1000 * 60 * 10);
         producer.send(message);
      }
      // 更新已提醒
      UserCloudManage updateManage = new UserCloudManage();
      updateManage.setId(uid);
      updateManage.setOfflineNotice(true);
      userCloudManageService.updateByPrimaryKeySelective(updateManage);
   }
   // 站内信通知
   @Override
   public void offlineNotificationZNX(Long uid) {
      // 验证是否开通
      UserCloud userCloud = userCloudMapper.getValidByUid(uid);
      if (userCloud == null)
         return;
      Integer robotId = userCloud.getRobotId();
      if (robotId == null)
         return;
      // 登录状态
      if (AitaokerApiUtil.onlineCheck(robotId)) {
         return;
      }
      try {
         pushService.pushZNX(uid, "【重要通知】你的云发单微信已掉线。", "需要你重新扫描二维码登录", null, null);
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
   }
}