瀏覽代碼

解决短信发送一系列BUG

wukai 1 年之前
父節點
當前提交
8086299267

+ 1 - 1
doc-biz/src/main/java/com/doc/biz/controller/DocSpaceExpansionController.java

@@ -111,7 +111,7 @@ public class DocSpaceExpansionController extends BaseController {
         Pair<Boolean, String> pair = userService.isOnline(expansion.getCreated());
         if (!pair.getKey()) {
             //如果不在线发送短信
-            smsService.send(SmsType.CAP_EXPAND_SUCCESS, pair.getValue(), space.getFreeCap().toString() + "GB");
+            smsService.send(SmsType.CAP_EXPAND_SUCCESS, pair.getValue(), space.getFreeCap().setScale(2) + "GB");
         }
         return success(docSpaceExpansionService.updateDocSpaceExpansion(expansion));
     }

+ 29 - 77
doc-system/src/main/java/com/doc/sms/domain/SmsRecord.java

@@ -1,12 +1,13 @@
 package com.doc.sms.domain;
 
 import com.baomidou.mybatisplus.annotation.TableId;
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
 import com.doc.common.annotation.Excel;
 import com.doc.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
 
 /**
  * 短信记录对象 sms_record
@@ -15,105 +16,56 @@ import com.doc.common.core.domain.BaseEntity;
  * @date 2024-01-19
  */
 @ApiModel(value = "SmsRecord", description = "短信记录")
-public class SmsRecord extends BaseEntity
-{
+@Data
+public class SmsRecord extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** 记录ID */
+    /**
+     * 记录ID
+     */
     @ApiModelProperty("记录ID")
     @Excel(name = "记录ID")
     @TableId
     private Long recordId;
 
-    /** 接收手机号 */
+    /**
+     * 接收手机号
+     */
     @ApiModelProperty("接收手机号")
     @Excel(name = "接收手机号")
     private String sendPhone;
 
-    /** 数据 */
+    /**
+     * 数据
+     */
     @ApiModelProperty("数据")
     @Excel(name = "数据")
     private String sendContent;
 
-    /** 模板ID */
+    /**
+     * 模板ID
+     */
     @ApiModelProperty("模板ID")
     @Excel(name = "模板ID")
     private String templateId;
 
-    /** 成功状态 */
+    /**
+     * 成功状态
+     */
     @ApiModelProperty("成功状态")
     @Excel(name = "成功状态")
     private String snedSuccess;
 
-    /** 返回值 */
+    /**
+     * 返回值
+     */
     @ApiModelProperty("返回值")
     @Excel(name = "返回值")
     private String sendResult;
 
-    public void setRecordId(Long recordId)
-    {
-        this.recordId = recordId;
-    }
-
-    public Long getRecordId()
-    {
-        return recordId;
-    }
-    public void setSendPhone(String sendPhone)
-    {
-        this.sendPhone = sendPhone;
-    }
-
-    public String getSendPhone()
-    {
-        return sendPhone;
-    }
-    public void setSendContent(String sendContent)
-    {
-        this.sendContent = sendContent;
-    }
-
-    public String getSendContent()
-    {
-        return sendContent;
-    }
-    public void setTemplateId(String templateId)
-    {
-        this.templateId = templateId;
-    }
-
-    public String getTemplateId()
-    {
-        return templateId;
-    }
-    public void setSnedSuccess(String snedSuccess)
-    {
-        this.snedSuccess = snedSuccess;
-    }
-
-    public String getSnedSuccess()
-    {
-        return snedSuccess;
-    }
-    public void setSendResult(String sendResult)
-    {
-        this.sendResult = sendResult;
-    }
-
-    public String getSendResult()
-    {
-        return sendResult;
-    }
+    @ApiModelProperty("发送时间")
+    private Date sendTime;
+    @ApiModelProperty("短信类型")
+    private Integer smsType;
 
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("recordId", getRecordId())
-            .append("sendPhone", getSendPhone())
-            .append("sendContent", getSendContent())
-            .append("templateId", getTemplateId())
-            .append("snedSuccess", getSnedSuccess())
-            .append("sendResult", getSendResult())
-            .toString();
-    }
 }

+ 3 - 1
doc-system/src/main/java/com/doc/sms/service/impl/SmsRecordServiceImpl.java

@@ -6,6 +6,7 @@ import com.doc.sms.service.ISmsRecordService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -49,7 +50,8 @@ public class SmsRecordServiceImpl implements ISmsRecordService {
      */
     @Override
     public int insertSmsRecord(SmsRecord smsRecord) {
-            return smsRecordMapper.insertSmsRecord(smsRecord);
+        smsRecord.setSendTime(new Date());
+        return smsRecordMapper.insertSmsRecord(smsRecord);
     }
 
     /**

+ 1 - 0
doc-system/src/main/java/com/doc/sms/service/impl/SmsServiceImpl.java

@@ -108,6 +108,7 @@ public class SmsServiceImpl implements ISmsService {
         SmsRecord record = new SmsRecord();
         record.setSendContent(JSON.toJSONString(data));
         record.setTemplateId(templateId);
+        record.setSmsType(smsType.ordinal());
         record.setSendPhone(phone);
         try {
             SendSmsResponse res = sendTencentSms(phone, templateId, data);

+ 29 - 18
doc-system/src/main/resources/mapper/sms/SmsRecordMapper.xml

@@ -1,32 +1,37 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.doc.sms.mapper.SmsRecordMapper">
 
     <resultMap type="SmsRecord" id="SmsRecordResult">
-        <result property="recordId"    column="RECORD_ID"    />
-        <result property="sendPhone"    column="SEND_PHONE"    />
-        <result property="sendContent"    column="SEND_CONTENT"    />
-        <result property="templateId"    column="TEMPLATE_ID"    />
-        <result property="snedSuccess"    column="SNED_SUCCESS"    />
-        <result property="sendResult"    column="SEND_RESULT"    />
+        <result property="recordId" column="RECORD_ID"/>
+        <result property="sendPhone" column="SEND_PHONE"/>
+        <result property="sendContent" column="SEND_CONTENT"/>
+        <result property="templateId" column="TEMPLATE_ID"/>
+        <result property="snedSuccess" column="SNED_SUCCESS"/>
+        <result property="sendResult" column="SEND_RESULT"/>
+        <result property="sendTime" column="SEND_TIME"/>
+        <result property="smsType" column="SMS_TYPE"/>
     </resultMap>
 
     <sql id="selectSmsRecordVo">
-        select RECORD_ID, SEND_PHONE, SEND_CONTENT, TEMPLATE_ID, SNED_SUCCESS, SEND_RESULT from sms_record
+        select RECORD_ID, SEND_PHONE, SEND_CONTENT, TEMPLATE_ID, SNED_SUCCESS, SEND_RESULT, SEND_TIME,SMS_TYPE
+        from sms_record
     </sql>
 
     <select id="selectSmsRecordList" parameterType="SmsRecord" resultMap="SmsRecordResult">
         <include refid="selectSmsRecordVo"/>
         <where>
-            <if test="recordId != null "> and RECORD_ID = #{recordId}</if>
-            <if test="sendPhone != null  and sendPhone != ''"> and SEND_PHONE = #{sendPhone}</if>
-            <if test="sendContent != null  and sendContent != ''"> and SEND_CONTENT = #{sendContent}</if>
-            <if test="templateId != null  and templateId != ''"> and TEMPLATE_ID = #{templateId}</if>
-            <if test="snedSuccess != null  and snedSuccess != ''"> and SNED_SUCCESS = #{snedSuccess}</if>
-            <if test="sendResult != null  and sendResult != ''"> and SEND_RESULT = #{sendResult}</if>
+            <if test="recordId != null ">and RECORD_ID = #{recordId}</if>
+            <if test="sendPhone != null  and sendPhone != ''">and SEND_PHONE = #{sendPhone}</if>
+            <if test="sendContent != null  and sendContent != ''">and SEND_CONTENT = #{sendContent}</if>
+            <if test="templateId != null  and templateId != ''">and TEMPLATE_ID = #{templateId}</if>
+            <if test="snedSuccess != null  and snedSuccess != ''">and SNED_SUCCESS = #{snedSuccess}</if>
+            <if test="sendResult != null  and sendResult != ''">and SEND_RESULT = #{sendResult}</if>
+            <if test="smsType != null  and smsType != ''">and SMS_TYPE = #{smsType}</if>
         </where>
+        order by send_time desc
     </select>
 
     <select id="selectSmsRecordByRecordId" parameterType="Long" resultMap="SmsRecordResult">
@@ -43,7 +48,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="templateId != null">TEMPLATE_ID,</if>
             <if test="snedSuccess != null">SNED_SUCCESS,</if>
             <if test="sendResult != null">SEND_RESULT,</if>
-         </trim>
+            <if test="sendTime != null">SEND_TIME,</if>
+            <if test="smsType != null">SMS_TYPE,</if>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="recordId != null">#{recordId},</if>
             <if test="sendPhone != null">#{sendPhone},</if>
@@ -51,7 +58,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="templateId != null">#{templateId},</if>
             <if test="snedSuccess != null">#{snedSuccess},</if>
             <if test="sendResult != null">#{sendResult},</if>
-         </trim>
+            <if test="sendTime != null">#{sendTime},</if>
+            <if test="smsType != null">#{smsType},</if>
+        </trim>
     </insert>
 
     <update id="updateSmsRecord" parameterType="SmsRecord">
@@ -67,7 +76,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </update>
 
     <delete id="deleteSmsRecordByRecordId" parameterType="Long">
-        delete from sms_record where RECORD_ID = #{recordId}
+        delete
+        from sms_record
+        where RECORD_ID = #{recordId}
     </delete>
 
     <delete id="deleteSmsRecordByRecordIds" parameterType="String">