update:修改工作组全部文件导出
This commit is contained in:
+80
-105
@@ -830,58 +830,53 @@ public class PayWorkingGroupServiceImpl extends ServiceImpl<PayWorkingGroupMappe
|
||||
@Override
|
||||
public void exportAllFile(HttpServletRequest request, HttpServletResponse response, PayWorkingGroup payWorkingGroup) {
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
if (StringUtils.isNotBlank(sysUser.getRoleCode())){
|
||||
if (StringUtils.isNotBlank(sysUser.getRoleCode())) {
|
||||
List<String> roleCodes = new ArrayList<>(Arrays.asList(sysUser.getRoleCode().split(",")));
|
||||
//管理员和财务查询全部,其余角色查询自己的
|
||||
if(!roleCodes.contains(constant.ADMIN)&&!roleCodes.contains(constant.CWRY)){
|
||||
if (!roleCodes.contains(constant.ADMIN) && !roleCodes.contains(constant.CWRY)) {
|
||||
payWorkingGroup.setPrincipalA(sysUser.getId());
|
||||
payWorkingGroup.setPrincipalB(sysUser.getId());
|
||||
}
|
||||
} else {
|
||||
throw new JeroBootException("登录用户角色为空!");
|
||||
}
|
||||
// 创建一个不分页的 Page 对象
|
||||
|
||||
Page<PayWorkingGroupVO> page = new Page<>(-1, -1);
|
||||
// 处理 workingGroupProject 字段
|
||||
String workingGroupProject = payWorkingGroup.getWorkingGroupProject();
|
||||
if (StringUtils.isNotBlank(workingGroupProject)) {
|
||||
payWorkingGroup.setWorkingGroupProject(oConvertUtils.replaceAllPercent(workingGroupProject));
|
||||
}
|
||||
// 查询分页列表
|
||||
|
||||
List<PayWorkingGroupVO> pageList = payWorkingGroupService.queryPageList(page, payWorkingGroup).getRecords();
|
||||
// 获取前端传递的 selections 参数
|
||||
String selections = request.getParameter("selections");
|
||||
List<String> ids = pageList.stream()
|
||||
.map(PayWorkingGroupVO::getId)
|
||||
.collect(Collectors.toList());
|
||||
List<String> ids = pageList.stream().map(PayWorkingGroupVO::getId).collect(Collectors.toList());
|
||||
|
||||
if (oConvertUtils.isNotEmpty(selections)) {
|
||||
List<String> selectionList = Arrays.asList(selections.split(","));
|
||||
ids.retainAll(selectionList); // 仅保留在 selections 中的 id
|
||||
ids.retainAll(selectionList);
|
||||
}
|
||||
|
||||
if (oConvertUtils.isEmpty(ids)) {
|
||||
throw new JeroBootException("没有工作组文件可以导出!");
|
||||
}
|
||||
Set<String> addedEntries = new HashSet<>(); // 用于记录已添加的条目路径
|
||||
|
||||
Set<String> addedEntries = new HashSet<>();
|
||||
|
||||
try (ZipOutputStream zipos = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()))) {
|
||||
response.reset();
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("multipart/form-data");
|
||||
// 设置压缩包的名字
|
||||
response.setContentType("application/zip");
|
||||
|
||||
String downloadName = UUID.randomUUID().toString() + ".zip";
|
||||
String agent = request.getHeader("USER-AGENT");
|
||||
try {
|
||||
if (agent != null) {
|
||||
if (agent.contains("MSIE") || agent.contains("Trident")) {
|
||||
downloadName = java.net.URLEncoder.encode(downloadName, "UTF-8");
|
||||
} else {
|
||||
downloadName = new String(downloadName.getBytes("UTF-8"), "ISO-8859-1");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
response.setHeader("Content-Disposition", "attachment;fileName=\"" + downloadName + "\"");
|
||||
|
||||
// 处理工作组资料
|
||||
for (String projectId : ids) {
|
||||
PayWorkingGroupDataFile payWorkingGroupDataFile = new PayWorkingGroupDataFile();
|
||||
payWorkingGroupDataFile.setProjectId(projectId);
|
||||
@@ -891,22 +886,21 @@ public class PayWorkingGroupServiceImpl extends ServiceImpl<PayWorkingGroupMappe
|
||||
if (payWorkingGroupDB == null) {
|
||||
throw new JeroBootException("工作组不存在!");
|
||||
}
|
||||
String groupName = payWorkingGroupDB.getWorkingGroupProject(); // 获取工作组名称
|
||||
|
||||
String groupName = payWorkingGroupDB.getWorkingGroupProject();
|
||||
String groupFolderPath = "工作组资料/" + groupName + "/";
|
||||
String researchProjectFolderPath = groupFolderPath + "在研项目/";
|
||||
String otherFilesFolderPath = groupFolderPath + "其他分发资料/";
|
||||
String chargeNoticeFolderPath = groupFolderPath + "收费通知/";
|
||||
|
||||
// 创建工作组文件夹
|
||||
zipos.putNextEntry(new ZipEntry(groupFolderPath));
|
||||
zipos.closeEntry();
|
||||
// 创建在研项目文件夹
|
||||
zipos.putNextEntry(new ZipEntry(researchProjectFolderPath));
|
||||
zipos.closeEntry();
|
||||
// 创建分发资料文件夹
|
||||
zipos.putNextEntry(new ZipEntry(otherFilesFolderPath));
|
||||
zipos.closeEntry();
|
||||
createEntry(zipos, groupFolderPath, addedEntries);
|
||||
createEntry(zipos, researchProjectFolderPath, addedEntries);
|
||||
createEntry(zipos, otherFilesFolderPath, addedEntries);
|
||||
createEntry(zipos, chargeNoticeFolderPath, addedEntries);
|
||||
|
||||
addFileToZip(payWorkingGroupDB.getChargeNoticeAId(), zipos, chargeNoticeFolderPath, addedEntries);
|
||||
addFileToZip(payWorkingGroupDB.getChargeNoticeBId(), zipos, chargeNoticeFolderPath, addedEntries);
|
||||
|
||||
// 在研项目的文件
|
||||
LambdaQueryWrapper<PayResearchProject> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(PayResearchProject::getWorkingGroupId, projectId);
|
||||
List<PayResearchProject> payResearchProjectList = payResearchProjectService.list(queryWrapper);
|
||||
@@ -914,80 +908,23 @@ public class PayWorkingGroupServiceImpl extends ServiceImpl<PayWorkingGroupMappe
|
||||
String projectName = payResearchProject.getProjectName();
|
||||
String projectFolderPath = researchProjectFolderPath + projectName + "/";
|
||||
|
||||
// 创建在研项目名文件夹
|
||||
zipos.putNextEntry(new ZipEntry(projectFolderPath));
|
||||
zipos.closeEntry();
|
||||
createEntry(zipos, projectFolderPath, addedEntries);
|
||||
|
||||
List<String> researchProjectFileIds = new ArrayList<>();
|
||||
if (!StringUtils.isEmpty(payResearchProject.getFiles())) {
|
||||
researchProjectFileIds.addAll(Arrays.asList(payResearchProject.getFiles().split(",")));
|
||||
}
|
||||
|
||||
// 添加在研项目的文件到在研项目名文件夹
|
||||
for (String fileId : researchProjectFileIds) {
|
||||
OSSFile ossFile = iossFileService.getById(fileId.trim());
|
||||
if (ossFile == null) {
|
||||
continue;
|
||||
}
|
||||
File file = new File(upLoadPath + File.separator + ossFile.getUrl());
|
||||
if (!file.exists()) {
|
||||
continue;
|
||||
}
|
||||
String entryPath = projectFolderPath + ossFile.getFileName();
|
||||
// 检查是否已经添加过相同路径的条目
|
||||
if (addedEntries.contains(entryPath)) {
|
||||
// 如果已经存在相同路径的条目,可以修改文件名或者跳过处理
|
||||
continue;
|
||||
}
|
||||
// 添加到压缩包中
|
||||
zipos.putNextEntry(new ZipEntry(entryPath));
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
byte[] b = new byte[1024];
|
||||
int length;
|
||||
while ((length = is.read(b)) != -1) {
|
||||
zipos.write(b, 0, length);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
zipos.closeEntry(); // 关闭当前条目
|
||||
addedEntries.add(entryPath); // 记录已添加的条目路径
|
||||
addFileToZip(fileId.trim(), zipos, projectFolderPath, addedEntries);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加工作组资料文件到分发资料文件夹
|
||||
for (PayWorkingGroupDataFile dataFile : fileList) {
|
||||
OSSFile ossFile = iossFileService.getById(dataFile.getFileId());
|
||||
if (ossFile == null) {
|
||||
continue;
|
||||
}
|
||||
File file = new File(upLoadPath + File.separator + ossFile.getUrl());
|
||||
if (!file.exists()) {
|
||||
continue;
|
||||
}
|
||||
String entryPath = otherFilesFolderPath + ossFile.getFileName();
|
||||
// 检查是否已经添加过相同路径的条目
|
||||
if (addedEntries.contains(entryPath)) {
|
||||
// 如果已经存在相同路径的条目,可以修改文件名或者跳过处理
|
||||
continue;
|
||||
}
|
||||
// 添加到压缩包中
|
||||
zipos.putNextEntry(new ZipEntry(entryPath));
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
byte[] b = new byte[1024];
|
||||
int length;
|
||||
while ((length = is.read(b)) != -1) {
|
||||
zipos.write(b, 0, length);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
zipos.closeEntry(); // 关闭当前条目
|
||||
addedEntries.add(entryPath); // 记录已添加的条目路径
|
||||
addFileToZip(dataFile.getFileId(), zipos, otherFilesFolderPath, addedEntries);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理工作组会议资料
|
||||
for (String projectId : ids) {
|
||||
LambdaQueryWrapper<PayMeeting> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(PayMeeting::getWorkingGroupId, projectId);
|
||||
@@ -998,16 +935,12 @@ public class PayWorkingGroupServiceImpl extends ServiceImpl<PayWorkingGroupMappe
|
||||
String meetingFolderPath = "会议资料/" + meetingName + "/";
|
||||
String meetingMinutesFolderPath = meetingFolderPath + "会议纪要/";
|
||||
String meetingDataFolderPath = meetingFolderPath + "上传文件/";
|
||||
String meetingNoticeFilesPath = meetingFolderPath + "会议通知/";
|
||||
|
||||
// 创建会议文件夹
|
||||
zipos.putNextEntry(new ZipEntry(meetingFolderPath));
|
||||
zipos.closeEntry();
|
||||
// 创建会议纪要文件夹
|
||||
zipos.putNextEntry(new ZipEntry(meetingMinutesFolderPath));
|
||||
zipos.closeEntry();
|
||||
// 创建上传文件文件夹
|
||||
zipos.putNextEntry(new ZipEntry(meetingDataFolderPath));
|
||||
zipos.closeEntry();
|
||||
createEntry(zipos, meetingFolderPath, addedEntries);
|
||||
createEntry(zipos, meetingMinutesFolderPath, addedEntries);
|
||||
createEntry(zipos, meetingDataFolderPath, addedEntries);
|
||||
createEntry(zipos, meetingNoticeFilesPath, addedEntries);
|
||||
|
||||
List<String> fileIds = new ArrayList<>();
|
||||
if (!StringUtils.isEmpty(payMeeting.getMeetingMinute())) {
|
||||
@@ -1016,6 +949,10 @@ public class PayWorkingGroupServiceImpl extends ServiceImpl<PayWorkingGroupMappe
|
||||
if (!StringUtils.isEmpty(payMeeting.getMeetingData())) {
|
||||
fileIds.addAll(Arrays.asList(payMeeting.getMeetingData().split(",")));
|
||||
}
|
||||
if (!StringUtils.isEmpty(payMeeting.getMeetingFiles())) {
|
||||
fileIds.addAll(Arrays.asList(payMeeting.getMeetingFiles().split(",")));
|
||||
}
|
||||
|
||||
for (String fileId : fileIds) {
|
||||
OSSFile ossFile = iossFileService.getById(fileId.trim());
|
||||
if (ossFile == null) {
|
||||
@@ -1025,19 +962,20 @@ public class PayWorkingGroupServiceImpl extends ServiceImpl<PayWorkingGroupMappe
|
||||
if (!file.exists()) {
|
||||
continue;
|
||||
}
|
||||
// 根据文件类型,放入对应的文件夹
|
||||
|
||||
String entryPath;
|
||||
if (payMeeting.getMeetingMinute() != null && Arrays.asList(payMeeting.getMeetingMinute().split(",")).contains(fileId)) {
|
||||
entryPath = meetingMinutesFolderPath + ossFile.getFileName();
|
||||
} else {
|
||||
} else if (payMeeting.getMeetingData() != null && Arrays.asList(payMeeting.getMeetingData().split(",")).contains(fileId)){
|
||||
entryPath = meetingDataFolderPath + ossFile.getFileName();
|
||||
} else {
|
||||
entryPath = meetingNoticeFilesPath + ossFile.getFileName();
|
||||
}
|
||||
// 检查是否已经添加过相同路径的条目
|
||||
|
||||
if (addedEntries.contains(entryPath)) {
|
||||
// 如果已经存在相同路径的条目,可以修改文件名或者跳过处理
|
||||
continue;
|
||||
}
|
||||
// 添加到压缩包中
|
||||
|
||||
zipos.putNextEntry(new ZipEntry(entryPath));
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
byte[] b = new byte[1024];
|
||||
@@ -1048,8 +986,8 @@ public class PayWorkingGroupServiceImpl extends ServiceImpl<PayWorkingGroupMappe
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
zipos.closeEntry(); // 关闭当前条目
|
||||
addedEntries.add(entryPath); // 记录已添加的条目路径
|
||||
zipos.closeEntry();
|
||||
addedEntries.add(entryPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1058,4 +996,41 @@ public class PayWorkingGroupServiceImpl extends ServiceImpl<PayWorkingGroupMappe
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void createEntry(ZipOutputStream zipos, String folderPath, Set<String> addedEntries) throws IOException {
|
||||
if (!addedEntries.contains(folderPath)) {
|
||||
zipos.putNextEntry(new ZipEntry(folderPath));
|
||||
zipos.closeEntry();
|
||||
addedEntries.add(folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void addFileToZip(String fileId, ZipOutputStream zipos, String folderPath, Set<String> addedEntries) throws IOException {
|
||||
OSSFile ossFile = iossFileService.getById(fileId);
|
||||
if (ossFile == null) {
|
||||
return;
|
||||
}
|
||||
File file = new File(upLoadPath + File.separator + ossFile.getUrl());
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
String entryPath = folderPath + ossFile.getFileName();
|
||||
if (addedEntries.contains(entryPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
zipos.putNextEntry(new ZipEntry(entryPath));
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
byte[] b = new byte[1024];
|
||||
int length;
|
||||
while ((length = is.read(b)) != -1) {
|
||||
zipos.write(b, 0, length);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
zipos.closeEntry();
|
||||
addedEntries.add(entryPath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user