martin 3 lat temu
rodzic
commit
46e071dd71

+ 18 - 0
api-common/src/main/java/api/common/pojo/po/WebLog.java

@@ -0,0 +1,18 @@
+package api.common.pojo.po;
+
+/**
+ * Controller层的日志封装类
+ */
+public class WebLog {
+    private String description;
+    private String username;
+    private Long startTime;
+    private Integer spendTime;
+    private String basePath;
+    private String uri;
+    private String url;
+    private String method;
+    private String ip;
+    private Object parameter;
+    private Object result;    //省略了getter,setter方法
+}

+ 19 - 0
api-common/src/main/java/api/common/util/FileUtil.java

@@ -14,6 +14,25 @@ import java.util.*;
 public class FileUtil {
 
 
+
+    /**
+     * 获取当前目录下的一级文件全路径列表
+     * @param path 根路径
+     * @return 文件全路径列表
+     */
+    public static List<String> ls(String path) {
+        File[] files = new File(path).listFiles();
+        if (files == null){
+            throw new RuntimeException("路径不存在!");
+        }
+        List<String> result = new ArrayList<>();
+        for (File file : files) {
+            result.add(file.getAbsolutePath()) ;
+        }
+        return result;
+    }
+
+
     public static String read(String path) throws Exception {
         return read(getFile(path));
     }

+ 4 - 4
simulation-resource-common/src/main/java/com/css/simulation/resource/common/controller/MinioController.java

@@ -140,9 +140,9 @@ public class MinioController {
         CreateMultipartUploadResponse multipartUpload = minioClient.createMultipartUpload(bucketName, null, objectName, null, null);
         String uploadId = multipartUpload.result().uploadId();
         List<String> UrlList = new LinkedList<>();
-        Map<String, String> queryParam = new HashMap();
+        Map<String, String> queryParam = new HashMap<>();
         queryParam.put("uploadId", uploadId);
-        int size = Integer.valueOf(chunkSize);
+        int size = Integer.parseInt(chunkSize);
         for (int i = 1; i <= size; i++) {
             queryParam.put("partNumber", String.valueOf(i));
             String presignedObjectUrl = minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
@@ -166,7 +166,7 @@ public class MinioController {
         String objectName = paramMap.get("objectName");
         String uploadId = paramMap.get("uploadId");
         if (ObjectUtil.isNull(objectName) || ObjectUtil.isNull(uploadId)) {
-            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "请求参数缺失");
+            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "请求参数缺失");
         }
         ListPartsResponse listPartsResponse = minioClient.listParts(bucketName, null, objectName, 10000, 0, uploadId, null, null);
         List<Part> parts = listPartsResponse.result().partList();
@@ -177,6 +177,6 @@ public class MinioController {
             partNumber++;
         }
         minioClient.completeMultipartUpload(bucketName, null, objectName, uploadId, partArr, null, null);
-        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, "合并成功");
+        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, "合并成功");
     }
 }

+ 64 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/aspect/WebLogAspect.java

@@ -0,0 +1,64 @@
+//package com.css.simulation.resource.aspect;
+//
+//import api.common.pojo.po.WebLog;
+//import lombok.extern.slf4j.Slf4j;
+//import org.aspectj.lang.JoinPoint;
+//import org.aspectj.lang.ProceedingJoinPoint;
+//import org.aspectj.lang.Signature;
+//import org.aspectj.lang.annotation.*;
+//import org.aspectj.lang.reflect.MethodSignature;
+//import org.springframework.stereotype.Component;
+//import org.springframework.web.context.request.RequestContextHolder;
+//import org.springframework.web.context.request.ServletRequestAttributes;
+//import sun.net.util.URLUtil;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import java.lang.reflect.Method;
+//import java.util.HashMap;
+//import java.util.Map;
+//
+///**
+// * 统一日志处理切面 * Created by 石磊
+// */
+//@Aspect
+//@Component
+//@Slf4j
+//public class WebLogAspect {
+//
+//    @Pointcut("execution(public * com.*.controller.*.*(..))")
+//    public void webLog() {
+//    }
+//
+//    @Before("webLog()")
+//    public void doBefore(JoinPoint joinPoint) throws Throwable {
+//    }
+//
+//    @AfterReturning(value = "webLog()", returning = "ret")
+//    public void doAfterReturning(Object ret) throws Throwable {
+//    }
+//
+//    @Around("webLog()")
+//    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
+//        long startTime = System.currentTimeMillis();        //获取当前请求对象
+//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+//        HttpServletRequest request = attributes.getRequest();        //记录请求信息(通过Logstash传入Elasticsearch)
+//        WebLog webLog = new WebLog();
+//        Object result = joinPoint.proceed();
+//        Signature signature = joinPoint.getSignature();
+//        MethodSignature methodSignature = (MethodSignature) signature;
+//        Method method = methodSignature.getMethod();
+//        if (method.isAnnotationPresent(ApiOperation.class)) {
+//            ApiOperation log = method.getAnnotation(ApiOperation.class);
+//            webLog.setDescription(log.value());
+//        }
+//        long endTime = System.currentTimeMillis();
+//        String urlStr = request.getRequestURL().toString();
+//        webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath()));
+//        webLog.setIp(request.getRemoteUser());
+//        Map<String, Object> logMap = new HashMap<>();
+//        logMap.put("spendTime", webLog.getSpendTime());
+//        logMap.put("description", webLog.getDescription());
+//        LOGGER.info("{}", JSONUtil.parse(webLog));
+//        return result;
+//    }
+//}