|
|
|
@ -1666,4 +1666,147 @@ public class QcBaseInfoServiceImpl implements QcBaseInfoService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void qcSpecUpload(MultipartFile file, GetParamInData data) { |
|
|
|
try { |
|
|
|
InputStream is = file.getInputStream(); |
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook(is); |
|
|
|
XSSFSheet sheet = workbook.getSheetAt(0); |
|
|
|
int rows = sheet.getPhysicalNumberOfRows(); |
|
|
|
|
|
|
|
StringBuilder errInfo = new StringBuilder(); |
|
|
|
int successCount = 0; |
|
|
|
int errorCount = 0; |
|
|
|
|
|
|
|
// 先获取所有检验类型用于匹配 |
|
|
|
QcInspectionTypeData searchData = new QcInspectionTypeData(); |
|
|
|
searchData.setSite(data.getSite()); |
|
|
|
List<QcInspectionTypeData> typeList = qcBaseInfoMapper.inspectionTypeSearch(searchData); |
|
|
|
org.apache.poi.ss.usermodel.DataFormatter formatter = new org.apache.poi.ss.usermodel.DataFormatter(); |
|
|
|
|
|
|
|
for (int j = 1; j < rows; j++) { |
|
|
|
try { |
|
|
|
if (sheet.getRow(j) == null || sheet.getRow(j).getCell(0) == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
XSSFRow row = sheet.getRow(j); |
|
|
|
|
|
|
|
// 检验类型 |
|
|
|
String inspectionTypeName = formatter.formatCellValue(row.getCell(0)).trim(); |
|
|
|
if (StringUtils.isBlank(inspectionTypeName)) { |
|
|
|
errInfo.append("第").append(j + 1).append("行检验类型不能为空;"); |
|
|
|
errorCount++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// 项目编码 |
|
|
|
String itemNo = formatter.formatCellValue(row.getCell(1)).trim(); |
|
|
|
if (StringUtils.isBlank(itemNo)) { |
|
|
|
errInfo.append("第").append(j + 1).append("行项目编码不能为空;"); |
|
|
|
errorCount++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// 标准值 |
|
|
|
String defaultValue = formatter.formatCellValue(row.getCell(2)).trim(); |
|
|
|
if (StringUtils.isBlank(defaultValue)) { |
|
|
|
defaultValue = null; |
|
|
|
} |
|
|
|
|
|
|
|
// 最大值 |
|
|
|
BigDecimal maxValue = null; |
|
|
|
String maxStr = formatter.formatCellValue(row.getCell(3)).trim(); |
|
|
|
if (StringUtils.isNotBlank(maxStr)) { |
|
|
|
try { |
|
|
|
maxValue = new BigDecimal(maxStr); |
|
|
|
} catch (Exception e) { |
|
|
|
errInfo.append("第").append(j + 1).append("行最大值格式错误;"); |
|
|
|
errorCount++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 最小值 |
|
|
|
BigDecimal minValue = null; |
|
|
|
String minStr = formatter.formatCellValue(row.getCell(4)).trim(); |
|
|
|
if (StringUtils.isNotBlank(minStr)) { |
|
|
|
try { |
|
|
|
minValue = new BigDecimal(minStr); |
|
|
|
} catch (Exception e) { |
|
|
|
errInfo.append("第").append(j + 1).append("行最小值格式错误;"); |
|
|
|
errorCount++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (maxValue != null && minValue != null && maxValue.compareTo(minValue) < 0) { |
|
|
|
errInfo.append("第").append(j + 1).append("行最大值不能小于最小值;"); |
|
|
|
errorCount++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// 查找检验类型编码 |
|
|
|
String inspectionTypeNo = null; |
|
|
|
if ("IPQC".equalsIgnoreCase(inspectionTypeName)) { |
|
|
|
inspectionTypeNo = "101"; |
|
|
|
} else if ("IQC".equalsIgnoreCase(inspectionTypeName)) { |
|
|
|
inspectionTypeNo = "105"; |
|
|
|
} else if ("FQC".equalsIgnoreCase(inspectionTypeName)) { |
|
|
|
inspectionTypeNo = "107"; |
|
|
|
} else if ("OQC".equalsIgnoreCase(inspectionTypeName)) { |
|
|
|
inspectionTypeNo = "109"; |
|
|
|
} else { |
|
|
|
for (QcInspectionTypeData type : typeList) { |
|
|
|
if (inspectionTypeName.equals(type.getInspectionTypeName())) { |
|
|
|
inspectionTypeNo = type.getInspectionTypeNo(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (inspectionTypeNo == null) { |
|
|
|
errInfo.append("第").append(j + 1).append("行检验类型不存在;"); |
|
|
|
errorCount++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
QcSpecData qcSpecData = new QcSpecData(); |
|
|
|
qcSpecData.setSite(data.getSite()); |
|
|
|
qcSpecData.setBuNo(data.getBuNo()); |
|
|
|
qcSpecData.setPartNo(data.getPartNo()); |
|
|
|
qcSpecData.setItemNo(itemNo); |
|
|
|
qcSpecData.setInspectionTypeNo(inspectionTypeNo); |
|
|
|
qcSpecData.setDefaultValue(defaultValue); |
|
|
|
qcSpecData.setMaxValue(maxValue); |
|
|
|
qcSpecData.setMinValue(minValue); |
|
|
|
qcSpecData.setCreateBy(data.getCreateBy()); |
|
|
|
|
|
|
|
// 先删除再保存,实现覆盖更新 |
|
|
|
qcBaseInfoMapper.qcSpecDelete(qcSpecData); |
|
|
|
qcBaseInfoMapper.qcSpecSave(qcSpecData); |
|
|
|
|
|
|
|
successCount++; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
errInfo.append("第").append(j + 1).append("行导入失败:").append(e.getMessage()).append(";"); |
|
|
|
errorCount++; |
|
|
|
log.error("导入第{}行失败", j + 1, e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
workbook.close(); |
|
|
|
is.close(); |
|
|
|
|
|
|
|
if (errorCount > 0) { |
|
|
|
throw new RuntimeException("导入完成,成功" + successCount + "条,失败" + errorCount + "条;" + errInfo.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("检验标准导入失败", e); |
|
|
|
throw new RuntimeException(e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |