Procházet zdrojové kódy

获取当前用户接口修改

my-csc-config-file.git před 5 roky
rodič
revize
f8f540b424

+ 17 - 0
pom.xml

@@ -48,7 +48,24 @@
48 48
             <groupId>org.apache.commons</groupId>
49 49
             <artifactId>commons-lang3</artifactId>
50 50
         </dependency>
51
+        <!--feign(默认集成hystrix熔断器)-->
52
+        <dependency>
53
+            <groupId>org.springframework.cloud</groupId>
54
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
55
+            <version>2.1.0.RELEASE</version>
56
+        </dependency>
57
+        <!--使用security-jwt-->
58
+        <dependency>
59
+            <groupId>org.springframework.security</groupId>
60
+            <artifactId>spring-security-jwt</artifactId>
61
+        </dependency>
51 62
 
63
+        <!--jwt解析相关-->
64
+        <dependency>
65
+            <groupId>io.jsonwebtoken</groupId>
66
+            <artifactId>jjwt</artifactId>
67
+            <version>0.9.1</version>
68
+        </dependency>
52 69
         <dependency>
53 70
             <groupId>org.projectlombok</groupId>
54 71
             <artifactId>lombok</artifactId>

+ 20 - 129
src/main/java/com/unissoft/model/SysUserPO.java

@@ -1,6 +1,7 @@
1 1
 package com.unissoft.model;
2 2
 
3 3
 
4
+import com.baomidou.mybatisplus.annotation.TableField;
4 5
 
5 6
 import java.io.Serializable;
6 7
 
@@ -17,40 +18,20 @@ public class SysUserPO implements Serializable {
17 18
     private static final long serialVersionUID = 1L;
18 19
 
19 20
     private Integer uId;
20
-//    用户名
21
+    //    用户名
21 22
     private String uName;
22
-//    人员名称(姓名)
23
-    private String personnelName;
24
-//    人员id必填
25
-    private Integer personnelId;
26
-//    电话
27
-    private String uPhone;
28
-//    岗位(职务)
29
-    private String pPost;
30
-//    用户状态(1:正常,2:异常,3:禁用)
31
-    private Integer uStatus;
32
-//    头像地址
33
-    private String pHeadPortrait;
34
-//    所属库id
23
+    //"用于区分登录跳转那个页面(1.分公司领导首页 2.库主任及以上领导首页 3.员工首页)必填项
24
+    private Integer homeType;
25
+    //密码
26
+    private String uPassword;
27
+    //    所属库id
35 28
     private Integer depotId;
36
-//    所属库名称
37
-    private String depotName;
38
-//    仓房id,多个使用‘,’号隔开
29
+    //    仓房id,多个使用‘,’号隔开
39 30
     private String storehouseIds;
40
-//    仓房名称,多个使用‘,’号隔开
41
-    private String storehouseNames;
42
-//    角色id,多个使用‘,’号隔开
31
+    //    角色id,多个使用‘,’号隔开
43 32
     private String roleIds;
44
-//    角色名称,多个使用‘,’号隔开
33
+    //    角色名称,多个使用‘,’号隔开
45 34
     private String roleName;
46
-//    所属公司id
47
-    private Integer companyId;
48
-//    所属公司名称
49
-    private String companyName;
50
-//    所属部门id
51
-    private Integer departmentId;
52
-//    所属部门名称
53
-    private String departmentName;
54 35
 
55 36
     public Integer getuId() {
56 37
         return uId;
@@ -68,52 +49,20 @@ public class SysUserPO implements Serializable {
68 49
         this.uName = uName;
69 50
     }
70 51
 
71
-    public String getPersonnelName() {
72
-        return personnelName;
52
+    public Integer getHomeType() {
53
+        return homeType;
73 54
     }
74 55
 
75
-    public void setPersonnelName(String personnelName) {
76
-        this.personnelName = personnelName;
56
+    public void setHomeType(Integer homeType) {
57
+        this.homeType = homeType;
77 58
     }
78 59
 
79
-    public Integer getPersonnelId() {
80
-        return personnelId;
60
+    public String getuPassword() {
61
+        return uPassword;
81 62
     }
82 63
 
83
-    public void setPersonnelId(Integer personnelId) {
84
-        this.personnelId = personnelId;
85
-    }
86
-
87
-    public String getuPhone() {
88
-        return uPhone;
89
-    }
90
-
91
-    public void setuPhone(String uPhone) {
92
-        this.uPhone = uPhone;
93
-    }
94
-
95
-    public String getpPost() {
96
-        return pPost;
97
-    }
98
-
99
-    public void setpPost(String pPost) {
100
-        this.pPost = pPost;
101
-    }
102
-
103
-    public Integer getuStatus() {
104
-        return uStatus;
105
-    }
106
-
107
-    public void setuStatus(Integer uStatus) {
108
-        this.uStatus = uStatus;
109
-    }
110
-
111
-    public String getpHeadPortrait() {
112
-        return pHeadPortrait;
113
-    }
114
-
115
-    public void setpHeadPortrait(String pHeadPortrait) {
116
-        this.pHeadPortrait = pHeadPortrait;
64
+    public void setuPassword(String uPassword) {
65
+        this.uPassword = uPassword;
117 66
     }
118 67
 
119 68
     public Integer getDepotId() {
@@ -124,14 +73,6 @@ public class SysUserPO implements Serializable {
124 73
         this.depotId = depotId;
125 74
     }
126 75
 
127
-    public String getDepotName() {
128
-        return depotName;
129
-    }
130
-
131
-    public void setDepotName(String depotName) {
132
-        this.depotName = depotName;
133
-    }
134
-
135 76
     public String getStorehouseIds() {
136 77
         return storehouseIds;
137 78
     }
@@ -140,14 +81,6 @@ public class SysUserPO implements Serializable {
140 81
         this.storehouseIds = storehouseIds;
141 82
     }
142 83
 
143
-    public String getStorehouseNames() {
144
-        return storehouseNames;
145
-    }
146
-
147
-    public void setStorehouseNames(String storehouseNames) {
148
-        this.storehouseNames = storehouseNames;
149
-    }
150
-
151 84
     public String getRoleIds() {
152 85
         return roleIds;
153 86
     }
@@ -164,59 +97,17 @@ public class SysUserPO implements Serializable {
164 97
         this.roleName = roleName;
165 98
     }
166 99
 
167
-    public Integer getCompanyId() {
168
-        return companyId;
169
-    }
170
-
171
-    public void setCompanyId(Integer companyId) {
172
-        this.companyId = companyId;
173
-    }
174
-
175
-    public String getCompanyName() {
176
-        return companyName;
177
-    }
178
-
179
-    public void setCompanyName(String companyName) {
180
-        this.companyName = companyName;
181
-    }
182
-
183
-    public Integer getDepartmentId() {
184
-        return departmentId;
185
-    }
186
-
187
-    public void setDepartmentId(Integer departmentId) {
188
-        this.departmentId = departmentId;
189
-    }
190
-
191
-    public String getDepartmentName() {
192
-        return departmentName;
193
-    }
194
-
195
-    public void setDepartmentName(String departmentName) {
196
-        this.departmentName = departmentName;
197
-    }
198
-
199 100
     @Override
200 101
     public String toString() {
201 102
         return "SysUserPO{" +
202 103
                 "uId=" + uId +
203 104
                 ", uName='" + uName + '\'' +
204
-                ", personnelName='" + personnelName + '\'' +
205
-                ", personnelId=" + personnelId +
206
-                ", uPhone='" + uPhone + '\'' +
207
-                ", pPost='" + pPost + '\'' +
208
-                ", uStatus=" + uStatus +
209
-                ", pHeadPortrait='" + pHeadPortrait + '\'' +
105
+                ", homeType=" + homeType +
106
+                ", uPassword='" + uPassword + '\'' +
210 107
                 ", depotId=" + depotId +
211
-                ", depotName='" + depotName + '\'' +
212 108
                 ", storehouseIds='" + storehouseIds + '\'' +
213
-                ", storehouseNames='" + storehouseNames + '\'' +
214 109
                 ", roleIds='" + roleIds + '\'' +
215 110
                 ", roleName='" + roleName + '\'' +
216
-                ", companyId=" + companyId +
217
-                ", companyName='" + companyName + '\'' +
218
-                ", departmentId=" + departmentId +
219
-                ", departmentName='" + departmentName + '\'' +
220 111
                 '}';
221 112
     }
222 113
 }

+ 0 - 24
src/main/java/com/unissoft/utils/HttpUtil.java

@@ -1,24 +0,0 @@
1
-package com.unissoft.utils;
2
-
3
-import org.springframework.web.context.request.RequestContextHolder;
4
-import org.springframework.web.context.request.ServletRequestAttributes;
5
-
6
-import javax.servlet.http.HttpServletRequest;
7
-import javax.servlet.http.HttpServletResponse;
8
-
9
-/**
10
- * 文件描述
11
- *
12
- * @author tongxi.xia
13
- * @date 2020年12月12日 12:40
14
- */
15
-public class HttpUtil {
16
-
17
-    public static HttpServletRequest getRequest() {
18
-        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
19
-    }
20
-
21
-    public static HttpServletResponse getResponse() {
22
-        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
23
-    }
24
-}

+ 22 - 3
src/main/java/com/unissoft/utils/UserUtils.java

@@ -1,8 +1,17 @@
1 1
 package com.unissoft.utils;
2 2
 
3
-import com.unissoft.MyConstant;
3
+import com.alibaba.fastjson.JSON;
4
+import com.alibaba.fastjson.JSONObject;
4 5
 import com.unissoft.model.SysUserPO;
6
+import org.springframework.security.jwt.Jwt;
7
+import org.springframework.security.jwt.JwtHelper;
5 8
 import org.springframework.stereotype.Component;
9
+import org.springframework.util.StringUtils;
10
+import org.springframework.web.context.request.RequestContextHolder;
11
+import org.springframework.web.context.request.ServletRequestAttributes;
12
+
13
+import javax.servlet.http.HttpServletRequest;
14
+import java.util.Map;
6 15
 
7 16
 /**
8 17
  * 文件描述
@@ -14,9 +23,19 @@ import org.springframework.stereotype.Component;
14 23
 public class UserUtils {
15 24
 
16 25
     public static SysUserPO getCurrUserInfo() {
26
+        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
27
+        HttpServletRequest request = attributes.getRequest();
17 28
         SysUserPO loginUser = null;
18
-        if (HttpUtil.getRequest().getSession().getAttribute(MyConstant.LOGIN_USER) != null) {
19
-            loginUser = (SysUserPO) HttpUtil.getRequest().getSession().getAttribute(MyConstant.LOGIN_USER);
29
+        if (request != null && !StringUtils.isEmpty(request.getHeader("Authorization"))) {
30
+            // 只携带token
31
+            String authorization = request.getHeader("Authorization").replace("bearer ","");
32
+            System.out.println(authorization);
33
+            Jwt decode = JwtHelper.decode(authorization);
34
+            String claims = decode.getClaims();
35
+            JSONObject jsonObject = JSON.parseObject(claims);
36
+            Map<String, String> jsonMap = JSONObject.toJavaObject(jsonObject, Map.class);
37
+            JSONObject user = JSON.parseObject(jsonMap.get("user_name"));
38
+            loginUser = JSONObject.toJavaObject(user, SysUserPO.class);
20 39
         }
21 40
         return loginUser;
22 41
     }