refactor:用户表改为逻辑删

This commit is contained in:
sugus 2025-07-09 11:42:11 +08:00
parent 1d52e4da84
commit 5ac6e0523b
6 changed files with 22 additions and 9 deletions

View File

@ -42,7 +42,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler {
this.strictInsertFill(metaObject, "createBy", String.class, username); this.strictInsertFill(metaObject, "createBy", String.class, username);
this.strictInsertFill(metaObject, "updateBy", String.class, username); this.strictInsertFill(metaObject, "updateBy", String.class, username);
// 插入时候默认赋值为正常 // 插入时候默认赋值为正常
this.strictInsertFill(metaObject, "delFlag", String.class, DelFlagStatus.NORMAL.getValue()); this.strictInsertFill(metaObject, "delFlag", Integer.class, DelFlagStatus.NORMAL.getValue());
} }
@Override @Override

View File

@ -9,19 +9,19 @@ public enum DelFlagStatus {
/** /**
* 正常 * 正常
*/ */
NORMAL("0"), NORMAL(0),
/** /**
* 删除 * 删除
*/ */
DELETED("1"); DELETED(1);
private final String value; private final Integer value;
DelFlagStatus(String value) { DelFlagStatus(Integer value) {
this.value = value; this.value = value;
} }
public String getValue() { public Integer getValue() {
return value; return value;
} }
} }

View File

@ -15,6 +15,7 @@
*/ */
package com.aircraft.modules.system.domain; package com.aircraft.modules.system.domain;
import com.aircraft.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
@ -38,7 +39,7 @@ import java.util.Set;
@Getter @Getter
@Setter @Setter
@TableName("sys_user") @TableName("sys_user")
public class User extends SysBaseEntity implements Serializable { public class User extends BaseEntity implements Serializable {
@NotNull(groups = Update.class) @NotNull(groups = Update.class)
@TableId(value="user_id", type = IdType.AUTO) @TableId(value="user_id", type = IdType.AUTO)

View File

@ -16,7 +16,8 @@
</delete> </delete>
<delete id="deleteByUserIds"> <delete id="deleteByUserIds">
delete from sys_users_jobs UPDATE sys_users_jobs
SET del_flag = 1
where user_id in where user_id in
<foreach collection="userIds" item="id" open="(" separator="," close=")"> <foreach collection="userIds" item="id" open="(" separator="," close=")">
#{id} #{id}

View File

@ -54,6 +54,7 @@
<sql id="Whrer_Sql"> <sql id="Whrer_Sql">
<where> <where>
u.del_flag = 0
<if test="criteria.id != null"> <if test="criteria.id != null">
and u.user_id = #{criteria.id} and u.user_id = #{criteria.id}
</if> </if>
@ -114,33 +115,39 @@
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
where u.username = #{username} where u.username = #{username}
and u.del_flag = 0
</select> </select>
<select id="findByEmail" resultType="com.aircraft.modules.system.domain.User"> <select id="findByEmail" resultType="com.aircraft.modules.system.domain.User">
select user_id as id, username from sys_user select user_id as id, username from sys_user
where email = #{email} where email = #{email}
and del_flag = 0
</select> </select>
<select id="findByPhone" resultType="com.aircraft.modules.system.domain.User"> <select id="findByPhone" resultType="com.aircraft.modules.system.domain.User">
select user_id as id, username from sys_user select user_id as id, username from sys_user
where phone = #{phone} where phone = #{phone}
and del_flag = 0
</select> </select>
<select id="findByRoleId" resultType="com.aircraft.modules.system.domain.User"> <select id="findByRoleId" resultType="com.aircraft.modules.system.domain.User">
SELECT u.user_id as id, u.username FROM sys_user u, sys_users_roles r SELECT u.user_id as id, u.username FROM sys_user u, sys_users_roles r
WHERE u.user_id = r.user_id AND r.role_id = #{roleId} WHERE u.user_id = r.user_id AND r.role_id = #{roleId}
and u.del_flag = 0
group by u.user_id group by u.user_id
</select> </select>
<select id="findByRoleDeptId" resultType="com.aircraft.modules.system.domain.User"> <select id="findByRoleDeptId" resultType="com.aircraft.modules.system.domain.User">
SELECT u.* FROM sys_user u, sys_users_roles r, sys_roles_depts d SELECT u.* FROM sys_user u, sys_users_roles r, sys_roles_depts d
WHERE u.user_id = r.user_id AND r.role_id = d.role_id AND d.dept_id = #{deptId} WHERE u.user_id = r.user_id AND r.role_id = d.role_id AND d.dept_id = #{deptId}
and u.del_flag = 0
group by u.user_id group by u.user_id
</select> </select>
<select id="findByMenuId" resultType="com.aircraft.modules.system.domain.User"> <select id="findByMenuId" resultType="com.aircraft.modules.system.domain.User">
SELECT u.user_id as id, u.username FROM sys_user u, sys_users_roles ur, sys_roles_menus rm SELECT u.user_id as id, u.username FROM sys_user u, sys_users_roles ur, sys_roles_menus rm
WHERE u.user_id = ur.user_id AND ur.role_id = rm.role_id AND rm.menu_id = #{menuId} WHERE u.user_id = ur.user_id AND ur.role_id = rm.role_id AND rm.menu_id = #{menuId}
and u.del_flag = 0
group by u.user_id group by u.user_id
</select> </select>
@ -150,6 +157,7 @@
<foreach collection="jobIds" item="jobId" open="(" separator="," close=")"> <foreach collection="jobIds" item="jobId" open="(" separator="," close=")">
#{jobId} #{jobId}
</foreach> </foreach>
and u.del_flag = 0
</select> </select>
<select id="countByDepts" resultType="int"> <select id="countByDepts" resultType="int">
@ -158,6 +166,7 @@
<foreach collection="deptIds" item="deptId" open="(" separator="," close=")"> <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
#{deptId} #{deptId}
</foreach> </foreach>
and u.del_flag = 0
</select> </select>
<select id="countByRoles" resultType="int"> <select id="countByRoles" resultType="int">
@ -166,6 +175,7 @@
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")"> <foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
#{roleId} #{roleId}
</foreach> </foreach>
and u.del_flag = 0
</select> </select>
<update id="resetPwd"> <update id="resetPwd">

View File

@ -16,7 +16,8 @@
</delete> </delete>
<delete id="deleteByUserIds"> <delete id="deleteByUserIds">
delete from sys_users_roles UPDATE sys_users_roles
SET del_flag = 0
where user_id in where user_id in
<foreach collection="userIds" item="id" open="(" separator="," close=")"> <foreach collection="userIds" item="id" open="(" separator="," close=")">
#{id} #{id}