外卖项目day14(day11)---数据统计

news2024/9/23 3:21:18

Apache ECharts

大家可以看我这篇文章:

Apache ECharts-CSDN博客

营业额统计

产品原型

接口设计

新建admin/ReportController 

/**
 * 数据统计相关接口
 */
@RestController
@RequestMapping("/admin/report")
@Api(tags = "数据统计相关接口")
@Slf4j
public class ReportController {

    @Autowired
    private 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));
    }


}

新建ReportService

public interface ReportService {

    /**
     * 统计指定时间区间内的营业额数据
     * @param begin
     * @param end
     * @return
     */
    TurnoverReportVO getTurnoverStatistics(LocalDate begin,LocalDate end);
}

ReportServiceImpl

@Service
@Slf4j
public class ReportServiceImpl implements ReportService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 统计指定时间区间内的营业额数据
     * @param begin
     * @param end
     * @return
     */
    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);

            //select sum(amount) from orders where order_time > beginTime and order_time < endTime and status = 5
            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>

功能测试:

 

用户统计

产品原型

 

接口设计

 

 

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
     */
    public UserReportVO getUserStatistics(LocalDate begin, LocalDate end) {
        //存放从being 到 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();
    }

UserMapper

    /**
     * 根据动态条件统计营业额数据
     * @param map
     * @return
     */
    Double sumByMap(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>
    </select>

功能测试:

订单统计

 产品原型

接口设计

 

 

 ReportController 

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

ReportService

    /**
     * 统计指定时间区间内的订单数据
     * @param begin
     * @param end
     * @return
     */
    OrderReportVO getOrderStatistics(LocalDate begin, LocalDate end);

ReportServiceImpl

   /**
     * 统计指定时间区间内的订单数据
     * @param begin
     * @param end
     * @return
     */
    public OrderReportVO getOrderStatistics(LocalDate begin, LocalDate end) {
        //存放从being 到 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 =5
            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(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);
    }

OrderMapper

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

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

功能测试:

 

销量排名Top10

产品原型

接口设计

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

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

UserMapper.xml

    <select id="getSalesTop10" resultType="com.sky.dto.GoodsSalesDTO">
        SELECT name,SUM(od.number) number from order_detail od,orders o where 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.name
        order by number DESC
        LIMIT 0,10
    </select>

功能测试:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1982323.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

快速解密哈希算法利器Hasher:解密MD5、SHA256、SHA512、RIPEMD160等最佳工具

文章目录 一、工具概述1.1主要功能点1.2 支持多种哈希算法 二、安装方法三、使用教程四、结语 一、工具概述 Hasher 是一个哈希破解工具,支持多达 7 种类型的哈希算法,包括 MD4、MD5、SHA1、SHA224、SHA256、SHA384、SHA512 等。它具有自动检测哈希类型、支持 Windows 和 Linux…

浙大阿里联合开源AudioLCM,在通用音频合成领域实现潜在一致性模型的新突破...

文本到通用音频生成&#xff08;Text-to-Audio Generation&#xff0c;简称 TTA&#xff09;作为生成任务的一个子领域&#xff0c;涵盖了音效创作、音乐创作和合成语音&#xff0c;具有广泛的应用潜力。在此前的神经 TTA 模型中&#xff0c;潜在扩散模型&#xff08;Latent Di…

【RHEL7】无人值守安装系统

目录 一、kickstart服务 1.下载kickstart 2.启动图形制作工具 3.选择设置 4.查看生成的文件 5.修改ks.cfg文件 二、HTTP服务 1.下载HTTP服务 2.启动HTTP服务 3.将挂载文件和ks.cfg放在HTTP默认目录下 4.测试HTTP服务 三、PXE 1.查看pxe需要安装什么 2.安装 四、…

批量按照原图片名排序修改图片格式为00000001.png(附代码)

&#x1f4aa; 专业从事且热爱图像处理&#xff0c;图像处理专栏更新如下&#x1f447;&#xff1a; &#x1f4dd;《图像去噪》 &#x1f4dd;《超分辨率重建》 &#x1f4dd;《语义分割》 &#x1f4dd;《风格迁移》 &#x1f4dd;《目标检测》 &#x1f4dd;《暗光增强》 &a…

ARMxy工控机使用Node-Red教程:安装工具和依赖(2)

2.3 工具安装 Node-Red 安装过程需要用到网络。请通过网线将设备千兆网口 ETH1 连接至互联网&#xff0c;确保可正常访问互联网。 Node-Red 是一个基于Node的可视化编程工具&#xff0c;因此需要先安装Node。为了便于测试&#xff0c;我司提供的 node-v16.14.0-linux-arm64.t…

原神升级计划数据表:4个倒计时可以修改提示信息和时间,可以点击等级、命座、天赋、备注进行修改。

<!DOCTYPE html> <html lang"zh-CN"><head><meta charset"UTF-8"><title>原神倒计时</title><style>* {margin: 0;padding: 0;box-sizing: border-box;body {background: #0b1b2c;}}header {width: 100vw;heigh…

「队列」实现FIFO队列(先进先出队列|queue)的功能 / 手撕数据结构(C++)

概述 队列&#xff0c;是一种基本的数据结构&#xff0c;也是一种数据适配器。它在底层上以链表方法实现。 队列的显著特点是他的添加元素与删除元素操作&#xff1a;先加入的元素总是被先弹出。 一个队列应该应该是这样的&#xff1a; --------------QUEUE-------------——…

大数据资源平台建设可行性研究方案(58页PPT)

方案介绍: 在当今信息化高速发展的时代&#xff0c;大数据已成为推动各行各业创新与转型的关键力量。为了充分利用大数据的潜在价值&#xff0c;构建一个高效、安全、可扩展的大数据资源平台显得尤为重要。通过本方案的实施企业可以显著提升数据处理能力、优化资源配置、促进业…

SQL注入实例(sqli-labs/less-8)

0、初始页面 1、确定闭合字符 ?id1 and 11 ?id1 and 12 ?id1 ?id1 and 11 -- ?id1 and 12 -- 确定闭合字符为单引号&#xff0c;并且正确页面与错误页面的显示不同 2、爆库名 使用python脚本 def inject_database1(url):name for i in range(1, 20):low 32high 1…

【大模型从入门到精通5】openAI API高级内容审核-1

这里写目录标题 高级内容审核利用 OpenAI 内容审核 API 的高级内容审核技术整合与实施使用自定义规则增强审核综合示例防止提示注入的策略使用分隔符隔离命令理解分隔符使用分隔符实现命令隔离 高级内容审核 利用 OpenAI 内容审核 API 的高级内容审核技术 OpenAI 内容审核 AP…

SQL注入漏洞复现1

一、靶场信息 sqli-labs下载&#xff1a;https://github.com/Audi-1/sqli-labs phpstudy下载地址&#xff1a;http://down.php.cn/PhpStudy20180211.zip 我是在本地安装小皮搭建环境&#xff0c;相比于在服务器上搭建环境&#xff0c;更加简单 二、注入实操 Less-1 爆库名…

搭建高可用OpenStack(Queen版)集群(三)之部署认证管理服务(Keystone)控制节点集群

一、搭建高可用OpenStack&#xff08;Queen版&#xff09;集群之部署认证服务&#xff08;Keystone&#xff09;控制节点集群 一、Identity 服务简介 1、Identity概述 Identity为认证管理&#xff0c;授权管理和服务目录服务管理提供单点整合。其它Openstack服务将身份认证服务…

常用的图像增强操作

我们将介绍如何用PIL库实现一些简单的图像增强方法。 [!NOTE] 初始化配置 import numpy as np from PIL import Image, ImageOps, ImageEnhance import warningswarnings.filterwarnings(ignore) IMAGE_SIZE 640[!important] 辅助函数 主要用于控制增强幅度 def int_param…

centos7.9升级rocky

ELevate Quickstart Guide | AlmaLinux Wiki 将 CentOS 7 升级到 AlmaLinux 9 由于 Leapp 工具设计为执行一步升级&#xff0c;为了将您的 CentOS 7 机器升级到 AlmaLinux 9&#xff0c;您需要拆分升级过程&#xff1a; CentOS 7 到 AlmaLinux 8AlmaLinux 8 到 AlmaLinux 9 …

Chainlit快速实现AI对话应用1 分钟内实现聊天数据的持久化保存

概述 默认情况下&#xff0c;Chainlit 应用不会保留其生成的聊天和元素。即网页一刷新&#xff0c;所有的聊天记录&#xff0c;页面上的所有聊天记录都会消失。但是&#xff0c;存储和利用这些数据的能力可能是您的项目或组织的重要组成部分。 一旦启用&#xff0c;数据持久性…

3d模型贴图后有部分阴影怎么解决?---模大狮模型网

在展览3D模型设计行业中&#xff0c;贴图是使展品栩栩如生的关键步骤之一。然而&#xff0c;有时在贴图后可能会出现一些意外的阴影&#xff0c;影响了展品的逼真度和视觉效果。本文将探讨在3D模型贴图后出现部分阴影的原因及解决方法&#xff0c;帮助设计师有效应对这一常见问…

Transwarp Data Studio 4.0 :适应AI新时代实现三大能力提升

企业数据资产管理能力建设需要经历资源化、资产化和资本化三个阶段&#xff0c;对应数据底座建设、资产管理平台建设、流通运营平台建设三大任务。星环科技大数据开发工具 Transwarp Data Studio&#xff0c;在此过程中发挥着承上启下的关键作用。近日&#xff0c;星环科技重磅…

ESP8266 烧录----待坑

虚焊&#xff0c;连接不稳定&#xff08;*******&#xff09;&#xff1b;暂时只有通过测试接口电压进行判断&#xff0c;无其它方法 问题总结 1. 输入电压为3.3V USB转TTL RX TX 必须不能高3.3否则无输出(USB转TTL有多种类型&#xff0c;测RX TX电源&#xff1b;天问的是5V的…

sqli-labs闯关1-4

第一关&#xff1a; 这里的输入了 &#xff1f;id1 意思是以GET方式传入id1的参数 就等于SELECT * FROM users WHERE id1 LIMIT 0,1 注意&#xff1a;-- 与-- 空格的区别 在url中输入了--以后&#xff0c;后端数据会变成--空格。在 url中输入 -- 空格 变成 -- 在mysql中&…