| | |
| | | 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.*; |
| | |
| | | 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); |
| | | } |