设备统计查询优化

This commit is contained in:
zhangzhicheng 2024-08-17 17:56:52 +08:00
parent 61fccebbc6
commit 304d36e1cc

View File

@ -5,14 +5,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="org.dromara.web.mapper.EqEquipmentMapper"> <mapper namespace="org.dromara.web.mapper.EqEquipmentMapper">
<select id="selectEquipmentVoPage" resultType="org.dromara.web.domain.vo.EqUserEquipmentVo"> <!--<select id="selectEquipmentVoPage" resultType="org.dromara.web.domain.vo.EqUserEquipmentVo">
SELECT SELECT
user_id, user_id,
nick_name, nick_name,
user_name, user_name,
COUNT(*) AS bind_num, -- 设备总数 COUNT(*) AS bind_num, &#45;&#45; 设备总数
SUM(CASE WHEN line_status = 0 THEN 1 ELSE 0 END) AS offline_num, -- 离线个数 SUM(CASE WHEN line_status = 0 THEN 1 ELSE 0 END) AS offline_num, &#45;&#45; 离线个数
SUM(CASE WHEN line_status = 1 THEN 1 ELSE 0 END) AS online_num, -- 在线个数 SUM(CASE WHEN line_status = 1 THEN 1 ELSE 0 END) AS online_num &#45;&#45; 在线个数
FROM eq_equipment FROM eq_equipment
<where> <where>
<if test="nickName != null and nickName != ''"> <if test="nickName != null and nickName != ''">
@ -21,6 +21,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
</where> </where>
GROUP BY user_name, nick_name GROUP BY user_name, nick_name
</select>-->
<select id="selectEquipmentVoPage" resultType="org.dromara.web.domain.vo.EqUserEquipmentVo">
SELECT
e.user_id,
s.nick_name,
e.user_name,
COUNT(*) AS bind_num, -- 设备总数
SUM(CASE WHEN e.line_status = 0 THEN 1 ELSE 0 END) AS offline_num, -- 离线个数
SUM(CASE WHEN e.line_status = 1 THEN 1 ELSE 0 END) AS online_num -- 在线个数
FROM
eq_equipment e
JOIN
sys_user s ON e.user_id = s.user_id
<where>
<if test="nickName != null and nickName != ''">
AND nick_name like
CONCAT('%', #{nickName}, '%')
</if>
</where>
GROUP BY
e.user_name, s.nick_name;
</select> </select>
<select id="selectStatisticEquipmentList" resultType="org.dromara.web.domain.vo.EqEquipmentStatisticsVo"> <select id="selectStatisticEquipmentList" resultType="org.dromara.web.domain.vo.EqEquipmentStatisticsVo">