|  |  | @ -51,6 +51,57 @@ | 
			
		
	
		
			
				
					|  |  |  |         AND real_name LIKE CONCAT('%', #{realName}, '%') | 
			
		
	
		
			
				
					|  |  |  |     </select> | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     <select id="selectOrderRole" resultType="java.lang.String"> | 
			
		
	
		
			
				
					|  |  |  |         <!-- 按人员Id列表查询,先查询每个人有的角色,然后把有单位领导角色的人排在前边,其他的在按创建时间降序 --> | 
			
		
	
		
			
				
					|  |  |  |         SELECT | 
			
		
	
		
			
				
					|  |  |  |             t.staff_id | 
			
		
	
		
			
				
					|  |  |  |         FROM ( | 
			
		
	
		
			
				
					|  |  |  |             <!-- 里边的sql,尽管有去重,一个人有多个角色时,在里边sql查询出来的是一个人两条数据,is_first一个是0一个是1,所以外层需要在按人分组 --> | 
			
		
	
		
			
				
					|  |  |  |             SELECT DISTINCT<!-- 没有这个去重会改变最终的结果顺序,至于为什么还不清楚 --> | 
			
		
	
		
			
				
					|  |  |  |                 sr.staff_id, | 
			
		
	
		
			
				
					|  |  |  |                 case when gsr.role_key = | 
			
		
	
		
			
				
					|  |  |  |                 <choose> | 
			
		
	
		
			
				
					|  |  |  |                     <when test="orgType != null and orgType == 'agency' "> | 
			
		
	
		
			
				
					|  |  |  |                         'agency_leader' | 
			
		
	
		
			
				
					|  |  |  |                     </when> | 
			
		
	
		
			
				
					|  |  |  |                     <when test="orgType != null and orgType == 'dept' "> | 
			
		
	
		
			
				
					|  |  |  |                         'dept_leader' | 
			
		
	
		
			
				
					|  |  |  |                     </when> | 
			
		
	
		
			
				
					|  |  |  |                     <otherwise> | 
			
		
	
		
			
				
					|  |  |  |                         'grid_manager' | 
			
		
	
		
			
				
					|  |  |  |                     </otherwise> | 
			
		
	
		
			
				
					|  |  |  |                 </choose> | 
			
		
	
		
			
				
					|  |  |  |                 then 1 else 0 end is_first<!-- 有单位领导角色的人赋值为1,没有的赋值为0 --> | 
			
		
	
		
			
				
					|  |  |  |             FROM staff_role sr | 
			
		
	
		
			
				
					|  |  |  |             INNER JOIN gov_staff_role gsr ON sr.role_id = gsr.id AND gsr.customer_id = #{customerId} | 
			
		
	
		
			
				
					|  |  |  |             WHERE | 
			
		
	
		
			
				
					|  |  |  |                 sr.del_flag = '0' | 
			
		
	
		
			
				
					|  |  |  |             AND sr.staff_id IN | 
			
		
	
		
			
				
					|  |  |  |                 ( | 
			
		
	
		
			
				
					|  |  |  |                 <foreach collection="staffIds" item="staffId" separator=","> | 
			
		
	
		
			
				
					|  |  |  |                     #{staffId} | 
			
		
	
		
			
				
					|  |  |  |                 </foreach> | 
			
		
	
		
			
				
					|  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |             ORDER BY | 
			
		
	
		
			
				
					|  |  |  |                 gsr.role_key <![CDATA[<>]]> | 
			
		
	
		
			
				
					|  |  |  |                 <choose> | 
			
		
	
		
			
				
					|  |  |  |                     <when test="orgType != null and orgType == 'agency' "> | 
			
		
	
		
			
				
					|  |  |  |                         'agency_leader' | 
			
		
	
		
			
				
					|  |  |  |                     </when> | 
			
		
	
		
			
				
					|  |  |  |                     <when test="orgType != null and orgType == 'dept' "> | 
			
		
	
		
			
				
					|  |  |  |                         'dept_leader' | 
			
		
	
		
			
				
					|  |  |  |                     </when> | 
			
		
	
		
			
				
					|  |  |  |                     <otherwise> | 
			
		
	
		
			
				
					|  |  |  |                         'grid_manager' | 
			
		
	
		
			
				
					|  |  |  |                     </otherwise> | 
			
		
	
		
			
				
					|  |  |  |                 </choose> | 
			
		
	
		
			
				
					|  |  |  |                 , sr.created_time DESC<!-- 标注有点位领导角色的人不参与排序也就是默认拍在前边 --> | 
			
		
	
		
			
				
					|  |  |  |             ) t | 
			
		
	
		
			
				
					|  |  |  |         GROUP BY t.staff_id | 
			
		
	
		
			
				
					|  |  |  |         ORDER BY t.is_first <![CDATA[<>]]> 1 | 
			
		
	
		
			
				
					|  |  |  |         LIMIT #{pageNo}, #{pageSize} | 
			
		
	
		
			
				
					|  |  |  |     </select> | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     <select id="selectStaffList" resultMap="staffList"> | 
			
		
	
		
			
				
					|  |  |  |         SELECT | 
			
		
	
		
			
				
					|  |  |  |             * | 
			
		
	
	
		
			
				
					|  |  | @ -58,55 +109,15 @@ | 
			
		
	
		
			
				
					|  |  |  |             customer_staff | 
			
		
	
		
			
				
					|  |  |  |         WHERE | 
			
		
	
		
			
				
					|  |  |  |             del_flag = '0' | 
			
		
	
		
			
				
					|  |  |  |         AND user_id IN ( | 
			
		
	
		
			
				
					|  |  |  |         <!-- 按人员Id列表查询,先查询每个人有的角色,然后把有单位领导角色的人排在前边,其他的在按创建时间降序 --> | 
			
		
	
		
			
				
					|  |  |  |             SELECT | 
			
		
	
		
			
				
					|  |  |  |                 t.staff_id | 
			
		
	
		
			
				
					|  |  |  |             FROM ( | 
			
		
	
		
			
				
					|  |  |  |             <!-- 里边的sql,尽管有去重,一个人有多个角色时,在里边sql查询出来的是一个人两条数据,is_first一个是0一个是1,所以外层需要在按人分组 --> | 
			
		
	
		
			
				
					|  |  |  |                 SELECT DISTINCT<!-- 没有这个去重会改变最终的结果顺序,至于为什么还不清楚 --> | 
			
		
	
		
			
				
					|  |  |  |                     sr.staff_id, | 
			
		
	
		
			
				
					|  |  |  |                     case when gsr.role_key = | 
			
		
	
		
			
				
					|  |  |  |                     <choose> | 
			
		
	
		
			
				
					|  |  |  |                         <when test="orgType != null and orgType == 'agency' "> | 
			
		
	
		
			
				
					|  |  |  |                             'agency_leader' | 
			
		
	
		
			
				
					|  |  |  |                         </when> | 
			
		
	
		
			
				
					|  |  |  |                         <when test="orgType != null and orgType == 'dept' "> | 
			
		
	
		
			
				
					|  |  |  |                             'dept_leader' | 
			
		
	
		
			
				
					|  |  |  |                         </when> | 
			
		
	
		
			
				
					|  |  |  |                         <otherwise> | 
			
		
	
		
			
				
					|  |  |  |                             'grid_manager' | 
			
		
	
		
			
				
					|  |  |  |                         </otherwise> | 
			
		
	
		
			
				
					|  |  |  |                     </choose> | 
			
		
	
		
			
				
					|  |  |  |                     then 1 else 0 end is_first<!-- 有单位领导角色的人赋值为1,没有的赋值为0 --> | 
			
		
	
		
			
				
					|  |  |  |                 FROM staff_role sr | 
			
		
	
		
			
				
					|  |  |  |                 INNER JOIN gov_staff_role gsr ON sr.role_id = gsr.id AND gsr.customer_id = #{customerId} | 
			
		
	
		
			
				
					|  |  |  |                 WHERE | 
			
		
	
		
			
				
					|  |  |  |                     sr.del_flag = '0' | 
			
		
	
		
			
				
					|  |  |  |                 AND sr.staff_id IN | 
			
		
	
		
			
				
					|  |  |  |                 ( | 
			
		
	
		
			
				
					|  |  |  |                     <foreach collection="staffIds" item="staffId" separator=","> | 
			
		
	
		
			
				
					|  |  |  |                         #{staffId} | 
			
		
	
		
			
				
					|  |  |  |                     </foreach> | 
			
		
	
		
			
				
					|  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |                 ORDER BY | 
			
		
	
		
			
				
					|  |  |  |                     gsr.role_key <![CDATA[<>]]> | 
			
		
	
		
			
				
					|  |  |  |                     <choose> | 
			
		
	
		
			
				
					|  |  |  |                         <when test="orgType != null and orgType == 'agency' "> | 
			
		
	
		
			
				
					|  |  |  |                             'agency_leader' | 
			
		
	
		
			
				
					|  |  |  |                         </when> | 
			
		
	
		
			
				
					|  |  |  |                         <when test="orgType != null and orgType == 'dept' "> | 
			
		
	
		
			
				
					|  |  |  |                             'dept_leader' | 
			
		
	
		
			
				
					|  |  |  |                         </when> | 
			
		
	
		
			
				
					|  |  |  |                         <otherwise> | 
			
		
	
		
			
				
					|  |  |  |                             'grid_manager' | 
			
		
	
		
			
				
					|  |  |  |                         </otherwise> | 
			
		
	
		
			
				
					|  |  |  |                     </choose> | 
			
		
	
		
			
				
					|  |  |  |                     , sr.created_time DESC<!-- 标注有点位领导角色的人不参与排序也就是默认拍在前边 --> | 
			
		
	
		
			
				
					|  |  |  |             ) t | 
			
		
	
		
			
				
					|  |  |  |             GROUP BY t.staff_id | 
			
		
	
		
			
				
					|  |  |  |             ORDER BY t.is_first <![CDATA[<>]]> 1 | 
			
		
	
		
			
				
					|  |  |  |             LIMIT #{pageNo}, #{pageSize} | 
			
		
	
		
			
				
					|  |  |  |         AND user_id IN | 
			
		
	
		
			
				
					|  |  |  |         <foreach item="staffId" collection="staffIds" open="(" separator="," close=")"> | 
			
		
	
		
			
				
					|  |  |  |             #{staffId} | 
			
		
	
		
			
				
					|  |  |  |         </foreach> | 
			
		
	
		
			
				
					|  |  |  |         ORDER BY field( | 
			
		
	
		
			
				
					|  |  |  |             user_id, | 
			
		
	
		
			
				
					|  |  |  |             <foreach item="staffId" collection="staffIds" separator=","> | 
			
		
	
		
			
				
					|  |  |  |                 #{staffId} | 
			
		
	
		
			
				
					|  |  |  |             </foreach> | 
			
		
	
		
			
				
					|  |  |  |         ) | 
			
		
	
		
			
				
					|  |  |  |     </select> | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | 
 |