diff --git a/src/main/java/com/budwk/app/base/utils/SysOfficeTemplateUtil.java b/src/main/java/com/budwk/app/base/utils/SysOfficeTemplateUtil.java index d71d801..d1fcd09 100644 --- a/src/main/java/com/budwk/app/base/utils/SysOfficeTemplateUtil.java +++ b/src/main/java/com/budwk/app/base/utils/SysOfficeTemplateUtil.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; import com.budwk.app.base.exception.BaseException; import com.budwk.app.sys.models.Sys_file; import com.budwk.app.sys.models.Sys_office_template; +import com.budwk.app.sys.services.SysFileService; import com.budwk.app.sys.utils.SysFileMinIoUtil; import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.config.Configure; @@ -22,6 +23,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.util.List; import java.util.ArrayList; import java.util.LinkedHashSet; @@ -39,6 +41,9 @@ public class SysOfficeTemplateUtil { @Inject private Dao dao; + @Inject + private SysFileService sysFileService; + public String getTemplateFileName(String templateCode) { Sys_office_template officeTemplate = dao.fetch(Sys_office_template.class, Cnd.where(Sys_office_template::getTemplateCode, "=", templateCode)); if (ObjectUtil.isNull(officeTemplate)) { @@ -70,7 +75,16 @@ public class SysOfficeTemplateUtil { if (ObjectUtil.isEmpty(sysFile)) { throw new BaseException("模板文件不存在"); } - byte[] fileBytes = SysFileMinIoUtil.getFileBytes(sysFile.getBucket(), sysFile.getStoragePath()); + byte[] fileBytes; + try { + fileBytes = sysFileService.download(id); + } catch (IOException e) { + log.error("模板文件读取失败,templateCode={},fileId={}", templateCode, id, e); + throw new BaseException("模板 {} 的文件读取失败:{}", templateCode, e.getMessage()); + } + if (fileBytes == null || fileBytes.length == 0) { + throw new BaseException("模板 {} 的文件为空或读取失败,文件名:{}", templateCode, sysFile.getName()); + } return new ByteArrayInputStream(fileBytes); } 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 ccbce50..8f268e0 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 @@ -2,7 +2,6 @@ package com.budwk.app.zhgh.staffbenefit.difficulthelp.controller; import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; -import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; import cn.dev33.satoken.annotation.SaCheckLogin; @@ -327,11 +326,33 @@ public class DifficultHelpReadingController { @At @Ok("void") + @SaCheckPermission("difficultHelp.reading") + public void exportReadingApply(String id, DifficultHelpPageParam pageParam, HttpServletResponse response, Boolean print) throws Exception { + Cnd cnd = Cnd.where("id", "=", id); + pageParam.buildReadingSearch(cnd, ""); + if (difficultHelpCommonService.count(cnd) == 0) { + throw new RuntimeException("该记录不在当前可查看的范围内,无法导出"); + } + doExportApply(id, response, print); + } + + @At + @Ok("void") + @SaCheckLogin public void doExportApply(String id, HttpServletResponse response, Boolean print) throws Exception { DifficultHelpInfo difficultHelp = difficultHelpCommonService.fetch(id); if (difficultHelp == null) { throw new RuntimeException("该条记录不存在"); } + boolean ownApply = AuthUtil.hasPermission("difficultHelp.mine") + && SecurityUtil.getUserId().equals(difficultHelp.getCreatedBy()); + if (!ownApply) { + Cnd cnd = Cnd.where("id", "=", id); + new DifficultHelpPageParam().buildReadingSearch(cnd, ""); + if (!AuthUtil.hasPermission("difficultHelp.reading") || difficultHelpCommonService.count(cnd) == 0) { + throw new RuntimeException("该记录不在当前可查看的范围内,无法导出"); + } + } HashMap docData = new HashMap<>(); docData.put("unionName", difficultHelp.getUnitName()); @@ -493,6 +514,7 @@ public class DifficultHelpReadingController { info.subsidyStandards, info.bankOfDeposit, info.bankCardNum, + info.money, info.applyCount FROM difficult_help_info info @@ -504,12 +526,40 @@ public class DifficultHelpReadingController { cnd.groupBy("info.id"); sql.setCondition(cnd); List list = difficultHelpCommonService.listMap(sql); - Sys_user user = sysUserService.fetch(SecurityUtil.getUserId()); for (int i = 0; i < list.size(); i++) { list.get(i).put("index", (i + 1)); } + String fileName = "困难慰问汇总表_" + DateUtil.format(new Date(), "yyyyMMdd"); + if ("xlsx".equals(flag)) { + String[][] columns = { + {"序号", "index"}, {"姓名", "userName"}, {"工号", "loginName"}, + {"性别", "sex"}, {"身份证号", "idCard"}, {"年龄", "age"}, + {"职务", "position"}, {"职称", "officialCapacity"}, {"所属单位", "unitName"}, + {"手机号码", "mobile"}, {"生活致困原因", "reason"}, {"级别", "level"}, + {"家庭年总收入", "homeIncome"}, {"家庭人数", "homeNumber"}, + {"困难类型", "subsidyStandards"}, {"开户行", "bankOfDeposit"}, + {"银行卡号", "bankCardNum"}, {"实际金额(元)", "money"}, {"申请次数", "applyCount"} + }; + List entities = new ArrayList<>(); + for (String[] column : columns) { + entities.add(new ExcelExportEntity(column[0], column[1], 20)); + } + ExportParams exportParams = new ExportParams(); + exportParams.setType(ExcelType.XSSF); + exportParams.setTitle("困难帮扶汇总表"); + exportParams.setSheetName("汇总数据"); + try (Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entities, list)) { + CommonDownloadUtil.download(fileName + ".xlsx", workbook, response); + } catch (Exception e) { + log.error("导出Excel汇总表失败", e); + throw new RuntimeException("导出Excel汇总表失败:" + e.getMessage(), e); + } + return; + } + + Sys_user user = sysUserService.fetch(SecurityUtil.getUserId()); result.put("schoolName", "中国地址大学(武汉)"); result.put("year", DateUtil.format(new Date(), "yyyy")); result.put("applyTime", DateUtil.format(new Date(), "yyyy年MM月dd日")); @@ -517,32 +567,12 @@ public class DifficultHelpReadingController { result.put("mobile", user.getMobile()); result.put("da", list); - String resource; - if ("xlsx".equals(flag)) { - resource = "difficulty_summary_xlsx"; - if (AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name())) { - resource = "difficulty_summary_school_xlsx"; - } - } else { - resource = "difficulty_summary"; - if (AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name())) { - resource = "difficulty_summary_school"; - } + String resource = "difficulty_summary"; + if (AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name())) { + resource = "difficulty_summary_school"; } - String fileName = "困难慰问汇总表_" + DateUtil.format(new Date(), "yyyyMMdd"); - - if ("xlsx".equals(flag)) { - try { - InputStream is = sysOfficeTemplateUtil.getTemplate(resource); - TemplateExportParams exportParams = new TemplateExportParams(is, null); - Workbook workbook = ExcelExportUtil.exportExcel(exportParams, result); - CommonDownloadUtil.download(fileName + ".xlsx", workbook, response); - } catch (Exception e) { - log.error("导出Excel汇总表失败", e); - throw new RuntimeException("导出Excel汇总表失败:" + e.getMessage()); - } - } else if ("docx".equals(flag)) { + if ("docx".equals(flag)) { try (InputStream input = sysOfficeTemplateUtil.getTemplate(resource)) { Configure config = Configure.builder() .bind("da", new LoopRowTableRenderPolicy()) 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 5d8bb68..c7c806a 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 @@ -129,11 +129,7 @@ public class DifficultHelpCommonServiceImpl extends BaseServiceImpl infoList = dao().query(DifficultHelpInfo.class, cnd); // 3. 构建用户缴费索引 (userId -> year -> money) diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/vo/DifficultHelpPageParam.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/vo/DifficultHelpPageParam.java index 2269bd9..eaedccb 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/vo/DifficultHelpPageParam.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/difficulthelp/vo/DifficultHelpPageParam.java @@ -9,6 +9,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import org.nutz.dao.Cnd; import org.nutz.dao.util.cri.SqlExpressionGroup; +import org.nutz.dao.util.cri.Static; import org.nutz.lang.Lang; import java.util.List; @@ -35,6 +36,9 @@ public class DifficultHelpPageParam extends PageForm { public void buildReadingSearch(Cnd cnd, String prefix) { buildSearch(cnd, prefix, false); applyReadingScope(cnd, prefix); + String recordPrefix = StrUtil.isBlank(prefix) ? "difficult_help_info." : prefix; + cnd.and(new Static("EXISTS (SELECT 1 FROM wf_process_instance reading_instance WHERE reading_instance.businessNo = " + + recordPrefix + "id AND reading_instance.state = 20)")); } public void applyReadingScope(Cnd cnd, String prefix) { 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 fbe105e..2e3babf 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 @@ -45,8 +45,8 @@ layout("/layouts/platform.html"){ 导入实际金额 导出补助金额 导出申请表(压缩包) - 导出汇总表(excel) - 导出汇总表(word) + 导出汇总表(Excel) +