IotOpeationFillMapper.xml 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillMapper">
  4. <select id="getListByOrderId"
  5. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  6. select c.device_code ,c.device_name from rq_iot_opeation_fill c where c.deleted=0
  7. <if test="orderId != null and orderId != ''">
  8. and c.order_id = #{orderId}
  9. </if>
  10. </select>
  11. <select id="getFillDevices"
  12. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  13. select
  14. distinct
  15. c.id,
  16. c.dept_id,
  17. c.device_code,
  18. c.device_name,
  19. b.device_category_id,
  20. d.person_id user_id
  21. from
  22. rq_iot_model_template a,
  23. rq_iot_model_template_attrs b,
  24. rq_iot_device c,
  25. rq_iot_device_person d
  26. where
  27. a.device_category_id = b.device_category_id
  28. and
  29. a.device_category_id = c.asset_class
  30. and
  31. c.id = d.device_id
  32. and
  33. c.device_status in ('sg')
  34. and
  35. a.deleted = 0
  36. and
  37. c.deleted = 0
  38. and
  39. d.deleted = 0
  40. <if test="deviceIds != null and !deviceIds.isEmpty()">
  41. and c.id in
  42. <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
  43. #{id}
  44. </foreach>
  45. </if>
  46. </select>
  47. <select id="getFillById" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  48. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  49. select * from rq_iot_opeation_fill_order where id = #{id}
  50. </select>
  51. <select id="getFillDevices1"
  52. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  53. select
  54. distinct
  55. c.id,
  56. c.dept_id,
  57. c.device_code,
  58. c.device_name,
  59. b.device_category_id,
  60. d.person_id user_id,
  61. e.name dept_name,
  62. f.nickname,
  63. g.name,
  64. c.device_status
  65. from
  66. rq_iot_model_template a,
  67. rq_iot_model_template_attrs b,
  68. rq_iot_device c,
  69. rq_iot_device_person d,
  70. system_dept e,
  71. system_users f,
  72. rq_iot_product_classify g
  73. where
  74. a.device_category_id = b.device_category_id
  75. and
  76. a.device_category_id = c.asset_class
  77. and
  78. c.id = d.device_id
  79. and
  80. c.dept_id = e.id
  81. and
  82. d.person_id = f.id
  83. and
  84. a.device_category_id = g.id
  85. and
  86. c.device_status in ('sg','dm')
  87. and
  88. a.deleted = 0
  89. and
  90. c.deleted = 0
  91. and
  92. d.deleted = 0
  93. <if test="deviceIds != null and !deviceIds.isEmpty()">
  94. and e.id in
  95. <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
  96. #{id}
  97. </foreach>
  98. </if>
  99. order by c.dept_id
  100. </select>
  101. <select id="getFillDevices2"
  102. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  103. select
  104. distinct
  105. c.id,
  106. c.dept_id,
  107. c.device_code,
  108. c.device_name,
  109. b.device_category_id,
  110. d.person_id user_id,
  111. e.name dept_name,
  112. f.nickname,
  113. g.name,
  114. c.device_status
  115. from
  116. rq_iot_model_template a,
  117. rq_iot_model_template_attrs b,
  118. rq_iot_device c,
  119. rq_iot_device_person d,
  120. system_dept e,
  121. system_users f,
  122. rq_iot_product_classify g
  123. where
  124. a.device_category_id = b.device_category_id
  125. and
  126. a.device_category_id = c.asset_class
  127. and
  128. c.id = d.device_id
  129. and
  130. c.dept_id = e.id
  131. and
  132. d.person_id = f.id
  133. and
  134. a.device_category_id = g.id
  135. and
  136. c.device_status = 'sg'
  137. and
  138. a.deleted = 0
  139. and
  140. c.deleted = 0
  141. and
  142. d.deleted = 0
  143. <if test="deptIds != null and !deptIds.isEmpty()">
  144. and e.id in
  145. <foreach collection="deptIds" item="id" open="(" separator="," close=")">
  146. #{id}
  147. </foreach>
  148. </if>
  149. order by c.dept_id
  150. </select>
  151. <insert id="insertFill"
  152. parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  153. insert into rq_iot_opeation_fill(device_id,device_code,device_name,device_category_id,create_time,dept_id,order_id,is_report)
  154. values
  155. <foreach collection="list" item="item" separator=",">
  156. (#{item.deviceId},#{item.deviceCode},#{item.deviceName},
  157. #{item.deviceCategoryId},#{item.createTime},#{item.deptId},#{item.orderId},#{item.isReport})
  158. </foreach>
  159. </insert>
  160. <!-- <insert id="insertFillOrder"
  161. parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  162. insert into rq_iot_opeation_fill_order(dept_id,order_name,
  163. order_status,create_time,order_type,user_name,user_id)
  164. values
  165. <foreach collection="list" item="item" separator=",">
  166. (#{item.deptId},#{item.orderName},#{item.orderStatus},
  167. #{item.createTime},#{item.orderType},#{item.userName},#{item.userId})
  168. </foreach>
  169. </insert>-->
  170. <insert id="insertLog"
  171. parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  172. insert into rq_iot_device_run_log
  173. (dept_id,device_id,device_code,point_code,fill_content,create_time,point_name,total_run_time,is_sum)
  174. values
  175. <foreach collection="list" item="item" separator=",">
  176. (#{item.deptId},#{item.deviceId},#{item.deviceCode},
  177. #{item.pointCode},#{item.fillContent},#{item.createTime},#{item.pointName},#{item.totalRunTime},#{item.isSum})
  178. </foreach>
  179. </insert>
  180. <insert id="insertLog1"
  181. parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  182. insert into rq_iot_device_run_log
  183. (dept_id, device_id, device_code, point_code, fill_content, create_time, point_name, total_run_time,is_sum)
  184. values
  185. (#{deptId}, #{deviceId}, #{deviceCode},
  186. #{pointCode}, #{fillContent}, #{createTime}, #{pointName}, #{totalRunTime},#{isSum})
  187. </insert>
  188. <insert id="batchInsertLogs" parameterType="java.util.List">
  189. insert into rq_iot_device_run_log
  190. (dept_id, device_id, device_code, point_code, fill_content, create_time, point_name, total_run_time, is_sum)
  191. values
  192. <foreach collection="list" item="item" separator=",">
  193. (#{item.deptId}, #{item.deviceId}, #{item.deviceCode},
  194. #{item.pointCode}, #{item.fillContent}, #{item.createTime}, #{item.pointName}, #{item.totalRunTime}, #{item.isSum})
  195. </foreach>
  196. </insert>
  197. <update id="updateLog" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  198. update rq_iot_device_run_log
  199. set
  200. fill_content = #{fillContent}
  201. where
  202. device_id = #{deviceId}
  203. and
  204. point_name = #{pointName}
  205. and
  206. DATE(create_time) = #{createTime}
  207. and
  208. is_sum = 0
  209. </update>
  210. <update id="batchUpdateLogs" parameterType="java.util.List">
  211. update rq_iot_device_run_log
  212. set
  213. fill_content = CASE
  214. <foreach collection="list" item="item" separator="">
  215. WHEN device_id = #{item.deviceId}
  216. AND point_name = #{item.pointName}
  217. AND DATE(create_time) = #{item.createTime}
  218. AND is_sum = 0
  219. THEN #{item.fillContent}
  220. </foreach>
  221. ELSE fill_content <!-- 不满足条件的记录不更新 -->
  222. END
  223. where
  224. <!-- 只更新集合中存在的记录,避免全表扫描 -->
  225. (device_id, point_name, DATE(create_time), is_sum) IN (
  226. <foreach collection="list" item="item" separator=",">
  227. (#{item.deviceId}, #{item.pointName}, #{item.createTime}, 0)
  228. </foreach>
  229. )
  230. </update>
  231. <update id="updateSumLog" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  232. update rq_iot_device_run_log
  233. set
  234. total_run_time = #{totalRunTime}
  235. where
  236. device_id = #{deviceId}
  237. and
  238. point_name = #{pointName}
  239. and
  240. DATE(create_time) = #{createTime}
  241. and
  242. is_sum = 1
  243. </update>
  244. <update id="batchUpdateSumLogs" parameterType="java.util.List">
  245. update rq_iot_device_run_log
  246. set
  247. total_run_time = CASE
  248. <foreach collection="list" item="item" separator="">
  249. <!-- 匹配每条记录的唯一条件:device_id + point_name + 日期 + is_sum=1 -->
  250. WHEN device_id = #{item.deviceId}
  251. AND point_name = #{item.pointName}
  252. AND DATE(create_time) = #{item.createTime}
  253. AND is_sum = 1
  254. THEN #{item.totalRunTime} <!-- 赋值对应的总运行时间 -->
  255. </foreach>
  256. ELSE total_run_time <!-- 不匹配的记录保持原数值,不更新 -->
  257. END
  258. where
  259. <!-- 限定更新范围,避免全表扫描(仅更新集合中存在的记录) -->
  260. (device_id, point_name, DATE(create_time), is_sum) IN (
  261. <foreach collection="list" item="item" separator=",">
  262. (#{item.deviceId}, #{item.pointName}, #{item.createTime}, 1)
  263. </foreach>
  264. )
  265. </update>
  266. <!-- <select id="fillList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  267. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  268. SELECT * FROM
  269. rq_iot_opeation_fill
  270. WHERE DATE(create_time) = CURDATE()
  271. <if test="deptId != null and deptId != ''">
  272. and dept_id in (SELECT d1.id
  273. FROM system_dept d1
  274. JOIN system_dept d2 ON d2.id = d1.parent_id
  275. WHERE d2.parent_id = #{deptId}
  276. union
  277. select id from system_dept where id = #{deptId})
  278. </if>
  279. </select>-->
  280. <select id="fillList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  281. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  282. SELECT * FROM
  283. rq_iot_opeation_fill
  284. WHERE DATE(create_time) = CURDATE()
  285. <if test="userId != null and userId != ''">
  286. and device_id in (select device_id from
  287. rq_iot_device_person where person_id = #{userId})
  288. </if>
  289. </select>
  290. <select id="fills" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  291. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  292. SELECT * FROM
  293. rq_iot_opeation_fill
  294. WHERE 1=1
  295. <if test="deviceIds != null and !deviceIds.isEmpty()">
  296. and device_id in
  297. <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
  298. #{id}
  299. </foreach>
  300. </if>
  301. </select>
  302. <update id="upFill" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  303. update rq_iot_opeation_fill set dept_id = #{deptId} where 1=1
  304. <if test="deviceIds != null and !deviceIds.isEmpty()">
  305. and device_id in
  306. <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
  307. #{id}
  308. </foreach>
  309. </if>
  310. </update>
  311. <update id="upFill1" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillSaveReqVO">
  312. update rq_iot_opeation_fill_order
  313. set order_status = '3',
  314. reason = #{reason}
  315. where
  316. id = #{id}
  317. </update>
  318. <update id="upFill2" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillSaveReqVO">
  319. update rq_iot_opeation_fill
  320. set is_fill = '3'
  321. where
  322. order_id = #{id}
  323. </update>
  324. <select id="deviceList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  325. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  326. select device_id from
  327. rq_iot_device_person where person_id = #{userId}
  328. </select>
  329. <select id="fillListByUserId" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  330. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  331. SELECT DISTINCT
  332. a.*,
  333. b.name org_name
  334. FROM
  335. rq_iot_opeation_fill a
  336. JOIN system_dept b ON a.dept_id = b.id
  337. JOIN rq_iot_model_template_attrs c ON a.device_category_id = c.device_category_id
  338. JOIN rq_iot_opeation_fill_order d ON a.order_id = d.id
  339. WHERE
  340. (
  341. 1=1
  342. <if test="orderId != null and orderId != ''">
  343. and a.order_id = #{orderId}
  344. </if>
  345. )
  346. ORDER BY
  347. CASE WHEN device_code IS NULL OR device_code = '' THEN 1 ELSE 0 END ASC,
  348. CAST(SUBSTRING(device_code, 3) AS UNSIGNED) ASC
  349. </select>
  350. <select id="fillListPage" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  351. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  352. SELECT DISTINCT
  353. a.*,
  354. b.name org_name
  355. FROM
  356. rq_iot_opeation_fill a
  357. JOIN system_dept b ON a.dept_id = b.id
  358. JOIN rq_iot_model_template_attrs c ON a.device_category_id = c.device_category_id
  359. JOIN rq_iot_opeation_fill_order d ON a.order_id = d.id
  360. WHERE
  361. (
  362. 1=1
  363. <if test="orderId != null and orderId != ''">
  364. and a.order_id = #{orderId}
  365. </if>
  366. )
  367. ORDER BY
  368. CASE WHEN device_code IS NULL OR device_code = '' THEN 1 ELSE 0 END ASC,
  369. CAST(SUBSTRING(device_code, 3) AS UNSIGNED) ASC,
  370. a.id ASC
  371. </select>
  372. <select id="getOrderIds" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  373. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  374. select
  375. distinct a.order_id
  376. from
  377. rq_iot_opeation_fill a,
  378. rq_iot_opeation_fill_order b
  379. where
  380. a.order_id = b.id
  381. and
  382. a.deleted = 0
  383. and
  384. b.deleted = 0
  385. and
  386. a.order_id is not null
  387. and(
  388. <if test="orgName != null and orgName != ''">
  389. (
  390. a.device_name LIKE CONCAT('%', #{orgName}, '%')
  391. OR a.device_code LIKE CONCAT('%', #{orgName}, '%')
  392. or b.user_name LIKE CONCAT('%', #{orgName}, '%')
  393. or b.order_name LIKE CONCAT('%', #{orgName}, '%')
  394. )
  395. </if>
  396. <if test="orgName == null or orgName == ''">
  397. 1=1
  398. </if>)
  399. </select>
  400. <select id="fillListByDeptId" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  401. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  402. select
  403. distinct
  404. a.*,
  405. b.name org_name
  406. from
  407. rq_iot_opeation_fill a,
  408. system_dept b,
  409. rq_iot_model_template_attrs c
  410. where
  411. a.dept_id = b.id
  412. and
  413. a.device_category_id = c.device_category_id
  414. <if test="orderId != null and orderId != ''">
  415. and a.order_id = #{orderId}
  416. </if>
  417. <if test="deviceId != null and deviceId != ''">
  418. and a.device_id = #{deviceId}
  419. </if>
  420. </select>
  421. <select id="devListByOrderId" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  422. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  423. SELECT
  424. COUNT(*) AS allDev, -- 总数量
  425. SUM(CASE WHEN is_fill = 1 THEN 1 ELSE 0 END) AS fillDev, -- is_fill为1的数量
  426. SUM(CASE WHEN is_fill = 0 THEN 1 ELSE 0 END) AS unFillDev -- is_fill为0的数量
  427. FROM
  428. rq_iot_opeation_fill
  429. WHERE
  430. order_id = #{orderId}
  431. and
  432. dept_id IN (
  433. SELECT id FROM (
  434. SELECT d1.id FROM system_dept d1 WHERE d1.id = #{deptId}
  435. UNION ALL
  436. SELECT d2.id FROM system_dept d1 JOIN system_dept d2 ON d2.parent_id = d1.id WHERE d1.id = #{deptId}
  437. UNION ALL
  438. 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}
  439. UNION ALL
  440. 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}
  441. ) AS dept_hierarchy
  442. )
  443. and device_name != '日报填报'
  444. </select>
  445. <!-- -->
  446. <select id="selectReportsByYear" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  447. SELECT *
  448. FROM rq_iot_opeation_fill
  449. WHERE is_report = 1
  450. <if test="deptId != null">
  451. AND dept_id = #{deptId}
  452. </if>
  453. AND YEAR(create_time) = #{year}
  454. </select>
  455. <select id="selectRyFillReports" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  456. SELECT dr.id reportId, dr.task_id taskId, pt.well_name wellName
  457. FROM rq_iot_ry_daily_report dr
  458. LEFT JOIN rq_iot_project_task pt ON pt.id = dr.task_id
  459. WHERE dr.deleted = 0
  460. AND pt.deleted = 0
  461. <if test="deptId != null">
  462. AND dr.dept_id = #{deptId}
  463. </if>
  464. AND DATE(dr.create_time) = #{reportDateStr}
  465. LIMIT 1
  466. </select>
  467. <select id="selectRhFillReports" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  468. SELECT dr.task_id taskId, pt.well_name wellName
  469. FROM rq_iot_rh_daily_report dr
  470. LEFT JOIN rq_iot_project_task pt ON pt.id = dr.task_id
  471. WHERE dr.deleted = 0
  472. AND pt.deleted = 0
  473. <if test="deptId != null">
  474. AND dr.dept_id = #{deptId}
  475. </if>
  476. AND DATE(dr.create_time) = #{reportDateStr}
  477. LIMIT 1
  478. </select>
  479. <select id="fillRecords" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO"
  480. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
  481. SELECT a.*
  482. FROM rq_iot_opeation_fill_order a
  483. JOIN rq_iot_opeation_fill b ON a.id = b.order_id
  484. WHERE b.device_id = #{deviceId}
  485. <if test="orderName != null and orderName != ''">
  486. AND (a.order_name LIKE CONCAT('%', #{orderName}, '%')
  487. OR b.device_code LIKE CONCAT('%', #{orderName}, '%')
  488. OR b.device_name LIKE CONCAT('%', #{orderName}, '%'))
  489. </if>
  490. <if test="orderStatus != null">
  491. AND a.order_status = #{orderStatus}
  492. </if>
  493. ORDER BY a.create_time DESC
  494. </select>
  495. <select id="selectListByCreateTime" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO"
  496. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
  497. SELECT a.id, a.create_time
  498. FROM rq_iot_opeation_fill_order a
  499. WHERE a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  500. <if test="deptIds != null and deptIds.size &gt; 0">
  501. AND a.dept_id IN
  502. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  503. #{key}
  504. </foreach>
  505. </if>
  506. </select>
  507. <select id="countFills" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO"
  508. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  509. SELECT a.*
  510. FROM rq_iot_opeation_fill a
  511. WHERE a.deleted = 0
  512. AND a.device_name = '生产日报'
  513. AND a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  514. AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  515. <if test="deptIds != null and deptIds.size &gt; 0">
  516. AND a.dept_id IN
  517. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  518. #{key}
  519. </foreach>
  520. </if>
  521. </select>
  522. <select id="rhList"
  523. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  524. SELECT au.id, au.name, au.parent_id
  525. FROM (SELECT * FROM system_dept WHERE parent_id IS NOT NULL) au,
  526. (SELECT @parent_id := '157') pd
  527. WHERE FIND_IN_SET(parent_id, @parent_id) > 0
  528. AND @parent_id := concat(@parent_id, ',', id)
  529. UNION
  530. SELECT id, name, parent_id
  531. FROM system_dept
  532. WHERE id = '157'
  533. ORDER BY id;
  534. </select>
  535. <select id="rdList"
  536. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  537. SELECT au.id, au.name, au.parent_id
  538. FROM (SELECT * FROM system_dept WHERE parent_id IS NOT NULL) au,
  539. (SELECT @parent_id := '163') pd
  540. WHERE FIND_IN_SET(parent_id, @parent_id) > 0
  541. AND @parent_id := concat(@parent_id, ',', id)
  542. UNION
  543. SELECT id, name, parent_id
  544. FROM system_dept
  545. WHERE id = '163'
  546. ORDER BY id;
  547. </select>
  548. <select id="ryList"
  549. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  550. SELECT au.id, au.name, au.parent_id
  551. FROM (SELECT * FROM system_dept WHERE parent_id IS NOT NULL) au,
  552. (SELECT @parent_id := '158') pd
  553. WHERE FIND_IN_SET(parent_id, @parent_id) > 0
  554. AND @parent_id := concat(@parent_id, ',', id)
  555. UNION
  556. SELECT id, name, parent_id
  557. FROM system_dept
  558. WHERE id = '158'
  559. ORDER BY id;
  560. </select>
  561. <select id="pdList1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  562. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  563. SELECT au.id, au.name, au.parent_id
  564. FROM (SELECT * FROM system_dept WHERE parent_id IS NOT NULL) au,
  565. (SELECT @parent_id := #{id}) pd
  566. WHERE FIND_IN_SET(parent_id, @parent_id) > 0
  567. AND @parent_id := concat(@parent_id, ',', id)
  568. UNION
  569. SELECT id, name, parent_id
  570. FROM system_dept
  571. WHERE id = #{id}
  572. ORDER BY id;
  573. </select>
  574. <select id="flList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  575. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  576. SELECT au.id, au.name, au.parent_id
  577. FROM (SELECT * FROM rq_iot_product_classify WHERE parent_id IS NOT NULL) au,
  578. (SELECT @parent_id := #{id}) pd
  579. WHERE FIND_IN_SET(parent_id, @parent_id) > 0
  580. AND @parent_id := concat(@parent_id, ',', id)
  581. UNION
  582. SELECT id, name, parent_id
  583. FROM rq_iot_product_classify
  584. WHERE id = #{id}
  585. ORDER BY id;
  586. </select>
  587. <select id="pdList" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  588. select
  589. distinct
  590. b.id user_id,
  591. b.nickname user_name,
  592. c.id dept_id,
  593. b.mobile,
  594. c.name orgName
  595. from
  596. rq_iot_device_person a
  597. left join
  598. system_users b
  599. on
  600. a.person_id = b.id
  601. left join
  602. system_dept c
  603. on
  604. b.dept_id = c.id
  605. where b.id is not null
  606. <if test="deviceIds != null and !deviceIds.isEmpty()">
  607. and a.device_id in
  608. <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
  609. #{id}
  610. </foreach>
  611. </if>
  612. </select>
  613. <select id="pdListRh" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  614. select
  615. distinct
  616. b.id user_id,
  617. b.nickname user_name,
  618. c.id dept_id,
  619. b.mobile,
  620. c.name orgName
  621. from
  622. rq_iot_device_person a
  623. left join
  624. system_users b
  625. on
  626. a.person_id = b.id
  627. left join
  628. system_dept c
  629. on
  630. b.dept_id = c.id
  631. where b.id is not null
  632. and c.type = '3'
  633. <if test="deviceIds != null and !deviceIds.isEmpty()">
  634. and c.id in
  635. <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
  636. #{id}
  637. </foreach>
  638. </if>
  639. </select>
  640. <select id="allOrder" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
  641. select distinct user_name
  642. from
  643. rq_iot_opeation_fill_order
  644. where
  645. DATE(create_time) = DATE(#{localDateTime})
  646. <if test="userNames != null and !userNames.isEmpty()">
  647. and user_name in
  648. <foreach collection="userNames" item="userName" open="(" separator="," close=")">
  649. #{userName}
  650. </foreach>
  651. </if>
  652. </select>
  653. <select id="pdList2" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  654. select
  655. distinct
  656. b.id user_id,
  657. b.nickname user_name,
  658. c.id dept_id,
  659. b.mobile,
  660. c.name orgName
  661. from
  662. rq_iot_device_person a
  663. left join
  664. system_users b
  665. on
  666. a.person_id = b.id
  667. left join
  668. system_dept c
  669. on
  670. b.dept_id = c.id
  671. where
  672. b.id is not null
  673. and
  674. c.id is not null
  675. <if test="deviceIds != null and !deviceIds.isEmpty()">
  676. and c.id in
  677. <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
  678. #{id}
  679. </foreach>
  680. </if>
  681. and
  682. a.person_id
  683. not in
  684. (select
  685. distinct
  686. d.person_id
  687. from
  688. rq_iot_model_template a,
  689. rq_iot_model_template_attrs b,
  690. rq_iot_device c,
  691. rq_iot_device_person d
  692. where
  693. a.device_category_id = b.device_category_id
  694. and
  695. a.device_category_id = c.asset_class
  696. and
  697. c.id = d.device_id
  698. and
  699. c.device_status in ('sg','dm')
  700. and
  701. a.deleted = 0
  702. and
  703. c.deleted = 0
  704. and
  705. d.deleted = 0)
  706. </select>
  707. <select id="fillList1" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  708. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  709. SELECT * FROM
  710. rq_iot_opeation_fill_order
  711. WHERE 1=1
  712. <if test="deptId != null and deptId != ''">
  713. and dept_id = #{deptId}
  714. </if>
  715. </select>
  716. <select id="selectList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO"
  717. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  718. SELECT * FROM rq_iot_opeation_fill
  719. <where>
  720. <if test="reqVO.deviceCode != null and reqVO.deviceCode != ''">
  721. AND device_code = #{reqVO.deviceCode}
  722. </if>
  723. <if test="reqVO.deviceName != null and reqVO.deviceName != ''">
  724. AND device_name LIKE CONCAT('%', #{reqVO.deviceName}, '%')
  725. </if>
  726. <if test="reqVO.deptId != null">
  727. AND dept_id = #{reqVO.deptId}
  728. </if>
  729. <if test="reqVO.deviceIds != null and reqVO.deviceIds.size() > 0">
  730. AND device_id IN
  731. <foreach collection="reqVO.deviceIds" item="id" open="(" separator="," close=")">
  732. #{id}
  733. </foreach>
  734. </if>
  735. <if test="reqVO.createTime != null and reqVO.createTime.length == 2">
  736. AND create_time BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
  737. </if>
  738. <if test="reqVO.createTimeStr != null and reqVO.createTimeStr != ''">
  739. AND DATE(create_time) = #{reqVO.createTimeStr}
  740. </if>
  741. </where>
  742. </select>
  743. <select id="getAttrsById" parameterType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO"
  744. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO">
  745. select
  746. id,
  747. name,
  748. type,
  749. model_attr,
  750. is_sum,
  751. threshold,
  752. default_value,
  753. sum_id,
  754. description
  755. from
  756. rq_iot_model_template_attrs
  757. where
  758. device_category_id = #{deviceCategoryId} and deleted = 0
  759. </select>
  760. <!--
  761. 批量查询属性模板:入参为List<IotDeviceRespVO>(含多个deviceCategoryId)
  762. 出参:List<IotModelTemplateAttrsDO>(所有分类ID对应的属性模板,包含deviceCategoryId便于分组)
  763. -->
  764. <select id="getAttrsByIdBatch" parameterType="java.util.List"
  765. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO">
  766. SELECT
  767. id,
  768. name,
  769. type,
  770. model_attr,
  771. is_sum,
  772. threshold,
  773. default_value,
  774. sum_id,
  775. description,
  776. device_category_id
  777. FROM
  778. rq_iot_model_template_attrs
  779. WHERE
  780. -- 批量匹配多个deviceCategoryId,deleted=0条件不变
  781. device_category_id IN (
  782. <foreach collection="vos" item="item" separator="," open="" close="">
  783. #{item.deviceCategoryId}
  784. </foreach>
  785. )
  786. AND deleted = 0
  787. -- 按分类ID和属性名称排序,保持结果一致性
  788. ORDER BY
  789. device_category_id ASC, name ASC
  790. </select>
  791. <update id="updateFill" parameterType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotOpeationModelPageReqVO">
  792. update rq_iot_opeation_fill
  793. set is_fill = '1'
  794. where device_id = #{deviceId}
  795. and DATE(create_time) = DATE(#{createTime})
  796. </update>
  797. <!-- 推荐使用这个方案 -->
  798. <update id="batchUpdateFill" parameterType="java.util.List">
  799. UPDATE rq_iot_opeation_fill
  800. SET is_fill = '1'
  801. WHERE (device_id, DATE(create_time)) IN
  802. <foreach collection="list" item="item" open="(" separator="," close=")">
  803. (#{item.deviceId}, DATE(#{item.createTime}))
  804. </foreach>
  805. </update>
  806. <select id="getFillList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
  807. resultType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO">
  808. select distinct b.* from
  809. rq_iot_opeation_fill b,
  810. rq_iot_opeation_fill_order c
  811. where
  812. c.id = #{orderId}
  813. and
  814. b.dept_id = c.dept_id
  815. and
  816. b.order_id = c.id
  817. and
  818. DATE(b.create_time)=DATE(#{createTime})
  819. order by b.create_time desc
  820. </select>
  821. <select id="getDeivceFillInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  822. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  823. <!--SELECT * FROM rq_iot_device_run_log
  824. WHERE
  825. device_id = #{deviceId}
  826. and
  827. create_time = (SELECT MAX(create_time) FROM rq_iot_device_run_log WHERE
  828. device_id = #{deviceId})-->
  829. SELECT
  830. point_name,
  831. fill_content,
  832. (select max(total_run_time) from rq_iot_device_run_log where device_id = #{deviceId})total_run_time
  833. FROM rq_iot_device_run_log
  834. WHERE
  835. device_id = #{deviceId}
  836. and
  837. DATE(create_time) = DATE(#{createTime})
  838. order by id
  839. desc
  840. limit 1
  841. </select>
  842. <select id="getLogInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  843. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  844. SELECT
  845. *
  846. FROM rq_iot_device_run_log
  847. WHERE
  848. device_id = #{deviceId}
  849. and
  850. point_name = #{pointName}
  851. and
  852. DATE(create_time) = DATE(#{createTime})
  853. order by id
  854. desc
  855. limit 1
  856. </select>
  857. <select id="batchGetLogInfo" parameterType="java.util.List"
  858. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  859. SELECT
  860. *
  861. FROM rq_iot_device_run_log r
  862. WHERE-- 批量匹配多个 (device_id, point_name, DATE(create_time)) 三元组
  863. (r.device_id, r.point_name, DATE(r.create_time)) IN (
  864. <foreach collection="list" item="item" separator=",">
  865. (#{item.deviceId}, #{item.pointName}, DATE(#{item.createTime}))
  866. </foreach>
  867. )
  868. -- 确保每个条件只返回最新一条记录(按id降序,取最大id)
  869. AND r.id IN (
  870. SELECT MAX(id)
  871. FROM rq_iot_device_run_log
  872. WHERE (device_id, point_name, DATE(create_time)) IN (
  873. <foreach collection="list" item="item" separator=",">
  874. (#{item.deviceId}, #{item.pointName}, DATE(#{item.createTime}))
  875. </foreach>
  876. )
  877. GROUP BY device_id, point_name, DATE(create_time)
  878. )
  879. </select>
  880. <select id="getMaxFillInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  881. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  882. select max(total_run_time)total_run_time
  883. from rq_iot_device_run_log
  884. where
  885. device_id = #{deviceId}
  886. and
  887. point_name=#{pointName}
  888. </select>
  889. <!--<select id="batchGetMaxFillInfo" parameterType="java.util.List"
  890. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  891. select
  892. device_id,
  893. point_name,
  894. max(total_run_time)total_run_time
  895. from rq_iot_device_run_log
  896. where
  897. &#45;&#45; 批量匹配多个 (device_id, point_name) 组合
  898. (device_id, point_name) IN (
  899. <foreach collection="list" item="item" separator=",">
  900. (#{item.deviceId}, #{item.pointName})
  901. </foreach>
  902. )
  903. group by
  904. device_id
  905. </select>-->
  906. <select id="batchGetMaxFillInfo" parameterType="java.util.List"
  907. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  908. SELECT
  909. device_id,
  910. point_name,
  911. total_run_time -- 直接取最新记录的 total_run_time,无需 max()(最新数据已通过排序筛选)
  912. FROM (
  913. SELECT
  914. device_id,
  915. point_name,
  916. total_run_time,
  917. create_time, -- 表中的时间字段,替换为实际字段名(如 log_time/update_time)
  918. -- 按 (device_id, point_name) 分组,每组内按时间倒序排名
  919. ROW_NUMBER() OVER (
  920. PARTITION BY device_id, point_name
  921. ORDER BY create_time DESC -- 时间倒序:最新的排第1
  922. -- 可选:若同一时间有重复记录,加次要排序(如 id DESC)确保唯一
  923. -- ORDER BY create_time DESC, id DESC
  924. ) AS rn
  925. FROM rq_iot_device_run_log
  926. WHERE
  927. -- 批量匹配多个 (device_id, point_name) 组合(保留原 foreach 逻辑)
  928. (device_id, point_name) IN (
  929. <foreach collection="list" item="item" separator=",">
  930. (#{item.deviceId}, #{item.pointName})
  931. </foreach>
  932. )
  933. ) AS temp
  934. WHERE rn = 1; -- 只取每个组合的最新记录(排名第1)
  935. </select>
  936. <select id="devList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  937. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  938. select device_id from rq_iot_opeation_fill where order_id = #{orderId}
  939. </select>
  940. <select id="orderList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  941. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  942. select distinct order_id
  943. from
  944. rq_iot_opeation_fill
  945. where
  946. device_id = #{deviceId}
  947. and DATE(create_time) = #{creDate}
  948. and order_id != #{orderId}
  949. </select>
  950. <select id="delList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  951. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  952. select * from rq_iot_opeation_fill where order_id = #{orderId}
  953. </select>
  954. <delete id="delRepeat" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  955. delete from rq_iot_opeation_fill where order_id = #{orderId}
  956. </delete>
  957. <delete id="delRepeatOrder" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  958. delete from rq_iot_opeation_fill_order where id = #{orderId}
  959. </delete>
  960. <update id="updateFillOrder" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  961. update rq_iot_opeation_fill_order set order_status = 1,update_time = NOW() where id = #{id}
  962. </update>
  963. <update id="updateFillOrder1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  964. update rq_iot_opeation_fill_order set order_status = 0 where id = #{id}
  965. </update>
  966. <update id="updateFillOrder2" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  967. update rq_iot_opeation_fill_order set order_status = 2,update_time = NOW() where id = #{id}
  968. </update>
  969. <select id="carList"
  970. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotZHBD.DeviceZHBDDO">
  971. select distinct device_code ,car_id from rq_iot_car_zhbd
  972. </select>
  973. <update id="upLocation"
  974. parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotZHBD.DeviceZHBDDO">
  975. update rq_iot_device set location= #{location} where device_code = #{deviceCode}
  976. </update>
  977. <select id="deviceCountList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicecountdata.IotDeviceCountData"
  978. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicecountdata.IotDeviceCountData">
  979. select
  980. distinct
  981. a.device_code,
  982. a.device_name,
  983. a.create_time,
  984. b.name dept_name,
  985. a.is_fill,
  986. d.nickname,
  987. e.order_name
  988. FROM rq_iot_opeation_fill a
  989. LEFT JOIN system_dept b
  990. ON a.dept_id = b.id
  991. AND b.deleted = 0 -- 将删除检查移至JOIN条件
  992. LEFT JOIN rq_iot_device_person c
  993. ON a.device_id = c.device_id
  994. AND c.deleted = 0 -- 将删除检查移至JOIN条件
  995. LEFT JOIN system_users d
  996. ON c.person_id = d.id
  997. AND d.deleted = 0 -- 将删除检查移至JOIN条件
  998. LEFT JOIN rq_iot_opeation_fill_order e
  999. ON a.order_id = e.id
  1000. and e.deleted = 0
  1001. WHERE a.deleted = 0
  1002. and e.order_name is not null
  1003. and a.device_name != '生产日报'
  1004. AND b.id IN (
  1005. SELECT id FROM system_dept WHERE id = #{deptId}
  1006. UNION ALL
  1007. SELECT id FROM system_dept WHERE parent_id = #{deptId}
  1008. UNION ALL
  1009. SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})
  1010. UNION ALL
  1011. 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}))
  1012. UNION ALL
  1013. 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})))
  1014. )
  1015. <if test="isFill != null">
  1016. and a.is_fill = #{isFill}
  1017. </if>
  1018. <if test="createTime != null and createTime.length > 0">
  1019. <choose>
  1020. <when test="createTime.length == 1">
  1021. AND a.create_time = #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  1022. </when>
  1023. <otherwise>
  1024. AND a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  1025. </otherwise>
  1026. </choose>
  1027. </if>
  1028. <if test="orderName != null and orderName != ''">
  1029. AND (e.order_name LIKE CONCAT('%', #{orderName}, '%')
  1030. OR a.device_code LIKE CONCAT('%', #{orderName}, '%')
  1031. OR a.device_name LIKE CONCAT('%', #{orderName}, '%')
  1032. OR d.nickname LIKE CONCAT('%', #{orderName}, '%'))
  1033. </if>
  1034. order by a.create_time desc,a.is_fill asc,b.name asc
  1035. </select>
  1036. <select id="countList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO"
  1037. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO">
  1038. -- 统计指定部门及其子部门的工单状态
  1039. SELECT
  1040. dept_id,
  1041. name,
  1042. COALESCE(total_count, 0) AS total_count,
  1043. COALESCE(filled_count, 0) AS filled_count,
  1044. COALESCE(unfilled_count, 0) AS unfilled_count,
  1045. COALESCE(filling_count, 0) AS filling_count,
  1046. COALESCE(ignore_count, 0) AS ignore_count
  1047. FROM (
  1048. -- 第一行:汇总数据
  1049. SELECT
  1050. #{deptId} AS dept_id,
  1051. (SELECT name FROM system_dept WHERE id = #{deptId}) AS name,
  1052. COUNT(o.id) AS total_count,
  1053. SUM(CASE WHEN o.order_status = 1 THEN 1 ELSE 0 END) AS filled_count,
  1054. SUM(CASE WHEN o.order_status = 0 THEN 1 ELSE 0 END) AS unfilled_count,
  1055. SUM(CASE WHEN o.order_status = 2 THEN 1 ELSE 0 END) AS filling_count,
  1056. SUM(CASE WHEN o.order_status = 3 THEN 1 ELSE 0 END) AS ignore_count,
  1057. 0 AS sort_order -- 确保汇总数据排在第一行
  1058. FROM rq_iot_opeation_fill_order o
  1059. WHERE o.deleted = 0
  1060. <if test="createTime != null and createTime.length > 0">
  1061. <choose>
  1062. <when test="createTime.length == 1">
  1063. AND o.create_time = #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  1064. </when>
  1065. <otherwise>
  1066. AND o.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  1067. </otherwise>
  1068. </choose>
  1069. </if>
  1070. AND o.dept_id IN (
  1071. SELECT id FROM system_dept WHERE id = #{deptId} -- 包含根部门自身
  1072. UNION ALL
  1073. SELECT id FROM system_dept WHERE parent_id = #{deptId} -- 一级子部门
  1074. UNION ALL
  1075. SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId}) -- 二级子部门
  1076. UNION ALL
  1077. 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})) -- 三级子部门
  1078. UNION ALL
  1079. 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}))) -- 四级子部门
  1080. )
  1081. UNION ALL
  1082. -- 后续行:直接子部门数据
  1083. SELECT
  1084. d.id AS dept_id,
  1085. d.name,
  1086. COUNT(o.id) AS total_count,
  1087. SUM(CASE WHEN o.order_status = 1 THEN 1 ELSE 0 END) AS filled_count,
  1088. SUM(CASE WHEN o.order_status = 0 THEN 1 ELSE 0 END) AS unfilled_count,
  1089. SUM(CASE WHEN o.order_status = 2 THEN 1 ELSE 0 END) AS filling_count,
  1090. SUM(CASE WHEN o.order_status = 3 THEN 1 ELSE 0 END) AS ignore_count,
  1091. 1 AS sort_order -- 子部门数据排在后面
  1092. FROM system_dept d
  1093. LEFT JOIN rq_iot_opeation_fill_order o
  1094. ON o.deleted = 0
  1095. <if test="createTime != null and createTime.length > 0">
  1096. <choose>
  1097. <when test="createTime.length == 1">
  1098. AND o.create_time = #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  1099. </when>
  1100. <otherwise>
  1101. AND o.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  1102. </otherwise>
  1103. </choose>
  1104. </if>
  1105. AND o.dept_id IN (
  1106. SELECT id FROM system_dept WHERE id = d.id -- 子部门自身
  1107. UNION ALL
  1108. SELECT id FROM system_dept WHERE parent_id = d.id -- 子部门的一级子部门
  1109. UNION ALL
  1110. SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = d.id) -- 子部门的二级子部门
  1111. UNION ALL
  1112. 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)) -- 子部门的三级子部门
  1113. UNION ALL
  1114. 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))) -- 子部门的四级子部门
  1115. )
  1116. WHERE d.parent_id = #{deptId} -- 只查询直接子部门
  1117. AND d.deleted = 0 -- 排除已删除的部门
  1118. GROUP BY d.id, d.name
  1119. HAVING COUNT(o.id) > 0 -- 只显示有数据的部门
  1120. ) t
  1121. ORDER BY sort_order, dept_id;
  1122. </select>
  1123. <select id="countDeviceList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO"
  1124. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO">
  1125. -- 统计指定部门及其子部门的工单状态
  1126. -- 第一行:汇总数据
  1127. SELECT
  1128. COUNT(*) AS total_count,
  1129. SUM(CASE WHEN is_fill = 1 THEN 1 ELSE 0 END) AS filled_count,
  1130. SUM(CASE WHEN is_fill = 3 THEN 1 ELSE 0 END) AS ignore_count,
  1131. 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
  1132. from(
  1133. select
  1134. distinct
  1135. a.device_code,
  1136. a.device_name,
  1137. a.create_time,
  1138. b.name dept_name,
  1139. a.is_fill,
  1140. d.nickname,
  1141. e.order_name
  1142. FROM rq_iot_opeation_fill a
  1143. LEFT JOIN system_dept b
  1144. ON a.dept_id = b.id
  1145. AND b.deleted = 0 -- 将删除检查移至JOIN条件
  1146. LEFT JOIN rq_iot_device_person c
  1147. ON a.device_id = c.device_id
  1148. AND c.deleted = 0 -- 将删除检查移至JOIN条件
  1149. LEFT JOIN system_users d
  1150. ON c.person_id = d.id
  1151. AND d.deleted = 0 -- 将删除检查移至JOIN条件
  1152. LEFT JOIN rq_iot_opeation_fill_order e
  1153. ON a.order_id = e.id
  1154. and e.deleted = 0
  1155. WHERE a.deleted = 0
  1156. and e.order_name is not null
  1157. and a.device_name != '生产日报'
  1158. AND b.id IN (
  1159. SELECT id FROM system_dept WHERE id = #{deptId}
  1160. UNION ALL
  1161. SELECT id FROM system_dept WHERE parent_id = #{deptId}
  1162. UNION ALL
  1163. SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})
  1164. UNION ALL
  1165. SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM
  1166. system_dept WHERE parent_id = #{deptId}))
  1167. UNION ALL
  1168. SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM
  1169. system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})))
  1170. )
  1171. <if test="createTime != null and createTime.length > 0">
  1172. <choose>
  1173. <when test="createTime.length == 1">
  1174. AND a.create_time = #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  1175. </when>
  1176. <otherwise>
  1177. AND a.create_time BETWEEN
  1178. #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND
  1179. #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  1180. </otherwise>
  1181. </choose>
  1182. </if>) a
  1183. </select>
  1184. <select id="childList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO"
  1185. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
  1186. SELECT id dept_id
  1187. FROM system_dept
  1188. WHERE parent_id = #{deptId}
  1189. AND deleted = 0
  1190. </select>
  1191. <select id="devStatus" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO"
  1192. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO">
  1193. SELECT device_status
  1194. FROM rq_iot_device
  1195. WHERE dept_id = #{deptId}
  1196. AND asset_class in (159,160,122,106,157,158,191)
  1197. LIMIT 1
  1198. </select>
  1199. <select id="selectDevStatusBatch" parameterType="java.util.List"
  1200. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO">
  1201. WITH dept_with_sg AS (
  1202. SELECT DISTINCT dept_id
  1203. FROM rq_iot_device
  1204. WHERE deleted = 0
  1205. AND dept_id IN
  1206. <foreach collection="teams" item="item" open="(" separator="," close=")">
  1207. #{item.id}
  1208. </foreach>
  1209. AND asset_class IN (159, 160, 122, 106, 157, 158, 308, 108, 229)
  1210. AND device_status = 'sg'
  1211. )
  1212. SELECT dept_id, device_status
  1213. FROM (
  1214. SELECT
  1215. d.dept_id,
  1216. d.device_status,
  1217. ROW_NUMBER() OVER (
  1218. PARTITION BY d.dept_id
  1219. ORDER BY
  1220. CASE d.asset_class
  1221. WHEN 159 THEN 1 WHEN 160 THEN 1
  1222. WHEN 122 THEN 2
  1223. WHEN 157 THEN 3 WHEN 158 THEN 3
  1224. WHEN 106 THEN 4
  1225. WHEN 308 THEN 5
  1226. WHEN 108 THEN 6
  1227. WHEN 229 THEN 7
  1228. END ASC
  1229. ) AS rn
  1230. FROM rq_iot_device d
  1231. LEFT JOIN dept_with_sg e ON d.dept_id = e.dept_id
  1232. WHERE d.deleted = 0
  1233. AND d.dept_id IN
  1234. <foreach collection="teams" item="item" open="(" separator="," close=")">
  1235. #{item.id}
  1236. </foreach>
  1237. AND d.asset_class IN (159, 160, 122, 106, 157, 158, 308, 108, 229)
  1238. AND d.device_status != 'sg'
  1239. AND e.dept_id IS NULL
  1240. ) t
  1241. WHERE t.rn = 1;
  1242. </select>
  1243. <select id="isReport" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  1244. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  1245. select * from
  1246. rq_iot_opeation_fill
  1247. where
  1248. device_id = #{deviceId}
  1249. and
  1250. DATE(create_time) = DATE(#{createTime})
  1251. LIMIT 1
  1252. </select>
  1253. <!--
  1254. 批量查询isReport状态:入参为List<IotOpeationFillDO>(包含deviceId和createTime)
  1255. 出参:List<IotOpeationFillDO>(每条记录对应一个deviceId+createTime组合的查询结果)
  1256. -->
  1257. <select id="batchGetIsReport" parameterType="java.util.List"
  1258. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  1259. SELECT
  1260. t.device_id,
  1261. COALESCE(t.is_report, 0) AS is_report
  1262. FROM (
  1263. -- 子查询:先过滤批量匹配的记录,再按设备+日期分组取最新1条
  1264. SELECT
  1265. *,
  1266. -- 分组内排序:按create_time降序(最新的排第1)
  1267. ROW_NUMBER() OVER (
  1268. PARTITION BY device_id, DATE(create_time) -- 分组键:设备+日期
  1269. ORDER BY create_time DESC -- 取数规则:最新的1条(可修改)
  1270. ) AS rn
  1271. FROM rq_iot_opeation_fill
  1272. WHERE
  1273. -- 批量匹配:(设备ID, 日期) 组合(与之前批量查询逻辑兼容)
  1274. (device_id, DATE(create_time)) IN
  1275. <foreach collection="list" item="item" separator="," open="(" close=")">
  1276. (#{item.deviceId}, DATE(#{item.createTime}))
  1277. </foreach>
  1278. ) t
  1279. WHERE t.rn = 1; -- 只保留每组第1条(即每个设备每天1条)
  1280. </select>
  1281. <select id="orderDO" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  1282. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  1283. select
  1284. order_id
  1285. from
  1286. rq_iot_opeation_fill
  1287. where
  1288. device_id = #{deviceId}
  1289. and
  1290. DATE(create_time) = #{createTime}
  1291. </select>
  1292. <select id="batchGetOrderDO" parameterType="java.util.List"
  1293. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  1294. select
  1295. device_id,
  1296. order_id
  1297. from(
  1298. -- 内层查询:批量匹配条件 + 去重(同一 deviceId+日期 取最新记录)
  1299. SELECT
  1300. device_id,
  1301. order_id
  1302. FROM
  1303. rq_iot_opeation_fill
  1304. WHERE
  1305. (device_id, DATE(create_time)) IN (
  1306. <foreach collection="list" item="item" separator=",">
  1307. -- 匹配入参中的 deviceId 和 日期(DATE(createTime) 与原逻辑一致)
  1308. (#{item.deviceId}, DATE(#{item.createTime}))
  1309. </foreach>
  1310. )
  1311. -- 去重逻辑:按 id 降序,确保每个分组取最新记录
  1312. AND id IN (
  1313. SELECT MAX(id) -- 取最新记录的 id
  1314. FROM rq_iot_opeation_fill
  1315. WHERE (device_id, DATE(create_time)) IN (
  1316. <foreach collection="list" item="item" separator=",">
  1317. (#{item.deviceId}, DATE(#{item.createTime}))
  1318. </foreach>
  1319. )
  1320. GROUP BY device_id, DATE(create_time) -- 按 deviceId+日期 分组
  1321. )
  1322. ) AS iof
  1323. </select>
  1324. <select id="orderDO1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  1325. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  1326. select
  1327. order_id
  1328. from
  1329. rq_iot_opeation_fill
  1330. where
  1331. device_id = #{deviceId}
  1332. and
  1333. DATE(create_time) = CURDATE()
  1334. </select>
  1335. <select id="reportList" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  1336. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  1337. SELECT DISTINCT
  1338. a.device_id,
  1339. a.device_code,
  1340. a.device_name,
  1341. a.create_time,
  1342. b.name AS org_name
  1343. FROM
  1344. rq_iot_opeation_fill a
  1345. INNER JOIN
  1346. rq_iot_model_template_attrs b
  1347. ON
  1348. a.device_category_id = b.device_category_id
  1349. WHERE
  1350. a.order_id = #{orderId}
  1351. AND (
  1352. -- 第一个查询的条件
  1353. (a.is_report = 1 AND b.daily_report = 0
  1354. AND b.name NOT IN (
  1355. SELECT
  1356. DISTINCT
  1357. b2.name
  1358. FROM
  1359. rq_iot_opeation_fill a2
  1360. INNER JOIN
  1361. rq_iot_model_template_attrs b2
  1362. ON
  1363. a2.device_category_id = b2.device_category_id
  1364. WHERE
  1365. a2.order_id = #{orderId}
  1366. AND
  1367. a2.is_report = 0
  1368. AND
  1369. b2.daily_report = 1
  1370. ))
  1371. -- 第二个查询的条件(通过OR代替UNION)
  1372. OR (a.is_report is null AND b.daily_report = 1)
  1373. )
  1374. and a.device_code != ''
  1375. </select>
  1376. <select id="reportList2" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  1377. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  1378. SELECT DISTINCT
  1379. a.device_id,
  1380. a.device_code,
  1381. a.device_name,
  1382. a.create_time,
  1383. b.name AS org_name
  1384. FROM
  1385. rq_iot_opeation_fill a
  1386. INNER JOIN
  1387. rq_iot_model_template_attrs b
  1388. ON
  1389. a.device_category_id = b.device_category_id
  1390. WHERE
  1391. a.order_id = #{orderId}
  1392. AND (
  1393. -- 第一个查询的条件
  1394. (a.is_report = 1 AND b.daily_report = 0
  1395. AND b.name NOT IN (
  1396. SELECT
  1397. DISTINCT
  1398. b2.name
  1399. FROM
  1400. rq_iot_opeation_fill a2
  1401. INNER JOIN
  1402. rq_iot_model_template_attrs b2
  1403. ON
  1404. a2.device_category_id = b2.device_category_id
  1405. WHERE
  1406. a2.order_id = #{orderId}
  1407. AND
  1408. a2.is_report = 0
  1409. AND
  1410. b2.daily_report = 1
  1411. ))
  1412. -- 第二个查询的条件(通过OR代替UNION)
  1413. OR (a.is_report is null AND b.daily_report = 1)
  1414. )
  1415. </select>
  1416. <select id="reportList1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
  1417. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
  1418. SELECT DISTINCT
  1419. a.device_id,
  1420. a.device_code,
  1421. a.device_name,
  1422. a.create_time,
  1423. b.name AS org_name
  1424. FROM
  1425. rq_iot_opeation_fill a
  1426. INNER JOIN
  1427. rq_iot_model_template_attrs b
  1428. ON
  1429. a.device_category_id = b.device_category_id
  1430. WHERE
  1431. a.order_id = #{orderId}
  1432. and
  1433. a.is_report = 1
  1434. </select>
  1435. <select id="reportData" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  1436. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1437. select * from
  1438. rq_iot_device_run_log
  1439. where
  1440. device_id = #{deviceId}
  1441. and
  1442. point_name = #{pointName}
  1443. and DATE(create_time) = DATE(#{createTime})
  1444. </select>
  1445. <!--
  1446. 批量查询设备运行日志:入参为List<IotDeviceRunLogDO>(含deviceId、pointName、createTime)
  1447. 出参:List<IotDeviceRunLogDO>(所有匹配条件的日志记录,结构与原单查一致)
  1448. -->
  1449. <select id="batchReportData" parameterType="java.util.List"
  1450. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1451. SELECT
  1452. *
  1453. -- 如需其他字段,按原单查SQL补充(原SQL用select *,此处显式列出避免冗余)
  1454. FROM
  1455. rq_iot_device_run_log
  1456. WHERE
  1457. -- 批量匹配多个 (device_id, point_name, DATE(create_time)) 三元组条件
  1458. (device_id, point_name, DATE(create_time)) IN (
  1459. <foreach collection="list" item="item" separator=",">
  1460. (#{item.deviceId}, #{item.pointName}, DATE(#{item.createTime}))
  1461. </foreach>
  1462. )
  1463. AND device_code = ''
  1464. -- 按创建时间降序,保持结果一致性(可选,与原单查行为对齐)
  1465. ORDER BY
  1466. create_time DESC
  1467. </select>
  1468. <select id="batchQueryExistingLogs" parameterType="java.util.List"
  1469. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1470. select * from rq_iot_device_run_log
  1471. where
  1472. <!-- 多组条件组合:device_id + point_name + 日期 匹配 -->
  1473. (device_id, point_name, DATE(create_time)) IN (
  1474. <foreach collection="list" item="item" separator=",">
  1475. (#{item.deviceId}, #{item.pointName}, DATE(#{item.createTime}))
  1476. </foreach>
  1477. )
  1478. </select>
  1479. <select id="maxReportData" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  1480. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1481. SELECT
  1482. MAX(total_Run_Time) AS total_run_time
  1483. FROM
  1484. rq_iot_device_run_log
  1485. WHERE
  1486. device_id = #{deviceId}
  1487. AND point_name = #{pointName}
  1488. AND create_time &lt; #{createTime}
  1489. </select>
  1490. <select id="batchQueryMaxReportData" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1491. SELECT t.device_id, t.point_name, MAX(t.total_run_time) as total_run_time
  1492. FROM rq_iot_device_run_log t
  1493. WHERE
  1494. <foreach collection="list" item="item" separator="OR">
  1495. (t.device_id = #{item.deviceId}
  1496. AND t.point_name = #{item.pointName})
  1497. </foreach>
  1498. GROUP BY t.device_id, t.point_name
  1499. </select>
  1500. <select id="reportData1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  1501. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1502. select * from
  1503. rq_iot_device_run_log
  1504. where
  1505. device_id = #{deviceId}
  1506. and
  1507. point_name = #{pointName}
  1508. and DATE(create_time) = DATE(#{createTime})
  1509. </select>
  1510. <select id="getDesc" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  1511. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1512. select
  1513. description point_name
  1514. from
  1515. rq_iot_model_template_attrs
  1516. where
  1517. name = #{pointName}
  1518. and
  1519. device_category_id =
  1520. (select device_category_id from rq_iot_opeation_fill where device_id = #{deviceId} and DATE(create_time) = #{createTime})
  1521. </select>
  1522. <select id="batchGetDescByPointNames" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1523. <!-- 注意:请根据你的实际表名和字段名修改! -->
  1524. <!-- 假设测点描述存储在 iot_device_run_log 表,核心字段:point_name(测点名)、point_desc(测点描述,可替换为你的实际字段) -->
  1525. select
  1526. description point_name
  1527. from
  1528. rq_iot_model_template_attrs
  1529. WHERE
  1530. 1 = 1
  1531. <!-- 批量查询:用 IN 关键字,配合 foreach 遍历测点名集合 -->
  1532. <if test="pointNameSet != null and pointNameSet.size() > 0">
  1533. AND name IN
  1534. <foreach collection="pointNameSet" item="pointName" open="(" separator="," close=")">
  1535. #{pointName} <!-- 遍历 Set 中的每个测点名 -->
  1536. </foreach>
  1537. </if>
  1538. <!-- 去重:避免同一测点名返回多条重复数据 -->
  1539. GROUP BY
  1540. point_name
  1541. </select>
  1542. <select id="getTeamType" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  1543. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1544. select type as point_code from system_dept_type where dept_id = #{deptId}
  1545. </select>
  1546. <select id="getUserInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  1547. resultType="cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO">
  1548. select * from system_users where dept_id = #{deptId} and nickname = '技术员'
  1549. </select>
  1550. <select id="getUserId" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
  1551. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
  1552. select distinct a.person_id device_id from
  1553. rq_iot_device_person a
  1554. left join
  1555. rq_iot_device b
  1556. on a.device_id = b.id
  1557. left join
  1558. system_dept c
  1559. on b.dept_id = c.id
  1560. where c.id = #{deptId}
  1561. limit 1
  1562. </select>
  1563. <select id="selectStatusNumber" parameterType="cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO"
  1564. resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.AllOrderResp">
  1565. select order_status as status,count(order_status) as num from rq_iot_opeation_fill_order a
  1566. <where>
  1567. a.deleted=0
  1568. <if test="reqVO.createTime[0] != null">
  1569. AND a.create_time &gt;= #{reqVO.createTime[0]}
  1570. </if>
  1571. <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
  1572. AND a.create_time &lt;= #{reqVO.createTime[1]}
  1573. </if>
  1574. <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
  1575. AND a.dept_id IN
  1576. <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
  1577. #{key}
  1578. </foreach>
  1579. </if>
  1580. </where>
  1581. group by order_status
  1582. </select>
  1583. </mapper>