whycxzp
2022-07-29 51a54c31b1fb937d23e1b1ddd0777076da009fe5
src/main/java/com/whyc/service/WorksheetLinkService.java
@@ -5,11 +5,15 @@
import com.whyc.mapper.ProductBomApprovingMapper;
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.pojo.*;
import com.whyc.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -39,20 +43,8 @@
        //更新节点信息
        linkMapper.updateById(link);
        if(link.getLinkStatus() == 2){ //驳回
            //驳回到员工进行处理
            //查询工单的员工
            Long createUserId = mainService.getInfoById(link.getMainId()).getCreateUserId();
            WorksheetLink link2 = new WorksheetLink();
            link2.setMainId(link.getMainId());
            link2.setParentId(link.getId());
            link2.setDealUserId(createUserId);
            link2.setDealType(0);
            link2.setDealDesc("工单被经理驳回,驳回信息:"+link.getDealReason());
            link2.setLinkStatus(0);
            link2.setEnableArchive(0);
            linkMapper.insert(link2);
            //更新主表状态
            mainService.updateStatusById(link.getMainId(),0);
            //项目经理驳回,驳回即终止
            mainService.updateEndStatusById(link.getMainId(),"经理驳回",0);
        }else{
            //进入下一节点,总经理审批
            WorksheetLink link2 = new WorksheetLink();
@@ -63,6 +55,7 @@
            link2.setDealDesc("工单被经理审核通过,信息:"+link.getDealReason());
            link2.setLinkStatus(0);
            link2.setEnableArchive(1);
            link2.setRejectVersion(link.getRejectVersion());
            linkMapper.insert(link2);
            //更新主表状态
            mainService.updateStatusById(link.getMainId(),2);
@@ -75,20 +68,25 @@
        //更新节点信息
        linkMapper.updateById(link);
        if(link.getLinkStatus() == 2){ //驳回
            //驳回到员工进行处理
            //查询工单的员工
            Long createUserId = mainService.getInfoById(link.getMainId()).getCreateUserId();
            WorksheetLink link2 = new WorksheetLink();
            link2.setMainId(link.getMainId());
            link2.setParentId(link.getId());
            link2.setDealUserId(createUserId);
            link2.setDealType(0);
            link2.setDealDesc("工单被经理驳回,驳回信息:"+link.getDealReason());
            link2.setLinkStatus(0);
            link2.setEnableArchive(0);
            linkMapper.insert(link2);
            //更新主表状态
            mainService.updateStatusById(link.getMainId(),0);
            if(link.getParentId()!=0) {
                //查询对应的项目经理
                Long createUserId = linkMapper.selectById(link.getParentId()).getDealUserId();
                WorksheetLink link2 = new WorksheetLink();
                link2.setMainId(link.getMainId());
                link2.setParentId(link.getId());
                link2.setDealUserId(createUserId);
                link2.setDealType(0);
                link2.setDealDesc("工单被总经理驳回,驳回信息:" + link.getDealReason());
                link2.setLinkStatus(0);
                link2.setEnableArchive(0);
                link2.setRejectVersion(link.getRejectVersion());
                linkMapper.insert(link2);
                //更新主表状态
                mainService.updateStatusById(link.getMainId(), 1);
            }else{
                //说明是项目经理提交的,驳回即终止
                mainService.updateEndStatusById(link.getMainId(),"总经理驳回",0);
            }
        }else{
            //审批通过,更新主表状态
            mainService.updateEndStatusById(link.getMainId(),"完结",5);
@@ -102,9 +100,10 @@
            //删除? TODO 需要约定逻辑
            //查询部件最新的版本号
            Integer currentVersion = bomService.getProduct(approvingList.get(0).getParentModel()).getVersion();
            if(currentVersion==null){
                currentVersion = 0;
            ProductBom product = bomService.getProduct(approvingList.get(0).getParentModel());
            int currentVersion = -1;
            if(product!=null){
                currentVersion = product.getVersion();
            }
            Integer nextVersion = currentVersion+1;
            //更新到product_bom_history,增加进去的需要sVersion和eVersion一致
@@ -143,8 +142,7 @@
                his.setThickness(approvingBom.getThickness());
                his.setType(approvingBom.getType());
                his.setUnit(approvingBom.getUnit());
                his.setUpdateDate(approvingBom.getUpdateDate());
                his.setUpUser(approvingBom.getUpUser());
                his.setUpUserId(approvingBom.getUpUserId());
                newHistoryList.add(his);
            });
@@ -158,8 +156,9 @@
                    .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName()))
                    .collect(Collectors.toList());
            newVersionCurrentHistoryList.forEach(history->{history.setEVersion(nextVersion);});
            historyService.updateVersionBatch(newVersionCurrentHistoryList);
            if(newVersionCurrentHistoryList.size()!=0) {
                historyService.updateVersionBatch(newVersionCurrentHistoryList);
            }
            /*更新到product_bom*/
            //查询新的版本
            List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion);
@@ -169,7 +168,43 @@
            FileUtil.copyDir()*/
            //将产品bom表的url修正,更新到正式表
            /*将产品bom表的url修正,更新到正式表*/
            //审批完后,将本次的bom带url的全部复制到正式文件夹中
            List<ProductBomApproving> fileBomApprovingList = approvingList.stream()
                    .filter(productBomApproving ->
                            productBomApproving.getPictureUrl() != null || productBomApproving.getDwgUrl() != null
                    ).collect(Collectors.toList());
            String projectDir = CommonUtil.getProjectDir();
            fileBomApprovingList.forEach(fileBom->{
                try {
                    String pictureUrl = fileBom.getPictureUrl();
                    String dwgUrl = fileBom.getDwgUrl();
                    if(pictureUrl !=null){
                        String newPictureUrl ="doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel()+File.separator+ pictureUrl.substring(pictureUrl.lastIndexOf(File.separator)+1);
                        File newPictureDir = new File(projectDir + File.separator + "doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel());
                        if(!newPictureDir.exists()){
                            newPictureDir.mkdirs();
                        }
                        FileCopyUtils.copy(new File(projectDir+File.separator+ pictureUrl),
                                new File(projectDir+File.separator+newPictureUrl));
                        fileBom.setPictureUrl(newPictureUrl);
                    }
                    if(dwgUrl !=null){
                        String newDwgUrl ="doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel()+File.separator+ dwgUrl.substring(dwgUrl.lastIndexOf(File.separator)+1);
                        File newDwgDir = new File(projectDir + File.separator + "doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel());
                        if(!newDwgDir.exists()){
                            newDwgDir.mkdirs();
                        }
                        FileCopyUtils.copy(new File(projectDir+File.separator+ dwgUrl),
                                new File(projectDir + File.separator + newDwgUrl));
                        fileBom.setDwgUrl(newDwgUrl);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
            //更新正式bom的对应url
            bomService.updateUrl(fileBomApprovingList);
        }
    }