mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
统计:Review修改
This commit is contained in:
parent
ea810bb5d6
commit
bb82c631e9
@ -1,16 +1,15 @@
|
||||
package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo;
|
||||
package cn.iocoder.yudao.module.statistics.controller.admin.common.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
// TODO @疯狂:是不是搞成公用的哈;类似,controller/admin/common,下面直接放它
|
||||
@Schema(description = "管理后台 - 交易统计对照 Response VO")
|
||||
@Schema(description = "管理后台 - 数据对照 Response VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TradeStatisticsComparisonRespVO<T> {
|
||||
public class DataComparisonRespVO<T> {
|
||||
|
||||
@Schema(description = "当前数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private T value;
|
@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.statistics.controller.admin.member;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.service.member.MemberStatisticsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -79,7 +79,7 @@ public class MemberStatisticsController {
|
||||
@GetMapping("/user-count-comparison")
|
||||
@Operation(summary = "获得用户数量对照")
|
||||
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
|
||||
public CommonResult<TradeStatisticsComparisonRespVO<MemberCountRespVO>> getUserCountComparison() {
|
||||
public CommonResult<DataComparisonRespVO<MemberCountRespVO>> getUserCountComparison() {
|
||||
return success(memberStatisticsService.getUserCountComparison());
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,11 @@ import lombok.Data;
|
||||
@Data
|
||||
public class MemberAnalyseComparisonRespVO {
|
||||
|
||||
// TODO @疯狂:这个字段,要不改成注册用户量;registerUserCount;
|
||||
@Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer userCount;
|
||||
private Integer registerUserCount;
|
||||
|
||||
// TODO @疯狂:这个字段,名字改成 visitUserCount;有访问,就算活跃;
|
||||
@Schema(description = "活跃用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer activeUserCount;
|
||||
private Integer visitUserCount;
|
||||
|
||||
@Schema(description = "充值会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "221")
|
||||
private Integer rechargeUserCount;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.statistics.controller.admin.member.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@ -8,9 +8,8 @@ import lombok.Data;
|
||||
@Data
|
||||
public class MemberAnalyseRespVO {
|
||||
|
||||
// TODO @疯狂:这个字段改成 visitUserCount,保持和 userCount 字段统一
|
||||
@Schema(description = "访客数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer visitorCount;
|
||||
private Integer visitUserCount;
|
||||
|
||||
@Schema(description = "下单用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer orderUserCount;
|
||||
@ -22,6 +21,6 @@ public class MemberAnalyseRespVO {
|
||||
private Integer atv;
|
||||
|
||||
@Schema(description = "对照数据", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private TradeStatisticsComparisonRespVO<MemberAnalyseComparisonRespVO> comparison;
|
||||
private DataComparisonRespVO<MemberAnalyseComparisonRespVO> comparison;
|
||||
|
||||
}
|
||||
|
@ -15,11 +15,10 @@ public class MemberAreaStatisticsRespVO {
|
||||
@Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer userCount;
|
||||
|
||||
// TODO @疯狂:要不 orderCreateUserCount 和 orderPayUserCount 貌似更统一一些;
|
||||
@Schema(description = "订单创建数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer orderCreateCount;
|
||||
@Schema(description = "订单支付数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "512")
|
||||
private Integer orderPayCount;
|
||||
@Schema(description = "下单的会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer orderCreateUserCount;
|
||||
@Schema(description = "支付订单的会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "512")
|
||||
private Integer orderPayUserCount;
|
||||
|
||||
@Schema(description = "订单支付金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "622")
|
||||
private Integer orderPayPrice;
|
||||
|
@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.statistics.controller.admin.trade;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*;
|
||||
import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert;
|
||||
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.AfterSaleStatisticsService;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.BrokerageStatisticsService;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
|
||||
import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleStatusEnum;
|
||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -47,41 +50,47 @@ public class TradeStatisticsController {
|
||||
@GetMapping("/summary")
|
||||
@Operation(summary = "获得交易统计")
|
||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||
public CommonResult<TradeStatisticsComparisonRespVO<TradeSummaryRespVO>> getTradeSummaryComparison() {
|
||||
// TODO @疯狂:这个要不要 tradeStatisticsService 调用里面的多个方法,组合出最终的 TradeSummaryRespVO;
|
||||
return success(tradeStatisticsService.getTradeSummaryComparison());
|
||||
public CommonResult<DataComparisonRespVO<TradeSummaryRespVO>> getTradeSummaryComparison() {
|
||||
// 1.1 昨天的数据
|
||||
TradeSummaryRespBO yesterdayData = tradeStatisticsService.getTradeSummaryByDays(-1);
|
||||
// 1.2 前天的数据(用于对照昨天的数据)
|
||||
TradeSummaryRespBO beforeYesterdayData = tradeStatisticsService.getTradeSummaryByDays(-2);
|
||||
// 2.1 本月数据
|
||||
TradeSummaryRespBO monthData = tradeStatisticsService.getTradeSummaryByMonths(0);
|
||||
// 2.2 上月数据(用于对照本月的数据)
|
||||
TradeSummaryRespBO lastMonthData = tradeStatisticsService.getTradeSummaryByMonths(-1);
|
||||
// 拼接数据
|
||||
return success(TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData));
|
||||
}
|
||||
|
||||
// TODO @疯狂:【晚点再改和讨论;等首页的接口出来】这个要不还是叫 analyse,对比选中的时间段,和上一个时间段;类似 MemberStatisticsController 的 getMemberAnalyse
|
||||
@GetMapping("/trend/summary")
|
||||
@Operation(summary = "获得交易状况统计")
|
||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||
public CommonResult<TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO>> getTradeTrendSummaryComparison(
|
||||
public CommonResult<DataComparisonRespVO<TradeTrendSummaryRespVO>> getTradeTrendSummaryComparison(
|
||||
TradeTrendReqVO reqVO) {
|
||||
return success(tradeStatisticsService.getTradeTrendSummaryComparison(ArrayUtil.get(reqVO.getTimes(), 0),
|
||||
ArrayUtil.get(reqVO.getTimes(), 1)));
|
||||
}
|
||||
|
||||
// TODO 芋艿:已经 review
|
||||
// TODO @疯狂:这个要不直接叫 list;它即使就是把每条统计拿出来
|
||||
@GetMapping("/trend/list")
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得交易状况明细")
|
||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||
public CommonResult<List<TradeTrendSummaryRespVO>> getTradeStatisticsList(
|
||||
TradeTrendReqVO reqVO) {
|
||||
return success(tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0),
|
||||
ArrayUtil.get(reqVO.getTimes(), 1)));
|
||||
public CommonResult<List<TradeTrendSummaryRespVO>> getTradeStatisticsList(TradeTrendReqVO reqVO) {
|
||||
List<TradeStatisticsDO> list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0),
|
||||
ArrayUtil.get(reqVO.getTimes(), 1));
|
||||
return success(TradeStatisticsConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
// TODO @疯狂:这个要不直接叫 export;它即使就是把每条统计导出
|
||||
@GetMapping("/trend/export-excel")
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出获得交易状况明细 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('statistics:trade:export')")
|
||||
public void exportTradeStatisticsExcel(TradeTrendReqVO reqVO, HttpServletResponse response) throws IOException {
|
||||
List<TradeTrendSummaryRespVO> list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0),
|
||||
List<TradeStatisticsDO> list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0),
|
||||
ArrayUtil.get(reqVO.getTimes(), 1));
|
||||
// 导出 Excel
|
||||
List<TradeTrendSummaryExcelVO> data = TradeStatisticsConvert.INSTANCE.convertList02(list);
|
||||
List<TradeTrendSummaryRespVO> voList = TradeStatisticsConvert.INSTANCE.convertList(list);
|
||||
List<TradeTrendSummaryExcelVO> data = TradeStatisticsConvert.INSTANCE.convertList02(voList);
|
||||
ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data);
|
||||
}
|
||||
|
||||
@ -98,14 +107,14 @@ public class TradeStatisticsController {
|
||||
@GetMapping("/order-comparison")
|
||||
@Operation(summary = "获得交易订单数量")
|
||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||
public CommonResult<TradeStatisticsComparisonRespVO<TradeOrderSummaryRespVO>> getOrderComparison() {
|
||||
public CommonResult<DataComparisonRespVO<TradeOrderSummaryRespVO>> getOrderComparison() {
|
||||
return success(tradeOrderStatisticsService.getOrderComparison());
|
||||
}
|
||||
|
||||
@GetMapping("/order-count-trend")
|
||||
@Operation(summary = "获得订单量趋势统计")
|
||||
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
|
||||
public CommonResult<List<TradeStatisticsComparisonRespVO<TradeOrderTrendRespVO>>> getOrderCountTrendComparison(@Valid TradeOrderTrendReqVO reqVO) {
|
||||
public CommonResult<List<DataComparisonRespVO<TradeOrderTrendRespVO>>> getOrderCountTrendComparison(@Valid TradeOrderTrendReqVO reqVO) {
|
||||
return success(tradeOrderStatisticsService.getOrderCountTrendComparison(reqVO));
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class TradeTrendSummaryExcelVO {
|
||||
private LocalDate date;
|
||||
|
||||
@ExcelProperty(value = "营业额", converter = MoneyConvert.class)
|
||||
private Integer turnover;
|
||||
private Integer turnoverPrice;
|
||||
|
||||
@ExcelProperty(value = "商品支付金额", converter = MoneyConvert.class)
|
||||
private Integer orderPayPrice;
|
||||
@ -34,7 +34,7 @@ public class TradeTrendSummaryExcelVO {
|
||||
private Integer expensePrice;
|
||||
|
||||
@ExcelProperty(value = "余额支付金额", converter = MoneyConvert.class)
|
||||
private Integer balancePrice;
|
||||
private Integer orderWalletPayPrice;
|
||||
|
||||
@ExcelProperty(value = "支付佣金金额", converter = MoneyConvert.class)
|
||||
private Integer brokerageSettlementPrice;
|
||||
|
@ -16,13 +16,15 @@ public class TradeTrendSummaryRespVO {
|
||||
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY)
|
||||
private LocalDate date;
|
||||
|
||||
// TODO @疯狂,要不加个 turnoverPrice?
|
||||
@Schema(description = "营业额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer turnover; // 营业额 = 商品支付金额 + 充值金额
|
||||
private Integer turnoverPrice; // 营业额 = 商品支付金额 + 充值金额
|
||||
|
||||
@Schema(description = "订单支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer orderPayPrice;
|
||||
|
||||
@Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer orderWalletPayPrice;
|
||||
|
||||
@Schema(description = "订单退款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer orderRefundPrice;
|
||||
|
||||
@ -35,7 +37,4 @@ public class TradeTrendSummaryRespVO {
|
||||
@Schema(description = "支出金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer expensePrice; // 余额支付金额 + 支付佣金金额 + 商品退款金额
|
||||
|
||||
@Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer balancePrice; // TODO @疯狂:这个字段要不改成:walletPayPrice
|
||||
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ public interface MemberStatisticsConvert {
|
||||
return new MemberAreaStatisticsRespVO()
|
||||
.setAreaId(area.getId()).setAreaName(area.getName())
|
||||
.setUserCount(MapUtil.getInt(userCountMap, area.getId(), 0))
|
||||
.setOrderCreateCount(ObjUtil.defaultIfNull(orderVo.getOrderCreateCount(), 0))
|
||||
.setOrderPayCount(ObjUtil.defaultIfNull(orderVo.getOrderPayCount(), 0))
|
||||
.setOrderCreateUserCount(ObjUtil.defaultIfNull(orderVo.getOrderCreateUserCount(), 0))
|
||||
.setOrderPayUserCount(ObjUtil.defaultIfNull(orderVo.getOrderPayUserCount(), 0))
|
||||
.setOrderPayPrice(ObjUtil.defaultIfNull(orderVo.getOrderPayPrice(), 0));
|
||||
});
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package cn.iocoder.yudao.module.statistics.convert.trade;
|
||||
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryExcelVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -25,10 +25,10 @@ public interface TradeStatisticsConvert {
|
||||
|
||||
TradeStatisticsConvert INSTANCE = Mappers.getMapper(TradeStatisticsConvert.class);
|
||||
|
||||
default TradeStatisticsComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespBO yesterdayData,
|
||||
TradeSummaryRespBO beforeYesterdayData,
|
||||
TradeSummaryRespBO monthData,
|
||||
TradeSummaryRespBO lastMonthData) {
|
||||
default DataComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespBO yesterdayData,
|
||||
TradeSummaryRespBO beforeYesterdayData,
|
||||
TradeSummaryRespBO monthData,
|
||||
TradeSummaryRespBO lastMonthData) {
|
||||
return convert(convert(yesterdayData, monthData), convert(beforeYesterdayData, lastMonthData));
|
||||
}
|
||||
|
||||
@ -39,10 +39,10 @@ public interface TradeStatisticsConvert {
|
||||
.setMonthOrderCount(monthData.getCount()).setMonthPayPrice(monthData.getSummary());
|
||||
}
|
||||
|
||||
TradeStatisticsComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespVO value, TradeSummaryRespVO reference);
|
||||
DataComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespVO value, TradeSummaryRespVO reference);
|
||||
|
||||
TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> convert(TradeTrendSummaryRespVO value,
|
||||
TradeTrendSummaryRespVO reference);
|
||||
DataComparisonRespVO<TradeTrendSummaryRespVO> convert(TradeTrendSummaryRespVO value,
|
||||
TradeTrendSummaryRespVO reference);
|
||||
|
||||
List<TradeTrendSummaryExcelVO> convertList02(List<TradeTrendSummaryRespVO> list);
|
||||
|
||||
@ -50,4 +50,20 @@ public interface TradeStatisticsConvert {
|
||||
AfterSaleSummaryRespBO afterSaleSummary, Integer brokerageSettlementPrice,
|
||||
WalletSummaryRespBO walletSummary);
|
||||
|
||||
List<TradeTrendSummaryRespVO> convertList(List<TradeStatisticsDO> list);
|
||||
|
||||
default TradeTrendSummaryRespVO convert(TradeStatisticsDO tradeStatistics) {
|
||||
return new TradeTrendSummaryRespVO()
|
||||
.setDate(tradeStatistics.getTime().toLocalDate())
|
||||
// 营业额 = 商品支付金额 + 充值金额
|
||||
.setTurnoverPrice(tradeStatistics.getOrderPayPrice() + tradeStatistics.getRechargePayPrice())
|
||||
.setOrderPayPrice(tradeStatistics.getOrderPayPrice())
|
||||
.setRechargePrice(tradeStatistics.getRechargePayPrice())
|
||||
// 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
|
||||
.setExpensePrice(tradeStatistics.getOrderWalletPayPrice() + tradeStatistics.getBrokerageSettlementPrice() + tradeStatistics.getAfterSaleRefundPrice())
|
||||
.setOrderWalletPayPrice(tradeStatistics.getOrderWalletPayPrice())
|
||||
.setBrokerageSettlementPrice(tradeStatistics.getBrokerageSettlementPrice())
|
||||
.setOrderRefundPrice(tradeStatistics.getAfterSaleRefundPrice());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,11 +48,6 @@ public class TradeStatisticsDO extends TenantBaseDO {
|
||||
* 总支付金额,单位:分
|
||||
*/
|
||||
private Integer orderPayPrice;
|
||||
// TODO @疯狂:这个字段改成 walletPayPrice,然后挪到 rechargePayCount 前面;
|
||||
/**
|
||||
* 总支付金额(余额),单位:分
|
||||
*/
|
||||
private Integer orderWalletPayPrice;
|
||||
|
||||
/**
|
||||
* 退款订单数
|
||||
@ -68,6 +63,10 @@ public class TradeStatisticsDO extends TenantBaseDO {
|
||||
*/
|
||||
private Integer brokerageSettlementPrice;
|
||||
|
||||
/**
|
||||
* 总支付金额(余额),单位:分
|
||||
*/
|
||||
private Integer orderWalletPayPrice;
|
||||
/**
|
||||
* 充值订单数
|
||||
* <p>
|
||||
|
@ -16,12 +16,12 @@ import java.time.LocalDateTime;
|
||||
@SuppressWarnings("rawtypes")
|
||||
public interface ApiAccessLogStatisticsMapper extends BaseMapperX {
|
||||
|
||||
Integer selectIpCountByCreateTimeBetween(@Param("userType") Integer userType,
|
||||
@Param("beginTime") LocalDateTime beginTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
Integer selectIpCountByUserTypeAndCreateTimeBetween(@Param("userType") Integer userType,
|
||||
@Param("beginTime") LocalDateTime beginTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
Integer selectUserCountByCreateTimeBetween(@Param("userType") Integer userType,
|
||||
@Param("beginTime") LocalDateTime beginTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
Integer selectUserCountByUserTypeAndCreateTimeBetween(@Param("userType") Integer userType,
|
||||
@Param("beginTime") LocalDateTime beginTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package cn.iocoder.yudao.module.statistics.dal.mysql.member;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberRegisterCountRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@ -19,9 +19,7 @@ import java.util.List;
|
||||
@SuppressWarnings("rawtypes")
|
||||
public interface MemberStatisticsMapper extends BaseMapperX {
|
||||
|
||||
// TODO @芋艿:已经 review
|
||||
// TODO @疯狂:要不还是搞下 bo?虽然可能冗余了点~~
|
||||
List<MemberAreaStatisticsRespVO> selectSummaryListByAreaId();
|
||||
List<MemberAreaStatisticsRespBO> selectSummaryListByAreaId();
|
||||
|
||||
List<MemberSexStatisticsRespVO> selectSummaryListBySex();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.statistics.dal.mysql.trade;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
|
||||
@ -21,14 +22,20 @@ public interface TradeStatisticsMapper extends BaseMapperX<TradeStatisticsDO> {
|
||||
TradeSummaryRespBO selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
TradeTrendSummaryRespVO selectByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
TradeTrendSummaryRespVO selectVoByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
// TODO @芋艿:已经 review
|
||||
List<TradeTrendSummaryRespVO> selectListByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
default List<TradeStatisticsDO> selectListByTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
return selectList(new LambdaQueryWrapperX<TradeStatisticsDO>()
|
||||
.between(TradeStatisticsDO::getTime, beginTime, endTime));
|
||||
}
|
||||
|
||||
Integer selectExpensePriceByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
default TradeStatisticsDO selectByTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
return selectOne(new LambdaQueryWrapperX<TradeStatisticsDO>()
|
||||
.between(TradeStatisticsDO::getTime, beginTime, endTime));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.module.statistics.job.trade;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
|
||||
@ -19,11 +21,24 @@ public class TradeStatisticsJob implements JobHandler {
|
||||
@Resource
|
||||
private TradeStatisticsService tradeStatisticsService;
|
||||
|
||||
/**
|
||||
* 执行交易统计任务
|
||||
*
|
||||
* @param param 要统计的天数,只能是正整数,1 代表昨日数据
|
||||
* @return 统计结果
|
||||
*/
|
||||
@Override
|
||||
@TenantJob
|
||||
public String execute(String param) {
|
||||
String times = tradeStatisticsService.statisticsYesterdayTrade();
|
||||
return StrUtil.format("交易统计耗时: {}", times);
|
||||
if (NumberUtil.isInteger(param)) {
|
||||
throw new RuntimeException("交易统计任务的参数只能为是正整数");
|
||||
}
|
||||
Integer days = Convert.toInt(param, 0);
|
||||
if (days < 1) {
|
||||
throw new RuntimeException("交易统计任务的参数只能为是正整数");
|
||||
}
|
||||
String result = tradeStatisticsService.statisticsTrade(days);
|
||||
return StrUtil.format("交易统计:\n{}", result);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ import java.time.LocalDateTime;
|
||||
*/
|
||||
public interface ApiAccessLogStatisticsService {
|
||||
|
||||
// TODO @疯狂:需要传递 userType;因为访问日志,可能涉及多种用户类型;
|
||||
// TODO @疯狂:方法名,要不改成 getUserCount;原因:让它更业务无关
|
||||
/**
|
||||
* 获取活跃用户数量
|
||||
*
|
||||
@ -19,10 +17,8 @@ public interface ApiAccessLogStatisticsService {
|
||||
* @param endTime 截止时间
|
||||
* @return 活跃用户数量
|
||||
*/
|
||||
Integer getActiveUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime);
|
||||
Integer getUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime);
|
||||
|
||||
// TODO @疯狂:需要传递 userType;因为访问日志,可能涉及多种用户类型;
|
||||
// TODO @疯狂:方法名,要不改成 getIpCount;原因:让它更业务无关
|
||||
/**
|
||||
* 获取访问用户数量
|
||||
*
|
||||
@ -31,6 +27,6 @@ public interface ApiAccessLogStatisticsService {
|
||||
* @param endTime 截止时间
|
||||
* @return 访问用户数量
|
||||
*/
|
||||
Integer getVisitorUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime);
|
||||
Integer getIpCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime);
|
||||
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ public class ApiAccessLogStatisticsServiceImpl implements ApiAccessLogStatistics
|
||||
private ApiAccessLogStatisticsMapper apiAccessLogStatisticsMapper;
|
||||
|
||||
@Override
|
||||
public Integer getActiveUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
return apiAccessLogStatisticsMapper.selectUserCountByCreateTimeBetween(userType, beginTime, endTime);
|
||||
public Integer getUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
return apiAccessLogStatisticsMapper.selectUserCountByUserTypeAndCreateTimeBetween(userType, beginTime, endTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getVisitorUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
return apiAccessLogStatisticsMapper.selectIpCountByCreateTimeBetween(userType, beginTime, endTime);
|
||||
public Integer getIpCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
return apiAccessLogStatisticsMapper.selectIpCountByUserTypeAndCreateTimeBetween(userType, beginTime, endTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.statistics.service.member;
|
||||
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@ -59,6 +59,6 @@ public interface MemberStatisticsService {
|
||||
*
|
||||
* @return 用户数量量统计对照
|
||||
*/
|
||||
TradeStatisticsComparisonRespVO<MemberCountRespVO> getUserCountComparison();
|
||||
DataComparisonRespVO<MemberCountRespVO> getUserCountComparison();
|
||||
|
||||
}
|
||||
|
@ -5,11 +5,12 @@ import cn.hutool.core.util.NumberUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.convert.member.MemberStatisticsConvert;
|
||||
import cn.iocoder.yudao.module.statistics.dal.mysql.member.MemberStatisticsMapper;
|
||||
import cn.iocoder.yudao.module.statistics.service.infra.ApiAccessLogStatisticsService;
|
||||
import cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO;
|
||||
import cn.iocoder.yudao.module.statistics.service.pay.PayWalletStatisticsService;
|
||||
import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService;
|
||||
@ -63,14 +64,14 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService {
|
||||
// TODO @疯狂:可能得把每个省的用户,都查询出来,然后去 order 那边 in;因为要按照这些人为基础来计算;;用户规模量大可能不太好,但是暂时就先这样搞吧 = =
|
||||
Map<Integer, Integer> userCountMap = convertMap(memberStatisticsMapper.selectSummaryListByAreaId(),
|
||||
vo -> AreaUtils.getParentIdByType(vo.getAreaId(), AreaTypeEnum.PROVINCE),
|
||||
MemberAreaStatisticsRespVO::getUserCount, Integer::sum);
|
||||
MemberAreaStatisticsRespBO::getUserCount, Integer::sum);
|
||||
// 统计订单
|
||||
Map<Integer, MemberAreaStatisticsRespVO> orderMap = convertMap(tradeOrderStatisticsService.getSummaryListByAreaId(),
|
||||
vo -> AreaUtils.getParentIdByType(vo.getAreaId(), AreaTypeEnum.PROVINCE),
|
||||
vo -> vo,
|
||||
(a, b) -> new MemberAreaStatisticsRespVO()
|
||||
.setOrderCreateCount(a.getOrderCreateCount() + b.getOrderCreateCount())
|
||||
.setOrderPayCount(a.getOrderPayCount() + b.getOrderPayCount())
|
||||
.setOrderCreateUserCount(a.getOrderCreateUserCount() + b.getOrderCreateUserCount())
|
||||
.setOrderPayUserCount(a.getOrderPayUserCount() + b.getOrderPayUserCount())
|
||||
.setOrderPayPrice(a.getOrderPayPrice() + b.getOrderPayPrice()));
|
||||
// 拼接数据
|
||||
return MemberStatisticsConvert.INSTANCE.convertList(AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area), userCountMap, orderMap);
|
||||
@ -96,19 +97,19 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService {
|
||||
atv = NumberUtil.div(payPrice, payUserCount).intValue();
|
||||
}
|
||||
return new MemberAnalyseRespVO()
|
||||
.setVisitorCount(apiAccessLogStatisticsService.getVisitorUserCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime))
|
||||
.setVisitUserCount(apiAccessLogStatisticsService.getIpCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime))
|
||||
.setOrderUserCount(tradeOrderStatisticsService.getOrderUserCount(beginTime, endTime))
|
||||
.setPayUserCount(payUserCount)
|
||||
.setAtv(atv)
|
||||
.setComparison(new TradeStatisticsComparisonRespVO<>(vo, reference));
|
||||
.setComparison(new DataComparisonRespVO<>(vo, reference));
|
||||
}
|
||||
|
||||
private MemberAnalyseComparisonRespVO getMemberAnalyseComparisonData(LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
Integer rechargeUserCount = Optional.ofNullable(payWalletStatisticsService.getUserRechargeSummary(beginTime, endTime))
|
||||
.map(RechargeSummaryRespBO::getRechargeUserCount).orElse(0);
|
||||
return new MemberAnalyseComparisonRespVO()
|
||||
.setUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime))
|
||||
.setActiveUserCount(apiAccessLogStatisticsService.getActiveUserCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime))
|
||||
.setRegisterUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime))
|
||||
.setVisitUserCount(apiAccessLogStatisticsService.getUserCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime))
|
||||
.setRechargeUserCount(rechargeUserCount);
|
||||
}
|
||||
|
||||
@ -124,14 +125,14 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStatisticsComparisonRespVO<MemberCountRespVO> getUserCountComparison() {
|
||||
public DataComparisonRespVO<MemberCountRespVO> getUserCountComparison() {
|
||||
// 今日时间范围
|
||||
LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
|
||||
LocalDateTime endOfToday = LocalDateTimeUtil.endOfDay(beginOfToday);
|
||||
// 昨日时间范围
|
||||
LocalDateTime beginOfYesterday = LocalDateTimeUtil.beginOfDay(beginOfToday.minusDays(1));
|
||||
LocalDateTime endOfYesterday = LocalDateTimeUtil.endOfDay(beginOfYesterday);
|
||||
return new TradeStatisticsComparisonRespVO<MemberCountRespVO>()
|
||||
return new DataComparisonRespVO<MemberCountRespVO>()
|
||||
.setValue(getUserCount(beginOfToday, endOfToday))
|
||||
.setReference(getUserCount(beginOfYesterday, endOfYesterday));
|
||||
}
|
||||
@ -139,7 +140,7 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService {
|
||||
private MemberCountRespVO getUserCount(LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
return new MemberCountRespVO()
|
||||
.setCreateUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime))
|
||||
.setVisitUserCount(apiAccessLogStatisticsService.getVisitorUserCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime));
|
||||
.setVisitUserCount(apiAccessLogStatisticsService.getIpCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package cn.iocoder.yudao.module.statistics.service.member.bo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 会员地区统计 Response BO")
|
||||
@Data
|
||||
public class MemberAreaStatisticsRespBO {
|
||||
|
||||
/**
|
||||
* 省份编号
|
||||
*/
|
||||
private Integer areaId;
|
||||
/**
|
||||
* 省份名称
|
||||
*/
|
||||
private String areaName;
|
||||
|
||||
/**
|
||||
* 会员数量
|
||||
*/
|
||||
private Integer userCount;
|
||||
|
||||
/**
|
||||
* 下单的会员数量
|
||||
*/
|
||||
private Integer orderCreateUserCount;
|
||||
/**
|
||||
* 支付订单的会员数量
|
||||
*/
|
||||
private Integer orderPayUserCount;
|
||||
|
||||
/**
|
||||
* 订单支付金额,单位:分
|
||||
*/
|
||||
private Integer orderPayPrice;
|
||||
|
||||
}
|
@ -3,15 +3,21 @@ package cn.iocoder.yudao.module.statistics.service.pay.bo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
// TODO @疯狂:BO 不用写 swagger 注解哈,写注释就好啦;
|
||||
@Schema(description = "管理后台 - 充值统计 Response VO")
|
||||
/**
|
||||
* 充值统计 Response BO
|
||||
*/
|
||||
@Schema(description = "管理后台 - ")
|
||||
@Data
|
||||
public class RechargeSummaryRespBO {
|
||||
|
||||
@Schema(description = "充值会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "221")
|
||||
/**
|
||||
* 充值会员数量
|
||||
*/
|
||||
private Integer rechargeUserCount;
|
||||
|
||||
@Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
/**
|
||||
* 充值金额
|
||||
*/
|
||||
private Integer rechargePrice;
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.statistics.service.trade;
|
||||
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO;
|
||||
@ -73,7 +74,7 @@ public interface TradeOrderStatisticsService {
|
||||
*
|
||||
* @return 销售额对照
|
||||
*/
|
||||
TradeStatisticsComparisonRespVO<TradeOrderSummaryRespVO> getOrderComparison();
|
||||
DataComparisonRespVO<TradeOrderSummaryRespVO> getOrderComparison();
|
||||
|
||||
/**
|
||||
* 获得订单量趋势统计
|
||||
@ -81,6 +82,6 @@ public interface TradeOrderStatisticsService {
|
||||
* @param reqVO 统计参数
|
||||
* @return 订单量趋势统计
|
||||
*/
|
||||
List<TradeStatisticsComparisonRespVO<TradeOrderTrendRespVO>> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO);
|
||||
List<DataComparisonRespVO<TradeOrderTrendRespVO>> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO);
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*;
|
||||
import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeOrderStatisticsMapper;
|
||||
@ -71,8 +72,8 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStatisticsComparisonRespVO<TradeOrderSummaryRespVO> getOrderComparison() {
|
||||
return new TradeStatisticsComparisonRespVO<TradeOrderSummaryRespVO>()
|
||||
public DataComparisonRespVO<TradeOrderSummaryRespVO> getOrderComparison() {
|
||||
return new DataComparisonRespVO<TradeOrderSummaryRespVO>()
|
||||
.setValue(getPayPriceSummary(LocalDateTime.now()))
|
||||
.setReference(getPayPriceSummary(LocalDateTime.now().minusDays(1)));
|
||||
}
|
||||
@ -85,7 +86,7 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TradeStatisticsComparisonRespVO<TradeOrderTrendRespVO>> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO) {
|
||||
public List<DataComparisonRespVO<TradeOrderTrendRespVO>> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO) {
|
||||
// 查询当前数据
|
||||
List<TradeOrderTrendRespVO> value = getOrderCountTrend(reqVO.getType(), reqVO.getBeginTime(), reqVO.getEndTime());
|
||||
// 查询对照数据
|
||||
@ -94,7 +95,7 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ
|
||||
List<TradeOrderTrendRespVO> reference = getOrderCountTrend(reqVO.getType(), referenceBeginTime, referenceEndTime);
|
||||
|
||||
return IntStream.range(0, value.size())
|
||||
.mapToObj(index -> new TradeStatisticsComparisonRespVO<TradeOrderTrendRespVO>()
|
||||
.mapToObj(index -> new DataComparisonRespVO<TradeOrderTrendRespVO>()
|
||||
.setValue(CollUtil.get(value, index))
|
||||
.setReference(CollUtil.get(reference, index)))
|
||||
.collect(Collectors.toList());
|
||||
|
@ -1,8 +1,9 @@
|
||||
package cn.iocoder.yudao.module.statistics.service.trade;
|
||||
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
|
||||
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@ -14,19 +15,12 @@ import java.util.List;
|
||||
*/
|
||||
public interface TradeStatisticsService {
|
||||
|
||||
/**
|
||||
* 获得交易统计
|
||||
*
|
||||
* @return 统计数据对照
|
||||
*/
|
||||
TradeStatisticsComparisonRespVO<TradeSummaryRespVO> getTradeSummaryComparison();
|
||||
|
||||
/**
|
||||
* 获得交易状况统计对照
|
||||
*
|
||||
* @return 统计数据对照
|
||||
*/
|
||||
TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(
|
||||
DataComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(
|
||||
LocalDateTime beginTime, LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
@ -45,14 +39,30 @@ public interface TradeStatisticsService {
|
||||
* @param endTime 结束时间
|
||||
* @return 统计数据列表
|
||||
*/
|
||||
List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime);
|
||||
List<TradeStatisticsDO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime);
|
||||
|
||||
// TODO 芋艿:已经 review;
|
||||
/**
|
||||
* 统计昨日交易
|
||||
* 统计指定天数的交易数据
|
||||
*
|
||||
* @return 耗时
|
||||
* @return 统计结果
|
||||
*/
|
||||
String statisticsYesterdayTrade();
|
||||
String statisticsTrade(Integer days);
|
||||
|
||||
/**
|
||||
* 统计指定日期的交易数据
|
||||
*
|
||||
* @param days 增加的天数
|
||||
* @return 交易数据
|
||||
*/
|
||||
TradeSummaryRespBO getTradeSummaryByDays(int days);
|
||||
|
||||
/**
|
||||
* 统计指定月份的交易数据
|
||||
*
|
||||
* @param months 增加的月数
|
||||
* @return 交易数据
|
||||
*/
|
||||
TradeSummaryRespBO getTradeSummaryByMonths(int months);
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package cn.iocoder.yudao.module.statistics.service.trade;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert;
|
||||
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
|
||||
@ -21,6 +21,8 @@ import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* 交易统计 Service 实现类
|
||||
@ -44,51 +46,27 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
|
||||
private PayWalletStatisticsService payWalletStatisticsService;
|
||||
|
||||
@Override
|
||||
public TradeStatisticsComparisonRespVO<TradeSummaryRespVO> getTradeSummaryComparison() {
|
||||
// 1.1 昨天的数据
|
||||
TradeSummaryRespBO yesterdayData = getTradeSummaryByDays(-1);
|
||||
// 1.2 前天的数据(用于对照昨天的数据)
|
||||
TradeSummaryRespBO beforeYesterdayData = getTradeSummaryByDays(-2);
|
||||
// 2.1 本月数据
|
||||
TradeSummaryRespBO monthData = getTradeSummaryByMonths(0);
|
||||
// 2.2 上月数据(用于对照本月的数据)
|
||||
TradeSummaryRespBO lastMonthData = getTradeSummaryByMonths(-1);
|
||||
// 转换返回
|
||||
return TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计指定日期的交易数据
|
||||
*
|
||||
* @param days 增加的天数
|
||||
* @return 交易数据
|
||||
*/
|
||||
private TradeSummaryRespBO getTradeSummaryByDays(int days) {
|
||||
public TradeSummaryRespBO getTradeSummaryByDays(int days) {
|
||||
LocalDateTime date = LocalDateTime.now().plusDays(days);
|
||||
return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(
|
||||
LocalDateTimeUtil.beginOfDay(date), LocalDateTimeUtil.endOfDay(date));
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计指定月份的交易数据
|
||||
*
|
||||
* @param months 增加的月数
|
||||
* @return 交易数据
|
||||
*/
|
||||
private TradeSummaryRespBO getTradeSummaryByMonths(int months) {
|
||||
@Override
|
||||
public TradeSummaryRespBO getTradeSummaryByMonths(int months) {
|
||||
LocalDateTime monthDate = LocalDateTime.now().plusMonths(months);
|
||||
return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(
|
||||
LocalDateTimeUtils.beginOfMonth(monthDate), LocalDateTimeUtils.endOfMonth(monthDate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(LocalDateTime beginTime,
|
||||
LocalDateTime endTime) {
|
||||
public DataComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(LocalDateTime beginTime,
|
||||
LocalDateTime endTime) {
|
||||
// 统计数据
|
||||
TradeTrendSummaryRespVO value = tradeStatisticsMapper.selectByTimeBetween(beginTime, endTime);
|
||||
TradeTrendSummaryRespVO value = tradeStatisticsMapper.selectVoByTimeBetween(beginTime, endTime);
|
||||
// 对照数据
|
||||
LocalDateTime referenceBeginTime = beginTime.minus(Duration.between(beginTime, endTime));
|
||||
TradeTrendSummaryRespVO reference = tradeStatisticsMapper.selectByTimeBetween(referenceBeginTime, beginTime);
|
||||
TradeTrendSummaryRespVO reference = tradeStatisticsMapper.selectVoByTimeBetween(referenceBeginTime, beginTime);
|
||||
return TradeStatisticsConvert.INSTANCE.convert(value, reference);
|
||||
}
|
||||
|
||||
@ -97,41 +75,60 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
|
||||
return tradeStatisticsMapper.selectExpensePriceByTimeBetween(beginTime, endTime);
|
||||
}
|
||||
|
||||
// TODO @疯狂:是不是直接返回 TradeStatisticsDO;上层在去聚合?
|
||||
@Override
|
||||
public List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
public List<TradeStatisticsDO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String statisticsYesterdayTrade() {
|
||||
// TODO @疯狂:如果已经统计,则跳过;
|
||||
// TODO @疯狂:改成 statisticsTrade,然后传入 days,统计多少天;days 通过 job 传参;方便把历史给统计出来;或者大家有的时候要修复数据(会 fix 业务数据,然后清理统计表),重新统计的时候;
|
||||
// 1. 从各个数据表,统计对应数据
|
||||
LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
|
||||
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
|
||||
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
|
||||
// 1.1 统计订单
|
||||
StopWatch stopWatch = new StopWatch("交易统计");
|
||||
public String statisticsTrade(Integer days) {
|
||||
LocalDateTime today = LocalDateTime.now();
|
||||
return IntStream.rangeClosed(1, days)
|
||||
.parallel()
|
||||
.mapToObj(day -> statisticsTrade(today.minusDays(day)))
|
||||
.sorted()
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计交易数据
|
||||
*
|
||||
* @param date 需要统计的日期
|
||||
* @return 统计结果
|
||||
*/
|
||||
private String statisticsTrade(LocalDateTime date) {
|
||||
// 1. 处理统计时间范围
|
||||
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(date);
|
||||
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(date);
|
||||
String dateStr = DatePattern.NORM_DATE_FORMAT.format(date);
|
||||
// 2. 检查该日是否已经统计过
|
||||
TradeStatisticsDO entity = tradeStatisticsMapper.selectByTimeBetween(beginTime, endTime);
|
||||
if (entity != null) {
|
||||
return dateStr + " 数据已存在,如果需要重新统计,请先删除对应的数据";
|
||||
}
|
||||
|
||||
// 3. 从各个数据表,统计对应数据
|
||||
StopWatch stopWatch = new StopWatch(dateStr);
|
||||
// 3.1 统计订单
|
||||
stopWatch.start("统计订单");
|
||||
TradeOrderSummaryRespBO orderSummary = tradeOrderStatisticsService.getOrderSummary(beginTime, endTime);
|
||||
stopWatch.stop();
|
||||
// 1.2 统计售后
|
||||
// 3.2 统计售后
|
||||
stopWatch.start("统计售后");
|
||||
AfterSaleSummaryRespBO afterSaleSummary = afterSaleStatisticsService.getAfterSaleSummary(beginTime, endTime);
|
||||
stopWatch.stop();
|
||||
// 1.3 统计佣金
|
||||
// 3.3 统计佣金
|
||||
stopWatch.start("统计佣金");
|
||||
Integer brokerageSettlementPrice = brokerageStatisticsService.getBrokerageSettlementPriceSummary(beginTime, endTime);
|
||||
stopWatch.stop();
|
||||
// 1.4 统计充值
|
||||
// 3.4 统计充值
|
||||
stopWatch.start("统计充值");
|
||||
WalletSummaryRespBO walletSummary = payWalletStatisticsService.getWalletSummary(beginTime, endTime);
|
||||
stopWatch.stop();
|
||||
|
||||
// 2. 插入数据
|
||||
TradeStatisticsDO entity = TradeStatisticsConvert.INSTANCE.convert(yesterday, orderSummary, afterSaleSummary,
|
||||
brokerageSettlementPrice, walletSummary);
|
||||
// 4. 插入数据
|
||||
entity = TradeStatisticsConvert.INSTANCE.convert(date, orderSummary, afterSaleSummary, brokerageSettlementPrice,
|
||||
walletSummary);
|
||||
tradeStatisticsMapper.insert(entity);
|
||||
return stopWatch.prettyPrint();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!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.infra.ApiAccessLogStatisticsMapper">
|
||||
|
||||
<select id="selectIpCountByCreateTimeBetween" resultType="java.lang.Integer">
|
||||
<select id="selectIpCountByUserTypeAndCreateTimeBetween" resultType="java.lang.Integer">
|
||||
SELECT COUNT(DISTINCT user_ip)
|
||||
FROM infra_api_access_log
|
||||
WHERE user_type = #{userType}
|
||||
@ -10,7 +10,7 @@
|
||||
AND deleted = FALSE
|
||||
</select>
|
||||
|
||||
<select id="selectUserCountByCreateTimeBetween" resultType="java.lang.Integer">
|
||||
<select id="selectUserCountByUserTypeAndCreateTimeBetween" resultType="java.lang.Integer">
|
||||
SELECT COUNT(DISTINCT user_id)
|
||||
FROM infra_api_access_log
|
||||
WHERE user_id > 0
|
||||
|
@ -3,7 +3,7 @@
|
||||
<mapper namespace="cn.iocoder.yudao.module.statistics.dal.mysql.member.MemberStatisticsMapper">
|
||||
|
||||
<select id="selectSummaryListByAreaId"
|
||||
resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO">
|
||||
resultType="cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO">
|
||||
SELECT area_id, COUNT(1) AS userCount
|
||||
FROM member_user
|
||||
WHERE deleted = FALSE
|
||||
|
@ -32,9 +32,8 @@
|
||||
|
||||
<select id="selectRechargeSummaryGroupByWalletId"
|
||||
resultType="cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO">
|
||||
<!-- TODO @疯狂:是不是不用 group by,而是通过 DISTINCT wallet_id 更合适哈? -->
|
||||
SELECT COUNT(1) AS rechargeUserCount,
|
||||
SUM(pay_price) AS rechargePrice
|
||||
SELECT COUNT(DISTINCT wallet_id) AS rechargeUserCount,
|
||||
SUM(pay_price) AS rechargePrice
|
||||
FROM pay_wallet_recharge
|
||||
WHERE pay_status = #{payStatus}
|
||||
<if test="beginTime != null">
|
||||
@ -44,7 +43,6 @@
|
||||
AND pay_time <= #{endTime}
|
||||
</if>
|
||||
AND deleted = FALSE
|
||||
GROUP BY wallet_id
|
||||
</select>
|
||||
|
||||
<select id="selectRechargePriceSummary" resultType="java.lang.Integer">
|
||||
|
@ -4,14 +4,14 @@
|
||||
<select id="selectSummaryListByAreaId"
|
||||
resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO">
|
||||
SELECT receiver_area_id AS areaId,
|
||||
(SELECT COUNT(1)
|
||||
(SELECT COUNT(DISTINCT s.user_id)
|
||||
FROM trade_order AS s
|
||||
WHERE s.receiver_area_id = m.receiver_area_id) AS orderCreateCount,
|
||||
(SELECT COUNT(1)
|
||||
WHERE s.receiver_area_id = m.receiver_area_id) AS orderCreateUserCount,
|
||||
(SELECT COUNT(DISTINCT s.user_id)
|
||||
FROM trade_order AS s
|
||||
WHERE s.receiver_area_id = m.receiver_area_id
|
||||
AND s.pay_status = TRUE
|
||||
AND s.deleted = FALSE) AS orderPayCount,
|
||||
AND s.deleted = FALSE) AS orderPayUserCount,
|
||||
(SELECT SUM(s.pay_price)
|
||||
FROM trade_order AS s
|
||||
WHERE s.receiver_area_id = m.receiver_area_id
|
||||
|
@ -11,16 +11,16 @@
|
||||
AND deleted = FALSE
|
||||
</select>
|
||||
|
||||
<select id="selectByTimeBetween"
|
||||
<select id="selectVoByTimeBetween"
|
||||
resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO">
|
||||
SELECT
|
||||
-- 营业额 = 商品支付金额 + 充值金额
|
||||
SUM(order_pay_price + recharge_pay_price) AS turnover,
|
||||
SUM(order_pay_price + recharge_pay_price) AS turnoverPrice,
|
||||
SUM(order_pay_price) AS orderPayPrice,
|
||||
SUM(recharge_pay_price) AS rechargePrice,
|
||||
-- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
|
||||
SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice,
|
||||
SUM(order_wallet_pay_price) AS balancePrice,
|
||||
SUM(order_wallet_pay_price) AS orderWalletPayPrice,
|
||||
SUM(brokerage_settlement_price) AS brokerageSettlementPrice,
|
||||
SUM(after_sale_refund_price) AS orderRefundPrice
|
||||
FROM trade_statistics
|
||||
@ -28,25 +28,6 @@
|
||||
AND deleted = FALSE
|
||||
</select>
|
||||
|
||||
<select id="selectListByTimeBetween"
|
||||
resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO">
|
||||
SELECT DATE_FORMAT(time, '%Y-%m-%d') AS date,
|
||||
-- 营业额 = 商品支付金额 + 充值金额
|
||||
SUM(order_pay_price + recharge_pay_price) AS turnover,
|
||||
SUM(order_pay_price) AS orderPayPrice,
|
||||
SUM(recharge_pay_price) AS rechargePrice,
|
||||
-- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
|
||||
SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice,
|
||||
SUM(order_wallet_pay_price) AS balancePrice,
|
||||
SUM(brokerage_settlement_price) AS brokerageSettlementPrice,
|
||||
SUM(after_sale_refund_price) AS orderRefundPrice
|
||||
FROM trade_statistics
|
||||
WHERE time BETWEEN #{beginTime} AND #{endTime}
|
||||
AND deleted = FALSE
|
||||
<!-- TODO @疯狂:已经不用 group by,它就是每天统计一条; -->
|
||||
GROUP BY date
|
||||
</select>
|
||||
|
||||
<select id="selectExpensePriceByTimeBetween" resultType="java.lang.Integer">
|
||||
SELECT -- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
|
||||
SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice
|
||||
|
Loading…
Reference in New Issue
Block a user