From 7d76ef0c527fa0aa969ef054f7885ef6c5ff7ba3 Mon Sep 17 00:00:00 2001 From: Joshi <3040996759@qq.com> Date: Thu, 11 Jun 2026 11:49:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(wms):=20=E6=B7=BB=E5=8A=A0=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8A=A5=E8=A1=A8=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在WmsMaterialCoilBo中新增abnormalExportCount字段用于控制导出格式 - 实现异常报表的Excel导出功能,支持两种导出模式 - 添加extracted方法处理导出逻辑,构建EasyExcel导出数据 - 创建createExportVo方法组装导出DTO对象,包含钢卷基本信息和异常信息 - 集成EasyExcel实现报表导出,设置响应头和文件下载格式 - 处理无异常信息钢卷的空数据行创建逻辑 --- .../com/klp/domain/bo/WmsMaterialCoilBo.java | 4 + .../impl/WmsMaterialCoilServiceImpl.java | 137 ++++++++++++++++++ 2 files changed, 141 insertions(+) diff --git a/klp-wms/src/main/java/com/klp/domain/bo/WmsMaterialCoilBo.java b/klp-wms/src/main/java/com/klp/domain/bo/WmsMaterialCoilBo.java index 224eee39..ead6ec0b 100644 --- a/klp-wms/src/main/java/com/klp/domain/bo/WmsMaterialCoilBo.java +++ b/klp-wms/src/main/java/com/klp/domain/bo/WmsMaterialCoilBo.java @@ -412,5 +412,9 @@ public class WmsMaterialCoilBo extends BaseEntity { */ @TableField(exist = false) private Boolean orderByPlanDesc; + + // 异常报表导出格式 + @TableField(exist = false) + private Integer abnormalExportCount; } diff --git a/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java b/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java index 893c43e3..6a4f9b6b 100644 --- a/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java +++ b/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java @@ -5783,7 +5783,144 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService { } } } + if(bo.getAbnormalExportCount() == 1){ + extracted(response, abnormalMap, coilList, rejudgeReasonMap); + }else { + extracted(response, coilList, abnormalMap, rejudgeReasonMap); + } + + } + + private void extracted(HttpServletResponse response, List coilList, Map> abnormalMap, Map rejudgeReasonMap) { + // 5. 构建EasyExcel导出数据 - O(n)复杂度 + List exportData = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (WmsMaterialCoilVo coil : coilList) { + Long coilId = coil.getCoilId(); + List abnormalList = abnormalMap.getOrDefault(coilId, new ArrayList<>()); + String rejudgeReason = rejudgeReasonMap.get(coilId); + + if (abnormalList.isEmpty()) { + // 无异常信息的钢卷,创建一行空异常数据 + WmsCoilAbnormalExportVo dto = createExportVo(coil, rejudgeReason, null, sdf); + dto.setCoilId(coilId); + exportData.add(dto); + } else { + // 有异常信息的钢卷,每个异常创建一行 + for (WmsCoilAbnormal abnormal : abnormalList) { + WmsCoilAbnormalExportVo dto = createExportVo(coil, rejudgeReason, abnormal, sdf); + dto.setCoilId(coilId); + exportData.add(dto); + } + } + } + + // 6. 使用EasyExcel导出 - O(n)复杂度,瞬间完成 + try { + // 设置响应头 + String filename = "abnormal_report_" + System.currentTimeMillis() + ".xlsx"; + String encoded = URLEncoder.encode(filename, StandardCharsets.UTF_8.name()); + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encoded); + + // 使用EasyExcel写入,正常导出 + EasyExcel.write(response.getOutputStream(), WmsCoilAbnormalExportVo.class) + .sheet("异常报表") + .doWrite(exportData); + + } catch (IOException e) { + throw new RuntimeException("导出失败:" + e.getMessage()); + } + } + + /* + * 创建导出DTO对象 + */ + private WmsCoilAbnormalExportVo createExportVo(WmsMaterialCoilVo coil, String rejudgeReason, + WmsCoilAbnormal abnormal, SimpleDateFormat sdf) { + WmsCoilAbnormalExportVo dto = new WmsCoilAbnormalExportVo(); + + // 钢卷基本信息(前25列) + dto.setItemType(coil.getItemType() != null ? coil.getItemType() : ""); + dto.setWarehouseName(coil.getWarehouseName() != null ? coil.getWarehouseName() : ""); + dto.setActualWarehouseName(coil.getActualWarehouseName() != null ? coil.getActualWarehouseName() : ""); + dto.setEnterCoilNo(coil.getEnterCoilNo() != null ? coil.getEnterCoilNo() : ""); + dto.setSupplierCoilNo(coil.getSupplierCoilNo() != null ? coil.getSupplierCoilNo() : ""); + dto.setCurrentCoilNo(coil.getCurrentCoilNo() != null ? coil.getCurrentCoilNo() : ""); + dto.setCreateTime(coil.getCreateTime() != null ? sdf.format(coil.getCreateTime()) : ""); + dto.setNetWeight(coil.getNetWeight() != null ? coil.getNetWeight().toString() : ""); + dto.setBusinessPurpose(coil.getBusinessPurpose() != null ? coil.getBusinessPurpose() : ""); + dto.setTrimmingRequirement(coil.getTrimmingRequirement() != null ? coil.getTrimmingRequirement() : ""); + dto.setPackagingRequirement(coil.getPackagingRequirement() != null ? coil.getPackagingRequirement() : ""); + dto.setQualityStatus(coil.getQualityStatus() != null ? coil.getQualityStatus() : ""); + dto.setPackingStatus(coil.getPackingStatus() != null ? coil.getPackingStatus() : ""); + dto.setStatus(coil.getStatus() != null ? coil.getStatus().toString() : ""); + dto.setRemark(coil.getRemark() != null ? coil.getRemark() : ""); + dto.setItemName(coil.getItemName() != null ? coil.getItemName() : ""); + dto.setSpecification(coil.getSpecification() != null ? coil.getSpecification() : ""); + dto.setLength(coil.getLength() != null ? coil.getLength().toString() : ""); + dto.setMaterial(coil.getMaterial() != null ? coil.getMaterial() : ""); + dto.setManufacturer(coil.getManufacturer() != null ? coil.getManufacturer() : ""); + dto.setSurfaceTreatmentDesc(coil.getSurfaceTreatmentDesc() != null ? coil.getSurfaceTreatmentDesc() : ""); + dto.setZincLayer(coil.getZincLayer() != null ? coil.getZincLayer() : ""); + dto.setItemId(coil.getItemId() != null ? coil.getItemId().toString() : ""); + dto.setActionCompleteTime(coil.getActionCompleteTime() != null ? sdf.format(coil.getActionCompleteTime()) : ""); + dto.setTransferType(coil.getTransferType() != null ? coil.getTransferType() : ""); + + // 改判原因(第26列) + dto.setRejudgeReason(rejudgeReason != null ? rejudgeReason : ""); + + // 异常信息(后17列) + if (abnormal != null) { + dto.setProductionLine(abnormal.getProductionLine() != null ? abnormal.getProductionLine() : ""); + dto.setPosition(abnormal.getPosition() != null ? abnormal.getPosition() : ""); + dto.setAbnormalLength(abnormal.getLength() != null ? abnormal.getLength().toString() : ""); + dto.setStartPosition(abnormal.getStartPosition() != null ? abnormal.getStartPosition().toString() : ""); + dto.setEndPosition(abnormal.getEndPosition() != null ? abnormal.getEndPosition().toString() : ""); + dto.setDefectCode(abnormal.getDefectCode() != null ? abnormal.getDefectCode() : ""); + dto.setDefectType(abnormal.getDefectType() != null ? abnormal.getDefectType() : ""); + dto.setDefectRate(abnormal.getDefectRate() != null ? abnormal.getDefectRate().toString() : ""); + dto.setDefectWeight(abnormal.getDefectWeight() != null ? abnormal.getDefectWeight().toString() : ""); + dto.setDegree(abnormal.getDegree() != null ? abnormal.getDegree() : ""); +// dto.setJudgeLevel(abnormal.getJudgeLevel() != null ? abnormal.getJudgeLevel() : ""); +// dto.setJudgeBy(abnormal.getJudgeBy() != null ? abnormal.getJudgeBy() : ""); +// dto.setJudgeTime(abnormal.getJudgeTime() != null ? sdf.format(abnormal.getJudgeTime()) : ""); + dto.setMainMark(abnormal.getMainMark() != null ? abnormal.getMainMark().toString() : ""); + dto.setWholeCoilMark(abnormal.getWholeCoilMark() != null ? abnormal.getWholeCoilMark().toString() : ""); + dto.setAbnormalRemark(abnormal.getRemark() != null ? abnormal.getRemark() : ""); + dto.setPlateSurface(abnormal.getPlateSurface() != null ? abnormal.getPlateSurface() : ""); +// dto.setSourceSystem(abnormal.getSourceSystem() != null ? abnormal.getSourceSystem().toString() : ""); +// dto.setProcessSource(abnormal.getProcessSource() != null ? abnormal.getProcessSource() : ""); + } else { + // 空异常信息 + dto.setProductionLine(""); + dto.setPosition(""); + dto.setAbnormalLength(""); + dto.setStartPosition(""); + dto.setEndPosition(""); + dto.setDefectCode(""); + dto.setDefectType(""); + dto.setDefectRate(""); + dto.setDefectWeight(""); + dto.setDegree(""); +// dto.setJudgeLevel(""); +// dto.setJudgeBy(""); +// dto.setJudgeTime(""); + dto.setMainMark(""); + dto.setWholeCoilMark(""); + dto.setAbnormalRemark(""); + dto.setPlateSurface(""); +// dto.setSourceSystem(""); +// dto.setProcessSource(""); + } + + return dto; + } + + private void extracted(HttpServletResponse response, Map> abnormalMap, List coilList, Map rejudgeReasonMap) { // 5. 计算最大异常数,用于动态生成横向异常列组 int maxAbnormalCount = 1; for (List list : abnormalMap.values()) {