Browse Source

#ADD 未支付、补单 短信发送

tanbin 1 year ago
parent
commit
3a9cdbffe8

+ 16 - 0
sys-api-service/src/main/java/com/xy/service/AliSmsServiceImpl.java

@@ -1,6 +1,7 @@
 package com.xy.service;
 
 import com.xy.dto.SmsDTO;
+import com.xy.dto.SmsSendCommonDTO;
 import com.xy.dto.SmsSendDTO;
 import com.xy.enums.SmsSceneEnum;
 import com.xy.error.CommRuntimeException;
@@ -61,5 +62,20 @@ public class AliSmsServiceImpl implements AliSmsService {
         return R.ok(smsUtil.verifyCode(smsDTO.getMobile(), smsDTO.getSmsSceneEnum(), smsDTO.getUid(), smsDTO.getCode()));
     }
 
+    @Override
+    public R sendMsgCommon(SmsSendCommonDTO smsSendDTO) {
+        String mobile = smsSendDTO.getMobile();
+        Integer scene = smsSendDTO.getScene();
+        String paramValue = smsSendDTO.getParamValue();
+        Long msgConfigId = smsSendDTO.getMsgConfigId();
+        SmsSceneEnum smsSceneEnum = SmsSceneEnum.getCodeByScene(scene);
+        if (smsSceneEnum == null) {
+            throw new CommRuntimeException("发送场景有误!");
+        }
+        //发短信验证码
+        smsUtil.sendSmsCommon(mobile, msgConfigId, paramValue);
+        return R.ok();
+    }
+
 
 }

+ 26 - 0
sys-api-service/src/main/java/com/xy/service/SmsUtilAliImplService.java

@@ -114,6 +114,32 @@ public class SmsUtilAliImplService implements SmsUtil {
         setCacheCode(cacheKey, code);
     }
 
+    @Override
+    public void sendSmsCommon(String mobile, Long configId, String paramValue) {
+        MsgConfigDto.Vo msgConfig = R.feignCheckData(msgSendApiService.getMsgConfig(new MsgConfigDto.Vo().setId(configId)));
+        List<MsgConfigTestDto.BizParam> bizParams = R.feignCheckData(msgSendApiService.getBizParamByMsgConfig(new MsgConfigTestDto.MsgConfig().setConfigId(configId)));
+        if (CollUtil.isNotEmpty(bizParams) && msgConfig != null) {
+            List<MsgConfigTestDto.BizData> bizDataList = BeanUtil.copyToList(bizParams, MsgConfigTestDto.BizData.class);
+            List<MsgConfigTestDto.BizData> sendList = new ArrayList<>();
+            for (MsgConfigTestDto.BizData b : bizDataList) {
+                String channelType = b.getChannelType();
+                if (Integer.valueOf(channelType).intValue() == ChannelType.SMS.getCode().intValue()) {
+                    Map<String, Object> params = MapUtil.newHashMap();
+                    params.put("data", paramValue);
+                    b.setReceivers(CollUtil.newHashSet(mobile));
+                    b.setTemplateParams(params);
+                    sendList.add(b);
+                }
+            }
+            MsgConfigTestDto.SendByMsgConfig sendByMsgConfig = new MsgConfigTestDto.SendByMsgConfig().setConfigId(configId).setBizDataList(sendList);
+            log.info("通用短信发送参数-->{}", JSONUtil.toJsonStr(sendByMsgConfig));
+            msgSendApiService.sendByMsgConfig(sendByMsgConfig);
+
+
+        }
+
+    }
+
     @Override
     public boolean verifyCode(String mobile, SmsSceneEnum smsSceneEnum, String uuid, String code) {
         String cacheKey = cacheKey(smsSceneEnum, mobile, uuid);

+ 34 - 0
sys-api/src/main/java/com/xy/dto/SmsSendCommonDTO.java

@@ -0,0 +1,34 @@
+package com.xy.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+
+@Data
+@Accessors(chain = true)
+public class SmsSendCommonDTO {
+
+    @NotBlank(message = "手机号不能为空")
+    private String mobile;
+
+    @NotNull(message = "发送场景不能为空")
+    private Integer scene;
+
+
+    @NotBlank(message = "短信模板参数值")
+    @ApiModelProperty(value = "短信模板参数值")
+    private String paramValue;
+
+    @NotNull(message = "手机号不能为空")
+    @ApiModelProperty(value = "消息配置ID")
+    private Long msgConfigId;
+
+    @ApiModelProperty(value = "用户ID")
+    private Long userInfoId;
+
+
+}

+ 3 - 1
sys-api/src/main/java/com/xy/enums/MsgConfigId.java

@@ -19,7 +19,9 @@ public enum MsgConfigId {
     RISK_ORDER(14L, "异常订单通知"),
     CUT_ORDER(13L, "补扣成功通知"),
     DEVICE_EXCEPTION(12L, "设备故障提醒"),
-    SMS_CODE(15L, "短信验证码");
+    SMS_CODE(15L, "短信验证码"),
+    SMS_NOTIFY_C1(20L, "C端短信通知-未支付"),
+    SMS_NOTIFY_C2(21L, "C端短信通知-补单");
 
     /**
      * 编码值

+ 3 - 1
sys-api/src/main/java/com/xy/enums/SmsSceneEnum.java

@@ -19,7 +19,9 @@ public enum SmsSceneEnum {
     B_ALIPAY_BIND(3, "B端设置 - 绑定支付宝"),
     B_PAY_ACCOUNT_WX_CONFIG(4, "商户信息修改 - 微信收款号配置"),
     B_PAY_ACCOUNT_ALIPAY_SCAN_CONFIG(5, "商户信息修改 - 支付宝扫码收款号配置"),
-    B_PAY_ACCOUNT_ALIPAY_FACE_CONFIG(6, "商户信息修改 - 支付刷脸收款号配置");
+    B_PAY_ACCOUNT_ALIPAY_FACE_CONFIG(6, "商户信息修改 - 支付刷脸收款号配置"),
+    C_UN_PAY_NOTIFY(7, "C端订单 - 余额不足-未支付"),
+    C_FILL_ORDER_NOTIFY(8, "C端订单 - 补单");
 
 
     /**

+ 11 - 0
sys-api/src/main/java/com/xy/service/AliSmsService.java

@@ -2,6 +2,7 @@ package com.xy.service;
 
 import com.xy.annotate.RestMappingController;
 import com.xy.dto.SmsDTO;
+import com.xy.dto.SmsSendCommonDTO;
 import com.xy.dto.SmsSendDTO;
 import com.xy.utils.R;
 import org.springframework.validation.annotation.Validated;
@@ -27,4 +28,14 @@ public interface AliSmsService {
      */
     @PostMapping("verifyCode")
     R<Boolean> verifyCode(@RequestBody @Validated SmsDTO.Validation smsDTO);
+
+    /**
+     * 短信发送通用 (目前只支持阿里云短信,且占位参数名为 data)
+     *
+     * @param smsSendDTO
+     * @return {@link R}
+     */
+    @PostMapping("sendMsgCommon")
+    R sendMsgCommon(@RequestBody @Validated SmsSendCommonDTO smsSendDTO);
+
 }

+ 9 - 0
sys-api/src/main/java/com/xy/service/SmsUtil.java

@@ -22,6 +22,15 @@ public interface SmsUtil {
      */
     void sendSmsCode(String mobile, SmsSceneEnum smsSceneEnum, String uid);
 
+    /**
+     * 发送短信通用
+     *
+     * @param mobile
+     * @param msgConfigId
+     * @param paramValue
+     */
+    void sendSmsCommon(String mobile, Long msgConfigId, String paramValue);
+
     /**
      * 验证码验证
      *