|
|
|
@ -315,6 +315,8 @@ public class QcServiceImpl implements QcService { |
|
|
|
XSSFSheet sheet = workbook.getSheetAt(0); |
|
|
|
// 获取行数 |
|
|
|
int rows = sheet.getPhysicalNumberOfRows(); |
|
|
|
// 检验类型编码文件里没有该列,由前端默认传入(如 105 IQC),缺省兜底 105 |
|
|
|
String inspectionTypeNo = StringUtils.isBlank(data.getInspectionTypeNo()) ? "105" : data.getInspectionTypeNo().trim(); |
|
|
|
// 声明对象 |
|
|
|
QcItemData task = null; |
|
|
|
// 遍历每一行(从第二行开始) |
|
|
|
@ -324,66 +326,55 @@ public class QcServiceImpl implements QcService { |
|
|
|
if (row == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 读取关键列(不能用 getRawValue,文本单元格它返回的是共享字符串表索引而非真实文本) |
|
|
|
String itemDesc = getCellStringValue(row.getCell(0)); |
|
|
|
String inspectionTypeNo = getCellStringValue(row.getCell(3)); |
|
|
|
// 按导入文件列顺序读取(不能用 getRawValue,文本单元格它返回的是共享字符串表索引而非真实文本) |
|
|
|
// 列: 0=检验项目编码 1=检验项目描述 2=检验方法编码 3=检验值类型 4=标准值 5=最大值 6=最小值 |
|
|
|
String itemNo = getCellStringValue(row.getCell(0)); |
|
|
|
String itemDesc = getCellStringValue(row.getCell(1)); |
|
|
|
// 关键列均为空视为空行,跳过(避免模板残留空行导致插入失败) |
|
|
|
if (StringUtils.isBlank(itemDesc) && StringUtils.isBlank(inspectionTypeNo)) { |
|
|
|
if (StringUtils.isBlank(itemNo) && StringUtils.isBlank(itemDesc)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 实例化对象 |
|
|
|
task = new QcItemData(); |
|
|
|
// 为对象赋值 |
|
|
|
QcSiteBuHelper.resolveSiteParam(data.getSite(), task::setSite, task::setBuNo); |
|
|
|
// itemType 必须在 getItemNo 之前设置,否则按类型查不到已有编码,每行都会生成相同编码 |
|
|
|
task.setItemType("D"); |
|
|
|
task.setInspectionTypeNo(inspectionTypeNo); |
|
|
|
// 获取编码 |
|
|
|
String itemNo = qcMapper.getItemNo(task); |
|
|
|
if ("101".equals(task.getInspectionTypeNo()) || "102".equals(task.getInspectionTypeNo()) || "103".equals(task.getInspectionTypeNo()) || "104".equals(task.getInspectionTypeNo())) { |
|
|
|
task.setItemNo("IPQC-" + itemNo); |
|
|
|
} else if ("105".equals(task.getInspectionTypeNo())) { |
|
|
|
task.setItemNo("IQC-" + itemNo); |
|
|
|
} else if ("106".equals(task.getInspectionTypeNo())) { |
|
|
|
task.setItemNo("FAI-" + itemNo); |
|
|
|
} else if ("107".equals(task.getInspectionTypeNo())) { |
|
|
|
task.setItemNo("FQC-" + itemNo); |
|
|
|
} else if ("108".equals(task.getInspectionTypeNo())) { |
|
|
|
task.setItemNo("PQC-" + itemNo); |
|
|
|
} else if ("GX".equals(task.getInspectionTypeNo())) { |
|
|
|
task.setItemNo("GX-" + itemNo); |
|
|
|
} else if ("***".equals(task.getInspectionTypeNo())) { |
|
|
|
task.setItemNo("PF-" + itemNo); |
|
|
|
// 检验项目编码直接使用上传的编码,不再自动生成 |
|
|
|
if (StringUtils.isBlank(itemNo)) { |
|
|
|
throw new RuntimeException("第" + (j + 1) + "行检验项目编码不能为空!"); |
|
|
|
} |
|
|
|
// 检验类型编码无效时明确报错,避免 ItemNo 为空导致 INSERT 失败 |
|
|
|
if (StringUtils.isBlank(task.getItemNo())) { |
|
|
|
throw new RuntimeException("第" + (j + 1) + "行检验类型编码无效:" + task.getInspectionTypeNo()); |
|
|
|
task.setItemNo(itemNo.trim()); |
|
|
|
// 编码已存在时明确报错,避免主键冲突回滚整批导入 |
|
|
|
if (!qcMapper.checkQcItem(task).isEmpty()) { |
|
|
|
throw new RuntimeException("第" + (j + 1) + "行检验项目编码已存在:" + task.getItemNo()); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(itemDesc)) { |
|
|
|
throw new RuntimeException("第" + (j + 1) + "行检验项目描述不能为空!"); |
|
|
|
} |
|
|
|
task.setItemDesc(itemDesc.trim()); |
|
|
|
String valueType = getCellStringValue(row.getCell(1)); |
|
|
|
String valueType = getCellStringValue(row.getCell(3)); |
|
|
|
if (StringUtils.isBlank(valueType)) { |
|
|
|
throw new RuntimeException("第" + (j + 1) + "行值类型不能为空!"); |
|
|
|
} |
|
|
|
valueType = valueType.trim(); |
|
|
|
task.setValueType(valueType); |
|
|
|
if (valueType.equals("文本")){ |
|
|
|
if ("文本".equals(valueType)){ |
|
|
|
task.setValueTypeDb("T"); |
|
|
|
task.setMaxValue(null); |
|
|
|
task.setMinValue(null); |
|
|
|
} else if (valueType.equals("数字")) { |
|
|
|
} else if ("数字".equals(valueType)) { |
|
|
|
task.setValueTypeDb("N"); |
|
|
|
String maxValue = getCellStringValue(row.getCell(4)); |
|
|
|
String maxValue = getCellStringValue(row.getCell(5)); |
|
|
|
task.setMaxValue(StringUtils.isBlank(maxValue) ? null : new BigDecimal(maxValue.trim())); |
|
|
|
String minValue = getCellStringValue(row.getCell(5)); |
|
|
|
String minValue = getCellStringValue(row.getCell(6)); |
|
|
|
task.setMinValue(StringUtils.isBlank(minValue) ? null : new BigDecimal(minValue.trim())); |
|
|
|
} else { |
|
|
|
throw new RuntimeException("第" + (j + 1) + "行值类型无效:" + valueType + "(只能填写 文本 或 数字)"); |
|
|
|
} |
|
|
|
task.setDefaultValue(getCellStringValue(row.getCell(2))); |
|
|
|
task.setDefaultValue(getCellStringValue(row.getCell(4))); |
|
|
|
task.setCreatedBy(data.getCreateBy()); |
|
|
|
task.setMethodNo(getCellStringValue(row.getCell(6))); |
|
|
|
task.setMethodNo(getCellStringValue(row.getCell(2))); |
|
|
|
// 新增 |
|
|
|
qcMapper.qcItemSave(task); |
|
|
|
// 新增项目里的方法 |
|
|
|
|