From ad7865cb29f149777d72700e0c45c0a419afb4b2 Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期一, 16 八月 2021 16:44:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/test' into test
---
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/controller/BaseController.java | 62 +++++++++++++++++++++++++++----
1 files changed, 54 insertions(+), 8 deletions(-)
diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/controller/BaseController.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/controller/BaseController.java
index 45d48f1..6299e69 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/controller/BaseController.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/controller/BaseController.java
@@ -4,6 +4,7 @@
import com.panzhihua.common.constants.Constants;
import com.panzhihua.common.constants.TokenConstant;
import com.panzhihua.common.constants.UserConstants;
+import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.exceptions.UnAuthenticationException;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.utlis.AES;
@@ -13,9 +14,9 @@
import org.springframework.util.ObjectUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
-import sun.security.krb5.internal.crypto.Aes256;
import javax.servlet.http.HttpServletRequest;
+
/**
* @program: springcloud_k8s_panzhihuazhihuishequ
@@ -34,9 +35,10 @@
/**
* 获取登录对象信息
+ *
* @return 对象userid
*/
- public Long getUserId(){
+ public Long getUserId() {
LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
Long userId = loginUserInfo.getUserId();
return userId;
@@ -44,29 +46,53 @@
/**
* 获取登录对象所在社区id
+ *
* @return 社区id
*/
- public Long getCommunityId(){
+ public Long getCommunityId() {
LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
Long communityId = loginUserInfo.getCommunityId();
+ if (null == communityId || 0 == communityId) {
+ throw new ServiceException("用户未绑定社区");
+ }
return communityId;
}
/**
+ * 获取登录对象所在社区名称
+ *
+ * @return 社区名称
+ */
+ public String getCommunityName() {
+ LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
+ Long communityId = loginUserInfo.getCommunityId();
+ if (null == communityId || 0 == communityId) {
+ throw new ServiceException("用户未绑定社区");
+ }
+ String communityName = loginUserInfo.getCommunityName();
+ return communityName;
+ }
+
+ /**
* 获取登录对象所在小区
+ *
* @return 小区id
*/
- public Long getAreaId(){
+ public Long getAreaId() {
LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
Long areaId = loginUserInfo.getAreaId();
+ if (null == areaId || 0 == areaId) {
+ throw new ServiceException("用户未绑定社区");
+ }
return areaId;
}
/**
* 获取登录token
+ *
* @return token
*/
- public String getToken(){
+ public String getToken() {
HttpServletRequest request = this.getRequest();
String header = request.getHeader(TokenConstant.TOKEN_LOGOUT);
return header;
@@ -74,10 +100,11 @@
/**
* 获取登录对象所有信息
+ *
* @return 所有信息
*/
@SneakyThrows
- public LoginUserInfoVO getLoginUserInfo(){
+ public LoginUserInfoVO getLoginUserInfo() {
HttpServletRequest request = this.getRequest();
String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO);
boolean empty = ObjectUtils.isEmpty(userInfo);
@@ -89,8 +116,27 @@
// log.info("bytes【{}】",bytes);
byte[] decrypt = AES.decrypt(bytes, Constants.AES_KEY);
// log.info("decrypt【{}】",decrypt);
- userInfo=new String(decrypt);
- LoginUserInfoVO loginUserInfoVO= JSONObject.parseObject(userInfo,LoginUserInfoVO.class);
+ userInfo = new String(decrypt);
+ LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(userInfo, LoginUserInfoVO.class);
+ return loginUserInfoVO;
+ }
+
+ @SneakyThrows
+ public LoginUserInfoVO getLoginUserInfoSureNoLogin() {
+ HttpServletRequest request = this.getRequest();
+ String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO);
+ boolean empty = ObjectUtils.isEmpty(userInfo);
+ if (empty) {
+ return null;
+// throw new UnAuthenticationException("获取登录人信息失败");
+ }
+// log.info("userInfo【{}】",userInfo);
+ byte[] bytes = AES.parseHexStr2Byte(userInfo);
+// log.info("bytes【{}】",bytes);
+ byte[] decrypt = AES.decrypt(bytes, Constants.AES_KEY);
+// log.info("decrypt【{}】",decrypt);
+ userInfo = new String(decrypt);
+ LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(userInfo, LoginUserInfoVO.class);
return loginUserInfoVO;
}
--
Gitblit v1.7.1