|
@@ -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;
|
|
@@ -77,7 +70,7 @@ public class WeComHistoryDataJob {
|
|
|
private CorpMapper corpMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private RedisTemplate<String, Object> redisTemplate;
|
|
|
+ private MessageAttachmentMapper messageAttachmentMapper;
|
|
|
|
|
|
|
|
|
@XxlJob("saveHistoryMessageJob")
|
|
@@ -113,14 +106,12 @@ public class WeComHistoryDataJob {
|
|
|
}
|
|
|
for (Corp corp : corps) {
|
|
|
for (; startTime < endTime; startTime += TimeConstant.DAY) {
|
|
|
- selectGroupMsgList(startTime, Math.min(startTime + TimeConstant.DAY, endTime), corp.getId());
|
|
|
+ selectGroupMsgList(startTime, Math.min(startTime + TimeConstant.DAY, endTime), corp.getId(), xxlJobParam.getStaffId());
|
|
|
}
|
|
|
}
|
|
|
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;
|
|
|
}
|
|
|
|
|
@@ -165,8 +156,8 @@ public class WeComHistoryDataJob {
|
|
|
LarkRobotUtil.sendMessage(stringBuilder.toString());
|
|
|
}
|
|
|
|
|
|
- private void selectGroupMsgList(Long startTime, Long endTime, Long corpId) {
|
|
|
- delHistoryMessageList(startTime, endTime);
|
|
|
+ private void selectGroupMsgList(Long startTime, Long endTime, Long corpId, Long staffId) {
|
|
|
+ delHistoryMessageList(startTime, endTime, corpId, staffId);
|
|
|
try {
|
|
|
String cursor = "";
|
|
|
do {
|
|
@@ -218,24 +209,33 @@ 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);
|
|
|
+ //指定id以后 过滤其他id
|
|
|
+ if (staffId != null) {
|
|
|
+ if (!Objects.equals(staffList.get(0).getId(), staffId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<ExternalUser> externalUsers = selectGroupMsgSendResult(msgId, carrierId, corpId);
|
|
|
if (CollectionUtils.isEmpty(externalUsers)) {
|
|
|
continue;
|
|
|
}
|
|
|
- insertHistoryMessageList(staffList.get(0), externalUsers, miniprogramRecordList, createTime, corpId);
|
|
|
- messageAttachmentService.addMiniProgram(messageAttachmentList);
|
|
|
+ messageAttachmentService.addMiniProgram(messageAttachmentList, createTime);
|
|
|
+ insertHistoryMessageList(staffList.get(0), externalUsers, miniprogramRecordList, createTime, corpId, startTime, endTime);
|
|
|
+ for (MessageAttachment messageAttachment : messageAttachmentList) {
|
|
|
+ messageAttachment.setStaffId(staffList.get(0).getId());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
String nextCursor = jsonObject.getString("next_cursor");
|
|
@@ -250,16 +250,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 +282,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);
|
|
@@ -336,26 +336,38 @@ public class WeComHistoryDataJob {
|
|
|
return httpPoolClient.post(url, param.toJSONString());
|
|
|
}
|
|
|
|
|
|
- private void delHistoryMessageList(Long startTime, Long endTime) {
|
|
|
+ private void delHistoryMessageList(Long startTime, Long endTime, Long corpId, Long staffId) {
|
|
|
HistoryMessage historyMessage = new HistoryMessage();
|
|
|
historyMessage.setIsDelete(1);
|
|
|
HistoryMessageExample example = new HistoryMessageExample();
|
|
|
- example.createCriteria().andSendTimeBetween(new Date(startTime * 1000), new Date(endTime * 1000));
|
|
|
+ HistoryMessageExample.Criteria criteria =
|
|
|
+ example.createCriteria().andSendTimeBetween(new Date(startTime * 1000), new Date(endTime * 1000))
|
|
|
+ .andCorpIdEqualTo(corpId);
|
|
|
+ if (staffId != null) {
|
|
|
+ criteria.andStaffIdEqualTo(staffId);
|
|
|
+ }
|
|
|
historyMessageMapper.updateByExampleSelective(historyMessage, example);
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void insertHistoryMessageList(Staff staff, List<ExternalUser> externalUsers, List<MiniprogramRecord> miniprogramRecordList, Long createTime, Long corpId) {
|
|
|
+ private void insertHistoryMessageList(Staff staff, List<ExternalUser> externalUsers,
|
|
|
+ List<MiniprogramRecord> miniprogramRecordList,
|
|
|
+ Long createTime, Long corpId, Long startTime, Long endTime) {
|
|
|
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())
|
|
|
+ .andSendTimeBetween(new Date(startTime * 1000), new Date(endTime * 1000));
|
|
|
+ List<MessageAttachment> messageAttachments = messageAttachmentMapper.selectByExample(example);
|
|
|
+ if (CollectionUtils.isEmpty(messageAttachments)) {
|
|
|
LarkRobotUtil.sendMessage("获取保底set失败");
|
|
|
return;
|
|
|
}
|
|
|
- Long sendTime = externalUsers.stream().map(ExternalUser::getSendTime).filter(Objects::nonNull).findFirst().orElse(null);
|
|
|
+ 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) {
|
|
|
Long userId = userMapper.selectIdByExternalUserId(externalUser.getExternalUserId());
|