Files
molly-multi-tenant/server/molly-pms/src/main/resources/mapper/PmsDeptMapper.xml
Wang Chen Chen eff969b2fb 1.完成数据权限功能。
2.角色,用户,部门,项目全部支持数据权限
2024-10-29 11:14:44 +08:00

138 lines
4.7 KiB
XML

<?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="com.xaaef.molly.perms.mapper.PmsDeptMapper">
<resultMap id="BaseResultMap" type="PmsDept">
<id property="deptId" column="dept_id"/>
<result property="parentId" column="parent_id"/>
<result property="deptName" column="dept_name"/>
<result property="leader" column="leader"/>
<result property="leaderMobile" column="leader_mobile"/>
<result property="sort" column="sort"/>
<result property="description" column="description"/>
<result property="ancestors" column="ancestors"/>
<result property="createTime" column="create_time"/>
<result property="createUser" column="create_user"/>
<result property="lastUpdateTime" column="last_update_time"/>
<result property="lastUpdateUser" column="last_update_user"/>
</resultMap>
<sql id="Base_Column_List">
dept_id
,parent_id,
dept_name,leader,leader_mobile,
sort,`description`,ancestors,create_time,
create_user,last_update_time,last_update_user
</sql>
<update id="updateChilds" parameterType="java.util.List">
update pms_dept set ancestors =
<foreach collection="childs" item="item" index="index"
separator=" " open="case dept_id" close="end">
when #{item.deptId} then #{item.ancestors}
</foreach>
where dept_id in
<foreach collection="childs" item="item" index="index"
separator="," open="(" close=")">
#{item.deptId}
</foreach>
</update>
<insert id="insertByMenus">
insert into pms_dept_menu (dept_id, menu_id) values
<foreach collection='menus' item='item' index='index' separator=','>
(#{id},#{item})
</foreach>
</insert>
<select id="selectChildDeptByUserId" resultMap="BaseResultMap">
SELECT *
FROM pms_dept
WHERE dept_id = (SELECT u1.dept_id FROM pms_user AS u1 WHERE u1.user_id = #{userId})
UNION
SELECT *
FROM pms_dept
WHERE find_in_set((SELECT u1.dept_id FROM pms_user AS u1 WHERE u1.user_id = #{userId}), ancestors)
</select>
<select id="selectChildDeptIdByUserId" resultType="java.lang.Long">
SELECT dept_id
FROM pms_dept
WHERE dept_id = (SELECT u1.dept_id FROM pms_user AS u1 WHERE u1.user_id = #{userId})
UNION
SELECT dept_id
FROM pms_dept
WHERE find_in_set((SELECT u1.dept_id FROM pms_user AS u1 WHERE u1.user_id = #{userId}), ancestors)
</select>
<select id="selectDeptByUserId" resultMap="BaseResultMap">
SELECT *
FROM pms_dept
WHERE dept_id = (SELECT u1.dept_id FROM pms_user AS u1 WHERE u1.user_id = #{userId})
</select>
<select id="selectDeptByRuleIds" resultMap="BaseResultMap">
SELECT * FROM pms_dept
WHERE dept_id IN (
SELECT dept_id FROM pms_role_dept WHERE role_id IN
<foreach item="item" index="index" collection="roleIds" open="(" separator="," close=")">
#{item}
</foreach>
)
</select>
<select id="selectDeptIdByRuleIds" resultType="java.lang.Long">
SELECT DISTINCT dept_id FROM pms_role_dept WHERE role_id IN
<foreach item="item" index="index" collection="roleIds" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<sql id="DataScopeWhere">
<where>
<if test="p.deptId != null and p.deptId != 0">
AND d.dept_id = #{p.deptId}
</if>
<if test="p.parentId != null and p.parentId != 0">
AND d.parent_id = #{p.parentId}
</if>
<if test="p.deptName != null and p.deptName != ''">
AND CONCAT(d.dept_name,d.leader,d.description) LIKE CONCAT('%',#{p.deptName},'%')
</if>
<!-- 数据范围过滤 -->
${p.params.dataScope}
</where>
</sql>
<select id="selectDeptPage" parameterType="PmsDept" resultMap="BaseResultMap">
select d.* from pms_dept as d
<include refid="DataScopeWhere"/>
order by d.parent_id, d.sort
</select>
<select id="selectDeptList" parameterType="PmsDept" resultMap="BaseResultMap">
select d.* from pms_dept as d
<include refid="DataScopeWhere"/>
order by d.parent_id, d.sort
</select>
<select id="selectDeptIdList" parameterType="PmsDept" resultType="java.lang.Long">
select d.dept_id from pms_dept as d
<include refid="DataScopeWhere"/>
</select>
</mapper>