zss
2023-09-21 2dbc49184bd74845c8da694c20d6fd03d7ac87e0
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,18 +106,16 @@
        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));
        /**
         * 根据选择的情况,判断是拉取基础数据的数据,还是某一个产品下某一个型号的数据
         */
        //如果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());
@@ -157,7 +152,6 @@
                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));
@@ -165,30 +159,58 @@
            }
        }
        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);
            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(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);
        }
        techniqueService.saveBatch(techniqueList);
            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 "添加物料【" + materialDto.getName() + "】成功";
    }
    //添加同一个型号工艺路线,技术指标,物料清单,生产工艺的版本
    //添加同一个型号工艺路线,技术指标,物料清单的版本
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer addVersion(Integer specificationsId, Integer version) {
@@ -231,7 +253,6 @@
                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);
@@ -241,22 +262,6 @@
            }
        }
        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();
    }