| | |
| | | map.put("head", PrintChina.printChina(CostStatisticsDto.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("costStatistics"); |
| | | if (map1.get("look") == 1) costStatisticsDto.setCreateUser(map1.get("userId")); |
| | | map.put("body", insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59"))); |
| | | IPage<CostStatisticsDto> costStatisticsDtoIPage = insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59")); |
| | | List<CostStatisticsDto> costStatisticsDtoList = costStatisticsDtoIPage.getRecords(); |
| | | for (CostStatisticsDto statisticsDto : costStatisticsDtoList) { |
| | | statisticsDto.setNum(1); |
| | | } |
| | | List<CostStatisticsDto> costStatisticsDtoList1 = deduplicateAndSumCounts(costStatisticsDtoList); |
| | | costStatisticsDtoIPage.setRecords(costStatisticsDtoList1); |
| | | map.put("body", costStatisticsDtoIPage); |
| | | return map; |
| | | } |
| | | private static List<CostStatisticsDto> deduplicateAndSumCounts(List<CostStatisticsDto> list) { |
| | | // 使用一个 Map 来存放已经出现过的 inspectionItem + entrustCode + sample 的组合 |
| | | Map<String, CostStatisticsDto> map = new HashMap<>(); |
| | | // 遍历列表进行去重和计数 |
| | | for (CostStatisticsDto dto : list) { |
| | | String key = dto.getInspectionItem() + dto.getEntrustCode() + dto.getSample(); |
| | | if (map.containsKey(key)) { |
| | | // 如果已经存在,则累加数量 |
| | | CostStatisticsDto existingDto = map.get(key); |
| | | existingDto.setNum(existingDto.getNum() + dto.getNum()); |
| | | existingDto.setPrice(existingDto.getPrice().add(dto.getPrice())); |
| | | } else { |
| | | // 如果不存在,则放入 Map 中 |
| | | map.put(key, dto); |
| | | } |
| | | } |
| | | // 将 Map 中的值转为 List 返回 |
| | | return new ArrayList<>(map.values()); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> costStatistics2(CostStatisticsDto costStatisticsDto) { |