fix(ticket-solution): 修复解决方案数据处理逻辑
- 过滤解决方案项中描述为空的数据,避免无效内容保存 - 获取所有字典项后移除已处理项,确保新增项准确无遗漏 - 未处理的初始字典项批量新增解决方案实体 - 新增数据保存前删除对应旧的空描述记录,防止数据重复 - 优化代码结构,提升处理流程的清晰度和准确性
This commit is contained in:
parent
8865f971f8
commit
027f4a17ad
|
|
@ -93,14 +93,18 @@ public class TicketSolutionServiceImpl extends ServiceImpl<TicketSolutionMapper,
|
|||
} else if (CollectionUtil.isEmpty(initial)) {
|
||||
items = groupedSolutions.entrySet().stream().map(ks -> new SolutionMeasuresItemVO()
|
||||
.setName(ks.getValue().get(0).getDictionaryItemName())
|
||||
.setItems(ks.getValue().stream().map(v -> new SolutionMeasuresDataItemVO()
|
||||
.setId(Long.valueOf(v.getId()))
|
||||
.setName(v.getDescription())
|
||||
.setSuperintendent(v.getSuperintendent())
|
||||
.setScheduleDate(v.getScheduleDate())
|
||||
.setConfirmedDate(v.getConfirmedDate())
|
||||
.setRemark(v.getRemark())
|
||||
.setCreateUserId(v.getCreateUserId())).collect(Collectors.toList())
|
||||
.setItems(ks.getValue()
|
||||
.stream()
|
||||
.filter(v -> StrUtil.isNotBlank(v.getDescription()))
|
||||
.map(v -> new SolutionMeasuresDataItemVO()
|
||||
.setId(Long.valueOf(v.getId()))
|
||||
.setName(v.getDescription())
|
||||
.setSuperintendent(v.getSuperintendent())
|
||||
.setScheduleDate(v.getScheduleDate())
|
||||
.setConfirmedDate(v.getConfirmedDate())
|
||||
.setRemark(v.getRemark())
|
||||
.setCreateUserId(v.getCreateUserId())
|
||||
).collect(Collectors.toList())
|
||||
)).collect(Collectors.toList());
|
||||
} else {
|
||||
for (DictionaryItem it : initial) {
|
||||
|
|
@ -215,9 +219,11 @@ public class TicketSolutionServiceImpl extends ServiceImpl<TicketSolutionMapper,
|
|||
VUtils.trueThrowBusinessError(cqmIds.stream().noneMatch(uid -> Objects.equals(uid, userId))
|
||||
&& handleIds.stream().noneMatch(uid -> Objects.equals(uid, userId)))
|
||||
.throwMessage("无权修改解决方案");
|
||||
List<DictionaryItem> initial = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_SOLUTION_MEASURES, Constant.DEFAULT_LANGUAGE_CODE);
|
||||
List<TicketSolution> forAdd = new ArrayList<>();
|
||||
List<TicketSolution> forUpdate = new ArrayList<>();
|
||||
for (SolutionMeasuresItemVO solutionMeasuresItemVO : request.getSolutionMeasures()) {
|
||||
initial.removeIf(it -> Objects.equals(it.getId(), solutionMeasuresItemVO.getId()));
|
||||
for (SolutionMeasuresDataItemVO solutionMeasuresDataItemVO : solutionMeasuresItemVO.getItems()) {
|
||||
TicketSolution solution = new TicketSolution()
|
||||
.setTicketId(request.getTicketId())
|
||||
|
|
@ -239,6 +245,17 @@ public class TicketSolutionServiceImpl extends ServiceImpl<TicketSolutionMapper,
|
|||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(initial)) {
|
||||
initial.forEach(it -> {
|
||||
forAdd.add(new TicketSolution()
|
||||
.setTicketId(request.getTicketId())
|
||||
.setDictionaryItemId(it.getId())
|
||||
.setDictionaryItemName(it.getName())
|
||||
.setCreateUserId(userId)
|
||||
.setCreateTime(LocalDateTime.now())
|
||||
);
|
||||
});
|
||||
}
|
||||
List<Integer> idForReserve = forUpdate.stream().map(TicketSolution::getId).collect(Collectors.toList());
|
||||
List<TicketSolution> solutions = lambdaQuery().eq(TicketSolution::getTicketId, request.getTicketId()).orderByAsc(TicketSolution::getId).list();
|
||||
if (!cqmIds.contains(userId)) {
|
||||
|
|
@ -263,6 +280,12 @@ public class TicketSolutionServiceImpl extends ServiceImpl<TicketSolutionMapper,
|
|||
);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(forAdd)) {
|
||||
lambdaUpdate()
|
||||
.eq(TicketSolution::getTicketId, request.getTicketId())
|
||||
.notIn(CollectionUtil.isNotEmpty(forUpdate), TicketSolution::getId, forUpdate.stream().map(TicketSolution::getId).collect(Collectors.toList()))
|
||||
.isNull(TicketSolution::getDescription)
|
||||
.remove();
|
||||
forAdd.sort(Comparator.comparing(TicketSolution::getDictionaryItemId));
|
||||
saveBatch(forAdd);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(forUpdate)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue