huliguo
9 天以前 2485a4875adda2ffd0e8cfccdf749f15fe8d48cb
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.ruoyi.web.controller.system;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.pojo.dto.AddLicenceDTO;
import com.ruoyi.system.pojo.vo.IndexLineChartVO;
import com.ruoyi.system.pojo.vo.QichachaStatisticsVO;
import com.ruoyi.system.pojo.vo.TodayStatisticsVO;
import com.ruoyi.system.service.OrderService;
import com.ruoyi.system.service.QichachaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.scene.chart.Chart;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.Index;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
 
@Slf4j
@RestController
@RequestMapping("/system/index")
@Api( tags = "后台-首页统计")
public class IndexController {
 
    @Resource
    private OrderService orderService;
 
    @Resource
    private QichachaService qichachaService;
 
    /**
     * 接口统计
     */
    @GetMapping("/qichacha")
    @ApiOperation(value = "接口统计")
    @PreAuthorize("@ss.hasPermi('index:manage')")
    public R<QichachaStatisticsVO> qichacha() {
        return R.ok( qichachaService.qichacha());
    }
 
    /**
     * 收入统计 - 今日入账
     */
    @GetMapping("/today")
    @ApiOperation(value = "收入统计-今日入账")
    @PreAuthorize("@ss.hasPermi('index:manage')")
    public R<TodayStatisticsVO> today() {
        return R.ok( orderService.today());
    }
 
    /**
     * 折线图
     */
    @GetMapping("/chart")
    @ApiOperation(value = "收入统计-折线图")
    @PreAuthorize("@ss.hasPermi('index:manage')")
    public R<IndexLineChartVO> chart(@RequestParam(required = false, defaultValue = "7") Integer days,
                                     @RequestParam(required = false)  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
                                     @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime) {
        // 处理日期范围
        LocalDate now = LocalDate.now();
        LocalDate start;
        LocalDate end ;
        if (startTime == null || endTime == null) {
            start = now.minusDays(days - 1);
            end = now;
        } else {
            // 验证日期范围不超过30天
            long daysBetween = ChronoUnit.DAYS.between(startTime, endTime);
            start=startTime.toLocalDate();
            end = endTime.toLocalDate();
            if (daysBetween > 30) {
                endTime = startTime.plusDays(30);
            }
        }
        return R.ok(orderService.chart(start,end));
    }
 
 
}