|
@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
|
|
import com.tzld.piaoquan.wecom.common.constant.TimeConstant;
|
|
import com.tzld.piaoquan.wecom.common.constant.TimeConstant;
|
|
import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
|
|
import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
|
|
import com.tzld.piaoquan.wecom.dao.mapper.HistoryMessageMapper;
|
|
import com.tzld.piaoquan.wecom.dao.mapper.HistoryMessageMapper;
|
|
-import com.tzld.piaoquan.wecom.dao.mapper.StaffWithUserMapper;
|
|
|
|
import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
|
|
import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
|
|
import com.tzld.piaoquan.wecom.model.bo.MiniprogramRecord;
|
|
import com.tzld.piaoquan.wecom.model.bo.MiniprogramRecord;
|
|
import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
|
|
import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
|
|
@@ -13,10 +12,7 @@ import com.tzld.piaoquan.wecom.model.po.*;
|
|
import com.tzld.piaoquan.wecom.service.AccessTokenService;
|
|
import com.tzld.piaoquan.wecom.service.AccessTokenService;
|
|
import com.tzld.piaoquan.wecom.service.HistoryMessageService;
|
|
import com.tzld.piaoquan.wecom.service.HistoryMessageService;
|
|
import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
|
|
import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
|
|
-import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
|
|
|
|
-import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
|
|
|
|
-import com.tzld.piaoquan.wecom.utils.LarkRobotUtil;
|
|
|
|
-import com.tzld.piaoquan.wecom.utils.MessageUtil;
|
|
|
|
|
|
+import com.tzld.piaoquan.wecom.utils.*;
|
|
import com.tzld.piaoquan.wecom.utils.page.Page;
|
|
import com.tzld.piaoquan.wecom.utils.page.Page;
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
@@ -31,8 +27,6 @@ import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.Map;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.GET_HISTORY_DATA_URL;
|
|
import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.GET_HISTORY_DATA_URL;
|
|
|
|
|
|
@@ -59,8 +53,6 @@ public class WeComHistoryDataJob {
|
|
@Autowired
|
|
@Autowired
|
|
private MessageAttachmentService messageAttachmentService;
|
|
private MessageAttachmentService messageAttachmentService;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private StaffWithUserMapper staffWithUserMapper;
|
|
|
|
|
|
|
|
@XxlJob("saveHistoryMessageJob")
|
|
@XxlJob("saveHistoryMessageJob")
|
|
public ReturnT<String> selectHistoryMessageByDay(String param) {
|
|
public ReturnT<String> selectHistoryMessageByDay(String param) {
|
|
@@ -116,7 +108,6 @@ public class WeComHistoryDataJob {
|
|
miniprogramRecord.setVideoId(videoId);
|
|
miniprogramRecord.setVideoId(videoId);
|
|
miniprogramRecord.setAttachmentIdx(j + 1);
|
|
miniprogramRecord.setAttachmentIdx(j + 1);
|
|
miniprogramRecordList.add(miniprogramRecord);
|
|
miniprogramRecordList.add(miniprogramRecord);
|
|
-
|
|
|
|
String cover = attachments.getJSONObject(j).getJSONObject("miniprogram").getString("cover");
|
|
String cover = attachments.getJSONObject(j).getJSONObject("miniprogram").getString("cover");
|
|
String appid = attachments.getJSONObject(j).getJSONObject("miniprogram").getString("appid");
|
|
String appid = attachments.getJSONObject(j).getJSONObject("miniprogram").getString("appid");
|
|
String title = attachments.getJSONObject(j).getJSONObject("miniprogram").getString("title");
|
|
String title = attachments.getJSONObject(j).getJSONObject("miniprogram").getString("title");
|
|
@@ -132,15 +123,6 @@ public class WeComHistoryDataJob {
|
|
JSONArray subMissionList = jsonArray.getJSONObject(i).getJSONArray("sub_mission_list");
|
|
JSONArray subMissionList = jsonArray.getJSONObject(i).getJSONArray("sub_mission_list");
|
|
for (int k = 0; k < subMissionList.size(); k++) {
|
|
for (int k = 0; k < subMissionList.size(); k++) {
|
|
if (!"sended".equals(subMissionList.getJSONObject(k).getString("status"))) {
|
|
if (!"sended".equals(subMissionList.getJSONObject(k).getString("status"))) {
|
|
- Integer id = jsonArray.getJSONObject(i).getInteger("id");
|
|
|
|
- JSONArray staffExtIdList = jsonArray.getJSONObject(i).getJSONArray("staff_id_list");
|
|
|
|
- List<Long> videoIds = messageAttachmentList.stream().map(MessageAttachment::getMiniprogramVideoId).collect(Collectors.toList());
|
|
|
|
- JSONObject error = new JSONObject();
|
|
|
|
- error.put("id", id);
|
|
|
|
- error.put("staff_id_list", staffExtIdList);
|
|
|
|
- error.put("videoIds", videoIds);
|
|
|
|
- error.put("status", subMissionList.getJSONObject(k).getString("status"));
|
|
|
|
- LarkRobotUtil.sendMessage(error.toJSONString());
|
|
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
List<String> externalUserList = subMissionList.getJSONObject(k).getJSONArray("external_user_list").toJavaList(String.class);
|
|
List<String> externalUserList = subMissionList.getJSONObject(k).getJSONArray("external_user_list").toJavaList(String.class);
|
|
@@ -210,6 +192,70 @@ public class WeComHistoryDataJob {
|
|
}
|
|
}
|
|
return ReturnT.SUCCESS;
|
|
return ReturnT.SUCCESS;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @XxlJob("sendMessageAlertJob")
|
|
|
|
+ public ReturnT<String> sendMessageAlert(String param) {
|
|
|
|
+ XxlJobParam xxlJobParam = new XxlJobParam();
|
|
|
|
+ if (StringUtils.isNotEmpty(param)) {
|
|
|
|
+ xxlJobParam = JSONObject.parseObject(param, XxlJobParam.class);
|
|
|
|
+ }
|
|
|
|
+ if (xxlJobParam.getStartTime() == null) {
|
|
|
|
+ xxlJobParam.setStartTime(TimeUtil.getTodayTimestamp() / 1000);
|
|
|
|
+ }
|
|
|
|
+ if (xxlJobParam.getEndTime() == null) {
|
|
|
|
+ xxlJobParam.setEndTime(System.currentTimeMillis() / 1000);
|
|
|
|
+ }
|
|
|
|
+ Long startTime = xxlJobParam.getStartTime();
|
|
|
|
+ Long endTime = xxlJobParam.getEndTime();
|
|
|
|
+ selectAlertHistoryMessage(startTime, endTime);
|
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void selectAlertHistoryMessage(Long startTime, Long endTime) {
|
|
|
|
+ try {
|
|
|
|
+ Integer total = getHistoryDataTotal(startTime, endTime);
|
|
|
|
+ if (total == null || total == 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ int page = total / size + 1;
|
|
|
|
+ for (int n = 0; n < page; n++) {
|
|
|
|
+ String res = getHistoryData(size, n * size, startTime, endTime);
|
|
|
|
+ log.info("selectAlertHistoryMessage size={}, n={}, startTime={}, endTime={}, res={}", size, n, startTime, endTime, res);
|
|
|
|
+ if (ObjectUtils.isEmpty(res)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("missions");
|
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
+ Date sendAt = jsonArray.getJSONObject(i).getDate("send_at");
|
|
|
|
+ JSONArray attachments = jsonArray.getJSONObject(i).getJSONObject("msg_data").getJSONArray("attachments");
|
|
|
|
+ List<Long> videoIds = new ArrayList<>();
|
|
|
|
+ for (int j = 0; j < attachments.size(); j++) {
|
|
|
|
+ String indexPage = attachments.getJSONObject(j).getJSONObject("miniprogram").getString("page");
|
|
|
|
+ Long videoId = MessageUtil.getVideoId(indexPage);
|
|
|
|
+ videoIds.add(videoId);
|
|
|
|
+ }
|
|
|
|
+ JSONArray subMissionList = jsonArray.getJSONObject(i).getJSONArray("sub_mission_list");
|
|
|
|
+ for (int k = 0; k < subMissionList.size(); k++) {
|
|
|
|
+ if (!"sended".equals(subMissionList.getJSONObject(k).getString("status"))) {
|
|
|
|
+ Integer id = jsonArray.getJSONObject(i).getInteger("id");
|
|
|
|
+ JSONArray staffExtIdList = jsonArray.getJSONObject(i).getJSONArray("staff_id_list");
|
|
|
|
+ JSONObject error = new JSONObject();
|
|
|
|
+ error.put("id", id);
|
|
|
|
+ error.put("sentAt", sendAt);
|
|
|
|
+ error.put("staff_id_list", staffExtIdList);
|
|
|
|
+ error.put("videoIds", videoIds);
|
|
|
|
+ error.put("status", subMissionList.getJSONObject(k).getString("status"));
|
|
|
|
+ LarkRobotUtil.sendMessage(error.toJSONString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.error("selectAlertHistoryMessage error", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|