yujian
2020-04-02 0ec22dcf4fd9c4496e6f681e7fab89f56c6e4e8a
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
package com.yeshi.fanli.service.impl.money;
 
import java.math.BigDecimal;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.yeshi.fanli.dao.mybatis.user.UserMoneyExtraMapper;
import com.yeshi.fanli.entity.bus.user.UserMoneyExtra;
import com.yeshi.fanli.service.inter.money.UserMoneyExtraService;
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
 
@Service
public class UserMoneyExtraServiceImpl implements UserMoneyExtraService {
 
    @Resource
    private UserMoneyExtraMapper userMoneyExtraMapper;
    
    @Resource
    private IntegralTaskRecordService integralTaskRecordService;
 
    @Override
    public UserMoneyExtra selectByPrimaryKey(Long uid) {
        return userMoneyExtraMapper.selectByPrimaryKey(uid);
    }
 
    @Override
    public void updateByPrimaryKeySelective(UserMoneyExtra record) {
        userMoneyExtraMapper.updateByPrimaryKeySelective(record);    
    }
    
        
    @Override
    public List<UserMoneyExtra> listValid(int page, int count) {
        return userMoneyExtraMapper.listValid((page-1) * count, count);
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void taoLiJinExchange(int page, int count) {
        List<UserMoneyExtra> listValid = userMoneyExtraMapper.listValid((page-1) * count, count);
        if (listValid == null || listValid.isEmpty())
            return;
        
        BigDecimal zero = new BigDecimal(0);
        for (UserMoneyExtra moneyExtra: listValid) {
            BigDecimal tlj = moneyExtra.getTlj();
            BigDecimal tljSelf = moneyExtra.getTljSelf();
            if (tlj == null || tlj.compareTo(zero) <= 0 || tljSelf == null || tljSelf.intValue() <= 0)
                continue;
            
            integralTaskRecordService.taoLiJinExchange(moneyExtra.getUid(), tljSelf.intValue(), tlj);
            
            moneyExtra.setTlj(zero);
            moneyExtra.setTljSelf(zero);
            userMoneyExtraMapper.updateByPrimaryKeySelective(moneyExtra);
        }
    }
    
}