ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/vo/GunStatusStatisticsVO.java
@@ -10,12 +10,12 @@ @Data @ApiModel(value = "设备状态统计VO") public class GunStatusStatisticsVO implements Serializable { public class GunStatusStatisticsVO { @ApiModelProperty(value = "充电桩类型统计 key:充电模式(1=超级快充,2=快充,3=慢充)") private List<Map<Integer,Integer>> modeStatistics; private List<Map<String,Object>> modeStatistics; @ApiModelProperty(value = "状态统计 key:充电模式(1=离线,2=故障,3=充电中)") private Map<Integer,Integer> statusStatistics; private List<Map<String,Integer>> statusStatistics; @ApiModelProperty(value = "状态统计根据类型分组") private List<StatusModeStatisticsVO> statusModeStatistics; } ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java
@@ -34,9 +34,9 @@ public class GlobalExceptionHandler { private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); @Value("${spring.servlet.multipart.max-file-size}") @Value("${spring.servlet.multipart.max-file-size:50MB}") private String maxFileSize; @Value("${spring.servlet.multipart.max-request-size}") @Value("${spring.servlet.multipart.max-request-size:100MB}") private String maxRequestSize; ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TChargingGunController.java
@@ -184,7 +184,7 @@ */ @ApiOperation(tags = {"后台-工作台"},value = "设备状态统计") @PutMapping(value = "/gunStatusStatistics") public AjaxResult<GunStatusStatisticsVO> gunStatusStatistics() { public R<GunStatusStatisticsVO> gunStatusStatistics() { List<Integer> siteIds = new ArrayList<>(); Long userId = SecurityUtils.getUserId(); //获取当前登录的siteIds @@ -192,7 +192,7 @@ for (GetSiteListDTO datum : siteList1.getRecords()) { siteIds.add(datum.getId()); } return AjaxResult.ok(chargingGunService.gunStatusStatistics(siteIds)); return R.ok(chargingGunService.gunStatusStatistics(siteIds)); } /** ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/mapper/TChargingGunMapper.java
@@ -37,7 +37,7 @@ * @param siteIds * @return */ List<Map<Integer, Integer>> getModeStatistics(@Param("siteIds")List<Integer> siteIds); List<Map<String, Object>> getModeStatistics(@Param("siteIds")List<Integer> siteIds); /** * 统计充电枪状态 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingGunServiceImpl.java
@@ -186,16 +186,22 @@ GunStatusStatisticsVO gunStatusStatisticsVO = new GunStatusStatisticsVO(); if(CollectionUtils.isEmpty(siteIds)){ List<Map<Integer, Integer>> modeStatisticsNull = new ArrayList<>(); modeStatisticsNull.add(new HashMap<>(1,0)); modeStatisticsNull.add(new HashMap<>(2,0)); modeStatisticsNull.add(new HashMap<>(3,0)); gunStatusStatisticsVO.setModeStatistics(modeStatisticsNull); Map<Integer, Integer> statusStatisticsNull = new HashMap<>(); statusStatisticsNull.put(1, 0); statusStatisticsNull.put(2, 0); statusStatisticsNull.put(3, 0); gunStatusStatisticsVO.setStatusStatistics(statusStatisticsNull); // List<Map<Integer, Integer>> modeStatisticsNull = new ArrayList<>(); // HashMap<Integer, Integer> objectObjectHashMap1 = new HashMap<>(); // objectObjectHashMap1.put(1, 0); // modeStatisticsNull.add(objectObjectHashMap1); // HashMap<Integer, Integer> objectObjectHashMap2= new HashMap<>(); // objectObjectHashMap2.put(2, 0); // modeStatisticsNull.add(objectObjectHashMap2); // HashMap<Integer, Integer> objectObjectHashMap3= new HashMap<>(); // objectObjectHashMap3.put(3, 0); // modeStatisticsNull.add(objectObjectHashMap3); // gunStatusStatisticsVO.setModeStatistics(modeStatisticsNull); // Map<Integer, Integer> statusStatisticsNull = new HashMap<>(); // statusStatisticsNull.put(1, 0); // statusStatisticsNull.put(2, 0); // statusStatisticsNull.put(3, 0); // gunStatusStatisticsVO.setStatusStatistics(statusStatisticsNull); List<StatusModeStatisticsVO> statusModeStatistics = new ArrayList<>(); for (int i = 1; i < 4; i++) { StatusModeStatisticsVO statusModeStatisticsVO = new StatusModeStatisticsVO(); @@ -209,35 +215,41 @@ gunStatusStatisticsVO.setStatusModeStatistics(statusModeStatistics); } List<Map<Integer, Integer>> modeStatistics = this.baseMapper.getModeStatistics(siteIds); List<Map<String, Object>> modeStatistics = this.baseMapper.getModeStatistics(siteIds); if(CollectionUtils.isEmpty(modeStatistics)){ Map<Integer, Integer> modeStatistics1 = new HashMap<>(3,0); modeStatistics1.put(1, 0); modeStatistics1.put(2, 0); modeStatistics1.put(3, 0); Map<String, Object> modeStatistics1 = new HashMap<>(); modeStatistics1.put("1", "0"); modeStatistics1.put("2", "0"); modeStatistics1.put("3", "0"); modeStatistics.add(modeStatistics1); } gunStatusStatisticsVO.setModeStatistics(modeStatistics); List<Map<Integer, Integer>> statusStatistics = new ArrayList<>(); List<Map<String, Integer>> statusStatistics = new ArrayList<>(); // 离线 Long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(TChargingGun.class) .eq(TChargingGun::getStatus, 1)); statusStatistics.add(new HashMap<>(1,count.intValue())); HashMap<String, Integer> objectObjectHashMap1 = new HashMap<>(); objectObjectHashMap1.put("1", count.intValue()); statusStatistics.add(objectObjectHashMap1); // statusStatistics.put(1, count.intValue()); // 故障 count = this.baseMapper.selectCount(Wrappers.lambdaQuery(TChargingGun.class) .eq(TChargingGun::getStatus, 7)); statusStatistics.add(new HashMap<>(2,count.intValue())); HashMap<String, Integer> objectObjectHashMap2 = new HashMap<>(); objectObjectHashMap2.put("2", count.intValue()); statusStatistics.add(objectObjectHashMap2); // statusStatistics.put(2, count.intValue()); // 充电中 count = this.baseMapper.selectCount(Wrappers.lambdaQuery(TChargingGun.class) .in(TChargingGun::getStatus, Arrays.asList(3,4,5,6))); statusStatistics.add(new HashMap<>(3,count.intValue())); HashMap<String, Integer> objectObjectHashMap = new HashMap<>(); objectObjectHashMap.put("3", count.intValue()); statusStatistics.add(objectObjectHashMap); // statusStatistics.put(3, count.intValue()); gunStatusStatisticsVO.setModeStatistics(statusStatistics); gunStatusStatisticsVO.setStatusStatistics(statusStatistics); List<StatusModeStatisticsVO> statusModeStatisticsVOS = new ArrayList<>(); StatusModeStatisticsVO statusModeStatistics1 = this.baseMapper.getStatusModeStatistics(siteIds,1); ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
@@ -72,6 +72,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.PrintWriter; import java.time.YearMonth; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAdjusters; import java.util.*; @@ -991,11 +992,67 @@ } return R.ok(charMap); }else if (statisticsQueryDto.getDayType()==2){ List<Map<String,Object>> charMap = chargingOrderService.getDateType(siteIds,statisticsQueryDto); return R.ok(charMap); // 假设 chargingOrderService.getDateType() 返回的是按天的数据 List<Map<String, Object>> charMap1 = chargingOrderService.getDateType(siteIds, statisticsQueryDto); // 解析 startTime 和 endTime 为 LocalDate LocalDate startDate = statisticsQueryDto.getStartTime(); LocalDate endDate = statisticsQueryDto.getEndTime(); List<Map<String, Object>> dateRangeStatistics = new ArrayList<>(); // 遍历日期范围 while (!startDate.isAfter(endDate)) { String formattedDate = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); Map<String, Object> dailyStats = findMapWithDateValue(charMap1, formattedDate); if (dailyStats != null) { dateRangeStatistics.add(dailyStats); } else { Map<String, Object> dateMap = new HashMap<>(); dateMap.put("time", formattedDate); dateMap.put("electrovalence", 0); dateMap.put("orderCount", 0); dateMap.put("servicecharge", 0); dateMap.put("electricity", 0); dateRangeStatistics.add(dateMap); } // 移动到下一天 startDate = startDate.plusDays(1); } // return dateRangeStatistics; return R.ok(dateRangeStatistics); }else if (statisticsQueryDto.getDayType()==3){ List<Map<String,Object>> charMap = chargingOrderService.getMonthType(siteIds,statisticsQueryDto); return R.ok(charMap); List<Map<String,Object>> charMap1 = chargingOrderService.getMonthType(siteIds,statisticsQueryDto); // 解析 startTime 和 endTime 为 LocalDate LocalDate startDate = statisticsQueryDto.getStartTime(); LocalDate endDate = statisticsQueryDto.getEndTime(); List<Map<String, Object>> dateRangeStatistics = new ArrayList<>(); // 遍历日期范围 while (!startDate.isAfter(endDate)) { String formattedDate = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM")); Map<String, Object> dailyStats = findMapWithDateValue(charMap1, formattedDate); if (dailyStats != null) { dateRangeStatistics.add(dailyStats); } else { Map<String, Object> dateMap = new HashMap<>(); dateMap.put("time", formattedDate); dateMap.put("electrovalence", 0); dateMap.put("orderCount", 0); dateMap.put("servicecharge", 0); dateMap.put("electricity", 0); dateRangeStatistics.add(dateMap); } // 移动到下一天 startDate = startDate.plusMonths(1); } return R.ok(dateRangeStatistics); } return R.ok(); @@ -1012,13 +1069,21 @@ return null; // 如果没有找到,返回 null } private Map<String, Object> findMapWithDateValue(List<Map<String, Object>> list, String date) { for (Map<String, Object> map : list) { if (date.equals(map.get("time"))) { return map; } } return null; } @ResponseBody @PostMapping(value = "/work/use") @ApiOperation(value = "运营情况", tags = {"管理后台-工作台"}) @ApiOperation(value = "利用率", tags = {"管理后台-工作台"}) public R workUse(@RequestBody ChargingDetailQueryDto statisticsQueryDto) { List<Integer> siteIds = new ArrayList<>(); if (statisticsQueryDto.getSiteId() == null) { @@ -1042,7 +1107,34 @@ BigDecimal result = chargingCapacity.divide(totalRatedPower, 2, RoundingMode.HALF_UP); map.put("chargingCapacity", result); }); return R.ok(capMap); // // 解析 startTime 和 endTime 为 LocalDate LocalDate startDate = statisticsQueryDto.getStartTime(); LocalDate endDate = statisticsQueryDto.getEndTime(); List<Map<String, Object>> dateRangeStatistics = new ArrayList<>(); // 遍历日期范围 while (!startDate.isAfter(endDate)) { String formattedDate = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); Map<String, Object> dailyStats = findMapWithDateValue(capMap, formattedDate); if (dailyStats != null) { dateRangeStatistics.add(dailyStats); } else { Map<String, Object> dateMap = new HashMap<>(); dateMap.put("time", formattedDate); dateMap.put("chargingCapacity", 0); dateRangeStatistics.add(dateMap); } // 移动到下一天 startDate = startDate.plusDays(1); } return R.ok(dateRangeStatistics); }