| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.excel.StructureTestObjectData; |
| | | import com.ruoyi.basic.service.*; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.basic.dto.PageTestObjectDto; |
| | | import com.ruoyi.basic.dto.TestItemDto; |
| | | import com.ruoyi.basic.mapper.*; |
| | | import com.ruoyi.basic.pojo.*; |
| | | import com.ruoyi.basic.service.CapacityScopeService; |
| | | import com.ruoyi.basic.service.StandardProductListService; |
| | | import com.ruoyi.basic.service.StructureItemParameterService; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | |
| | | |
| | | private ProductMapper productMapper; |
| | | |
| | | private ProductService productService; |
| | | |
| | | private StructureTestObjectService structureTestObjectService; |
| | | |
| | | private StructureTestObjectPartMapper structureTestObjectPartMapper; |
| | | |
| | | private ProductPartMapper productPartMapper; |
| | |
| | | |
| | | private StructureItemParameterService structureItemParameterService; |
| | | |
| | | private WorkShopMapper workShopMapper; |
| | | |
| | | @Override |
| | | public IPage<StructureItemParameter> selectItemParameterList(Page page, StructureItemParameter itemParameter) { |
| | | return structureItemParameterMapper.selectItemParameterList(page, QueryWrappers.queryWrappers(itemParameter)); |
| | |
| | | public List<TestItemDto> getItemTree() { |
| | | return structureItemParameterMapper.getItemTree(); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void importPartExcel(List<StructureTestObjectData> list) { |
| | | // 批量查询 StructureTestObject |
| | | Map<String, StructureTestObject> structureTestObjectMap = getStructureTestObjectMap(list); |
| | | // 批量查询 WorkShop |
| | | Map<String, WorkShop> workShopMap = getWorkShopMap(list); |
| | | |
| | | List<StructureTestObject> insertStructureTestObjects = new ArrayList<>(); |
| | | List<StructureTestObject> updateStructureTestObjects = new ArrayList<>(); |
| | | List<Product> insertProducts = new ArrayList<>(); |
| | | List<Product> updateProducts = new ArrayList<>(); |
| | | |
| | | for (StructureTestObjectData data : list) { |
| | | String key = data.getSpecimenName() + "_" + data.getSpecimenNameEn(); |
| | | StructureTestObject structureTestObject = structureTestObjectMap.get(key); |
| | | |
| | | if (ObjectUtils.isEmpty(structureTestObject)) { |
| | | structureTestObject = createStructureTestObject(data); |
| | | insertStructureTestObjects.add(structureTestObject); |
| | | } else { |
| | | updateStructureTestObject(structureTestObject, data); |
| | | updateStructureTestObjects.add(structureTestObject); |
| | | } |
| | | |
| | | String productKey = data.getName() + "_" + data.getNameEn(); |
| | | Product product = productMapper.selectOne(new LambdaQueryWrapper<Product>() |
| | | .eq(Product::getName, data.getName()) |
| | | .eq(Product::getNameEn, data.getNameEn())); |
| | | |
| | | if (ObjectUtils.isEmpty(product)) { |
| | | product = createProduct(data, structureTestObject.getId(), workShopMap); |
| | | insertProducts.add(product); |
| | | } else { |
| | | updateProduct(product, data, structureTestObject.getId(), workShopMap); |
| | | updateProducts.add(product); |
| | | } |
| | | } |
| | | |
| | | // 批量插入和更新 |
| | | if (!insertStructureTestObjects.isEmpty()) { |
| | | structureTestObjectService.saveOrUpdateBatch(insertStructureTestObjects); |
| | | } |
| | | if (!updateStructureTestObjects.isEmpty()) { |
| | | structureTestObjectService.updateBatchById(updateStructureTestObjects); |
| | | } |
| | | if (!insertProducts.isEmpty()) { |
| | | productService.saveOrUpdateBatch(insertProducts); |
| | | } |
| | | if (!updateProducts.isEmpty()) { |
| | | productService.updateBatchById(updateProducts); |
| | | } |
| | | } |
| | | |
| | | private Map<String, StructureTestObject> getStructureTestObjectMap(List<StructureTestObjectData> list) { |
| | | List<String> specimenNames = list.stream().map(StructureTestObjectData::getSpecimenName).collect(Collectors.toList()); |
| | | List<String> specimenNamesEn = list.stream().map(StructureTestObjectData::getSpecimenNameEn).collect(Collectors.toList()); |
| | | List<StructureTestObject> structureTestObjects = structureTestObjectMapper.selectList(new LambdaQueryWrapper<StructureTestObject>() |
| | | .in(StructureTestObject::getSpecimenName, specimenNames) |
| | | .in(StructureTestObject::getSpecimenNameEn, specimenNamesEn)); |
| | | Map<String, StructureTestObject> map = new HashMap<>(); |
| | | for (StructureTestObject obj : structureTestObjects) { |
| | | map.put(obj.getSpecimenName() + "_" + obj.getSpecimenNameEn(), obj); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | private Map<String, WorkShop> getWorkShopMap(List<StructureTestObjectData> list) { |
| | | List<String> workShopNames = list.stream() |
| | | .map(StructureTestObjectData::getWorkShopName) |
| | | .filter(StringUtils::isNotEmpty) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | List<WorkShop> workShops = workShopMapper.selectList(new LambdaQueryWrapper<WorkShop>() |
| | | .in(WorkShop::getName, workShopNames)); |
| | | Map<String, WorkShop> map = new HashMap<>(); |
| | | for (WorkShop workShop : workShops) { |
| | | map.put(workShop.getName(), workShop); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | private StructureTestObject createStructureTestObject(StructureTestObjectData data) { |
| | | StructureTestObject structureTestObject = new StructureTestObject(); |
| | | structureTestObject.setLaboratoryId(9); |
| | | structureTestObject.setSpecimenName(data.getSpecimenName()); |
| | | structureTestObject.setSpecimenNameEn(data.getSpecimenNameEn()); |
| | | structureTestObject.setCode(data.getCode()); |
| | | structureTestObject.setWorkShopName(""); |
| | | return structureTestObject; |
| | | } |
| | | |
| | | private void updateStructureTestObject(StructureTestObject structureTestObject, StructureTestObjectData data) { |
| | | structureTestObject.setCode(data.getCode()); |
| | | structureTestObject.setLaboratoryId(9); |
| | | } |
| | | |
| | | private Product createProduct(StructureTestObjectData data, Integer objectId, Map<String, WorkShop> workShopMap) { |
| | | Product product = new Product(); |
| | | product.setName(data.getName()); |
| | | product.setNameEn(data.getNameEn()); |
| | | if (StringUtils.isNotEmpty(data.getWorkShopName())) { |
| | | WorkShop workShop = workShopMap.get(data.getWorkShopName()); |
| | | if (workShop == null) { |
| | | throw new BaseException("请先维护车间信息"); |
| | | } |
| | | product.setWorkShopId(workShop.getId()); |
| | | } |
| | | product.setWorkShopName(data.getWorkShopName()); |
| | | product.setObjectId(objectId); |
| | | return product; |
| | | } |
| | | |
| | | private void updateProduct(Product product, StructureTestObjectData data, Integer objectId, Map<String, WorkShop> workShopMap) { |
| | | if (StringUtils.isNotEmpty(data.getWorkShopName())) { |
| | | WorkShop workShop = workShopMap.get(data.getWorkShopName()); |
| | | if (workShop == null) { |
| | | throw new BaseException("请先维护车间信息"); |
| | | } |
| | | product.setWorkShopId(workShop.getId()); |
| | | } |
| | | product.setWorkShopName(data.getWorkShopName()); |
| | | product.setName(data.getName()); |
| | | product.setNameEn(data.getNameEn()); |
| | | product.setObjectId(objectId); |
| | | } |
| | | } |
| | | |