diff --git a/hw-api/hw-api-system/src/main/java/com/hw/system/api/model/LoginUser.java b/hw-api/hw-api-system/src/main/java/com/hw/system/api/model/LoginUser.java index 41ecba8..d1c9c90 100644 --- a/hw-api/hw-api-system/src/main/java/com/hw/system/api/model/LoginUser.java +++ b/hw-api/hw-api-system/src/main/java/com/hw/system/api/model/LoginUser.java @@ -63,6 +63,11 @@ public class LoginUser implements Serializable */ private Long stationId; + /** + * 工位编号 + */ + private String stationCode; + public String getToken() { return token; @@ -160,4 +165,12 @@ public class LoginUser implements Serializable public void setStationId(Long stationId) { this.stationId = stationId; } + + public String getStationCode() { + return stationCode; + } + + public void setStationCode(String stationCode) { + this.stationCode = stationCode; + } } diff --git a/hw-auth/src/main/java/com/hw/auth/controller/TokenController.java b/hw-auth/src/main/java/com/hw/auth/controller/TokenController.java index 45f7d9d..3651588 100644 --- a/hw-auth/src/main/java/com/hw/auth/controller/TokenController.java +++ b/hw-auth/src/main/java/com/hw/auth/controller/TokenController.java @@ -44,6 +44,7 @@ public class TokenController // 用户登录 LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); userInfo.setStationId(form.getStationId()); + userInfo.setStationCode(form.getStationCode()); // 获取登录token return R.ok(tokenService.createToken(userInfo)); } diff --git a/hw-auth/src/main/java/com/hw/auth/form/LoginBody.java b/hw-auth/src/main/java/com/hw/auth/form/LoginBody.java index 730d4d6..ac8c72a 100644 --- a/hw-auth/src/main/java/com/hw/auth/form/LoginBody.java +++ b/hw-auth/src/main/java/com/hw/auth/form/LoginBody.java @@ -23,6 +23,10 @@ public class LoginBody */ private Long stationId; + /** + * 工位编号 + */ + private String stationCode; public String getUsername() { @@ -51,4 +55,12 @@ public class LoginBody public void setStationId(Long stationId) { this.stationId = stationId; } + + public String getStationCode() { + return stationCode; + } + + public void setStationCode(String stationCode) { + this.stationCode = stationCode; + } } diff --git a/hw-common/hw-common-core/src/main/java/com/hw/common/core/constant/SecurityConstants.java b/hw-common/hw-common-core/src/main/java/com/hw/common/core/constant/SecurityConstants.java index d797c91..baf312c 100644 --- a/hw-common/hw-common-core/src/main/java/com/hw/common/core/constant/SecurityConstants.java +++ b/hw-common/hw-common-core/src/main/java/com/hw/common/core/constant/SecurityConstants.java @@ -52,4 +52,9 @@ public class SecurityConstants * 工位ID字段 */ public static final String DETAILS_STATION_ID = "station_id"; + + /** + * 工位编码字段 + */ + public static final String DETAILS_STATION_CODE = "station_code"; } diff --git a/hw-common/hw-common-core/src/main/java/com/hw/common/core/context/SecurityContextHolder.java b/hw-common/hw-common-core/src/main/java/com/hw/common/core/context/SecurityContextHolder.java index 4553379..664e38c 100644 --- a/hw-common/hw-common-core/src/main/java/com/hw/common/core/context/SecurityContextHolder.java +++ b/hw-common/hw-common-core/src/main/java/com/hw/common/core/context/SecurityContextHolder.java @@ -107,4 +107,14 @@ public class SecurityContextHolder set(SecurityConstants.DETAILS_STATION_ID, stationId); } + public static String getStationCode() + { + return get(SecurityConstants.DETAILS_STATION_CODE); + } + + public static void setStationCode(String stationCode) + { + set(SecurityConstants.DETAILS_STATION_CODE, stationCode); + } + } diff --git a/hw-common/hw-common-core/src/main/java/com/hw/common/core/utils/JwtUtils.java b/hw-common/hw-common-core/src/main/java/com/hw/common/core/utils/JwtUtils.java index 2a64ac1..00b4e85 100644 --- a/hw-common/hw-common-core/src/main/java/com/hw/common/core/utils/JwtUtils.java +++ b/hw-common/hw-common-core/src/main/java/com/hw/common/core/utils/JwtUtils.java @@ -133,4 +133,14 @@ public class JwtUtils return getValue(claims, SecurityConstants.DETAILS_STATION_ID); } + /** + * 根据身份信息获取工位编号 + * + * @param claims 身份信息 + * @return 工位编号 + */ + public static String getStationCode(Claims claims) + { + return getValue(claims, SecurityConstants.DETAILS_STATION_CODE); + } } diff --git a/hw-common/hw-common-security/src/main/java/com/hw/common/security/interceptor/HeaderInterceptor.java b/hw-common/hw-common-security/src/main/java/com/hw/common/security/interceptor/HeaderInterceptor.java index 0c4de90..48c8d2b 100644 --- a/hw-common/hw-common-security/src/main/java/com/hw/common/security/interceptor/HeaderInterceptor.java +++ b/hw-common/hw-common-security/src/main/java/com/hw/common/security/interceptor/HeaderInterceptor.java @@ -32,6 +32,7 @@ public class HeaderInterceptor implements AsyncHandlerInterceptor SecurityContextHolder.setUserName(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USERNAME)); SecurityContextHolder.setUserKey(ServletUtils.getHeader(request, SecurityConstants.USER_KEY)); SecurityContextHolder.setStationId(ServletUtils.getHeader(request, SecurityConstants.DETAILS_STATION_ID)); + SecurityContextHolder.setStationCode(ServletUtils.getHeader(request, SecurityConstants.DETAILS_STATION_CODE)); String token = SecurityUtils.getToken(); if (StringUtils.isNotEmpty(token)) diff --git a/hw-common/hw-common-security/src/main/java/com/hw/common/security/service/TokenService.java b/hw-common/hw-common-security/src/main/java/com/hw/common/security/service/TokenService.java index 734a69a..899605d 100644 --- a/hw-common/hw-common-security/src/main/java/com/hw/common/security/service/TokenService.java +++ b/hw-common/hw-common-security/src/main/java/com/hw/common/security/service/TokenService.java @@ -62,6 +62,7 @@ public class TokenService claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId); claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName); claimsMap.put(SecurityConstants.DETAILS_STATION_ID, loginUser.getStationId()); + claimsMap.put(SecurityConstants.DETAILS_STATION_CODE, loginUser.getStationCode()); // 接口返回信息 Map rspMap = new HashMap(); diff --git a/hw-common/hw-common-security/src/main/java/com/hw/common/security/utils/SecurityUtils.java b/hw-common/hw-common-security/src/main/java/com/hw/common/security/utils/SecurityUtils.java index 07adddd..bd78504 100644 --- a/hw-common/hw-common-security/src/main/java/com/hw/common/security/utils/SecurityUtils.java +++ b/hw-common/hw-common-security/src/main/java/com/hw/common/security/utils/SecurityUtils.java @@ -48,6 +48,14 @@ public class SecurityUtils return SecurityContextHolder.getStationId(); } + /** + * 获取工位编号 + */ + public static String getStationCode() + { + return SecurityContextHolder.getStationCode(); + } + /** * 获取登录用户信息 */ diff --git a/hw-gateway/src/main/java/com/hw/gateway/filter/AuthFilter.java b/hw-gateway/src/main/java/com/hw/gateway/filter/AuthFilter.java index b3bf281..4348468 100644 --- a/hw-gateway/src/main/java/com/hw/gateway/filter/AuthFilter.java +++ b/hw-gateway/src/main/java/com/hw/gateway/filter/AuthFilter.java @@ -70,6 +70,7 @@ public class AuthFilter implements GlobalFilter, Ordered String userid = JwtUtils.getUserId(claims); String username = JwtUtils.getUserName(claims); String stationId = JwtUtils.getStationId(claims); + String stationCode = JwtUtils.getStationCode(claims); if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) { return unauthorizedResponse(exchange, "令牌验证失败"); @@ -80,6 +81,7 @@ public class AuthFilter implements GlobalFilter, Ordered addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid); addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username); addHeader(mutate, SecurityConstants.DETAILS_STATION_ID, stationId); + addHeader(mutate, SecurityConstants.DETAILS_STATION_CODE, stationCode); // 内部请求来源参数清除 removeHeader(mutate, SecurityConstants.FROM_SOURCE); return chain.filter(exchange.mutate().request(mutate.build()).build()); diff --git a/hw-ui/src/api/login.js b/hw-ui/src/api/login.js index 1dd9e9a..1edec14 100644 --- a/hw-ui/src/api/login.js +++ b/hw-ui/src/api/login.js @@ -1,7 +1,7 @@ import request from '@/utils/request' // 登录方法 -export function login(username, password, code, uuid, stationId) { +export function login(username, password, code, uuid, stationId,stationCode) { return request({ url: '/auth/login', headers: { @@ -9,7 +9,7 @@ export function login(username, password, code, uuid, stationId) { repeatSubmit: false }, method: 'post', - data: {username, password, code, uuid, stationId} + data: {username, password, code, uuid, stationId,stationCode} }) } diff --git a/hw-ui/src/store/modules/user.js b/hw-ui/src/store/modules/user.js index 0f6fbc9..7cee416 100644 --- a/hw-ui/src/store/modules/user.js +++ b/hw-ui/src/store/modules/user.js @@ -43,8 +43,9 @@ const user = { const code = userInfo.code const uuid = userInfo.uuid const stationId = userInfo.stationId || '' + const stationCode = userInfo.stationCode || '' return new Promise((resolve, reject) => { - login(username, password, code, uuid,stationId).then(res => { + login(username, password, code, uuid,stationId,stationCode).then(res => { let data = res.data setToken(data.access_token) commit('SET_TOKEN', data.access_token) diff --git a/hw-ui/src/views/login.vue b/hw-ui/src/views/login.vue index 7a9c971..6cd058b 100644 --- a/hw-ui/src/views/login.vue +++ b/hw-ui/src/views/login.vue @@ -1,7 +1,7 @@