IotDeviceMapper.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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.IotDeviceMapper">
  4. <!--
  5. 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  6. 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  7. 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  8. 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  9. -->
  10. <select id="deviceAssociateBomPage"
  11. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  12. SELECT
  13. t.id ,
  14. t.device_code,
  15. t.device_name,
  16. t.brand,
  17. t.model,
  18. t.dept_id,
  19. t.device_status,
  20. t.asset_property,
  21. t.pic_url,
  22. t.remark,
  23. t.create_time,
  24. t1.id bomNodeId,
  25. t1.`name`,
  26. t1.`code`
  27. FROM
  28. rq_iot_device t
  29. INNER JOIN rq_iot_bom t1 ON ( t1.device_category_id = t.asset_class AND t1.deleted = 0 )
  30. WHERE
  31. t.deleted = 0
  32. AND t1.deleted = 0
  33. AND t1.leaf_flag = 1
  34. AND t1.type LIKE '%2%'
  35. <if test="deptIds != null and deptIds.size &gt; 0">
  36. AND t.dept_id IN
  37. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  38. #{key}
  39. </foreach>
  40. </if>
  41. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  42. AND t.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  43. </if>
  44. <if test="reqVO.name!=null and reqVO.name!=''">
  45. AND t1.name LIKE concat(concat("%",#{reqVO.name}),"%")
  46. </if>
  47. </select>
  48. <select id="allDeviceDistances"
  49. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  50. SELECT
  51. rid.id,
  52. rid.dept_id AS deptId,
  53. rid.device_code AS deviceCode,
  54. rid.device_name AS deviceName,
  55. rid.device_status AS deviceStatus,
  56. rid.model AS model,
  57. rid.asset_property AS assetProperty
  58. FROM rq_iot_device rid
  59. WHERE rid.deleted = 0
  60. <if test="deptIds != null and deptIds.size &gt; 0">
  61. AND rid.dept_id IN
  62. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  63. #{key}
  64. </foreach>
  65. </if>
  66. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  67. AND rid.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  68. </if>
  69. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  70. AND rid.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  71. </if>
  72. ORDER BY
  73. <if test="alarmDeviceIds != null and alarmDeviceIds.size &gt; 0">
  74. CASE WHEN rid.id IN
  75. <foreach collection="alarmDeviceIds" index="index" item="key" open="(" separator="," close=")">
  76. #{key}
  77. </foreach>
  78. THEN 0 ELSE 1 END,
  79. FIELD(rid.id,
  80. <foreach collection="alarmDeviceIds" index="index" item="key" separator=",">
  81. #{key}
  82. </foreach>),
  83. </if>
  84. rid.id DESC;
  85. </select>
  86. <select id="timeoutDeviceMaintenances"
  87. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  88. SELECT
  89. rid.id,
  90. rid.dept_id AS deptId,
  91. rid.device_code AS deviceCode,
  92. rid.device_name AS deviceName,
  93. rid.device_status AS deviceStatus,
  94. rid.model AS model,
  95. rid.asset_property AS assetProperty
  96. FROM rq_iot_device rid
  97. WHERE rid.deleted = 0
  98. <if test="deptIds != null and deptIds.size &gt; 0">
  99. AND rid.dept_id IN
  100. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  101. #{key}
  102. </foreach>
  103. </if>
  104. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  105. AND rid.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  106. </if>
  107. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  108. AND rid.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  109. </if>
  110. <if test="alarmDeviceIds != null and alarmDeviceIds.size &gt; 0">
  111. AND rid.id IN
  112. <foreach collection="alarmDeviceIds" index="index" item="key" open="(" separator="," close=")">
  113. #{key}
  114. </foreach>
  115. </if>
  116. ORDER BY
  117. <if test="alarmDeviceIds != null and alarmDeviceIds.size &gt; 0">
  118. CASE WHEN rid.id IN
  119. <foreach collection="alarmDeviceIds" index="index" item="key" open="(" separator="," close=")">
  120. #{key}
  121. </foreach>
  122. THEN 0 ELSE 1 END,
  123. FIELD(rid.id,
  124. <foreach collection="alarmDeviceIds" index="index" item="key" separator=",">
  125. #{key}
  126. </foreach>),
  127. </if>
  128. rid.id DESC;
  129. </select>
  130. <select id="deviceDistances"
  131. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  132. SELECT *
  133. FROM (
  134. SELECT
  135. rid.id,
  136. rid.dept_id deptId,
  137. rid.device_code deviceCode,
  138. rid.device_name deviceName,
  139. rid.device_status deviceStatus,
  140. rid.asset_property assetProperty,
  141. MAX(mwoo.work_order_id) workOrderId,
  142. '' planId
  143. FROM rq_iot_main_work_order_bom mwoo
  144. LEFT JOIN rq_iot_device rid ON rid.id = mwoo.device_id
  145. WHERE mwoo.deleted = 0
  146. AND mwoo.`status` = 0
  147. AND rid.device_code IS NOT NULL
  148. <if test="deptIds != null and deptIds.size &gt; 0">
  149. AND rid.dept_id IN
  150. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  151. #{key}
  152. </foreach>
  153. </if>
  154. <if test="deviceIds != null and deviceIds.size &gt; 0">
  155. AND rid.id IN
  156. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  157. #{key}
  158. </foreach>
  159. </if>
  160. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  161. AND rid.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  162. </if>
  163. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  164. AND rid.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  165. </if>
  166. GROUP BY mwoo.device_id
  167. UNION ALL
  168. SELECT
  169. rid.id,
  170. rid.dept_id deptId,
  171. rid.device_code deviceCode,
  172. rid.device_name deviceName,
  173. rid.device_status deviceStatus,
  174. rid.asset_property assetProperty,
  175. '' workOrderId,
  176. MAX(mb.plan_id) planId
  177. FROM rq_iot_maintenance_bom mb
  178. LEFT JOIN rq_iot_device rid ON rid.id = mb.device_id
  179. WHERE mb.deleted = 0
  180. AND mb.`status` = 0
  181. AND rid.device_code IS NOT NULL
  182. <if test="deptIds != null and deptIds.size &gt; 0">
  183. AND rid.dept_id IN
  184. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  185. #{key}
  186. </foreach>
  187. </if>
  188. <if test="mainBomDeviceIds != null and mainBomDeviceIds.size &gt; 0">
  189. AND rid.id IN
  190. <foreach collection="mainBomDeviceIds" index="index" item="key" open="(" separator="," close=")">
  191. #{key}
  192. </foreach>
  193. </if>
  194. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  195. AND rid.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  196. </if>
  197. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  198. AND rid.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  199. </if>
  200. GROUP BY mb.device_id
  201. ) tmp
  202. ORDER BY FIELD(tmp.id,
  203. <if test="sortedDeviceIds != null and sortedDeviceIds.size &gt; 0">
  204. <foreach collection="sortedDeviceIds" index="index" item="key" separator=",">
  205. #{key}
  206. </foreach>
  207. </if>
  208. )
  209. </select>
  210. <select id="deviceAlarmDistances"
  211. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  212. SELECT *
  213. FROM (
  214. SELECT
  215. rid.id,
  216. rid.dept_id deptId,
  217. rid.device_code deviceCode,
  218. rid.device_name deviceName,
  219. rid.device_status deviceStatus,
  220. rid.asset_property assetProperty,
  221. MAX(mwoo.work_order_id) workOrderId,
  222. '' planId
  223. FROM rq_iot_main_work_order_bom mwoo
  224. LEFT JOIN rq_iot_device rid ON rid.id = mwoo.device_id
  225. WHERE mwoo.deleted = 0
  226. AND mwoo.`status` = 0
  227. AND rid.device_code IS NOT NULL
  228. <if test="deviceIds != null and deviceIds.size &gt; 0">
  229. AND rid.id IN
  230. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  231. #{key}
  232. </foreach>
  233. </if>
  234. GROUP BY mwoo.device_id
  235. UNION ALL
  236. SELECT
  237. rid.id,
  238. rid.dept_id deptId,
  239. rid.device_code deviceCode,
  240. rid.device_name deviceName,
  241. rid.device_status deviceStatus,
  242. rid.asset_property assetProperty,
  243. '' workOrderId,
  244. MAX(mb.plan_id) planId
  245. FROM rq_iot_maintenance_bom mb
  246. LEFT JOIN rq_iot_device rid ON rid.id = mb.device_id
  247. WHERE mb.deleted = 0
  248. AND mb.`status` = 0
  249. AND rid.device_code IS NOT NULL
  250. <if test="mainBomDeviceIds != null and mainBomDeviceIds.size &gt; 0">
  251. AND rid.id IN
  252. <foreach collection="mainBomDeviceIds" index="index" item="key" open="(" separator="," close=")">
  253. #{key}
  254. </foreach>
  255. </if>
  256. GROUP BY mb.device_id
  257. ) tmp
  258. ORDER BY FIELD(tmp.id,
  259. <if test="sortedDeviceIds != null and sortedDeviceIds.size &gt; 0">
  260. <foreach collection="sortedDeviceIds" index="index" item="key" separator=",">
  261. #{key}
  262. </foreach>
  263. </if>
  264. )
  265. </select>
  266. <select id="deviceAlarmDistancesSearch"
  267. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  268. SELECT *
  269. FROM (
  270. SELECT
  271. rid.id,
  272. rid.dept_id deptId,
  273. rid.device_code deviceCode,
  274. rid.device_name deviceName,
  275. rid.device_status deviceStatus,
  276. rid.asset_property assetProperty,
  277. '' workOrderId,
  278. MAX(mb.plan_id) planId
  279. FROM rq_iot_maintenance_bom mb
  280. LEFT JOIN rq_iot_device rid ON rid.id = mb.device_id
  281. WHERE mb.deleted = 0
  282. AND mb.`status` = 0
  283. AND rid.device_code IS NOT NULL
  284. <if test="mainBomDeviceIds != null and mainBomDeviceIds.size &gt; 0">
  285. AND rid.id IN
  286. <foreach collection="mainBomDeviceIds" index="index" item="key" open="(" separator="," close=")">
  287. #{key}
  288. </foreach>
  289. </if>
  290. GROUP BY mb.device_id
  291. ) tmp
  292. ORDER BY FIELD(tmp.id,
  293. <if test="sortedDeviceIds != null and sortedDeviceIds.size &gt; 0">
  294. <foreach collection="sortedDeviceIds" index="index" item="key" separator=",">
  295. #{key}
  296. </foreach>
  297. </if>
  298. )
  299. </select>
  300. <select id="personRelationDevices"
  301. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  302. SELECT
  303. t.id,
  304. t.device_code,
  305. t.device_name,
  306. t.brand,
  307. t.model,
  308. t.dept_id,
  309. t.device_status,
  310. t.asset_property,
  311. t.pic_url,
  312. t.remark,
  313. t.create_time
  314. FROM
  315. rq_iot_device t
  316. WHERE t.deleted = 0
  317. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="Y" '>
  318. AND
  319. t.id IN (
  320. SELECT device_id FROM rq_iot_device_person
  321. )
  322. </if>
  323. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="N" '>
  324. AND
  325. t.id NOT IN (
  326. SELECT device_id FROM rq_iot_device_person
  327. )
  328. </if>
  329. <if test="deptIds != null and deptIds.size &gt; 0">
  330. AND t.dept_id IN
  331. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  332. #{key}
  333. </foreach>
  334. </if>
  335. <if test="deviceIds != null and deviceIds.size &gt; 0">
  336. AND t.id IN
  337. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  338. #{key}
  339. </foreach>
  340. </if>
  341. <if test="reqVO.deviceIds != null and reqVO.deviceIds.size &gt; 0">
  342. AND t.id IN
  343. <foreach collection="reqVO.deviceIds" index="index" item="key" open="(" separator="," close=")">
  344. #{key}
  345. </foreach>
  346. </if>
  347. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  348. AND t.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  349. </if>
  350. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  351. AND t.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  352. </if>
  353. </select>
  354. <!-- 设备状态列表 -->
  355. <select id="deviceStatuses"
  356. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  357. SELECT
  358. t.id,
  359. t.device_code,
  360. t.device_name,
  361. t.brand,
  362. t.model,
  363. t.dept_id,
  364. t.device_status,
  365. t.asset_property,
  366. t.pic_url,
  367. t.remark,
  368. t.create_time
  369. FROM
  370. rq_iot_device t
  371. WHERE t.deleted = 0
  372. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="Y" '>
  373. AND
  374. t.id IN (
  375. SELECT device_id FROM rq_iot_device_status_log
  376. )
  377. </if>
  378. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="N" '>
  379. AND
  380. t.id NOT IN (
  381. SELECT device_id FROM rq_iot_device_status_log
  382. )
  383. </if>
  384. <if test="deptIds != null and deptIds.size &gt; 0">
  385. AND t.dept_id IN
  386. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  387. #{key}
  388. </foreach>
  389. </if>
  390. <if test="reqVO.deviceIds != null and reqVO.deviceIds.size &gt; 0">
  391. AND t.id IN
  392. <foreach collection="reqVO.deviceIds" index="index" item="key" open="(" separator="," close=")">
  393. #{key}
  394. </foreach>
  395. </if>
  396. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  397. AND t.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  398. </if>
  399. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  400. AND t.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  401. </if>
  402. </select>
  403. <!-- 设备调拨列表 -->
  404. <select id="deviceAllots"
  405. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  406. SELECT
  407. t.id,
  408. t.device_code,
  409. t.device_name,
  410. t.brand,
  411. t.model,
  412. t.dept_id,
  413. t.device_status,
  414. t.asset_property,
  415. t.pic_url,
  416. t.remark,
  417. t.create_time
  418. FROM
  419. rq_iot_device t
  420. WHERE t.deleted = 0
  421. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="Y" '>
  422. AND
  423. t.id IN (
  424. SELECT device_id FROM rq_iot_device_allot_log
  425. )
  426. </if>
  427. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="N" '>
  428. AND
  429. t.id NOT IN (
  430. SELECT device_id FROM rq_iot_device_allot_log
  431. )
  432. </if>
  433. <if test="deptIds != null and deptIds.size &gt; 0">
  434. AND t.dept_id IN
  435. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  436. #{key}
  437. </foreach>
  438. </if>
  439. <if test="reqVO.deviceIds != null and reqVO.deviceIds.size &gt; 0">
  440. AND t.id IN
  441. <foreach collection="reqVO.deviceIds" index="index" item="key" open="(" separator="," close=")">
  442. #{key}
  443. </foreach>
  444. </if>
  445. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  446. AND t.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  447. </if>
  448. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  449. AND t.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  450. </if>
  451. </select>
  452. <select id="deviceAssociateBomList"
  453. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  454. SELECT
  455. t.id ,
  456. t.device_code,
  457. t.device_name,
  458. t.asset_class,
  459. t.brand,
  460. t.model,
  461. t.dept_id,
  462. t.device_status,
  463. t.asset_property,
  464. t.pic_url,
  465. t.remark,
  466. t.create_time,
  467. t1.id bomNodeId,
  468. t1.`name`,
  469. t1.`code`,
  470. t1.`type`
  471. FROM
  472. rq_iot_device t
  473. INNER JOIN rq_iot_device_bom t1 ON ( t1.device_id = t.id AND t1.deleted = 0 )
  474. WHERE
  475. t.deleted = 0
  476. AND t1.deleted = 0
  477. AND t1.leaf_flag = 1
  478. <if test='bomFlag!=null and bomFlag!="" and bomFlag=="b" '>
  479. AND t1.type LIKE '%2%'
  480. </if>
  481. <if test='bomFlag!=null and bomFlag!="" and bomFlag=="w" '>
  482. AND t1.type LIKE '%1%'
  483. </if>
  484. <if test="deviceIds != null and deviceIds.size &gt; 0">
  485. AND t.id IN
  486. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  487. #{key}
  488. </foreach>
  489. </if>
  490. </select>
  491. <select id="deviceAssociateBomListPage"
  492. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  493. SELECT *
  494. FROM (
  495. SELECT
  496. t.id ,
  497. t.device_code,
  498. t.device_name,
  499. t.asset_class,
  500. t.brand,
  501. t.model,
  502. t.dept_id,
  503. t.device_status,
  504. t.asset_property,
  505. t.pic_url,
  506. t.remark,
  507. t.create_time,
  508. t1.id bomNodeId,
  509. t1.`name`,
  510. t1.`code`
  511. FROM
  512. rq_iot_device t
  513. INNER JOIN rq_iot_device_bom t1 ON ( t1.device_id = t.id AND t1.deleted = 0 )
  514. WHERE
  515. t.deleted = 0
  516. AND t1.deleted = 0
  517. AND t1.leaf_flag = 1
  518. <if test='bomFlag!=null and bomFlag!="" and bomFlag=="b" '>
  519. AND t1.type LIKE '%2%'
  520. </if>
  521. <if test='bomFlag!=null and bomFlag!="" and bomFlag=="w" '>
  522. AND t1.type LIKE '%1%'
  523. </if>
  524. <if test="deviceIds != null and deviceIds.size &gt; 0">
  525. AND t.id IN
  526. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  527. #{key}
  528. </foreach>
  529. </if>
  530. ) t2
  531. LEFT JOIN (
  532. SELECT
  533. l.device_id,
  534. l.total_run_time,
  535. l.total_mileage,
  536. l.time
  537. FROM rq_iot_device_run_log l
  538. RIGHT JOIN (
  539. SELECT
  540. device_id,
  541. MAX(time) AS latest_time,
  542. MAX(id) AS max_id
  543. FROM rq_iot_device_run_log
  544. GROUP BY device_id
  545. ) AS latest
  546. ON l.device_id = latest.device_id
  547. AND l.time = latest.latest_time
  548. AND l.id = latest.max_id
  549. ) tmp ON tmp.device_id = t2.id
  550. </select>
  551. <!-- 查询设备表中所有 设备名称中包含 车牌号的车辆 -->
  552. <select id="allCarsContainsPlates"
  553. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotCarDevicePlateVO">
  554. SELECT
  555. id deviceId,
  556. device_code deviceCode,
  557. device_name deviceName,
  558. REGEXP_SUBSTR(device_name, '([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-Z0-9]{4,7}[A-Z0-9挂学警港澳使领])') as licensePlate
  559. FROM rq_iot_device
  560. WHERE
  561. deleted = 0
  562. AND device_name REGEXP '([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-Z0-9]{4,7}[A-Z0-9挂学警港澳使领])';
  563. </select>
  564. <select id="selectCodeAndNameList"
  565. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSimple">
  566. SELECT
  567. id,
  568. device_code as deviceCode,
  569. device_name as deviceName
  570. FROM rq_iot_device
  571. WHERE
  572. deleted = 0
  573. </select>
  574. <select id="selectTypeNumber" resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSimple">
  575. select b.name as category, a.count as value from (select asset_class, count(id) as count from rq_iot_device d
  576. <where>
  577. d.deleted=0
  578. <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
  579. AND d.dept_id IN
  580. <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
  581. #{key}
  582. </foreach>
  583. </if>
  584. and d.deleted=0
  585. <if test="products != null and products.size &gt; 0">
  586. AND d.asset_class IN
  587. <foreach collection="products" index="index" item="key" open="(" separator="," close=")">
  588. #{key}
  589. </foreach>
  590. </if>
  591. </where>
  592. group by asset_class)a
  593. left join rq_iot_product_classify b on a.asset_class=b.id
  594. </select>
  595. <select id="selectExport"
  596. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  597. select a.*,
  598. g.label as deviceStatus,m.name as manufacturer,
  599. CASE
  600. WHEN d.type = 1 THEN COALESCE(d.`name`, '')
  601. WHEN d.type = 2 THEN COALESCE(p1.`name`, '')
  602. WHEN d.type = 3 THEN COALESCE(p2.`name`, '')
  603. ELSE ''
  604. END AS company,
  605. -- 按type规则填充project字段
  606. CASE
  607. WHEN d.type = 2 THEN COALESCE(d.`name`, '')
  608. WHEN d.type = 3 THEN COALESCE(p1.`name`, '')
  609. ELSE ''
  610. END AS project,
  611. -- 按type规则填充deptName字段(仅type=3时有值)
  612. CASE
  613. WHEN d.type = 3 THEN COALESCE(d.`name`, '')
  614. ELSE ''
  615. END AS deptName
  616. from rq_iot_device a
  617. -- 左关联当前部门(避免主表数据丢失)
  618. LEFT JOIN system_dept d ON a.dept_id = d.id
  619. -- 左关联父级部门(type=2/3时用)
  620. LEFT JOIN system_dept p1 ON d.parent_id = p1.id
  621. -- 左关联祖父级部门(type=3时用)
  622. LEFT JOIN system_dept p2 ON p1.parent_id = p2.id
  623. left join rq_iot_supplier m on a.manufacturer_id=m.id
  624. left join (select r.value,r.label from system_dict_data r where r.dict_type='pms_device_status') g on a.device_status = g.value COLLATE utf8mb4_general_ci
  625. <where>
  626. a.deleted=0
  627. <if test="reqVO.createTime[0] != null">
  628. AND a.create_time &gt;= #{reqVO.createTime[0]}
  629. </if>
  630. <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
  631. AND a.create_time &lt;= #{reqVO.createTime[1]}
  632. </if>
  633. <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
  634. AND a.dept_id IN
  635. <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
  636. #{key}
  637. </foreach>
  638. </if>
  639. <if test="reqVO.deviceCode != null">
  640. AND a.deviceCode LIKE concat("%",#{reqVO.deviceCode},"%")
  641. </if>
  642. <if test="reqVO.deviceName != null">
  643. AND a.deviceName LIKE concat("%",#{reqVO.deviceName},"%")
  644. </if>
  645. </where>
  646. </select>
  647. <select id="getTotalA" resultType="java.lang.Long">
  648. SELECT COUNT(1) FROM RQ_IOT_DEVICE b WHERE ASSET_CLASS IN(select id from rq_iot_product_classify a
  649. <where>
  650. a.deleted=0
  651. <if test='reqVO.remark!=null'>
  652. AND a.remark = #{reqVO.remark}
  653. </if>
  654. </where>
  655. )
  656. and
  657. b.deleted=0
  658. <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
  659. AND b.dept_id IN
  660. <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
  661. #{key}
  662. </foreach>
  663. </if>
  664. </select>
  665. <select id="getFailureCount" resultType="java.lang.Long">
  666. select b.device_id from (SELECT ID FROM RQ_IOT_DEVICE c WHERE ASSET_CLASS IN(select id from rq_iot_product_classify a
  667. <where>
  668. a.deleted=0
  669. <if test='reqVO.remark!=null'>
  670. AND a.remark = #{reqVO.remark}
  671. </if>
  672. </where>
  673. )
  674. and
  675. c.deleted=0
  676. <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
  677. AND c.dept_id IN
  678. <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
  679. #{key}
  680. </foreach>
  681. </if>
  682. )a
  683. left JOIN (select DISTINCT(device_id) from rq_iot_failure_report where `status`!='finished' and `status`!='oareject' and `status`!='reporting' and if_stop=1)b
  684. on a.id=b.device_id where b.device_id is not NULL
  685. </select>
  686. <select id="getRepairCount" resultType="java.lang.Long">
  687. select b.device_id from (SELECT ID FROM RQ_IOT_DEVICE c WHERE ASSET_CLASS IN(select id from rq_iot_product_classify a
  688. <where>
  689. a.deleted=0
  690. <if test='reqVO.remark!=null'>
  691. AND a.remark = #{reqVO.remark}
  692. </if>
  693. </where>
  694. )
  695. and
  696. c.deleted=0
  697. <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
  698. AND c.dept_id IN
  699. <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
  700. #{key}
  701. </foreach>
  702. </if>
  703. )a
  704. left JOIN (select DISTINCT(device_id) from rq_iot_maintain where `status`!='finished' and `status`!='oareject' and if_stop=1)b
  705. on a.id=b.device_id where b.device_id is not NULL
  706. </select>
  707. </mapper>