From 3b72e7e83d94b5d78d28f068570facbdcd4036bb Mon Sep 17 00:00:00 2001
From: Cui Zhi Feng <cuizf@fengyuntec.com>
Date: 星期二, 29 十月 2024 11:35:02 +0800
Subject: [PATCH] 统计 订单量 供应商数量 全部用户量 售后订单数量
---
src/main/java/com/mzl/flower/service/statistics/StatisticsService.java | 243 ++++++++++++++++++++++++++++++++++++++--
src/main/java/com/mzl/flower/dto/request/payment/OrderItemSalesQueryDTO.java | 3
src/main/java/com/mzl/flower/service/payment/OrderItemSalesService.java | 2
src/main/java/com/mzl/flower/web/statistics/StatisticsController.java | 87 ++++++++++++++
src/main/resources/mapper/payment/OrderItemSalesMapper.xml | 7
src/main/java/com/mzl/flower/dto/response/statistics/RateStatisticsDTO.java | 17 ++
6 files changed, 345 insertions(+), 14 deletions(-)
diff --git a/src/main/java/com/mzl/flower/dto/request/payment/OrderItemSalesQueryDTO.java b/src/main/java/com/mzl/flower/dto/request/payment/OrderItemSalesQueryDTO.java
index 63adac0..d69bd85 100644
--- a/src/main/java/com/mzl/flower/dto/request/payment/OrderItemSalesQueryDTO.java
+++ b/src/main/java/com/mzl/flower/dto/request/payment/OrderItemSalesQueryDTO.java
@@ -5,6 +5,7 @@
import java.io.Serializable;
import java.time.LocalDateTime;
+import java.util.List;
@Data
public class OrderItemSalesQueryDTO implements Serializable {
@@ -69,4 +70,6 @@
private LocalDateTime salesEndDate;
private String salesType;//售后类型
+
+ private List<String> statusList;
}
diff --git a/src/main/java/com/mzl/flower/dto/response/statistics/RateStatisticsDTO.java b/src/main/java/com/mzl/flower/dto/response/statistics/RateStatisticsDTO.java
new file mode 100644
index 0000000..79468fd
--- /dev/null
+++ b/src/main/java/com/mzl/flower/dto/response/statistics/RateStatisticsDTO.java
@@ -0,0 +1,17 @@
+package com.mzl.flower.dto.response.statistics;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class RateStatisticsDTO {
+ @ApiModelProperty(value = "量")
+ private Long count;
+
+ @ApiModelProperty(value = "新增量")
+ private Long countToday;
+
+ @ApiModelProperty(value = "日环比")
+ private Double countRate;
+
+}
diff --git a/src/main/java/com/mzl/flower/service/payment/OrderItemSalesService.java b/src/main/java/com/mzl/flower/service/payment/OrderItemSalesService.java
index 7fddc66..3e1edc4 100644
--- a/src/main/java/com/mzl/flower/service/payment/OrderItemSalesService.java
+++ b/src/main/java/com/mzl/flower/service/payment/OrderItemSalesService.java
@@ -197,6 +197,7 @@
dto.setOrderEndDate(parseLocalDateTime(dto.getOrderEndDateStr(), false));
dto.setSalesStartDate(parseLocalDateTime(dto.getSalesStartDateStr(), true));
dto.setSalesEndDate(parseLocalDateTime(dto.getSalesEndDateStr(), false));
+ dto.setStatusList(splitParam(dto.getStatus()));
List<OrderItemSalesNewListDTO> ls = orderItemSalesMapper.selectItemSalesList(page, dto);
@@ -209,6 +210,7 @@
dto.setOrderEndDate(parseLocalDateTime(dto.getOrderEndDateStr(), false));
dto.setSalesStartDate(parseLocalDateTime(dto.getSalesStartDateStr(), true));
dto.setSalesEndDate(parseLocalDateTime(dto.getSalesEndDateStr(), false));
+ dto.setStatusList(splitParam(dto.getStatus()));
List<OrderItemSalesNewListDTO> ls = orderItemSalesMapper.selectItemSalesList(null, dto);
codeDecorator.decorate(ls);
diff --git a/src/main/java/com/mzl/flower/service/statistics/StatisticsService.java b/src/main/java/com/mzl/flower/service/statistics/StatisticsService.java
index a0322f9..a2c7a37 100644
--- a/src/main/java/com/mzl/flower/service/statistics/StatisticsService.java
+++ b/src/main/java/com/mzl/flower/service/statistics/StatisticsService.java
@@ -7,12 +7,14 @@
import com.mzl.flower.dto.request.flower.FlowerQueryDTO;
import com.mzl.flower.dto.request.payment.OrderItemSalesQueryDTO;
import com.mzl.flower.dto.request.payment.OrderQueryDTO;
-import com.mzl.flower.dto.response.flower.FlowerListDTO;
import com.mzl.flower.dto.response.statistics.FlowerStatisticsDTO;
import com.mzl.flower.dto.response.statistics.OrderStatisticsDTO;
+import com.mzl.flower.dto.response.statistics.RateStatisticsDTO;
import com.mzl.flower.dto.response.statistics.SaleStatisticsDTO;
+import com.mzl.flower.entity.customer.Customer;
import com.mzl.flower.entity.payment.Order;
import com.mzl.flower.entity.supplier.Supplier;
+import com.mzl.flower.mapper.customer.CustomerMapper;
import com.mzl.flower.mapper.flower.FlowerMapper;
import com.mzl.flower.mapper.payment.*;
import com.mzl.flower.mapper.supplier.SupplierMapper;
@@ -24,6 +26,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
@@ -49,6 +52,9 @@
@Autowired
private OrderItemSalesMapper orderItemSalesMapper;
+ @Autowired
+ private CustomerMapper customerMapper;
+
public SaleStatisticsDTO getSaleStatistics(String date){
if(StringUtils.isEmpty(date)){
throw new ValidationException("日期不能为空");
@@ -62,8 +68,8 @@
LocalDateTime begin = end.plusDays(-1);
SaleStatisticsDTO dto = new SaleStatisticsDTO();
- BigDecimal a = orderMapper.getOrderSaleAmount(begin, end);
- Integer c = orderItemMapper.getFlowerSaleNum(begin, end);
+ BigDecimal a = orderMapper.getOrderSaleAmount(begin, end);//今日销售额:今日全部的实际支付金额合计
+ Integer c = orderItemMapper.getFlowerSaleNum(begin, end);//今日销售扎数:今日成功交易的订单的成交数量
dto.setSaleAmount(a);
dto.setSaleFlowerCount(c == null ? 0 : c.longValue());
@@ -83,26 +89,26 @@
statusList.add(Constants.FLOWER_STATUS.FORCE_OFF.name());
q.setStatusList(statusList);
flowerMapper.selectFlowerList(page, q);
- dto.setFlowerCount(page.getTotal());
+ dto.setFlowerCount(page.getTotal());//商品管理:待审核+上架+下架(点击跳转到商品列表)
Integer sc = supplierMapper.selectCount(new QueryWrapper<Supplier>()
.eq("is_enabled", 1)
.eq("status", "P")
.eq("deleted", 0));
- dto.setSupplierCount(sc.longValue());
+ dto.setSupplierCount(sc.longValue());//用户管理:统计商户列表已启用的全部用户(点击跳转到商户列表)
Integer oc = orderMapper.selectCount(new QueryWrapper<Order>()
.eq("deleted", 0)
.isNotNull("payment_time")
.isNull("cancel_time")
.isNull("refund_time"));
- dto.setOrderCount(oc.longValue());
+ dto.setOrderCount(oc.longValue());//订单管理:全部订单数量-待付款-已取消-已退款(点击跳转到订单列表)
page = new Page(1, 1);
OrderQueryDTO oq = new OrderQueryDTO();
oq.setStatusBackend(Constants.ORDER_STATUS_BACKEND.SEND.name());
orderMapper.selectOrderList(page, oq);
- dto.setOrderSendCount(page.getTotal());
+ dto.setOrderSendCount(page.getTotal());//待发货:统计订单列表待发货的数量(点击跳转到订单列表-待发货页面)
page = new Page(1, 1);
q = new FlowerQueryDTO();
@@ -110,7 +116,7 @@
statusList.add(Constants.FLOWER_STATUS.UP.name());
q.setStatusList(statusList);
flowerMapper.selectFlowerList(page, q);
- dto.setFlowerUpCount(page.getTotal());
+ dto.setFlowerUpCount(page.getTotal());//在售商品:统计商品列表上架的商品数量(点击跳转到商品列表-上架页面)
page = new Page(1, 1);
q = new FlowerQueryDTO();
@@ -118,21 +124,22 @@
statusList.add(Constants.FLOWER_STATUS.PENDING.name());
q.setStatusList(statusList);
flowerMapper.selectFlowerList(page, q);
- dto.setFlowerPendingCount(page.getTotal());
+ dto.setFlowerPendingCount(page.getTotal());//待审核商品:跳转到商品列表-待审核页面
page = new Page(1, 1);
OrderItemSalesQueryDTO sq = new OrderItemSalesQueryDTO();
sq.setStatus(Constants.ORDER_SALES_STATUS.PENDING.name());
+ sq.setStatusList(splitParam(sq.getStatus()));
orderItemSalesMapper.selectItemSalesList(page, sq);
- dto.setOrderSalesCount(page.getTotal());
+ dto.setOrderSalesCount(page.getTotal());//待售后处理:统计售后理赔-待审核的数量(跳转到售后理赔-待审核页面)
return dto;
}
public OrderStatisticsDTO getOrderStatistics(){
OrderStatisticsDTO dto = new OrderStatisticsDTO();
- BigDecimal a = orderMapper.getOrderSaleAmount(null, null);
- Integer c = orderItemMapper.getFlowerSaleNum(null, null);
+ BigDecimal a = orderMapper.getOrderSaleAmount(null, null);//总销售金额:全部有效订单的实际支付金额合计
+ Integer c = orderItemMapper.getFlowerSaleNum(null, null);//总销售扎数:成功交易订单的成交数量
dto.setTotalSaleAmount(a);
dto.setTotalSaleFlowerCount(c == null ? 0 : c.longValue());
@@ -141,4 +148,216 @@
return dto;
}
+
+ public RateStatisticsDTO getOrderRateStatistics(String date){
+ if(StringUtils.isEmpty(date)){
+ throw new ValidationException("日期不能为空");
+ }
+ LocalDate localDate = parseLocalDate(date);
+ if(localDate == null){
+ throw new ValidationException("日期无效");
+ }
+
+ LocalDateTime end = localDate.atTime(17, 0, 0);
+ LocalDateTime begin = end.plusDays(-1);
+
+ LocalDateTime endY = begin;
+ LocalDateTime beginY = endY.plusDays(-1);
+
+ RateStatisticsDTO dto = new RateStatisticsDTO();
+
+ //订单量:与订单管理一致(并计算新增量,计算日环比)
+ Integer oc = orderMapper.selectCount(new QueryWrapper<Order>()
+ .eq("deleted", 0)
+ .isNotNull("payment_time")
+ .isNull("cancel_time")
+ .isNull("refund_time"));
+ dto.setCount(oc.longValue());
+
+ Integer ocToday = orderMapper.selectCount(new QueryWrapper<Order>()
+ .eq("deleted", 0)
+ .isNotNull("payment_time")
+ .isNull("cancel_time")
+ .isNull("refund_time")
+ .gt("create_time", begin)
+ .le("create_time", end)
+ );
+ dto.setCountToday(ocToday.longValue());
+
+ Integer ocY = orderMapper.selectCount(new QueryWrapper<Order>()
+ .eq("deleted", 0)
+ .isNotNull("payment_time")
+ .isNull("cancel_time")
+ .isNull("refund_time")
+ .gt("create_time", beginY)
+ .le("create_time", endY)
+ );
+ dto.setCountRate(getRate(ocToday, ocY));
+
+ return dto;
+ }
+
+ public RateStatisticsDTO getSupplierRateStatistics(String date) {
+ if (StringUtils.isEmpty(date)) {
+ throw new ValidationException("日期不能为空");
+ }
+ LocalDate localDate = parseLocalDate(date);
+ if (localDate == null) {
+ throw new ValidationException("日期无效");
+ }
+
+ LocalDateTime end = localDate.atTime(23, 59, 59);
+ LocalDateTime begin = localDate.atTime(0, 0, 0);
+
+ LocalDateTime endY = end.plusDays(-1);
+ LocalDateTime beginY = begin.plusDays(-1);
+
+ RateStatisticsDTO dto = new RateStatisticsDTO();
+
+ //供应商数量:已启用的供应商数量(并计算新增量,计算日环比)
+ Integer sc = supplierMapper.selectCount(new QueryWrapper<Supplier>()
+ .eq("is_enabled", 1)
+ .eq("status", "P")
+ .eq("deleted", 0));
+ dto.setCount(sc.longValue());
+
+ Integer scT = supplierMapper.selectCount(new QueryWrapper<Supplier>()
+ .eq("is_enabled", 1)
+ .eq("status", "P")
+ .eq("deleted", 0)
+ .gt("create_time", begin)
+ .le("create_time", end)
+ );
+ dto.setCountToday(scT.longValue());
+
+ Integer scY = supplierMapper.selectCount(new QueryWrapper<Supplier>()
+ .eq("is_enabled", 1)
+ .eq("status", "P")
+ .eq("deleted", 0)
+ .gt("create_time", beginY)
+ .le("create_time", endY)
+ );
+ dto.setCountRate(getRate(scT, scY));
+
+ return dto;
+ }
+
+ public RateStatisticsDTO getCustomerRateStatistics(String date) {
+ if (StringUtils.isEmpty(date)) {
+ throw new ValidationException("日期不能为空");
+ }
+ LocalDate localDate = parseLocalDate(date);
+ if (localDate == null) {
+ throw new ValidationException("日期无效");
+ }
+
+ LocalDateTime end = localDate.atTime(23, 59, 59);
+ LocalDateTime begin = localDate.atTime(0, 0, 0);
+
+ LocalDateTime endY = end.plusDays(-1);
+ LocalDateTime beginY = begin.plusDays(-1);
+
+ RateStatisticsDTO dto = new RateStatisticsDTO();
+ //全部用户量:已启用的用户数量合计(并计算新增量,计算日环比)
+
+ Integer c = customerMapper.selectCount(new QueryWrapper<Customer>()
+ .eq("deleted", 0));
+ dto.setCount(c.longValue());
+
+ Integer cT = customerMapper.selectCount(new QueryWrapper<Customer>()
+ .eq("deleted", 0)
+ .gt("create_time", begin)
+ .le("create_time", end)
+ );
+ dto.setCountToday(cT.longValue());
+
+ Integer cY = customerMapper.selectCount(new QueryWrapper<Customer>()
+ .eq("deleted", 0)
+ .gt("create_time", beginY)
+ .le("create_time", endY)
+ );
+ dto.setCountRate(getRate(cT, cY));
+
+ return dto;
+ }
+
+ public RateStatisticsDTO getCustomerVisitRateStatistics(String date) {
+ if (StringUtils.isEmpty(date)) {
+ throw new ValidationException("日期不能为空");
+ }
+ LocalDate localDate = parseLocalDate(date);
+ if (localDate == null) {
+ throw new ValidationException("日期无效");
+ }
+
+ LocalDateTime end = localDate.atTime(23, 59, 59);
+ LocalDateTime begin = localDate.atTime(0, 0, 0);
+
+ LocalDateTime endY = end.plusDays(-1);
+ LocalDateTime beginY = begin.plusDays(-1);
+
+ RateStatisticsDTO dto = new RateStatisticsDTO();
+ //TODO 用户访问量:点击到交易大厅或者商品详情页面计算,同一个用户,每天只计算一次(包含游客)(并计算新增量,计算日环比)
+
+ return dto;
+ }
+
+ public RateStatisticsDTO getSalesRateStatistics(String date) {
+ if (StringUtils.isEmpty(date)) {
+ throw new ValidationException("日期不能为空");
+ }
+ LocalDate localDate = parseLocalDate(date);
+ if (localDate == null) {
+ throw new ValidationException("日期无效");
+ }
+
+ LocalDateTime end = localDate.atTime(23, 59, 59);
+ LocalDateTime begin = localDate.atTime(0, 0, 0);
+
+ LocalDateTime endY = end.plusDays(-1);
+ LocalDateTime beginY = begin.plusDays(-1);
+
+ RateStatisticsDTO dto = new RateStatisticsDTO();
+ //售后订单数量:统计待审核+已通过(并计算新增量,计算日环比)
+
+ List<String> statusList = new ArrayList<>();
+ statusList.add(Constants.ORDER_SALES_STATUS.PENDING.name());
+ statusList.add(Constants.ORDER_SALES_STATUS.AGREED.name());
+
+ Page page = new Page(1, 1);
+ OrderItemSalesQueryDTO sq = new OrderItemSalesQueryDTO();
+ sq.setStatusList(statusList);
+ orderItemSalesMapper.selectItemSalesList(page, sq);
+ dto.setCount(page.getTotal());
+
+ page = new Page(1, 1);
+ sq = new OrderItemSalesQueryDTO();
+ sq.setStatusList(statusList);
+ sq.setSalesStartDate(begin);
+ sq.setSalesStartDate(end);
+ orderItemSalesMapper.selectItemSalesList(page, sq);
+ dto.setCountToday(page.getTotal());
+
+ page = new Page(1, 1);
+ sq = new OrderItemSalesQueryDTO();
+ sq.setStatusList(statusList);
+ sq.setSalesStartDate(beginY);
+ sq.setSalesStartDate(endY);
+ orderItemSalesMapper.selectItemSalesList(page, sq);
+ dto.setCountRate(getRate(dto.getCountToday().intValue(), (int)page.getTotal()));
+
+ return dto;
+ }
+
+ private Double getRate(Integer today, Integer yesterday){
+ if(yesterday > 0){
+ Integer ty = today - yesterday;
+ BigDecimal ttyy = BigDecimal.valueOf(ty);
+ BigDecimal yy = BigDecimal.valueOf(yesterday);
+ BigDecimal rate = ttyy.divide(yy, 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
+ return rate.doubleValue();
+ }
+
+ return 100D;
+ }
}
diff --git a/src/main/java/com/mzl/flower/web/statistics/StatisticsController.java b/src/main/java/com/mzl/flower/web/statistics/StatisticsController.java
new file mode 100644
index 0000000..3227d8b
--- /dev/null
+++ b/src/main/java/com/mzl/flower/web/statistics/StatisticsController.java
@@ -0,0 +1,87 @@
+package com.mzl.flower.web.statistics;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.mzl.flower.base.BaseController;
+import com.mzl.flower.base.R;
+import com.mzl.flower.base.ReturnDataDTO;
+import com.mzl.flower.dto.response.statistics.FlowerStatisticsDTO;
+import com.mzl.flower.dto.response.statistics.OrderStatisticsDTO;
+import com.mzl.flower.dto.response.statistics.RateStatisticsDTO;
+import com.mzl.flower.dto.response.statistics.SaleStatisticsDTO;
+import com.mzl.flower.service.statistics.StatisticsService;
+import com.mzl.flower.utils.HttpUtil;
+import com.wechat.pay.java.core.http.HttpMethod;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/statistics")
+@Api(value = "统计", tags = "统计")
+@Validated
+@Slf4j
+public class StatisticsController extends BaseController {
+
+ @Autowired
+ private StatisticsService statisticsService;
+
+ @GetMapping("/sale/date")
+ @ApiOperation(value = "当日销售统计")
+ public ResponseEntity<ReturnDataDTO<SaleStatisticsDTO>> getSaleStatistics(String date){
+ return returnData(R.SUCCESS.getCode(), statisticsService.getSaleStatistics(date));
+ }
+
+ @GetMapping("/flower/count")
+ @ApiOperation(value = "商品商户统计")
+ public ResponseEntity<ReturnDataDTO<FlowerStatisticsDTO>> getFlowerStatistics(){
+ return returnData(R.SUCCESS.getCode(), statisticsService.getFlowerStatistics());
+ }
+
+ @GetMapping("/order/amount")
+ @ApiOperation(value = "订单金额统计")
+ public ResponseEntity<ReturnDataDTO<OrderStatisticsDTO>> getOrderStatistics(){
+ return returnData(R.SUCCESS.getCode(), statisticsService.getOrderStatistics());
+ }
+
+ @GetMapping("/order/rate")
+ @ApiOperation(value = "订单环比统计")
+ public ResponseEntity<ReturnDataDTO<RateStatisticsDTO>> getOrderRateStatistics(String date){
+ return returnData(R.SUCCESS.getCode(), statisticsService.getOrderRateStatistics(date));
+ }
+
+ @GetMapping("/supplier/rate")
+ @ApiOperation(value = "商户环比统计")
+ public ResponseEntity<ReturnDataDTO<RateStatisticsDTO>> getSupplierRateStatistics(String date){
+ return returnData(R.SUCCESS.getCode(), statisticsService.getSupplierRateStatistics(date));
+ }
+
+ @GetMapping("/customer/rate")
+ @ApiOperation(value = "花店环比统计")
+ public ResponseEntity<ReturnDataDTO<RateStatisticsDTO>> getCustomerRateStatistics(String date){
+ return returnData(R.SUCCESS.getCode(), statisticsService.getCustomerRateStatistics(date));
+ }
+
+ @GetMapping("/customer/visit/rate")
+ @ApiOperation(value = "花店访问环比统计")
+ public ResponseEntity<ReturnDataDTO<RateStatisticsDTO>> getCustomerVisitRateStatistics(String date){
+ return returnData(R.SUCCESS.getCode(), statisticsService.getCustomerVisitRateStatistics(date));
+ }
+
+ @GetMapping("/sales/rate")
+ @ApiOperation(value = "售后环比统计")
+ public ResponseEntity<ReturnDataDTO<RateStatisticsDTO>> getSalesRateStatistics(String date){
+ return returnData(R.SUCCESS.getCode(), statisticsService.getSalesRateStatistics(date));
+ }
+
+
+}
diff --git a/src/main/resources/mapper/payment/OrderItemSalesMapper.xml b/src/main/resources/mapper/payment/OrderItemSalesMapper.xml
index 207a856..7fdb06b 100644
--- a/src/main/resources/mapper/payment/OrderItemSalesMapper.xml
+++ b/src/main/resources/mapper/payment/OrderItemSalesMapper.xml
@@ -123,8 +123,11 @@
AND si.create_time <= #{condition.salesEndDate}
</if>
- <if test="condition.status != null and condition.status != ''">
- AND si.status = #{condition.status}
+ <if test="condition.statusList != null and condition.statusList.size > 0">
+ AND si.status in
+ <foreach collection="condition.statusList" item="item" open="(" separator="," close=")">
+ #{item}
+ </foreach>
</if>
<if test="condition.createBy != null and condition.createBy != ''">
--
Gitblit v1.9.3