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

news/2025/4/1 3:45:30/

一、介绍

二、营业额统计

需求分析和设计:

Controller:

Service:

/*** 营业额统计* @param begindate* @param enddate* @return* */@Overridepublic 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:5999Map 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* */@Overridepublic 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:5999Map 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:5999Map 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* */@Overridepublic 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* */@Overridepublic 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) numberfrom sky_take_out.order_detail od , sky_take_out.orders owhere 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.nameorder by number desclimit 0,10</select>


http://www.ppmy.cn/news/1584049.html

相关文章

对匿名认证的理解

概述&#xff1a;在 Spring Security 中&#xff0c;** 匿名认证&#xff08;Anonymous Authentication&#xff09;** 是一种特殊的认证机制&#xff0c;用于处理未提供有效凭证的请求。 匿名认证的本质 目的&#xff1a;允许未认证用户访问特定资源。原理&#xff1a; 当请求…

Claude 3.7:混合推理架构如何重塑AI编程范式

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》、《前端求职突破计划》 &#x1f35a; 蓝桥云课签约作者、…

[MRCTF2020]套娃

一。 按F12看源代码 发现代码 读代码发现 1.我们传的参数中不能存在_和%5f&#xff0c;可以通过使用空格来代替_&#xff0c;还是能够上传成功。 2.正则表达式"/^23333/ " &#xff0c;开头结尾都被 " " 和 " /"&#xff0c;开头结尾都被&qu…

!!!谷歌停止开源安卓

2025年3月27日&#xff0c;谷歌宣布将停止维护Android开源项目&#xff08;AOSP&#xff09;&#xff0c;未来所有Android开发将仅在谷歌内部进行。这一决定对安卓生态系统和开发者产生了深远影响。 一、事件背景 AOSP&#xff08;Android Open Source Project&#xff09;是…

设计心得——发布订阅

一、发布/订阅 发布/订阅&#xff08;Pub/Sub&#xff09;方式&#xff0c;在互联网中应用是极其广泛的&#xff0c;可以不负责任的说&#xff0c;只要上过网就用到过这种消息通信模式。发布/订阅基于异步通信模式&#xff0c;允许消息的生产者&#xff08;Publisher&#xff…

【Qt】程序加入开机自启动

设置程序为开机自启动 一是与 Windows 系统注册表交互&#xff0c;实现开机自启动功能的设置与取消&#xff1b; setAutoStart 函数 功能&#xff1a;负责处理程序开机自启动的设置与取消操作。实现细节&#xff1a; 首先&#xff0c;创建一个 QSettings 对象&#xff0c;指…

解决 Gin Web 应用中 Air 热部署无效的问题

解决 Gin Web 应用中 Air 热部署无效的问题 在使用 Go 语言开发 Web 应用时&#xff0c;Gin 框架因其高效和简洁深受开发者喜爱。为了提升开发效率&#xff0c;我们常常借助 Air 工具实现热部署&#xff0c;让代码修改后能实时生效&#xff0c;无需手动重启服务。然而&#xf…

如何构建化工质检的体系 质检LIMS系统在化工原料生产中的应用

一、构建化工质检的全流程质量管控体系 化工原料生产具有成分复杂、检测参数多的特点&#xff0c;传统实验室管理模式难以满足多品类、高频次检测需求。质检LIMS系统通过数字化改造&#xff0c;实现"样品登记-任务分配-数据采集-报告生成"的全流程自动化。以某精细化…