数据统计--图形报表--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();
    }
相关推荐
China_Yanhy37 分钟前
AWS S3 深度配置指南:每一栏每个选项有什么作用
java·数据库·aws
秃了也弱了。1 小时前
FASTJSON库:阿里出品java界json解析库,使用与踩坑记录
java·开发语言·json
安全渗透Hacker1 小时前
参数未校验导致的DOS(服务拒绝)问题典型场景
java·安全·web安全·网络安全·安全性测试
superman超哥1 小时前
Rust 或模式(Or Patterns)的语法:多重匹配的优雅表达
开发语言·后端·rust·编程语言·rust或模式·or patterns·多重匹配
Chan161 小时前
微服务 - Higress网关
java·spring boot·微服务·云原生·面试·架构·intellij-idea
二哈喇子!1 小时前
JavaSE 与 JavaEE 知识点整合
java·servlet·tomcat
之歆1 小时前
Spring AI入门到实战到原理源码-多模型协作智能客服系统
java·人工智能·spring
yyy(十一月限定版)2 小时前
c++(3)类和对象(中)
java·开发语言·c++
摸鱼的春哥2 小时前
实战:在 Docker (Windows) 中构建集成 yt-dlp 的“满血版” n8n 自动化工作流
前端·javascript·后端