From 2dbc49184bd74845c8da694c20d6fd03d7ac87e0 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期四, 21 九月 2023 16:16:21 +0800
Subject: [PATCH] 修改   9.21

---
 standard-server/src/main/java/com/yuanchu/mom/service/impl/SpecificationsServiceImpl.java |  181 +++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 159 insertions(+), 22 deletions(-)

diff --git a/standard-server/src/main/java/com/yuanchu/mom/service/impl/SpecificationsServiceImpl.java b/standard-server/src/main/java/com/yuanchu/mom/service/impl/SpecificationsServiceImpl.java
index 75ea50f..42ae537 100644
--- a/standard-server/src/main/java/com/yuanchu/mom/service/impl/SpecificationsServiceImpl.java
+++ b/standard-server/src/main/java/com/yuanchu/mom/service/impl/SpecificationsServiceImpl.java
@@ -1,20 +1,25 @@
 package com.yuanchu.mom.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.yuanchu.mom.mapper.SpecificationsMapper;
-import com.yuanchu.mom.pojo.Specifications;
-import com.yuanchu.mom.service.SpecificationsService;
+import com.yuanchu.mom.mapper.*;
+import com.yuanchu.mom.pojo.*;
+import com.yuanchu.mom.pojo.dto.SpecificationsDto;
+import com.yuanchu.mom.service.*;
 import com.yuanchu.mom.utils.MyUtil;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author Administrator
@@ -22,29 +27,161 @@
  * @createDate 2023-07-26 16:01:49
  */
 @Service
-public class SpecificationsServiceImpl extends ServiceImpl<SpecificationsMapper, Specifications>
-        implements SpecificationsService {
+public class SpecificationsServiceImpl extends ServiceImpl<SpecificationsMapper, Specifications> implements SpecificationsService {
 
     @Resource
-    private SpecificationsMapper specificationsMapper;
+    MaterialMapper materialMapper;
 
-    /**
-     * 妫�楠屾ā鍧�-->OMS绠$悊-->鎴愬搧妫�楠�-->鏂板(闇�瑕佽鏍煎瀷鍙风殑Id涓庡悕绉�)
-     */
+    @Resource
+    SpecificationsMapper specificationsMapper;
+
+    @Resource
+    TechnologyService technologyService;
+
+    @Resource
+    TechnologyTemplateMapper technologyTemplateMapper;
+
+    @Resource
+    ProductService productService;
+
+    @Resource
+    TechnicalModelMapper technicalModelMapper;
+
+    @Resource
+    MbomService mbomService;
+
+    @Resource
+    MbomModelMapper mbomModelMapper;
+
+    @Resource
+    ProductMapper productMapper;
+
+    @Resource
+    MbomMapper mbomMapper;
+
+    @Resource
+    TechnologyMapper technologyMapper;
+
+    //(4绾�)鏂板-->鍨嬪彿
     @Override
-    public List<Map<String, Object>> selectSpecificationIdAndName(Integer materialId) {
-        List<Map<String, Object>> maps = specificationsMapper.selectSpecificationIdAndName(materialId);
-        return maps;
-    }
-
-
-    //鏍规嵁瑙勬牸id鍜屽瀷鍙峰悕绉版煡璇㈠瀷鍙蜂俊鎭�
-    @Override
-    public Specifications selectSpIdByname(Integer id, String name) {
-        Specifications specifications = specificationsMapper.selectOne(Wrappers.<Specifications>query()
-                .eq("standard_id", id)
-                .eq("name", name));
-        return specifications;
+    @Transactional(rollbackFor = Exception.class)
+    public String addSpecifications(SpecificationsDto specificationsDto, Integer spId, Integer ver) {
+        //鏍¢獙娣诲姞璇ユ爣鍑嗕笅鐨勫瀷鍙锋槸鍚﹂噸澶�
+        List<String> specificationsNameList = specificationsMapper.selectList(Wrappers.<Specifications>query().eq("standard_id", specificationsDto.getId())).stream().map(specifications -> {
+            String specificationsName = specifications.getName();
+            return specificationsName;
+        }).collect(Collectors.toList());
+        if (specificationsNameList.contains(specificationsDto.getSpecifications())) {
+            return "璇ユ爣鍑嗕笅鏈夎鍨嬪彿";
+        }
+        /*鏂板鍨嬪彿琛�*/
+        Specifications specifications = new Specifications();
+        specifications.setStandardId(specificationsDto.getId());
+        specifications.setName(specificationsDto.getSpecifications());
+        specificationsMapper.insert(specifications);
+        /**
+         * 鏍规嵁閫夋嫨鐨勬儏鍐�,鍒ゆ柇鏄媺鍙栧熀纭�鏁版嵁鐨勬暟鎹�,杩樻槸鏌愪竴涓骇鍝佷笅鏌愪竴涓瀷鍙风殑鏁版嵁
+         */
+        //濡傛灉spId浼犵殑鍙傛暟鏄�0,鍒欐媺鍙栧熀纭�鏁版嵁鐨勬暟鎹�
+        if (spId == 0) {
+            /*鏂板鏍囧噯BOM-->宸ヨ壓璺嚎(鎵归噺娣诲姞)*/
+            //鏍规嵁鏍囧噯id鏌ヨ鐗╂枡澶х被
+            Material material = materialMapper.selFath(specificationsDto.getId());
+            List<TechnologyTemplate> technologyTemplateList = technologyTemplateMapper.selectList(Wrappers.<TechnologyTemplate>query().eq("type", material.getFather()));
+            if (ObjectUtils.isEmpty(technologyTemplateList)) {
+                return "娣诲姞鍨嬪彿銆�" + specificationsDto.getSpecifications() + "銆戞垚鍔燂紒";
+            }
+            List<Technology> technologyList = technologyTemplateList.stream().map(technologyTemplate -> {
+                Technology technology = new Technology();
+                technology.setSpecificationsId(specifications.getId());
+                technology.setFather(technologyTemplate.getFather());
+                technology.setName(technologyTemplate.getName());
+                technology.setDeviceGroup(technologyTemplate.getDeviceGroup());
+                return technology;
+            }).collect(Collectors.toList());
+            technologyService.saveBatch(technologyList);
+            /*鏂板鏍囧噯BOM-->鎶�鏈寚鏍�(鎵归噺娣诲姞)*/
+            //鏂板鐨勫伐鑹鸿矾绾縤d闆嗗悎
+            List<Integer> technologyIds = technologyList.stream().map(Technology::getId).collect(Collectors.toList());
+            //鍩虹鏁版嵁涓伐鑹鸿矾绾縤d闆嗗悎
+            List<Integer> techTemIds = technologyTemplateList.stream().map(TechnologyTemplate::getId).collect(Collectors.toList());
+            //涓よ�呴暱搴︿竴瀹氫竴鏍�
+            List<Product> productList = new ArrayList<>();
+            for (int i = 0; i < technologyIds.size(); i++) {
+                List<TechnicalModel> technicalModelList = technicalModelMapper.selectList(Wrappers.<TechnicalModel>query().eq("tech_tem_id", techTemIds.get(i)));
+                for (TechnicalModel technicalModel : technicalModelList) {
+                    Product product = new Product();
+                    product.setFather(technicalModel.getFather());
+                    product.setName(technicalModel.getName());
+                    product.setUnit(technicalModel.getUnit());
+                    product.setTechnologyId(technologyIds.get(i));
+                    productList.add(product);
+                }
+            }
+            productService.saveBatch(productList);
+            /*鏂板鏍囧噯BOM-->鐗╂枡娓呭崟(鎵归噺娣诲姞)*/
+            List<Mbom> mbomList = new ArrayList<>();
+            for (int i = 0; i < technologyIds.size(); i++) {
+                List<MbomModel> mbomModelList = mbomModelMapper.selectList(Wrappers.<MbomModel>query().eq("tech_tem_id", techTemIds.get(i)));
+                for (MbomModel mbomModel : mbomModelList) {
+                    Mbom mbom = new Mbom();
+                    mbom.setUnit(mbomModel.getUnit());
+                    mbom.setName(mbomModel.getName());
+                    mbom.setQualityTraceability(mbomModel.getQualityTraceability());
+                    mbom.setSpecifications(mbomModel.getSpecifications());
+                    mbom.setTechnologyId(technologyIds.get(i));
+                    mbomList.add(mbom);
+                }
+            }
+            mbomService.saveBatch(mbomList);
+            return "娣诲姞鍨嬪彿銆�" + specificationsDto.getSpecifications() + "銆戞垚鍔燂紒";
+        }
+        //濡傛灉spId!=0,绛変簬閫夋嫨鐨勫叿浣撳瀷鍙�,鍒欐坊鍔犺鍨嬪彿鐗堟湰鐨勬暟鎹�
+        /*鏂板鏍囧噯BOM-->宸ヨ壓璺嚎(鎵归噺娣诲姞)*/
+        List<Technology> technologyList = technologyMapper.selAllByVerSpId(spId, ver);
+        List<Technology> technologys = technologyList.stream().map(technology -> {
+            Technology tec = new Technology();
+            tec.setSpecificationsId(specifications.getId());
+            tec.setName(technology.getName());
+            tec.setFather(technology.getFather());
+            tec.setDeviceGroup(technology.getDeviceGroup());
+            tec.setProductionQuota(technology.getProductionQuota());
+            return tec;
+        }).collect(Collectors.toList());
+        technologyService.saveBatch(technologys);
+        //涓よ�呴暱搴︿竴瀹氫竴鏍�
+        for (int i = 0; i < technologyList.size(); i++) {
+            /*鏂板鏍囧噯BOM-->鎶�鏈寚鏍�(鎵归噺娣诲姞)*/
+            List<Product> productList = productMapper.selProByVerSpe(technologyList.get(i).getId());
+            List<Product> products = new ArrayList<>();
+            for (Product product : productList) {
+                Product pro = new Product();
+                pro.setTechnologyId(technologys.get(i).getId());
+                pro.setName(product.getName());
+                pro.setFather(product.getFather());
+                pro.setUnit(product.getUnit());
+                pro.setRequired(product.getRequired());
+                pro.setInternal(product.getInternal());
+                products.add(pro);
+            }
+            productService.saveBatch(products);
+            /*鏂板鏍囧噯BOM-->鐗╂枡娓呭崟(鎵归噺娣诲姞)*/
+            List<Mbom> mbomList = mbomMapper.seleByTechId(technologyList.get(i).getId());
+            List<Mbom> mboms = new ArrayList<>();
+            for (Mbom mbom : mbomList) {
+                Mbom mbo = new Mbom();
+                mbo.setTechnologyId(technologys.get(i).getId());
+                mbo.setName(mbom.getName());
+                mbo.setUnit(mbom.getUnit());
+                mbo.setUnit(mbom.getUnit());
+                mbo.setNum(mbom.getNum());
+                mbo.setQualityTraceability(mbom.getQualityTraceability());
+                mbo.setSpecifications(mbom.getSpecifications());
+                mboms.add(mbo);
+            }
+            mbomService.saveBatch(mboms);
+        }
+        return "娣诲姞鍨嬪彿銆�" + specificationsDto.getSpecifications() + "銆戞垚鍔燂紒";
     }
 }
 

--
Gitblit v1.9.3