|
|
|
@ -24,128 +24,128 @@ import java.util.UUID;
|
|
|
|
|
@RestController
|
|
|
|
|
public class uploadController {
|
|
|
|
|
|
|
|
|
|
// @Value("${file_path}")
|
|
|
|
|
// private String filePath;
|
|
|
|
|
// @Value("${file_url}")
|
|
|
|
|
// private String fileUrl;
|
|
|
|
|
// @Value("${file_lpath}")
|
|
|
|
|
// private String fileLpath;
|
|
|
|
|
// @Value("${minio_path}")
|
|
|
|
|
// private String minioPath;
|
|
|
|
|
// @Value("${minio_url}")
|
|
|
|
|
// private String minioUrl;
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 上传PDF模板
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// @PostMapping("/udiwms/upload/pdf/template/jasper")
|
|
|
|
|
// public BaseResponse uploadPDFTemplate(@RequestParam("file") MultipartFile file) throws UnsupportedEncodingException {
|
|
|
|
|
// if (file.isEmpty()) {
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件不能为空");
|
|
|
|
|
// }
|
|
|
|
|
// // 保存文件 ---------------------
|
|
|
|
|
// String fileName = file.getOriginalFilename();
|
|
|
|
|
// String fileType = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
// // 文件类型判断
|
|
|
|
|
// if (StringUtils.isBlank(fileType) || !fileType.equals(".jasper")) {
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件只能是 jasper 格式");
|
|
|
|
|
// }
|
|
|
|
|
// String newName = UUID.randomUUID() + fileType;//生成新文件名
|
|
|
|
|
// String savePath = filePath + "/pdf/template";
|
|
|
|
|
//
|
|
|
|
|
// File file1 = new File(savePath);
|
|
|
|
|
// if (!file1.exists()) {// 判断目录是否存在
|
|
|
|
|
// file1.mkdirs();// 创建多层目录
|
|
|
|
|
// }
|
|
|
|
|
// file1 = new File(savePath + "/" + newName);
|
|
|
|
|
// try {
|
|
|
|
|
// file.transferTo(file1);
|
|
|
|
|
// Map<String, String> rMap = new HashMap<>();
|
|
|
|
|
// rMap.put("msg", "上传成功");
|
|
|
|
|
// rMap.put("path", newName);
|
|
|
|
|
// return ResultVOUtils.success(rMap);
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传失败");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// @PostMapping("/udiwms/upload/pdf/template/jrxml")
|
|
|
|
|
// public BaseResponse uploadPDFJrxmlTemplate(@RequestParam("file") MultipartFile file) throws UnsupportedEncodingException {
|
|
|
|
|
// if (file.isEmpty()) {
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件不能为空");
|
|
|
|
|
// }
|
|
|
|
|
// // 保存文件 ---------------------
|
|
|
|
|
// String fileName = file.getOriginalFilename();
|
|
|
|
|
// String fileType = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
// // 文件类型判断
|
|
|
|
|
// if (StringUtils.isBlank(fileType) || !fileType.equals(".jrxml")) {
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件只能是 jrxml 格式");
|
|
|
|
|
// }
|
|
|
|
|
// String newName = UUID.randomUUID() + fileType;//生成新文件名
|
|
|
|
|
// String savePath = filePath + "/pdf/template";
|
|
|
|
|
//
|
|
|
|
|
// File file1 = new File(savePath);
|
|
|
|
|
// if (!file1.exists()) {// 判断目录是否存在
|
|
|
|
|
// file1.mkdirs();// 创建多层目录
|
|
|
|
|
// }
|
|
|
|
|
// file1 = new File(savePath + "/" + newName);
|
|
|
|
|
// try {
|
|
|
|
|
// file.transferTo(file1);
|
|
|
|
|
// Map<String, String> rMap = new HashMap<>();
|
|
|
|
|
// rMap.put("msg", "上传成功");
|
|
|
|
|
// rMap.put("path", savePath + "/" + newName);
|
|
|
|
|
// return ResultVOUtils.success(rMap);
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传失败");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 注册页面上传文件
|
|
|
|
|
// */
|
|
|
|
|
// @PostMapping("/udiwms/upload/register/file")
|
|
|
|
|
// public BaseResponse uploadRegisterFile(@RequestParam("file") MultipartFile file,
|
|
|
|
|
// @RequestParam("type") String type) throws UnsupportedEncodingException {
|
|
|
|
|
// if (file.isEmpty()) {
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件不能为空");
|
|
|
|
|
// }
|
|
|
|
|
// if (StringUtils.isBlank(type)) {
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件类型不能为空");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 保存文件 ---------------------
|
|
|
|
|
// String fileName = file.getOriginalFilename();
|
|
|
|
|
// String fileType = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
// // 文件类型判断
|
|
|
|
|
// if (StringUtils.isBlank(fileType) || (!fileType.equals(".jpg") && !fileType.equals(".png") && !fileType.equals(".doc") && !fileType.equals(".pdf"))) {
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件只能是 jpg,png,doc,pdf 格式");
|
|
|
|
|
// }
|
|
|
|
|
// String newName = UUID.randomUUID() + fileType;//生成新文件名
|
|
|
|
|
// String savePath = filePath + "/register/file/" + type;
|
|
|
|
|
// String savePath1 = fileLpath + "?type=" + type;
|
|
|
|
|
// String fileFullName = savePath + "/" + newName;
|
|
|
|
|
//
|
|
|
|
|
// File file1 = new File(savePath);
|
|
|
|
|
// if (!file1.exists()) {// 判断目录是否存在
|
|
|
|
|
// file1.mkdirs();// 创建多层目录
|
|
|
|
|
// }
|
|
|
|
|
// file1 = new File(savePath + "/" + newName);
|
|
|
|
|
// try {
|
|
|
|
|
// file.transferTo(file1);
|
|
|
|
|
//// MinioUtil.uploadFile(fileFullName, file);
|
|
|
|
|
// Map<String, String> rMap = new HashMap<>();
|
|
|
|
|
// rMap.put("msg", "上传成功");
|
|
|
|
|
// rMap.put("name", fileUrl + savePath1 + "&name=" + newName);
|
|
|
|
|
// rMap.put("type", type);
|
|
|
|
|
// return ResultVOUtils.success(rMap);
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传失败");
|
|
|
|
|
// }
|
|
|
|
|
@Value("${file_path}")
|
|
|
|
|
private String filePath;
|
|
|
|
|
@Value("${file_url}")
|
|
|
|
|
private String fileUrl;
|
|
|
|
|
@Value("${file_lpath}")
|
|
|
|
|
private String fileLpath;
|
|
|
|
|
@Value("${minio_path}")
|
|
|
|
|
private String minioPath;
|
|
|
|
|
@Value("${minio_url}")
|
|
|
|
|
private String minioUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上传PDF模板
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@PostMapping("/udiwms/upload/pdf/template/jasper")
|
|
|
|
|
public BaseResponse uploadPDFTemplate(@RequestParam("file") MultipartFile file) throws UnsupportedEncodingException {
|
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件不能为空");
|
|
|
|
|
}
|
|
|
|
|
// 保存文件 ---------------------
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
String fileType = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
// 文件类型判断
|
|
|
|
|
if (StringUtils.isBlank(fileType) || !fileType.equals(".jasper")) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件只能是 jasper 格式");
|
|
|
|
|
}
|
|
|
|
|
String newName = UUID.randomUUID() + fileType;//生成新文件名
|
|
|
|
|
String savePath = filePath + "/pdf/template";
|
|
|
|
|
|
|
|
|
|
File file1 = new File(savePath);
|
|
|
|
|
if (!file1.exists()) {// 判断目录是否存在
|
|
|
|
|
file1.mkdirs();// 创建多层目录
|
|
|
|
|
}
|
|
|
|
|
file1 = new File(savePath + "/" + newName);
|
|
|
|
|
try {
|
|
|
|
|
file.transferTo(file1);
|
|
|
|
|
Map<String, String> rMap = new HashMap<>();
|
|
|
|
|
rMap.put("msg", "上传成功");
|
|
|
|
|
rMap.put("path", newName);
|
|
|
|
|
return ResultVOUtils.success(rMap);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/udiwms/upload/pdf/template/jrxml")
|
|
|
|
|
public BaseResponse uploadPDFJrxmlTemplate(@RequestParam("file") MultipartFile file) throws UnsupportedEncodingException {
|
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件不能为空");
|
|
|
|
|
}
|
|
|
|
|
// 保存文件 ---------------------
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
String fileType = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
// 文件类型判断
|
|
|
|
|
if (StringUtils.isBlank(fileType) || !fileType.equals(".jrxml")) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件只能是 jrxml 格式");
|
|
|
|
|
}
|
|
|
|
|
String newName = UUID.randomUUID() + fileType;//生成新文件名
|
|
|
|
|
String savePath = filePath + "/pdf/template";
|
|
|
|
|
|
|
|
|
|
File file1 = new File(savePath);
|
|
|
|
|
if (!file1.exists()) {// 判断目录是否存在
|
|
|
|
|
file1.mkdirs();// 创建多层目录
|
|
|
|
|
}
|
|
|
|
|
file1 = new File(savePath + "/" + newName);
|
|
|
|
|
try {
|
|
|
|
|
file.transferTo(file1);
|
|
|
|
|
Map<String, String> rMap = new HashMap<>();
|
|
|
|
|
rMap.put("msg", "上传成功");
|
|
|
|
|
rMap.put("path", savePath + "/" + newName);
|
|
|
|
|
return ResultVOUtils.success(rMap);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 注册页面上传文件
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/udiwms/upload/register/file")
|
|
|
|
|
public BaseResponse uploadRegisterFile(@RequestParam("file") MultipartFile file,
|
|
|
|
|
@RequestParam("type") String type) throws UnsupportedEncodingException {
|
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件不能为空");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(type)) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件类型不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存文件 ---------------------
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
String fileType = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
// 文件类型判断
|
|
|
|
|
if (StringUtils.isBlank(fileType) || (!fileType.equals(".jpg") && !fileType.equals(".png") && !fileType.equals(".doc") && !fileType.equals(".pdf"))) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传文件只能是 jpg,png,doc,pdf 格式");
|
|
|
|
|
}
|
|
|
|
|
String newName = UUID.randomUUID() + fileType;//生成新文件名
|
|
|
|
|
String savePath = filePath + "/register/file/" + type;
|
|
|
|
|
String savePath1 = fileLpath + "?type=" + type;
|
|
|
|
|
String fileFullName = savePath + "/" + newName;
|
|
|
|
|
|
|
|
|
|
File file1 = new File(savePath);
|
|
|
|
|
if (!file1.exists()) {// 判断目录是否存在
|
|
|
|
|
file1.mkdirs();// 创建多层目录
|
|
|
|
|
}
|
|
|
|
|
file1 = new File(savePath + "/" + newName);
|
|
|
|
|
try {
|
|
|
|
|
file.transferTo(file1);
|
|
|
|
|
// MinioUtil.uploadFile(fileFullName, file);
|
|
|
|
|
Map<String, String> rMap = new HashMap<>();
|
|
|
|
|
rMap.put("msg", "上传成功");
|
|
|
|
|
rMap.put("name", fileUrl + savePath1 + "&name=" + newName);
|
|
|
|
|
rMap.put("type", type);
|
|
|
|
|
return ResultVOUtils.success(rMap);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "上传失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|