From 63877cc12fce5db53e69941c1dd4eee9e12eaa9f Mon Sep 17 00:00:00 2001
From: CMM <2198256324@qq.com>
Date: Thu, 19 Jan 2023 16:56:25 +0800
Subject: [PATCH] =?UTF-8?q?=E5=BE=85=E5=8A=9E=E4=B8=AD=E5=BF=83=E9=A1=B9?=
=?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E5=AF=BC=E5=87=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pmapi/pom.xml | 5 ++
.../pmapi/common/util/ExcelDownUtil.java | 71 +++++++++++++++++++
.../pmapi/common/util/ExcelExportStyle.java | 80 ++++++++++++++++++++++
.../controller/TodoCenterController.java | 16 ++++-
.../pmapi/todocenter/manage/TodoCenterManage.java | 28 ++++++++
.../model/dto/res/ResToBeProjectListExportDTO.java | 42 ++++++++++++
6 files changed, 241 insertions(+), 1 deletion(-)
create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/ExcelDownUtil.java
create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/ExcelExportStyle.java
create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/dto/res/ResToBeProjectListExportDTO.java
diff --git a/pmapi/pom.xml b/pmapi/pom.xml
index c9326b5..e009967 100644
--- a/pmapi/pom.xml
+++ b/pmapi/pom.xml
@@ -238,6 +238,11 @@
+ * ExcelDownUtil + *
+ * + * @author WendyYang + * @since 00:48 2022/11/5 + */ +@Slf4j +public class ExcelDownUtil { + + private static String encodeName(String name) { + String fileName; + try { + fileName = URLEncoder.encode(name, "UTF-8"); + } catch (UnsupportedEncodingException e) { + log.error("文件名编码异常:", e); + fileName = UUID.randomUUID().toString().replace("-", ""); + } + return fileName; + } + + @SneakyThrows + private static+ * ExcelExportStyle + *
+ * + * @author WendyYang + * @since 01:39 2022/11/5 + */ +public class ExcelExportStyle { + + public static HorizontalCellStyleStrategy formalStyle() { + // 表头样式策略 + WriteCellStyle headStyle = new WriteCellStyle(); + // 是否换行 + headStyle.setWrapped(false); + // 水平对齐方式 + headStyle.setHorizontalAlignment(HorizontalAlignment.LEFT); + // 垂直对齐方式 + headStyle.setVerticalAlignment(VerticalAlignment.CENTER); + // 前景色 + headStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + // 背景色 + headStyle.setFillBackgroundColor(IndexedColors.AUTOMATIC.getIndex()); + + // 设置为1时,单元格将被前景色填充 + headStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); + // 控制单元格是否应自动调整大小以适应文本过长时的大小 + headStyle.setShrinkToFit(false); + // 单元格边框类型 + headStyle.setBorderBottom(BorderStyle.NONE); + headStyle.setBorderLeft(BorderStyle.NONE); + headStyle.setBorderRight(BorderStyle.NONE); + headStyle.setBorderTop(BorderStyle.NONE); + // 单元格边框颜色 + headStyle.setLeftBorderColor(IndexedColors.BLACK.index); + headStyle.setRightBorderColor(IndexedColors.BLACK.index); + headStyle.setTopBorderColor(IndexedColors.BLACK.index); + headStyle.setBottomBorderColor(IndexedColors.BLACK.index); + // 字体策略 + WriteFont writeFont = new WriteFont(); + // 是否加粗/黑体 + writeFont.setBold(false); + // 字体颜色 + writeFont.setColor(Font.COLOR_NORMAL); + // 字体名称 + writeFont.setFontName("宋体"); + // 字体大小 + writeFont.setFontHeightInPoints((short) 11); + // 是否使用斜体 + writeFont.setItalic(false); + // 是否在文本中使用横线删除 + writeFont.setStrikeout(false); + // 设置要使用的文本下划线的类型 + writeFont.setUnderline(Font.U_NONE); + // 设置要使用的字符集 + writeFont.setCharset((int) Font.DEFAULT_CHARSET); + headStyle.setWriteFont(writeFont); + + // 内容样式策略策略 + WriteCellStyle contentStyle = new WriteCellStyle(); + contentStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); + contentStyle.setHorizontalAlignment(HorizontalAlignment.GENERAL); + contentStyle.setBorderBottom(BorderStyle.NONE); + contentStyle.setBorderLeft(BorderStyle.NONE); + contentStyle.setBorderRight(BorderStyle.NONE); + contentStyle.setBorderTop(BorderStyle.NONE); + contentStyle.setFillPatternType(FillPatternType.NO_FILL); + contentStyle.setWrapped(false); + return new HorizontalCellStyleStrategy(headStyle, contentStyle); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/controller/TodoCenterController.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/controller/TodoCenterController.java index 0340347..1e8756d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/controller/TodoCenterController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/controller/TodoCenterController.java @@ -1,8 +1,10 @@ package com.ningdatech.pmapi.todocenter.controller; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import com.ningdatech.pmapi.common.util.ExcelDownUtil; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; @@ -34,7 +36,7 @@ public class TodoCenterController { private final TodoCenterManage todoCenterManage; /** - * 查询待办中心-待我处理中非增补项目列表 + * 待办中心-待我处理项目列表查询 * @param param * @return */ @@ -44,4 +46,16 @@ public class TodoCenterController { return ApiResponse.ofSuccess(result); } + /** + * 待办中心-待我处理项目列表导出 + * + * @param param + * @param response + * @return void + */ + @GetMapping("/export") + public void exportProjectList(ReqToBeProcessedDTO param, HttpServletResponse response){ + ExcelDownUtil.downXlsx(response,param,todoCenterManage::exportProjectList); + } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java index f9d3f68..8268ac5 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java @@ -1,9 +1,13 @@ package com.ningdatech.pmapi.todocenter.manage; import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ningdatech.basic.util.NdDateUtils; import com.ningdatech.pmapi.common.constant.ProjectDeclareConstants; +import com.ningdatech.pmapi.common.util.ExcelDownUtil; +import com.ningdatech.pmapi.common.util.ExcelExportStyle; import com.ningdatech.pmapi.todocenter.enums.ProcessStatusEnum; +import com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProjectListExportDTO; import com.ningdatech.pmapi.user.util.LoginUserUtil; import com.wflow.workflow.bean.dto.ProcessInstanceOwnerDto; import com.wflow.workflow.bean.process.OrgUser; @@ -27,6 +31,8 @@ import com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProcessedDTO; import lombok.RequiredArgsConstructor; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -121,4 +127,26 @@ public class TodoCenterManage { } + public void exportProjectList(HttpServletResponse response, ReqToBeProcessedDTO param) { + PageVo