admin
2020-11-13 ae08b37317103344b9be1b9f91b6bdf7abbc839b
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
package com.ks.goldcorn.service.remote;
 
import com.ks.goldcorn.exception.GoldAppException;
import com.ks.goldcorn.mapper.GoldCornBalanceMapper;
import com.ks.goldcorn.pojo.DO.GoldCornBalance;
import com.ks.goldcorn.service.GoldCornAppManager;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
@Service(version = "1.0")
public class GoldCornBalanceServiceImpl implements GoldCornBalanceService {
 
    @Resource
    private GoldCornBalanceMapper goldCornBalanceMapper;
 
    @Resource
    private GoldCornAppManager goldCornAppManager;
 
    @Transactional
    @Override
    public void init(String appCode, String uid) throws GoldAppException {
        Long appId = goldCornAppManager.getAppId(appCode);
        GoldCornBalance balance = goldCornBalanceMapper.selectByAppIdAndUid(appId, uid);
        if (balance == null) {
            balance = new GoldCornBalance();
            balance.setAppId(appId);
            balance.setBalance(0L);
            balance.setCreateTime(new Date());
            balance.setUid(uid);
            goldCornBalanceMapper.insertSelective(balance);
        }
 
    }
 
    @Override
    public Long getBalance(String appCode, String uid) throws GoldAppException {
        Long appId = goldCornAppManager.getAppId(appCode);
        GoldCornBalance balance = goldCornBalanceMapper.selectByAppIdAndUid(appId, uid);
        if (balance != null) {
            return balance.getBalance();
        }
        return null;
    }
 
    @Override
    public List<GoldCornBalance> getBalanceList(String appCode, List<String> uidList) throws GoldAppException {
        Long appId = goldCornAppManager.getAppId(appCode);
        return goldCornBalanceMapper.listByUids(appId, uidList);
    }
 
 
}