Files
fad_oa/ruoyi-oa/src/main/resources/mapper/oa/SysOaTaskMapper.xml

423 lines
16 KiB
XML
Raw Normal View History

2024-07-07 21:09:28 +08:00
<?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="com.ruoyi.oa.mapper.SysOaTaskMapper">
2025-03-30 19:43:55 +08:00
<resultMap type="com.ruoyi.oa.domain.vo.SysOaTaskVo" id="SysOaTaskResult">
2024-07-07 21:09:28 +08:00
<result property="taskId" column="task_id"/>
<result property="projectId" column="project_id"/>
<result property="taskTitle" column="task_title"/>
<result property="taskType" column="task_type"/>
<result property="taskGrade" column="task_grade"/>
<result property="collaborator" column="collaborator"/>
<result property="beginTime" column="begin_time"/>
<result property="finishTime" column="finish_time"/>
<result property="content" column="content"/>
<result property="remark" column="remark"/>
2025-03-30 19:43:55 +08:00
<result property="state" column="state"/>
<result property="status" column="status"/>
<result property="taskRank" column="task_rank"/>
<result property="ownRank" column="own_rank"/>
<result property="timeGap" column="time_gap"/>
<result property="tempTime" column="temp_time"/>
2024-07-07 21:09:28 +08:00
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
2025-03-30 19:43:55 +08:00
<result property="completedTime" column="completed_time"/>
<result property="createUserNickName" column="createUserNickName"/>
<result property="workerNickName" column="workerNickName"/>
<result property="postponements" column="postponements"/>
2025-05-25 18:15:07 +08:00
<result property="accessory" column="accessory"/>
<result property="projectName" column="project_name"/>
<result property="projectNum" column="project_num"/>
<result property="overDays" column="overDays"/>
<result property="itemId" column="item_id"/>
<result property="files" column="files"/>
<collection property="taskItemVoList"
ofType="com.ruoyi.oa.domain.vo.SysOaTaskItemVo"
javaType="list"
select="selectTaskItemsByTaskId"
column="task_id"/>
2024-07-07 21:09:28 +08:00
</resultMap>
<!--先删除数据-->
<delete id="deleteSysOaTaskByProjectId" parameterType="Long">
delete from sys_oa_task where project_id = #{projectId}
</delete>
<select id="selectListVoPage" resultType="com.ruoyi.oa.domain.vo.SysOaTaskVo">
2025-07-30 21:10:17 +08:00
SELECT sot.task_id,
sot.project_id,
sot.create_user_id,
sot.worker_id,
sot.task_title,
sot.task_type,
sot.task_grade,
sot.collaborator,
sot.finish_time,
sot.temp_time,
sot.begin_time,
sot.origin_finish_time,
sot.postponements,
sot.completed_time,
sot.rank_number,
sot.remark,
sot.task_rank,
sot.state,
sot.time_gap,
sot.status,
sot.accessory,
sot.create_by,
sot.create_time,
sot.update_by,
sot.update_time,
sot.del_flag,
sot.own_rank,
sot.track_id,
stepAgg.tab_node AS tabNode,
stepAgg.first_level_node AS firstLevelNode,
stepAgg.second_level_node AS secondLevelNode,
2025-07-30 21:10:17 +08:00
sop.project_name,
sop.project_num,
sop.project_code,
su1.nick_name AS createUserNickName,
su2.nick_name AS workerNickName,
sd.dept_name AS deptName,
2025-07-30 21:10:17 +08:00
IF(
sot.completed_time IS NULL,
IF(
-- 子查询取第一个未完成 item 的 end_time
(
SELECT a.end_time
FROM sys_oa_task_item a
WHERE a.task_id = sot.task_id
AND a.completed_time IS NULL
LIMIT 1
) IS NOT NULL,
2025-07-30 21:10:17 +08:00
-- 如果子查询有值,就用它来算超期天数
DATEDIFF(
NOW(),
(
SELECT a.end_time
FROM sys_oa_task_item a
WHERE a.task_id = sot.task_id
AND a.completed_time IS NULL
LIMIT 1
)
),
-- 否则就退回到 sot.finish_time如果它也可能为 NULL可再加一层 IF 或 COALESCE
DATEDIFF(NOW(), sot.finish_time)
),
0
) AS overDays
2025-03-30 19:43:55 +08:00
FROM sys_oa_task sot
LEFT JOIN sys_user su1 ON su1.user_id = sot.create_user_id
LEFT JOIN sys_user su2 ON su2.user_id = sot.worker_id
LEFT JOIN sys_oa_project sop ON sop.project_id = sot.project_id
LEFT JOIN sys_dept sd ON sd.dept_id = su2.dept_id
LEFT JOIN oa_project_schedule_step stepAgg ON stepAgg.track_id = sot.track_id
2025-03-30 19:43:55 +08:00
${ew.getCustomSqlSegment}
</select>
<select id="selectDetailVoById" resultMap="SysOaTaskResult">
SELECT sot.task_id,
sot.project_id,
sot.create_user_id,
sot.worker_id,
sot.task_title,
sot.task_type,
sot.task_grade,
sot.accessory,
COALESCE(
sot.finish_time,
(SELECT a.end_time
2025-03-30 19:43:55 +08:00
FROM sys_oa_task_item a
WHERE a.task_id = sot.task_id
AND a.completed_time IS NULL
LIMIT 1)
) AS finish_time,
COALESCE(
sot.temp_time,
(SELECT a.temp_time
2025-03-30 19:43:55 +08:00
FROM sys_oa_task_item a
WHERE a.task_id = sot.task_id
AND a.completed_time IS NULL
LIMIT 1)
) AS temp_time,
sot.begin_time,
sot.origin_finish_time,
sot.postponements,
sot.completed_time,
sot.content,
su1.nick_name AS createUserNickName,
su2.nick_name AS workerNickName,
sot.rank_number,
sot.remark,
sot.task_rank,
sot.state,
sot.time_gap,
sot.status,
sot.create_by,
sot.create_time,
sot.update_by,
sot.update_time,
sot.del_flag,
sot.own_rank,
sop.project_name,
sop.project_num,
CASE
WHEN sot.completed_time IS NULL
THEN DATEDIFF(
NOW(),
COALESCE(
sot.finish_time,
(SELECT a.end_time
2025-03-30 19:43:55 +08:00
FROM sys_oa_task_item a
WHERE a.task_id = sot.task_id
AND a.completed_time IS NULL
LIMIT 1)
)
)
ELSE 0
END AS overDays
FROM sys_oa_task sot
LEFT JOIN sys_user su1 ON su1.user_id = sot.create_user_id
LEFT JOIN sys_user su2 ON su2.user_id = sot.worker_id
LEFT JOIN sys_oa_project sop ON sop.project_id = sot.project_id
WHERE sot.task_id = #{taskId}
2025-03-30 19:43:55 +08:00
AND sot.del_flag = '0'
</select>
2025-03-30 19:43:55 +08:00
<!-- 嵌套查询根据任务ID获取报工单元列表 -->
<select id="selectTaskItemsByTaskId" resultType="com.ruoyi.oa.domain.vo.SysOaTaskItemVo">
SELECT soti.item_id,
soti.content,
soti.sign_time,
soti.status,
soti.begin_time,
soti.completed_time,
soti.end_time,
soti.remark,
soti.files
FROM sys_oa_task_item soti
WHERE soti.task_id = #{task_id}
AND soti.del_flag = '0'
ORDER BY soti.create_time DESC
2025-03-30 19:43:55 +08:00
</select>
<select id="getMonthlyData"
parameterType="java.lang.String"
resultType="com.ruoyi.oa.domain.UserMonthlyData">
SELECT
-- 员工昵称
su.nick_name AS nickName,
-- 拼接多个项目名称
GROUP_CONCAT(DISTINCT sop.project_name SEPARATOR ',') AS projectName,
-- 计算 totalTasks
(
-- 1) status=0 属于当月 => 加1
SUM(
CASE
WHEN sot.status = 0
AND DATE_FORMAT(sot.begin_time, '%Y-%m') = #{month}
THEN 1
ELSE 0
END
)
+
-- 2) status=1 => 统计符合当月的子记录数量
COUNT(
CASE
WHEN sot.status = 1
AND DATE_FORMAT(soti.begin_time, '%Y-%m') = #{month}
THEN soti.item_id
END
)
) AS totalTasks,
-- 计算 completedTasks
(
-- status=0 当月 completed_time非空 => +1
SUM(
CASE
WHEN sot.status = 0
AND DATE_FORMAT(sot.begin_time, '%Y-%m') = #{month}
AND sot.completed_time IS NOT NULL
THEN 1
ELSE 0
END
)
+
-- status=1 => 统计子记录当月 且 sign_time非空
COUNT(
CASE
WHEN sot.status = 1
AND DATE_FORMAT(soti.begin_time, '%Y-%m') = #{month}
AND soti.sign_time IS NOT NULL
THEN soti.item_id
END
)
) AS completedTasks,
-- 计算 delayedTimes
(
-- status=0 当月 => 累加 sot.postponements
SUM(
CASE
WHEN sot.status = 0
AND DATE_FORMAT(sot.begin_time, '%Y-%m') = #{month}
THEN sot.postponements
ELSE 0
END
)
+
-- status=1 当月(子记录) => 同样加上 sot.postponements
SUM(
CASE
WHEN sot.status = 1
AND DATE_FORMAT(soti.begin_time, '%Y-%m') = #{month}
THEN sot.postponements
ELSE 0
END
)
) AS delayedTimes
FROM sys_oa_task sot
2025-03-30 19:43:55 +08:00
LEFT JOIN sys_oa_task_item soti
ON soti.task_id = sot.task_id
LEFT JOIN sys_user su
ON su.user_id = sot.worker_id
LEFT JOIN sys_oa_project sop
ON sop.project_id = sot.project_id
-- 只按用户分组 => 每个nickName合并为一行
GROUP BY su.user_id
</select>
<select id="queryPageListDocument" resultType="com.ruoyi.oa.domain.vo.SysOaTaskVo">
SELECT
sot.task_id,
sot.project_id,
sot.create_user_id,
sot.worker_id,
sot.task_title,
sot.task_type,
sot.task_grade,
sot.collaborator,
COALESCE(sot.finish_time, soti.end_time) AS finish_time,
COALESCE(sot.temp_time, soti.temp_time) AS temp_time,
sot.begin_time,
sot.origin_finish_time,
sot.postponements,
sot.completed_time,
sot.content,
sot.accessory,
2025-03-30 19:43:55 +08:00
sot.rank_number,
sot.remark,
sot.task_rank,
sot.state,
sot.time_gap,
sot.status,
sot.create_by,
sot.create_time,
sot.update_by,
sot.update_time,
sot.del_flag,
sot.own_rank,
sop.project_name,
soti.item_id,
sop.project_num,
su1.nick_name AS createUserNickName,
su2.nick_name AS workerNickName,
CASE
WHEN sot.completed_time IS NULL
THEN DATEDIFF(NOW(), COALESCE(sot.finish_time, soti.end_time))
ELSE 0
END AS overDays,
soti.files
2025-03-30 19:43:55 +08:00
FROM sys_oa_task_user sotu
left join sys_oa_task sot on sot.task_id = sotu.task_id
LEFT JOIN sys_user su1 ON su1.user_id = sot.create_user_id
LEFT JOIN sys_user su2 ON su2.user_id = sot.worker_id
LEFT JOIN sys_oa_project sop ON sop.project_id = sot.project_id
2025-03-30 19:43:55 +08:00
LEFT JOIN sys_oa_task_item soti
ON soti.task_id = sot.task_id
AND soti.completed_time IS NULL
${ew.getCustomSqlSegment}
2025-03-30 19:43:55 +08:00
</select>
<select id="listDocumentProject" resultType="com.ruoyi.oa.domain.vo.SysOaTaskVo">
SELECT
sot.create_user_id,
sot.worker_id,
sop.accessory,
2025-03-30 19:43:55 +08:00
su1.nick_name AS createUserNickName,
su2.nick_name AS workerNickName,
soti.files
2025-03-30 19:43:55 +08:00
FROM sys_oa_task sot
LEFT JOIN sys_user su1 ON su1.user_id = sot.create_user_id
LEFT JOIN sys_user su2 ON su2.user_id = sot.worker_id
LEFT JOIN sys_oa_project sop ON sop.project_id = sot.project_id
LEFT JOIN sys_oa_task_item soti ON soti.task_id = sot.task_id
WHERE
sot.project_id = #{projectId}
AND sot.del_flag = '0'
</select>
2025-07-09 18:50:26 +08:00
<select id="queryListPlus" parameterType="com.ruoyi.oa.domain.bo.SysOaTaskBo" resultType="com.ruoyi.oa.domain.vo.SysOaTaskVo">
SELECT
task_id AS taskId,
project_id AS projectId,
task_title AS taskTitle,
task_type AS taskType,
task_grade AS taskGrade,
collaborator AS collaborator,
begin_time AS beginTime,
finish_time AS finishTime,
content AS content,
accessory AS accessory,
remark AS remark,
create_by AS createBy,
create_time AS createTime,
create_user_id AS createUserId,
worker_id AS workerId,
origin_finish_time AS originFinishTime,
postponements AS postponements,
rank_number AS rankNumber,
completed_time AS completedTime,
state AS state,
task_rank AS taskRank,
own_rank AS ownRank,
status AS status,
time_gap AS timeGap,
temp_time AS tempTime
FROM sys_oa_task
<where>
<if test="state != null">
state = #{state}
</if>
</where>
</select>
2024-07-07 21:09:28 +08:00
</mapper>