admin
2019-01-05 86e46bc28e78b3a883132816e23dbcca37f9ca3a
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
package com.yeshi.fanli.util.account;
 
import java.lang.reflect.InvocationTargetException;
 
import org.apache.commons.beanutils.PropertyUtils;
 
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 + "");
    }
 
}