feat(wms): 添加异常报表导出功能
- 在WmsMaterialCoilBo中新增abnormalExportCount字段用于控制导出格式 - 实现异常报表的Excel导出功能,支持两种导出模式 - 添加extracted方法处理导出逻辑,构建EasyExcel导出数据 - 创建createExportVo方法组装导出DTO对象,包含钢卷基本信息和异常信息 - 集成EasyExcel实现报表导出,设置响应头和文件下载格式 - 处理无异常信息钢卷的空数据行创建逻辑
This commit is contained in:
@@ -412,5 +412,9 @@ public class WmsMaterialCoilBo extends BaseEntity {
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private Boolean orderByPlanDesc;
|
||||
|
||||
// 异常报表导出格式
|
||||
@TableField(exist = false)
|
||||
private Integer abnormalExportCount;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<WmsMaterialCoilVo> coilList, Map<Long, List<WmsCoilAbnormal>> abnormalMap, Map<Long, String> rejudgeReasonMap) {
|
||||
// 5. 构建EasyExcel导出数据 - O(n)复杂度
|
||||
List<WmsCoilAbnormalExportVo> exportData = new ArrayList<>();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
for (WmsMaterialCoilVo coil : coilList) {
|
||||
Long coilId = coil.getCoilId();
|
||||
List<WmsCoilAbnormal> 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<Long, List<WmsCoilAbnormal>> abnormalMap, List<WmsMaterialCoilVo> coilList, Map<Long, String> rejudgeReasonMap) {
|
||||
// 5. 计算最大异常数,用于动态生成横向异常列组
|
||||
int maxAbnormalCount = 1;
|
||||
for (List<WmsCoilAbnormal> list : abnormalMap.values()) {
|
||||
|
||||
Reference in New Issue
Block a user