优化代码结构
This commit is contained in:
parent
f7ab6dc6ae
commit
ea80777ef6
@ -13,41 +13,41 @@ import lombok.Data;
|
|||||||
public class OrderOverviewVO {
|
public class OrderOverviewVO {
|
||||||
|
|
||||||
@ApiModelProperty(value = "UV人次")
|
@ApiModelProperty(value = "UV人次")
|
||||||
private Integer uvNum = 0;
|
private Long uvNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下单统计
|
* 下单统计
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "下单数量")
|
@ApiModelProperty(value = "下单数量")
|
||||||
private Long orderNum = 0L;
|
private Long orderNum;
|
||||||
|
|
||||||
@ApiModelProperty(value = "下单人数")
|
@ApiModelProperty(value = "下单人数")
|
||||||
private Long orderMemberNum = 0L;
|
private Long orderMemberNum;
|
||||||
|
|
||||||
@ApiModelProperty(value = "下单金额")
|
@ApiModelProperty(value = "下单金额")
|
||||||
private Double orderAmount = 0D;
|
private Double orderAmount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 付款统计
|
* 付款统计
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "付款订单数量")
|
@ApiModelProperty(value = "付款订单数量")
|
||||||
private Long paymentOrderNum = 0L;
|
private Long paymentOrderNum;
|
||||||
|
|
||||||
@ApiModelProperty(value = "付款人数")
|
@ApiModelProperty(value = "付款人数")
|
||||||
private Long paymentsNum = 0L;
|
private Long paymentsNum;
|
||||||
|
|
||||||
@ApiModelProperty(value = "付款金额")
|
@ApiModelProperty(value = "付款金额")
|
||||||
private Double paymentAmount = 0D;
|
private Double paymentAmount;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退单统计
|
* 退单统计
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "退单笔数")
|
@ApiModelProperty(value = "退单笔数")
|
||||||
private Long refundOrderNum = 0L;
|
private Long refundOrderNum;
|
||||||
|
|
||||||
@ApiModelProperty(value = "退单金额")
|
@ApiModelProperty(value = "退单金额")
|
||||||
private Double refundOrderPrice = 0D;
|
private Double refundOrderPrice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换率
|
* 转换率
|
||||||
@ -61,5 +61,66 @@ public class OrderOverviewVO {
|
|||||||
@ApiModelProperty(value = "整体转换率")
|
@ApiModelProperty(value = "整体转换率")
|
||||||
private String overallConversionRate;
|
private String overallConversionRate;
|
||||||
|
|
||||||
|
public Long getUvNum() {
|
||||||
|
if (uvNum == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return uvNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getOrderNum() {
|
||||||
|
if (orderNum == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return orderNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getOrderMemberNum() {
|
||||||
|
if (orderMemberNum == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return orderMemberNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getOrderAmount() {
|
||||||
|
if (orderAmount == null) {
|
||||||
|
return 0D;
|
||||||
|
}
|
||||||
|
return orderAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getPaymentOrderNum() {
|
||||||
|
if (paymentOrderNum == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return paymentOrderNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getPaymentsNum() {
|
||||||
|
if (paymentsNum == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return paymentsNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getPaymentAmount() {
|
||||||
|
if (paymentAmount == null) {
|
||||||
|
return 0D;
|
||||||
|
}
|
||||||
|
return paymentAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getRefundOrderNum() {
|
||||||
|
if (refundOrderNum == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return refundOrderNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getRefundOrderPrice() {
|
||||||
|
if (refundOrderPrice == null) {
|
||||||
|
return 0D;
|
||||||
|
}
|
||||||
|
return refundOrderPrice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.lili.modules.statistics.mapper;
|
package cn.lili.modules.statistics.mapper;
|
||||||
|
|
||||||
import cn.lili.modules.order.order.entity.dos.StoreFlow;
|
import cn.lili.modules.order.order.entity.dos.Order;
|
||||||
import cn.lili.modules.order.order.entity.vo.OrderSimpleVO;
|
import cn.lili.modules.order.order.entity.vo.OrderSimpleVO;
|
||||||
import cn.lili.modules.statistics.entity.vo.OrderStatisticsDataVO;
|
import cn.lili.modules.statistics.entity.vo.OrderStatisticsDataVO;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
@ -18,10 +18,11 @@ import java.util.List;
|
|||||||
* @author Bulbasaur
|
* @author Bulbasaur
|
||||||
* @since 2020/11/17 7:34 下午
|
* @since 2020/11/17 7:34 下午
|
||||||
*/
|
*/
|
||||||
public interface OrderStatisticsMapper extends BaseMapper<StoreFlow> {
|
public interface OrderStatisticsMapper extends BaseMapper<Order> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取订单统计数据
|
* 获取订单统计数据
|
||||||
|
*
|
||||||
* @param queryWrapper 查询条件
|
* @param queryWrapper 查询条件
|
||||||
* @return 订单统计列表
|
* @return 订单统计列表
|
||||||
*/
|
*/
|
||||||
@ -31,6 +32,7 @@ public interface OrderStatisticsMapper extends BaseMapper<StoreFlow> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单数量
|
* 订单数量
|
||||||
|
*
|
||||||
* @param queryWrapper 查询条件
|
* @param queryWrapper 查询条件
|
||||||
* @return 订单数量
|
* @return 订单数量
|
||||||
*/
|
*/
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.lili.modules.statistics.service;
|
package cn.lili.modules.statistics.service;
|
||||||
|
|
||||||
import cn.lili.common.vo.PageVO;
|
import cn.lili.common.vo.PageVO;
|
||||||
import cn.lili.modules.order.order.entity.dos.StoreFlow;
|
import cn.lili.modules.order.order.entity.dos.Order;
|
||||||
import cn.lili.modules.order.order.entity.vo.OrderSimpleVO;
|
import cn.lili.modules.order.order.entity.vo.OrderSimpleVO;
|
||||||
import cn.lili.modules.statistics.entity.dto.StatisticsQueryParam;
|
import cn.lili.modules.statistics.entity.dto.StatisticsQueryParam;
|
||||||
import cn.lili.modules.statistics.entity.vo.OrderOverviewVO;
|
import cn.lili.modules.statistics.entity.vo.OrderOverviewVO;
|
||||||
@ -18,7 +18,7 @@ import java.util.Map;
|
|||||||
* @author Bulbasaur
|
* @author Bulbasaur
|
||||||
* @since 2020/12/9 11:06
|
* @since 2020/12/9 11:06
|
||||||
*/
|
*/
|
||||||
public interface OrderStatisticsService extends IService<StoreFlow> {
|
public interface OrderStatisticsService extends IService<Order> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单统计概览
|
* 订单统计概览
|
||||||
@ -35,14 +35,6 @@ public interface OrderStatisticsService extends IService<StoreFlow> {
|
|||||||
*/
|
*/
|
||||||
Map<String, Object> getStoreOrderStatisticsPrice();
|
Map<String, Object> getStoreOrderStatisticsPrice();
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询今日付款统计
|
|
||||||
*
|
|
||||||
* @return 订单统计金额
|
|
||||||
*/
|
|
||||||
Map<String, Object> getOrderStatisticsPrice();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取订单总数量
|
* 获取订单总数量
|
||||||
*
|
*
|
||||||
|
@ -2,14 +2,18 @@ package cn.lili.modules.statistics.service;
|
|||||||
|
|
||||||
import cn.lili.modules.order.order.entity.dos.StoreFlow;
|
import cn.lili.modules.order.order.entity.dos.StoreFlow;
|
||||||
import cn.lili.modules.statistics.entity.dto.GoodsStatisticsQueryParam;
|
import cn.lili.modules.statistics.entity.dto.GoodsStatisticsQueryParam;
|
||||||
|
import cn.lili.modules.statistics.entity.dto.StatisticsQueryParam;
|
||||||
import cn.lili.modules.statistics.entity.vo.CategoryStatisticsDataVO;
|
import cn.lili.modules.statistics.entity.vo.CategoryStatisticsDataVO;
|
||||||
import cn.lili.modules.statistics.entity.vo.GoodsStatisticsDataVO;
|
import cn.lili.modules.statistics.entity.vo.GoodsStatisticsDataVO;
|
||||||
|
import cn.lili.modules.statistics.entity.vo.OrderOverviewVO;
|
||||||
import cn.lili.modules.statistics.entity.vo.StoreStatisticsDataVO;
|
import cn.lili.modules.statistics.entity.vo.StoreStatisticsDataVO;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流水统计业务层
|
* 流水统计业务层
|
||||||
@ -46,4 +50,20 @@ public interface StoreFlowStatisticsService extends IService<StoreFlow> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<StoreStatisticsDataVO> getStoreStatisticsData(Page page, QueryWrapper queryWrapper);
|
List<StoreStatisticsDataVO> getStoreStatisticsData(Page page, QueryWrapper queryWrapper);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询今日付款统计
|
||||||
|
*
|
||||||
|
* @return 订单统计金额
|
||||||
|
*/
|
||||||
|
Map<String, Object> getOrderStatisticsPrice();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单统计,数据概览
|
||||||
|
*
|
||||||
|
* @param dates
|
||||||
|
* @param orderOverviewVO
|
||||||
|
* @param statisticsQueryParam
|
||||||
|
*/
|
||||||
|
void overview(Date[] dates, OrderOverviewVO orderOverviewVO, StatisticsQueryParam statisticsQueryParam);
|
||||||
}
|
}
|
@ -133,7 +133,7 @@ public class IndexStatisticsServiceImpl implements IndexStatisticsService {
|
|||||||
indexStatisticsVO.setStoreNum(storeStatisticsService.storeNum());
|
indexStatisticsVO.setStoreNum(storeStatisticsService.storeNum());
|
||||||
|
|
||||||
//下单统计
|
//下单统计
|
||||||
Map<String, Object> map = orderStatisticsService.getOrderStatisticsPrice();
|
Map<String, Object> map = storeFlowStatisticsService.getOrderStatisticsPrice();
|
||||||
//今日下单数
|
//今日下单数
|
||||||
indexStatisticsVO.setTodayOrderNum(map.get("num") == null ? 0L : (Long) map.get("num"));
|
indexStatisticsVO.setTodayOrderNum(map.get("num") == null ? 0L : (Long) map.get("num"));
|
||||||
//今日下单金额
|
//今日下单金额
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
package cn.lili.modules.statistics.serviceimpl;
|
package cn.lili.modules.statistics.serviceimpl;
|
||||||
|
|
||||||
import cn.lili.common.security.AuthUser;
|
|
||||||
import cn.lili.common.security.context.UserContext;
|
import cn.lili.common.security.context.UserContext;
|
||||||
import cn.lili.common.security.enums.UserEnums;
|
import cn.lili.common.security.enums.UserEnums;
|
||||||
import cn.lili.common.utils.CurrencyUtil;
|
import cn.lili.common.utils.CurrencyUtil;
|
||||||
import cn.lili.common.utils.DateUtil;
|
|
||||||
import cn.lili.common.utils.StringUtils;
|
import cn.lili.common.utils.StringUtils;
|
||||||
import cn.lili.common.vo.PageVO;
|
import cn.lili.common.vo.PageVO;
|
||||||
import cn.lili.modules.order.order.entity.dos.Order;
|
import cn.lili.modules.order.order.entity.dos.Order;
|
||||||
import cn.lili.modules.order.order.entity.dos.StoreFlow;
|
|
||||||
import cn.lili.modules.order.order.entity.enums.FlowTypeEnum;
|
import cn.lili.modules.order.order.entity.enums.FlowTypeEnum;
|
||||||
import cn.lili.modules.order.order.entity.enums.PayStatusEnum;
|
import cn.lili.modules.order.order.entity.enums.PayStatusEnum;
|
||||||
import cn.lili.modules.order.order.entity.vo.OrderSimpleVO;
|
import cn.lili.modules.order.order.entity.vo.OrderSimpleVO;
|
||||||
import cn.lili.modules.order.order.service.OrderService;
|
|
||||||
import cn.lili.modules.statistics.entity.dto.StatisticsQueryParam;
|
import cn.lili.modules.statistics.entity.dto.StatisticsQueryParam;
|
||||||
import cn.lili.modules.statistics.entity.vo.OrderOverviewVO;
|
import cn.lili.modules.statistics.entity.vo.OrderOverviewVO;
|
||||||
import cn.lili.modules.statistics.entity.vo.OrderStatisticsDataVO;
|
import cn.lili.modules.statistics.entity.vo.OrderStatisticsDataVO;
|
||||||
@ -38,18 +34,13 @@ import java.util.*;
|
|||||||
* @since 2020/12/9 17:16
|
* @since 2020/12/9 17:16
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class OrderStatisticsServiceImpl extends ServiceImpl<OrderStatisticsMapper, StoreFlow> implements OrderStatisticsService {
|
public class OrderStatisticsServiceImpl extends ServiceImpl<OrderStatisticsMapper, Order> implements OrderStatisticsService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台PV统计
|
* 平台PV统计
|
||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlatformViewService platformViewService;
|
private PlatformViewService platformViewService;
|
||||||
/**
|
|
||||||
* 订单
|
|
||||||
*/
|
|
||||||
@Autowired
|
|
||||||
private OrderService orderService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OrderOverviewVO overview(StatisticsQueryParam statisticsQueryParam) {
|
public OrderOverviewVO overview(StatisticsQueryParam statisticsQueryParam) {
|
||||||
@ -57,16 +48,10 @@ public class OrderStatisticsServiceImpl extends ServiceImpl<OrderStatisticsMappe
|
|||||||
|
|
||||||
OrderOverviewVO orderOverviewVO = new OrderOverviewVO();
|
OrderOverviewVO orderOverviewVO = new OrderOverviewVO();
|
||||||
//访客数
|
//访客数
|
||||||
orderOverviewVO.setUvNum(platformViewService.countUv(statisticsQueryParam));
|
Integer uv = platformViewService.countUv(statisticsQueryParam);
|
||||||
|
if (uv != null) {
|
||||||
//下单统计
|
orderOverviewVO.setUvNum(uv.longValue());
|
||||||
initOrder(dates, orderOverviewVO, statisticsQueryParam);
|
}
|
||||||
|
|
||||||
//付款统计
|
|
||||||
initPayment(dates, orderOverviewVO, statisticsQueryParam);
|
|
||||||
|
|
||||||
//退单统计
|
|
||||||
initAfterSale(dates, orderOverviewVO, statisticsQueryParam);
|
|
||||||
|
|
||||||
//数据运算(转换率,比例相关)
|
//数据运算(转换率,比例相关)
|
||||||
conversionRateOperation(orderOverviewVO);
|
conversionRateOperation(orderOverviewVO);
|
||||||
@ -100,102 +85,6 @@ public class OrderStatisticsServiceImpl extends ServiceImpl<OrderStatisticsMappe
|
|||||||
orderOverviewVO.setOverallConversionRate(CurrencyUtil.mul(overallConversionRate, 100) + "%");
|
orderOverviewVO.setOverallConversionRate(CurrencyUtil.mul(overallConversionRate, 100) + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单统计-下单属性填充
|
|
||||||
*
|
|
||||||
* @param dates
|
|
||||||
* @param orderOverviewVO
|
|
||||||
*/
|
|
||||||
private void initOrder(Date[] dates, OrderOverviewVO orderOverviewVO, StatisticsQueryParam statisticsQueryParam) {
|
|
||||||
//构建查询条件
|
|
||||||
QueryWrapper queryWrapper = Wrappers.query();
|
|
||||||
//时间区间
|
|
||||||
queryWrapper.between("create_time", dates[0], dates[1]);
|
|
||||||
//如果有店铺id传入,则查询店铺
|
|
||||||
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
|
||||||
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
|
||||||
}
|
|
||||||
//查询流水金额和订单数量
|
|
||||||
queryWrapper.select("SUM(flow_price) AS price , COUNT(0) AS num");
|
|
||||||
//获取查询结果
|
|
||||||
Map order = orderService.getMap(queryWrapper);
|
|
||||||
//赋予订单数和流水金额
|
|
||||||
orderOverviewVO.setOrderNum(order != null && order.containsKey("num") ? (Long) order.get("num") : 0L);
|
|
||||||
orderOverviewVO.setOrderAmount(order != null && order.containsKey("price") ? (double) order.get("price") : 0L);
|
|
||||||
|
|
||||||
//查询下单人数
|
|
||||||
queryWrapper = Wrappers.query();
|
|
||||||
//时间区间
|
|
||||||
queryWrapper.between("create_time", dates[0], dates[1]);
|
|
||||||
//如果有店铺id传入,则查询店铺
|
|
||||||
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
|
||||||
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
|
||||||
}
|
|
||||||
//查询下单人数的sql
|
|
||||||
queryWrapper.select("count(DISTINCT member_id) AS num");
|
|
||||||
//获取查询结果
|
|
||||||
Map memberNum = orderService.getMap(queryWrapper);
|
|
||||||
//写入下单人数
|
|
||||||
orderOverviewVO.setOrderMemberNum(memberNum != null && memberNum.containsKey("num") ? (Long) memberNum.get("num") : 0L);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单统计-付款属性填充
|
|
||||||
*
|
|
||||||
* @param dates
|
|
||||||
* @param orderOverviewVO
|
|
||||||
*/
|
|
||||||
private void initPayment(Date[] dates, OrderOverviewVO orderOverviewVO, StatisticsQueryParam statisticsQueryParam) {
|
|
||||||
//付款订单数,付款金额
|
|
||||||
QueryWrapper queryWrapper = Wrappers.query();
|
|
||||||
queryWrapper.between("create_time", dates[0], dates[1]);
|
|
||||||
//如果有店铺id传入,则查询店铺
|
|
||||||
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
|
||||||
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
|
||||||
}
|
|
||||||
queryWrapper.select("SUM(final_price) AS price , COUNT(0) AS num");
|
|
||||||
queryWrapper.eq("flow_type", FlowTypeEnum.PAY.name());
|
|
||||||
Map payment = this.getMap(queryWrapper);
|
|
||||||
|
|
||||||
orderOverviewVO.setPaymentOrderNum(payment != null && payment.containsKey("num") ? (Long) payment.get("num") : 0L);
|
|
||||||
orderOverviewVO.setPaymentAmount(payment != null && payment.containsKey("price") ? (Double) payment.get("price") : 0D);
|
|
||||||
|
|
||||||
//付款人数
|
|
||||||
queryWrapper = Wrappers.query();
|
|
||||||
queryWrapper.between("create_time", dates[0], dates[1]);
|
|
||||||
//如果有店铺id传入,则查询店铺
|
|
||||||
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
|
||||||
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
|
||||||
}
|
|
||||||
queryWrapper.select("COUNT(0) AS num");
|
|
||||||
queryWrapper.groupBy("member_id");
|
|
||||||
Map paymentMemberNum = this.getMap(queryWrapper);
|
|
||||||
|
|
||||||
orderOverviewVO.setPaymentsNum(paymentMemberNum != null && paymentMemberNum.containsKey("num") ? (Long) paymentMemberNum.get("num") : 0L);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单统计-付款属性填充
|
|
||||||
*
|
|
||||||
* @param dates
|
|
||||||
* @param orderOverviewVO
|
|
||||||
*/
|
|
||||||
private void initAfterSale(Date[] dates, OrderOverviewVO orderOverviewVO, StatisticsQueryParam statisticsQueryParam) {
|
|
||||||
//付款订单数,付款金额
|
|
||||||
QueryWrapper queryWrapper = Wrappers.query();
|
|
||||||
queryWrapper.between("create_time", dates[0], dates[1]);
|
|
||||||
queryWrapper.select("SUM(final_price) AS price , COUNT(0) AS num");
|
|
||||||
//如果有店铺id传入,则查询店铺
|
|
||||||
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
|
||||||
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
|
||||||
}
|
|
||||||
queryWrapper.eq("flow_type", FlowTypeEnum.REFUND.name());
|
|
||||||
Map payment = this.getMap(queryWrapper);
|
|
||||||
orderOverviewVO.setRefundOrderNum(payment != null && payment.containsKey("num") ? (Long) payment.get("num") : 0L);
|
|
||||||
orderOverviewVO.setRefundOrderPrice(payment != null && payment.containsKey("price") ? (Double) payment.get("price") : 0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getStoreOrderStatisticsPrice() {
|
public Map<String, Object> getStoreOrderStatisticsPrice() {
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
@ -205,23 +94,6 @@ public class OrderStatisticsServiceImpl extends ServiceImpl<OrderStatisticsMappe
|
|||||||
return this.getMap(queryWrapper);
|
return this.getMap(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> getOrderStatisticsPrice() {
|
|
||||||
QueryWrapper queryWrapper = Wrappers.query();
|
|
||||||
//支付订单
|
|
||||||
queryWrapper.eq("flow_type", FlowTypeEnum.PAY.name());
|
|
||||||
|
|
||||||
//商家查询,则增加商家判定
|
|
||||||
AuthUser authUser = UserContext.getCurrentUser();
|
|
||||||
if (authUser.getRole().equals(UserEnums.STORE)) {
|
|
||||||
queryWrapper.eq("store_id", authUser.getStoreId());
|
|
||||||
}
|
|
||||||
//大于今天凌晨
|
|
||||||
queryWrapper.ge("create_time", DateUtil.startOfTodDayTime());
|
|
||||||
|
|
||||||
queryWrapper.select("SUM(final_price) AS price , COUNT(0) AS num");
|
|
||||||
return this.getMap(queryWrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer orderNum(String orderStatus) {
|
public Integer orderNum(String orderStatus) {
|
||||||
@ -229,7 +101,7 @@ public class OrderStatisticsServiceImpl extends ServiceImpl<OrderStatisticsMappe
|
|||||||
queryWrapper.eq(StringUtils.isNotEmpty(orderStatus), Order::getOrderStatus, orderStatus);
|
queryWrapper.eq(StringUtils.isNotEmpty(orderStatus), Order::getOrderStatus, orderStatus);
|
||||||
queryWrapper.eq(StringUtils.equals(UserContext.getCurrentUser().getRole().name(), UserEnums.STORE.name()),
|
queryWrapper.eq(StringUtils.equals(UserContext.getCurrentUser().getRole().name(), UserEnums.STORE.name()),
|
||||||
Order::getStoreId, UserContext.getCurrentUser().getStoreId());
|
Order::getStoreId, UserContext.getCurrentUser().getStoreId());
|
||||||
return orderService.count(queryWrapper);
|
return this.count(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -286,6 +158,7 @@ public class OrderStatisticsServiceImpl extends ServiceImpl<OrderStatisticsMappe
|
|||||||
queryWrapper.orderByDesc("o.id");
|
queryWrapper.orderByDesc("o.id");
|
||||||
return this.baseMapper.queryByParams(PageUtil.initPage(pageVO), queryWrapper);
|
return this.baseMapper.queryByParams(PageUtil.initPage(pageVO), queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private QueryWrapper getQueryWrapper(StatisticsQueryParam statisticsQueryParam) {
|
private QueryWrapper getQueryWrapper(StatisticsQueryParam statisticsQueryParam) {
|
||||||
|
|
||||||
QueryWrapper queryWrapper = Wrappers.query();
|
QueryWrapper queryWrapper = Wrappers.query();
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package cn.lili.modules.statistics.serviceimpl;
|
package cn.lili.modules.statistics.serviceimpl;
|
||||||
|
|
||||||
|
import cn.lili.common.security.AuthUser;
|
||||||
|
import cn.lili.common.security.context.UserContext;
|
||||||
|
import cn.lili.common.security.enums.UserEnums;
|
||||||
import cn.lili.common.utils.StringUtils;
|
import cn.lili.common.utils.StringUtils;
|
||||||
import cn.lili.modules.order.order.entity.dos.StoreFlow;
|
import cn.lili.modules.order.order.entity.dos.StoreFlow;
|
||||||
import cn.lili.modules.order.order.entity.enums.FlowTypeEnum;
|
import cn.lili.modules.order.order.entity.enums.FlowTypeEnum;
|
||||||
import cn.lili.modules.statistics.entity.dto.GoodsStatisticsQueryParam;
|
import cn.lili.modules.statistics.entity.dto.GoodsStatisticsQueryParam;
|
||||||
|
import cn.lili.modules.statistics.entity.dto.StatisticsQueryParam;
|
||||||
import cn.lili.modules.statistics.entity.enums.StatisticsQuery;
|
import cn.lili.modules.statistics.entity.enums.StatisticsQuery;
|
||||||
import cn.lili.modules.statistics.entity.vo.CategoryStatisticsDataVO;
|
import cn.lili.modules.statistics.entity.vo.CategoryStatisticsDataVO;
|
||||||
import cn.lili.modules.statistics.entity.vo.GoodsStatisticsDataVO;
|
import cn.lili.modules.statistics.entity.vo.GoodsStatisticsDataVO;
|
||||||
|
import cn.lili.modules.statistics.entity.vo.OrderOverviewVO;
|
||||||
import cn.lili.modules.statistics.entity.vo.StoreStatisticsDataVO;
|
import cn.lili.modules.statistics.entity.vo.StoreStatisticsDataVO;
|
||||||
import cn.lili.modules.statistics.mapper.StoreFlowStatisticsMapper;
|
import cn.lili.modules.statistics.mapper.StoreFlowStatisticsMapper;
|
||||||
import cn.lili.modules.statistics.service.StoreFlowStatisticsService;
|
import cn.lili.modules.statistics.service.StoreFlowStatisticsService;
|
||||||
@ -19,6 +24,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品统计业务层实现
|
* 商品统计业务层实现
|
||||||
@ -57,6 +63,133 @@ public class StoreFlowStatisticsServiceImpl extends ServiceImpl<StoreFlowStatist
|
|||||||
return this.baseMapper.getStoreStatisticsData(page, queryWrapper);
|
return this.baseMapper.getStoreStatisticsData(page, queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getOrderStatisticsPrice() {
|
||||||
|
QueryWrapper queryWrapper = Wrappers.query();
|
||||||
|
//支付订单
|
||||||
|
queryWrapper.eq("flow_type", FlowTypeEnum.PAY.name());
|
||||||
|
|
||||||
|
//商家查询,则增加商家判定
|
||||||
|
AuthUser authUser = UserContext.getCurrentUser();
|
||||||
|
if (authUser.getRole().equals(UserEnums.STORE)) {
|
||||||
|
queryWrapper.eq("store_id", authUser.getStoreId());
|
||||||
|
}
|
||||||
|
//大于今天凌晨
|
||||||
|
queryWrapper.ge("create_time", cn.lili.common.utils.DateUtil.startOfTodDayTime());
|
||||||
|
|
||||||
|
queryWrapper.select("SUM(final_price) AS price , COUNT(0) AS num");
|
||||||
|
return this.getMap(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void overview(Date[] dates, OrderOverviewVO orderOverviewVO, StatisticsQueryParam statisticsQueryParam) {
|
||||||
|
//下单统计
|
||||||
|
initOrder(dates, orderOverviewVO, statisticsQueryParam);
|
||||||
|
|
||||||
|
//付款统计
|
||||||
|
initPayment(dates, orderOverviewVO, statisticsQueryParam);
|
||||||
|
|
||||||
|
//退单统计
|
||||||
|
initAfterSale(dates, orderOverviewVO, statisticsQueryParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单统计-下单属性填充
|
||||||
|
*
|
||||||
|
* @param dates
|
||||||
|
* @param orderOverviewVO
|
||||||
|
*/
|
||||||
|
private void initOrder(Date[] dates, OrderOverviewVO orderOverviewVO, StatisticsQueryParam statisticsQueryParam) {
|
||||||
|
//构建查询条件
|
||||||
|
QueryWrapper queryWrapper = Wrappers.query();
|
||||||
|
//时间区间
|
||||||
|
queryWrapper.between("create_time", dates[0], dates[1]);
|
||||||
|
//如果有店铺id传入,则查询店铺
|
||||||
|
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
||||||
|
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
||||||
|
}
|
||||||
|
//查询流水金额和订单数量
|
||||||
|
queryWrapper.select("SUM(flow_price) AS price , COUNT(0) AS num");
|
||||||
|
//获取查询结果
|
||||||
|
Map order = this.getMap(queryWrapper);
|
||||||
|
//赋予订单数和流水金额
|
||||||
|
orderOverviewVO.setOrderNum(order != null && order.containsKey("num") ? (Long) order.get("num") : 0L);
|
||||||
|
orderOverviewVO.setOrderAmount(order != null && order.containsKey("price") ? (double) order.get("price") : 0L);
|
||||||
|
|
||||||
|
//查询下单人数
|
||||||
|
queryWrapper = Wrappers.query();
|
||||||
|
//时间区间
|
||||||
|
queryWrapper.between("create_time", dates[0], dates[1]);
|
||||||
|
//如果有店铺id传入,则查询店铺
|
||||||
|
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
||||||
|
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
||||||
|
}
|
||||||
|
//查询下单人数的sql
|
||||||
|
queryWrapper.select("count(DISTINCT member_id) AS num");
|
||||||
|
//获取查询结果
|
||||||
|
Map memberNum = this.getMap(queryWrapper);
|
||||||
|
//写入下单人数
|
||||||
|
orderOverviewVO.setOrderMemberNum(memberNum != null && memberNum.containsKey("num") ? (Long) memberNum.get("num") : 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单统计-付款属性填充
|
||||||
|
*
|
||||||
|
* @param dates
|
||||||
|
* @param orderOverviewVO
|
||||||
|
*/
|
||||||
|
private void initPayment(Date[] dates, OrderOverviewVO orderOverviewVO, StatisticsQueryParam statisticsQueryParam) {
|
||||||
|
//付款订单数,付款金额
|
||||||
|
QueryWrapper queryWrapper = Wrappers.query();
|
||||||
|
queryWrapper.between("create_time", dates[0], dates[1]);
|
||||||
|
//如果有店铺id传入,则查询店铺
|
||||||
|
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
||||||
|
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
||||||
|
}
|
||||||
|
queryWrapper.select("SUM(final_price) AS price , COUNT(0) AS num");
|
||||||
|
queryWrapper.eq("flow_type", FlowTypeEnum.PAY.name());
|
||||||
|
Map payment = this.getMap(queryWrapper);
|
||||||
|
|
||||||
|
orderOverviewVO.setPaymentOrderNum(payment != null && payment.containsKey("num") ? (Long) payment.get("num") : 0L);
|
||||||
|
orderOverviewVO.setPaymentAmount(payment != null && payment.containsKey("price") ? (Double) payment.get("price") : 0D);
|
||||||
|
|
||||||
|
//付款人数
|
||||||
|
queryWrapper = Wrappers.query();
|
||||||
|
queryWrapper.between("create_time", dates[0], dates[1]);
|
||||||
|
//如果有店铺id传入,则查询店铺
|
||||||
|
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
||||||
|
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
||||||
|
}
|
||||||
|
queryWrapper.select("COUNT(0) AS num");
|
||||||
|
queryWrapper.groupBy("member_id");
|
||||||
|
Map paymentMemberNum = this.getMap(queryWrapper);
|
||||||
|
|
||||||
|
orderOverviewVO.setPaymentsNum(paymentMemberNum != null && paymentMemberNum.containsKey("num") ? (Long) paymentMemberNum.get("num") : 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单统计-付款属性填充
|
||||||
|
*
|
||||||
|
* @param dates
|
||||||
|
* @param orderOverviewVO
|
||||||
|
*/
|
||||||
|
private void initAfterSale(Date[] dates, OrderOverviewVO orderOverviewVO, StatisticsQueryParam statisticsQueryParam) {
|
||||||
|
//付款订单数,付款金额
|
||||||
|
QueryWrapper queryWrapper = Wrappers.query();
|
||||||
|
queryWrapper.between("create_time", dates[0], dates[1]);
|
||||||
|
queryWrapper.select("SUM(final_price) AS price , COUNT(0) AS num");
|
||||||
|
//如果有店铺id传入,则查询店铺
|
||||||
|
if (StringUtils.isNotEmpty(statisticsQueryParam.getStoreId())) {
|
||||||
|
queryWrapper.eq("store_id", statisticsQueryParam.getStoreId());
|
||||||
|
}
|
||||||
|
queryWrapper.eq("flow_type", FlowTypeEnum.REFUND.name());
|
||||||
|
Map payment = this.getMap(queryWrapper);
|
||||||
|
orderOverviewVO.setRefundOrderNum(payment != null && payment.containsKey("num") ? (Long) payment.get("num") : 0L);
|
||||||
|
orderOverviewVO.setRefundOrderPrice(payment != null && payment.containsKey("price") ? (Double) payment.get("price") : 0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 组织查询条件
|
* 组织查询条件
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user