统计:增加商品统计
parent
6de17c38fd
commit
4a007f0c98
@ -0,0 +1,34 @@
|
||||
CREATE TABLE product_statistics
|
||||
(
|
||||
id bigint AUTO_INCREMENT COMMENT '编号,主键自增' PRIMARY KEY,
|
||||
time date NOT NULL COMMENT '统计日期',
|
||||
spu_id bigint NOT NULL COMMENT '商品SPU编号',
|
||||
browse_count int DEFAULT 0 NOT NULL COMMENT '浏览量',
|
||||
browse_user_count int DEFAULT 0 NOT NULL COMMENT '访客量',
|
||||
favorite_count int DEFAULT 0 NOT NULL COMMENT '收藏数量',
|
||||
cart_count int DEFAULT 0 NOT NULL COMMENT '加购数量',
|
||||
order_count int DEFAULT 0 NOT NULL COMMENT '下单件数',
|
||||
order_pay_count int DEFAULT 0 NOT NULL COMMENT '支付件数',
|
||||
order_pay_price int DEFAULT 0 NOT NULL COMMENT '支付金额,单位:分',
|
||||
after_sale_count int DEFAULT 0 NOT NULL COMMENT '退款件数',
|
||||
after_sale_refund_price int DEFAULT 0 NOT NULL COMMENT '退款金额,单位:分',
|
||||
browse_convert_percent int DEFAULT 0 NOT NULL COMMENT '访客支付转化率(百分比)',
|
||||
creator varchar(64) DEFAULT '' NULL COMMENT '创建者',
|
||||
create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间',
|
||||
updater varchar(64) DEFAULT '' NULL COMMENT '更新者',
|
||||
update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
deleted bit DEFAULT b'0' NOT NULL COMMENT '是否删除',
|
||||
tenant_id bigint DEFAULT 0 NOT NULL COMMENT '租户编号'
|
||||
)
|
||||
COMMENT '商品统计表';
|
||||
|
||||
CREATE INDEX idx_time
|
||||
ON product_statistics (time);
|
||||
|
||||
CREATE INDEX idx_spu_id
|
||||
ON product_statistics (spu_id);
|
||||
|
||||
INSERT INTO system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name, status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted) VALUES ('商品统计', '', 2, 6, 2358, 'product', 'fa:product-hunt', 'statistics/product/index', 'ProductStatistics', 0, true, true, true, '', '2023-12-15 18:54:28', '', '2023-12-15 18:54:33', false);
|
||||
SELECT @parentId1 := LAST_INSERT_ID();
|
||||
INSERT INTO system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name, status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted) VALUES ('商品统计查询', 'statistics:product:query', 3, 1, @parentId, '', '', '', null, 0, true, true, true, '', '2023-09-30 03:22:40', '', '2023-09-30 03:22:40', false);
|
||||
INSERT INTO system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name, status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted) VALUES ('商品统计导出', 'statistics:product:export', 3, 2, @parentId, '', '', '', null, 0, true, true, true, '', '2023-09-30 03:22:40', '', '2023-09-30 03:22:40', false);
|
||||
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.framework.common.pojo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "可排序的分页参数")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SortablePageParam extends PageParam {
|
||||
|
||||
@Schema(description = "排序字段")
|
||||
private List<SortingField> sortingFields;
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.statistics.controller.admin.product.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 商品统计分析 Request VO")
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ProductStatisticsReqVO {
|
||||
|
||||
@Schema(description = "统计时间范围", example = "[2022-07-01 00:00:00, 2022-07-01 23:59:59]")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] times;
|
||||
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package cn.iocoder.yudao.module.statistics.controller.admin.product.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
|
||||
|
||||
@Schema(description = "管理后台 - 商品统计 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class ProductStatisticsRespVO {
|
||||
|
||||
@Schema(description = "编号,主键自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "12393")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "统计日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2023-12-16")
|
||||
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY)
|
||||
@ExcelProperty("统计日期")
|
||||
private LocalDate time;
|
||||
|
||||
@Schema(description = "商品SPU编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15114")
|
||||
@ExcelProperty("商品SPU编号")
|
||||
private Long spuId;
|
||||
|
||||
//region 商品信息
|
||||
|
||||
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "商品名称")
|
||||
@ExcelProperty("商品名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "商品封面图", requiredMode = Schema.RequiredMode.REQUIRED, example = "15114")
|
||||
@ExcelProperty("商品封面图")
|
||||
private String picUrl;
|
||||
|
||||
//endregion
|
||||
|
||||
@Schema(description = "浏览量", requiredMode = Schema.RequiredMode.REQUIRED, example = "17505")
|
||||
@ExcelProperty("浏览量")
|
||||
private Integer browseCount;
|
||||
|
||||
@Schema(description = "访客量", requiredMode = Schema.RequiredMode.REQUIRED, example = "11814")
|
||||
@ExcelProperty("访客量")
|
||||
private Integer browseUserCount;
|
||||
|
||||
@Schema(description = "收藏数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20950")
|
||||
@ExcelProperty("收藏数量")
|
||||
private Integer favoriteCount;
|
||||
|
||||
@Schema(description = "加购数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "28493")
|
||||
@ExcelProperty("加购数量")
|
||||
private Integer cartCount;
|
||||
|
||||
@Schema(description = "下单件数", requiredMode = Schema.RequiredMode.REQUIRED, example = "18966")
|
||||
@ExcelProperty("下单件数")
|
||||
private Integer orderCount;
|
||||
|
||||
@Schema(description = "支付件数", requiredMode = Schema.RequiredMode.REQUIRED, example = "15142")
|
||||
@ExcelProperty("支付件数")
|
||||
private Integer orderPayCount;
|
||||
|
||||
@Schema(description = "支付金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "11595")
|
||||
@ExcelProperty("支付金额,单位:分")
|
||||
private Integer orderPayPrice;
|
||||
|
||||
@Schema(description = "退款件数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2591")
|
||||
@ExcelProperty("退款件数")
|
||||
private Integer afterSaleCount;
|
||||
|
||||
@Schema(description = "退款金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "21709")
|
||||
@ExcelProperty("退款金额,单位:分")
|
||||
private Integer afterSaleRefundPrice;
|
||||
|
||||
@Schema(description = "访客支付转化率(百分比)", requiredMode = Schema.RequiredMode.REQUIRED, example = "15")
|
||||
private Integer browseConvertPercent;
|
||||
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package cn.iocoder.yudao.module.statistics.dal.mysql.product;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.product.vo.ProductStatisticsReqVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.product.vo.ProductStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.dal.dataobject.product.ProductStatisticsDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品统计 Mapper
|
||||
*
|
||||
* @author owen
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductStatisticsMapper extends BaseMapperX<ProductStatisticsDO> {
|
||||
|
||||
default PageResult<ProductStatisticsDO> selectPageGroupBySpuId(ProductStatisticsReqVO reqVO, SortablePageParam pageParam) {
|
||||
return selectPage(pageParam, buildWrapper(reqVO)
|
||||
.groupBy(ProductStatisticsDO::getSpuId)
|
||||
.select(ProductStatisticsDO::getSpuId)
|
||||
);
|
||||
}
|
||||
|
||||
default List<ProductStatisticsDO> selectListByTimeBetween(ProductStatisticsReqVO reqVO) {
|
||||
return selectList(buildWrapper(reqVO)
|
||||
.groupBy(ProductStatisticsDO::getTime)
|
||||
.select(ProductStatisticsDO::getTime));
|
||||
}
|
||||
|
||||
default ProductStatisticsRespVO selectVoByTimeBetween(ProductStatisticsReqVO reqVO) {
|
||||
return selectJoinOne(ProductStatisticsRespVO.class, buildWrapper(reqVO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 LambdaWrapper
|
||||
*
|
||||
* @param reqVO 查询参数
|
||||
* @return LambdaWrapper
|
||||
*/
|
||||
private static MPJLambdaWrapperX<ProductStatisticsDO> buildWrapper(ProductStatisticsReqVO reqVO) {
|
||||
return new MPJLambdaWrapperX<ProductStatisticsDO>()
|
||||
.betweenIfPresent(ProductStatisticsDO::getTime, reqVO.getTimes())
|
||||
.selectSum(ProductStatisticsDO::getBrowseCount)
|
||||
.selectSum(ProductStatisticsDO::getBrowseUserCount)
|
||||
.selectSum(ProductStatisticsDO::getFavoriteCount)
|
||||
.selectSum(ProductStatisticsDO::getCartCount)
|
||||
.selectSum(ProductStatisticsDO::getOrderCount)
|
||||
.selectSum(ProductStatisticsDO::getOrderPayCount)
|
||||
.selectSum(ProductStatisticsDO::getOrderPayPrice)
|
||||
.selectSum(ProductStatisticsDO::getAfterSaleCount)
|
||||
.selectSum(ProductStatisticsDO::getAfterSaleRefundPrice)
|
||||
.selectAvg(ProductStatisticsDO::getBrowseConvertPercent);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.statistics.service.product;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
|
||||
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;
|
||||
import cn.iocoder.yudao.module.statistics.dal.dataobject.product.ProductStatisticsDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品统计 Service 接口
|
||||
*
|
||||
* @author owen
|
||||
*/
|
||||
public interface ProductStatisticsService {
|
||||
|
||||
/**
|
||||
* 创建商品统计
|
||||
*
|
||||
* @param entity 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createProductStatistics(ProductStatisticsDO entity);
|
||||
|
||||
/**
|
||||
* 获得商品统计排行榜分页
|
||||
*
|
||||
* @param reqVO 查询条件
|
||||
* @param pageParam 分页排序查询
|
||||
* @return 商品统计分页
|
||||
*/
|
||||
PageResult<ProductStatisticsDO> getProductStatisticsRankPage(ProductStatisticsReqVO reqVO, SortablePageParam pageParam);
|
||||
|
||||
/**
|
||||
* 获得商品状况统计分析
|
||||
*
|
||||
* @param reqVO 查询条件
|
||||
* @return 统计数据对照
|
||||
*/
|
||||
DataComparisonRespVO<ProductStatisticsRespVO> getProductStatisticsAnalyse(ProductStatisticsReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得商品状况明细
|
||||
*
|
||||
* @param reqVO 查询条件
|
||||
* @return 统计数据对照
|
||||
*/
|
||||
List<ProductStatisticsDO> getProductStatisticsList(ProductStatisticsReqVO reqVO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package cn.iocoder.yudao.module.statistics.service.product;
|
||||
|
||||
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.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;
|
||||
import cn.iocoder.yudao.module.statistics.dal.dataobject.product.ProductStatisticsDO;
|
||||
import cn.iocoder.yudao.module.statistics.dal.mysql.product.ProductStatisticsMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 商品统计 Service 实现类
|
||||
*
|
||||
* @author owen
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductStatisticsServiceImpl implements ProductStatisticsService {
|
||||
|
||||
@Resource
|
||||
private ProductStatisticsMapper productStatisticsMapper;
|
||||
|
||||
@Override
|
||||
public Long createProductStatistics(ProductStatisticsDO entity) {
|
||||
// 计算 访客支付转化率(百分比)
|
||||
if (entity.getBrowseUserCount() != null && ObjUtil.notEqual(entity.getBrowseUserCount(), 0)) {
|
||||
entity.setBrowseConvertPercent(100 * entity.getOrderPayCount() / entity.getBrowseUserCount());
|
||||
}
|
||||
// 插入
|
||||
productStatisticsMapper.insert(entity);
|
||||
// 返回
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ProductStatisticsDO> getProductStatisticsRankPage(ProductStatisticsReqVO reqVO, SortablePageParam pageParam) {
|
||||
// 默认浏览量倒序
|
||||
MyBatisUtils.buildDefaultSortingField(pageParam, ProductStatisticsDO::getBrowseCount);
|
||||
return productStatisticsMapper.selectPageGroupBySpuId(reqVO, pageParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataComparisonRespVO<ProductStatisticsRespVO> getProductStatisticsAnalyse(ProductStatisticsReqVO reqVO) {
|
||||
LocalDateTime beginTime = ArrayUtil.get(reqVO.getTimes(), 0);
|
||||
LocalDateTime endTime = ArrayUtil.get(reqVO.getTimes(), 1);
|
||||
|
||||
// 统计数据
|
||||
ProductStatisticsRespVO value = productStatisticsMapper.selectVoByTimeBetween(reqVO);
|
||||
// 对照数据
|
||||
LocalDateTime referenceBeginTime = beginTime.minus(Duration.between(beginTime, endTime));
|
||||
ProductStatisticsReqVO referenceReqVO = new ProductStatisticsReqVO(new LocalDateTime[]{referenceBeginTime, beginTime});
|
||||
ProductStatisticsRespVO reference = productStatisticsMapper.selectVoByTimeBetween(referenceReqVO);
|
||||
return new DataComparisonRespVO<>(value, reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductStatisticsDO> getProductStatisticsList(ProductStatisticsReqVO reqVO) {
|
||||
return productStatisticsMapper.selectListByTimeBetween(reqVO);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue