销量排名top10统计

文章目录

概要

所谓销量排名,销量指的是商品销售的数量。项目当中的商品主要包含两类:一个是套餐,一个是菜品,所以销量排名其实指的就是菜品和套餐销售的数量排名。通过柱形图来展示销量排名,这些销量是按照降序来排列,并且只需要统计销量排名前十的商品。

需求分析以及接口设计

业务规则:

  • 根据时间选择区间,展示销量前10的商品(包括菜品和套餐)

  • 基于可视化报表的柱状图降序展示商品销量

  • 此处的销量为商品销售的份数  

技术细节

1.Controller层

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

2.Service层:

 public SalesTop10ReportVO top10(LocalDate begin, LocalDate end) {

        LocalDateTime beginTime = LocalDateTime.of(begin, LocalTime.MIN);
        LocalDateTime endTime = LocalDateTime.of(end, LocalTime.MAX);
        List<GoodsSalesDTO> list = orderMapper.getListByStatusAndOrderTime(beginTime,endTime,Orders.COMPLETED);
        ArrayList<String> nameList = new ArrayList<>();
        ArrayList<Integer> numberList = new ArrayList<>();
        for (GoodsSalesDTO goodsSalesDTO : list) {
            nameList.add(goodsSalesDTO.getName());
            numberList.add(goodsSalesDTO.getNumber());
        }
        String nameListStr = StringUtils.join(nameList, ",");
        String numberListStr = StringUtils.join(numberList, ",");

        return SalesTop10ReportVO
                .builder()
                .nameList(nameListStr)
                .numberList(numberListStr)
                .build();
    }

3.Mapper层

 <select id="getListByStatusAndOrderTime" resultType="com.sky.dto.GoodsSalesDTO">
        select od.name,sum(od.number) number from `sky-take-out`.orders o,`sky-take-out`.order_detail od
        where o.id = od.order_id and o.status = #{status}
        <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 #将name分为一组,就是将他们结合
        order by number desc #根据销量倒序排序
        limit 0,10 #查前十个
    </select>

效果展示

 

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个VBA代码示例,用于返回各类型销量前10的产品名称和销量: ```VBA Sub Top10SalesByType() Dim ws As Worksheet Dim lastRow As Long Dim typeCol As Long, nameCol As Long, salesCol As Long Dim typeList As Variant Dim i As Long, j As Long Dim typeDict As Object, salesDict As Object Dim type As String, name As String Dim sales As Double, tempSales As Double Dim topSalesList As Variant, topNameList As Variant Dim topCount As Long 'set up worksheet and column positions Set ws = ActiveWorkbook.ActiveSheet lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row typeCol = 1 'assume type column is column A nameCol = 2 'assume name column is column B salesCol = 3 'assume sales column is column C 'get unique list of types typeList = ws.Range(ws.Cells(2, typeCol), ws.Cells(lastRow, typeCol)).Value Set typeDict = CreateObject("Scripting.Dictionary") For i = 1 To UBound(typeList, 1) If Not typeDict.Exists(typeList(i, 1)) Then typeDict.Add typeList(i, 1), 1 End If Next i 'loop through types and get top 10 sales Set salesDict = CreateObject("Scripting.Dictionary") For Each type In typeDict.keys 'get sales for each product in this type For i = 2 To lastRow If ws.Cells(i, typeCol).Value = type Then name = ws.Cells(i, nameCol).Value sales = ws.Cells(i, salesCol).Value If salesDict.Exists(name) Then tempSales = salesDict(name) tempSales = tempSales + sales salesDict(name) = tempSales Else salesDict.Add name, sales End If End If Next i 'get top 10 sales for this type topCount = 0 ReDim topSalesList(1 To 10) ReDim topNameList(1 To 10) For j = 1 To 10 topSalesList(j) = 0 topNameList(j) = "" Next j For Each name In salesDict.keys sales = salesDict(name) For j = 1 To 10 If sales > topSalesList(j) Then 'shift down other values to make room For k = 10 To j + 1 Step -1 topSalesList(k) = topSalesList(k - 1) topNameList(k) = topNameList(k - 1) Next k 'insert new value topSalesList(j) = sales topNameList(j) = name topCount = topCount + 1 Exit For End If Next j Next name 'output top 10 sales for this type ws.Range(ws.Cells(1, 5), ws.Cells(1, 6)).Value = Array("Type", "Product") For j = 1 To 10 If topNameList(j) <> "" Then ws.Cells(j + 1, 5).Value = type ws.Cells(j + 1, 6).Value = topNameList(j) End If Next j 'reset sales dictionary for next type Set salesDict = CreateObject("Scripting.Dictionary") Next type End Sub ``` 这个代码假设销售数据表格中有3列:类型、产品名称和销售额。它首先获取不同的类型列表,然后循环遍历每个类型,获取该类型下每个产品的销售额。然后,它使用字典对象来计算每个产品的总销售额,并找出该类型下销售额前10的产品。最后,它将结果输出到原始表格的右侧,其中第一列是类型,第二列是产品名称。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值