苍穹外卖项目DAY11

2024-08-26 22:36
文章标签 项目 day11 外卖 苍穹

本文主要是介绍苍穹外卖项目DAY11,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

苍穹外卖项目DAY11

1、Apache ECharts

1.1、介绍

Apache ECharts是一款基于JavaScript的数据可视化图标库,提供直观,生动,可交互,可个性化定制的数据可视化图标

官网:Apache ECharts

1.3、入门案例

<!DOCTYPE html>
<html><head><meta charset="utf-8" /><title>ECharts</title><!-- 引入刚刚下载的 ECharts 文件 --><script src="echarts.js"></script></head><body><!-- 为 ECharts 准备一个定义了宽高的 DOM --><div id="main" style="width: 600px;height:400px;"></div><script type="text/javascript">// 基于准备好的dom,初始化echarts实例var myChart = echarts.init(document.getElementById('main'));// 指定图表的配置项和数据var option = {title: {text: 'ECharts 入门示例'},tooltip: {},legend: {data: ['销量']},xAxis: {data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']},yAxis: {},series: [{name: '销量',type: 'bar',data: [5, 20, 36, 10, 10, 20]}]};// 使用刚指定的配置项和数据显示图表。myChart.setOption(option);</script></body>
</html>

效果图:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

总结:使用Echarts,重点在于研究当前图表所需的数据格式。通常是需要后端提供符合格式要求的动态数据,然后响应给前端来展示图表

2、营业额统计

2.1、需求分析和设计

产品原型

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

接口设计:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

根据接口定义设计对应的VO:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

2.2、代码开发

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));
}

ReportServiceImpl

/*** 营业额统计* @param begin* @param end* @return*/
@Override
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);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();}

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>

2.3、功能测试

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

3、用户统计

3.1、需求分析和设计

产品原型:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

业务规则:

  • 基于可视化报表的折线图展示用户数据,X轴日期, Y轴为用户数
  • 根据时间选择区间,展示每天的用户数量和新增用户数量

接口设计:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

3.2、代码开发

根据用户统计接口的返回结果设计VO:

在这里插入图片描述

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*/
@Override
public 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(dateList,",")).newUserList(StringUtils.join(dateList,",")).build();
}

UserMapper

/*** 动态条件统计用户数量* @param map* @return*/
Integer countByMap(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>

3.3、功能测试

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

4、订单统计

4.1、需求分析和设计

产品原型:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

业务规则:

  • 有效订单指状态为“已完成”的订单
  • 基于可视化报表的折线图展示订单数据,x轴为日期,y轴为订单数量
  • 根据时间选择区间,展示每天的订单总数和有效订单数
  • 展示所选时间区间内的有效订单数、总订单数、订单完成率=有效订单数/总订单数*100%

接口设计:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

4.2、代码开发

根据订单统计接口的返回结果设计VO:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

ReportController

/*** 订单统计* @param begin* @param end* @return*/
@GetMapping("/ordersStatistics")
@ApiOperation("订单统计")
public Result<OrderReportVO> orderStatistics(@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*/
@Override
public 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) {//查询每天的订单总数LocalDateTime beginTime = LocalDateTime.of( date,LocalTime.MIN);LocalDateTime endTime = LocalDateTime.of(date,LocalTime.MAX);Integer orderCount = getOrderCount(beginTime,endTime,null);//查询每天的有效订单数Integer 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(totalOrderCount).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);

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

4.3、功能测试

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

5、销量排名Top10

5.1、需求分析和设计

产品原型:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

业务规则:

  • 根据时间选择区间,展示销量前10的商品(包括菜品和套餐)
  • 基于可视化报表的柱状图降序展示商品销量
  • 此处的销量为商品销售的份数

接口设计:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

5.2、代码开发

根据销量排名接口的返回结果设计VO:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

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*/
@Override
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

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

OrderMapper.xml

    <select id="getSalesTop10" resultType="com.sky.dto.GoodsSalesDTO">select od.name name,sum(od.number) numberfrom order_detail od,orders owhere od.order_id = o.id and o.status = 5<if test="begin != null">and order_time &gt; #{begin}</if><if test="end != null">and order_time &lt; #{end}</if>group by nameorder by number desclimit 0,10</select></mapper>

5.3、功能测试

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

查看近30日销量排名Top10统计

若查询的某一段时间没有销量数据,则显示不出效果。

这篇关于苍穹外卖项目DAY11的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1109871

相关文章

基于 Cursor 开发 Spring Boot 项目详细攻略

《基于Cursor开发SpringBoot项目详细攻略》Cursor是集成GPT4、Claude3.5等LLM的VSCode类AI编程工具,支持SpringBoot项目开发全流程,涵盖环境配... 目录cursor是什么?基于 Cursor 开发 Spring Boot 项目完整指南1. 环境准备2. 创建

Three.js构建一个 3D 商品展示空间完整实战项目

《Three.js构建一个3D商品展示空间完整实战项目》Three.js是一个强大的JavaScript库,专用于在Web浏览器中创建3D图形,:本文主要介绍Three.js构建一个3D商品展... 目录引言项目核心技术1. 项目架构与资源组织2. 多模型切换、交互热点绑定3. 移动端适配与帧率优化4. 可

sky-take-out项目中Redis的使用示例详解

《sky-take-out项目中Redis的使用示例详解》SpringCache是Spring的缓存抽象层,通过注解简化缓存管理,支持Redis等提供者,适用于方法结果缓存、更新和删除操作,但无法实现... 目录Spring Cache主要特性核心注解1.@Cacheable2.@CachePut3.@Ca

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat

Springboot项目构建时各种依赖详细介绍与依赖关系说明详解

《Springboot项目构建时各种依赖详细介绍与依赖关系说明详解》SpringBoot通过spring-boot-dependencies统一依赖版本管理,spring-boot-starter-w... 目录一、spring-boot-dependencies1.简介2. 内容概览3.核心内容结构4.

在ASP.NET项目中如何使用C#生成二维码

《在ASP.NET项目中如何使用C#生成二维码》二维码(QRCode)已广泛应用于网址分享,支付链接等场景,本文将以ASP.NET为示例,演示如何实现输入文本/URL,生成二维码,在线显示与下载的完整... 目录创建前端页面(Index.cshtml)后端二维码生成逻辑(Index.cshtml.cs)总结

Spring Boot项目如何使用外部application.yml配置文件启动JAR包

《SpringBoot项目如何使用外部application.yml配置文件启动JAR包》文章介绍了SpringBoot项目通过指定外部application.yml配置文件启动JAR包的方法,包括... 目录Spring Boot项目中使用外部application.yml配置文件启动JAR包一、基本原理

Springboot项目登录校验功能实现

《Springboot项目登录校验功能实现》本文介绍了Web登录校验的重要性,对比了Cookie、Session和JWT三种会话技术,分析其优缺点,并讲解了过滤器与拦截器的统一拦截方案,推荐使用JWT... 目录引言一、登录校验的基本概念二、HTTP协议的无状态性三、会话跟android踪技术1. Cook

springboot项目中集成shiro+jwt完整实例代码

《springboot项目中集成shiro+jwt完整实例代码》本文详细介绍如何在项目中集成Shiro和JWT,实现用户登录校验、token携带及接口权限管理,涉及自定义Realm、ModularRe... 目录简介目的需要的jar集成过程1.配置shiro2.创建自定义Realm2.1 LoginReal

idea Maven Springboot多模块项目打包时90%的问题及解决方案

《ideaMavenSpringboot多模块项目打包时90%的问题及解决方案》:本文主要介绍ideaMavenSpringboot多模块项目打包时90%的问题及解决方案,具有很好的参考价值,... 目录1. 前言2. 问题3. 解决办法4. jar 包冲突总结1. 前言之所以写这篇文章是因为在使用Mav