|
|
@@ -1,22 +1,23 @@
|
|
|
package com.tzld.piaoquan.api.job.wecom.thirdpart;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
|
+import com.tzld.piaoquan.api.common.enums.wecom.ConfigTaskContentTypeEnum;
|
|
|
+import com.tzld.piaoquan.api.common.enums.wecom.MsgSendStatusEnum;
|
|
|
+import com.tzld.piaoquan.api.common.enums.wecom.ThirdPartWeComStaffStatusEnum;
|
|
|
import com.tzld.piaoquan.api.component.VideoApiService;
|
|
|
import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformPlanMapperExt;
|
|
|
import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComMsgMapper;
|
|
|
import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComRoomMapper;
|
|
|
-import com.tzld.piaoquan.api.model.param.wecom.thirdpart.CdnUploadImgLinkRequest;
|
|
|
-import com.tzld.piaoquan.api.model.param.wecom.thirdpart.CdnUploadImgLinkResponse;
|
|
|
-import com.tzld.piaoquan.api.model.param.wecom.thirdpart.SendAppMsgRequest;
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ext.ThirdPartWeComVideoMapperExt;
|
|
|
+import com.tzld.piaoquan.api.model.param.wecom.thirdpart.*;
|
|
|
import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo;
|
|
|
-import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComMsg;
|
|
|
-import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComMsgExample;
|
|
|
-import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoom;
|
|
|
-import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaff;
|
|
|
+import com.tzld.piaoquan.api.model.po.wecom.thirdpart.*;
|
|
|
import com.tzld.piaoquan.api.model.vo.contentplatform.WxVideoV2VO;
|
|
|
-import com.tzld.piaoquan.api.service.WeComThirdPartyService;
|
|
|
+import com.tzld.piaoquan.api.service.VideoMultiService;
|
|
|
+import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyAccountService;
|
|
|
+import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyRoomService;
|
|
|
+import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyService;
|
|
|
import com.tzld.piaoquan.api.util.CdnUtil;
|
|
|
import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketData;
|
|
|
import com.tzld.piaoquan.growth.common.model.po.Staff;
|
|
|
@@ -24,22 +25,22 @@ import com.tzld.piaoquan.growth.common.service.MessageAttachmentService;
|
|
|
import com.tzld.piaoquan.growth.common.utils.DateUtil;
|
|
|
import com.tzld.piaoquan.growth.common.utils.LarkRobotUtil;
|
|
|
import com.tzld.piaoquan.growth.common.utils.MessageUtil;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.RedisUtils;
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -49,30 +50,31 @@ public class WeComSendMsgJob {
|
|
|
@Autowired
|
|
|
WeComThirdPartyService weComThirdPartyService;
|
|
|
@Autowired
|
|
|
+ WeComThirdPartyAccountService weComThirdPartyAccountService;
|
|
|
+ @Autowired
|
|
|
+ WeComThirdPartyRoomService weComThirdPartyRoomService;
|
|
|
+ @Autowired
|
|
|
MessageAttachmentService messageAttachmentService;
|
|
|
@Autowired
|
|
|
VideoApiService videoApiService;
|
|
|
@Autowired
|
|
|
ContentPlatformPlanMapperExt planMapperExt;
|
|
|
@Autowired
|
|
|
+ ThirdPartWeComVideoMapperExt videoMapperExt;
|
|
|
+ @Autowired
|
|
|
ThirdPartWeComRoomMapper roomMapper;
|
|
|
@Autowired
|
|
|
ThirdPartWeComMsgMapper msgMapper;
|
|
|
+ @Autowired
|
|
|
+ private VideoMultiService videoMultiService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisUtils redisUtils;
|
|
|
|
|
|
- @Value("${send.room.msg.video.min.score:3}")
|
|
|
+ @Value("${send.room.msg.video.min.score:1}")
|
|
|
private Double videoMinScore;
|
|
|
- @Value("${send.room.msg.duplicate.days:7}")
|
|
|
+ @Value("${send.room.msg.duplicate.days:30}")
|
|
|
private Integer duplicateDays;
|
|
|
- @Value("${send.room.msg.video.num:2}")
|
|
|
- private Integer videoNum;
|
|
|
- @ApolloJsonValue("${send.room.msg.test.roomList:[]}")
|
|
|
- private List<String> testRoomList;
|
|
|
- @ApolloJsonValue("${send.room.msg.video.source.staff.config:{}}")
|
|
|
- private Map<Long, JSONObject> videoSourceStaffConfig;
|
|
|
- @ApolloJsonValue("${send.room.msg.staff.put.scene.config:{}}")
|
|
|
- private Map<Long, String> staffPutSceneConfig;
|
|
|
- @ApolloJsonValue("${send.room.msg.auto.open.staff:[]}")
|
|
|
- private List<Long> autoOpenStaffList;
|
|
|
|
|
|
private final static ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.SECONDS,
|
|
|
new LinkedBlockingQueue<>(),
|
|
|
@@ -83,30 +85,160 @@ public class WeComSendMsgJob {
|
|
|
public ReturnT<String> autoSendAppMsg(String param) {
|
|
|
List<ThirdPartWeComStaff> activeStaffList = weComThirdPartyService.getActiveStaffList();
|
|
|
String time = DateUtil.getCurrentDateStr("HH:mm");
|
|
|
+ List<Long> staffIdList = activeStaffList.stream().map(ThirdPartWeComStaff::getId).collect(Collectors.toList());
|
|
|
+ List<ThirdPartWeComStaffConfig> staffConfigList = weComThirdPartyAccountService.getStaffConfigListByStaffIds(staffIdList);
|
|
|
+ Map<Long, ThirdPartWeComStaffConfig> staffConfigMap = staffConfigList.stream().collect(Collectors.toMap(ThirdPartWeComStaffConfig::getStaffId, a -> a));
|
|
|
for (ThirdPartWeComStaff staff : activeStaffList) {
|
|
|
+ ThirdPartWeComStaffConfig staffConfig = staffConfigMap.get(staff.getId());
|
|
|
+ if (Objects.isNull(staffConfig) || staffConfig.getSwitchFlag() != 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
List<ThirdPartWeComRoom> roomList = weComThirdPartyService.getStaffRoomList(staff.getId());
|
|
|
- for (ThirdPartWeComRoom room : roomList) {
|
|
|
- if (room.getSendStatus() != 1) {
|
|
|
+ if (CollectionUtils.isEmpty(roomList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<Long> roomIds = roomList.stream().map(ThirdPartWeComRoom::getId).collect(Collectors.toList());
|
|
|
+ List<ThirdPartWeComRoomConfig> roomConfigList = weComThirdPartyRoomService.getRoomConfigListByRoomIds(roomIds);
|
|
|
+ if (CollectionUtils.isEmpty(roomConfigList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<Long, ThirdPartWeComRoomConfig> roomConfigMap = roomConfigList.stream().collect(Collectors.toMap(ThirdPartWeComRoomConfig::getRoomId, a -> a));
|
|
|
+ List<String> configIds = roomConfigList.stream().map(ThirdPartWeComRoomConfig::getId).map(String::valueOf).collect(Collectors.toList());
|
|
|
+ List<ThirdPartWeComRoomConfigTask> roomConfigTaskList = weComThirdPartyRoomService.getRoomConfigTasks(configIds);
|
|
|
+ if (CollectionUtils.isEmpty(roomConfigTaskList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, List<ThirdPartWeComRoomConfigTask>> roomConfigTaskMap = roomConfigTaskList.stream()
|
|
|
+ .filter(o -> o.getSwitchFlag() == 1).collect(Collectors.groupingBy(ThirdPartWeComRoomConfigTask::getConfigId));
|
|
|
+ sendStaffRoomMsg(staff, time, roomList, roomConfigMap, roomConfigTaskMap);
|
|
|
+ }
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendStaffRoomMsg(ThirdPartWeComStaff staff,
|
|
|
+ String time,
|
|
|
+ List<ThirdPartWeComRoom> roomList,
|
|
|
+ Map<Long, ThirdPartWeComRoomConfig> roomConfigMap,
|
|
|
+ Map<String, List<ThirdPartWeComRoomConfigTask>> roomConfigTaskMap) {
|
|
|
+ for (ThirdPartWeComRoom room : roomList) {
|
|
|
+ if (room.getSendStatus() != 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ pool.execute(() -> {
|
|
|
+ ThirdPartWeComRoomConfig roomConfig = roomConfigMap.get(room.getId());
|
|
|
+ if (roomConfig == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ThirdPartWeComRoomConfigTask> taskList = roomConfigTaskMap.getOrDefault(roomConfig.getId(), new ArrayList<>());
|
|
|
+ if (taskList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<String> configTaskIds = taskList.stream().map(ThirdPartWeComRoomConfigTask::getId).collect(Collectors.toList());
|
|
|
+ List<ThirdPartWeComRoomConfigTaskContent> taskContentList = weComThirdPartyRoomService.getRoomConfigTaskContents(configTaskIds);
|
|
|
+ if (CollectionUtils.isEmpty(taskContentList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, List<ThirdPartWeComRoomConfigTaskContent>> taskContentMap = taskContentList.stream()
|
|
|
+ .collect(Collectors.groupingBy(ThirdPartWeComRoomConfigTaskContent::getTaskId));
|
|
|
+ ThirdPartWeComStaff pushStaff = getSendStaff(roomConfig);
|
|
|
+ if (Objects.isNull(pushStaff)) {
|
|
|
+ LarkRobotUtil.sendWeComThirdPartMessage(
|
|
|
+ "【账号发送群消息,推送账号获取失败通知】\n" +
|
|
|
+ "账号名称:" + staff.getName() + "\n" +
|
|
|
+ "账号VID:" + staff.getThirdStaffId() + "\n" +
|
|
|
+ "群名称:" + room.getName());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ sendRoomConfigTaskMsg(staff, pushStaff, time, room, roomConfig, taskList, taskContentMap);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendRoomConfigTaskMsg(ThirdPartWeComStaff staff,
|
|
|
+ ThirdPartWeComStaff pushStaff,
|
|
|
+ String time,
|
|
|
+ ThirdPartWeComRoom room,
|
|
|
+ ThirdPartWeComRoomConfig roomConfig,
|
|
|
+ List<ThirdPartWeComRoomConfigTask> taskList,
|
|
|
+ Map<String, List<ThirdPartWeComRoomConfigTaskContent>> taskContentMap) {
|
|
|
+ for (ThirdPartWeComRoomConfigTask configTask : taskList) {
|
|
|
+ List<String> timeList = getRoomSendTime(room, roomConfig, configTask);
|
|
|
+ if (timeList.contains(time)) {
|
|
|
+ // 选取视频
|
|
|
+ List<ThirdPartWeComRoomConfigTaskContent> contentList = taskContentMap.get(configTask.getId());
|
|
|
+ if (Objects.isNull(contentList) || contentList.isEmpty()) {
|
|
|
continue;
|
|
|
}
|
|
|
- pool.execute(() -> {
|
|
|
- List<String> timeList = JSONObject.parseArray(room.getSendTime()).toJavaList(String.class);
|
|
|
- if (timeList.contains(time)) {
|
|
|
- // 选取视频
|
|
|
- List<CgiReplyBucketData> cgiReplyBucketDataList = getCgiReplyBucketData(room.getThirdRoomId(), staff);
|
|
|
+ contentList = contentList.stream().sorted(Comparator.comparing(ThirdPartWeComRoomConfigTaskContent::getSeq)).collect(Collectors.toList());
|
|
|
+ for (ThirdPartWeComRoomConfigTaskContent configTaskContent : contentList) {
|
|
|
+ if (ConfigTaskContentTypeEnum.TEXT.getVal() == configTaskContent.getType()) {
|
|
|
+ // build发送体
|
|
|
+ SendTextMsgRequest request = buildSendTextMsgRequest(configTaskContent.getContent(), pushStaff, room);
|
|
|
+ // 发送消息
|
|
|
+ CommonResponse<SendTextMsgResponse> response = weComThirdPartyService.sendTextMsg(pushStaff, room, request);
|
|
|
+ // 存储消息
|
|
|
+ saveTextWeComMsg(pushStaff.getId(), configTaskContent.getContent(), request, response);
|
|
|
+ } else if (ConfigTaskContentTypeEnum.MINI_PROGRAM.getVal() == configTaskContent.getType()) {
|
|
|
+ List<CgiReplyBucketData> cgiReplyBucketDataList = getCgiReplyBucketData(room.getThirdRoomId(), staff, roomConfig, configTaskContent);
|
|
|
for (CgiReplyBucketData cgiReplyBucketData : cgiReplyBucketDataList) {
|
|
|
// build发送体
|
|
|
- SendAppMsgRequest request = buildSendAppMsgRequest(cgiReplyBucketData, staff, room);
|
|
|
- // 发送消息
|
|
|
- weComThirdPartyService.sendAppMsg(request);
|
|
|
- // 存储消息
|
|
|
- saveWeComMsg(staff.getId(), cgiReplyBucketData.getMiniVideoId(), request);
|
|
|
+ SendAppMsgRequest request = buildSendAppMsgRequest(cgiReplyBucketData, pushStaff, room);
|
|
|
+ try {
|
|
|
+ // 发送消息
|
|
|
+ CommonResponse<SendAppMsgResponse> response = weComThirdPartyService.sendAppMsg(pushStaff, room, request);
|
|
|
+ // 存储消息
|
|
|
+ saveAppWeComMsg(pushStaff.getId(), cgiReplyBucketData.getMiniVideoId(), request, response);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送群消息失败,账号名称:{},账号VID:{},群名称:{},视频ID:{},request:{},异常信息:{}",
|
|
|
+ staff.getName(), staff.getThirdStaffId(), room.getName(),
|
|
|
+ cgiReplyBucketData.getMiniVideoId(), JSONObject.toJSONString(request), e.getMessage(), e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ThirdPartWeComStaff getSendStaff(ThirdPartWeComRoomConfig roomConfig) {
|
|
|
+ List<ThirdPartWeComStaff> pushStaffList = weComThirdPartyRoomService.getRoomConfigPushList(Collections.singletonList(roomConfig));
|
|
|
+ Map<Long, ThirdPartWeComStaff> pushStaffMap = pushStaffList.stream()
|
|
|
+ .collect(Collectors.toMap(ThirdPartWeComStaff::getThirdStaffId, Function.identity()));
|
|
|
+ ThirdPartWeComStaff pushStaff = pushStaffMap.get(roomConfig.getPrimaryThirdStaffId());
|
|
|
+ if (Objects.isNull(pushStaff) || pushStaff.getStatus() != ThirdPartWeComStaffStatusEnum.NORMAL.getVal()) {
|
|
|
+ if (Objects.nonNull(roomConfig.getSecondThirdStaffId())) {
|
|
|
+ pushStaff = pushStaffMap.get(roomConfig.getSecondThirdStaffId());
|
|
|
+ if (Objects.isNull(pushStaff) || pushStaff.getStatus() != ThirdPartWeComStaffStatusEnum.NORMAL.getVal()) {
|
|
|
+ pushStaff = null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ pushStaff = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pushStaff;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getRoomSendTime(ThirdPartWeComRoom room,
|
|
|
+ ThirdPartWeComRoomConfig roomConfig,
|
|
|
+ ThirdPartWeComRoomConfigTask configTask) {
|
|
|
+ String key = "wecom:room:send:time:" + room.getThirdRoomId() + ":" + roomConfig.getId() + ":" + configTask.getId();
|
|
|
+ String timeStr = redisUtils.get(key);
|
|
|
+ if (StringUtils.isBlank(timeStr)) {
|
|
|
+ return JSONObject.parseArray(room.getSendTime()).toJavaList(String.class);
|
|
|
+ }
|
|
|
+ return JSONObject.parseArray(timeStr).toJavaList(String.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ private SendTextMsgRequest buildSendTextMsgRequest(String content,
|
|
|
+ ThirdPartWeComStaff staff,
|
|
|
+ ThirdPartWeComRoom room) {
|
|
|
+ String thirdRoomId = room.getThirdRoomId();
|
|
|
+ SendTextMsgRequest request = new SendTextMsgRequest();
|
|
|
+ request.setUuid(staff.getThirdUuid());
|
|
|
+ request.setSend_userid(Long.valueOf(thirdRoomId));
|
|
|
+ request.setIsRoom(true);
|
|
|
+ request.setContent(content);
|
|
|
+ return request;
|
|
|
}
|
|
|
|
|
|
private SendAppMsgRequest buildSendAppMsgRequest(CgiReplyBucketData cgiReplyBucketData,
|
|
|
@@ -123,11 +255,8 @@ public class WeComSendMsgJob {
|
|
|
request.setTitle(cgiReplyBucketData.getTitle());
|
|
|
request.setWeappIconUrl("http://rescdn.yishihui.com/temp/1755515422185_%E7%A5%A8%E5%9C%88Vlog_logo.jpg");
|
|
|
// 填充视频信息
|
|
|
- String coverUrl = cgiReplyBucketData.getCoverUrl();
|
|
|
- // 实验 封面添加播放按钮水印
|
|
|
- if (!testRoomList.contains(thirdRoomId)) {
|
|
|
- coverUrl = addPlayWatermark(cgiReplyBucketData.getCoverUrl());
|
|
|
- }
|
|
|
+ // 封面添加播放按钮水印
|
|
|
+ String coverUrl = addPlayWatermark(cgiReplyBucketData.getCoverUrl());
|
|
|
request.setDesc(cgiReplyBucketData.getTitle());
|
|
|
request.setPagepath(cgiReplyBucketData.getMiniPagePath());
|
|
|
CdnUploadImgLinkRequest cdnUploadImgLinkRequest = new CdnUploadImgLinkRequest();
|
|
|
@@ -152,66 +281,54 @@ public class WeComSendMsgJob {
|
|
|
return coverUrl + waterMark;
|
|
|
}
|
|
|
|
|
|
- private List<CgiReplyBucketData> getCgiReplyBucketData(String roomId, ThirdPartWeComStaff thirdPartWeComStaff) {
|
|
|
- String dt = planMapperExt.getVideoMaxDt();
|
|
|
- String datastatDt = planMapperExt.getVideoDatastatMaxDt();
|
|
|
+ private List<CgiReplyBucketData> getCgiReplyBucketData(String roomId,
|
|
|
+ ThirdPartWeComStaff thirdPartWeComStaff,
|
|
|
+ ThirdPartWeComRoomConfig roomConfig,
|
|
|
+ ThirdPartWeComRoomConfigTaskContent configTaskContent) {
|
|
|
// 排除最近发送过的视频
|
|
|
List<Long> sentVideoIds = getSentVideoIds(Long.valueOf(roomId));
|
|
|
- // 按行业获取视频
|
|
|
- String sort = "datastat.fission_rate desc, video.score desc";
|
|
|
- String type = "企微-社群";
|
|
|
- String channel = "sum";
|
|
|
- List<ContentPlatformVideo> videoList = getVideoByStrategy(thirdPartWeComStaff.getThirdStaffId(), roomId, dt, datastatDt, type, channel, videoMinScore,
|
|
|
- sentVideoIds, 1, 100, sort);
|
|
|
+ List<ContentPlatformVideo> videoList = getVideoByStrategy(roomId, videoMinScore, sentVideoIds,
|
|
|
+ configTaskContent, 1, 100);
|
|
|
if (CollectionUtils.isEmpty(videoList)) {
|
|
|
LarkRobotUtil.sendWeComThirdPartMessage(
|
|
|
"【账号发送群消息,视频数量不足通知】\n" +
|
|
|
"账号名称:" + thirdPartWeComStaff.getName() + "\n" +
|
|
|
"账号VID:" + thirdPartWeComStaff.getThirdStaffId() + "\n" +
|
|
|
"群ID:" + roomId + "\n" +
|
|
|
- "账号配置:" + videoSourceStaffConfig.get(thirdPartWeComStaff.getId()));
|
|
|
+ "账号配置:" + JSONObject.toJSONString(configTaskContent));
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
List<CgiReplyBucketData> result = new ArrayList<>();
|
|
|
- for (int i = 0; i < videoNum; i++) {
|
|
|
- ContentPlatformVideo video = videoList.get(i);
|
|
|
- Staff staff = new Staff();
|
|
|
- staff.setCarrierId(String.valueOf(thirdPartWeComStaff.getThirdStaffId()));
|
|
|
- staff.setRemark(thirdPartWeComStaff.getName());
|
|
|
- String putScene = staffPutSceneConfig.getOrDefault(thirdPartWeComStaff.getThirdStaffId(), "touliu");
|
|
|
- String page = messageAttachmentService.getPageNoCache(putScene, staff, video.getVideoId(), "企微", "社群");
|
|
|
+ ContentPlatformVideo video = videoList.get(0);
|
|
|
+ Staff staff = new Staff();
|
|
|
+ staff.setCarrierId(String.valueOf(thirdPartWeComStaff.getThirdStaffId()));
|
|
|
+ staff.setRemark(thirdPartWeComStaff.getName());
|
|
|
+ String putScene = StringUtils.isNotBlank(roomConfig.getPutScene()) ? roomConfig.getPutScene() : "touliu";
|
|
|
+ String pageChannel = StringUtils.isNotBlank(roomConfig.getChannel()) ? roomConfig.getChannel() : "tencentqw";
|
|
|
+ String page = messageAttachmentService.getPageNoCache(putScene, pageChannel, staff, video.getVideoId(), "企微", "社群");
|
|
|
+ page = videoMultiService.setVideoMultiTitleCoverPagePath(video.getVideoId(), page, video.getTitle(), video.getCover());
|
|
|
|
|
|
- CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
|
|
|
- cgiReplyBucketData.setMiniVideoId(video.getVideoId());
|
|
|
- cgiReplyBucketData.setTitle(video.getTitle());
|
|
|
- cgiReplyBucketData.setCoverUrl(video.getCover());
|
|
|
- cgiReplyBucketData.setMiniPagePath(page);
|
|
|
- result.add(cgiReplyBucketData);
|
|
|
- }
|
|
|
+ CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
|
|
|
+ cgiReplyBucketData.setMiniVideoId(video.getVideoId());
|
|
|
+ cgiReplyBucketData.setTitle(video.getTitle());
|
|
|
+ cgiReplyBucketData.setCoverUrl(video.getCover());
|
|
|
+ cgiReplyBucketData.setMiniPagePath(page);
|
|
|
+ result.add(cgiReplyBucketData);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private List<ContentPlatformVideo> getVideoByStrategy(Long staffId,
|
|
|
- String roomId,
|
|
|
- String dt,
|
|
|
- String datastatDt,
|
|
|
- String type,
|
|
|
- String channel,
|
|
|
+ private List<ContentPlatformVideo> getVideoByStrategy(String roomId,
|
|
|
Double videoMinScore,
|
|
|
List<Long> sentVideoIds,
|
|
|
+ ThirdPartWeComRoomConfigTaskContent configTaskContent,
|
|
|
int pageNum,
|
|
|
- int pageSize,
|
|
|
- String sort) {
|
|
|
+ int pageSize) {
|
|
|
List<ContentPlatformVideo> result = new ArrayList<>();
|
|
|
- JSONObject staffConfig = videoSourceStaffConfig.get(staffId);
|
|
|
- if (staffConfig == null) {
|
|
|
- staffConfig = new JSONObject();
|
|
|
- }
|
|
|
List<ContentPlatformVideo> videoList;
|
|
|
- String source = (String) staffConfig.getOrDefault("source", "");
|
|
|
- switch (source) {
|
|
|
- case "user":
|
|
|
- Long uid = staffConfig.getLong("uid");
|
|
|
+ // 0-热榜 1-标签 2-账号
|
|
|
+ switch (configTaskContent.getSource()) {
|
|
|
+ case 2:
|
|
|
+ Long uid = Long.valueOf(configTaskContent.getSourceContent());
|
|
|
List<WxVideoV2VO> list = videoApiService.getUserVideoList(uid, sentVideoIds, pageNum, pageSize);
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
break;
|
|
|
@@ -219,8 +336,8 @@ public class WeComSendMsgJob {
|
|
|
videoList = convertWxVideoV2VOToVideo(list);
|
|
|
result.addAll(videoList);
|
|
|
break;
|
|
|
- case "tag":
|
|
|
- String tagName = staffConfig.getString("tagName");
|
|
|
+ case 1:
|
|
|
+ String tagName = configTaskContent.getSourceContent();
|
|
|
list = videoApiService.getTagVideoList(tagName, roomId, sentVideoIds, pageNum, pageSize);
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
break;
|
|
|
@@ -229,11 +346,9 @@ public class WeComSendMsgJob {
|
|
|
result.addAll(videoList);
|
|
|
break;
|
|
|
default:
|
|
|
- result = planMapperExt.getVideoMinDatastatScoreList(dt, datastatDt,
|
|
|
- type, channel, "normal", videoMinScore, sentVideoIds, 0, 100, sort);
|
|
|
- // 行业数量不足,按平台推荐top选取视频
|
|
|
- sort = "video.score desc";
|
|
|
- result.addAll(planMapperExt.getVideoMinScoreList(dt, videoMinScore, sentVideoIds, 0, 100, sort));
|
|
|
+ // 按平台推荐top选取视频
|
|
|
+ String dt = videoMapperExt.getVideoMaxDt();
|
|
|
+ result.addAll(videoMapperExt.getVideoMinScoreList(dt, videoMinScore, roomId, 0, 100, "video.score desc"));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
@@ -253,17 +368,19 @@ public class WeComSendMsgJob {
|
|
|
private List<Long> getSentVideoIds(Long roomId) {
|
|
|
ThirdPartWeComMsgExample msgExample = new ThirdPartWeComMsgExample();
|
|
|
msgExample.createCriteria().andSendUseridEqualTo(roomId)
|
|
|
- .andCreateTimeGreaterThan(DateUtil.getDaysAgoDate(duplicateDays));
|
|
|
+ .andCreateTimeGreaterThan(DateUtil.getDaysAgoDate(duplicateDays))
|
|
|
+ .andVideoIdIsNotNull();
|
|
|
List<ThirdPartWeComMsg> msgList = msgMapper.selectByExample(msgExample);
|
|
|
return msgList.stream().map(ThirdPartWeComMsg::getVideoId).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- private void saveWeComMsg(Long staffId, Long videoId, SendAppMsgRequest request) {
|
|
|
+ private void saveAppWeComMsg(Long staffId, Long videoId, SendAppMsgRequest request, CommonResponse<SendAppMsgResponse> response) {
|
|
|
ThirdPartWeComMsg msg = new ThirdPartWeComMsg();
|
|
|
msg.setStaffId(staffId);
|
|
|
msg.setVideoId(videoId);
|
|
|
msg.setUuid(request.getUuid());
|
|
|
msg.setSendUserid(request.getSend_userid());
|
|
|
+ msg.setSendType(ConfigTaskContentTypeEnum.MINI_PROGRAM.getVal());
|
|
|
msg.setIsroom(request.getIsRoom());
|
|
|
msg.setAppid(request.getAppid());
|
|
|
msg.setUsername(request.getUsername());
|
|
|
@@ -277,15 +394,39 @@ public class WeComSendMsgJob {
|
|
|
msg.setMd5(request.getMd5());
|
|
|
msg.setAeskey(request.getAeskey());
|
|
|
msg.setFilesize(request.getFileSize());
|
|
|
+ if (response.getErrcode() == 0) {
|
|
|
+ msg.setStatus(MsgSendStatusEnum.NORMAL.getVal());
|
|
|
+ } else {
|
|
|
+ msg.setStatus(MsgSendStatusEnum.FAIL.getVal());
|
|
|
+ }
|
|
|
msgMapper.insertSelective(msg);
|
|
|
}
|
|
|
|
|
|
+ private void saveTextWeComMsg(Long staffId, String content, SendTextMsgRequest request, CommonResponse<SendTextMsgResponse> response) {
|
|
|
+ ThirdPartWeComMsg msg = new ThirdPartWeComMsg();
|
|
|
+ msg.setStaffId(staffId);
|
|
|
+ msg.setUuid(request.getUuid());
|
|
|
+ msg.setSendUserid(request.getSend_userid());
|
|
|
+ msg.setSendType(ConfigTaskContentTypeEnum.TEXT.getVal());
|
|
|
+ msg.setContent(content);
|
|
|
+ msg.setIsroom(request.getIsRoom());
|
|
|
+ if (response.getErrcode() == 0) {
|
|
|
+ msg.setStatus(MsgSendStatusEnum.NORMAL.getVal());
|
|
|
+ } else {
|
|
|
+ msg.setStatus(MsgSendStatusEnum.FAIL.getVal());
|
|
|
+ }
|
|
|
+ msgMapper.insertSelective(msg);
|
|
|
+ }
|
|
|
|
|
|
@XxlJob("autoOpenSendStatusJob")
|
|
|
public ReturnT<String> autoOpenSendStatusJob(String param) {
|
|
|
List<ThirdPartWeComStaff> activeStaffList = weComThirdPartyService.getActiveStaffList();
|
|
|
+ List<Long> staffIdList = activeStaffList.stream().map(ThirdPartWeComStaff::getId).collect(Collectors.toList());
|
|
|
+ List<ThirdPartWeComStaffConfig> staffConfigList = weComThirdPartyAccountService.getStaffConfigListByStaffIds(staffIdList);
|
|
|
+ Map<Long, ThirdPartWeComStaffConfig> staffConfigMap = staffConfigList.stream().collect(Collectors.toMap(ThirdPartWeComStaffConfig::getStaffId, a -> a));
|
|
|
for (ThirdPartWeComStaff staff : activeStaffList) {
|
|
|
- if (!autoOpenStaffList.contains(staff.getThirdStaffId())) {
|
|
|
+ ThirdPartWeComStaffConfig staffConfig = staffConfigMap.get(staff.getId());
|
|
|
+ if (Objects.isNull(staffConfig) || staffConfig.getSwitchFlag() != 1 || Objects.isNull(staffConfig.getOpenRoomSendSwitchNum())) {
|
|
|
continue;
|
|
|
}
|
|
|
List<ThirdPartWeComRoom> roomList = weComThirdPartyService.getStaffRoomList(staff.getId());
|
|
|
@@ -293,7 +434,7 @@ public class WeComSendMsgJob {
|
|
|
if (room.getSendStatus() == 1) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (room.getMemberCount() > 20) {
|
|
|
+ if (room.getMemberCount() > staffConfig.getOpenRoomSendSwitchNum()) {
|
|
|
room.setSendStatus(1);
|
|
|
roomMapper.updateByPrimaryKeySelective(room);
|
|
|
}
|
|
|
@@ -301,4 +442,74 @@ public class WeComSendMsgJob {
|
|
|
}
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
+
|
|
|
+ @XxlJob("randomRoomSendTimeJob")
|
|
|
+ public ReturnT<String> randomRoomSendTimeJob(String param) {
|
|
|
+ List<ThirdPartWeComStaff> activeStaffList = weComThirdPartyService.getActiveStaffList();
|
|
|
+ String now = DateUtil.getCurrentDateStr("HH:mm");
|
|
|
+ for (ThirdPartWeComStaff staff : activeStaffList) {
|
|
|
+ List<ThirdPartWeComRoom> roomList = weComThirdPartyService.getStaffRoomList(staff.getId());
|
|
|
+ List<ThirdPartWeComRoomConfig> roomConfigList = weComThirdPartyRoomService.getRoomConfigListByRoomIds(roomList.stream().map(ThirdPartWeComRoom::getId).collect(Collectors.toList()));
|
|
|
+ Map<Long, ThirdPartWeComRoomConfig> roomConfigMap = roomConfigList.stream().collect(Collectors.toMap(ThirdPartWeComRoomConfig::getRoomId, Function.identity()));
|
|
|
+ List<String> configIds = roomConfigList.stream().map(ThirdPartWeComRoomConfig::getId).map(String::valueOf).collect(Collectors.toList());
|
|
|
+ List<ThirdPartWeComRoomConfigTask> roomConfigTaskList = weComThirdPartyRoomService.getRoomConfigTasks(configIds);
|
|
|
+ Map<String, List<ThirdPartWeComRoomConfigTask>> roomConfigTaskMap = roomConfigTaskList.stream().collect(Collectors.groupingBy(ThirdPartWeComRoomConfigTask::getConfigId));
|
|
|
+ for (ThirdPartWeComRoom room : roomList) {
|
|
|
+ ThirdPartWeComRoomConfig roomConfig = roomConfigMap.get(room.getId());
|
|
|
+ if (roomConfig == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<ThirdPartWeComRoomConfigTask> taskList = roomConfigTaskMap.getOrDefault(roomConfig.getId(), new ArrayList<>());
|
|
|
+ if (taskList.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ randomRoomSendTime(room, roomConfig, taskList, now);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void randomRoomSendTime(ThirdPartWeComRoom room,
|
|
|
+ ThirdPartWeComRoomConfig roomConfig,
|
|
|
+ List<ThirdPartWeComRoomConfigTask> taskList,
|
|
|
+ String now) {
|
|
|
+ for (ThirdPartWeComRoomConfigTask configTask : taskList) {
|
|
|
+ String key = "wecom:room:send:time:" + room.getThirdRoomId() + ":" + roomConfig.getId() + ":" + configTask.getId();
|
|
|
+ if (redisUtils.containsKey(key)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> timeList = JSONObject.parseArray(room.getSendTime()).toJavaList(String.class);
|
|
|
+ // 判断timeList中在now之后的时间,随机增加或减少20以内的分钟数
|
|
|
+ List<String> newTimeList = new ArrayList<>();
|
|
|
+ for (String time : timeList) {
|
|
|
+ // time与now比较,判断是否在now之后
|
|
|
+ int hour = Integer.parseInt(time.substring(0, 2));
|
|
|
+ int minute = Integer.parseInt(time.substring(3, 5));
|
|
|
+ int nowHour = Integer.parseInt(now.substring(0, 2));
|
|
|
+ int nowMinute = Integer.parseInt(now.substring(3, 5));
|
|
|
+ if (hour < nowHour || (hour == nowHour && minute <= nowMinute)) {
|
|
|
+ newTimeList.add(time);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 增加或减少20以内的分钟数 -20~20
|
|
|
+ int randomTimeRange = Objects.isNull(configTask.getRandomMin()) ? 0 : configTask.getRandomMin();
|
|
|
+ int randomMinute = randomTimeRange == 0 ? 0 : new Random().nextInt(randomTimeRange * 2) - randomTimeRange;
|
|
|
+ minute += randomMinute;
|
|
|
+ if (minute < 0) {
|
|
|
+ hour--;
|
|
|
+ minute += 60;
|
|
|
+ } else if (minute >= 60) {
|
|
|
+ hour++;
|
|
|
+ minute -= 60;
|
|
|
+ }
|
|
|
+ // 确保时间在now之后
|
|
|
+ if (hour < nowHour || (hour == nowHour && minute <= nowMinute)) {
|
|
|
+ newTimeList.add(time);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ newTimeList.add(String.format("%02d:%02d", hour, minute));
|
|
|
+ }
|
|
|
+ redisUtils.set(key, JSONObject.toJSONString(newTimeList), 18 * 60 * 60);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|