From 179c4d64313c9b7572778da4aaaf6c6584fe457d Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期二, 20 五月 2025 23:48:08 +0800
Subject: [PATCH] 修改文件上传类型限制

---
 springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/controller/BaseController.java |  197 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 179 insertions(+), 18 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 71fd6c9..0af5274 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
@@ -1,14 +1,28 @@
 package com.panzhihua.common.controller;
 
-import com.panzhihua.common.constants.TokenConstant;
-import com.panzhihua.common.constants.UserConstants;
-import com.panzhihua.common.model.vos.LoginUserInfoVO;
-import io.swagger.models.auth.In;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.panzhihua.common.model.vos.community.ComActVO;
+import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo;
+import com.panzhihua.common.utlis.StringUtils;
 import org.springframework.util.ObjectUtils;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
-import javax.servlet.http.HttpServletRequest;
+import com.alibaba.fastjson.JSONObject;
+import com.panzhihua.common.constants.Constants;
+import com.panzhihua.common.constants.TokenConstant;
+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;
+
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+
+import static java.util.Objects.isNull;
+import static org.apache.commons.lang3.StringUtils.isBlank;
 
 /**
  * @program: springcloud_k8s_panzhihuazhihuishequ
@@ -16,39 +30,186 @@
  * @author: huang.hongfa weixin hhf9596 qq 959656820
  * @create: 2020-11-24 09:31
  **/
+@Slf4j
 public class BaseController {
+
     /**
      * 获取request对象
      */
     public HttpServletRequest getRequest() {
-        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+        return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
+    }
+
+
+    /**
+     * 获取request对象
+     */
+    public HttpServletResponse getResponse() {
+        return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();
     }
 
     /**
      * 获取登录对象信息
-     * @return
+     *
+     * @return 对象userid
      */
-    public Long getUserId(){
-        HttpServletRequest request = this.getRequest();
-        Long header = Long.valueOf(request.getHeader(UserConstants.USER_ID));
-        boolean empty = ObjectUtils.isEmpty(header);
-        if (empty) {
-            return null;
+    public Long getUserId() {
+        LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
+        Long userId = loginUserInfo.getUserId();
+        return userId;
+    }
+
+    /**
+     * 获取登录对象所在社区id
+     *
+     * @return 社区id
+     */
+    public Long getCommunityId() {
+        LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
+        Long communityId = loginUserInfo.getCommunityId();
+//        if (null == 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("用户未绑定社区");
         }
-        return header;
+        String communityName = loginUserInfo.getCommunityName();
+        return communityName;
+    }
+
+    /**
+     * 获取登录对象所在小区
+     *
+     * @return 小区id
+     */
+    public Long getAreaId() {
+        LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
+        Long areaId = loginUserInfo.getAreaId();
+        if (null == areaId) {
+            throw new ServiceException("用户未绑定小区");
+        }
+        return areaId;
     }
     /**
-     * 获取登录token
+     * 获取登录对象所在区域编码
+     *
      * @return
      */
-    public String getToken(){
+    public String getAreaCode() {
+        String appid = this.getRequest().getHeader("appid");
+        if(StringUtils.isNotEmpty(appid)){
+            if(appid.equals("wx08932ba29546ff82")){
+                return "510411";
+            }
+            else if(appid.equals("wx50d8c395af50481b")){
+                return "510402";
+            }
+            else {
+                return "510423";
+            }
+        } else {
+            LoginUserInfoVO loginUserInfoVO=this.getLoginUserInfo();
+            ComActVO comActVO=loginUserInfoVO.getComActVO();
+            if(isNull(comActVO) || isBlank(comActVO.getAreaCode())){
+                return "510423";
+            }
+            return comActVO.getAreaCode();
+        }
+    }
+
+
+    /**
+     * 获取登录token
+     *
+     * @return token
+     */
+    public String getToken() {
         HttpServletRequest request = this.getRequest();
         String header = request.getHeader(TokenConstant.TOKEN_LOGOUT);
-        boolean empty = ObjectUtils.isEmpty(header);
+        return header;
+    }
+
+    public String getAppId(){
+        String appid = this.getRequest().getHeader("appid");
+        if(StringUtils.isEmpty(appid)){
+            return "wx0cef797390444b75";
+        }
+        return appid;
+    }
+
+    public String getAppSecret(){
+        LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
+        return loginUserInfo.getAppSecret();
+    }
+    /**
+     * 获取登录对象所有信息
+     *
+     * @return 所有信息
+     */
+    @SneakyThrows
+    public LoginUserInfoVO getLoginUserInfo() {
+        HttpServletRequest request = this.getRequest();
+        String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO);
+        boolean empty = ObjectUtils.isEmpty(userInfo);
+        if (empty) {
+            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;
+    }
+
+    @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;
+    }
+    /**
+     * 获取三个身边管理后台登录用户信息
+     * @return
+     */
+    @SneakyThrows
+    public SystemUserVo getLoginUserInfoSanGeShenBian() {
+        HttpServletRequest request = this.getRequest();
+        String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO);
+        boolean empty = ObjectUtils.isEmpty(userInfo);
         if (empty) {
             return null;
         }
-        return header;
+        byte[] bytes = AES.parseHexStr2Byte(userInfo);
+        byte[] decrypt = AES.decrypt(bytes, Constants.AES_KEY);
+        userInfo = new String(decrypt);
+        SystemUserVo loginUserInfoVO = JSONObject.parseObject(userInfo, SystemUserVo.class);
+        return loginUserInfoVO;
     }
 
 }

--
Gitblit v1.7.1