Browse Source

add
新增短信发送接口

18339543638 5 months ago
parent
commit
db1bda57c5

+ 1 - 1
pom.xml

@@ -5,7 +5,7 @@
     <modelVersion>4.0.0</modelVersion>
 
     <groupId>cn.tr</groupId>
-    <artifactId>tr-footstone</artifactId>
+    <artifactId>SmartFollowUp</artifactId>
     <version>${revision}</version>
     <packaging>pom</packaging>
     <description>驼人通用型管理框架</description>

+ 1 - 1
tr-framework/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>tr-footstone</artifactId>
+        <artifactId>SmartFollowUp</artifactId>
         <groupId>cn.tr</groupId>
         <version>${revision}</version>
     </parent>

+ 1 - 1
tr-modules-api/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>tr-footstone</artifactId>
+        <artifactId>SmartFollowUp</artifactId>
         <groupId>cn.tr</groupId>
         <version>${revision}</version>
     </parent>

+ 5 - 0
tr-modules-api/tr-module-system-api/pom.xml

@@ -17,6 +17,11 @@
             <artifactId>tr-framework</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>cn.tr</groupId>
+            <artifactId>tr-spring-boot-starter-plugin-doc</artifactId>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 
 </project>

+ 21 - 0
tr-modules-api/tr-module-system-api/src/main/java/cn/tr/module/api/sys/sms/BizSmsPOJO.java

@@ -0,0 +1,21 @@
+package cn.tr.module.api.sys.sms;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+
+
+@Data
+public class BizSmsPOJO {
+    @ApiModelProperty("短信类型 1、医生端登录 2、修改密码")
+    @NotNull(message = "短信类型不能为空")
+    private String type;
+
+    @ApiModelProperty("手机号")
+    @NotBlank(message = "手机号不能为空")
+    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
+    private String phone;
+}

+ 7 - 0
tr-modules-api/tr-module-system-api/src/main/java/cn/tr/module/api/sys/sms/SmsApi.java

@@ -0,0 +1,7 @@
+package cn.tr.module.api.sys.sms;
+
+import java.util.Map;
+
+public interface SmsApi {
+    String sendSms(String mobile, String templateCode, Map<String, Object> templateParam);
+}

+ 1 - 1
tr-modules/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>tr-footstone</artifactId>
+        <artifactId>SmartFollowUp</artifactId>
         <groupId>cn.tr</groupId>
         <version>${revision}</version>
     </parent>

+ 32 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/controller/BizSMSController.java

@@ -0,0 +1,32 @@
+package cn.tr.module.smart.common.controller;
+
+import cn.tr.core.pojo.CommonResult;
+import cn.tr.module.api.sys.sms.BizSmsPOJO;
+import cn.tr.module.smart.common.service.IBizSmsService;
+import cn.tr.plugin.mybatis.base.BaseController;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author wangzl
+ * @description: TODO
+ * @date 2025/6/9 15:07
+ */
+@Api(tags = "短信接口")
+@RestController
+@RequestMapping("/common/sms")
+@AllArgsConstructor
+public class BizSMSController extends BaseController {
+    private final IBizSmsService smsService;
+    @ApiOperationSupport(author = "lf", order = 1)
+    @ApiOperation(value = "发送手机验证码", notes = "权限: 无")
+    @PostMapping("/send")
+    public CommonResult<Boolean> selectList(@RequestBody @Validated BizSmsPOJO source) {
+        smsService.sendSingleSms(source);
+        return CommonResult.success(Boolean.TRUE);
+    }
+}

+ 1 - 1
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/entity/BizWxAppletQuestionAnswerEntity.java

@@ -23,4 +23,4 @@ public class BizWxAppletQuestionAnswerEntity {
 
     @ApiModelProperty("问题回答")
     private List<String> content;
-}
+}

+ 7 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/enums/SmsCodeEnums.java

@@ -0,0 +1,7 @@
+package cn.tr.module.smart.common.enums;
+
+public interface SmsCodeEnums {
+    String LOGIN="test";
+
+    String RESET="resetCode";
+}

+ 9 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/service/IBizSmsService.java

@@ -0,0 +1,9 @@
+package cn.tr.module.smart.common.service;
+
+import cn.tr.module.api.sys.sms.BizSmsPOJO;
+
+public interface IBizSmsService {
+    Boolean sendSingleSms(BizSmsPOJO source);
+
+    String getSmsCode(String type, String phone);
+}

+ 61 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/service/impl/BizSmsServiceImpl.java

@@ -0,0 +1,61 @@
+
+package cn.tr.module.smart.common.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.tr.core.exception.ServiceException;
+import cn.tr.core.exception.TRExcCode;
+import cn.tr.module.api.sys.sms.BizSmsPOJO;
+import cn.tr.module.api.sys.sms.SmsApi;
+import cn.tr.module.smart.common.enums.SmsCodeEnums;
+import cn.tr.module.smart.common.service.IBizSmsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+public class BizSmsServiceImpl implements IBizSmsService {
+    @Autowired
+    private SmsApi smsApi;
+
+    @Autowired
+    @Lazy
+    private BizSmsServiceImpl self;
+    @Override
+    public Boolean sendSingleSms(BizSmsPOJO source) {
+        if(ObjectUtil.isNull(source.getType())){
+            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"短信类型不能为空");
+        }
+        int validateCode = RandomUtil.randomInt(1000,9999);
+        Map<String, Object> param = new HashMap<>();
+        param.put("code",validateCode);
+        switch (source.getType()){
+            case "1":
+                smsApi.sendSms(source.getPhone(), SmsCodeEnums.LOGIN,param);
+                self.refreshSmsCode(source.getType(),source.getPhone(),String.valueOf(validateCode));
+                return Boolean.TRUE;
+            case "2":
+                smsApi.sendSms(source.getPhone(), SmsCodeEnums.RESET,param);
+                self.refreshSmsCode(source.getType(),source.getPhone(),String.valueOf(validateCode));
+                return Boolean.TRUE;
+            default:
+                throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"短信类型不支持");
+        }
+    }
+
+    @Cacheable(value = "sms:code", key = "#type+#phone")
+    @Override
+    public String getSmsCode(String type, String phone){
+        return null;
+    }
+
+    @CachePut(value = "sms:code",key = "#type+#phone")
+    public String refreshSmsCode(String type,String phone,String code){
+        return code;
+    }
+}

+ 6 - 1
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/sms/service/impl/SmsSendServiceImpl.java

@@ -8,6 +8,7 @@ import cn.tr.core.exception.ServiceException;
 import cn.tr.core.exception.TRExcCode;
 import cn.tr.core.pojo.KeyValue;
 import cn.tr.core.utils.JsonUtils;
+import cn.tr.module.api.sys.sms.SmsApi;
 import cn.tr.module.sys.sms.dto.SmsSendMessageDTO;
 import cn.tr.module.sys.sms.dto.SysSmsChannelDTO;
 import cn.tr.module.sys.sms.dto.SysSmsTempDTO;
@@ -41,7 +42,7 @@ import java.util.stream.Collectors;
 @Service
 @Slf4j
 @AllArgsConstructor
-public class SmsSendServiceImpl implements ISmsSendService {
+public class SmsSendServiceImpl implements ISmsSendService, SmsApi {
     private final ISysUserService userService;
 
     private final ISysSmsTempService smsTempService;
@@ -198,4 +199,8 @@ public class SmsSendServiceImpl implements ISmsSendService {
         eventBus.publishEx("/sms/send",message);
     }
 
+    @Override
+    public String sendSms(String mobile, String templateCode, Map<String, Object>  templateParam) {
+        return sendSingleSms(mobile,null,UserTypeEnum.MEMBER,templateCode, templateParam);
+    }
 }

+ 1 - 1
tr-plugins/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>tr-footstone</artifactId>
+        <artifactId>SmartFollowUp</artifactId>
         <groupId>cn.tr</groupId>
         <version>${revision}</version>
     </parent>

+ 1 - 1
tr-test/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>tr-footstone</artifactId>
+        <artifactId>SmartFollowUp</artifactId>
         <groupId>cn.tr</groupId>
         <version>${revision}</version>
     </parent>