項目-蒼穹外賣(十五) Apache ECharts+數據統計

一、介紹

二、營業額統計

需求分析和設計:

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.pswp.cn/bicheng/74812.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/74812.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/74812.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Postgresql導出及導入符合條件的記錄

Postgresql導出及導入符合條件的記錄 Export specific rows from a PostgreSQL table as INSERT SQL script 首先進入psql。 切換到指定資料庫後將資料表中符合條件的記錄導出成csv檔&#xff1a; \c <dbname>; COPY (SELECT * FROM <tablename> WHERE <cond…

體育比分網站開發避坑指南:如何選擇靠譜的數據服務商?(10年行業經驗總結,避免踩坑!)

作為一家專業的體育比分數據服務商&#xff0c;我們接觸過大量客戶&#xff0c;發現很多人在開發體育比分網站或接入數據API時&#xff0c;由于選擇不靠譜的服務商&#xff0c;導致項目延期、數據延遲、售后無響應、隱性收費等問題&#xff0c;最終影響運營效果&#xff0c;甚至…

離心萃取機在畢赤酵母萃取中的應用

在生物醫藥領域&#xff0c;畢赤酵母因其高效表達重組蛋白的能力&#xff0c;成為基因工程的“明星宿主”。然而&#xff0c;如何從復雜的發酵體系中高效提取目標產物&#xff0c;一直是行業痛點。離心萃取機的出現&#xff0c;憑借其高速分離、精準提純的特性&#xff0c;正在…

CNN和LSTM的計算復雜度分析

前言&#xff1a;今天做邊緣計算的時候&#xff0c;在評估模型性能的時候發現NPU計算的大部分時間都花在了LSTM上&#xff0c;使用的是Bi-LSTM&#xff08;耗時占比98%&#xff09;&#xff0c;CNN耗時很短&#xff0c;不禁會思考為什么LSTM會花費這么久時間。 首先聲明一下實…

StarRocks 中 CURRENT_TIMESTAMP 和 current_time 分區過濾問題

背景 本文基于Starrocks 3.3.5 最近在進行Starrocks 跑數據的時候&#xff0c;發現了一個SQL 掃描了所有分區的數據&#xff0c;簡化后的SQL如下&#xff1a; select date_created from tableA where date_createddate_format(current_time(), %Y-%m-%d %H:%i:%S) limit 20其…

從物理學到機器學習:用技術手段量化分析職場被動攻擊行為

從物理學到機器學習:用技術手段量化分析職場被動攻擊行為 1. 從物理系統視角看團隊協作 1.1 團隊系統的能量模型 在熱力學系統中,系統的總能量由動能和勢能組成。類比到團隊協作中,我們可以建立如下模型: class TeamEnergy:def __init__(self, members):self.kinetic = …

Pytroch搭建全連接神經網絡識別MNIST手寫數字數據集

編寫步驟 之前已經記錄國多次的編寫步驟了&#xff0c;無需多言。 &#xff08;1&#xff09;準備數據集 這里我們使用MNIST數據集&#xff0c;有官方下載渠道。我們直接使用torchvison里面提供的數據讀取功能包就行。如果不使用這個&#xff0c;自己像這樣子構建也一樣。 # …

Java 基本數據類型 vs 包裝類(引用數據類型)

一、核心概念對比&#xff08;以 int vs Integer 為例&#xff09; 特性基本數據類型&#xff08;int&#xff09;包裝類&#xff08;Integer&#xff09;數據類型原始值&#xff08;Primitive Value&#xff09;對象&#xff08;Object&#xff09;默認值0null內存位置棧&…

什么是 強化學習(RL):以DQN、PPO等經典模型

什么是 強化學習(RL):以DQN、PPO等經典模型 DQN(深度 Q 網絡)和 PPO(近端策略優化)共同屬于強化學習(Reinforcement Learning,RL)這一領域。強化學習是機器學習中的一個重要分支,其核心在于智能體(Agent)通過與環境進行交互,根據環境反饋的獎勵信號來學習最優的…

【Sql Server】在SQL Server中生成雪花ID(Snowflake ID)

大家好&#xff0c;我是全棧小5&#xff0c;歡迎來到《小5講堂》。 這是《Sql Server》系列文章&#xff0c;每篇文章將以博主理解的角度展開講解。 溫馨提示&#xff1a;博主能力有限&#xff0c;理解水平有限&#xff0c;若有不對之處望指正&#xff01; 目錄 前言認識雪花ID…

HTML 表單處理進階:驗證與提交機制的學習心得與進度(一)

引言 在前端開發的廣袤領域中&#xff0c;HTML 表單處理堪稱基石般的存在&#xff0c;是構建交互性 Web 應用不可或缺的關鍵環節。從日常頻繁使用的登錄注冊表單&#xff0c;到功能多樣的搜索欄、反饋表單&#xff0c;HTML 表單如同橋梁&#xff0c;緊密連接著用戶與 Web 應用…

C# CancellationTokenSource CancellationToken Task.Run傳入token 取消令牌

基本使用方法創建 CancellationTokenSource獲取 CancellationToken將 CancellationToken 傳遞給任務***注意*** 在任務中檢查取消狀態請求取消處理取消異常 高級用法設置超時自動取消或者使用 CancelAfter 方法關聯多個取消令牌注冊回調 注意事項 CancellationTokenSource 是 …

Git 之配置ssh

1、打開 Git Bash 終端 2、設置用戶名 git config --global user.name tom3、生成公鑰 ssh-keygen -t rsa4、查看公鑰 cat ~/.ssh/id_rsa.pub5、將查看到的公鑰添加到不同Git平臺 6、驗證ssh遠程連接git倉庫 ssh -T gitgitee.com ssh -T gitcodeup.aliyun.com

cli命令編寫

新建文件夾 template-cli template-cli下運行 npm init生成package.json 新建bin文件夾和index.js文件 編寫index.js #! /usr/bin/env node console.log(hello cli)package.json增加 bin 字段注冊命令template-cli template-cli命令對應執行的內容文件 bin/index.js 運行 n…

vue3自定義動態錨點列表,實現本頁面錨點跳轉效果

需求&#xff1a;當前頁面存在多個模塊且內容很長時&#xff0c;需要提供一個錨點列表&#xff0c;可以快速查看對應模塊內容 實現步驟&#xff1a; 1.每個模塊添加唯一id&#xff0c;添加錨點列表div <template><!-- 模塊A --><div id"modalA">…

L2TP實驗

一、實驗拓撲 二、實驗內容 手工部署IPec VPN 三、實驗步驟 1、配置接口IP和安全區域 [PPPoE Client]firewall zone trust [PPPoE Client-zone-trust]add int g 1/0/0[NAS]firewall zone untrust [NAS-zone-untrust]add int g 1/0/1 [NAS]firewall zone trust [NAS-zon…

青少年編程與數學 02-012 SQLite 數據庫簡介 01課題、數據庫概要

青少年編程與數學 02-012 SQLite 數據庫簡介 01課題、數據庫概要&#xff09; 一、特點二、功能 課題摘要:SQLite 是一種輕量級的嵌入式關系型數據庫管理系統。 一、特點 輕量級 它不需要單獨的服務器進程來運行。不像 MySQL 或 PostgreSQL 這樣的數據庫系統需要一個專門的服務…

分布式系統面試總結:3、分布式鎖(和本地鎖的區別、特點、常見實現方案)

僅供自學回顧使用&#xff0c;請支持javaGuide原版書籍。 本篇文章涉及到的分布式鎖&#xff0c;在本人其他文章中也有涉及。 《JUC&#xff1a;三、兩階段終止模式、死鎖的jconsole檢測、樂觀鎖&#xff08;版本號機制CAS實現&#xff09;悲觀鎖》&#xff1a;https://blog.…

Ubuntu 系統上完全卸載 Docker

以下是在 Ubuntu 系統上完全卸載 Docker 的分步指南 一.卸載驗證 二.卸載步驟 1.停止 Docker 服務 sudo systemctl stop docker.socket sudo systemctl stop docker.service2.卸載 Docker 軟件包 # 移除 Docker 核心組件 sudo apt-get purge -y \docker-ce \docker-ce-cli …

Postman 版本信息速查:快速定位版本號

保持 Postman 更新至最新版本是非常重要的&#xff0c;因為這能讓我們享受到最新的功能&#xff0c;同時也保證了軟件的安全性。所以&#xff0c;如何快速查看你的 Postman 版本信息呢&#xff1f; 如何查看 Postman 的版本信息教程