| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 |
- <?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.maintain.IotMaintainMapper">
- <select id="selectNotice"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.OrderVo">
- select * from (select a.id,
- a.failure_name title,
- '待填写' as status,
- (select nickname COLLATE utf8mb4_general_ci from system_users mm where cast(mm.id COLLATE utf8mb4_general_ci as char) =a.maintain_person COLLATE utf8mb4_general_ci) as person,
- '维修工单' as type,
- a.create_time
- from rq_iot_maintain a
- where status = 'tx'
- and deleted = false
- union all
- select b.id,
- b.inspect_order_title title,
- '待执行' as status,
- b.charge_name person,
- '巡检工单' as type,
- b.create_time
- from rq_iot_inspect_order b
- where status = 'todo'
- and deleted = false
- union all
- select c.id,
- c.name title,
- '待填写' as status,
- (select nickname COLLATE utf8mb4_general_ci from system_users bb where cast(bb.id COLLATE utf8mb4_general_ci as char) = c.responsible_person COLLATE utf8mb4_general_ci) as person,
- '保养工单' as type,
- c.create_time
- from rq_iot_main_work_order c
- where result = 1
- and deleted = false
- union all
- select d.id,
- d.order_name title,
- '待填写' as status,
- user_name as person,
- '运行记录' as type,
- d.create_time
- from rq_iot_opeation_fill_order d
- where order_status = 0
- and deleted = false)fin
- <where>
- <if test="reqVO.commonParam != null and reqVO.commonParam != ''">
- (fin.title LIKE CONCAT('%', #{reqVO.commonParam}, '%')
- OR fin.type LIKE CONCAT('%', #{reqVO.commonParam}, '%')
- OR fin.person LIKE CONCAT('%', #{reqVO.commonParam}, '%'))
- </if>
- </where>
- </select>
- <select id="getCost" parameterType="cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.ReportCost">
- select * from (select CAST(create_time AS CHAR) as date, '内部维修'as type, device_code as deviceCode, device_name as deviceName, maintain_fee as cost from rq_iot_maintain a
- <where>
- a.deleted=0 and a.type!='out'
- <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>
- </where>
- select CAST(create_time AS CHAR) as date, '委外维修'as type, device_code as deviceCode, device_name as deviceName, maintain_fee as cost from rq_iot_maintain a
- <where>
- a.deleted=0 and a.type='out'
- <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>
- </where>
- UNION ALL
- SELECT
- CAST(wo.update_time AS CHAR) as date,
- '保养' as type,
- d.device_code as deviceCode,
- d.device_name as deviceName,
- wo.cost
- FROM rq_iot_main_work_order wo
- LEFT JOIN rq_iot_main_work_order_bom wob ON (wob.work_order_id = wo.id AND wob.deleted = 0)
- LEFT JOIN rq_iot_device d ON (d.id = wob.device_id AND d.deleted = 0)
- WHERE
- wob.deleted = 0
- AND wo.deleted = 0
- AND d.deleted = 0
- <if test="reqVO.createTime[0] != null">
- AND wo.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND wo.create_time <= #{reqVO.createTime[1]}
- </if>
- <if test="reqVO.deptIds != null and reqVO.deptIds.size > 0">
- AND wo.dept_id IN
- <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- GROUP BY wo.id, wob.device_id) fin
- <where>
- <if test="reqVO.type != null">
- AND fin.type = #{reqVO.type}
- </if>
- </where>
- </select>
- <select id="selectStatusNumber" parameterType="cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.AllOrderResp">
- select status,count(status) as num from rq_iot_maintain a
- <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>
- </where>
- group by status
- </select>
- <select id="getAllOrder" parameterType="cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.AllOrderResp">
- select * from (
- select a.id,'维修工单' as type,
- '' as taskId,
- a.create_time as createTime,
- CASE
- WHEN a.status = 'todo' THEN '未完成'
- WHEN a.status = 'finished' THEN '已完成'
- WHEN a.status = 'ignore' THEN '忽略'
- ELSE '' -- 兼容其他未知状态值
- END AS status,concat(a.device_code,'|',a.device_name) as device, a.dept_id as deptId,
- 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_maintain 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
- <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>
- </where>
- UNION ALL
- select b.id,'巡检工单' as type,
- '' as taskId,
- b.create_time as createTime,
- CASE
- WHEN b.status = 'todo' THEN '未完成'
- WHEN b.status = 'finished' THEN '已完成'
- WHEN b.status = 'ignore' THEN '忽略'
- ELSE '' -- 兼容其他未知状态值
- END AS status, '' as device,b.dept_id as deptId,
- 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_inspect_order b
- -- 左关联当前部门(避免主表数据丢失)
- LEFT JOIN system_dept d ON b.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
- <where>
- b.deleted=0
- <if test="reqVO.createTime[0] != null">
- AND b.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND b.create_time <= #{reqVO.createTime[1]}
- </if>
- <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>
- </where>
- UNION ALL
- SELECT
- c.id,
- '' AS taskId,
- '运行记录' AS type,
- c.create_time AS createTime,
- -- 核心优化:status 数值转中文描述
- CASE
- WHEN c.order_status = 0 THEN '未完成'
- WHEN c.order_status = 1 THEN '已完成'
- WHEN c.order_status = 2 THEN '填写中'
- ELSE '' -- 兼容其他未知状态值
- END AS status,
- '' AS device,
- c.dept_id AS deptId,
- -- 按type规则填充company字段
- 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_opeation_fill_order c
- -- 左关联当前部门(避免主表数据丢失)
- LEFT JOIN system_dept d ON c.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
- <where>
- c.deleted=0
- <if test="reqVO.createTime[0] != null">
- AND c.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND c.create_time <= #{reqVO.createTime[1]}
- </if>
- <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>
- </where>
- union all
- select b.id,'保养工单' as type,
- '' as taskId,
- b.create_time as createTime,
- CASE
- WHEN b.result = 1 THEN '未完成'
- WHEN b.result = 2 THEN '已完成'
- ELSE '' -- 兼容其他未知状态值
- END AS status, '' as device,b.dept_id as deptId,
- 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_main_work_order b
- -- 左关联当前部门(避免主表数据丢失)
- LEFT JOIN system_dept d ON b.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
- <where>
- b.deleted = 0
- <if test="reqVO.createTime[0] != null">
- AND b.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND b.create_time <= #{reqVO.createTime[1]}
- </if>
- <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>
- </where>
- UNION ALL
- select b.id,'瑞恒日报' as type,
- b.task_id as taskId,
- b.create_time as createTime,
- CASE
- WHEN b.status = 0 THEN '未完成'
- WHEN b.status = 1 THEN '已完成'
- ELSE '' -- 兼容其他未知状态值
- END AS status, '' as device,b.dept_id as deptId,
- 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_rh_daily_report b
- -- 左关联当前部门(避免主表数据丢失)
- LEFT JOIN system_dept d ON b.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
- <where>
- b.deleted = 0
- <if test="reqVO.createTime[0] != null">
- AND b.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND b.create_time <= #{reqVO.createTime[1]}
- </if>
- <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>
- </where>
- UNION ALL
- select b.id,'瑞鹰日报' as type,
- b.task_id taskId,
- b.create_time as createTime,
- CASE
- WHEN b.status = 0 THEN '未完成'
- WHEN b.status = 1 THEN '已完成'
- ELSE '' -- 兼容其他未知状态值
- END AS status, '' as device,b.dept_id as deptId,
- 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_ry_daily_report b
- -- 左关联当前部门(避免主表数据丢失)
- LEFT JOIN system_dept d ON b.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
- <where>
- b.deleted = 0
- <if test="reqVO.createTime[0] != null">
- AND b.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND b.create_time <= #{reqVO.createTime[1]}
- </if>
- <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>
- </where>
- UNION ALL
- select b.id,'瑞都日报' as type,
- b.task_id as taskId,
- b.create_time as createTime,
- CASE
- WHEN b.status = 0 THEN '未完成'
- WHEN b.status = 1 THEN '已完成'
- ELSE '' -- 兼容其他未知状态值
- END AS status, '' as device,b.dept_id as deptId,
- 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_rd_daily_report b
- -- 左关联当前部门(避免主表数据丢失)
- LEFT JOIN system_dept d ON b.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
- <where>
- b.deleted = 0
- <if test="reqVO.createTime[0] != null">
- AND b.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND b.create_time <= #{reqVO.createTime[1]}
- </if>
- <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>
- </where>
- ) fin
- <where>
- <if test="reqVO.type != null">
- AND fin.type LIKE concat("%",#{reqVO.type},"%")
- </if>
- </where>
- </select>
- <select id="getMaintainFee" resultType="java.math.BigDecimal" >
- select sum(maintain_fee) from rq_iot_maintain c
- <where>
- c.deleted=0
- <if test="reqVO.createTime[0] != null">
- AND c.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND c.create_time <= #{reqVO.createTime[1]}
- </if>
- <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>
- <if test="reqVO.type != null">
- AND c.type = #{reqVO.type}
- </if>
- </where>
- </select>
- <select id="getMaintainFeeIn" resultType="java.math.BigDecimal" >
- select sum(maintain_fee) from rq_iot_maintain c
- <where>
- c.deleted=0 and c.type !='out'
- <if test="reqVO.createTime[0] != null">
- AND c.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND c.create_time <= #{reqVO.createTime[1]}
- </if>
- <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>
- <if test="reqVO.type != null">
- AND c.type = #{reqVO.type}
- </if>
- </where>
- </select>
- </mapper>
|