code review:商城统计

This commit is contained in:
zhijiantianya@gmail.com 2023-10-16 20:01:25 +08:00
parent 1502159608
commit b6e63e885d
29 changed files with 74 additions and 9 deletions

View File

@ -35,9 +35,8 @@ public enum TimeRangeTypeEnum implements IntArrayValuable {
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(TimeRangeTypeEnum::getType).toArray();
/**
* 状态
* 类型
*/
private final Integer type;

View File

@ -77,6 +77,7 @@ public class MemberStatisticsController {
}
// TODO 芋艿已经 review
// TODO @疯狂要不 get 前缀去掉和下面的 list 接口保持一致
@GetMapping("/get-area-statistics-list")
@Operation(summary = "按照省份,获得会员统计列表")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
@ -85,6 +86,7 @@ public class MemberStatisticsController {
}
// TODO 芋艿已经 review
// TODO @疯狂要不 get 前缀去掉和下面的 list 接口保持一致
@GetMapping("/get-sex-statistics-list")
@Operation(summary = "按照性别,获得会员统计列表")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
@ -92,6 +94,8 @@ public class MemberStatisticsController {
return success(memberStatisticsService.getMemberSexStatisticsList());
}
// TODO 芋艿已经 review
// TODO @疯狂要不 get 前缀去掉和下面的 list 接口保持一致
@GetMapping("/get-terminal-statistics-list")
@Operation(summary = "按照终端,获得会员统计列表")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
@ -106,6 +110,7 @@ public class MemberStatisticsController {
return success(memberStatisticsService.getUserCountComparison());
}
// TODO 芋艿已经 review
@GetMapping("/register-count-list")
@Operation(summary = "获得会员注册数量列表")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")

View File

@ -10,6 +10,7 @@ public class MemberCountRespVO {
@Schema(description = "用户访问量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer visitUserCount;
// TODO @疯狂要不改成 registerUserCount注册
@Schema(description = "新增用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer createUserCount;

View File

@ -24,6 +24,7 @@ public class PayStatisticsController {
@Resource
private PayWalletStatisticsService payWalletStatisticsService;
// TODO @疯狂要不搞成 PaySummary只是目前只有 rechargePrice 充值金额
@GetMapping("/wallet-recharge-price")
@Operation(summary = "获取充值金额")
public CommonResult<Integer> getWalletRechargePrice() {

View File

@ -47,6 +47,7 @@ public class TradeStatisticsController {
@Resource
private BrokerageStatisticsService brokerageStatisticsService;
// TODO 芋艿已经 review
@GetMapping("/summary")
@Operation(summary = "获得交易统计")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
@ -55,6 +56,7 @@ public class TradeStatisticsController {
TradeSummaryRespBO yesterdayData = tradeStatisticsService.getTradeSummaryByDays(-1);
// 1.2 前天的数据用于对照昨天的数据
TradeSummaryRespBO beforeYesterdayData = tradeStatisticsService.getTradeSummaryByDays(-2);
// 2.1 本月数据
TradeSummaryRespBO monthData = tradeStatisticsService.getTradeSummaryByMonths(0);
// 2.2 上月数据用于对照本月的数据
@ -73,6 +75,7 @@ public class TradeStatisticsController {
ArrayUtil.get(reqVO.getTimes(), 1)));
}
// TODO 芋艿已经 review
@GetMapping("/list")
@Operation(summary = "获得交易状况明细")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
@ -82,6 +85,7 @@ public class TradeStatisticsController {
return success(TradeStatisticsConvert.INSTANCE.convertList(list));
}
// TODO 芋艿已经 review
@GetMapping("/export-excel")
@Operation(summary = "导出获得交易状况明细 Excel")
@PreAuthorize("@ss.hasPermission('statistics:trade:export')")
@ -94,16 +98,20 @@ public class TradeStatisticsController {
ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data);
}
// TODO 芋艿已经 review
@GetMapping("/order-count")
@Operation(summary = "获得交易订单数量")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
public CommonResult<TradeOrderCountRespVO> getOrderCount() {
// 订单统计
TradeOrderCountRespVO vo = tradeOrderStatisticsService.getOrderCount();
// 售后统计
vo.setAfterSaleApply(afterSaleStatisticsService.getCountByStatus(AfterSaleStatusEnum.APPLY))
.setAuditingWithdraw(brokerageStatisticsService.getWithdrawCountByStatus(BrokerageWithdrawStatusEnum.AUDITING));
return success(vo);
}
// TODO 芋艿已经 review
@GetMapping("/order-comparison")
@Operation(summary = "获得交易订单数量")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
@ -111,6 +119,7 @@ public class TradeStatisticsController {
return success(tradeOrderStatisticsService.getOrderComparison());
}
// TODO 芋艿已经 review
@GetMapping("/order-count-trend")
@Operation(summary = "获得订单量趋势统计")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")

View File

@ -52,6 +52,7 @@ public interface TradeStatisticsConvert {
List<TradeTrendSummaryRespVO> convertList(List<TradeStatisticsDO> list);
// TODO @疯狂要不要搞个默认的 convertA 方法然后这个 convert 去调用 convertA特殊字段再去 set
default TradeTrendSummaryRespVO convert(TradeStatisticsDO tradeStatistics) {
return new TradeTrendSummaryRespVO()
.setDate(tradeStatistics.getTime().toLocalDate())

View File

@ -63,6 +63,7 @@ public class TradeStatisticsDO extends TenantBaseDO {
*/
private Integer brokerageSettlementPrice;
// TODO @疯狂walletPayPrice钱包支付金额
/**
* 总支付金额余额单位
*/

View File

@ -16,10 +16,12 @@ import java.time.LocalDateTime;
@SuppressWarnings("rawtypes")
public interface ApiAccessLogStatisticsMapper extends BaseMapperX {
// TODO 芋艿已经 review
Integer selectIpCountByUserTypeAndCreateTimeBetween(@Param("userType") Integer userType,
@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
Integer selectUserCountByUserTypeAndCreateTimeBetween(@Param("userType") Integer userType,
@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);

View File

@ -20,16 +20,27 @@ import java.util.List;
@SuppressWarnings("rawtypes")
public interface MemberStatisticsMapper extends BaseMapperX {
// TODO @芋艿已经 review
List<MemberAreaStatisticsRespBO> selectSummaryListByAreaId();
// TODO @芋艿已经 review
List<MemberSexStatisticsRespVO> selectSummaryListBySex();
// TODO @芋艿已经 review
List<MemberTerminalStatisticsRespVO> selectSummaryListByRegisterTerminal();
// TODO @芋艿已经 review
Integer selectUserCount(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO @芋艿已经 review
/**
* 获得用户的每天注册数量列表
*
* @param beginTime 开始时间
* @param endTime 结束时间
* @return 每天注册数量列表
*/
List<MemberRegisterCountRespVO> selectListByCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);

View File

@ -37,6 +37,7 @@ public interface PayWalletStatisticsMapper extends BaseMapperX {
@Param("endTime") LocalDateTime endTime,
@Param("payStatus") Boolean payStatus);
// TODO 芋艿已经 review
Integer selectRechargePriceSummary(@Param("payStatus") Integer payStatus);
}

View File

@ -20,6 +20,7 @@ public interface AfterSaleStatisticsMapper extends BaseMapperX<TradeStatisticsDO
AfterSaleSummaryRespBO selectSummaryByRefundTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
Long selectCountByStatus(@Param("status") Integer status);
}

View File

@ -15,11 +15,13 @@ import java.time.LocalDateTime;
@Mapper
public interface BrokerageStatisticsMapper extends BaseMapperX<TradeStatisticsDO> {
// TODO 芋艿已经 review
Integer selectSummaryPriceByStatusAndUnfreezeTimeBetween(@Param("bizType") Integer bizType,
@Param("status") Integer status,
@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
Long selectWithdrawCountByStatus(@Param("status") Integer status);
}

View File

@ -42,6 +42,7 @@ public interface TradeOrderStatisticsMapper extends BaseMapperX<TradeStatisticsD
Integer selectUserCountByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 按照支付时间统计订单按天分组
*
@ -52,6 +53,7 @@ public interface TradeOrderStatisticsMapper extends BaseMapperX<TradeStatisticsD
List<TradeOrderTrendRespVO> selectListByPayTimeBetweenAndGroupByDay(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 按照支付时间统计订单按月分组
*
@ -62,10 +64,13 @@ public interface TradeOrderStatisticsMapper extends BaseMapperX<TradeStatisticsD
List<TradeOrderTrendRespVO> selectListByPayTimeBetweenAndGroupByMonth(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO @芋艿已经 review
Long selectCountByStatus(@Param("status") Integer status);
// TODO 芋艿已经 review
Long selectCountByStatusAndPickUpStoreIdIsNotNull(@Param("status") Integer status);
// TODO 芋艿已经 review
TradeOrderSummaryRespVO selectPaySummaryByStatusAndPayTimeBetween(@Param("status") Integer status,
@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);

View File

@ -25,14 +25,17 @@ public interface TradeStatisticsMapper extends BaseMapperX<TradeStatisticsDO> {
TradeTrendSummaryRespVO selectVoByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO @芋艿已经 review
default List<TradeStatisticsDO> selectListByTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
return selectList(new LambdaQueryWrapperX<TradeStatisticsDO>()
.between(TradeStatisticsDO::getTime, beginTime, endTime));
}
// TODO @芋艿已经 review
Integer selectExpensePriceByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO @芋艿已经 review
default TradeStatisticsDO selectByTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
return selectOne(new LambdaQueryWrapperX<TradeStatisticsDO>()
.between(TradeStatisticsDO::getTime, beginTime, endTime));

View File

@ -30,6 +30,7 @@ public class TradeStatisticsJob implements JobHandler {
@Override
@TenantJob
public String execute(String param) {
// TODO @疯狂要搞个默认的 1
if (NumberUtil.isInteger(param)) {
throw new RuntimeException("交易统计任务的参数只能为是正整数");
}

View File

@ -9,6 +9,7 @@ import java.time.LocalDateTime;
*/
public interface ApiAccessLogStatisticsService {
// TODO 芋艿已经 review
/**
* 获取活跃用户数量
*
@ -19,6 +20,7 @@ public interface ApiAccessLogStatisticsService {
*/
Integer getUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获取访问用户数量
*

View File

@ -21,6 +21,7 @@ public interface MemberStatisticsService {
*/
MemberSummaryRespVO getMemberSummary();
// TODO 芋艿已经 review
/**
* 获取会员分析对照数据
*
@ -31,6 +32,7 @@ public interface MemberStatisticsService {
DataComparisonRespVO<MemberAnalyseDataRespVO> getMemberAnalyseComparisonData(LocalDateTime beginTime,
LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 按照省份获得会员统计列表
*
@ -38,6 +40,7 @@ public interface MemberStatisticsService {
*/
List<MemberAreaStatisticsRespVO> getMemberAreaStatisticsList();
// TODO 芋艿已经 review
/**
* 按照性别获得会员统计列表
*
@ -45,6 +48,7 @@ public interface MemberStatisticsService {
*/
List<MemberSexStatisticsRespVO> getMemberSexStatisticsList();
// TODO @疯狂这个要不要使用 getMemberTerminalStatisticsList保持统一
/**
* 按照终端获得会员统计列表
*
@ -52,6 +56,7 @@ public interface MemberStatisticsService {
*/
List<MemberTerminalStatisticsRespVO> getRegisterTerminalStatisticsList();
// TODO 芋艿已经 review
/**
* 获取用户注册数量列表
*
@ -61,6 +66,7 @@ public interface MemberStatisticsService {
*/
List<MemberRegisterCountRespVO> getMemberRegisterCountList(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获得用户数量量统计对照
*

View File

@ -32,6 +32,7 @@ public interface PayWalletStatisticsService {
*/
RechargeSummaryRespBO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获取充值金额合计
*

View File

@ -6,7 +6,6 @@ import lombok.Data;
/**
* 充值统计 Response BO
*/
@Schema(description = "管理后台 - ")
@Data
public class RechargeSummaryRespBO {

View File

@ -22,6 +22,7 @@ public interface AfterSaleStatisticsService {
*/
AfterSaleSummaryRespBO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获取指定状态的售后订单数量
*

View File

@ -21,6 +21,7 @@ public interface BrokerageStatisticsService {
*/
Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获取指定状态的提现记录数量
*

View File

@ -62,6 +62,7 @@ public interface TradeOrderStatisticsService {
*/
Integer getOrderPayPrice(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获得交易订单数量
*
@ -69,6 +70,7 @@ public interface TradeOrderStatisticsService {
*/
TradeOrderCountRespVO getOrderCount();
// TODO 芋艿已经 review
/**
* 交易订单销售额对照
*
@ -76,6 +78,7 @@ public interface TradeOrderStatisticsService {
*/
DataComparisonRespVO<TradeOrderSummaryRespVO> getOrderComparison();
// TODO 芋艿已经 review
/**
* 获得订单量趋势统计
*

View File

@ -63,9 +63,9 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ
@Override
public TradeOrderCountRespVO getOrderCount() {
// TODO 疯狂这个可以根据 status + delivertyType 来过滤呀ps是不是搞个 service 方法交给上层去聚合这样 TradeOrderCountRespVO 可以更明确返回不用搞 bo
Long undeliveredCount = tradeOrderStatisticsMapper.selectCountByStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus());
Long pickUpCount = tradeOrderStatisticsMapper.selectCountByStatusAndPickUpStoreIdIsNotNull(TradeOrderStatusEnum.DELIVERED.getStatus());
return new TradeOrderCountRespVO()
.setPickUp(ObjUtil.defaultIfNull(pickUpCount, 0L))
.setUndelivered(ObjUtil.defaultIfNull(undeliveredCount, 0L));
@ -81,8 +81,8 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ
private TradeOrderSummaryRespVO getPayPriceSummary(LocalDateTime date) {
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(date);
LocalDateTime endTime = LocalDateTimeUtil.beginOfDay(date);
return tradeOrderStatisticsMapper.selectPaySummaryByStatusAndPayTimeBetween(PayOrderStatusEnum.SUCCESS.getStatus(), beginTime, endTime);
return tradeOrderStatisticsMapper.selectPaySummaryByStatusAndPayTimeBetween(
PayOrderStatusEnum.SUCCESS.getStatus(), beginTime, endTime);
}
@Override
@ -93,7 +93,7 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ
LocalDateTime referenceEndTime = reqVO.getBeginTime().minusDays(1);
LocalDateTime referenceBeginTime = referenceEndTime.minus(Duration.between(reqVO.getBeginTime(), reqVO.getEndTime()));
List<TradeOrderTrendRespVO> reference = getOrderCountTrend(reqVO.getType(), referenceBeginTime, referenceEndTime);
// 顺序对比返回
return IntStream.range(0, value.size())
.mapToObj(index -> new DataComparisonRespVO<TradeOrderTrendRespVO>()
.setValue(CollUtil.get(value, index))

View File

@ -49,6 +49,7 @@ public interface TradeStatisticsService {
*/
String statisticsTrade(Integer days);
// TODO 芋艿已经 review
/**
* 统计指定日期的交易数据
*
@ -57,6 +58,7 @@ public interface TradeStatisticsService {
*/
TradeSummaryRespBO getTradeSummaryByDays(int days);
// TODO 芋艿已经 review
/**
* 统计指定月份的交易数据
*

View File

@ -83,6 +83,7 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
@Override
public String statisticsTrade(Integer days) {
LocalDateTime today = LocalDateTime.now();
// TODO @疯狂不用并发哈因为租户可能会丢然后一般串行就好对性能没绝对的要求哈天数也不会多
return IntStream.rangeClosed(1, days)
.parallel()
.mapToObj(day -> statisticsTrade(today.minusDays(day)))
@ -130,6 +131,7 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
entity = TradeStatisticsConvert.INSTANCE.convert(date, orderSummary, afterSaleSummary, brokerageSettlementPrice,
walletSummary);
tradeStatisticsMapper.insert(entity);
// TODO @疯狂这里是不是也要把日期带上类似 108 那边
return stopWatch.prettyPrint();
}

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeOrderStatisticsMapper">
<!-- TODO @疯狂:是返回不是的 MemberAreaStatisticsRespBO 哈 -->
<select id="selectSummaryListByAreaId"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO">
SELECT receiver_area_id AS areaId,
@ -87,7 +89,8 @@
<select id="selectCountByStatus" resultType="java.lang.Long">
SELECT COUNT(1)
FROM trade_order
WHERE status = #{status} AND deleted = FALSE
WHERE status = #{status}
AND deleted = FALSE
</select>
<select id="selectCountByStatusAndPickUpStoreIdIsNotNull" resultType="java.lang.Long">

View File

@ -187,6 +187,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus());
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
// TODO @疯狂无状态terminal 不从 servletuTILS 而是通过 controller 传递给 service
order.setTerminal(ServletUtils.getTerminal());
// 支付 + 退款信息
order.setAdjustPrice(0).setPayStatus(false);

View File

@ -117,7 +117,7 @@ public class MemberUserDO extends TenantBaseDO {
* 积分
*/
private Integer point;
// TODO 芋艿增加一个 totalPoint个人信息接口要返回
// TODO 疯狂增加一个 totalPoint个人信息接口要返回
/**
* 会员标签列表以逗号分隔

View File

@ -100,6 +100,7 @@ public class MemberUserServiceImpl implements MemberUserService {
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
user.setPassword(encodePassword(password)); // 加密密码
user.setRegisterIp(registerIp);
// TODO @疯狂无状态terminal 不从 servletuTILS 而是通过 controller 传递给 service
user.setRegisterTerminal(ServletUtils.getTerminal());
memberUserMapper.insert(user);