yujian
2019-01-22 2366d2ada9e67f915a06b51b3c5be08a00847f0c
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package com.yeshi.fanli.util.account;
 
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
import org.apache.commons.beanutils.PropertyUtils;
import org.yeshi.utils.HttpUtil;
 
import com.yeshi.fanli.entity.bus.user.BindingAccount;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
public class UserUtil {
 
    /**
     * 处理输出给客户端的用户信息
     * 
     * @param user
     * @return
     */
    public static UserInfo filterForClientUser(UserInfo user) {
        if (user == null)
            return user;
 
        UserInfo newUser = new UserInfo();
        try {
            PropertyUtils.copyProperties(newUser, user);
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } catch (InvocationTargetException e1) {
            e1.printStackTrace();
        } catch (NoSuchMethodException e1) {
            e1.printStackTrace();
        }
 
        if (!StringUtil.isNullOrEmpty(user.getPhone())) {
            if (user.getPhone().length() > 5) {
                String phone = user.getPhone().substring(0, 3);
                phone += "******";
                phone += user.getPhone().substring(user.getPhone().length() - 2, user.getPhone().length());
                newUser.setPhone(phone);
            }
        }
 
        if (user != null) {
            newUser.setRankIcon(UserUtil.getRankIcon(user.getRank()));
            newUser.setRankNamePicture(UserUtil.getRankNamePicture(user.getRank()));
        }
 
        return newUser;
    }
 
    public static String getRankIcon(Integer rank) {
        if (rank == null)
            return "";
        if (rank == 0)
            return "";
        else
            return String.format(Constant.systemCommonConfig.getBaseUserRankIconUrl() + "/rank_icon_%s.png", rank + "");
    }
 
    public static String getRankNamePicture(Integer rank) {
        if (rank == null)
            rank = 0;
 
        return String.format(Constant.systemCommonConfig.getBaseUserRankIconUrl() + "/rank_picture_%s.png", rank + "");
    }
    
    
    public static String getInviteShortLink (Long uid) {
        return HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/"
                + Constant.systemCommonConfig.getProjectName() + "/"
                + java.lang.System.currentTimeMillis()+
                "/client/threeShareNew?uid=" + uid);
    }
    
    
    
    public static String getInviteCode(Long uid) {
 
        long num = 1000000000L + uid;
 
        return convert10To36(num);
    }
 
    private static String convert10To36(Long num) {
        String numbers = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        BigDecimal numBig = new BigDecimal(num);
 
        int ge = numBig.divideAndRemainder(new BigDecimal(36))[1].intValue();
        int n = 1;
        String result = "";
        result += numbers.charAt(ge);
 
        while (numBig.divideAndRemainder(new BigDecimal(36).pow(n))[0].compareTo(new BigDecimal(0)) > 0) {
            int w = numBig.divideAndRemainder(new BigDecimal(36).pow(n))[0].divideAndRemainder(new BigDecimal(36))[1]
                    .intValue();
            result = numbers.charAt(w) + result;
            n++;
        }
        return result;
    }
 
    /**
     * 过滤支付宝账号,中间用*代替
     * 
     * @param bindingAccountList
     * @return
     */
    public static List<BindingAccount> filterBindingAccount(List<BindingAccount> bindingAccountList) {
        List<BindingAccount> accountList = new ArrayList<>();
 
        if (bindingAccountList != null)
            for (BindingAccount bindingAccount : bindingAccountList) {
                accountList.add(filterBindingAccount(bindingAccount));
            }
        return accountList;
    }
 
    public static BindingAccount filterBindingAccount(BindingAccount bindingAccount) {
 
        BindingAccount dest = new BindingAccount();
        try {
            PropertyUtils.copyProperties(dest, bindingAccount);
            if (!StringUtil.isNullOrEmpty(dest.getAccount()) && !StringUtil.isNullOrEmpty(dest.getName())) {
                String name = "";
                if ((dest.getName() + "").length() > 2)
                    for (int i = 0; i < (dest.getName() + "").length(); i++) {
                        if (i == 0)
                            name += dest.getName().charAt(i);
                        else
                            name += "*";
                    }
                else
                    name = dest.getName().charAt(0) + "*";
                dest.setName(name);
 
                String account = "";
                if (dest.getAccount().indexOf("@") > -1) {// 邮箱
                    int index = dest.getAccount().indexOf("@");
 
                    for (int i = 0; i < dest.getAccount().length(); i++) {
                        if (i < 3 || i >= index)
                            account += dest.getAccount().charAt(i);
                        else
                            account += "*";
                    }
                } else if (StringUtil.isMobile(dest.getAccount())) {// 电话
                    account = dest.getAccount().substring(0, 3) + "*****"
                            + dest.getAccount().substring(dest.getAccount().length() - 2, dest.getAccount().length());
 
                } else {// 其他
                    if (dest.getAccount().length() >= 6) {
                        for (int i = 0; i < dest.getAccount().length(); i++) {
                            if (i < 3 || i >= dest.getAccount().length() - 2)
                                account += dest.getAccount().charAt(i);
                            else
                                account += "*";
                        }
                    } else {
                        for (int i = 0; i < dest.getAccount().length(); i++) {
                            if (i < 1 || i >= dest.getAccount().length() - 1)
                                account += dest.getAccount().charAt(i);
                            else
                                account += "*";
                        }
                    }
                }
 
                dest.setAccount(account);
            }
        } catch (Exception e) {
        }
 
        return dest;
    }
 
}