|
|
@ -982,6 +982,139 @@ public class QcServiceImpl implements QcService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional |
|
|
|
|
|
public void uploadTemplateExcel1(MultipartFile file, GetParamInData paraData) { |
|
|
|
|
|
try{ |
|
|
|
|
|
// 转流 |
|
|
|
|
|
InputStream is = file.getInputStream(); |
|
|
|
|
|
// 读取工作簿 |
|
|
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook(is); |
|
|
|
|
|
// 读取工作表 |
|
|
|
|
|
XSSFSheet sheet = workbook.getSheetAt(0); |
|
|
|
|
|
// 获取行数 |
|
|
|
|
|
int rows = sheet.getPhysicalNumberOfRows(); |
|
|
|
|
|
// 声明对象 |
|
|
|
|
|
QcTemplateData task = null; |
|
|
|
|
|
// 遍历每一行(从第二行开始) |
|
|
|
|
|
for (int j = 1; j < rows; j++) { |
|
|
|
|
|
// 获得该行 |
|
|
|
|
|
XSSFRow row = sheet.getRow(j); |
|
|
|
|
|
// 检验模板编码(A列)与检验模板名称(B列)均为空视为空行直接跳过,兼容行间/行尾残留的空白行 |
|
|
|
|
|
String templateId = getCellStringValue(row == null ? null : row.getCell(0)); |
|
|
|
|
|
String templateName = getCellStringValue(row == null ? null : row.getCell(1)); |
|
|
|
|
|
if (StringUtils.isBlank(templateId) && StringUtils.isBlank(templateName)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isBlank(templateId)) { |
|
|
|
|
|
throw new RuntimeException("第" + (j + 1) + "行检验模板编码不能为空!"); |
|
|
|
|
|
} |
|
|
|
|
|
// 实例化对象 |
|
|
|
|
|
task = new QcTemplateData(); |
|
|
|
|
|
//截取site和bu |
|
|
|
|
|
QcSiteBuHelper.resolveSiteParam(paraData.getSite(), task::setSite, task::setBuNo); |
|
|
|
|
|
// 检验模板编码直接取上传文件中的值,不再自动生成 |
|
|
|
|
|
task.setTemplateId(templateId.trim()); |
|
|
|
|
|
//获取用户传入的 检验类型描述(getCell 对从未写入过的单元格返回 null,统一走工具方法取值) |
|
|
|
|
|
String type = getCellStringValue(row.getCell(10)); |
|
|
|
|
|
if (StringUtils.isBlank(type)) { |
|
|
|
|
|
throw new RuntimeException("第" + (j + 1) + "行检验类型不能为空!"); |
|
|
|
|
|
} |
|
|
|
|
|
//根据type 设置检验类型编码 |
|
|
|
|
|
if (type.equals("IPQC")){ |
|
|
|
|
|
task.setInspectionTypeNo("101"); |
|
|
|
|
|
}else if (type.equals("IQC")){ |
|
|
|
|
|
task.setInspectionTypeNo("105"); |
|
|
|
|
|
}else if (type.equals("FAI")){ |
|
|
|
|
|
task.setInspectionTypeNo("106"); |
|
|
|
|
|
}else if (type.equals("FQC")){ |
|
|
|
|
|
task.setInspectionTypeNo("107"); |
|
|
|
|
|
}else if (type.equals("PQC")){ |
|
|
|
|
|
task.setInspectionTypeNo("108"); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new RuntimeException("第" + (j + 1) + "行检验类型无效:" + type + "(只能填写 IPQC/IQC/FAI/FQC/PQC)"); |
|
|
|
|
|
} |
|
|
|
|
|
// task.setInspectionTypeNo(row.getCell(9).getRawValue()); |
|
|
|
|
|
|
|
|
|
|
|
// 获取编码 |
|
|
|
|
|
// String templateNo = qcMapper.getTemplateNo(task); |
|
|
|
|
|
// if ("101".equals(task.getInspectionTypeNo()) || "102".equals(task.getInspectionTypeNo()) || "103".equals(task.getInspectionTypeNo()) || "104".equals(task.getInspectionTypeNo())) { |
|
|
|
|
|
// task.setTemplateId("IPQC-" + templateNo); |
|
|
|
|
|
// } else if ("105".equals(task.getInspectionTypeNo())) { |
|
|
|
|
|
// task.setTemplateId("IQC-" + templateNo); |
|
|
|
|
|
// } else if ("106".equals(task.getInspectionTypeNo())) { |
|
|
|
|
|
// task.setTemplateId("FAI-" + templateNo); |
|
|
|
|
|
// } else if ("107".equals(task.getInspectionTypeNo())) { |
|
|
|
|
|
// task.setTemplateId("FQC-" + templateNo); |
|
|
|
|
|
// } else if ("108".equals(task.getInspectionTypeNo())) { |
|
|
|
|
|
// task.setTemplateId("PQC-" + templateNo); |
|
|
|
|
|
// } |
|
|
|
|
|
//判断用户是否输入 抽样方案编码、默认抽样数量和默认抽样比例 其中之一 |
|
|
|
|
|
boolean isFlag = false; |
|
|
|
|
|
task.setTemplateName(StringUtils.isBlank(templateName) ? null : templateName.trim()); |
|
|
|
|
|
String samplingProgrammeNo = getCellStringValue(row.getCell(2)); |
|
|
|
|
|
if (StringUtils.isBlank(samplingProgrammeNo)){ |
|
|
|
|
|
task.setSamplingProgrammeNo(null); |
|
|
|
|
|
}else { |
|
|
|
|
|
isFlag = true; |
|
|
|
|
|
task.setSamplingProgrammeNo(samplingProgrammeNo); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String samplingLevelNo = getCellStringValue(row.getCell(3)); |
|
|
|
|
|
task.setSamplingLevelNo(StringUtils.isBlank(samplingLevelNo) ? null : samplingLevelNo); |
|
|
|
|
|
|
|
|
|
|
|
task.setInspectionCycle(getCellBigDecimalValue(row.getCell(4))); |
|
|
|
|
|
BigDecimal defaultSamplingQuantity = getCellBigDecimalValue(row.getCell(5)); |
|
|
|
|
|
if (defaultSamplingQuantity != null){ |
|
|
|
|
|
isFlag = true; |
|
|
|
|
|
} |
|
|
|
|
|
task.setDefaultSamplingQuantity(defaultSamplingQuantity); |
|
|
|
|
|
BigDecimal defaultSamplingProportion = getCellBigDecimalValue(row.getCell(6)); |
|
|
|
|
|
if (defaultSamplingProportion != null){ |
|
|
|
|
|
isFlag = true; |
|
|
|
|
|
} |
|
|
|
|
|
task.setDefaultSamplingProportion(defaultSamplingProportion); |
|
|
|
|
|
if (!isFlag){ |
|
|
|
|
|
throw new RuntimeException("第" + (j + 1) + "行抽样方案编码、默认抽样数量和默认抽样比例至少填写一个!"); |
|
|
|
|
|
} |
|
|
|
|
|
task.setAql(getCellBigDecimalValue(row.getCell(7))); |
|
|
|
|
|
task.setAc(getCellBigDecimalValue(row.getCell(8))); |
|
|
|
|
|
task.setRe(getCellBigDecimalValue(row.getCell(9))); |
|
|
|
|
|
task.setTemplateRemark(getCellStringValue(row.getCell(11))); |
|
|
|
|
|
task.setTemplateVersion(getCellStringValue(row.getCell(12))); |
|
|
|
|
|
task.setCreateBy(paraData.getCreateBy()); |
|
|
|
|
|
// 查重:模板编码(主键)已存在时明确报错,避免主键冲突回滚整批导入 |
|
|
|
|
|
if (!qcMapper.checkTemplateOnlyOne(task).isEmpty()) { |
|
|
|
|
|
throw new RuntimeException("第" + (j + 1) + "行检验模板编码已存在:" + task.getTemplateId()); |
|
|
|
|
|
} |
|
|
|
|
|
// 新增模板 |
|
|
|
|
|
qcMapper.templateSave(task); |
|
|
|
|
|
// 新增模板中的项目(检验项目编码从第14列开始,读到空单元格为止,避免行尾残留格式单元格导致越界读取) |
|
|
|
|
|
int orderId = 1; |
|
|
|
|
|
for (int i = 13; ; i++) { |
|
|
|
|
|
String itemNo = getCellStringValue(row.getCell(i)); |
|
|
|
|
|
if (StringUtils.isBlank(itemNo)) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
String itemType = "D"; |
|
|
|
|
|
QcTemplateData data = qcMapper.selectItem(itemNo.trim(),itemType,task.getBuNo()); |
|
|
|
|
|
if (data== null){ |
|
|
|
|
|
throw new RuntimeException("第" + (j + 1) + "行,工厂为"+task.getSite()+"时,检验项目不存在:"+itemNo); |
|
|
|
|
|
} |
|
|
|
|
|
data.setTemplateId(task.getTemplateId()); |
|
|
|
|
|
data.setOrderId(orderId++); |
|
|
|
|
|
// 新增 |
|
|
|
|
|
qcMapper.addItemDetails(data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
//给新导入为null的orderId排序 |
|
|
|
|
|
qcMapper.updateQCDetailOrderIdNull(); |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
throw new RuntimeException("导入失败:"+e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ======================= 样本量维护 ======================= |
|
|
// ======================= 样本量维护 ======================= |
|
|
/** |
|
|
/** |
|
|
|