yujian
2020-06-11 20bb4f95184453d4addfd27e40a78f3c63bcf6c3
fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java
@@ -15,7 +15,6 @@
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.Producer;
import com.yeshi.fanli.dao.mybatis.user.cloud.UserCloudMapper;
import com.yeshi.fanli.dto.aitaoker.RobotInfoDTO;
import com.yeshi.fanli.dto.aitaoker.WeiXinGroupDTO;
import com.yeshi.fanli.dto.jd.JDCouponInfo;
import com.yeshi.fanli.dto.jd.JDPingouInfo;
@@ -71,6 +70,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;
@@ -236,56 +236,56 @@
         }
      }
      RobotInfoDTO dto = null;
      if (renew) { // 续费
         dto = AitaokerApiUtil.robotRenewals(userCloud.getRobotId(), menuEnum.getMonth());
      } else {
         dto = AitaokerApiUtil.robotCreate(menuEnum.getMonth(), menuEnum.getType(), "wechatrobot", null);
      }
      if (dto == null) {
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回空值");
         throw new UserCloudException(1, "机器人获取失败");
      }
      String endTimeStr = dto.getEndTime();
      if (StringUtil.isNullOrEmpty(endTimeStr)) {
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回时间为空");
         throw new UserCloudException(1, "机器人返回时间为空");
      }
      long endTime = 0;
      try {
         endTime = Long.parseLong(endTimeStr);
      } catch (Exception e) {
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回时间格式不正确");
         throw new UserCloudException(1, "机器人返回时间格式不正确");
      }
      Integer robotId = dto.getId();
      if (robotId == null) {
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 机器人ID返回为空");
         throw new UserCloudException(1, "机器人ID返回为空");
      }
      Integer groupNum = dto.getGroupNum();
      if (groupNum == null) {
         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: groupNum返回为空");
         throw new UserCloudException(1, "groupNum返回为空");
      }
//      RobotInfoDTO dto = null;
//      if (renew) { // 续费
//         dto = AitaokerApiUtil.robotRenewals(userCloud.getRobotId(), menuEnum.getMonth());
//      } else { // 创建机器人
//         dto = AitaokerApiUtil.robotCreate(menuEnum.getMonth(), menuEnum.getType(), "wechatrobot", null);
//      }
//
//      if (dto == null) {
//         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回空值");
//         throw new UserCloudException(1, "机器人获取失败");
//      }
//
//      String endTimeStr = dto.getEndTime();
//      if (StringUtil.isNullOrEmpty(endTimeStr)) {
//         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回时间为空");
//         throw new UserCloudException(1, "机器人返回时间为空");
//      }
//
//      long endTime = 0;
//      try {
//         endTime = Long.parseLong(endTimeStr);
//      } catch (Exception e) {
//         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回时间格式不正确");
//         throw new UserCloudException(1, "机器人返回时间格式不正确");
//      }
//
//      Integer robotId = dto.getId();
//      if (robotId == null) {
//         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 机器人ID返回为空");
//         throw new UserCloudException(1, "机器人ID返回为空");
//      }
//
//      Integer groupNum = dto.getGroupNum();
//      if (groupNum == null) {
//         LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: groupNum返回为空");
//         throw new UserCloudException(1, "groupNum返回为空");
//      }
      UserCloud newCloud = new UserCloud();
      newCloud.setUid(uid);
      newCloud.setOrderId(orderId);
      newCloud.setGroupNum(groupNum);
      newCloud.setRobotId(robotId);
//      newCloud.setGroupNum(groupNum);
//      newCloud.setRobotId(robotId);
      newCloud.setRobotType(menuEnum.getType());
      if (renew) {
         newCloud.setStartTime(userCloud.getStartTime());
      } else {
         newCloud.setStartTime(new Date());
      }
      newCloud.setEndTime(new Date(endTime * 1000)); // Unix 转换 普通时间
//      if (renew) {
//         newCloud.setStartTime(userCloud.getStartTime());
//      } else {
//         newCloud.setStartTime(new Date());
//      }
//      newCloud.setEndTime(new Date(endTime * 1000)); // Unix 转换 普通时间
      newCloud.setCreateTime(new Date());
      userCloudMapper.insertSelective(newCloud);
      
@@ -306,12 +306,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);
@@ -374,6 +389,10 @@
      String wxId = userCloud.getWxId();
      if (StringUtil.isNullOrEmpty(wxId)) 
         throw new UserCloudException(1003, "微信号不存在,请先微信登录");
      if (!AitaokerApiUtil.onlineCheck(robotId)) {
         throw new UserCloudException(1003, "微信已掉线,请先重新登录微信");
      }
      
      // 验证开启状态
      List<UserCloudGroup> listGroup = userCloudGroupService.listByUid(uid);
@@ -516,9 +535,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);
               // 发送图文
@@ -675,6 +697,11 @@
      String wxId = userCloud.getWxId();
      if (StringUtil.isNullOrEmpty(wxId)) 
         throw new UserCloudException(1002, "请先登录微信");
      if (!AitaokerApiUtil.onlineCheck(robotId)) {
         throw new UserCloudException(1003, "微信已掉线,请先重新登录微信");
      }
      
      // 验证开启状态
      List<UserCloudGroup> listGroup = userCloudGroupService.listByUid(uid);
@@ -1009,9 +1036,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);