feat(examine): 更新考核任务模板

- 在 ExamineConfigMapper 和 ExamineDetailMapper 中添加了按任务 ID 删除记录的方法
- 更新了 ExamineTaskMapper 和 ExamineTemplateMapper 的查询语句,增加了模板类型和名称字段
- 修改了 TaskServiceImpl 中的 updateTask 方法,以支持更换考核模板时自动更新指标项
dev_1.2.1
chenhao 2025-04-25 17:55:27 +08:00
parent d010449773
commit c03486036f
11 changed files with 77 additions and 24 deletions

View File

@ -86,5 +86,7 @@ public interface ExamineConfigMapper {
List<ExamineConfig> list(ExamineConfig examineConfig);
void deleteByTaskId(Integer taskId);
}

View File

@ -78,5 +78,7 @@ public interface ExamineDetailMapper {
void deleteByExamineId(List<Integer> collect);
List<ExamineDetail> listByExamineId(List<Integer> idList);
void deleteByTaskId(Integer taskId);
}

View File

@ -72,6 +72,7 @@ public interface ExamineDetailService {
void deleteByExamineId( List<Integer> collect);
void deleteByTaskId( Integer taskId);
List<ExamineDetail> listByExamineId(List<Integer> taskId);
}

View File

@ -198,6 +198,13 @@ public class ExamineDetailServiceImpl implements ExamineDetailService {
examineDetailMapper.deleteByExamineId(collect);
}
@Override
public void deleteByTaskId(Integer taskId) {
examineDetailMapper.deleteByTaskId(taskId);
}
@Override
public List<ExamineDetail> listByExamineId(List<Integer> idList) {
return examineDetailMapper.listByExamineId(idList);

View File

@ -44,5 +44,7 @@ public class ExamineTask implements Serializable {
private Integer year;
private Integer templateId;
private String templateType;
private String templateName;
}

View File

@ -1,9 +1,11 @@
package tech.unissense.pms.business.examine.task.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.unissense.pms.business.examine.config.domain.ExamineConfig;
import tech.unissense.pms.business.examine.config.enums.ReviewTypeEnum;
import tech.unissense.pms.business.examine.config.mapper.ExamineConfigMapper;
@ -31,6 +33,7 @@ import java.util.stream.Collectors;
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class TaskServiceImpl implements TaskService {
@Autowired
@ -100,6 +103,22 @@ public class TaskServiceImpl implements TaskService {
@Override
public ExamineTask updateTask(ExamineTask updatedTask) {
//如果模板变化 删除原有的指标项 重新生成
ExamineTask examineTask = examineTaskDao.queryById(updatedTask.getId());
if (!examineTask.getTemplateId().equals(updatedTask.getTemplateId())) {
//对应考核指标详情删除
detailService.deleteByTaskId(updatedTask.getId());
//对应考核指标项删除
examineConfigMapper.deleteByTaskId(updatedTask.getId());
//重新生成考核指标项
ExamineConfig examineConfig = new ExamineConfig();
examineConfig.setTemplateId(updatedTask.getTemplateId());
List<ExamineConfig> list = examineConfigMapper.list(examineConfig);
list.forEach(item -> {
item.setExamineTaskId(updatedTask.getId());
});
examineConfigMapper.insertBatch(list);
}
examineTaskDao.updateTask(updatedTask);
List<Integer> userIdList = updatedTask.getUserIdList();
@ -114,7 +133,11 @@ public class TaskServiceImpl implements TaskService {
existingUsers.stream()
.filter(user -> !userIdList.contains(user.getUserId()))
.forEach(user -> userMapper.deleteById(user.getId()));
//删除对应考核指标详情
List<Integer> examineIdList = existingUsers.stream().filter(user -> !userIdList.contains(user.getUserId())).map(ExamineUser::getId).collect(Collectors.toList());
if (CollUtil.isNotEmpty(examineIdList)) {
detailService.deleteByExamineId(examineIdList);
}
// 2. 添加新的用户记录(只插入那些不在现有用户中的用户)
userIdList.stream()
.filter(userId -> !existingUserIds.contains(userId))

View File

@ -33,11 +33,13 @@ public class ExamineTemplate {
*/
private Integer createBy;
private String createByName;
/**
*
*/
private Integer updateBy;
private String updateByName;
/**
*
*/

View File

@ -181,6 +181,9 @@
from pms_examine_config
where id = #{id}
</delete>
<delete id="deleteByTaskId">
delete from pms_examine_config where examine_task_id = #{examineTaskId}
</delete>
</mapper>

View File

@ -142,6 +142,10 @@
#{item}
</foreach>
</delete>
<delete id="deleteByTaskId">
delete
from pms_examine_detail where config_id in (select id from pms_examine_config where examine_task_id=#{taskId});
</delete>
</mapper>

View File

@ -11,57 +11,58 @@
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="endTime" column="end_time" jdbcType="TIMESTAMP"/>
<result property="taskEditFlag" column="task_edit_flag" jdbcType="BOOLEAN"/>
<result property="templateId" column="template_id" jdbcType="BOOLEAN"/>
</resultMap>
<!-- 新增任务 -->
<insert id="addTask" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
INSERT INTO pms_examine_task (task_name, people_number, people_number_detail, task_status, create_time, end_time, year)
VALUES (#{taskName}, #{peopleNumber}, #{peopleNumberDetail}, #{taskStatus}, #{createTime}, #{endTime}, #{year})
INSERT INTO pms_examine_task (task_name, people_number, people_number_detail, task_status, create_time, end_time, year,template_id)
VALUES (#{taskName}, #{peopleNumber}, #{peopleNumberDetail}, #{taskStatus}, #{createTime}, #{endTime}, #{year},#{templateId})
</insert>
<select id="getTasks" resultMap="ExamineTaskMap">
SELECT * FROM pms_examine_task
SELECT t1.*,t2.template_type,t2.template_name FROM pms_examine_task t1 left join pms_examine_template t2 on t1.template_id=t2.id
<where>
<if test="taskName != null and taskName != ''">
AND task_name LIKE CONCAT('%', #{taskName}, '%')
AND t1.task_name LIKE CONCAT('%', #{taskName}, '%')
</if>
<if test="taskStatus != null">
<choose>
<when test="taskStatus == 2">
AND end_time &lt; NOW()
AND t1.end_time &lt; NOW()
</when>
<when test="taskStatus == 0">
AND end_time > CURRENT_TIMESTAMP
AND t1.end_time > CURRENT_TIMESTAMP
</when>
</choose>
</if>
<if test="year != null">
AND year = #{year}
AND t1.year = #{year}
</if>
</where>
order by create_time desc
</select>
<select id="listTask" resultMap="ExamineTaskMap">
select distinct t1.id,t1.task_name, t1.people_number,t1.task_edit_flag, t1.people_number_detail, t1.task_status, t1.create_time, t1.end_time
select distinct t1.id,t1.task_name, t1.people_number,t1.task_edit_flag, t1.people_number_detail, t1.task_status, t1.create_time, t1.end_time,t1.template_id
from pms_examine_task t1
left join pms_examine_user t2 on t1.id = t2.task_id
left join sys_user t3 on t2.user_id = t3.user_id
<where>
<if test="taskName != null and taskName != ''">
AND task_name LIKE CONCAT('%', #{taskName}, '%')
AND t1.task_name LIKE CONCAT('%', #{taskName}, '%')
</if>
<if test="taskStatus != null">
<choose>
<when test="taskStatus == 2">
AND end_time &lt; NOW()
AND t1.end_time &lt; NOW()
</when>
<when test="taskStatus == 0">
AND end_time > CURRENT_TIMESTAMP
AND t1.end_time > CURRENT_TIMESTAMP
</when>
</choose>
</if>
<if test="year != null">
AND year = #{year}
AND t1.year = #{year}
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
@ -69,8 +70,9 @@
order by t1.create_time desc
</select>
<select id="queryById" resultMap="ExamineTaskMap">
SELECT * FROM pms_examine_task
WHERE id = #{id}
SELECT t1.*,t2.template_name,t2.template_type FROM pms_examine_task t1
left join pms_examine_template t2 on t1.template_id=t2.id
WHERE t1.id = #{id}
</select>
<select id="listTaskSelf" resultType="tech.unissense.pms.business.examine.task.domain.ExamineTaskDto">
select t1.examine_status_self,t1.id as examine_id,
@ -90,6 +92,7 @@
<if test="createTime != null">create_time = #{createTime},</if>
<if test="endTime != null">end_time = #{endTime},</if>
<if test="year != null">year = #{year},</if>
<if test="templateId != null">template_id = #{templateId},</if>
</set>
WHERE id = #{id}
</update>

View File

@ -20,29 +20,33 @@
<!--通过实体作为筛选条件查询-->
<select id="queryAll" resultMap="ExamineTemplateMap">
select
<include refid="Base_Column_List"/>
from pms_examine_template
t1.id, t1.template_name, t1.template_type, t1.create_by, t1.update_by, t1.update_time, t1.create_time,
t2.nick_name as create_by_name,
t3.nick_name as update_by_name
from pms_examine_template t1
left join sys_user t2 on t1.create_by=t2.user_id
left join sys_user t3 on t1.update_by=t3.user_id
<where>
<if test="id != null">
and id = #{id}
and t1.id = #{id}
</if>
<if test="templateName != null and templateName != ''">
and template_name = #{templateName}
and t1.template_name = #{templateName}
</if>
<if test="templateType != null and templateType != ''">
and template_type = #{templateType}
and t1.template_type = #{templateType}
</if>
<if test="createBy != null">
and create_by = #{createBy}
and t1.create_by = #{createBy}
</if>
<if test="updateBy != null">
and update_by = #{updateBy}
and t1.update_by = #{updateBy}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
and t1.update_time = #{updateTime}
</if>
<if test="createTime != null">
and create_time = #{createTime}
and t1.create_time = #{createTime}
</if>
</where>
</select>