Stwzhj-Cloud-Plus/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/SysDeptMapper.xml

235 lines
12 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="org.dromara.system.mapper.SysDeptMapper">
<resultMap type="org.dromara.system.domain.vo.SysDeptVo" id="SysDeptResult">
</resultMap>
<select id="selectDeptList" resultMap="SysDeptResult">
select
<if test="ew.getSqlSelect != null">
${ew.getSqlSelect}
</if>
<if test="ew.getSqlSelect == null">
*
</if>
from sys_dept ${ew.getCustomSqlSegment}
</select>
<select id="countDeptById" resultType="Long">
select count(*) from sys_dept where del_flag = '0' and dept_id = #{deptId}
</select>
<select id="selectDeptListByRoleId" resultType="Long">
select d.dept_id
from sys_dept d
left join sys_role_dept rd on d.dept_id = rd.dept_id
where rd.role_id = #{roleId}
<if test="deptCheckStrictly">
and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId})
</if>
order by d.parent_id, d.order_num
</select>
<!-- 各机构设备在线总数 参数deviceType -->
<select id="deviceStatics" parameterType="String" resultMap="SysDeptResult">
select * from (
<!--市局数量-->
select dept_id as deptId,short_name as deptName,parent_id as parentId,(select count(1) from t_device_redis
where online =1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
) as onlineCount,
(select count(1) from t_device
where valid =1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
) as allCount from sys_dept d
where parent_id = '0'
union
<!--支队数量-->
select dept_id,short_name,parent_id,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select SUBSTRING(zzjgdm,1,8) as zzjgdm ,count(*) as onlineCount from t_device_redis
where online =1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by SUBSTRING(zzjgdm,1,8)) o
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(o.zzjgdm,1,8)
LEFT JOIN
(select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device
where valid =1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by SUBSTRING(zzjgdm,1,8)) a
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8)
where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '341800000000' and dept_id like '341800%'
union
<!--分局数量-->
select dept_id,short_name,parent_id,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select SUBSTRING(zzjgdm,1,6) as zzjgdm ,count(*) as onlineCount from t_device_redis
where online =1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by SUBSTRING(zzjgdm,1,6)) o
on SUBSTRING(d.dept_id,1,6) = SUBSTRING(o.zzjgdm,1,6)
LEFT JOIN
(select substring(zzjgdm,1,6) as zzjgdm ,count(*) as allCount from t_device
where valid =1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by SUBSTRING(zzjgdm,1,6)) a
on SUBSTRING(d.dept_id,1,6) = SUBSTRING(a.zzjgdm,1,6)
where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '341800000000' and dept_id not like '341800%'
union
<!--派出所等三级四级机构-->
select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select SUBSTRING(zzjgdm,1,8) as zzjgdm ,count(*) as onlineCount from t_device_redis
where online =1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by SUBSTRING(zzjgdm,1,8)) o
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(o.zzjgdm,1,8)
LEFT JOIN
(select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device
where valid = 1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by SUBSTRING(zzjgdm,1,8)) a
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8)
where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000' and parent_id != '0' and dept_id like '%0000'
<!--大队等三级四级机构-->
UNION
select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select SUBSTRING(zzjgdm,1,10) as zzjgdm ,count(*) as onlineCount from t_device_redis
where online =1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by SUBSTRING(zzjgdm,1,10)) o
on SUBSTRING(d.dept_id,1,10) = SUBSTRING(o.zzjgdm,1,10)
LEFT JOIN
(select substring(zzjgdm,1,10) as zzjgdm ,count(*) as allCount from t_device
where valid = 1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by SUBSTRING(zzjgdm,1,10)) a
on SUBSTRING(d.dept_id,1,10) = SUBSTRING(a.zzjgdm,1,10)
where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000'
and parent_id != '0' and dept_id not like '%0000' and dept_id like '%00'
union
<!--四级机构-->
select dept_id as deptId,dept_name as deptName,parent_id,IFNULL(onlineCount,0) onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select zzjgdm ,count(*) as onlineCount from t_device_redis
where online =1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by zzjgdm) o
on d.dept_id = o.zzjgdm
LEFT JOIN
(select zzjgdm as zzjgdm ,count(*) as allCount from t_device
where valid = 1
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
group by zzjgdm) a
on d.dept_id = a.zzjgdm
where `status` = '0' and del_flag =0 and is_visible = '1' and dept_id not like '%00' and LENGTH(ancestors) >= 40
) a
order by a.deptId asc
</select>
<select id="deviceStaticsByDeptId" resultMap="SysDeptResult">
select * from (
<!--市局数量-->
select dept_id as deptId,short_name as deptName,parent_id as parentId,(select count(1) from t_device_redis where online =1 and device_type=#{deviceType}) as onlineCount,
(select count(1) from t_device where device_type=#{deviceType} and valid =1) as allCount from sys_dept d
where parent_id = '0'
union
<!--支队数量-->
select dept_id,short_name,parent_id,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select SUBSTRING(zzjgdm,1,8) as zzjgdm ,count(*) as onlineCount from t_device_redis where online =1 and device_type = #{deviceType} group by SUBSTRING(zzjgdm,1,8)) o
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(o.zzjgdm,1,8)
LEFT JOIN
(select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid =1 group by SUBSTRING(zzjgdm,1,8)) a
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8)
where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '340100000000' and dept_id like '340100%'
union
<!--分局数量-->
select dept_id,short_name,parent_id,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select SUBSTRING(zzjgdm,1,6) as zzjgdm ,count(*) as onlineCount from t_device_redis where online =1 and device_type = #{deviceType} group by SUBSTRING(zzjgdm,1,6)) o
on SUBSTRING(d.dept_id,1,6) = SUBSTRING(o.zzjgdm,1,6)
LEFT JOIN
(select substring(zzjgdm,1,6) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid =1 group by SUBSTRING(zzjgdm,1,6)) a
on SUBSTRING(d.dept_id,1,6) = SUBSTRING(a.zzjgdm,1,6)
where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '340100000000' and dept_id not like '340100%'
union
<!--派出所等三级四级机构-->
select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select SUBSTRING(zzjgdm,1,8) as zzjgdm ,count(*) as onlineCount from t_device_redis where online =1 and device_type = #{deviceType} group by SUBSTRING(zzjgdm,1,8)) o
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(o.zzjgdm,1,8)
LEFT JOIN
(select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by SUBSTRING(zzjgdm,1,8)) a
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8)
where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000' and parent_id != '0' and dept_id like '%0000'
<!--大队等三级四级机构-->
UNION
select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select SUBSTRING(zzjgdm,1,10) as zzjgdm ,count(*) as onlineCount from t_device_redis where online =1 and device_type = #{deviceType} group by SUBSTRING(zzjgdm,1,10)) o
on SUBSTRING(d.dept_id,1,10) = SUBSTRING(o.zzjgdm,1,10)
LEFT JOIN
(select substring(zzjgdm,1,10) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by SUBSTRING(zzjgdm,1,10)) a
on SUBSTRING(d.dept_id,1,10) = SUBSTRING(a.zzjgdm,1,10)
where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000'
and parent_id != '0' and dept_id not like '%0000' and dept_id like '%00'
union
<!--四级机构-->
select dept_id as deptId,short_name as deptName,parent_id,IFNULL(onlineCount,0) onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN
(select zzjgdm ,count(*) as onlineCount from t_device_redis where online =1 and device_type = #{deviceType} group by zzjgdm) o
on d.dept_id = o.zzjgdm
LEFT JOIN
(select zzjgdm as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by zzjgdm) a
on d.dept_id = a.zzjgdm
where `status` = '0' and del_flag =0 and is_visible = '1' and dept_id not like '%00' and LENGTH(ancestors) >= 40
) count_temp
<where>
<if test="deptId != null and deptId != ''">
and deptId like concat('%',#{deptId},'%')
</if>
</where>
</select>
</mapper>