IotDeviceRunLogMapper.xml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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.iotdevicerunlog.IotDeviceRunLogMapper">
  4. <!--
  5. 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  6. 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  7. 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  8. 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  9. -->
  10. <select id="distinctDevices"
  11. resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
  12. SELECT drl.device_id,
  13. MAX(CASE WHEN mta.`code` = 'sc' THEN drl.total_run_time ELSE 0 END) AS total_run_time,
  14. MAX(CASE WHEN mta.`code` = 'gls' THEN drl.total_run_time ELSE 0 END) AS total_mileage,
  15. MAX(drl.point_name) point_name,
  16. mta.`code` point_code
  17. FROM rq_iot_device_run_log drl
  18. LEFT JOIN rq_iot_model_template_attrs mta ON (mta.`name` = drl.point_name AND (mta.`code` ='sc' OR mta.`code`='gls'))
  19. WHERE drl.deleted = 0
  20. <if test="deviceIds != null and deviceIds.size &gt; 0">
  21. AND drl.device_id IN
  22. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  23. #{key}
  24. </foreach>
  25. </if>
  26. AND (mta.`code` = 'sc' OR mta.`code` = 'gls')
  27. <if test="actualStartTime!=null and actualStartTime!=''">
  28. AND DATE(drl.create_time) = #{actualStartTime}
  29. </if>
  30. <if test="deviceCategoryIds != null and deviceCategoryIds.size &gt; 0">
  31. AND mta.device_category_id IN
  32. <foreach collection="deviceCategoryIds" index="index" item="key" open="(" separator="," close=")">
  33. #{key}
  34. </foreach>
  35. </if>
  36. GROUP BY drl.device_id, mta.`code`
  37. </select>
  38. <select id="distinctDevicesSearch"
  39. resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
  40. SELECT drl.device_id,
  41. MAX(drl.total_run_time) AS total_run_time,
  42. 0.0 total_mileage,
  43. drl.point_name point_name
  44. FROM rq_iot_device_max_run_log drl
  45. WHERE drl.deleted = 0
  46. AND drl.is_sum = 1
  47. <if test="deviceIds != null and deviceIds.size &gt; 0">
  48. AND drl.device_id IN
  49. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  50. #{key}
  51. </foreach>
  52. </if>
  53. GROUP BY drl.device_id, drl.point_name
  54. </select>
  55. <!-- 查询正常统计的累计 公里数 时长 -->
  56. <select id="normalCumulativeAttrs"
  57. resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
  58. SELECT
  59. mta.device_category_id,
  60. mta.`name` pointName,
  61. mta.`code` point_code
  62. FROM rq_iot_model_template_attrs mta
  63. WHERE mta.deleted = 0
  64. AND (mta.`code` ='sc' OR mta.`code`='gls')
  65. <if test="deviceCategoryIds != null and deviceCategoryIds.size &gt; 0">
  66. AND mta.device_category_id IN
  67. <foreach collection="deviceCategoryIds" index="index" item="key" open="(" separator="," close=")">
  68. #{key}
  69. </foreach>
  70. </if>
  71. </select>
  72. <select id="selectListByCreateTimeAndDeptList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO"
  73. resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
  74. SELECT a.id, a.create_time,a.total_run_time,a.fill_content
  75. FROM rq_iot_device_run_log a
  76. WHERE a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
  77. and a.point_name = #{pointName}
  78. and (a.device_code is null or a.device_code='')
  79. <if test="deptIds != null and deptIds.size &gt; 0">
  80. AND a.dept_id IN
  81. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  82. #{key}
  83. </foreach>
  84. </if>
  85. </select>
  86. <select id="selectYearTotalGas" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO"
  87. resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.YearTotalGas">
  88. SELECT
  89. DATE_FORMAT(create_time, '%Y-%m') AS month,
  90. SUM(IFNULL(fill_content, 0)) AS total_gas
  91. FROM
  92. rq_iot_device_run_log a
  93. WHERE
  94. a.create_time >= DATE_SUB(NOW(), INTERVAL 1 YEAR)
  95. AND a.fill_content IS NOT NULL
  96. and (a.device_code is null or a.device_code ='')
  97. and a.point_name = #{pointName}
  98. <if test="deptIds != null and deptIds.size &gt; 0">
  99. AND a.dept_id IN
  100. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  101. #{key}
  102. </foreach>
  103. </if>
  104. GROUP BY
  105. month
  106. ORDER BY
  107. month ASC;
  108. </select>
  109. <!-- 查询指定设备 指定运行模板属性的累计时长 累计公里数 -->
  110. <select id="multipleAccumulatedData"
  111. resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
  112. SELECT
  113. device_id,
  114. point_name,
  115. MAX( total_run_time ) AS total_run_time,
  116. MAX( total_mileage ) AS total_mileage
  117. FROM
  118. rq_iot_device_run_log
  119. WHERE
  120. deleted = 0
  121. <if test="actualStartTime!=null and actualStartTime!=''">
  122. AND DATE(create_time) = #{actualStartTime}
  123. </if>
  124. <if test="deviceIds != null and deviceIds.size &gt; 0">
  125. AND device_id IN
  126. <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
  127. #{key}
  128. </foreach>
  129. </if>
  130. <if test="attrNames != null and attrNames.size &gt; 0">
  131. AND point_name IN
  132. <foreach collection="attrNames" index="index" item="key" open="(" separator="," close=")">
  133. #{key}
  134. </foreach>
  135. </if>
  136. GROUP BY
  137. device_id,
  138. point_name
  139. </select>
  140. <select id="theMaxTotalRuntime" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO"
  141. resultType="java.math.BigDecimal">
  142. SELECT MAX(total_run_time)
  143. FROM rq_iot_device_run_log
  144. WHERE deleted = 0
  145. AND device_id = #{deviceId}
  146. AND point_name = #{pointName}
  147. </select>
  148. </mapper>