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; /** *

* 服务实现类 *

* * @author @TaoJie * @since 2024-10-22 */ @Service public class WalletServiceImpl extends ServiceImpl implements WalletService { @Autowired private SupplierService supplierService; @Override public WalletDO getCurrentSupplier() { final SupplierDTO currentSupplier = supplierService.getCurrentSupplier(); // 根据供应商ID获取钱包信息 // 查询的条件的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()); } return walletDO; } @Override public WalletDO getBySupplierId(Long supplierId) { // 不用getOne,用获取list的第一个元素 List walletDOS = baseMapper.selectList(new LambdaQueryWrapper() .eq(WalletDO::getDeleted, TrueOrFalseEnum.FALSE.isFlag()) .eq(WalletDO::getSupplierId, supplierId)); if(!CollectionUtils.isEmpty(walletDOS)){ return walletDOS.get(0); }else return null; } }