diff --git a/src/main/java/com/biutag/supervision/service/NegativeScoreService.java b/src/main/java/com/biutag/supervision/service/NegativeScoreService.java index 72d3d49..666d417 100644 --- a/src/main/java/com/biutag/supervision/service/NegativeScoreService.java +++ b/src/main/java/com/biutag/supervision/service/NegativeScoreService.java @@ -61,6 +61,8 @@ public class NegativeScoreService { try { String formula = "%s + (%s * %s) + (%s * %s)"; List scoreDeparts = new ArrayList<>(); + record PoliceScoreKey(String negativeId, String idCode) {} + Map scorePolices = new LinkedHashMap<>(); negativeScorePoliceService.remove(new LambdaQueryWrapper().isNotNull(NegativeScorePolice::getNegativeId)); negativeScoreDepartService.remove(new LambdaQueryWrapper().isNotNull(NegativeScoreDepart::getNegativeId)); Set negativeIds = negativeBlames.stream().map(NegativeBlame::getNegativeId).collect(Collectors.toSet()); @@ -103,7 +105,11 @@ public class NegativeScoreService { negativeScorePolice.setScore(score) .setExpression(expression); - negativeScorePoliceService.save(negativeScorePolice); + PoliceScoreKey scoreKey = new PoliceScoreKey(blame.getNegativeId(), blame.getBlameIdCode()); + NegativeScorePolice existingScore = scorePolices.get(scoreKey); + if (Objects.isNull(existingScore) || existingScore.getScore() < score) { + scorePolices.put(scoreKey, negativeScorePolice); + } NegativeScoreDepart scoreDepart = scoreDeparts.stream().filter(item -> item.getNegativeId().equals(negative.getId())).findFirst().orElse(null); if (Objects.isNull(scoreDepart)) { scoreDepart = new NegativeScoreDepart(); @@ -112,8 +118,12 @@ public class NegativeScoreService { scoreDeparts.add(scoreDepart); } else if (scoreDepart.getScore() < score) { scoreDepart.setScore(score); + scoreDepart.setExpression(expression); } }); + if (!scorePolices.isEmpty()) { + negativeScorePoliceService.saveBatch(scorePolices.values()); + } if (!scoreDeparts.isEmpty()) { negativeScoreDepartService.saveBatch(scoreDeparts); } @@ -125,6 +135,7 @@ public class NegativeScoreService { System.out.println("calculateScore-------------------------------------------------End"); } + private final BusinessDepartService businessDepartService; private final SupPoliceService policeService;