mitao
2024-06-06 3d2b51ea4520533de5e78f88dddf5b5c7dce4247
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
package com.sinata.rest.modular.mall.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinata.rest.common.lock.IdLock;
import com.sinata.rest.common.lock.IdLocker;
import com.sinata.rest.modular.mall.dao.MemMerchantBankMapper;
import com.sinata.rest.modular.mall.model.MemMerchantBank;
import com.sinata.rest.modular.mall.service.IMemMerchantBankService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
 
/**
 * <p>
 * 门店账户信息 服务实现类
 * </p>
 *
 * @author goku
 * @since 2023-03-23
 */
@Service
public class MemMerchantBankServiceImpl extends ServiceImpl<MemMerchantBankMapper, MemMerchantBank> implements IMemMerchantBankService {
 
    final IdLocker locker = new IdLocker();
 
    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ)
    public void addUserBank(Integer merchantId, BigDecimal balance, BigDecimal balanceFreeze, BigDecimal rice, BigDecimal froze, BigDecimal score) {
        IdLock lock = locker.acquireLock(merchantId);
        synchronized (lock) {
            LambdaQueryWrapper<MemMerchantBank> wr = new LambdaQueryWrapper<>();
            wr.eq(MemMerchantBank::getId, merchantId);
            MemMerchantBank b = getOne(wr);
            if (b != null) {
                this.baseMapper.editUserBank(merchantId,
                        balance == null ? BigDecimal.ZERO : balance,
                        balanceFreeze == null ? BigDecimal.ZERO : balanceFreeze,
                        rice == null ? BigDecimal.ZERO : rice,
                        froze == null ? BigDecimal.ZERO : froze,
                        score == null ? BigDecimal.ZERO : score);
            }
        }
        locker.releaseLock(lock);
    }
 
    @Override
    public MemMerchantBank getMerchantBankByUserId(Integer userId) {
        return this.baseMapper.getMerchantBankByUserId(userId);
    }
}