sunyj 8 роки тому
батько
коміт
7ee2eccf46

+ 16 - 11
report/src/main/java/com/uas/report/controller/FileController.java

@@ -1,13 +1,8 @@
 package com.uas.report.controller;
 
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import com.uas.report.service.FileService;
+import com.uas.report.util.ArrayUtils;
+import com.uas.report.util.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,9 +10,12 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.multipart.MultipartFile;
 
-import com.uas.report.service.FileService;
-import com.uas.report.util.ArrayUtils;
-import com.uas.report.util.StringUtils;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 文件操作请求
@@ -138,4 +136,11 @@ public class FileController {
 			throws IOException {
 		return fileService.listFiles(filePath, isAbsolutePath);
 	}
+
+	@RequestMapping("/newFolder")
+	@ResponseBody
+	public boolean newFolder(String filePath, Boolean isAbsolutePath, String folderName, HttpServletRequest request)
+			throws IOException {
+		return fileService.newFolder(filePath, isAbsolutePath, folderName);
+	}
 }

+ 14 - 0
report/src/main/java/com/uas/report/service/FileService.java

@@ -195,6 +195,20 @@ public interface FileService {
 	 */
 	public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath) throws IOException;
 
+	/**
+	 * 在指定路径下创建文件夹
+	 *
+	 * @param filePath
+	 *            指定的路径
+	 * @param isAbsolutePath
+	 *            文件路径是否为绝对路径,不传的话默认为假
+	 * @param folderName
+	 *            需要创建的文件夹名称
+	 * @return 文件夹创建是否成功
+	 * @throws IOException
+	 */
+	boolean newFolder(String filePath, Boolean isAbsolutePath, String folderName) throws IOException;
+
 	/**
 	 * 判断文件是否有效(文件存在并且未过有效期,并且比模板新)
 	 * 

+ 11 - 1
report/src/main/java/com/uas/report/service/impl/FileServiceImpl.java

@@ -489,7 +489,7 @@ public class FileServiceImpl implements FileService {
 		if (isAbsolutePath == null || !isAbsolutePath) {
 			information.put("filePath", getRelativePath(file));
 		} else {
-			information.put("filePath", file.getPath());
+			information.put("filePath", file.getPath().replace("\\", "/"));
 		}
 		information.put("lastModified",
 				new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified())));
@@ -517,6 +517,16 @@ public class FileServiceImpl implements FileService {
 		return file.getPath().replace(new File(specialProperties.getLocalBaseDir()).getPath(), "").replace("\\", "/");
 	}
 
+	@Override
+	public boolean newFolder(String filePath, Boolean isAbsolutePath, String folderName) throws IOException{
+		filePath = getAbsolutePath(filePath, isAbsolutePath);
+		File file = new File(filePath, folderName);
+		if (file.exists()) {
+			throw new IOException("文件夹已存在");
+		}
+		return file.mkdirs();
+	}
+
 	@Override
 	public boolean isFileValid(String fileAbsolutePath, String jrxmlFileAbsolutePath) {
 		if (!StringUtils.isEmpty(fileAbsolutePath) && !StringUtils.isEmpty(jrxmlFileAbsolutePath)) {