fix: 修复接单部门审核页面重新调整任务明细数量后无法生效的问题
问题描述: - 接单部门负责人在审核页面调整任务明细数量时 - applyTaskUpdates方法只更新了主任务的taskTypeIds、quantity和score - 但没有同步更新子任务(task_item)表中的quantity、totalScore和typeDetails字段 - 导致调整后的数量无法生效 解决方案: - 在applyTaskUpdates方法中添加updateTaskItemsQuantityAndScore调用 - 新增updateTaskItemsQuantityAndScore方法:同步更新子任务的数量和积分 - 新增updateTypeDetailsJson方法:更新typeDetails JSON字段中的数量信息
This commit is contained in:
parent
20e7ede2d5
commit
b49c9e411a
@ -1061,6 +1061,139 @@ public class TaskApprovalService {
|
||||
// 重新计算积分
|
||||
java.math.BigDecimal totalScore = taskService.calculateTotalScoreDecimal(updates.getTaskTypes());
|
||||
task.setScore(totalScore);
|
||||
|
||||
// 🔥 同步更新子任务(task_item)的数量和积分
|
||||
// 这是修复接单部门审核页面调整任务明细数量后无法生效的问题
|
||||
updateTaskItemsQuantityAndScore(task.getId(), updates.getTaskTypes());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新子任务的数量和积分
|
||||
* 当审核人调整任务明细数量时,同步更新对应的子任务
|
||||
*/
|
||||
private void updateTaskItemsQuantityAndScore(Long taskId, List<TaskUpdateDTO.TaskTypeUpdateDTO> taskTypes) {
|
||||
// 获取该任务的所有子任务
|
||||
List<TaskItem> taskItems = taskItemMapper.selectList(
|
||||
new LambdaQueryWrapper<TaskItem>()
|
||||
.eq(TaskItem::getTaskId, taskId)
|
||||
);
|
||||
|
||||
if (taskItems == null || taskItems.isEmpty()) {
|
||||
log.info("任务 {} 没有子任务,跳过子任务更新", taskId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 构建 taskTypeId -> (quantity, unitScore) 的映射
|
||||
java.util.Map<Long, TaskUpdateDTO.TaskTypeUpdateDTO> typeUpdateMap = new java.util.HashMap<>();
|
||||
for (TaskUpdateDTO.TaskTypeUpdateDTO typeUpdate : taskTypes) {
|
||||
typeUpdateMap.put(typeUpdate.getTaskTypeId(), typeUpdate);
|
||||
}
|
||||
|
||||
// 遍历子任务,更新数量和积分
|
||||
for (TaskItem item : taskItems) {
|
||||
boolean needUpdate = false;
|
||||
|
||||
// 检查子任务的 taskTypeId 是否在更新列表中
|
||||
if (item.getTaskTypeId() != null && typeUpdateMap.containsKey(item.getTaskTypeId())) {
|
||||
TaskUpdateDTO.TaskTypeUpdateDTO typeUpdate = typeUpdateMap.get(item.getTaskTypeId());
|
||||
Integer newQuantity = typeUpdate.getQuantity();
|
||||
|
||||
if (newQuantity != null && !newQuantity.equals(item.getQuantity())) {
|
||||
// 获取单价积分
|
||||
java.math.BigDecimal unitScore = item.getUnitScore();
|
||||
if (unitScore == null) {
|
||||
// 如果没有单价,从配置中获取
|
||||
DemandType demandType = configService.getDemandTypeById(item.getTaskTypeId());
|
||||
if (demandType != null && demandType.getUnitScore() != null) {
|
||||
unitScore = demandType.getUnitScore();
|
||||
} else {
|
||||
unitScore = java.math.BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新数量和总积分
|
||||
item.setQuantity(newQuantity);
|
||||
item.setTotalScore(unitScore.multiply(new java.math.BigDecimal(newQuantity)));
|
||||
item.setUpdateTime(LocalDateTime.now());
|
||||
needUpdate = true;
|
||||
|
||||
log.info("更新子任务数量和积分: itemId={}, taskTypeId={}, oldQuantity={}, newQuantity={}, unitScore={}, newTotalScore={}",
|
||||
item.getId(), item.getTaskTypeId(), item.getQuantity(), newQuantity, unitScore, item.getTotalScore());
|
||||
}
|
||||
}
|
||||
|
||||
// 🔥 同时更新 typeDetails JSON 字段(如果存在)
|
||||
if (item.getTypeDetails() != null && !item.getTypeDetails().isEmpty()) {
|
||||
String updatedTypeDetails = updateTypeDetailsJson(item.getTypeDetails(), typeUpdateMap);
|
||||
if (!item.getTypeDetails().equals(updatedTypeDetails)) {
|
||||
item.setTypeDetails(updatedTypeDetails);
|
||||
item.setUpdateTime(LocalDateTime.now());
|
||||
needUpdate = true;
|
||||
log.info("更新子任务typeDetails: itemId={}, newTypeDetails={}", item.getId(), updatedTypeDetails);
|
||||
}
|
||||
}
|
||||
|
||||
if (needUpdate) {
|
||||
taskItemMapper.updateById(item);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("完成子任务数量和积分更新: taskId={}, 子任务数量={}", taskId, taskItems.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 typeDetails JSON 中的数量
|
||||
*/
|
||||
private String updateTypeDetailsJson(String typeDetails, java.util.Map<Long, TaskUpdateDTO.TaskTypeUpdateDTO> typeUpdateMap) {
|
||||
try {
|
||||
// 解析 JSON 数组
|
||||
com.fasterxml.jackson.databind.JsonNode rootNode = objectMapper.readTree(typeDetails);
|
||||
if (!rootNode.isArray()) {
|
||||
return typeDetails;
|
||||
}
|
||||
|
||||
com.fasterxml.jackson.databind.node.ArrayNode arrayNode = (com.fasterxml.jackson.databind.node.ArrayNode) rootNode;
|
||||
boolean hasChanges = false;
|
||||
|
||||
for (int i = 0; i < arrayNode.size(); i++) {
|
||||
com.fasterxml.jackson.databind.JsonNode itemNode = arrayNode.get(i);
|
||||
if (itemNode.has("typeId")) {
|
||||
Long typeId = itemNode.get("typeId").asLong();
|
||||
if (typeUpdateMap.containsKey(typeId)) {
|
||||
TaskUpdateDTO.TaskTypeUpdateDTO typeUpdate = typeUpdateMap.get(typeId);
|
||||
Integer newQuantity = typeUpdate.getQuantity();
|
||||
|
||||
if (newQuantity != null) {
|
||||
// 修改数量
|
||||
com.fasterxml.jackson.databind.node.ObjectNode objectNode = (com.fasterxml.jackson.databind.node.ObjectNode) itemNode;
|
||||
int oldQuantity = objectNode.has("quantity") ? objectNode.get("quantity").asInt() : 0;
|
||||
|
||||
if (oldQuantity != newQuantity) {
|
||||
objectNode.put("quantity", newQuantity);
|
||||
|
||||
// 重新计算 totalScore
|
||||
if (objectNode.has("unitScore")) {
|
||||
double unitScore = objectNode.get("unitScore").asDouble();
|
||||
objectNode.put("totalScore", unitScore * newQuantity);
|
||||
}
|
||||
|
||||
hasChanges = true;
|
||||
log.info("更新typeDetails中的任务类型: typeId={}, oldQuantity={}, newQuantity={}",
|
||||
typeId, oldQuantity, newQuantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasChanges) {
|
||||
return objectMapper.writeValueAsString(arrayNode);
|
||||
}
|
||||
return typeDetails;
|
||||
} catch (Exception e) {
|
||||
log.error("更新typeDetails JSON失败: {}", e.getMessage());
|
||||
return typeDetails;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user