|
@@ -32,8 +32,12 @@ import com.fs.his.mapper.FsDoctorMapper;
|
|
|
import com.fs.his.mapper.FsFollowMapper;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.im.config.IMConfig;
|
|
|
+import com.fs.im.domain.FsImMsgSendDetail;
|
|
|
+import com.fs.im.domain.FsImMsgSendLog;
|
|
|
import com.fs.im.domain.ImSendLog;
|
|
|
import com.fs.im.dto.*;
|
|
|
+import com.fs.im.mapper.FsImMsgSendDetailMapper;
|
|
|
+import com.fs.im.mapper.FsImMsgSendLogMapper;
|
|
|
import com.fs.im.mapper.ImSendLogMapper;
|
|
|
import com.fs.im.service.OpenIMService;
|
|
|
import com.fs.im.vo.OpenImMsgCallBackVO;
|
|
@@ -87,6 +91,13 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
private FsCourseWatchLogMapper courseWatchLogMapper;
|
|
|
@Autowired
|
|
|
private ImSendLogMapper imSendLogMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsImMsgSendLogMapper fsImMsgSendLogMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsImMsgSendDetailMapper fsImMsgSendDetailMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsImMsgSendDetailServiceImpl fsImMsgSendDetailServiceImpl;
|
|
|
+
|
|
|
|
|
|
// @Value("${openIM.prefix}")
|
|
|
// private String openImPrefix;
|
|
@@ -1071,12 +1082,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 忽略null字段
|
|
|
|
|
|
//获取需要发送的人
|
|
|
- List<String> userIds;
|
|
|
- if(!batchSendCourseDTO.getUserIds().isEmpty()){
|
|
|
- userIds = batchSendCourseDTO.getUserIds().stream().map(v -> "U" + v).collect(Collectors.toList());
|
|
|
- } else {
|
|
|
- userIds = this.getRecvIds(batchSendCourseDTO);
|
|
|
- }
|
|
|
+ List<String> userIds = this.getRecvIds(batchSendCourseDTO);
|
|
|
|
|
|
//注册和添加好友
|
|
|
for (String userId : userIds) {
|
|
@@ -1084,14 +1090,85 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
checkAndImportFriendByDianBo(batchSendCourseDTO.getCompanyUserId(), uId,null,false);
|
|
|
}
|
|
|
|
|
|
- //组装消息数据
|
|
|
- PayloadDTO.Extension extension = new PayloadDTO.Extension();
|
|
|
- extension.setTitle(batchSendCourseDTO.getTitle());
|
|
|
- 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);
|
|
|
+ long planSendTimeStamp;
|
|
|
+ if(batchSendCourseDTO.getSendType() == 1 && batchSendCourseDTO.getSendTime() != null && batchSendCourseDTO.getSendTime().compareTo(new Date()) > 0){
|
|
|
+ planSendTimeStamp = batchSendCourseDTO.getSendTime().getTime();
|
|
|
+ } else {
|
|
|
+ planSendTimeStamp = System.currentTimeMillis();
|
|
|
+ }
|
|
|
+
|
|
|
+ OpenImBatchMsgDTO openImBatchMsgDTO = makeOpenImBatchMsgDTO(batchSendCourseDTO, fsUserCourse, objectMapper, userIds, planSendTimeStamp, "发课");
|
|
|
+
|
|
|
+ int sendType;
|
|
|
+ if(batchSendCourseDTO.getSendType() == 1 && batchSendCourseDTO.getSendTime() != null && batchSendCourseDTO.getSendTime().compareTo(new Date()) > 0) {
|
|
|
+ sendType = 1; //定时
|
|
|
+ } else {
|
|
|
+ sendType = 2; //实时
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建消息发送记录
|
|
|
+ List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog("发课",batchSendCourseDTO, planSendTimeStamp, sendType, userIds);
|
|
|
+
|
|
|
+ OpenImResponseDTO openImResponseDTO = new OpenImResponseDTO();
|
|
|
+ if(sendType == 1) {
|
|
|
+ // 定时发送
|
|
|
+// for (String userId : userIds) {
|
|
|
+ // 缓存定时发课消息
|
|
|
+ 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, fsUserCourse, objectMapper, userIds, planSendTimeStamp, "催课");
|
|
|
+
|
|
|
+ //缓存定时催课消息
|
|
|
+ List<FsImMsgSendDetail> imMsgSendDetailUrgeList = createImMsgSendLog("催课", batchSendCourseDTO, planSendTimeStamp, sendType, userIds);
|
|
|
+// for (String userId : userIds) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private OpenImBatchMsgDTO makeOpenImBatchMsgDTO(BatchSendCourseDTO batchSendCourseDTO, FsUserCourse fsUserCourse, ObjectMapper objectMapper, List<String> userIds, long planSendTimeStamp, String logType) throws JsonProcessingException {
|
|
|
+ PayloadDTO.Extension extension = new PayloadDTO.Extension();
|
|
|
+ OpenImBatchMsgDTO openImBatchMsgDTO = new OpenImBatchMsgDTO();
|
|
|
+ if("发课".equals(logType)){
|
|
|
+ extension.setTitle(batchSendCourseDTO.getTitle());
|
|
|
+ extension.setAppRealLink(batchSendCourseDTO.getUrl());
|
|
|
+ extension.setCourseUrl(fsUserCourse != null ? fsUserCourse.getImgUrl() : null);
|
|
|
+ extension.setSendTime(new Date(planSendTimeStamp));
|
|
|
+ openImBatchMsgDTO.setSendTime(planSendTimeStamp);
|
|
|
+ } else {
|
|
|
+ extension.setTitle(batchSendCourseDTO.getUrgeContent());
|
|
|
+ extension.setSendTime(batchSendCourseDTO.getUrgeTime());
|
|
|
+ openImBatchMsgDTO.setSendTime(batchSendCourseDTO.getUrgeTime().getTime());
|
|
|
+ }
|
|
|
|
|
|
PayloadDTO payload = new PayloadDTO();
|
|
|
payload.setData("course");
|
|
@@ -1111,7 +1188,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
offlinePushInfo.setIOSPushSound("");
|
|
|
|
|
|
// 设置发送的消息
|
|
|
- OpenImBatchMsgDTO openImBatchMsgDTO = new OpenImBatchMsgDTO();
|
|
|
+
|
|
|
openImBatchMsgDTO.setSendID("C" + batchSendCourseDTO.getCompanyUserId());
|
|
|
openImBatchMsgDTO.setRecvIDs(userIds);
|
|
|
openImBatchMsgDTO.setContent(content);
|
|
@@ -1119,125 +1196,122 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
openImBatchMsgDTO.setSessionType(1);
|
|
|
openImBatchMsgDTO.setIsOnlineOnly(false);
|
|
|
openImBatchMsgDTO.setNotOfflinePush(false);
|
|
|
- long planSendTimeStamp;
|
|
|
- if(batchSendCourseDTO.getSendTime() != null && batchSendCourseDTO.getSendTime().compareTo(new Date()) > 0){
|
|
|
- planSendTimeStamp = batchSendCourseDTO.getSendTime().getTime();
|
|
|
- } else {
|
|
|
- planSendTimeStamp = System.currentTimeMillis();
|
|
|
- }
|
|
|
- openImBatchMsgDTO.setSendTime(planSendTimeStamp);
|
|
|
openImBatchMsgDTO.setOfflinePushInfo(offlinePushInfo);
|
|
|
openImBatchMsgDTO.setIsSendAll(false);
|
|
|
-
|
|
|
- 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;
|
|
|
+ return openImBatchMsgDTO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public OpenImResponseDTO batchSendMsgTask(BatchSendCourseDTO batchSendCourseDTO, OpenImBatchMsgDTO openImBatchMsgDTO, Long project, Integer sendType) {
|
|
|
-
|
|
|
+ public OpenImResponseDTO batchSendCourseTask(BatchSendCourseDTO batchSendCourseDTO, OpenImBatchMsgDTO openImBatchMsgDTO, Long project, List<FsImMsgSendDetail> imMsgSendDetailList) {
|
|
|
log.info("批量发送课程消息: \n{}", JSON.toJSONString(openImBatchMsgDTO));
|
|
|
OpenImResponseDTO openImResponseDTO = openIMBatchSendMsg(openImBatchMsgDTO);
|
|
|
// openImBatchMsgDTO = null;
|
|
|
// content = null;
|
|
|
|
|
|
- //获取发送消息结果,成功后再生成看课记录和发送记录
|
|
|
+ //获取发送消息结果,成功后再生成看课记录和发送记录;
|
|
|
if(openImResponseDTO.getErrCode() == 0 && openImResponseDTO.getData() != null){
|
|
|
- Object data = openImResponseDTO.getData();
|
|
|
- OpenImBatchResponseDataDTO openImBatchResponseDataDTO = JSON.parseObject(JSON.toJSONString(data), OpenImBatchResponseDataDTO.class);
|
|
|
+ OpenImBatchResponseDataDTO openImBatchResponseDataDTO = JSON.parseObject(JSON.toJSONString(openImResponseDTO.getData()), OpenImBatchResponseDataDTO.class);
|
|
|
List<OpenImBatchResponseDataDTO.Results> results = openImBatchResponseDataDTO.getResults();
|
|
|
|
|
|
- // 生成发送记录
|
|
|
- this.batchInsertSendLogs(openImBatchMsgDTO, openImResponseDTO, openImBatchResponseDataDTO, sendType);
|
|
|
+ // 发送成功,生成看课记录
|
|
|
+ this.batchInsertWatchLogs(batchSendCourseDTO, results, project, imMsgSendDetailList);
|
|
|
+ }
|
|
|
|
|
|
- // 生成看课记录
|
|
|
- this.batchInsertWatchLogs(batchSendCourseDTO, results, project);
|
|
|
+ // 修改发送记录
|
|
|
+ this.updateImMsgSendLog(openImBatchMsgDTO, imMsgSendDetailList, openImResponseDTO, "发课");
|
|
|
|
|
|
- } else {
|
|
|
- // 生成发送记录
|
|
|
- this.batchInsertSendLogs(openImBatchMsgDTO, openImResponseDTO, null, sendType);
|
|
|
- log.error("发送消息失败,结果:{}", openImResponseDTO);
|
|
|
- throw new ServiceException("发送消息失败");
|
|
|
- }
|
|
|
+ return openImResponseDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public OpenImResponseDTO batchUrgeCourseTask(OpenImBatchMsgDTO openImBatchMsgDTO, List<FsImMsgSendDetail> imMsgSendDetailList) {
|
|
|
+ log.info("批量催课消息: \n{}", JSON.toJSONString(openImBatchMsgDTO));
|
|
|
+ OpenImResponseDTO openImResponseDTO = openIMBatchSendMsg(openImBatchMsgDTO);
|
|
|
|
|
|
+ // 修改发送记录
|
|
|
+ this.updateImMsgSendLog(openImBatchMsgDTO, imMsgSendDetailList, openImResponseDTO, "催课");
|
|
|
return openImResponseDTO;
|
|
|
}
|
|
|
|
|
|
private List<String> getRecvIds(BatchSendCourseDTO batchSendCourseDTO) {
|
|
|
- Map<String,Object> param = new HashMap<>();
|
|
|
- param.put("tagIds", batchSendCourseDTO.getTagIds());
|
|
|
- param.put("companyUserId", batchSendCourseDTO.getCompanyUserId());
|
|
|
- List<FsUserCompanyUser> fsUserCompanyUsers = fsUserCompanyUserMapper.selectFsUserCompanyUserByIds(param);
|
|
|
- if(fsUserCompanyUsers.isEmpty()){
|
|
|
- log.error("没有消息接收人,参数:{}", batchSendCourseDTO);
|
|
|
- throw new ServiceException("没有消息接收人");
|
|
|
+ List<String> userIds;
|
|
|
+ if(!batchSendCourseDTO.getUserIds().isEmpty()) {
|
|
|
+ userIds = batchSendCourseDTO.getUserIds().stream().map(v -> "U" + v).collect(Collectors.toList());
|
|
|
+ } else{
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
+ param.put("tagIds", batchSendCourseDTO.getTagIds());
|
|
|
+ param.put("companyUserId", batchSendCourseDTO.getCompanyUserId());
|
|
|
+ List<FsUserCompanyUser> fsUserCompanyUsers = fsUserCompanyUserMapper.selectFsUserCompanyUserByIds(param);
|
|
|
+ if(fsUserCompanyUsers.isEmpty()){
|
|
|
+ log.error("没有消息接收人,参数:{}", batchSendCourseDTO);
|
|
|
+ throw new ServiceException("没有消息接收人");
|
|
|
+ }
|
|
|
+ userIds = fsUserCompanyUsers.stream().map(v -> "U" + v.getUserId()).collect(Collectors.toList());
|
|
|
}
|
|
|
- return fsUserCompanyUsers.stream().map(v -> "U" + v.getUserId()).collect(Collectors.toList());
|
|
|
+ return userIds;
|
|
|
}
|
|
|
|
|
|
- private void batchInsertSendLogs(OpenImBatchMsgDTO openImBatchMsgDTO, OpenImResponseDTO openImResponseDTO, OpenImBatchResponseDataDTO openImBatchResponseDataDTO, Integer sendType) {
|
|
|
- List<ImSendLog> list = new LinkedList<>();
|
|
|
- if(openImResponseDTO.getErrCode() != 0){
|
|
|
- ImSendLog imSendLog = createImsendLog(openImBatchMsgDTO, openImBatchMsgDTO.getSendTime());
|
|
|
- imSendLog.setStatus(1);
|
|
|
- imSendLog.setResultMessage(JSON.toJSONString(openImResponseDTO.getErrMsg()));
|
|
|
- imSendLog.setExceptionInfo(JSON.toJSONString(openImResponseDTO.getErrDlt()));
|
|
|
- list.add(imSendLog);
|
|
|
- } else {
|
|
|
- if(openImBatchResponseDataDTO.getFailedUserIDs() != null) {
|
|
|
- for (String failedUserID : openImBatchResponseDataDTO.getFailedUserIDs()) {
|
|
|
- ImSendLog imSendLog = createImsendLog(openImBatchMsgDTO, openImBatchMsgDTO.getSendTime());
|
|
|
- imSendLog.setRecvId(failedUserID);
|
|
|
- imSendLog.setStatus(1);
|
|
|
- imSendLog.setResultMessage(JSON.toJSONString(openImBatchResponseDataDTO));
|
|
|
- list.add(imSendLog);
|
|
|
- }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建消息发送记录
|
|
|
+ */
|
|
|
+ private List<FsImMsgSendDetail> createImMsgSendLog(String logType, BatchSendCourseDTO batchSendCourseDTO, long planSendTimeStamp, int sendType, List<String> userIds) {
|
|
|
+ // 记录发送消息记录主表
|
|
|
+ FsImMsgSendLog fsImMsgSendLog = new FsImMsgSendLog();
|
|
|
+ BeanUtils.copyProperties(batchSendCourseDTO, fsImMsgSendLog);
|
|
|
+ fsImMsgSendLog.setCreateBy(batchSendCourseDTO.getCompanyUserId().toString());
|
|
|
+ fsImMsgSendLog.setCreateTime(new Date());
|
|
|
+ if("发课".equals(logType)){
|
|
|
+ // 发课
|
|
|
+ fsImMsgSendLog.setPlanSendTime(new Date(planSendTimeStamp));
|
|
|
+ fsImMsgSendLog.setSendTitle(batchSendCourseDTO.getTitle()).setMsgType(1);
|
|
|
+ if(sendType == 1){
|
|
|
+ fsImMsgSendLog.setSendStatus(2);
|
|
|
+ } else {
|
|
|
+ fsImMsgSendLog.setSendStatus(1);
|
|
|
}
|
|
|
- for (OpenImBatchResponseDataDTO.Results result : openImBatchResponseDataDTO.getResults()) {
|
|
|
- ImSendLog imSendLog = createImsendLog(openImBatchMsgDTO, openImBatchMsgDTO.getSendTime());
|
|
|
- imSendLog.setRecvId(result.getRecvID());
|
|
|
- imSendLog.setActualSendTime(new Date(result.getSendTime()));
|
|
|
- imSendLog.setSendType(sendType);
|
|
|
- imSendLog.setStatus(0);
|
|
|
- imSendLog.setResultMessage(JSON.toJSONString(openImBatchResponseDataDTO));
|
|
|
- list.add(imSendLog);
|
|
|
+ } else {
|
|
|
+ //催课
|
|
|
+ fsImMsgSendLog.setPlanSendTime(batchSendCourseDTO.getUrgeTime());
|
|
|
+ fsImMsgSendLog.setSendTitle(batchSendCourseDTO.getUrgeContent()).setMsgType(2).setIsUrgeCourse(1);
|
|
|
+ if(batchSendCourseDTO.getUrgeTime() != null && batchSendCourseDTO.getUrgeTime().compareTo(new Date()) > 0){
|
|
|
+ fsImMsgSendLog.setSendStatus(2);
|
|
|
+ } else{
|
|
|
+ fsImMsgSendLog.setSendStatus(1);
|
|
|
}
|
|
|
}
|
|
|
+ fsImMsgSendLogMapper.insert(fsImMsgSendLog);
|
|
|
|
|
|
- imSendLogMapper.insertImSendLogBatch(list);
|
|
|
- }
|
|
|
-
|
|
|
- private static ImSendLog createImsendLog(OpenImBatchMsgDTO openImBatchMsgDTO, long planSendTimeStamp) {
|
|
|
- ImSendLog imSendLog = new ImSendLog();
|
|
|
- imSendLog.setSendId(openImBatchMsgDTO.getSendID());
|
|
|
- imSendLog.setSendTitle(openImBatchMsgDTO.getOfflinePushInfo() != null ? openImBatchMsgDTO.getOfflinePushInfo().getTitle() : null);
|
|
|
- imSendLog.setPlanSendTime(new Date(planSendTimeStamp));
|
|
|
- imSendLog.setParamJson(JSON.toJSONString(openImBatchMsgDTO));
|
|
|
-
|
|
|
- return imSendLog;
|
|
|
+ // 记录发送消息记录详情
|
|
|
+ List<FsImMsgSendDetail> list = new LinkedList<>();
|
|
|
+ for (String userId : userIds) {
|
|
|
+ FsImMsgSendDetail fsImMsgSendDetail = new FsImMsgSendDetail();
|
|
|
+ BeanUtils.copyProperties(batchSendCourseDTO, fsImMsgSendDetail);
|
|
|
+ fsImMsgSendDetail.setLogId(fsImMsgSendLog.getLogId())
|
|
|
+ .setCreateTime(new Date());
|
|
|
+ Long id = Long.parseLong(userId.replaceFirst("^" + "U", ""));
|
|
|
+ fsImMsgSendDetail.setUserId(id);
|
|
|
+ if("发课".equals(logType)) {
|
|
|
+ fsImMsgSendDetail.setPlanSendTime(new Date(planSendTimeStamp));
|
|
|
+ if (sendType == 1) {
|
|
|
+ fsImMsgSendDetail.setSendStatus(2);
|
|
|
+ } else {
|
|
|
+ fsImMsgSendDetail.setSendStatus(1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fsImMsgSendDetail.setPlanSendTime(batchSendCourseDTO.getUrgeTime());
|
|
|
+ fsImMsgSendDetail.setSendStatus(2);
|
|
|
+ }
|
|
|
+ list.add(fsImMsgSendDetail);
|
|
|
+ }
|
|
|
+ fsImMsgSendDetailServiceImpl.saveBatch(list);
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
- public void batchInsertWatchLogs(BatchSendCourseDTO batchSendCourseDTO, List<OpenImBatchResponseDataDTO.Results> results, Long project) {
|
|
|
+ public void batchInsertWatchLogs(BatchSendCourseDTO batchSendCourseDTO, List<OpenImBatchResponseDataDTO.Results> results, Long project, List<FsImMsgSendDetail> imMsgSendDetailList) {
|
|
|
+ Map<Long, FsImMsgSendDetail> map = imMsgSendDetailList.stream().collect(Collectors.toMap(FsImMsgSendDetail::getUserId, v -> v));
|
|
|
List<FsCourseWatchLog> watchLogsInsertList = new LinkedList<>();
|
|
|
for (OpenImBatchResponseDataDTO.Results result : results) {
|
|
|
FsCourseWatchLog fsCourseWatchLog = new FsCourseWatchLog();
|
|
@@ -1246,15 +1320,78 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
fsCourseWatchLog.setUserId(Long.parseLong(userId));
|
|
|
fsCourseWatchLog.setSendType(1);
|
|
|
fsCourseWatchLog.setDuration(0L);
|
|
|
- fsCourseWatchLog.setCreateTime(new Date());
|
|
|
+ fsCourseWatchLog.setCreateTime(new Date(result.getSendTime()));
|
|
|
fsCourseWatchLog.setLogType(3);
|
|
|
fsCourseWatchLog.setProject(project);
|
|
|
+ fsCourseWatchLog.setImMsgSendDetailId(map.get(Long.parseLong(userId)).getLogDetailId());
|
|
|
watchLogsInsertList.add(fsCourseWatchLog);
|
|
|
}
|
|
|
courseWatchLogMapper.insertFsCourseWatchLogBatch(watchLogsInsertList);
|
|
|
log.info("批量插入FsCourseWatchLog表完成,共插入 {} 条记录", watchLogsInsertList.size());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void updateImMsgSendLog(OpenImBatchMsgDTO openImBatchMsgDTO, List<FsImMsgSendDetail> imMsgSendDetailList, OpenImResponseDTO openImResponseDTO, String logType) {
|
|
|
+ List<FsImMsgSendDetail> updateList = new ArrayList<>();
|
|
|
+ if(openImResponseDTO.getErrCode() != 0){
|
|
|
+ // 所有都发送失败
|
|
|
+ List<FsImMsgSendDetail> allFailedList = imMsgSendDetailList.stream().map(v -> {
|
|
|
+ v.setSendStatus(1).setParamJson(JSON.toJSONString(openImBatchMsgDTO))
|
|
|
+ .setStatus(1)
|
|
|
+ .setResultMessage(JSON.toJSONString(openImResponseDTO))
|
|
|
+ .setExceptionInfo(openImResponseDTO.getErrDlt())
|
|
|
+ .setUpdateTime(new Date());
|
|
|
+ return v;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ updateList.addAll(allFailedList);
|
|
|
+
|
|
|
+ log.error("发送消息失败,结果:{}", openImResponseDTO);
|
|
|
+ throw new ServiceException("发送消息失败");
|
|
|
+ } else {
|
|
|
+ OpenImBatchResponseDataDTO openImBatchResponseDataDTO = JSON.parseObject(JSON.toJSONString(openImResponseDTO.getData()), OpenImBatchResponseDataDTO.class);
|
|
|
+ if(openImBatchResponseDataDTO != null && openImBatchResponseDataDTO.getFailedUserIDs() != null) {
|
|
|
+ //发送失败的
|
|
|
+ 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(JSON.toJSONString(openImBatchMsgDTO))
|
|
|
+ .setStatus(1)
|
|
|
+ .setResultMessage(JSON.toJSONString(openImBatchResponseDataDTO))
|
|
|
+ .setExceptionInfo(JSON.toJSONString(openImResponseDTO.getErrDlt()))
|
|
|
+ .setUpdateTime(new Date());
|
|
|
+ return v;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ updateList.addAll(failedList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送成功的
|
|
|
+ if(openImBatchResponseDataDTO != null){
|
|
|
+ List<OpenImBatchResponseDataDTO.Results> results = openImBatchResponseDataDTO.getResults();
|
|
|
+ Map<String, OpenImBatchResponseDataDTO.Results> resultsMap = results.stream().collect(Collectors.toMap(OpenImBatchResponseDataDTO.Results::getRecvID, v -> v));
|
|
|
+ List<String> actualRecvIdList = openImBatchResponseDataDTO.getResults().stream().map(OpenImBatchResponseDataDTO.Results::getRecvID).collect(Collectors.toList());
|
|
|
+ List<FsImMsgSendDetail> successList = imMsgSendDetailList.stream().filter(v -> actualRecvIdList.contains("U" + v.getUserId())).map(v -> {
|
|
|
+ v.setActualSendTime(new Date(resultsMap.get("U" + v.getUserId()).getSendTime()))
|
|
|
+ .setSendStatus(1).setParamJson(JSON.toJSONString(openImBatchMsgDTO))
|
|
|
+ .setStatus(0)
|
|
|
+ .setResultMessage(JSON.toJSONString(openImBatchResponseDataDTO))
|
|
|
+ .setUpdateTime(new Date());
|
|
|
+ return v;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ updateList.addAll(successList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fsImMsgSendDetailServiceImpl.updateBatchById(updateList);
|
|
|
+
|
|
|
+ // 更新记录主表
|
|
|
+ if("发课".equals(logType)) {
|
|
|
+ FsImMsgSendLog fsImMsgSendLog = new FsImMsgSendLog();
|
|
|
+ fsImMsgSendLog.setLogId(imMsgSendDetailList.get(0).getLogId());
|
|
|
+ fsImMsgSendLog.setSendStatus(1);
|
|
|
+ fsImMsgSendLog.setUpdateTime(new Date());
|
|
|
+ fsImMsgSendLogMapper.updateById(fsImMsgSendLog);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改好友信息
|
|
|
* @param ownerUserID
|