| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="cn.iocoder.yudao.module.pms.dal.mysql.iotrddailyreport.IotRdDailyReportMapper">
- <!-- 基础结果映射 -->
- <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.pms.dal.dataobject.iotrddailyreport.IotRdDailyReportDO">
- <!-- 根据实际字段配置 -->
- <id column="id" property="id" />
- <result column="dept_id" property="deptId" />
- <result column="project_id" property="projectId" />
- <result column="task_id" property="taskId" />
- <result column="rd_status" property="rdStatus" />
- <result column="construction_start_date" property="constructionStartDate" />
- <result column="construction_end_date" property="constructionEndDate" />
- <!-- 其他字段映射 -->
- <result column="project_classification" property="projectClassification" />
- <result column="daily_power_usage" property="dailyPowerUsage" />
- <!-- 其他字段映射 -->
- <result column="non_production_time" property="nonProductionTime" />
- <result column="rd_npt_reason" property="rdNptReason" />
- <result column="production_status" property="productionStatus" />
- <result column="next_plan" property="nextPlan" />
- <result column="personnel" property="personnel" />
- <!-- 其他字段映射 -->
- <result column="remark" property="remark" />
- <result column="status" property="status" />
- <result column="creator" property="creator" />
- <result column="create_time" property="createTime" />
- <result column="updater" property="updater" />
- <result column="update_time" property="updateTime" />
- </resultMap>
- <select id="selectListGrouped" resultMap="BaseResultMap"
- parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
- SELECT t1.*, g.min_start_date
- FROM rq_iot_rd_daily_report t1
- INNER JOIN (
- SELECT
- rd_status,
- MIN(construction_start_date) as min_start_date
- FROM rq_iot_rd_daily_report
- <where>
- <if test="reqVO.deptId != null">
- AND dept_id = #{reqVO.deptId}
- </if>
- <if test="reqVO.projectId != null">
- AND project_id = #{reqVO.projectId}
- </if>
- <if test="reqVO.taskId != null">
- AND task_id = #{reqVO.taskId}
- </if>
- </where>
- GROUP BY rd_status
- ) g ON t1.rd_status = g.rd_status
- AND t1.construction_start_date = g.min_start_date
- AND t1.rd_status <![CDATA[<>]]> ''
- WHERE NOT EXISTS (
- SELECT 1 FROM rq_iot_rd_daily_report t2
- WHERE t2.rd_status = t1.rd_status
- AND t2.construction_start_date < t1.construction_start_date
- <if test="reqVO.deptId != null">
- AND t2.dept_id = #{reqVO.deptId}
- </if>
- <if test="reqVO.projectId != null">
- AND t2.project_id = #{reqVO.projectId}
- </if>
- <if test="reqVO.taskId != null">
- AND t2.task_id = #{reqVO.taskId}
- </if>
- )
- <if test="reqVO.deptId != null">
- AND t1.dept_id = #{reqVO.deptId}
- </if>
- <if test="reqVO.projectId != null">
- AND t1.project_id = #{reqVO.projectId}
- </if>
- <if test="reqVO.taskId != null">
- AND t1.task_id = #{reqVO.taskId}
- </if>
- ORDER BY g.min_start_date ASC
- </select>
- <select id="taskConstructionPeriod" resultType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportTaskPeriodVO">
- SELECT
- task_id taskId,
- MIN(construction_start_date) AS startDate,
- MIN(CASE WHEN rd_status = 'wg' THEN construction_start_date ELSE NULL END) AS endDate
- FROM rq_iot_rd_daily_report
- WHERE deleted = b'0'
- GROUP BY task_id;
- </select>
- <select id="rdWellNameDailyReports" resultMap="BaseResultMap"
- parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
- SELECT
- rdr.*
- FROM
- rq_iot_rd_daily_report rdr
- INNER JOIN system_dept d ON d.id = rdr.dept_id
- LEFT JOIN system_dept pd ON pd.id = d.parent_id
- WHERE
- rdr.deleted = 0
- AND rdr.dept_id IS NOT NULL
- <if test="deptIds != null and deptIds.size > 0">
- AND rdr.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="projectIds != null and projectIds.size > 0">
- AND rdr.project_id IN
- <foreach collection="projectIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="taskIds != null and taskIds.size > 0">
- AND rdr.task_id IN
- <foreach collection="taskIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
- <!-- 处理“开始时间”(数组第1位,如 createTime[0] = 2024-01-01 00:00:00) -->
- <if test="reqVO.createTime[0] != null">
- AND rdr.create_time >= #{reqVO.createTime[0]}
- </if>
- <!-- 处理“结束时间”(数组第2位,如 createTime[1] = 2024-01-31 23:59:59) -->
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND rdr.create_time <= #{reqVO.createTime[1]}
- </if>
- </if>
- ORDER BY
- COALESCE(pd.sort, 999999) ASC,
- d.sort ASC,
- DATE(rdr.create_time) DESC;
- </select>
- <select id="rdWellNameDailyReportsGroupIds" resultMap="BaseResultMap"
- parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
- WITH sorted_data AS (
- SELECT
- rdr.id,
- rdr.dept_id,
- rdr.task_id,
- ROW_NUMBER() OVER (
- PARTITION BY rdr.dept_id, rdr.task_id
- ORDER BY
- COALESCE(pd.sort, 999999) DESC, -- 反转:ASC -> DESC
- d.sort DESC, -- 反转:ASC -> DESC
- rdr.task_id ASC, -- 反转:DESC -> ASC
- DATE(rdr.create_time) ASC -- 反转:DESC -> ASC
- ) AS rn
- FROM
- rq_iot_rd_daily_report rdr
- INNER JOIN system_dept d ON d.id = rdr.dept_id
- LEFT JOIN system_dept pd ON pd.id = d.parent_id
- WHERE
- rdr.deleted = 0
- AND rdr.dept_id IS NOT NULL
- <if test="deptIds != null and deptIds.size > 0">
- AND rdr.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="projectIds != null and projectIds.size > 0">
- AND rdr.project_id IN
- <foreach collection="projectIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="taskIds != null and taskIds.size > 0">
- AND rdr.task_id IN
- <foreach collection="taskIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
- <!-- 处理“开始时间”(数组第1位,如 createTime[0] = 2024-01-01 00:00:00) -->
- <if test="reqVO.createTime[0] != null">
- AND rdr.create_time >= #{reqVO.createTime[0]}
- </if>
- <!-- 处理“结束时间”(数组第2位,如 createTime[1] = 2024-01-31 23:59:59) -->
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND rdr.create_time <= #{reqVO.createTime[1]}
- </if>
- </if>
- )
- SELECT
- id,
- dept_id,
- task_id
- FROM sorted_data
- WHERE rn = 1
- </select>
- <select id="rdDeptDailyReports" resultMap="BaseResultMap"
- parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
- SELECT
- rdr.*
- FROM
- rq_iot_rd_daily_report rdr
- INNER JOIN system_dept d ON d.id = rdr.dept_id
- LEFT JOIN system_dept pd ON pd.id = d.parent_id
- WHERE
- rdr.deleted = 0
- AND rdr.dept_id IS NOT NULL
- <if test="deptIds != null and deptIds.size > 0">
- AND rdr.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="projectIds != null and projectIds.size > 0">
- AND rdr.project_id IN
- <foreach collection="projectIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="taskIds != null and taskIds.size > 0">
- AND rdr.task_id IN
- <foreach collection="taskIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
- <!-- 处理“开始时间”(数组第1位,如 createTime[0] = 2024-01-01 00:00:00) -->
- <if test="reqVO.createTime[0] != null">
- AND rdr.create_time >= #{reqVO.createTime[0]}
- </if>
- <!-- 处理“结束时间”(数组第2位,如 createTime[1] = 2024-01-31 23:59:59) -->
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND rdr.create_time <= #{reqVO.createTime[1]}
- </if>
- </if>
- ORDER BY
- rdr.task_id DESC,
- COALESCE(pd.sort, 999999) ASC,
- d.sort ASC,
- DATE(rdr.create_time) DESC;
- </select>
- <select id="rdDeptDailyReportsGroupIds" resultMap="BaseResultMap"
- parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO">
- WITH sorted_data AS (
- SELECT
- rdr.id,
- rdr.dept_id,
- rdr.task_id,
- ROW_NUMBER() OVER (
- PARTITION BY rdr.dept_id, rdr.task_id
- ORDER BY
- rdr.task_id ASC, -- 反转:DESC -> ASC
- COALESCE(pd.sort, 999999) DESC, -- 反转:ASC -> DESC
- d.sort DESC, -- 反转:ASC -> DESC
- DATE(rdr.create_time) ASC -- 反转:DESC -> ASC
- ) AS rn
- FROM
- rq_iot_rd_daily_report rdr
- INNER JOIN system_dept d ON d.id = rdr.dept_id
- LEFT JOIN system_dept pd ON pd.id = d.parent_id
- WHERE
- rdr.deleted = 0
- AND rdr.dept_id IS NOT NULL
- <if test="deptIds != null and deptIds.size > 0">
- AND rdr.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="projectIds != null and projectIds.size > 0">
- AND rdr.project_id IN
- <foreach collection="projectIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="taskIds != null and taskIds.size > 0">
- AND rdr.task_id IN
- <foreach collection="taskIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
- <!-- 处理“开始时间”(数组第1位,如 createTime[0] = 2024-01-01 00:00:00) -->
- <if test="reqVO.createTime[0] != null">
- AND rdr.create_time >= #{reqVO.createTime[0]}
- </if>
- <!-- 处理“结束时间”(数组第2位,如 createTime[1] = 2024-01-31 23:59:59) -->
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND rdr.create_time <= #{reqVO.createTime[1]}
- </if>
- </if>
- )
- SELECT
- id,
- dept_id,
- task_id
- FROM sorted_data
- WHERE rn = 1
- </select>
- <select id="selectStatusNumber" parameterType="cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.AllOrderResp">
- SELECT status AS status, COUNT(status) AS num FROM rq_iot_rd_daily_report a
- <where>
- a.deleted = 0
- <if test="reqVO.createTime[0] != null">
- AND a.create_time >= #{reqVO.createTime[0]}
- </if>
- <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
- AND a.create_time <= #{reqVO.createTime[1]}
- </if>
- <if test="reqVO.deptIds != null and reqVO.deptIds.size > 0">
- AND a.dept_id IN
- <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- </where>
- GROUP BY status
- </select>
- </mapper>
|