修复三个任务相关问题 1. 修复驳回任务重新编辑时数据丢失问题 - loadTaskForEdit正确加载流水线任务子任务数据 - 加载预览图和指定设计师信息 2. 同部门多设计师时自动拆分子任务并行 - 分组键改为部门+设计师ID组合 - 不同设计师的任务自动拆分为不同子任务 3. 修复驳回任务重新发布后审核不到的问题 - updatePipelineTask在initApprovalStatus后再次保存任务 - 确保审核状态和审核人ID正确保存到数据库

This commit is contained in:
Your Name 2026-01-14 17:56:28 +08:00
parent c9cd8e3f78
commit 0030233062
2 changed files with 70 additions and 22 deletions

View File

@ -356,10 +356,11 @@ public class TaskService {
taskMapper.insert(task);
log.info("主任务创建成功,ID: {}, 任务编号: {}", task.getId(), task.getTaskNo());
// **步骤1:按接单部门自动分组**
// 遍历任务类型列表,根据接单部门分组
// **步骤1:按接单部门和设计师自动分组**
// 遍历任务类型列表,根据接单部门和设计师分组
// 规则:同一部门内如果指定了不同的设计师,也需要拆分为不同的子任务
int currentGroupNo = 1;
String lastDeptKey = null;
String lastGroupKey = null; // 格式:deptKey_receiverId
for (int i = 0; i < dto.getItems().size(); i++) {
com.designhub.dto.PipelineTaskDTO.TaskItemDTO itemDto = dto.getItems().get(i);
@ -386,28 +387,35 @@ public class TaskService {
}
}
// 🔥 构建分组键:部门 + 设计师(如果指定了设计师)
String currentGroupKey;
if (itemDto.getReceiverId() != null) {
// 如果指定了设计师,分组键 = 部门_设计师ID
currentGroupKey = (currentDeptKey != null ? currentDeptKey : "null") + "_" + itemDto.getReceiverId();
log.info("任务类型 {} 指定了设计师 {},分组键: {}", demandType.getName(), itemDto.getReceiverId(), currentGroupKey);
} else {
// 没有指定设计师,分组键 = 部门_0
currentGroupKey = (currentDeptKey != null ? currentDeptKey : "null") + "_0";
}
// 判断是否需要创建新分组
boolean needNewGroup = false;
if (i > 0) {
// 如果当前或上一个的部门配置为 null,则必须分组
if (currentDeptKey == null || lastDeptKey == null) {
needNewGroup = true;
}
// 如果两者都不为 null,则比较是否相同
else if (!currentDeptKey.equals(lastDeptKey)) {
// 如果分组键不同,则需要创建新分组
if (lastGroupKey == null || !lastGroupKey.equals(currentGroupKey)) {
needNewGroup = true;
}
}
if (needNewGroup) {
currentGroupNo++;
log.info("检测到接单部门变化,创建新分组: groupNo={}, 前一部门={}, 当前部门={}",
currentGroupNo, lastDeptKey, currentDeptKey);
log.info("检测到分组变化,创建新分组: groupNo={}, 前一分组键={}, 当前分组键={}",
currentGroupNo, lastGroupKey, currentGroupKey);
}
// 记录当前分组号(临时存储在sortOrder字段,稍后会恢复)
itemDto.setSortOrder(currentGroupNo * 1000 + i); // 高位存group_no,低位存原始顺序
lastDeptKey = currentDeptKey;
lastGroupKey = currentGroupKey;
}
log.info("分组完成,共 {} 个子任务组", currentGroupNo);
@ -1300,6 +1308,12 @@ public class TaskService {
// 重新初始化审核状态并发送通知
initApprovalStatus(existTask);
// 再次保存任务,因为initApprovalStatus修改了approvalStatus、currentApproverId等字段
taskMapper.updateById(existTask);
log.info("任务审核状态已重新初始化: taskId={}, approvalStatus={}, currentApproverId={}",
existTask.getId(), existTask.getApprovalStatus(), existTask.getCurrentApproverId());
sendApprovalNotification(existTask);
log.info("流水线任务更新成功: taskId={}, userId={}", id, userId);
@ -1309,9 +1323,10 @@ public class TaskService {
* 为更新操作创建流水线子任务(复用createPipelineTask的子任务创建逻辑)
*/
private void createPipelineTaskItemsForUpdate(Task mainTask, com.designhub.dto.PipelineTaskDTO dto) {
// **步骤1:按接单部门自动分组**
// **步骤1:按接单部门和设计师自动分组**
// 规则:同一部门内如果指定了不同的设计师,也需要拆分为不同的子任务
int currentGroupNo = 1;
String lastDeptKey = null;
String lastGroupKey = null; // 格式:deptKey_receiverId
for (int i = 0; i < dto.getItems().size(); i++) {
com.designhub.dto.PipelineTaskDTO.TaskItemDTO itemDto = dto.getItems().get(i);
@ -1331,22 +1346,33 @@ public class TaskService {
}
}
// 🔥 构建分组键:部门 + 设计师(如果指定了设计师)
String currentGroupKey;
if (itemDto.getReceiverId() != null) {
// 如果指定了设计师,分组键 = 部门_设计师ID
currentGroupKey = (currentDeptKey != null ? currentDeptKey : "null") + "_" + itemDto.getReceiverId();
} else {
// 没有指定设计师,分组键 = 部门_0
currentGroupKey = (currentDeptKey != null ? currentDeptKey : "null") + "_0";
}
// 判断是否需要创建新分组
boolean needNewGroup = false;
if (i > 0) {
if (currentDeptKey == null || lastDeptKey == null) {
needNewGroup = true;
} else if (!currentDeptKey.equals(lastDeptKey)) {
// 如果分组键不同,则需要创建新分组
if (lastGroupKey == null || !lastGroupKey.equals(currentGroupKey)) {
needNewGroup = true;
}
}
if (needNewGroup) {
currentGroupNo++;
log.info("更新任务分组变化: groupNo={}, 前一分组键={}, 当前分组键={}",
currentGroupNo, lastGroupKey, currentGroupKey);
}
itemDto.setSortOrder(currentGroupNo * 1000 + i);
lastDeptKey = currentDeptKey;
lastGroupKey = currentGroupKey;
}
// **步骤2:按分组汇总,每个分组创建一个子任务**

View File

@ -1660,6 +1660,8 @@ const loadTaskForEdit = async (taskId: number) => {
const task = response.data
if (task) {
console.log('加载任务数据:', task)
// 填充基本表单数据
formData.title = task.title || ''
formData.taskSubType = task.taskSubType || ''
@ -1671,10 +1673,30 @@ const loadTaskForEdit = async (taskId: number) => {
formData.releaseType = task.releaseType || 'recruitment'
formData.isUrgent = task.isUrgent === 1 || task.isUrgent === true
// 处理任务类型和数量
if (task.taskTypeIds) {
// 处理预览图
if (task.previewImage) {
formData.previewImage = task.previewImage
previewFileList.value = [{
uid: 'existing-preview',
name: '预览图',
status: 'done' as const,
url: task.previewImage
}]
}
// 处理任务类型和数量 - 优先从子任务中获取
if (task.isPipeline === 1 && task.subTasks && task.subTasks.length > 0) {
// 流水线任务:从子任务中提取任务类型信息
console.log('流水线任务子任务:', task.subTasks)
formData.taskTypes = task.subTasks.map((subTask: any) => ({
taskTypeId: subTask.taskTypeId,
quantity: subTask.quantity || 1,
receiverId: subTask.receiverId,
selectedDeptId: subTask.receiverDeptId
}))
} else if (task.taskTypeIds) {
// 非流水线任务:从taskTypeIds字符串解析
const typeIds = task.taskTypeIds.split(',').map((id: string) => parseInt(id.trim()))
// 尝试获取每个类型对应的数量(如果有taskItems,从中获取)
formData.taskTypes = typeIds.map((typeId: number, index: number) => ({
taskTypeId: typeId,
quantity: index === 0 ? (task.quantity || 1) : 1,
@ -1713,7 +1735,7 @@ const loadTaskForEdit = async (taskId: number) => {
message.warning(`驳回原因:${task.rejectReason},请修改后重新提交`)
}
console.log('任务数据加载成功:', task)
console.log('任务数据加载成功,formData.taskTypes:', formData.taskTypes)
}
} catch (error) {
console.error('加载任务数据失败:', error)