| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728 |
- <?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="getListByOrderId"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- select c.device_code ,c.device_name from rq_iot_opeation_fill c where c.deleted=0
- <if test="orderId != null and orderId != ''">
- and c.order_id = #{orderId}
- </if>
- </select>
- <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,
- a.id 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="selectRyFillReports" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT dr.id reportId, dr.task_id taskId, pt.well_name wellName
- FROM rq_iot_ry_daily_report dr
- LEFT JOIN rq_iot_project_task pt ON pt.id = dr.task_id
- WHERE dr.deleted = 0
- AND pt.deleted = 0
- <if test="deptId != null">
- AND dr.dept_id = #{deptId}
- </if>
- AND DATE(dr.create_time) = #{reportDateStr}
- LIMIT 1
- </select>
- <select id="selectRhFillReports" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT dr.task_id taskId, pt.well_name wellName
- FROM rq_iot_rh_daily_report dr
- LEFT JOIN rq_iot_project_task pt ON pt.id = dr.task_id
- WHERE dr.deleted = 0
- AND pt.deleted = 0
- <if test="deptId != null">
- AND dr.dept_id = #{deptId}
- </if>
- AND DATE(dr.create_time) = #{reportDateStr}
- LIMIT 1
- </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
- and c.type = '3'
- <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="selectList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
- SELECT * FROM rq_iot_opeation_fill
- <where>
- <if test="reqVO.deviceCode != null and reqVO.deviceCode != ''">
- AND device_code = #{reqVO.deviceCode}
- </if>
- <if test="reqVO.deviceName != null and reqVO.deviceName != ''">
- AND device_name LIKE CONCAT('%', #{reqVO.deviceName}, '%')
- </if>
- <if test="reqVO.deptId != null">
- AND dept_id = #{reqVO.deptId}
- </if>
- <if test="reqVO.deviceIds != null and reqVO.deviceIds.size() > 0">
- AND device_id IN
- <foreach collection="reqVO.deviceIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- <if test="reqVO.createTime != null and reqVO.createTime.length == 2">
- AND create_time BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
- </if>
- <if test="reqVO.createTimeStr != null and reqVO.createTimeStr != ''">
- AND DATE(create_time) = #{reqVO.createTimeStr}
- </if>
- </where>
- </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">
- WITH dept_with_sg AS (
- SELECT DISTINCT dept_id
- FROM rq_iot_device
- WHERE deleted = 0
- AND dept_id IN
- <foreach collection="teams" item="item" open="(" separator="," close=")">
- #{item.id}
- </foreach>
- AND asset_class IN (159, 160, 122, 106, 157, 158, 308, 108, 229)
- AND device_status = 'sg'
- )
- SELECT dept_id, device_status
- FROM (
- SELECT
- d.dept_id,
- d.device_status,
- ROW_NUMBER() OVER (
- PARTITION BY d.dept_id
- ORDER BY
- CASE d.asset_class
- WHEN 159 THEN 1 WHEN 160 THEN 1
- WHEN 122 THEN 2
- WHEN 157 THEN 3 WHEN 158 THEN 3
- WHEN 106 THEN 4
- WHEN 308 THEN 5
- WHEN 108 THEN 6
- WHEN 229 THEN 7
- END ASC
- ) AS rn
- FROM rq_iot_device d
- LEFT JOIN dept_with_sg e ON d.dept_id = e.dept_id
- WHERE d.deleted = 0
- AND d.dept_id IN
- <foreach collection="teams" item="item" open="(" separator="," close=")">
- #{item.id}
- </foreach>
- AND d.asset_class IN (159, 160, 122, 106, 157, 158, 308, 108, 229)
- AND d.device_status != 'sg'
- AND e.dept_id IS NULL
- ) t
- WHERE t.rn = 1;
- </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
- device_id,
- order_id
- from(
- -- 内层查询:批量匹配条件 + 去重(同一 deviceId+日期 取最新记录)
- SELECT
- device_id,
- 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="reportList2" 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)
- )
- </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>
- )
- AND device_code = ''
- -- 按创建时间降序,保持结果一致性(可选,与原单查行为对齐)
- 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>
- <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 order_status as status,count(order_status) as num from rq_iot_opeation_fill_order 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 order_status
- </select>
- </mapper>
|