luodangjia
2024-09-27 801164d62ea165e90e77cd7da90829b1615532e3
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.*;
@@ -584,7 +585,7 @@
    }
    @ResponseBody
    @GetMapping(value = "/work/shop")
    @PostMapping(value = "/work/shop")
    @ApiOperation(value = "购物收入", tags = {"后台-工作台"})
    public R workShop(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto) {
        //count近6个月的数据
@@ -625,7 +626,7 @@
    @ResponseBody
    @PostMapping(value = "/watch/chargingOrder")
    @ApiOperation(value = "监控订单", tags = {"管理后台-订单管理"})
    public AjaxResult<TCharingOrderVO> watchChargingOrder(@RequestBody ChargingOrderQuery dto) {
    public R<List<ChargingOrderAndUploadRealTimeMonitoringDataDto>> watchChargingOrder(@RequestBody ChargingOrderQuery dto) {
        Integer page = dto.getPageCurr();
        Integer pageSize = dto.getPageSize();
        List<Long> data = appUserClient.getUserIdsByPhone(dto.getPhone()).getData();
@@ -652,7 +653,7 @@
        }
        return AjaxResult.success(res);
        return R.ok(dtos);
    }
    
    
@@ -971,23 +972,118 @@
            siteIds.add(statisticsQueryDto.getSiteId());
        }
        if (statisticsQueryDto.getDayType()==1) {
          List<Map<String,Object>> charMap = chargingOrderService.getHourType(siteIds,statisticsQueryDto);
          List<Map<String,Object>> charMap1 = chargingOrderService.getHourType(siteIds,statisticsQueryDto);
            List<Map<String, Object>> charMap = new ArrayList<>();
            // 生成从 "00:00" 到 "23:00" 的时间数据
            for (int hour = 0; hour < 24; hour++) {
                String time = String.format("%02d:00", hour);
                 Map<String, Object> mapWithTimeValue = findMapWithTimeValue(charMap1, time);
                if (mapWithTimeValue!=null){
                    charMap.add(mapWithTimeValue);
                }else {
                    Map<String, Object> timeMap = new HashMap<>();
                    timeMap.put("time", time); // 初始化值为 null
                    timeMap.put("electrovalence", 0);
                    timeMap.put("orderCount", 0);
                    timeMap.put("servicecharge", 0);
                    timeMap.put("electricity", 0);
                    charMap.add(timeMap);
                }
            }
          return R.ok(charMap);
        }else if (statisticsQueryDto.getDayType()==2){
            List<Map<String,Object>> charMap =  chargingOrderService.getDateType(siteIds,statisticsQueryDto);
            return R.ok(charMap);
        }else if (statisticsQueryDto.getDayType()==3){
            List<Map<String,Object>> charMap =  chargingOrderService.getMonthType(siteIds,statisticsQueryDto);
        }
            // 假设 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>> 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();
    }
    private static Map<String, Object> findMapWithTimeValue(List<Map<String, Object>> charMap1,String timeValue) {
        for (Map<String, Object> map : charMap1) {
            if (map.containsKey("time") && map.get("time").equals(timeValue)) {
                return map;
            }
        }
        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) {
@@ -1011,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);
    }
@@ -1019,9 +1142,9 @@
    @Resource
    private TOrderInvoiceService invoiceService;
    @ResponseBody
    @PostMapping(value = "/work/shopOrder")
    @GetMapping(value = "/work/shopOrder")
    @ApiOperation(value = "购物订单统计", tags = {"管理后台-工作台"})
    public R shopOrder(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto) {
    public R shopOrder() {
        Long count = shoppingOrderService.lambdaQuery().eq(TShoppingOrder::getStatus, 1).count();
        Long count1 = shoppingOrderService.lambdaQuery().eq(TShoppingOrder::getStatus, 2).count();
        List<Long> counts = new ArrayList<>();
@@ -1031,9 +1154,9 @@
    }
    @ResponseBody
    @PostMapping(value = "/work/invoice")
    @GetMapping(value = "/work/invoice")
    @ApiOperation(value = "开票统计", tags = {"管理后台-工作台"})
    public R invoice(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto) {
    public R invoice() {
        Long count = invoiceService.lambdaQuery().eq(TOrderInvoice::getStatus, 1).count();
        Long count1 = invoiceService.lambdaQuery().eq(TOrderInvoice::getStatus, 3).count();
        List<Long> counts = new ArrayList<>();
@@ -1043,9 +1166,9 @@
    }
    @ResponseBody
    @PostMapping(value = "/work/users/count")
    @GetMapping(value = "/work/users/count")
    @ApiOperation(value = "用户数量", tags = {"管理后台-工作台"})
    public R usersCount(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto) {
    public R usersCount() {
       List<Map<String,Object>>  userMap  =    chargingOrderService.countAllUserData();
            return R.ok(userMap);