admin
2019-02-21 7e57a20c0ccde504c2f2b2b9fd4a9fd7c89d5e92
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
package org.fanli.service.user.service.impl.money;
 
import java.math.BigDecimal;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.fanli.facade.system.service.common.ConfigService;
import org.fanli.facade.user.entity.money.extract.Extract;
import org.fanli.facade.user.entity.money.extract.ExtractRecord;
import org.fanli.facade.user.exception.AdminLimitException;
import org.fanli.facade.user.service.money.ExtractRecordService;
import org.fanli.service.user.dao.money.ExtractRecordMapper;
import org.springframework.stereotype.Service;
import org.yeshi.utils.MoneyBigDecimalUtil;
 
import com.yeshi.fanli.base.entity.user.UserInfo;
 
@Service
public class ExtractRecordServiceImpl implements ExtractRecordService {
 
    @Resource
    private ExtractRecordMapper extractRecordMapper;
 
    @Resource
    private ConfigService configService;
 
    public void setExtractRecord(Extract extract) throws AdminLimitException {
        long uid = extract.getUserInfo().getId();
        BigDecimal money = extract.getMoney();
        List<ExtractRecord> extractRecordList = extractRecordMapper.selectByUid(uid);
        if (extractRecordList.size() == 0) {
            ExtractRecord er = new ExtractRecord();
            er.setCount(1);
            er.setMoney(money);
            er.setUserInfo(new UserInfo(uid));
            extractRecordMapper.insertSelective(er);
        } else {
            ExtractRecord er = extractRecordList.get(0);
            int count = er.getCount();
            String maxCount = configService.get("extract_count_day");
            int maxCountInt = Integer.parseInt(maxCount);
            if (count >= maxCountInt) {
                throw new AdminLimitException("超出每日最大提现次数!");
            }
            BigDecimal oldMoney = er.getMoney();
            BigDecimal sumMoney = MoneyBigDecimalUtil.add(money, oldMoney);
            String maxMoney = configService.get("extract_money_day");
            BigDecimal maxMoneyDou = new BigDecimal(maxMoney);
            if (maxMoneyDou.compareTo(sumMoney) == -1) {
                BigDecimal exceedMoney = MoneyBigDecimalUtil.sub(sumMoney, maxMoneyDou);
                throw new AdminLimitException("超出每日最大提现金额!超出金额为:" + exceedMoney + "元");
            }
            er.setCount(count + 1);
            er.setMoney(sumMoney);
            extractRecordMapper.updateByPrimaryKeySelective(er);
        }
    }
 
    // 定时删除ExtractRecord记录
    public void deleteExtractRecord() {
        extractRecordMapper.deleteAll();
    }
 
    @Override
    public ExtractRecord getExtractRecordByUid(Long uid) {
        List<ExtractRecord> extractRecordList = extractRecordMapper.selectByUid(uid);
        if (extractRecordList == null || extractRecordList.size() == 0)
            return null;
        else
            return extractRecordList.get(0);
    }
 
}