From facdb5f52a7f82be2803b4dc4fbe425ec69bf392 Mon Sep 17 00:00:00 2001 From: hongqiwei <1143662660@qq.com> Date: Mon, 7 Sep 2026 17:18:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=B0=E9=9A=BE=E5=B8=AE=E6=89=B6=E9=98=85?= =?UTF-8?q?=E8=A7=88=E5=A2=9E=E5=8A=A0=E5=AF=BC=E5=87=BA=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=88=E5=88=86=E5=B7=A5=E4=BC=9A=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E9=80=9A=E5=90=8E=E6=89=8D=E8=83=BD=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DifficultHelpMineController.java | 2 + .../DifficultHelpReadingController.java | 32 ++++ .../service/DifficultHelpCommonService.java | 20 ++ .../impl/DifficultHelpCommonServiceImpl.java | 177 ++++++++++++++++++ .../difficulthelp/reading/index.html | 10 + 5 files changed, 241 insertions(+) diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/controller/DifficultHelpMineController.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/controller/DifficultHelpMineController.java index c5120d0..81ef657 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/controller/DifficultHelpMineController.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/controller/DifficultHelpMineController.java @@ -102,6 +102,8 @@ public class DifficultHelpMineController { Cnd cnd = Cnd.NEW(); pageParam.buildSearch(cnd, "info."); cnd.and("info.createdBy", "=", SecurityUtil.getUserId()); + // 同一进行中任务存在多个参与人时,按困难补助申请主表 ID 去重,保证每条申请只展示一次。 + cnd.groupBy("info.id"); if (StrUtil.isAllBlank(pageParam.getPageOrderName(), pageParam.getPageOrderBy())) { cnd.desc("info.applyTime"); } else { diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/controller/DifficultHelpReadingController.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/controller/DifficultHelpReadingController.java index 8efb535..257c97f 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/controller/DifficultHelpReadingController.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/controller/DifficultHelpReadingController.java @@ -4,6 +4,7 @@ import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import com.budwk.app.base.page.Pagination; import com.budwk.app.base.result.Result; +import com.budwk.app.base.utils.CommonDownloadUtil; import com.budwk.app.flow.engine.FlowEngine; import com.budwk.app.zhgh.staffbenefit.difficulthelp.service.DifficultHelpCommonService; import com.budwk.app.zhgh.staffbenefit.difficulthelp.vo.DifficultHelpPageParam; @@ -21,6 +22,9 @@ import org.nutz.mvc.annotation.At; import org.nutz.mvc.annotation.Ok; import org.nutz.mvc.annotation.Param; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + /** * @version 1.0 * @Author zzr @@ -94,6 +98,34 @@ public class DifficultHelpReadingController { return Result.success().addData(pagination); } + /** + * 导出当前阅览条件下困难补助申请人上传的附件。 + * + * @param pageParam 阅览页筛选条件,包含年度、受助人关键字、所属工会和所属单位 + * @param response HTTP 文件下载响应,返回名为“困难补助附件.zip”的 ZIP 二进制文件 + */ + @At + @Ok("void") + @ApiOperation("导出困难补助附件压缩包") + @SaCheckPermission("difficultHelp.reading") + public void exportAttachmentZip(DifficultHelpPageParam pageParam, HttpServletResponse response) throws IOException { + byte[] zipBytes = difficultHelpCommonService.exportAttachmentZip(pageParam); + CommonDownloadUtil.download("困难补助附件.zip", zipBytes, response); + } + + /** + * 校验当前筛选范围内是否存在可导出的困难补助附件。 + * + * @param pageParam 阅览页筛选条件,包含年度、受助人关键字、所属工会和所属单位 + * @return 布尔值;true 表示存在分工会审核已同意且已上传附件的申请 + */ + @At + @ApiOperation("校验困难补助可导出附件") + @SaCheckPermission("difficultHelp.reading") + public Result hasExportableAttachment(DifficultHelpPageParam pageParam) { + return Result.success(difficultHelpCommonService.hasExportableAttachment(pageParam)); + } + @At @SaCheckLogin diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/service/DifficultHelpCommonService.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/service/DifficultHelpCommonService.java index 34b6e29..7d0fb64 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/service/DifficultHelpCommonService.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/service/DifficultHelpCommonService.java @@ -2,6 +2,9 @@ package com.budwk.app.zhgh.staffbenefit.difficulthelp.service; import com.budwk.app.base.service.BaseService; import com.budwk.app.zhgh.staffbenefit.difficulthelp.models.DifficultHelpInfo; +import com.budwk.app.zhgh.staffbenefit.difficulthelp.vo.DifficultHelpPageParam; + +import java.io.IOException; /** * @version 1.0 @@ -11,4 +14,21 @@ import com.budwk.app.zhgh.staffbenefit.difficulthelp.models.DifficultHelpInfo; * @注释 */ public interface DifficultHelpCommonService extends BaseService { + + /** + * 按困难补助阅览页的查询条件生成分工会审核已同意申请的附件压缩包。 + * + * @param pageParam 阅览页筛选参数,包含年度、工会、单位、受助人关键字及当前用户的数据范围 + * @return ZIP 二进制内容,内部按“姓名(工号)”目录归档该受助人的上传附件 + * @throws IOException 文件下载或 ZIP 写入失败时抛出 + */ + byte[] exportAttachmentZip(DifficultHelpPageParam pageParam) throws IOException; + + /** + * 判断当前阅览筛选范围内是否存在可导出的困难补助附件。 + * + * @param pageParam 阅览页筛选参数,包含年度、工会、单位、受助人关键字及当前用户的数据范围 + * @return 分工会审核已同意且已上传附件时返回 true,否则返回 false + */ + boolean hasExportableAttachment(DifficultHelpPageParam pageParam); } diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/service/impl/DifficultHelpCommonServiceImpl.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/service/impl/DifficultHelpCommonServiceImpl.java index d6d1696..e7cfcd9 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/service/impl/DifficultHelpCommonServiceImpl.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/service/impl/DifficultHelpCommonServiceImpl.java @@ -1,11 +1,30 @@ package com.budwk.app.zhgh.staffbenefit.difficulthelp.service.impl; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; import com.budwk.app.base.service.impl.BaseServiceImpl; +import com.budwk.app.flow.enums.ProcessSubmitTypeEnum; +import com.budwk.app.flow.enums.ProcessTaskStateEnum; +import com.budwk.app.sys.services.SysFileService; import com.budwk.app.zhgh.staffbenefit.difficulthelp.models.DifficultHelpInfo; import com.budwk.app.zhgh.staffbenefit.difficulthelp.service.DifficultHelpCommonService; +import com.budwk.app.zhgh.staffbenefit.difficulthelp.vo.DifficultHelpPageParam; +import lombok.extern.slf4j.Slf4j; +import org.nutz.dao.Cnd; import org.nutz.dao.Dao; +import org.nutz.dao.Sqls; +import org.nutz.dao.sql.Sql; +import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + /** * @version 1.0 * @Author zzr @@ -13,10 +32,168 @@ import org.nutz.ioc.loader.annotation.IocBean; * @Date 2025/7/31 9:16 * @注释 */ +@Slf4j @IocBean(args = {"refer:dao"}) public class DifficultHelpCommonServiceImpl extends BaseServiceImpl implements DifficultHelpCommonService { + /** 困难补助流程中“分工会审核”节点的实际 wf 节点编码。 */ + private static final String BRANCH_UNION_AUDIT_TASK_NAME = "9d11798e-a0e4-4ff5-939b-e6c5519e0eb6"; + + @Inject + private SysFileService sysFileService; + public DifficultHelpCommonServiceImpl(Dao dao) { super(dao); } + + /** + * 根据阅览页筛选结果下载分工会审核已同意的附件,并以受助人姓名和工号作为 ZIP 内目录。 + * 无附件、文件记录不存在或文件下载失败的记录会跳过,避免单个异常附件影响其他附件导出。 + * + * @param pageParam 阅览页筛选条件,数据权限由 {@link DifficultHelpPageParam#buildSearch(Cnd, String)} 统一处理 + * @return 困难补助附件 ZIP 的二进制内容 + * @throws IOException ZIP 输出流创建或关闭失败时抛出 + */ + @Override + public byte[] exportAttachmentZip(DifficultHelpPageParam pageParam) throws IOException { + List helpInfoList = listBranchUnionApprovedHelpInfo(pageParam); + + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) { + Set entryNames = new HashSet<>(); + for (DifficultHelpInfo helpInfo : helpInfoList) { + if (helpInfo.getFiles() == null || helpInfo.getFiles().isEmpty()) { + continue; + } + String folderName = buildFolderName(helpInfo); + for (JSONObject file : helpInfo.getFiles()) { + String fileId = getFileId(file); + if (StrUtil.isBlank(fileId)) { + continue; + } + try { + byte[] fileBytes = sysFileService.download(fileId); + String entryName = getUniqueEntryName(folderName, file.getStr("name"), entryNames); + zipOutputStream.putNextEntry(new ZipEntry(entryName)); + zipOutputStream.write(fileBytes); + zipOutputStream.closeEntry(); + } catch (IOException e) { + // 单个附件异常时保留其余可用附件,便于管理员完成批量导出。 + log.warn("困难补助附件导出失败,申请记录ID:{},文件ID:{}", helpInfo.getId(), fileId, e); + } + } + } + zipOutputStream.finish(); + return outputStream.toByteArray(); + } + } + + /** + * 判断当前筛选范围内是否有分工会审核已同意且已上传的附件。 + * + * @param pageParam 阅览页筛选条件,数据权限由 {@link DifficultHelpPageParam#buildSearch(Cnd, String)} 统一处理 + * @return 存在至少一条可导出附件时返回 true + */ + @Override + public boolean hasExportableAttachment(DifficultHelpPageParam pageParam) { + return listBranchUnionApprovedHelpInfo(pageParam).stream() + .anyMatch(helpInfo -> helpInfo.getFiles() != null && !helpInfo.getFiles().isEmpty()); + } + + /** + * 查询当前数据权限范围内,最新分工会审核任务已同意的困难补助申请。 + * 同一申请被退回后再次审核时,仅认可最新一次分工会审核结果,防止历史同意记录绕过当前流程状态。 + * + * @param pageParam 阅览页筛选条件,包含年度、工会、单位和受助人关键字 + * @return 已通过分工会审核的困难补助申请列表 + */ + private List listBranchUnionApprovedHelpInfo(DifficultHelpPageParam pageParam) { + Sql approvedBusinessSql = Sqls.create(""" + SELECT ins.businessNo + FROM wf_process_instance ins + INNER JOIN wf_process_task branchTask ON branchTask.processInstanceId = ins.id + WHERE branchTask.taskName = @branchUnionAuditTaskName + AND branchTask.id = ( + SELECT MAX(latestBranchTask.id) + FROM wf_process_task latestBranchTask + WHERE latestBranchTask.processInstanceId = ins.id + AND latestBranchTask.taskName = @branchUnionAuditTaskName + ) + AND branchTask.taskState = @finishedTaskState + AND JSON_UNQUOTE(JSON_EXTRACT(branchTask.variable, '$.submitType')) = @agreeSubmitType + """); + approvedBusinessSql.setParam("branchUnionAuditTaskName", BRANCH_UNION_AUDIT_TASK_NAME); + approvedBusinessSql.setParam("finishedTaskState", ProcessTaskStateEnum.FINISHED.getCode()); + approvedBusinessSql.setParam("agreeSubmitType", String.valueOf(ProcessSubmitTypeEnum.AGREE.getCode())); + + Cnd cnd = Cnd.NEW(); + pageParam.buildSearch(cnd, "info."); + cnd.and("info.id", "in", approvedBusinessSql); + cnd.desc("info.applyTime"); + + Sql sql = Sqls.create(""" + SELECT info.* + FROM difficult_help_info info + $condition + """); + sql.setCondition(cnd); + return listEntity(sql); + } + + /** + * 从 file-upload 保存的响应数据中提取系统文件 ID。 + * + * @param file 上传组件保存的附件信息,响应数据格式为 /platform/sys/file/download?id=文件ID + * @return 系统文件 ID;附件信息不完整时返回空字符串 + */ + private String getFileId(JSONObject file) { + if (file == null || file.getJSONObject("response") == null) { + return StrUtil.EMPTY; + } + String downloadUrl = file.getJSONObject("response").getStr("data"); + String fileId = StrUtil.subAfter(downloadUrl, "id=", true); + return StrUtil.subBefore(fileId, "&", false); + } + + /** + * 为同一受助人的附件创建稳定且不含路径分隔符的目录名称。 + * + * @param helpInfo 困难补助申请信息,包含受助人姓名和工号 + * @return ZIP 内的受助人目录名称 + */ + private String buildFolderName(DifficultHelpInfo helpInfo) { + String userName = sanitizeEntryName(StrUtil.blankToDefault(helpInfo.getUserName(), "未命名受助人")); + String loginName = sanitizeEntryName(StrUtil.blankToDefault(helpInfo.getLoginName(), "无工号")); + return userName + "(" + loginName + ")"; + } + + /** + * 为附件生成不重复的 ZIP 条目名称,防止同一受助人上传同名文件时被覆盖。 + * + * @param folderName 受助人目录名称 + * @param fileName 原始附件名称 + * @param entryNames 已写入 ZIP 的条目名称集合 + * @return 可安全写入 ZIP 的唯一条目名称 + */ + private String getUniqueEntryName(String folderName, String fileName, Set entryNames) { + String safeFileName = sanitizeEntryName(StrUtil.blankToDefault(fileName, "未命名附件")); + String entryName = folderName + "/" + safeFileName; + int duplicateIndex = 1; + while (entryNames.contains(entryName)) { + entryName = folderName + "/" + duplicateIndex + "_" + safeFileName; + duplicateIndex++; + } + entryNames.add(entryName); + return entryName; + } + + /** + * 清理 ZIP 条目中的路径和 Windows 非法字符,避免附件名称改变 ZIP 目录结构。 + * + * @param entryName 用户姓名、工号或上传文件名 + * @return 可用于 ZIP 单级目录或文件名的安全字符串 + */ + private String sanitizeEntryName(String entryName) { + return entryName.replaceAll("[\\\\/:*?\"<>|\\r\\n]", "_"); + } } diff --git a/src/main/resources/views/platform/zhgh/staffbenefit/difficulthelp/reading/index.html b/src/main/resources/views/platform/zhgh/staffbenefit/difficulthelp/reading/index.html index fdf9242..adf78cf 100644 --- a/src/main/resources/views/platform/zhgh/staffbenefit/difficulthelp/reading/index.html +++ b/src/main/resources/views/platform/zhgh/staffbenefit/difficulthelp/reading/index.html @@ -42,6 +42,7 @@ layout("/layouts/platform.html"){ + 导出附件Zip { + if (res.code === 0 && res.data) { + this.$downLoad(loc() + "/exportAttachmentZip", this.pageForm) + } else { + this.$message.warning("当前筛选范围内没有可导出的附件") + } + }) + }, openView(row) { this.$refs.guava.view(() => { this.$refs.infoRef.onOpen(row)