admin
2019-09-16 cc55ffcea74c7d23dadaa0860befbcdf98f35341
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
package com.yeshi.fanli.service.impl.money;
 
import java.math.BigDecimal;
import java.util.Date;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
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.util.MoneyBigDecimalUtil;
 
@Service
public class UserMoneyExtraServiceImpl implements UserMoneyExtraService {
 
    @Resource
    private UserMoneyExtraMapper userMoneyExtraMapper;
 
    @Override
    public UserMoneyExtra selectByPrimaryKey(Long uid) {
        return userMoneyExtraMapper.selectByPrimaryKey(uid);
    }
 
    @Override
    public void updateByPrimaryKeySelective(UserMoneyExtra record) {
        userMoneyExtraMapper.updateByPrimaryKeySelective(record);    
    }
    
    
    @Override
    public void addTaoLiJin(Long uid, BigDecimal money, boolean canSelf) {
        if (uid == null || money == null) {
            return;
        }
        
        UserMoneyExtra record = new UserMoneyExtra();
        record.setUid(uid);
        
        UserMoneyExtra existExtra = userMoneyExtraMapper.selectByPrimaryKey(record.getUid());
        if (existExtra == null) {
            record.setTlj(money);
            
            if (canSelf) {
                record.setTljSelf(money);
            } else {
                record.setTljSelf(new BigDecimal(0));
            }
            
            record.setCreateTime(new Date());
            record.setUpdateTime(new Date());
            userMoneyExtraMapper.insertSelective(record);
        } else {
            BigDecimal tlj = existExtra.getTlj();
            record.setTlj(MoneyBigDecimalUtil.add(tlj, money));
            
            if (canSelf) {
                BigDecimal tljSelf = existExtra.getTljSelf();
                record.setTljSelf(MoneyBigDecimalUtil.add(tljSelf, money));
            }
            
            record.setUpdateTime(new Date());
            userMoneyExtraMapper.updateByPrimaryKeySelective(record);    
        }
    }
}