| | |
| | | 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 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(productModelMap.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(TestPorjectTypeEnums.getNameByCode(objectType)); |
| | | List<StructureTestObjectDto> structureTestObjectTypeList = objectTypeMap.get(objectType); |
| | | if (CollectionUtils.isEmpty(structureTestObjectTypeList)) { |
| | | continue; |
| | | } |
| | | // å°è£
è½¦é´æ |
| | | if (objectType.equals("1") || objectType.equals("5")) { |
| | | 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("2") || objectType.equals("3") || objectType.equals("4")) { |
| | | 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 laboratoryTreeDtoList; |
| | | } |
| | | |
| | | |
| | | @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(StandardProductList::getSample, standardTree.getSample()) |
| | | .eq(StandardProductList::getSampleType, standardTree.getSampleType()) |
| | | .eq(StandardProductList::getModel, standardTree.getOldModel())); |
| | | if (CollectionUtils.isNotEmpty(standardProductLists)) { |
| | | if (!CollectionUtils.isEmpty(standardProductLists)) { |
| | | for (StandardProductList standardProductList : standardProductLists) { |
| | | // ä¿®æ¹æ ·ååç§° |
| | | standardProductList.setModel(standardTree.getModel()); |