From d2e9373d08edad3ebccbcf1831c2e809a693ae6a Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期三, 27 十一月 2024 13:49:31 +0800
Subject: [PATCH] 565-订单列表:增加用户账号搜索框
---
src/main/java/com/mzl/flower/service/impl/wallet/WalletServiceImpl.java | 107 ++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 76 insertions(+), 31 deletions(-)
diff --git a/src/main/java/com/mzl/flower/service/impl/wallet/WalletServiceImpl.java b/src/main/java/com/mzl/flower/service/impl/wallet/WalletServiceImpl.java
index 2f44539..0e784cd 100644
--- a/src/main/java/com/mzl/flower/service/impl/wallet/WalletServiceImpl.java
+++ b/src/main/java/com/mzl/flower/service/impl/wallet/WalletServiceImpl.java
@@ -2,9 +2,10 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mzl.flower.config.security.SecurityUtils;
+import com.mzl.flower.constant.LockConstants;
import com.mzl.flower.dto.request.wallet.QueryWalletAmountDTO;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
-import com.mzl.flower.entity.coupon.CouponTemplateDO;
+import com.mzl.flower.entity.supplier.Supplier;
import com.mzl.flower.entity.wallet.WalletDO;
import com.mzl.flower.enums.TrueOrFalseEnum;
import com.mzl.flower.mapper.wallet.WalletMapper;
@@ -13,13 +14,17 @@
import com.mzl.flower.service.wallet.WalletService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
/**
@@ -42,6 +47,8 @@
private static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
private static final Pattern dateTimeRegex = Pattern.compile("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");
+ @Autowired
+ RedissonClient redissonClient;
@Override
public String getWalletOnLineTime() {
@@ -64,47 +71,76 @@
// 查询的条件的deleted的字段得为0
// 下面的单独封装成一个方法
- WalletDO walletDO = getBySupplierId(currentSupplier.getId());
-
- if(null==walletDO){
- // 先创建一个钱包
- walletDO=new WalletDO();
- walletDO.setUserId(SecurityUtils.getUserId());
- walletDO.setSupplierId(currentSupplier.getId());
- walletDO.setTotalAmount(BigDecimal.ZERO);
- walletDO.setWithdrawableAmount(BigDecimal.ZERO);
- //把所有涉及BigDecimal的金额都设置为0
- walletDO.setWithdrawingAmount(BigDecimal.ZERO);
- walletDO.setWithdrawnAmount(BigDecimal.ZERO);
- walletDO.setSettlingAmount(BigDecimal.ZERO);
- walletDO.setTotalDeduction(BigDecimal.ZERO);
- walletDO.setTotalTransactionAmount(BigDecimal.ZERO);
- walletDO.setSettlingAmount(BigDecimal.ZERO);
- walletDO.create(SecurityUtils.getUserId());
- baseMapper.insert(walletDO);
- // 将再次查询的结果返回
- walletDO=getBySupplierId(currentSupplier.getId());
- }
-
+ WalletDO walletDO = getOrCreateBySupplierId(currentSupplier.getId());
return walletDO;
}
@Override
- public WalletDO getBySupplierId(Long supplierId) {
- // 不用getOne,用获取list的第一个元素
+ public WalletDO getOrCreateBySupplierId(Long supplierId) {
+
+ WalletDO walletDO=getBySupplierId(supplierId);
+ if(null==walletDO){
+ RLock lock = redissonClient.getLock(String.format(LockConstants.WALLET_SUPPLIER_ID_KEY, supplierId));
+ try {
+ if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
+ try {
+ walletDO=getBySupplierId(supplierId);
+ if(null!=walletDO) return walletDO;
+
+ final Supplier supplier = supplierService.getSupplierById(supplierId);
+
+ // 创建一个钱包
+ walletDO =new WalletDO();
+ walletDO.setUserId(supplier.getUserId());
+ walletDO.setSupplierId(supplierId);
+ walletDO.setTotalAmount(BigDecimal.ZERO);
+ walletDO.setWithdrawableAmount(BigDecimal.ZERO);
+ //把所有涉及BigDecimal的金额都设置为0
+ walletDO.setWithdrawingAmount(BigDecimal.ZERO);
+ walletDO.setWithdrawnAmount(BigDecimal.ZERO);
+ walletDO.setSettlingAmount(BigDecimal.ZERO);
+ walletDO.setTotalDeduction(BigDecimal.ZERO);
+ walletDO.setTotalTransactionAmount(BigDecimal.ZERO);
+ walletDO.setSettledAmount(BigDecimal.ZERO);
+ walletDO.create(SecurityUtils.getUserId());
+ baseMapper.insert(walletDO);
+ // 将再次查询的结果返回
+ walletDO= getBySupplierId(supplierId);
+ return walletDO;
+
+ } finally {
+ lock.unlock();
+ }
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+
+ return null;
+ }else{
+ return walletDO;
+ }
+ }
+
+ @Override
+ public WalletDO getBySupplierId(Long supplierId) {
List<WalletDO> walletDOS = baseMapper.selectList(new LambdaQueryWrapper<WalletDO>()
.eq(WalletDO::getDeleted, TrueOrFalseEnum.FALSE.isFlag())
.eq(WalletDO::getSupplierId, supplierId));
if(!CollectionUtils.isEmpty(walletDOS)){
return walletDOS.get(0);
- }else return null;
+ }
+ return null;
}
@Override
public BigDecimal getWaittingSettlementAmount(WalletDO walletDO) {
-
+ if(null!=walletDO && !StringUtils.isEmpty(walletDO.getSupplierId()) && StringUtils.isEmpty(walletDO.getUserId())){
+ final Supplier supplier = supplierService.getSupplierById(walletDO.getSupplierId());
+ walletDO.setUserId(supplier.getUserId());
+ }
return baseMapper.getWaittingSettlementAmount(walletDO);
}
@@ -128,15 +164,24 @@
queryWalletAmountDTO.setStartTime(getWalletOnLineTime());
queryWalletAmountDTO.setUserId(walletDO.getUserId());
- // 质检扣款
- BigDecimal checkDeduceAmount = walletReduceService.getCheckReduceAmount(queryWalletAmountDTO);
- checkDeduceAmount = checkDeduceAmount != null ? checkDeduceAmount : BigDecimal.ZERO;
+ // 质检扣款(缺货和补货)
+ BigDecimal checkReplaceLockAmount = walletReduceService.getCheckLackReplaceAmount(queryWalletAmountDTO);
+ checkReplaceLockAmount = checkReplaceLockAmount != null ? checkReplaceLockAmount : BigDecimal.ZERO;
+
+ // 质检扣款(降级)
+ BigDecimal checkReduceAmount = walletReduceService.getCheckReduceAmount(queryWalletAmountDTO);
+ checkReduceAmount = checkReduceAmount != null ? checkReduceAmount : BigDecimal.ZERO;
+
// 售后扣款
BigDecimal saleDeduceAmount = walletReduceService.getSaleReduceAmount(queryWalletAmountDTO);
saleDeduceAmount = saleDeduceAmount != null ? saleDeduceAmount : BigDecimal.ZERO;
+ // 集货站运费
+ BigDecimal stationFeeAmount = walletReduceService.getStationFeeAmount(queryWalletAmountDTO);
+ stationFeeAmount = stationFeeAmount != null ? stationFeeAmount : BigDecimal.ZERO;
+
// 总扣款
- BigDecimal deduceAmount = checkDeduceAmount.add(saleDeduceAmount);
+ BigDecimal deduceAmount = checkReplaceLockAmount.add(checkReduceAmount).add(saleDeduceAmount).add(stationFeeAmount);
return deduceAmount;
}
--
Gitblit v1.9.3