longz
2026-08-04 3fe81a2e2ef55c9eda69fef17c660fa7f4edcaf5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.ruoyi.order.controller;
 
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.order.dto.SixChargingDto;
import com.ruoyi.order.service.TChargingOrderService;
import com.ruoyi.order.vo.LargeChargingPowerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
 
@Api(tags = "大屏")
@RestController
@RequestMapping("/large-screen")
public class LargeScreenController {
 
    @Resource
    private TChargingOrderService chargingOrderService;
 
    @ApiOperation(tags = {"大屏-累计指标"}, value = "累计充电指标")
    @GetMapping("/summary")
    public R<Map<String, Object>> summary(@RequestParam("siteIds") List<Integer> siteIds) {
        return R.ok(chargingOrderService.getLargeScreenSummary(normalizeSiteIds(siteIds)));
    }
 
    @ApiOperation(tags = {"大屏-收入趋势"}, value = "当年按月充电收入")
    @GetMapping("/incomeTrend")
    public R<List<SixChargingDto>> incomeTrend(@RequestParam("siteIds") List<Integer> siteIds) {
        return R.ok(chargingOrderService.getLargeScreenIncomeTrend(
                normalizeSiteIds(siteIds), LocalDate.now().withDayOfYear(1)));
    }
 
    @ApiOperation(tags = {"大屏-停车场充电功率曲线图"},value = "停车场充电功率曲线图")
    @GetMapping("/getChargingPower")
    public R<List<LargeChargingPowerVo>> getChargingPower(
            @RequestParam(value = "siteIds", required = false) List<Integer> siteIds){
        LocalDate today = LocalDate.now();
        LocalDateTime startTime = today.minusDays(7).atStartOfDay();
        LocalDateTime endTime = today.atStartOfDay();
        List<LargeChargingPowerVo> powerData = chargingOrderService.getLargeScreenChargingPower(
                siteIds == null ? null : normalizeSiteIds(siteIds), startTime, endTime);
        Map<String, LargeChargingPowerVo> powerByDate = powerData.stream()
                .collect(Collectors.toMap(LargeChargingPowerVo::getTime, Function.identity(), (left, right) -> left));
        ArrayList<LargeChargingPowerVo> largeChargingPowerVos = new ArrayList<>();
        for (int count = 7; count > 0; count--) {
            String time = today.minusDays(count).toString();
            LargeChargingPowerVo largeChargingPowerVo = powerByDate.getOrDefault(time, new LargeChargingPowerVo());
            largeChargingPowerVo.setTime(time);
            largeChargingPowerVos.add(largeChargingPowerVo);
        }
        return R.ok(largeChargingPowerVos);
    }
 
    private List<Integer> normalizeSiteIds(List<Integer> siteIds) {
        return siteIds == null || siteIds.isEmpty() ? Collections.singletonList(-1) : siteIds;
    }
 
}