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/MaterialServiceImpl.java |  209 ++++++++++++++++++++++++++-------------------------
 1 files changed, 107 insertions(+), 102 deletions(-)

diff --git a/standard-server/src/main/java/com/yuanchu/mom/service/impl/MaterialServiceImpl.java b/standard-server/src/main/java/com/yuanchu/mom/service/impl/MaterialServiceImpl.java
index 35e9113..33ee29d 100644
--- a/standard-server/src/main/java/com/yuanchu/mom/service/impl/MaterialServiceImpl.java
+++ b/standard-server/src/main/java/com/yuanchu/mom/service/impl/MaterialServiceImpl.java
@@ -1,6 +1,7 @@
 package com.yuanchu.mom.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yuanchu.mom.mapper.*;
@@ -13,6 +14,7 @@
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -53,15 +55,6 @@
     MbomModelMapper mbomModelMapper;
 
     @Resource
-    TechniqueService techniqueService;
-
-    @Resource
-    TechniqueModelMapper techniqueModelMapper;
-
-    @Resource
-    DeviceMapper deviceMapper;
-
-    @Resource
     TechnologyMapper technologyMapper;
 
     @Resource
@@ -70,8 +63,12 @@
     @Resource
     MbomMapper mbomMapper;
 
-    @Resource
-    TechniqueMapper techniqueMapper;
+
+    //鏂板-->閫夋嫨浜у搧澶х被
+    @Override
+    public List<String> chooseFather() {
+        return technologyTemplateMapper.chooseType();
+    }
 
     //鏍囧噯MOM-->宸︿晶浜旂骇鏍戝睍绀�
     @Override
@@ -82,7 +79,7 @@
     //(1,2绾�)鏂板-->鐗╂枡,鏍囧噯,鍨嬪彿
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public String addMaterial(MaterialDto materialDto) {
+    public String addMaterial(MaterialDto materialDto, Integer spId, Integer ver) {
         //鏍¢獙娣诲姞鐗╂枡鏄惁閲嶅
         List<Material> materialList = materialMapper.selectList(Wrappers.<Material>query()
                 .eq("type", materialDto.getType())
@@ -109,86 +106,111 @@
         specifications.setName(materialDto.getSpecifications());
         specifications.setStandardId(standard.getId());
         specificationsMapper.insert(specifications);
-        /*鏂板鏍囧噯BOM-->宸ヨ壓璺嚎(鎵归噺娣诲姞)*///0锛氭鑳惰繛鎺ュ櫒锛�1锛氶噾灞炶繛鎺ュ櫒锛�2锛氭箍鎻掓嫈鐢佃繛鎺ュ櫒锛�3锛氬垎鏀粍浠�
-        Integer type = null;
-        if (materialDto.getFather().equals("姗¤兌杩炴帴鍣�")){
-            type=0;
-        }else if (materialDto.getFather().equals("閲戝睘杩炴帴鍣�")){
-            type=1;
-        }else if(materialDto.getFather().equals("婀挎彃鎷旂數杩炴帴鍣�")){
-            type=2;
-        }else if(materialDto.getFather().equals("鍒嗘敮缁勪欢")){
-            type=3;
-        }else return "娣诲姞鐗╂枡銆�" + materialDto.getName() + "銆戞垚鍔�";
-        List<TechnologyTemplate> technologyTemplateList = technologyTemplateMapper.selectList(Wrappers.<TechnologyTemplate>query().eq("type", type));
-        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;
+        /**
+         * 鏍规嵁閫夋嫨鐨勬儏鍐�,鍒ゆ柇鏄媺鍙栧熀纭�鏁版嵁鐨勬暟鎹�,杩樻槸鏌愪竴涓骇鍝佷笅鏌愪竴涓瀷鍙风殑鏁版嵁
+         */
+        //濡傛灉spId浼犵殑鍙傛暟鏄�0,鍒欐媺鍙栧熀纭�鏁版嵁鐨勬暟鎹�
+        if (spId == 0) {
+            /*鏂板鏍囧噯BOM-->宸ヨ壓璺嚎(鎵归噺娣诲姞)*/
+            List<TechnologyTemplate> technologyTemplateList = technologyTemplateMapper.selectList(Wrappers.<TechnologyTemplate>query().eq("type", material.getFather()));
+            if (ObjectUtils.isEmpty(technologyTemplateList)) {
+                return "娣诲姞鐗╂枡銆�" + materialDto.getName() + "銆戞垚鍔�";
+            }
+            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 "娣诲姞鐗╂枡銆�" + materialDto.getName() + "銆戞垚鍔�";
+        }
+        //濡傛灉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(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());
+        technologyService.saveBatch(technologys);
         //涓よ�呴暱搴︿竴瀹氫竴鏍�
-        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);
+        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(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.setSupplier(mbomModel.getSupplier());
-                mbom.setQualityTraceability(mbomModel.getQualityTraceability());
-                mbom.setSpecifications(mbomModel.getSpecifications());
-                mbom.setTechnologyId(technologyIds.get(i));
-                mbomList.add(mbom);
+            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);
         }
-        mbomService.saveBatch(mbomList);
-        /*鏂板鏍囧噯BOM-->鐢熶骇宸ヨ壓(鎵归噺娣诲姞)*/
-        List<Technique> techniqueList = new ArrayList<>();
-        for (int i = 0; i < technologyIds.size(); i++) {
-            List<TechniqueModel> techniqueModelList = techniqueModelMapper.selectList(Wrappers.<TechniqueModel>query().eq("tech_tem_id", techTemIds.get(i)));
-            for (TechniqueModel techniqueModel : techniqueModelList) {
-                //鏌ヨ璁惧鍚嶇О
-                Device device = deviceMapper.selectById(techniqueModel.getDeviceId());
-                //鏌ヨ鍩虹鐢熶骇宸ヨ壓涓瘡涓澶囩殑鍏蜂綋椤圭洰
-                TechnicalModel technicalModel = technicalModelMapper.selectById(techniqueModel.getTechnicalModelId());
-                Technique technique = new Technique();
-                technique.setTechnologyId(technologyIds.get(i));
-                technique.setDevice(device.getName());
-                technique.setProductFather(technicalModel.getFather());
-                technique.setProduct(technicalModel.getName());
-                technique.setUnit(technicalModel.getUnit());
-                techniqueList.add(technique);
-            }
-        }
-        techniqueService.saveBatch(techniqueList);
         return "娣诲姞鐗╂枡銆�" + materialDto.getName() + "銆戞垚鍔�";
     }
 
 
-    //娣诲姞鍚屼竴涓瀷鍙峰伐鑹鸿矾绾�,鎶�鏈寚鏍�,鐗╂枡娓呭崟,鐢熶骇宸ヨ壓鐨勭増鏈�
+    //娣诲姞鍚屼竴涓瀷鍙峰伐鑹鸿矾绾�,鎶�鏈寚鏍�,鐗╂枡娓呭崟鐨勭増鏈�
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Integer addVersion(Integer specificationsId, Integer version) {
@@ -217,7 +239,7 @@
                 product.setUnit(pro.getUnit());
                 product.setRequired(pro.getRequired());
                 product.setInternal(pro.getInternal());
-                product.setVersion(pro.getVersion()+1);
+                product.setVersion(pro.getVersion() + 1);
                 product.setTechnologyId(technologyIds.get(i));
                 productList.add(product);
             }
@@ -231,32 +253,15 @@
                 Mbom mbom = new Mbom();
                 mbom.setUnit(mb.getUnit());
                 mbom.setName(mb.getName());
-                mbom.setSupplier(mb.getSupplier());
                 mbom.setQualityTraceability(mb.getQualityTraceability());
                 mbom.setSpecifications(mb.getSpecifications());
-                mbom.setVersion(mb.getVersion()+1);
+                mbom.setVersion(mb.getVersion() + 1);
                 mbom.setNum(mb.getNum());
                 mbom.setTechnologyId(technologyIds.get(i));
                 mbomList.add(mbom);
             }
         }
         mbomService.saveBatch(mbomList);
-        /*鏂板鏍囧噯BOM-->鐢熶骇宸ヨ壓(鎵归噺娣诲姞)*/
-        List<Technique> techniqueList = new ArrayList<>();
-        for (int i = 0; i < technologyIds.size(); i++) {
-            List<Technique> techniques = techniqueMapper.selectList(Wrappers.<Technique>query().eq("technology_id", techTemIds.get(i)));
-            for (Technique teque : techniques) {
-                Technique technique = new Technique();
-                technique.setTechnologyId(technologyIds.get(i));
-                technique.setDevice(teque.getDevice());
-                technique.setProductFather(teque.getProductFather());
-                technique.setProduct(teque.getProduct());
-                technique.setUnit(teque.getUnit());
-                technique.setVersion(teque.getVersion()+1);
-                techniqueList.add(technique);
-            }
-        }
-        techniqueService.saveBatch(techniqueList);
         return technologyList.get(0).getVersion();
     }
 

--
Gitblit v1.9.3