From 20bb4f95184453d4addfd27e40a78f3c63bcf6c3 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期四, 11 六月 2020 18:15:53 +0800 Subject: [PATCH] 用户统计 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java | 130 ++++++++++++++++++++++++++---------------- 1 files changed, 80 insertions(+), 50 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java index 7807105..0cfcf16 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java +++ b/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, "鏈哄櫒浜鸿繑鍥炴椂闂存牸寮忎笉姝g‘"); - } - - Integer robotId = dto.getId(); - if (robotId == null) { - LogHelper.cloudInfo("鏂规硶openCloud: [uid=" + uid + "][璁㈠崟ID=" + orderId + "]鏈哄櫒浜哄け璐ワ細 鏈哄櫒浜篒D杩斿洖涓虹┖"); - throw new UserCloudException(1, "鏈哄櫒浜篒D杩斿洖涓虹┖"); - } - - 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, "鏈哄櫒浜鸿繑鍥炴椂闂存牸寮忎笉姝g‘"); +// } +// +// Integer robotId = dto.getId(); +// if (robotId == null) { +// LogHelper.cloudInfo("鏂规硶openCloud: [uid=" + uid + "][璁㈠崟ID=" + orderId + "]鏈哄櫒浜哄け璐ワ細 鏈哄櫒浜篒D杩斿洖涓虹┖"); +// throw new UserCloudException(1, "鏈哄櫒浜篒D杩斿洖涓虹┖"); +// } +// +// 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); -- Gitblit v1.8.0