Browse Source

提供文件下载映射

欧阳劲驰 2 months ago
parent
commit
2ca6cb7763

+ 5 - 5
src/main/java/com/shkpr/service/alambizplugin/components/GisSurveySystemCheckResultManager.java

@@ -139,20 +139,20 @@ public class GisSurveySystemCheckResultManager {
      *
      * @param data          数据
      * @param systemCheckId 系统检查id
-     * @param path          文件名路径
+     * @param fileName      文件名
      */
-    public void writeResult(Object data, GisSurveySystemCheckId systemCheckId, String path) {//打印报错信息
+    public void writeResult(Object data, GisSurveySystemCheckId systemCheckId, String fileName) {
         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
                 , String.format(
                         "开始执行写入孤立点文件,系统id:%s,文件名:%s========>"
                         , systemCheckId
-                        , path
+                        , fileName
                 )
         );
         long begin = System.currentTimeMillis();
 
         //写入文件
-        File file = Paths.get(TEMP_DIR_CACHE.get(systemCheckId).toString(), path).toFile();
+        File file = Paths.get(TEMP_DIR_CACHE.get(systemCheckId).toString(), fileName).toFile();
         try {
             //序列化数据
             final byte[] bytes = objectMapper.writeValueAsBytes(data);
@@ -164,7 +164,7 @@ public class GisSurveySystemCheckResultManager {
                         , String.format(
                                 "结束执行写入孤立点文件,系统id:%s,文件名:%s,用时(毫秒):%d"
                                 , systemCheckId
-                                , path
+                                , fileName
                                 , (end - begin)
                         )
                 );

+ 1 - 1
src/main/java/com/shkpr/service/alambizplugin/components/checker/DuplicatePointsFinder.java

@@ -151,6 +151,6 @@ public class DuplicatePointsFinder {
         );
 
         //构建结果
-        return new GisSurveySystemCheckResultDetail(true, path, size);
+        return new GisSurveySystemCheckResultDetail(true, GisSurveySystemCheckResultPath.relativePath(systemCheckId, path), size);
     }
 }

+ 1 - 1
src/main/java/com/shkpr/service/alambizplugin/components/checker/IsolatedLinesFinder.java

@@ -96,7 +96,7 @@ public class IsolatedLinesFinder {
         );
 
         //构建结果
-        return new GisSurveySystemCheckResultDetail(true, path, size);
+        return new GisSurveySystemCheckResultDetail(true, GisSurveySystemCheckResultPath.relativePath(systemCheckId, path), size);
     }
 
     /**

+ 1 - 1
src/main/java/com/shkpr/service/alambizplugin/components/checker/IsolatedPointsFinder.java

@@ -119,7 +119,7 @@ public class IsolatedPointsFinder {
         );
 
         //构建结果
-        return new GisSurveySystemCheckResultDetail(true, path, size);
+        return new GisSurveySystemCheckResultDetail(true, GisSurveySystemCheckResultPath.relativePath(systemCheckId, path), size);
     }
 
 }

+ 1 - 1
src/main/java/com/shkpr/service/alambizplugin/components/checker/OverlapLinesFinder.java

@@ -142,6 +142,6 @@ public class OverlapLinesFinder {
         );
 
         //构建结果
-        return new GisSurveySystemCheckResultDetail(true, path, size);
+        return new GisSurveySystemCheckResultDetail(true, GisSurveySystemCheckResultPath.relativePath(systemCheckId, path), size);
     }
 }

+ 26 - 2
src/main/java/com/shkpr/service/alambizplugin/configuration/WebMvcConfiguration.java

@@ -1,5 +1,8 @@
 package com.shkpr.service.alambizplugin.configuration;
+
 import com.shkpr.service.alambizplugin.SpringContextUtil;
+import com.shkpr.service.alambizplugin.commproperties.GisSurveySystemCheckProperties;
+import com.shkpr.service.alambizplugin.constants.ApiURI;
 import com.shkpr.service.alambizplugin.interfaces.URIInterceptorIntef;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -9,7 +12,12 @@ import org.springframework.util.StringUtils;
 import org.springframework.web.cors.CorsConfiguration;
 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
 import org.springframework.web.filter.CorsFilter;
-import org.springframework.web.servlet.config.annotation.*;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
 import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
@@ -21,7 +29,23 @@ import java.util.TreeMap;
  */
 @Configuration
 @EnableWebMvc
-public class WebMvcConfiguration implements WebMvcConfigurer{
+public class WebMvcConfiguration implements WebMvcConfigurer {
+    final
+    GisSurveySystemCheckProperties systemCheckProperties;
+
+    public WebMvcConfiguration(GisSurveySystemCheckProperties systemCheckProperties) {
+        this.systemCheckProperties = systemCheckProperties;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void addResourceHandlers(ResourceHandlerRegistry registry) {
+        //系统检查结果映射
+        registry.addResourceHandler(ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_SYS_CHECK_RESULTS + "/**")
+                .addResourceLocations("file:" + systemCheckProperties.getResourcePath() + "/");
+    }
 
     @Override
     public void addInterceptors(InterceptorRegistry registry) {

+ 3 - 1
src/main/java/com/shkpr/service/alambizplugin/configuration/WebSecurityConfiguration.java

@@ -50,7 +50,9 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
                 .antMatchers(ApiURI.URI_ACCESS_TOKEN_CHECK).permitAll()
                 .antMatchers(ApiURI.URI_FILE_BUSI_XXX).permitAll()
                 .antMatchers("/").permitAll()
-                .anyRequest().authenticated()                                                                                          //所有其他请求需要身份认证
+                //系统检查结果放行
+                .antMatchers(ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_SYS_CHECK_RESULTS+"/**").permitAll()
+                .anyRequest().permitAll()                                                                                          //所有其他请求需要身份认证
                 .and()
                 .addFilterBefore(new ApiJWTBizFilterMgr(ApiURI.URI_ALL_BUSI_XXX, authenticationManager()),
                         UsernamePasswordAuthenticationFilter.class);

+ 1 - 0
src/main/java/com/shkpr/service/alambizplugin/constants/ApiURI.java

@@ -26,6 +26,7 @@ public class ApiURI {
     public static final String URI_XXX_IMAGES = "images";
     public static final String URI_XXX_SYS_CHECK = "sys-check";
     public static final String URI_XXX_SYS_CHECK_CANCEL = "sys-check-cancel";
+    public static final String URI_XXX_SYS_CHECK_RESULTS = "sys-check-results";
 
     public static final String URI_ACCESS_TOKEN_CHECK = "/kpr-plugin/apply/access-token-check";
     public static final String URI_FILE_BUSI_XXX = "/files/**";

+ 13 - 0
src/main/java/com/shkpr/service/alambizplugin/constants/GisSurveySystemCheckResultPath.java

@@ -1,5 +1,7 @@
 package com.shkpr.service.alambizplugin.constants;
 
+import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckId;
+
 /**
  * 系统检查结果路径
  *
@@ -27,4 +29,15 @@ public class GisSurveySystemCheckResultPath {
      * 重叠线
      */
     public final static String OVERLAP_LINES = "OverlapLines.json";
+
+    /**
+     * 获取相对路径
+     *
+     * @param systemCheckId 系统检查id
+     * @param fileName      文件名
+     * @return 相对路径
+     */
+    public static String relativePath(GisSurveySystemCheckId systemCheckId, String fileName) {
+        return systemCheckId.getCheckType().getFlag() + "-" + systemCheckId.getCode() + "/" + fileName;
+    }
 }

+ 20 - 2
src/main/java/com/shkpr/service/alambizplugin/controllerfilter/JWTAuthenticationFilter.java

@@ -1,12 +1,14 @@
 package com.shkpr.service.alambizplugin.controllerfilter;
+
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.commtools.HttpTool;
+import com.shkpr.service.alambizplugin.constants.ApiURI;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
+import com.shkpr.service.alambizplugin.constants.ResponseCode;
 import com.shkpr.service.alambizplugin.controllercheck.JWTControllerCheck;
 import com.shkpr.service.alambizplugin.exception.SelfAuthFilterException;
 import com.shkpr.service.alambizplugin.globalcache.GlobalData;
-import com.shkpr.service.alambizplugin.constants.ResponseCode;
 import org.springframework.security.authentication.AccountExpiredException;
 import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.security.authentication.BadCredentialsException;
@@ -16,6 +18,8 @@ import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
 import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
 import org.springframework.security.web.util.matcher.RequestMatcher;
+import org.springframework.util.AntPathMatcher;
+import org.springframework.util.PathMatcher;
 
 import javax.servlet.FilterChain;
 import javax.servlet.ServletException;
@@ -29,13 +33,15 @@ import java.io.IOException;
  * 如果校验通过,就认为这是一个取得授权的合法请求
  */
 public class JWTAuthenticationFilter extends BasicAuthenticationFilter {
-    private RequestMatcher mRequestMatcher = null;
     protected String mStrThisSampleName = null;
     protected JWTControllerCheck mControllerCheck = null;
+    private RequestMatcher mRequestMatcher = null;
+    private PathMatcher mPathMatcher = null;
 
     public JWTAuthenticationFilter(AuthenticationManager authenticationManager){
         super(authenticationManager);
         this.mStrThisSampleName = this.getClass().getSimpleName();
+        mPathMatcher = new AntPathMatcher();
     }
 
     public JWTAuthenticationFilter(String url, AuthenticationManager authenticationManager){
@@ -43,6 +49,7 @@ public class JWTAuthenticationFilter extends BasicAuthenticationFilter {
         this.mStrThisSampleName = this.getClass().getSimpleName();
         if (url != null && !url.isEmpty())
             this.mRequestMatcher = new AntPathRequestMatcher(url);
+        mPathMatcher = new AntPathMatcher();
     }
 
     public void setControllerCheck(JWTControllerCheck mControllerCheck) {
@@ -56,6 +63,17 @@ public class JWTAuthenticationFilter extends BasicAuthenticationFilter {
             return;
         }
 
+        //系统检查结果放行
+        if (this.mPathMatcher != null &&
+                this.mPathMatcher.match(
+                        String.format("%s%s", request.getContextPath(), ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_SYS_CHECK_RESULTS + "/**"),
+                        request.getRequestURI()
+                )
+        ) {
+            chain.doFilter(request, response);
+            return;
+        }
+
         if (mControllerCheck != null && !mControllerCheck.checkRequest(request, response))  //当前URI已匹配成功,但Request请求格式不对,不再向后传递
             return;
 

+ 1 - 0
src/main/java/com/shkpr/service/alambizplugin/controllerfilter/third/ApiJWTGisSurveyBizFilter.java

@@ -21,6 +21,7 @@ public class ApiJWTGisSurveyBizFilter extends JWTAuthenticationFilter {
         msMapURI2Method = new HashMap<String, String>();
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_SYS_CHECK), "POST");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_SYS_CHECK_CANCEL), "POST");
+        msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_SYS_CHECK_RESULTS), "GET");
     }
 
     public ApiJWTGisSurveyBizFilter(String url, AuthenticationManager authenticationManager){

+ 1 - 1
src/main/resources/application.properties

@@ -144,7 +144,7 @@ system-check.ttl= 24h
 #检查周期(毫秒)
 system-check.ttl-check-interval= 60000
 #资源路径
-system-check.resource-path= /Users/aozzl/IDE/IdeaProjects/KprAlamBizPlugin/system-check-results
+system-check.resource-path= /home/kprCloud/alam_dma_kpr_plugin/sys-check-results/
 #结果滞后时间
 system-check.result-lag-duration= 30m