【sms】整理sms模块的字段和业务

pull/3/head
fengshuonan 2020-12-19 16:46:33 +08:00
parent 3e0b4e60a8
commit 0c4feb51a0
5 changed files with 47 additions and 44 deletions

View File

@ -1,11 +1,11 @@
package cn.stylefeng.roses.kernel.sms.modular.entity; package cn.stylefeng.roses.kernel.sms.modular.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -28,13 +28,14 @@ public class SysSms extends BaseEntity implements Serializable {
/** /**
* *
*/ */
@TableId(type = IdType.ASSIGN_ID) @TableId(value = "sms_id", type = IdType.ASSIGN_ID)
private Long id; private Long smsId;
/** /**
* *
*/ */
@TableField("phone_numbers") @TableField("phone_number")
private String phoneNumbers; private String phoneNumber;
/** /**
* *
@ -43,33 +44,34 @@ public class SysSms extends BaseEntity implements Serializable {
private String validateCode; private String validateCode;
/** /**
* ID *
*/ */
@TableField("template_code") @TableField("template_code")
private String templateCode; private String templateCode;
/** /**
* idid * id
*/ */
@TableField("biz_id") @TableField("biz_id")
private String bizId; private String bizId;
/** /**
* 0 1 2 3 * 1-2-3-4-
*/ */
@TableField("status") @TableField("status_flag")
private Integer status; private Integer statusFlag;
/** /**
* 1 app 2 pc 3 * 1-app2-pc3-
*/ */
@TableField("source") @TableField("source")
private Integer source; private Integer source;
/** /**
* *
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField("invalid_time") @TableField("invalid_time")
private Date invalidTime; private Date invalidTime;
} }

View File

@ -19,12 +19,12 @@ public class SysSmsInfoParam extends BaseRequest {
/** /**
* *
*/ */
private Long id; private Long smsId;
/** /**
* *
*/ */
private String phoneNumbers; private String phoneNumber;
/** /**
* *
@ -32,27 +32,28 @@ public class SysSmsInfoParam extends BaseRequest {
private String validateCode; private String validateCode;
/** /**
* ID *
*/ */
private String templateCode; private String templateCode;
/** /**
* idid * id
*/ */
private String bizId; private String bizId;
/** /**
* 0 1 2 3 * 1-2-3-4-
*/ */
private Integer status; private Integer statusFlag;
/** /**
* 1 app 2 pc 3 * 1-app2-pc3-
*/ */
private Integer source; private Integer source;
/** /**
* *
*/ */
private Date invalidTime; private Date invalidTime;
} }

View File

@ -20,7 +20,7 @@ public class SysSmsSendParam {
* *
*/ */
@NotBlank(message = "手机号码为空请检查phoneNumbers参数") @NotBlank(message = "手机号码为空请检查phoneNumbers参数")
private String phoneNumbers; private String phoneNumber;
/** /**
* *

View File

@ -18,7 +18,7 @@ public class SysSmsVerifyParam {
* *
*/ */
@NotBlank(message = "手机号不能为空") @NotBlank(message = "手机号不能为空")
private String phoneNumbers; private String phoneNumber;
/** /**
* *

View File

@ -3,14 +3,6 @@ package cn.stylefeng.roses.kernel.sms.modular.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.stylefeng.roses.kernel.sms.modular.enums.SmsTypeEnum;
import cn.stylefeng.roses.kernel.sms.modular.mapper.SysSmsMapper;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsInfoParam;
import cn.stylefeng.roses.kernel.sms.modular.service.SysSmsInfoService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
@ -19,8 +11,16 @@ import cn.stylefeng.roses.kernel.sms.api.exception.SmsException;
import cn.stylefeng.roses.kernel.sms.api.expander.SmsConfigExpander; import cn.stylefeng.roses.kernel.sms.api.expander.SmsConfigExpander;
import cn.stylefeng.roses.kernel.sms.modular.entity.SysSms; import cn.stylefeng.roses.kernel.sms.modular.entity.SysSms;
import cn.stylefeng.roses.kernel.sms.modular.enums.SmsSendStatusEnum; import cn.stylefeng.roses.kernel.sms.modular.enums.SmsSendStatusEnum;
import cn.stylefeng.roses.kernel.sms.modular.enums.SmsTypeEnum;
import cn.stylefeng.roses.kernel.sms.modular.mapper.SysSmsMapper;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsInfoParam;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsSendParam; import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsSendParam;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsVerifyParam; import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsVerifyParam;
import cn.stylefeng.roses.kernel.sms.modular.service.SysSmsInfoService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -54,7 +54,7 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
// 1. 如果是纯消息发送,直接发送,校验类短信要把验证码存库 // 1. 如果是纯消息发送,直接发送,校验类短信要把验证码存库
if (SmsTypeEnum.MESSAGE.equals(sysSmsSendParam.getSmsTypeEnum())) { if (SmsTypeEnum.MESSAGE.equals(sysSmsSendParam.getSmsTypeEnum())) {
smsSenderApi.sendSms(sysSmsSendParam.getPhoneNumbers(), sysSmsSendParam.getTemplateCode(), params); smsSenderApi.sendSms(sysSmsSendParam.getPhoneNumber(), sysSmsSendParam.getTemplateCode(), params);
} }
// 2. 如果参数中有code参数则获取参数param中的code值 // 2. 如果参数中有code参数则获取参数param中的code值
@ -75,10 +75,10 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
// 4. 存储短信到数据库 // 4. 存储短信到数据库
Long smsId = this.saveSmsInfo(sysSmsSendParam, validateCode); Long smsId = this.saveSmsInfo(sysSmsSendParam, validateCode);
log.info(">>> 开始发送短信:发送的电话号码= " + sysSmsSendParam.getPhoneNumbers() + ",发送的模板号=" + sysSmsSendParam.getTemplateCode() + ",发送的参数是:" + JSON.toJSONString(params)); log.info(">>> 开始发送短信:发送的电话号码= " + sysSmsSendParam.getPhoneNumber() + ",发送的模板号=" + sysSmsSendParam.getTemplateCode() + ",发送的参数是:" + JSON.toJSONString(params));
// 5. 发送短信 // 5. 发送短信
smsSenderApi.sendSms(sysSmsSendParam.getPhoneNumbers(), sysSmsSendParam.getTemplateCode(), params); smsSenderApi.sendSms(sysSmsSendParam.getPhoneNumber(), sysSmsSendParam.getTemplateCode(), params);
// 6. 更新短信发送状态 // 6. 更新短信发送状态
this.updateSmsInfo(smsId, SmsSendStatusEnum.SUCCESS); this.updateSmsInfo(smsId, SmsSendStatusEnum.SUCCESS);
@ -100,8 +100,8 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
SysSms sysSms = new SysSms(); SysSms sysSms = new SysSms();
sysSms.setCreateTime(nowDate); sysSms.setCreateTime(nowDate);
sysSms.setInvalidTime(invalidate); sysSms.setInvalidTime(invalidate);
sysSms.setPhoneNumbers(sysSmsSendParam.getPhoneNumbers()); sysSms.setPhoneNumber(sysSmsSendParam.getPhoneNumber());
sysSms.setStatus(SmsSendStatusEnum.WAITING.getCode()); sysSms.setStatusFlag(SmsSendStatusEnum.WAITING.getCode());
sysSms.setSource(sysSmsSendParam.getSmsSendSourceEnum().getCode()); sysSms.setSource(sysSmsSendParam.getSmsSendSourceEnum().getCode());
sysSms.setTemplateCode(sysSmsSendParam.getTemplateCode()); sysSms.setTemplateCode(sysSmsSendParam.getTemplateCode());
sysSms.setValidateCode(validateCode); sysSms.setValidateCode(validateCode);
@ -110,13 +110,13 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
log.info(">>> 发送短信,存储短信到数据库,数据为:" + JSON.toJSONString(sysSms)); log.info(">>> 发送短信,存储短信到数据库,数据为:" + JSON.toJSONString(sysSms));
return sysSms.getId(); return sysSms.getSmsId();
} }
@Override @Override
public void updateSmsInfo(Long smsId, SmsSendStatusEnum smsSendStatusEnum) { public void updateSmsInfo(Long smsId, SmsSendStatusEnum smsSendStatusEnum) {
SysSms sysSms = this.getById(smsId); SysSms sysSms = this.getById(smsId);
sysSms.setStatus(smsSendStatusEnum.getCode()); sysSms.setStatusFlag(smsSendStatusEnum.getCode());
this.updateById(sysSms); this.updateById(sysSms);
} }
@ -126,7 +126,7 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
// 查询有没有这条记录 // 查询有没有这条记录
LambdaQueryWrapper<SysSms> smsQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysSms> smsQueryWrapper = new LambdaQueryWrapper<>();
smsQueryWrapper.eq(SysSms::getPhoneNumbers, sysSmsVerifyParam.getPhoneNumbers()) smsQueryWrapper.eq(SysSms::getPhoneNumber, sysSmsVerifyParam.getPhoneNumber())
.and(f -> f.eq(SysSms::getSource, sysSmsVerifyParam.getSmsSendSourceEnum().getCode())) .and(f -> f.eq(SysSms::getSource, sysSmsVerifyParam.getSmsSendSourceEnum().getCode()))
.and(f -> f.eq(SysSms::getTemplateCode, sysSmsVerifyParam.getTemplateCode())); .and(f -> f.eq(SysSms::getTemplateCode, sysSmsVerifyParam.getTemplateCode()));
smsQueryWrapper.orderByDesc(SysSms::getCreateTime); smsQueryWrapper.orderByDesc(SysSms::getCreateTime);
@ -144,7 +144,7 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
SysSms sysSms = sysSmsList.get(0); SysSms sysSms = sysSmsList.get(0);
// 先判断状态是不是失效的状态 // 先判断状态是不是失效的状态
if (SmsSendStatusEnum.INVALID.getCode().equals(sysSms.getStatus())) { if (SmsSendStatusEnum.INVALID.getCode().equals(sysSms.getStatusFlag())) {
throw new SmsException(SMS_VALIDATE_ERROR_INVALIDATE_STATUS); throw new SmsException(SMS_VALIDATE_ERROR_INVALIDATE_STATUS);
} }
@ -160,7 +160,7 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
} }
// 验证成功把短信设置成失效 // 验证成功把短信设置成失效
sysSms.setStatus(SmsSendStatusEnum.INVALID.getCode()); sysSms.setStatusFlag(SmsSendStatusEnum.INVALID.getCode());
this.updateById(sysSms); this.updateById(sysSms);
} }
@ -171,13 +171,13 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
if (ObjectUtil.isNotNull(sysSmsInfoParam)) { if (ObjectUtil.isNotNull(sysSmsInfoParam)) {
// 根据手机号模糊查询 // 根据手机号模糊查询
if (ObjectUtil.isNotEmpty(sysSmsInfoParam.getPhoneNumbers())) { if (ObjectUtil.isNotEmpty(sysSmsInfoParam.getPhoneNumber())) {
queryWrapper.like(SysSms::getPhoneNumbers, sysSmsInfoParam.getPhoneNumbers()); queryWrapper.like(SysSms::getPhoneNumber, sysSmsInfoParam.getPhoneNumber());
} }
// 根据发送状态查询(字典 0 未发送1 发送成功2 发送失败3 失效) // 根据发送状态查询(字典 0 未发送1 发送成功2 发送失败3 失效)
if (ObjectUtil.isNotEmpty(sysSmsInfoParam.getStatus())) { if (ObjectUtil.isNotEmpty(sysSmsInfoParam.getStatusFlag())) {
queryWrapper.eq(SysSms::getStatus, sysSmsInfoParam.getStatus()); queryWrapper.eq(SysSms::getStatusFlag, sysSmsInfoParam.getStatusFlag());
} }
// 根据来源查询(字典 1 app 2 pc 3 其他) // 根据来源查询(字典 1 app 2 pc 3 其他)