IotRdDailyReportMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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.iotrddailyreport.IotRdDailyReportMapper">
  4. <!-- 基础结果映射 -->
  5. <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.pms.dal.dataobject.iotrddailyreport.IotRdDailyReportDO">
  6. <!-- 根据实际字段配置 -->
  7. <id column="id" property="id" />
  8. <result column="dept_id" property="deptId" />
  9. <result column="project_id" property="projectId" />
  10. <result column="task_id" property="taskId" />
  11. <result column="rd_status" property="rdStatus" />
  12. <result column="construction_start_date" property="constructionStartDate" />
  13. <result column="construction_end_date" property="constructionEndDate" />
  14. <!-- 其他字段映射 -->
  15. <result column="project_classification" property="projectClassification" />
  16. <result column="daily_power_usage" property="dailyPowerUsage" />
  17. <!-- 其他字段映射 -->
  18. <result column="non_production_time" property="nonProductionTime" />
  19. <result column="rd_npt_reason" property="rdNptReason" />
  20. <result column="production_status" property="productionStatus" />
  21. <result column="next_plan" property="nextPlan" />
  22. <result column="personnel" property="personnel" />
  23. <!-- 其他字段映射 -->
  24. <result column="remark" property="remark" />
  25. <result column="status" property="status" />
  26. <result column="creator" property="creator" />
  27. <result column="create_time" property="createTime" />
  28. <result column="updater" property="updater" />
  29. <result column="update_time" property="updateTime" />
  30. </resultMap>
  31. <select id="selectListGrouped" resultMap="BaseResultMap"
  32. parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
  33. SELECT t1.*, g.min_start_date
  34. FROM rq_iot_rd_daily_report t1
  35. INNER JOIN (
  36. SELECT
  37. rd_status,
  38. MIN(construction_start_date) as min_start_date
  39. FROM rq_iot_rd_daily_report
  40. <where>
  41. <if test="reqVO.deptId != null">
  42. AND dept_id = #{reqVO.deptId}
  43. </if>
  44. <if test="reqVO.projectId != null">
  45. AND project_id = #{reqVO.projectId}
  46. </if>
  47. <if test="reqVO.taskId != null">
  48. AND task_id = #{reqVO.taskId}
  49. </if>
  50. </where>
  51. GROUP BY rd_status
  52. ) g ON t1.rd_status = g.rd_status
  53. AND t1.construction_start_date = g.min_start_date
  54. AND t1.rd_status <![CDATA[<>]]> ''
  55. WHERE NOT EXISTS (
  56. SELECT 1 FROM rq_iot_rd_daily_report t2
  57. WHERE t2.rd_status = t1.rd_status
  58. AND t2.construction_start_date &lt; t1.construction_start_date
  59. <if test="reqVO.deptId != null">
  60. AND t2.dept_id = #{reqVO.deptId}
  61. </if>
  62. <if test="reqVO.projectId != null">
  63. AND t2.project_id = #{reqVO.projectId}
  64. </if>
  65. <if test="reqVO.taskId != null">
  66. AND t2.task_id = #{reqVO.taskId}
  67. </if>
  68. )
  69. <if test="reqVO.deptId != null">
  70. AND t1.dept_id = #{reqVO.deptId}
  71. </if>
  72. <if test="reqVO.projectId != null">
  73. AND t1.project_id = #{reqVO.projectId}
  74. </if>
  75. <if test="reqVO.taskId != null">
  76. AND t1.task_id = #{reqVO.taskId}
  77. </if>
  78. ORDER BY g.min_start_date ASC
  79. </select>
  80. <select id="taskConstructionPeriod" resultType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportTaskPeriodVO">
  81. SELECT
  82. task_id taskId,
  83. MIN(construction_start_date) AS startDate,
  84. MIN(CASE WHEN rd_status = 'wg' THEN construction_start_date ELSE NULL END) AS endDate
  85. FROM rq_iot_rd_daily_report
  86. WHERE deleted = b'0'
  87. GROUP BY task_id;
  88. </select>
  89. <select id="rdWellNameDailyReports" resultMap="BaseResultMap"
  90. parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
  91. SELECT
  92. rdr.*
  93. FROM
  94. rq_iot_rd_daily_report rdr
  95. INNER JOIN system_dept d ON d.id = rdr.dept_id
  96. LEFT JOIN system_dept pd ON pd.id = d.parent_id
  97. WHERE
  98. rdr.deleted = 0
  99. AND rdr.dept_id IS NOT NULL
  100. <if test="deptIds != null and deptIds.size &gt; 0">
  101. AND rdr.dept_id IN
  102. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  103. #{key}
  104. </foreach>
  105. </if>
  106. <if test="projectIds != null and projectIds.size &gt; 0">
  107. AND rdr.project_id IN
  108. <foreach collection="projectIds" index="index" item="key" open="(" separator="," close=")">
  109. #{key}
  110. </foreach>
  111. </if>
  112. <if test="taskIds != null and taskIds.size &gt; 0">
  113. AND rdr.task_id IN
  114. <foreach collection="taskIds" index="index" item="key" open="(" separator="," close=")">
  115. #{key}
  116. </foreach>
  117. </if>
  118. <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
  119. <!-- 处理“开始时间”(数组第1位,如 createTime[0] = 2024-01-01 00:00:00) -->
  120. <if test="reqVO.createTime[0] != null">
  121. AND rdr.create_time &gt;= #{reqVO.createTime[0]}
  122. </if>
  123. <!-- 处理“结束时间”(数组第2位,如 createTime[1] = 2024-01-31 23:59:59) -->
  124. <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
  125. AND rdr.create_time &lt;= #{reqVO.createTime[1]}
  126. </if>
  127. </if>
  128. ORDER BY
  129. COALESCE(pd.sort, 999999) ASC,
  130. d.sort ASC,
  131. DATE(rdr.create_time) DESC;
  132. </select>
  133. <select id="rdWellNameDailyReportsGroupIds" resultMap="BaseResultMap"
  134. parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
  135. WITH sorted_data AS (
  136. SELECT
  137. rdr.id,
  138. rdr.dept_id,
  139. rdr.task_id,
  140. ROW_NUMBER() OVER (
  141. PARTITION BY rdr.dept_id, rdr.task_id
  142. ORDER BY
  143. COALESCE(pd.sort, 999999) DESC, -- 反转:ASC -> DESC
  144. d.sort DESC, -- 反转:ASC -> DESC
  145. rdr.task_id ASC, -- 反转:DESC -> ASC
  146. DATE(rdr.create_time) ASC -- 反转:DESC -> ASC
  147. ) AS rn
  148. FROM
  149. rq_iot_rd_daily_report rdr
  150. INNER JOIN system_dept d ON d.id = rdr.dept_id
  151. LEFT JOIN system_dept pd ON pd.id = d.parent_id
  152. WHERE
  153. rdr.deleted = 0
  154. AND rdr.dept_id IS NOT NULL
  155. <if test="deptIds != null and deptIds.size &gt; 0">
  156. AND rdr.dept_id IN
  157. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  158. #{key}
  159. </foreach>
  160. </if>
  161. <if test="projectIds != null and projectIds.size &gt; 0">
  162. AND rdr.project_id IN
  163. <foreach collection="projectIds" index="index" item="key" open="(" separator="," close=")">
  164. #{key}
  165. </foreach>
  166. </if>
  167. <if test="taskIds != null and taskIds.size &gt; 0">
  168. AND rdr.task_id IN
  169. <foreach collection="taskIds" index="index" item="key" open="(" separator="," close=")">
  170. #{key}
  171. </foreach>
  172. </if>
  173. <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
  174. <!-- 处理“开始时间”(数组第1位,如 createTime[0] = 2024-01-01 00:00:00) -->
  175. <if test="reqVO.createTime[0] != null">
  176. AND rdr.create_time &gt;= #{reqVO.createTime[0]}
  177. </if>
  178. <!-- 处理“结束时间”(数组第2位,如 createTime[1] = 2024-01-31 23:59:59) -->
  179. <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
  180. AND rdr.create_time &lt;= #{reqVO.createTime[1]}
  181. </if>
  182. </if>
  183. )
  184. SELECT
  185. id,
  186. dept_id,
  187. task_id
  188. FROM sorted_data
  189. WHERE rn = 1
  190. </select>
  191. <select id="rdDeptDailyReports" resultMap="BaseResultMap"
  192. parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
  193. SELECT
  194. rdr.*
  195. FROM
  196. rq_iot_rd_daily_report rdr
  197. INNER JOIN system_dept d ON d.id = rdr.dept_id
  198. LEFT JOIN system_dept pd ON pd.id = d.parent_id
  199. WHERE
  200. rdr.deleted = 0
  201. AND rdr.dept_id IS NOT NULL
  202. <if test="deptIds != null and deptIds.size &gt; 0">
  203. AND rdr.dept_id IN
  204. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  205. #{key}
  206. </foreach>
  207. </if>
  208. <if test="projectIds != null and projectIds.size &gt; 0">
  209. AND rdr.project_id IN
  210. <foreach collection="projectIds" index="index" item="key" open="(" separator="," close=")">
  211. #{key}
  212. </foreach>
  213. </if>
  214. <if test="taskIds != null and taskIds.size &gt; 0">
  215. AND rdr.task_id IN
  216. <foreach collection="taskIds" index="index" item="key" open="(" separator="," close=")">
  217. #{key}
  218. </foreach>
  219. </if>
  220. <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
  221. <!-- 处理“开始时间”(数组第1位,如 createTime[0] = 2024-01-01 00:00:00) -->
  222. <if test="reqVO.createTime[0] != null">
  223. AND rdr.create_time &gt;= #{reqVO.createTime[0]}
  224. </if>
  225. <!-- 处理“结束时间”(数组第2位,如 createTime[1] = 2024-01-31 23:59:59) -->
  226. <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
  227. AND rdr.create_time &lt;= #{reqVO.createTime[1]}
  228. </if>
  229. </if>
  230. ORDER BY
  231. rdr.task_id DESC,
  232. COALESCE(pd.sort, 999999) ASC,
  233. d.sort ASC,
  234. DATE(rdr.create_time) DESC;
  235. </select>
  236. <select id="rdDeptDailyReportsGroupIds" resultMap="BaseResultMap"
  237. parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
  238. WITH sorted_data AS (
  239. SELECT
  240. rdr.id,
  241. rdr.dept_id,
  242. rdr.task_id,
  243. ROW_NUMBER() OVER (
  244. PARTITION BY rdr.dept_id, rdr.task_id
  245. ORDER BY
  246. rdr.task_id ASC, -- 反转:DESC -> ASC
  247. COALESCE(pd.sort, 999999) DESC, -- 反转:ASC -> DESC
  248. d.sort DESC, -- 反转:ASC -> DESC
  249. DATE(rdr.create_time) ASC -- 反转:DESC -> ASC
  250. ) AS rn
  251. FROM
  252. rq_iot_rd_daily_report rdr
  253. INNER JOIN system_dept d ON d.id = rdr.dept_id
  254. LEFT JOIN system_dept pd ON pd.id = d.parent_id
  255. WHERE
  256. rdr.deleted = 0
  257. AND rdr.dept_id IS NOT NULL
  258. <if test="deptIds != null and deptIds.size &gt; 0">
  259. AND rdr.dept_id IN
  260. <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
  261. #{key}
  262. </foreach>
  263. </if>
  264. <if test="projectIds != null and projectIds.size &gt; 0">
  265. AND rdr.project_id IN
  266. <foreach collection="projectIds" index="index" item="key" open="(" separator="," close=")">
  267. #{key}
  268. </foreach>
  269. </if>
  270. <if test="taskIds != null and taskIds.size &gt; 0">
  271. AND rdr.task_id IN
  272. <foreach collection="taskIds" index="index" item="key" open="(" separator="," close=")">
  273. #{key}
  274. </foreach>
  275. </if>
  276. <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
  277. <!-- 处理“开始时间”(数组第1位,如 createTime[0] = 2024-01-01 00:00:00) -->
  278. <if test="reqVO.createTime[0] != null">
  279. AND rdr.create_time &gt;= #{reqVO.createTime[0]}
  280. </if>
  281. <!-- 处理“结束时间”(数组第2位,如 createTime[1] = 2024-01-31 23:59:59) -->
  282. <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
  283. AND rdr.create_time &lt;= #{reqVO.createTime[1]}
  284. </if>
  285. </if>
  286. )
  287. SELECT
  288. id,
  289. dept_id,
  290. task_id
  291. FROM sorted_data
  292. WHERE rn = 1
  293. </select>
  294. <select id="selectStatusNumber" parameterType="cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO"
  295. resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.AllOrderResp">
  296. SELECT status AS status, COUNT(status) AS num FROM rq_iot_rd_daily_report a
  297. <where>
  298. a.deleted = 0
  299. <if test="reqVO.createTime[0] != null">
  300. AND a.create_time &gt;= #{reqVO.createTime[0]}
  301. </if>
  302. <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
  303. AND a.create_time &lt;= #{reqVO.createTime[1]}
  304. </if>
  305. <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
  306. AND a.dept_id IN
  307. <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
  308. #{key}
  309. </foreach>
  310. </if>
  311. </where>
  312. GROUP BY status
  313. </select>
  314. </mapper>