mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
📖 MALL:code review 商品统计的代码
This commit is contained in:
parent
eb048532f7
commit
bbba83ef61
@ -1,34 +0,0 @@
|
|||||||
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);
|
|
@ -1,6 +1,15 @@
|
|||||||
package cn.iocoder.yudao.framework.common.util.object;
|
package cn.iocoder.yudao.framework.common.util.object;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.lang.func.Func1;
|
||||||
|
import cn.hutool.core.lang.func.LambdaUtil;
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.SortingField;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link cn.iocoder.yudao.framework.common.pojo.PageParam} 工具类
|
* {@link cn.iocoder.yudao.framework.common.pojo.PageParam} 工具类
|
||||||
@ -9,8 +18,50 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|||||||
*/
|
*/
|
||||||
public class PageUtils {
|
public class PageUtils {
|
||||||
|
|
||||||
|
private static final Object[] ORDER_TYPES = new String[]{SortingField.ORDER_ASC, SortingField.ORDER_DESC};
|
||||||
|
|
||||||
public static int getStart(PageParam pageParam) {
|
public static int getStart(PageParam pageParam) {
|
||||||
return (pageParam.getPageNo() - 1) * pageParam.getPageSize();
|
return (pageParam.getPageNo() - 1) * pageParam.getPageSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建排序字段(默认倒序)
|
||||||
|
*
|
||||||
|
* @param func 排序字段的 Lambda 表达式
|
||||||
|
* @param <T> 排序字段所属的类型
|
||||||
|
* @return 排序字段
|
||||||
|
*/
|
||||||
|
public static <T> SortingField buildSortingField(Func1<T, ?> func) {
|
||||||
|
return buildSortingField(func, SortingField.ORDER_DESC);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建排序字段
|
||||||
|
*
|
||||||
|
* @param func 排序字段的 Lambda 表达式
|
||||||
|
* @param order 排序类型 {@link SortingField#ORDER_ASC} {@link SortingField#ORDER_DESC}
|
||||||
|
* @param <T> 排序字段所属的类型
|
||||||
|
* @return 排序字段
|
||||||
|
*/
|
||||||
|
public static <T> SortingField buildSortingField(Func1<T, ?> func, String order) {
|
||||||
|
Assert.isTrue(ArrayUtil.contains(ORDER_TYPES, order), String.format("字段的排序类型只能是 %s/%s", ORDER_TYPES));
|
||||||
|
|
||||||
|
String fieldName = LambdaUtil.getFieldName(func);
|
||||||
|
return new SortingField(fieldName, order);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建默认的排序字段
|
||||||
|
* 如果排序字段为空,则设置排序字段;否则忽略
|
||||||
|
*
|
||||||
|
* @param sortablePageParam 排序分页查询参数
|
||||||
|
* @param func 排序字段的 Lambda 表达式
|
||||||
|
* @param <T> 排序字段所属的类型
|
||||||
|
*/
|
||||||
|
public static <T> void buildDefaultSortingField(SortablePageParam sortablePageParam, Func1<T, ?> func) {
|
||||||
|
if (sortablePageParam != null && CollUtil.isEmpty(sortablePageParam.getSortingFields())) {
|
||||||
|
sortablePageParam.setSortingFields(List.of(buildSortingField(func)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
package cn.iocoder.yudao.framework.mybatis.core.util;
|
package cn.iocoder.yudao.framework.mybatis.core.util;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.func.Func1;
|
|
||||||
import cn.hutool.core.lang.func.LambdaUtil;
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.SortingField;
|
import cn.iocoder.yudao.framework.common.pojo.SortingField;
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
@ -16,7 +11,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import net.sf.jsqlparser.expression.Alias;
|
import net.sf.jsqlparser.expression.Alias;
|
||||||
import net.sf.jsqlparser.schema.Column;
|
import net.sf.jsqlparser.schema.Column;
|
||||||
import net.sf.jsqlparser.schema.Table;
|
import net.sf.jsqlparser.schema.Table;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -91,46 +85,4 @@ public class MyBatisUtils {
|
|||||||
return new Column(tableName + StringPool.DOT + column);
|
return new Column(tableName + StringPool.DOT + column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建排序字段(默认倒序)
|
|
||||||
*
|
|
||||||
* @param func 排序字段的 Lambda 表达式
|
|
||||||
* @param <T> 排序字段所属的类型
|
|
||||||
* @return 排序字段
|
|
||||||
*/
|
|
||||||
public static <T> SortingField buildSortingField(Func1<T, ?> func) {
|
|
||||||
return buildSortingField(func, SortingField.ORDER_DESC);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建排序字段
|
|
||||||
*
|
|
||||||
* @param func 排序字段的 Lambda 表达式
|
|
||||||
* @param order 排序类型 {@link SortingField#ORDER_ASC} {@link SortingField#ORDER_DESC}
|
|
||||||
* @param <T> 排序字段所属的类型
|
|
||||||
* @return 排序字段
|
|
||||||
*/
|
|
||||||
public static <T> SortingField buildSortingField(Func1<T, ?> func, String order) {
|
|
||||||
Object[] orderTypes = {SortingField.ORDER_ASC, SortingField.ORDER_DESC};
|
|
||||||
Assert.isTrue(ArrayUtil.contains(orderTypes, order), String.format("字段的排序类型只能是%s/%s", orderTypes));
|
|
||||||
|
|
||||||
String fieldName = LambdaUtil.getFieldName(func);
|
|
||||||
return new SortingField(fieldName, order);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建默认的排序字段
|
|
||||||
* 如果排序字段为空,则设置排序字段;否则忽略
|
|
||||||
*
|
|
||||||
* @param sortablePageParam 排序分页查询参数
|
|
||||||
* @param func 排序字段的 Lambda 表达式
|
|
||||||
* @param <T> 排序字段所属的类型
|
|
||||||
*/
|
|
||||||
public static <T> void buildDefaultSortingField(SortablePageParam sortablePageParam, Func1<T, ?> func) {
|
|
||||||
if (sortablePageParam != null && CollUtil.isEmpty(sortablePageParam.getSortingFields())) {
|
|
||||||
sortablePageParam.setSortingFields(List.of(buildSortingField(func)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -252,15 +252,11 @@ import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vu
|
|||||||
/** ${table.classComment} 列表 */
|
/** ${table.classComment} 列表 */
|
||||||
defineOptions({ name: '${table.className}' })
|
defineOptions({ name: '${table.className}' })
|
||||||
|
|
||||||
// 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
const message = useMessage()
|
const { t } = useI18n() // 国际化
|
||||||
// 国际化
|
|
||||||
const { t } = useI18n()
|
|
||||||
|
|
||||||
// 列表的加载中
|
const loading = ref(true) // 列表的加载中
|
||||||
const loading = ref(true)
|
const list = ref<${simpleClassName}VO[]>([]) // 列表的数据
|
||||||
// 列表的数据
|
|
||||||
const list = ref<${simpleClassName}VO[]>([])
|
|
||||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
#if ( $table.templateType != 2 )
|
#if ( $table.templateType != 2 )
|
||||||
// 列表的总页数
|
// 列表的总页数
|
||||||
@ -283,10 +279,8 @@ const queryParams = reactive({
|
|||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
})
|
})
|
||||||
// 搜索的表单
|
const queryFormRef = ref() // 搜索的表单
|
||||||
const queryFormRef = ref()
|
const exportLoading = ref(false) // 导出的加载中
|
||||||
// 导出的加载中
|
|
||||||
const exportLoading = ref(false)
|
|
||||||
|
|
||||||
/** 查询列表 */
|
/** 查询列表 */
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
|
@ -28,6 +28,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
|
|||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
|
|
||||||
|
// TODO 芋艿:后面再看
|
||||||
@Tag(name = "用户 APP - 商品浏览记录")
|
@Tag(name = "用户 APP - 商品浏览记录")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/product/browse-history")
|
@RequestMapping("/product/browse-history")
|
||||||
@ -65,10 +66,9 @@ public class AppProductBrowseHistoryController {
|
|||||||
@Operation(summary = "获得商品浏览记录分页")
|
@Operation(summary = "获得商品浏览记录分页")
|
||||||
@PreAuthenticated
|
@PreAuthenticated
|
||||||
public CommonResult<PageResult<AppProductBrowseHistoryRespVO>> getBrowseHistoryPage(AppProductBrowseHistoryPageReqVO reqVO) {
|
public CommonResult<PageResult<AppProductBrowseHistoryRespVO>> getBrowseHistoryPage(AppProductBrowseHistoryPageReqVO reqVO) {
|
||||||
ProductBrowseHistoryPageReqVO pageReqVO = BeanUtils.toBean(reqVO, ProductBrowseHistoryPageReqVO.class);
|
ProductBrowseHistoryPageReqVO pageReqVO = BeanUtils.toBean(reqVO, ProductBrowseHistoryPageReqVO.class)
|
||||||
pageReqVO.setUserId(getLoginUserId());
|
.setUserId(getLoginUserId())
|
||||||
// 排除用户已删除的(隐藏的)
|
.setUserDeleted(false); // 排除用户已删除的(隐藏的)
|
||||||
pageReqVO.setUserDeleted(false);
|
|
||||||
PageResult<ProductBrowseHistoryDO> pageResult = productBrowseHistoryService.getBrowseHistoryPage(pageReqVO);
|
PageResult<ProductBrowseHistoryDO> pageResult = productBrowseHistoryService.getBrowseHistoryPage(pageReqVO);
|
||||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||||
return success(PageResult.empty());
|
return success(PageResult.empty());
|
||||||
@ -77,14 +77,9 @@ public class AppProductBrowseHistoryController {
|
|||||||
// 得到商品 spu 信息
|
// 得到商品 spu 信息
|
||||||
Set<Long> spuIds = convertSet(pageResult.getList(), ProductBrowseHistoryDO::getSpuId);
|
Set<Long> spuIds = convertSet(pageResult.getList(), ProductBrowseHistoryDO::getSpuId);
|
||||||
Map<Long, ProductSpuDO> spuMap = convertMap(productSpuService.getSpuList(spuIds), ProductSpuDO::getId);
|
Map<Long, ProductSpuDO> spuMap = convertMap(productSpuService.getSpuList(spuIds), ProductSpuDO::getId);
|
||||||
|
return success(BeanUtils.toBean(pageResult, AppProductBrowseHistoryRespVO.class,
|
||||||
// 转换 VO 结果
|
vo -> Optional.ofNullable(spuMap.get(vo.getSpuId()))
|
||||||
PageResult<AppProductBrowseHistoryRespVO> result = BeanUtils.toBean(pageResult, AppProductBrowseHistoryRespVO.class,
|
.ifPresent(spu -> vo.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()))));
|
||||||
vo -> Optional.ofNullable(spuMap.get(vo.getSpuId())).ifPresent(spu -> {
|
|
||||||
vo.setSpuName(spu.getName());
|
|
||||||
vo.setPicUrl(spu.getPicUrl());
|
|
||||||
}));
|
|
||||||
return success(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class AppProductBrowseHistoryPageReqVO extends PageParam {
|
public class AppProductBrowseHistoryPageReqVO extends PageParam {
|
||||||
|
|
||||||
@Schema(description = "创建时间")
|
@Schema(description = "创建时间")
|
||||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
private LocalDateTime[] createTime;
|
private LocalDateTime[] createTime;
|
||||||
|
@ -30,14 +30,6 @@ public interface ProductBrowseHistoryService {
|
|||||||
*/
|
*/
|
||||||
void hideUserBrowseHistory(Long userId, Collection<Long> spuId);
|
void hideUserBrowseHistory(Long userId, Collection<Long> spuId);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得商品浏览记录
|
|
||||||
*
|
|
||||||
* @param id 编号
|
|
||||||
* @return 商品浏览记录
|
|
||||||
*/
|
|
||||||
ProductBrowseHistoryDO getBrowseHistory(Long id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户记录数量
|
* 获取用户记录数量
|
||||||
*
|
*
|
||||||
|
@ -50,7 +50,6 @@ public class ProductBrowseHistoryServiceImpl implements ProductBrowseHistoryServ
|
|||||||
.setUserId(userId)
|
.setUserId(userId)
|
||||||
.setSpuId(spuId);
|
.setSpuId(spuId);
|
||||||
browseHistoryMapper.insert(browseHistory);
|
browseHistoryMapper.insert(browseHistory);
|
||||||
// 返回
|
|
||||||
return browseHistory.getId();
|
return browseHistory.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,11 +58,6 @@ public class ProductBrowseHistoryServiceImpl implements ProductBrowseHistoryServ
|
|||||||
browseHistoryMapper.updateUserDeletedByUserId(userId, spuIds, true);
|
browseHistoryMapper.updateUserDeletedByUserId(userId, spuIds, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductBrowseHistoryDO getBrowseHistory(Long id) {
|
|
||||||
return browseHistoryMapper.selectById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getBrowseHistoryCount(Long userId, Boolean userDeleted) {
|
public Long getBrowseHistoryCount(Long userId, Boolean userDeleted) {
|
||||||
return browseHistoryMapper.selectCountByUserIdAndUserDeleted(userId, userDeleted);
|
return browseHistoryMapper.selectCountByUserIdAndUserDeleted(userId, userDeleted);
|
||||||
|
@ -79,13 +79,9 @@ public class ProductStatisticsController {
|
|||||||
// 处理商品信息
|
// 处理商品信息
|
||||||
Set<Long> spuIds = convertSet(pageResult.getList(), ProductStatisticsDO::getSpuId);
|
Set<Long> spuIds = convertSet(pageResult.getList(), ProductStatisticsDO::getSpuId);
|
||||||
Map<Long, ProductSpuRespDTO> spuMap = convertMap(productSpuApi.getSpuList(spuIds), ProductSpuRespDTO::getId);
|
Map<Long, ProductSpuRespDTO> spuMap = convertMap(productSpuApi.getSpuList(spuIds), ProductSpuRespDTO::getId);
|
||||||
// 拼接返回
|
|
||||||
return success(BeanUtils.toBean(pageResult, ProductStatisticsRespVO.class,
|
return success(BeanUtils.toBean(pageResult, ProductStatisticsRespVO.class,
|
||||||
// 拼接商品信息
|
item -> Optional.ofNullable(spuMap.get(item.getSpuId()))
|
||||||
item -> Optional.ofNullable(spuMap.get(item.getSpuId())).ifPresent(spu -> {
|
.ifPresent(spu -> item.setName(spu.getName()).setPicUrl(spu.getPicUrl()))));
|
||||||
item.setName(spu.getName());
|
|
||||||
item.setPicUrl(spu.getPicUrl());
|
|
||||||
})));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ public class ProductStatisticsRespVO {
|
|||||||
@ExcelProperty("商品SPU编号")
|
@ExcelProperty("商品SPU编号")
|
||||||
private Long spuId;
|
private Long spuId;
|
||||||
|
|
||||||
//region 商品信息
|
// region 商品信息
|
||||||
|
|
||||||
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "商品名称")
|
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "商品名称")
|
||||||
@ExcelProperty("商品名称")
|
@ExcelProperty("商品名称")
|
||||||
@ -37,7 +37,7 @@ public class ProductStatisticsRespVO {
|
|||||||
@ExcelProperty("商品封面图")
|
@ExcelProperty("商品封面图")
|
||||||
private String picUrl;
|
private String picUrl;
|
||||||
|
|
||||||
//endregion
|
// endregion
|
||||||
|
|
||||||
@Schema(description = "浏览量", requiredMode = Schema.RequiredMode.REQUIRED, example = "17505")
|
@Schema(description = "浏览量", requiredMode = Schema.RequiredMode.REQUIRED, example = "17505")
|
||||||
@ExcelProperty("浏览量")
|
@ExcelProperty("浏览量")
|
||||||
|
@ -49,7 +49,6 @@ public class TradeStatisticsController {
|
|||||||
@Resource
|
@Resource
|
||||||
private BrokerageStatisticsService brokerageStatisticsService;
|
private BrokerageStatisticsService brokerageStatisticsService;
|
||||||
|
|
||||||
// TODO 芋艿:已经 review
|
|
||||||
@GetMapping("/summary")
|
@GetMapping("/summary")
|
||||||
@Operation(summary = "获得交易统计")
|
@Operation(summary = "获得交易统计")
|
||||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||||
@ -75,7 +74,6 @@ public class TradeStatisticsController {
|
|||||||
ArrayUtil.get(reqVO.getTimes(), 1)));
|
ArrayUtil.get(reqVO.getTimes(), 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:已经 review
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Operation(summary = "获得交易状况明细")
|
@Operation(summary = "获得交易状况明细")
|
||||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||||
@ -85,7 +83,6 @@ public class TradeStatisticsController {
|
|||||||
return success(TradeStatisticsConvert.INSTANCE.convertList(list));
|
return success(TradeStatisticsConvert.INSTANCE.convertList(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:已经 review
|
|
||||||
@GetMapping("/export-excel")
|
@GetMapping("/export-excel")
|
||||||
@Operation(summary = "导出获得交易状况明细 Excel")
|
@Operation(summary = "导出获得交易状况明细 Excel")
|
||||||
@PreAuthorize("@ss.hasPermission('statistics:trade:export')")
|
@PreAuthorize("@ss.hasPermission('statistics:trade:export')")
|
||||||
@ -98,7 +95,6 @@ public class TradeStatisticsController {
|
|||||||
ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data);
|
ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:已经 review
|
|
||||||
@GetMapping("/order-count")
|
@GetMapping("/order-count")
|
||||||
@Operation(summary = "获得交易订单数量")
|
@Operation(summary = "获得交易订单数量")
|
||||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||||
@ -116,7 +112,6 @@ public class TradeStatisticsController {
|
|||||||
return success(TradeStatisticsConvert.INSTANCE.convert(undeliveredCount, pickUpCount, afterSaleApplyCount, auditingWithdrawCount));
|
return success(TradeStatisticsConvert.INSTANCE.convert(undeliveredCount, pickUpCount, afterSaleApplyCount, auditingWithdrawCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:已经 review
|
|
||||||
@GetMapping("/order-comparison")
|
@GetMapping("/order-comparison")
|
||||||
@Operation(summary = "获得交易订单数量")
|
@Operation(summary = "获得交易订单数量")
|
||||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||||
@ -124,7 +119,6 @@ public class TradeStatisticsController {
|
|||||||
return success(tradeOrderStatisticsService.getOrderComparison());
|
return success(tradeOrderStatisticsService.getOrderComparison());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:已经 review
|
|
||||||
@GetMapping("/order-count-trend")
|
@GetMapping("/order-count-trend")
|
||||||
@Operation(summary = "获得订单量趋势统计")
|
@Operation(summary = "获得订单量趋势统计")
|
||||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||||
|
@ -33,7 +33,7 @@ public class ProductStatisticsDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private LocalDate time;
|
private LocalDate time;
|
||||||
/**
|
/**
|
||||||
* 商品SPU编号
|
* 商品 SPU 编号
|
||||||
*/
|
*/
|
||||||
private Long spuId;
|
private Long spuId;
|
||||||
/**
|
/**
|
||||||
|
@ -45,4 +45,5 @@ public class ProductStatisticsJob implements JobHandler {
|
|||||||
String result = productStatisticsService.statisticsProduct(days);
|
String result = productStatisticsService.statisticsProduct(days);
|
||||||
return StrUtil.format("商品统计:\n{}", result);
|
return StrUtil.format("商品统计:\n{}", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import cn.hutool.core.util.ArrayUtil;
|
|||||||
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
|
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.common.vo.DataComparisonRespVO;
|
||||||
import cn.iocoder.yudao.module.statistics.controller.admin.product.vo.ProductStatisticsReqVO;
|
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.controller.admin.product.vo.ProductStatisticsRespVO;
|
||||||
@ -42,8 +42,7 @@ public class ProductStatisticsServiceImpl implements ProductStatisticsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<ProductStatisticsDO> getProductStatisticsRankPage(ProductStatisticsReqVO reqVO, SortablePageParam pageParam) {
|
public PageResult<ProductStatisticsDO> getProductStatisticsRankPage(ProductStatisticsReqVO reqVO, SortablePageParam pageParam) {
|
||||||
// 默认浏览量倒序
|
PageUtils.buildDefaultSortingField(pageParam, ProductStatisticsDO::getBrowseCount); // 默认浏览量倒序
|
||||||
MyBatisUtils.buildDefaultSortingField(pageParam, ProductStatisticsDO::getBrowseCount);
|
|
||||||
return productStatisticsMapper.selectPageGroupBySpuId(reqVO, pageParam);
|
return productStatisticsMapper.selectPageGroupBySpuId(reqVO, pageParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,31 +91,26 @@ public class ProductStatisticsServiceImpl implements ProductStatisticsService {
|
|||||||
return dateStr + " 数据已存在,如果需要重新统计,请先删除对应的数据";
|
return dateStr + " 数据已存在,如果需要重新统计,请先删除对应的数据";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 统计数据
|
|
||||||
StopWatch stopWatch = new StopWatch(dateStr);
|
StopWatch stopWatch = new StopWatch(dateStr);
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
// 4. 分页统计,避免商品表数据较多时,出现超时问题
|
||||||
// 分页统计,避免商品表数据较多时,出现超时问题
|
|
||||||
final int pageSize = 100;
|
final int pageSize = 100;
|
||||||
for (int pageNo = 1; ; pageNo ++) {
|
for (int pageNo = 1; ; pageNo++) {
|
||||||
IPage<ProductStatisticsDO> page = productStatisticsMapper.selectStatisticsResultPageByTimeBetween(
|
IPage<ProductStatisticsDO> page = productStatisticsMapper.selectStatisticsResultPageByTimeBetween(
|
||||||
Page.of(pageNo, pageSize, false), beginTime, endTime);
|
Page.of(pageNo, pageSize, false), beginTime, endTime);
|
||||||
if (CollUtil.isEmpty(page.getRecords())) {
|
if (CollUtil.isEmpty(page.getRecords())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// 4.1 计算访客支付转化率(百分比)
|
||||||
for (ProductStatisticsDO record : page.getRecords()) {
|
for (ProductStatisticsDO record : page.getRecords()) {
|
||||||
record.setTime(date.toLocalDate());
|
record.setTime(date.toLocalDate());
|
||||||
// 计算 访客支付转化率(百分比)
|
|
||||||
if (record.getBrowseUserCount() != null && ObjUtil.notEqual(record.getBrowseUserCount(), 0)) {
|
if (record.getBrowseUserCount() != null && ObjUtil.notEqual(record.getBrowseUserCount(), 0)) {
|
||||||
record.setBrowseConvertPercent(100 * record.getOrderPayCount() / record.getBrowseUserCount());
|
record.setBrowseConvertPercent(100 * record.getOrderPayCount() / record.getBrowseUserCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 4.2 插入数据
|
||||||
// 4. 插入数据
|
|
||||||
productStatisticsMapper.insertBatch(page.getRecords());
|
productStatisticsMapper.insertBatch(page.getRecords());
|
||||||
}
|
}
|
||||||
|
|
||||||
return stopWatch.prettyPrint();
|
return stopWatch.prettyPrint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user