cloudroam
2024-10-24 d19b094bde681e2a261ff28a088dd969b68ac65c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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>
 *  服务实现类
 * </p>
 *
 * @author @TaoJie
 * @since 2024-10-22
 */
@Service
public class WalletServiceImpl extends ServiceImpl<WalletMapper, WalletDO> 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<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;
    }
 
}