From cddcf22a61489ee9c2dfee169d817ccd66f95430 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期五, 03 九月 2021 02:23:43 +0800
Subject: [PATCH] 优化代码

---
 service-front/src/main/java/com/java110/front/controller/app/AppController.java |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/service-front/src/main/java/com/java110/front/controller/app/AppController.java b/service-front/src/main/java/com/java110/front/controller/app/AppController.java
old mode 100644
new mode 100755
index 264d67b..1cadca3
--- a/service-front/src/main/java/com/java110/front/controller/app/AppController.java
+++ b/service-front/src/main/java/com/java110/front/controller/app/AppController.java
@@ -1,7 +1,23 @@
+/*
+ * Copyright 2017-2020 鍚村鏂� and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.java110.front.controller.app;
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.base.controller.BaseController;
+import com.java110.core.context.IPageData;
 import com.java110.front.smo.api.IApiSMO;
 import com.java110.utils.constant.CommonConstant;
 import io.swagger.annotations.ApiImplicitParam;
@@ -12,6 +28,7 @@
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.HashMap;
@@ -33,6 +50,9 @@
 
     @Autowired
     private IApiSMO apiSMOImpl;
+
+    @Autowired
+    private RestTemplate restTemplate;
 
     /**
      * 璧勬簮璇锋眰 post鏂瑰紡
@@ -60,6 +80,8 @@
             headers.put(CommonConstant.HTTP_SERVICE, service);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_POST);
             logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", service, postInfo, headers);
+            IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
+            hasPrivilege(restTemplate, pd, "/app/" + service);
             responseEntity = apiSMOImpl.doApi(postInfo, headers, request);
         } catch (Throwable e) {
             logger.error("璇锋眰post 鏂规硶[" + service + "]澶辫触锛�" + postInfo, e);
@@ -90,6 +112,8 @@
             headers.put(CommonConstant.HTTP_SERVICE, service);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_GET);
             logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", "", headers);
+            IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
+            hasPrivilege(restTemplate, pd, "/app/" + service);
             responseEntity = apiSMOImpl.doApi(JSONObject.toJSONString(getParameterStringMap(request)), headers, request);
         } catch (Throwable e) {
             logger.error("璇锋眰get 鏂规硶[" + service + "]澶辫触锛�", e);
@@ -123,6 +147,8 @@
             headers.put(CommonConstant.HTTP_ACTION, action);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_GET);
             logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", "", headers);
+            IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
+            hasPrivilege(restTemplate, pd, "/app/" + resource + "/" + action);
             responseEntity = apiSMOImpl.doApi(JSONObject.toJSONString(getParameterStringMap(request)), headers, request);
         } catch (Throwable e) {
             logger.error("璇锋眰get 鏂规硶[" + action + "]澶辫触锛�", e);
@@ -158,6 +184,8 @@
             headers.put(CommonConstant.HTTP_ACTION, action);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_POST);
             logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", action, postInfo, headers);
+            IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
+            hasPrivilege(restTemplate, pd, "/app/" + resource + "/" + action);
             responseEntity = apiSMOImpl.doApi(postInfo, headers, request);
         } catch (Throwable e) {
             logger.error("璇锋眰post 鏂规硶[" + action + "]澶辫触锛�" + postInfo, e);
@@ -190,6 +218,8 @@
             headers.put(CommonConstant.HTTP_SERVICE, service);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_PUT);
             logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", service, postInfo, headers);
+            IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
+            hasPrivilege(restTemplate, pd, "/app/" + service );
             responseEntity = apiSMOImpl.doApi(postInfo, headers, request);
         } catch (Throwable e) {
             logger.error("璇锋眰put 鏂规硶[" + service + "]澶辫触锛�", e);
@@ -219,7 +249,8 @@
             headers.put(CommonConstant.HTTP_SERVICE, service);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_DELETE);
             logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", service, "", headers);
-
+            IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
+            hasPrivilege(restTemplate, pd, "/app/" + service );
             responseEntity = apiSMOImpl.doApi(JSONObject.toJSONString(getParameterStringMap(request)), headers, request);
         } catch (Throwable e) {
             logger.error("璇锋眰delete 鏂规硶[" + service + "]澶辫触锛�", e);

--
Gitblit v1.8.0