当前位置: 首页 > news >正文

外卖项目day14(day11)---数据统计

Apache ECharts

大家可以看我这篇文章:

Apache ECharts-CSDN博客

营业额统计

产品原型

接口设计

新建admin/ReportController 

/*** 数据统计相关接口*/
@RestController
@RequestMapping("/admin/report")
@Api(tags = "数据统计相关接口")
@Slf4j
public class ReportController {@Autowiredprivate ReportService reportService;/*** 营业额统计* @param begin* @param end* @return*/@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));}}

新建ReportService

public interface ReportService {/*** 统计指定时间区间内的营业额数据* @param begin* @param end* @return*/TurnoverReportVO getTurnoverStatistics(LocalDate begin,LocalDate end);
}

ReportServiceImpl

@Service
@Slf4j
public class ReportServiceImpl implements ReportService {@Autowiredprivate OrderMapper orderMapper;/*** 统计指定时间区间内的营业额数据* @param begin* @param end* @return*/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 = 5Map 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();}
}

 OrderMapper

    /*** 根据动态条件统计营业额数据* @param map* @return*/Double sumByMap(Map map);

OrderMapper.xml

    <select id="sumByMap" resultType="java.lang.Double">select sum(amount) from 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>

功能测试:

 

用户统计

产品原型

 

接口设计

 

 

ReportController 

    /*** 用户统计* @param begin* @param end* @return*/@GetMapping("/userStatistics")@ApiOperation("用户统计")public Result<UserReportVO> userStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){log.info("用户数据统计:{},{}",begin,end);return Result.success(reportService.getUserStatistics(begin,end));}

ReportService

    /*** 统计指定时间区间内的用户数据* @param begin* @param end* @return*/UserReportVO getUserStatistics(LocalDate begin, LocalDate end);

ReportServiceImpl

    /*** 统计指定时间区间内的用户数据* @param begin* @param end* @return*/public UserReportVO getUserStatistics(LocalDate begin, LocalDate end) {//存放从being 到 end之间的每天对应的日期List<LocalDate> dateList = new ArrayList<>();dateList.add(begin);while (!begin.equals(end)) {begin = begin.plusDays(1);dateList.add(begin);}//存放每天的新增用户数量 select count(id) from user where create_time < ?  and create_time > ?List<Integer> newUserList = new ArrayList<>();//存放每天的总用户数量  select count(id) from user where create_time < ?List<Integer> totalUserList = new ArrayList<>();for (LocalDate date : dateList) {LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);Map map = new HashMap();map.put("end",endTime);//总用户数量Integer totalUser = userMapper.countByMap(map);map.put("begin",beginTime);//新增用户数量Integer newUser = userMapper.countByMap(map);totalUserList.add(totalUser);newUserList.add(newUser);}//封装结果数据return UserReportVO.builder().dateList(StringUtils.join(dateList,",")).totalUserList(StringUtils.join(totalUserList,",")).newUserList(StringUtils.join(newUserList,",")).build();}

UserMapper

    /*** 根据动态条件统计营业额数据* @param map* @return*/Double sumByMap(Map map);

UserMapper.xml

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

功能测试:

订单统计

 产品原型

接口设计

 

 

 ReportController 

    /*** 订单统计* @param begin* @param end* @return*/@GetMapping("/ordersStatistics")@ApiOperation("订单统计")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.getOrderStatistics(begin,end));}

ReportService

    /*** 统计指定时间区间内的订单数据* @param begin* @param end* @return*/OrderReportVO getOrderStatistics(LocalDate begin, LocalDate end);

ReportServiceImpl

   /*** 统计指定时间区间内的订单数据* @param begin* @param end* @return*/public OrderReportVO getOrderStatistics(LocalDate begin, LocalDate end) {//存放从being 到 end之间的每天对应的日期List<LocalDate> dateList = new ArrayList<>();dateList.add(begin);while (!begin.equals(end)) {begin = begin.plusDays(1);dateList.add(begin);}//存放每天的订单总数List<Integer> orderCountList = new ArrayList<>();//存放每天的有效订单数List<Integer> validOrderCountList = new ArrayList<>();//遍历dateList集合,查询每天的有效订单数和订单总数for (LocalDate date : dateList) {//查询每天的订单总数 select count(id) from orders where order_time > ? and order_time < ?LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);Integer orderCount = getOrderCount(beginTime, endTime, null);//查询每天的有效订单数 select count(id) from orders where order_time > ? and order_time < ? and status =5Integer validOrderCount = getOrderCount(beginTime, endTime, Orders.COMPLETED);orderCountList.add(orderCount);validOrderCountList.add(validOrderCount);}//计算时间区间内的订单总数量Integer totalOrderCount = orderCountList.stream().reduce(Integer::sum).get();//计算时间区间内的有效订单数量Integer validOrderCount = validOrderCountList.stream().reduce(Integer::sum).get();Double orderCompletionRate = 0.0;if (totalOrderCount != 0){//计算订单完成率orderCompletionRate = validOrderCount.doubleValue() / totalOrderCount;}return  OrderReportVO.builder().dateList(StringUtils.join(dateList,",")).orderCountList(StringUtils.join(orderCountList,",")).validOrderCountList(StringUtils.join(validOrderCountList,",")).totalOrderCount(totalOrderCount).validOrderCount(validOrderCount).orderCompletionRate(orderCompletionRate).build();}/*** 根据条件统计订单数量* @param begin* @param end* @param status* @return*/private Integer getOrderCount(LocalDateTime begin,LocalDateTime end,Integer status){Map map = new HashMap();map.put("begin",begin);map.put("end",end);map.put("status",status);return orderMapper.countByMap(map);}

OrderMapper

    /*** 根据动态条件统计订单数量* @param map* @return*/Integer countByMap(Map map);

UserMapper.xml

    <select id="countByMap" resultType="java.lang.Integer">select count(id) from 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>

功能测试:

 

销量排名Top10

产品原型

接口设计

 ReportController 

    /*** 销量排名top10* @param begin* @param end* @return*/@GetMapping("/top10")@ApiOperation("销量排名top10")public Result<SalesTop10ReportVO> top10(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){log.info("销量排名top10:{},{}",begin,end);return Result.success(reportService.getSalesTop10(begin,end));}

ReportService

    /*** 统计指定时间区间内的销量排名前10* @param begin* @param end* @return*/SalesTop10ReportVO getSalesTop10(LocalDate begin, LocalDate end);

ReportServiceImpl

    /*** 统计指定时间区间内的销量排名前10* @param begin* @param end* @return*/public SalesTop10ReportVO getSalesTop10(LocalDate begin, LocalDate end) {LocalDateTime beginTime = LocalDateTime.of(begin, LocalTime.MIN);LocalDateTime endTime = LocalDateTime.of(end, LocalTime.MAX);List<GoodsSalesDTO> salesTop10 = orderMapper.getSalesTop10(beginTime, endTime);List<String> names = salesTop10.stream().map(GoodsSalesDTO::getName).collect(Collectors.toList());String nameList = StringUtils.join(names, ',');List<Integer> numbers = salesTop10.stream().map(GoodsSalesDTO::getNumber).collect(Collectors.toList());String numberList = StringUtils.join(numbers, ',');//封装返回结果return SalesTop10ReportVO.builder().nameList(nameList).numberList(numberList).build();}

OrderMapper

    /*** 统计指定时间区间销量排名前十* @param begin* @param end* @return*/List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin,LocalDateTime end);

UserMapper.xml

    <select id="getSalesTop10" resultType="com.sky.dto.GoodsSalesDTO">SELECT name,SUM(od.number) number from order_detail od,orders o where od.order_id = o.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.nameorder by number DESCLIMIT 0,10</select>

功能测试:

相关文章:

外卖项目day14(day11)---数据统计

Apache ECharts 大家可以看我这篇文章&#xff1a; Apache ECharts-CSDN博客 营业额统计 产品原型 接口设计 新建admin/ReportController /*** 数据统计相关接口*/ RestController RequestMapping("/admin/report") Api(tags "数据统计相关接口") Slf…...

养猫科普!牙口不好的猫咪怎么选粮?好吃易消化主食罐推荐

我家的猫猫已经九岁了&#xff0c;已经是一位老奶奶了&#xff0c;她的牙口不太好。对于她来说&#xff0c;膨化猫粮过于硬&#xff0c;很难咀嚼&#xff0c;所以我为她准备了质地柔软的主食罐头。哪种主食罐头更适合牙口不好的猫咪呢&#xff1f;下面&#xff0c;我就来分享一…...

力扣刷题之3143.正方形中的最多点数

题干描述 给你一个二维数组 points 和一个字符串 s &#xff0c;其中 points[i] 表示第 i 个点的坐标&#xff0c;s[i] 表示第 i 个点的 标签 。 如果一个正方形的中心在 (0, 0) &#xff0c;所有边都平行于坐标轴&#xff0c;且正方形内 不 存在标签相同的两个点&#xff0c…...

【更新2022】省级经济高质量发展指标体系测度 含代码 2000-2022

重磅更新&#xff01;【章汕】制作“省级经济高质量发展指标体系测度 含代码”&#xff0c;市面上有这个版本的数据&#xff0c;但其内容非常不全面&#xff0c;个别指标有误&#xff0c;没有stata和代码&#xff0c;即使有代码小白也很容易报错&#xff1b;没有权重、宽面板等…...

缓冲流练习

练习1&#xff1a;拷贝文件 四种方式拷贝文件&#xff0c;并统计各自用时。 字节流的基本流&#xff1a;一次读写一个字节 字节流的基本流&#xff1a;一次读写一个字节数组 字节缓冲流&#xff1a;一次读写一个字节 字节缓冲流&#xff1a;一次读写一个字节数组 这里我只使用了…...

自己履行很多的话语,依旧按照这个方式进行生活

《明朝那些事儿》最后一段讲述了徐霞客的故事&#xff0c;作者当年明月通过徐霞客的生平表达了一种人生哲学。在书的结尾&#xff0c;当年明月写道&#xff1a;"成功只有一个——按照自己的方式&#xff0c;去度过人生"&#xff0c;这句话被用作《明朝那些事儿》的结…...

交通预测数据文件梳理:METR-LA

文章目录 前言一、adj_METR-LA.pkl文件读取子文件1读取子文件2读取子文件3 二、METR-LA.h5文件 前言 最近做的实验比较多&#xff0c;对于交通预测数据的各种文件和文件中的数据格式理解愈加混乱&#xff0c;因此打算重新做一遍梳理来加深实验数据集的理解&#xff0c;本文章作…...

按钮类控件

目录 1.Push Button 代码示例: 带有图标的按钮 代码示例: 带有快捷键的按钮 代码示例: 按钮的重复触发 2.Radio Buttion 代码示例: 选择性别 代码示例: click, press, release, toggled 的区别 代码示例: 单选框分组 3.3 Check Box 代码示例: 获取复选按钮的取值 1.Pu…...

opencascade AIS_ViewController源码学习 视图控制、包含鼠标事件等

opencascade AIS_ViewController 前言 用于在GUI和渲染线程之间处理视图器事件的辅助结构。 该类实现了以下功能&#xff1a; 缓存存储用户输入状态&#xff08;鼠标、触摸和键盘&#xff09;。 将鼠标/多点触控输入映射到视图相机操作&#xff08;平移、旋转、缩放&#xff0…...

拉削基础知识——拉床的类型及特点

拉床是所有机械加工工具中最简单的一种&#xff0c;由拉削工具、夹具、驱动装置和支撑架组成。拉削加工可获得较高的尺寸精度和较小的表面粗糙度&#xff0c;生产率较高&#xff0c;适用于大批量生产。拉床按其结构主要分为卧式和立式。应用领域和功能可分为液压拉床、自动拉床…...

docker-compose笔记

docker 目前docker官网已经无法登录&#xff0c;但是还可以从清华镜像站&#xff08;https://mirrors.tuna.tsinghua.edu.cn/docker-ce/&#xff09;下载。 使用方法可以参考早期文章《docker笔记》 docker-compose 可以从Github下载不同版本的二进制文件&#xff0c;例如do…...

C# 自定义控件无法加载

问题 在做winform开发时自己定义了一个控件&#xff0c;控件在工具箱中显示了&#xff0c;但是拖动到窗体设计器时会提示未能加载工具箱项xxx&#xff0c;将从工具箱中将其删除&#xff0c;如下图所示: 点击确定后&#xff0c;控件会从工具箱中移除。 解决方法 将 生成>…...

avl树自实现(带图),探讨平衡因子与旋转

引子&#xff1a; 在此之前&#xff0c;我们学过了搜索二叉树&#xff0c;这种树&#xff0c;在如果数据有序或接近有序的情况下&#xff0c;二叉搜索树将退化为单支树&#xff0c;查找元素相当于在顺序表中搜索元素&#xff0c;效率低下&#xff0c;而且普通搜索二叉树无法有…...

Elasticsearch 的DSL查询,聚合查询与多维度数据统计

文章目录 搜索聚合高阶概念 搜索 即从一个索引下按照特定的字段或关键词搜索出符合用户预期的一个或者一堆cocument&#xff0c;然后根据文档的相关度得分&#xff0c;在返回的结果集里并根据得分对这些文档进行一定的排序。 聚合 根据业务需求&#xff0c;对文档中的某个或…...

【如何高效处理前端常见问题:策略与实践】

在快速发展的Web开发领域&#xff0c;前端作为用户与应用程序直接交互的界面&#xff0c;其重要性不言而喻。然而&#xff0c;随着技术的不断演进和项目的复杂化&#xff0c;前端开发者在日常工作中难免会遇到各种挑战和问题。本文旨在深入探讨前端开发中常见的问题类型&#x…...

聊聊前端 JavaScript 的扩展运算符 “...“ 的使用场景

前言 在 JavaScript 中&#xff0c;... 被称为 “扩展运算符” 或 “剩余参数运算符”。 扩展运算符是在 ES6&#xff08;ECMAScript 2015&#xff09;中被引入的&#xff0c;目的是为了提高语言的表达能力和代码的可读性。 根据上下文不同&#xff0c;它主要用在数组、对象…...

华为续签了,但我准备离职了

离职华为 今天在牛客网看到一篇帖子&#xff0c;名为《华为续签了&#xff0c;但我准备离职了》。 讲得挺真诚&#xff0c;可能也是一类毕业进华为的同学的心声。 贴主提到&#xff0c;当年自己还是应届毕业的时候&#xff0c;手握多个 offer&#xff0c;最终选的华为&#xff…...

RocketMQ 的认证与授权机制

Apache RocketMQ 是一个高性能、高吞吐量、分布式的消息中间件&#xff0c;广泛应用于异步通信、应用解耦、流量削峰等场景。在企业级应用中&#xff0c;消息安全尤为重要&#xff0c;本文将深入探讨 RocketMQ 的认证与授权机制&#xff0c;帮助开发者和系统管理员更好地理解和…...

【设计模式】六大原则-上

首先什么是设计模式&#xff1f; 相信刚上大学的你和我一样&#xff0c;在学习这门课的时候根本不了解这些设计原则和模式有什么用处&#xff0c;反而不如隔壁的C更有意思&#xff0c;至少还能弹出一个小黑框&#xff0c;给我个hello world。 如何你和我一样也是这么想&#xf…...

CRC16循环冗余校验

代码&#xff1a; #include<stdio.h> #include <stdint.h>#define uchar unsigned char #define uint unsigned int static const uint8_t auchCRCHi[] { 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x0…...

Mysql80主从复制搭建;遇到问题 Slave_IO_Running: Connecting和Slave_SQL_Running以及解决过程

总结主要步骤 1.配置一个提供复制的账号&#xff1b; 创建用户 CREATE USER replication% IDENTIFIED BY your_password; GRANT REPLICATION SLAVE ON *.* TO replication%; FLUSH PRIVILEGES;2.修改配置 选择模式 主库配置&#xff1b; windows的得话是my.ini文件 默认这个目…...

Yarn网络代理配置指南:在受限网络环境中优化依赖管理

Yarn是一个现代的包管理器&#xff0c;用于JavaScript项目&#xff0c;它提供了快速、可靠和安全的依赖管理方式。然而&#xff0c;在某些受限的网络环境中&#xff0c;例如公司内网或某些国家地区&#xff0c;直接连接到公共npm仓库可能不可行或效率低下。这时&#xff0c;配置…...

AOE网及其求解关键路径

全称 Activity on Edge Network 边活动网 特点 仅存在 有向无环图 作用 用于记录完成整个工程至少花费的时间 > 哪条路径最耗时&#xff1f;也就是“ 关键路径 ” AOE网元素介绍 关键活动 关键路径上的活动称为关键活动 &#xff0c; 关键活动是不允许拖延的&#x…...

【FPGA】modelsim编译verilog代码产生错误集合

错误1&#xff1a; LHS in procedural continuous assignment may not be a net 可能是一些变量不能放在一些begin和end中&#xff0c;改下assign的位置 新手求助 LHS in procedural continuous assignment may not be a net - 数字IC设计讨论(IC前端|FPGA|ASIC) - EETOP 创…...

Rabbitmq的持久化机制

我们通过手动应答处理了在消费者出故障消息丢失的情况&#xff0c;但是如何保障当 RabbitMQ 服务停掉以后消息生产者发送过来的消息不丢失。默认情况下 RabbitMQ 退出或由于某种原因崩溃时&#xff0c;它会清空队列和消息&#xff0c;除非告知它不要这样做。确保消息不会丢失可…...

Unity UnityWebRequest封装类

简化api调用流程&#xff0c;非常奈斯。 RestWebClient.cs using System; using System.Collections; using UnityEngine; using UnityEngine.Networking;namespace MYTOOL.RestClient {/// <summary>/// UnityWebRequest封装类/// </summary>public class RestW…...

JVM内存划分

Java虚拟机&#xff08;JVM&#xff09;的内存划分是指JVM在运行时所使用的内存区域的组织和管理方式。JVM内存主要分为以下几个区域&#xff1a; 堆区&#xff08;Heap&#xff09;&#xff1a; 用途&#xff1a;用于存储所有对象实例和数组&#xff0c;是JVM中最大的一块内存…...

c++ 全排列

在C中&#xff0c;全排列&#xff08;permutation&#xff09;可以使用递归算法或标准库函数来实现。以下是使用递归和STL库std::next_permutation来生成一个集合的全排列的两种方法。 方法一&#xff1a;递归算法 递归方法通过交换元素来生成所有可能的排列组合。 #include…...

未授权访问漏洞系列详解⑤!

Kubernetes Api Server未授权访问漏洞 Kubernetes 的服务在正常启动后会开启两个端口:Localhost Port(默认8080)Secure Port(默认6443)。这两个端口都是提供 Api Server 服务的&#xff0c;一个可以直接通过Web 访问&#xff0c;另一个可以通过 kubectl 客户端进行调用。如果运…...

【CONDA】库冲突解决办法

如今&#xff0c;使用PYTHON作为开发语言时&#xff0c;或多或少都会使用到conda。安装Annaconda时一般都会选择在启动终端时进入conda的base环境。该操作&#xff0c;实际上是在~/.bashrc中添加如下脚本&#xff1a; # >>> conda initialize >>> # !! Cont…...