yujian
2020-06-22 652de4214ebe5efcf3abd30e68c83cb38beb2a23
云发单-发圈调整
3个文件已修改
491 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/entity/bus/user/cloud/UserCloudSendContent.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java 459 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/aitaoker/AitaokerApiUtil.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/bus/user/cloud/UserCloudSendContent.java
@@ -30,6 +30,8 @@
    @Field
    private String picUrl;
    @Field
    private String picUrlUpload;
    @Field
    private List<String> comments;
    @Field
    private boolean state; // 是否发送成功
@@ -124,4 +126,12 @@
        this.createTime = createTime;
    }
    public String getPicUrlUpload() {
        return picUrlUpload;
    }
    public void setPicUrlUpload(String picUrlUpload) {
        this.picUrlUpload = picUrlUpload;
    }
}
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;
@@ -110,75 +109,73 @@
    @Resource
    private ConvertLinkManager convertLinkManager;
    @Resource
    private UserCloudGoodsService userCloudGoodsService;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Resource
    private ConfigService configService;
    @Resource
    private JDGoodsCacheUtil jdGoodsCacheUtil;
    @Resource
    private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
    @Resource
    private QrCodeService qrCodeService;
    @Resource
    private RedisManager redisManager;
    @Resource
    private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private ShareGoodsTextTemplateService shareGoodsTextTemplateService;
    @Resource
    private CommonGoodsService commonGoodsService;
    @Resource
    private UserCloudSendRecordService userCloudSendRecordService;
    @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
    public UserCloud getValidByUid(Long uid) {
        return userCloudMapper.getValidByUid(uid);
@@ -194,13 +191,12 @@
        Long count = userCloudMapper.countByUid(uid);
        return count;
    }
    @Override
    public List<UserCloud> query(int page, int count,String key, Integer state) {
        return userCloudMapper.query((page-1)* count, count, key, state);
    public List<UserCloud> query(int page, int count, String key, Integer state) {
        return userCloudMapper.query((page - 1) * count, count, key, state);
    }
    @Override
    public long count(String key, Integer state) {
        Long count = userCloudMapper.count(key, state);
@@ -222,9 +218,8 @@
        if (!StringUtil.isNullOrEmpty(result)) {
            return;
        }
        redisManager.cacheCommonString(key , "true" , 60);
        redisManager.cacheCommonString(key, "true", 60);
        // 更新信息
        UserCloud update = new UserCloud();
        update.setId(userCloud.getId());
@@ -232,13 +227,13 @@
        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) {
@@ -249,7 +244,7 @@
            updateManage.setOfflineNotice(false);
            userCloudManageService.updateByPrimaryKeySelective(updateManage);
        }
        // 微信号变化-清空群信息
        if (!wxId.equals(userCloud.getWxId())) {
            userCloudGroupService.deleteGroupByUid(uid);
@@ -296,7 +291,7 @@
        if (robotId == null) {
            LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 机器人ID返回为空");
        }
        String endTimeStr = dto.getEndTime();
        if (StringUtil.isNullOrEmpty(endTimeStr)) {
            LogHelper.cloudInfo("方法openCloud: [uid=" + uid + "][订单ID=" + orderId + "]机器人失败: 返回时间为空");
@@ -331,10 +326,10 @@
        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) {
@@ -342,7 +337,7 @@
            } else {
                item = "成功开通" + menuEnum.getDescShow();
            }
            String desc = "完成充值支付"+ BigDecimal.valueOf(menuEnum.getMoney()).setScale(2, BigDecimal.ROUND_DOWN) +"元";
            String desc = "完成充值支付" + BigDecimal.valueOf(menuEnum.getMoney()).setScale(2, BigDecimal.ROUND_DOWN) + "元";
            userOtherMsgNotificationService.cloudMsg(uid, "云发单充值", item, desc);
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
@@ -362,7 +357,7 @@
        List<String> list = AitaokerApiUtil.getContract(12793);
        if (list == null || list.size() == 0)
            throw new UserCloudException(1, "未检索到对应群");
        String wxId = userCloud.getWxId();
        for (String roomId : list) {
            String key = RedisKeyEnum.cloudMatchGroup.getKey() + StringUtil.Md5(wxId + "_" + roomId);
@@ -377,21 +372,20 @@
            }
        }
    }
    @Override
    public void cacheMatchGroup(String wxId, String groupId) {
         if (StringUtil.isNullOrEmpty(wxId) || StringUtil.isNullOrEmpty(groupId))
        if (StringUtil.isNullOrEmpty(wxId) || StringUtil.isNullOrEmpty(groupId))
            return;
        String key =  RedisKeyEnum.cloudMatchGroup.getKey() + StringUtil.Md5(wxId + "_" + groupId);
        redisManager.cacheCommonString(key , "true" , 60*20);
        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{
    public void sendByDynamic(Long uid, String id) throws UserCloudException {
        sendCircleByDynamic(uid, id, UserCloudSendRecord.SEND_WAY_MANUAL);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void autoSendByDynamic(Long uid, String id) {
@@ -401,17 +395,16 @@
            if (cloudManage.getOfficial() != null)
                official = cloudManage.getOfficial();
        }
        if (!official)
            return;
        try {
            sendCircleByDynamic(uid, id, UserCloudSendRecord.SEND_WAY_AUTO);
        } catch (UserCloudException e) {
            LogHelper.cloudInfo("autoSendByDynamic - [uid:" +uid + " 动态id:"+  id +  "]原因:"+ e.getMsg());
            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);
@@ -421,7 +414,7 @@
        if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
            throw new UserCloudException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
        }
        String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
        if (StringUtil.isNullOrEmpty(inviteCode))
            throw new UserCloudException(3, "邀请码未激活");
@@ -434,8 +427,7 @@
        if (StringUtil.isNullOrEmpty(relationId))
            throw new UserCloudException(2, "淘宝未授权,请前往\"我的\"绑定淘宝账号");
        // 验证是否开通
        UserCloud userCloud = userCloudMapper.getValidByUid(uid);
        if (userCloud == null)
@@ -446,9 +438,9 @@
            throw new UserCloudException(1002, "云发单机器人不存在");
        String wxId = userCloud.getWxId();
        if (StringUtil.isNullOrEmpty(wxId))
        if (StringUtil.isNullOrEmpty(wxId))
            throw new UserCloudException(1003, "微信号不存在,请先微信登录");
        // 验证开启状态
        List<UserCloudGroup> listGroup = userCloudGroupService.listByUid(uid);
        if (listGroup == null || listGroup.size() == 0)
@@ -462,8 +454,7 @@
        }
        if (listOpen.size() == 0)
            throw new UserCloudException(1005, "请先开启云发单群功能");
        // 验证发圈是否可行
        GoodsEvaluate evaluate = goodsEvaluateService.getById(id);
        if (evaluate == null || evaluate.getState() == 0)
@@ -481,11 +472,10 @@
        if (!AitaokerApiUtil.onlineCheck(robotId)) {
            // 通知登录微信
            offlineNotification(uid);
            throw new UserCloudException(1003, "微信已掉线,需要重新扫描二维码登录");
        }
        boolean hasToken = false;
        List<String> listComment = new ArrayList<>();
        for (CommentInfo commentInfo : comments) {
@@ -517,17 +507,16 @@
                }
                comment = comment.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n");
            }
            listComment.add(comment);
        }
        if (!hasToken)
            throw new UserCloudException(1, "该内容包含可转链口令或链接");
        ImgInfo imgVideo = null;
        List<String> listImg = new ArrayList<>();
        List<ImgInfo> imgs = evaluate.getImgList();
        if (imgs != null && imgs.size() > 0) {
            for (ImgInfo imgInfo : imgs) {
@@ -538,8 +527,7 @@
                listImg.add(imgInfo.getUrl());
            }
        }
        // 保存发送记录
        UserCloudSendRecord sendRecord = new UserCloudSendRecord();
        sendRecord.setUid(uid);
@@ -551,45 +539,48 @@
        sendRecord.setSendOrigin(UserCloudSendRecord.ORIGIN_EVALUATE);
        UserCloudSendRecord result = userCloudSendRecordService.save(sendRecord);
        String pid = result.getId();
        for (UserCloudGroup cloudGroup: listOpen) {
        for (UserCloudGroup cloudGroup : listOpen) {
            String title = evaluate.getTitle();
            UserCloudSendContent sendContent = new UserCloudSendContent();
            sendContent.setPid(pid);
            sendContent.setUid(uid);
            sendContent.setGroupId(cloudGroup.getGroupId());
            sendContent.setCreateTime(new Date());
            if(cloudGroup.getType() == UserCloudGroup.TYPE_CIRCLE) { // 朋友圈
            if (cloudGroup.getType() == UserCloudGroup.TYPE_CIRCLE) { // 朋友圈
                String circleId = null;
                sendContent.setType(UserCloudSendContent.TYPE_CIRCLE);
                if (imgVideo == null) {
                    // 发送图文
                    String picUrl = "";
                    if (listImg.size() > 0) {
                        for (String img: listImg) {
                            picUrl +=  TbImgUtil.getTBSize220Img(img) + ";" ;
                        for (String img : listImg) {
                            picUrl += img + ";";
                        }
                        if (picUrl.endsWith(";"))
                            picUrl = picUrl.substring(0, picUrl.length()-1);
                        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());
                    sendContent.setVideoUrl(imgVideo.getVideoUrl());
                    circleId = AitaokerApiUtil.macsendCircleVideo(robotId, imgVideo.getVideoUrl(), imgVideo.getUrl());
                }
                // 评论文本
                if (!StringUtil.isNullOrEmpty(circleId)) {
                    sendContent.setState(true);
                    List<String> list = new ArrayList<>();
                    for (String comment: listComment) {
                    for (String comment : listComment) {
                        boolean macsend = AitaokerApiUtil.macsendCircleComment(robotId, wxId, circleId, comment);
                        if (macsend) {
                            list.add(comment);
@@ -599,36 +590,37 @@
                }
            } else { // 群
                sendContent.setType(UserCloudSendContent.TYPE_GROUP);
                // 发送文本
                if (!StringUtil.isNullOrEmpty(title)) {
                    boolean macsend = AitaokerApiUtil.macsendText(robotId, cloudGroup.getGroupId(), title);
                    if (macsend)
                        sendContent.setTitle(title);
                }
                // 发送图片
                int num = 1;
                String picNum = configService.get(ConfigKeyEnum.robotCloudGroupPictureNum.getKey());
                if (!StringUtil.isNullOrEmpty(picNum)) {
                    num = Integer.parseInt(picNum);
                }
                if (listImg.size() > 0)
                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);
                            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<>();
                for (String comment: listComment) {
                for (String comment : listComment) {
                    boolean macsend = AitaokerApiUtil.macsendText(robotId, cloudGroup.getGroupId(), comment);
                    if (macsend) {
                        list.add(comment);
@@ -640,12 +632,11 @@
            userCloudSendContentService.save(sendContent);
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void sendCustomGoods(Long uid, Long goodsId, Integer goodsType, Long sellerId) throws UserCloudException{
        sendCircleByGoods(uid, goodsId, goodsType, null, sellerId,  UserCloudSendRecord.SEND_WAY_MANUAL);
    public void sendCustomGoods(Long uid, Long goodsId, Integer goodsType, Long sellerId) throws UserCloudException {
        sendCircleByGoods(uid, goodsId, goodsType, null, sellerId, UserCloudSendRecord.SEND_WAY_MANUAL);
    }
    @Override
@@ -657,29 +648,30 @@
            if (cloudManage.getCustom() != null)
                custom = cloudManage.getCustom();
        }
        if (!custom) {
            return;
        }
        UserCloudGoods cloudGoods = userCloudGoodsService.selectByPrimaryKey(id);
        if (cloudGoods == null) {
            return;
        }
        CommonGoods cgoods = cloudGoods.getCommonGoods();
        if (cgoods == null)
        if (cgoods == null)
            return;
        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());
            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)
@@ -688,7 +680,7 @@
        if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
            throw new UserCloudException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
        }
        String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
        if (StringUtil.isNullOrEmpty(inviteCode))
            throw new UserCloudException(3, "邀请码未激活");
@@ -707,19 +699,19 @@
        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();
                    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, "加入云发单备选库失败");
            }
        }
        // 自选库商品是否打开
        boolean custom = false;
        UserCloudManage cloudManage = userCloudManageService.selectByPrimaryKey(uid);
@@ -730,15 +722,15 @@
        if (!custom) {
            return;
        }
        Integer robotId = userCloud.getRobotId();
        if (robotId == null)
            throw new UserCloudException(1, "云发单机器人不存在");
        String wxId = userCloud.getWxId();
        if (StringUtil.isNullOrEmpty(wxId))
        if (StringUtil.isNullOrEmpty(wxId))
            throw new UserCloudException(1002, "请先登录微信");
        // 验证开启状态
        List<UserCloudGroup> listGroup = userCloudGroupService.listByUid(uid);
        if (listGroup == null || listGroup.size() == 0)
@@ -750,19 +742,18 @@
                listOpen.add(cloudGrou);
            }
        }
        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);
@@ -779,7 +770,7 @@
            sendRecord.setSendWay(UserCloudSendRecord.SEND_WAY_MANUAL);
        }
        UserCloudSendRecord result = userCloudSendRecordService.save(sendRecord);
        try {
            if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
                sendTaoBaoGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
@@ -801,9 +792,9 @@
                record.setUpdateTime(new Date());
                userCloudGoodsService.updateByPrimaryKeySelective(record);
            }
        } catch (UserCloudException e) {
            LogHelper.cloudInfo("autoSendCustomGoods - [uid:" +uid + " 库id:"+  storeId +  "]原因:"+ e.getMsg());
            LogHelper.cloudInfo("autoSendCustomGoods - [uid:" + uid + " 库id:" + storeId + "]原因:" + e.getMsg());
            // 更新发单记录
            if (storeId != null) {
                UserCloudGoods record = new UserCloudGoods();
@@ -814,13 +805,12 @@
                userCloudGoodsService.updateByPrimaryKeySelective(record);
            }
        }
    }
    /**
     * 淘宝商品信息处理
     *
     * @param user
     * @param inviteCode
     * @param robotId
@@ -830,7 +820,7 @@
     * @param listOpen
     * @throws UserCloudException
     */
    private void sendTaoBaoGoods(UserInfo user, int robotId, String wxId, Long goodsId, String relationId,
    private void sendTaoBaoGoods(UserInfo user, int robotId, String wxId, Long goodsId, String relationId,
            List<UserCloudGroup> listOpen, String pid) throws UserCloudException {
        TaoBaoLink taoBaoLink = null;
        try {
@@ -841,13 +831,13 @@
        }
        if (taoBaoLink == null)
            throw new UserCloudException(1, "该商品已下架");
        TaoBaoGoodsBrief goods = taoBaoLink.getGoods();
        boolean coupon = false;
        if (!StringUtil.isNullOrEmpty(goods.getCouponInfo())) {
            coupon = true;
        }
        String quanPrice = "";
        String description = "";
        String couponAmount = "";
@@ -857,21 +847,21 @@
            couponAmount = MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString();
        }
        String sales = TaoBaoUtil.getSaleCount(goods.getBiz30day());
        // 获取推荐语
        String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getTitle(), sales,
        String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getTitle(), sales,
                couponAmount, description);
        // 获取评论语
        String commentText = shareGoodsTextTemplateService.getCommentTextByTaoToken(coupon, taoBaoLink.getTaoToken(),
                goods.getZkPrice().toString(), quanPrice);
        // 云发单
        sendGoods(robotId, wxId, listOpen, recommendText, commentText,  goods.getImgList(), user.getId(), pid);
        sendGoods(robotId, wxId, listOpen, recommendText, commentText, goods.getImgList(), user.getId(), pid);
    }
    /**
     * 京东商品云发单
     *
     * @param user
     * @param robotId
     * @param wxId
@@ -880,39 +870,39 @@
     * @param listOpen
     * @throws UserCloudException
     */
    private void sendJDGoods(UserInfo user, int robotId, String wxId, Long goodsId, String relationId,
    private void sendJDGoods(UserInfo user, int robotId, String wxId, Long goodsId, String relationId,
            List<UserCloudGroup> listOpen, String pid) throws UserCloudException {
        JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
        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) {
            coupon = true;
        }
        String quanPrice = "";
        String couponAmount = "";
        if (coupon) {
            quanPrice = BigDecimalUtil.getWithNoZera(JDUtil.getQuanPrice(jdGoods)).toString() + "";
            couponAmount = BigDecimalUtil.getWithNoZera(couponInfo.getDiscount()).toString();
        }
        String sales = JDUtil.getSaleCount(jdGoods.getInOrderCount30Days());
        // 获取推荐语
        String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, jdGoods.getSkuName(), sales,
        String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, jdGoods.getSkuName(), sales,
                couponAmount, null);
        // 获取评论语
        BigDecimal price = jdGoods.getPrice();
        JDPingouInfo pinGouInfo = jdGoods.getPinGouInfo();
@@ -920,15 +910,16 @@
            price = pinGouInfo.getPingouPrice();
        }
        String zkPrice = BigDecimalUtil.getWithNoZera(price).toString();
        String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, zkPrice, quanPrice,
        String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, zkPrice, quanPrice,
                ConfigKeyEnum.quickShareJDCommentText);
        // 云发单
        sendGoods(robotId, wxId, listOpen, recommendText, commentText,  jdGoods.getImageList(), user.getId(), pid);
        sendGoods(robotId, wxId, listOpen, recommendText, commentText, jdGoods.getImageList(), user.getId(), pid);
    }
    /**
     * 京东商品云发单
     *
     * @param user
     * @param robotId
     * @param wxId
@@ -937,19 +928,19 @@
     * @param listOpen
     * @throws UserCloudException
     */
    private void sendPDDGoods(UserInfo user, int robotId, String wxId, Long goodsId, String relationId,
    private void sendPDDGoods(UserInfo user, int robotId, String wxId, Long goodsId, String relationId,
            List<UserCloudGroup> listOpen, String pid) throws UserCloudException {
        PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
        if (goods == null)
            throw new UserCloudException(1, "该商品已下架");
        String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsId, PinDuoDuoApiUtil.PID_SHARE + "", user.getId() + "");
        boolean coupon = true;
        if (goods.getHasCoupon() == null || !goods.getHasCoupon()) {
            coupon = false;
        }
        String quanPrice = "";
        String couponAmount = "";
        if (coupon) {
@@ -958,33 +949,34 @@
            quanPrice = BigDecimalUtil.getWithNoZera(amount).toString();
            couponAmount = BigDecimalUtil.getWithNoZera(PinDuoDuoUtil.getQuanPrice(goods)).toString();
        }
        String sales = goods.getSalesTip();
        if (StringUtil.isNullOrEmpty(sales)) {
            sales = "0";
        }
        // 获取推荐语
        String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getGoodsName(), sales,
        String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getGoodsName(), sales,
                couponAmount, null);
        // 获取评论语
        String zkPrice =  MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100)).setScale(2).toString();
        String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, zkPrice, quanPrice,
        String zkPrice = MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100))
                .setScale(2).toString();
        String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, zkPrice, quanPrice,
                ConfigKeyEnum.quickSharePDDCommentText);
        List<String> list = null;
        String[] goodsGalleryUrls = goods.getGoodsGalleryUrls();
        if (goodsGalleryUrls != null && goodsGalleryUrls.length > 0) {
            list = Arrays.asList(goodsGalleryUrls);
        }
        // 云发单
        sendGoods(robotId, wxId, listOpen, recommendText, commentText, list, user.getId(), pid );
        sendGoods(robotId, wxId, listOpen, recommendText, commentText, list, user.getId(), pid);
    }
    /**
     * 唯品会商品
     *
     * @param user
     * @param robotId
     * @param wxId
@@ -994,15 +986,16 @@
     * @param pid
     * @throws UserCloudException
     */
    private void sendVIPGoods(UserInfo user, int robotId, String wxId, Long goodsId, String relationId,
    private void sendVIPGoods(UserInfo user, int robotId, String wxId, Long goodsId, String relationId,
            List<UserCloudGroup> listOpen, String pid) throws UserCloudException {
        VIPGoodsInfo goods = VipShopApiUtil.getGoodsDetail(goodsId + "");
        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;
        String quanPrice = "";
        String couponAmount = "";
@@ -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,46 +1022,44 @@
     * @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 {
        SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(goodsId +"", sellerId +"");
    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 +""),
        String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(sellerId + "", goodsId + ""),
                StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, SuningApiUtil.PID_SHARE, user.getId() + "");
        boolean coupon = false;
        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 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()) {
            imgList.add(img.getPicUrl());
        }
        // 云发单
        sendGoods(robotId, wxId, listOpen, recommendText, commentText, imgList, user.getId(), pid);
    }
    /**
     * 发送商品
     *
     * @param robotId
     * @param title
     * @param comment
@@ -1075,32 +1067,33 @@
     * @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) {
        for (UserCloudGroup cloudGroup : listOpen) {
            UserCloudSendContent sendContent = new UserCloudSendContent();
            sendContent.setPid(pid);
            sendContent.setUid(uid);
            sendContent.setGroupId(cloudGroup.getGroupId());
            sendContent.setCreateTime(new Date());
            if(cloudGroup.getType() == UserCloudGroup.TYPE_CIRCLE) { // 朋友圈
            if (cloudGroup.getType() == UserCloudGroup.TYPE_CIRCLE) { // 朋友圈
                sendContent.setType(UserCloudSendContent.TYPE_CIRCLE);
                String picUrl = "";
                if (listImg.size() > 0) {
                    for (String img: listImg) {
                        picUrl +=  TbImgUtil.getTBSize220Img(img) + ";" ;
                    for (String img : listImg) {
                        picUrl += TbImgUtil.getTBSize220Img(img) + ";";
                    }
                    if (picUrl.endsWith(";"))
                        picUrl = picUrl.substring(0, picUrl.length() - 1);
                }
                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);
@@ -1119,27 +1112,27 @@
                    if (macsend)
                        sendContent.setTitle(title);
                }
                // 发送图片
                int num = 1;
                String picNum = configService.get(ConfigKeyEnum.robotCloudGroupPictureNum.getKey());
                if (!StringUtil.isNullOrEmpty(picNum)) {
                    num = Integer.parseInt(picNum);
                }
                if (listImg.size() > 0)
                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);
                            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);
@@ -1153,22 +1146,21 @@
        }
    }
    @Override
    public void fixedTimeSend(List<GoodsEvaluate> listActivity, List<GoodsEvaluate> listGoods) {
        if (listGoods == null && listActivity == null)
        if (listGoods == null && listActivity == null)
            return;
        // 一个小时之前
        Date lastTime = new Date(java.lang.System.currentTimeMillis() - 1000 * 60 * 60);
        for (int i = 0; i < 1000; i ++) {
        for (int i = 0; i < 1000; i++) {
            // 查询哪些用户开通
            List<Long> listUser = userCloudMapper.listValidUid(i*1000, 1000);
            List<Long> listUser = userCloudMapper.listValidUid(i * 1000, 1000);
            if (listUser == null || listUser.size() == 0) {
                break;
            }
            // 遍历用户
            for (Long uid: listUser) {
            for (Long uid : listUser) {
                try {// 判断是否开通官方采集
                    UserCloudManage cloudManage = userCloudManageService.selectByPrimaryKey(uid);
                    if (cloudManage == null || cloudManage.getOfficial() == null || !cloudManage.getOfficial()) {
@@ -1178,34 +1170,37 @@
                    UserCloudSendRecord last = userCloudSendRecordService.getLastByUid(uid, lastTime);
                    if (last != null)
                        continue;
                    String evaluateId = null;
                    // 活动
                    if (listActivity != null && listActivity.size() > 0) {
                        for (GoodsEvaluate evaluate: listActivity) {
                            UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid, evaluate.getId());
                            if (record != null)
                        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)
                        for (GoodsEvaluate evaluate : listGoods) {
                            UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid,
                                    evaluate.getId());
                            if (record != null)
                                continue;
                            evaluateId = evaluate.getId();
                            break;
                        }
                    }
                    if(!StringUtil.isNullOrEmpty(evaluateId)) {
                    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) {
@@ -1214,42 +1209,42 @@
            }
        }
    }
    private void offlineNotification(Long uid) {
        UserCloudManage cloudManage = userCloudManageService.selectForUpdate(uid);
        if (cloudManage == null) {
             return;
            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) {
        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) {
@@ -1257,21 +1252,21 @@
        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);
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/util/aitaoker/AitaokerApiUtil.java
@@ -411,7 +411,7 @@
        map.put("pic_url", picUrl);
        map.put("content", content);
        // 请求结果
        String result = baseRequest("itaoke.robot.macsend.circle", map);
        String result = baseRequest("itaoke.robot.circle.send", map);
        JSONObject resultJson = JSONObject.fromObject(result);
        if ("0000".equals(resultJson.optString("status"))) {
            resultJson = resultJson.optJSONObject("data");
@@ -425,6 +425,26 @@
        return null;
    }
    
    /**
     * 发朋友圈
     * @param robotId
     * @param content
     * @param picUrl 图片url,多个请用;分隔
     * @return
     */
    public static String macsendUpload(int robotId, String picUrl) {
        Map<String, String> map = new HashMap<>();
        map.put("robot_id", robotId +"");
        map.put("pic_url", picUrl);
        map.put("type", "2");
        String result = baseRequest("itaoke.robot.circle.upload", map);
        JSONObject resultJson = JSONObject.fromObject(result);
        if ("0000".equals(resultJson.optString("status"))) {
            return resultJson.optString("data");
        }
        return null;
    }
    
    /**
     * 朋友圈发送视频