IotDeviceMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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="deviceDistances"
  49. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  50. SELECT
  51. rid.id,
  52. rid.dept_id deptId,
  53. rid.device_code deviceCode,
  54. rid.device_name deviceName,
  55. rid.device_status deviceStatus,
  56. rid.asset_property assetProperty
  57. FROM rq_iot_main_work_order_bom mwoo
  58. LEFT JOIN rq_iot_device rid ON rid.id = mwoo.device_id
  59. WHERE mwoo.deleted = 0
  60. AND mwoo.`status` = 0
  61. AND rid.device_code IS NOT NULL
  62. <if test="deptIds != null and deptIds.size &gt; 0">
  63. AND rid.dept_id IN
  64. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  65. #{key}
  66. </foreach>
  67. </if>
  68. <if test="sortedDeviceIds != null and sortedDeviceIds.size &gt; 0">
  69. AND rid.id IN
  70. <foreach collection="sortedDeviceIds" index="index" item="key" open="(" separator="," close=")">
  71. #{key}
  72. </foreach>
  73. </if>
  74. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  75. AND rid.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  76. </if>
  77. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  78. AND rid.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  79. </if>
  80. GROUP BY mwoo.device_id
  81. ORDER BY FIELD(rid.id,
  82. <if test="sortedDeviceIds != null and sortedDeviceIds.size &gt; 0">
  83. <foreach collection="sortedDeviceIds" index="index" item="key" separator=",">
  84. #{key}
  85. </foreach>
  86. </if>
  87. )
  88. </select>
  89. <select id="personRelationDevices"
  90. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  91. SELECT
  92. t.id,
  93. t.device_code,
  94. t.device_name,
  95. t.brand,
  96. t.model,
  97. t.dept_id,
  98. t.device_status,
  99. t.asset_property,
  100. t.pic_url,
  101. t.remark,
  102. t.create_time
  103. FROM
  104. rq_iot_device t
  105. WHERE t.deleted = 0
  106. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="Y" '>
  107. AND
  108. t.id IN (
  109. SELECT device_id FROM rq_iot_device_person
  110. )
  111. </if>
  112. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="N" '>
  113. AND
  114. t.id NOT IN (
  115. SELECT device_id FROM rq_iot_device_person
  116. )
  117. </if>
  118. <if test="deptIds != null and deptIds.size &gt; 0">
  119. AND t.dept_id IN
  120. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  121. #{key}
  122. </foreach>
  123. </if>
  124. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  125. AND t.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  126. </if>
  127. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  128. AND t.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  129. </if>
  130. </select>
  131. <!-- 设备状态列表 -->
  132. <select id="deviceStatuses"
  133. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  134. SELECT
  135. t.id,
  136. t.device_code,
  137. t.device_name,
  138. t.brand,
  139. t.model,
  140. t.dept_id,
  141. t.device_status,
  142. t.asset_property,
  143. t.pic_url,
  144. t.remark,
  145. t.create_time
  146. FROM
  147. rq_iot_device t
  148. WHERE t.deleted = 0
  149. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="Y" '>
  150. AND
  151. t.id IN (
  152. SELECT device_id FROM rq_iot_device_status_log
  153. )
  154. </if>
  155. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="N" '>
  156. AND
  157. t.id NOT IN (
  158. SELECT device_id FROM rq_iot_device_status_log
  159. )
  160. </if>
  161. <if test="deptIds != null and deptIds.size &gt; 0">
  162. AND t.dept_id IN
  163. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  164. #{key}
  165. </foreach>
  166. </if>
  167. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  168. AND t.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  169. </if>
  170. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  171. AND t.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  172. </if>
  173. </select>
  174. <!-- 设备调拨列表 -->
  175. <select id="deviceAllots"
  176. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  177. SELECT
  178. t.id,
  179. t.device_code,
  180. t.device_name,
  181. t.brand,
  182. t.model,
  183. t.dept_id,
  184. t.device_status,
  185. t.asset_property,
  186. t.pic_url,
  187. t.remark,
  188. t.create_time
  189. FROM
  190. rq_iot_device t
  191. WHERE t.deleted = 0
  192. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="Y" '>
  193. AND
  194. t.id IN (
  195. SELECT device_id FROM rq_iot_device_allot_log
  196. )
  197. </if>
  198. <if test='reqVO.setFlag!=null and reqVO.setFlag!="" and reqVO.setFlag=="N" '>
  199. AND
  200. t.id NOT IN (
  201. SELECT device_id FROM rq_iot_device_allot_log
  202. )
  203. </if>
  204. <if test="deptIds != null and deptIds.size &gt; 0">
  205. AND t.dept_id IN
  206. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  207. #{key}
  208. </foreach>
  209. </if>
  210. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  211. AND t.device_name LIKE concat(concat("%",#{reqVO.deviceName}),"%")
  212. </if>
  213. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  214. AND t.device_code LIKE concat(concat("%",#{reqVO.deviceCode}),"%")
  215. </if>
  216. </select>
  217. <select id="deviceAssociateBomList"
  218. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  219. SELECT *
  220. FROM (
  221. SELECT
  222. t.id ,
  223. t.device_code,
  224. t.device_name,
  225. t.asset_class,
  226. t.brand,
  227. t.model,
  228. t.dept_id,
  229. t.device_status,
  230. t.asset_property,
  231. t.pic_url,
  232. t.remark,
  233. t.create_time,
  234. t1.id bomNodeId,
  235. t1.`name`,
  236. t1.`code`
  237. FROM
  238. rq_iot_device t
  239. INNER JOIN rq_iot_bom t1 ON ( t1.device_category_id = t.asset_class AND t1.deleted = 0 )
  240. WHERE
  241. t.deleted = 0
  242. AND t1.deleted = 0
  243. AND t1.leaf_flag = 1
  244. AND t1.type LIKE '%2%'
  245. <if test="deviceIds != null and deviceIds.size &gt; 0">
  246. AND t.id IN
  247. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  248. #{key}
  249. </foreach>
  250. </if>
  251. ) t2
  252. LEFT JOIN (
  253. SELECT
  254. l.device_id,
  255. l.total_run_time,
  256. l.total_mileage,
  257. l.time
  258. FROM rq_iot_device_run_log l
  259. RIGHT JOIN (
  260. SELECT
  261. device_id,
  262. MAX(time) AS latest_time,
  263. MAX(id) AS max_id
  264. FROM rq_iot_device_run_log
  265. GROUP BY device_id
  266. ) AS latest
  267. ON l.device_id = latest.device_id
  268. AND l.time = latest.latest_time
  269. AND l.id = latest.max_id
  270. ) tmp ON tmp.device_id = t2.id
  271. </select>
  272. <select id="deviceAssociateBomListPage"
  273. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  274. SELECT *
  275. FROM (
  276. SELECT
  277. t.id ,
  278. t.device_code,
  279. t.device_name,
  280. t.asset_class,
  281. t.brand,
  282. t.model,
  283. t.dept_id,
  284. t.device_status,
  285. t.asset_property,
  286. t.pic_url,
  287. t.remark,
  288. t.create_time,
  289. t1.id bomNodeId,
  290. t1.`name`,
  291. t1.`code`
  292. FROM
  293. rq_iot_device t
  294. INNER JOIN rq_iot_bom t1 ON ( t1.device_category_id = t.asset_class AND t1.deleted = 0 )
  295. WHERE
  296. t.deleted = 0
  297. AND t1.deleted = 0
  298. AND t1.leaf_flag = 1
  299. AND t1.type LIKE '%2%'
  300. <if test="deviceIds != null and deviceIds.size &gt; 0">
  301. AND t.id IN
  302. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  303. #{key}
  304. </foreach>
  305. </if>
  306. ) t2
  307. LEFT JOIN (
  308. SELECT
  309. l.device_id,
  310. l.total_run_time,
  311. l.total_mileage,
  312. l.time
  313. FROM rq_iot_device_run_log l
  314. RIGHT JOIN (
  315. SELECT
  316. device_id,
  317. MAX(time) AS latest_time,
  318. MAX(id) AS max_id
  319. FROM rq_iot_device_run_log
  320. GROUP BY device_id
  321. ) AS latest
  322. ON l.device_id = latest.device_id
  323. AND l.time = latest.latest_time
  324. AND l.id = latest.max_id
  325. ) tmp ON tmp.device_id = t2.id
  326. </select>
  327. </mapper>