将Role_Name为 Null 的列查询数据在前,来排序
ORDER BY
(CASE
WHEN r.role_name is null then 1
WHEN r.role_name is not null then 2
END)
完整SQL(自定义State列,是否分配权限,为空将值设为1未分配,否则就给2已分配)
<!--查询权限分配列表-->
<select id="getRoleAllot" parameterType="Map" resultType="HashMap">
select p.oid as "oid",p.user_code as "userCode",p.user_cname as "userCname",i.user_cname as "operatorName",
u.operate_date as "operateDate",r.role_name as "roleName",
(case when r.role_name is null then 1 else 2 end) as "state"
from person_info p
left join authority_user_role u on u.user_oid = p.oid
left join authority_role r on r.oid = u.role_oid
left join person_info i on u.operator = i.oid
where p.invalid_flag = '1'
<if test="userCname != null and userCname != ''">
and p.user_cname like '%${userCname}%'
</if>
<if test="roleName != null and roleName != ''">
and r.role_name like '%${roleName}%'
</if>
<if test="allotFlag != null and allotFlag != ''">
<if test="allotFlag == '1'.toString()">
and r.role_name is null
</if>
<if test="allotFlag == '2'.toString()">
and r.role_name is not null
</if>
</if>
ORDER BY
(CASE
WHEN r.role_name is null then 1
WHEN r.role_name is not null then 2
END)
<if test="pageNo != null and pageNo != ''">
limit #{pageNo},#{pageSize}
</if>
</select>