From 8720856b52c908354321d074959bd8b9edbc38b1 Mon Sep 17 00:00:00 2001 From: 陶杰 <1378534974@qq.com> Date: 星期二, 22 十月 2024 17:35:33 +0800 Subject: [PATCH] 1.查询时候如果钱包不存在则创建 --- src/main/java/com/mzl/flower/service/impl/wallet/WalletServiceImpl.java | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 53 insertions(+), 7 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 3a28344..0d6a144 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 @@ -1,13 +1,21 @@ package com.mzl.flower.service.impl.wallet; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.mzl.flower.config.security.SecurityUtils; +import com.mzl.flower.dto.response.supplier.SupplierDTO; import com.mzl.flower.entity.coupon.CouponTemplateDO; import com.mzl.flower.entity.wallet.WalletDO; import com.mzl.flower.enums.TrueOrFalseEnum; import com.mzl.flower.mapper.wallet.WalletMapper; +import com.mzl.flower.service.supplier.SupplierService; import com.mzl.flower.service.wallet.WalletService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; /** * <p> @@ -20,16 +28,54 @@ @Service public class WalletServiceImpl extends ServiceImpl<WalletMapper, WalletDO> implements WalletService { + @Autowired + private SupplierService supplierService; @Override - public WalletDO getBySupplierId(Long supplierId) { + public WalletDO getBySupplierId() { + final SupplierDTO currentSupplier = supplierService.getCurrentSupplier(); // 根据供应商ID获取钱包信息 - if (supplierId != null) { + // 查询的条件的deleted的字段得为0 - return getOne(new LambdaQueryWrapper<WalletDO>() - .eq(WalletDO::getDeleted, TrueOrFalseEnum.FALSE.isFlag()) - .eq(WalletDO::getSupplierId, supplierId)); - } - return null; + // 下面的单独封装成一个方法 + 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.create(SecurityUtils.getUserId()); + baseMapper.insert(walletDO); + // 将再次查询的结果返回 + walletDO=getBySupplierId(currentSupplier.getId()); + } + + + return walletDO; } + + + public WalletDO getBySupplierId(Long supplierId){ + // 不用getOne,用获取list的第一个元素 + + 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; + } + + + + } -- Gitblit v1.9.3