liujie
2025-07-23 e0916aa2e78266fb12da41d75bf7aab701bbf3d0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/IndexController.java
@@ -19,6 +19,7 @@
import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
@Slf4j
@@ -38,7 +39,7 @@
     */
    @GetMapping("/qichacha")
    @ApiOperation(value = "接口统计")
    @PreAuthorize("@ss.hasPermi('index:manage')")
//    @PreAuthorize("@ss.hasPermi('index:manage')")
    public R<QichachaStatisticsVO> qichacha() {
        return R.ok( qichachaService.qichacha());
    }
@@ -48,7 +49,7 @@
     */
    @GetMapping("/today")
    @ApiOperation(value = "收入统计-今日入账")
    @PreAuthorize("@ss.hasPermi('index:manage')")
//    @PreAuthorize("@ss.hasPermi('index:manage')")
    public R<TodayStatisticsVO> today() {
        return R.ok( orderService.today());
    }
@@ -58,23 +59,27 @@
     */
    @GetMapping("/chart")
    @ApiOperation(value = "收入统计-折线图")
    @PreAuthorize("@ss.hasPermi('index:manage')")
//    @PreAuthorize("@ss.hasPermi('index:manage')")
    public R<IndexLineChartVO> chart(@RequestParam(required = false, defaultValue = "7") Integer days,
                                     @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd ") LocalDate startDate,
                                     @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
                                     @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();
        if (startDate == null || endDate == null) {
            startDate = now.minusDays(days - 1);
            endDate = now;
        LocalDate start;
        LocalDate end ;
        if (startTime == null || endTime == null) {
            start = now.minusDays(days - 1);
            end = now;
        } else {
            // 验证日期范围不超过30天
            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
            long daysBetween = ChronoUnit.DAYS.between(startTime, endTime);
            start=startTime.toLocalDate();
            end = endTime.toLocalDate();
            if (daysBetween > 30) {
                endDate = startDate.plusDays(30);
                endTime = startTime.plusDays(30);
            }
        }
        return R.ok(orderService.chart(startDate,endDate));
        return R.ok(orderService.chart(start,end));
    }