提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.service.sms; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.pojo.PageResult; |
|
4 |
import com.iailab.module.system.controller.admin.sms.vo.log.SmsLogPageReqVO; |
|
5 |
import com.iailab.module.system.dal.dataobject.sms.SmsLogDO; |
|
6 |
import com.iailab.module.system.dal.dataobject.sms.SmsTemplateDO; |
|
7 |
import com.iailab.module.system.dal.mysql.sms.SmsLogMapper; |
|
8 |
import com.iailab.module.system.enums.sms.SmsReceiveStatusEnum; |
|
9 |
import com.iailab.module.system.enums.sms.SmsSendStatusEnum; |
|
10 |
import lombok.extern.slf4j.Slf4j; |
|
11 |
import org.springframework.stereotype.Service; |
|
12 |
|
|
13 |
import javax.annotation.Resource; |
|
14 |
import java.time.LocalDateTime; |
|
15 |
import java.util.Map; |
|
16 |
import java.util.Objects; |
|
17 |
|
|
18 |
/** |
|
19 |
* 短信日志 Service 实现类 |
|
20 |
* |
|
21 |
* @author zzf |
|
22 |
*/ |
|
23 |
@Slf4j |
|
24 |
@Service |
|
25 |
public class SmsLogServiceImpl implements SmsLogService { |
|
26 |
|
|
27 |
@Resource |
|
28 |
private SmsLogMapper smsLogMapper; |
|
29 |
|
|
30 |
@Override |
|
31 |
public Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend, |
|
32 |
SmsTemplateDO template, String templateContent, Map<String, Object> templateParams) { |
|
33 |
SmsLogDO.SmsLogDOBuilder logBuilder = SmsLogDO.builder(); |
|
34 |
// 根据是否要发送,设置状态 |
|
35 |
logBuilder.sendStatus(Objects.equals(isSend, true) ? SmsSendStatusEnum.INIT.getStatus() |
|
36 |
: SmsSendStatusEnum.IGNORE.getStatus()); |
|
37 |
// 设置手机相关字段 |
|
38 |
logBuilder.mobile(mobile).userId(userId).userType(userType); |
|
39 |
// 设置模板相关字段 |
|
40 |
logBuilder.templateId(template.getId()).templateCode(template.getCode()).templateType(template.getType()); |
|
41 |
logBuilder.templateContent(templateContent).templateParams(templateParams) |
|
42 |
.apiTemplateId(template.getApiTemplateId()); |
|
43 |
// 设置渠道相关字段 |
|
44 |
logBuilder.channelId(template.getChannelId()).channelCode(template.getChannelCode()); |
|
45 |
// 设置接收相关字段 |
|
46 |
logBuilder.receiveStatus(SmsReceiveStatusEnum.INIT.getStatus()); |
|
47 |
|
|
48 |
// 插入数据库 |
|
49 |
SmsLogDO logDO = logBuilder.build(); |
|
50 |
smsLogMapper.insert(logDO); |
|
51 |
return logDO.getId(); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public void updateSmsSendResult(Long id, Boolean success, |
|
56 |
String apiSendCode, String apiSendMsg, |
|
57 |
String apiRequestId, String apiSerialNo) { |
|
58 |
SmsSendStatusEnum sendStatus = success ? SmsSendStatusEnum.SUCCESS : SmsSendStatusEnum.FAILURE; |
|
59 |
smsLogMapper.updateById(SmsLogDO.builder().id(id) |
|
60 |
.sendStatus(sendStatus.getStatus()).sendTime(LocalDateTime.now()) |
|
61 |
.apiSendCode(apiSendCode).apiSendMsg(apiSendMsg) |
|
62 |
.apiRequestId(apiRequestId).apiSerialNo(apiSerialNo).build()); |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public void updateSmsReceiveResult(Long id, Boolean success, LocalDateTime receiveTime, |
|
67 |
String apiReceiveCode, String apiReceiveMsg) { |
|
68 |
SmsReceiveStatusEnum receiveStatus = Objects.equals(success, true) ? |
|
69 |
SmsReceiveStatusEnum.SUCCESS : SmsReceiveStatusEnum.FAILURE; |
|
70 |
smsLogMapper.updateById(SmsLogDO.builder().id(id).receiveStatus(receiveStatus.getStatus()) |
|
71 |
.receiveTime(receiveTime).apiReceiveCode(apiReceiveCode).apiReceiveMsg(apiReceiveMsg).build()); |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public PageResult<SmsLogDO> getSmsLogPage(SmsLogPageReqVO pageReqVO) { |
|
76 |
return smsLogMapper.selectPage(pageReqVO); |
|
77 |
} |
|
78 |
|
|
79 |
} |