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 |  116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 115 insertions(+), 1 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 9279599..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,14 +1,33 @@
 package com.yuanchu.limslaboratory.service.impl;
 
+
+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.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * <p>
- *  鏈嶅姟瀹炵幇绫�
+ * 鏈嶅姟瀹炵幇绫�
  * </p>
  *
  * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃
@@ -17,4 +36,99 @@
 @Service
 public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements MaterialService {
 
+    @Resource
+    private MaterialMapper materialMapper;
+
+    @Autowired
+    private StandardService standardService;
+
+    @Autowired
+    private SpecificationsService specificationsService;
+
+    @Autowired
+    private ProductService productService;
+
+    @Resource
+    ProductModelMapper productModelMapper;
+
+    //鏌ヨ鐗╂枡淇℃伅
+    @Override
+    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);
+        int isDeleteSuccess = materialMapper.update(new Material(), updateWrapper);
+        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
+    @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 0;
+    }
+
+    @Override
+    public List<Map<String, Object>> getFourLevelInformation() {
+        return materialMapper.FourTree();
+    }
+
+    //娣诲姞鎸囨爣-->閫夋嫨鏍峰搧鍚嶇О
+    @Override
+    public List<String> selectmater() {
+        return productModelMapper.selectmater();
+    }
+
+
 }

--
Gitblit v1.9.3