Procházet zdrojové kódy

1.启动时判断必须创建的文件夹是否创建

GouGengquan před 6 měsíci
rodič
revize
05788c60f4

+ 29 - 0
common/src/main/java/com/dayou/initializer/ApplicationStartup.java

@@ -0,0 +1,29 @@
+package com.dayou.initializer;
+
+import com.dayou.config.FileNetConfig;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+
+/**
+ * 项目启动时初始化操作
+ */
+@Component
+public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent> {
+
+    @Autowired
+    private FileNetConfig fileNetConfig;
+
+    // 判断所需文件夹是否存在
+    @Override
+    public void onApplicationEvent(ContextRefreshedEvent event) {
+        // 判断文件夹是否存在
+        File folder = new File(fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputCalculatePath());
+        if (!folder.exists()) { // 不存在就创建一个
+            folder.mkdirs();
+        }
+    }
+}

+ 1 - 0
service/src/main/java/com/dayou/service/impl/AssetsCalculateServiceImpl.java

@@ -33,6 +33,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;