@@ -1,8 +1,8 @@
|
|||||||
package com.yunhai.dormnotice.service;
|
package com.yunhai.dormnotice.service;
|
||||||
|
|
||||||
import com.yunhai.dormnotice.entity.UpFile;
|
import com.yunhai.dormnotice.entity.UpFile;
|
||||||
import com.yunhai.dormnotice.model.notice.UpFileVo;
|
|
||||||
import com.yunhai.dormnotice.model.notice.UpFileResultVo;
|
import com.yunhai.dormnotice.model.notice.UpFileResultVo;
|
||||||
|
import com.yunhai.dormnotice.model.notice.UpFileVo;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -82,11 +82,6 @@ public interface IFileService {
|
|||||||
*/
|
*/
|
||||||
void downloadZipByTopic(String topicType, Integer topicId, String zipName, HttpServletResponse response);
|
void downloadZipByTopic(String topicType, Integer topicId, String zipName, HttpServletResponse response);
|
||||||
|
|
||||||
/**
|
|
||||||
* 按附件ID集合打包下载为 ZIP(通知 AllFileDown 用:通知存的是 fileIds 逗号串)。
|
|
||||||
*/
|
|
||||||
void downloadZipByIds(List<Integer> fileIds, String zipName, HttpServletResponse response);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量上传图片(循环上传,返回每个文件的视图对象列表)。
|
* 批量上传图片(循环上传,返回每个文件的视图对象列表)。
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.yunhai.dormnotice.service.impl;
|
package com.yunhai.dormnotice.service.impl;
|
||||||
|
|
||||||
import com.yunhai.dormnotice.entity.UpFile;
|
import com.yunhai.dormnotice.entity.UpFile;
|
||||||
import com.yunhai.dormnotice.model.notice.UpFileVo;
|
|
||||||
import com.yunhai.dormnotice.model.notice.UpFileResultVo;
|
import com.yunhai.dormnotice.model.notice.UpFileResultVo;
|
||||||
|
import com.yunhai.dormnotice.model.notice.UpFileVo;
|
||||||
import com.yunhai.dormnotice.repository.UpFileRepository;
|
import com.yunhai.dormnotice.repository.UpFileRepository;
|
||||||
import com.yunhai.dormnotice.service.IFileService;
|
import com.yunhai.dormnotice.service.IFileService;
|
||||||
import com.yunhai.platform.apistd.BizException;
|
import com.yunhai.platform.apistd.BizException;
|
||||||
@@ -18,7 +18,6 @@ import org.springframework.util.StringUtils;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
@@ -26,15 +25,7 @@ import java.net.URLEncoder;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.time.LocalDate;
|
import java.util.*;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
@@ -53,11 +44,9 @@ public class FileService implements IFileService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UpFileRepository upFileRepository;
|
private UpFileRepository upFileRepository;
|
||||||
|
|
||||||
@Value("${file.upload-path}")
|
@Value("${FILE_PATH}")
|
||||||
private String uploadPath;
|
private String uploadPath;
|
||||||
|
|
||||||
private static final String DEFAULT_APP_TYPE = "dormnotice";
|
|
||||||
|
|
||||||
// ============================ 上传 ============================
|
// ============================ 上传 ============================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,13 +66,10 @@ public class FileService implements IFileService {
|
|||||||
ext = originalName.substring(dotIdx + 1).toLowerCase();
|
ext = originalName.substring(dotIdx + 1).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造存储子路径:{appType}/{yyyyMMdd}/{uuid}.{ext}
|
|
||||||
String dateDir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
||||||
String savedName = UUID.randomUUID().toString().replace("-", "") + (ext.isEmpty() ? "" : "." + ext);
|
String savedName = UUID.randomUUID().toString().replace("-", "") + (ext.isEmpty() ? "" : "." + ext);
|
||||||
String relativePath = (appType == null ? DEFAULT_APP_TYPE : appType) + "/" + dateDir + "/" + savedName;
|
|
||||||
|
|
||||||
// 物理写入
|
// 物理写入
|
||||||
Path fullPath = Paths.get(uploadPath, relativePath);
|
Path fullPath = Paths.get(uploadPath, savedName);
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(fullPath.getParent());
|
Files.createDirectories(fullPath.getParent());
|
||||||
file.transferTo(fullPath.toFile());
|
file.transferTo(fullPath.toFile());
|
||||||
@@ -94,10 +80,10 @@ public class FileService implements IFileService {
|
|||||||
|
|
||||||
// 入库
|
// 入库
|
||||||
UpFile entity = new UpFile();
|
UpFile entity = new UpFile();
|
||||||
entity.setTopicType(appType == null ? DEFAULT_APP_TYPE : appType);
|
entity.setTopicType(appType);
|
||||||
entity.setTopicId(topicId);
|
entity.setTopicId(topicId);
|
||||||
entity.setFileTrueName(originalName);
|
entity.setFileTrueName(originalName);
|
||||||
entity.setFileName(relativePath);
|
entity.setFileName(savedName);
|
||||||
entity.setFileSize((int) file.getSize());
|
entity.setFileSize((int) file.getSize());
|
||||||
entity.setFileType(ext);
|
entity.setFileType(ext);
|
||||||
upFileRepository.save(entity);
|
upFileRepository.save(entity);
|
||||||
@@ -125,8 +111,7 @@ public class FileService implements IFileService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UpFileVo> listByTopic(String appType, Integer topicId) {
|
public List<UpFileVo> listByTopic(String appType, Integer topicId) {
|
||||||
String type = appType == null ? DEFAULT_APP_TYPE : appType;
|
return upFileRepository.findByTopicTypeAndTopicId(appType, topicId).stream()
|
||||||
return upFileRepository.findByTopicTypeAndTopicId(type, topicId).stream()
|
|
||||||
.map(this::toVo)
|
.map(this::toVo)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@@ -279,17 +264,7 @@ public class FileService implements IFileService {
|
|||||||
@Override
|
@Override
|
||||||
public void downloadZipByTopic(String topicType, Integer topicId, String zipName,
|
public void downloadZipByTopic(String topicType, Integer topicId, String zipName,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
String type = topicType == null ? DEFAULT_APP_TYPE : topicType;
|
List<UpFile> files = upFileRepository.findByTopicTypeAndTopicId(topicType, topicId);
|
||||||
List<UpFile> files = upFileRepository.findByTopicTypeAndTopicId(type, topicId);
|
|
||||||
downloadZip(files, zipName, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void downloadZipByIds(List<Integer> fileIds, String zipName, HttpServletResponse response) {
|
|
||||||
if (fileIds == null || fileIds.isEmpty()) {
|
|
||||||
throw new BizException(ErrorCode.PARAM_ERROR, "无附件可下载");
|
|
||||||
}
|
|
||||||
List<UpFile> files = upFileRepository.findAllById(fileIds);
|
|
||||||
downloadZip(files, zipName, response);
|
downloadZip(files, zipName, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,9 +277,8 @@ public class FileService implements IFileService {
|
|||||||
if (files == null || files.length == 0) {
|
if (files == null || files.length == 0) {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
String type = appType != null ? appType : DEFAULT_APP_TYPE;
|
|
||||||
for (MultipartFile file : files) {
|
for (MultipartFile file : files) {
|
||||||
results.add(upload(file, type, null));
|
results.add(upload(file, appType, null));
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -911,7 +911,8 @@ public class NoticeService implements INoticeService {
|
|||||||
m.put("receiveText", receiveText(n));
|
m.put("receiveText", receiveText(n));
|
||||||
m.put("roomCount", targetRooms(n).size());
|
m.put("roomCount", targetRooms(n).size());
|
||||||
m.put("bedCount", allowCount(n));
|
m.put("bedCount", allowCount(n));
|
||||||
m.put("progress", "draft".equals(n.getNoticeStatus()) ? null : progress(n.getId(), n));
|
// 仅通知类(none)不产生回执行,progress 置空,前端据此显示「仅通知 · 无需回执」而不是 0/0
|
||||||
|
m.put("progress", "draft".equals(n.getNoticeStatus()) || "none".equals(n.getReceiptMode()) ? null : progress(n.getId(), n));
|
||||||
m.put("createBy", n.getCreateBy());
|
m.put("createBy", n.getCreateBy());
|
||||||
m.put("createTime", fmt(n.getCreateTime()));
|
m.put("createTime", fmt(n.getCreateTime()));
|
||||||
m.put("updateBy", n.getUpdateBy());
|
m.put("updateBy", n.getUpdateBy());
|
||||||
@@ -943,7 +944,7 @@ public class NoticeService implements INoticeService {
|
|||||||
m.put("needSupervisor", nz(n.getNeedSupervisor()));
|
m.put("needSupervisor", nz(n.getNeedSupervisor()));
|
||||||
m.put("noticeStatus", n.getNoticeStatus());
|
m.put("noticeStatus", n.getNoticeStatus());
|
||||||
m.put("noticeStatusDesc", DormEnums.statusDesc(n.getNoticeStatus()));
|
m.put("noticeStatusDesc", DormEnums.statusDesc(n.getNoticeStatus()));
|
||||||
m.put("progress", "draft".equals(n.getNoticeStatus()) ? null : progress(n.getId(), n));
|
m.put("progress", "draft".equals(n.getNoticeStatus()) || "none".equals(n.getReceiptMode()) ? null : progress(n.getId(), n));
|
||||||
m.put("ChaoSend", fileItems(n.getFileIds()));
|
m.put("ChaoSend", fileItems(n.getFileIds()));
|
||||||
m.put("tlist", "ALL".equalsIgnoreCase(str(n.getReceiveList()).trim()) ? "all" : new ArrayList<>(targetRoomIds(n)));
|
m.put("tlist", "ALL".equalsIgnoreCase(str(n.getReceiveList()).trim()) ? "all" : new ArrayList<>(targetRoomIds(n)));
|
||||||
m.put("receiveType", "room");
|
m.put("receiveType", "room");
|
||||||
|
|||||||
Reference in New Issue
Block a user