feat(aps): 添加排产单导出功能

- 新增 ApsPlanSheetQueryReq 查询参数类
- 新增 ApsPlanSheetRowVo 数据传输对象
- 实现 controller 层 exportAll 接口
- 实现 service 层 exportExcel 导出逻辑
- 添加 mapper 层 selectList 查询方法
- 配置 mybatis xml 查询映射
- 优化 Excel 导出样式和数据处理
This commit is contained in:
2026-03-26 14:59:33 +08:00
parent 281f86ca8c
commit 38862cf0ea
8 changed files with 345 additions and 0 deletions

View File

@@ -3,6 +3,8 @@ package com.klp.aps.controller;
import java.util.List;
import java.util.Arrays;
import com.klp.aps.domain.dto.ApsPlanSheetQueryReq;
import com.klp.aps.domain.dto.ApsQuickSheetQueryReq;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
@@ -54,6 +56,10 @@ public class ApsPlanSheetController extends BaseController {
ExcelUtil.exportExcel(list, "排产单主", ApsPlanSheetVo.class, response);
}
@GetMapping("/exportAll")
public void export(@Validated ApsPlanSheetQueryReq req, javax.servlet.http.HttpServletResponse response) {
iApsPlanSheetService.exportExcel(req, response);
}
/**
* 获取排产单主详细信息
*

View File

@@ -0,0 +1,23 @@
package com.klp.aps.domain.dto;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
@Data
public class ApsPlanSheetQueryReq {
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate;
private Long lineId;
// planSheetId
private Long planSheetId;
private String customerName;
}

View File

@@ -0,0 +1,59 @@
package com.klp.aps.domain.dto;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@Data
public class ApsPlanSheetSaveReq {
@NotEmpty(message = "rows 不能为空")
private List<ApsQuickSheetSaveReq.Row> rows;
@Data
public static class Row {
private Long quickSheetId;
private Long lineId;
private String lineName;
private String planCode;
private String planType;
private String scheduler;
private String remark;
private String bizSeqNo;
private String orderCode;
private String contractCode;
private String customerName;
private String salesman;
private String productName;
private String productMaterial;
private String coatingG;
private String productWidth;
private String rollingThick;
private String markCoatThick;
private String tonSteelLengthRange;
private String planQty;
private String planWeight;
private String surfaceTreatment;
private String widthReq;
private String usageReq;
private String postProcess;
private String nextProcess;
private String sampleReq;
private String rawManufacturer;
private String rawMaterial;
private String rawThick;
private String rawWidth;
private String rawMaterialId;
private String rawCoilNos;
private String rawLocation;
private String rawPackaging;
private String rawEdgeReq;
private String rawCoatingType;
private String rawNetWeight;
private String startTime;
private String endTime;
}
}

View File

@@ -0,0 +1,56 @@
package com.klp.aps.domain.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
public class ApsPlanSheetRowVo {
private Long detailSheetId;
private java.time.LocalDate planDate;
private Long lineId;
private String lineName;
private String planCode;
private String planType;
private String scheduler;
private String masterRemark;
private String updateBy;
private String bizSeqNo;
private String orderCode;
private String contractCode;
private String customerName;
private String salesman;
private String productName;
private String productMaterial;
private BigDecimal coatingG;
private BigDecimal productWidth;
private BigDecimal rollingThick;
private BigDecimal markCoatThick;
private String tonSteelLengthRange;
private BigDecimal planQty;
private BigDecimal planWeight;
private String surfaceTreatment;
private String widthReq;
private String usageReq;
private String postProcess;
private String nextProcess;
private String sampleReq;
private String rawManufacturer;
private String rawMaterial;
private BigDecimal rawThick;
private BigDecimal rawWidth;
private String rawMaterialId;
private String rawCoilNos;
private String rawLocation;
private String rawPackaging;
private String rawEdgeReq;
private String rawCoatingType;
private BigDecimal rawNetWeight;
private LocalDateTime startTime;
private LocalDateTime endTime;
private String detailRemark;
}

View File

@@ -1,9 +1,15 @@
package com.klp.aps.mapper;
import com.klp.aps.domain.dto.ApsPlanSheetQueryReq;
import com.klp.aps.domain.dto.ApsQuickSheetQueryReq;
import com.klp.aps.domain.entity.ApsPlanSheet;
import com.klp.aps.domain.vo.ApsPlanSheetRowVo;
import com.klp.aps.domain.vo.ApsPlanSheetVo;
import com.klp.aps.domain.vo.ApsQuickSheetRowVo;
import com.klp.common.core.mapper.BaseMapperPlus;
import java.util.List;
/**
* 排产单主Mapper接口
*
@@ -12,4 +18,5 @@ import com.klp.common.core.mapper.BaseMapperPlus;
*/
public interface ApsPlanSheetMapper extends BaseMapperPlus<ApsPlanSheetMapper, ApsPlanSheet, ApsPlanSheetVo> {
List<ApsPlanSheetRowVo> selectList(ApsPlanSheetQueryReq req);
}

View File

@@ -1,10 +1,13 @@
package com.klp.aps.service;
import com.klp.aps.domain.dto.ApsPlanSheetQueryReq;
import com.klp.aps.domain.dto.ApsQuickSheetQueryReq;
import com.klp.aps.domain.vo.ApsPlanSheetVo;
import com.klp.aps.domain.bo.ApsPlanSheetBo;
import com.klp.common.core.page.TableDataInfo;
import com.klp.common.core.domain.PageQuery;
import javax.servlet.http.HttpServletResponse;
import java.util.Collection;
import java.util.List;
@@ -45,4 +48,7 @@ public interface IApsPlanSheetService {
* 校验并批量删除排产单主信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
void exportExcel(ApsPlanSheetQueryReq req, HttpServletResponse response);
}

View File

@@ -1,11 +1,16 @@
package com.klp.aps.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.klp.aps.domain.dto.ApsPlanSheetQueryReq;
import com.klp.aps.domain.dto.ApsQuickSheetQueryReq;
import com.klp.aps.domain.vo.ApsPlanSheetRowVo;
import com.klp.aps.domain.vo.ApsQuickSheetRowVo;
import com.klp.common.core.page.TableDataInfo;
import com.klp.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.klp.common.exception.ServiceException;
import com.klp.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -111,4 +116,122 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService {
}
return baseMapper.deleteBatchIds(ids) > 0;
}
@Override
public void exportExcel(ApsPlanSheetQueryReq req, javax.servlet.http.HttpServletResponse response) {
List<ApsPlanSheetRowVo> rows = queryListAll(req);
try (org.apache.poi.ss.usermodel.Workbook wb = new org.apache.poi.xssf.usermodel.XSSFWorkbook()) {
org.apache.poi.ss.usermodel.Sheet sheet = wb.createSheet("快速排产表");
int r = 0;
org.apache.poi.ss.usermodel.Row title = sheet.createRow(r++);
title.setHeightInPoints(36f);
org.apache.poi.ss.usermodel.Cell t0 = title.createCell(0);
t0.setCellValue("快速排产表");
sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 0, 0, 38));
org.apache.poi.ss.usermodel.CellStyle titleStyle = wb.createCellStyle();
titleStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER);
titleStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
org.apache.poi.xssf.usermodel.XSSFFont titleFont = ((org.apache.poi.xssf.usermodel.XSSFWorkbook) wb).createFont();
titleFont.setBold(true);
titleFont.setFontHeightInPoints((short) 15);
titleStyle.setFont(titleFont);
t0.setCellStyle(titleStyle);
String[] headers = new String[]{
"产线", "排产日期", "排产单号", "排产类型", "排产人", "修改人", "计划备注",
"内容序号", "销售内容", "订单合同号", "客户", "业务员",
"成品名称", "材质", "镀层g", "成品宽度", "轧制厚度", "标丝厚度", "吨钢长度区间m",
"数量", "重量", "表面处理", "切边要求", "宽度要求", "用途", "后处理", "下工序", "取样",
"厂家", "原料信息", "原料厚度mm", "宽度mm", "原料钢卷", "原料卷号", "钢卷位置", "包装要求", "镀层种类", "原料净重",
"开始时间", "结束时间", "明细备注"
};
org.apache.poi.ss.usermodel.Row head = sheet.createRow(r++);
for (int i = 0; i < headers.length; i++) {
head.createCell(i).setCellValue(headers[i]);
}
if (rows != null) {
for (ApsPlanSheetRowVo row : rows) {
org.apache.poi.ss.usermodel.Row rr = sheet.createRow(r++);
int cc = 0;
rr.createCell(cc++).setCellValue(nvl(row.getLineName(), row.getLineId()));
rr.createCell(cc++).setCellValue(row.getPlanDate() == null ? "" : row.getPlanDate().toString());
rr.createCell(cc++).setCellValue(nvl(row.getPlanCode(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getPlanType(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getScheduler(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getUpdateBy(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getMasterRemark(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getBizSeqNo(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getOrderCode(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getContractCode(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getCustomerName(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getSalesman(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getProductName(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getProductMaterial(), ""));
rr.createCell(cc++).setCellValue(row.getCoatingG() == null ? "" : row.getCoatingG().toPlainString());
rr.createCell(cc++).setCellValue(row.getProductWidth() == null ? "" : row.getProductWidth().toPlainString());
rr.createCell(cc++).setCellValue(row.getRollingThick() == null ? "" : row.getRollingThick().toPlainString());
rr.createCell(cc++).setCellValue(row.getMarkCoatThick() == null ? "" : row.getMarkCoatThick().toPlainString());
rr.createCell(cc++).setCellValue(nvl(row.getTonSteelLengthRange(), ""));
rr.createCell(cc++).setCellValue(row.getPlanQty() == null ? "" : row.getPlanQty().toPlainString());
rr.createCell(cc++).setCellValue(row.getPlanWeight() == null ? "" : row.getPlanWeight().toPlainString());
rr.createCell(cc++).setCellValue(nvl(row.getSurfaceTreatment(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getWidthReq(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawEdgeReq(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getUsageReq(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getPostProcess(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getNextProcess(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getSampleReq(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawManufacturer(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawMaterial(), ""));
rr.createCell(cc++).setCellValue(row.getRawThick() == null ? "" : row.getRawThick().toPlainString());
rr.createCell(cc++).setCellValue(row.getRawWidth() == null ? "" : row.getRawWidth().toPlainString());
rr.createCell(cc++).setCellValue(nvl(row.getRawMaterialId(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawCoilNos(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawLocation(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawPackaging(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawCoatingType(), ""));
rr.createCell(cc++).setCellValue(row.getRawNetWeight() == null ? "" : row.getRawNetWeight().toPlainString());
rr.createCell(cc++).setCellValue(row.getStartTime() == null ? "" : row.getStartTime().toString());
rr.createCell(cc++).setCellValue(row.getEndTime() == null ? "" : row.getEndTime().toString());
rr.createCell(cc++).setCellValue(nvl(row.getDetailRemark(), ""));
}
}
for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i, true);
int w = sheet.getColumnWidth(i);
sheet.setColumnWidth(i, Math.min(Math.max(w, 3000), 12000));
}
String filename = "aps_quick_sheet_" + System.currentTimeMillis() + ".xlsx";
String encoded = java.net.URLEncoder.encode(filename, java.nio.charset.StandardCharsets.UTF_8.name());
response.setCharacterEncoding(java.nio.charset.StandardCharsets.UTF_8.name());
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encoded);
try (javax.servlet.ServletOutputStream os = response.getOutputStream()) {
wb.write(os);
os.flush();
}
} catch (java.io.IOException e) {
throw new ServiceException("导出失败:" + e.getMessage());
}
}
private List<ApsPlanSheetRowVo> queryListAll(ApsPlanSheetQueryReq req) {
return baseMapper.selectList(req);
}
private String nvl(Object v, Object fallback) {
if (v == null) return String.valueOf(fallback);
String s = String.valueOf(v);
return s == null ? String.valueOf(fallback) : s;
}
}

View File

@@ -19,6 +19,71 @@
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="selectList" parameterType="com.klp.aps.domain.dto.ApsPlanSheetQueryReq" resultType="com.klp.aps.domain.vo.ApsPlanSheetRowVo">
SELECT
d.plan_detail_id AS detailSheetId,
s.plan_date AS planDate,
s.line_id AS lineId,
s.line_name AS lineName,
s.plan_code AS planCode,
s.plan_type AS planType,
s.scheduler AS scheduler,
s.remark AS masterRemark,
d.remark AS detailRemark,
s.update_by AS updateBy,
d.biz_seq_no AS bizSeqNo,
d.order_code AS orderCode,
d.contract_code AS contractCode,
d.customer_name AS customerName,
d.salesman AS salesman,
d.product_name AS productName,
d.product_material AS productMaterial,
d.coating_g AS coatingG,
d.product_width AS productWidth,
d.rolling_thick AS rollingThick,
d.mark_coat_thick AS markCoatThick,
d.ton_steel_length_range AS tonSteelLengthRange,
d.plan_qty AS planQty,
d.plan_weight AS planWeight,
d.surface_treatment AS surfaceTreatment,
d.width_req AS widthReq,
d.usage_req AS usageReq,
d.post_process AS postProcess,
d.next_process AS nextProcess,
d.sample_req AS sampleReq,
d.raw_manufacturer AS rawManufacturer,
d.raw_material AS rawMaterial,
d.raw_thick AS rawThick,
d.raw_width AS rawWidth,
CAST(d.raw_material_id AS CHAR) AS rawMaterialId,
d.raw_coil_nos AS rawCoilNos,
d.raw_location AS rawLocation,
d.raw_packaging AS rawPackaging,
d.raw_edge_req AS rawEdgeReq,
d.raw_coating_type AS rawCoatingType,
d.raw_net_weight AS rawNetWeight,
d.start_time AS startTime,
d.end_time AS endTime
FROM aps_plan_sheet s
INNER JOIN aps_plan_detail d ON d.plan_sheet_id = s.plan_sheet_id AND d.del_flag = 0
WHERE s.del_flag = 0
<if test="startDate != null">
AND d.start_time <![CDATA[>=]]> CONCAT(#{startDate}, ' 00:00:00')
</if>
<if test="endDate != null">
AND d.start_time <![CDATA[<=]]> CONCAT(#{endDate}, ' 23:59:59')
</if>
<if test="lineId != null">
AND s.line_id = #{lineId}
</if>
<if test="planSheetId != null">
AND s.plan_sheet_id = #{planSheetId}
</if>
<if test="customerName != null and customerName != ''">
AND d.customer_name LIKE CONCAT('%', #{customerName}, '%')
</if>
ORDER BY d.plan_detail_id DESC
</select>
</mapper>