| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.poi.excel.ExcelUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.dto.SampleDto; |
| | | import com.ruoyi.basic.dto.*; |
| | | import com.ruoyi.basic.enums.BasicTreeEnums; |
| | | import com.ruoyi.basic.enums.TestPorjectTypeEnums; |
| | | import com.ruoyi.basic.mapper.*; |
| | | import com.ruoyi.basic.pojo.*; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.basic.dto.FactoryDto; |
| | | import com.ruoyi.basic.dto.LaboratoryDto; |
| | | import com.ruoyi.basic.dto.SampleTypeDto; |
| | | import com.ruoyi.basic.mapper.StandardProductListMapper; |
| | | import com.ruoyi.basic.mapper.StandardTreeMapper; |
| | | import com.ruoyi.basic.pojo.StandardProductList; |
| | | import com.ruoyi.basic.pojo.StandardTemplate; |
| | | import com.ruoyi.basic.pojo.StandardTree; |
| | | import com.ruoyi.basic.pojo.StructureTestObject; |
| | | import com.ruoyi.basic.service.*; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | |
| | | |
| | | private StructureTestObjectService structureTestObjectService; |
| | | |
| | | private StructureTestObjectMapper structureTestObjectMapper; |
| | | |
| | | private ProductMapper productMapper; |
| | | |
| | | private ModelMapper modelMapper; |
| | | |
| | | private LaboratoryMapper laboratoryMapper; |
| | | |
| | | private WorkShopMapper workShopMapper; |
| | | |
| | | |
| | | @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()); |
| | | public List<BasicTreeDto> selectStandardTreeList() { |
| | | // 查询所有检查对象 |
| | | List<StructureTestObject> structureTestObjectList = structureTestObjectMapper.selectList(new QueryWrapper<StructureTestObject>()); |
| | | // 查询所有产品 |
| | | List<Product> productList = productMapper.selectList(new LambdaQueryWrapper<Product>()); |
| | | // 查询所有型号 |
| | | List<Model> modelList = modelMapper.selectList(new QueryWrapper<Model>()); |
| | | // 按照归属产品id还是归属检测对象id将型号分组并组装成BasicTreeDto |
| | | Map<Integer, List<BasicTreeDto>> productModelMap = new HashMap<>(); |
| | | Map<Integer, List<BasicTreeDto>> testObjectModelMap = new HashMap<>(); |
| | | for (Model model : modelList) { |
| | | BasicTreeDto basicTreeDto = new BasicTreeDto(); |
| | | basicTreeDto.setLevel(BasicTreeEnums.MODEL_TYPE.getCode()); |
| | | basicTreeDto.setValue(String.valueOf(model.getId())); |
| | | basicTreeDto.setLabel(model.getModelName()); |
| | | basicTreeDto.setChildren(null); |
| | | if(model.getProductId() != null) { |
| | | if(CollectionUtils.isEmpty(productModelMap.get(model.getProductId()))){ |
| | | List<BasicTreeDto> basicTreeDtoList = new ArrayList<>(); |
| | | basicTreeDtoList.add(basicTreeDto); |
| | | productModelMap.put(model.getProductId(),basicTreeDtoList); |
| | | }else { |
| | | productModelMap.get(model.getProductId()).add(basicTreeDto); |
| | | } |
| | | } |
| | | if(model.getStructureTestObjectId() != null) { |
| | | if(CollectionUtils.isEmpty(testObjectModelMap.get(model.getStructureTestObjectId()))){ |
| | | List<BasicTreeDto> basicTreeDtoList = new ArrayList<>(); |
| | | basicTreeDtoList.add(basicTreeDto); |
| | | testObjectModelMap.put(model.getStructureTestObjectId(),basicTreeDtoList); |
| | | }else { |
| | | testObjectModelMap.get(model.getStructureTestObjectId()).add(basicTreeDto); |
| | | } |
| | | } |
| | | } |
| | | // 批量查询所有 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); |
| | | // 按照检测对象id将产品分组并组装成BasicTreeDto |
| | | Map<Integer, List<BasicTreeDto>> productMap = productList.stream().collect(Collectors.groupingBy( |
| | | Product::getObjectId, |
| | | Collectors.mapping(product -> { |
| | | BasicTreeDto basicTreeDto = new BasicTreeDto(); |
| | | basicTreeDto.setValue(String.valueOf(product.getId())); |
| | | basicTreeDto.setLabel(product.getName()); |
| | | basicTreeDto.setLevel(BasicTreeEnums.PRODUCT_TYPE.getCode()); |
| | | basicTreeDto.setChildren(productModelMap.get(product.getId())); |
| | | return basicTreeDto; |
| | | }, Collectors.toList()) |
| | | )); |
| | | // 对检测对象先按照实验室在按照检查对象类别分类 |
| | | Map<Integer, Map<String, List<StructureTestObjectDto>>> laboratoryObjectTypeMap = structureTestObjectList.stream().collect( |
| | | Collectors.groupingBy( |
| | | StructureTestObject::getLaboratoryId, |
| | | Collectors.groupingBy( |
| | | StructureTestObject::getObjectType, |
| | | Collectors.mapping(structureTestObject -> { |
| | | StructureTestObjectDto structureTestObjectDto = new StructureTestObjectDto(); |
| | | BeanUtils.copyProperties(structureTestObject, structureTestObjectDto); |
| | | List<BasicTreeDto> children = new ArrayList<>(); |
| | | if(!CollectionUtils.isEmpty(productMap.get(structureTestObject.getId()))){ |
| | | children.addAll(productMap.get(structureTestObject.getId())); |
| | | } |
| | | if(!CollectionUtils.isEmpty(testObjectModelMap.get(structureTestObject.getId()))){ |
| | | children.addAll(testObjectModelMap.get(structureTestObject.getId())); |
| | | } |
| | | structureTestObjectDto.setChildren(children); |
| | | return structureTestObjectDto; |
| | | },Collectors.toList()) |
| | | ) |
| | | ) |
| | | ); |
| | | // 查询车间 |
| | | List<WorkShop> workShopList = workShopMapper.selectList(new LambdaQueryWrapper<WorkShop>()); |
| | | // 查询实验室 |
| | | List<Laboratory> laboratoryList = laboratoryMapper.selectList(new QueryWrapper<Laboratory>()); |
| | | // 封装实验室树 |
| | | List<BasicTreeDto> laboratoryTreeDtoList = laboratoryList.stream().map(laboratory -> { |
| | | BasicTreeDto laboratoryTreeDto = new BasicTreeDto(); |
| | | laboratoryTreeDto.setValue(String.valueOf(laboratory.getId())); |
| | | laboratoryTreeDto.setLevel(BasicTreeEnums.LABORATORY_TYPE.getCode()); |
| | | laboratoryTreeDto.setLabel(laboratory.getLaboratoryName()); |
| | | // 封装检测对象材料类型树 |
| | | List<BasicTreeDto> objectTypeChildren = new ArrayList<>(); |
| | | Map<String, List<StructureTestObjectDto>> objectTypeMap = laboratoryObjectTypeMap.get(laboratory.getId()); |
| | | if (!CollectionUtils.isEmpty(objectTypeMap)) { |
| | | for (String objectType : objectTypeMap.keySet()) { |
| | | BasicTreeDto objectTypeBasicTreeDto = new BasicTreeDto(); |
| | | objectTypeBasicTreeDto.setValue(objectType); |
| | | objectTypeBasicTreeDto.setLevel(BasicTreeEnums.MATERIAL_TYPE.getCode()); |
| | | objectTypeBasicTreeDto.setLabel(objectType); |
| | | List<StructureTestObjectDto> structureTestObjectTypeList = objectTypeMap.get(objectType); |
| | | if (CollectionUtils.isEmpty(structureTestObjectTypeList)) { |
| | | continue; |
| | | } |
| | | // 封装车间树 |
| | | if (objectType.equals(TestPorjectTypeEnums.RAW_MATERIALS.getName()) || objectType.equals(TestPorjectTypeEnums.PACKAGING_MATERIALS.getName())) { |
| | | List<BasicTreeDto> workShopTreeDtoList = new ArrayList<>(); |
| | | for (WorkShop workShop : workShopList) { |
| | | BasicTreeDto workShopTreeDto = new BasicTreeDto(); |
| | | workShopTreeDto.setLevel(BasicTreeEnums.WORK_SHOP_TYPE.getCode()); |
| | | workShopTreeDto.setValue(String.valueOf(workShop.getId())); |
| | | workShopTreeDto.setLabel(workShop.getName()); |
| | | List<BasicTreeDto> testObjectChildren = new ArrayList<>(); |
| | | // 封装检测对象树 |
| | | for (StructureTestObjectDto structureTestObjectDto : structureTestObjectTypeList) { |
| | | if (workShop.getId().equals(structureTestObjectDto.getWorkShopId())) { |
| | | BasicTreeDto testObjectTreeDto = new BasicTreeDto(); |
| | | testObjectTreeDto.setLevel(BasicTreeEnums.STRUCTURE_TEST_OBJECT_TYPE.getCode()); |
| | | testObjectTreeDto.setValue(String.valueOf(structureTestObjectDto.getId())); |
| | | testObjectTreeDto.setLabel(structureTestObjectDto.getSpecimenName()); |
| | | testObjectTreeDto.setChildren(structureTestObjectDto.getChildren()); |
| | | testObjectChildren.add(testObjectTreeDto); |
| | | } |
| | | } |
| | | workShopTreeDto.setChildren(testObjectChildren); |
| | | if(!CollectionUtils.isEmpty(testObjectChildren)){ |
| | | workShopTreeDtoList.add(workShopTreeDto); |
| | | } |
| | | } |
| | | objectTypeBasicTreeDto.setChildren(workShopTreeDtoList); |
| | | } |
| | | // 封装检测对象树 |
| | | if (objectType.equals(TestPorjectTypeEnums.FINISHED_PRODUCT.getName()) || objectType.equals(TestPorjectTypeEnums.SEMI_FINISHED_PRODUCT.getName()) || objectType.equals(TestPorjectTypeEnums.PURCHASED_PART.getName())) { |
| | | objectTypeBasicTreeDto.setChildren(structureTestObjectTypeList.stream().map(structureTestObjectDto -> { |
| | | BasicTreeDto testObjectBasicTreeDto = new BasicTreeDto(BasicTreeEnums.STRUCTURE_TEST_OBJECT_TYPE.getCode(), |
| | | structureTestObjectDto.getSpecimenName(), |
| | | String.valueOf(structureTestObjectDto.getId()), |
| | | structureTestObjectDto.getChildren()); |
| | | return testObjectBasicTreeDto; |
| | | }).collect(Collectors.toList())); |
| | | } |
| | | objectTypeChildren.add(objectTypeBasicTreeDto); |
| | | } |
| | | } |
| | | } |
| | | return factoryDtos; |
| | | laboratoryTreeDto.setChildren(objectTypeChildren); |
| | | return laboratoryTreeDto; |
| | | }).collect(Collectors.toList()); |
| | | List<BasicTreeDto> factoryList = new ArrayList<>(); |
| | | factoryList.add(new BasicTreeDto(BasicTreeEnums.FACTORY_TYPE.getCode(),"中天科技","1",laboratoryTreeDtoList)); |
| | | return factoryList; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int addStandardTree(StandardTree standardTree) { |
| | | LambdaQueryWrapper<StandardTree> wrapper = Wrappers.<StandardTree>lambdaQuery() |
| | | .eq(StandardTree::getFactory, standardTree.getFactory()) |
| | | .eq(StandardTree::getLaboratory, standardTree.getLaboratory()) |
| | | .eq(StandardTree::getSampleType, standardTree.getSampleType()) |
| | | .eq(StandardTree::getSample, standardTree.getSample()) |
| | | .eq(StandardTree::getModel, standardTree.getModel()); |
| | | if (StringUtils.isNotBlank(standardTree.getSample())) { |
| | | wrapper.eq(StandardTree::getSample, standardTree.getSample()); |
| | | public int addStandardTree(ModelAddDto modelAddDto) { |
| | | // 校验 |
| | | if(StringUtils.isEmpty(modelAddDto.getParentId())){ |
| | | throw new RuntimeException("缺少父层级绑定关系"); |
| | | } |
| | | Model model = new Model(); |
| | | String parentLevel = modelAddDto.getParentLevel(); |
| | | // 名称重复性性校验 |
| | | QueryWrapper<Model> modelQueryWrapper = new QueryWrapper<>(); |
| | | if(BasicTreeEnums.PRODUCT_TYPE.getCode().equals(parentLevel)){ |
| | | model.setProductId(Integer.valueOf(modelAddDto.getParentId())); |
| | | modelQueryWrapper.eq("product_id", model.getProductId()); |
| | | }else if(BasicTreeEnums.STRUCTURE_TEST_OBJECT_TYPE.getCode().equals(parentLevel)){ |
| | | model.setStructureTestObjectId(Integer.valueOf(modelAddDto.getParentId())); |
| | | modelQueryWrapper.eq("structure_test_object_id", model.getStructureTestObjectId()); |
| | | }else { |
| | | throw new RuntimeException("型号只能绑定对象和产品"); |
| | | } |
| | | model.setModelName(modelAddDto.getModelName()); |
| | | modelQueryWrapper.eq("model_name", model.getModelName()); |
| | | Model modelResult = modelMapper.selectOne(modelQueryWrapper); |
| | | |
| | | StandardTree tree = standardTreeMapper.selectOne(wrapper); |
| | | if (tree != null) { |
| | | throw new BaseException("该型号已存在"); |
| | | if(ObjectUtils.isNotEmpty(modelResult)){ |
| | | throw new RuntimeException("请勿添加重复型号"); |
| | | } |
| | | return standardTreeMapper.insert(standardTree); |
| | | return modelMapper.insert(model); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int delStandardTree(String tree) { |
| | | String[] trees = tree.split(" - "); |
| | | switch (trees.length) { |
| | | case 5: |
| | | if (trees[3].equals("null")) { |
| | | standardTreeMapper.delete(Wrappers.<StandardTree>lambdaUpdate().eq(StandardTree::getFactory, trees[0]).eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]).isNull(StandardTree::getSample).eq(StandardTree::getModel, trees[4])); |
| | | } else { |
| | | 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; |
| | | public int delStandardTree(String level,String id) { |
| | | if(BasicTreeEnums.MODEL_TYPE.getCode().equals(level)){ |
| | | modelMapper.deleteById(id); |
| | | } |
| | | 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) { |
| | | public List<BasicTreeDto> getStandardTree2() { |
| | | // 查询所有检查对象 |
| | | List<StructureTestObject> structureTestObjectList = structureTestObjectMapper.selectList(new QueryWrapper<StructureTestObject>()); |
| | | // 查询所有产品 |
| | | List<Product> productList = productMapper.selectList(new LambdaQueryWrapper<Product>()); |
| | | // 查询所有型号 |
| | | List<Model> modelList = modelMapper.selectList(new QueryWrapper<Model>()); |
| | | // 按照归属产品id还是归属检测对象id将型号分组并组装成BasicTreeDto |
| | | Map<Integer, List<BasicTreeDto>> productModelMap = new HashMap<>(); |
| | | Map<Integer, List<BasicTreeDto>> testObjectModelMap = new HashMap<>(); |
| | | for (Model model : modelList) { |
| | | BasicTreeDto basicTreeDto = new BasicTreeDto(); |
| | | basicTreeDto.setLevel(BasicTreeEnums.MODEL_TYPE.getCode()); |
| | | basicTreeDto.setValue(model.getModelName()); |
| | | basicTreeDto.setLabel(model.getModelName()); |
| | | basicTreeDto.setChildren(null); |
| | | if(model.getProductId() != null) { |
| | | if(CollectionUtils.isEmpty(productModelMap.get(model.getProductId()))){ |
| | | List<BasicTreeDto> basicTreeDtoList = new ArrayList<>(); |
| | | basicTreeDtoList.add(basicTreeDto); |
| | | productModelMap.put(model.getProductId(),basicTreeDtoList); |
| | | }else { |
| | | productModelMap.get(model.getProductId()).add(basicTreeDto); |
| | | } |
| | | } |
| | | try { |
| | | standardProductList.setSampleType(trees[2]); |
| | | } catch (Exception e) { |
| | | if(model.getStructureTestObjectId() != null) { |
| | | if(CollectionUtils.isEmpty(testObjectModelMap.get(model.getStructureTestObjectId()))){ |
| | | List<BasicTreeDto> basicTreeDtoList = new ArrayList<>(); |
| | | basicTreeDtoList.add(basicTreeDto); |
| | | testObjectModelMap.put(model.getStructureTestObjectId(),basicTreeDtoList); |
| | | }else { |
| | | testObjectModelMap.get(model.getStructureTestObjectId()).add(basicTreeDto); |
| | | } |
| | | } |
| | | try { |
| | | standardProductList.setSample(trees[3]); |
| | | } catch (Exception e) { |
| | | } |
| | | try { |
| | | standardProductList.setModel(trees[4]); |
| | | } catch (Exception e) { |
| | | } |
| | | standardProductListMapper.insert(standardProductList); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | public List<SampleTypeDto> getStandardTree2() { |
| | | return standardTreeMapper.getStandardTree2(); |
| | | // 按照检测对象id将产品分组并组装成BasicTreeDto |
| | | Map<Integer, List<BasicTreeDto>> productMap = productList.stream().collect(Collectors.groupingBy( |
| | | Product::getObjectId, |
| | | Collectors.mapping(product -> { |
| | | BasicTreeDto basicTreeDto = new BasicTreeDto(); |
| | | basicTreeDto.setValue(product.getName()); |
| | | basicTreeDto.setLabel(product.getName()); |
| | | basicTreeDto.setLevel(BasicTreeEnums.PRODUCT_TYPE.getCode()); |
| | | basicTreeDto.setChildren(productModelMap.get(product.getId())); |
| | | return basicTreeDto; |
| | | }, Collectors.toList()) |
| | | )); |
| | | // 对检测对象先按照实验室在按照检查对象类别分类 |
| | | List<BasicTreeDto> testProjectBasicTreeList = structureTestObjectList.stream().map(structureTestObject -> { |
| | | BasicTreeDto basicTreeDto = new BasicTreeDto(); |
| | | basicTreeDto.setValue(structureTestObject.getSpecimenName()); |
| | | basicTreeDto.setLabel(structureTestObject.getSpecimenName()); |
| | | basicTreeDto.setLevel(BasicTreeEnums.STRUCTURE_TEST_OBJECT_TYPE.getCode()); |
| | | List<BasicTreeDto> children = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(productMap.get(structureTestObject.getId()))) { |
| | | children.addAll(productMap.get(structureTestObject.getId())); |
| | | } |
| | | if (!CollectionUtils.isEmpty(testObjectModelMap.get(structureTestObject.getId()))) { |
| | | children.addAll(testObjectModelMap.get(structureTestObject.getId())); |
| | | } |
| | | basicTreeDto.setChildren(children); |
| | | return basicTreeDto; |
| | | }).collect(Collectors.toList()); |
| | | return testProjectBasicTreeList; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | /** |
| | | * 修改标准数 |
| | | * @param standardTree |
| | | * @param modelAddDto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int updateStandardTree(StandardTree standardTree) { |
| | | // 修改名称匹配的标准树下的检验项目 |
| | | // 查询所有对象+名称的树 |
| | | |
| | | List<StandardProductList> standardProductLists = standardProductListService.list(Wrappers.<StandardProductList>lambdaUpdate() |
| | | .eq(StandardProductList::getSample, standardTree.getSample()) |
| | | .eq(StandardProductList::getSampleType, standardTree.getSampleType()) |
| | | .eq(StandardProductList::getModel, standardTree.getOldModel())); |
| | | if (CollectionUtils.isNotEmpty(standardProductLists)) { |
| | | for (StandardProductList standardProductList : standardProductLists) { |
| | | // 修改样品名称 |
| | | standardProductList.setModel(standardTree.getModel()); |
| | | // 修改树名称 |
| | | // 需要截取第四级, 避免三四级名称一样修改错误 |
| | | String[] trees = standardProductList.getTree().split(" - "); |
| | | trees[4] = standardTree.getModel(); |
| | | List<String> list = CollUtil.newArrayList(trees); |
| | | String newName = CollUtil.join(list, " - "); |
| | | standardProductList.setTree(newName); |
| | | public int updateStandardTree(ModelAddDto modelAddDto) { |
| | | if(modelAddDto.getId() == null){ |
| | | throw new RuntimeException("缺少型号主键"); |
| | | } |
| | | Model model = modelMapper.selectById(modelAddDto.getId()); |
| | | if(ObjectUtils.isEmpty(model)){ |
| | | throw new RuntimeException("型号查找失败"); |
| | | } |
| | | QueryWrapper<Model> modelQueryWrapper = new QueryWrapper<>(); |
| | | if(model.getStructureTestObjectId() != null){ |
| | | modelQueryWrapper.eq("structure_test_object_id", model.getStructureTestObjectId()); |
| | | } |
| | | if(model.getProductId() != null){ |
| | | modelQueryWrapper.eq("product_id", model.getProductId()); |
| | | } |
| | | modelQueryWrapper.eq("model_name", modelAddDto.getModelName()); |
| | | model.setModelName(modelAddDto.getModelName()); |
| | | List<Model> modelList = modelMapper.selectList(modelQueryWrapper); |
| | | if(CollectionUtils.isEmpty(modelList)){ |
| | | return modelMapper.updateById(model); |
| | | }else if (modelList.size() == 1) { |
| | | if( !model.getId().equals(modelList.get(0).getId())){ |
| | | throw new RuntimeException("型号名称重复"); |
| | | }else { |
| | | return modelMapper.updateById(model); |
| | | } |
| | | standardProductListService.updateBatchById(standardProductLists); |
| | | }else { |
| | | throw new RuntimeException("型号名称重复"); |
| | | } |
| | | |
| | | // 修改标准数检验项目 |
| | | LambdaUpdateWrapper<StandardTree> wrapper = Wrappers.<StandardTree>lambdaUpdate() |
| | | .eq(StandardTree::getFactory, standardTree.getFactory()) |
| | | .eq(StandardTree::getLaboratory, standardTree.getLaboratory()) |
| | | .eq(StandardTree::getSampleType, standardTree.getSampleType()) |
| | | .eq(StandardTree::getModel, standardTree.getOldModel()) |
| | | .set(StandardTree::getModel, standardTree.getModel()); |
| | | if (StringUtils.isNotBlank(standardTree.getSample())) { |
| | | wrapper.eq(StandardTree::getSample, standardTree.getSample()); |
| | | } |
| | | return standardTreeMapper.update(null, wrapper); |
| | | } |
| | | |
| | | @Override |