Kaynağa Gözat

微信绑定表增加isDeleted字段,逻辑删除,不进行物理删除

Hai Lin 2 ay önce
ebeveyn
işleme
dd00b135e1

+ 13 - 3
mirage-service/src/main/java/com/mirage/mirageservice/domain/WechatBind.java

@@ -2,9 +2,9 @@ package com.mirage.mirageservice.domain;
 
 import java.util.Date;
 
-/** 
-* Created by hzlinhai on 2025/8/26. 
-*/
+/**
+ * Created by hzlinhai on 2025/9/2.
+ */
 public class WechatBind {
     private Integer id;
 
@@ -18,6 +18,8 @@ public class WechatBind {
 
     private Date createtime;
 
+    private Integer isdeleted;
+
     public Integer getId() {
         return id;
     }
@@ -65,4 +67,12 @@ public class WechatBind {
     public void setCreatetime(Date createtime) {
         this.createtime = createtime;
     }
+
+    public Integer getIsdeleted() {
+        return isdeleted;
+    }
+
+    public void setIsdeleted(Integer isdeleted) {
+        this.isdeleted = isdeleted;
+    }
 }

+ 5 - 7
mirage-service/src/main/java/com/mirage/mirageservice/mapper/mysql/WechatBindMapper.java

@@ -1,11 +1,11 @@
 package com.mirage.mirageservice.mapper.mysql;
-import org.apache.ibatis.annotations.Param;
 
 import com.mirage.mirageservice.domain.WechatBind;
+import org.apache.ibatis.annotations.Param;
 
-/** 
-* Created by hzlinhai on 2025/8/26. 
-*/
+/**
+ * Created by hzlinhai on 2025/9/2.
+ */
 public interface WechatBindMapper {
     int deleteByPrimaryKey(Integer id);
 
@@ -19,7 +19,5 @@ public interface WechatBindMapper {
 
     int updateByPrimaryKey(WechatBind record);
 
-    WechatBind selectOneByOpenid(@Param("openid")String openid);
-
-
+    WechatBind selectOneByOpenid(@Param("openid") String openid);
 }

+ 7 - 2
mirage-service/src/main/java/com/mirage/mirageservice/service/UserService.java

@@ -57,7 +57,7 @@ public class UserService {
 
     public PageResultVo<StudentDataReportResponse> reportList(String openId, Integer pageIndex, Integer pageSize){
         WechatBind wechatBind = wechatBindMapper.selectOneByOpenid(openId);
-        if(null == wechatBind){
+        if(null == wechatBind || wechatBind.getIsdeleted() == 1){
             return new PageResultVo<>();
         }
         Student student = studentMapper.selectByPrimaryKey(wechatBind.getStudentid());
@@ -82,7 +82,8 @@ public class UserService {
         if(null == wechatBind){
             return true;
         }
-        wechatBindMapper.deleteByPrimaryKey(wechatBind.getId());
+        wechatBind.setIsdeleted(1);
+        wechatBindMapper.updateByPrimaryKeySelective(wechatBind);
         return true;
     }
 
@@ -103,7 +104,11 @@ public class UserService {
             wechatBind.setPhone(bindRequest.getPhone());
             wechatBind.setCreatetime(new Date());
             wechatBind.setOpenid(bindRequest.getOpenId());
+            wechatBind.setIsdeleted(0);
             wechatBindMapper.insertSelective(wechatBind);
+        }else if(wechatBind.getIsdeleted() == 1){ // 解绑后重新绑定
+            wechatBind.setIsdeleted(0);
+            wechatBindMapper.updateByPrimaryKeySelective(wechatBind);
         }
         BindRequest bindResponse = BeanConvertUtil.safeConvert(bindRequest, BindRequest.class, BindRequest.class);
         if(null == bindResponse){

+ 18 - 5
mirage-service/src/main/resources/com/mirage/mirageservice/mapper/mysql/WechatBindMapper.xml

@@ -10,10 +10,11 @@
     <result column="Phone" jdbcType="CHAR" property="phone" />
     <result column="OpenId" jdbcType="VARCHAR" property="openid" />
     <result column="CreateTime" jdbcType="TIMESTAMP" property="createtime" />
+    <result column="IsDeleted" jdbcType="INTEGER" property="isdeleted" />
   </resultMap>
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
-    Id, StudentId, StudentName, Phone, OpenId, CreateTime
+    Id, StudentId, StudentName, Phone, OpenId, CreateTime, IsDeleted
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
     <!--@mbg.generated-->
@@ -30,9 +31,11 @@
   <insert id="insert" keyColumn="Id" keyProperty="id" parameterType="com.mirage.mirageservice.domain.WechatBind" useGeneratedKeys="true">
     <!--@mbg.generated-->
     insert into wechat_bind (StudentId, StudentName, Phone, 
-      OpenId, CreateTime)
+      OpenId, CreateTime, IsDeleted
+      )
     values (#{studentid,jdbcType=INTEGER}, #{studentname,jdbcType=VARCHAR}, #{phone,jdbcType=CHAR}, 
-      #{openid,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP})
+      #{openid,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, #{isdeleted,jdbcType=INTEGER}
+      )
   </insert>
   <insert id="insertSelective" keyColumn="Id" keyProperty="id" parameterType="com.mirage.mirageservice.domain.WechatBind" useGeneratedKeys="true">
     <!--@mbg.generated-->
@@ -53,6 +56,9 @@
       <if test="createtime != null">
         CreateTime,
       </if>
+      <if test="isdeleted != null">
+        IsDeleted,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="studentid != null">
@@ -70,6 +76,9 @@
       <if test="createtime != null">
         #{createtime,jdbcType=TIMESTAMP},
       </if>
+      <if test="isdeleted != null">
+        #{isdeleted,jdbcType=INTEGER},
+      </if>
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.mirage.mirageservice.domain.WechatBind">
@@ -91,6 +100,9 @@
       <if test="createtime != null">
         CreateTime = #{createtime,jdbcType=TIMESTAMP},
       </if>
+      <if test="isdeleted != null">
+        IsDeleted = #{isdeleted,jdbcType=INTEGER},
+      </if>
     </set>
     where Id = #{id,jdbcType=INTEGER}
   </update>
@@ -101,14 +113,15 @@
       StudentName = #{studentname,jdbcType=VARCHAR},
       Phone = #{phone,jdbcType=CHAR},
       OpenId = #{openid,jdbcType=VARCHAR},
-      CreateTime = #{createtime,jdbcType=TIMESTAMP}
+      CreateTime = #{createtime,jdbcType=TIMESTAMP},
+      IsDeleted = #{isdeleted,jdbcType=INTEGER}
     where Id = #{id,jdbcType=INTEGER}
   </update>
 
 <!--auto generated by MybatisCodeHelper on 2025-08-26-->
   <select id="selectOneByOpenid" resultMap="BaseResultMap">
         select
-        <include refid="Base_Column_List"/>
+        <include refid="Base_Column_List" />
         from wechat_bind
         where OpenId=#{openid,jdbcType=VARCHAR}
     </select>