From 085b7685cf2ed7840b26a28a7e7281d07af994ab Mon Sep 17 00:00:00 2001 From: qiankanghui Date: Tue, 8 Sep 2026 15:06:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(qms):=20=E6=B7=BB=E5=8A=A0=E6=A3=80?= =?UTF-8?q?=E9=AA=8C=E6=A8=A1=E6=9D=BF=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在QcController中新增uploadTemplateExcel1接口用于检验模板导入 - 在QcService接口中定义uploadTemplateExcel1方法 - 在QcServiceImpl中实现检验模板导入的核心逻辑 - 支持Excel文件读取和数据验证 - 实现检验类型映射(IPQC/IQC/FAI/FQC/PQC) - 添加模板编码重复检查机制 - 实现检验项目批量导入功能 - 添加空行和数据校验处理 --- .../modules/qms/controller/QcController.java | 13 ++ .../xujie/modules/qms/service/QcService.java | 2 + .../qms/service/impl/QcServiceImpl.java | 133 ++++++++++++++++++ 3 files changed, 148 insertions(+) diff --git a/src/main/java/com/xujie/modules/qms/controller/QcController.java b/src/main/java/com/xujie/modules/qms/controller/QcController.java index 752b7dc..3c6a314 100644 --- a/src/main/java/com/xujie/modules/qms/controller/QcController.java +++ b/src/main/java/com/xujie/modules/qms/controller/QcController.java @@ -511,6 +511,19 @@ public class QcController { return R.ok(); } + /** + * @description: 检验模板导入 + * @author: fengyuan_yang + * @date: 2023/4/22 16:29 + * @param: [file] + * @return: com.xujie.common.utils.R + **/ + @PostMapping("/uploadTemplateExcel1") + public R uploadTemplateExcel1(@RequestParam(value = "file") MultipartFile file, @ModelAttribute GetParamInData data){ + qcService.uploadTemplateExcel1(file, data); + return R.ok(); + } + // ======================= 样本量API ======================= diff --git a/src/main/java/com/xujie/modules/qms/service/QcService.java b/src/main/java/com/xujie/modules/qms/service/QcService.java index e05fd5b..ce4a229 100644 --- a/src/main/java/com/xujie/modules/qms/service/QcService.java +++ b/src/main/java/com/xujie/modules/qms/service/QcService.java @@ -184,6 +184,8 @@ public interface QcService { void uploadTemplateExcel(MultipartFile file, GetParamInData data); + void uploadTemplateExcel1(MultipartFile file, GetParamInData data); + void samplingProgrammeDelete(QcSamplingInspectionProgrammeData data); void uploadPartAttributeExcel(MultipartFile file, GetParamInData data); diff --git a/src/main/java/com/xujie/modules/qms/service/impl/QcServiceImpl.java b/src/main/java/com/xujie/modules/qms/service/impl/QcServiceImpl.java index ffb42bf..4db5bc3 100644 --- a/src/main/java/com/xujie/modules/qms/service/impl/QcServiceImpl.java +++ b/src/main/java/com/xujie/modules/qms/service/impl/QcServiceImpl.java @@ -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()); + } + } + // ======================= 样本量维护 ======================= /**