dept/role/user的where中补充del_flag='0'条件,防止查询或更新时数据问题。

This commit is contained in:
likun5 2022-05-02 12:02:07 +08:00
parent 7414bc492e
commit 32199c42f2
3 changed files with 26 additions and 20 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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>