|
@@ -5,10 +5,10 @@ import com.aliyuncs.DefaultAcsClient;
|
|
import com.aliyuncs.IAcsClient;
|
|
import com.aliyuncs.IAcsClient;
|
|
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
|
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
|
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
|
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
|
-import com.aliyuncs.exceptions.ClientException;
|
|
|
|
import com.aliyuncs.http.MethodType;
|
|
import com.aliyuncs.http.MethodType;
|
|
import com.aliyuncs.profile.DefaultProfile;
|
|
import com.aliyuncs.profile.DefaultProfile;
|
|
import com.aliyuncs.profile.IClientProfile;
|
|
import com.aliyuncs.profile.IClientProfile;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.qmth.distributed.print.business.config.DictionaryConfig;
|
|
import com.qmth.distributed.print.business.config.DictionaryConfig;
|
|
import com.qmth.distributed.print.business.entity.BasicMessage;
|
|
import com.qmth.distributed.print.business.entity.BasicMessage;
|
|
@@ -21,17 +21,17 @@ import com.qmth.distributed.print.business.service.BasicMessageService;
|
|
import com.qmth.distributed.print.business.service.CacheService;
|
|
import com.qmth.distributed.print.business.service.CacheService;
|
|
import com.qmth.distributed.print.business.service.ExamTaskService;
|
|
import com.qmth.distributed.print.business.service.ExamTaskService;
|
|
import com.qmth.distributed.print.business.service.SysConfigService;
|
|
import com.qmth.distributed.print.business.service.SysConfigService;
|
|
|
|
+import com.qmth.distributed.print.business.util.ServletUtil;
|
|
import com.qmth.distributed.print.common.contant.SpringContextHolder;
|
|
import com.qmth.distributed.print.common.contant.SpringContextHolder;
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 短信消息发送
|
|
* @Description: 短信消息发送
|
|
@@ -49,26 +49,31 @@ public class BasicMessageServiceImpl extends ServiceImpl<BasicMessageMapper, Bas
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
- public void saveMessageSendLog(Long userId,String mobileNumber,Long businessId,String variableParams,Long createId,MessageEnum messageType) {
|
|
|
|
- // 其他方法调用所传入的参数,必须校验有值
|
|
|
|
- this.checkData(userId,mobileNumber,businessId,variableParams,createId,messageType);
|
|
|
|
-
|
|
|
|
|
|
+ public void saveMessageSendLog(Long userId, String mobileNumber, Long businessId, String variableParams, Long createId, MessageEnum messageType, String remark) {
|
|
|
|
+ BasicMessage basicMessage = new BasicMessage();
|
|
// code和content
|
|
// code和content
|
|
- Map<String,String> enumInfo = this.getCodeAndContentByEnum(messageType);
|
|
|
|
|
|
+ Map<String, String> enumInfo = this.getCodeAndContentByEnum(messageType);
|
|
String templateCode = enumInfo.get("templateCode");
|
|
String templateCode = enumInfo.get("templateCode");
|
|
String templateContent = enumInfo.get("templateContent");
|
|
String templateContent = enumInfo.get("templateContent");
|
|
|
|
|
|
-
|
|
|
|
- // 短信提示系统是否启用配置验证
|
|
|
|
- SysConfig sysConfig = sysConfigService.getByKey("sys.message.enable");
|
|
|
|
- if (sysConfig.getConfigValue() == null) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("短信消息提示启用开关未设置");
|
|
|
|
- }
|
|
|
|
- if (sysConfig.getConfigValue().equals("false")) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("短信消息提示已关闭");
|
|
|
|
- }
|
|
|
|
|
|
+ String errorMessage = null;
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
+ // 其他方法调用所传入的参数,必须校验有值
|
|
|
|
+ this.checkData(userId, mobileNumber, variableParams, messageType);
|
|
|
|
+
|
|
|
|
+ // 短信提示系统是否启用配置验证
|
|
|
|
+ SysConfig sysConfig = sysConfigService.getByKey("sys.message.enable");
|
|
|
|
+ if (sysConfig == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未找到短信配置");
|
|
|
|
+ }
|
|
|
|
+ if (sysConfig.getConfigValue() == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("短信消息提示启用开关未设置");
|
|
|
|
+ }
|
|
|
|
+ if (sysConfig.getConfigValue().equals("false")) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("短信消息提示已关闭");
|
|
|
|
+ }
|
|
|
|
+
|
|
System.setProperty("sun.net.client.defaultConnectTimeout", "180000");
|
|
System.setProperty("sun.net.client.defaultConnectTimeout", "180000");
|
|
System.setProperty("sun.net.client.defaultReadTimeout", "18000");
|
|
System.setProperty("sun.net.client.defaultReadTimeout", "18000");
|
|
// 初始化ascClient需要的几个参数
|
|
// 初始化ascClient需要的几个参数
|
|
@@ -103,29 +108,36 @@ public class BasicMessageServiceImpl extends ServiceImpl<BasicMessageMapper, Bas
|
|
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
|
|
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
|
|
|
|
|
|
if (sendSmsResponse.getCode() != null) {
|
|
if (sendSmsResponse.getCode() != null) {
|
|
- BasicMessage basicMessage = new BasicMessage();
|
|
|
|
- // 传入的必填字段
|
|
|
|
- basicMessage.setUserId(userId);
|
|
|
|
- basicMessage.setMobileNumber(mobileNumber);
|
|
|
|
- basicMessage.setBusinessId(businessId);
|
|
|
|
- basicMessage.setVariableParams(variableParams);
|
|
|
|
- basicMessage.setCreateId(createId);
|
|
|
|
- basicMessage.setMessageType(messageType);
|
|
|
|
-
|
|
|
|
- // 经过处理的新字段
|
|
|
|
- basicMessage.setId(SystemConstant.getDbUuid());
|
|
|
|
- basicMessage.setBusinessOperate(messageType.getName());
|
|
|
|
- basicMessage.setCreateTime(System.currentTimeMillis());
|
|
|
|
- basicMessage.setTemplateCode(templateCode);
|
|
|
|
-// basicMessage.setTemplateContent(templateContent);
|
|
|
|
|
|
+
|
|
basicMessage.setSendStatus(sendSmsResponse.getCode());
|
|
basicMessage.setSendStatus(sendSmsResponse.getCode());
|
|
basicMessage.setSendResult(sendSmsResponse.getMessage());
|
|
basicMessage.setSendResult(sendSmsResponse.getMessage());
|
|
- this.save(basicMessage);
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
throw ExceptionResultEnum.ERROR.exception(sendSmsResponse.getMessage());
|
|
throw ExceptionResultEnum.ERROR.exception(sendSmsResponse.getMessage());
|
|
}
|
|
}
|
|
- }catch (ClientException e){
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ errorMessage = e.getMessage();
|
|
|
|
+ } finally {
|
|
|
|
+ // 传入的必填字段
|
|
|
|
+ basicMessage.setUserId(userId);
|
|
|
|
+ basicMessage.setMobileNumber(mobileNumber);
|
|
|
|
+ basicMessage.setBusinessId(businessId);
|
|
|
|
+ basicMessage.setVariableParams(variableParams);
|
|
|
|
+ basicMessage.setCreateId(createId);
|
|
|
|
+ basicMessage.setMessageType(messageType);
|
|
|
|
+ basicMessage.setRemark(remark);
|
|
|
|
+ basicMessage.setResendCount(0);
|
|
|
|
+
|
|
|
|
+ // 经过处理的新字段
|
|
|
|
+ basicMessage.setId(SystemConstant.getDbUuid());
|
|
|
|
+ basicMessage.setBusinessOperate(messageType.getName());
|
|
|
|
+ basicMessage.setCreateTime(System.currentTimeMillis());
|
|
|
|
+ basicMessage.setTemplateCode(templateCode);
|
|
|
|
+ if (errorMessage != null && errorMessage.length() > 0) {
|
|
|
|
+ basicMessage.setSendStatus("SYSTEM_ERROR");
|
|
|
|
+ basicMessage.setSendResult(errorMessage);
|
|
|
|
+ }
|
|
|
|
+ this.save(basicMessage);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -133,15 +145,15 @@ public class BasicMessageServiceImpl extends ServiceImpl<BasicMessageMapper, Bas
|
|
@Override
|
|
@Override
|
|
public void noticeOfExamTaskAudit(List<Long> examTaskIdList, MessageEnum messageType, SysUser sysUser) {
|
|
public void noticeOfExamTaskAudit(List<Long> examTaskIdList, MessageEnum messageType, SysUser sysUser) {
|
|
ExamTaskService examTaskService = SpringContextHolder.getBean(ExamTaskService.class);
|
|
ExamTaskService examTaskService = SpringContextHolder.getBean(ExamTaskService.class);
|
|
- Long createId = sysUser.getId();
|
|
|
|
for (Long examTaskId : examTaskIdList) {
|
|
for (Long examTaskId : examTaskIdList) {
|
|
ExamTask examTask = examTaskService.getById(examTaskId);
|
|
ExamTask examTask = examTaskService.getById(examTaskId);
|
|
- if (Objects.nonNull(examTask)){
|
|
|
|
|
|
+ if (Objects.nonNull(examTask)) {
|
|
String courseName = examTask.getCourseName();
|
|
String courseName = examTask.getCourseName();
|
|
String paperNumber = examTask.getPaperNumber();
|
|
String paperNumber = examTask.getPaperNumber();
|
|
- Long userId = examTask.getCreateId();
|
|
|
|
|
|
+ // 获取短信接收对象的信息
|
|
|
|
+ Long userId = examTask.getUserId();
|
|
SysUser user = cacheService.userCache(userId);
|
|
SysUser user = cacheService.userCache(userId);
|
|
- if (Objects.nonNull(user)){
|
|
|
|
|
|
+ if (Objects.nonNull(user)) {
|
|
String userName = user.getRealName();
|
|
String userName = user.getRealName();
|
|
String mobileNumber = user.getMobileNumber();
|
|
String mobileNumber = user.getMobileNumber();
|
|
|
|
|
|
@@ -150,48 +162,125 @@ public class BasicMessageServiceImpl extends ServiceImpl<BasicMessageMapper, Bas
|
|
jsonMap.put("courseName", courseName);
|
|
jsonMap.put("courseName", courseName);
|
|
jsonMap.put("paperNumber", paperNumber);
|
|
jsonMap.put("paperNumber", paperNumber);
|
|
String variableParams = JSON.toJSONString(jsonMap);
|
|
String variableParams = JSON.toJSONString(jsonMap);
|
|
- this.saveMessageSendLog(userId,mobileNumber, examTaskId,variableParams,createId,messageType);
|
|
|
|
|
|
+ this.saveMessageSendLog(userId, mobileNumber, examTaskId, variableParams, sysUser.getId(), messageType, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private void checkData(Object ... objects){
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 发送给命题老师-待办提醒
|
|
|
|
+ *
|
|
|
|
+ * @param examTasks
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void sendNoticeTaskCreate(ExamTask... examTasks) {
|
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
+ // 指派命题老师的命题任务
|
|
|
|
+ Map<Long, List<String>> collects = Arrays.stream(examTasks).filter(m -> m.getUserId() != null).collect(Collectors.groupingBy(ExamTask::getUserId, Collectors.mapping(m -> String.valueOf(m.getId()), Collectors.toList())));
|
|
|
|
+ for (Map.Entry<Long, List<String>> longListEntry : collects.entrySet()) {
|
|
|
|
+ Long userId = longListEntry.getKey();
|
|
|
|
+ List<String> ids = longListEntry.getValue();
|
|
|
|
+ SysUser user = cacheService.userCache(userId);
|
|
|
|
+ if (Objects.nonNull(user)) {
|
|
|
|
+ String userName = user.getRealName();
|
|
|
|
+ String mobileNumber = user.getMobileNumber();
|
|
|
|
+
|
|
|
|
+ Map<String, Object> jsonMap = new HashMap<>();
|
|
|
|
+ jsonMap.put("userName", userName);
|
|
|
|
+ jsonMap.put("count", ids.size());
|
|
|
|
+ String variableParams = JSON.toJSONString(jsonMap);
|
|
|
|
+ String remark = String.format("命题任务ID:%s", String.join(",", ids));
|
|
|
|
+ this.saveMessageSendLog(userId, mobileNumber, null, variableParams, sysUser.getId(), MessageEnum.NOTICE_OF_EXAM_TASK_CREATED, remark);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void sendNoticeTaskAuditCreateOrReview(ExamTask examTask, MessageEnum messageType) {
|
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
+ // 考务老师(命题任务创建人)
|
|
|
|
+ Long userId = examTask.getCreateId();
|
|
|
|
+ SysUser user = cacheService.userCache(userId);
|
|
|
|
+ if (Objects.nonNull(user)) {
|
|
|
|
+ String userName = user.getRealName();
|
|
|
|
+ String mobileNumber = user.getMobileNumber();
|
|
|
|
+
|
|
|
|
+ Map<String, Object> jsonMap = new HashMap<>();
|
|
|
|
+ jsonMap.put("userName", userName);
|
|
|
|
+ jsonMap.put("courseName", examTask.getCourseName());
|
|
|
|
+ jsonMap.put("paperNumber", examTask.getPaperNumber());
|
|
|
|
+ String variableParams = JSON.toJSONString(jsonMap);
|
|
|
|
+ String remark = String.format("命题任务ID:%s", examTask.getId().toString());
|
|
|
|
+ this.saveMessageSendLog(userId, mobileNumber, examTask.getId(), variableParams, sysUser.getId(), messageType, remark);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void sendNoticeExpireOrOverdue(MessageEnum messageType, Long userId, List<String> ids) {
|
|
|
|
+ // 考务老师(命题任务创建人)
|
|
|
|
+ SysUser user = cacheService.userCache(userId);
|
|
|
|
+ if (Objects.nonNull(user)) {
|
|
|
|
+ String userName = user.getRealName();
|
|
|
|
+ String mobileNumber = user.getMobileNumber();
|
|
|
|
+ Map<String, Object> jsonMap = new HashMap<>();
|
|
|
|
+ jsonMap.put("userName", userName);
|
|
|
|
+ jsonMap.put("count", ids.size());
|
|
|
|
+ String variableParams = JSON.toJSONString(jsonMap);
|
|
|
|
+ String remark = String.format("命题任务ID:%s", String.join(",", ids));
|
|
|
|
+ this.saveMessageSendLog(userId, mobileNumber, null, variableParams, null, messageType, remark);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void resendSmsTask() {
|
|
|
|
+ SysConfig sysConfig = sysConfigService.getByKey("sys.message.resendCount");
|
|
|
|
+ if(sysConfig != null){
|
|
|
|
+ Integer resendCount = StringUtils.isBlank(sysConfig.getConfigValue()) ? 0 : Integer.valueOf(sysConfig.getConfigValue());
|
|
|
|
+ QueryWrapper<BasicMessage> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().ne(BasicMessage::getSendStatus, "OK").lt(BasicMessage::getResendCount, resendCount);
|
|
|
|
+ List<BasicMessage> basicMessageList = this.list(queryWrapper);
|
|
|
|
+ if (basicMessageList != null && basicMessageList.size() > 0) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void checkData(Object... objects) {
|
|
for (Object object : objects) {
|
|
for (Object object : objects) {
|
|
- if (object instanceof String){
|
|
|
|
|
|
+ if (Objects.isNull(object)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("调用发送短信方法时必传参数缺失");
|
|
|
|
+ } else if (object instanceof String) {
|
|
String param = String.valueOf(object);
|
|
String param = String.valueOf(object);
|
|
- if (param.length() == 0 || param.equals("null")){
|
|
|
|
|
|
+ if (param.length() == 0 || param.equals("null")) {
|
|
throw ExceptionResultEnum.ERROR.exception("调用发送短信方法时必传参数缺失");
|
|
throw ExceptionResultEnum.ERROR.exception("调用发送短信方法时必传参数缺失");
|
|
}
|
|
}
|
|
- }else if (object instanceof Long){
|
|
|
|
|
|
+ } else if (object instanceof Long) {
|
|
Long param = SystemConstant.convertIdToLong(String.valueOf(object));
|
|
Long param = SystemConstant.convertIdToLong(String.valueOf(object));
|
|
- if (param == null || param == 0){
|
|
|
|
|
|
+ if (param == null || param == 0) {
|
|
throw ExceptionResultEnum.ERROR.exception("调用发送短信方法时必传参数缺失");
|
|
throw ExceptionResultEnum.ERROR.exception("调用发送短信方法时必传参数缺失");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private Map<String,String> getCodeAndContentByEnum(MessageEnum messageEnum){
|
|
|
|
- Map<String,String> result = new HashMap<>();
|
|
|
|
- String templateContent;
|
|
|
|
- String templateCode;
|
|
|
|
- switch (messageEnum){
|
|
|
|
|
|
+ private Map<String, String> getCodeAndContentByEnum(MessageEnum messageEnum) {
|
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
|
+ String templateContent = null;
|
|
|
|
+ String templateCode = null;
|
|
|
|
+ switch (messageEnum) {
|
|
case NOTICE_OF_AUDIT_PASS:
|
|
case NOTICE_OF_AUDIT_PASS:
|
|
- // ${userName}您好,${courseName}、${paperNumber}试卷入库申请已通过,您可在卷库里进行查看已审核通过的试卷!
|
|
|
|
templateCode = dictionaryConfig.smsDomain().getAliyunSMSAuditPassCode();
|
|
templateCode = dictionaryConfig.smsDomain().getAliyunSMSAuditPassCode();
|
|
- templateContent = "${userName}您好,${courseName}、${paperNumber}试卷入库申请已通过,您可在卷库里进行查看已审核通过的试卷!";
|
|
|
|
|
|
+ templateContent = messageEnum.getTemplate();
|
|
break;
|
|
break;
|
|
case NOTICE_OF_AUDIT_NOT_PASS:
|
|
case NOTICE_OF_AUDIT_NOT_PASS:
|
|
templateCode = dictionaryConfig.smsDomain().getAliyunSMSAuditNotPassCode();
|
|
templateCode = dictionaryConfig.smsDomain().getAliyunSMSAuditNotPassCode();
|
|
- templateContent = "${userName}您好,${courseName}、${paperNumber}试卷入库申请未通过,您可查看审核意见后重新提交入库申请";
|
|
|
|
|
|
+ templateContent = messageEnum.getTemplate();
|
|
break;
|
|
break;
|
|
- default:
|
|
|
|
- throw new IllegalStateException("Unexpected value: " + messageEnum);
|
|
|
|
}
|
|
}
|
|
- result.put("templateContent",templateContent);
|
|
|
|
- result.put("templateCode",templateCode);
|
|
|
|
|
|
+ result.put("templateContent", templateContent);
|
|
|
|
+ result.put("templateCode", templateCode);
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
}
|