苍穹外卖day11——数据统计图形报表(Apache ECharts)

这篇具有很好参考价值的文章主要介绍了苍穹外卖day11——数据统计图形报表(Apache ECharts)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

效果展示

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

Apache  ECharts

介绍

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

常见图表

 苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 文章来源地址https://www.toymoban.com/news/detail-621838.html

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

入门案例

快速上手 - Handbook - Apache ECharts

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 营业额统计——需求分析与设计

产品原型

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 接口设计

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

VO设计

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 营业额统计——代码开发

Controller中

/**
 * 数据统计相关接口
 */
@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));
    }
}

Service中

@Service
@Slf4j
public class ReportServiceImpl implements ReportService {
    @Autowired
    private OrderMapper orderMapper;

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

            //select sum(amount) from orders where order_time > ? and order_time < ? 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();
    }
}

Mapper中

    /**
     * 根据动态条件统计营业额数据
     * @param map
     * @return
     */
    Double sumByMap(Map map);

对应的映射文件

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

 

 营业额统计——功能测试

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 

用户统计——需求分析与设计

产品原型

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 接口设计

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

VO设计

 

用户统计——代码开发

Controller中

    /**
     * 用户统计
     * @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);
        UserReportVO userStatistics = reportService.getUserStatistics(begin, end);
        return Result.success(userStatistics);
    }

Service中

    /**
     * 统计指定时间区间内的用户数量
     * @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(totalUserList,","))
                .newUserList(StringUtils.join(newUserList,","))
                .build();
    }

Mapper中

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

对应的映射文件

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

用户统计——功能测试

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

订单统计——需求分析与设计

产品原型

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

接口设计

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 

VO设计

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring 

订单统计——代码开发

Controller中

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

Service中

    /**
     * 统计指定时间区间内的订单数据
     * @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) {
            //查询每天订单总数 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.CONFIRMED);

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

Mapper中

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

对应的映射文件

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

 

订单统计——功能测试

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 

销量排名统计——需求分析与设计

产品原型

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

接口设计

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

VO设计

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring 

销量排名统计——代码开发

Controller中

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

Service中

    /**
     * 统计指定时间区间内的销量排名前10
     * @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();
    }

Mapper中

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 > '2022-10-01' and o.order_time < '2023-10-01'
group by od.name
order by number desc
limit 0,10

 

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

对应的映射文件

    <select id="getSalesTop10" resultType="com.sky.dto.GoodsSalesDTO">
        select od.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>

 

销量排名统计——功能测试

苍穹外卖day11——数据统计图形报表(Apache ECharts),SpringBoot,spring

 

到了这里,关于苍穹外卖day11——数据统计图形报表(Apache ECharts)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 项目实战————苍穹外卖(DAY11)

    Apache ECharts 营业额统计 用户统计 订单统计 销量排名Top10 功能实现: 数据统计 数据统计效果图: 1.1 介绍 Apache ECharts 是一款基于 Javascript 的数据可视化图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表。 官网地址:Apache ECharts 常见效果展示: 1). 柱形图

    2024年01月20日
    浏览(39)
  • 【学习笔记】java项目—苍穹外卖day11

    Apache ECharts 营业额统计 用户统计 订单统计 销量排名Top10 功能实现: 数据统计 数据统计效果图: 1.1 介绍 Apache ECharts 是一款基于 Javascript 的数据可视化图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表。 官网地址:https://echarts.apache.org/zh/index.html 常见效果

    2024年04月09日
    浏览(36)
  • 苍穹外卖 Spring Task 来单提醒 催单Apache ECharts day10~11

    Spring Task 订单状态定时处理 WebSocket 来单提醒 客户催单 功能实现: 订单状态定时处理 、 来单提醒 和 客户催单 订单状态定时处理: 来单提醒: 客户催单: 1.1 介绍 Spring Task 是Spring框架提供的 任务调度工具 ,可以按照约定的时间自动执行某个代码逻辑。 定位: 定时任务框

    2024年02月14日
    浏览(29)
  • Python数据可视化(三)绘制统计图形大全

    以 Python 代码的形式讲解柱状图的绘制原理,这里重点讲解 bar()函数的使用方法。 代码: 运行结果: 为了展示图表里的中文字体,我们选择字体“SimHei”, 通 过 “mpl.rcParams[\\\"font.sans-serif\\\"] =[\\\"SimHei\\\"]”完成字体配置任务。不使用默认的“Unicode minus”模式来处理坐标轴轴线的刻

    2024年02月02日
    浏览(36)
  • 苍穹外卖 day12 Echats 营业台数据可视化整合

    工作台 Apache POI 导出运营数据Excel报表 功能实现: 工作台 、 数据导出 工作台效果图: 数据导出效果图: 在数据统计页面点击 数据导出 :生成Excel报表 1.1 需求分析和设计 1.1.1 产品原型 工作台是 系统运营的数据看板,并提供快捷操作入口 ,可以有效提高商家的工作效率。

    2024年02月09日
    浏览(39)
  • PythonStock(37)股票系统:Python股票系统发布V2.0版本,改个名字吧,叫Python全栈股票系统2.0,可以实现数据的抓取(akshare),统计分析,数据报表展示。

    使用Python开发一个web股票项目。 【github项目地址】: https://github.com/pythonstock/stock 【知乎专栏地址】: https://zhuanlan.zhihu.com/pythonstock 【docker hub地址下载】: https://hub.docker.com/r/pythonstock/pythonstock 【相关stock资料分类】: http://blog.csdn.net/freewebsys/article/category/7076584 主要使用开发

    2023年04月08日
    浏览(33)
  • 【大数据学习篇11】广告点击流实时统计

    掌握广告点击流实时统计实现思路 掌握利用Kafka生产用户广告点击流数据 了解数据库设计 掌握如何创建Spark Streaming连接 掌握利用Spark Streaming读取业务数据 掌握利用Spark读取黑名单用户 掌握利用Spark Streaming过滤黑名单用户 掌握利用Spark Streaming统计每个城市不同广告的点击次

    2024年02月08日
    浏览(29)
  • 黑马苍穹外卖学习Day12

    结果 Controller层 Service实现类

    2024年01月25日
    浏览(42)
  • 苍穹外卖day02项目日志

    参考产品原型,设计表和接口。 1.1.1设计表 看员工管理的产品原型: 有员工姓名、账号、手机号、账号状态、最后操作时间等。 注意,操作一栏不是字段,其中的启用禁用才是。 再看添加员工的原型:  可以发现还有性别和身份证号。 不要忘了旁边: 还有密码。 总结出了

    2024年02月14日
    浏览(59)
  • 【100天精通Python】Day57:Python 数据分析_Pandas数据描述性统计,分组聚合,数据透视表和相关性分析

    目录 1 描述性统计(Descriptive Statistics) 2 数据分组和聚合 3 数据透视表 4 相关性分析

    2024年02月07日
    浏览(42)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包