| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729 |
- <?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="allDeviceDistances"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- SELECT
- rid.id,
- rid.dept_id AS deptId,
- rid.device_code AS deviceCode,
- rid.device_name AS deviceName,
- rid.device_status AS deviceStatus,
- rid.model AS model,
- rid.asset_property AS assetProperty
- FROM rq_iot_device rid
- WHERE rid.deleted = 0
- <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="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>
- ORDER BY
- <if test="alarmDeviceIds != null and alarmDeviceIds.size > 0">
- CASE WHEN rid.id IN
- <foreach collection="alarmDeviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- THEN 0 ELSE 1 END,
- FIELD(rid.id,
- <foreach collection="alarmDeviceIds" index="index" item="key" separator=",">
- #{key}
- </foreach>),
- </if>
- rid.id DESC;
- </select>
- <select id="timeoutDeviceMaintenances"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- SELECT
- rid.id,
- rid.dept_id AS deptId,
- rid.device_code AS deviceCode,
- rid.device_name AS deviceName,
- rid.device_status AS deviceStatus,
- rid.model AS model,
- rid.asset_property AS assetProperty
- FROM rq_iot_device rid
- WHERE rid.deleted = 0
- <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="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>
- <if test="alarmDeviceIds != null and alarmDeviceIds.size > 0">
- AND rid.id IN
- <foreach collection="alarmDeviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- ORDER BY
- <if test="alarmDeviceIds != null and alarmDeviceIds.size > 0">
- CASE WHEN rid.id IN
- <foreach collection="alarmDeviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- THEN 0 ELSE 1 END,
- FIELD(rid.id,
- <foreach collection="alarmDeviceIds" index="index" item="key" separator=",">
- #{key}
- </foreach>),
- </if>
- rid.id DESC;
- </select>
- <select id="deviceDistances"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- SELECT *
- FROM (
- SELECT
- rid.id,
- rid.dept_id deptId,
- rid.device_code deviceCode,
- rid.device_name deviceName,
- rid.device_status deviceStatus,
- rid.asset_property assetProperty,
- MAX(mwoo.work_order_id) workOrderId,
- '' planId
- 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="deviceIds != null and deviceIds.size > 0">
- AND rid.id IN
- <foreach collection="deviceIds" 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
- UNION ALL
- SELECT
- rid.id,
- rid.dept_id deptId,
- rid.device_code deviceCode,
- rid.device_name deviceName,
- rid.device_status deviceStatus,
- rid.asset_property assetProperty,
- '' workOrderId,
- MAX(mb.plan_id) planId
- FROM rq_iot_maintenance_bom mb
- LEFT JOIN rq_iot_device rid ON rid.id = mb.device_id
- WHERE mb.deleted = 0
- AND mb.`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="mainBomDeviceIds != null and mainBomDeviceIds.size > 0">
- AND rid.id IN
- <foreach collection="mainBomDeviceIds" 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 mb.device_id
- ) tmp
- ORDER BY FIELD(tmp.id,
- <if test="sortedDeviceIds != null and sortedDeviceIds.size > 0">
- <foreach collection="sortedDeviceIds" index="index" item="key" separator=",">
- #{key}
- </foreach>
- </if>
- )
- </select>
- <select id="deviceAlarmDistances"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- SELECT *
- FROM (
- SELECT
- rid.id,
- rid.dept_id deptId,
- rid.device_code deviceCode,
- rid.device_name deviceName,
- rid.device_status deviceStatus,
- rid.asset_property assetProperty,
- MAX(mwoo.work_order_id) workOrderId,
- '' planId
- 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="deviceIds != null and deviceIds.size > 0">
- AND rid.id IN
- <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- GROUP BY mwoo.device_id
- UNION ALL
- SELECT
- rid.id,
- rid.dept_id deptId,
- rid.device_code deviceCode,
- rid.device_name deviceName,
- rid.device_status deviceStatus,
- rid.asset_property assetProperty,
- '' workOrderId,
- MAX(mb.plan_id) planId
- FROM rq_iot_maintenance_bom mb
- LEFT JOIN rq_iot_device rid ON rid.id = mb.device_id
- WHERE mb.deleted = 0
- AND mb.`status` = 0
- AND rid.device_code IS NOT NULL
- <if test="mainBomDeviceIds != null and mainBomDeviceIds.size > 0">
- AND rid.id IN
- <foreach collection="mainBomDeviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- GROUP BY mb.device_id
- ) tmp
- ORDER BY FIELD(tmp.id,
- <if test="sortedDeviceIds != null and sortedDeviceIds.size > 0">
- <foreach collection="sortedDeviceIds" index="index" item="key" separator=",">
- #{key}
- </foreach>
- </if>
- )
- </select>
- <select id="deviceAlarmDistancesSearch"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- SELECT *
- FROM (
- SELECT
- rid.id,
- rid.dept_id deptId,
- rid.device_code deviceCode,
- rid.device_name deviceName,
- rid.device_status deviceStatus,
- rid.asset_property assetProperty,
- '' workOrderId,
- MAX(mb.plan_id) planId
- FROM rq_iot_maintenance_bom mb
- LEFT JOIN rq_iot_device rid ON rid.id = mb.device_id
- WHERE mb.deleted = 0
- AND mb.`status` = 0
- AND rid.device_code IS NOT NULL
- <if test="mainBomDeviceIds != null and mainBomDeviceIds.size > 0">
- AND rid.id IN
- <foreach collection="mainBomDeviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- GROUP BY mb.device_id
- ) tmp
- ORDER BY FIELD(tmp.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="deviceIds != null and deviceIds.size > 0">
- AND t.id IN
- <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="reqVO.deviceIds != null and reqVO.deviceIds.size > 0">
- AND t.id IN
- <foreach collection="reqVO.deviceIds" 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.deviceIds != null and reqVO.deviceIds.size > 0">
- AND t.id IN
- <foreach collection="reqVO.deviceIds" 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.deviceIds != null and reqVO.deviceIds.size > 0">
- AND t.id IN
- <foreach collection="reqVO.deviceIds" 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
- 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`,
- t1.`type`
- FROM
- rq_iot_device t
- INNER JOIN rq_iot_device_bom t1 ON ( t1.device_id = t.id AND t1.deleted = 0 )
- WHERE
- t.deleted = 0
- AND t1.deleted = 0
- AND t1.leaf_flag = 1
- <if test='bomFlag!=null and bomFlag!="" and bomFlag=="b" '>
- AND t1.type LIKE '%2%'
- </if>
- <if test='bomFlag!=null and bomFlag!="" and bomFlag=="w" '>
- AND t1.type LIKE '%1%'
- </if>
- <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>
- </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_device_bom t1 ON ( t1.device_id = t.id AND t1.deleted = 0 )
- WHERE
- t.deleted = 0
- AND t1.deleted = 0
- AND t1.leaf_flag = 1
- <if test='bomFlag!=null and bomFlag!="" and bomFlag=="b" '>
- AND t1.type LIKE '%2%'
- </if>
- <if test='bomFlag!=null and bomFlag!="" and bomFlag=="w" '>
- AND t1.type LIKE '%1%'
- </if>
- <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="allCarsContainsPlates"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotCarDevicePlateVO">
- SELECT
- id deviceId,
- device_code deviceCode,
- device_name deviceName,
- REGEXP_SUBSTR(device_name, '([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-Z0-9]{4,7}[A-Z0-9挂学警港澳使领])') as licensePlate
- FROM rq_iot_device
- WHERE
- deleted = 0
- AND device_name REGEXP '([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-Z0-9]{4,7}[A-Z0-9挂学警港澳使领])';
- </select>
- <select id="selectCodeAndNameList"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSimple">
- SELECT
- id,
- device_code as deviceCode,
- device_name as deviceName
- FROM rq_iot_device
- WHERE
- deleted = 0
- </select>
- <select id="selectTypeNumber" resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSimple">
- select b.name as category, a.count as value from (select asset_class, count(id) as count from rq_iot_device d
- <where>
- d.deleted=0
- <if test="reqVO.deptIds != null and reqVO.deptIds.size > 0">
- AND d.dept_id IN
- <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- and d.deleted=0
- <if test="products != null and products.size > 0">
- AND d.asset_class IN
- <foreach collection="products" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- </where>
- group by asset_class)a
- left join rq_iot_product_classify b on a.asset_class=b.id
- </select>
- <select id="selectExport"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- select a.*,
- g.label as deviceStatus,m.name as manufacturer,
- CASE
- WHEN d.type = 1 THEN COALESCE(d.`name`, '')
- WHEN d.type = 2 THEN COALESCE(p1.`name`, '')
- WHEN d.type = 3 THEN COALESCE(p2.`name`, '')
- ELSE ''
- END AS company,
- -- 按type规则填充project字段
- CASE
- WHEN d.type = 2 THEN COALESCE(d.`name`, '')
- WHEN d.type = 3 THEN COALESCE(p1.`name`, '')
- ELSE ''
- END AS project,
- -- 按type规则填充deptName字段(仅type=3时有值)
- CASE
- WHEN d.type = 3 THEN COALESCE(d.`name`, '')
- ELSE ''
- END AS deptName
- from rq_iot_device a
- -- 左关联当前部门(避免主表数据丢失)
- LEFT JOIN system_dept d ON a.dept_id = d.id
- -- 左关联父级部门(type=2/3时用)
- LEFT JOIN system_dept p1 ON d.parent_id = p1.id
- -- 左关联祖父级部门(type=3时用)
- LEFT JOIN system_dept p2 ON p1.parent_id = p2.id
- left join rq_iot_supplier m on a.manufacturer_id=m.id
- left join (select r.value,r.label from system_dict_data r where r.dict_type='pms_device_status') g on a.device_status = g.value COLLATE utf8mb4_general_ci
- <where>
- a.deleted=0
- <if test="reqVO.createTime[0] != null">
- AND a.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND a.create_time <= #{reqVO.createTime[1]}
- </if>
- <if test="reqVO.deptIds != null and reqVO.deptIds.size > 0">
- AND a.dept_id IN
- <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="reqVO.deviceCode != null">
- AND a.deviceCode LIKE concat("%",#{reqVO.deviceCode},"%")
- </if>
- <if test="reqVO.deviceName != null">
- AND a.deviceName LIKE concat("%",#{reqVO.deviceName},"%")
- </if>
- </where>
- </select>
- <select id="getTotalA" resultType="java.lang.Long">
- SELECT COUNT(1) FROM RQ_IOT_DEVICE b WHERE ASSET_CLASS IN(select id from rq_iot_product_classify a
- <where>
- a.deleted=0
- <if test='reqVO.remark!=null'>
- AND a.remark = #{reqVO.remark}
- </if>
- </where>
- )
- and
- b.deleted=0
- <if test="reqVO.deptIds != null and reqVO.deptIds.size > 0">
- AND b.dept_id IN
- <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- </select>
- <select id="getFailureCount" resultType="java.lang.Long">
- select b.device_id from (SELECT ID FROM RQ_IOT_DEVICE c WHERE ASSET_CLASS IN(select id from rq_iot_product_classify a
- <where>
- a.deleted=0
- <if test='reqVO.remark!=null'>
- AND a.remark = #{reqVO.remark}
- </if>
- </where>
- )
- and
- c.deleted=0
- <if test="reqVO.deptIds != null and reqVO.deptIds.size > 0">
- AND c.dept_id IN
- <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- )a
- left JOIN (select DISTINCT(device_id) from rq_iot_failure_report where `status`!='finished' and `status`!='oareject' and `status`!='reporting' and if_stop=1)b
- on a.id=b.device_id where b.device_id is not NULL
- </select>
- <select id="getRepairCount" resultType="java.lang.Long">
- select b.device_id from (SELECT ID FROM RQ_IOT_DEVICE c WHERE ASSET_CLASS IN(select id from rq_iot_product_classify a
- <where>
- a.deleted=0
- <if test='reqVO.remark!=null'>
- AND a.remark = #{reqVO.remark}
- </if>
- </where>
- )
- and
- c.deleted=0
- <if test="reqVO.deptIds != null and reqVO.deptIds.size > 0">
- AND c.dept_id IN
- <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- )a
- left JOIN (select DISTINCT(device_id) from rq_iot_maintain where `status`!='finished' and `status`!='oareject' and if_stop=1)b
- on a.id=b.device_id where b.device_id is not NULL
- </select>
- </mapper>
|