|
@@ -2,9 +2,7 @@ package com.example.nngkxxdp.service.impl;
|
|
|
|
|
|
import cn.hutool.core.io.FileTypeUtil;
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
-import com.example.nngkxxdp.dao.FileDao;
|
|
|
import com.example.nngkxxdp.dao.RectificationDao;
|
|
|
-import com.example.nngkxxdp.entity.SFile;
|
|
|
import com.example.nngkxxdp.service.RectificationService;
|
|
|
import com.example.nngkxxdp.util.Blank;
|
|
|
import com.example.nngkxxdp.util.ConstStr;
|
|
@@ -19,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -39,9 +38,6 @@ public class RectificationServiceImpl implements RectificationService {
|
|
|
@Value("${file.location}")
|
|
|
private String location;
|
|
|
|
|
|
- @Resource
|
|
|
- private FileDao fileDao;
|
|
|
-
|
|
|
/**
|
|
|
* description: 详情
|
|
|
*
|
|
@@ -103,47 +99,45 @@ public class RectificationServiceImpl implements RectificationService {
|
|
|
* description: 新增
|
|
|
*
|
|
|
* @param rectificationDO 实例对象
|
|
|
- * @param file 文件对象
|
|
|
+ * @param files 文件对象
|
|
|
* @return java.util.Map<java.lang.String, java.lang.Object> 数据
|
|
|
* @author zwq
|
|
|
* @date 2023/01/30 10:44
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String, Object> add(RectificationDO rectificationDO, MultipartFile file) throws IOException {
|
|
|
+ public Map<String, Object> add(RectificationDO rectificationDO, MultipartFile[] files) throws IOException {
|
|
|
if (!Blank.isPhone(rectificationDO.getPhone())) {
|
|
|
return SendUtil.send(false, "请输入正确的手机号");
|
|
|
}
|
|
|
if (!Blank.isEmail(rectificationDO.getMail())) {
|
|
|
return SendUtil.send(false, "请输入正确的邮箱");
|
|
|
}
|
|
|
- if (Blank.isNotEmpty(file)) {
|
|
|
+ if (Blank.isNotEmpty(files)) {
|
|
|
File pathFile = new File(location);
|
|
|
if (!pathFile.isDirectory()) {
|
|
|
if (!pathFile.mkdirs()) {
|
|
|
return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
}
|
|
|
}
|
|
|
- //获取上传过来的文件名
|
|
|
- File temporaryFile = new File(location + file.getOriginalFilename());
|
|
|
- file.transferTo(temporaryFile);
|
|
|
- String type = FileTypeUtil.getType(temporaryFile);
|
|
|
- if (!("jpg".equals(type) || "png".equals(type) || "bmp".equals(type) || "jpeg".equals(type))) {
|
|
|
- return SendUtil.send(false, ConstStr.ADD_FAILED, "上传的格式必须是jpg或png或bmp或jpeg");
|
|
|
- }
|
|
|
- String newName = (new Date()).getTime() + ((int) (Math.random() * 9000) + 1000) + "." + type;
|
|
|
- String filePath = location + newName;
|
|
|
- File newFile = new File(filePath);
|
|
|
- if (!temporaryFile.renameTo(newFile)) {
|
|
|
- return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
- }
|
|
|
- // 增加数据到s_file表
|
|
|
- SFile sFile = new SFile();
|
|
|
- sFile.setPath(newName);
|
|
|
- sFile.setSuffix(type);
|
|
|
- if (fileDao.addFile(sFile) <= 0) {
|
|
|
- return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
+ ArrayList<String> picPathList = new ArrayList<>();
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ //获取上传过来的文件名
|
|
|
+ File temporaryFile = new File(location + file.getOriginalFilename());
|
|
|
+ file.transferTo(temporaryFile);
|
|
|
+ String type = FileTypeUtil.getType(temporaryFile);
|
|
|
+ if (!("jpg".equals(type) || "png".equals(type) || "bmp".equals(type) || "jpeg".equals(type))) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "上传的格式必须是jpg或png或bmp或jpeg");
|
|
|
+ }
|
|
|
+ String newName = (new Date()).getTime() + ((int) (Math.random() * 9000) + 1000) + "." + type;
|
|
|
+ String filePath = location + newName;
|
|
|
+ File newFile = new File(filePath);
|
|
|
+ if (!temporaryFile.renameTo(newFile)) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
+ }
|
|
|
+ picPathList.add(newName);
|
|
|
}
|
|
|
- rectificationDO.setPicture(newName);
|
|
|
+ String picPath = String.join(",", picPathList);
|
|
|
+ rectificationDO.setPicture(picPath);
|
|
|
}
|
|
|
rectificationDO.setId(UUID.randomUUID().toString());
|
|
|
rectificationDO.setCreateTime(new Date());
|