|
|
<?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="cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper">
|
|
|
|
|
|
<!--
|
|
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
|
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
|
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
|
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
|
|
-->
|
|
|
|
|
|
|
|
|
<select id="lineDevicePage"
|
|
|
resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.LineDeviceRespVO">
|
|
|
|
|
|
select
|
|
|
mo.id,
|
|
|
iod.id as deviceId,
|
|
|
mo.code as lineNode,
|
|
|
mo.name as lineName,
|
|
|
iod.device_code as deviceCode,
|
|
|
IFNULL(mo.device_name, iod.device_name) as deviceName,
|
|
|
iod.status,
|
|
|
CASE iod.status
|
|
|
WHEN '1' THEN '在线'
|
|
|
WHEN '2' THEN '离线'
|
|
|
ELSE iod.status
|
|
|
END as statusName
|
|
|
from mes_organization mo
|
|
|
left join iot_device iod on mo.machine_id = iod.id
|
|
|
where mo.deleted = 0
|
|
|
and mo.machine_id is not null
|
|
|
<if test="pageReqVO.lineNode != null and pageReqVO.lineNode != ''">
|
|
|
and mo.code like concat(concat('%', #{pageReqVO.lineNode}), '%')
|
|
|
</if>
|
|
|
<if test="pageReqVO.lineName != null and pageReqVO.lineName != ''">
|
|
|
and mo.name like concat(concat('%', #{pageReqVO.lineName}), '%')
|
|
|
</if>
|
|
|
<!-- 新增ids过滤条件 -->
|
|
|
<if test="pageReqVO.ids != null and pageReqVO.ids != ''">
|
|
|
and FIND_IN_SET(mo.id, #{pageReqVO.ids})
|
|
|
</if>
|
|
|
<if test="pageReqVO.deviceCode != null and pageReqVO.deviceCode != ''">
|
|
|
and iod.device_code like concat(concat('%', #{pageReqVO.deviceCode}), '%')
|
|
|
</if>
|
|
|
|
|
|
<if test="pageReqVO.deviceName != null and pageReqVO.deviceName != ''">
|
|
|
and iod.device_name like concat(concat('%', #{pageReqVO.deviceName}), '%')
|
|
|
</if>
|
|
|
|
|
|
<if test="pageReqVO.status != null and pageReqVO.status != ''">
|
|
|
and iod.status like concat(concat('%', #{pageReqVO.status}), '%')
|
|
|
</if>
|
|
|
|
|
|
order by mo.id desc
|
|
|
</select>
|
|
|
|
|
|
<select id="getDeviceOperationalStatus"
|
|
|
resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.DeviceOperationStatusRespVO">
|
|
|
SELECT
|
|
|
-- 设备总数
|
|
|
COUNT(DISTINCT ide.id) AS totalDevices,
|
|
|
|
|
|
-- 各状态设备数量
|
|
|
SUM(CASE WHEN latest_status.rule = '1' THEN 1 ELSE 0 END) AS runningCount,
|
|
|
SUM(CASE WHEN latest_status.rule = '2' THEN 1 ELSE 0 END) AS standbyCount,
|
|
|
SUM(CASE WHEN latest_status.rule = '3' THEN 1 ELSE 0 END) AS faultCount,
|
|
|
SUM(CASE WHEN latest_status.rule = '4' THEN 1 ELSE 0 END) AS warningCount
|
|
|
|
|
|
FROM besure.iot_device ide
|
|
|
LEFT JOIN (
|
|
|
-- 获取每个设备的最新状态
|
|
|
SELECT
|
|
|
device_id,
|
|
|
rule,
|
|
|
ROW_NUMBER() OVER (PARTITION BY device_id ORDER BY create_time DESC) AS rn
|
|
|
FROM besure.iot_device_operation_record
|
|
|
WHERE rule IN ('1', '2', '3', '4')
|
|
|
AND deleted = 0
|
|
|
) latest_status ON ide.id = latest_status.device_id AND latest_status.rn = 1
|
|
|
WHERE ide.deleted = 0
|
|
|
|
|
|
</select>
|
|
|
<select id="lineDeviceList"
|
|
|
resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.LineDeviceRespVO">
|
|
|
select
|
|
|
mo.id,
|
|
|
iod.id as deviceId,
|
|
|
mo.code as lineNode,
|
|
|
mo.name as lineName,
|
|
|
iod.device_code as deviceCode,
|
|
|
iod.device_name as deviceName,
|
|
|
iod.status
|
|
|
from mes_organization mo
|
|
|
left join iot_device iod on mo.machine_id = iod.id
|
|
|
where mo.deleted = 0
|
|
|
and mo.machine_id is not null
|
|
|
<if test="pageReqVO.lineNode != null and pageReqVO.lineNode != ''">
|
|
|
and mo.code like concat(concat('%', #{pageReqVO.lineNode}), '%')
|
|
|
</if>
|
|
|
<if test="pageReqVO.lineName != null and pageReqVO.lineName != ''">
|
|
|
and mo.name like concat(concat('%', #{pageReqVO.lineName}), '%')
|
|
|
</if>
|
|
|
<!-- 新增ids过滤条件 -->
|
|
|
<if test="pageReqVO.ids != null and pageReqVO.ids != ''">
|
|
|
and FIND_IN_SET(mo.id, #{pageReqVO.ids})
|
|
|
</if>
|
|
|
<if test="pageReqVO.deviceCode != null and pageReqVO.deviceCode != ''">
|
|
|
and iod.device_code like concat(concat('%', #{pageReqVO.deviceCode}), '%')
|
|
|
</if>
|
|
|
|
|
|
<if test="pageReqVO.deviceName != null and pageReqVO.deviceName != ''">
|
|
|
and iod.device_name like concat(concat('%', #{pageReqVO.deviceName}), '%')
|
|
|
</if>
|
|
|
|
|
|
<if test="pageReqVO.status != null and pageReqVO.status != ''">
|
|
|
and iod.status like concat(concat('%', #{pageReqVO.status}), '%')
|
|
|
</if>
|
|
|
|
|
|
order by mo.id desc
|
|
|
</select>
|
|
|
</mapper> |