|
@@ -1378,12 +1378,19 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
|
|
|
|
|
//是否催课
|
|
//是否催课
|
|
|
if(batchSendCourseDTO.getIsUrgeCourse()){
|
|
if(batchSendCourseDTO.getIsUrgeCourse()){
|
|
|
|
|
+ // 催课文本消息 Content 必填,空内容会导致 OpenIM TextElem 校验失败
|
|
|
|
|
+ if (StringUtils.isBlank(batchSendCourseDTO.getUrgeContent())) {
|
|
|
|
|
+ throw new ServiceException("催课内容不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (batchSendCourseDTO.getUrgeTime() == null) {
|
|
|
|
|
+ throw new ServiceException("催课时间不能为空");
|
|
|
|
|
+ }
|
|
|
// 组装催课消息数据
|
|
// 组装催课消息数据
|
|
|
OpenImBatchMsgDTO openImBatchUrgeCourse = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, userIds, planSendTimeStamp, "催课");
|
|
OpenImBatchMsgDTO openImBatchUrgeCourse = makeOpenImBatchMsgDTO(batchSendCourseDTO, courseUrl, objectMapper, userIds, planSendTimeStamp, "催课");
|
|
|
|
|
|
|
|
//缓存定时催课消息
|
|
//缓存定时催课消息
|
|
|
int urgSendType;
|
|
int urgSendType;
|
|
|
- if(batchSendCourseDTO.getUrgeTime() != null && batchSendCourseDTO.getUrgeTime().compareTo(new Date()) > 0) {
|
|
|
|
|
|
|
+ if(batchSendCourseDTO.getUrgeTime().compareTo(new Date()) > 0) {
|
|
|
urgSendType = 1; //定时
|
|
urgSendType = 1; //定时
|
|
|
} else {
|
|
} else {
|
|
|
urgSendType = 2; //实时
|
|
urgSendType = 2; //实时
|
|
@@ -1423,11 +1430,12 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
openImBatchMsgDTO.setContent(content);
|
|
openImBatchMsgDTO.setContent(content);
|
|
|
openImBatchMsgDTO.setContentType(110);
|
|
openImBatchMsgDTO.setContentType(110);
|
|
|
} else {
|
|
} else {
|
|
|
- // 催课
|
|
|
|
|
-// extension.setTitle(batchSendCourseDTO.getUrgeContent());
|
|
|
|
|
-// extension.setSendTime(batchSendCourseDTO.getUrgeTime() != null ? batchSendCourseDTO.getUrgeTime() : new Date());
|
|
|
|
|
|
|
+ // 催课:OpenIM contentType=101 文本消息,Content 必填
|
|
|
|
|
+ if (StringUtils.isBlank(batchSendCourseDTO.getUrgeContent())) {
|
|
|
|
|
+ throw new ServiceException("催课内容不能为空");
|
|
|
|
|
+ }
|
|
|
OpenImBatchMsgDTO.Content content = new OpenImBatchMsgDTO.Content();
|
|
OpenImBatchMsgDTO.Content content = new OpenImBatchMsgDTO.Content();
|
|
|
- content.setContent(batchSendCourseDTO.getUrgeContent());
|
|
|
|
|
|
|
+ content.setContent(batchSendCourseDTO.getUrgeContent().trim());
|
|
|
openImBatchMsgDTO.setContent(content);
|
|
openImBatchMsgDTO.setContent(content);
|
|
|
openImBatchMsgDTO.setContentType(101);
|
|
openImBatchMsgDTO.setContentType(101);
|
|
|
openImBatchMsgDTO.setSendTime(batchSendCourseDTO.getUrgeTime() != null ? batchSendCourseDTO.getUrgeTime().getTime() : System.currentTimeMillis());
|
|
openImBatchMsgDTO.setSendTime(batchSendCourseDTO.getUrgeTime() != null ? batchSendCourseDTO.getUrgeTime().getTime() : System.currentTimeMillis());
|
|
@@ -1479,6 +1487,19 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public OpenImResponseDTO batchUrgeCourseTask(OpenImBatchMsgDTO openImBatchMsgDTO, List<FsImMsgSendDetail> imMsgSendDetailList) {
|
|
public OpenImResponseDTO batchUrgeCourseTask(OpenImBatchMsgDTO openImBatchMsgDTO, List<FsImMsgSendDetail> imMsgSendDetailList) {
|
|
|
log.info("批量催课消息: \n{}", JSON.toJSONString(openImBatchMsgDTO));
|
|
log.info("批量催课消息: \n{}", JSON.toJSONString(openImBatchMsgDTO));
|
|
|
|
|
+ // 兜底:历史脏数据可能 Content 为空,避免反复打 OpenIM 报 TextElem.Content required
|
|
|
|
|
+ if (openImBatchMsgDTO == null
|
|
|
|
|
+ || openImBatchMsgDTO.getContent() == null
|
|
|
|
|
+ || StringUtils.isBlank(openImBatchMsgDTO.getContent().getContent())) {
|
|
|
|
|
+ log.error("催课消息内容为空,跳过发送。recvIDs={}", openImBatchMsgDTO != null ? openImBatchMsgDTO.getRecvIDs() : null);
|
|
|
|
|
+ OpenImResponseDTO failResp = new OpenImResponseDTO();
|
|
|
|
|
+ failResp.setErrCode(400);
|
|
|
|
|
+ failResp.setErrMsg("催课内容不能为空");
|
|
|
|
|
+ failResp.setErrDlt("TextElem.Content is required but empty");
|
|
|
|
|
+ // 直接落库失败状态并返回,避免再抛异常导致事务回滚后状态丢失
|
|
|
|
|
+ markUrgeCourseSendFailed(openImBatchMsgDTO, imMsgSendDetailList, failResp);
|
|
|
|
|
+ return failResp;
|
|
|
|
|
+ }
|
|
|
OpenImResponseDTO openImResponseDTO = openIMBatchSendMsg(openImBatchMsgDTO);
|
|
OpenImResponseDTO openImResponseDTO = openIMBatchSendMsg(openImBatchMsgDTO);
|
|
|
|
|
|
|
|
// 修改发送记录
|
|
// 修改发送记录
|
|
@@ -1486,6 +1507,34 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
return openImResponseDTO;
|
|
return openImResponseDTO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 催课发送前校验失败时,标记明细与主表为已处理失败(不抛异常,保证事务可提交)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void markUrgeCourseSendFailed(OpenImBatchMsgDTO openImBatchMsgDTO,
|
|
|
|
|
+ List<FsImMsgSendDetail> imMsgSendDetailList,
|
|
|
|
|
+ OpenImResponseDTO openImResponseDTO) {
|
|
|
|
|
+ if (imMsgSendDetailList == null || imMsgSendDetailList.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ List<FsImMsgSendDetail> updateList = imMsgSendDetailList.stream().map(v -> {
|
|
|
|
|
+ v.setSendStatus(1)
|
|
|
|
|
+ .setParamJson(openImBatchMsgDTO == null ? null : JSON.toJSONString(openImBatchMsgDTO))
|
|
|
|
|
+ .setStatus(1)
|
|
|
|
|
+ .setResultMessage(StringUtils.substring(JSON.toJSONString(openImResponseDTO), 0, 3999))
|
|
|
|
|
+ .setExceptionInfo(StringUtils.substring(openImResponseDTO.getErrDlt(), 0, 1999))
|
|
|
|
|
+ .setUpdateTime(now);
|
|
|
|
|
+ return v;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ fsImMsgSendDetailServiceImpl.updateBatchById(updateList);
|
|
|
|
|
+
|
|
|
|
|
+ FsImMsgSendLog fsImMsgSendLog = new FsImMsgSendLog();
|
|
|
|
|
+ fsImMsgSendLog.setLogId(imMsgSendDetailList.get(0).getLogId());
|
|
|
|
|
+ fsImMsgSendLog.setSendStatus(1);
|
|
|
|
|
+ fsImMsgSendLog.setUpdateTime(now);
|
|
|
|
|
+ fsImMsgSendLogMapper.updateById(fsImMsgSendLog);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public OpenImResponseDTO batchUrgeCourse(BatchUrgeCourseDTO batchUrgeCourseDTO, FsImMsgSendLog fsImMsgSendLog, String url) throws JsonProcessingException {
|
|
public OpenImResponseDTO batchUrgeCourse(BatchUrgeCourseDTO batchUrgeCourseDTO, FsImMsgSendLog fsImMsgSendLog, String url) throws JsonProcessingException {
|
|
@@ -1526,6 +1575,11 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 催课
|
|
// 催课
|
|
|
|
|
+ if (StringUtils.isBlank(batchUrgeCourseDTO.getUrgeContent())) {
|
|
|
|
|
+ openImResponseDTO.setErrCode(400);
|
|
|
|
|
+ openImResponseDTO.setErrMsg("催课内容不能为空");
|
|
|
|
|
+ return openImResponseDTO;
|
|
|
|
|
+ }
|
|
|
// 组装催课消息
|
|
// 组装催课消息
|
|
|
BatchSendCourseDTO batchSendCourseDTO = new BatchSendCourseDTO();
|
|
BatchSendCourseDTO batchSendCourseDTO = new BatchSendCourseDTO();
|
|
|
BeanUtils.copyProperties(fsImMsgSendLog, batchSendCourseDTO);
|
|
BeanUtils.copyProperties(fsImMsgSendLog, batchSendCourseDTO);
|