From 32199c42f24a31126e63e198cb3b6f249cb58c5e Mon Sep 17 00:00:00 2001
From: likun5 <lk123@126.com>
Date: Mon, 2 May 2022 12:02:07 +0800
Subject: [PATCH] =?UTF-8?q?dept/role/user=E7=9A=84where=E4=B8=AD=E8=A1=A5?=
 =?UTF-8?q?=E5=85=85del=5Fflag=3D'0'=E6=9D=A1=E4=BB=B6=EF=BC=8C=E9=98=B2?=
 =?UTF-8?q?=E6=AD=A2=E6=9F=A5=E8=AF=A2=E6=88=96=E6=9B=B4=E6=96=B0=E6=97=B6?=
 =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=97=AE=E9=A2=98=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../resources/mapper/system/SysDeptMapper.xml    | 15 +++++++++------
 .../resources/mapper/system/SysRoleMapper.xml    | 15 ++++++++-------
 .../resources/mapper/system/SysUserMapper.xml    | 16 +++++++++-------
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
index 984f89ccc..42ff5bc14 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -52,6 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		from sys_dept d
             left join sys_role_dept rd on d.dept_id = rd.dept_id
         where rd.role_id = #{roleId}
+			and d.del_flag = '0'
             <if test="deptCheckStrictly">
               and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId})
             </if>
@@ -60,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     
     <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
 		<include refid="selectDeptVo"/>
-		where dept_id = #{deptId}
+		where d.dept_id = #{deptId} and d.del_flag = '0'
 	</select>
     
     <select id="checkDeptExistUser" parameterType="Long" resultType="int">
@@ -73,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 	
 	<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
-		select * from sys_dept where find_in_set(#{deptId}, ancestors)
+		select * from sys_dept where find_in_set(#{deptId}, ancestors)  and del_flag = '0'
 	</select>
 	
 	<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
@@ -82,10 +83,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	
 	<select id="checkDeptNameUnique" resultMap="SysDeptResult">
 	    <include refid="selectDeptVo"/>
-		where dept_name=#{deptName} and parent_id = #{parentId} limit 1
+		where d.dept_name=#{deptName} and d.parent_id = #{parentId}  and d.del_flag = '0' limit 1
 	</select>
     
-    <insert id="insertDept" parameterType="SysDept">
+    <insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">
  		insert into sys_dept(
  			<if test="deptId != null and deptId != 0">dept_id,</if>
  			<if test="parentId != null and parentId != 0">parent_id,</if>
@@ -127,7 +128,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  			update_time = sysdate()
  		</set>
- 		where dept_id = #{deptId}
+ 		where dept_id = #{deptId}  and del_flag = '0'
 	</update>
 	
 	<update id="updateDeptChildren" parameterType="java.util.List">
@@ -141,6 +142,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	        separator="," open="(" close=")">
 	        #{item.deptId}
 	    </foreach>
+		and del_flag = '0'
 	</update>
 	 
 	<update id="updateDeptStatusNormal" parameterType="Long">
@@ -148,10 +150,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  	    <foreach collection="array" item="deptId" open="(" separator="," close=")">
         	#{deptId}
         </foreach>
+		and del_flag = '0'
 	</update>
 	
 	<delete id="deleteDeptById" parameterType="Long">
-		update sys_dept set del_flag = '2' where dept_id = #{deptId}
+		update sys_dept set del_flag = '2' where dept_id = #{deptId}  and del_flag = '0'
 	</delete>
 
 </mapper> 
\ No newline at end of file
diff --git a/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml
index a8d3ede58..ab704aaad 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml
@@ -70,12 +70,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         from sys_role r
 	        left join sys_user_role ur on ur.role_id = r.role_id
 	        left join sys_user u on u.user_id = ur.user_id
-	    where u.user_id = #{userId}
+	    where u.user_id = #{userId} and r.del_flag = '0'
 	</select>
 	
 	<select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
-		where r.role_id = #{roleId}
+		where r.role_id = #{roleId} and r.del_flag = '0'
 	</select>
 	
 	<select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
@@ -85,12 +85,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	
 	<select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
-		 where r.role_name=#{roleName} limit 1
+		 where r.role_name=#{roleName}  and r.del_flag = '0' limit 1
 	</select>
 	
 	<select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
-		 where r.role_key=#{roleKey} limit 1
+		 where r.role_key=#{roleKey}  and r.del_flag = '0' limit 1
 	</select>
 	
  	<insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
@@ -135,18 +135,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  			update_time = sysdate()
  		</set>
- 		where role_id = #{roleId}
+ 		where role_id = #{roleId} and del_flag = '0'
 	</update>
 	
 	<delete id="deleteRoleById" parameterType="Long">
-		update sys_role set del_flag = '2' where role_id = #{roleId}
+		update sys_role set del_flag = '2' where role_id = #{roleId} and del_flag = '0'
  	</delete>
  	
  	<delete id="deleteRoleByIds" parameterType="Long">
  	    update sys_role set del_flag = '2' where role_id in
  		<foreach collection="array" item="roleId" open="(" separator="," close=")">
  			#{roleId}
-        </foreach> 
+        </foreach>
+		and del_flag = '0'
  	</delete>
  	
 </mapper> 
\ No newline at end of file
diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
index 16a64c2a3..a4972e031 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
@@ -122,24 +122,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	
 	<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
 	    <include refid="selectUserVo"/>
-		where u.user_name = #{userName}
+		where u.user_name = #{userName} and u.del_flag ='0'
 	</select>
 	
 	<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
 		<include refid="selectUserVo"/>
-		where u.user_id = #{userId}
+		where u.user_id = #{userId} and u.del_flag ='0'
 	</select>
 	
 	<select id="checkUserNameUnique" parameterType="String" resultType="int">
-		select count(1) from sys_user where user_name = #{userName} limit 1
+		select count(1) from sys_user where user_name = #{userName}  and del_flag ='0' limit 1
 	</select>
 	
 	<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
-		select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} limit 1
+		select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag ='0' limit 1
 	</select>
 	
 	<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
-		select user_id, email from sys_user where email = #{email} limit 1
+		select user_id, email from sys_user where email = #{email} and del_flag ='0' limit 1
 	</select>
 	
 	<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
@@ -193,6 +193,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			update_time = sysdate()
  		</set>
  		where user_id = #{userId}
+		and del_flag ='0'
 	</update>
 	
 	<update id="updateUserStatus" parameterType="SysUser">
@@ -208,14 +209,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</update>
 	
 	<delete id="deleteUserById" parameterType="Long">
-		update sys_user set del_flag = '2' where user_id = #{userId}
+		update sys_user set del_flag = '2' where user_id = #{userId} and del_flag ='0'
  	</delete>
  	
  	<delete id="deleteUserByIds" parameterType="Long">
  		update sys_user set del_flag = '2' where user_id in
  		<foreach collection="array" item="userId" open="(" separator="," close=")">
  			#{userId}
-        </foreach> 
+        </foreach>
+		and del_flag ='0'
  	</delete>
 	
 </mapper> 
\ No newline at end of file