refactor(sms): 重构短信发送功能并优化数据库配置
- 移除旧的短信发送实现和相关依赖 - 引入新的短信发送服务接口和实现 - 添加短信发送记录实体和数据访问层 - 创建短信发送控制器提供REST API - 实现带重试机制的短信发送功能 - 添加系统凭证管理和缓存机制 - 更新数据库连接配置信息 - 修改统计查询接口参数类型 - 清理过时的代码和服务方法
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.njcn.user.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.user.api.fallback.SmsSendClientFallbackFactory;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.USER, path = "/sms", fallbackFactory = SmsSendClientFallbackFactory.class,contextId = "sms")
|
||||
public interface SmsSendFeignClient {
|
||||
|
||||
@PostMapping("/send/simple")
|
||||
@ApiOperation("发送短信(简化参数)")
|
||||
HttpResult<String> sendSmsSimple(@RequestParam("receiver") String receiver
|
||||
, @RequestParam("content") String content
|
||||
, @RequestParam("messageType") String messageType);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.njcn.user.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.user.api.SmsSendFeignClient;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SmsSendClientFallbackFactory implements FallbackFactory<SmsSendFeignClient> {
|
||||
@Override
|
||||
public SmsSendFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new SmsSendFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> sendSmsSimple(String receiver, String content, String messageType) {
|
||||
log.error("{}异常,降级处理,异常为:{}","发送短信(简化参数)数据异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.user.pojo.dto;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-31
|
||||
*/
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 系统凭证请求 DTO
|
||||
*
|
||||
* @author msgpush
|
||||
*/
|
||||
@Data
|
||||
public class CredentialReqDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 上游系统名称
|
||||
*/
|
||||
@NotEmpty(message = "上游系统名称不能为空")
|
||||
private String systemName;
|
||||
|
||||
/**
|
||||
* 密钥(用于生成凭证)
|
||||
*/
|
||||
@NotEmpty(message = "密钥不能为空")
|
||||
private String secretKey;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.njcn.user.pojo.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class SendResult implements Serializable {
|
||||
|
||||
private final boolean success;
|
||||
private final String messageId;
|
||||
private final String failReason;
|
||||
private final boolean isTimeOut;
|
||||
private final boolean unauthorized;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.njcn.user.pojo.po.app;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_send_record")
|
||||
public class SmsSendRecord implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
private String receiver;
|
||||
|
||||
private String content;
|
||||
|
||||
private String messageType;
|
||||
|
||||
private String credentialToken;
|
||||
|
||||
private Integer sendStatus;
|
||||
|
||||
@TableField(updateStrategy = FieldStrategy.IGNORED)
|
||||
private String failReason;
|
||||
|
||||
private Integer retryCount;
|
||||
|
||||
private Integer maxRetry;
|
||||
|
||||
private Long responseTime;
|
||||
|
||||
private LocalDateTime sendTime;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.njcn.user.pojo.vo.app;
|
||||
|
||||
import cn.hutool.core.lang.RegexPool;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
@Data
|
||||
@Schema(description = "管理后台 - 消息记录发送 Request VO")
|
||||
public class MessageRecordReqVO {
|
||||
|
||||
private String channel;
|
||||
|
||||
@Schema(description = "消息类型", example = "verify_code/order_notify/marketing/system_notify")
|
||||
@NotBlank(message = "消息类型不能为空")
|
||||
private String messageType;
|
||||
|
||||
@Schema(description = "接收者")
|
||||
@NotBlank(message = "接收者不能为空")
|
||||
@Pattern(regexp = RegexPool.EMAIL + "|" + RegexPool.MOBILE, message = "必须是有效的邮箱或手机号格式")
|
||||
private String receiver;
|
||||
|
||||
@Schema(description = "标题")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "消息内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "模板编码")
|
||||
private String templateCode;
|
||||
|
||||
@Schema(description = "模板参数")
|
||||
private String templateParams;
|
||||
}
|
||||
Reference in New Issue
Block a user