| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?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.pms.dal.mysql.IotDeviceMapper">
- <!--
- 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
- 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
- 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
- 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
- -->
- <select id="deviceAssociateBomPage"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- SELECT
- t.id ,
- t.device_code,
- t.device_name,
- t.brand,
- t.model,
- t.dept_id,
- t.device_status,
- t.asset_property,
- t.pic_url,
- t.remark,
- t.create_time,
- t1.id bomNodeId,
- t1.`name`,
- t1.`code`
- FROM
- rq_iot_device t
- INNER JOIN rq_iot_bom t1 ON ( t1.device_category_id = t.asset_class AND t1.deleted = 0 )
- WHERE
- t.deleted = 0
- AND t1.deleted = 0
- AND t1.leaf_flag = 1
- AND t1.type LIKE '%2%'
- <if test="deptIds != null and deptIds.size > 0">
- AND t.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
- AND t.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
- </if>
- <if test="reqVO.name!=null and reqVO.name!=''">
- AND t1.name LIKE concat(concat("%",#{reqVO.name}),"%")
- </if>
- </select>
- <select id="deviceAssociateBomList"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- SELECT *
- FROM (
- SELECT
- t.id ,
- t.device_code,
- t.device_name,
- t.asset_class,
- t.brand,
- t.model,
- t.dept_id,
- t.device_status,
- t.asset_property,
- t.pic_url,
- t.remark,
- t.create_time,
- t1.id bomNodeId,
- t1.`name`,
- t1.`code`
- FROM
- rq_iot_device t
- INNER JOIN rq_iot_bom t1 ON ( t1.device_category_id = t.asset_class AND t1.deleted = 0 )
- WHERE
- t.deleted = 0
- AND t1.deleted = 0
- AND t1.leaf_flag = 1
- AND t1.type LIKE '%2%'
- <if test="deviceIds != null and deviceIds.size > 0">
- AND t.id IN
- <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- ) t2
- LEFT JOIN (
- SELECT
- l.device_id,
- l.total_run_time,
- l.total_mileage,
- l.time
- FROM rq_iot_device_run_log l
- RIGHT JOIN (
- SELECT
- device_id,
- MAX(time) AS latest_time,
- MAX(id) AS max_id
- FROM rq_iot_device_run_log
- GROUP BY device_id
- ) AS latest
- ON l.device_id = latest.device_id
- AND l.time = latest.latest_time
- AND l.id = latest.max_id
- ) tmp ON tmp.device_id = t2.id
- </select>
- <select id="deviceAssociateBomListPage"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- SELECT *
- FROM (
- SELECT
- t.id ,
- t.device_code,
- t.device_name,
- t.asset_class,
- t.brand,
- t.model,
- t.dept_id,
- t.device_status,
- t.asset_property,
- t.pic_url,
- t.remark,
- t.create_time,
- t1.id bomNodeId,
- t1.`name`,
- t1.`code`
- FROM
- rq_iot_device t
- INNER JOIN rq_iot_bom t1 ON ( t1.device_category_id = t.asset_class AND t1.deleted = 0 )
- WHERE
- t.deleted = 0
- AND t1.deleted = 0
- AND t1.leaf_flag = 1
- AND t1.type LIKE '%2%'
- <if test="deviceIds != null and deviceIds.size > 0">
- AND t.id IN
- <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- ) t2
- LEFT JOIN (
- SELECT
- l.device_id,
- l.total_run_time,
- l.total_mileage,
- l.time
- FROM rq_iot_device_run_log l
- RIGHT JOIN (
- SELECT
- device_id,
- MAX(time) AS latest_time,
- MAX(id) AS max_id
- FROM rq_iot_device_run_log
- GROUP BY device_id
- ) AS latest
- ON l.device_id = latest.device_id
- AND l.time = latest.latest_time
- AND l.id = latest.max_id
- ) tmp ON tmp.device_id = t2.id
- </select>
- </mapper>
|