zhuo
2025-03-19 68b68d7962a506b3b173517a088fab70b4d2f687
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTreeServiceImpl.java
@@ -61,28 +61,14 @@
    @Override
    public List<FactoryDto> selectStandardTreeList() {
        List<FactoryDto> factoryDtos = standardTreeMapper.selectStandardTreeList();
        // 收集所有 sampleTypeDto 的 value
        Set<String> sampleTypeValues = new HashSet<>();
        for (FactoryDto factoryDto : factoryDtos) {
            for (LaboratoryDto laboratoryDto : factoryDto.getChildren()) {
                laboratoryDto.getChildren().sort((o1, o2) -> (o1.getSort() == null ? 0 : o1.getSort())
                        - (o2.getSort() == null ? 0 : o2.getSort()));
                for (SampleTypeDto sampleTypeDto : laboratoryDto.getChildren()) {
                    sampleTypeValues.add(sampleTypeDto.getValue());
                }
            }
        }
        // 批量查询所有 sampleTypeDto 的数据
        List<SampleDto> standardList = standardTreeMapper.getStandardTree3Batch(sampleTypeValues);
        Map<String, List<SampleDto>> standardTreeMap = standardList.stream().collect(Collectors.groupingBy(SampleDto::getValue));
        // 将查询结果分配到对应的 sampleTypeDto
        for (FactoryDto factoryDto : factoryDtos) {
            for (LaboratoryDto laboratoryDto : factoryDto.getChildren()) {
                for (SampleTypeDto sampleTypeDto : laboratoryDto.getChildren()) {
                    List<SampleDto> standardTreeList = standardTreeMap.get(sampleTypeDto.getValue());
                    if (standardTreeList != null) {
                        sampleTypeDto.getChildren().addAll(standardTreeList);
                    }
//                    if (sampleTypeDto.getChildren().size() == 0) {
                    sampleTypeDto.getChildren().addAll(standardTreeMapper.getStandardTree3(sampleTypeDto.getValue()));
//                    }
                }
            }
        }
@@ -122,35 +108,6 @@
                    standardTreeMapper.delete(Wrappers.<StandardTree>lambdaUpdate().eq(StandardTree::getFactory, trees[0]).eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]).eq(StandardTree::getSample, trees[3]).eq(StandardTree::getModel, trees[4]));
                }
                break;
        }
        return 1;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addStandardProduct(String ids, String tree) {
        String[] trees = tree.split(" - ");
        JSONArray jsonArray = JSON.parseArray(ids);
        for (Object o : jsonArray) {
            StandardProductList standardProductList = standardTreeMapper.selectStandardProductById(Integer.parseInt("" + o));
            standardProductList.setFactory(trees[0]);
            try {
                standardProductList.setLaboratory(trees[1]);
            } catch (Exception e) {
            }
            try {
                standardProductList.setSampleType(trees[2]);
            } catch (Exception e) {
            }
            try {
                standardProductList.setSample(trees[3]);
            } catch (Exception e) {
            }
            try {
                standardProductList.setModel(trees[4]);
            } catch (Exception e) {
            }
            standardProductListMapper.insert(standardProductList);
        }
        return 1;
    }