|
|
@@ -22,6 +22,7 @@ import com.fs.course.domain.FsUserCourse;
|
|
|
import com.fs.course.dto.BatchSendCourseAllDTO;
|
|
|
import com.fs.course.dto.BatchSendCourseDTO;
|
|
|
import com.fs.course.dto.BatchUrgeCourseDTO;
|
|
|
+import com.fs.course.dto.BatchUrgeCourseTaskDTO;
|
|
|
import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
import com.fs.course.mapper.FsUserCompanyUserMapper;
|
|
|
import com.fs.course.mapper.FsUserCourseMapper;
|
|
|
@@ -1341,6 +1342,123 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
return openImResponseDTO;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public OpenImResponseDTO batchUrgeCourseTaskCreate(BatchUrgeCourseTaskDTO batchUrgeCourseTaskDTO) throws JsonProcessingException {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
|
+
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("companyUserId", batchUrgeCourseTaskDTO.getCompanyUserId());
|
|
|
+ param.put("projectId", batchUrgeCourseTaskDTO.getProjectId());
|
|
|
+ List<FsUserCompanyUser> fsUserCompanyUsers = fsUserCompanyUserMapper.selectFsUserCompanyUserByIds(param);
|
|
|
+ if (CollectionUtils.isEmpty(fsUserCompanyUsers)) {
|
|
|
+ throw new ServiceException("没有消息接收人");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> rawUserIds = fsUserCompanyUsers.stream()
|
|
|
+ .map(FsUserCompanyUser::getUserId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(rawUserIds)) {
|
|
|
+ throw new ServiceException("没有消息接收人");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FsCourseWatchLog> watchCourseByVideoList = fsCourseWatchLogMapper.getWatchCourseByVideoId(batchUrgeCourseTaskDTO.getVideoId(), rawUserIds);
|
|
|
+ Map<Long, List<FsCourseWatchLog>> watchLogMap = CollectionUtils.isEmpty(watchCourseByVideoList)
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : watchCourseByVideoList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(v -> v.getUserId() != null)
|
|
|
+ .collect(Collectors.groupingBy(FsCourseWatchLog::getUserId));
|
|
|
+
|
|
|
+ List<String> userIds;
|
|
|
+ if (Objects.equals(batchUrgeCourseTaskDTO.getTaskType(), 1)) {
|
|
|
+ userIds = rawUserIds.stream()
|
|
|
+ .filter(userId -> {
|
|
|
+ List<FsCourseWatchLog> logs = watchLogMap.get(userId);
|
|
|
+ return CollectionUtils.isEmpty(logs) || logs.stream()
|
|
|
+ .map(FsCourseWatchLog::getLogType)
|
|
|
+ .allMatch(logType -> logType == null || logType == 3);
|
|
|
+ })
|
|
|
+ .map(userId -> "U" + userId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else if (Objects.equals(batchUrgeCourseTaskDTO.getTaskType(), 2)) {
|
|
|
+ userIds = rawUserIds.stream()
|
|
|
+ .filter(userId -> {
|
|
|
+ List<FsCourseWatchLog> logs = watchLogMap.get(userId);
|
|
|
+ return CollectionUtils.isEmpty(logs) || logs.stream()
|
|
|
+ .map(FsCourseWatchLog::getLogType)
|
|
|
+ .noneMatch(logType -> logType != null && logType == 2);
|
|
|
+ })
|
|
|
+ .map(userId -> "U" + userId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("催课任务类型不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(userIds)) {
|
|
|
+ throw new ServiceException("没有符合条件的催课用户");
|
|
|
+ }
|
|
|
+
|
|
|
+ BatchSendCourseDTO batchSendCourseDTO = new BatchSendCourseDTO();
|
|
|
+ BeanUtils.copyProperties(batchUrgeCourseTaskDTO, batchSendCourseDTO);
|
|
|
+ batchSendCourseDTO.setId(batchUrgeCourseTaskDTO.getPeriodDaysId());
|
|
|
+ batchSendCourseDTO.setSendType(1);
|
|
|
+ batchSendCourseDTO.setIsUrgeCourse(true);
|
|
|
+ batchSendCourseDTO.setUrgeTime(batchUrgeCourseTaskDTO.getUrgeTime());
|
|
|
+ if (Boolean.TRUE.equals(batchUrgeCourseTaskDTO.getSendCourse())) {
|
|
|
+ batchSendCourseDTO.setTitle(batchUrgeCourseTaskDTO.getTitle());
|
|
|
+ } else {
|
|
|
+ batchSendCourseDTO.setTitle(batchUrgeCourseTaskDTO.getUrgeContent());
|
|
|
+ }
|
|
|
+
|
|
|
+ OpenImBatchMsgDTO openImBatchMsgDTO = makeOpenImBatchMsgDTO(
|
|
|
+ batchSendCourseDTO,
|
|
|
+ null,
|
|
|
+ objectMapper,
|
|
|
+ userIds,
|
|
|
+ batchUrgeCourseTaskDTO.getUrgeTime().getTime(),
|
|
|
+ "催课"
|
|
|
+ );
|
|
|
+
|
|
|
+ String sendUnionId = UUID.randomUUID().toString();
|
|
|
+ List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog(
|
|
|
+ "催课",
|
|
|
+ batchSendCourseDTO,
|
|
|
+ batchUrgeCourseTaskDTO.getUrgeTime().getTime(),
|
|
|
+ 1,
|
|
|
+ userIds,
|
|
|
+ sendUnionId
|
|
|
+ );
|
|
|
+
|
|
|
+ String redisKey = "openIm:batchSendMsg:urgeCourse";
|
|
|
+ Map<String, Object> redisMap = redisCache.getCacheMap(redisKey);
|
|
|
+ if (redisMap == null) {
|
|
|
+ redisMap = new HashMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
|
|
|
+ batchSendCourseAllDTO.setBatchSendCourseDTO(batchSendCourseDTO)
|
|
|
+ .setOpenImBatchMsgDTO(openImBatchMsgDTO)
|
|
|
+ .setImMsgSendDetailList(imMsgSendDetailList);
|
|
|
+
|
|
|
+ String batchKey = batchUrgeCourseTaskDTO.getCourseId() + ":"
|
|
|
+ + batchUrgeCourseTaskDTO.getVideoId() + ":"
|
|
|
+ + batchUrgeCourseTaskDTO.getUrgeTime().getTime() + ":"
|
|
|
+ + imMsgSendDetailList.get(0).getLogId();
|
|
|
+ redisMap.put(batchKey, batchSendCourseAllDTO);
|
|
|
+ redisCache.setCacheMap(redisKey, redisMap);
|
|
|
+
|
|
|
+ OpenImResponseDTO responseDTO = new OpenImResponseDTO();
|
|
|
+ responseDTO.setErrCode(0);
|
|
|
+ responseDTO.setErrMsg("催课任务创建成功,待消息发送");
|
|
|
+ return responseDTO;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public OpenImResponseDTO batchUrgeCourse(BatchUrgeCourseDTO batchUrgeCourseDTO, FsImMsgSendLog fsImMsgSendLog, String url) throws JsonProcessingException {
|