Apache ECharts

Apache ECharts介紹:

Apache ECharts 是一款基于 Javascript 的數據可視化圖表庫,提供直觀,生動,可交互,可個性化定制的數據可視化圖表。

官網地址:https://echarts.apache.org/zh/index.html

Apache ECharts入門程序:

進入官網,按照官方給的步驟:

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

?

營業額統計:

業務規則及接口設計:

  • 營業額指訂單狀態為已完成的訂單金額合計
  • 基于可視化報表的折線圖展示營業額數據,X軸為日期,Y軸為營業額
  • 根據時間選擇區間,展示每天的營業額數據

?

?前端想展示數據,也要設計接口從后端獲取數據。

返回數據這一塊,因為是前端來展示數據,所以我們提供的數據是要依照前端的規則。

?具體代碼實現:

Controll層:

@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("營業額統計");TurnoverReportVO turnoverReportVO = reportService.turnoverStatistics(begin,end);return Result.success(turnoverReportVO);}

這里有個小細節,就是查詢統計營業額,前端傳的參數是日期的起始時間和結束時間,

格式是yyyy-MM-dd這種形式,所以,我們也要用這種形式來進行接收。

@DateTimeFormat(pattern = "yyyy-MM-dd"),就用到了這個方法。

?Service層:

package com.sky.service.impl;import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import com.sky.service.ReportService;
import com.sky.vo.TurnoverReportVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import javax.validation.constraints.Min;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;@Service
public class ReportServiceImpl implements ReportService {@Autowiredprivate OrderMapper orderMapper;@Overridepublic TurnoverReportVO turnoverStatistics(LocalDate begin, LocalDate end) {//封裝TurnoverReportVO的dateList對象List<LocalDate> datelist = new ArrayList<>();datelist.add(begin);while(!begin.equals(end)){//將日期加到list集合中begin = begin.plusDays(1);datelist.add(begin);}String datejoin = StringUtils.join(datelist, ",");//封裝TurnoverReportVO的turnoverList對象List<Double> turnoverlist = new ArrayList<>();for (LocalDate localDate : datelist) {//查詢date日期對應的營業額數據,營業額是指:狀態為“已完成”的訂單金額合計LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);LocalDateTime endTime = LocalDateTime.of(localDate,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.TurnoverOfSum(map);turnover = turnover==null?0.0:turnover;turnoverlist.add(turnover);}for (Double v : turnoverlist) {System.out.println("今日份營業額:"+ v);}//封裝TurnoverReportVO對象TurnoverReportVO turnoverReportVO = new TurnoverReportVO();turnoverReportVO.setDateList(datejoin);turnoverReportVO.setTurnoverList(StringUtils.join(turnoverlist,","));return  turnoverReportVO;}
}
思路:

我們觀察TurnoverReportVO對象里面有兩個值,dateList,turnoverList

一個是日期列表,一個是營業額列表。

我們觀察前端頁面也能看成

橫坐標:是日期? ?縱坐標:是營業額。

?所以我們Service層的思路就很簡單了

1:封裝dateList對象

創建一個LocalDate的列表,然后通過LocalDate提供的庫函數plusDay,將日期由begin一直加到end,并且TurnoverReportVO對象中的dateList對象是一個String,所以我們再調用String.utils的方法對這個列表進行逗號分割。

2:封裝turnoverList對象

我們已經有了每一天的日期了,我們需要每一天的營業額(當然這里也不一定是每一天的,我們前端界面是可以選擇的,有可能是一周,也有可能是一個月)。

這個turnoverList對象的封裝就需要查詢數據庫了

select sum(amout) from orders where?order_time > ? and order_time < ? and status = 5

我們創建一個map對象里面有beginTime,endTime,status,然后傳到mapper層,查詢數據中的數據。

3:最后再封裝TurnoverReportVO對象返回。

Mapper層及注解:

/*** 動態查詢營業額* @param map* @return*/Double TurnoverOfSum(Map map);
<select id="TurnoverOfSum" 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>

用戶統計:

業務規則及接口設計:

業務規則:

  • 基于可視化報表的折線圖展示用戶數據,X軸為日期,Y軸為用戶數
  • 根據時間選擇區間,展示每天的用戶總量和新增用戶量數據

?

用戶統計和上面的不同點就是我們的返回值有三個列表:

  • dateList
  • newUserList
  • totalUserList

?具體代碼實現:

整體的思路和上面的營業額統計差不多

Controll層:

/*** 用戶數量統計* @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("用戶數量統計");UserReportVO userReportVO = reportService.userStatistics(begin,end);return Result.success(userReportVO);}

Service層:

    /*** 用戶數量統計* @param begin* @param end* @return*/@Overridepublic UserReportVO userStatistics(LocalDate begin, LocalDate end) {//封裝UserReportVO的dateList對象List<LocalDate> dateList = new ArrayList<>();while (!begin.equals(end)){dateList.add(begin);begin = begin.plusDays(1);}String datejoin = StringUtils.join(dateList, ",");//封裝UserReportVO的totalUserList對象//select count(id) from user where create_time < endTime//封裝UserReportVO的newUserList對象//select count(id) from user where create_time > beginTime and create_time < endTimeList<Integer> totalUserList =  new ArrayList<>();List<Integer> newUserList = 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.UserofSum(map);map.put("begin",beginTime);Integer newUser = userMapper.UserofSum(map);totalUserList.add(totalUser);newUserList.add(newUser);}String totaluserjoin = StringUtils.join(totalUserList, ",");String newluserjoin = StringUtils.join(newUserList, ",");UserReportVO userReportVO = new UserReportVO();userReportVO.setDateList(datejoin);userReportVO.setTotalUserList(totaluserjoin);userReportVO.setNewUserList(newluserjoin);return userReportVO;}

這里Service層的業務就是封裝三個列表

要想封裝這個用戶,我們需要去調userMapper

我們想要知道總共的用戶的sql是:

//select count(id) from user where create_time < endTime

截至到這個end時間時候的用戶數量。

而新增用戶的sql是:

//select count(id) from user where create_time > beginTime and create_time < endTime

我們要給這個新增確定一個日期范圍。?

userMapper及注解:

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

?訂單統計:

業務規則及接口設計:

業務規則:

  • 有效訂單指狀態為 “已完成” 的訂單
  • 基于可視化報表的折線圖展示訂單數據,X軸為日期,Y軸為訂單數量
  • 根據時間選擇區間,展示每天的訂單總數和有效訂單數
  • 展示所選時間區間內的有效訂單數、總訂單數、訂單完成率,訂單完成率 = 有效訂單數 / 總訂單數 * 100%

具體的代碼實現:?

Controll層:

    /*** 訂單統計* @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("訂單統計");OrderReportVO orderReportVO = reportService.ordersStatistics(begin,end);return Result.success(orderReportVO);}

Service層:

/*** 訂單統計* @param begin* @param end* @return*/@Overridepublic OrderReportVO ordersStatistics(LocalDate begin, LocalDate end) {//封裝OrderReportVO的dateList對象List<LocalDate> dateList = new ArrayList<>();while (!begin.equals(end)){dateList.add(begin);begin = begin.plusDays(1);}String datejoin = StringUtils.join(dateList, ",");//封裝OrderReportVO的orderCountList對象//封裝OrderReportVO的validOrderCountList對象List<Integer> orderCountList = new ArrayList<>();List<Integer> validOrderCountList = 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("begin",beginTime);map.put("end",endTime);Integer totalorders = orderMapper.OrdersofSum(map);map.put("status",Orders.COMPLETED);Integer validorders = orderMapper.OrdersofSum(map);orderCountList.add(totalorders);validOrderCountList.add(validorders);}String totaljoin = StringUtils.join(orderCountList, ",");String validjoin = StringUtils.join(validOrderCountList,",");//計算時間區間內的訂單總數量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.doubleValue();}OrderReportVO orderReportVO = new OrderReportVO();orderReportVO.setDateList(datejoin);orderReportVO.setOrderCountList(totaljoin);orderReportVO.setValidOrderCountList(validjoin);orderReportVO.setTotalOrderCount(totalOrderCount);orderReportVO.setValidOrderCount(validOrderCount);orderReportVO.setOrderCompletionRate(orderCompletionRate);return orderReportVO;}

Mapper層及注解:

     /*** 訂單統計* @param map* @return*/Integer OrdersofSum(Map map);
<select id="OrdersofSum" resultType="java.lang.Integer">select count(id) from sky_take_out.orders<where><if test="begin != null">and order_time > #{begin}</if><if test="end != null">and order_Time &lt; #{end}</if><if test="status != null">and status=#{status}</if></where></select>

銷量排名統計(TOP10):

業務規則及接口設計:

業務規則:

  • 根據時間選擇區間,展示銷量前10的商品(包括菜品和套餐)
  • 基于可視化報表的柱狀圖降序展示商品銷量
  • 此處的銷量為商品銷售的份數

具體的代碼實現:

?Controll層:

/*** TOP10銷量統計* @param begin* @param end* @return*/@GetMapping("/top10")@ApiOperation("TOP10銷量統計")public Result<SalesTop10ReportVO> Top10Statostics(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){log.info("TOP10銷量統計");SalesTop10ReportVO salesTop10ReportVO = reportService.Top10Statostics(begin,end);return Result.success(salesTop10ReportVO);}

Service層:

    /*** TOP10銷量統計* @param begin* @param end* @return*/@Overridepublic SalesTop10ReportVO Top10Statostics(LocalDate begin, LocalDate end) {LocalDateTime beginTime = LocalDateTime.of(begin,LocalTime.MIN);LocalDateTime endTime = LocalDateTime.of(end,LocalTime.MAX);System.out.println("開始時間是:"+beginTime);System.out.println("結束時間是:"+endTime);List<GoodsSalesDTO> goodsSalesDTOList = orderMapper.GetTop10(beginTime,endTime);List<String> names = goodsSalesDTOList.stream().map(GoodsSalesDTO::getName).collect(Collectors.toList());String nameList = StringUtils.join(names, ",");List<Integer> numbers = goodsSalesDTOList.stream().map(GoodsSalesDTO::getNumber).collect(Collectors.toList());String numberList = StringUtils.join(numbers, ",");SalesTop10ReportVO salesTop10ReportVO = new SalesTop10ReportVO();salesTop10ReportVO.setNameList(nameList);salesTop10ReportVO.setNumberList(numberList);return salesTop10ReportVO;}

這題的從sql語句開始分析比較簡單

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 < 2024-05-04 and o.order_time > 2024-05-10
group by od.name
order by number desc
limit 0,10

根據傳入的時間范圍來獲取數據。

Mapper層及注解:

    /*** TOP10銷量統計* @param beginTime* @param endTime* @return*/List<GoodsSalesDTO> GetTop10(LocalDateTime beginTime, LocalDateTime endTime);
<select id="GetTop10" resultType="com.sky.dto.GoodsSalesDTO">select od.name,sum(od.number) numberfrom sky_take_out.order_detail od,sky_take_out.orders owhere od.order_id = o.id and o.status = 5<if test="beginTime != null">and o.order_time > #{beginTime}</if><if test="endTime != null">and o.order_Time &lt; #{endTime}</if>group by od.nameorder by number desclimit 0,10</select>

結果展示:

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/10452.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/10452.shtml
英文地址,請注明出處:http://en.pswp.cn/web/10452.shtml

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

相關文章

Stable Diffusion寫真完整教程

前言 最近自己對AI非常癡迷&#xff0c;并且今后也會一直在這個領域深耕&#xff0c;所以就想著先入門&#xff0c;因此花時間研究了一番&#xff0c;還好&#xff0c;出了點小成果&#xff0c;接下來給大家匯報一下。 AI繪畫 提到AI繪畫&#xff0c;大家可能立馬會想到made…

A-loam建圖算法

A-LOAM構建3d點云地圖并實時轉存二維柵格地圖 A-loam算法。源代碼用的是velodyne雷達話題&#xff0c;但是現在用rslidar來處理。所以也會遇到另外一個包來轉換相關的數據。 git clone https://github.com/HKUST-Aerial-Robotics/A-LOAM.githttps://github.com/HViktorTsoi/r…

重慶市工程技術生態環境專業職稱申報條件

重慶市工程技術生態環境專業職稱申報條件鏈接重慶市人力資源和社會保障局 重慶市生態環境局關于印發重慶市工程技術生態環境專業職稱申報條件的通知_重慶市人力資源和社會保障局類別基本條件業績成果備注工程師具備博士學位&#xff1b;或具備碩士學位或第二學士學位&#xff0…

cin.ignore()函數和stoll函數

cin.ignore()函數 cin.ignore() 是一個非常實用的函數&#xff0c;主要用于控制輸入流 cin 的行為 cin.ignore(int n 1, char delimiter EOF); n&#xff1a;一個整數參數&#xff0c;表示要忽略的字符數量。默認值是1&#xff0c;意味著只忽略下一個字符。delimiter&#x…

Android 屏幕適配全攻略(下)-百變屏幕無壓力,這才是Android屏幕適配的終極解決方案

在上一篇文章中&#xff0c;我們介紹了Android屏幕適配的基本方法&#xff0c;比如使用限定符資源、圖片適配、矢量圖等。 感興趣的朋友&#xff0c;請前往查閱&#xff1a;Android 屏幕適配全攻略&#xff08;中&#xff09;-從九宮格到矢量圖&#xff0c;揭秘Android多屏幕適…

模擬集成電路(3)----單級放大器(共源極)

模擬集成電路(3)----單級放大器&#xff08;共源極&#xff09; 放大是模擬電路的基本功能 大多數自然模擬信號太小而無法處理需要足夠的信噪比 理想的放大器 線性&#xff1a;無限的幅度和頻率范圍 輸入阻抗無限大 輸出阻抗無限小 共源放大器 共源放大器就是將源極接A…

01面向類的講解

指針指向類成員使用 代碼&#xff1a; #include<iostream> using namespace std;class Test { public:void func() { cout << "call Test::func" << endl; }static void static_func();int ma;static int mb; //不依賴對象 }; void Test::static…

JavaScript 動態網頁實例 —— 事件處理應用

前言 事件處理的應用很廣泛。在事件處理的應用中,鼠標事件的應用是最常用到的。本章給出幾個鼠標事件處理應用的示例,包括:頁面預覽、圖像切換、點亮文本、鼠標跟隨、鼠標感應和禁用鼠標按鍵。在這些示例中,有的可以直接拿來應用,有的則只提供了一種應用的方法,稍加拓展,…

示例十一、聲音傳感器

通過以下幾個示例來具體展開學習,了解聲音傳感器原理及特性&#xff0c;學習聲音傳感器的應用&#xff08;干貨版&#xff09;&#xff1a; 示例十一、聲音傳感器 ino文件源碼&#xff1a; //Arduino C demo void setup() {Serial.begin(9600);pinMode(5, OUTPUT); }void loo…

機器學習-無監督學習

無監督學習是機器學習和人工智能的另一個重要分支&#xff0c;它主要處理沒有標簽的數據集&#xff0c;目的是發現數據中的隱藏模式、結構或異常。無監督學習不依賴于預先定義的輸出&#xff0c;而是讓算法自己揭示數據的本質特征。 無監督學習的過程通常包括以下幾個步驟&…

標準服務器控件

文本類型控件 通常指的是用于輸入或顯示文本的控件。 TextBox&#xff1a;這是最基本的文本輸入控件。它允許用戶在頁面上輸入文本。你可以設置它的屬性來控制其行為&#xff0c;如MaxLength&#xff08;限制輸入的最大字符數&#xff09;、ReadOnly&#xff08;是否只讀&…

【C/C++筆試練習】DNS設置文件、應用層、Dos攻擊、DNS服務、DNS、子網劃分、http狀態、路由設置、TCP連接、HTTP狀態碼、剪花布條、客似云來

文章目錄 C/C筆試練習選擇部分&#xff08;1&#xff09;DNS設置文件&#xff08;2&#xff09;應用層&#xff08;3&#xff09;Dos攻擊&#xff08;4&#xff09;DNS服務&#xff08;5&#xff09;DNS&#xff08;6&#xff09;子網劃分&#xff08;7&#xff09;http狀態&am…

docker01-簡介和概述

什么是docker&#xff1f; 我們現在開發項目是在windows操作系統使用idea開發&#xff0c;本地windows操作系統上有我們項目所需的jdk&#xff0c;mysql&#xff0c;redis&#xff0c;tomcat等環境&#xff0c;如果我們想打包我們的項目到一個別的服務器上&#xff0c;在別的服…

【Apache POI】Apache POI-操作Excel表格-簡易版

Catalog Apache POI-操作Excel表格1. 需求2. 優點3. 缺點4. 應用場景5. 使用方法6. SpringBoot工程中處理Excel表格7. Demo示例 Apache POI-操作Excel表格 1. 需求 大多數項目的在運營過程中&#xff0c;會產生運營數據&#xff0c;如外賣系統中需要統計每日的訂單完成數、每…

SpringBoot實現圖片驗證碼

引入依賴 <dependency><groupId>com.github.whvcse</groupId><artifactId>easy-captcha</artifactId><version>1.6.2</version> </dependency>代碼實現 package com.qiangesoft.captcha.controller;import com.wf.captcha.*…

最少數量線段覆蓋-華為OD

系列文章目錄 文章目錄 系列文章目錄前言一、題目描述二、輸入描述三、輸出描述四、java代碼五、測試用例 前言 本人最近再練習算法&#xff0c;所以會發布一些解題思路&#xff0c;希望大家多指教 一、題目描述 給定坐標軸上的一組線段&#xff0c;線段的起點和終點均為整數…

C++:類與對象—繼承

類與對象—繼承 一、繼承是什么&#xff1f;二、繼承定義三、基類和派生類對象賦值轉換四、繼承中的作用域五、派生類的默認成員函數六、繼承與友元七、繼承與靜態成員八、復雜的菱形繼承及菱形虛擬繼承九、繼承的總結和反思十、考察重點 一、繼承是什么&#xff1f; 繼承(inh…

知識付費系統需要哪些資質要求,教育機構教務工作計劃內容有哪些?

每個培訓教育機構都是由很多人員組成&#xff0c;作為教育機構&#xff0c;老師不必須&#xff0c;是必不可少的&#xff0c;但是除了老師之外還得配備一定數量的銷售人員和教務工作者&#xff0c;教務老師其實也就是搞后勤的&#xff0c;但是是必須的&#xff0c;那么教育機構…

Java的時間類

1. 日期類 1.1 第一代日期類 1) Date: 精確到毫秒&#xff0c;代表特定的瞬間 2) SimpleDateFormat: 格式和解析日期的類 SimpleDateFormat 格式化和解析日期的具體類。它允許進行格式化(日期-→>文本)、解析(文本->日期)和規范化. import java.text.ParseExce…

Java基礎(27)Web應用中web.xml文件中可以配置哪些內容

在Java Web應用中&#xff0c;web.xml文件&#xff08;也被稱為部署描述符&#xff09;是一個核心的配置文件&#xff0c;它位于應用的WEB-INF目錄下。web.xml文件中可以配置多種不同的組件和參數&#xff0c;它們用來定義和調整應用的行為。以下是一些web.xml中可以配置的內容…