数据统计--图形报表--ApacheEcharts技术 --苍穹外卖day10

Apache Echarts

营业额统计

重点:已完成订单金额要排除其他状态的金额 根据时间选择区间

设计vo用于后端向前端传输数据,dto用于后端接收前端发送的数据

java 复制代码
 @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额统计")
    public Result<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        log.info("营业额数据统计:{},{}",begin,end);
        return Result.success(reportService.getTurnoverStatistics(begin,end));
    }
java 复制代码
 public TurnoverReportVO getTurnoverStatistics(LocalDate begin, LocalDate end) {
        //当前集合用于存放从begin到end范围内的每天的日期
        List<LocalDate> dateList = new ArrayList<>();

        dateList.add(begin);

        while (!begin.equals(end)) {
            //日期计算,计算指定日期的后一天对应的日期
            //把每天的东西一个一个放进去
            begin = begin.plusDays(1);
            dateList.add(begin);
        }

        //存放每天的营业额
        List<Double> turnoverList = new ArrayList<>();
        for (LocalDate date : dateList) {
            //查询date日期对应的营业额数据,营业额是指:状态为"已完成"的订单金额合计
            LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
            LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);

            // select sum(amount) from orders where order_time > beginTime and order_time < endTime and status = 5
            Map map = new HashMap();
            map.put("begin", beginTime);
            map.put("end", endTime);
            map.put("status", Orders.COMPLETED);
            Double turnover = orderMapper.sumByMap(map);
            turnover = turnover == null ? 0.0 : turnover;
            turnoverList.add(turnover);
        }

        //封装返回结果
        return TurnoverReportVO
                .builder()
                .dateList(StringUtils.join(dateList, ","))//使用字符串拼接工具
                //将几个不同的时间字符串用逗号分隔开,组合成一个字符串
                .turnoverList(StringUtils.join(turnoverList, ","))
                .build();
    }
相关推荐
唐青枫2 小时前
看懂内存地址之后,才算真正入门 Zig:指针、切片与实战
后端
朋克洛德的码农2 小时前
Go并发-sync包四剑客:Mutex、RWMutex、WaitGroup、Once-从入门到原理
开发语言·后端·golang
fulton2 小时前
为什么不用现成的开源工具?NovelOps与6大AI写作工具横向对比
后端
fulton3 小时前
3个月踩坑实录:从想法到270章规划,AI写长篇到底要花多少成本?
后端
fulton3 小时前
为什么AI写到20章就开始"复制粘贴"自己?创意扰动机制详解
后端
艺艺生辉3 小时前
从if-else到策略模式
后端·设计模式
fulton3 小时前
AI写小说失败的第一原因是什么
后端
fulton3 小时前
这段文字有AI味"到底怎么判断
后端
fulton3 小时前
为什么AI写的小说节奏总是崩
后端
fulton3 小时前
为什么AI写到30章角色就崩人设
后端