Commit 171161e6c7fbcbf0a8ff9291cce62901966ed547
1 parent
b2c608e7
统计:交易统计
Showing
17 changed files
with
534 additions
and
41 deletions
sql/mysql/statistics.sql
0 → 100644
| 1 | +-- 交易统计表 | ||
| 2 | +CREATE TABLE trade_statistics | ||
| 3 | +( | ||
| 4 | + id bigint AUTO_INCREMENT COMMENT '编号,主键自增' | ||
| 5 | + PRIMARY KEY, | ||
| 6 | + time datetime NOT NULL COMMENT '统计日期', | ||
| 7 | + order_create_count int DEFAULT 0 NOT NULL COMMENT '创建订单数', | ||
| 8 | + order_pay_count int DEFAULT 0 NOT NULL COMMENT '支付订单商品数', | ||
| 9 | + order_pay_price int DEFAULT 0 NOT NULL COMMENT '总支付金额,单位:分', | ||
| 10 | + order_wallet_pay_price int DEFAULT 0 NOT NULL COMMENT '总支付金额(余额),单位:分', | ||
| 11 | + after_sale_count int DEFAULT 0 NOT NULL COMMENT '退款订单数', | ||
| 12 | + after_sale_refund_price int DEFAULT 0 NOT NULL COMMENT '总退款金额,单位:分', | ||
| 13 | + brokerage_settlement_price int DEFAULT 0 NOT NULL COMMENT '佣金金额(已结算),单位:分', | ||
| 14 | + recharge_pay_count int DEFAULT 0 NOT NULL COMMENT '充值订单数', | ||
| 15 | + recharge_pay_price int DEFAULT 0 NOT NULL COMMENT '充值金额,单位:分', | ||
| 16 | + recharge_refund_count int DEFAULT 0 NOT NULL COMMENT '充值退款订单数', | ||
| 17 | + recharge_refund_price int DEFAULT 0 NOT NULL COMMENT '充值退款金额,单位:分', | ||
| 18 | + creator varchar(64) DEFAULT '' NULL COMMENT '创建者', | ||
| 19 | + create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间', | ||
| 20 | + updater varchar(64) DEFAULT '' NULL COMMENT '更新者', | ||
| 21 | + update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ||
| 22 | + deleted bit DEFAULT b'0' NOT NULL COMMENT '是否删除', | ||
| 23 | + tenant_id bigint DEFAULT 0 NOT NULL COMMENT '租户编号' | ||
| 24 | +) | ||
| 25 | + COMMENT '交易统计表'; | ||
| 26 | + | ||
| 27 | +CREATE INDEX trade_statistics_time_index | ||
| 28 | + ON trade_statistics (time); | ||
| 29 | + | ||
| 30 | +-- 菜单 | ||
| 31 | +INSERT INTO `ruoyi-vue-pro`.system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name) | ||
| 32 | +VALUES ('统计管理', '', 1, 4, 0, '/statistics', 'ep:data-line', '', ''); | ||
| 33 | +SELECT @parentId := LAST_INSERT_ID(); | ||
| 34 | +INSERT INTO `ruoyi-vue-pro`.system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name) | ||
| 35 | +VALUES ('交易统计', '', 2, 4, @parentId, 'trade', 'fa-solid:credit-card', 'statistics/trade/index', 'TradeStatistics'); | ||
| 36 | +SELECT @parentId := LAST_INSERT_ID(); | ||
| 37 | +-- 按钮 | ||
| 38 | +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) | ||
| 39 | +VALUES ('交易统计查询', 'statistics:trade:query', 3, 1, @parentId, '', '', '', 0); | ||
| 40 | +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) | ||
| 41 | +VALUES ('交易统计导出', 'statistics:trade:export', 3, 2, @parentId, '', '', '', 0); | ||
| 42 | + | ||
| 43 | + |
yudao-module-mall/yudao-module-statistics-biz/pom.xml
| @@ -49,6 +49,10 @@ | @@ -49,6 +49,10 @@ | ||
| 49 | <groupId>cn.iocoder.boot</groupId> | 49 | <groupId>cn.iocoder.boot</groupId> |
| 50 | <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId> | 50 | <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId> |
| 51 | </dependency> | 51 | </dependency> |
| 52 | + <dependency> | ||
| 53 | + <groupId>cn.iocoder.boot</groupId> | ||
| 54 | + <artifactId>yudao-spring-boot-starter-biz-tenant</artifactId> | ||
| 55 | + </dependency> | ||
| 52 | 56 | ||
| 53 | <!-- Web 相关 --> | 57 | <!-- Web 相关 --> |
| 54 | <dependency> | 58 | <dependency> |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.controller.admin.trade; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.util.ArrayUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 5 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 6 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*; | ||
| 7 | +import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert; | ||
| 8 | +import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService; | ||
| 9 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 10 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 11 | +import lombok.extern.slf4j.Slf4j; | ||
| 12 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 13 | +import org.springframework.validation.annotation.Validated; | ||
| 14 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 15 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 16 | +import org.springframework.web.bind.annotation.RestController; | ||
| 17 | + | ||
| 18 | +import javax.annotation.Resource; | ||
| 19 | +import javax.servlet.http.HttpServletResponse; | ||
| 20 | +import java.io.IOException; | ||
| 21 | +import java.util.List; | ||
| 22 | + | ||
| 23 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 24 | + | ||
| 25 | +@Tag(name = "管理后台 - 交易统计") | ||
| 26 | +@RestController | ||
| 27 | +@RequestMapping("/statistics/trade") | ||
| 28 | +@Validated | ||
| 29 | +@Slf4j | ||
| 30 | +public class TradeStatisticsController { | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private TradeStatisticsService tradeStatisticsService; | ||
| 34 | + | ||
| 35 | + @GetMapping("/summary") | ||
| 36 | + @Operation(summary = "获得交易统计") | ||
| 37 | + @PreAuthorize("@ss.hasPermission('statistics:trade:query')") | ||
| 38 | + public CommonResult<TradeStatisticsComparisonRespVO<TradeSummaryRespVO>> getTradeSummaryComparison() { | ||
| 39 | + return success(tradeStatisticsService.getTradeSummaryComparison()); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @GetMapping("/trend/summary") | ||
| 43 | + @Operation(summary = "获得交易状况统计") | ||
| 44 | + @PreAuthorize("@ss.hasPermission('statistics:trade:query')") | ||
| 45 | + public CommonResult<TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO>> getTradeTrendSummaryComparison( | ||
| 46 | + TradeTrendReqVO reqVO) { | ||
| 47 | + return success(tradeStatisticsService.getTradeTrendSummaryComparison(ArrayUtil.get(reqVO.getTimes(), 0), | ||
| 48 | + ArrayUtil.get(reqVO.getTimes(), 1))); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + @GetMapping("/trend/list") | ||
| 52 | + @Operation(summary = "获得交易状况明细") | ||
| 53 | + @PreAuthorize("@ss.hasPermission('statistics:trade:query')") | ||
| 54 | + public CommonResult<List<TradeTrendSummaryRespVO>> getTradeStatisticsList( | ||
| 55 | + TradeTrendReqVO reqVO) { | ||
| 56 | + return success(tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0), | ||
| 57 | + ArrayUtil.get(reqVO.getTimes(), 1))); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @GetMapping("/trend/export-excel") | ||
| 61 | + @Operation(summary = "导出获得交易状况明细 Excel") | ||
| 62 | + @PreAuthorize("@ss.hasPermission('statistics:trade:export')") | ||
| 63 | + public void exportTradeStatisticsExcel(TradeTrendReqVO reqVO, HttpServletResponse response) throws IOException { | ||
| 64 | + List<TradeTrendSummaryRespVO> list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0), | ||
| 65 | + ArrayUtil.get(reqVO.getTimes(), 1)); | ||
| 66 | + // 导出 Excel | ||
| 67 | + List<TradeTrendSummaryExcelVO> data = TradeStatisticsConvert.INSTANCE.convertList02(list); | ||
| 68 | + ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeStatisticsComparisonRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.AllArgsConstructor; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.NoArgsConstructor; | ||
| 7 | + | ||
| 8 | +@Schema(description = "管理后台 - 交易统计对照 Response VO") | ||
| 9 | +@Data | ||
| 10 | +@NoArgsConstructor | ||
| 11 | +@AllArgsConstructor | ||
| 12 | +public class TradeStatisticsComparisonRespVO<T> { | ||
| 13 | + | ||
| 14 | + @Schema(description = "当前数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 15 | + private T value; | ||
| 16 | + | ||
| 17 | + @Schema(description = "参照数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 18 | + private T reference; | ||
| 19 | + | ||
| 20 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeSummaryRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +@Schema(description = "管理后台 - 交易统计 Response VO") | ||
| 7 | +@Data | ||
| 8 | +public class TradeSummaryRespVO { | ||
| 9 | + @Schema(description = "昨日订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 10 | + private Integer yesterdayOrderCount; | ||
| 11 | + @Schema(description = "昨日支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 12 | + private Integer yesterdayPayPrice; | ||
| 13 | + | ||
| 14 | + @Schema(description = "本月订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 15 | + private Integer monthOrderCount; | ||
| 16 | + @Schema(description = "本月支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 17 | + private Integer monthPayPrice; | ||
| 18 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 6 | + | ||
| 7 | +import java.time.LocalDateTime; | ||
| 8 | + | ||
| 9 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 10 | + | ||
| 11 | +@Schema(description = "管理后台 - 交易状况 Request VO") | ||
| 12 | +@Data | ||
| 13 | +public class TradeTrendReqVO { | ||
| 14 | + | ||
| 15 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 16 | + @Schema(description = "时间范围") | ||
| 17 | + private LocalDateTime[] times; | ||
| 18 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryExcelVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.excel.core.convert.MoneyConvert; | ||
| 4 | +import com.alibaba.excel.annotation.ExcelProperty; | ||
| 5 | +import com.alibaba.excel.annotation.format.DateTimeFormat; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +import java.time.LocalDate; | ||
| 9 | + | ||
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 交易状况统计 Excel VO | ||
| 14 | + * | ||
| 15 | + * @author owen | ||
| 16 | + */ | ||
| 17 | +@Data | ||
| 18 | +public class TradeTrendSummaryExcelVO { | ||
| 19 | + | ||
| 20 | + @ExcelProperty(value = "日期") | ||
| 21 | + @DateTimeFormat(FORMAT_YEAR_MONTH_DAY) | ||
| 22 | + private LocalDate date; | ||
| 23 | + | ||
| 24 | + @ExcelProperty(value = "营业额", converter = MoneyConvert.class) | ||
| 25 | + private Integer turnover; | ||
| 26 | + | ||
| 27 | + @ExcelProperty(value = "商品支付金额", converter = MoneyConvert.class) | ||
| 28 | + private Integer orderPayPrice; | ||
| 29 | + | ||
| 30 | + @ExcelProperty(value = "充值金额", converter = MoneyConvert.class) | ||
| 31 | + private Integer rechargePrice; | ||
| 32 | + | ||
| 33 | + @ExcelProperty(value = "支出金额", converter = MoneyConvert.class) | ||
| 34 | + private Integer expensePrice; | ||
| 35 | + | ||
| 36 | + @ExcelProperty(value = "余额支付金额", converter = MoneyConvert.class) | ||
| 37 | + private Integer balancePrice; | ||
| 38 | + | ||
| 39 | + @ExcelProperty(value = "支付佣金金额", converter = MoneyConvert.class) | ||
| 40 | + private Integer brokerageSettlementPrice; | ||
| 41 | + | ||
| 42 | + @ExcelProperty(value = "商品退款金额", converter = MoneyConvert.class) | ||
| 43 | + private Integer orderRefundPrice; | ||
| 44 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +import java.time.LocalDate; | ||
| 8 | + | ||
| 9 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; | ||
| 10 | + | ||
| 11 | +@Schema(description = "管理后台 - 交易状况统计 Response VO") | ||
| 12 | +@Data | ||
| 13 | +public class TradeTrendSummaryRespVO { | ||
| 14 | + | ||
| 15 | + @Schema(description = "日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 16 | + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY) | ||
| 17 | + private LocalDate date; | ||
| 18 | + | ||
| 19 | + @Schema(description = "营业额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 20 | + private Integer turnover; | ||
| 21 | + | ||
| 22 | + @Schema(description = "商品支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 23 | + private Integer orderPayPrice; | ||
| 24 | + | ||
| 25 | + @Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 26 | + private Integer rechargePrice; | ||
| 27 | + | ||
| 28 | + @Schema(description = "支出金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 29 | + private Integer expensePrice; | ||
| 30 | + | ||
| 31 | + @Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 32 | + private Integer balancePrice; | ||
| 33 | + | ||
| 34 | + @Schema(description = "支付佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 35 | + private Integer brokerageSettlementPrice; | ||
| 36 | + | ||
| 37 | + @Schema(description = "商品退款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 38 | + private Integer orderRefundPrice; | ||
| 39 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/trade/TradeStatisticsController.java deleted
| 1 | -package cn.iocoder.yudao.module.statistics.controller.trade; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | -import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsDO; | ||
| 5 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 6 | -import lombok.extern.slf4j.Slf4j; | ||
| 7 | -import org.springframework.validation.annotation.Validated; | ||
| 8 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 9 | -import org.springframework.web.bind.annotation.RestController; | ||
| 10 | - | ||
| 11 | -import java.time.LocalDateTime; | ||
| 12 | -import java.util.List; | ||
| 13 | - | ||
| 14 | -@Tag(name = "管理后台 - 交易统计") | ||
| 15 | -@RestController | ||
| 16 | -@RequestMapping("/statistics/product") | ||
| 17 | -@Validated | ||
| 18 | -@Slf4j | ||
| 19 | -public class TradeStatisticsController { | ||
| 20 | - | ||
| 21 | - // TODO @疯狂:有个 summary 接口,返回昨日、本月、支付金额、本月订单金额等数据;具体看 ui 哈; | ||
| 22 | - | ||
| 23 | - // TODO @疯狂:返回 ProductStatisticsComparisonResp, 里面有两个字段,一个是选择的时间范围的合计结果,一个是对比的时间范围的合计结果; | ||
| 24 | - // 例如说,选择时间范围是 2023-10-01 ~ 2023-10-02,那么对比就是 2023-09-30,再倒推 2 天; | ||
| 25 | - public CommonResult<Object> getTradeStatisticsComparison() { | ||
| 26 | - return null; | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - // TODO @疯狂:查询指定时间范围内的交易统计数据;DO 到时需要改成 VO 哈 | ||
| 30 | - // 总收入(营业额)= 订单、充值的支付 - 订单、充值的退款 | ||
| 31 | - public CommonResult<List<TradeStatisticsDO>> getTradeStatisticsList( | ||
| 32 | - LocalDateTime[] times) { | ||
| 33 | - return null; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | -} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/trade/TradeStatisticsConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.convert.trade; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; | ||
| 4 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO; | ||
| 5 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryExcelVO; | ||
| 6 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO; | ||
| 7 | +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; | ||
| 8 | +import org.mapstruct.Mapper; | ||
| 9 | +import org.mapstruct.factory.Mappers; | ||
| 10 | + | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 交易统计 Convert | ||
| 15 | + * | ||
| 16 | + * @author owen | ||
| 17 | + */ | ||
| 18 | +@Mapper | ||
| 19 | +public interface TradeStatisticsConvert { | ||
| 20 | + | ||
| 21 | + TradeStatisticsConvert INSTANCE = Mappers.getMapper(TradeStatisticsConvert.class); | ||
| 22 | + | ||
| 23 | + default TradeStatisticsComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespBO yesterdayData, | ||
| 24 | + TradeSummaryRespBO beforeYesterdayData, | ||
| 25 | + TradeSummaryRespBO monthData, | ||
| 26 | + TradeSummaryRespBO lastMonthData) { | ||
| 27 | + return convert(convert(yesterdayData, monthData), convert(beforeYesterdayData, lastMonthData)); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + default TradeSummaryRespVO convert(TradeSummaryRespBO yesterdayData, TradeSummaryRespBO monthData) { | ||
| 32 | + return new TradeSummaryRespVO() | ||
| 33 | + .setYesterdayOrderCount(yesterdayData.getCount()).setYesterdayPayPrice(yesterdayData.getSummary()) | ||
| 34 | + .setMonthOrderCount(monthData.getCount()).setMonthPayPrice(monthData.getSummary()); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + TradeStatisticsComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespVO value, TradeSummaryRespVO reference); | ||
| 38 | + | ||
| 39 | + TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> convert(TradeTrendSummaryRespVO value, TradeTrendSummaryRespVO reference); | ||
| 40 | + | ||
| 41 | + List<TradeTrendSummaryExcelVO> convertList02(List<TradeTrendSummaryRespVO> list); | ||
| 42 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsDO.java renamed to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/dataobject/trade/TradeStatisticsDO.java
| 1 | -package cn.iocoder.yudao.module.statistics.dal.mysql.trade; | 1 | +package cn.iocoder.yudao.module.statistics.dal.dataobject.trade; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; |
| 4 | import com.baomidou.mybatisplus.annotation.KeySequence; | 4 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -10,7 +10,7 @@ import java.time.LocalDateTime; | @@ -10,7 +10,7 @@ import java.time.LocalDateTime; | ||
| 10 | 10 | ||
| 11 | /** | 11 | /** |
| 12 | * 交易统计 DO | 12 | * 交易统计 DO |
| 13 | - * | 13 | + * <p> |
| 14 | * 以天为维度,统计全部的数据 | 14 | * 以天为维度,统计全部的数据 |
| 15 | * | 15 | * |
| 16 | * @author 芋道源码 | 16 | * @author 芋道源码 |
| @@ -23,7 +23,7 @@ import java.time.LocalDateTime; | @@ -23,7 +23,7 @@ import java.time.LocalDateTime; | ||
| 23 | @Builder | 23 | @Builder |
| 24 | @NoArgsConstructor | 24 | @NoArgsConstructor |
| 25 | @AllArgsConstructor | 25 | @AllArgsConstructor |
| 26 | -public class TradeStatisticsDO extends BaseDO { | 26 | +public class TradeStatisticsDO extends TenantBaseDO { |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | * 编号,主键自增 | 29 | * 编号,主键自增 |
| @@ -69,7 +69,7 @@ public class TradeStatisticsDO extends BaseDO { | @@ -69,7 +69,7 @@ public class TradeStatisticsDO extends BaseDO { | ||
| 69 | 69 | ||
| 70 | /** | 70 | /** |
| 71 | * 充值订单数 | 71 | * 充值订单数 |
| 72 | - * | 72 | + * <p> |
| 73 | * 从 PayWalletRechargeDO 计算 | 73 | * 从 PayWalletRechargeDO 计算 |
| 74 | */ | 74 | */ |
| 75 | private Integer rechargePayCount; | 75 | private Integer rechargePayCount; |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.dal.mysql.trade; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 4 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO; | ||
| 5 | +import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; | ||
| 6 | +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; | ||
| 7 | +import org.apache.ibatis.annotations.Mapper; | ||
| 8 | +import org.apache.ibatis.annotations.Param; | ||
| 9 | +import org.apache.ibatis.annotations.Select; | ||
| 10 | + | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * 交易统计 Mapper | ||
| 16 | + * | ||
| 17 | + * @author owen | ||
| 18 | + */ | ||
| 19 | +@Mapper | ||
| 20 | +public interface TradeStatisticsMapper extends BaseMapperX<TradeStatisticsDO> { | ||
| 21 | + | ||
| 22 | + @Select("SELECT IFNULL(SUM(order_create_count), 0) AS count, IFNULL(SUM(order_pay_price), 0) AS summary " + | ||
| 23 | + "FROM trade_statistics " + | ||
| 24 | + "WHERE time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE") | ||
| 25 | + TradeSummaryRespBO selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(@Param("beginTime") LocalDateTime beginTime, | ||
| 26 | + @Param("endTime") LocalDateTime endTime); | ||
| 27 | + | ||
| 28 | + TradeTrendSummaryRespVO selectByTimeBetween(@Param("beginTime") LocalDateTime beginTime, | ||
| 29 | + @Param("endTime") LocalDateTime endTime); | ||
| 30 | + | ||
| 31 | + List<TradeTrendSummaryRespVO> selectListByTimeBetween(@Param("beginTime") LocalDateTime beginTime, | ||
| 32 | + @Param("endTime") LocalDateTime endTime); | ||
| 33 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.service.trade; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; | ||
| 4 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO; | ||
| 5 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO; | ||
| 6 | + | ||
| 7 | +import java.time.LocalDateTime; | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 交易统计 Service 接口 | ||
| 12 | + * | ||
| 13 | + * @author owen | ||
| 14 | + */ | ||
| 15 | +public interface TradeStatisticsService { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 获得交易统计 | ||
| 19 | + * | ||
| 20 | + * @return 统计数据对照 | ||
| 21 | + */ | ||
| 22 | + TradeStatisticsComparisonRespVO<TradeSummaryRespVO> getTradeSummaryComparison(); | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 获得交易状况统计 | ||
| 26 | + * | ||
| 27 | + * @return 统计数据对照 | ||
| 28 | + */ | ||
| 29 | + TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(LocalDateTime beginTime, LocalDateTime endTime); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 获得交易状况明细 | ||
| 33 | + * | ||
| 34 | + * @return 统计数据列表 | ||
| 35 | + */ | ||
| 36 | + List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime); | ||
| 37 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.service.trade; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.date.LocalDateTimeUtil; | ||
| 4 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; | ||
| 5 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO; | ||
| 6 | +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO; | ||
| 7 | +import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert; | ||
| 8 | +import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsMapper; | ||
| 9 | +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | +import java.time.Duration; | ||
| 15 | +import java.time.LocalDateTime; | ||
| 16 | +import java.time.LocalTime; | ||
| 17 | +import java.time.temporal.TemporalAdjusters; | ||
| 18 | +import java.util.List; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * 交易统计 Service 实现类 | ||
| 22 | + * | ||
| 23 | + * @author owen | ||
| 24 | + */ | ||
| 25 | +@Service | ||
| 26 | +@Validated | ||
| 27 | +public class TradeStatisticsServiceImpl implements TradeStatisticsService { | ||
| 28 | + | ||
| 29 | + @Resource | ||
| 30 | + private TradeStatisticsMapper tradeStatisticsMapper; | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public TradeStatisticsComparisonRespVO<TradeSummaryRespVO> getTradeSummaryComparison() { | ||
| 34 | + // 昨天的数据 | ||
| 35 | + TradeSummaryRespBO yesterdayData = getTradeSummaryByDays(-1); | ||
| 36 | + // 前天的数据(用于对照昨天的数据) | ||
| 37 | + TradeSummaryRespBO beforeYesterdayData = getTradeSummaryByDays(-2); | ||
| 38 | + | ||
| 39 | + // 本月数据; | ||
| 40 | + TradeSummaryRespBO monthData = getTradeSummaryByMonths(0); | ||
| 41 | + // 上月数据(用于对照本月的数据) | ||
| 42 | + TradeSummaryRespBO lastMonthData = getTradeSummaryByMonths(-1); | ||
| 43 | + | ||
| 44 | + return TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(LocalDateTime beginTime, | ||
| 49 | + LocalDateTime endTime) { | ||
| 50 | + // 统计数据 | ||
| 51 | + TradeTrendSummaryRespVO value = tradeStatisticsMapper.selectByTimeBetween(beginTime, endTime); | ||
| 52 | + // 对照数据 | ||
| 53 | + LocalDateTime referenceBeginTime = beginTime.minus(Duration.between(beginTime, endTime)); | ||
| 54 | + TradeTrendSummaryRespVO reference = tradeStatisticsMapper.selectByTimeBetween(referenceBeginTime, beginTime); | ||
| 55 | + return TradeStatisticsConvert.INSTANCE.convert(value, reference); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + public List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) { | ||
| 60 | + return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * 统计指定日期的交易数据 | ||
| 65 | + * | ||
| 66 | + * @param days 增加的天数 | ||
| 67 | + * @return 交易数据 | ||
| 68 | + */ | ||
| 69 | + private TradeSummaryRespBO getTradeSummaryByDays(int days) { | ||
| 70 | + LocalDateTime date = LocalDateTime.now().plusDays(days); | ||
| 71 | + return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween( | ||
| 72 | + LocalDateTimeUtil.beginOfDay(date), LocalDateTimeUtil.endOfDay(date)); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * 统计指定月份的交易数据 | ||
| 77 | + * | ||
| 78 | + * @param months 增加的月数 | ||
| 79 | + * @return 交易数据 | ||
| 80 | + */ | ||
| 81 | + private TradeSummaryRespBO getTradeSummaryByMonths(int months) { | ||
| 82 | + // 月份开始时间 | ||
| 83 | + LocalDateTime beginOfMonth = LocalDateTime.now() | ||
| 84 | + .plusMonths(months) | ||
| 85 | + .with(TemporalAdjusters.firstDayOfMonth()) | ||
| 86 | + .with(LocalTime.MIN); | ||
| 87 | + // 月份截止时间 | ||
| 88 | + LocalDateTime endOfToday = LocalDateTime.now() | ||
| 89 | + .plusMonths(months) | ||
| 90 | + .with(TemporalAdjusters.lastDayOfMonth()) | ||
| 91 | + .with(LocalTime.MAX); | ||
| 92 | + return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(beginOfMonth, endOfToday); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeSummaryRespBO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.service.trade.bo; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 交易统计 Resp BO | ||
| 7 | + * | ||
| 8 | + * @author owen | ||
| 9 | + */ | ||
| 10 | +@Data | ||
| 11 | +public class TradeSummaryRespBO { | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 数量 | ||
| 15 | + */ | ||
| 16 | + private Integer count; | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 合计 | ||
| 20 | + */ | ||
| 21 | + private Integer summary; | ||
| 22 | +} |
yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeStatisticsMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 3 | +<mapper namespace="cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsMapper"> | ||
| 4 | + <select id="selectByTimeBetween" | ||
| 5 | + resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO"> | ||
| 6 | + SELECT | ||
| 7 | + -- 营业额 = 商品支付金额 + 充值金额 | ||
| 8 | + SUM(order_pay_price + recharge_pay_price) AS turnover, | ||
| 9 | + SUM(order_pay_price) AS orderPayPrice, | ||
| 10 | + SUM(recharge_pay_price) AS rechargePrice, | ||
| 11 | + -- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额 | ||
| 12 | + SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice, | ||
| 13 | + SUM(order_wallet_pay_price) AS balancePrice, | ||
| 14 | + SUM(brokerage_settlement_price) AS brokerageSettlementPrice, | ||
| 15 | + SUM(after_sale_refund_price) AS orderRefundPrice | ||
| 16 | + FROM trade_statistics | ||
| 17 | + WHERE time BETWEEN #{beginTime} AND #{endTime} | ||
| 18 | + AND deleted = FALSE | ||
| 19 | + </select> | ||
| 20 | + | ||
| 21 | + <select id="selectListByTimeBetween" | ||
| 22 | + resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO"> | ||
| 23 | + SELECT DATE_FORMAT(time, '%Y-%m-%d') AS date, | ||
| 24 | + -- 营业额 = 商品支付金额 + 充值金额 | ||
| 25 | + SUM(order_pay_price + recharge_pay_price) AS turnover, | ||
| 26 | + SUM(order_pay_price) AS orderPayPrice, | ||
| 27 | + SUM(recharge_pay_price) AS rechargePrice, | ||
| 28 | + -- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额 | ||
| 29 | + SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice, | ||
| 30 | + SUM(order_wallet_pay_price) AS balancePrice, | ||
| 31 | + SUM(brokerage_settlement_price) AS brokerageSettlementPrice, | ||
| 32 | + SUM(after_sale_refund_price) AS orderRefundPrice | ||
| 33 | + FROM trade_statistics | ||
| 34 | + WHERE time BETWEEN #{beginTime} AND #{endTime} | ||
| 35 | + AND deleted = FALSE | ||
| 36 | + GROUP BY date | ||
| 37 | + </select> | ||
| 38 | +</mapper> |
yudao-server/pom.xml
| @@ -83,6 +83,11 @@ | @@ -83,6 +83,11 @@ | ||
| 83 | <artifactId>yudao-module-trade-biz</artifactId> | 83 | <artifactId>yudao-module-trade-biz</artifactId> |
| 84 | <version>${revision}</version> | 84 | <version>${revision}</version> |
| 85 | </dependency> | 85 | </dependency> |
| 86 | + <dependency> | ||
| 87 | + <groupId>cn.iocoder.boot</groupId> | ||
| 88 | + <artifactId>yudao-module-statistics-biz</artifactId> | ||
| 89 | + <version>${revision}</version> | ||
| 90 | + </dependency> | ||
| 86 | 91 | ||
| 87 | <!-- spring boot 配置所需依赖 --> | 92 | <!-- spring boot 配置所需依赖 --> |
| 88 | <dependency> | 93 | <dependency> |