From 0c4feb51a07d2fb691fb8084a1e8ca1ef5e16fcc Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Sat, 19 Dec 2020 16:46:33 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90sms=E3=80=91=E6=95=B4=E7=90=86sms?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E5=AD=97=E6=AE=B5=E5=92=8C=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernel/sms/modular/entity/SysSms.java | 26 ++++++----- .../sms/modular/param/SysSmsInfoParam.java | 17 +++---- .../sms/modular/param/SysSmsSendParam.java | 2 +- .../sms/modular/param/SysSmsVerifyParam.java | 2 +- .../service/impl/SysSmsInfoServiceImpl.java | 44 +++++++++---------- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/entity/SysSms.java b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/entity/SysSms.java index d75ab844c..3d8288025 100644 --- a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/entity/SysSms.java +++ b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/entity/SysSms.java @@ -1,11 +1,11 @@ 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.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; -import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity; import lombok.Data; import lombok.EqualsAndHashCode; @@ -28,13 +28,14 @@ public class SysSms extends BaseEntity implements Serializable { /** * 主键 */ - @TableId(type = IdType.ASSIGN_ID) - private Long id; + @TableId(value = "sms_id", type = IdType.ASSIGN_ID) + private Long smsId; + /** * 手机号 */ - @TableField("phone_numbers") - private String phoneNumbers; + @TableField("phone_number") + private String phoneNumber; /** * 短信验证码 @@ -43,33 +44,34 @@ public class SysSms extends BaseEntity implements Serializable { private String validateCode; /** - * 短信模板ID + * 短信模板编号 */ @TableField("template_code") private String templateCode; /** - * 回执id,可根据该id查询具体的发送状态 + * 业务id */ @TableField("biz_id") private String bizId; /** - * 发送状态(字典 0 未发送,1 发送成功,2 发送失败,3 失效) + * 发送状态:1-未发送,2-发送成功,3-发送失败,4-失效 */ - @TableField("status") - private Integer status; + @TableField("status_flag") + private Integer statusFlag; /** - * 来源(字典 1 app, 2 pc, 3 其他) + * 来源:1-app,2-pc,3-其他 */ @TableField("source") private Integer source; /** - * 失效时间 + * 短信失效截止时间 */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("invalid_time") private Date invalidTime; + } diff --git a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsInfoParam.java b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsInfoParam.java index 3f1c174ff..48f02036b 100644 --- a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsInfoParam.java +++ b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsInfoParam.java @@ -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; /** - * 短信模板ID + * 短信模板编号 */ private String templateCode; /** - * 回执id,可根据该id查询具体的发送状态 + * 业务id */ private String bizId; /** - * 发送状态(字典 0 未发送,1 发送成功,2 发送失败,3 失效) + * 发送状态:1-未发送,2-发送成功,3-发送失败,4-失效 */ - private Integer status; + private Integer statusFlag; /** - * 来源(字典 1 app, 2 pc, 3 其他) + * 来源:1-app,2-pc,3-其他 */ private Integer source; /** - * 失效时间 + * 短信失效截止时间 */ private Date invalidTime; + } diff --git a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsSendParam.java b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsSendParam.java index 672615dbb..b5f97ec95 100644 --- a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsSendParam.java +++ b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsSendParam.java @@ -20,7 +20,7 @@ public class SysSmsSendParam { * 手机号 */ @NotBlank(message = "手机号码为空,请检查phoneNumbers参数") - private String phoneNumbers; + private String phoneNumber; /** * 模板号 diff --git a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsVerifyParam.java b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsVerifyParam.java index 21809f3b6..6d416a122 100644 --- a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsVerifyParam.java +++ b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/param/SysSmsVerifyParam.java @@ -18,7 +18,7 @@ public class SysSmsVerifyParam { * 手机号 */ @NotBlank(message = "手机号不能为空") - private String phoneNumbers; + private String phoneNumber; /** * 验证码 diff --git a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/service/impl/SysSmsInfoServiceImpl.java b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/service/impl/SysSmsInfoServiceImpl.java index 0f0a41f44..8bce7ef38 100644 --- a/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/service/impl/SysSmsInfoServiceImpl.java +++ b/kernel-d-sms/sms-business-validation/src/main/java/cn/stylefeng/roses/kernel/sms/modular/service/impl/SysSmsInfoServiceImpl.java @@ -3,14 +3,6 @@ package cn.stylefeng.roses.kernel.sms.modular.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; 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.PageResultFactory; 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.modular.entity.SysSms; 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.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 org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -54,7 +54,7 @@ public class SysSmsInfoServiceImpl extends ServiceImpl imp // 1. 如果是纯消息发送,直接发送,校验类短信要把验证码存库 if (SmsTypeEnum.MESSAGE.equals(sysSmsSendParam.getSmsTypeEnum())) { - smsSenderApi.sendSms(sysSmsSendParam.getPhoneNumbers(), sysSmsSendParam.getTemplateCode(), params); + smsSenderApi.sendSms(sysSmsSendParam.getPhoneNumber(), sysSmsSendParam.getTemplateCode(), params); } // 2. 如果参数中有code参数,则获取参数param中的code值 @@ -75,10 +75,10 @@ public class SysSmsInfoServiceImpl extends ServiceImpl imp // 4. 存储短信到数据库 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. 发送短信 - smsSenderApi.sendSms(sysSmsSendParam.getPhoneNumbers(), sysSmsSendParam.getTemplateCode(), params); + smsSenderApi.sendSms(sysSmsSendParam.getPhoneNumber(), sysSmsSendParam.getTemplateCode(), params); // 6. 更新短信发送状态 this.updateSmsInfo(smsId, SmsSendStatusEnum.SUCCESS); @@ -100,8 +100,8 @@ public class SysSmsInfoServiceImpl extends ServiceImpl imp SysSms sysSms = new SysSms(); sysSms.setCreateTime(nowDate); sysSms.setInvalidTime(invalidate); - sysSms.setPhoneNumbers(sysSmsSendParam.getPhoneNumbers()); - sysSms.setStatus(SmsSendStatusEnum.WAITING.getCode()); + sysSms.setPhoneNumber(sysSmsSendParam.getPhoneNumber()); + sysSms.setStatusFlag(SmsSendStatusEnum.WAITING.getCode()); sysSms.setSource(sysSmsSendParam.getSmsSendSourceEnum().getCode()); sysSms.setTemplateCode(sysSmsSendParam.getTemplateCode()); sysSms.setValidateCode(validateCode); @@ -110,13 +110,13 @@ public class SysSmsInfoServiceImpl extends ServiceImpl imp log.info(">>> 发送短信,存储短信到数据库,数据为:" + JSON.toJSONString(sysSms)); - return sysSms.getId(); + return sysSms.getSmsId(); } @Override public void updateSmsInfo(Long smsId, SmsSendStatusEnum smsSendStatusEnum) { SysSms sysSms = this.getById(smsId); - sysSms.setStatus(smsSendStatusEnum.getCode()); + sysSms.setStatusFlag(smsSendStatusEnum.getCode()); this.updateById(sysSms); } @@ -126,7 +126,7 @@ public class SysSmsInfoServiceImpl extends ServiceImpl imp // 查询有没有这条记录 LambdaQueryWrapper 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::getTemplateCode, sysSmsVerifyParam.getTemplateCode())); smsQueryWrapper.orderByDesc(SysSms::getCreateTime); @@ -144,7 +144,7 @@ public class SysSmsInfoServiceImpl extends ServiceImpl imp 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); } @@ -160,7 +160,7 @@ public class SysSmsInfoServiceImpl extends ServiceImpl imp } // 验证成功把短信设置成失效 - sysSms.setStatus(SmsSendStatusEnum.INVALID.getCode()); + sysSms.setStatusFlag(SmsSendStatusEnum.INVALID.getCode()); this.updateById(sysSms); } @@ -171,13 +171,13 @@ public class SysSmsInfoServiceImpl extends ServiceImpl imp if (ObjectUtil.isNotNull(sysSmsInfoParam)) { // 根据手机号模糊查询 - if (ObjectUtil.isNotEmpty(sysSmsInfoParam.getPhoneNumbers())) { - queryWrapper.like(SysSms::getPhoneNumbers, sysSmsInfoParam.getPhoneNumbers()); + if (ObjectUtil.isNotEmpty(sysSmsInfoParam.getPhoneNumber())) { + queryWrapper.like(SysSms::getPhoneNumber, sysSmsInfoParam.getPhoneNumber()); } // 根据发送状态查询(字典 0 未发送,1 发送成功,2 发送失败,3 失效) - if (ObjectUtil.isNotEmpty(sysSmsInfoParam.getStatus())) { - queryWrapper.eq(SysSms::getStatus, sysSmsInfoParam.getStatus()); + if (ObjectUtil.isNotEmpty(sysSmsInfoParam.getStatusFlag())) { + queryWrapper.eq(SysSms::getStatusFlag, sysSmsInfoParam.getStatusFlag()); } // 根据来源查询(字典 1 app, 2 pc, 3 其他)