|
|
@@ -1173,8 +1173,9 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
return openImResponseDTO;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public OpenImResponseDTO batchSendCourseLimit(BatchSendCourseDTO batchSendCourseDTO) throws JsonProcessingException {
|
|
|
+ public OpenImResponseDTO batchSendCourseLimit(BatchSendCourseDTO batchSendCourseDTO) {
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 忽略 null 字段
|
|
|
|
|
|
@@ -1279,41 +1280,15 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
// 保存最后一个批次的响应
|
|
|
finalResponseDTO = responseDTO;
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- failCount += batchUserIds.size();
|
|
|
- log.error("批次 {}/{} 发送异常:{}", i, end, e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
+ //是否催课
|
|
|
+ if(batchSendCourseDTO.getIsUrgeCourse()){
|
|
|
+ // 组装催课消息数据
|
|
|
+ OpenImBatchMsgDTO openImBatchUrgeCourse = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, batchUserIds, planSendTimeStamp, "催课");
|
|
|
|
|
|
- // 设置汇总结果
|
|
|
- if (sendType == 2) { // 只有实时发送需要返回统计
|
|
|
- finalResponseDTO.setErrMsg(String.format("发送完成:总数=%d, 成功=%d, 失败=%d", totalSent, successCount, failCount));
|
|
|
- }
|
|
|
-
|
|
|
- //是否催课
|
|
|
- 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; //实时
|
|
|
- }
|
|
|
-
|
|
|
- // 催课也按批次拆分
|
|
|
- if (urgSendType == 1 && userIds.size() > BATCH_SIZE) {
|
|
|
- log.info("定时催课消息接收人{}人,超过{}人,拆分缓存", userIds.size(), BATCH_SIZE);
|
|
|
-
|
|
|
- for (int i = 0; i < userIds.size(); i += BATCH_SIZE) {
|
|
|
- int end = Math.min(i + BATCH_SIZE, userIds.size());
|
|
|
- List<String> batchUserIds = userIds.subList(i, end);
|
|
|
-
|
|
|
- OpenImBatchMsgDTO batchUrgeMsgDTO = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, batchUserIds, planSendTimeStamp, "催课");
|
|
|
- List<FsImMsgSendDetail> imMsgSendDetailUrgeList = createImMsgSendLog("催课", batchSendCourseDTO, planSendTimeStamp, urgSendType, batchUserIds, UUID.randomUUID().toString());
|
|
|
+ // 催课使用与发课相同的批次(batchUserIds),不需要再次拆分
|
|
|
+ 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) {
|
|
|
@@ -1321,10 +1296,10 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
}
|
|
|
|
|
|
BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
|
|
|
- batchSendCourseAllDTO.setOpenImBatchMsgDTO(batchUrgeMsgDTO)
|
|
|
+ batchSendCourseAllDTO.setOpenImBatchMsgDTO(openImBatchUrgeCourse)
|
|
|
.setImMsgSendDetailList(imMsgSendDetailUrgeList);
|
|
|
|
|
|
- // 使用唯一的 key
|
|
|
+ // 使用唯一的 key:课程 ID+ 视频 ID+ 时间戳+logId
|
|
|
String batchKey = batchSendCourseDTO.getCourseId() + ":" +
|
|
|
batchSendCourseDTO.getVideoId() + ":" +
|
|
|
batchSendCourseDTO.getUrgeTime().getTime() + ":" +
|
|
|
@@ -1332,30 +1307,23 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
|
|
|
redisMap.put(batchKey, batchSendCourseAllDTO);
|
|
|
redisCache.setCacheMap(redisKey, redisMap);
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 不超过 100 人或实时发送,按原逻辑
|
|
|
- List<FsImMsgSendDetail> imMsgSendDetailUrgeList = createImMsgSendLog("催课", batchSendCourseDTO, planSendTimeStamp, urgSendType, userIds, UUID.randomUUID().toString());
|
|
|
- String redisKey = "openIm:batchSendMsg:urgeCourse";
|
|
|
- Map<String, Object> redisMap = new HashMap<>();
|
|
|
- BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
|
|
|
- batchSendCourseAllDTO.setOpenImBatchMsgDTO(openImBatchUrgeCourse)
|
|
|
- .setImMsgSendDetailList(imMsgSendDetailUrgeList);
|
|
|
-
|
|
|
- String batchKey = batchSendCourseDTO.getCourseId()+":"+batchSendCourseDTO.getVideoId()+":"+batchSendCourseDTO.getUrgeTime().getTime();
|
|
|
- if (urgSendType == 1) {
|
|
|
- batchKey += ":0:" + imMsgSendDetailUrgeList.get(0).getLogId();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- redisMap.put(batchKey, batchSendCourseAllDTO);
|
|
|
- redisCache.setCacheMap(redisKey, redisMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ failCount += batchUserIds.size();
|
|
|
+ log.error("批次 {}/{} 发送异常:{}", i, end, e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 设置汇总结果
|
|
|
+ if (sendType == 2) { // 只有实时发送需要返回统计
|
|
|
+ finalResponseDTO.setErrMsg(String.format("发送完成:总数=%d, 成功=%d, 失败=%d", totalSent, successCount, failCount));
|
|
|
+ }
|
|
|
+
|
|
|
return finalResponseDTO;
|
|
|
}
|
|
|
|
|
|
-// ... existing code ...
|
|
|
|
|
|
|
|
|
private OpenImBatchMsgDTO makeOpenImBatchMsgDTO(BatchSendCourseDTO batchSendCourseDTO, String courseUrl, ObjectMapper objectMapper, List<String> userIds, long planSendTimeStamp, String logType) throws JsonProcessingException {
|