|
@@ -18,6 +18,7 @@ import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
|
import com.fs.course.domain.FsUserCompanyUser;
|
|
|
import com.fs.course.domain.FsUserCourse;
|
|
|
+import com.fs.course.dto.BatchSendCourseAllDTO;
|
|
|
import com.fs.course.dto.BatchSendCourseDTO;
|
|
|
import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
import com.fs.course.mapper.FsUserCompanyUserMapper;
|
|
@@ -1089,6 +1090,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
extension.setAppRealLink(batchSendCourseDTO.getUrl());
|
|
|
extension.setSendTime(new Date());
|
|
|
FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(batchSendCourseDTO.getCourseId());
|
|
|
+ Long project = fsUserCourse != null ? fsUserCourse.getProject() : null;
|
|
|
extension.setCourseUrl(fsUserCourse != null ? fsUserCourse.getImgUrl() : null);
|
|
|
|
|
|
PayloadDTO payload = new PayloadDTO();
|
|
@@ -1127,7 +1129,34 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
openImBatchMsgDTO.setOfflinePushInfo(offlinePushInfo);
|
|
|
openImBatchMsgDTO.setIsSendAll(false);
|
|
|
|
|
|
- log.info("批量发送课程消息: \n{}", JSON.toJSONString(openImBatchMsgDTO));
|
|
|
+ OpenImResponseDTO openImResponseDTO = new OpenImResponseDTO();
|
|
|
+ // 保存发送时间到缓存中
|
|
|
+ if(batchSendCourseDTO.getSendTime() != null && batchSendCourseDTO.getSendTime().compareTo(new Date()) > 0) {
|
|
|
+ // 定时发送
|
|
|
+ for (String userId : userIds) {
|
|
|
+ String redisKey = "openIm:batchSendMsg";
|
|
|
+ Map<String, Object> redisMap = new HashMap<>();
|
|
|
+ BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
|
|
|
+ batchSendCourseAllDTO.setBatchSendCourseDTO(batchSendCourseDTO).setOpenImBatchMsgDTO(openImBatchMsgDTO).setProject(project);
|
|
|
+ redisMap.put(batchSendCourseDTO.getCourseId()+":"+batchSendCourseDTO.getVideoId()+":"+userId+":"+batchSendCourseDTO.getSendTime().getTime()
|
|
|
+ , batchSendCourseAllDTO);
|
|
|
+ redisCache.setCacheMap(redisKey, redisMap);
|
|
|
+ }
|
|
|
+ openImResponseDTO.setErrCode(0);
|
|
|
+ openImResponseDTO.setErrMsg("计划发送创建成功,待消息发送");
|
|
|
+ } else {
|
|
|
+ // 实时发送
|
|
|
+ openImResponseDTO = this.batchSendMsgTask(batchSendCourseDTO, openImBatchMsgDTO, project, 2);
|
|
|
+ openImResponseDTO.setErrMsg("实时发送成功");
|
|
|
+ }
|
|
|
+ return openImResponseDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public OpenImResponseDTO batchSendMsgTask(BatchSendCourseDTO batchSendCourseDTO, OpenImBatchMsgDTO openImBatchMsgDTO, Long project, Integer sendType) {
|
|
|
+
|
|
|
+ log.info("批量发送课程消息: \n{}", JSON.toJSONString(openImBatchMsgDTO));
|
|
|
OpenImResponseDTO openImResponseDTO = openIMBatchSendMsg(openImBatchMsgDTO);
|
|
|
// openImBatchMsgDTO = null;
|
|
|
// content = null;
|
|
@@ -1139,14 +1168,14 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
List<OpenImBatchResponseDataDTO.Results> results = openImBatchResponseDataDTO.getResults();
|
|
|
|
|
|
// 生成发送记录
|
|
|
- this.batchInsertSendLogs(openImBatchMsgDTO, openImResponseDTO, openImBatchResponseDataDTO, planSendTimeStamp);
|
|
|
+ this.batchInsertSendLogs(openImBatchMsgDTO, openImResponseDTO, openImBatchResponseDataDTO, sendType);
|
|
|
|
|
|
// 生成看课记录
|
|
|
- this.batchInsertWatchLogs(batchSendCourseDTO, results, fsUserCourse);
|
|
|
+ this.batchInsertWatchLogs(batchSendCourseDTO, results, project);
|
|
|
|
|
|
} else {
|
|
|
// 生成发送记录
|
|
|
- this.batchInsertSendLogs(openImBatchMsgDTO, openImResponseDTO, null, planSendTimeStamp);
|
|
|
+ this.batchInsertSendLogs(openImBatchMsgDTO, openImResponseDTO, null, sendType);
|
|
|
log.error("发送消息失败,结果:{}", openImResponseDTO);
|
|
|
throw new ServiceException("发送消息失败");
|
|
|
}
|
|
@@ -1166,10 +1195,10 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
return fsUserCompanyUsers.stream().map(v -> "U" + v.getUserId()).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- private void batchInsertSendLogs(OpenImBatchMsgDTO openImBatchMsgDTO, OpenImResponseDTO openImResponseDTO, OpenImBatchResponseDataDTO openImBatchResponseDataDTO, long planSendTimeStamp) {
|
|
|
+ private void batchInsertSendLogs(OpenImBatchMsgDTO openImBatchMsgDTO, OpenImResponseDTO openImResponseDTO, OpenImBatchResponseDataDTO openImBatchResponseDataDTO, Integer sendType) {
|
|
|
List<ImSendLog> list = new LinkedList<>();
|
|
|
if(openImResponseDTO.getErrCode() != 0){
|
|
|
- ImSendLog imSendLog = createImsendLog(openImBatchMsgDTO, planSendTimeStamp);
|
|
|
+ ImSendLog imSendLog = createImsendLog(openImBatchMsgDTO, openImBatchMsgDTO.getSendTime());
|
|
|
imSendLog.setStatus(1);
|
|
|
imSendLog.setResultMessage(JSON.toJSONString(openImResponseDTO.getErrMsg()));
|
|
|
imSendLog.setExceptionInfo(JSON.toJSONString(openImResponseDTO.getErrDlt()));
|
|
@@ -1177,24 +1206,20 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
} else {
|
|
|
if(openImBatchResponseDataDTO.getFailedUserIDs() != null) {
|
|
|
for (String failedUserID : openImBatchResponseDataDTO.getFailedUserIDs()) {
|
|
|
- ImSendLog imSendLog = createImsendLog(openImBatchMsgDTO, planSendTimeStamp);
|
|
|
+ ImSendLog imSendLog = createImsendLog(openImBatchMsgDTO, openImBatchMsgDTO.getSendTime());
|
|
|
imSendLog.setRecvId(failedUserID);
|
|
|
imSendLog.setStatus(1);
|
|
|
- imSendLog.setResultMessage(JSON.toJSONString(openImBatchResponseDataDTO.getResults()));
|
|
|
+ imSendLog.setResultMessage(JSON.toJSONString(openImBatchResponseDataDTO));
|
|
|
list.add(imSendLog);
|
|
|
}
|
|
|
}
|
|
|
for (OpenImBatchResponseDataDTO.Results result : openImBatchResponseDataDTO.getResults()) {
|
|
|
- ImSendLog imSendLog = createImsendLog(openImBatchMsgDTO, planSendTimeStamp);
|
|
|
+ ImSendLog imSendLog = createImsendLog(openImBatchMsgDTO, openImBatchMsgDTO.getSendTime());
|
|
|
imSendLog.setRecvId(result.getRecvID());
|
|
|
imSendLog.setActualSendTime(new Date(result.getSendTime()));
|
|
|
- if(planSendTimeStamp == result.getSendTime()){
|
|
|
- imSendLog.setSendType(2);
|
|
|
- } else {
|
|
|
- imSendLog.setSendType(1);
|
|
|
- }
|
|
|
+ imSendLog.setSendType(sendType);
|
|
|
imSendLog.setStatus(0);
|
|
|
- imSendLog.setResultMessage(JSON.toJSONString(openImBatchResponseDataDTO.getResults()));
|
|
|
+ imSendLog.setResultMessage(JSON.toJSONString(openImBatchResponseDataDTO));
|
|
|
list.add(imSendLog);
|
|
|
}
|
|
|
}
|
|
@@ -1212,8 +1237,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
return imSendLog;
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
- public void batchInsertWatchLogs(BatchSendCourseDTO batchSendCourseDTO, List<OpenImBatchResponseDataDTO.Results> results, FsUserCourse fsUserCourse) {
|
|
|
+ public void batchInsertWatchLogs(BatchSendCourseDTO batchSendCourseDTO, List<OpenImBatchResponseDataDTO.Results> results, Long project) {
|
|
|
List<FsCourseWatchLog> watchLogsInsertList = new LinkedList<>();
|
|
|
for (OpenImBatchResponseDataDTO.Results result : results) {
|
|
|
FsCourseWatchLog fsCourseWatchLog = new FsCourseWatchLog();
|
|
@@ -1224,7 +1248,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
fsCourseWatchLog.setDuration(0L);
|
|
|
fsCourseWatchLog.setCreateTime(new Date());
|
|
|
fsCourseWatchLog.setLogType(3);
|
|
|
- fsCourseWatchLog.setProject(fsUserCourse != null ? fsUserCourse.getProject() : null);
|
|
|
+ fsCourseWatchLog.setProject(project);
|
|
|
watchLogsInsertList.add(fsCourseWatchLog);
|
|
|
}
|
|
|
courseWatchLogMapper.insertFsCourseWatchLogBatch(watchLogsInsertList);
|