|
@@ -9,6 +9,7 @@ import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
|
|
|
|
|
import com.fs.common.service.ISmsService;
|
|
import com.fs.common.service.ISmsService;
|
|
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.vo.SmsNotifyVO;
|
|
import com.fs.common.vo.SmsNotifyVO;
|
|
|
import com.fs.common.vo.SmsSendItemVO;
|
|
import com.fs.common.vo.SmsSendItemVO;
|
|
@@ -26,9 +27,15 @@ import com.fs.his.domain.FsStoreOrder;
|
|
|
import com.fs.his.mapper.FsPackageOrderMapper;
|
|
import com.fs.his.mapper.FsPackageOrderMapper;
|
|
|
import com.fs.his.mapper.FsStoreOrderMapper;
|
|
import com.fs.his.mapper.FsStoreOrderMapper;
|
|
|
import com.fs.his.vo.FsPackageOrderVO;
|
|
import com.fs.his.vo.FsPackageOrderVO;
|
|
|
|
|
+import com.fs.qw.domain.QwAcquisitionSendMsgLog;
|
|
|
|
|
+import com.fs.qw.domain.QwCourseLinkSendMsgLog;
|
|
|
import com.fs.qw.domain.QwSopSmsLogs;
|
|
import com.fs.qw.domain.QwSopSmsLogs;
|
|
|
|
|
+import com.fs.qw.enums.SmsLogType;
|
|
|
|
|
+import com.fs.qw.mapper.QwAcquisitionSendMsgLogMapper;
|
|
|
|
|
+import com.fs.qw.mapper.QwCourseLinkSendMsgLogMapper;
|
|
|
import com.fs.qw.mapper.QwSopSmsLogsMapper;
|
|
import com.fs.qw.mapper.QwSopSmsLogsMapper;
|
|
|
import com.fs.qw.service.IQwSopSmsLogsService;
|
|
import com.fs.qw.service.IQwSopSmsLogsService;
|
|
|
|
|
+import com.fs.qw.strategy.SmsLogStrategyManager;
|
|
|
import com.fs.sms.domain.SendSmsReturn;
|
|
import com.fs.sms.domain.SendSmsReturn;
|
|
|
import com.fs.sms.service.impl.SmsTServiceImpl;
|
|
import com.fs.sms.service.impl.SmsTServiceImpl;
|
|
|
import com.fs.sop.domain.QwSopLogs;
|
|
import com.fs.sop.domain.QwSopLogs;
|
|
@@ -91,6 +98,14 @@ public class SmsServiceImpl implements ISmsService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsPackageOrderMapper packageOrderMapper;
|
|
private FsPackageOrderMapper packageOrderMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private QwAcquisitionSendMsgLogMapper acquisitionSendMsgLogMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private QwCourseLinkSendMsgLogMapper courseLinkSendMsgLogMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SmsLogStrategyManager smsLogStrategyManager;
|
|
|
@Override
|
|
@Override
|
|
|
public R sendTSms(String mobile, String code) {
|
|
public R sendTSms(String mobile, String code) {
|
|
|
// try{
|
|
// try{
|
|
@@ -839,51 +854,82 @@ public class SmsServiceImpl implements ISmsService
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送简单短信
|
|
|
|
|
+ * @param phone 接收方手机号
|
|
|
|
|
+ * @param content 短信内容
|
|
|
|
|
+ * @param temp 短信模板
|
|
|
|
|
+ * @param logType 日志记录类型,用于区分调用方
|
|
|
|
|
+ * @param contextObject 特定业务的上下文对象,如qwAcquisitionId或externalContactId
|
|
|
|
|
+ * @return R 响应结果
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
- public R sendAcquisitionMessage(String phone, String content, CompanySmsTemp temp) {
|
|
|
|
|
|
|
+ public R simpleSmsSend(String phone, String content, CompanySmsTemp temp, SmsLogType logType, Object contextObject) {
|
|
|
String urls = null;
|
|
String urls = null;
|
|
|
|
|
+ R response; // 存储最终响应
|
|
|
|
|
+ Integer number = calculateSmsCount(content);
|
|
|
SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.sms");
|
|
SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.sms");
|
|
|
FsSmsConfig sms = JSON.parseObject(sysConfig.getConfigValue(), FsSmsConfig.class);
|
|
FsSmsConfig sms = JSON.parseObject(sysConfig.getConfigValue(), FsSmsConfig.class);
|
|
|
- try {
|
|
|
|
|
- urls = sms.getRfUrl2() + "sms?action=send&account=" + sms.getRfAccount2() + "&password=" + sms.getRfPassword2() + "&mobile=" + phone + "&content=" + URLEncoder.encode(content, "UTF-8") + "&extno=" + sms.getRfCode2() + "&rt=json";
|
|
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
|
|
- log.error("{}发送失败", phone, e);
|
|
|
|
|
- return R.error("短信发送失败:" + e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- String post = HttpRequest.get(urls)
|
|
|
|
|
- .execute().body();
|
|
|
|
|
- SmsSendVO vo = JSONUtil.toBean(post, SmsSendVO.class);
|
|
|
|
|
- if (vo.getStatus().equals(0)) {
|
|
|
|
|
- for (SmsSendItemVO itemVO : vo.getList()) {
|
|
|
|
|
- if (itemVO.getResult().equals("0")) {
|
|
|
|
|
- CompanySmsLogs logs = new CompanySmsLogs();
|
|
|
|
|
- logs.setContent(content);
|
|
|
|
|
- logs.setTempCode(temp.getTempCode());
|
|
|
|
|
- logs.setTempId(temp.getTempId());
|
|
|
|
|
- logs.setPhone(phone);
|
|
|
|
|
- logs.setSendTime(new Date());
|
|
|
|
|
- logs.setStatus(0);
|
|
|
|
|
- logs.setType(sms.getType());
|
|
|
|
|
- logs.setMid(itemVO.getMid());
|
|
|
|
|
- int counts = logs.getContent().length() / 67;
|
|
|
|
|
- if (logs.getContent().length() % 67 > 0) {
|
|
|
|
|
- counts = counts + 1;
|
|
|
|
|
- }
|
|
|
|
|
- if (counts == 0) {
|
|
|
|
|
- counts = 1;
|
|
|
|
|
- }
|
|
|
|
|
- logs.setNumber(counts);
|
|
|
|
|
- smsLogsService.insertCompanySmsLogs(logs);
|
|
|
|
|
- }else{
|
|
|
|
|
- log.info("{}不发送短信-itemVO.getResult().equals(\"0\"):{}", phone, itemVO);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }else{
|
|
|
|
|
- log.info("{}不发送短信-vo.getStatus().equals(0):{}", phone, vo.getStatus());
|
|
|
|
|
|
|
|
|
|
- return R.error("发送获客链接短信失败!");
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ urls = sms.getRfUrl2() + "sms?action=send&account=" + sms.getRfAccount2() + "&password=" + sms.getRfPassword2() + "&mobile=" + phone + "&content=" + URLEncoder.encode(content, "UTF-8") + "&extno=" + sms.getRfCode2() + "&rt=json";
|
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
|
+ log.error("{}发送失败", phone, e);
|
|
|
|
|
+ response = R.error("短信发送失败:" + e.getMessage());
|
|
|
|
|
+ // 发送失败也要记录特定业务日志
|
|
|
|
|
+ smsLogStrategyManager.executeLogStrategy(logType, response, content, phone, temp.getTempId(), sms.getType(), number, contextObject);
|
|
|
|
|
+ return response;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String post = HttpRequest.get(urls).execute().body();
|
|
|
|
|
+ SmsSendVO vo = JSONUtil.toBean(post, SmsSendVO.class);
|
|
|
|
|
+
|
|
|
|
|
+ if (vo.getStatus().equals(0)) {
|
|
|
|
|
+ boolean anySuccess = false;
|
|
|
|
|
+ for (SmsSendItemVO itemVO : vo.getList()) {
|
|
|
|
|
+ if (itemVO.getResult().equals("0")) {
|
|
|
|
|
+ anySuccess = true;
|
|
|
|
|
+ // 记录通用日志
|
|
|
|
|
+ CompanySmsLogs logs = new CompanySmsLogs();
|
|
|
|
|
+ logs.setContent(content);
|
|
|
|
|
+ logs.setTempCode(temp.getTempCode());
|
|
|
|
|
+ logs.setTempId(temp.getTempId());
|
|
|
|
|
+ logs.setPhone(phone);
|
|
|
|
|
+ logs.setSendTime(new Date());
|
|
|
|
|
+ logs.setStatus(0);
|
|
|
|
|
+ logs.setType(sms.getType());
|
|
|
|
|
+ logs.setMid(itemVO.getMid());
|
|
|
|
|
+ logs.setNumber(number);
|
|
|
|
|
+ smsLogsService.insertCompanySmsLogs(logs);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+ if(anySuccess) {
|
|
|
|
|
+ response = R.ok();
|
|
|
|
|
+ // 记录特定业务日志
|
|
|
|
|
+ smsLogStrategyManager.executeLogStrategy(logType, response, content, phone, temp.getTempId(), sms.getType(), number, contextObject);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ response = R.error("发送短信失败,服务商返回无成功项!");
|
|
|
|
|
+ smsLogStrategyManager.executeLogStrategy(logType, response, content, phone, temp.getTempId(), sms.getType(), number, contextObject);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ response = R.error("发送短信失败!状态码: " + vo.getStatus());
|
|
|
|
|
+ // 发送失败也要记录特定业务日志
|
|
|
|
|
+ smsLogStrategyManager.executeLogStrategy(logType, response, content, phone, temp.getTempId(), sms.getType(), number, contextObject);
|
|
|
|
|
+ }
|
|
|
|
|
+ return response;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 将计算短信条数的逻辑提取出来,方便复用
|
|
|
|
|
+ private int calculateSmsCount(String content) {
|
|
|
|
|
+ if (content == null) return 1;
|
|
|
|
|
+ int counts = content.length() / 67;
|
|
|
|
|
+ if (content.length() % 67 > 0) {
|
|
|
|
|
+ counts = counts + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (counts == 0) {
|
|
|
|
|
+ counts = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ return counts;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|