| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567 |
- <?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.iotopeationfill.IotOpeationFillMapper">
- <select id="getFillDevices"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select
- distinct
- c.id,
- c.dept_id,
- c.device_code,
- c.device_name,
- b.device_category_id,
- d.person_id user_id
- from
- rq_iot_model_template a,
- rq_iot_model_template_attrs b,
- rq_iot_device c,
- rq_iot_device_person d
- where
- a.device_category_id = b.device_category_id
- and
- a.device_category_id = c.asset_class
- and
- c.id = d.device_id
- and
- c.device_status in ('sg')
- and
- a.deleted = 0
- and
- c.deleted = 0
- and
- d.deleted = 0
- <if test="deviceIds != null and !deviceIds.isEmpty()">
- and c.id in
- <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- </select>
- <select id="getFillById" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select * from rq_iot_opeation_fill_order where id = #{id}
- </select>
- <select id="getFillDevices1"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- select
- distinct
- c.id,
- c.dept_id,
- c.device_code,
- c.device_name,
- b.device_category_id,
- d.person_id user_id,
- e.name dept_name,
- f.nickname,
- g.name,
- c.device_status
- from
- rq_iot_model_template a,
- rq_iot_model_template_attrs b,
- rq_iot_device c,
- rq_iot_device_person d,
- system_dept e,
- system_users f,
- rq_iot_product_classify g
- where
- a.device_category_id = b.device_category_id
- and
- a.device_category_id = c.asset_class
- and
- c.id = d.device_id
- and
- c.dept_id = e.id
- and
- d.person_id = f.id
- and
- a.device_category_id = g.id
- and
- c.device_status in ('sg','dm')
- and
- a.deleted = 0
- and
- c.deleted = 0
- and
- d.deleted = 0
- <if test="deviceIds != null and !deviceIds.isEmpty()">
- and e.id in
- <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- order by c.dept_id
- </select>
- <select id="getFillDevices2"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
- select
- distinct
- c.id,
- c.dept_id,
- c.device_code,
- c.device_name,
- b.device_category_id,
- d.person_id user_id,
- e.name dept_name,
- f.nickname,
- g.name,
- c.device_status
- from
- rq_iot_model_template a,
- rq_iot_model_template_attrs b,
- rq_iot_device c,
- rq_iot_device_person d,
- system_dept e,
- system_users f,
- rq_iot_product_classify g
- where
- a.device_category_id = b.device_category_id
- and
- a.device_category_id = c.asset_class
- and
- c.id = d.device_id
- and
- c.dept_id = e.id
- and
- d.person_id = f.id
- and
- a.device_category_id = g.id
- and
- c.device_status = 'sg'
- and
- a.deleted = 0
- and
- c.deleted = 0
- and
- d.deleted = 0
- <if test="deptIds != null and !deptIds.isEmpty()">
- and e.id in
- <foreach collection="deptIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- order by c.dept_id
- </select>
- <insert id="insertFill"
- parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- insert into rq_iot_opeation_fill(device_id,device_code,device_name,device_category_id,create_time,dept_id,order_id,is_report)
- values
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId},#{item.deviceCode},#{item.deviceName},
- #{item.deviceCategoryId},#{item.createTime},#{item.deptId},#{item.orderId},#{item.isReport})
- </foreach>
- </insert>
- <!-- <insert id="insertFillOrder"
- parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- insert into rq_iot_opeation_fill_order(dept_id,order_name,
- order_status,create_time,order_type,user_name,user_id)
- values
- <foreach collection="list" item="item" separator=",">
- (#{item.deptId},#{item.orderName},#{item.orderStatus},
- #{item.createTime},#{item.orderType},#{item.userName},#{item.userId})
- </foreach>
- </insert>-->
- <insert id="insertLog"
- parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- insert into rq_iot_device_run_log
- (dept_id,device_id,device_code,point_code,fill_content,create_time,point_name,total_run_time,is_sum)
- values
- <foreach collection="list" item="item" separator=",">
- (#{item.deptId},#{item.deviceId},#{item.deviceCode},
- #{item.pointCode},#{item.fillContent},#{item.createTime},#{item.pointName},#{item.totalRunTime},#{item.isSum})
- </foreach>
- </insert>
- <insert id="insertLog1"
- parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- insert into rq_iot_device_run_log
- (dept_id, device_id, device_code, point_code, fill_content, create_time, point_name, total_run_time,is_sum)
- values
- (#{deptId}, #{deviceId}, #{deviceCode},
- #{pointCode}, #{fillContent}, #{createTime}, #{pointName}, #{totalRunTime},#{isSum})
- </insert>
- <insert id="batchInsertLogs" parameterType="java.util.List">
- insert into rq_iot_device_run_log
- (dept_id, device_id, device_code, point_code, fill_content, create_time, point_name, total_run_time, is_sum)
- values
- <foreach collection="list" item="item" separator=",">
- (#{item.deptId}, #{item.deviceId}, #{item.deviceCode},
- #{item.pointCode}, #{item.fillContent}, #{item.createTime}, #{item.pointName}, #{item.totalRunTime}, #{item.isSum})
- </foreach>
- </insert>
- <update id="updateLog" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- update rq_iot_device_run_log
- set
- fill_content = #{fillContent}
- where
- device_id = #{deviceId}
- and
- point_name = #{pointName}
- and
- DATE(create_time) = #{createTime}
- and
- is_sum = 0
- </update>
- <update id="batchUpdateLogs" parameterType="java.util.List">
- update rq_iot_device_run_log
- set
- fill_content = CASE
- <foreach collection="list" item="item" separator="">
- WHEN device_id = #{item.deviceId}
- AND point_name = #{item.pointName}
- AND DATE(create_time) = #{item.createTime}
- AND is_sum = 0
- THEN #{item.fillContent}
- </foreach>
- ELSE fill_content <!-- 不满足条件的记录不更新 -->
- END
- where
- <!-- 只更新集合中存在的记录,避免全表扫描 -->
- (device_id, point_name, DATE(create_time), is_sum) IN (
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId}, #{item.pointName}, #{item.createTime}, 0)
- </foreach>
- )
- </update>
- <update id="updateSumLog" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- update rq_iot_device_run_log
- set
- total_run_time = #{totalRunTime}
- where
- device_id = #{deviceId}
- and
- point_name = #{pointName}
- and
- DATE(create_time) = #{createTime}
- and
- is_sum = 1
- </update>
- <update id="batchUpdateSumLogs" parameterType="java.util.List">
- update rq_iot_device_run_log
- set
- total_run_time = CASE
- <foreach collection="list" item="item" separator="">
- <!-- 匹配每条记录的唯一条件:device_id + point_name + 日期 + is_sum=1 -->
- WHEN device_id = #{item.deviceId}
- AND point_name = #{item.pointName}
- AND DATE(create_time) = #{item.createTime}
- AND is_sum = 1
- THEN #{item.totalRunTime} <!-- 赋值对应的总运行时间 -->
- </foreach>
- ELSE total_run_time <!-- 不匹配的记录保持原数值,不更新 -->
- END
- where
- <!-- 限定更新范围,避免全表扫描(仅更新集合中存在的记录) -->
- (device_id, point_name, DATE(create_time), is_sum) IN (
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId}, #{item.pointName}, #{item.createTime}, 1)
- </foreach>
- )
- </update>
- <!-- <select id="fillList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT * FROM
- rq_iot_opeation_fill
- WHERE DATE(create_time) = CURDATE()
- <if test="deptId != null and deptId != ''">
- and dept_id in (SELECT d1.id
- FROM system_dept d1
- JOIN system_dept d2 ON d2.id = d1.parent_id
- WHERE d2.parent_id = #{deptId}
- union
- select id from system_dept where id = #{deptId})
- </if>
- </select>-->
- <select id="fillList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT * FROM
- rq_iot_opeation_fill
- WHERE DATE(create_time) = CURDATE()
- <if test="userId != null and userId != ''">
- and device_id in (select device_id from
- rq_iot_device_person where person_id = #{userId})
- </if>
- </select>
- <select id="fills" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT * FROM
- rq_iot_opeation_fill
- WHERE 1=1
- <if test="deviceIds != null and !deviceIds.isEmpty()">
- and device_id in
- <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- </select>
- <update id="upFill" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- update rq_iot_opeation_fill set dept_id = #{deptId} where 1=1
- <if test="deviceIds != null and !deviceIds.isEmpty()">
- and device_id in
- <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- </update>
- <update id="upFill1" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillSaveReqVO">
- update rq_iot_opeation_fill_order
- set order_status = '3',
- reason = #{reason}
- where
- id = #{id}
- </update>
- <update id="upFill2" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillSaveReqVO">
- update rq_iot_opeation_fill
- set is_fill = '3'
- where
- order_id = #{id}
- </update>
- <select id="deviceList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select device_id from
- rq_iot_device_person where person_id = #{userId}
- </select>
- <select id="fillListByUserId" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT DISTINCT
- a.*,
- b.name org_name
- FROM
- rq_iot_opeation_fill a
- JOIN system_dept b ON a.dept_id = b.id
- JOIN rq_iot_model_template_attrs c ON a.device_category_id = c.device_category_id
- JOIN rq_iot_opeation_fill_order d ON a.order_id = d.id
- WHERE
- (
- 1=1
- <if test="orderId != null and orderId != ''">
- and a.order_id = #{orderId}
- </if>
- )
- ORDER BY
- CASE WHEN device_code IS NULL OR device_code = '' THEN 1 ELSE 0 END ASC,
- CAST(SUBSTRING(device_code, 3) AS UNSIGNED) ASC
- </select>
- <select id="fillListPage" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT DISTINCT
- a.*,
- b.name org_name
- FROM
- rq_iot_opeation_fill a
- JOIN system_dept b ON a.dept_id = b.id
- JOIN rq_iot_model_template_attrs c ON a.device_category_id = c.device_category_id
- JOIN rq_iot_opeation_fill_order d ON a.order_id = d.id
- WHERE
- (
- 1=1
- <if test="orderId != null and orderId != ''">
- and a.order_id = #{orderId}
- </if>
- )
- ORDER BY
- CASE WHEN device_code IS NULL OR device_code = '' THEN 1 ELSE 0 END ASC,
- CAST(SUBSTRING(device_code, 3) AS UNSIGNED) ASC
- </select>
- <select id="getOrderIds" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select
- distinct a.order_id
- from
- rq_iot_opeation_fill a,
- rq_iot_opeation_fill_order b
- where
- a.order_id = b.id
- and
- a.deleted = 0
- and
- b.deleted = 0
- and
- a.order_id is not null
- and(
- <if test="orgName != null and orgName != ''">
- (
- a.device_name LIKE CONCAT('%', #{orgName}, '%')
- OR a.device_code LIKE CONCAT('%', #{orgName}, '%')
- or b.user_name LIKE CONCAT('%', #{orgName}, '%')
- or b.order_name LIKE CONCAT('%', #{orgName}, '%')
- )
- </if>
- <if test="orgName == null or orgName == ''">
- 1=1
- </if>)
- </select>
- <select id="fillListByDeptId" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select
- distinct
- a.*,
- b.name org_name
- from
- rq_iot_opeation_fill a,
- system_dept b,
- rq_iot_model_template_attrs c
- where
- a.dept_id = b.id
- and
- a.device_category_id = c.device_category_id
- <if test="orderId != null and orderId != ''">
- and a.order_id = #{orderId}
- </if>
- <if test="deviceId != null and deviceId != ''">
- and a.device_id = #{deviceId}
- </if>
- </select>
- <select id="devListByOrderId" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT
- COUNT(*) AS allDev, -- 总数量
- SUM(CASE WHEN is_fill = 1 THEN 1 ELSE 0 END) AS fillDev, -- is_fill为1的数量
- SUM(CASE WHEN is_fill = 0 THEN 1 ELSE 0 END) AS unFillDev -- is_fill为0的数量
- FROM
- rq_iot_opeation_fill
- WHERE
- order_id = #{orderId}
- and
- dept_id IN (
- SELECT id FROM (
- SELECT d1.id FROM system_dept d1 WHERE d1.id = #{deptId}
- UNION ALL
- SELECT d2.id FROM system_dept d1 JOIN system_dept d2 ON d2.parent_id = d1.id WHERE d1.id = #{deptId}
- UNION ALL
- SELECT d3.id FROM system_dept d1 JOIN system_dept d2 ON d2.parent_id = d1.id JOIN system_dept d3 ON d3.parent_id = d2.id WHERE d1.id = #{deptId}
- UNION ALL
- SELECT d4.id FROM system_dept d1 JOIN system_dept d2 ON d2.parent_id = d1.id JOIN system_dept d3 ON d3.parent_id = d2.id JOIN system_dept d4 ON d4.parent_id = d3.id WHERE d1.id = #{deptId}
- ) AS dept_hierarchy
- )
- and device_name != '日报填报'
- </select>
- <!-- -->
- <select id="selectReportsByYear" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT *
- FROM rq_iot_opeation_fill
- WHERE is_report = 1
- <if test="deptId != null">
- AND dept_id = #{deptId}
- </if>
- AND YEAR(create_time) = #{year}
- </select>
- <select id="fillRecords" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
- SELECT a.*
- FROM rq_iot_opeation_fill_order a
- JOIN rq_iot_opeation_fill b ON a.id = b.order_id
- WHERE b.device_id = #{deviceId}
- <if test="orderName != null and orderName != ''">
- AND (a.order_name LIKE CONCAT('%', #{orderName}, '%')
- OR b.device_code LIKE CONCAT('%', #{orderName}, '%')
- OR b.device_name LIKE CONCAT('%', #{orderName}, '%'))
- </if>
- <if test="orderStatus != null">
- AND a.order_status = #{orderStatus}
- </if>
- ORDER BY a.create_time DESC
- </select>
- <select id="selectListByCreateTime" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
- SELECT a.id, a.create_time
- FROM rq_iot_opeation_fill_order a
- WHERE a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- <if test="deptIds != null and deptIds.size > 0">
- AND a.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- </select>
- <select id="countFills" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT a.*
- FROM rq_iot_opeation_fill a
- WHERE a.deleted = 0
- AND a.device_name = '生产日报'
- AND a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- <if test="deptIds != null and deptIds.size > 0">
- AND a.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- </select>
- <select id="rhList"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT au.id, au.name, au.parent_id
- FROM (SELECT * FROM system_dept WHERE parent_id IS NOT NULL) au,
- (SELECT @parent_id := '157') pd
- WHERE FIND_IN_SET(parent_id, @parent_id) > 0
- AND @parent_id := concat(@parent_id, ',', id)
- UNION
- SELECT id, name, parent_id
- FROM system_dept
- WHERE id = '157'
- ORDER BY id;
- </select>
- <select id="rdList"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT au.id, au.name, au.parent_id
- FROM (SELECT * FROM system_dept WHERE parent_id IS NOT NULL) au,
- (SELECT @parent_id := '163') pd
- WHERE FIND_IN_SET(parent_id, @parent_id) > 0
- AND @parent_id := concat(@parent_id, ',', id)
- UNION
- SELECT id, name, parent_id
- FROM system_dept
- WHERE id = '163'
- ORDER BY id;
- </select>
- <select id="ryList"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT au.id, au.name, au.parent_id
- FROM (SELECT * FROM system_dept WHERE parent_id IS NOT NULL) au,
- (SELECT @parent_id := '158') pd
- WHERE FIND_IN_SET(parent_id, @parent_id) > 0
- AND @parent_id := concat(@parent_id, ',', id)
- UNION
- SELECT id, name, parent_id
- FROM system_dept
- WHERE id = '158'
- ORDER BY id;
- </select>
- <select id="pdList1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT au.id, au.name, au.parent_id
- FROM (SELECT * FROM system_dept WHERE parent_id IS NOT NULL) au,
- (SELECT @parent_id := #{id}) pd
- WHERE FIND_IN_SET(parent_id, @parent_id) > 0
- AND @parent_id := concat(@parent_id, ',', id)
- UNION
- SELECT id, name, parent_id
- FROM system_dept
- WHERE id = #{id}
- ORDER BY id;
- </select>
- <select id="flList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT au.id, au.name, au.parent_id
- FROM (SELECT * FROM rq_iot_product_classify WHERE parent_id IS NOT NULL) au,
- (SELECT @parent_id := #{id}) pd
- WHERE FIND_IN_SET(parent_id, @parent_id) > 0
- AND @parent_id := concat(@parent_id, ',', id)
- UNION
- SELECT id, name, parent_id
- FROM rq_iot_product_classify
- WHERE id = #{id}
- ORDER BY id;
- </select>
- <select id="pdList" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select
- distinct
- b.id user_id,
- b.nickname user_name,
- c.id dept_id,
- b.mobile,
- c.name orgName
- from
- rq_iot_device_person a
- left join
- system_users b
- on
- a.person_id = b.id
- left join
- system_dept c
- on
- b.dept_id = c.id
- where b.id is not null
- <if test="deviceIds != null and !deviceIds.isEmpty()">
- and a.device_id in
- <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- </select>
- <select id="pdListRh" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select
- distinct
- b.id user_id,
- b.nickname user_name,
- c.id dept_id,
- b.mobile,
- c.name orgName
- from
- rq_iot_device_person a
- left join
- system_users b
- on
- a.person_id = b.id
- left join
- system_dept c
- on
- b.dept_id = c.id
- where b.id is not null
- <if test="deviceIds != null and !deviceIds.isEmpty()">
- and c.id in
- <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- </select>
- <select id="allOrder" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
- select distinct user_name
- from
- rq_iot_opeation_fill_order
- where
- DATE(create_time) = DATE(#{localDateTime})
- <if test="userNames != null and !userNames.isEmpty()">
- and user_name in
- <foreach collection="userNames" item="userName" open="(" separator="," close=")">
- #{userName}
- </foreach>
- </if>
- </select>
- <select id="pdList2" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select
- distinct
- b.id user_id,
- b.nickname user_name,
- c.id dept_id,
- b.mobile,
- c.name orgName
- from
- rq_iot_device_person a
- left join
- system_users b
- on
- a.person_id = b.id
- left join
- system_dept c
- on
- b.dept_id = c.id
- where
- b.id is not null
- and
- c.id is not null
- <if test="deviceIds != null and !deviceIds.isEmpty()">
- and c.id in
- <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- and
- a.person_id
- not in
- (select
- distinct
- d.person_id
- from
- rq_iot_model_template a,
- rq_iot_model_template_attrs b,
- rq_iot_device c,
- rq_iot_device_person d
- where
- a.device_category_id = b.device_category_id
- and
- a.device_category_id = c.asset_class
- and
- c.id = d.device_id
- and
- c.device_status in ('sg','dm')
- and
- a.deleted = 0
- and
- c.deleted = 0
- and
- d.deleted = 0)
- </select>
- <select id="fillList1" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT * FROM
- rq_iot_opeation_fill_order
- WHERE 1=1
- <if test="deptId != null and deptId != ''">
- and dept_id = #{deptId}
- </if>
- </select>
- <select id="getAttrsById" parameterType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO">
- select
- id,
- name,
- type,
- model_attr,
- is_sum,
- threshold,
- default_value,
- sum_id,
- description
- from
- rq_iot_model_template_attrs
- where
- device_category_id = #{deviceCategoryId} and deleted = 0
- </select>
- <!--
- 批量查询属性模板:入参为List<IotDeviceRespVO>(含多个deviceCategoryId)
- 出参:List<IotModelTemplateAttrsDO>(所有分类ID对应的属性模板,包含deviceCategoryId便于分组)
- -->
- <select id="getAttrsByIdBatch" parameterType="java.util.List"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO">
- SELECT
- id,
- name,
- type,
- model_attr,
- is_sum,
- threshold,
- default_value,
- sum_id,
- description,
- device_category_id
- FROM
- rq_iot_model_template_attrs
- WHERE
- -- 批量匹配多个deviceCategoryId,deleted=0条件不变
- device_category_id IN (
- <foreach collection="vos" item="item" separator="," open="" close="">
- #{item.deviceCategoryId}
- </foreach>
- )
- AND deleted = 0
- -- 按分类ID和属性名称排序,保持结果一致性
- ORDER BY
- device_category_id ASC, name ASC
- </select>
- <update id="updateFill" parameterType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotOpeationModelPageReqVO">
- update rq_iot_opeation_fill
- set is_fill = '1'
- where device_id = #{deviceId}
- and DATE(create_time) = DATE(#{createTime})
- </update>
- <!-- 推荐使用这个方案 -->
- <update id="batchUpdateFill" parameterType="java.util.List">
- UPDATE rq_iot_opeation_fill
- SET is_fill = '1'
- WHERE (device_id, DATE(create_time)) IN
- <foreach collection="list" item="item" open="(" separator="," close=")">
- (#{item.deviceId}, DATE(#{item.createTime}))
- </foreach>
- </update>
- <select id="getFillList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO">
- select distinct b.* from
- rq_iot_opeation_fill b,
- rq_iot_opeation_fill_order c
- where
- c.id = #{orderId}
- and
- b.dept_id = c.dept_id
- and
- b.order_id = c.id
- and
- DATE(b.create_time)=DATE(#{createTime})
- order by b.create_time desc
- </select>
- <select id="getDeivceFillInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- <!--SELECT * FROM rq_iot_device_run_log
- WHERE
- device_id = #{deviceId}
- and
- create_time = (SELECT MAX(create_time) FROM rq_iot_device_run_log WHERE
- device_id = #{deviceId})-->
- SELECT
- point_name,
- fill_content,
- (select max(total_run_time) from rq_iot_device_run_log where device_id = #{deviceId})total_run_time
- FROM rq_iot_device_run_log
- WHERE
- device_id = #{deviceId}
- and
- DATE(create_time) = DATE(#{createTime})
- order by id
- desc
- limit 1
- </select>
- <select id="getLogInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- SELECT
- *
- FROM rq_iot_device_run_log
- WHERE
- device_id = #{deviceId}
- and
- point_name = #{pointName}
- and
- DATE(create_time) = DATE(#{createTime})
- order by id
- desc
- limit 1
- </select>
- <select id="batchGetLogInfo" parameterType="java.util.List"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- SELECT
- *
- FROM rq_iot_device_run_log r
- WHERE-- 批量匹配多个 (device_id, point_name, DATE(create_time)) 三元组
- (r.device_id, r.point_name, DATE(r.create_time)) IN (
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId}, #{item.pointName}, DATE(#{item.createTime}))
- </foreach>
- )
- -- 确保每个条件只返回最新一条记录(按id降序,取最大id)
- AND r.id IN (
- SELECT MAX(id)
- FROM rq_iot_device_run_log
- WHERE (device_id, point_name, DATE(create_time)) IN (
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId}, #{item.pointName}, DATE(#{item.createTime}))
- </foreach>
- )
- GROUP BY device_id, point_name, DATE(create_time)
- )
- </select>
- <select id="getMaxFillInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- select max(total_run_time)total_run_time
- from rq_iot_device_run_log
- where
- device_id = #{deviceId}
- and
- point_name=#{pointName}
- </select>
- <!--<select id="batchGetMaxFillInfo" parameterType="java.util.List"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- select
- device_id,
- point_name,
- max(total_run_time)total_run_time
- from rq_iot_device_run_log
- where
- -- 批量匹配多个 (device_id, point_name) 组合
- (device_id, point_name) IN (
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId}, #{item.pointName})
- </foreach>
- )
- group by
- device_id
- </select>-->
- <select id="batchGetMaxFillInfo" parameterType="java.util.List"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- SELECT
- device_id,
- point_name,
- total_run_time -- 直接取最新记录的 total_run_time,无需 max()(最新数据已通过排序筛选)
- FROM (
- SELECT
- device_id,
- point_name,
- total_run_time,
- create_time, -- 表中的时间字段,替换为实际字段名(如 log_time/update_time)
- -- 按 (device_id, point_name) 分组,每组内按时间倒序排名
- ROW_NUMBER() OVER (
- PARTITION BY device_id, point_name
- ORDER BY create_time DESC -- 时间倒序:最新的排第1
- -- 可选:若同一时间有重复记录,加次要排序(如 id DESC)确保唯一
- -- ORDER BY create_time DESC, id DESC
- ) AS rn
- FROM rq_iot_device_run_log
- WHERE
- -- 批量匹配多个 (device_id, point_name) 组合(保留原 foreach 逻辑)
- (device_id, point_name) IN (
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId}, #{item.pointName})
- </foreach>
- )
- ) AS temp
- WHERE rn = 1; -- 只取每个组合的最新记录(排名第1)
- </select>
- <select id="devList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select device_id from rq_iot_opeation_fill where order_id = #{orderId}
- </select>
- <select id="orderList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select distinct order_id
- from
- rq_iot_opeation_fill
- where
- device_id = #{deviceId}
- and DATE(create_time) = #{creDate}
- and order_id != #{orderId}
- </select>
- <select id="delList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select * from rq_iot_opeation_fill where order_id = #{orderId}
- </select>
- <delete id="delRepeat" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- delete from rq_iot_opeation_fill where order_id = #{orderId}
- </delete>
- <delete id="delRepeatOrder" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- delete from rq_iot_opeation_fill_order where id = #{orderId}
- </delete>
- <update id="updateFillOrder" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- update rq_iot_opeation_fill_order set order_status = 1,update_time = NOW() where id = #{id}
- </update>
- <update id="updateFillOrder1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- update rq_iot_opeation_fill_order set order_status = 0 where id = #{id}
- </update>
- <update id="updateFillOrder2" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- update rq_iot_opeation_fill_order set order_status = 2,update_time = NOW() where id = #{id}
- </update>
- <select id="carList"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotZHBD.DeviceZHBDDO">
- select distinct device_code ,car_id from rq_iot_car_zhbd
- </select>
- <update id="upLocation"
- parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotZHBD.DeviceZHBDDO">
- update rq_iot_device set location= #{location} where device_code = #{deviceCode}
- </update>
- <select id="deviceCountList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicecountdata.IotDeviceCountData"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicecountdata.IotDeviceCountData">
- select
- distinct
- a.device_code,
- a.device_name,
- a.create_time,
- b.name dept_name,
- a.is_fill,
- d.nickname,
- e.order_name
- FROM rq_iot_opeation_fill a
- LEFT JOIN system_dept b
- ON a.dept_id = b.id
- AND b.deleted = 0 -- 将删除检查移至JOIN条件
- LEFT JOIN rq_iot_device_person c
- ON a.device_id = c.device_id
- AND c.deleted = 0 -- 将删除检查移至JOIN条件
- LEFT JOIN system_users d
- ON c.person_id = d.id
- AND d.deleted = 0 -- 将删除检查移至JOIN条件
- LEFT JOIN rq_iot_opeation_fill_order e
- ON a.order_id = e.id
- and e.deleted = 0
- WHERE a.deleted = 0
- and e.order_name is not null
- and a.device_name != '生产日报'
- AND b.id IN (
- SELECT id FROM system_dept WHERE id = #{deptId}
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id = #{deptId}
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId}))
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})))
- )
- <if test="isFill != null">
- and a.is_fill = #{isFill}
- </if>
- <if test="createTime != null and createTime.length > 0">
- <choose>
- <when test="createTime.length == 1">
- AND a.create_time = #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- </when>
- <otherwise>
- AND a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- </otherwise>
- </choose>
- </if>
- <if test="orderName != null and orderName != ''">
- AND (e.order_name LIKE CONCAT('%', #{orderName}, '%')
- OR a.device_code LIKE CONCAT('%', #{orderName}, '%')
- OR a.device_name LIKE CONCAT('%', #{orderName}, '%')
- OR d.nickname LIKE CONCAT('%', #{orderName}, '%'))
- </if>
- order by a.create_time desc,a.is_fill asc,b.name asc
- </select>
- <select id="countList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO">
- -- 统计指定部门及其子部门的工单状态
- SELECT
- dept_id,
- name,
- COALESCE(total_count, 0) AS total_count,
- COALESCE(filled_count, 0) AS filled_count,
- COALESCE(unfilled_count, 0) AS unfilled_count,
- COALESCE(filling_count, 0) AS filling_count,
- COALESCE(ignore_count, 0) AS ignore_count
- FROM (
- -- 第一行:汇总数据
- SELECT
- #{deptId} AS dept_id,
- (SELECT name FROM system_dept WHERE id = #{deptId}) AS name,
- COUNT(o.id) AS total_count,
- SUM(CASE WHEN o.order_status = 1 THEN 1 ELSE 0 END) AS filled_count,
- SUM(CASE WHEN o.order_status = 0 THEN 1 ELSE 0 END) AS unfilled_count,
- SUM(CASE WHEN o.order_status = 2 THEN 1 ELSE 0 END) AS filling_count,
- SUM(CASE WHEN o.order_status = 3 THEN 1 ELSE 0 END) AS ignore_count,
- 0 AS sort_order -- 确保汇总数据排在第一行
- FROM rq_iot_opeation_fill_order o
- WHERE o.deleted = 0
- <if test="createTime != null and createTime.length > 0">
- <choose>
- <when test="createTime.length == 1">
- AND o.create_time = #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- </when>
- <otherwise>
- AND o.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- </otherwise>
- </choose>
- </if>
- AND o.dept_id IN (
- SELECT id FROM system_dept WHERE id = #{deptId} -- 包含根部门自身
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id = #{deptId} -- 一级子部门
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId}) -- 二级子部门
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})) -- 三级子部门
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId}))) -- 四级子部门
- )
- UNION ALL
- -- 后续行:直接子部门数据
- SELECT
- d.id AS dept_id,
- d.name,
- COUNT(o.id) AS total_count,
- SUM(CASE WHEN o.order_status = 1 THEN 1 ELSE 0 END) AS filled_count,
- SUM(CASE WHEN o.order_status = 0 THEN 1 ELSE 0 END) AS unfilled_count,
- SUM(CASE WHEN o.order_status = 2 THEN 1 ELSE 0 END) AS filling_count,
- SUM(CASE WHEN o.order_status = 3 THEN 1 ELSE 0 END) AS ignore_count,
- 1 AS sort_order -- 子部门数据排在后面
- FROM system_dept d
- LEFT JOIN rq_iot_opeation_fill_order o
- ON o.deleted = 0
- <if test="createTime != null and createTime.length > 0">
- <choose>
- <when test="createTime.length == 1">
- AND o.create_time = #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- </when>
- <otherwise>
- AND o.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- </otherwise>
- </choose>
- </if>
- AND o.dept_id IN (
- SELECT id FROM system_dept WHERE id = d.id -- 子部门自身
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id = d.id -- 子部门的一级子部门
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = d.id) -- 子部门的二级子部门
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = d.id)) -- 子部门的三级子部门
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = d.id))) -- 子部门的四级子部门
- )
- WHERE d.parent_id = #{deptId} -- 只查询直接子部门
- AND d.deleted = 0 -- 排除已删除的部门
- GROUP BY d.id, d.name
- HAVING COUNT(o.id) > 0 -- 只显示有数据的部门
- ) t
- ORDER BY sort_order, dept_id;
- </select>
- <select id="countDeviceList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO">
- -- 统计指定部门及其子部门的工单状态
- -- 第一行:汇总数据
- SELECT
- COUNT(*) AS total_count,
- SUM(CASE WHEN is_fill = 1 THEN 1 ELSE 0 END) AS filled_count,
- SUM(CASE WHEN is_fill = 3 THEN 1 ELSE 0 END) AS ignore_count,
- COUNT(*) - SUM(CASE WHEN is_fill = 1 THEN 1 ELSE 0 END)-SUM(CASE WHEN is_fill = 3 THEN 1 ELSE 0 END) AS unfilled_count
- from(
- select
- distinct
- a.device_code,
- a.device_name,
- a.create_time,
- b.name dept_name,
- a.is_fill,
- d.nickname,
- e.order_name
- FROM rq_iot_opeation_fill a
- LEFT JOIN system_dept b
- ON a.dept_id = b.id
- AND b.deleted = 0 -- 将删除检查移至JOIN条件
- LEFT JOIN rq_iot_device_person c
- ON a.device_id = c.device_id
- AND c.deleted = 0 -- 将删除检查移至JOIN条件
- LEFT JOIN system_users d
- ON c.person_id = d.id
- AND d.deleted = 0 -- 将删除检查移至JOIN条件
- LEFT JOIN rq_iot_opeation_fill_order e
- ON a.order_id = e.id
- and e.deleted = 0
- WHERE a.deleted = 0
- and e.order_name is not null
- and a.device_name != '生产日报'
- AND b.id IN (
- SELECT id FROM system_dept WHERE id = #{deptId}
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id = #{deptId}
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM
- system_dept WHERE parent_id = #{deptId}))
- UNION ALL
- SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM
- system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})))
- )
- <if test="createTime != null and createTime.length > 0">
- <choose>
- <when test="createTime.length == 1">
- AND a.create_time = #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- </when>
- <otherwise>
- AND a.create_time BETWEEN
- #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND
- #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- </otherwise>
- </choose>
- </if>) a
- </select>
- <select id="childList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
- SELECT id dept_id
- FROM system_dept
- WHERE parent_id = #{deptId}
- AND deleted = 0
- </select>
- <select id="devStatus" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO">
- SELECT device_status
- FROM rq_iot_device
- WHERE dept_id = #{deptId}
- AND asset_class in (159,160,122,106,157,158,191)
- LIMIT 1
- </select>
- <select id="selectDevStatusBatch" parameterType="java.util.List"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO">
- SELECT
- dept_id, -- 建议返回部门ID,方便后续关联结果
- device_status
- FROM rq_iot_device
- WHERE dept_id IN
- <foreach collection="teams" item="item" open="(" separator="," close=")">
- #{item.id}
- </foreach>
- AND asset_class IN (159, 160, 122, 106, 157, 158, 191)
- AND device_status != 'sg'
- GROUP BY dept_id -- 确保每个部门只返回1条记录(若多个设备,取任意1条)
- -- 可选:如需指定返回某条设备(如最新/最早),可加排序:
- -- ORDER BY create_time DESC -- 按创建时间倒序(取最新)
- </select>
- <select id="isReport" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select * from
- rq_iot_opeation_fill
- where
- device_id = #{deviceId}
- and
- DATE(create_time) = DATE(#{createTime})
- LIMIT 1
- </select>
- <!--
- 批量查询isReport状态:入参为List<IotOpeationFillDO>(包含deviceId和createTime)
- 出参:List<IotOpeationFillDO>(每条记录对应一个deviceId+createTime组合的查询结果)
- -->
- <select id="batchGetIsReport" parameterType="java.util.List"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT
- t.device_id,
- COALESCE(t.is_report, 0) AS is_report
- FROM (
- -- 子查询:先过滤批量匹配的记录,再按设备+日期分组取最新1条
- SELECT
- *,
- -- 分组内排序:按create_time降序(最新的排第1)
- ROW_NUMBER() OVER (
- PARTITION BY device_id, DATE(create_time) -- 分组键:设备+日期
- ORDER BY create_time DESC -- 取数规则:最新的1条(可修改)
- ) AS rn
- FROM rq_iot_opeation_fill
- WHERE
- -- 批量匹配:(设备ID, 日期) 组合(与之前批量查询逻辑兼容)
- (device_id, DATE(create_time)) IN
- <foreach collection="list" item="item" separator="," open="(" close=")">
- (#{item.deviceId}, DATE(#{item.createTime}))
- </foreach>
- ) t
- WHERE t.rn = 1; -- 只保留每组第1条(即每个设备每天1条)
- </select>
- <select id="orderDO" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select
- order_id
- from
- rq_iot_opeation_fill
- where
- device_id = #{deviceId}
- and
- DATE(create_time) = #{createTime}
- </select>
- <select id="batchGetOrderDO" parameterType="java.util.List"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select
- order_id
- from(
- -- 内层查询:批量匹配条件 + 去重(同一 deviceId+日期 取最新记录)
- SELECT
- order_id
- FROM
- rq_iot_opeation_fill
- WHERE
- (device_id, DATE(create_time)) IN (
- <foreach collection="list" item="item" separator=",">
- -- 匹配入参中的 deviceId 和 日期(DATE(createTime) 与原逻辑一致)
- (#{item.deviceId}, DATE(#{item.createTime}))
- </foreach>
- )
- -- 去重逻辑:按 id 降序,确保每个分组取最新记录
- AND id IN (
- SELECT MAX(id) -- 取最新记录的 id
- FROM rq_iot_opeation_fill
- WHERE (device_id, DATE(create_time)) IN (
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId}, DATE(#{item.createTime}))
- </foreach>
- )
- GROUP BY device_id, DATE(create_time) -- 按 deviceId+日期 分组
- )
- ) AS iof
- </select>
- <select id="orderDO1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select
- order_id
- from
- rq_iot_opeation_fill
- where
- device_id = #{deviceId}
- and
- DATE(create_time) = CURDATE()
- </select>
- <select id="reportList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT DISTINCT
- a.device_id,
- a.device_code,
- a.device_name,
- a.create_time,
- b.name AS org_name
- FROM
- rq_iot_opeation_fill a
- INNER JOIN
- rq_iot_model_template_attrs b
- ON
- a.device_category_id = b.device_category_id
- WHERE
- a.order_id = #{orderId}
- AND (
- -- 第一个查询的条件
- (a.is_report = 1 AND b.daily_report = 0
- AND b.name NOT IN (
- SELECT
- DISTINCT
- b2.name
- FROM
- rq_iot_opeation_fill a2
- INNER JOIN
- rq_iot_model_template_attrs b2
- ON
- a2.device_category_id = b2.device_category_id
- WHERE
- a2.order_id = #{orderId}
- AND
- a2.is_report = 0
- AND
- b2.daily_report = 1
- ))
- -- 第二个查询的条件(通过OR代替UNION)
- OR (a.is_report is null AND b.daily_report = 1)
- )
- and a.device_code != ''
- </select>
- <select id="reportList1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT DISTINCT
- a.device_id,
- a.device_code,
- a.device_name,
- a.create_time,
- b.name AS org_name
- FROM
- rq_iot_opeation_fill a
- INNER JOIN
- rq_iot_model_template_attrs b
- ON
- a.device_category_id = b.device_category_id
- WHERE
- a.order_id = #{orderId}
- and
- a.is_report = 1
- </select>
- <select id="reportData" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- select * from
- rq_iot_device_run_log
- where
- device_id = #{deviceId}
- and
- point_name = #{pointName}
- and DATE(create_time) = DATE(#{createTime})
- </select>
- <!--
- 批量查询设备运行日志:入参为List<IotDeviceRunLogDO>(含deviceId、pointName、createTime)
- 出参:List<IotDeviceRunLogDO>(所有匹配条件的日志记录,结构与原单查一致)
- -->
- <select id="batchReportData" parameterType="java.util.List"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- SELECT
- *
- -- 如需其他字段,按原单查SQL补充(原SQL用select *,此处显式列出避免冗余)
- FROM
- rq_iot_device_run_log
- WHERE
- -- 批量匹配多个 (device_id, point_name, DATE(create_time)) 三元组条件
- (device_id, point_name, DATE(create_time)) IN (
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId}, #{item.pointName}, DATE(#{item.createTime}))
- </foreach>
- )
- -- 按创建时间降序,保持结果一致性(可选,与原单查行为对齐)
- ORDER BY
- create_time DESC
- </select>
- <select id="batchQueryExistingLogs" parameterType="java.util.List"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- select * from rq_iot_device_run_log
- where
- <!-- 多组条件组合:device_id + point_name + 日期 匹配 -->
- (device_id, point_name, DATE(create_time)) IN (
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceId}, #{item.pointName}, DATE(#{item.createTime}))
- </foreach>
- )
- </select>
- <select id="maxReportData" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- SELECT
- MAX(total_Run_Time) AS total_run_time
- FROM
- rq_iot_device_run_log
- WHERE
- device_id = #{deviceId}
- AND point_name = #{pointName}
- AND create_time < #{createTime}
- </select>
- <select id="batchQueryMaxReportData" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- SELECT t.device_id, t.point_name, MAX(t.total_run_time) as total_run_time
- FROM rq_iot_device_run_log t
- WHERE
- <foreach collection="list" item="item" separator="OR">
- (t.device_id = #{item.deviceId}
- AND t.point_name = #{item.pointName})
- </foreach>
- GROUP BY t.device_id, t.point_name
- </select>
- <select id="reportData1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- select * from
- rq_iot_device_run_log
- where
- device_id = #{deviceId}
- and
- point_name = #{pointName}
- and DATE(create_time) = DATE(#{createTime})
- </select>
- <select id="getDesc" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- select
- description point_name
- from
- rq_iot_model_template_attrs
- where
- name = #{pointName}
- and
- device_category_id =
- (select device_category_id from rq_iot_opeation_fill where device_id = #{deviceId} and DATE(create_time) = #{createTime})
- </select>
- <select id="batchGetDescByPointNames" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- <!-- 注意:请根据你的实际表名和字段名修改! -->
- <!-- 假设测点描述存储在 iot_device_run_log 表,核心字段:point_name(测点名)、point_desc(测点描述,可替换为你的实际字段) -->
- select
- description point_name
- from
- rq_iot_model_template_attrs
- WHERE
- 1 = 1
- <!-- 批量查询:用 IN 关键字,配合 foreach 遍历测点名集合 -->
- <if test="pointNameSet != null and pointNameSet.size() > 0">
- AND name IN
- <foreach collection="pointNameSet" item="pointName" open="(" separator="," close=")">
- #{pointName} <!-- 遍历 Set 中的每个测点名 -->
- </foreach>
- </if>
- <!-- 去重:避免同一测点名返回多条重复数据 -->
- GROUP BY
- point_name
- </select>
- <select id="getTeamType" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- select type as point_code from system_dept_type where dept_id = #{deptId}
- </select>
- <select id="getUserInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO">
- select * from system_users where dept_id = #{deptId} and nickname = '技术员'
- </select>
- <select id="getUserId" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
- select distinct a.person_id device_id from
- rq_iot_device_person a
- left join
- rq_iot_device b
- on a.device_id = b.id
- left join
- system_dept c
- on b.dept_id = c.id
- where c.id = #{deptId}
- limit 1
- </select>
-
- </mapper>
|