| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | 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.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.excel.StructureTestObjectData; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.ProductMapper; |
| | | import com.yuanchu.mom.mapper.StructureTestObjectMapper; |
| | | import com.yuanchu.mom.pojo.Laboratory; |
| | | import com.yuanchu.mom.pojo.Product; |
| | | import com.yuanchu.mom.pojo.StructureTestObject; |
| | | import com.yuanchu.mom.service.LaboratoryService; |
| | | import com.yuanchu.mom.service.ProductService; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | 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; |
| | |
| | | private ProductMapper productMapper; |
| | | |
| | | private GetLook getLook; |
| | | |
| | | private LaboratoryService laboratoryService; |
| | | |
| | | private StructureTestObjectMapper structureTestObjectMapper; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectProductListByObjectId(Page page, Product product) { |
| | |
| | | return productMapper.deleteById(id); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void importPartExcel(List<StructureTestObjectData> list) { |
| | | System.out.println(list); |
| | | List<StructureTestObject> addList = new ArrayList<>(); |
| | | List<StructureTestObject> updateList = new ArrayList<>(); |
| | | List<Product> addProductList = new ArrayList<>(); |
| | | list.forEach(i -> { |
| | | // 检验对象 |
| | | StructureTestObject structureTestObject1 = structureTestObjectMapper.selectOne(Wrappers.<StructureTestObject>lambdaQuery() |
| | | .eq(StructureTestObject::getSpecimenName, i.getSpecimenName()) |
| | | .eq(StructureTestObject::getSpecimenNameEn, i.getSpecimenNameEn())); |
| | | Laboratory laboratory = laboratoryService.getOne(Wrappers.<Laboratory>lambdaQuery() |
| | | .eq(Laboratory::getLaboratoryName, i.getLaboratory())); |
| | | if (ObjectUtils.isEmpty(laboratory)) { |
| | | throw new ErrorException("未找到该场所:" + i.getLaboratory() + ",请检查是否存在该场所!"); |
| | | } |
| | | // 如果为空进行新增 |
| | | if(ObjectUtils.isEmpty(structureTestObject1)) { |
| | | StructureTestObject structureTestObject = new StructureTestObject(); |
| | | structureTestObject.setLaboratoryId(laboratory.getId()); |
| | | structureTestObject.setSpecimenName(i.getSpecimenName()); |
| | | structureTestObject.setSpecimenNameEn(i.getSpecimenNameEn()); |
| | | structureTestObject.setCode(i.getCode()); |
| | | addList.add(structureTestObject); |
| | | } else { |
| | | structureTestObject1.setCode(i.getCode()); |
| | | structureTestObject1.setLaboratoryId(laboratory.getId()); |
| | | updateList.add(structureTestObject1); |
| | | } |
| | | |
| | | // 产品 |
| | | Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery() |
| | | .eq(Product::getName, i.getName()) |
| | | .eq(Product::getNameEn, i.getNameEn())); |
| | | if (ObjectUtils.isEmpty(product)){ |
| | | Product product1 = new Product(); |
| | | product1.setName(i.getName()); |
| | | product1.setNameEn(i.getNameEn()); |
| | | addProductList.add(product1); |
| | | } |
| | | }); |
| | | addList.forEach(i -> { |
| | | structureTestObjectMapper.insert(i); |
| | | }); |
| | | saveBatch(addProductList); |
| | | updateList.forEach(i -> { |
| | | structureTestObjectMapper.updateById(i); |
| | | }); |
| | | } |
| | | } |
| | | |