修改需求计划导出及导出样式修改

This commit is contained in:
haozq 2026-02-06 14:21:24 +08:00
parent 1d07f0dc22
commit c2da457c39
7 changed files with 254 additions and 2 deletions

View File

@ -4,9 +4,11 @@ import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.bonus.aqgqj.business.backstage.entity.MaTypeVo;
import com.bonus.aqgqj.business.backstage.entity.plan.ExportPlanApplyVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanApplyVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanDetailVo;
import com.bonus.aqgqj.business.backstage.service.plan.PlanApplyService;
import com.bonus.aqgqj.business.utils.ExcelBorderStyle;
import com.bonus.aqgqj.manager.annotation.DecryptAndVerify;
import com.bonus.aqgqj.manager.core.entity.EncryptedReq;
import com.bonus.aqgqj.manager.webResult.AjaxResult;
@ -165,7 +167,7 @@ public class PlanApplyController {
@PostMapping("exportApplyPlanList")
public void exportApplyPlanList(HttpServletResponse response, @RequestBody PlanApplyVo dto) {
try {
List<PlanApplyVo> list = service.getApplyPlanList(dto);
List<ExportPlanApplyVo> list = service.exportApplyPlanList(dto);
final int[] num = {1};
list.forEach(vo -> {
vo.setId(num[0]);
@ -173,7 +175,8 @@ public class PlanApplyController {
num[0]++;
});
ExportParams exportParams = new ExportParams("需求计划申请", "需求计划申请", ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PlanApplyVo.class, list);
exportParams.setStyle(ExcelBorderStyle.class); // 关键设置自定义边框样式类
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, ExportPlanApplyVo.class, list);
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("需求计划申请" + ".xlsx", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();

View File

@ -0,0 +1,54 @@
package com.bonus.aqgqj.business.backstage.entity.plan;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
@Data
public class ExportPlanApplyVo {
/**
* id
*/
@Excel(name = "序号", width = 10.0, orderNum = "0")
private Integer id;
/**
* 计划编号
*/
@Excel(name = "计划编号", width = 20.0,mergeVertical = true, orderNum = "1")
private String code;
/**
* 工程名称
*/
@Excel(name = "工程名称", width = 20.0,mergeVertical = true, orderNum = "2")
private String proName;
@Excel(name = "类型", width = 20.0, orderNum = "2")
private String type;
@Excel(name = "名称", width = 20.0, orderNum = "2")
private String name;
@Excel(name = "规格", width = 20.0, orderNum = "2")
private String model;
@Excel(name = "需用数量", width = 20.0, orderNum = "2")
private String needNum;
@Excel(name = "申请人", width = 20.0, orderNum = "2")
private String creator;
@Excel(name = "申请时间", width = 20.0, orderNum = "2")
private String createTime;
@Excel(name = "备注", width = 20.0, orderNum = "2")
private String remark;
@Excel(name = "审核状态", width = 20.0, orderNum = "2")
private String status;
private String statusType;
}

View File

@ -1,6 +1,7 @@
package com.bonus.aqgqj.business.backstage.mapper.plan;
import com.bonus.aqgqj.business.backstage.entity.MaTypeVo;
import com.bonus.aqgqj.business.backstage.entity.plan.ExportPlanApplyVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanApplyVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanAuditRecordVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanDetailVo;
@ -192,4 +193,11 @@ public interface PlanApplyMapper {
* @return
*/
List<ProVo> getProSelectAndCompanyName(PlanApplyVo data);
/**
* 导出查询
* @param dto
* @return
*/
List<ExportPlanApplyVo> exportApplyPlanList(PlanApplyVo dto);
}

View File

@ -1,6 +1,7 @@
package com.bonus.aqgqj.business.backstage.service.plan;
import com.bonus.aqgqj.business.backstage.entity.MaTypeVo;
import com.bonus.aqgqj.business.backstage.entity.plan.ExportPlanApplyVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanApplyVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanDetailVo;
import com.bonus.aqgqj.manager.webResult.AjaxResult;
@ -125,4 +126,11 @@ public interface PlanApplyService {
* @return
*/
ServerResponse getProSelectAndCompanyName(PlanApplyVo data);
/**
* 查询导出数据
* @param dto
* @return
*/
List<ExportPlanApplyVo> exportApplyPlanList(PlanApplyVo dto);
}

View File

@ -2,6 +2,7 @@ package com.bonus.aqgqj.business.backstage.service.plan;
import com.alibaba.fastjson.JSON;
import com.bonus.aqgqj.business.backstage.entity.MaTypeVo;
import com.bonus.aqgqj.business.backstage.entity.plan.ExportPlanApplyVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanApplyVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanAuditRecordVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanDetailVo;
@ -280,6 +281,21 @@ public class PlanApplyServiceImpl implements PlanApplyService {
}
}
/**
* 查询导出信息
* @param dto
* @return
*/
@Override
public List<ExportPlanApplyVo> exportApplyPlanList(PlanApplyVo dto) {
try{
return mapper.exportApplyPlanList(dto);
}catch (Exception e){
log.error(e.toString(), e);
}
return Collections.emptyList();
}
private String getCellStringValue(Cell cell) {
if (cell == null) return "";
switch (cell.getCellType()) {

View File

@ -0,0 +1,134 @@
package com.bonus.aqgqj.business.utils;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams;
import cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerDefaultImpl;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
import org.apache.poi.ss.usermodel.*;
/**
* EasyPoi Excel导出自定义边框样式类
* 实现IExcelExportStyler给单元格添加全边框+文字居中
*/
public class ExcelBorderStyle implements IExcelExportStyler {
// 基础样式对象复用EasyPoi默认样式减少重复代码
private final IExcelExportStyler baseStyle;
/**
* 构造方法传入Workbook初始化默认样式
* EasyPoi会自动调用该构造方法无需手动实例化
*/
public ExcelBorderStyle(Workbook workbook) {
this.baseStyle = new ExcelExportStylerDefaultImpl(workbook);
}
/**
* 表头样式加边框+水平垂直居中
*/
@Override
public CellStyle getHeaderStyle(short color) {
CellStyle headerStyle = baseStyle.getHeaderStyle(color);
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
setCellBorder(headerStyle); // 给表头加全边框
return headerStyle;
}
/**
* Sheet标题样式加边框+水平垂直居中
*/
@Override
public CellStyle getTitleStyle(short color) {
CellStyle titleStyle = baseStyle.getTitleStyle(color);
titleStyle.setAlignment(HorizontalAlignment.CENTER);
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
setCellBorder(titleStyle); // 给标题加全边框
return titleStyle;
}
/**
* 内容行基础样式奇数行加边框+水平垂直居中
*/
@Override
public CellStyle getStyles(boolean isWarp, ExcelExportEntity entity) {
CellStyle style = baseStyle.getStyles(isWarp, entity);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
setCellBorder(style); // 给内容行加全边框
return style;
}
/**
* 必须实现单元格级样式EasyPoi新版接口方法不可返回null
* 复用基础样式+加边框避免样式失效
*/
@Override
public CellStyle getStyles(Cell cell, int index, ExcelExportEntity entity, Object obj, Object data) {
CellStyle style = baseStyle.getStyles(cell, index, entity, obj, data);
setCellBorder(style); // 给单元格加全边框
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/**
* 必须实现模板导出样式不可返回null普通导出也会调用
* 复用基础样式+加边框兼容模板导出场景
*/
@Override
public CellStyle getTemplateStyles(boolean isWarp, ExcelForEachParams params) {
CellStyle style = baseStyle.getTemplateStyles(isWarp, params);
setCellBorder(style); // 给模板单元格加全边框
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/**
* 内容行样式按索引区分奇偶行加边框+水平垂直居中
* 可在此实现隔行变色效果
*/
public CellStyle getStyles(boolean isWarp, ExcelExportEntity entity, int index) {
// 调用baseStyle中存在的2参数方法
CellStyle style = baseStyle.getStyles(isWarp, entity);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
setCellBorder(style);
// 自行实现隔行变色逻辑
if (index % 2 == 0) {
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
}
return style;
}
/**
* 合并单元格样式加边框+水平垂直居中
*/
public CellStyle getMergeStyle(boolean isWarp, ExcelExportEntity entity) {
// 1. 直接创建新的单元格样式不依赖baseStyle
CellStyle mergeStyle = baseStyle.getStyles(isWarp, entity);
// 2. 应用边框和居中样式
mergeStyle.setAlignment(HorizontalAlignment.CENTER);
mergeStyle.setVerticalAlignment(VerticalAlignment.CENTER);
setCellBorder(mergeStyle);
return mergeStyle;
}
/**
* 通用方法给单元格设置黑色细边框
* 抽离边框逻辑统一复用
*/
private void setCellBorder(CellStyle cellStyle) {
// 边框样式细边框BORDER_THIN可改为粗边框BORDER_THICK
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
// 可选显式设置边框颜色为黑色默认黑色可注释
cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
}
}

View File

@ -315,4 +315,33 @@
WHERE
bp.is_active = '1'
</select>
<select id="exportApplyPlanList" resultType="com.bonus.aqgqj.business.backstage.entity.plan.ExportPlanApplyVo">
SELECT spa.id,
spa.code,
tbp.name AS proName,
spd.model,spd.ck_num,spd.`name`,spd.type,spd.need_num needNum,spd.lk_num,
spa.need_time AS needTime,
spa.creator,
spa.create_time AS createTime,
spa.remark,
spa.status,
spa.status_type AS statusType
FROM st_plan_apply spa
left join st_plan_details spd on spd.apply_id=spa.id
LEFT JOIN bm_project tbp ON spa.project_id = tbp.bid_id
<where>
<if test="keyWord!=null and keyWord!=''">
AND (
INSTR(spa.code,#{keyWord}) > 0 OR
INSTR(spa.creator,#{keyWord}) > 0 OR
INSTR(spa.remark,#{keyWord}) > 0 OR
INSTR(tbp.name,#{keyWord}) > 0
)
</if>
<if test="status!=null and status!=''">
and status=#{status}
</if>
</where>
ORDER BY spa.create_time DESC
</select>
</mapper>