mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	📖 MALL:code review 商品统计的代码
This commit is contained in:
		@@ -79,13 +79,9 @@ public class ProductStatisticsController {
 | 
			
		||||
        // 处理商品信息
 | 
			
		||||
        Set<Long> spuIds = convertSet(pageResult.getList(), ProductStatisticsDO::getSpuId);
 | 
			
		||||
        Map<Long, ProductSpuRespDTO> spuMap = convertMap(productSpuApi.getSpuList(spuIds), ProductSpuRespDTO::getId);
 | 
			
		||||
        // 拼接返回
 | 
			
		||||
        return success(BeanUtils.toBean(pageResult, ProductStatisticsRespVO.class,
 | 
			
		||||
                // 拼接商品信息
 | 
			
		||||
                item -> Optional.ofNullable(spuMap.get(item.getSpuId())).ifPresent(spu -> {
 | 
			
		||||
                    item.setName(spu.getName());
 | 
			
		||||
                    item.setPicUrl(spu.getPicUrl());
 | 
			
		||||
                })));
 | 
			
		||||
                item -> Optional.ofNullable(spuMap.get(item.getSpuId()))
 | 
			
		||||
                        .ifPresent(spu -> item.setName(spu.getName()).setPicUrl(spu.getPicUrl()))));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -27,7 +27,7 @@ public class ProductStatisticsRespVO {
 | 
			
		||||
    @ExcelProperty("商品SPU编号")
 | 
			
		||||
    private Long spuId;
 | 
			
		||||
 | 
			
		||||
    //region 商品信息
 | 
			
		||||
    // region 商品信息
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "商品名称")
 | 
			
		||||
    @ExcelProperty("商品名称")
 | 
			
		||||
@@ -37,7 +37,7 @@ public class ProductStatisticsRespVO {
 | 
			
		||||
    @ExcelProperty("商品封面图")
 | 
			
		||||
    private String picUrl;
 | 
			
		||||
 | 
			
		||||
    //endregion
 | 
			
		||||
    // endregion
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "浏览量", requiredMode = Schema.RequiredMode.REQUIRED, example = "17505")
 | 
			
		||||
    @ExcelProperty("浏览量")
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,6 @@ public class TradeStatisticsController {
 | 
			
		||||
    @Resource
 | 
			
		||||
    private BrokerageStatisticsService brokerageStatisticsService;
 | 
			
		||||
 | 
			
		||||
    // TODO 芋艿:已经 review
 | 
			
		||||
    @GetMapping("/summary")
 | 
			
		||||
    @Operation(summary = "获得交易统计")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('statistics:trade:query')")
 | 
			
		||||
@@ -75,7 +74,6 @@ public class TradeStatisticsController {
 | 
			
		||||
                ArrayUtil.get(reqVO.getTimes(), 1)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO 芋艿:已经 review
 | 
			
		||||
    @GetMapping("/list")
 | 
			
		||||
    @Operation(summary = "获得交易状况明细")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('statistics:trade:query')")
 | 
			
		||||
@@ -85,7 +83,6 @@ public class TradeStatisticsController {
 | 
			
		||||
        return success(TradeStatisticsConvert.INSTANCE.convertList(list));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO 芋艿:已经 review
 | 
			
		||||
    @GetMapping("/export-excel")
 | 
			
		||||
    @Operation(summary = "导出获得交易状况明细 Excel")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('statistics:trade:export')")
 | 
			
		||||
@@ -98,7 +95,6 @@ public class TradeStatisticsController {
 | 
			
		||||
        ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO 芋艿:已经 review
 | 
			
		||||
    @GetMapping("/order-count")
 | 
			
		||||
    @Operation(summary = "获得交易订单数量")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('statistics:trade:query')")
 | 
			
		||||
@@ -116,7 +112,6 @@ public class TradeStatisticsController {
 | 
			
		||||
        return success(TradeStatisticsConvert.INSTANCE.convert(undeliveredCount, pickUpCount, afterSaleApplyCount, auditingWithdrawCount));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO 芋艿:已经 review
 | 
			
		||||
    @GetMapping("/order-comparison")
 | 
			
		||||
    @Operation(summary = "获得交易订单数量")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('statistics:trade:query')")
 | 
			
		||||
@@ -124,7 +119,6 @@ public class TradeStatisticsController {
 | 
			
		||||
        return success(tradeOrderStatisticsService.getOrderComparison());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO 芋艿:已经 review
 | 
			
		||||
    @GetMapping("/order-count-trend")
 | 
			
		||||
    @Operation(summary = "获得订单量趋势统计")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('statistics:trade:query')")
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ public class ProductStatisticsDO extends BaseDO {
 | 
			
		||||
     */
 | 
			
		||||
    private LocalDate time;
 | 
			
		||||
    /**
 | 
			
		||||
     * 商品SPU编号
 | 
			
		||||
     * 商品 SPU 编号
 | 
			
		||||
     */
 | 
			
		||||
    private Long spuId;
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -45,4 +45,5 @@ public class ProductStatisticsJob implements JobHandler {
 | 
			
		||||
        String result = productStatisticsService.statisticsProduct(days);
 | 
			
		||||
        return StrUtil.format("商品统计:\n{}", result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ import cn.hutool.core.util.ArrayUtil;
 | 
			
		||||
import cn.hutool.core.util.ObjUtil;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
 | 
			
		||||
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
 | 
			
		||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
 | 
			
		||||
import cn.iocoder.yudao.module.statistics.controller.admin.product.vo.ProductStatisticsReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.statistics.controller.admin.product.vo.ProductStatisticsRespVO;
 | 
			
		||||
@@ -42,8 +42,7 @@ public class ProductStatisticsServiceImpl implements ProductStatisticsService {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PageResult<ProductStatisticsDO> getProductStatisticsRankPage(ProductStatisticsReqVO reqVO, SortablePageParam pageParam) {
 | 
			
		||||
        // 默认浏览量倒序
 | 
			
		||||
        MyBatisUtils.buildDefaultSortingField(pageParam, ProductStatisticsDO::getBrowseCount);
 | 
			
		||||
        PageUtils.buildDefaultSortingField(pageParam, ProductStatisticsDO::getBrowseCount); // 默认浏览量倒序
 | 
			
		||||
        return productStatisticsMapper.selectPageGroupBySpuId(reqVO, pageParam);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -92,31 +91,26 @@ public class ProductStatisticsServiceImpl implements ProductStatisticsService {
 | 
			
		||||
            return dateStr + " 数据已存在,如果需要重新统计,请先删除对应的数据";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 3. 统计数据
 | 
			
		||||
        StopWatch stopWatch = new StopWatch(dateStr);
 | 
			
		||||
        stopWatch.start();
 | 
			
		||||
 | 
			
		||||
        // 分页统计,避免商品表数据较多时,出现超时问题
 | 
			
		||||
        // 4. 分页统计,避免商品表数据较多时,出现超时问题
 | 
			
		||||
        final int pageSize = 100;
 | 
			
		||||
        for (int pageNo = 1; ; pageNo ++) {
 | 
			
		||||
        for (int pageNo = 1; ; pageNo++) {
 | 
			
		||||
            IPage<ProductStatisticsDO> page = productStatisticsMapper.selectStatisticsResultPageByTimeBetween(
 | 
			
		||||
                    Page.of(pageNo, pageSize, false), beginTime, endTime);
 | 
			
		||||
            if (CollUtil.isEmpty(page.getRecords())) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 4.1 计算访客支付转化率(百分比)
 | 
			
		||||
            for (ProductStatisticsDO record : page.getRecords()) {
 | 
			
		||||
                record.setTime(date.toLocalDate());
 | 
			
		||||
                // 计算 访客支付转化率(百分比)
 | 
			
		||||
                if (record.getBrowseUserCount() != null && ObjUtil.notEqual(record.getBrowseUserCount(), 0)) {
 | 
			
		||||
                    record.setBrowseConvertPercent(100 * record.getOrderPayCount() / record.getBrowseUserCount());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 4. 插入数据
 | 
			
		||||
            // 4.2 插入数据
 | 
			
		||||
            productStatisticsMapper.insertBatch(page.getRecords());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return stopWatch.prettyPrint();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user