admin
2022-04-07 e1cc0d03fadc2d251d36c0dc3650f75e830d5363
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.yeshi.makemoney.app.utils.factory;
 
import com.ks.lib.common.exception.ParamsException;
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeRecord;
import com.yeshi.makemoney.app.entity.money.Extract;
import com.yeshi.makemoney.app.entity.money.UserMoneyRecord;
import com.yeshi.makemoney.app.entity.money.UserMoneyType;
import com.yeshi.makemoney.app.entity.user.UserInfo;
import org.yeshi.utils.StringUtil;
 
import java.math.BigDecimal;
import java.util.Date;
 
/**
 * @author hxh
 * @title: UserMoneyRecordFactory
 * @description: 用户资金记录工厂
 * @date 2022/4/1 17:57
 */
public class UserMoneyRecordFactory {
 
    public static UserMoneyRecord createExtract(Extract extract) throws ParamsException {
        if (extract == null) {
            throw new ParamsException(1, "提现记录不能为空");
        }
        if (extract.getId() == null) {
            throw new ParamsException(1, "提现记录主键不能为空");
        }
        if (extract.getMoney() == null) {
            throw new ParamsException(1, "提现金额不能为空");
        }
        if (extract.getUser() == null || extract.getUser().getId() == null) {
            throw new ParamsException(1, "提现用户不能为空");
        }
 
        UserMoneyRecord detail = new UserMoneyRecord();
        detail.setCreateTime(new Date());
        detail.setSerialNo(UserMoneyType.extract.name() + "_" + extract.getId());
        detail.setMoney(new BigDecimal("0").subtract(extract.getMoney()));
        detail.setType(UserMoneyType.extract);
        detail.setUpdateTime(new Date());
        detail.setUser(extract.getUser());
        detail.setShow(false);
        detail.setAdd(false);
        return detail;
    }
 
 
    public static UserMoneyRecord createExtractReject(Extract extract) throws ParamsException {
        if (extract == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "提现记录不能为空");
        }
        if (extract.getId() == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "提现记录主键不能为空");
        }
        if (extract.getMoney() == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "提现金额不能为空");
        }
        if (extract.getUser() == null || extract.getUser().getId() == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "提现用户不能为空");
        }
        UserMoneyRecord detail = new UserMoneyRecord();
        detail.setCreateTime(new Date());
        detail.setSerialNo(UserMoneyType.extractReject.name().toLowerCase() + "_" + extract.getId());
        detail.setMoney(extract.getMoney());
        detail.setType(UserMoneyType.extractReject);
        detail.setUpdateTime(new Date());
        detail.setUser(extract.getUser());
        // 隐藏提现失败记录
        detail.setShow(false);
        detail.setAdd(true);
        return detail;
    }
 
 
    public static UserMoneyRecord createGoldCornExchange(GoldCornConsumeRecord record) throws ParamsException {
        if (record == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "金币兑换记录不能为空");
        }
        if (record.getId() == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "金币兑换记录主键不能为空");
        }
        if (record.getMoney() == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "兑换金额不能为空");
        }
        if (record.getUid() == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "兑换用户不能为空");
        }
        UserMoneyRecord detail = new UserMoneyRecord();
        detail.setCreateTime(new Date());
        detail.setSerialNo(UserMoneyType.goldCorn.name().toLowerCase() + "_" + record.getId());
        detail.setMoney(record.getMoney());
        detail.setType(UserMoneyType.goldCorn);
        detail.setUpdateTime(new Date());
        detail.setUser(new UserInfo(record.getUid()));
        detail.setShow(true);
        detail.setAdd(true);
        return detail;
    }
 
 
}