From 15bba267b1992286f04be9db924af2786f3aac97 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Wed, 23 Feb 2022 16:12:12 +0800
Subject: [PATCH] 督办单修改
---
screen-api/src/main/java/com/moral/api/service/SupervisionService.java | 2
screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java | 88 ++++++++++++++++++++++++++------------------
screen-api/src/main/java/com/moral/api/controller/SupervisionController.java | 5 ++
3 files changed, 57 insertions(+), 38 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/controller/SupervisionController.java b/screen-api/src/main/java/com/moral/api/controller/SupervisionController.java
index 5b4e590..b266fa9 100644
--- a/screen-api/src/main/java/com/moral/api/controller/SupervisionController.java
+++ b/screen-api/src/main/java/com/moral/api/controller/SupervisionController.java
@@ -36,7 +36,10 @@
private SupervisionService supervisionService;
@PostMapping("add")
- public ResultMessage add(MultipartFile[] files, Supervision supervision) {
+ public ResultMessage add(HttpServletRequest request) {
+ Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
+ List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
+ Supervision supervision = JSONObject.parseObject(JSONObject.toJSONString(params), Supervision.class);
Map<String, Object> response = supervisionService.add(files, supervision);
if (!response.isEmpty()) {
return ResultMessage.fail(Integer.parseInt(response.get("code").toString()), response.get("msg").toString());
diff --git a/screen-api/src/main/java/com/moral/api/service/SupervisionService.java b/screen-api/src/main/java/com/moral/api/service/SupervisionService.java
index 58e30db..69ffdea 100644
--- a/screen-api/src/main/java/com/moral/api/service/SupervisionService.java
+++ b/screen-api/src/main/java/com/moral/api/service/SupervisionService.java
@@ -19,7 +19,7 @@
public interface SupervisionService extends IService<Supervision> {
//���������������
- Map<String, Object> add(MultipartFile[] files, Supervision supervision);
+ Map<String, Object> add(List<MultipartFile> files, Supervision supervision);
//���������������
Map<String, Object> selectSupervisions(Map<String, Object> params);
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
index 1893205..1368bcb 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
@@ -51,7 +51,7 @@
@Override
@Transactional
- public Map<String, Object> add(MultipartFile[] files, Supervision supervision) {
+ public Map<String, Object> add(List<MultipartFile> files, Supervision supervision) {
//������jar���������������
ApplicationHome applicationHome = new ApplicationHome(getClass());
//���jar������������������������������upload������������������������������������
@@ -69,24 +69,27 @@
}
List<String> images = new ArrayList<>();
- for (MultipartFile file : files) {
- //������������������������
- String fileType = file.getContentType();
- if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) {
- //���������������
- String fileName = file.getOriginalFilename();
- //���������������������
- String suffixName = fileName.substring(fileName.lastIndexOf("."));
- //���������������������
- fileName = UUID.randomUUID() + suffixName;
- //������������
- if (FileUtils.upload(file, path, fileName)) {
- images.add(fileName);
+
+ if (files.size() > 0) {
+ for (MultipartFile file : files) {
+ //������������������������
+ String fileType = file.getContentType();
+ if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) {
+ //���������������
+ String fileName = file.getOriginalFilename();
+ //���������������������
+ String suffixName = fileName.substring(fileName.lastIndexOf("."));
+ //���������������������
+ fileName = UUID.randomUUID() + suffixName;
+ //������������
+ if (FileUtils.upload(file, path, fileName)) {
+ images.add(fileName);
+ }
+ } else {
+ result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode());
+ result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg());
+ return result;
}
- } else {
- result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode());
- result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg());
- return result;
}
}
@@ -166,28 +169,41 @@
List<String> images = new ArrayList<>();
-
- for (MultipartFile file : files) {
- //������������������������
- String fileType = file.getContentType();
- if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) {
- //���������������
- String fileName = file.getOriginalFilename();
- //���������������������
- String suffixName = fileName.substring(fileName.lastIndexOf("."));
- //���������������������
- fileName = UUID.randomUUID() + suffixName;
- //������������
- if (FileUtils.upload(file, path, fileName)) {
- images.add(fileName);
+ System.out.println(files.size());
+ //������������������������������������������������������������������������
+ if (files.size() > 0) {
+ for (MultipartFile file : files) {
+ //������������������������
+ String fileType = file.getContentType();
+ if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) {
+ //������������������
+ String contentType = file.getContentType();
+ //���������������������
+ String suffixName = contentType.substring(contentType.lastIndexOf("/")).replace("/", ".");
+ //���������������������
+ String fileName = UUID.randomUUID() + suffixName;
+ //������������
+ if (FileUtils.upload(file, path, fileName)) {
+ images.add(fileName);
+ }
+ } else {
+ result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode());
+ result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg());
+ return result;
}
- } else {
- result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode());
- result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg());
- return result;
}
}
+
+
if (!ObjectUtils.isEmpty(images)) {
+ //���������������������������������������������
+ for (String image : images) {
+ String realPath = path + File.separator + image;
+ File file = new File(realPath);
+ if (file.exists() && file.isFile()) {
+ file.delete();
+ }
+ }
String image = images.stream()
.map(String::valueOf)
.collect(Collectors.joining(","));
--
Gitblit v1.8.0