zxl
17 小时以前 d3e36feef46d4b5d381333698977a5a913f18284
ycl-server/src/main/java/com/ycl/platform/service/impl/CheckScoreServiceImpl.java
@@ -42,6 +42,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.InetAddress;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
@@ -179,7 +180,7 @@
            }
        }
        //分数保留一位小数
        checkScores.stream().forEach(item -> item.setScore(item.getScore().setScale(1, RoundingMode.HALF_UP)));
        checkScores.stream().forEach(item -> item.setScore(item.getScore().setScale(3, RoundingMode.HALF_UP)));
        Map<Long, List<CheckScore>> map = checkScores.stream().collect(Collectors.groupingBy(CheckScore::getDeptId));
        for (Map.Entry<Long, List<CheckScore>> entry : map.entrySet()) {
            List<CheckScore> tempList = getCheckScores(entry);
@@ -191,18 +192,30 @@
    private List<CheckScore> getCheckScores(Map.Entry<Long, List<CheckScore>> entry) {
        List<CheckScore> tempList = new ArrayList<>(); // 临时存储需要添加的元素
        for (CheckScore listCheckScore : entry.getValue()) {
            if (listCheckScore.getExamineCategory() == 1 && entry.getValue().size() == 1) {
                CheckScore face = new CheckScore();
                face.setExamineCategory((short) 2);
                face.setScore(new BigDecimal("0.0"));
                CheckScore car = new CheckScore();
                car.setExamineCategory((short) 3);
                car.setScore(new BigDecimal("0.0"));
                tempList.add(face);
                tempList.add(car);
        boolean hasFace = false;
        boolean hasCar = false;
        for (int i =0;i <entry.getValue().size();i++) {
            CheckScore checkScore = entry.getValue().get(i);
            if (checkScore.getExamineCategory() == 2){
                hasCar = true;
            }else if (checkScore.getExamineCategory() == 3){
                hasFace = true;
            }
        }
        if (!hasCar){
            CheckScore car = new CheckScore();
            car.setExamineCategory((short) 2);
            car.setScore(new BigDecimal("0.00"));
            tempList.add(car);
        }
        if (!hasFace){
            CheckScore face = new CheckScore();
            face.setExamineCategory((short) 3);
            face.setScore(new BigDecimal("0.00"));
            tempList.add(face);
        }
        return tempList;
    }
@@ -558,24 +571,33 @@
        dashboardQuery.setStartTime(format.format(DateUtils.getDayStart(now)));
        dashboardQuery.setEndTime(format.format(DateUtils.getDayEnd(now)));
        List<CheckScore> dashboard = scoreMapper.dashboard(dashboardQuery);
        DecimalFormat decimalFormat = new DecimalFormat("0.00%");
        // 设置四舍五入模式
        decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
        //初始化各个区县数据
        Map<String, Map<String, Object>> resultMap = new HashMap<>();
        for (AreaDeptEnum value : AreaDeptEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("video", 0);
            map.put("car", 0);
            map.put("face", 0);
            map.put("video", "0.00%");
            map.put("car","0.00%");
            map.put("face", "0.00%");
            resultMap.put(value.getName(), map);
        }
        //填充各个区县数据
        for (CheckScore checkScore : dashboard) {
            Map<String, Object> map = resultMap.get(checkScore.getDeptName());
            BigDecimal score = checkScore.getScore();
            // 核心逻辑:原始score ×10 → 保留两位小数 → 拼接百分号
            BigDecimal scoreMultiplied = score.multiply(new BigDecimal("10")); // 4.6160 ×10 = 46.160
            BigDecimal scoreWithTwoDecimals = scoreMultiplied.setScale(2, RoundingMode.HALF_UP); // 保留两位小数:46.16
            String formattedScore = scoreWithTwoDecimals + "%"; // 拼接百分号:46.16%
            if (CheckConstants.Rule_Category_Video.equals(checkScore.getExamineCategory())) {
                map.put("video", checkScore.getScore().setScale(1, RoundingMode.HALF_UP));
                map.put("video", formattedScore);
            } else if (CheckConstants.Rule_Category_Car.equals(checkScore.getExamineCategory())) {
                map.put("car", checkScore.getScore().setScale(1, RoundingMode.HALF_UP));
                map.put("car", formattedScore);
            } else if (CheckConstants.Rule_Category_Face.equals(checkScore.getExamineCategory())) {
                map.put("face", checkScore.getScore().setScale(1, RoundingMode.HALF_UP));
                map.put("face",formattedScore);
            }
            resultMap.put(checkScore.getDeptName(), map);
        }