admin
2019-07-09 531d93708df8017e59830f15b41f3cc42d6126e6
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package com.yeshi.fanli.util.factory;
 
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.Map;
 
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.entity.bus.user.AccountMessage;
import com.yeshi.fanli.entity.bus.user.Extract;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.PropertiesUtil;
import com.yeshi.fanli.util.TimeUtil;
 
public class AccountMessageFactory {
 
    /**
     * 新人红包
     */
    public static final int NEWUSER = 1;
 
    /**
     * 返利
     */
    public static final int REBATE = 2;
 
    /**
     * 分销提成
     */
    public static final int SALE = 3;
 
    /**
     * 分享赚
     */
    public static final int SHARE = 4;
 
    /**
     * 售后订单扣款
     */
    public static final int SERVICE = 5;
 
    /**
     * 提现申请
     */
    public static final int EXTRACTAPPLY = 6;
 
    /**
     * 提现失败(被动)
     */
    public static final int EXTRACTFAIL = 7;
 
    /**
     * 提现失败(被拒)
     */
    public static final int EXTRACTFAIL2 = 9;
 
    /**
     * 新人红包扣除
     */
    public static final int XINREN_DRAWBACK = 10;
 
    /**
     * 提现成功
     */
    public static final int EXTRACTSUCCESS = 8;
 
    private static final String FANTITLE = "fan_title";
 
    private static final String FANCONTENT = "fan_content";
 
    private static final String SALETITLE = "sale_title";
 
    private static final String SALECONTENT = "sale_content";
 
    private static final String USERTITLE = "user_title";
 
    private static final String USERCONTENT = "user_content";
 
    private static final String SERVICETITLE = "service_title";
 
    private static final String SERVICECONTENT = "service_content";
 
    private static final String EXTRACTAPPLYTITLE = "extract_apply_title";
 
    private static final String EXTRACTAPPLYCONTENT = "extract_apply_content";
 
    private static final String EXTRACTSUCCESSTITLE = "extract_success_title";
 
    private static final String EXTRACTSUCCESSCONTENT = "extract_success_content";
 
    private static final String EXTRACTFAILTITLE = "extract_fail_title";
 
    private static final String EXTRACTFAILCONTENT1 = "extract_fail_content1";
    private static final String EXTRACTFAILCONTENT2 = "extract_fail_content2";
 
    public static AccountMessage create(UserInfo userInfo, String orderId, BigDecimal moeny, Extract extract,
            int type) {
        String wholeTime = TimeUtil.getWholeTime(extract.getExtractTime());
        if (type == EXTRACTAPPLY) {
            return create(userInfo, EXTRACTSUCCESSTITLE, EXTRACTSUCCESSCONTENT, wholeTime);
        } else if (type == EXTRACTFAIL) {
            return create(userInfo, EXTRACTFAILTITLE, EXTRACTFAILCONTENT1, wholeTime);
        } else if (type == EXTRACTFAIL2) {
            return create(userInfo, EXTRACTFAILTITLE, EXTRACTFAILCONTENT2, wholeTime);
        } else if (type == EXTRACTSUCCESS) {
            return create(userInfo, EXTRACTSUCCESSTITLE, EXTRACTSUCCESSCONTENT, wholeTime);
        }
        return null;
    }
 
    public static AccountMessage create(UserInfo userInfo, String orderId, BigDecimal moeny, int type) {
 
        switch (type) {
        case NEWUSER:
            AccountMessage am = new AccountMessage();
            am.setContent(Constant.znxConfig.getNewerHongbaoMsg());
            am.setCreateTime(System.currentTimeMillis());
            am.setIsOpen(false);
            am.setTitle(Constant.znxConfig.getNewerHongbaoTitle());
            am.setUserInfo(userInfo);
            return am;
        }
 
        return null;
 
        // if (type == REBATE) {
        // return create(userInfo, FANTITLE, FANCONTENT, orderId, moeny);
        // } else if (type == SALE) {
        // return create(userInfo, SALETITLE, SALECONTENT, moeny);
        // } else if (type == EXTRACTAPPLY) {
        // return create(userInfo, EXTRACTAPPLYTITLE, EXTRACTAPPLYCONTENT);
        // } else if (type == NEWUSER) {
        // return create(userInfo, USERTITLE, USERCONTENT, moeny);
        // } else if (type == SERVICE) {
        // return create(userInfo, SERVICETITLE, SERVICECONTENT, orderId,
        // moeny);
        // }
        // return null;
    }
 
    private static AccountMessage create(UserInfo userInfo, String titleKey, String contentKey, Object... objs) {
        AccountMessage am = new AccountMessage();
        Map<String, String> map = PropertiesUtil.getMap();
        String title = map.get(titleKey);
        String content = map.get(contentKey);
        content = MessageFormat.format(content, objs);
        am.setContent(content);
        am.setCreateTime(System.currentTimeMillis());
        am.setIsOpen(false);
        am.setTitle(title);
        am.setUserInfo(userInfo);
        return am;
    }
 
    public static AccountMessage create(HongBao hb) {
        int type = hb.getType();
        if (type == Constant.TAOBAO) {
            return create(hb.getUserInfo(), FANTITLE, FANCONTENT, hb.getOrder().getOrderId(), hb.getMoney());
        } else if (type == Constant.ONESALE || type == Constant.TWOSALE) {
            return create(hb.getUserInfo(), SALETITLE, SALECONTENT, hb.getOrder().getOrderId(), hb.getMoney());
        } else if (type == Constant.HB_NEWUSER) {
            return create(hb.getUserInfo(), USERTITLE, USERCONTENT, hb.getMoney());
        }
        return null;
    }
 
}