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));
|
}
|
|
|
}
|