202 lines
6.8 KiB
XML
202 lines
6.8 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.mhd.user.domain.roleAggregate.repository.mapper.RoleMapper">
|
|
|
|
<sql id="selectRoleVo">
|
|
SELECT a.role_id,
|
|
a.parent_role_id,
|
|
a.role_business_example_id,
|
|
a.role_business_example_name,
|
|
a.role_type,
|
|
a.role_code,
|
|
a.role_name,
|
|
a.role_remark,
|
|
a.role_data_scope,
|
|
a.role_status
|
|
FROM `role` a
|
|
WHERE a.del_flag = 1
|
|
</sql>
|
|
|
|
<select id="queryList" parameterType="com.mhd.user.domain.roleAggregate.repository.todo.RoleDo"
|
|
resultType="com.mhd.common.core.domain.po.RolePO">
|
|
SELECT
|
|
a.role_id,
|
|
a.parent_role_id,
|
|
a.organization_id,
|
|
a.role_code,
|
|
a.role_name,
|
|
a.role_remark,
|
|
a.role_data_scope,
|
|
a.role_status,
|
|
a.create_time,
|
|
a.create_by,
|
|
a.create_by_name,
|
|
a.update_by,
|
|
a.update_time,
|
|
a.update_by_name,
|
|
a.del_flag,
|
|
a.role_business_example_id,
|
|
a.role_business_example_name,
|
|
a.role_type,
|
|
a.role_type_name,
|
|
a.role_grade,
|
|
COUNT(DISTINCT u.user_id) roleUserCount
|
|
FROM
|
|
`role` a
|
|
LEFT JOIN user_role b on a.role_id = b.role_id
|
|
left join user u on b.user_id = u.user_id and u.del_flag = 1
|
|
WHERE
|
|
a.del_flag = 1
|
|
<include refid="common_where"></include>
|
|
GROUP BY a.role_id
|
|
</select>
|
|
<select id="selectByOrganizationIdAndRoleCode"
|
|
parameterType="com.mhd.user.domain.roleAggregate.repository.todo.RoleDo"
|
|
resultType="com.mhd.user.domain.roleAggregate.entity.RoleEntity">
|
|
SELECT
|
|
a.role_id,
|
|
a.parent_role_id,
|
|
a.role_business_example_id,
|
|
a.role_business_example_name,
|
|
a.role_type,
|
|
a.role_code,
|
|
a.role_name,
|
|
a.role_remark,
|
|
a.role_data_scope,
|
|
a.role_status
|
|
FROM
|
|
`role` a
|
|
WHERE
|
|
a.del_flag=1
|
|
<include refid="common_where"></include>
|
|
LIMIT 1
|
|
</select>
|
|
|
|
<select id="findDelByRoleId" parameterType="com.mhd.common.core.domain.po.RolePO"
|
|
resultType="com.mhd.common.core.domain.po.RolePO">
|
|
SELECT a.role_id,
|
|
a.parent_role_id,
|
|
a.role_business_example_id,
|
|
a.role_business_example_name,
|
|
a.role_type,
|
|
a.role_code,
|
|
a.role_name,
|
|
a.role_remark,
|
|
a.role_data_scope,
|
|
a.role_status
|
|
FROM `role` a
|
|
WHERE a.role_id = #{value}
|
|
</select>
|
|
<select id="selectByRoleId" parameterType="com.mhd.common.core.domain.po.RolePO"
|
|
resultType="com.mhd.common.core.domain.po.RolePO">
|
|
<include refid="selectRoleVo"/>
|
|
and a.role_id = #{value}
|
|
</select>
|
|
|
|
<select id="selectByRoleCodeAndOrganizationId" parameterType="com.mhd.user.domain.roleAggregate.repository.todo.RoleDo"
|
|
resultType="com.mhd.common.core.domain.po.RolePO">
|
|
<include refid="selectRoleVo"/>
|
|
and a.role_code = #{roleCode}
|
|
and a.organization_id = #{organizationId}
|
|
</select>
|
|
|
|
<select id="selectRoleByOrganizationAndCode"
|
|
parameterType="com.mhd.user.domain.roleAggregate.repository.todo.RoleDo"
|
|
resultType="com.mhd.common.core.domain.po.RolePO">
|
|
<include refid="selectRoleVo"/>
|
|
<include refid="common_where"></include>
|
|
LIMIT 1
|
|
</select>
|
|
|
|
<sql id="common_where">
|
|
<if test="roleId !=null and roleId !='' ">
|
|
and a.role_id = #{roleId}
|
|
</if>
|
|
<if test="roleGrade !=null and roleGrade !='' ">
|
|
and a.role_grade = #{roleGrade}
|
|
</if>
|
|
<if test="organizationId !=null">
|
|
and a.organization_id = #{organizationId}
|
|
</if>
|
|
<if test="organizationIds !=null">
|
|
and a.organization_id in
|
|
<foreach item="organizationId" collection="organizationIds" open="(" separator="," close=")">
|
|
#{organizationId}
|
|
</foreach>
|
|
</if>
|
|
<if test="roleCodeList !=null">
|
|
and a.role_code in
|
|
<foreach item="roleCode" collection="roleCodeList" open="(" separator="," close=")">
|
|
#{roleCode}
|
|
</foreach>
|
|
</if>
|
|
|
|
<if test="roleCode !=null and roleCode !='' ">
|
|
and a.role_code = #{roleCode}
|
|
</if>
|
|
<if test="roleTypeName !=null and roleTypeName !='' ">
|
|
and a.role_name like concat('%' , #{roleTypeName} , '%')
|
|
</if>
|
|
<if test="roleBusinessExampleName !=null and roleBusinessExampleName !='' ">
|
|
and a.role_business_example_name like concat('%' , #{roleBusinessExampleName} , '%')
|
|
</if>
|
|
/*职务/角色状态:0-无状态,1-开启,2-关闭*/
|
|
<if test="roleStatus !=null and roleStatus !='' ">
|
|
and a.role_status = #{roleStatus}
|
|
</if>
|
|
/*角色分类:0-无状态,1-托运人,2-承运人,3-公共*/
|
|
<if test="roleType !=null and roleType !='' ">
|
|
and a.role_type = #{roleType}
|
|
</if>
|
|
/*角色分类:0-无状态,1-托运人,2-承运人,3-公共*/
|
|
<if test="createBy !=null">
|
|
and a.create_by = #{createBy}
|
|
</if>
|
|
</sql>
|
|
|
|
<!-- 根据组织ID物理删除角色 -->
|
|
<select id="deleteByOrganizationId" parameterType="java.lang.Long">
|
|
DELETE
|
|
FROM `role` a
|
|
WHERE a.del_flag = 1
|
|
and a.organization_id = #{value}
|
|
</select>
|
|
|
|
<!-- 根据IDs合集查询角色名称 -->
|
|
<select id="findRoleNameByRoleIds" parameterType="java.lang.Long" resultType="java.lang.String">
|
|
SELECT
|
|
GROUP_CONCAT( a.role_name SEPARATOR ';' ) AS roleName
|
|
FROM
|
|
`role` a
|
|
WHERE
|
|
a.del_flag = 1
|
|
AND a.role_id IN
|
|
<foreach collection="list" item="roleIds" index="index" open="(" separator=" , " close=")">
|
|
#{roleIds}
|
|
</foreach>
|
|
</select>
|
|
<select id="selectByRoleCode" resultType="com.mhd.common.core.domain.po.RolePO">
|
|
select * from role
|
|
where del_flag = 1
|
|
and role_code = #{roleCode}
|
|
and organization_id = #{organizationId}
|
|
<if test="roleId !=null and roleId !='' ">
|
|
and role_id != #{roleId}
|
|
</if>
|
|
LIMIT 1
|
|
</select>
|
|
|
|
<select id="getRoleListByUserId" resultType="com.mhd.common.core.domain.po.RolePO">
|
|
select distinct r.*
|
|
from role r
|
|
left join user_role ur on ur.role_id = r.role_id and ur.del_flag = 1
|
|
<where>
|
|
r.role_status = 1
|
|
and r.del_flag = 1
|
|
and ur.user_id = #{userId}
|
|
</where>
|
|
</select>
|
|
</mapper>
|