zss
2023-09-21 2dbc49184bd74845c8da694c20d6fd03d7ac87e0
standard-server/src/main/java/com/yuanchu/mom/service/impl/SpecificationsServiceImpl.java
@@ -1,5 +1,6 @@
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;
@@ -9,6 +10,7 @@
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;
@@ -52,108 +54,134 @@
    MbomModelMapper mbomModelMapper;
    @Resource
    TechniqueService techniqueService;
    ProductMapper productMapper;
    @Resource
    TechniqueModelMapper techniqueModelMapper;
    MbomMapper mbomMapper;
    @Resource
    DeviceMapper deviceMapper;
    TechnologyMapper technologyMapper;
    //(4级)新增-->型号
    @Override
    public void addSpecifications(SpecificationsDto specificationsDto) {
    @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-->技术指标(批量添加)*/
            //新增的工艺路线id集合
            List<Integer> technologyIds = technologyList.stream().map(Technology::getId).collect(Collectors.toList());
            //基础数据中工艺路线id集合
            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-->工艺路线(批量添加)*/
        //根据标准id查询物料大类
        Material material = materialMapper.selFath(specificationsDto.getId());
        List<TechnologyTemplate> technologyTemplateList = technologyTemplateMapper.selectList(Wrappers.<TechnologyTemplate>query().eq("type", material.getFather()));
        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;
        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-->技术指标(批量添加)*/
        //新增的工艺路线id集合
        List<Integer> technologyIds = technologyList.stream().map(Technology::getId).collect(Collectors.toList());
        //基础数据中工艺路线id集合
        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);
    }
    /**
     * 检验模块-->QMS管理-->成品检验-->新增(需要规格型号的Id与名称)
     */
    @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;
        return "添加型号【" + specificationsDto.getSpecifications() + "】成功!";
    }
}