当前位置: 首页 > news >正文

统计销量前十的订单

 

 传入参数:

传入begin和end两个时间

返回参数

返回nameList和numberList两个String类型的列表

 

 controller层

    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> top10(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        SalesTop10ReportVO salesTop10ReportVO = reportService.getSaleTop10(begin, end);
        return Result.success(salesTop10ReportVO);
    }

实现类

    public SalesTop10ReportVO getSaleTop10(LocalDate begin, LocalDate end) {
        LocalDateTime beginTime = LocalDateTime.of(begin, LocalTime.MIN);
        LocalDateTime endTime = LocalDateTime.of(end, LocalTime.MAX);

        List<GoodsSalesDTO> saleTop = orderMapper.getSaleTop(beginTime, endTime);

        List<String> nameList = saleTop.stream().map(GoodsSalesDTO::getName).collect(Collectors.toList());
        String namelist = StringUtils.join(nameList, ",");

        List<Integer> numberList = saleTop.stream().map(GoodsSalesDTO::getNumber).collect(Collectors.toList());
        String numberlist = StringUtils.join(numberList, ",");

        SalesTop10ReportVO salesTop10ReportVO = SalesTop10ReportVO.builder()
                .nameList(namelist)
                .numberList(numberlist)
                .build();
        return salesTop10ReportVO;


    }

mapper

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 < '2022-10-30' AND o.order_time > '2022-10-01'
GROUP BY od.name 
ORDER BY `number` DESC 
limit 0,10
 <select id="getSaleTop" 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>

 

相关文章:

  • 前端面试宝典---闭包
  • Spring AOP 学习笔记 之 常用注解
  • 数据库表设计: 批次首件检验单(自定义表单)
  • Activiti(六)- 启动、挂起、激活,查询及删除流程实例
  • Why does Java‘s hashCode() in String use 31 as a multiplier?
  • AT_abc398_e [ABC398E] Tree Game 题解
  • LLM做逻辑推理题 - 三人贴纸条游戏
  • STM32 HAL实现DHT11采集温湿度
  • 大模型面经 | DeepSeek-R1中提到的思维链(Chain of Thought,CoT)是什么?
  • 如何通过Radius认证服务器实现虚拟云桌面安全登录认证:安当ASP身份认证系统解决方案
  • 鼎讯信通 便携式雷达信号模拟器:打造复杂电磁环境的“全能型选手”
  • 突破亚马逊壁垒,Web Unlocker API 助您轻松获取数据
  • 通过使用 include 语句加载并执行一个CMake脚本来引入第三方库
  • MySQL:事务隔离级别和一致性
  • 第十章 json操作
  • java实现加密解密
  • 01_JDBC
  • 集合 Collection、Map
  • Qt炫酷仪表盘
  • 计算机网络:流量控制与可靠传输机制
  • 具身智能资本盛宴:3个月37笔融资,北上深争锋BAT下场,人形机器人最火
  • 今年一季度,上海对东盟进出口总值同比增长7.1%
  • 儿童阅读空间、残疾人友好书店……上海黄浦如何打造城市书房
  • 沈辛成评《主动出击》丨科学普及,究竟需要靠谁主动出击
  • 日本长野一夜连震47次,当局呼吁警惕更大地震
  • 信心从何而来|当消博会展商遇上关税战