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

苍穹外卖day11——数据统计图形报表(Apache ECharts)

效果展示

Apache  ECharts

介绍

常见图表

 

 

入门案例

快速上手 - Handbook - Apache ECharts

 

 营业额统计——需求分析与设计

产品原型

 接口设计

VO设计

 营业额统计——代码开发

Controller中

/*** 数据统计相关接口*/
@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));}
}

Service中

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

Mapper中

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

对应的映射文件

    <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>

 

 营业额统计——功能测试

 

用户统计——需求分析与设计

产品原型

 接口设计

VO设计

 

用户统计——代码开发

Controller中

    /*** 用户统计* @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);UserReportVO userStatistics = reportService.getUserStatistics(begin, end);return Result.success(userStatistics);}

Service中

    /*** 统计指定时间区间内的用户数量* @return*/@Overridepublic UserReportVO getUserStatistics(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);}//存放每天的新增用户数量 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();}

Mapper中

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

对应的映射文件

    <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>

用户统计——功能测试

订单统计——需求分析与设计

产品原型

接口设计

 

VO设计

 

订单统计——代码开发

Controller中

    /*** 订单统计* @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));}

Service中

    /*** 统计指定时间区间内的订单数据* @param begin* @param end* @return*/@Overridepublic OrderReportVO getOrderStatistics(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<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.CONFIRMED);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);}

Mapper中

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

对应的映射文件

    <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>

 

订单统计——功能测试

 

销量排名统计——需求分析与设计

产品原型

接口设计

VO设计

 

销量排名统计——代码开发

Controller中

    /*** 订单统计* @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));}

Service中

    /*** 统计指定时间区间内的销量排名前10* @return*/@Overridepublic 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();}

Mapper中

select od.name ,sum(od.number) number from order_detail od,orders o where od.order_id = o.id and o.status = 5
and o.order_time > '2022-10-01' and o.order_time < '2023-10-01'
group by od.name
order by number desc
limit 0,10

 

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

对应的映射文件

    <select id="getSalesTop10" resultType="com.sky.dto.GoodsSalesDTO">select od.name ,sum(od.number) numberfrom order_detail od,orders owhere 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>

 

销量排名统计——功能测试

 

相关文章:

苍穹外卖day11——数据统计图形报表(Apache ECharts)

效果展示 Apache ECharts 介绍 常见图表 入门案例 快速上手 - Handbook - Apache ECharts 营业额统计——需求分析与设计 产品原型 接口设计 VO设计 营业额统计——代码开发 Controller中 /*** 数据统计相关接口*/ RestController RequestMapping("/admin/report&qu…...

在制作PC端Game Launcher游戏启动器时涉及到的技术选型

1&#xff09;在制作PC端Game Launcher游戏启动器时涉及到的技术选型​ 2&#xff09;​如何将图片显示到Canvas的Raw Image上面 3&#xff09;Unity 2018.4.4f1退出重启后出现黑屏 4&#xff09;如何获取到GPU耗时 这是第346篇UWA技术知识分享的推送&#xff0c;精选了UWA社区…...

SQL力扣练习(九)

目录 1.订单最多的用户(586) 示例 1 解法一(limit) 解法二(dense_rank()) 2.体育馆的人流量 示例 1 解法一(临时表) 解法二&#xff08;三表法&#xff09; 1.订单最多的用户(586) 表: Orders --------------------------- | Column Name | Type | ---------…...

软考高级架构师笔记-10数学计算题

目录 1. 前文回顾 & 考情分析2. 最小生成树3. 最短路径4. 网络与最大流量5. 线性规划6. 动态规划/决策表7. 博弈论8. 状态转移矩阵9. 决策论10. 结语1. 前文回顾 & 考情分析 前文回顾: 软考高级架构师笔记-1计算机硬件软考高级架构师笔记-2计算机软件(操作系统)软考…...

设计模式五:建造者模式(Builder Pattern)

建造者模式(Builder Pattern)是一种创建型设计模式&#xff0c;用于通过一系列步骤来构建复杂对象。它将对象的构建过程与其表示分离&#xff0c;从而允许相同的构建过程可以创建不同的表示。 建造者模式中的几个角色&#xff1a; 产品(Product)&#xff1a;表示被构建的复杂…...

C++多线程编程(包含c++20内容)

C多线程编程(包含c20内容) 文章目录 C多线程编程(包含c20内容)线程通过函数指针创建线程通过函数对象创建线程通过lambda创建线程通过成员函数创建线程线程本地存储取消线程自动join线程从线程获得结果 原子操作库原子操作原子智能指针原子引用使用原子类型等待原子变量 互斥互…...

【C语言】通讯录2.0 (动态增长版)

前言 通讯录是一种记录联系人信息的工具&#xff0c;包括姓名、电话号码、电子邮件地址、住址等。 文章的一二三章均于上一篇相同&#xff0c;可以直接看第四章改造内容。 此通讯录是基于通讯录1.0&#xff08;静态版&#xff09;的基础上进行改进&#xff0c;请先看系列文字第…...

详解AMQP协议以及JAVA体系中的AMQP

目录 1.概述 1.1.简介 1.2.抽象模型 2.spring中的amqp 2.1.spring amqp 2.2.spring boot amqp 1.概述 1.1.简介 AMQP&#xff0c;Advanced Message Queuing Protocol&#xff0c;高级消息队列协议。 百度百科上的介绍&#xff1a; 一个提供统一消息服务的应用层标准高…...

跨境电商外贸常态下,深度分析Live Market的优势

据统计&#xff0c;今年上半年&#xff0c;面对复杂严峻的外部环境&#xff0c;我国外贸进出口规模在历史同期首次突破20万亿元&#xff0c;展现较强韧性。我国正处于大力支持跨境电商发展的时代节点。在此背景下,无数商家准备抓住时代机遇,将品牌影响力从国内延伸至全世界。同…...

vue2企业级项目(八)

vue2企业级项目&#xff08;八&#xff09; 组件封装&#xff08;二&#xff09; 4、searchForm 创建components/searchForm/index.js import XSearchForm from "./index.vue"; export default XSearchForm;使用案例 <template><div class"wrap"…...

小研究 - 主动式微服务细粒度弹性缩放算法研究(二)

微服务架构已成为云数据中心的基本服务架构。但目前关于微服务系统弹性缩放的研究大多是基于服务或实例级别的水平缩放&#xff0c;忽略了能够充分利用单台服务器资源的细粒度垂直缩放&#xff0c;从而导致资源浪费。为此&#xff0c;本文设计了主动式微服务细粒度弹性缩放算法…...

【雕爷学编程】Arduino动手做(177)---ESP-32 掌控板

37款传感器与执行器的提法&#xff0c;在网络上广泛流传&#xff0c;其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块&#xff0c;依照实践出真知&#xff08;一定要动手做&#xff09;的理念&#xff0c;以学习和交流为目的&am…...

使用Gunicorn+Nginx部署Flask项目

部署-开发机上的准备工作 确认项目没有bug。用pip freeze > requirements.txt将当前环境的包导出到requirements.txt文件中&#xff0c;方便部署的时候安装。将项目上传到服务器上的/srv目录下。这里以git为例。使用git比其他上传方式&#xff08;比如使用pycharm&#xff…...

【12】STM32·HAL库开发-STM32时钟系统 | F1/F4/F7时钟树 | 配置系统时钟

目录 1.认识时钟树&#xff08;掌握&#xff09;1.1什么是时钟&#xff1f;1.2认识时钟树&#xff08;F1&#xff09;1.2.1STM32F103时钟树简图1.2.2STM32CubeMX时钟树&#xff08;F103&#xff09; 1.3认识时钟树&#xff08;F4&#xff09;1.3.1F407时钟树1.3.2F429时钟树1.3…...

Kotlin基础(十):函数进阶

前言 本文主要讲解kotlin函数&#xff0c;之前系列文章中提到过函数&#xff0c;本文是kotlin函数的进阶内容。 Kotlin文章列表 Kotlin文章列表: 点击此处跳转查看 目录 1.1 函数基本用法 Kotlin 是一种现代的静态类型编程语言&#xff0c;它在函数的定义和使用上有一些特点…...

计算机视觉(四)神经网络与典型的机器学习步骤

文章目录 神经网络生物神经元人工神经元激活函数导数 人工神经网络“层”的通俗理解 前馈神经网络Delta学习规则前馈神经网络的目标函数梯度下降输出层权重改变量 误差方向传播算法误差传播迭代公式简单的BP算例随机梯度下降&#xff08;SGD&#xff09;Mini-batch Gradient De…...

使用easyui的tree组件实现给角色快捷分配权限功能

这篇文章主要介绍怎么实现角色权限的快捷分配功能&#xff0c;不需要像大多数项目的授权一样&#xff0c;使用类似穿梭框的组件来授权。 具体实现&#xff1a;通过菜单树的勾选和取消勾选来给角色分配权限&#xff0c;在这之前&#xff0c;需要得到角色的菜单树&#xff0c;角色…...

Postman打不开/黄屏/一直转圈/Windows

环境背景 内网环境Postman-win64-8.11.1-Setup.exe 问题描述 电脑重启后&#xff0c;打开Postman后&#xff0c;出现加载弹窗&#xff1a;Preparing your workspaces…This might take a few minutes&#xff1b; 等待数分钟后&#xff0c;还是没有反应&#xff0c;于是关闭…...

使用SVM模型完成分类任务

SVM&#xff0c;即支持向量机&#xff08;Support Vector Machine&#xff09;&#xff0c;是一种常见的机器学习算法&#xff0c;用于分类和回归分析。SVM的基本思想是将数据集映射到高维空间中&#xff0c;在该空间中找到一个最优的超平面&#xff0c;将不同类别的数据点分开…...

计算机毕设 深度学习实现行人重识别 - python opencv yolo Reid

文章目录 0 前言1 课题背景2 效果展示3 行人检测4 行人重识别5 其他工具6 最后 0 前言 &#x1f525; 这两年开始毕业设计和毕业答辩的要求和难度不断提升&#xff0c;传统的毕设题目缺少创新和亮点&#xff0c;往往达不到毕业答辩的要求&#xff0c;这两年不断有学弟学妹告诉…...

手游刚开服就被攻击怎么办?如何防御DDoS?

开服初期是手游最脆弱的阶段&#xff0c;极易成为DDoS攻击的目标。一旦遭遇攻击&#xff0c;可能导致服务器瘫痪、玩家流失&#xff0c;甚至造成巨大经济损失。本文为开发者提供一套简洁有效的应急与防御方案&#xff0c;帮助快速应对并构建长期防护体系。 一、遭遇攻击的紧急应…...

python打卡day49

知识点回顾&#xff1a; 通道注意力模块复习空间注意力模块CBAM的定义 作业&#xff1a;尝试对今天的模型检查参数数目&#xff0c;并用tensorboard查看训练过程 import torch import torch.nn as nn# 定义通道注意力 class ChannelAttention(nn.Module):def __init__(self,…...

条件运算符

C中的三目运算符&#xff08;也称条件运算符&#xff0c;英文&#xff1a;ternary operator&#xff09;是一种简洁的条件选择语句&#xff0c;语法如下&#xff1a; 条件表达式 ? 表达式1 : 表达式2• 如果“条件表达式”为true&#xff0c;则整个表达式的结果为“表达式1”…...

基础测试工具使用经验

背景 vtune&#xff0c;perf, nsight system等基础测试工具&#xff0c;都是用过的&#xff0c;但是没有记录&#xff0c;都逐渐忘了。所以写这篇博客总结记录一下&#xff0c;只要以后发现新的用法&#xff0c;就记得来编辑补充一下 perf 比较基础的用法&#xff1a; 先改这…...

高危文件识别的常用算法:原理、应用与企业场景

高危文件识别的常用算法&#xff1a;原理、应用与企业场景 高危文件识别旨在检测可能导致安全威胁的文件&#xff0c;如包含恶意代码、敏感数据或欺诈内容的文档&#xff0c;在企业协同办公环境中&#xff08;如Teams、Google Workspace&#xff09;尤为重要。结合大模型技术&…...

HTML前端开发:JavaScript 常用事件详解

作为前端开发的核心&#xff0c;JavaScript 事件是用户与网页交互的基础。以下是常见事件的详细说明和用法示例&#xff1a; 1. onclick - 点击事件 当元素被单击时触发&#xff08;左键点击&#xff09; button.onclick function() {alert("按钮被点击了&#xff01;&…...

汇编常见指令

汇编常见指令 一、数据传送指令 指令功能示例说明MOV数据传送MOV EAX, 10将立即数 10 送入 EAXMOV [EBX], EAX将 EAX 值存入 EBX 指向的内存LEA加载有效地址LEA EAX, [EBX4]将 EBX4 的地址存入 EAX&#xff08;不访问内存&#xff09;XCHG交换数据XCHG EAX, EBX交换 EAX 和 EB…...

多模态大语言模型arxiv论文略读(108)

CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文标题&#xff1a;CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文作者&#xff1a;Sayna Ebrahimi, Sercan O. Arik, Tejas Nama, Tomas Pfister ➡️ 研究机构: Google Cloud AI Re…...

MySQL账号权限管理指南:安全创建账户与精细授权技巧

在MySQL数据库管理中&#xff0c;合理创建用户账号并分配精确权限是保障数据安全的核心环节。直接使用root账号进行所有操作不仅危险且难以审计操作行为。今天我们来全面解析MySQL账号创建与权限分配的专业方法。 一、为何需要创建独立账号&#xff1f; 最小权限原则&#xf…...

打手机检测算法AI智能分析网关V4守护公共/工业/医疗等多场景安全应用

一、方案背景​ 在现代生产与生活场景中&#xff0c;如工厂高危作业区、医院手术室、公共场景等&#xff0c;人员违规打手机的行为潜藏着巨大风险。传统依靠人工巡查的监管方式&#xff0c;存在效率低、覆盖面不足、判断主观性强等问题&#xff0c;难以满足对人员打手机行为精…...