From d962aa2469ec362711180062f85104a1afbdf133 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 25 Jul 2023 00:23:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=93=E5=AE=B6?= =?UTF-8?q?=E8=B4=B9=E7=94=A8=E5=8D=95=E3=80=81=E8=AF=84=E5=AE=A1=E8=A1=A8?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ningdatech/pmapi/common/util/WordUtil.java | 7 +- .../controller/MeetingExportController.java | 16 +- .../meeting/entity/dto/ExpertFeeExportDTO.java | 27 +- .../pmapi/meeting/entity/dto/ExpertInfoDTO.java | 38 + .../meeting/entity/dto/ExpertInviteTableDTO.java | 34 + .../meeting/entity/dto/LaborFeeAuditTableDTO.java | 26 + .../pmapi/meeting/manage/ExpertExportManage.java | 102 +- .../main/resources/template/专家抽取表.ftl | 1361 ++++++++++++++++++++ pmapi/src/main/resources/template/专家费.ftl | 2 +- .../main/resources/template/劳务费发放.ftl | 885 +++++++++++++ 10 files changed, 2461 insertions(+), 37 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertInfoDTO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertInviteTableDTO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/LaborFeeAuditTableDTO.java create mode 100644 pmapi/src/main/resources/template/专家抽取表.ftl create mode 100644 pmapi/src/main/resources/template/劳务费发放.ftl diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/WordUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/WordUtil.java index b6d173d..9a32ad9 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/WordUtil.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/WordUtil.java @@ -1,6 +1,7 @@ package com.ningdatech.pmapi.common.util; import com.ningdatech.pmapi.meeting.entity.dto.ExpertFeeExportDTO; +import com.ningdatech.pmapi.meeting.entity.dto.ExpertInfoDTO; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; @@ -98,9 +99,9 @@ public class WordUtil { dto.setMeetingAddress("杭州市滨江区海创还能到我当时防守打法十大发放"); dto.setMeetingTime("2023-01-01 12:20"); dto.setProjectName("阿萨法舒服舒服舒服舒服送达方"); - dto.setTableData(new ArrayList<>()); + dto.setExperts(new ArrayList<>()); for (int i = 0; i < 100; i++) { - ExpertFeeExportDTO.ExpertInfoDTO expert = new ExpertFeeExportDTO.ExpertInfoDTO(); + ExpertInfoDTO expert = new ExpertInfoDTO(); expert.setNo(i); expert.setBank("中国建设银行"); expert.setMobile("17839192616"); @@ -110,7 +111,7 @@ public class WordUtil { expert.setName("张三"); expert.setSex("男"); expert.setIdcard("121212121121"); - dto.getTableData().add(expert); + dto.getExperts().add(expert); } create(dto, "专家费.ftl", "/Users/wendy/Desktop/", "专家费.doc"); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java index 0ac0126..542845d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java @@ -29,7 +29,7 @@ public class MeetingExportController { private final ExpertExportManage expertExportManage; - @GetMapping("/feeForExpert/{meetingId}") + @GetMapping("/expertFee/{meetingId}") @ApiOperation("专家费用单导出") public void exportFeeForExpert(@PathVariable Long meetingId, HttpServletResponse response) { expertExportManage.exportFeeForExpert(meetingId, response); @@ -37,8 +37,20 @@ public class MeetingExportController { @GetMapping("/expertReviewTable/{meetingId}") @ApiOperation("专家评审单导出") - public void expertReviewTable(@PathVariable Long meetingId, HttpServletResponse response) { + public void exportExpertReviewTable(@PathVariable Long meetingId, HttpServletResponse response) { expertExportManage.expertReviewTable(meetingId, response); } + @GetMapping("/laborFeeAuditTable/{meetingId}") + @ApiOperation("劳务费发放单导出") + public void exportLaborFeeAuditTable(@PathVariable Long meetingId, HttpServletResponse response) { + expertExportManage.laborFeeAuditTable(meetingId, response); + } + + @GetMapping("/expertInviteTable/{meetingId}") + @ApiOperation("专家评审单导出") + public void exportExpertInviteTable(@PathVariable Long meetingId, HttpServletResponse response) { + expertExportManage.expertInviteTable(meetingId, response); + } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertFeeExportDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertFeeExportDTO.java index 68b2e64..0c2effe 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertFeeExportDTO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertFeeExportDTO.java @@ -2,8 +2,6 @@ package com.ningdatech.pmapi.meeting.entity.dto; import lombok.Data; -import java.math.BigDecimal; -import java.security.SecureRandom; import java.util.List; /** @@ -23,30 +21,7 @@ public class ExpertFeeExportDTO { private String meetingTime; - private List tableData; - - @Data - public static class ExpertInfoDTO { - - private Integer no; - - private String name; - - private String bank; - - private String bankNo; - - private String mobile; - - private String sex; - - private String company; - - private BigDecimal fee; - - private String idcard; - - } + private List experts; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertInfoDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertInfoDTO.java new file mode 100644 index 0000000..5b350a8 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertInfoDTO.java @@ -0,0 +1,38 @@ +package com.ningdatech.pmapi.meeting.entity.dto; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + *

+ * ExpertInfoDTO + *

+ * + * @author WendyYang + * @since 2023/7/24 + **/ +@Data +public class ExpertInfoDTO { + + private Integer no; + + private String name; + + private String bank; + + private String bankNo; + + private String mobile; + + private String sex; + + private String company; + + private String job; + + private BigDecimal fee; + + private String idcard; + +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertInviteTableDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertInviteTableDTO.java new file mode 100644 index 0000000..fcef7fe --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertInviteTableDTO.java @@ -0,0 +1,34 @@ +package com.ningdatech.pmapi.meeting.entity.dto; + +import lombok.Data; + +import java.util.List; + +/** + *

+ * ExpertInviteTableDTO + *

+ * + * @author WendyYang + * @since 2023/7/24 + **/ +@Data +public class ExpertInviteTableDTO { + + private List experts; + + private String projectCode; + + private String projectName; + + private String meetingCreateBy; + + private String meetingUsageTime; + + private String meetingAddress; + + private String meetingTime; + + private String buildOrg; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/LaborFeeAuditTableDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/LaborFeeAuditTableDTO.java new file mode 100644 index 0000000..1b0966d --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/LaborFeeAuditTableDTO.java @@ -0,0 +1,26 @@ +package com.ningdatech.pmapi.meeting.entity.dto; + +import lombok.Data; + +import java.util.List; + +/** + *

+ * LaborFeeAuditTableDTO + *

+ * + * @author WendyYang + * @since 2023/7/24 + **/ +@Data +public class LaborFeeAuditTableDTO { + + private String projectName; + + private String meetingTime; + + private Integer expertCount; + + private List experts; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java index a5239b6..954f6a0 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java @@ -1,5 +1,6 @@ package com.ningdatech.pmapi.meeting.manage; +import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.UUID; import cn.hutool.core.util.StrUtil; import com.ningdatech.basic.exception.BizException; @@ -11,8 +12,7 @@ import com.ningdatech.pmapi.meeting.entity.domain.Meeting; import com.ningdatech.pmapi.meeting.entity.domain.MeetingExpert; import com.ningdatech.pmapi.meeting.entity.domain.MeetingInnerProject; import com.ningdatech.pmapi.meeting.entity.domain.MeetingOuterProject; -import com.ningdatech.pmapi.meeting.entity.dto.ExpertFeeExportDTO; -import com.ningdatech.pmapi.meeting.entity.dto.ExpertReviewTableDTO; +import com.ningdatech.pmapi.meeting.entity.dto.*; import com.ningdatech.pmapi.meeting.service.IMeetingExpertService; import com.ningdatech.pmapi.meeting.service.IMeetingInnerProjectService; import com.ningdatech.pmapi.meeting.service.IMeetingOuterProjectService; @@ -31,6 +31,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; /** @@ -72,7 +73,7 @@ public class ExpertExportManage { inners.forEach(w -> projectNames.add(w.getProjectName())); } data.setProjectName(StrUtil.join("、", projectNames)); - data.setTableData(new ArrayList<>()); + data.setExperts(new ArrayList<>()); // 设置专家信息 List experts = meetingExpertService.listAgreedExperts(meetingId); List expertIds = CollUtils.fieldList(experts, MeetingExpert::getExpertId); @@ -80,7 +81,7 @@ public class ExpertExportManage { Map expertMap = CollUtils.listToMap(expertInfos, ExpertUserFullInfo::getUserId); AtomicInteger integer = new AtomicInteger(0); experts.forEach(w -> { - ExpertFeeExportDTO.ExpertInfoDTO expert = new ExpertFeeExportDTO.ExpertInfoDTO(); + ExpertInfoDTO expert = new ExpertInfoDTO(); expert.setNo(integer.incrementAndGet()); expert.setFee(BigDecimal.valueOf(500)); expert.setName(w.getExpertName()); @@ -93,7 +94,7 @@ public class ExpertExportManage { expert.setCompany(expertUser.getCompany()); expert.setSex(expertUser.getGender()); } - data.getTableData().add(expert); + data.getExperts().add(expert); }); WordUtil.export(fileName, data, response, template); } catch (TemplateException | IOException e) { @@ -129,4 +130,95 @@ public class ExpertExportManage { } } + public void laborFeeAuditTable(Long meetingId, HttpServletResponse response) { + final String template = "劳务费发放.ftl"; + String fileName = UUID.randomUUID().toString(true) + ".doc"; + try { + Meeting meeting = meetingService.getById(meetingId); + LaborFeeAuditTableDTO data = new LaborFeeAuditTableDTO(); + data.setMeetingTime(DateUtil.localDateTimeFormat(meeting.getStartTime(), "yyyy-MM-dd HH:mm")); + List projectNames = new ArrayList<>(); + if (meeting.getIsInnerProject()) { + List inners = meetingInnerProjectService.listByMeetingId(meetingId); + List projectIds = CollUtils.fieldList(inners, MeetingInnerProject::getProjectId); + List projects = projectService.listByIds(projectIds); + projects.forEach(w -> projectNames.add(w.getProjectName())); + } else { + List inners = meetingOuterProjectService.listByMeetingId(meetingId); + inners.forEach(w -> projectNames.add(w.getProjectName())); + } + data.setProjectName(StrUtil.join("、", projectNames)); + data.setExperts(new ArrayList<>()); + // 设置专家信息 + List experts = meetingExpertService.listAgreedExperts(meetingId); + List expertIds = CollUtils.fieldList(experts, MeetingExpert::getExpertId); + List expertInfos = expertUserInfoService.listByUserId(expertIds); + Map expertMap = CollUtils.listToMap(expertInfos, ExpertUserFullInfo::getUserId); + experts.forEach(w -> { + ExpertInfoDTO expert = new ExpertInfoDTO(); + expert.setName(w.getExpertName()); + ExpertUserFullInfo expertUser = expertMap.get(w.getExpertId()); + if (expertUser != null) { + expert.setCompany(expertUser.getCompany()); + expert.setJob(expertUser.getAdministrativeDuties()); + } + data.getExperts().add(expert); + }); + data.setExpertCount(experts.size()); + WordUtil.export(fileName, data, response, template); + } catch (TemplateException | IOException e) { + log.error("劳务费发放审批单导出异常:{}", meetingId, e); + throw BizException.wrap("劳务费发放审批单导出失败"); + } + } + + public void expertInviteTable(Long meetingId, HttpServletResponse response) { + final String template = "专家抽取表.ftl"; + try { + Meeting meeting = meetingService.getById(meetingId); + ExpertInviteTableDTO data = new ExpertInviteTableDTO(); + data.setMeetingTime(DateUtil.localDateTimeFormat(meeting.getStartTime(), "yyyy-MM-dd HH:mm")); + data.setMeetingUsageTime(Objects.equals(1, meeting.getMeetingUsageTime()) ? "半天" : "一天"); + data.setMeetingCreateBy(meeting.getCreator()); + data.setMeetingAddress(meeting.getMeetingAddress()); + if (meeting.getIsInnerProject()) { + List inners = meetingInnerProjectService.listByMeetingId(meetingId); + Assert.isTrue(inners.size() == 1, "专家抽取表导出失败"); + Project project = projectService.getById(inners.get(0).getProjectId()); + data.setProjectCode(project.getProjectCode()); + data.setProjectName(project.getProjectName()); + data.setBuildOrg(project.getBuildOrgName()); + } else { + List inners = meetingOuterProjectService.listByMeetingId(meetingId); + Assert.isTrue(inners.size() == 1, "专家抽取表导出失败"); + data.setProjectName(inners.get(0).getProjectName()); + data.setProjectCode(StrUtil.EMPTY); + data.setBuildOrg(StrUtil.EMPTY); + } + data.setExperts(new ArrayList<>()); + // 设置专家信息 + List experts = meetingExpertService.listAgreedExperts(meetingId); + List expertIds = CollUtils.fieldList(experts, MeetingExpert::getExpertId); + List expertInfos = expertUserInfoService.listByUserId(expertIds); + Map expertMap = CollUtils.listToMap(expertInfos, ExpertUserFullInfo::getUserId); + AtomicInteger integer = new AtomicInteger(0); + experts.forEach(w -> { + ExpertInfoDTO expert = new ExpertInfoDTO(); + expert.setNo(integer.incrementAndGet()); + expert.setName(w.getExpertName()); + expert.setMobile(w.getMobile()); + ExpertUserFullInfo expertUser = expertMap.get(w.getExpertId()); + if (expertUser != null) { + expert.setCompany(expertUser.getCompany()); + } + data.getExperts().add(expert); + }); + String fileName = UUID.randomUUID().toString(true) + ".doc"; + WordUtil.export(fileName, data, response, template); + } catch (Exception e) { + log.error("专家抽取表导出异常:{}", meetingId, e); + throw BizException.wrap("专家抽取表导出失败"); + } + } + } diff --git a/pmapi/src/main/resources/template/专家抽取表.ftl b/pmapi/src/main/resources/template/专家抽取表.ftl new file mode 100644 index 0000000..9514b14 --- /dev/null +++ b/pmapi/src/main/resources/template/专家抽取表.ftl @@ -0,0 +1,1361 @@ + + + + Data + 潦草迷茫 + 2023-07-21T00:04:00Z + 2023-07-24T23:54:20Z + 1440 + 14 + + + wqlLaW5nc29mdCBQREYgdG8gV1BTIDkw + 2023-07-24T17:28:04Z + 2052-5.5.1.7991 + BB348C58014F7E88AC9EBE649F4580AC_43 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 信息化项目专家抽取表 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 项目编码 + + + + + + + + + + + + + + + + + + + + + + + + + + ${projectCode} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 项目名称 + + + + + + + + + + + + + + + + + + + + + + + + + ${projectName} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 建设单位 + + + + + + + + + + + + + + + + + + + + + + + + ${buildOrg} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 评审地点 + + + + + + + + + + + + + + + + + + + + + + + + ${meetingAddress} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 评审时间 + + + + + + + + + + + + + + + + + + + + + + + + ${meetingTime} + + + + + + + + + + + + + + + + + + + + 评审耗时 + + + + + + + + + + + + + + + + + + + + + + + ${meetingUsageTime} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 抽取人 + + + + + + + + + + + + + + + + + + + + + + ${meetingCreateBy} + + + + + + + + + + + + + + + + + + + + 监督人 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 序号 + + + + + + + + + + + + + + + + + + + + + 姓名 + + + + + + + + + + + + + + + + + + + + + 电话 + + + + + + + + + + + + + + + + + + + + 工作单位 + + + + + + + + + + + + + + + + + + + + + 签名 + + + + + <#list experts as expert> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${expert.no} + + + + + + + + + + + + + + + + + + + + + + + ${expert.name} + + + + + + + + + + + + + + + + + + + + + + + ${expert.mobile} + + + + + + + + + + + + + + + + + + + + + + + ${expert.company} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pmapi/src/main/resources/template/专家费.ftl b/pmapi/src/main/resources/template/专家费.ftl index 19f61e9..8d1786b 100644 --- a/pmapi/src/main/resources/template/专家费.ftl +++ b/pmapi/src/main/resources/template/专家费.ftl @@ -938,7 +938,7 @@ - <#list tableData as rowData> + <#list experts as rowData> diff --git a/pmapi/src/main/resources/template/劳务费发放.ftl b/pmapi/src/main/resources/template/劳务费发放.ftl new file mode 100644 index 0000000..2191840 --- /dev/null +++ b/pmapi/src/main/resources/template/劳务费发放.ftl @@ -0,0 +1,885 @@ + + +pdfbuilderKingsoft-PDF潦草迷茫2023-07-25T01:28:00Z2023-07-24T20:57:44Z864014 + wqlLaW5nc29mdCBQREYgdG8gV1BTIDg1 + 2023-07-24T17:28:23Z + 64be4428423552001fc57fc5 + 2052-5.5.1.7991 + FAEC9044C61332E24875BE64CD024754_43 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 劳务费发放审批单 + + + + 制表单位(盖章): + + + + + + + + + + + + + + + + + + + + + + + + + + 劳务活动项目 + + + + + + ${projectName} + + + + + + + + + + + 活动时间 + + + + + + ${meetingTime} + + + + + + + + + + + 劳务费类别 + + + + + + □讲课费□稿费□考务(监考费) + + + + □评审费□其他项目 + + + + + + + + + + + 发放标准 + + + + + + 500元/人 + + + + + + + + + + + 有关情况说明 + + + + + + 通过市信息化专家库系统抽取 + + ${expertCount} + + 名专家。 + + + + + + + + + + + 发放清单 + + + + + + + + + + + 姓名 + + + + + + 工作单位 + + + + + + 职务(职称) + + + + + + 标准 + + + + + + 发放金额 + + + + + (元) + + + + + + 签字 + <#list experts as expert> + + + + + + + + + + + ${expert.name} + + + + + + ${expert.company} + + + + + + ${(expert.job)!} + + + + + + 半天 + + + + + + 500 + + + + + + + + + + + + + + + + 发放单位审批意见 + + + + + + + + + + + 业务部门意见 + + + + + + + + 分管领导意见 + + + + + + 单位负责人 + + + + + (财务审批人)意见 + + + + + + + + + + + 经办人意见 + + + + + + 部门负责人意见 + + + + + + + + + + + + + + + + + + + + + + + (签字) + + + + + + + + + + + + + + + + + + + + + + + + + + + (签字): + + + + + + + + + + + + + + + + + + + + + + + + + + + 分管领导(签字): + + + + + + + + + + + + + + + + + + + + + + + + + 负责人(财务审批人) + + + + + (签字): + + + + + + + + + + + + + + + \ No newline at end of file From 31471113744b8f09586123f4ce8c65bb07f162ad Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 25 Jul 2023 10:20:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8A=B3=E5=8A=A1=E8=B4=B9=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=A2=9E=E5=8A=A0=E8=B4=B9=E7=94=A8=E6=A0=87=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MeetingExportController.java | 2 +- .../meeting/entity/dto/LaborFeeAuditTableDTO.java | 2 ++ .../pmapi/meeting/manage/ExpertExportManage.java | 23 ++++++++++++++++++---- .../main/resources/template/劳务费发放.ftl | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java index 542845d..b742e40 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java @@ -29,7 +29,7 @@ public class MeetingExportController { private final ExpertExportManage expertExportManage; - @GetMapping("/expertFee/{meetingId}") + @GetMapping("/expertFeeTable/{meetingId}") @ApiOperation("专家费用单导出") public void exportFeeForExpert(@PathVariable Long meetingId, HttpServletResponse response) { expertExportManage.exportFeeForExpert(meetingId, response); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/LaborFeeAuditTableDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/LaborFeeAuditTableDTO.java index 1b0966d..f4cb201 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/LaborFeeAuditTableDTO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/LaborFeeAuditTableDTO.java @@ -23,4 +23,6 @@ public class LaborFeeAuditTableDTO { private List experts; + private String meetingUsageTime; + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java index 954f6a0..02ae9c5 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java @@ -21,7 +21,7 @@ import com.ningdatech.pmapi.projectlib.model.entity.Project; import com.ningdatech.pmapi.projectlib.service.IProjectService; import com.ningdatech.pmapi.sms.utils.DateUtil; import freemarker.template.TemplateException; -import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -31,8 +31,8 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; /** *

@@ -44,7 +44,7 @@ import java.util.concurrent.atomic.AtomicInteger; **/ @Slf4j @Component -@AllArgsConstructor +@RequiredArgsConstructor public class ExpertExportManage { private final IMeetingService meetingService; @@ -54,6 +54,20 @@ public class ExpertExportManage { private final IExpertUserFullInfoService expertUserInfoService; private final IProjectService projectService; + //================================================================================================================== + + static Function meetingUsageTime = (type) -> { + if (1 == type) { + return "半天"; + } + if (2 == type) { + return "一天"; + } + return StrUtil.EMPTY; + }; + + //================================================================================================================== + public void exportFeeForExpert(Long meetingId, HttpServletResponse response) { final String template = "专家费.ftl"; String fileName = UUID.randomUUID().toString(true) + ".doc"; @@ -137,6 +151,7 @@ public class ExpertExportManage { Meeting meeting = meetingService.getById(meetingId); LaborFeeAuditTableDTO data = new LaborFeeAuditTableDTO(); data.setMeetingTime(DateUtil.localDateTimeFormat(meeting.getStartTime(), "yyyy-MM-dd HH:mm")); + data.setMeetingUsageTime(meetingUsageTime.apply(meeting.getMeetingUsageTime())); List projectNames = new ArrayList<>(); if (meeting.getIsInnerProject()) { List inners = meetingInnerProjectService.listByMeetingId(meetingId); @@ -178,7 +193,7 @@ public class ExpertExportManage { Meeting meeting = meetingService.getById(meetingId); ExpertInviteTableDTO data = new ExpertInviteTableDTO(); data.setMeetingTime(DateUtil.localDateTimeFormat(meeting.getStartTime(), "yyyy-MM-dd HH:mm")); - data.setMeetingUsageTime(Objects.equals(1, meeting.getMeetingUsageTime()) ? "半天" : "一天"); + data.setMeetingUsageTime(meetingUsageTime.apply(meeting.getMeetingUsageTime())); data.setMeetingCreateBy(meeting.getCreator()); data.setMeetingAddress(meeting.getMeetingAddress()); if (meeting.getIsInnerProject()) { diff --git a/pmapi/src/main/resources/template/劳务费发放.ftl b/pmapi/src/main/resources/template/劳务费发放.ftl index 2191840..af6bcc0 100644 --- a/pmapi/src/main/resources/template/劳务费发放.ftl +++ b/pmapi/src/main/resources/template/劳务费发放.ftl @@ -599,7 +599,7 @@ - 半天 + ${meetingUsageTime} From 22ca1ecacf2cafe2585c2e402895d4b045454ab9 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 25 Jul 2023 10:35:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9word=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/common/util/FreemarkerWordUtil.java | 113 +++++++++++++++++++ .../com/ningdatech/pmapi/common/util/WordUtil.java | 120 --------------------- .../pmapi/meeting/manage/ExpertExportManage.java | 10 +- 3 files changed, 118 insertions(+), 125 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/FreemarkerWordUtil.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/WordUtil.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/FreemarkerWordUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/FreemarkerWordUtil.java new file mode 100644 index 0000000..dca4042 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/FreemarkerWordUtil.java @@ -0,0 +1,113 @@ +package com.ningdatech.pmapi.common.util; + +import cn.hutool.core.io.IoUtil; +import com.ningdatech.basic.exception.BizException; +import com.ningdatech.pmapi.meeting.entity.dto.ExpertFeeExportDTO; +import com.ningdatech.pmapi.meeting.entity.dto.ExpertInfoDTO; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.entity.ContentType; +import org.springframework.core.io.ByteArrayResource; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.math.BigDecimal; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; + +/** + *

+ * FreemarkerWordUtil + *

+ * + * @author WendyYang + * @since 2023/7/24 + **/ +@Slf4j +public class FreemarkerWordUtil { + + private static final Configuration CONFIGURATION = new Configuration(Configuration.VERSION_2_3_31); + + static { + CONFIGURATION.setDefaultEncoding("UTF-8"); + CONFIGURATION.setClassForTemplateLoading(FreemarkerWordUtil.class, "/template"); + } + + /** + * 生成word文件 + * + * @param dataMap word中需要展示的动态数据,用map集合来保存 + * @param templateName word模板名称,例如:test.ftl + * @param filePath 文件生成的目标路径,例如:D:/wordFile/ + * @param fileName 生成的文件名称,例如:test.doc + */ + public static void create(Object dataMap, String templateName, String filePath, String fileName) { + try { + Template template = CONFIGURATION.getTemplate(templateName); + //输出文件 + File outFile = new File(filePath + File.separator + fileName); + //如果输出目标文件夹不存在,则创建 + if (!outFile.getParentFile().exists()) { + boolean ignore = outFile.getParentFile().mkdirs(); + } + //将模板和数据模型合并生成文件 + Writer out = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(outFile.toPath()), StandardCharsets.UTF_8)); + //生成文件 + template.process(dataMap, out); + IoUtil.flush(out); + IoUtil.close(out); + } catch (Exception e) { + log.error("根据模版生成Word文件失败:", e); + throw BizException.wrap("根据模版生成Word文件失败"); + } + } + + public static void export(String fileName, Object data, HttpServletResponse response, String templateName) throws TemplateException, IOException { + Template template = CONFIGURATION.getTemplate(templateName); + StringWriter out = new StringWriter(); + Writer writer = new BufferedWriter(out, 4096); + template.process(data, writer); + response.setCharacterEncoding(StandardCharsets.UTF_8.displayName()); + response.setContentType(ContentType.APPLICATION_JSON.getMimeType()); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + URLEncoder.encode(fileName, "UTF-8")); + try (InputStream is = new ByteArrayResource(out.toString().getBytes(StandardCharsets.UTF_8)).getInputStream(); + ServletOutputStream outputStream = response.getOutputStream()) { + // 缓冲区 + byte[] buffer = new byte[1024]; + int bytesToRead; + // 通过循环将读入的Word文件的内容输出到浏览器中 + while ((bytesToRead = is.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesToRead); + } + } + } + + public static void main(String[] args) { + ExpertFeeExportDTO dto = new ExpertFeeExportDTO(); + dto.setMeetingAddress("杭州市滨江区海创还能到我当时防守打法十大发放"); + dto.setMeetingTime("2023-01-01 12:20"); + dto.setProjectName("阿萨法舒服舒服舒服舒服送达方"); + dto.setExperts(new ArrayList<>()); + for (int i = 0; i < 10; i++) { + ExpertInfoDTO expert = new ExpertInfoDTO(); + expert.setNo(i); + expert.setBank("中国建设银行"); + expert.setMobile("17819392616"); + expert.setBankNo("6111111172121324354"); + expert.setCompany("宁达科技有限公司"); + expert.setFee(BigDecimal.valueOf(500)); + expert.setName("张三丰"); + expert.setSex("男"); + expert.setIdcard("1212121211212121"); + dto.getExperts().add(expert); + } + create(dto, "专家费.ftl", "/Users/wendy/Desktop/", "专家费.doc"); + } + + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/WordUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/WordUtil.java deleted file mode 100644 index 9a32ad9..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/WordUtil.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.ningdatech.pmapi.common.util; - -import com.ningdatech.pmapi.meeting.entity.dto.ExpertFeeExportDTO; -import com.ningdatech.pmapi.meeting.entity.dto.ExpertInfoDTO; -import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateException; -import org.springframework.core.io.ByteArrayResource; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; -import java.io.*; -import java.math.BigDecimal; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.ArrayList; - -/** - *

- * WordUtil - *

- * - * @author WendyYang - * @since 2023/7/24 - **/ -public class WordUtil { - - private static final Configuration CONFIGURATION = new Configuration(Configuration.VERSION_2_3_31); - - static { - CONFIGURATION.setDefaultEncoding("UTF-8"); - CONFIGURATION.setClassForTemplateLoading(WordUtil.class, "/template"); - } - - /** - * 生成word文件 - * - * @param dataMap word中需要展示的动态数据,用map集合来保存 - * @param templateName word模板名称,例如:test.ftl - * @param filePath 文件生成的目标路径,例如:D:/wordFile/ - * @param fileName 生成的文件名称,例如:test.doc - */ - public static void create(Object dataMap, String templateName, String filePath, String fileName) { - try { - - - //获取模板 - Template template = CONFIGURATION.getTemplate(templateName); - - //输出文件 - File outFile = new File(filePath + File.separator + fileName); - - //如果输出目标文件夹不存在,则创建 - if (!outFile.getParentFile().exists()) { - boolean ignore = outFile.getParentFile().mkdirs(); - } - - //将模板和数据模型合并生成文件 - Writer out = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(outFile.toPath()), StandardCharsets.UTF_8)); - - //生成文件 - template.process(dataMap, out); - - //关闭流 - out.flush(); - out.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static void export(String fileName, Object data, HttpServletResponse response, String templateName) throws TemplateException, IOException { - Template template = CONFIGURATION.getTemplate(templateName); - StringWriter out = new StringWriter(); - Writer writer = new BufferedWriter(out, 4096); - template.process(data, writer); - InputStream fin = new ByteArrayResource(out.toString().getBytes(StandardCharsets.UTF_8)).getInputStream(); - ServletOutputStream outputStream; - response.setCharacterEncoding(StandardCharsets.UTF_8.displayName()); - response.setContentType("application/json"); - response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + URLEncoder.encode(fileName, "UTF-8")); - outputStream = response.getOutputStream(); - // 缓冲区 - byte[] buffer = new byte[1024]; - int bytesToRead; - // 通过循环将读入的Word文件的内容输出到浏览器中 - while ((bytesToRead = fin.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesToRead); - } - if (outputStream != null) { - outputStream.close(); - } - fin.close(); - } - - public static void main(String[] args) { - ExpertFeeExportDTO dto = new ExpertFeeExportDTO(); - dto.setMeetingAddress("杭州市滨江区海创还能到我当时防守打法十大发放"); - dto.setMeetingTime("2023-01-01 12:20"); - dto.setProjectName("阿萨法舒服舒服舒服舒服送达方"); - dto.setExperts(new ArrayList<>()); - for (int i = 0; i < 100; i++) { - ExpertInfoDTO expert = new ExpertInfoDTO(); - expert.setNo(i); - expert.setBank("中国建设银行"); - expert.setMobile("17839192616"); - expert.setBankNo("121212121212121212"); - expert.setCompany("宁大科技有限公司"); - expert.setFee(BigDecimal.valueOf(500)); - expert.setName("张三"); - expert.setSex("男"); - expert.setIdcard("121212121121"); - dto.getExperts().add(expert); - } - create(dto, "专家费.ftl", "/Users/wendy/Desktop/", "专家费.doc"); - } - - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java index 02ae9c5..8752cf6 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java @@ -5,7 +5,7 @@ import cn.hutool.core.lang.UUID; import cn.hutool.core.util.StrUtil; import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.util.CollUtils; -import com.ningdatech.pmapi.common.util.WordUtil; +import com.ningdatech.pmapi.common.util.FreemarkerWordUtil; import com.ningdatech.pmapi.expert.entity.ExpertUserFullInfo; import com.ningdatech.pmapi.expert.service.IExpertUserFullInfoService; import com.ningdatech.pmapi.meeting.entity.domain.Meeting; @@ -110,7 +110,7 @@ public class ExpertExportManage { } data.getExperts().add(expert); }); - WordUtil.export(fileName, data, response, template); + FreemarkerWordUtil.export(fileName, data, response, template); } catch (TemplateException | IOException e) { log.error("专家费用单导出异常:{}", meetingId, e); throw BizException.wrap("专家费用单导出失败"); @@ -137,7 +137,7 @@ public class ExpertExportManage { inners.forEach(w -> projectNames.add(w.getProjectName())); } data.setProjectName(StrUtil.join("、", projectNames)); - WordUtil.export(fileName, data, response, template); + FreemarkerWordUtil.export(fileName, data, response, template); } catch (TemplateException | IOException e) { log.error("专家评审单导出异常:{}", meetingId, e); throw BizException.wrap("专家评审单导出失败"); @@ -180,7 +180,7 @@ public class ExpertExportManage { data.getExperts().add(expert); }); data.setExpertCount(experts.size()); - WordUtil.export(fileName, data, response, template); + FreemarkerWordUtil.export(fileName, data, response, template); } catch (TemplateException | IOException e) { log.error("劳务费发放审批单导出异常:{}", meetingId, e); throw BizException.wrap("劳务费发放审批单导出失败"); @@ -229,7 +229,7 @@ public class ExpertExportManage { data.getExperts().add(expert); }); String fileName = UUID.randomUUID().toString(true) + ".doc"; - WordUtil.export(fileName, data, response, template); + FreemarkerWordUtil.export(fileName, data, response, template); } catch (Exception e) { log.error("专家抽取表导出异常:{}", meetingId, e); throw BizException.wrap("专家抽取表导出失败");