瀏覽代碼

更换上传s3目录

lyhzzz 3 年之前
父節點
當前提交
4d06e6dfea

+ 4 - 0
src/main/java/com/cdf/config/WebAppConfig.java

@@ -2,6 +2,7 @@ package com.cdf.config;
 
 import com.cdf.interceptor.BackUserInterceptor;
 import com.cdf.interceptor.SceneInterceptor;
+import com.cdf.interceptor.TokenInterceptor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
@@ -17,6 +18,8 @@ public class WebAppConfig implements WebMvcConfigurer {
 	BackUserInterceptor backUserInterceptor;
 	@Autowired
 	SceneInterceptor sceneInterceptor;
+	@Autowired
+	TokenInterceptor tokenInterceptor;
 
 	@Override
 	public void addCorsMappings(CorsRegistry registry) {
@@ -26,6 +29,7 @@ public class WebAppConfig implements WebMvcConfigurer {
 
 	@Override
 	public void addInterceptors(InterceptorRegistry registry) {
+		//registry.addInterceptor(tokenInterceptor).addPathPatterns("/**").excludePathPatterns("/**/login/**");
 		registry.addInterceptor(backUserInterceptor).addPathPatterns("/back/**").excludePathPatterns("/**/login/**");
 		registry.addInterceptor(sceneInterceptor).addPathPatterns("/service/**")
 				.excludePathPatterns("/service/scene/edit/tag/save","/service/scene/edit/tag/delete",

+ 5 - 4
src/main/java/com/cdf/controller/back/UploadController.java

@@ -3,7 +3,8 @@ package com.cdf.controller.back;
 import com.cdf.common.ResultCode;
 import com.cdf.common.ResultData;
 import com.cdf.exception.BusinessException;
-import com.cdf.util.UploadToOssUtil;
+import com.cdf.util.UploadToCdfOssUtil;
+import com.cdf.util.UploadToFdkkOssUtil;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -20,7 +21,7 @@ import java.util.UUID;
 public class UploadController {
 
     @Resource
-    private UploadToOssUtil uploadToOssUtil;
+    private UploadToCdfOssUtil uploadToCdfOssUtil;
 
     @Value("${upload.file-path}")
     private String filePath;
@@ -46,8 +47,8 @@ public class UploadController {
         File localFile = File.createTempFile(fileName,suffixName);
         file.transferTo(localFile);
         String path = localFile.getPath();
-        uploadToOssUtil.upload(path,filePath + fileName + suffixName);
-        if(!uploadToOssUtil.existKey(filePath + fileName + suffixName)){
+        uploadToCdfOssUtil.upload(path,filePath + fileName + suffixName);
+        if(!uploadToCdfOssUtil.existKey(filePath + fileName + suffixName)){
             throw new BusinessException(ResultCode.UPLOAD_ERROR);
         }
         return ResultData.ok( queryPath + filePath + fileName + suffixName);

+ 1 - 2
src/main/java/com/cdf/interceptor/BackUserInterceptor.java

@@ -1,7 +1,6 @@
 package com.cdf.interceptor;
 
 
-import cn.hutool.jwt.JWTUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.cdf.common.ResultCode;
 import com.cdf.common.ResultData;
@@ -48,7 +47,7 @@ public class BackUserInterceptor implements HandlerInterceptor {
 		}
 	}
 
-	public boolean checkUser(String token,HttpServletRequest request, HttpServletResponse response){
+	public boolean checkUser(String token,HttpServletRequest request, HttpServletResponse response) throws Exception {
 		Integer userId = JwtUtil.getId(token);
 		User user = userService.getById(userId);
 		LambdaQueryWrapper<UserToken> wrapper = new LambdaQueryWrapper<>();

+ 60 - 0
src/main/java/com/cdf/interceptor/TokenInterceptor.java

@@ -0,0 +1,60 @@
+package com.cdf.interceptor;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.cdf.common.ResultCode;
+import com.cdf.common.ResultData;
+import com.cdf.entity.User;
+import com.cdf.entity.UserToken;
+import com.cdf.service.IUserService;
+import com.cdf.service.IUserTokenService;
+import com.cdf.util.DateUtil;
+import com.cdf.util.JwtUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+@Component
+public class TokenInterceptor implements HandlerInterceptor {
+
+	private static final Log log = LogFactory.getLog("programLog");
+
+	@Autowired
+	private IUserService userService;
+	@Autowired
+	private IUserTokenService userTokenService;
+
+	@Override
+	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+		response.setContentType("text/html;charset=UTF-8");
+		String token = request.getHeader("token");
+		if(StringUtils.isEmpty(token)){
+			return true;
+		}
+		LambdaQueryWrapper<UserToken> wrapper = new LambdaQueryWrapper<>();
+		wrapper.eq(UserToken::getLoginToken,token);
+		List<UserToken> list = userTokenService.list(wrapper);
+		if(list!=null && list.size() >0){
+			UserToken userToken = list.get(0);
+			long time = new Date().getTime() - DateUtil.getDateTime(userToken.getUpdateTime());
+			if(time > 60 * 60 *1000){
+				userTokenService.removeById(userToken);
+			}else {
+				userToken.setUpdateTime(DateUtil.getDateTime(new Date()));
+				userTokenService.updateById(userToken);
+			}
+		}
+		return true;
+	}
+
+}
+

+ 7 - 13
src/main/java/com/cdf/service/impl/FdkkSceneEditService.java

@@ -1,11 +1,9 @@
 package com.cdf.service.impl;
 
 import cn.hutool.json.JSONUtil;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.cdf.common.ResultCode;
-import com.cdf.entity.FdkkUser;
 import com.cdf.entity.HotRelation;
 import com.cdf.exception.BusinessException;
 import com.cdf.httpClient.client.CdfClient;
@@ -16,7 +14,6 @@ import com.cdf.httpClient.request.FdkkUploadRequest;
 import com.cdf.httpClient.request.SceneRequest;
 import com.cdf.httpClient.response.FdkkResponse;
 import com.cdf.httpClient.response.cdf.*;
-import com.cdf.service.IFdkkUserService;
 import com.cdf.service.IHotRelationService;
 import com.cdf.util.*;
 import com.google.zxing.client.j2se.MatrixToImageWriter;
@@ -26,7 +23,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
@@ -35,15 +31,14 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.IOException;
 import java.util.*;
-import java.util.stream.Collectors;
 
 @Service
 @Slf4j
 public class FdkkSceneEditService {
     @Resource
-    private UploadToOssUtil uploadToOssUtil;
-    @Value("${upload.bucket}")
-    private String bucket;
+    private UploadToFdkkOssUtil uploadToFdkkOssUtil;
+    @Resource
+    private UploadToCdfOssUtil uploadToCdfOssUtil;
     @Value("${fdkk.hot-path}")
     private String hotPath;
     @Value("${fdkk.hot-cdf-path}")
@@ -132,7 +127,7 @@ public class FdkkSceneEditService {
     }
 
     public JSONArray getHotJson(String num) {
-        String data = uploadToOssUtil.getObjectContent(bucket, String.format(hotPath, num) );
+        String data = uploadToFdkkOssUtil.getObjectContent(String.format(hotPath, num) );
         if(StringUtils.isBlank(data)){
             throw new BusinessException(ResultCode.NOT_RECORD);
         }
@@ -141,9 +136,9 @@ public class FdkkSceneEditService {
     }
 
     public JSONArray getCdfHotJson(String num) {
-        String data = uploadToOssUtil.getObjectContent(bucket, String.format(hotCdfPath, num));
+        String data = uploadToCdfOssUtil.getObjectContent(String.format(hotCdfPath, num));
         if(StringUtils.isBlank(data)){
-            data = uploadToOssUtil.getObjectContent(bucket, String.format(hotPath, num));
+            data = uploadToFdkkOssUtil.getObjectContent( String.format(hotPath, num));
         }
         if(StringUtils.isBlank(data)){
             throw new BusinessException(ResultCode.NOT_RECORD);
@@ -158,7 +153,6 @@ public class FdkkSceneEditService {
             throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
         }
         writeHotJson(fdkkHotRequest.getNum());
-        //ReadCmdLine.callShellByExec("aws s3 sync s3://4dkankan/cdf s3://4dage-moderate2/cdf --profile user1");
     }
 
     public void writeHotJson(String num) throws IOException {
@@ -166,7 +160,7 @@ public class FdkkSceneEditService {
         String path = String.format(hotLocalPath,num)+"/"+"hot.json";
         String json = JSONUtil.toJsonStr(hotJson);
         FileUtils.writeFile(path,json );
-        uploadToOssUtil.upload(path,String.format(hotCdfPath, num));
+        uploadToCdfOssUtil.upload(path,String.format(hotCdfPath, num));
     }
     public FdkkResponse uploadFiles(FdkkUploadRequest fdkkUploadRequest, MultipartFile[] files, String token) throws IOException {
         List<MultipartFile> multipartFiles = new ArrayList<>();

文件差異過大導致無法顯示
+ 1057 - 0
src/main/java/com/cdf/util/UploadToCdfOssUtil.java


+ 7 - 8
src/main/java/com/cdf/util/UploadToOssUtil.java

@@ -39,7 +39,7 @@ import java.util.stream.Collectors;
 
 @Slf4j
 @Component
-public class UploadToOssUtil {
+public class UploadToFdkkOssUtil {
 
 
 	@Value("${oss.point:http://oss-cn-shenzhen-internal.aliyuncs.com}")
@@ -60,13 +60,13 @@ public class UploadToOssUtil {
 	@Value("${upload.type:oss}")
 	private String type;
 
-	@Value("${aws.s3key:AKIAWCV5QFZ3ZNELKYUY}")
+	@Value("${fdkk.aws.s3key:AKIAWCV5QFZ3ZNELKYUY}")
 	private String s3key;
 
-	@Value("${aws.s3secrey:epS5ghyR4LJ7rxk/qJO9ZYh6m9Oz6g5haKDu4yws}")
+	@Value("${fdkk.aws.s3secrey:epS5ghyR4LJ7rxk/qJO9ZYh6m9Oz6g5haKDu4yws}")
 	private String s3secrey;
 
-	@Value("${aws.s3bucket:4dkankan}")
+	@Value("${fdkk.aws.s3bucket:4dkankan}")
 	private String s3bucket;
 
 	@Value("${local.path:/home/4dkankan}")
@@ -826,17 +826,16 @@ public class UploadToOssUtil {
 
 	/**
 	 * 获取文件内容
-	 * @param bucketName
 	 * @param objectName
 	 * @return
 	 */
-	public String getObjectContent(String bucketName, String objectName){
+	public String getObjectContent( String objectName){
 		StorageType storageType = StorageType.get(type);
 		switch (storageType){
 			case OSS:
-				return this.getObjectContentFromAli(bucketName, objectName);
+				return this.getObjectContentFromAli(bucket, objectName);
 			case AWS:
-				return this.getObjectContentFromAws(bucketName, objectName);
+				return this.getObjectContentFromAws(bucket, objectName);
 			case LOCAL:
 				return this.getObjectContentFromLocal(objectName);
 		}

+ 0 - 48
src/main/resources/application-cnpord.yaml

@@ -1,48 +0,0 @@
-spring:
-  datasource:
-    name: druidDataSource
-    type: com.alibaba.druid.pool.DruidDataSource
-    druid:
-      url: jdbc:mysql://127.0.0.1:3306/cdf_gm?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true
-      username: root
-      password: 4Dage@zhongmian#@168
-logging:
-  config: classpath:logback-spring.xml
-mybatis-plus:
-  configuration:
-    log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl #开启sql日志
-
-
-fdkk:
-  login-path: http://www.4dkankan.com
-  scene-path: http://www.4dkankan.com
-  hot-path: scene_view_data/%s/user/hot.json
-  hot-cdf-path: cdf/hot/%s/hot.json
-  hot-local-path: /home/cdf/fdkk/%s
-  qr-code-url: http://vr.cdfmembers.com/index.html?m=
-#    type: oss      阿里云 oss
-#    type: aws      亚马逊 s3
-#    type: local    本地化
-upload:
-  type: oss
-  file-path: cdf/file/
-  bucket: 4dkankan
-  query-path: https://4dkk.4dage.com/     #oss
-oss:
-  point: http://oss-cn-shenzhen.aliyuncs.com
-  key: LTAIUrvuHqj8pvry
-  secrey: JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4
-  bucket: 4dkankan
-  sdk: 4dscene
-  prefix:
-    ali: https://4dkk.4dage.com/
-    sdk: https://4dscene.4dage.com/
-    url: https://4dkk.4dage.com/
-
-aws:
-  s3key: AKIAWCV5QFZ3ZNELKYUY
-  s3secrey: epS5ghyR4LJ7rxk/qJO9ZYh6m9Oz6g5haKDu4yws
-  s3bucket: 4dkankan
-
-local:
-  path: /home/4dkankan/

+ 0 - 49
src/main/resources/application-dev.yaml

@@ -1,49 +0,0 @@
-spring:
-  datasource:
-    name: druidDataSource
-    type: com.alibaba.druid.pool.DruidDataSource
-    druid:
-      url: jdbc:mysql://127.0.0.1:3306/cdf_gm?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true
-      username: root
-      password: 4Dage@zhongmian#@168
-logging:
-  config: classpath:logback-spring.xml
-mybatis-plus:
-  configuration:
-    log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl #开启sql日志
-
-
-fdkk:
-  login-path: http://eur.4dkankan.com
-  scene-path: http://eur.4dkankan.com
-  hot-path: scene_view_data/%s/user/hot.json
-  hot-cdf-path: cdf/hot/%s/hot.json
-  hot-local-path: /home/cdf/fdkk/%s
-  qr-code-url: http://vr.cdfmembers.com/index.html?m=
-#    type: oss      阿里云 oss
-#    type: aws      亚马逊 s3
-#    type: local    本地化
-upload:
-  type: aws
-  file-path: cdf/file/
-  bucket: 4dkankan
-  #query-path: http://4dkankan.oss-cn-shenzhen.aliyuncs.com/     #oss
-  query-path: https://eurs3.4dkankan.com/
-oss:
-  point: http://oss-cn-shenzhen.aliyuncs.com
-  key: LTAIUrvuHqj8pvry
-  secrey: JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4
-  bucket: 4dkankan
-  sdk: 4dscene
-  prefix:
-    ali: https://4dkk.4dage.com/
-    sdk: https://4dscene.4dage.com/
-    url: https://4dkk.4dage.com/
-
-aws:
-  s3key: AKIAWCV5QFZ3ZNELKYUY
-  s3secrey: epS5ghyR4LJ7rxk/qJO9ZYh6m9Oz6g5haKDu4yws
-  s3bucket: 4dkankan
-
-local:
-  path: /home/4dkankan/

+ 12 - 20
src/main/resources/application-eurpord.yaml

@@ -20,29 +20,21 @@ fdkk:
   hot-cdf-path: cdf/hot/%s/hot.json
   hot-local-path: /home/cdf/fdkk/%s
   qr-code-url: http://vr.cdfmembers.com/index.html?m=
-#    type: oss      阿里云 oss
-#    type: aws      亚马逊 s3
-#    type: local    本地化
+  aws:
+    s3key: AKIAWCV5QFZ3ZNELKYUY
+    s3secrey: epS5ghyR4LJ7rxk/qJO9ZYh6m9Oz6g5haKDu4yws
+    s3bucket: 4dkankan
+
+cdf:
+  aws:
+    s3key: AKIAUI25IY4RAEMUZCOQ
+    s3secrey: CeL0IMH+I0qMxLXBRRs3cbRh9DeVOeTMy8wa60o7
+    s3bucket: 4dage-moderate2
+
 upload:
   type: aws
   file-path: cdf/file/
-  bucket: 4dkankan
-  query-path: https://eurs3.4dkankan.com/
-oss:
-  point: http://oss-cn-shenzhen.aliyuncs.com
-  key: LTAIUrvuHqj8pvry
-  secrey: JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4
-  bucket: 4dkankan
-  sdk: 4dscene
-  prefix:
-    ali: https://4dkk.4dage.com/
-    sdk: https://4dscene.4dage.com/
-    url: https://4dkk.4dage.com/
-
-aws:
-  s3key: AKIAWCV5QFZ3ZNELKYUY
-  s3secrey: epS5ghyR4LJ7rxk/qJO9ZYh6m9Oz6g5haKDu4yws
-  s3bucket: 4dkankan
+  query-path: http://glp-vr.cdfmembers.com/
 
 local:
   path: /home/4dkankan/

+ 15 - 25
src/main/resources/application-local.yaml

@@ -14,37 +14,27 @@ mybatis-plus:
 
 
 fdkk:
-  login-path: http://www.4dkankan.com
-  scene-path: http://www.4dkankan.com
+  login-path: http://eur.4dkankan.com
+  scene-path: http://eur.4dkankan.com
   hot-path: scene_view_data/%s/user/hot.json
   hot-cdf-path: cdf/hot/%s/hot.json
-  hot-local-path: D:\temp/%s
+  hot-local-path: /home/cdf/fdkk/%s
   qr-code-url: http://vr.cdfmembers.com/index.html?m=
+  aws:
+    s3key: AKIAWCV5QFZ3ZNELKYUY
+    s3secrey: epS5ghyR4LJ7rxk/qJO9ZYh6m9Oz6g5haKDu4yws
+    s3bucket: 4dkankan
+
+cdf:
+  aws:
+    s3key: AKIAUI25IY4RAEMUZCOQ
+    s3secrey: CeL0IMH+I0qMxLXBRRs3cbRh9DeVOeTMy8wa60o7
+    s3bucket: 4dage-moderate2
 
-#    type: oss      阿里云 oss
-#    type: aws      亚马逊 s3
-#    type: local    本地化
 upload:
-  type: oss
+  type: aws
   file-path: cdf/file/
-  bucket: 4dkankan
-  query-path: https://4dkk.4dage.com/   #oss
-  #query-path: https://eurs3.4dkankan.com/
-oss:
-  point: http://oss-cn-shenzhen.aliyuncs.com
-  key: LTAIUrvuHqj8pvry
-  secrey: JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4
-  bucket: 4dkankan
-  sdk: 4dscene
-  prefix:
-    ali: https://4dkk.4dage.com/
-    sdk: https://4dscene.4dage.com/
-    url: https://4dkk.4dage.com/
-
-aws:
-  s3key: AKIAWCV5QFZ3ZNELKYUY
-  s3secrey: epS5ghyR4LJ7rxk/qJO9ZYh6m9Oz6g5haKDu4yws
-  s3bucket: 4dkankan
+  query-path: http://glp-vr.cdfmembers.com/
 
 local:
   path: /home/4dkankan/