|
@@ -5,18 +5,13 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.tzld.piaoquan.wecom.common.constant.TimeConstant;
|
|
|
import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
|
|
|
-import com.tzld.piaoquan.wecom.common.enums.SourceEnum;
|
|
|
import com.tzld.piaoquan.wecom.component.HttpPoolClient;
|
|
|
-import com.tzld.piaoquan.wecom.dao.mapper.HistoryMessageMapper;
|
|
|
-import com.tzld.piaoquan.wecom.dao.mapper.StaffMapper;
|
|
|
-import com.tzld.piaoquan.wecom.dao.mapper.CorpMapper;
|
|
|
-import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
|
|
|
+import com.tzld.piaoquan.wecom.dao.mapper.*;
|
|
|
import com.tzld.piaoquan.wecom.model.bo.ExternalUser;
|
|
|
import com.tzld.piaoquan.wecom.model.bo.MiniprogramRecord;
|
|
|
import com.tzld.piaoquan.wecom.model.bo.SendDetail;
|
|
|
import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
|
|
|
import com.tzld.piaoquan.wecom.model.po.*;
|
|
|
-import com.tzld.piaoquan.wecom.model.vo.GuaranteedParam;
|
|
|
import com.tzld.piaoquan.wecom.service.AccessTokenService;
|
|
|
import com.tzld.piaoquan.wecom.service.HistoryMessageService;
|
|
|
import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
|
|
@@ -39,8 +34,6 @@ import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.MAX_VIDEO_NUM;
|
|
|
-import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_KEY;
|
|
|
-import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_SET_KEY;
|
|
|
import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.*;
|
|
|
import static com.tzld.piaoquan.wecom.common.enums.SourceEnum.HISTORICAL_TOP;
|
|
|
import static com.tzld.piaoquan.wecom.common.enums.SourceEnum.MANUAL;
|
|
@@ -79,6 +72,9 @@ public class WeComHistoryDataJob {
|
|
|
@Autowired
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MessageAttachmentMapper messageAttachmentMapper;
|
|
|
+
|
|
|
|
|
|
@XxlJob("saveHistoryMessageJob")
|
|
|
public ReturnT<String> selectHistoryMessageByDay(String param) {
|
|
@@ -119,8 +115,6 @@ public class WeComHistoryDataJob {
|
|
|
for (Corp corp : corps) {
|
|
|
selectAlertHistoryMessage(xxlJobParam.getStartTime(), xxlJobParam.getEndTime(), corp.getId(), corp.getName());
|
|
|
}
|
|
|
- String key = String.format(GUARANTEED_MINI_PROGRAM_SET_KEY, DateUtil.getThatDayDateString());
|
|
|
- redisTemplate.delete(key);
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -218,19 +212,19 @@ public class WeComHistoryDataJob {
|
|
|
messageAttachment.setType(MessageAttachmentTypeEnum.MINI_PROGRAM.getType());
|
|
|
messageAttachmentList.add(messageAttachment);
|
|
|
}
|
|
|
- List<String> userIdList = selectGroupMsgTask(msgId, corpId);
|
|
|
- if (CollectionUtils.isEmpty(userIdList)) {
|
|
|
+ List<String> carrierIdList = selectGroupMsgTask(msgId, corpId);
|
|
|
+ if (CollectionUtils.isEmpty(carrierIdList)) {
|
|
|
continue;
|
|
|
}
|
|
|
- for (String userId : userIdList) {
|
|
|
+ for (String carrierId : carrierIdList) {
|
|
|
StaffExample example = new StaffExample();
|
|
|
- example.createCriteria().andCarrierIdEqualTo(userId);
|
|
|
+ example.createCriteria().andCarrierIdEqualTo(carrierId);
|
|
|
List<Staff> staffList = staffMapper.selectByExample(example);
|
|
|
if (CollectionUtils.isEmpty(staffList)) {
|
|
|
- LarkRobotUtil.sendMessage("企微推送报警:userId不存在请检查 " + userId);
|
|
|
+ LarkRobotUtil.sendMessage("企微推送报警:carrierId不存在请检查 " + carrierId);
|
|
|
continue;
|
|
|
}
|
|
|
- List<ExternalUser> externalUsers = selectGroupMsgSendResult(msgId, userId, corpId);
|
|
|
+ List<ExternalUser> externalUsers = selectGroupMsgSendResult(msgId, carrierId, corpId);
|
|
|
if (CollectionUtils.isEmpty(externalUsers)) {
|
|
|
continue;
|
|
|
}
|
|
@@ -250,16 +244,16 @@ public class WeComHistoryDataJob {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<ExternalUser> selectGroupMsgSendResult(String msgId, String userId, Long corpId) throws IOException {
|
|
|
+ private List<ExternalUser> selectGroupMsgSendResult(String msgId, String carrierId, Long corpId) throws IOException {
|
|
|
List<ExternalUser> resList = new ArrayList<>();
|
|
|
String cursor = "";
|
|
|
do {
|
|
|
- String res = getGroupMsgSendResult(msgId, userId, cursor, corpId);
|
|
|
+ String res = getGroupMsgSendResult(msgId, carrierId, cursor, corpId);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
Integer errCode = jsonObject.getInteger("errcode");
|
|
|
if (errCode != 0) {
|
|
|
String errmsg = jsonObject.getString("errmsg");
|
|
|
- log.error("selectGroupMsgSendResult error msgId={} userId={} errCode={} errmsg={}", msgId, userId, errCode, errmsg);
|
|
|
+ log.error("selectGroupMsgSendResult error msgId={} carrierId={} errCode={} errmsg={}", msgId, carrierId, errCode, errmsg);
|
|
|
return resList;
|
|
|
}
|
|
|
JSONArray sendList = jsonObject.getJSONArray("send_list");
|
|
@@ -282,13 +276,13 @@ public class WeComHistoryDataJob {
|
|
|
return resList;
|
|
|
}
|
|
|
|
|
|
- private String getGroupMsgSendResult(String msgId, String userId, String cursor, Long corpId) throws IOException {
|
|
|
+ private String getGroupMsgSendResult(String msgId, String carrierId, String cursor, Long corpId) throws IOException {
|
|
|
String accessToken = accessTokenService.getWeComAccessToken(corpId);
|
|
|
String url = POST_WE_COM_GROUP_MSG_SEND_RESULT
|
|
|
+ "?access_token=" + accessToken;
|
|
|
JSONObject param = new JSONObject();
|
|
|
param.put("msgid", msgId);
|
|
|
- param.put("userid", userId);
|
|
|
+ param.put("userid", carrierId);
|
|
|
param.put("limit", 1000);
|
|
|
if (StringUtils.isNotEmpty(cursor)) {
|
|
|
param.put("cursor", cursor);
|
|
@@ -349,12 +343,14 @@ public class WeComHistoryDataJob {
|
|
|
if (CollectionUtils.isEmpty(externalUsers) || CollectionUtils.isEmpty(miniprogramRecordList)) {
|
|
|
return;
|
|
|
}
|
|
|
- String key = String.format(GUARANTEED_MINI_PROGRAM_SET_KEY, DateUtil.getThatDayDateString());
|
|
|
- Set<Long> guaranteedSet = (Set<Long>) redisTemplate.opsForValue().get(key);
|
|
|
- if (CollectionUtils.isEmpty(guaranteedSet)) {
|
|
|
+ MessageAttachmentExample example = new MessageAttachmentExample();
|
|
|
+ example.createCriteria().andStaffIdEqualTo(staff.getId()).andSendTimeGreaterThan(DateUtil.getThatDayDate());
|
|
|
+ List<MessageAttachment> messageAttachments = messageAttachmentMapper.selectByExample(example);
|
|
|
+ if(CollectionUtils.isEmpty(messageAttachments)){
|
|
|
LarkRobotUtil.sendMessage("获取保底set失败");
|
|
|
return;
|
|
|
}
|
|
|
+ Set<Long> guaranteedSet = messageAttachments.stream().map(MessageAttachment::getMiniprogramVideoId).collect(Collectors.toSet());
|
|
|
Long sendTime = externalUsers.stream().map(ExternalUser::getSendTime).filter(Objects::nonNull).findFirst().orElse(null);
|
|
|
List<HistoryMessage> historyMessageList = new ArrayList<>();
|
|
|
for (ExternalUser externalUser : externalUsers) {
|