|
|
|
<?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.epmet.dao.StaffRoleDao">
|
|
|
|
|
|
|
|
<resultMap type="com.epmet.entity.StaffRoleEntity" id="staffRoleMap">
|
|
|
|
<result property="id" column="ID"/>
|
|
|
|
<result property="staffId" column="STAFF_ID"/>
|
|
|
|
<result property="roleId" column="ROLE_ID"/>
|
|
|
|
<result property="orgId" column="ORG_ID"/>
|
|
|
|
<result property="delFlag" column="DEL_FLAG"/>
|
|
|
|
<result property="revision" column="REVISION"/>
|
|
|
|
<result property="createdBy" column="CREATED_BY"/>
|
|
|
|
<result property="createdTime" column="CREATED_TIME"/>
|
|
|
|
<result property="updatedBy" column="UPDATED_BY"/>
|
|
|
|
<result property="updatedTime" column="UPDATED_TIME"/>
|
|
|
|
</resultMap>
|
|
|
|
<update id="delStaffRoles" parameterType="com.epmet.dto.StaffRoleDTO">
|
|
|
|
update
|
|
|
|
staff_role sr inner join gov_staff_role gsr on (sr.ROLE_ID = gsr.ID and gsr.ROLE_KEY != 'root_manager')
|
|
|
|
set sr.DEL_FLAG = '1'
|
|
|
|
where sr.STAFF_ID = #{staffId}
|
|
|
|
and sr.ORG_ID = #{orgId}
|
|
|
|
and sr.DEL_FLAG = '0'
|
|
|
|
</update>
|
|
|
|
<update id="updateStaffRoleOrgId" parameterType="com.epmet.dto.StaffRoleDTO">
|
|
|
|
UPDATE staff_role SET ORG_ID = #{orgId}
|
|
|
|
WHERE STAFF_ID = #{staffId}
|
|
|
|
AND DEL_FLAG = '0'
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
|
|
<!--查询具有某角色的staff列表-->
|
|
|
|
<select id="listStaffIdsByRoleKeyAndOrgId" resultType="com.epmet.dto.result.GovStaffRoleResultDTO">
|
|
|
|
SELECT sr.STAFF_ID, sr.ROLE_ID, r.ROLE_NAME, r.ROLE_KEY, s.REAL_NAME, s.MOBILE, s.GENDER
|
|
|
|
FROM
|
|
|
|
staff_role sr
|
|
|
|
INNER JOIN gov_staff_role r ON ( sr.ROLE_ID = r.ID )
|
|
|
|
INNER JOIN customer_staff s ON (sr.STAFF_ID = s.USER_ID)
|
|
|
|
WHERE
|
|
|
|
r.ROLE_KEY = #{roleKey}
|
|
|
|
AND sr.ORG_ID = #{orgId}
|
|
|
|
AND sr.DEL_FLAG = '0'
|
|
|
|
AND r.DEL_FLAG = '0'
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- StaffRolesResultDTO的映射结果集 -->
|
|
|
|
<resultMap id="staffRolesResultMap" type="com.epmet.dto.result.StaffRolesResultDTO">
|
|
|
|
<id property="staffId" column="USER_ID"/>
|
|
|
|
<result property="enableFlag" column="ENABLE_FLAG"/>
|
|
|
|
<collection property="roleList" ofType="java.lang.String">
|
|
|
|
<constructor>
|
|
|
|
<arg column="ROLE_NAME"/>
|
|
|
|
</constructor>
|
|
|
|
</collection>
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 得到指定客户下的某个用户的全部角色 -->
|
|
|
|
<select id="getStaffRoles" parameterType="com.epmet.dto.form.CommonUserFormDTO" resultMap="staffRolesResultMap">
|
|
|
|
SELECT
|
|
|
|
staff.USER_ID,
|
|
|
|
staff.ENABLE_FLAG,
|
|
|
|
rolename.ROLE_NAME
|
|
|
|
FROM
|
|
|
|
STAFF_ROLE role
|
|
|
|
LEFT JOIN CUSTOMER_STAFF staff ON ( role.STAFF_ID = staff.USER_ID )
|
|
|
|
LEFT JOIN GOV_STAFF_ROLE rolename ON ( role.ROLE_ID = rolename.ID )
|
|
|
|
WHERE
|
|
|
|
role.DEL_FLAG = '0'
|
|
|
|
AND staff.DEL_FLAG = '0'
|
|
|
|
AND rolename.DEL_FLAG = '0'
|
|
|
|
AND staff.USER_ID = #{userId}
|
|
|
|
AND staff.CUSTOMER_ID = #{customerId}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<!-- 查询具有特定角色的工作人员Id -->
|
|
|
|
<select id="selectSpecificRolesStaffs" resultType="string">
|
|
|
|
SELECT
|
|
|
|
staffrole.STAFF_ID
|
|
|
|
FROM
|
|
|
|
`staff_role` staffrole
|
|
|
|
LEFT JOIN `customer_staff` staff ON staffrole.STAFF_ID = staff.USER_ID
|
|
|
|
LEFT JOIN `gov_staff_role` role ON staffrole.ROLE_ID = ROLE.ID
|
|
|
|
<where>
|
|
|
|
staffrole.DEL_FLAG = '0'
|
|
|
|
AND staff.DEL_FLAG = '0'
|
|
|
|
AND role.DEL_FLAG = '0'
|
|
|
|
AND staff.ENABLE_FLAG = 'enable'
|
|
|
|
AND staffrole.ROLE_ID IN (
|
|
|
|
SELECT
|
|
|
|
ID
|
|
|
|
FROM
|
|
|
|
GOV_STAFF_ROLE
|
|
|
|
WHERE
|
|
|
|
ROLE_KEY IN
|
|
|
|
<foreach item="roleKey" collection="roleKeys" open="(" separator="," close=")">
|
|
|
|
#{roleKey}
|
|
|
|
</foreach>
|
|
|
|
AND DEL_FLAG = '0' )
|
|
|
|
AND staffrole.STAFF_ID IN
|
|
|
|
<foreach item="userId" collection="userIds" open="(" separator="," close=")">
|
|
|
|
#{userId}
|
|
|
|
</foreach>
|
|
|
|
<if test='null != customerId and "" != customerId'>
|
|
|
|
AND staff.CUSTOMER_ID = #{customerId}
|
|
|
|
</if>
|
|
|
|
</where>
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectStaffRoleList" resultType="com.epmet.dto.result.CustomerStaffRoleResultDTO">
|
|
|
|
SELECT
|
|
|
|
sr.staff_id AS "staffId",
|
|
|
|
gsr.role_key AS "roleKey",
|
|
|
|
gsr.role_name AS "roleName"
|
|
|
|
FROM
|
|
|
|
staff_role sr
|
|
|
|
INNER JOIN gov_staff_role gsr ON sr.role_id = gsr.id
|
|
|
|
WHERE
|
|
|
|
sr.del_flag = '0'
|
|
|
|
AND gsr.del_flag = '0'
|
|
|
|
<foreach item="staffId" collection="staffIdList" separator="or" open="AND (" close=")" index="">
|
|
|
|
sr.staff_id = #{staffId}
|
|
|
|
</foreach>
|
|
|
|
</select>
|
|
|
|
<select id="selectCustomerStaffRoleList" resultType="com.epmet.dto.result.CustomerStaffRoleListResultDTO">
|
|
|
|
SELECT
|
|
|
|
staff.customer_id AS "customerId",
|
|
|
|
staff.user_id AS "staffId",
|
|
|
|
staff.real_name AS "staffName",
|
|
|
|
role.role_id AS "roleId",
|
|
|
|
rolename.role_key AS "roleKey",
|
|
|
|
rolename.role_name AS "roleName"
|
|
|
|
FROM
|
|
|
|
staff_role role
|
|
|
|
LEFT JOIN customer_staff staff ON ( role.staff_id = staff.user_id )
|
|
|
|
LEFT JOIN gov_staff_role rolename ON ( role.role_id = rolename.id )
|
|
|
|
WHERE
|
|
|
|
role.del_flag = '0'
|
|
|
|
AND staff.del_flag = '0'
|
|
|
|
AND rolename.del_flag = '0'
|
|
|
|
<if test='null != customerId and "" != customerId'>
|
|
|
|
AND staff.customer_id = #{customerId}
|
|
|
|
</if>
|
|
|
|
<if test='null != staffId and "" != staffId'>
|
|
|
|
AND staff.user_id = #{staffId}
|
|
|
|
</if>
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectStaffRoles" resultType="com.epmet.dto.result.CustomerStaffRoleResultDTO">
|
|
|
|
SELECT
|
|
|
|
sr.staff_id AS "staffId",
|
|
|
|
gsr.role_key AS "roleKey",
|
|
|
|
gsr.role_name AS "roleName"
|
|
|
|
FROM
|
|
|
|
staff_role sr
|
|
|
|
INNER JOIN gov_staff_role gsr ON sr.role_id = gsr.id
|
|
|
|
WHERE
|
|
|
|
sr.del_flag = '0'
|
|
|
|
AND gsr.del_flag = '0'
|
|
|
|
AND sr.staff_id = #{staffId}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="listStaffRoleEntytiesByStaffIdAndOrgId" resultType="com.epmet.entity.StaffRoleEntity">
|
|
|
|
select *
|
|
|
|
from staff_role sr
|
|
|
|
where sr.STAFF_ID = #{staffId}
|
|
|
|
and sr.ORG_ID = #{agencyId}
|
|
|
|
and sr.DEL_FLAG='0'
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectStaffRoleByStaffIdAndRoleId" resultType="com.epmet.dto.StaffRoleDTO">
|
|
|
|
select
|
|
|
|
ID id,
|
|
|
|
STAFF_ID staffId,
|
|
|
|
ROLE_ID roleId,
|
|
|
|
ORG_ID orgId
|
|
|
|
from staff_role sr
|
|
|
|
where sr.STAFF_ID = #{staffId}
|
|
|
|
and sr.ROLE_ID = #{roleId}
|
|
|
|
and sr.DEL_FLAG='0'
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectStaffRoleKeyList" resultType="java.lang.String">
|
|
|
|
SELECT
|
|
|
|
gsr.role_key
|
|
|
|
FROM
|
|
|
|
staff_role sr
|
|
|
|
INNER JOIN gov_staff_role gsr ON sr.role_id = gsr.id
|
|
|
|
WHERE
|
|
|
|
sr.del_flag = '0'
|
|
|
|
AND gsr.del_flag = '0'
|
|
|
|
AND sr.staff_id = #{userId}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<!-- 查询是网格员的人 -->
|
|
|
|
<select id="staffGridRole" resultType="com.epmet.dto.result.GridStaffResultDTO">
|
|
|
|
<foreach collection="forms" item="s" separator=" UNION ALL ">
|
|
|
|
SELECT
|
|
|
|
#{s.gridId} as gridId,
|
|
|
|
sr.STAFF_ID
|
|
|
|
FROM staff_role sr
|
|
|
|
LEFT JOIN gov_staff_role gsr ON gsr.ID = sr.ROLE_ID AND gsr.DEL_FLAG = 0
|
|
|
|
WHERE sr.DEL_FLAG = 0
|
|
|
|
AND gsr.ROLE_KEY = 'grid_member'
|
|
|
|
AND sr.STAFF_ID = #{s.staffId}
|
|
|
|
</foreach>
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<!-- 查询角色 -->
|
|
|
|
<select id="getRolesByDB" resultType="com.epmet.dto.result.RoleKeyValueResultDTO">
|
|
|
|
SELECT
|
|
|
|
sr.ORG_ID,
|
|
|
|
gsr.ROLE_KEY,
|
|
|
|
gsr.ROLE_NAME,
|
|
|
|
sr.STAFF_ID
|
|
|
|
FROM staff_role sr
|
|
|
|
LEFT JOIN gov_staff_role gsr ON gsr.ID = sr.ROLE_ID AND gsr.DEL_FLAG = 0
|
|
|
|
WHERE sr.DEL_FLAG = 0
|
|
|
|
AND sr.STAFF_ID = #{userId}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<!-- 查询所有用户角色 -->
|
|
|
|
<select id="selectAllUserRoles" resultType="com.epmet.dto.result.RepairStaffRoleCacheResultDTO">
|
|
|
|
SELECT
|
|
|
|
sr.ORG_ID,
|
|
|
|
sr.CUSTOMER_ID,
|
|
|
|
gsr.ROLE_KEY,
|
|
|
|
gsr.ROLE_NAME,
|
|
|
|
sr.STAFF_ID
|
|
|
|
FROM staff_role sr
|
|
|
|
LEFT JOIN gov_staff_role gsr ON gsr.ID = sr.ROLE_ID AND gsr.DEL_FLAG = 0
|
|
|
|
WHERE sr.DEL_FLAG = 0
|
|
|
|
</select>
|
|
|
|
</mapper>
|