mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-11-15 10:59:22 +08:00
refactor: 物理删除 => 逻辑删除(适配已有唯一索引)
1.涉及逻辑删除调整表: main_table.sql:菜单表、部门表、角色表、用户表、用户社会化关联表、字典表、字典项表、消息表、公告表、存储表、文件表、客户端表、短信配置表 插件:应用表、租户表、租户套餐表 2.deleted 是否已删除(0:否;id:是)
This commit is contained in:
@@ -38,6 +38,6 @@ public interface FileMapper extends BaseMapper<FileDO> {
|
||||
*
|
||||
* @return 文件资源统计信息
|
||||
*/
|
||||
@Select("SELECT type, COUNT(1) number, SUM(size) size FROM sys_file WHERE type != 0 GROUP BY type")
|
||||
@Select("SELECT type, COUNT(1) number, SUM(size) size FROM sys_file WHERE deleted = 0 AND type != 0 GROUP BY type")
|
||||
List<FileStatisticsResp> statistics();
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public interface UserMapper extends DataPermissionMapper<UserDO> {
|
||||
* @param username 用户名
|
||||
* @return 用户信息
|
||||
*/
|
||||
@Select("SELECT * FROM sys_user WHERE username = #{username}")
|
||||
@Select("SELECT * FROM sys_user WHERE username = #{username} AND deleted = 0")
|
||||
UserDO selectByUsername(@Param("username") String username);
|
||||
|
||||
/**
|
||||
@@ -74,7 +74,7 @@ public interface UserMapper extends DataPermissionMapper<UserDO> {
|
||||
* @param phone 手机号
|
||||
* @return 用户信息
|
||||
*/
|
||||
@Select("SELECT * FROM sys_user WHERE phone = #{phone}")
|
||||
@Select("SELECT * FROM sys_user WHERE phone = #{phone} AND deleted = 0")
|
||||
UserDO selectByPhone(@FieldEncrypt @Param("phone") String phone);
|
||||
|
||||
/**
|
||||
@@ -83,7 +83,7 @@ public interface UserMapper extends DataPermissionMapper<UserDO> {
|
||||
* @param email 邮箱
|
||||
* @return 用户信息
|
||||
*/
|
||||
@Select("SELECT * FROM sys_user WHERE email = #{email}")
|
||||
@Select("SELECT * FROM sys_user WHERE email = #{email} AND deleted = 0")
|
||||
UserDO selectByEmail(@FieldEncrypt @Param("email") String email);
|
||||
|
||||
/**
|
||||
@@ -92,6 +92,6 @@ public interface UserMapper extends DataPermissionMapper<UserDO> {
|
||||
* @param id ID
|
||||
* @return 昵称
|
||||
*/
|
||||
@Select("SELECT nickname FROM sys_user WHERE id = #{id}")
|
||||
@Select("SELECT nickname FROM sys_user WHERE id = #{id} AND deleted = 0")
|
||||
String selectNicknameById(@Param("id") Long id);
|
||||
}
|
||||
|
||||
@@ -85,4 +85,15 @@ public class MessageDO implements Serializable {
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除(0:否;id:是)
|
||||
*/
|
||||
private Long deleted;
|
||||
}
|
||||
@@ -75,4 +75,15 @@ public class UserSocialDO implements Serializable {
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除(0:否;id:是)
|
||||
*/
|
||||
private Long deleted;
|
||||
}
|
||||
|
||||
@@ -510,7 +510,8 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
q.in("t1.dept_id", deptIdList);
|
||||
})
|
||||
.in(CollUtil.isNotEmpty(userIdList), "t1.id", userIdList)
|
||||
.notIn(CollUtil.isNotEmpty(excludeUserIdList), "t1.id", excludeUserIdList);
|
||||
.notIn(CollUtil.isNotEmpty(excludeUserIdList), "t1.id", excludeUserIdList)
|
||||
.eq("t1.deleted", 0L);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
SELECT t1.label, t1.value, t1.color AS extra
|
||||
FROM sys_dict_item AS t1
|
||||
LEFT JOIN sys_dict AS t2 ON t1.dict_id = t2.id
|
||||
WHERE t1.status = 1 AND t2.code = #{dictCode}
|
||||
WHERE t1.deleted = 0
|
||||
AND t1.status = 1
|
||||
AND t2.code = #{dictCode}
|
||||
ORDER BY t1.sort
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -8,7 +8,8 @@
|
||||
LEFT JOIN sys_role AS t3 ON t3.id = t2.role_id
|
||||
LEFT JOIN sys_user_role AS t4 ON t4.role_id = t3.id
|
||||
LEFT JOIN sys_user AS t5 ON t5.id = t4.user_id
|
||||
WHERE t5.id = #{userId}
|
||||
WHERE t1.deleted = 0
|
||||
AND t5.id = #{userId}
|
||||
AND t1.status = 1
|
||||
AND t1.permission IS NOT NULL
|
||||
</select>
|
||||
@@ -18,6 +19,8 @@
|
||||
FROM sys_menu AS t1
|
||||
LEFT JOIN sys_role_menu AS t2 ON t2.menu_id = t1.id
|
||||
LEFT JOIN sys_role AS t3 ON t3.id = t2.role_id
|
||||
WHERE t3.id = #{roleId} AND t1.status = 1
|
||||
WHERE t1.deleted = 0
|
||||
AND t3.id = #{roleId}
|
||||
AND t1.status = 1
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,7 +1,6 @@
|
||||
<?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" >
|
||||
<mapper namespace="top.continew.admin.system.mapper.MessageMapper">
|
||||
|
||||
<resultMap id="messageDetailMap" type="top.continew.admin.system.model.resp.message.MessageDetailResp">
|
||||
<id column="id" property="id" />
|
||||
<result property="users" column="users" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
|
||||
@@ -19,27 +18,26 @@
|
||||
t2.read_time AS readTime
|
||||
FROM sys_message AS t1
|
||||
LEFT JOIN sys_message_log AS t2 ON t2.message_id = t1.id <if test="query.userId != null">AND t2.user_id = #{query.userId}</if>
|
||||
<where>
|
||||
<if test="query.userId != null">
|
||||
<choose>
|
||||
<when test="_databaseId == 'mysql'">
|
||||
(t1.scope = 1 OR (t1.scope = 2 AND JSON_CONTAINS(t1.users, CONCAT('"', #{query.userId}, '"'))))
|
||||
</when>
|
||||
<when test="_databaseId == 'pgsql'">
|
||||
(t1.scope = 1 OR (t1.scope = 2 AND t1.users::jsonb @> jsonb_build_array(#{query.userId}::text)))
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND t1.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
<if test="query.type != null and query.type != ''">
|
||||
AND t1.type = #{query.type}
|
||||
</if>
|
||||
<if test="query.isRead != null">
|
||||
AND t2.read_time IS <if test="query.isRead">NOT</if> NULL
|
||||
</if>
|
||||
</where>
|
||||
WHERE t1.deleted = 0
|
||||
<if test="query.userId != null">
|
||||
<choose>
|
||||
<when test="_databaseId == 'mysql'">
|
||||
AND (t1.scope = 1 OR (t1.scope = 2 AND JSON_CONTAINS(t1.users, CONCAT('"', #{query.userId}, '"'))))
|
||||
</when>
|
||||
<when test="_databaseId == 'pgsql'">
|
||||
AND (t1.scope = 1 OR (t1.scope = 2 AND t1.users::jsonb @> jsonb_build_array(#{query.userId}::text)))
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND t1.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
<if test="query.type != null and query.type != ''">
|
||||
AND t1.type = #{query.type}
|
||||
</if>
|
||||
<if test="query.isRead != null">
|
||||
AND t2.read_time IS <if test="query.isRead">NOT</if> NULL
|
||||
</if>
|
||||
ORDER BY t1.create_time DESC
|
||||
</select>
|
||||
|
||||
@@ -54,7 +52,8 @@
|
||||
t1.users,
|
||||
t1.create_time
|
||||
FROM sys_message AS t1
|
||||
WHERE t1.id = #{id}
|
||||
WHERE t1.deleted = 0
|
||||
AND t1.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectUnreadListByUserId" resultType="top.continew.admin.system.model.entity.MessageDO">
|
||||
@@ -62,13 +61,13 @@
|
||||
t1.*
|
||||
FROM sys_message AS t1
|
||||
LEFT JOIN sys_message_log AS t2 ON t2.message_id = t1.id AND t2.user_id = #{userId}
|
||||
WHERE
|
||||
WHERE t1.deleted = 0
|
||||
<choose>
|
||||
<when test="_databaseId == 'mysql'">
|
||||
(t1.scope = 1 OR (t1.scope = 2 AND JSON_CONTAINS(t1.users, CONCAT('"', #{userId}, '"'))))
|
||||
AND (t1.scope = 1 OR (t1.scope = 2 AND JSON_CONTAINS(t1.users, CONCAT('"', #{userId}, '"'))))
|
||||
</when>
|
||||
<when test="_databaseId == 'pgsql'">
|
||||
(t1.scope = 1 OR (t1.scope = 2 AND t1.users::jsonb @> jsonb_build_array(#{userId}::text) ))
|
||||
AND (t1.scope = 1 OR (t1.scope = 2 AND t1.users::jsonb @> jsonb_build_array(#{userId}::text) ))
|
||||
</when>
|
||||
</choose>
|
||||
AND t2.read_time IS NULL
|
||||
@@ -79,13 +78,13 @@
|
||||
COUNT(1)
|
||||
FROM sys_message AS t1
|
||||
LEFT JOIN sys_message_log AS t2 ON t2.message_id = t1.id AND t2.user_id = #{userId}
|
||||
WHERE
|
||||
WHERE t1.deleted = 0
|
||||
<choose>
|
||||
<when test="_databaseId == 'mysql'">
|
||||
(t1.scope = 1 OR (t1.scope = 2 AND JSON_CONTAINS(t1.users, CONCAT('"', #{userId}, '"'))))
|
||||
AND (t1.scope = 1 OR (t1.scope = 2 AND JSON_CONTAINS(t1.users, CONCAT('"', #{userId}, '"'))))
|
||||
</when>
|
||||
<when test="_databaseId == 'pgsql'">
|
||||
(t1.scope = 1 OR (t1.scope = 2 AND t1.users::jsonb @> jsonb_build_array(#{userId}::text) ))
|
||||
AND (t1.scope = 1 OR (t1.scope = 2 AND t1.users::jsonb @> jsonb_build_array(#{userId}::text) ))
|
||||
</when>
|
||||
</choose>
|
||||
AND t2.read_time IS NULL
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?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" >
|
||||
<mapper namespace="top.continew.admin.system.mapper.NoticeMapper">
|
||||
|
||||
<resultMap id="notice" type="top.continew.admin.system.model.resp.notice.NoticeResp">
|
||||
<id property="id" column="id" />
|
||||
<result property="noticeMethods" column="notice_methods" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
|
||||
@@ -26,24 +25,23 @@
|
||||
<if test="query.userId != null">
|
||||
LEFT JOIN sys_notice_log AS t2 ON t2.notice_id = t1.id AND t2.user_id = #{query.userId}
|
||||
</if>
|
||||
<where>
|
||||
<if test="query.userId != null">
|
||||
<choose>
|
||||
<when test="_databaseId == 'mysql'">
|
||||
(t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_CONTAINS(t1.notice_users, CONCAT('"', #{query.userId}, '"'))))
|
||||
</when>
|
||||
<when test="_databaseId == 'pgsql'">
|
||||
(t1.notice_scope = 1 OR (t1.notice_scope = 2 AND t1.notice_users::jsonb @> jsonb_build_array(#{query.userId}::text)))
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND t1.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
<if test="query.type != null and query.type != ''">
|
||||
AND t1.type = #{query.type}
|
||||
</if>
|
||||
</where>
|
||||
WHERE t1.deleted = 0
|
||||
<if test="query.userId != null">
|
||||
<choose>
|
||||
<when test="_databaseId == 'mysql'">
|
||||
AND (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_CONTAINS(t1.notice_users, CONCAT('"', #{query.userId}, '"'))))
|
||||
</when>
|
||||
<when test="_databaseId == 'pgsql'">
|
||||
AND (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND t1.notice_users::jsonb @> jsonb_build_array(#{query.userId}::text)))
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND t1.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
<if test="query.type != null and query.type != ''">
|
||||
AND t1.type = #{query.type}
|
||||
</if>
|
||||
<if test="query.userId != null">
|
||||
ORDER BY t1.is_top DESC, t1.publish_time DESC
|
||||
</if>
|
||||
@@ -57,13 +55,13 @@
|
||||
t1.id
|
||||
FROM sys_notice AS t1
|
||||
LEFT JOIN sys_notice_log AS t2 ON t2.notice_id = t1.id AND t2.user_id = #{userId}
|
||||
WHERE
|
||||
WHERE t1.deleted = 0
|
||||
<choose>
|
||||
<when test="_databaseId == 'mysql'">
|
||||
(t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_CONTAINS(t1.notice_users, CONCAT('"', #{userId}, '"'))))
|
||||
AND (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_CONTAINS(t1.notice_users, CONCAT('"', #{userId}, '"'))))
|
||||
</when>
|
||||
<when test="_databaseId == 'pgsql'">
|
||||
(t1.notice_scope = 1 OR (t1.notice_scope = 2 AND t1.notice_users::jsonb @> jsonb_build_array(#{userId}::text)))
|
||||
AND (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND t1.notice_users::jsonb @> jsonb_build_array(#{userId}::text)))
|
||||
</when>
|
||||
</choose>
|
||||
<if test="noticeMethod != null">
|
||||
@@ -82,20 +80,20 @@
|
||||
<select id="selectDashboardList"
|
||||
resultType="top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp">
|
||||
SELECT
|
||||
id, title, type, is_top
|
||||
FROM sys_notice
|
||||
WHERE status = 3
|
||||
t1.id, t1.title, t1.type, t1.is_top
|
||||
FROM sys_notice AS t1
|
||||
WHERE t1.deleted = 0 AND t1.status = 3
|
||||
<if test="userId != null">
|
||||
<choose>
|
||||
<when test="_databaseId == 'mysql'">
|
||||
AND (notice_scope = 1 OR (notice_scope = 2 AND JSON_CONTAINS(notice_users, CONCAT('"', #{userId}, '"'))))
|
||||
AND (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_CONTAINS(t1.notice_users, CONCAT('"', #{userId}, '"'))))
|
||||
</when>
|
||||
<when test="_databaseId == 'pgsql'">
|
||||
AND (notice_scope = 1 OR (notice_scope = 2 AND notice_users::jsonb @> jsonb_build_array(#{userId}::text)))
|
||||
AND (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND t1.notice_users::jsonb @> jsonb_build_array(#{userId}::text)))
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
ORDER BY is_top DESC, publish_time DESC
|
||||
ORDER BY t1.is_top DESC, t1.publish_time DESC
|
||||
LIMIT 5
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,7 +1,6 @@
|
||||
<?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" >
|
||||
<mapper namespace="top.continew.admin.system.mapper.UserRoleMapper">
|
||||
|
||||
<select id="selectUserPage" resultType="top.continew.admin.system.model.resp.role.RoleUserResp">
|
||||
SELECT
|
||||
t1.*,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?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" >
|
||||
<mapper namespace="top.continew.admin.system.mapper.user.UserMapper">
|
||||
|
||||
<sql id="selectUser">
|
||||
SELECT
|
||||
t1.id,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<mapper namespace="top.continew.admin.system.mapper.user.UserPasswordHistoryMapper">
|
||||
<delete id="deleteExpired" databaseId="mysql">
|
||||
DELETE t1 FROM sys_user_password_history AS t1
|
||||
LEFT JOIN (
|
||||
LEFT JOIN (
|
||||
SELECT id
|
||||
FROM sys_user_password_history
|
||||
WHERE user_id = #{userId}
|
||||
@@ -12,6 +12,7 @@
|
||||
) AS t2 ON t2.id = t1.id
|
||||
WHERE t2.id IS NULL
|
||||
</delete>
|
||||
|
||||
<delete id="deleteExpired" databaseId="pgsql">
|
||||
DELETE FROM sys_user_password_history AS t1
|
||||
WHERE user_id = #{userId}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
SELECT t1.*
|
||||
FROM sys_user_social AS t1
|
||||
LEFT JOIN sys_user AS t2 ON t2.id = t1.user_id
|
||||
WHERE t1.source = #{source} AND t1.open_id = #{openId}
|
||||
WHERE t1.deleted = 0
|
||||
AND t1.source = #{source}
|
||||
AND t1.open_id = #{openId}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user