ソースを参照

Merge remote-tracking branch 'origin/Payment-Configuration' into Payment-Configuration

yys 1 ヶ月 前
コミット
44cb6d94e1

+ 0 - 5
fs-company-app/src/main/java/com/fs/app/controller/FsUserCourseVideoController.java

@@ -399,11 +399,6 @@ public class FsUserCourseVideoController extends AppBaseController {
     @PostMapping("/batchSendCourse")
     public R batchSendCourse(@RequestBody BatchSendCourseDTO batchSendCourseDTO) throws JsonProcessingException {
 
-        if(batchSendCourseDTO.getSendType()==2){
-            log.error("实时发送课程功能系统维护中,请先用定时发送");
-            return R.error("实时发送课程功能系统维护中,请先用定时发送");
-        }
-
         // 生成看课短链
         FsCourseLinkCreateParam fsCourseLinkCreateParam = new FsCourseLinkCreateParam();
         BeanUtils.copyProperties(batchSendCourseDTO, fsCourseLinkCreateParam);

+ 7 - 7
fs-service/src/main/java/com/fs/im/service/OpenIMService.java

@@ -57,13 +57,13 @@ public interface OpenIMService {
      */
     OpenImResponseDTO openIMBatchSendMsg(OpenImBatchMsgDTO openImBatchMsgDTO);
 
-    /**
-     * 会员批量发课
-     * @param batchSendCourseDTO
-     * @return
-     * @throws JsonProcessingException
-     */
-    OpenImResponseDTO batchSendCourse(BatchSendCourseDTO batchSendCourseDTO) throws JsonProcessingException;
+//    /**
+//     * 会员批量发课
+//     * @param batchSendCourseDTO
+//     * @return
+//     * @throws JsonProcessingException
+//     */
+//    OpenImResponseDTO batchSendCourse(BatchSendCourseDTO batchSendCourseDTO) throws JsonProcessingException;
 
     /**
      * 会员批量发课

+ 143 - 151
fs-service/src/main/java/com/fs/im/service/impl/OpenIMServiceImpl.java

@@ -1442,87 +1442,89 @@ public class OpenIMServiceImpl implements OpenIMService {
         return responseDTO;
     }
 
-    @Override
-    @Transactional
-    public OpenImResponseDTO batchSendCourse(BatchSendCourseDTO batchSendCourseDTO) throws JsonProcessingException {
-        ObjectMapper objectMapper = new ObjectMapper();
-        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 忽略null字段
-
-        //获取需要发送的人
-        List<String> userIds = this.getRecvIds(batchSendCourseDTO);
-
-        //优化:批量注册和添加好友(替代逐个循环调用checkAndImportFriendByDianBo)
-        List<String> fsUserIds = userIds.stream().map(id -> id.substring(1)).collect(Collectors.toList());
-        batchCheckAndImportFriend(batchSendCourseDTO.getCompanyUserId(), fsUserIds, null, false);
-
-        //组装发课消息数据
-        FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(batchSendCourseDTO.getCourseId());
-        Long project = fsUserCourse != null ? fsUserCourse.getProject() : null;
-        long planSendTimeStamp;
-        if(ObjectUtils.isNotEmpty(batchSendCourseDTO.getSendType())&&batchSendCourseDTO.getSendType() == 1 && batchSendCourseDTO.getSendTime() != null && batchSendCourseDTO.getSendTime().compareTo(new Date()) > 0){
-            planSendTimeStamp = batchSendCourseDTO.getSendTime().getTime();
-        } else {
-            planSendTimeStamp = System.currentTimeMillis();
-        }
-
-        String courseUrl = fsUserCourse != null ? fsUserCourse.getImgUrl() : null;
-        OpenImBatchMsgDTO openImBatchMsgDTO = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, userIds, planSendTimeStamp, "发课");
-
-        int sendType;
-        if(ObjectUtils.isNotEmpty(batchSendCourseDTO.getSendType())&&batchSendCourseDTO.getSendType() == 1 && batchSendCourseDTO.getSendTime() != null && batchSendCourseDTO.getSendTime().compareTo(new Date()) > 0) {
-            sendType = 1; //定时
-        } else {
-            sendType = 2; //实时
-        }
-
-        // 创建消息发送记录
-        String sendUnionId = UUID.randomUUID().toString();
-        List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog("发课",batchSendCourseDTO, planSendTimeStamp, sendType, userIds, sendUnionId);
-
-        OpenImResponseDTO openImResponseDTO = new OpenImResponseDTO();
-        if(sendType == 1) {
-            // 定时发送
-            // 缓存定时发课消息
-            String redisKey = "openIm:batchSendMsg:sendCourse";
-            Map<String, Object> redisMap = new HashMap<>();
-            BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
-            batchSendCourseAllDTO.setBatchSendCourseDTO(batchSendCourseDTO).setOpenImBatchMsgDTO(openImBatchMsgDTO).setProject(project)
-                    .setImMsgSendDetailList(imMsgSendDetailList);
-            redisMap.put(batchSendCourseDTO.getCourseId()+":"+batchSendCourseDTO.getVideoId()+":"+batchSendCourseDTO.getSendTime().getTime()
-                    , batchSendCourseAllDTO);
-            redisCache.setCacheMap(redisKey, redisMap);
-            openImResponseDTO.setErrCode(0);
-            openImResponseDTO.setErrMsg("计划发送创建成功,待消息发送");
-        } else {
-            // 实时发送
-            openImResponseDTO = this.batchSendCourseTask(batchSendCourseDTO, openImBatchMsgDTO, project, imMsgSendDetailList);
-            openImResponseDTO.setErrMsg("实时发送成功");
-        }
-
-        //是否催课
-        if(batchSendCourseDTO.getIsUrgeCourse()){
-            // 组装催课消息数据
-            OpenImBatchMsgDTO openImBatchUrgeCourse = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, userIds, planSendTimeStamp, "催课");
-
-            //缓存定时催课消息
-            int urgSendType;
-            if(batchSendCourseDTO.getUrgeTime() != null && batchSendCourseDTO.getUrgeTime().compareTo(new Date()) > 0) {
-                urgSendType = 1; //定时
-            } else {
-                urgSendType = 2; //实时
-            }
-            List<FsImMsgSendDetail> imMsgSendDetailUrgeList = createImMsgSendLog("催课", batchSendCourseDTO, planSendTimeStamp, urgSendType, userIds, sendUnionId);
-            String redisKey = "openIm:batchSendMsg:urgeCourse";
-            Map<String, Object> redisMap = new HashMap<>();
-            BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
-            batchSendCourseAllDTO.setOpenImBatchMsgDTO(openImBatchUrgeCourse)
-                    .setImMsgSendDetailList(imMsgSendDetailUrgeList);
-            redisMap.put(batchSendCourseDTO.getCourseId()+":"+batchSendCourseDTO.getVideoId()+":"+batchSendCourseDTO.getUrgeTime().getTime()
-                    , batchSendCourseAllDTO);
-            redisCache.setCacheMap(redisKey, redisMap);
-        }
-        return openImResponseDTO;
-    }
+//    @Override
+//    @Transactional
+//    public OpenImResponseDTO batchSendCourse(BatchSendCourseDTO batchSendCourseDTO) throws JsonProcessingException {
+//        ObjectMapper objectMapper = new ObjectMapper();
+//        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 忽略null字段
+//
+//        //获取需要发送的人
+//        List<String> userIds = this.getRecvIds(batchSendCourseDTO);
+//
+//        //注册和添加好友
+//        for (String userId : userIds) {
+//            String uId = userId.substring(1);
+//            checkAndImportFriendByDianBo(batchSendCourseDTO.getCompanyUserId(), uId,null,false);
+//        }
+//
+//        //组装发课消息数据
+//        FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(batchSendCourseDTO.getCourseId());
+//        Long project = fsUserCourse != null ? fsUserCourse.getProject() : null;
+//        long planSendTimeStamp;
+//        if(ObjectUtils.isNotEmpty(batchSendCourseDTO.getSendType())&&batchSendCourseDTO.getSendType() == 1 && batchSendCourseDTO.getSendTime() != null && batchSendCourseDTO.getSendTime().compareTo(new Date()) > 0){
+//            planSendTimeStamp = batchSendCourseDTO.getSendTime().getTime();
+//        } else {
+//            planSendTimeStamp = System.currentTimeMillis();
+//        }
+//
+//        String courseUrl = fsUserCourse != null ? fsUserCourse.getImgUrl() : null;
+//        OpenImBatchMsgDTO openImBatchMsgDTO = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, userIds, planSendTimeStamp, "发课");
+//
+//        int sendType;
+//        if(ObjectUtils.isNotEmpty(batchSendCourseDTO.getSendType())&&batchSendCourseDTO.getSendType() == 1 && batchSendCourseDTO.getSendTime() != null && batchSendCourseDTO.getSendTime().compareTo(new Date()) > 0) {
+//            sendType = 1; //定时
+//        } else {
+//            sendType = 2; //实时
+//        }
+//
+//        // 创建消息发送记录
+//        String sendUnionId = UUID.randomUUID().toString();
+//        List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog("发课",batchSendCourseDTO, planSendTimeStamp, sendType, userIds, sendUnionId);
+//
+//        OpenImResponseDTO openImResponseDTO = new OpenImResponseDTO();
+//        if(sendType == 1) {
+//            // 定时发送
+//            // 缓存定时发课消息
+//            String redisKey = "openIm:batchSendMsg:sendCourse";
+//            Map<String, Object> redisMap = new HashMap<>();
+//            BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
+//            batchSendCourseAllDTO.setBatchSendCourseDTO(batchSendCourseDTO).setOpenImBatchMsgDTO(openImBatchMsgDTO).setProject(project)
+//                    .setImMsgSendDetailList(imMsgSendDetailList);
+//            redisMap.put(batchSendCourseDTO.getCourseId()+":"+batchSendCourseDTO.getVideoId()+":"+batchSendCourseDTO.getSendTime().getTime()
+//                    , batchSendCourseAllDTO);
+//            redisCache.setCacheMap(redisKey, redisMap);
+//            openImResponseDTO.setErrCode(0);
+//            openImResponseDTO.setErrMsg("计划发送创建成功,待消息发送");
+//        } else {
+//            // 实时发送
+//            openImResponseDTO = this.batchSendCourseTask(batchSendCourseDTO, openImBatchMsgDTO, project, imMsgSendDetailList);
+//            openImResponseDTO.setErrMsg("实时发送成功");
+//        }
+//
+//        //是否催课
+//        if(batchSendCourseDTO.getIsUrgeCourse()){
+//            // 组装催课消息数据
+//            OpenImBatchMsgDTO openImBatchUrgeCourse = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, userIds, planSendTimeStamp, "催课");
+//
+//            //缓存定时催课消息
+//            int urgSendType;
+//            if(batchSendCourseDTO.getUrgeTime() != null && batchSendCourseDTO.getUrgeTime().compareTo(new Date()) > 0) {
+//                urgSendType = 1; //定时
+//            } else {
+//                urgSendType = 2; //实时
+//            }
+//            List<FsImMsgSendDetail> imMsgSendDetailUrgeList = createImMsgSendLog("催课", batchSendCourseDTO, planSendTimeStamp, urgSendType, userIds, sendUnionId);
+//            String redisKey = "openIm:batchSendMsg:urgeCourse";
+//            Map<String, Object> redisMap = new HashMap<>();
+//            BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
+//            batchSendCourseAllDTO.setOpenImBatchMsgDTO(openImBatchUrgeCourse)
+//                    .setImMsgSendDetailList(imMsgSendDetailUrgeList);
+//            redisMap.put(batchSendCourseDTO.getCourseId()+":"+batchSendCourseDTO.getVideoId()+":"+batchSendCourseDTO.getUrgeTime().getTime()
+//                    , batchSendCourseAllDTO);
+//            redisCache.setCacheMap(redisKey, redisMap);
+//        }
+//        return openImResponseDTO;
+//    }
 
 
     @Override
@@ -1577,56 +1579,54 @@ public class OpenIMServiceImpl implements OpenIMService {
                 String sendUnionId = UUID.randomUUID().toString();
                 List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog("发课", batchSendCourseDTO, planSendTimeStamp, sendType, batchUserIds, sendUnionId);
 
-                OpenImResponseDTO responseDTO;
-                if(sendType == 1) {
-                    // 定时发送 - 每个批次独立缓存
-                    String redisKey = "openIm:batchSendMsg:sendCourse";
-                    Map<String, Object> redisMap = redisCache.getCacheMap(redisKey);
-                    if (redisMap == null) {
-                        redisMap = new HashMap<>();
-                    }
-
-                    BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
-                    batchSendCourseAllDTO.setBatchSendCourseDTO(batchSendCourseDTO)
-                            .setOpenImBatchMsgDTO(openImBatchMsgDTO)
-                            .setProject(project)
-                            .setImMsgSendDetailList(imMsgSendDetailList);
-
-                    // 使用唯一的 key:课程 ID+ 视频 ID+ 时间戳  +logId
-                    String batchKey = batchSendCourseDTO.getCourseId() + ":" +
-                            batchSendCourseDTO.getVideoId() + ":" +
-                            batchSendCourseDTO.getSendTime().getTime() + ":" +
-                            imMsgSendDetailList.get(0).getLogId();
-
-                    redisMap.put(batchKey, batchSendCourseAllDTO);
-                    redisCache.setCacheMap(redisKey, redisMap);
-
-                    responseDTO = new OpenImResponseDTO();
-                    responseDTO.setErrCode(0);
-                    responseDTO.setErrMsg("计划发送创建成功,待消息发送");
-                    totalSent += batchUserIds.size();
-                    successCount += batchUserIds.size();
-
-                } else {
-                    // 实时发送 - 立即执行
-                    responseDTO = this.batchSendCourseTask(batchSendCourseDTO, openImBatchMsgDTO, project, imMsgSendDetailList);
-                    totalSent += batchUserIds.size();
-                    if (responseDTO != null && responseDTO.getErrCode() == 0) {
-                        successCount += batchUserIds.size();
-                    } else {
-                        failCount += batchUserIds.size();
-                        log.error("批次 {}/{} 发送失败:{}", i, end, responseDTO != null ? responseDTO.getErrMsg() : "unknown error");
-                    }
-
-                    // 每批之间休眠 100ms,避免请求过快
-                    try {
-                        Thread.sleep(100);
-                    } catch (InterruptedException e) {
-                        Thread.currentThread().interrupt();
-                        break;
-                    }
+                // 定时发送 - 每个批次独立缓存 实时发送也走这个,通过缓存队列批次发送
+                String redisKey = "openIm:batchSendMsg:sendCourse";
+                Map<String, Object> redisMap = redisCache.getCacheMap(redisKey);
+                if (redisMap == null) {
+                    redisMap = new HashMap<>();
                 }
 
+                BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
+                batchSendCourseAllDTO.setBatchSendCourseDTO(batchSendCourseDTO)
+                        .setOpenImBatchMsgDTO(openImBatchMsgDTO)
+                        .setProject(project)
+                        .setImMsgSendDetailList(imMsgSendDetailList);
+
+                // 使用唯一的 key:课程 ID+ 视频 ID+ 时间戳  +logId
+                String batchKey = batchSendCourseDTO.getCourseId() + ":" +
+                        batchSendCourseDTO.getVideoId() + ":" +
+                        batchSendCourseDTO.getSendTime().getTime() + ":" +
+                        imMsgSendDetailList.get(0).getLogId();
+
+                redisMap.put(batchKey, batchSendCourseAllDTO);
+                redisCache.setCacheMap(redisKey, redisMap);
+
+                OpenImResponseDTO  responseDTO = new OpenImResponseDTO();
+                responseDTO.setErrCode(0);
+                responseDTO.setErrMsg("计划发送创建成功,待消息发送");
+                totalSent += batchUserIds.size();
+                successCount += batchUserIds.size();
+
+//                else {
+//                    // 实时发送 - 立即执行
+//                    responseDTO = this.batchSendCourseTask(batchSendCourseDTO, openImBatchMsgDTO, project, imMsgSendDetailList);
+//                    totalSent += batchUserIds.size();
+//                    if (responseDTO != null && responseDTO.getErrCode() == 0) {
+//                        successCount += batchUserIds.size();
+//                    } else {
+//                        failCount += batchUserIds.size();
+//                        log.error("批次 {}/{} 发送失败:{}", i, end, responseDTO != null ? responseDTO.getErrMsg() : "unknown error");
+//                    }
+//
+//                    // 每批之间休眠 100ms,避免请求过快
+//                    try {
+//                        Thread.sleep(100);
+//                    } catch (InterruptedException e) {
+//                        Thread.currentThread().interrupt();
+//                        break;
+//                    }
+//                }
+
                 // 保存最后一个批次的响应
                 finalResponseDTO = responseDTO;
 
@@ -1639,27 +1639,26 @@ public class OpenIMServiceImpl implements OpenIMService {
                     List<FsImMsgSendDetail> imMsgSendDetailUrgeList = createImMsgSendLog("催课", batchSendCourseDTO, planSendTimeStamp, 1, batchUserIds, sendUnionId);
 
                     // 定时催课 - 缓存到 Redis
-                    String redisKey = "openIm:batchSendMsg:urgeCourse";
-                    Map<String, Object> redisMap = redisCache.getCacheMap(redisKey);
-                    if (redisMap == null) {
-                        redisMap = new HashMap<>();
+                    String redisUrgeKey = "openIm:batchSendMsg:urgeCourse";
+                    Map<String, Object> redisUrgeMap = redisCache.getCacheMap(redisUrgeKey);
+                    if (redisUrgeMap == null) {
+                        redisUrgeMap = new HashMap<>();
                     }
 
-                    BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
-                    batchSendCourseAllDTO.setOpenImBatchMsgDTO(openImBatchUrgeCourse)
+                    BatchSendCourseAllDTO batchSendCourseUrgeAllDTO = new BatchSendCourseAllDTO();
+                    batchSendCourseUrgeAllDTO.setOpenImBatchMsgDTO(openImBatchUrgeCourse)
                             .setImMsgSendDetailList(imMsgSendDetailUrgeList);
 
                     // 使用唯一的 key:课程 ID+ 视频 ID+ 时间戳+logId
-                    String batchKey = batchSendCourseDTO.getCourseId() + ":" +
+                    String batchUrgeKey = batchSendCourseDTO.getCourseId() + ":" +
                             batchSendCourseDTO.getVideoId() + ":" +
                             batchSendCourseDTO.getUrgeTime().getTime() + ":" +
                             imMsgSendDetailUrgeList.get(0).getLogId();
 
-                    redisMap.put(batchKey, batchSendCourseAllDTO);
-                    redisCache.setCacheMap(redisKey, redisMap);
+                    redisUrgeMap.put(batchUrgeKey, batchSendCourseUrgeAllDTO);
+                    redisCache.setCacheMap(redisUrgeKey, redisUrgeMap);
 
                 }
-
             } catch (Exception e) {
                 failCount += batchUserIds.size();
                 log.error("批次 {}/{} 发送异常:{}", i, end, e.getMessage(), e);
@@ -1912,11 +1911,8 @@ public class OpenIMServiceImpl implements OpenIMService {
             String tagNames = Joiner.on(",").join(batchSendCourseDTO.getTagNames());
             fsImMsgSendLog.setTagNames(tagNames);
         }
-        if(sendType == 1){
-            fsImMsgSendLog.setSendStatus(2);
-        } else {
-            fsImMsgSendLog.setSendStatus(1);
-        }
+
+        fsImMsgSendLog.setSendStatus(2);
         if("发课".equals(logType)){
             // 发课
             fsImMsgSendLog.setPlanSendTime(new Date(planSendTimeStamp));
@@ -1937,11 +1933,7 @@ public class OpenIMServiceImpl implements OpenIMService {
                     .setCreateTime(new Date());
             Long id = Long.parseLong(userId.replaceFirst("^" + "U", ""));
             fsImMsgSendDetail.setUserId(id);
-            if (sendType == 1) {
-                fsImMsgSendDetail.setSendStatus(2);
-            } else {
-                fsImMsgSendDetail.setSendStatus(1);
-            }
+            fsImMsgSendDetail.setSendStatus(2);
             if("发课".equals(logType)) {
                 fsImMsgSendDetail.setPlanSendTime(new Date(planSendTimeStamp));
             } else {
@@ -1986,7 +1978,7 @@ public class OpenIMServiceImpl implements OpenIMService {
         if(openImResponseDTO.getErrCode() != 0){
             // 所有都发送失败
             List<FsImMsgSendDetail> allFailedList = imMsgSendDetailList.stream().map(v -> {
-                v.setSendStatus(1).setParamJson(batchMsgJson)
+                v.setSendStatus(3).setParamJson(batchMsgJson)
                         .setStatus(1)
                         .setResultMessage(responseJson)
                         .setExceptionInfo(errDltStr)
@@ -2014,7 +2006,7 @@ public class OpenIMServiceImpl implements OpenIMService {
                 String[] failedUserIds = openImBatchResponseDataDTO.getFailedUserIDs();
                 List<String> failedUserIdList = Arrays.asList(failedUserIds);
                 List<FsImMsgSendDetail> failedList = imMsgSendDetailList.stream().filter(v -> failedUserIdList.contains("U" + v.getUserId())).map(v -> {
-                    v.setSendStatus(1).setParamJson(batchMsgJson)
+                    v.setSendStatus(3).setParamJson(batchMsgJson)
                             .setStatus(1)
                             .setResultMessage(batchResponseJson)
                             .setExceptionInfo(exceptionInfo)