lxw
2022-08-13 5d0f425324ee72e50f0b7ad5200ccebab32e7099
src/main/java/com/whyc/service/WorksheetLinkService.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.config.EnumWorksheetType;
import com.whyc.mapper.ProductBomApprovingMapper;
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.pojo.*;
@@ -14,10 +15,7 @@
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@@ -45,12 +43,22 @@
    @Autowired
    private ComponentProductApprovingService cpAService;
    @Autowired
    private ComponentApprovingService cAService;
    @Autowired
    private ComponentService cService;
    @Transactional
    public void audit(WorksheetLink link) {
        link.setDealTime(new Date());
        //更新节点信息
        linkMapper.updateById(link);
        if(link.getLinkStatus() == 2){ //驳回
            //查看是否为散装件审批,是则需要更新散装件审批表中的状态为完结
            if(mainService.getInfoById(link.getMainId()).getType().equals(EnumWorksheetType.Component.getType())){
                cAService.endStatus(link.getMainId());
            }
            //项目经理驳回,驳回即终止
            mainService.updateEndStatusById(link.getMainId(),"经理驳回,驳回原因:"+link.getDealReason(),0);
            //项目经理驳回前,还曾经过总经理,则需要增加总经理驳回原因
@@ -83,7 +91,9 @@
    }
    @Transactional
    public void approve(WorksheetLink link, Integer componentProductFlag) {
    public void approve(WorksheetLink link) {
        //根据节点,查询主表类型
        Integer type = mainService.getInfoById(link.getMainId()).getType();
        link.setDealTime(new Date());
        //更新节点信息
        linkMapper.updateById(link);
@@ -110,7 +120,7 @@
        }else {
            //审批通过,更新主表状态
            mainService.updateEndStatusById(link.getMainId(), "完结", 5);
            if (componentProductFlag == null) { //产品审批
            if (type.intValue() == EnumWorksheetType.ProductBom.getType()) { //产品审批
                //将产品文件复制至正式路径
                QueryWrapper<ProductBomApproving> query = Wrappers.query();
                query.eq("main_id", link.getMainId());
@@ -184,7 +194,7 @@
                }
                //更新散件表当前版本,更新eVersion
                List<ComponentProductHistory> cphList = cphService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion);
                cphService.updateVersionBatch(cphList);
                if(cphList.size()!=0){cphService.updateVersionBatch(cphList);}
                /*更新到product_bom*/
                //查询新的版本
@@ -232,7 +242,30 @@
                });
                //更新正式bom的对应url
                bomService.updateUrl(fileBomApprovingList);
            }else{ //更新散装件-产品关系
            }
            else if(type.intValue() == EnumWorksheetType.Component.getType()){ //散装件
                //将散装件从审批表中转移到正式表
                List<Component> componentList = new LinkedList<>();
                List<ComponentApproving> approvingList = cAService.getListByMainId(link.getMainId());
                approvingList.forEach(approve->{
                    Component component = new Component();
                    component.setCategory(approve.getCategory());
                    component.setSubCode(approve.getSubCode());
                    component.setSubName(approve.getSubName());
                    component.setSubModel(approve.getSubModel());
                    component.setUnit(approve.getUnit());
                    component.setQuantity(approve.getQuantity());
                    component.setProducer(approve.getProducer());
                    component.setNotes(approve.getNotes());
                    component.setCreateDate(new Date());
                    component.setStatus(1);
                    componentList.add(component);
                });
                cService.insertBatch(componentList);
                //更新散装件审批子表中type为完结
                cAService.endStatus(link.getMainId());
            }
            else if(type.intValue() == EnumWorksheetType.ComponentProduct.getType()){ //更新散装件-产品关系
                //查找到对应的散装件-产品关系数据
                List<ComponentProductApproving> cpAList = cpAService.getListByMainId(link.getMainId());
                //查询部件最新的版本号
@@ -278,11 +311,21 @@
                //处理思路:先解除关联,再替换,再关联
                if(removedList.size()!=0){
                    removedList.forEach(remove -> {
                        nowHistoryList.forEach(nowHistory -> {
                        /*nowHistoryList.forEach(nowHistory -> {
                            if (remove.getComponentId().intValue() == nowHistory.getComponentId()) {
                                nowHistoryList.remove(nowHistory);
                            }
                        });
                        });*/
                        Iterator<ComponentProductHistory> iterator = nowHistoryList.iterator();
                        while (iterator.hasNext()){
                            ComponentProductHistory next = iterator.next();
                            if(remove.getComponentId().intValue() == next.getComponentId()
                                &&remove.getSubName().equals(next.getSubName())
                            ){
                                iterator.remove();
                                break;
                            }
                        }
                    });
                }
@@ -290,12 +333,24 @@
                if(replacedList.size()!=0){
                    replacedList.forEach(replace -> {
                        //当前生效的散装件-产品列表
                        nowHistoryList.forEach(nowHistory -> {
                        /*nowHistoryList.forEach(nowHistory -> {
                            if (replace.getComponentId().intValue() == nowHistory.getComponentId()) {
                                nowHistoryList.remove(nowHistory);
                            }
                        });
                        //下个版本新增的散装件-产品列表
                        });*/
                        if(nowHistoryList.size()!=0) {
                            Iterator<ComponentProductHistory> iterator = nowHistoryList.iterator();
                            while (iterator.hasNext()) {
                                ComponentProductHistory next = iterator.next();
                                if (replace.getComponentId().intValue() == next.getComponentId()
                                        && replace.getSubName().equals(next.getSubName())
                                ) {
                                    iterator.remove();
                                    break;
                                }
                            }
                        }
                        //下个版本新增替换的散装件-产品列表
                        ComponentProductHistory newHistory = new ComponentProductHistory();
                        newHistory.setComponentId(replace.getComponentId());
                        newHistory.setParentModel(replace.getParentModel());
@@ -306,25 +361,64 @@
                        newHistory.setEVersion(nextVersion);
                        newHistoryList.add(newHistory);
                        //当前生效的bom列表
                        nowBomHistoryList.forEach(nowBomHistory->{
                        /*nowBomHistoryList.forEach(nowBomHistory->{
                            if(replace.getSubName().equals(nowBomHistory.getSubName())){
                                nowBomHistoryList.remove(nowBomHistory);
                            }
                        });
                        });*/
                        Iterator<ProductBomHistory> iterator1 = nowBomHistoryList.iterator();
                        while (iterator1.hasNext()){
                            if(replace.getSubName().equals(iterator1.next().getSubName())){
                                iterator1.remove();
                                break;
                            }
                        }
                    });
                }
                //处理关联
                addedList.forEach(add -> {
                    nowHistoryList.forEach(nowHistory -> {
                    /*nowHistoryList.forEach(nowHistory -> {
                        if (add.getComponentId().intValue() == nowHistory.getComponentId()) {
                            nowHistoryList.remove(nowHistory);
                        }
                    });
                    });*/
                    if(nowHistoryList.size()!=0) {
                        Iterator<ComponentProductHistory> iterator = nowHistoryList.iterator();
                        while (iterator.hasNext()) {
                            ComponentProductHistory next = iterator.next();
                            if (add.getComponentId().intValue() == next.getComponentId()
                                    && add.getSubName().equals(next.getSubName())
                            ) {
                                iterator.remove();
                                break;
                            }
                        }
                    }
                    ComponentProductHistory newHistory = new ComponentProductHistory();
                    newHistory.setComponentId(add.getComponentId());
                    newHistory.setParentModel(add.getParentModel());
                    newHistory.setSubName(add.getSubName());
                    newHistory.setCreateTime(new Date());
                    newHistory.setLinkType(1);
                    newHistory.setSVersion(nextVersion);
                    newHistory.setEVersion(nextVersion);
                    newHistoryList.add(newHistory);
                });
                //处理完成,进行表单数据更新,分为nowHistoryList,newHistoryList,nowBomHistoryList
                //nowHistoryList.forEach(nowHis->nowHis.setEVersion(nextVersion));
                if(newHistoryList.size()!=0){newHistoryList.forEach(newHis->{newHis.setEVersion(nextVersion);newHis.setSVersion(nextVersion);});}
                if(nowBomHistoryList.size()!=0){nowBomHistoryList.forEach(nowBomHis->nowBomHis.setEVersion(nextVersion));}
                if(nowHistoryList.size()!=0){cphService.updateVersionBatch(nowHistoryList);}
                if(newHistoryList.size()!=0){cphService.insertBatch(newHistoryList);}
                if(nowBomHistoryList.size()!=0){historyService.updateVersionBatch(nowBomHistoryList);}
                //更新ProductBom
                List<ProductBomHistory> newBomList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), nextVersion);
                bomService.updateNewBom(newBomList);
            }
        }
    }