|
|
@@ -10,7 +10,6 @@ import com.xunmei.common.core.constant.HttpStatus;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.reminder.dto.ReminderScheduleMsgDto;
|
|
|
import com.xunmei.common.core.domain.reminder.vo.ReminderScheduleMsgVo;
|
|
|
-import com.xunmei.common.core.domain.sms.domain.SmsSendRecord;
|
|
|
import com.xunmei.common.core.web.domain.AjaxResult;
|
|
|
import com.xunmei.sms.utils.SmsUtil;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
@@ -47,9 +46,9 @@ public class SmsService implements ISmsService {
|
|
|
private ISmsSendRecordService recordService;
|
|
|
|
|
|
//告警代码
|
|
|
- private static final String ALARM_CODE="854002";
|
|
|
+ private static final String ALARM_CODE = "854002";
|
|
|
//逾期提醒代码
|
|
|
- private static final String TODO_CODE="854001";
|
|
|
+ private static final String TODO_CODE = "854001";
|
|
|
|
|
|
/**
|
|
|
* 在ESB系统里的 系统编码
|
|
|
@@ -77,10 +76,9 @@ public class SmsService implements ISmsService {
|
|
|
private String serviceScene;
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 发送短信
|
|
|
+ *
|
|
|
* @param data
|
|
|
* @return {@link AjaxResult}
|
|
|
*/
|
|
|
@@ -89,64 +87,70 @@ public class SmsService implements ISmsService {
|
|
|
public AjaxResult send(SmsInfoVo data) {
|
|
|
try {
|
|
|
logger.debug("【发送短信】开始,数据:" + JSONObject.toJSON(data));
|
|
|
- CompositeData smsCompositeData = SmsUtil.createSmsBody(data,systemCode,systemName,serviceCode,serviceScene);
|
|
|
+ CompositeData smsCompositeData = SmsUtil.createSmsBody(data, systemCode, systemName, serviceCode, serviceScene);
|
|
|
logger.debug("【发送短信】转换后数据:" + JSONObject.toJSON(smsCompositeData));
|
|
|
if (smsCompositeData == null) {
|
|
|
- logger.error("【发送短信】转换数据出错:原数据:"+JSONObject.toJSON(data));
|
|
|
+ logger.error("【发送短信】转换数据出错:原数据:" + JSONObject.toJSON(data));
|
|
|
return AjaxResult.error("【发送短信】转换数据出错");
|
|
|
}
|
|
|
CompositeData rspData = ESBClient.request(smsCompositeData);
|
|
|
logger.debug("【发送短信】返回数据:" + JSONObject.toJSON(rspData));
|
|
|
return getResult(rspData);
|
|
|
} catch (Exception ex) {
|
|
|
- logger.error("【发送短信】发送时内部异常:数据:"+JSONObject.toJSON(data),ex);
|
|
|
+ logger.error("【发送短信】发送时内部异常:数据:" + JSONObject.toJSON(data), ex);
|
|
|
return AjaxResult.error("【发送短信】发送时内部异常");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据机构获取机构下网点负责人角色,并发送告警短信
|
|
|
+ *
|
|
|
* @param orgId
|
|
|
* @param alarmContent
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public void sendSmsIot(Long orgId,String alarmType, String alarmContent,String alarmTime) {
|
|
|
+ public void sendSmsIot(Long orgId, String alarmType, String alarmContent, String alarmTime) {
|
|
|
List<SysUser> userList = RemoteCallHandlerExecutor.executeRemoteCall(() ->
|
|
|
remoteRoleService.selectUserByRoleNameAndOrgId("网点负责人", orgId, 0, SecurityConstants.INNER), ErrorMsgConstants.QUERY_USER_DATA_ERROR);
|
|
|
SysOrg sysOrg = remoteOrgService.selectOrgById(orgId, SecurityConstants.INNER);
|
|
|
Date now = new Date();
|
|
|
String date = DateUtil.format(now, "yyyy-MM-dd");
|
|
|
String time = DateUtil.format(now, "HH:mm:ss");
|
|
|
- if (ObjectUtil.isNotEmpty(userList)){
|
|
|
+ if (ObjectUtil.isNotEmpty(userList)) {
|
|
|
for (SysUser sysUser : userList) {
|
|
|
- String phone = sysUser.getPhone();
|
|
|
- if (ObjectUtil.isEmpty(phone)){
|
|
|
- continue;
|
|
|
- }
|
|
|
SmsInfoVo smsInfoVo = new SmsInfoVo();
|
|
|
smsInfoVo.setBelongBranchId(sysOrg.getGuid());
|
|
|
smsInfoVo.setTranType(ALARM_CODE);
|
|
|
- smsInfoVo.setMobile(phone);
|
|
|
+ smsInfoVo.setMobile(sysUser.getPhone());
|
|
|
smsInfoVo.setOccurDate(date);
|
|
|
smsInfoVo.setOccurTime(time);
|
|
|
smsInfoVo.setRetMsg(alarmType);
|
|
|
smsInfoVo.setBak3(alarmContent);
|
|
|
- CompositeData smsCompositeData = SmsUtil.createSmsBody(smsInfoVo,systemCode,systemName,serviceCode,serviceScene);
|
|
|
- CompositeData rspData = null;
|
|
|
- try {
|
|
|
- rspData = ESBClient.request(smsCompositeData);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("短信发送时发生异常 :",e);
|
|
|
- }
|
|
|
- AjaxResult result = getResult(rspData);
|
|
|
- recordService.saveSmsRecord(sysOrg, sysUser, result, smsInfoVo);
|
|
|
+ deal(sysOrg, sysUser, smsInfoVo);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void deal(SysOrg sysOrg, SysUser sysUser, SmsInfoVo smsInfoVo) {
|
|
|
+ if (ObjectUtil.isEmpty(sysUser.getPhone())) {
|
|
|
+ AjaxResult result = AjaxResult.error("用户" + sysUser.getName() + "手机号为空");
|
|
|
+ recordService.saveSmsRecord(sysOrg, sysUser, result, smsInfoVo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CompositeData smsCompositeData = SmsUtil.createSmsBody(smsInfoVo, systemCode, systemName, serviceCode, serviceScene);
|
|
|
+ CompositeData rspData = null;
|
|
|
+ try {
|
|
|
+ rspData = ESBClient.request(smsCompositeData);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("短信发送时发生异常 :", e);
|
|
|
+ }
|
|
|
+ AjaxResult result = getResult(rspData);
|
|
|
+ recordService.saveSmsRecord(sysOrg, sysUser, result, smsInfoVo);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- public void sendSmsTodo(Long orgId, String type,String content, Date time) {
|
|
|
+ public void sendSmsTodo(Long orgId, String type, String content, Date time) {
|
|
|
List<SysUser> userList = RemoteCallHandlerExecutor.executeRemoteCall(() ->
|
|
|
remoteRoleService.selectUserByRoleNameAndOrgId("网点负责人", orgId, 0, SecurityConstants.INNER), ErrorMsgConstants.QUERY_USER_DATA_ERROR);
|
|
|
SysOrg sysOrg = remoteOrgService.selectOrgById(orgId, SecurityConstants.INNER);
|
|
|
@@ -154,30 +158,17 @@ public class SmsService implements ISmsService {
|
|
|
Date now = new Date();
|
|
|
String day = DateUtil.format(now, "yyyy-MM-dd");
|
|
|
String sfm = DateUtil.format(now, "HH:mm:ss");
|
|
|
- if (ObjectUtil.isNotEmpty(userList)){
|
|
|
- List<SmsSendRecord> records = new ArrayList<>();
|
|
|
+ if (ObjectUtil.isNotEmpty(userList)) {
|
|
|
for (SysUser sysUser : userList) {
|
|
|
- String phone = sysUser.getPhone();
|
|
|
- if (ObjectUtil.isEmpty(phone)){
|
|
|
- continue;
|
|
|
- }
|
|
|
SmsInfoVo smsInfoVo = new SmsInfoVo();
|
|
|
smsInfoVo.setBelongBranchId(sysOrg.getGuid());
|
|
|
smsInfoVo.setTranType(TODO_CODE);
|
|
|
- smsInfoVo.setMobile(phone);
|
|
|
+ smsInfoVo.setMobile(sysUser.getPhone());
|
|
|
smsInfoVo.setOccurDate(day);
|
|
|
smsInfoVo.setOccurTime(sfm);
|
|
|
smsInfoVo.setRetMsg(type);
|
|
|
- smsInfoVo.setBak3("任务【"+ content + "】未完成,将于"+date+"逾期。");
|
|
|
- CompositeData smsCompositeData = SmsUtil.createSmsBody(smsInfoVo,systemCode,systemName,serviceCode,serviceScene);
|
|
|
- CompositeData rspData = null;
|
|
|
- try {
|
|
|
- rspData = ESBClient.request(smsCompositeData);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("短信发送时发生异常 :",e);
|
|
|
- }
|
|
|
- AjaxResult result = getResult(rspData);
|
|
|
- recordService.saveSmsRecord(sysOrg,sysUser,result,smsInfoVo);
|
|
|
+ smsInfoVo.setBak3("任务【" + content + "】未完成,将于" + date + "逾期。");
|
|
|
+ deal(sysOrg, sysUser, smsInfoVo);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -190,9 +181,7 @@ public class SmsService implements ISmsService {
|
|
|
String time = DateUtil.format(now, "HH:mm:ss");
|
|
|
List<ReminderScheduleMsgVo> returnData = new ArrayList<>();
|
|
|
for (ReminderScheduleMsgDto dto : msgDto) {
|
|
|
- if (ObjectUtil.isEmpty(dto.getPhone())){
|
|
|
- continue;
|
|
|
- }
|
|
|
+
|
|
|
SmsInfoVo smsInfoVo = new SmsInfoVo();
|
|
|
smsInfoVo.setBelongBranchId(dto.getOrgGuid());
|
|
|
smsInfoVo.setTranType(TODO_CODE);
|
|
|
@@ -201,15 +190,20 @@ public class SmsService implements ISmsService {
|
|
|
smsInfoVo.setOccurTime(time);
|
|
|
smsInfoVo.setRetMsg(dto.getType());
|
|
|
smsInfoVo.setBak3(dto.getMsgContent());
|
|
|
- CompositeData smsCompositeData = SmsUtil.createSmsBody(smsInfoVo,systemCode,systemName,serviceCode,serviceScene);
|
|
|
- CompositeData rspData = null;
|
|
|
- try {
|
|
|
- rspData = ESBClient.request(smsCompositeData);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("短信发送时发生异常 :",e);
|
|
|
+ AjaxResult result;
|
|
|
+ if (ObjectUtil.isEmpty(dto.getPhone())) {
|
|
|
+ result = AjaxResult.error("用户" + dto.getRecipientName() + "手机号为空");
|
|
|
+ } else {
|
|
|
+ CompositeData rspData = null;
|
|
|
+ CompositeData smsCompositeData = SmsUtil.createSmsBody(smsInfoVo, systemCode, systemName, serviceCode, serviceScene);
|
|
|
+ try {
|
|
|
+ rspData = ESBClient.request(smsCompositeData);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("短信发送时发生异常 :", e);
|
|
|
+ }
|
|
|
+ result = getResult(rspData);
|
|
|
}
|
|
|
- AjaxResult result = getResult(rspData);
|
|
|
- if (result.get(AjaxResult.CODE_TAG).equals(String.valueOf(HttpStatus.ERROR))){
|
|
|
+ if (result.get(AjaxResult.CODE_TAG).equals(String.valueOf(HttpStatus.ERROR))) {
|
|
|
ReminderScheduleMsgVo msgVo = new ReminderScheduleMsgVo();
|
|
|
String msg = (String) result.get(AjaxResult.MSG_TAG);
|
|
|
msgVo.setMsg(msg);
|
|
|
@@ -217,13 +211,13 @@ public class SmsService implements ISmsService {
|
|
|
msgVo.setScheduleId(dto.getScheduleId());
|
|
|
returnData.add(msgVo);
|
|
|
}
|
|
|
- recordService.saveSmsRecord(dto,result,smsInfoVo);
|
|
|
+ recordService.saveSmsRecord(dto, result, smsInfoVo);
|
|
|
}
|
|
|
return returnData;
|
|
|
}
|
|
|
|
|
|
private AjaxResult getResult(CompositeData repData) {
|
|
|
- if (repData==null){
|
|
|
+ if (repData == null) {
|
|
|
return AjaxResult.error("【发送短信】发送短信失败,短信发送返回结果为空");
|
|
|
}
|
|
|
boolean result = false;
|
|
|
@@ -245,5 +239,4 @@ public class SmsService implements ISmsService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|