IotInspectOrderDetailMapper.xml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.inspect.IotInspectOrderDetailMapper">
  4. <!--
  5. 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  6. 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  7. 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  8. 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  9. -->
  10. <select id="getDeviceStatusWei"
  11. resultType="cn.iocoder.yudao.module.pms.controller.admin.inspect.order.vo.IotInspectDeviceVo">
  12. select * from(select order_id, device_id,create_time, if_normal,dept_id,
  13. (select inspect_order_title from rq_iot_inspect_order aa where aa.id = fin.order_id) order_name,
  14. (select device_name from rq_iot_device aa where aa.id = fin.device_id) device_name,
  15. (select device_code from rq_iot_device aa where aa.id = fin.device_id) device_code
  16. from (SELECT
  17. order_id,
  18. device_id,
  19. max(create_time) create_time,
  20. max(dept_id) dept_id,
  21. '未填写' AS if_normal
  22. FROM
  23. rq_iot_inspect_order_detail de where de.deleted=0 and de.ignore_reason = false
  24. GROUP BY
  25. order_id, device_id
  26. HAVING
  27. SUM(CASE WHEN if_normal IS NULL THEN 1 ELSE 0 END)> 0) fin)finall
  28. <where>
  29. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  30. and finall.device_name LIKE CONCAT('%',#{reqVO.deviceName},'%')
  31. </if>
  32. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  33. and finall.device_code LIKE CONCAT('%',#{reqVO.deviceCode},'%')
  34. </if>
  35. <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
  36. <choose>
  37. <when test="reqVO.createTime.length == 1">
  38. AND finall.create_time = #{reqVO.createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  39. </when>
  40. <otherwise>
  41. AND finall.create_time BETWEEN #{reqVO.createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{reqVO.createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  42. </otherwise>
  43. </choose>
  44. </if>
  45. <if test="deptIds != null and deptIds.size &gt; 0">
  46. AND finall.dept_id IN
  47. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  48. #{key}
  49. </foreach>
  50. </if>
  51. </where>
  52. order by create_time desc
  53. </select>
  54. <select id="getDeviceStatusYi"
  55. resultType="cn.iocoder.yudao.module.pms.controller.admin.inspect.order.vo.IotInspectDeviceVo">
  56. select * from(select order_id, device_id,create_time, if_normal,dept_id,
  57. (select inspect_order_title from rq_iot_inspect_order aa where aa.id = fin.order_id) order_name,
  58. (select device_name from rq_iot_device aa where aa.id = fin.device_id) device_name,
  59. (select device_code from rq_iot_device aa where aa.id = fin.device_id) device_code
  60. from (SELECT
  61. order_id,
  62. device_id,
  63. max(create_time) create_time,
  64. max(dept_id) dept_id,
  65. '已填写' AS if_normal
  66. FROM
  67. rq_iot_inspect_order_detail de where de.deleted=0 and de.ignore_reason = false
  68. GROUP BY
  69. order_id, device_id
  70. HAVING
  71. SUM(CASE WHEN if_normal IS NULL THEN 1 ELSE 0 END)= 0) fin)finall
  72. <where>
  73. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  74. and finall.device_name LIKE CONCAT('%',#{reqVO.deviceName},'%')
  75. </if>
  76. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  77. and finall.device_code LIKE CONCAT('%',#{reqVO.deviceCode},'%')
  78. </if>
  79. <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
  80. <choose>
  81. <when test="reqVO.createTime.length == 1">
  82. AND finall.create_time = #{reqVO.createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  83. </when>
  84. <otherwise>
  85. AND finall.create_time BETWEEN #{reqVO.createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{reqVO.createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  86. </otherwise>
  87. </choose>
  88. </if>
  89. <if test="deptIds != null and deptIds.size &gt; 0">
  90. AND finall.dept_id IN
  91. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  92. #{key}
  93. </foreach>
  94. </if>
  95. </where>
  96. order by create_time desc
  97. </select>
  98. <select id="getDeviceStatusIgnore"
  99. resultType="cn.iocoder.yudao.module.pms.controller.admin.inspect.order.vo.IotInspectDeviceVo">
  100. select * from(select order_id, device_id,create_time, if_normal,dept_id,
  101. (select inspect_order_title from rq_iot_inspect_order aa where aa.id = fin.order_id) order_name,
  102. (select device_name from rq_iot_device aa where aa.id = fin.device_id) device_name,
  103. (select device_code from rq_iot_device aa where aa.id = fin.device_id) device_code
  104. from (SELECT
  105. order_id,
  106. device_id,
  107. max(create_time) create_time,
  108. max(dept_id) dept_id,
  109. '忽略' AS if_normal
  110. FROM
  111. rq_iot_inspect_order_detail de where de.deleted=0 and de.ignore_reason = true
  112. GROUP BY
  113. order_id, device_id
  114. ) fin)finall
  115. <where>
  116. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  117. and finall.device_name LIKE CONCAT('%',#{reqVO.deviceName},'%')
  118. </if>
  119. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  120. and finall.device_code LIKE CONCAT('%',#{reqVO.deviceCode},'%')
  121. </if>
  122. <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
  123. <choose>
  124. <when test="reqVO.createTime.length == 1">
  125. AND finall.create_time = #{reqVO.createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  126. </when>
  127. <otherwise>
  128. AND finall.create_time BETWEEN #{reqVO.createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{reqVO.createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  129. </otherwise>
  130. </choose>
  131. </if>
  132. <if test="deptIds != null and deptIds.size &gt; 0">
  133. AND finall.dept_id IN
  134. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  135. #{key}
  136. </foreach>
  137. </if>
  138. </where>
  139. order by create_time desc
  140. </select>
  141. <select id="getExceptionDevicePage" resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSimple">
  142. select b.device_code as deviceCode, b.device_name as deviceName, a.orderCount,a.dept_id as deptId, from (select device_id,count(distinct order_id) as orderCount from rq_iot_inspect_order_detail c
  143. <where>
  144. c.if_normal = false and c.deleted=0
  145. <if test="reqVO.createTime[0] != null">
  146. AND a.create_time &gt;= #{reqVO.createTime[0]}
  147. </if>
  148. <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
  149. AND a.create_time &lt;= #{reqVO.createTime[1]}
  150. </if>
  151. <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
  152. AND a.dept_id IN
  153. <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
  154. #{key}
  155. </foreach>
  156. </if>
  157. </where>
  158. group by device_id)a
  159. left join rq_iot_device b on a.device_id=b.id
  160. </select>
  161. </mapper>