派生自 projectDept/qhighschool

胡仁荣
2022-11-03 68408ba6f0ff9c4e7978735818ab12990c957c1a
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package com.qxueyou.scc.base.util;
 
import java.util.List;
import java.util.Map;
 
import com.qxueyou.scc.base.model.UserInfoWrapper;
import org.apache.commons.lang3.StringUtils;
 
import com.qxueyou.scc.base.model.Constants;
import com.qxueyou.scc.base.model.FilePathConstants;
import com.qxueyou.scc.sys.model.ResponseResult;
import com.qxueyou.scc.sys.model.SysMenu;
import com.qxueyou.scc.user.model.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
 
/**
 * ¿Í»§¶ËÐÅÏ¢´¦Àí¹¤¾ßÀà
 * @author µÂ»¢ 2014-12-29
 *
 */
public final class ClientUtils {
 
    /*
     * Ï̱߳äÁ¿: Óû§ÐÅÏ¢
     */
    private static ThreadLocal<UserInfoWrapper> threadLocalUserInfo = new ThreadLocal<UserInfoWrapper>();
    private static UserInfoWrapper wrapper = threadLocalUserInfo.get();
 
    /** µÃµ½Óû§ÐÅÏ¢*/
    public static UserInfoWrapper getUserInfo() {
        UserInfoWrapper wrapper = threadLocalUserInfo.get();
        if(wrapper == null){
            wrapper = new UserInfoWrapper();
            User user = new User();
            //ĬÈÏÖµ£¬ÉÏ´«¿ÉÒÔ×÷ΪĬÈÏÉÏ´«Õß
            user.setUserId(Constants.VISITOR_USER_ID);
            user.setName(Constants.VISITOR_USER_ID);
            wrapper.setUser(user);
            setUserInfo(wrapper);
        }
 
        return wrapper;
    }
 
 
    /** ÉèÖÃÓû§ÐÅÏ¢*/
    public static void setUserInfo(UserInfoWrapper wrapper) {
        threadLocalUserInfo.remove();
        threadLocalUserInfo.set(wrapper);
    }
 
    /** µÃµ½userId*/
    public static String getUserId(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String info = getUserInfo().getInfo(UserInfoWrapper.INF_USER_ID);
        if(info.equals("visitor_001")){
            info= (String) session.getAttribute(UserInfoWrapper.INF_USER_ID);
        }
        return info;
    }
 
    /** µÃµ½userName*/
    public static String getUserName(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String info = getUserInfo().getInfo(UserInfoWrapper.INF_USER_NAME);
        if(info!=null){
            info= (String) session.getAttribute(UserInfoWrapper.INF_USER_NAME);
        }
        return info;
    }
 
    /** µÃµ½Óû§Í·Ïñ*/
    public static String getUserImg(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_USER_HEAD_IMG);
//        return session.getAttribute();
    }
 
    /** µÃµ½ÊÖ»úºÅ*/
    public static String getUserMobilePhone(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_USER_MOBILE_PHONE);
    }
 
    /** µÃµ½ÕʺÅ*/
    public static String getUserAccount(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_USER_ACCOUNT);
    }
 
    /** µÃµ½classId*/
    public static String getClassId(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String info = getUserInfo().getInfo(UserInfoWrapper.INF_CLASS_ID);
        if(info!=null){
            info= (String) session.getAttribute(UserInfoWrapper.INF_CLASS_ID);
        }
        return info;
//        return getUserInfo().getInfo(UserInfoWrapper.);
    }
 
    /** µÃµ½className*/
    public static String getClassName(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String info = getUserInfo().getInfo(UserInfoWrapper.INF_CLASS_NAME);
        if(info!=null){
            info= (String) session.getAttribute(UserInfoWrapper.INF_CLASS_NAME);
        }
        return info;
//        System.out.println("CLassName"+session.getAttribute("className"));
//        return (String) session.getAttribute("className");
    }
 
    /** */
    public static String getClassCharger(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_CLASS_CHARGER);
    }
 
    /** µÃµ½¿ÆÄ¿ID*/
    public static String getCourseId(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_COURSE_ID);
    }
 
    /** µÃµ½¿ÆÄ¿Name*/
    public static String getCourseName(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_COURSE_NAME);
    }
 
    /** µÃµ½»ú¹¹ID*/
    public static String getOrgId(){
        return "1";
    }
 
    /** µÃµ½×îÉϲã»ú¹¹ID*/
    public static String getTopOrgId(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_TOP_ORG_ID);
    }
 
    /** µÃµ½»ú¹¹CODE*/
    public static String getOrgCode(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_ORG_CODE);
    }
 
    /** µÃµ½»ú¹¹NAME*/
    public static String getOrgName(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_ORG_NAME);
    }
 
    /** µÃµ½»ú¹¹SHORTNAME*/
    public static String getOrgShortName(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_ORG_SHORT_NAME);
    }
 
    /** µÃµ½»ú¹¹LOGO*/
    public static String getOrgLogoPath(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_ORG_LOGO_PATH);
    }
 
    /** µÃµ½µ±Ç°½ÇÉ«*/
    public static String getCurrentRole(){
        return getUserInfo().getCurrentRole();
    }
 
 
    /** µÃµ½µ±Ç°½ÇÉ«±àÂë*/
    public static String getCurrentRoleEName(){
        return getUserInfo().getInfo(UserInfoWrapper.INF_ROLE_ENAME);
    }
 
    /** µÃµ½µ±Ç°½ÇÉ«ID*/
    public static String getCurrentRoleId(){
        return getUserInfo().getCurrentRoleId();
    }
 
    /** µÃµ½µ±Ç°½Çɫֵ*/
    public static String getCurrentRoleValue(){
        return getUserInfo().getCurrentRoleValue();
    }
 
    /** µÃµ½µ±Ç°½ÇÉ«ÐÅÏ¢*/
    public static List<Map<String,Object>> getRoleInfo(String role){
        return getUserInfo().getRoleInfo(role);
    }
 
    /** »ñÈ¡µ±Ç°¾ÍÊÇ ²Ëµ¥ÐÅÏ¢*/
    public static List<SysMenu> getMenuInfo(){
        return getUserInfo().getMenus();
    }
 
    /** */
    public static Boolean getButtonPrivilegeEdit(){
        return getUserInfo().getButtonPrivilegeEdit();
    }
 
    /** µ±Ç°µÇ¼IP*/
    public static String getCurrentLoginIp(){
        return getUserInfo().getCurrentLoginIp();
    }
 
    /**
     * »ñÈ¡Óû§»ù±¾ÐÅÏ¢
     * @return
     */
    public static ResponseResult getUserBaseInfo(User user){
        ResponseResult userInfo = new ResponseResult();
        // Óû§
        userInfo.setUserId(user.getUserId());
        userInfo.setUserName(user.getName());
        userInfo.setImgPath(StringUtils.isNotBlank(user.getImgPath()) ? user.getImgPath() : FilePathConstants.USER_DEFAULT_IMG );
        userInfo.setMobilePhone(user.getMobilePhone());
        return userInfo;
    }
 
    /**
     * ÊÇ·ñΪ¹ÜÀíÔ±
     * @return
     */
    public static boolean isAdmin(){
        HttpServletRequest request =((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        Object admin =session.getAttribute("admin");
//        if(Boolean.valueOf((Boolean) admin)){
//            System.out.println(Boolean.valueOf((Boolean) admin));
//            return Boolean.valueOf((Boolean) admin);
//        }else{
//            return false;
//        }
        return true;
//        System.out.println(Boolean.valueOf((Boolean) admin));
//        return Boolean.valueOf((Boolean) admin);
    }
}