项目-苍穹外卖(十五) Apache ECharts+数据统计

news2025/4/1 1:55:45

一、介绍

二、营业额统计

需求分析和设计:

Controller:

Service:

/**
     * 营业额统计
     * @param begindate
     * @param enddate
     * @return
     * */
    @Override
    public TurnoverReportVO turnoverStatistics(LocalDate begindate, LocalDate enddate) {
        //创建时间集合
        List<LocalDate> datelist=new ArrayList<>();
        //加入起始时间
        datelist.add(begindate);
        //循环,直到将起始时间->结束时间期间的每一天都加入到集合中
        while(!begindate.equals(enddate)){
            begindate = begindate.plusDays(1);
            datelist.add(begindate);
        }
        //集合元素按照 a,b格式转化成字符串
        String dateList = StringUtils.join(datelist, ",");

        List<Double> turnoverList =new ArrayList<>();
        for (LocalDate localDate : datelist) {
            //根据日期查询营业额 (状态为已完成的订单的综合)
            LocalDateTime begin = LocalDateTime.of(localDate, LocalTime.MIN);//LocalTime.MIN 0点 0分 0秒
            LocalDateTime end = LocalDateTime.of(localDate, LocalTime.MAX);//LocalTime.MAX 59:59:5999
            Map map=new HashMap();
            map.put("begin",begin);
            map.put("end",end);
            map.put("status", Orders.COMPLETED);
            Double turnover =orderMapper.sumByMap(map);
            //当天没有营业额则置零
            turnover =  turnover==null?0.0:turnover;
            turnoverList.add(turnover);
        }
        //集合元素按照 a,b格式转化成字符串
        String turnoverlist = StringUtils.join(turnoverList, ",");
        
        return TurnoverReportVO.builder()
                .turnoverList(turnoverlist)
                .dateList(dateList)
                .build();
    }

Mapper:

    <select id="sumByMap" resultType="java.lang.Double">
        select sum(amount) from sky_take_out.orders
        <where>
            <if test=" begin != null">
                and order_time &gt; #{begin}
            </if>
            <if test=" end != null">
                and order_time &lt; #{end}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
        </where>
    </select>

三、用户统计

需求分析和设计:

Controller:

    /**
     * 用户统计
     * @param begin
     * @param end
     * @return
     * */
    @ApiOperation("用户统计")
    @GetMapping("/userStatistics")
    public Result<UserReportVO> getUserStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){

        log.info("用户统计:{},{}",begin,end);

        return Result.success(reportService.userStatistics(begin,end));
    }

Service: 

    /**
     * 用户统计
     * @param begin
     * @param end
     * @return
     * */
    @Override
    public UserReportVO userStatistics(LocalDate begin, LocalDate end) {
        List<LocalDate> datelist=new ArrayList<>();
        datelist.add(begin);
        while(!begin.equals(end)){
            //日期计算,循环到enddate为止
            begin = begin.plusDays(1);
            datelist.add(begin);
        }
        //集合元素按照 a,b格式转化成字符串
        String dateList = StringUtils.join(datelist, ",");

        List<Double> newuserlist=new ArrayList<>();
        for (LocalDate localDate : datelist) {
            //根据日期查询新增用户 (状态为已完成的订单的综合)
            LocalDateTime begindate = LocalDateTime.of(localDate, LocalTime.MIN);//LocalTime.MIN 0点 0分 0秒
            LocalDateTime enddate = LocalDateTime.of(localDate, LocalTime.MAX);//LocalTime.MAX 59:59:5999

            Map map=new HashMap();
            map.put("begin",begindate);
            map.put("end",enddate);

            Double usercount= orderMapper.sumuserByMap(map);
            usercount= usercount==null?0:usercount;
            newuserlist.add(usercount);
        }
        String newuser = StringUtils.join(newuserlist, ",");

        List<Double> totalueserlist=new ArrayList<>();
        for (LocalDate localDate : datelist) {
            //根据日期查询总用户
            LocalDateTime enddate = LocalDateTime.of(localDate, LocalTime.MAX);//LocalTime.MAX 59:59:5999

            Map map=new HashMap();
            map.put("end",enddate);

            Double totalusercount= orderMapper.sumuserByMap(map);
            totalusercount= totalusercount==null?0:totalusercount;
            totalueserlist.add(totalusercount);
        }
        String totaluser = StringUtils.join(totalueserlist, ",");

        return UserReportVO.builder()
                .newUserList(newuser)
                .totalUserList(totaluser)
                .dateList(dateList).build();
    }

Mapper:

    <select id="sumuserByMap" resultType="java.lang.Double">
        select count(id) from sky_take_out.user
        <where>
            <if test=" begin != null">
                and create_time  &gt; #{begin}
            </if>
            <if test=" end != null">
                and create_time  &lt; #{end}
            </if>
        </where>
    </select>

四、订单统计 

需求分析和设计:

Controller:


    /**
     * 订单统计
     * @param begin
     * @param end
     * @return
     * */
    @ApiOperation("订单统计")
    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> ordersStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        log.info("订单统计:{},{}",begin,end);

        return Result.success(reportService.ordersStatistics(begin,end));
    }

Service:

  /**
     * 订单统计
     * @param begin
     * @param end
     * @return
     * */
    @Override
    public OrderReportVO ordersStatistics(LocalDate begin, LocalDate end) {
        List<LocalDate> datelist=new ArrayList<>();
        datelist.add(begin);
        while(!begin.equals(end)){
            //日期计算,循环到enddate为止
            begin = begin.plusDays(1);
            datelist.add(begin);
        }
        //集合元素按照 a,b格式转化成字符串
        String dateList = StringUtils.join(datelist, ",");

        //每日订单数
        List<Double> orderslist =new ArrayList<>();
        for (LocalDate localDate : datelist) {
            LocalDateTime begindate = LocalDateTime.of(localDate, LocalTime.MIN);
            LocalDateTime enddate = LocalDateTime.of(localDate, LocalTime.MAX);
            Map map=new HashMap();
            map.put("begin",begindate);
            map.put("end",enddate);
            //每日订单数量
            Double ordercount = orderMapper.sumorderByMap(map);
            orderslist.add(ordercount);
        }
        //集合元素按照 a,b格式转化成字符串
        String orderCountList = StringUtils.join(orderslist, ",");

        //每日有效订单数
        List<Double> validorderslist =new ArrayList<>();
        for (LocalDate localDate : datelist) {
            LocalDateTime begindate = LocalDateTime.of(localDate, LocalTime.MIN);
            LocalDateTime enddate = LocalDateTime.of(localDate, LocalTime.MAX);
            Map map=new HashMap();
            map.put("begin",begindate);
            map.put("end",enddate);
            map.put("status",Orders.COMPLETED);
            //每日有效订单数量
            Double validordercount = orderMapper.sumorderByMap(map);
            validorderslist.add(validordercount);
        }
        //集合元素按照 a,b格式转化成字符串
        String validorderCountList = StringUtils.join(validorderslist, ",");
        
        //完成率
        Map map=new HashMap();
        map.put("end",LocalDateTime.now());
        Double total=orderMapper.sumorderByMap(map);
        int totalorder =total.intValue();
        Double valid=orderMapper.sumorderByMap(map);
        int validordercount=valid.intValue();
        Double orderCompletion=valid/total;

        return OrderReportVO.builder()
                .orderCompletionRate(orderCompletion)
                .orderCountList(orderCountList)
                .validOrderCountList(validorderCountList)
                .totalOrderCount(totalorder)
                .validOrderCount(validordercount)
                .dateList(dateList).build();
    }

Mapper:

    <select id="sumorderByMap" resultType="java.lang.Double">
        select count(id) from sky_take_out.orders
        <where>
            <if test=" begin != null">
                and order_time  &gt; #{begin}
            </if>
            <if test=" end != null">
                and order_time  &lt; #{end}
            </if>
            <if test=" status != null">
                and status = #{status}
            </if>
        </where>
    </select>

五、销量排名

需求分析和设计:

Controller:

Service:

    /**
     * 查询销量top10
     * @param begin
     * @param end
     * @return
     * */
    @Override
    public SalesTop10ReportVO getTop10(LocalDate begin, LocalDate end) {

        LocalDateTime begindate = LocalDateTime.of(begin, LocalTime.MIN);
        LocalDateTime enddate = LocalDateTime.of(end, LocalTime.MAX);
        
        //创建集合,将查询到的数据封装入对象存入集合
        List<GoodsSalesDTO> top10 = orderMapper.getTop10(begindate, enddate);
        //创建两个集合,将所需数据分别提取
        List<String> namelist=new ArrayList<>();
        List<Integer> numberList=new ArrayList<>();
        for (GoodsSalesDTO goodsSalesDTO : top10) {
            namelist.add(goodsSalesDTO.getName());
            numberList.add(goodsSalesDTO.getNumber());
        }
        String name = StringUtils.join(namelist, ",");
        String number = StringUtils.join(numberList, ",");


        return SalesTop10ReportVO.builder()
                .nameList(name)
                .numberList(number).build();
    }

Mapper:

    <select id="getTop10" resultType="com.sky.dto.GoodsSalesDTO">
        select od.name name,sum(od.number) number
        from sky_take_out.order_detail od , sky_take_out.orders o
        where o.id=od.order_id and o.status=5
            <if test=" begin != null">
                and o.order_time  &gt; #{begin}
            </if>
             <if test=" end != null">
                and o.order_time  &lt; #{end}
             </if>
           group by od.name
           order by number desc
           limit 0,10
    </select>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2323886.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Spring Data审计利器:@LastModifiedDate详解(依赖关系补充篇)!!!

&#x1f552; Spring Data审计利器&#xff1a;LastModifiedDate详解&#x1f525;&#xff08;依赖关系补充篇&#xff09; &#x1f50c; 核心依赖解析 使用LastModifiedDate必须知道的依赖关系 #mermaid-svg-qm1OUa9Era9ktbeK {font-family:"trebuchet ms",verd…

Tweak Power:全方位电脑系统优化的高效工具

Tweak Power&#xff08;系统&#xff09; Tweak Power是一款功能强大的系统优化工具&#xff0c;专为提升Windows电脑的性能和稳定性而设计。它提供了全面的清理、优化和调整选项&#xff0c;帮助用户轻松管理系统资源、提高运行速度、延长设备寿命。 快速扫描并清理系统垃圾…

CLion下载安装(Windows11)

目录 CLion工具下载安装其他 CLion CLion-2024.1.4.exe 工具 系统&#xff1a;Windows 11 下载 1.通过百度网盘分享的文件&#xff1a;CLion-2024.1.4.exe 链接&#xff1a;https://pan.baidu.com/s/1-zH0rZPCZtQ60IqdHA7Cew?pwdux5a 提取码&#xff1a;ux5a 安装 打开…

如何用 Postman 进行高效的 Mock 测试?

Postman 是一个强大的 API 开发和测试工具&#xff0c;它可以让你轻松地创建和发送各种 HTTP 请求&#xff0c;查看响应结果&#xff0c;并进行调试和优化。但是有时候&#xff0c;你可能还没有开发好后端服务&#xff0c;或者想要模拟不同的响应场景&#xff0c;这时候就可以使…

DeepSeek API集成开发指南——Flask示例实践

DeepSeek API集成开发指南——Flask示例实践 序言&#xff1a;智能化开发新范式 DeepSeek API提供了覆盖自然语言处理、代码生成等多领域的先进AI能力。本文将以一个功能完备的Flask示例系统为载体&#xff0c;详解API的集成方法与最佳实践。通过本案例&#xff0c;开发者可快…

【天梯赛】L2-004 这是二叉搜索树吗(经典问题C++)

解题反思 //镜像树满足&#xff1a;左子树>根节点>右子树 //特殊&#xff1a;独腿二叉树&#xff0c;如pre {2&#xff0c;3&#xff0c;4}&#xff0c;递归函数用if(root tail) return&#xff1b;无法识别这种二叉树 // 用ismirror来将一般二叉树和镜像二叉搜索树的…

Postman 全局 Header 如何设置?全局设置了解一下

在使用 Postman 设置全局请求头信息的关键步骤包括&#xff1a;在集合设置页面中添加所需的头部信息&#xff0c;并确保选择适当的类型和值&#xff1b;如果需要&#xff0c;可通过 JavaScript 脚本添加其他请求头&#xff1b;最后&#xff0c;验证设置是否成功生效。 Postman…

科技赋能建筑业变革:中建海龙创新引领高质量发展新路径

在建筑工业化浪潮中&#xff0c;中建海龙科技有限公司&#xff08;以下简称“中建海龙”&#xff09;凭借深厚的技术积累与持续创新&#xff0c;成为推动行业转型升级的标杆企业。作为中国建筑国际集团旗下核心科技力量&#xff0c;中建海龙深耕模块化集成建筑&#xff08;MiC&…

QT计算器开发

1.项目架构 1.图形化界面 ​ 2.widget.h​ #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QString> #include <QStack>QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACEclass Widget : public QWidget {Q_OBJECTp…

R语言对偏态换数据进行转换(对数、平方根、立方根)

我们进行研究的时候经常会遇见偏态数据&#xff0c;数据转换是统计分析和数据预处理中的一项基本技术。使用 R 时&#xff0c;了解如何正确转换数据有助于满足统计假设、标准化分布并提高分析的准确性。在 R 中实现和可视化最常见的数据转换&#xff1a;对数、平方根和立方根转…

【云服务器】在 Linux(Ubuntu / CentOS 7)上快速搭建我的世界 Minecraft 服务器,并实现远程联机,详细教程

【云服务器】在 Linux&#xff08;Ubuntu / CentOS 7&#xff09;上快速搭建我的世界 Minecraft 服务器&#xff0c;并实现远程联机&#xff0c;详细教程 一、 服务器介绍二、下载 Minecraft 服务端二、安装 JRE 21三、安装 MCS manager 面板四、搭建服务器五、本地测试连接六、…

docker torcherve打包mar包并部署模型

使用Docker打包深度网络模型mar包到服务端 参考链接&#xff1a;Docker torchserve 部署模型流程——以WSL部署YOLO-FaceV2为例_class myhandler(basehandler): def initialize(self,-CSDN博客 1、docker拉取环境镜像命令 docker images出现此提示为没有权限取执行命令&…

【安当产品应用案例100集】042-基于安当KADP实现机密文件安全流转

一、客户需求 某集团公司客户&#xff0c;在系统业务流中&#xff0c;存在大量的内部文件流转的需求。内部业务文件有不同的安全密级&#xff0c;最初在文件流转时&#xff0c;公司内部规定点对点的文件传输&#xff0c;要使用加密工具加密后再发给需要的一方。这种方式虽然能…

附录C SLAC匹配过程命令定义与实际抓包

附录C SLAC匹配过程命令定义与实际抓包 ISO15118-3 附录A中规定了SLAC匹配过程中的请求命令及应答&#xff0c; 本文将会对比协议中的定义和实际抓包内容&#xff0c;以便读者获得直观的认识。 1 CM_SET_KEY.REQ 定义内容&#xff1a; 实际数据&#xff1a; 注意报文中的 08…

【QT】新建QT工程(详细步骤)

新建QT工程 1.方法(1)点击new project按钮&#xff0c;弹出对话框&#xff0c;新建即可&#xff0c;步骤如下&#xff1a;(2) 点击文件菜单&#xff0c;选择新建文件或者工程&#xff0c;后续步骤如上 2.QT工程文件介绍(1).pro文件 --》QT工程配置文件(2)main.cpp --》QT工程主…

安装Webpack并创建vue项目

1、新建一个工程目录 在E盘中进行新建项目 2、从命令行进入该目录,并执行NPM 的初始化命令 3、会看到目录中生成了一个“package.json”文件,它相当于NPM项目的说明书&#xff0c;里面记录了项目名称、版本、仓库地址等信息。 4、执行安装 Webpack 的命令 npm install webpac…

如何快速解决django存储session变量时出现的django.db.utils.DatabaseError错误

我们在学习django进行web编程的时候&#xff0c;有时需要将一些全局变量信息存储在session中&#xff0c;但使用过程中&#xff0c;却发现会引起数据库的报错。通过查看django源码信息&#xff0c;发现其对session信息进行了ORM映射&#xff0c;如果数据库中不存在对应的表信息…

04 单目标定实战示例

看文本文,您将获得以下技能: 1:使用opencv进行相机单目标定实战 2:标定结果参数含义和数值分析 3:Python绘制各标定板姿态,查看图像采集多样性 4:如果相机画幅旋转90,标定输入参数该如何设置? 5:图像尺寸缩放,标定结果输出有何影响? 6:单目标定结果应用类别…

极速全场景 MPP数据库starrocks介绍

目录 一、引子 二、起源 &#xff08;一&#xff09;前身 &#xff08;二&#xff09;定位 三、特点 &#xff08;一&#xff09;高性能架构 &#xff08;二&#xff09;实时分析 &#xff08;三&#xff09;高并发与扩展性 &#xff08;四&#xff09;兼容性与生态 …

RS232转Profinet网关技术,检漏仪新篇章!

RS232转Profinet网关技术&#xff0c;检漏仪新篇章&#xff01; 在现代医疗监控系统中&#xff0c;RS232转PROFINET网关扮演着至关重要的角色。这种转换设备能够将传统的RS232串行通讯接口无缝转换为PROFINET以太网通信接口&#xff0c;确保老旧设备与现代自动化系统之间的顺畅…