Browse Source

feat(qms): 添加检验类型编码字段并优化导入功能

- 在 GetParamInData 中新增 inspectionTypeNo 字段及对应的 getter/setter 方法
- 实现检验类型编码的默认传入逻辑,缺省兜底值为 105
- 重构 Excel 导入解析逻辑,按正确列顺序读取数据
- 将检验项目编码改为直接使用上传的编码,不再自动生成
- 添加检验项目编码重复性检查,避免主键冲突
- 优化值类型判断逻辑,统一使用中文比较
- 调整数值型字段的最大值、最小值、默认值的列映射关系
- 修复导入文件列顺序与代码解析不匹配的问题
master
qiankanghui 2 months ago
parent
commit
2cf2deb21c
  1. 53
      src/main/java/com/xujie/modules/qms/service/impl/QcServiceImpl.java
  2. 11
      src/main/java/com/xujie/modules/sys/data/GetParamInData.java

53
src/main/java/com/xujie/modules/qms/service/impl/QcServiceImpl.java

@ -315,6 +315,8 @@ public class QcServiceImpl implements QcService {
XSSFSheet sheet = workbook.getSheetAt(0); XSSFSheet sheet = workbook.getSheetAt(0);
// 获取行数 // 获取行数
int rows = sheet.getPhysicalNumberOfRows(); int rows = sheet.getPhysicalNumberOfRows();
// 检验类型编码文件里没有该列,由前端默认传入(如 105 IQC),缺省兜底 105
String inspectionTypeNo = StringUtils.isBlank(data.getInspectionTypeNo()) ? "105" : data.getInspectionTypeNo().trim();
// 声明对象 // 声明对象
QcItemData task = null; QcItemData task = null;
// 遍历每一行(从第二行开始) // 遍历每一行(从第二行开始)
@ -324,66 +326,55 @@ public class QcServiceImpl implements QcService {
if (row == null) { if (row == null) {
continue; 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; continue;
} }
// 实例化对象 // 实例化对象
task = new QcItemData(); task = new QcItemData();
// 为对象赋值 // 为对象赋值
QcSiteBuHelper.resolveSiteParam(data.getSite(), task::setSite, task::setBuNo); QcSiteBuHelper.resolveSiteParam(data.getSite(), task::setSite, task::setBuNo);
// itemType 必须在 getItemNo 之前设置,否则按类型查不到已有编码,每行都会生成相同编码
task.setItemType("D"); task.setItemType("D");
task.setInspectionTypeNo(inspectionTypeNo); 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)) { if (StringUtils.isBlank(itemDesc)) {
throw new RuntimeException("第" + (j + 1) + "行检验项目描述不能为空!"); throw new RuntimeException("第" + (j + 1) + "行检验项目描述不能为空!");
} }
task.setItemDesc(itemDesc.trim()); task.setItemDesc(itemDesc.trim());
String valueType = getCellStringValue(row.getCell(1));
String valueType = getCellStringValue(row.getCell(3));
if (StringUtils.isBlank(valueType)) { if (StringUtils.isBlank(valueType)) {
throw new RuntimeException("第" + (j + 1) + "行值类型不能为空!"); throw new RuntimeException("第" + (j + 1) + "行值类型不能为空!");
} }
valueType = valueType.trim();
task.setValueType(valueType); task.setValueType(valueType);
if (valueType.equals("文本")){
if ("文本".equals(valueType)){
task.setValueTypeDb("T"); task.setValueTypeDb("T");
task.setMaxValue(null); task.setMaxValue(null);
task.setMinValue(null); task.setMinValue(null);
} else if (valueType.equals("数字")) {
} else if ("数字".equals(valueType)) {
task.setValueTypeDb("N"); 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())); 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())); task.setMinValue(StringUtils.isBlank(minValue) ? null : new BigDecimal(minValue.trim()));
} else { } else {
throw new RuntimeException("第" + (j + 1) + "行值类型无效:" + valueType + "(只能填写 文本 或 数字)"); throw new RuntimeException("第" + (j + 1) + "行值类型无效:" + valueType + "(只能填写 文本 或 数字)");
} }
task.setDefaultValue(getCellStringValue(row.getCell(2)));
task.setDefaultValue(getCellStringValue(row.getCell(4)));
task.setCreatedBy(data.getCreateBy()); task.setCreatedBy(data.getCreateBy());
task.setMethodNo(getCellStringValue(row.getCell(6)));
task.setMethodNo(getCellStringValue(row.getCell(2)));
// 新增 // 新增
qcMapper.qcItemSave(task); qcMapper.qcItemSave(task);
// 新增项目里的方法 // 新增项目里的方法

11
src/main/java/com/xujie/modules/sys/data/GetParamInData.java

@ -36,6 +36,9 @@ public class GetParamInData {
private String itemNo; private String itemNo;
// 检验类型编码(检验项目导入时由前端默认传入,如 105 IQC)
private String inspectionTypeNo;
private String userid; private String userid;
/** /**
@ -209,6 +212,14 @@ public class GetParamInData {
this.itemNo = itemNo; this.itemNo = itemNo;
} }
public String getInspectionTypeNo() {
return inspectionTypeNo;
}
public void setInspectionTypeNo(String inspectionTypeNo) {
this.inspectionTypeNo = inspectionTypeNo;
}
public String getUserid() { public String getUserid() {
return userid; return userid;
} }

Loading…
Cancel
Save