@@ -238,6 +238,11 @@ | |||||
<scope>system</scope> | <scope>system</scope> | ||||
<systemPath>${project.basedir}/src/lib/kingbase8-8.2.0.jar</systemPath> | <systemPath>${project.basedir}/src/lib/kingbase8-8.2.0.jar</systemPath> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>com.alibaba</groupId> | |||||
<artifactId>easyexcel-core</artifactId> | |||||
<version>3.1.2</version> | |||||
</dependency> | |||||
</dependencies> | </dependencies> | ||||
<!-- 打包 --> | <!-- 打包 --> | ||||
<!--配置环境的profile--> | <!--配置环境的profile--> | ||||
@@ -0,0 +1,71 @@ | |||||
package com.ningdatech.pmapi.common.util; | |||||
import java.io.UnsupportedEncodingException; | |||||
import java.net.URLEncoder; | |||||
import java.util.UUID; | |||||
import java.util.function.BiConsumer; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import org.apache.http.HttpStatus; | |||||
import com.alibaba.fastjson.JSON; | |||||
import com.ningdatech.basic.model.ApiResponse; | |||||
import com.ningdatech.basic.util.StrPool; | |||||
import cn.hutool.poi.excel.ExcelUtil; | |||||
import lombok.SneakyThrows; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
/** | |||||
* <p> | |||||
* ExcelDownUtil | |||||
* </p> | |||||
* | |||||
* @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 <T> void down(HttpServletResponse response, T param, BiConsumer<HttpServletResponse, T> consumer) { | |||||
response.setCharacterEncoding("utf-8"); | |||||
try { | |||||
consumer.accept(response, param); | |||||
} catch (Exception e) { | |||||
log.error("文件导出失败:", e); | |||||
response.reset(); | |||||
response.setContentType(StrPool.CONTENT_TYPE); | |||||
ApiResponse<Void> res = ApiResponse.of(HttpStatus.SC_BAD_REQUEST, "导出失败", null); | |||||
response.setStatus(HttpStatus.SC_BAD_REQUEST); | |||||
response.getWriter().println(JSON.toJSONString(res)); | |||||
} | |||||
} | |||||
public static <T> void downXls(HttpServletResponse response, T param, BiConsumer<HttpServletResponse, T> consumer) { | |||||
response.setContentType(ExcelUtil.XLS_CONTENT_TYPE); | |||||
down(response, param, consumer); | |||||
} | |||||
public static <T> void downXlsx(HttpServletResponse response, T param, BiConsumer<HttpServletResponse, T> consumer) { | |||||
response.setContentType(ExcelUtil.XLSX_CONTENT_TYPE); | |||||
down(response, param, consumer); | |||||
} | |||||
public static void setFileName(String fileName, HttpServletResponse response) { | |||||
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + encodeName(fileName) + ".xls"); | |||||
} | |||||
} |
@@ -0,0 +1,80 @@ | |||||
package com.ningdatech.pmapi.common.util; | |||||
import org.apache.poi.ss.usermodel.*; | |||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle; | |||||
import com.alibaba.excel.write.metadata.style.WriteFont; | |||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; | |||||
/** | |||||
* <p> | |||||
* ExcelExportStyle | |||||
* </p> | |||||
* | |||||
* @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); | |||||
} | |||||
} |
@@ -1,8 +1,10 @@ | |||||
package com.ningdatech.pmapi.todocenter.controller; | package com.ningdatech.pmapi.todocenter.controller; | ||||
import javax.servlet.http.HttpServletResponse; | |||||
import javax.validation.Valid; | import javax.validation.Valid; | ||||
import com.ningdatech.pmapi.common.util.ExcelDownUtil; | |||||
import org.springframework.web.bind.annotation.GetMapping; | import org.springframework.web.bind.annotation.GetMapping; | ||||
import org.springframework.web.bind.annotation.ModelAttribute; | import org.springframework.web.bind.annotation.ModelAttribute; | ||||
import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
@@ -34,7 +36,7 @@ public class TodoCenterController { | |||||
private final TodoCenterManage todoCenterManage; | private final TodoCenterManage todoCenterManage; | ||||
/** | /** | ||||
* 查询待办中心-待我处理中非增补项目列表 | |||||
* 待办中心-待我处理项目列表查询 | |||||
* @param param | * @param param | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -44,4 +46,16 @@ public class TodoCenterController { | |||||
return ApiResponse.ofSuccess(result); | 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); | |||||
} | |||||
} | } |
@@ -1,9 +1,13 @@ | |||||
package com.ningdatech.pmapi.todocenter.manage; | package com.ningdatech.pmapi.todocenter.manage; | ||||
import cn.hutool.core.collection.CollectionUtil; | import cn.hutool.core.collection.CollectionUtil; | ||||
import com.alibaba.excel.EasyExcel; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||
import com.ningdatech.basic.util.NdDateUtils; | import com.ningdatech.basic.util.NdDateUtils; | ||||
import com.ningdatech.pmapi.common.constant.ProjectDeclareConstants; | 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.enums.ProcessStatusEnum; | ||||
import com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProjectListExportDTO; | |||||
import com.ningdatech.pmapi.user.util.LoginUserUtil; | import com.ningdatech.pmapi.user.util.LoginUserUtil; | ||||
import com.wflow.workflow.bean.dto.ProcessInstanceOwnerDto; | import com.wflow.workflow.bean.dto.ProcessInstanceOwnerDto; | ||||
import com.wflow.workflow.bean.process.OrgUser; | import com.wflow.workflow.bean.process.OrgUser; | ||||
@@ -27,6 +31,8 @@ import com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProcessedDTO; | |||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
import javax.servlet.http.HttpServletResponse; | |||||
import java.io.IOException; | |||||
import java.util.HashSet; | import java.util.HashSet; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
@@ -121,4 +127,26 @@ public class TodoCenterManage { | |||||
} | } | ||||
public void exportProjectList(HttpServletResponse response, ReqToBeProcessedDTO param) { | |||||
PageVo<ResToBeProcessedDTO> page = | |||||
queryProjectList(param); | |||||
List<ResToBeProcessedDTO> collect = (List<ResToBeProcessedDTO>) page.getRecords(); | |||||
String fileName = null; | |||||
if (param.getIsSupplement()){ | |||||
fileName = "增补项目列表"; | |||||
}else { | |||||
fileName = "非增补项目列表"; | |||||
} | |||||
ExcelDownUtil.setFileName(fileName,response); | |||||
//数据导出处理函数 | |||||
try { | |||||
EasyExcel.write(response.getOutputStream(), ResToBeProjectListExportDTO.class) | |||||
.autoCloseStream(false) | |||||
.registerWriteHandler(ExcelExportStyle.formalStyle()) | |||||
.sheet(fileName) | |||||
.doWrite(collect); | |||||
} catch (IOException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | |||||
} | } |
@@ -0,0 +1,42 @@ | |||||
package com.ningdatech.pmapi.todocenter.model.dto.res; | |||||
import com.alibaba.excel.annotation.ExcelProperty; | |||||
import com.wflow.workflow.bean.vo.ProcessTaskVo; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.AllArgsConstructor; | |||||
import lombok.Data; | |||||
import lombok.NoArgsConstructor; | |||||
import java.io.Serializable; | |||||
import java.time.LocalDateTime; | |||||
/** | |||||
* 待办中心待我处理项目列表导出实体 | |||||
* | |||||
* @author CMM | |||||
* @since 2023/01/19 16:42 | |||||
*/ | |||||
@Data | |||||
@NoArgsConstructor | |||||
@AllArgsConstructor | |||||
public class ResToBeProjectListExportDTO implements Serializable { | |||||
private static final long serialVersionUID = 1L; | |||||
@ExcelProperty("项目名称") | |||||
private String projectName; | |||||
@ExcelProperty("申报单位") | |||||
private String reportUnitName; | |||||
@ExcelProperty("申报金额") | |||||
private Integer reportAmount; | |||||
@ExcelProperty("预算年度") | |||||
private Integer budgetYear; | |||||
@ExcelProperty("流程状态") | |||||
private String processStatusName; | |||||
@ExcelProperty("发起时间") | |||||
private LocalDateTime processLaunchTime; | |||||
} |