IotDeviceMapper.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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="deviceAssociateBomList"
  49. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  50. SELECT *
  51. FROM (
  52. SELECT
  53. t.id ,
  54. t.device_code,
  55. t.device_name,
  56. t.asset_class,
  57. t.brand,
  58. t.model,
  59. t.dept_id,
  60. t.device_status,
  61. t.asset_property,
  62. t.pic_url,
  63. t.remark,
  64. t.create_time,
  65. t1.id bomNodeId,
  66. t1.`name`,
  67. t1.`code`
  68. FROM
  69. rq_iot_device t
  70. INNER JOIN rq_iot_bom t1 ON ( t1.device_category_id = t.asset_class AND t1.deleted = 0 )
  71. WHERE
  72. t.deleted = 0
  73. AND t1.deleted = 0
  74. AND t1.leaf_flag = 1
  75. AND t1.type LIKE '%2%'
  76. <if test="deviceIds != null and deviceIds.size &gt; 0">
  77. AND t.id IN
  78. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  79. #{key}
  80. </foreach>
  81. </if>
  82. ) t2
  83. LEFT JOIN (
  84. SELECT
  85. l.device_id,
  86. l.total_run_time,
  87. l.total_mileage,
  88. l.time
  89. FROM rq_iot_device_run_log l
  90. RIGHT JOIN (
  91. SELECT
  92. device_id,
  93. MAX(time) AS latest_time,
  94. MAX(id) AS max_id
  95. FROM rq_iot_device_run_log
  96. GROUP BY device_id
  97. ) AS latest
  98. ON l.device_id = latest.device_id
  99. AND l.time = latest.latest_time
  100. AND l.id = latest.max_id
  101. ) tmp ON tmp.device_id = t2.id
  102. </select>
  103. <select id="deviceAssociateBomListPage"
  104. resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
  105. SELECT *
  106. FROM (
  107. SELECT
  108. t.id ,
  109. t.device_code,
  110. t.device_name,
  111. t.asset_class,
  112. t.brand,
  113. t.model,
  114. t.dept_id,
  115. t.device_status,
  116. t.asset_property,
  117. t.pic_url,
  118. t.remark,
  119. t.create_time,
  120. t1.id bomNodeId,
  121. t1.`name`,
  122. t1.`code`
  123. FROM
  124. rq_iot_device t
  125. INNER JOIN rq_iot_bom t1 ON ( t1.device_category_id = t.asset_class AND t1.deleted = 0 )
  126. WHERE
  127. t.deleted = 0
  128. AND t1.deleted = 0
  129. AND t1.leaf_flag = 1
  130. AND t1.type LIKE '%2%'
  131. <if test="deviceIds != null and deviceIds.size &gt; 0">
  132. AND t.id IN
  133. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  134. #{key}
  135. </foreach>
  136. </if>
  137. ) t2
  138. LEFT JOIN (
  139. SELECT
  140. l.device_id,
  141. l.total_run_time,
  142. l.total_mileage,
  143. l.time
  144. FROM rq_iot_device_run_log l
  145. RIGHT JOIN (
  146. SELECT
  147. device_id,
  148. MAX(time) AS latest_time,
  149. MAX(id) AS max_id
  150. FROM rq_iot_device_run_log
  151. GROUP BY device_id
  152. ) AS latest
  153. ON l.device_id = latest.device_id
  154. AND l.time = latest.latest_time
  155. AND l.id = latest.max_id
  156. ) tmp ON tmp.device_id = t2.id
  157. </select>
  158. </mapper>