diff --git a/src/main/java/com/spring/modules/test/controller/TestSoBomController.java b/src/main/java/com/spring/modules/test/controller/TestSoBomController.java index 4febf8fc..5dc54ad9 100644 --- a/src/main/java/com/spring/modules/test/controller/TestSoBomController.java +++ b/src/main/java/com/spring/modules/test/controller/TestSoBomController.java @@ -70,4 +70,15 @@ public class TestSoBomController { testSoBomService.removeBatchTestSoBom(testSoBomList); return R.ok("操作成功"); } + + /** + * BOM导入 - 批量新增测试产品结构 + * @param testSoBomList 从BOM导入的物料列表 + * @return + */ + @PostMapping("/saveBatch") + public R saveBatchTestSoBom(@RequestBody List testSoBomList){ + testSoBomService.saveBatchTestSoBom(testSoBomList); + return R.ok("导入成功"); + } } diff --git a/src/main/java/com/spring/modules/test/service/TestSoBomService.java b/src/main/java/com/spring/modules/test/service/TestSoBomService.java index 119527f7..dbf79639 100644 --- a/src/main/java/com/spring/modules/test/service/TestSoBomService.java +++ b/src/main/java/com/spring/modules/test/service/TestSoBomService.java @@ -16,5 +16,6 @@ public interface TestSoBomService extends IService { void removeBatchTestSoBom(List testSoBomList); void saveTestSoBom(TestSoBom testSoBom); void updateTestSoBom(TestSoBom testSoBom); + void saveBatchTestSoBom(List testSoBomList); } diff --git a/src/main/java/com/spring/modules/test/service/impl/TestSoBomServiceImpl.java b/src/main/java/com/spring/modules/test/service/impl/TestSoBomServiceImpl.java index e8f129aa..1443e93d 100644 --- a/src/main/java/com/spring/modules/test/service/impl/TestSoBomServiceImpl.java +++ b/src/main/java/com/spring/modules/test/service/impl/TestSoBomServiceImpl.java @@ -146,6 +146,45 @@ public class TestSoBomServiceImpl extends ServiceImpl testSoBomList) { + if (testSoBomList == null || testSoBomList.isEmpty()) { + return; + } + String site = testSoBomList.get(0).getSite(); + String testNo = testSoBomList.get(0).getTestNo(); + checkoutTestSoBomKey(testSoBomList.get(0)); + + TestInformationEntity testInfo = testInformationService.lambdaQuery() + .eq(TestInformationEntity::getTestNo, testNo) + .eq(TestInformationEntity::getSite, site) + .one(); + if (Objects.isNull(testInfo)) { + throw new RuntimeException("测试单号" + testNo + "不存在"); + } + + BigDecimal nextItemNo = baseMapper.selectTestSoBomItemNo(site, testNo); + if (nextItemNo == null) { + nextItemNo = BigDecimal.ONE; + } + + for (TestSoBom testSoBom : testSoBomList) { + if (testInfo.getTestPartNo().equals(testSoBom.getComponentPartNo())) { + throw new RuntimeException("不可将自身物料[" + testSoBom.getComponentPartNo() + "]作为产品结构"); + } + testSoBom.setSite(site); + testSoBom.setTestNo(testNo); + testSoBom.setItemNo(nextItemNo); + nextItemNo = nextItemNo.add(BigDecimal.ONE); + baseMapper.insert(testSoBom); + } + } + /** * 检查测试产品结构Key * @param testSoBom