2.根据小池数据,反写BOM及切割派工单的实际划线/切割长度,划线/切割实动工时等字段;定时执行; 3.导入套料图PDF时,将文件上传到服务器,并保存地址到数据库;master
parent
3924cc8ad6
commit
ab4fab389f
@ -0,0 +1,50 @@
|
|||||||
|
package com.dsic.gj_erp.util;
|
||||||
|
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
public class FileUtil {
|
||||||
|
|
||||||
|
public static String handlerUpload(MultipartFile multipartFile,@NonNull String path) {
|
||||||
|
String originalFilename = multipartFile.getOriginalFilename();
|
||||||
|
AtomicReference<String> url = new AtomicReference<>("");
|
||||||
|
Optional.ofNullable(originalFilename).ifPresent(name -> {
|
||||||
|
// String suffix = name.substring(name.lastIndexOf("."));
|
||||||
|
// String suffix = name.substring(name.lastIndexOf("/"));
|
||||||
|
File filePath = new File("./static/upload" + path);
|
||||||
|
if (!filePath.exists()) {
|
||||||
|
filePath.mkdirs();
|
||||||
|
}
|
||||||
|
String fileName = name.substring(name.lastIndexOf("/"));
|
||||||
|
String tmpUrl = path + fileName;
|
||||||
|
url.set(tmpUrl);
|
||||||
|
FileUtil.saveToDisk("./static/upload" + tmpUrl, multipartFile);
|
||||||
|
});
|
||||||
|
return url.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveToDisk(String filePath, MultipartFile multipartFile) {
|
||||||
|
try (BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(Paths.get(filePath)))) {
|
||||||
|
FileInputStream fileInputStream = (FileInputStream) multipartFile.getInputStream();
|
||||||
|
byte[] bs = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = fileInputStream.read(bs)) != -1) {
|
||||||
|
bos.write(bs, 0, len);
|
||||||
|
}
|
||||||
|
bos.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("上传失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue