数据统计--图形报表--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();
    }
相关推荐
月明长歌5 小时前
【码道初阶】【LeetCode 102】二叉树层序遍历:如何利用队列实现“一层一层切蛋糕”?
java·数据结构·算法·leetcode·职场和发展·队列
PFinal社区_南丞5 小时前
Git 那些不太常用但非常实用的命令
后端
沸腾_罗强5 小时前
GORM 软删除方案:使用 deleted_at 替代 is_deleted,用来支持表唯一索引创建
后端
codingPower5 小时前
制作ftl文件通过FreeMarke生成PDF文件(含图片处理)
java·开发语言·pdf
R.lin5 小时前
Spring AI Alibaba 1.1 正式发布!
java·后端·spring
程序员阿明5 小时前
spring security 6的知识点总结
java·后端·spring
李子园的李6 小时前
Java函数式接口——渐进式学习
java
running up6 小时前
Spring Bean生命周期- BeanDefinition 加载与 BeanFactoryPostProcessor BeanPostProcessor
java·后端·spring
222you6 小时前
Java线程的三种创建方式
java·开发语言
脸大是真的好~6 小时前
计算机408基础相关面试题-备用,不推荐
java