From c5138faa1c4771bfbc19de5b257e7c129c081cb8 Mon Sep 17 00:00:00 2001 From: Fixiaobai <fixiaobai@163.com> Date: 星期一, 28 八月 2023 13:30:17 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- standard-server/src/main/java/com/yuanchu/limslaboratory/service/impl/MaterialServiceImpl.java | 119 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 87 insertions(+), 32 deletions(-) diff --git a/standard-server/src/main/java/com/yuanchu/limslaboratory/service/impl/MaterialServiceImpl.java b/standard-server/src/main/java/com/yuanchu/limslaboratory/service/impl/MaterialServiceImpl.java index a373c2a..6650cf6 100644 --- a/standard-server/src/main/java/com/yuanchu/limslaboratory/service/impl/MaterialServiceImpl.java +++ b/standard-server/src/main/java/com/yuanchu/limslaboratory/service/impl/MaterialServiceImpl.java @@ -1,23 +1,33 @@ package com.yuanchu.limslaboratory.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; + import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.yuanchu.limslaboratory.mapper.ProductModelMapper; import com.yuanchu.limslaboratory.pojo.Material; import com.yuanchu.limslaboratory.mapper.MaterialMapper; +import com.yuanchu.limslaboratory.pojo.Product; +import com.yuanchu.limslaboratory.pojo.Specifications; +import com.yuanchu.limslaboratory.pojo.Standard; +import com.yuanchu.limslaboratory.pojo.dto.AddMaterialDto; import com.yuanchu.limslaboratory.service.MaterialService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.yuanchu.limslaboratory.service.ProductService; +import com.yuanchu.limslaboratory.service.SpecificationsService; +import com.yuanchu.limslaboratory.service.StandardService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * <p> - * 鏈嶅姟瀹炵幇绫� + * 鏈嶅姟瀹炵幇绫� * </p> * * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃 @@ -27,53 +37,98 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements MaterialService { @Resource - MaterialMapper materialMapper; + private MaterialMapper materialMapper; - //鏌ヨ鐗╂枡淇℃伅 - @Override - public List<Material> selectMaterialLimit(int pageSize, int countSize) { - return materialMapper.selectMaterialLimit((pageSize - 1) * countSize,pageSize * countSize); - } + @Autowired + private StandardService standardService; - //鏍规嵁鐗╂枡id鏌ヨ鐗╂枡淇℃伅 - @Override - public Map selectMaterialById(String materialId) { - return materialMapper.selectMaterialById(materialId); - } + @Autowired + private SpecificationsService specificationsService; @Autowired private ProductService productService; + @Resource + ProductModelMapper productModelMapper; + + //鏌ヨ鐗╂枡淇℃伅 @Override - public Integer deleteMaterialInformation(String materialId) { + public List<Map> selectMaterialLimit(int pageSize, int countSize, int type) { + return materialMapper.selectMaterialLimit((pageSize - 1) * countSize, pageSize * countSize, type); + } + + + @Override + public Integer deleteMaterialInformation(Integer materialId) { LambdaUpdateWrapper<Material> updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(Material::getId, materialId); updateWrapper.set(Material::getState, 0); - List<String> list = new ArrayList<>(); - list.add(materialId); int isDeleteSuccess = materialMapper.update(new Material(), updateWrapper); - if (isDeleteSuccess == 1){ - productService.MaterialIdDeleteProduct(list); + if (isDeleteSuccess == 1) { + List<Integer> isDeleteStandard = standardService.deleteStandardsInformation(materialId); + if (!ObjectUtils.isEmpty(isDeleteStandard)) { + List<Integer> idDeleteSpecifications = specificationsService.StandardIdDeleteSpecifications(isDeleteStandard); + if (!ObjectUtils.isEmpty(idDeleteSpecifications)) { + productService.deleteProductInformation(idDeleteSpecifications); + } + } return 1; } return 0; } + //涓夌骇鏂板 @Override - public List<String> specificationsIdDeleteMaterial(List<Integer> deleteSpecificationsId) { - List<String> list = new ArrayList<>(); - for (Integer serialNumberId:deleteSpecificationsId){ - LambdaQueryWrapper<Material> wrapper = new LambdaQueryWrapper<>(); - wrapper.select(Material::getId); - List<Material> maps1 = materialMapper.selectList(wrapper); - for (Material material:maps1){ - LambdaUpdateWrapper<Material> updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(Material::getId, material.getId()); - updateWrapper.set(Material::getState, 0); - materialMapper.update(new Material(), updateWrapper); - list.add(material.getId()); + @Transactional(rollbackFor = Exception.class) + public Integer addMaterialInformation(AddMaterialDto addMaterialDto) { + Material material = new Material() + .setCode("BZ" + IdWorker.getIdStr()) + .setName(addMaterialDto.getMaterialName()) + .setType(addMaterialDto.getType()); + int isInsertSuccess = materialMapper.insert(material); + if (isInsertSuccess > 0) { + Standard standard = new Standard() + .setMaterialId(material.getId()) + .setName(addMaterialDto.getStandardName()); + boolean save = standardService.save(standard); + if (save) { + Specifications specifications = new Specifications() + .setName(addMaterialDto.getSpecificationsName()) + .setStandardId(standard.getId()); + boolean save1 = specificationsService.save(specifications); + if (save1) { + //娣诲姞鍨嬪彿涔嬪悗娣诲姞椤圭洰 + List<Map<String, Object>> productModel = productModelMapper.seleMode(addMaterialDto.getMaterialName()); + List<Product> productList = productModel.stream().map(stringObjectMap -> { + Product product = new Product(); + product.setName(stringObjectMap.get("name").toString()); + if (ObjectUtils.isNotEmpty(stringObjectMap.get("father"))) { + product.setFather(stringObjectMap.get("father").toString()); + } + if (ObjectUtils.isNotEmpty(stringObjectMap.get("unit"))) { + product.setUnit(stringObjectMap.get("unit").toString()); + } + product.setSpecifications_id(specifications.getId()); + return product; + }).collect(Collectors.toList()); + productService.saveBatch(productList); + return 1; + } } } - return list; + return 0; } + + @Override + public List<Map<String, Object>> getFourLevelInformation() { + return materialMapper.FourTree(); + } + + //娣诲姞鎸囨爣-->閫夋嫨鏍峰搧鍚嶇О + @Override + public List<String> selectmater() { + return productModelMapper.selectmater(); + } + + } -- Gitblit v1.9.3