| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- <?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="deviceDistances"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- SELECT
- rid.id,
- rid.dept_id deptId,
- rid.device_code deviceCode,
- rid.device_name deviceName,
- rid.device_status deviceStatus,
- rid.asset_property assetProperty
- FROM rq_iot_main_work_order_bom mwoo
- LEFT JOIN rq_iot_device rid ON rid.id = mwoo.device_id
- WHERE mwoo.deleted = 0
- AND mwoo.`status` = 0
- AND rid.device_code IS NOT NULL
- <if test="deptIds != null and deptIds.size > 0">
- AND rid.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="sortedDeviceIds != null and sortedDeviceIds.size > 0">
- AND rid.id IN
- <foreach collection="sortedDeviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
- AND rid.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
- </if>
- <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
- AND rid.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
- </if>
- GROUP BY mwoo.device_id
- ORDER BY FIELD(rid.id,
- <if test="sortedDeviceIds != null and sortedDeviceIds.size > 0">
- <foreach collection="sortedDeviceIds" index="index" item="key" separator=",">
- #{key}
- </foreach>
- </if>
- )
- </select>
- <select id="personRelationDevices"
- 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
- FROM
- rq_iot_device t
- WHERE t.deleted = 0
- <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="Y" '>
- AND
- t.id IN (
- SELECT device_id FROM rq_iot_device_person
- )
- </if>
- <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="N" '>
- AND
- t.id NOT IN (
- SELECT device_id FROM rq_iot_device_person
- )
- </if>
- <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.deviceCode!=null and reqVO.deviceCode!=''">
- AND t.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
- </if>
- </select>
- <!-- 设备状态列表 -->
- <select id="deviceStatuses"
- 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
- FROM
- rq_iot_device t
- WHERE t.deleted = 0
- <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="Y" '>
- AND
- t.id IN (
- SELECT device_id FROM rq_iot_device_status_log
- )
- </if>
- <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="N" '>
- AND
- t.id NOT IN (
- SELECT device_id FROM rq_iot_device_status_log
- )
- </if>
- <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.deviceCode!=null and reqVO.deviceCode!=''">
- AND t.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
- </if>
- </select>
- <!-- 设备调拨列表 -->
- <select id="deviceAllots"
- 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
- FROM
- rq_iot_device t
- WHERE t.deleted = 0
- <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="Y" '>
- AND
- t.id IN (
- SELECT device_id FROM rq_iot_device_allot_log
- )
- </if>
- <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="N" '>
- AND
- t.id NOT IN (
- SELECT device_id FROM rq_iot_device_allot_log
- )
- </if>
- <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.deviceCode!=null and reqVO.deviceCode!=''">
- AND t.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
- </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>
|