Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f85ac0815b | |||
| 80fb367673 | |||
| 574c73d0b5 | |||
| cb18aa5670 | |||
| da3447cd0b | |||
| 9e946443ec | |||
| 71ffdede19 | |||
| 353404dde4 |
@@ -3,16 +3,16 @@ package com.czg.controller;
|
|||||||
import com.czg.annotation.Debounce;
|
import com.czg.annotation.Debounce;
|
||||||
import com.czg.order.dto.MkDistributionPayDTO;
|
import com.czg.order.dto.MkDistributionPayDTO;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
import com.czg.sa.StpKit;
|
|
||||||
import com.czg.service.order.service.DistributionPayService;
|
import com.czg.service.order.service.DistributionPayService;
|
||||||
import com.czg.system.service.SysParamsService;
|
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import com.czg.utils.ServletUtil;
|
import com.czg.utils.ServletUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -27,16 +27,6 @@ import java.util.Map;
|
|||||||
public class DistributionPayController {
|
public class DistributionPayController {
|
||||||
@Resource
|
@Resource
|
||||||
private DistributionPayService payService;
|
private DistributionPayService payService;
|
||||||
@DubboReference
|
|
||||||
private SysParamsService paramsService;
|
|
||||||
|
|
||||||
|
|
||||||
// @PostMapping("/cashPay")
|
|
||||||
// @Debounce(value = "#payParam.checkOrderPay.orderId")
|
|
||||||
// public CzgResult<Object> cashPayOrder(@RequestHeader Long shopId, @Validated @RequestBody MkDistributionPayDTO payParam) {
|
|
||||||
// payParam.setShopId(shopId);
|
|
||||||
// return payService.cashPayOrder(payParam);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序支付
|
* 小程序支付
|
||||||
@@ -60,26 +50,4 @@ public class DistributionPayController {
|
|||||||
AssertUtil.isBlank(payParam.getCode(), "微信code不为空");
|
AssertUtil.isBlank(payParam.getCode(), "微信code不为空");
|
||||||
return CzgResult.success(payService.mchRecharge(ServletUtil.getClientIP(request), payParam));
|
return CzgResult.success(payService.mchRecharge(ServletUtil.getClientIP(request), payParam));
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 正扫
|
|
||||||
// */
|
|
||||||
// @PostMapping("/scanPay")
|
|
||||||
// @Debounce(value = "#payParam.checkOrderPay.orderId")
|
|
||||||
// public CzgResult<Map<String, Object>> scanPayOrder(@RequestHeader Long shopId, HttpServletRequest request, @Validated @RequestBody MkDistributionPayDTO payParam) {
|
|
||||||
// payParam.setShopId(shopId);
|
|
||||||
// return payService.scanPayOrder(ServletUtil.getClientIP(request), payParam);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 反扫
|
|
||||||
// * authCode 必填 扫描码
|
|
||||||
// */
|
|
||||||
// @PostMapping("/microPay")
|
|
||||||
// @Debounce(value = "#payParam.checkOrderPay.orderId")
|
|
||||||
// public CzgResult<Map<String, Object>> microPayOrder(@RequestHeader Long shopId, @Validated @RequestBody MkDistributionPayDTO payParam) {
|
|
||||||
// payParam.setShopId(shopId);
|
|
||||||
// return payService.microPayOrder(payParam);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.czg.market.service;
|
package com.czg.market.service;
|
||||||
|
|
||||||
import com.czg.enums.ShopUserFlowBizEnum;
|
import com.czg.enums.ShopUserFlowBizEnum;
|
||||||
|
import com.czg.exception.CzgException;
|
||||||
import com.czg.market.dto.MkShopRechargeDTO;
|
import com.czg.market.dto.MkShopRechargeDTO;
|
||||||
import com.czg.market.vo.MkShopRechargeShopListVO;
|
import com.czg.market.vo.MkShopRechargeShopListVO;
|
||||||
import com.czg.market.vo.MkShopRechargeVO;
|
import com.czg.market.vo.MkShopRechargeVO;
|
||||||
@@ -21,7 +22,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface MkShopRechargeService extends IService<MkShopRecharge> {
|
public interface MkShopRechargeService extends IService<MkShopRecharge> {
|
||||||
|
|
||||||
MkShopRechargeVO detail(Long shopId);
|
MkShopRechargeVO detail(Long shopId) throws CzgException;
|
||||||
|
|
||||||
MkShopRechargeVO detailApp(Long shopId);
|
MkShopRechargeVO detailApp(Long shopId);
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class OrderPayment implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String tradeNumber;
|
private String tradeNumber;
|
||||||
|
|
||||||
@Column(onUpdateValue = "now()")
|
// @Column(onUpdateValue = "now()")
|
||||||
private LocalDateTime payTime;
|
private LocalDateTime payTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
@Override
|
@Override
|
||||||
@CacheEvict(key = "#shopInfoEditDTO.id")
|
@CacheEvict(key = "#shopInfoEditDTO.id")
|
||||||
public Boolean edit(ShopInfoEditDTO shopInfoEditDTO) {
|
public Boolean edit(ShopInfoEditDTO shopInfoEditDTO) {
|
||||||
|
shopInfoEditDTO.setIsMemberPrice(null);
|
||||||
ShopInfo shopInfo;
|
ShopInfo shopInfo;
|
||||||
if (!StpKit.USER.isAdmin()) {
|
if (!StpKit.USER.isAdmin()) {
|
||||||
shopInfo = queryChain().eq(ShopInfo::getId, StpKit.USER.getShopId()).one();
|
shopInfo = queryChain().eq(ShopInfo::getId, StpKit.USER.getShopId()).one();
|
||||||
@@ -319,8 +320,6 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
rabbitPublisher.sendOrderDetailStatusMsg(shopInfo.getId().toString(), "shopInfoUpdate");
|
rabbitPublisher.sendOrderDetailStatusMsg(shopInfo.getId().toString(), "shopInfoUpdate");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@
|
|||||||
<if test="amount != null">
|
<if test="amount != null">
|
||||||
AND a.amount >= #{amount}
|
AND a.amount >= #{amount}
|
||||||
</if>
|
</if>
|
||||||
|
group by a.id
|
||||||
ORDER BY a.create_time DESC
|
ORDER BY a.create_time DESC
|
||||||
</select>
|
</select>
|
||||||
<select id="selectVipCard_COUNT" resultType="java.lang.Long">
|
<select id="selectVipCard_COUNT" resultType="java.lang.Long">
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import com.czg.market.vo.InviteUserVO;
|
|||||||
import com.czg.market.vo.MkDistributionConfigVO;
|
import com.czg.market.vo.MkDistributionConfigVO;
|
||||||
import com.czg.order.dto.MkDistributionPayDTO;
|
import com.czg.order.dto.MkDistributionPayDTO;
|
||||||
import com.czg.order.entity.OrderInfo;
|
import com.czg.order.entity.OrderInfo;
|
||||||
import com.czg.market.service.OrderInfoService;
|
|
||||||
import com.czg.order.service.OrderPaymentService;
|
|
||||||
import com.czg.sa.StpKit;
|
import com.czg.sa.StpKit;
|
||||||
import com.czg.service.market.enums.OrderStatusEnums;
|
import com.czg.service.market.enums.OrderStatusEnums;
|
||||||
import com.czg.service.market.mapper.MkDistributionUserMapper;
|
import com.czg.service.market.mapper.MkDistributionUserMapper;
|
||||||
@@ -685,22 +683,15 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||||||
.ne(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.REFUND.getCode()));
|
.ne(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.REFUND.getCode()));
|
||||||
|
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
MkDistributionFlow refundFlow = BeanUtil.copyProperties(item, MkDistributionFlow.class);
|
|
||||||
refundFlow.setStatus(TableValueConstant.DistributionFlow.Status.REFUND.getCode());
|
|
||||||
refundFlow.setSourceId(item.getId());
|
|
||||||
refundFlow.setId(null);
|
|
||||||
refundFlow.setCreateTime(DateUtil.date().toLocalDateTime());
|
|
||||||
refundFlow.setUpdateTime(DateUtil.date().toLocalDateTime());
|
|
||||||
if (TableValueConstant.DistributionFlow.Status.PENDING.getCode().equals(item.getStatus())) {
|
if (TableValueConstant.DistributionFlow.Status.PENDING.getCode().equals(item.getStatus())) {
|
||||||
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
item.setStatus(TableValueConstant.DistributionFlow.Status.REFUND.getCode());
|
||||||
// updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
|
|
||||||
distributionFlowService.updateById(item);
|
distributionFlowService.updateById(item);
|
||||||
|
mapper.updateIncome(item.getRewardAmount().negate(), null, null, item.getDistributionUserId(), item.getShopId());
|
||||||
} else {
|
} else {
|
||||||
// 执行扣款
|
// 执行扣款
|
||||||
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
|
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
|
||||||
updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), orderId, TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退");
|
updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), orderId, TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退");
|
||||||
}
|
}
|
||||||
distributionFlowService.save(refundFlow);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,6 +729,13 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||||||
distributionDeliverService.save(deliver);
|
distributionDeliverService.save(deliver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分销金额修改
|
||||||
|
*
|
||||||
|
* @param pendingIncome 待入账金额
|
||||||
|
* @param receivedIncome 已入账
|
||||||
|
* @param withdrawIncome 已提现
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopUserId, Long shopId, Integer isOne) {
|
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopUserId, Long shopId, Integer isOne) {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MkShopRechargeVO detail(Long shopId) {
|
public MkShopRechargeVO detail(Long shopId) throws CzgException{
|
||||||
shopId = shopInfoService.getMainIdByShopId(shopId);
|
shopId = shopInfoService.getMainIdByShopId(shopId);
|
||||||
ShopInfo shopInfo = shopInfoService.getById(shopId);
|
ShopInfo shopInfo = shopInfoService.getById(shopId);
|
||||||
if (shopInfo.getMainId() != null) {
|
if (shopInfo.getMainId() != null) {
|
||||||
|
|||||||
@@ -45,36 +45,33 @@
|
|||||||
order by a.create_time desc
|
order by a.create_time desc
|
||||||
</select>
|
</select>
|
||||||
<select id="totalAmount" resultType="java.math.BigDecimal">
|
<select id="totalAmount" resultType="java.math.BigDecimal">
|
||||||
select sum(a.amount) from mk_distribution_flow as a
|
select sum(a.reward_amount)
|
||||||
left join mk_distribution_user as d on d.id=a.distribution_user_id
|
from mk_distribution_flow as a
|
||||||
left join tb_shop_user as b on a.shop_user_id=b.id
|
left join tb_shop_user as b on a.shop_user_id = b.id
|
||||||
left join tb_shop_user as c on c.id=a.shop_user_id
|
|
||||||
where a.shop_id=#{shopId}
|
where a.shop_id=#{shopId}
|
||||||
|
<if test="id != null">
|
||||||
|
and a.shop_user_id=#{id}
|
||||||
|
</if>
|
||||||
|
<if test="userId != null">
|
||||||
|
and a.user_id=#{userId}
|
||||||
|
</if>
|
||||||
|
<if test="status != null and status != ''">
|
||||||
|
and a.status=#{status}
|
||||||
|
</if>
|
||||||
|
<if test="type != null and type != ''">
|
||||||
|
and a.type=#{type}
|
||||||
|
</if>
|
||||||
<if test="startTime != null">
|
<if test="startTime != null">
|
||||||
and a.create_time>=#{startTime}
|
and a.create_time>=#{startTime}
|
||||||
</if>
|
</if>
|
||||||
<if test="endTime != null">
|
<if test="endTime != null">
|
||||||
and a.create_time<=#{endTime}
|
and a.create_time<=#{endTime}
|
||||||
</if>
|
</if>
|
||||||
<if test="status != null and status != ''">
|
|
||||||
and a.status=#{status}
|
|
||||||
</if>
|
|
||||||
<if test="key != null and key != ''">
|
<if test="key != null and key != ''">
|
||||||
and (
|
and (
|
||||||
b.nick_name like concat('%',#{key},'%')
|
b.nick_name like concat('%',#{key},'%')
|
||||||
or b.id like concat('%',#{key},'%')
|
or b.id like concat('%',#{key},'%')
|
||||||
or c.id like concat('%',#{key},'%')
|
|
||||||
or c.nick_name like concat('%',#{key},'%')
|
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
<if test="id != null">
|
|
||||||
and d.id=#{id}
|
|
||||||
</if>
|
|
||||||
<if test="type != null and type != ''">
|
|
||||||
and a.type=#{type}
|
|
||||||
</if>
|
|
||||||
<if test="userId != null">
|
|
||||||
and d.user_id=#{userId}
|
|
||||||
</if>
|
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -5,16 +5,24 @@
|
|||||||
<mapper namespace="com.czg.service.market.mapper.MkDistributionUserMapper">
|
<mapper namespace="com.czg.service.market.mapper.MkDistributionUserMapper">
|
||||||
<update id="updateIncome">
|
<update id="updateIncome">
|
||||||
update mk_distribution_user
|
update mk_distribution_user
|
||||||
set
|
<set>
|
||||||
<if test="pendingIncome != null">
|
<if test="pendingIncome != null">
|
||||||
total_income = total_income + #{pendingIncome},
|
total_income = total_income + #{pendingIncome},
|
||||||
</if>
|
</if>
|
||||||
<if test="receivedIncome != null">
|
<if test="receivedIncome != null">
|
||||||
total_income = total_income + #{receivedIncome},
|
total_income = total_income + #{receivedIncome},
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
|
<if test="pendingIncome != null">
|
||||||
pending_income = pending_income + #{pendingIncome},
|
pending_income = pending_income + #{pendingIncome},
|
||||||
|
</if>
|
||||||
|
<if test="receivedIncome != null">
|
||||||
received_income = received_income + #{receivedIncome},
|
received_income = received_income + #{receivedIncome},
|
||||||
|
</if>
|
||||||
|
<if test="withdrawIncome != null">
|
||||||
withdrawn_income = withdrawn_income + #{withdrawIncome}
|
withdrawn_income = withdrawn_income + #{withdrawIncome}
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
where id = #{id} and shop_id = #{shopId}
|
where id = #{id} and shop_id = #{shopId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
|
|||||||
" `order`.shop_id = #{shopId} " +
|
" `order`.shop_id = #{shopId} " +
|
||||||
" and trade_day = #{tradeDay} " +
|
" and trade_day = #{tradeDay} " +
|
||||||
" and paid_time is not null" +
|
" and paid_time is not null" +
|
||||||
" order by detail.product_id, detail.sku_id")
|
" group by detail.product_id, detail.sku_id")
|
||||||
List<ProductCostAmountVO> getOrderDetailProduct(Long shopId, LocalDate tradeDay);
|
List<ProductCostAmountVO> getOrderDetailProduct(Long shopId, LocalDate tradeDay);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -688,10 +688,7 @@ public class PayServiceImpl implements PayService {
|
|||||||
if (orderInfo.getStatus().equals(OrderStatusEnums.CANCELLED.getCode())) {
|
if (orderInfo.getStatus().equals(OrderStatusEnums.CANCELLED.getCode())) {
|
||||||
throw new CzgException("订单已过期不可退单");
|
throw new CzgException("订单已过期不可退单");
|
||||||
}
|
}
|
||||||
boolean isFirstRefund = true;
|
boolean isFirstRefund = orderInfo.getRefundAmount().compareTo(BigDecimal.ZERO) == 0;
|
||||||
if (orderInfo.getRefundAmount().compareTo(BigDecimal.ZERO) != 0) {
|
|
||||||
isFirstRefund = false;
|
|
||||||
}
|
|
||||||
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
|
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
|
||||||
Map<String, BigDecimal> returnProMap = new HashMap<>();
|
Map<String, BigDecimal> returnProMap = new HashMap<>();
|
||||||
boolean isPay = true;
|
boolean isPay = true;
|
||||||
@@ -821,8 +818,8 @@ public class PayServiceImpl implements PayService {
|
|||||||
if (!returnProMap.isEmpty()) {
|
if (!returnProMap.isEmpty()) {
|
||||||
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));
|
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));
|
||||||
}
|
}
|
||||||
refundOrderAfter(orderInfo.getId(), orderInfo.getShopId(), orderInfo.getUserId(), orderInfo.getOrderNo(),
|
FunUtils.asyncSafeRunVoid(() -> refundOrderAfter(orderInfo.getId(), orderInfo.getShopId(), orderInfo.getUserId(), orderInfo.getOrderNo(),
|
||||||
orderInfo.getPointsNum(), isFirstRefund, orderInfo.getStatus().equals(OrderStatusEnums.REFUND.getCode()));
|
orderInfo.getPointsNum(), isFirstRefund, orderInfo.getStatus().equals(OrderStatusEnums.REFUND.getCode())));
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -867,12 +864,11 @@ public class PayServiceImpl implements PayService {
|
|||||||
}
|
}
|
||||||
throw new CzgException(refund.getMsg());
|
throw new CzgException(refund.getMsg());
|
||||||
} else {
|
} else {
|
||||||
paymentService.updateChain()
|
OrderPayment uOrderPayment = new OrderPayment();
|
||||||
.eq(OrderPayment::getId, refundId)
|
uOrderPayment.setPayTime(LocalDateTime.now());
|
||||||
.set(OrderPayment::getPayTime, refund.getData().getRefundTime())
|
uOrderPayment.setTradeNumber(refund.getData().getRefundOrderId());
|
||||||
.set(OrderPayment::getTradeNumber, refund.getData().getRefundOrderId())
|
uOrderPayment.setRespJson(JSONObject.toJSONString(refund.getData()));
|
||||||
.set(OrderPayment::getRespJson, JSONObject.toJSONString(refund.getData()))
|
paymentService.update(uOrderPayment, QueryWrapper.create().eq(OrderPayment::getId, refundId));
|
||||||
.update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
|
|||||||
*/
|
*/
|
||||||
private BigDecimal getProductCostAmount(Long shopId, LocalDate day) {
|
private BigDecimal getProductCostAmount(Long shopId, LocalDate day) {
|
||||||
BigDecimal productCostAmount = BigDecimal.ZERO;
|
BigDecimal productCostAmount = BigDecimal.ZERO;
|
||||||
////获取orderDetail信息 productId skuId 数量
|
//获取orderDetail信息 productId skuId 数量
|
||||||
List<ProductCostAmountVO> orderDetailProduct = mapper.getOrderDetailProduct(shopId, day);
|
List<ProductCostAmountVO> orderDetailProduct = mapper.getOrderDetailProduct(shopId, day);
|
||||||
orderDetailProduct = orderDetailProduct.stream()
|
orderDetailProduct = orderDetailProduct.stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -167,44 +164,99 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
|
|||||||
* @return 合并后的数据
|
* @return 合并后的数据
|
||||||
*/
|
*/
|
||||||
private List<ShopProdStatistic> mergeProdStatistic(List<ShopProdStatistic> realTimeDataByDay, List<ShopProdStatistic> dateRange) {
|
private List<ShopProdStatistic> mergeProdStatistic(List<ShopProdStatistic> realTimeDataByDay, List<ShopProdStatistic> dateRange) {
|
||||||
if (realTimeDataByDay == null) {
|
// 1. 使用防御性编程,确保非空列表
|
||||||
realTimeDataByDay = new ArrayList<>();
|
List<ShopProdStatistic> realTimeData = Optional.ofNullable(realTimeDataByDay).orElseGet(ArrayList::new);
|
||||||
}
|
List<ShopProdStatistic> rangeData = Optional.ofNullable(dateRange).orElseGet(ArrayList::new);
|
||||||
if (dateRange == null) {
|
|
||||||
dateRange = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Stream.concat(realTimeDataByDay.stream(), dateRange.stream())
|
calculateValidData(realTimeData);
|
||||||
|
calculateValidData(rangeData);
|
||||||
|
|
||||||
|
return Stream.concat(realTimeData.stream(), rangeData.stream())
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toMap(
|
.collect(Collectors.toMap(
|
||||||
ShopProdStatistic::getProdId,
|
ShopProdStatistic::getProdId,
|
||||||
Function.identity(),
|
Function.identity(),
|
||||||
(stat1, stat2) -> {
|
this::mergeStatistics
|
||||||
// 创建合并后的对象
|
|
||||||
ShopProdStatistic merged = new ShopProdStatistic();
|
|
||||||
merged.setId(stat1.getId());
|
|
||||||
merged.setShopId(stat1.getShopId());
|
|
||||||
merged.setProdId(stat1.getProdId());
|
|
||||||
merged.setProductName(stat1.getProductName());
|
|
||||||
|
|
||||||
// 安全处理BigDecimal相加,处理null值
|
|
||||||
merged.setSaleCount(safeAdd(stat1.getSaleCount(), stat2.getSaleCount()));
|
|
||||||
merged.setSaleAmount(safeAdd(stat1.getSaleAmount(), stat2.getSaleAmount()));
|
|
||||||
merged.setRefundCount(safeAdd(stat1.getRefundCount(), stat2.getRefundCount()));
|
|
||||||
merged.setRefundAmount(safeAdd(stat1.getRefundAmount(), stat2.getRefundAmount()));
|
|
||||||
|
|
||||||
return merged;
|
|
||||||
}
|
|
||||||
))
|
))
|
||||||
.values()
|
.values()
|
||||||
.stream()
|
.stream()
|
||||||
|
.peek(this::recalculateValidData)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算有效销售数据
|
||||||
|
*/
|
||||||
|
private void calculateValidData(List<ShopProdStatistic> statistics) {
|
||||||
|
if (statistics == null || statistics.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
statistics.forEach(stat -> {
|
||||||
|
if (stat != null) {
|
||||||
|
stat.setValidSaleCount(safeSubtract(stat.getSaleCount(), stat.getRefundCount()));
|
||||||
|
stat.setValidSaleAmount(safeSubtract(stat.getValidSaleAmount(), stat.getRefundAmount()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并两个统计对象
|
||||||
|
*/
|
||||||
|
private ShopProdStatistic mergeStatistics(ShopProdStatistic stat1, ShopProdStatistic stat2) {
|
||||||
|
// 使用第一个非空对象作为基准
|
||||||
|
ShopProdStatistic baseStat = Optional.ofNullable(stat1).orElse(stat2);
|
||||||
|
ShopProdStatistic otherStat = stat1 == null ? null : stat2;
|
||||||
|
|
||||||
|
if (otherStat == null) {
|
||||||
|
return baseStat;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShopProdStatistic merged = new ShopProdStatistic();
|
||||||
|
|
||||||
|
// 设置基本信息(优先使用非空值)
|
||||||
|
merged.setId(baseStat.getId());
|
||||||
|
merged.setShopId(baseStat.getShopId());
|
||||||
|
merged.setProdId(baseStat.getProdId());
|
||||||
|
merged.setProductName(
|
||||||
|
Optional.ofNullable(baseStat.getProductName())
|
||||||
|
.orElse(otherStat.getProductName())
|
||||||
|
);
|
||||||
|
|
||||||
|
// 合并数值字段
|
||||||
|
merged.setSaleCount(safeAdd(baseStat.getSaleCount(), otherStat.getSaleCount()));
|
||||||
|
merged.setSaleAmount(safeAdd(baseStat.getSaleAmount(), otherStat.getSaleAmount()));
|
||||||
|
merged.setRefundCount(safeAdd(baseStat.getRefundCount(), otherStat.getRefundCount()));
|
||||||
|
merged.setRefundAmount(safeAdd(baseStat.getRefundAmount(), otherStat.getRefundAmount()));
|
||||||
|
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重新计算合并后的有效数据
|
||||||
|
*/
|
||||||
|
private void recalculateValidData(ShopProdStatistic stat) {
|
||||||
|
if (stat != null) {
|
||||||
|
stat.setValidSaleCount(safeSubtract(stat.getSaleCount(), stat.getRefundCount()));
|
||||||
|
stat.setValidSaleAmount(safeSubtract(stat.getSaleAmount(), stat.getRefundAmount()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全的BigDecimal加法(处理null值)
|
||||||
|
*/
|
||||||
private BigDecimal safeAdd(BigDecimal num1, BigDecimal num2) {
|
private BigDecimal safeAdd(BigDecimal num1, BigDecimal num2) {
|
||||||
BigDecimal safeNum1 = num1 != null ? num1 : BigDecimal.ZERO;
|
BigDecimal safeNum1 = Optional.ofNullable(num1).orElse(BigDecimal.ZERO);
|
||||||
BigDecimal safeNum2 = num2 != null ? num2 : BigDecimal.ZERO;
|
BigDecimal safeNum2 = Optional.ofNullable(num2).orElse(BigDecimal.ZERO);
|
||||||
return safeNum1.add(safeNum2);
|
return safeNum1.add(safeNum2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全的BigDecimal减法(处理null值)
|
||||||
|
*/
|
||||||
|
private BigDecimal safeSubtract(BigDecimal num1, BigDecimal num2) {
|
||||||
|
BigDecimal safeNum1 = Optional.ofNullable(num1).orElse(BigDecimal.ZERO);
|
||||||
|
BigDecimal safeNum2 = Optional.ofNullable(num2).orElse(BigDecimal.ZERO);
|
||||||
|
return safeNum1.subtract(safeNum2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user