|
@@ -20,6 +20,7 @@ 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.dto.BatchUrgeCourseDTO;
|
|
|
import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
import com.fs.course.mapper.FsUserCompanyUserMapper;
|
|
|
import com.fs.course.mapper.FsUserCourseMapper;
|
|
@@ -44,6 +45,7 @@ import com.fs.im.vo.OpenImMsgCallBackVO;
|
|
|
import com.fs.im.vo.OpenImResponseDTOTest;
|
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
import com.github.pagehelper.util.StringUtil;
|
|
|
+import com.google.common.base.Joiner;
|
|
|
import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
@@ -97,6 +99,8 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
private FsImMsgSendDetailMapper fsImMsgSendDetailMapper;
|
|
|
@Autowired
|
|
|
private FsImMsgSendDetailServiceImpl fsImMsgSendDetailServiceImpl;
|
|
|
+ @Autowired
|
|
|
+ private FsCourseWatchLogMapper fsCourseWatchLogMapper;
|
|
|
|
|
|
|
|
|
// @Value("${openIM.prefix}")
|
|
@@ -1100,7 +1104,8 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
planSendTimeStamp = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
- OpenImBatchMsgDTO openImBatchMsgDTO = makeOpenImBatchMsgDTO(batchSendCourseDTO, fsUserCourse, objectMapper, userIds, planSendTimeStamp, "发课");
|
|
|
+ String courseUrl = fsUserCourse != null ? fsUserCourse.getImgUrl() : null;
|
|
|
+ OpenImBatchMsgDTO openImBatchMsgDTO = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, userIds, planSendTimeStamp, "发课");
|
|
|
|
|
|
int sendType;
|
|
|
if(batchSendCourseDTO.getSendType() == 1 && batchSendCourseDTO.getSendTime() != null && batchSendCourseDTO.getSendTime().compareTo(new Date()) > 0) {
|
|
@@ -1110,22 +1115,21 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
}
|
|
|
|
|
|
// 创建消息发送记录
|
|
|
- List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog("发课",batchSendCourseDTO, planSendTimeStamp, sendType, userIds);
|
|
|
+ String sendUnionId = UUID.randomUUID().toString();
|
|
|
+ List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog("发课",batchSendCourseDTO, planSendTimeStamp, sendType, userIds, sendUnionId);
|
|
|
|
|
|
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);
|
|
|
-// }
|
|
|
+ // 缓存定时发课消息
|
|
|
+ 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 {
|
|
@@ -1137,37 +1141,41 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
//是否催课
|
|
|
if(batchSendCourseDTO.getIsUrgeCourse()){
|
|
|
// 组装催课消息数据
|
|
|
- OpenImBatchMsgDTO openImBatchUrgeCourse = makeOpenImBatchMsgDTO(batchSendCourseDTO, fsUserCourse, objectMapper, userIds, planSendTimeStamp, "催课");
|
|
|
+ OpenImBatchMsgDTO openImBatchUrgeCourse = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, 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);
|
|
|
-// }
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
- private OpenImBatchMsgDTO makeOpenImBatchMsgDTO(BatchSendCourseDTO batchSendCourseDTO, FsUserCourse fsUserCourse, ObjectMapper objectMapper, List<String> userIds, long planSendTimeStamp, String logType) throws JsonProcessingException {
|
|
|
+ private OpenImBatchMsgDTO makeOpenImBatchMsgDTO(BatchSendCourseDTO batchSendCourseDTO, String courseUrl, 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.setCourseUrl(courseUrl);
|
|
|
extension.setSendTime(new Date(planSendTimeStamp));
|
|
|
openImBatchMsgDTO.setSendTime(planSendTimeStamp);
|
|
|
} else {
|
|
|
extension.setTitle(batchSendCourseDTO.getUrgeContent());
|
|
|
- extension.setSendTime(batchSendCourseDTO.getUrgeTime());
|
|
|
- openImBatchMsgDTO.setSendTime(batchSendCourseDTO.getUrgeTime().getTime());
|
|
|
+ extension.setSendTime(batchSendCourseDTO.getUrgeTime() != null ? batchSendCourseDTO.getUrgeTime() : new Date());
|
|
|
+ openImBatchMsgDTO.setSendTime(batchSendCourseDTO.getUrgeTime() != null ? batchSendCourseDTO.getUrgeTime().getTime() : System.currentTimeMillis());
|
|
|
}
|
|
|
|
|
|
PayloadDTO payload = new PayloadDTO();
|
|
@@ -1235,6 +1243,60 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
return openImResponseDTO;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public OpenImResponseDTO batchUrgeCourse(BatchUrgeCourseDTO batchUrgeCourseDTO, FsImMsgSendLog fsImMsgSendLog, String url) throws JsonProcessingException {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 忽略null字段
|
|
|
+
|
|
|
+ FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(fsImMsgSendLog.getCourseId());
|
|
|
+ String courseUrl = fsUserCourse != null ? fsUserCourse.getImgUrl() : null;
|
|
|
+
|
|
|
+ FsImMsgSendDetail fsImMsgSendDetail = new FsImMsgSendDetail();
|
|
|
+ fsImMsgSendDetail.setLogId(fsImMsgSendLog.getLogId());
|
|
|
+ List<FsImMsgSendDetail> fsImMsgSendDetails = fsImMsgSendDetailMapper.selectFsImMsgSendDetailList(fsImMsgSendDetail);
|
|
|
+ List<Long> userIdList = fsImMsgSendDetails.stream().map(FsImMsgSendDetail::getUserId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 过滤掉已完课的用户,已完课的用户不发送;
|
|
|
+ // 如果全部完课,则提示
|
|
|
+ List<FsCourseWatchLog> watchCourseByVideoList = fsCourseWatchLogMapper.getWatchCourseByVideoId(fsImMsgSendLog.getVideoId(), userIdList);
|
|
|
+ List<String> userIds = watchCourseByVideoList.stream().filter(v -> v.getLogType() != 2).map(v -> "U" + v.getUserId()).collect(Collectors.toList());
|
|
|
+ OpenImResponseDTO openImResponseDTO = new OpenImResponseDTO();
|
|
|
+ if(userIds.isEmpty()){
|
|
|
+ openImResponseDTO.setErrCode(400);
|
|
|
+ openImResponseDTO.setErrMsg("用户都已完课,不需要催课");
|
|
|
+ return openImResponseDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是否需要发课
|
|
|
+ if(batchUrgeCourseDTO.getIsSendCourse()){
|
|
|
+ // 组装发课数据
|
|
|
+ BatchSendCourseDTO batchSendCourseDTO = new BatchSendCourseDTO();
|
|
|
+ BeanUtils.copyProperties(fsImMsgSendLog, batchSendCourseDTO);
|
|
|
+ batchSendCourseDTO.setTitle(batchUrgeCourseDTO.getTitle());
|
|
|
+ batchSendCourseDTO.setUrl(url);
|
|
|
+ batchSendCourseDTO.setId(fsImMsgSendLog.getPeriodDaysId());
|
|
|
+ OpenImBatchMsgDTO openImBatchMsgDTO = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, userIds, System.currentTimeMillis(), "发课");
|
|
|
+ log.info("一键催课-发课-批量发送课程消息: \n{}", JSON.toJSONString(openImBatchMsgDTO));
|
|
|
+ this.openIMBatchSendMsg(openImBatchMsgDTO);
|
|
|
+// List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog("发课",batchSendCourseDTO, System.currentTimeMillis(), 2, userIds, sendUnionId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 催课
|
|
|
+ // 组装催课消息
|
|
|
+ BatchSendCourseDTO batchSendCourseDTO = new BatchSendCourseDTO();
|
|
|
+ BeanUtils.copyProperties(fsImMsgSendLog, batchSendCourseDTO);
|
|
|
+ batchSendCourseDTO.setUrgeContent(batchUrgeCourseDTO.getUrgeContent());
|
|
|
+ batchSendCourseDTO.setId(fsImMsgSendLog.getPeriodDaysId());
|
|
|
+ OpenImBatchMsgDTO openImBatchMsgDTO = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, userIds, System.currentTimeMillis(), "催课");
|
|
|
+ log.info("一键催课-催课-批量催课消息: \n{}", JSON.toJSONString(openImBatchMsgDTO));
|
|
|
+ openImResponseDTO = this.openIMBatchSendMsg(openImBatchMsgDTO);
|
|
|
+
|
|
|
+ List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog("催课", batchSendCourseDTO, System.currentTimeMillis(), 2, userIds, fsImMsgSendLog.getSendUnionId());
|
|
|
+ this.updateImMsgSendLog(openImBatchMsgDTO, imMsgSendDetailList, openImResponseDTO, "催课");
|
|
|
+ return openImResponseDTO;
|
|
|
+ }
|
|
|
+
|
|
|
private List<String> getRecvIds(BatchSendCourseDTO batchSendCourseDTO) {
|
|
|
List<String> userIds;
|
|
|
if(!batchSendCourseDTO.getUserIds().isEmpty()) {
|
|
@@ -1257,30 +1319,37 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
/**
|
|
|
* 创建消息发送记录
|
|
|
*/
|
|
|
- private List<FsImMsgSendDetail> createImMsgSendLog(String logType, BatchSendCourseDTO batchSendCourseDTO, long planSendTimeStamp, int sendType, List<String> userIds) {
|
|
|
+ private List<FsImMsgSendDetail> createImMsgSendLog(String logType, BatchSendCourseDTO batchSendCourseDTO, long planSendTimeStamp, int sendType, List<String> userIds, String sendUnionId) {
|
|
|
// 记录发送消息记录主表
|
|
|
FsImMsgSendLog fsImMsgSendLog = new FsImMsgSendLog();
|
|
|
BeanUtils.copyProperties(batchSendCourseDTO, fsImMsgSendLog);
|
|
|
fsImMsgSendLog.setCreateBy(batchSendCourseDTO.getCompanyUserId().toString());
|
|
|
fsImMsgSendLog.setCreateTime(new Date());
|
|
|
+ fsImMsgSendLog.setSendUnionId(sendUnionId)
|
|
|
+ .setProjectId(batchSendCourseDTO
|
|
|
+ .getProjectId())
|
|
|
+ .setPeriodDaysId(batchSendCourseDTO.getId());
|
|
|
+ if(batchSendCourseDTO.getTagIds() != null && !batchSendCourseDTO.getTagIds().isEmpty()){
|
|
|
+ String tagIds = Joiner.on(",").join(batchSendCourseDTO.getTagIds());
|
|
|
+ fsImMsgSendLog.setTagIds(tagIds);
|
|
|
+ }
|
|
|
+ if(batchSendCourseDTO.getTagNames() != null && !batchSendCourseDTO.getTagNames().isEmpty()){
|
|
|
+ String tagNames = Joiner.on(",").join(batchSendCourseDTO.getTagNames());
|
|
|
+ fsImMsgSendLog.setTagNames(tagNames);
|
|
|
+ }
|
|
|
+ if(sendType == 1){
|
|
|
+ fsImMsgSendLog.setSendStatus(2);
|
|
|
+ } else {
|
|
|
+ fsImMsgSendLog.setSendStatus(1);
|
|
|
+ }
|
|
|
if("发课".equals(logType)){
|
|
|
// 发课
|
|
|
fsImMsgSendLog.setPlanSendTime(new Date(planSendTimeStamp));
|
|
|
fsImMsgSendLog.setSendTitle(batchSendCourseDTO.getTitle()).setMsgType(1);
|
|
|
- if(sendType == 1){
|
|
|
- fsImMsgSendLog.setSendStatus(2);
|
|
|
- } else {
|
|
|
- fsImMsgSendLog.setSendStatus(1);
|
|
|
- }
|
|
|
} 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);
|
|
|
- }
|
|
|
+ fsImMsgSendLog.setSendTitle(batchSendCourseDTO.getUrgeContent()).setMsgType(2);
|
|
|
}
|
|
|
fsImMsgSendLogMapper.insert(fsImMsgSendLog);
|
|
|
|
|
@@ -1293,16 +1362,15 @@ 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);
|
|
|
+ }
|
|
|
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);
|
|
|
}
|