Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
张松
2025-11-24 15:30:11 +08:00
5 changed files with 41 additions and 35 deletions

View File

@@ -78,19 +78,21 @@ public class ShopProdStatistic implements Serializable {
* @return true=有效false=无效 * @return true=有效false=无效
*/ */
public boolean isValid() { public boolean isValid() {
// 1. 校验所有字段是否为 null // 定义一个方法统一校验“字段非空且大于0”
if (saleCount == null || saleAmount == null || refundCount == null || refundAmount == null) { // 避免重复代码,提高可读性
return false; return isPositive(saleCount) ||
} isPositive(saleAmount) ||
// 2. 校验所有字段是否大于 0BigDecimal 需用 compareTo 比较,不能直接用 > isPositive(refundCount) ||
if (saleCount.compareTo(BigDecimal.ZERO) <= 0 || isPositive(refundAmount);
saleAmount.compareTo(BigDecimal.ZERO) <= 0 ||
refundCount.compareTo(BigDecimal.ZERO) <= 0 ||
refundAmount.compareTo(BigDecimal.ZERO) <= 0) {
return false;
}
// 3. 所有条件满足,返回 true
return true;
} }
/**
* 校验 BigDecimal 字段是否非空且大于0
* @param value 待校验字段
* @return true=非空且大于0false=否则
*/
private boolean isPositive(BigDecimal value) {
// 先判断是否非空,再用 compareTo 比较是否大于0compareTo 返回 >0 表示当前值大)
return value != null && value.compareTo(BigDecimal.ZERO) > 0;
}
} }

View File

@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@@ -42,8 +43,8 @@ public class CountPayTypeVo {
/** /**
* 合并实时数据和历史统计数据 * 合并实时数据和历史统计数据
*/ */
public static List<CountPayTypeVo> mergePayTypeData(Map<String, Integer> realTimeData, public static List<CountPayTypeVo> mergePayTypeData(Map<String, BigDecimal> realTimeData,
Map<String, Integer> historyData) { Map<String, BigDecimal> historyData) {
List<CountPayTypeVo> result = new ArrayList<>(); List<CountPayTypeVo> result = new ArrayList<>();
@@ -51,13 +52,13 @@ public class CountPayTypeVo {
String payCode = entry.getKey(); String payCode = entry.getKey();
String payName = entry.getValue(); String payName = entry.getValue();
Integer realTimeCount = getSafeValue(realTimeData, payCode); BigDecimal realTimeCount = getSafeValue(realTimeData, payCode);
Integer historyCount = getSafeValue(historyData, payCode); BigDecimal historyCount = getSafeValue(historyData, payCode);
int totalCount = (realTimeCount != null ? realTimeCount : 0) BigDecimal totalCount = (realTimeCount != null ? realTimeCount : BigDecimal.ZERO)
+ (historyCount != null ? historyCount : 0); .add(historyCount != null ? historyCount : BigDecimal.ZERO);
result.add(new CountPayTypeVo(totalCount, payName)); result.add(new CountPayTypeVo(totalCount.intValue(), payName));
} }
@@ -67,7 +68,7 @@ public class CountPayTypeVo {
/** /**
* 安全获取Map中的值处理null情况 * 安全获取Map中的值处理null情况
*/ */
private static Integer getSafeValue(Map<String, Integer> data, String key) { private static BigDecimal getSafeValue(Map<String, BigDecimal> data, String key) {
if (data == null || data.isEmpty()) { if (data == null || data.isEmpty()) {
return null; return null;
} }

View File

@@ -119,7 +119,7 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
" shop_id = #{shopId} " + " shop_id = #{shopId} " +
"and trade_day = #{tradeDay} " + "and trade_day = #{tradeDay} " +
"and paid_time is not null ") "and paid_time is not null ")
Map<String, Integer> getOnlinePayTypeDate(Long shopId, LocalDate tradeDay); Map<String, BigDecimal> getOnlinePayTypeDate(Long shopId, LocalDate tradeDay);
/** /**
* 订单支付方式统计 按日期范围查询 * 订单支付方式统计 按日期范围查询
@@ -136,7 +136,7 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
" WHERE shop_id = #{shopId} " + " WHERE shop_id = #{shopId} " +
" AND statistic_date >= #{start} " + " AND statistic_date >= #{start} " +
" AND statistic_date <= #{end} ") " AND statistic_date <= #{end} ")
Map<String, Integer> getPayTypeDateRangeRaw(Long shopId, LocalDate start, LocalDate end); Map<String, BigDecimal> getPayTypeDateRangeRaw(Long shopId, LocalDate start, LocalDate end);
//*********************以下为日常统计******************************************************************************** //*********************以下为日常统计********************************************************************************

View File

@@ -1,9 +1,7 @@
package com.czg.service.order.service.impl; package com.czg.service.order.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
@@ -20,27 +18,29 @@ import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
import com.czg.exception.PaySuccessException; import com.czg.exception.PaySuccessException;
import com.czg.market.dto.MemberOrderDTO; import com.czg.market.dto.MemberOrderDTO;
import com.czg.market.entity.MemberOrder;
import com.czg.market.entity.MkShopCouponRecord; import com.czg.market.entity.MkShopCouponRecord;
import com.czg.market.entity.MkShopRecharge;
import com.czg.market.entity.MkShopRechargeDetail; import com.czg.market.entity.MkShopRechargeDetail;
import com.czg.market.service.*; import com.czg.market.service.*;
import com.czg.market.vo.MkShopRechargeVO; import com.czg.market.vo.MkShopRechargeVO;
import com.czg.order.dto.BigDecimalDTO;
import com.czg.order.dto.CheckOrderPay; import com.czg.order.dto.CheckOrderPay;
import com.czg.order.dto.OrderInfoRefundDTO; import com.czg.order.dto.OrderInfoRefundDTO;
import com.czg.market.entity.MemberOrder;
import com.czg.order.entity.OrderDetail; import com.czg.order.entity.OrderDetail;
import com.czg.order.entity.OrderInfo; import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment; import com.czg.order.entity.OrderPayment;
import com.czg.order.enums.PayEnums; import com.czg.order.enums.PayEnums;
import com.czg.order.service.*; import com.czg.order.service.CreditBuyerOrderService;
import com.czg.order.service.OrderDetailService;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
import com.czg.resp.CzgRespCode; import com.czg.resp.CzgRespCode;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.service.CzgPayService; import com.czg.service.CzgPayService;
import com.czg.service.RedisService; import com.czg.service.RedisService;
import com.czg.service.market.service.impl.MemberOrderServiceImpl; import com.czg.service.order.dto.OrderPayParamDTO;
import com.czg.service.order.dto.*; import com.czg.service.order.dto.VipMemberPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO;
import com.czg.service.order.dto.VipRefundDTO;
import com.czg.service.order.enums.OrderStatusEnums; import com.czg.service.order.enums.OrderStatusEnums;
import com.czg.service.order.mapper.OrderPaymentMapper; import com.czg.service.order.mapper.OrderPaymentMapper;
import com.czg.service.order.service.PayService; import com.czg.service.order.service.PayService;
@@ -707,6 +707,7 @@ public class PayServiceImpl implements PayService {
if (returnNum.compareTo(BigDecimal.ZERO) <= 0 || returnNum.compareTo(refundDetail.getNum()) < 0) { if (returnNum.compareTo(BigDecimal.ZERO) <= 0 || returnNum.compareTo(refundDetail.getNum()) < 0) {
throw new CzgException("退单失败," + orderDetail.getProductName() + "可退数量不足"); throw new CzgException("退单失败," + orderDetail.getProductName() + "可退数量不足");
} }
refundDetail.setReturnAmount(refundDetail.getNum().multiply(orderDetail.getUnitPrice()).setScale(2, RoundingMode.UP));
if (isPay) { if (isPay) {
orderDetail.setRefundNum(orderDetail.getRefundNum().add(refNum)); orderDetail.setRefundNum(orderDetail.getRefundNum().add(refNum));
if (orderDetail.getNum().compareTo(orderDetail.getRefundNum().add(orderDetail.getReturnNum())) == 0) { if (orderDetail.getNum().compareTo(orderDetail.getRefundNum().add(orderDetail.getReturnNum())) == 0) {
@@ -722,12 +723,12 @@ public class PayServiceImpl implements PayService {
} }
orderDetail.setRefundNo(refPayOrderNo); orderDetail.setRefundNo(refPayOrderNo);
orderDetail.setRefundRemark(orderDetail.getRefundRemark() + param.getRefundReason()); orderDetail.setRefundRemark(orderDetail.getRefundRemark() + param.getRefundReason());
if (isPay) { // if (isPay) {
orderDetail.setReturnAmount(refundDetail.getReturnAmount().add(refundDetail.getReturnAmount())); orderDetail.setReturnAmount(orderDetail.getReturnAmount().add(refundDetail.getReturnAmount()));
if (orderDetail.getReturnAmount().compareTo(orderDetail.getPayAmount()) > 0) { if (orderDetail.getReturnAmount().compareTo(orderDetail.getPayAmount()) > 0) {
orderDetail.setReturnAmount(orderDetail.getPayAmount()); orderDetail.setReturnAmount(orderDetail.getPayAmount());
} }
} // }
orderDetailService.updateById(orderDetail); orderDetailService.updateById(orderDetail);
if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) { if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) {
returnProMap.put(Convert.toStr(orderDetail.getProductId()), refundDetail.getNum()); returnProMap.put(Convert.toStr(orderDetail.getProductId()), refundDetail.getNum());

View File

@@ -6,6 +6,8 @@
<select id="selectProStatByDay" resultType="com.czg.order.entity.ShopProdStatistic"> <select id="selectProStatByDay" resultType="com.czg.order.entity.ShopProdStatistic">
SELECT SELECT
#{shopId} as shopId,
#{day} as createDay,
CASE WHEN detail.is_temporary = 1 THEN -1 ELSE detail.product_id END AS prodId, CASE WHEN detail.is_temporary = 1 THEN -1 ELSE detail.product_id END AS prodId,
CASE WHEN detail.is_temporary = 1 THEN '临时菜' ELSE prod.name END AS productName, CASE WHEN detail.is_temporary = 1 THEN '临时菜' ELSE prod.name END AS productName,
sum(detail.num-detail.return_num) as saleCount, sum(detail.num-detail.return_num) as saleCount,