wangyunpeng před 4 týdny
rodič
revize
3f1f149988

+ 34 - 6
api-module/src/main/java/com/tzld/piaoquan/api/job/wecom/thirdpart/WeComSendMsgJob.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 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;
@@ -114,6 +115,15 @@ public class WeComSendMsgJob {
                     List<ThirdPartWeComRoomConfigTaskContent> taskContentList = weComThirdPartyRoomService.getRoomConfigTaskContents(configTaskIds);
                     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;
+                    }
                     for (ThirdPartWeComRoomConfigTask configTask : taskList) {
                         List<String> timeList = getRoomSendTime(room, roomConfig, configTask);
                         if (timeList.contains(time)) {
@@ -126,20 +136,20 @@ public class WeComSendMsgJob {
                             for (ThirdPartWeComRoomConfigTaskContent configTaskContent : contentList) {
                                 if (ConfigTaskContentTypeEnum.TEXT.getVal() == configTaskContent.getType()) {
                                     // build发送体
-                                    SendTextMsgRequest request = buildSendTextMsgRequest(configTaskContent.getContent(), staff, room);
+                                    SendTextMsgRequest request = buildSendTextMsgRequest(configTaskContent.getContent(), pushStaff, room);
                                     // 发送消息
-                                    CommonResponse<SendTextMsgResponse> response = weComThirdPartyService.sendTextMsg(staff, room, request);
+                                    CommonResponse<SendTextMsgResponse> response = weComThirdPartyService.sendTextMsg(pushStaff, room, request);
                                     // 存储消息
-                                    saveTextWeComMsg(staff.getId(), configTaskContent.getContent(), request, response);
+                                    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);
+                                        SendAppMsgRequest request = buildSendAppMsgRequest(cgiReplyBucketData, pushStaff, room);
                                         // 发送消息
-                                        CommonResponse<SendAppMsgResponse> response = weComThirdPartyService.sendAppMsg(staff, room, request);
+                                        CommonResponse<SendAppMsgResponse> response = weComThirdPartyService.sendAppMsg(pushStaff, room, request);
                                         // 存储消息
-                                        saveAppWeComMsg(staff.getId(), cgiReplyBucketData.getMiniVideoId(), request, response);
+                                        saveAppWeComMsg(pushStaff.getId(), cgiReplyBucketData.getMiniVideoId(), request, response);
                                     }
                                 }
                             }
@@ -151,6 +161,24 @@ public class WeComSendMsgJob {
         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) {

+ 3 - 4
api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/WeComThirdPartyRoomService.java

@@ -4,10 +4,7 @@ import com.tzld.piaoquan.api.model.param.wecom.thirdpart.ThirdPartyAccountConfig
 import com.tzld.piaoquan.api.model.param.wecom.thirdpart.ThirdPartyConfigGetParam;
 import com.tzld.piaoquan.api.model.param.wecom.thirdpart.ThirdPartyRoomConfigParam;
 import com.tzld.piaoquan.api.model.param.wecom.thirdpart.ThirdPartyRoomListParam;
-import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoom;
-import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoomConfig;
-import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoomConfigTask;
-import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoomConfigTaskContent;
+import com.tzld.piaoquan.api.model.po.wecom.thirdpart.*;
 import com.tzld.piaoquan.api.model.vo.IdNameVO;
 import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountConfigVO;
 import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyRoomConfigVO;
@@ -24,6 +21,8 @@ public interface WeComThirdPartyRoomService {
 
     ThirdPartyRoomConfigVO getRoomConfig(ThirdPartyConfigGetParam param);
 
+    List<ThirdPartWeComStaff> getRoomConfigPushList(List<ThirdPartWeComRoomConfig> configList);
+
     List<ThirdPartWeComRoomConfigTask> getRoomConfigTasks(List<String> configIds);
 
     List<ThirdPartWeComRoomConfigTaskContent> getRoomConfigTaskContents(List<String> taskIds);

+ 2 - 1
api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/impl/WeComThirdPartyRoomServiceImpl.java

@@ -169,7 +169,8 @@ public class WeComThirdPartyRoomServiceImpl implements WeComThirdPartyRoomServic
         return result;
     }
 
-    private List<ThirdPartWeComStaff> getRoomConfigPushList(List<ThirdPartWeComRoomConfig> configList) {
+    @Override
+    public List<ThirdPartWeComStaff> getRoomConfigPushList(List<ThirdPartWeComRoomConfig> configList) {
         List<Long> thirdStaffIds = new ArrayList<>();
         for (ThirdPartWeComRoomConfig config : configList) {
             if (Objects.nonNull(config.getPrimaryThirdStaffId())) {