fix: 修复流水线子任务完成后未通知下一组部门负责人的问题
1. 使用子任务的任务类型配置(allowed_dept_ids)获取目标部门 2. 递归向上查找父级类型的部门配置 3. 发送通知给所有相关部门负责人
This commit is contained in:
parent
6579bc2b25
commit
bd98e4a3ab
@ -37,6 +37,7 @@ public class TaskItemService {
|
||||
private final ConfigService configService;
|
||||
private final ExternalAssetService externalAssetService;
|
||||
private final SystemConfigService systemConfigService;
|
||||
private final com.designhub.mapper.TaskTypeMapper taskTypeMapper;
|
||||
|
||||
/**
|
||||
* 获取可接单的子任务列表
|
||||
@ -504,27 +505,38 @@ public class TaskItemService {
|
||||
result.put("unlockedCount", nextGroupItems.size());
|
||||
|
||||
// 发送通知给接单部门负责人
|
||||
if (mainTask.getReceiverDeptId() != null) {
|
||||
com.designhub.entity.Department receiverDept = departmentMapper.selectById(mainTask.getReceiverDeptId());
|
||||
if (receiverDept != null && receiverDept.getLeaderId() != null) {
|
||||
Notification notification = new Notification();
|
||||
notification.setReceiverId(receiverDept.getLeaderId());
|
||||
notification.setNotificationType("task_approval");
|
||||
notification.setTitle("新子任务组待审核");
|
||||
notification.setContent("任务《" + mainTask.getTitle() + "》第 " + nextGroupNo + " 组共 " +
|
||||
nextGroupItems.size() + " 个子任务已解锁,请审核并分配!");
|
||||
notification.setRelatedId(item.getTaskId());
|
||||
notification.setRelatedType("task");
|
||||
notification.setPriority(2); // 重要
|
||||
notification.setPushDingtalk(1); // 推送到钉钉
|
||||
notificationService.sendNotification(notification);
|
||||
|
||||
log.info("已通知接单部门负责人(ID: {})审核第 {} 组子任务",
|
||||
receiverDept.getLeaderId(), nextGroupNo);
|
||||
// 从子任务的任务类型配置中获取allowed_dept_ids
|
||||
Set<Long> notifiedLeaderIds = new java.util.HashSet<>();
|
||||
for (TaskItem nextItem : nextGroupItems) {
|
||||
Long targetDeptId = getTargetDeptIdFromTaskType(nextItem.getTaskTypeId());
|
||||
if (targetDeptId != null) {
|
||||
com.designhub.entity.Department receiverDept = departmentMapper.selectById(targetDeptId);
|
||||
if (receiverDept != null && receiverDept.getLeaderId() != null
|
||||
&& !notifiedLeaderIds.contains(receiverDept.getLeaderId())) {
|
||||
notifiedLeaderIds.add(receiverDept.getLeaderId());
|
||||
|
||||
Notification notification = new Notification();
|
||||
notification.setReceiverId(receiverDept.getLeaderId());
|
||||
notification.setNotificationType("task_approval");
|
||||
notification.setTitle("新子任务组待审核");
|
||||
notification.setContent("任务《" + mainTask.getTitle() + "》第 " + nextGroupNo + " 组共 " +
|
||||
nextGroupItems.size() + " 个子任务已解锁,请审核并分配!");
|
||||
notification.setRelatedId(item.getTaskId());
|
||||
notification.setRelatedType("task");
|
||||
notification.setPriority(2); // 重要
|
||||
notification.setPushDingtalk(1); // 推送到钉钉
|
||||
notificationService.sendNotification(notification);
|
||||
|
||||
log.info("已通知接单部门负责人(部门: {}, 负责人ID: {})审核第 {} 组子任务",
|
||||
receiverDept.getDeptName(), receiverDept.getLeaderId(), nextGroupNo);
|
||||
}
|
||||
} else {
|
||||
log.warn("子任务 {} 的任务类型未配置接单部门", nextItem.getItemNo());
|
||||
}
|
||||
}
|
||||
|
||||
log.info("第 {} 组 {} 个子任务已解锁,等待接单部门负责人审核", nextGroupNo, nextGroupItems.size());
|
||||
log.info("第 {} 组 {} 个子任务已解锁,等待接单部门负责人审核,已通知 {} 个部门负责人",
|
||||
nextGroupNo, nextGroupItems.size(), notifiedLeaderIds.size());
|
||||
} else {
|
||||
log.info("没有更多子任务组需要解锁");
|
||||
}
|
||||
@ -998,4 +1010,39 @@ public class TaskItemService {
|
||||
|
||||
return new java.util.ArrayList<>(groupMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从任务类型配置中获取目标接单部门ID
|
||||
* 如果当前类型未配置,则递归向上查找父级类型的配置
|
||||
*/
|
||||
private Long getTargetDeptIdFromTaskType(Long taskTypeId) {
|
||||
if (taskTypeId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
com.designhub.entity.TaskType taskType = taskTypeMapper.selectById(taskTypeId);
|
||||
if (taskType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 如果当前类型配置了allowed_dept_ids,返回第一个部门ID
|
||||
String allowedDeptIds = taskType.getAllowedDeptIds();
|
||||
if (allowedDeptIds != null && !allowedDeptIds.isEmpty()) {
|
||||
try {
|
||||
String[] deptIds = allowedDeptIds.split(",");
|
||||
if (deptIds.length > 0) {
|
||||
return Long.parseLong(deptIds[0].trim());
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("解析allowed_dept_ids失败: {}", allowedDeptIds, e);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果当前类型未配置,递归查找父级
|
||||
if (taskType.getParentId() != null) {
|
||||
return getTargetDeptIdFromTaskType(taskType.getParentId());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user