Kaynağa Gözat

Merge remote-tracking branch 'origin/develop' into develop

lijie 3 yıl önce
ebeveyn
işleme
875b2d35b5

Dosya farkı çok büyük olduğundan ihmal edildi
+ 38 - 6972
dmp-business/dmp-dic/src/main/resources/db/init/data.sql


+ 0 - 1
dmp-comp/dmp-file-starter/pom.xml

@@ -16,7 +16,6 @@
         <dependency>
             <groupId>io.minio</groupId>
             <artifactId>minio</artifactId>
-            <version>7.0.2</version>
         </dependency>
         <!-- fm 工具包 -->
         <dependency>

+ 6 - 7
dmp-comp/dmp-file-starter/src/main/java/com/persagy/dmp/storage/config/MinioConfig.java

@@ -1,8 +1,6 @@
 package com.persagy.dmp.storage.config;
 
-import com.persagy.dmp.common.exception.BusinessException;
 import io.minio.MinioClient;
-import io.minio.errors.MinioException;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -27,10 +25,11 @@ public class MinioConfig {
 
     @Bean
     public MinioClient minioClient() {
-        try {
-            return new MinioClient(url, accessKey, secretKey);
-        } catch (MinioException e) {
-            throw new BusinessException(e.getMessage(), e);
-        }
+//        try {
+//            return new MinioClient(url, accessKey, secretKey);
+            return MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build();
+//        } catch (MinioException e) {
+//            throw new BusinessException(e.getMessage(), e);
+//        }
     }
 }

+ 3 - 3
dmp-comp/dmp-file-starter/src/main/java/com/persagy/dmp/storage/service/impl/MinioExceptionHandler.java

@@ -31,9 +31,9 @@ public class MinioExceptionHandler {
         if(e instanceof InvalidResponseException) {
             throw new BusinessException("文件服务器密钥有误");
         }
-        if(e instanceof InvalidBucketNameException) {
-            throw new BusinessException("文件服务器-不合法的存储桶名称。");
-        }
+//        if(e instanceof InvalidBucketNameException) {
+//            throw new BusinessException("文件服务器-不合法的存储桶名称。");
+//        }
         if(e instanceof ErrorResponseException) {
             throw new BusinessException("文件服务器-执行失败异常。");
         }

+ 21 - 12
dmp-comp/dmp-file-starter/src/main/java/com/persagy/dmp/storage/service/impl/MinioStorageServiceImpl.java

@@ -4,9 +4,7 @@ import cn.hutool.core.util.StrUtil;
 import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.storage.constant.FileCommonConst;
 import com.persagy.dmp.storage.service.IFileStorageService;
-import io.minio.MinioClient;
-import io.minio.ObjectStat;
-import io.minio.PutObjectOptions;
+import io.minio.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -35,8 +33,10 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 上传文件
-            PutObjectOptions options = new PutObjectOptions(input.available(), -1);
-            minioClient.putObject(bucketName, fileName, input, options);
+//            PutObjectOptions options = new PutObjectOptions(input.available(), -1);
+//            minioClient.putObject(bucketName, fileName, input, options);
+            minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(fileName).
+                            stream(input, input.available(), -1).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -52,7 +52,8 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 下载文件
-            return minioClient.getObject(bucketName, fileName);
+//            return minioClient.getObject(bucketName, fileName);
+            return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(fileName).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -69,7 +70,9 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 下载文件
-            return minioClient.presignedGetObject(bucketName, fileName, FileCommonConst.URL_EXPIRES);
+//            return minioClient.presignedGetObject(bucketName, fileName, FileCommonConst.URL_EXPIRES);
+            return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
+                    .bucket(bucketName).object(fileName).expiry(FileCommonConst.URL_EXPIRES).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -86,7 +89,9 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 查看文件元数据
-            ObjectStat stat = minioClient.statObject(bucketName, fileName);
+//            ObjectStat stat = minioClient.statObject(bucketName, fileName);
+//            return stat != null;
+            StatObjectResponse stat = minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(fileName).build());
             return stat != null;
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
@@ -104,7 +109,8 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 删除文件
-            minioClient.removeObject(bucketName, fileName);
+//            minioClient.removeObject(bucketName, fileName);
+            minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(fileName).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -120,7 +126,8 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 删除桶
-            minioClient.removeBucket(bucketName);
+//            minioClient.removeBucket(bucketName);
+            minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -138,12 +145,14 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             bucketName = FileCommonConst.DEFAULT_BUCKET;
         }
         log.info("开始检查桶名:[{0}]是否存在", bucketName);
-        boolean isExist = minioClient.bucketExists(bucketName);
+//        boolean isExist = minioClient.bucketExists(bucketName);
+        boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
         if(isExist) {
             log.info("桶名:[{0}]已存在", bucketName);
             return bucketName;
         }
-        minioClient.makeBucket(bucketName);
+//        minioClient.makeBucket(bucketName);
+        minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
         log.info("桶名:[{0}]不存在,创建成功", bucketName);
         return bucketName;
     }

+ 21 - 1
dmp-parent/pom.xml

@@ -39,7 +39,7 @@
         <tomcat-jdbc.version>9.0.31</tomcat-jdbc.version>
         <HikariCP.version>3.2.0</HikariCP.version>
         <mysql.version>8.0.15</mysql.version>
-        <guava.version>27.0.1-jre</guava.version>
+        <guava.version>30.0-jre</guava.version>
         <spring.version>5.1.15.RELEASE</spring.version>
         <spring-cloud-dependencies.version>Greenwich.SR6</spring-cloud-dependencies.version>
         <spring-data.version>2.1.17.RELEASE</spring-data.version>
@@ -50,6 +50,10 @@
         <fastjson.version>1.2.47</fastjson.version>
         <druid.version>1.1.22</druid.version>
         <hutool.version>5.5.8</hutool.version>
+        <!-- Minio -->
+        <minio.version>8.3.0</minio.version>
+        <okhttp.version>4.8.1</okhttp.version>
+        <kotlin.version>1.3.70</kotlin.version>
         <!-- Plugins -->
         <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
         <spring-boot-maven-plugin.version>2.4.3</spring-boot-maven-plugin.version>
@@ -308,6 +312,22 @@
                 <artifactId>fastjson</artifactId>
                 <version>${fastjson.version}</version>
             </dependency>
+            <!-- Minio -->
+            <dependency>
+                <groupId>io.minio</groupId>
+                <artifactId>minio</artifactId>
+                <version>${minio.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.squareup.okhttp3</groupId>
+                <artifactId>okhttp</artifactId>
+                <version>${okhttp.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.jetbrains.kotlin</groupId>
+                <artifactId>kotlin-stdlib-common</artifactId>
+                <version>${kotlin.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 

+ 28 - 19
dmp-server/src/main/java/com/persagy/aspects/RequestLogAspect.java

@@ -1,9 +1,11 @@
 package com.persagy.aspects;
 
+import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.servlet.ServletUtil;
 import com.persagy.dmp.common.model.response.CommonResult;
-import com.persagy.utils.JacksonMapper;
+import com.persagy.dmp.common.utils.JsonHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.*;
@@ -48,25 +50,27 @@ public class RequestLogAspect {
 		LogData data = initFlag(request);
 		dataStorage.set(data);
 		log.info("{} REQUEST URL      : {} {} {} {}", data.intFlag, data.method, data.url, data.remoteIp, data.remotePort);
-		log.info("{} REQUEST ARGS     : {} ", data.intFlag, JacksonMapper.toSimpleJson(prepare(joinPoint)));
+		log.info("{} REQUEST ARGS     : {} ", data.intFlag, JsonHelper.toJsonStrQuietly(prepare(joinPoint)));
 	}
 
+	/**
+	 * 准备数据
+	 * @param joinPoint
+	 * @return
+	 */
 	public static List<Object> prepare(JoinPoint joinPoint) {
 		Object[] args = joinPoint.getArgs();
 		List<Object> list = new LinkedList<>();
-		if (args != null && args.length > 0) {
-			for (Object arg : args) {
-				if (arg instanceof ServletRequest) {
-					continue;
-				}
-				if (arg instanceof ServletResponse) {
-					continue;
-				}
-				if (arg instanceof MultipartFile) {
-					continue;
-				}
-				list.add(arg);
+		if(ArrayUtil.isEmpty(args)) {
+			return list;
+		}
+		for (Object arg : args) {
+			if (arg instanceof ServletRequest ||
+					arg instanceof ServletResponse ||
+					arg instanceof MultipartFile) {
+				continue;
 			}
+			list.add(arg);
 		}
 		return list;
 	}
@@ -74,15 +78,15 @@ public class RequestLogAspect {
 	@AfterReturning(returning = "ret", pointcut = "controllerPoint()")
 	public void doAfterReturning(Object ret) {
 		LogData data = dataStorage.get();
+		String result = null;
 		if (ret != null) {
 			if (ret instanceof CommonResult) {
-				log.info("{} REQUEST DURATION : {} {} {}", data.intFlag, System.currentTimeMillis() - data.timestamp, ((CommonResult) ret).getResult(), data.url);
+				result = ((CommonResult) ret).getResult();
 			} else {
-				log.info("{} REQUEST DURATION : {} {} {}", data.intFlag, System.currentTimeMillis() - data.timestamp, ret.getClass().getName(), data.url);
+				result = ret.getClass().getName();
 			}
-		} else {
-			log.info("{} REQUEST DURATION : {} {} {}", data.intFlag, System.currentTimeMillis() - data.timestamp, "null", data.url);
 		}
+		log.info("{} REQUEST DURATION : {} {} {}", data.intFlag, System.currentTimeMillis() - data.timestamp, result, data.url);
 		dataStorage.remove();
 	}
 
@@ -93,6 +97,11 @@ public class RequestLogAspect {
 		dataStorage.remove();
 	}
 
+	/**
+	 * 初始化日志记录
+	 * @param request
+	 * @return
+	 */
 	private static LogData initFlag(HttpServletRequest request) {
 		LogData data = new LogData();
 		// 请求IP
@@ -103,7 +112,7 @@ public class RequestLogAspect {
 		data.method = request.getMethod();
 		String requestURI = request.getRequestURI();
 		String queryString = request.getQueryString();
-		data.url = requestURI + (queryString == null ? "" : "?" + queryString);
+		data.url = StrUtil.isBlank(queryString) ? requestURI : StrUtil.concat(true, requestURI, "?", queryString);
 		data.intFlag = IdUtil.fastSimpleUUID();
 		dataStorage.set(data);
 		return data;

+ 0 - 222
dmp-server/src/main/java/com/persagy/utils/JacksonMapper.java

@@ -1,222 +0,0 @@
-package com.persagy.utils;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.*;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.JsonNodeType;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import lombok.extern.slf4j.Slf4j;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-
-/**
- * @author: yaoll
- * @date: 2020-09-04
- * @verison: 1.0
- */
-@Slf4j
-public class JacksonMapper {
-
-	public static final ObjectMapper nonEmptyMapper;
-	public static final ObjectMapper nonDefaultMapper;
-	public static final ObjectMapper nonEmptyFormatMapper;
-
-	static {
-		nonEmptyMapper = new ObjectMapper();
-		nonEmptyMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
-		nonEmptyMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
-		nonEmptyMapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
-
-		nonDefaultMapper = new ObjectMapper();
-		nonDefaultMapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
-		nonDefaultMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
-		nonDefaultMapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
-
-		nonEmptyFormatMapper = new ObjectMapper();
-		nonEmptyFormatMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
-		nonEmptyFormatMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
-		nonEmptyFormatMapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
-		nonEmptyFormatMapper.enable(SerializationFeature.INDENT_OUTPUT);
-	}
-
-	private static boolean isEmpty(final CharSequence cs) {
-		return cs == null || cs.length() == 0;
-	}
-
-	public static <T> T toObject(String jsonString, Class<T> clazz) {
-		if (!isEmpty(jsonString)) {
-			try {
-				return nonEmptyMapper.readValue(jsonString, clazz);
-			} catch (IOException e) {
-				log.warn("parse json string to {} error: {}", clazz.getName(), jsonString, e);
-			}
-		}
-		return null;
-	}
-
-	public static <T> T toObject(String jsonString, TypeReference<T> typeRef) {
-		if (!isEmpty(jsonString)) {
-			try {
-				return nonEmptyMapper.readValue(jsonString, typeRef);
-			} catch (IOException e) {
-				log.warn("parse json string to {} error: {}", typeRef.toString(), jsonString, e);
-			}
-		}
-		return null;
-	}
-
-	public static <T> T toObject(String jsonString, JavaType javaType) {
-		if (!isEmpty(jsonString)) {
-			try {
-				return (T) nonEmptyMapper.readValue(jsonString, javaType);
-			} catch (IOException e) {
-				log.warn("parse json string to {} error: {}", javaType.toString(), jsonString, e);
-			}
-		}
-		return null;
-	}
-
-	public static <T> T toObject(String jsonString, Class cla, Class... clb) {
-		if (!isEmpty(jsonString)) {
-			try {
-				JavaType javaType = nonEmptyMapper.getTypeFactory().constructParametricType(cla, clb);
-				return (T) nonEmptyMapper.readValue(jsonString, javaType);
-			} catch (IOException e) {
-				log.warn("parse json string to {} error: {}", cla.getName(), jsonString, e);
-			}
-		}
-		return null;
-	}
-
-	public static JavaType constructParametricType(Class<?> parametrized, Class<?>... parameterClasses) {
-		return nonEmptyMapper.getTypeFactory().constructParametricType(parametrized, parameterClasses);
-	}
-
-	public static JavaType constructParametricType(Class<?> rawType, JavaType... parameterTypes) {
-		return nonEmptyMapper.getTypeFactory().constructParametricType(rawType, parameterTypes);
-	}
-
-	public static String toSimpleJson(Object object) {
-		try {
-			return nonEmptyMapper.writeValueAsString(object);
-		} catch (JsonProcessingException e) {
-			log.error("write to json string error:" + object, e);
-		}
-		return null;
-	}
-
-	public static String toFormatJson(Object object) {
-		try {
-			return nonEmptyFormatMapper.writeValueAsString(object);
-		} catch (JsonProcessingException e) {
-			log.error("write to json string error:" + object, e);
-		}
-		return null;
-	}
-
-	public static final String getString(ObjectNode obj, String key) {
-		return getString(obj, key, null);
-	}
-
-	public static final String getString(ObjectNode obj, String key, String defaultValue) {
-		if (obj == null) {
-			return defaultValue;
-		}
-		if (!obj.has(key)) {
-			return defaultValue;
-		}
-		return obj.get(key).asText();
-	}
-
-	public static final Integer getInteger(ObjectNode obj, String key) {
-		return getInteger(obj, key, null);
-	}
-
-	public static final Integer getInteger(ObjectNode obj, String key, Integer defaultValue) {
-		if (obj == null) {
-			return defaultValue;
-		}
-		if (!obj.has(key)) {
-			return defaultValue;
-		}
-		JsonNode jsonNode = obj.get(key);
-
-		return Integer.valueOf(jsonNode.asText());
-	}
-
-	public static final Double getDouble(ObjectNode obj, String key) {
-		return getDouble(obj, key, null);
-	}
-
-	public static final Double getDouble(ObjectNode obj, String key, Double defaultValue) {
-		if (obj == null) {
-			return defaultValue;
-		}
-		if (!obj.has(key)) {
-			return defaultValue;
-		}
-		return Double.valueOf(obj.get(key).asText());
-	}
-
-	public static final Boolean getBoolean(ObjectNode obj, String key) {
-		return getBoolean(obj, key, null);
-	}
-
-	public static final Boolean getBoolean(ObjectNode obj, String key, Boolean defaultValue) {
-		if (obj == null) {
-			return defaultValue;
-		}
-		if (!obj.has(key)) {
-			return defaultValue;
-		}
-		return Boolean.valueOf(obj.get(key).toString());
-	}
-
-	public static final ObjectNode getObject(ObjectNode obj, String key) {
-		return getObject(obj, key, null);
-	}
-
-	public static final ObjectNode getObject(ObjectNode obj, String key, ObjectNode defaultValue) {
-		if (obj == null) {
-			return defaultValue;
-		}
-		if (!obj.has(key)) {
-			return defaultValue;
-		}
-		JsonNode jsonNode = obj.get(key);
-		JsonNodeType nodeType = jsonNode.getNodeType();
-		if (nodeType == JsonNodeType.STRING) {
-			return toObject(jsonNode.asText(), ObjectNode.class);
-		} else if (nodeType == JsonNodeType.OBJECT) {
-			return (ObjectNode) jsonNode;
-		}
-		return defaultValue;
-	}
-
-
-	public static final ArrayNode getArray(ObjectNode obj, String key) {
-		return getArray(obj, key, null);
-	}
-
-	public static final ArrayNode getArray(ObjectNode obj, String key, ArrayNode defaultValue) {
-		if (obj == null) {
-			return defaultValue;
-		}
-		if (!obj.has(key)) {
-			return defaultValue;
-		}
-		JsonNode jsonNode = obj.get(key);
-		JsonNodeType nodeType = jsonNode.getNodeType();
-		if (nodeType == JsonNodeType.STRING) {
-			return toObject(jsonNode.asText(), ArrayNode.class);
-		} else if (nodeType == JsonNodeType.ARRAY) {
-			return (ArrayNode) jsonNode;
-		}
-		return defaultValue;
-	}
-
-}