whycxzp
2022-08-09 57f2d2e696c5d46bae8149f824baefd73f4b5f46
更新散装件审批
7个文件已修改
381 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/WorksheetLinkController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/ComponentProductHistoryMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/ComponentProductHistory.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ComponentProductApprovingService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ComponentProductHistoryService.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/WorksheetLinkService.java 333 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ComponentProductHistoryMapper.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/WorksheetLinkController.java
@@ -35,8 +35,8 @@
    @PostMapping("approve")
    @ApiOperation(value = "总经理审批",notes = "传参:int id,int linkStatus,String dealReason,int mainId,int rejectVersion;" +
            "linkStatus:1通过,2驳回,驳回到员工,通知经理;dealReason:审核意见")
    public Response approve(@RequestBody WorksheetLink link){
        service.approve(link);
    public Response approve(@RequestBody WorksheetLink link,Integer componentProductFlag){
        service.approve(link,componentProductFlag);
        return new Response().setII(1,"审批完成");
    }
src/main/java/com/whyc/mapper/ComponentProductHistoryMapper.java
@@ -2,5 +2,9 @@
import com.whyc.pojo.ComponentProductHistory;
import java.util.List;
public interface ComponentProductHistoryMapper extends CustomMapper<ComponentProductHistory>{
    void updateVersionBatch(List<ComponentProductHistory> cphList);
}
src/main/java/com/whyc/pojo/ComponentProductHistory.java
@@ -87,19 +87,4 @@
        this.linkType = linkType;
    }
    public Integer getsVersion() {
        return sVersion;
    }
    public void setsVersion(Integer sVersion) {
        this.sVersion = sVersion;
    }
    public Integer geteVersion() {
        return eVersion;
    }
    public void seteVersion(Integer eVersion) {
        this.eVersion = eVersion;
    }
}
src/main/java/com/whyc/service/ComponentProductApprovingService.java
@@ -1,5 +1,7 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.mapper.ComponentProductApprovingMapper;
import com.whyc.pojo.ComponentProductApproving;
import org.springframework.stereotype.Service;
@@ -16,4 +18,10 @@
    public void insert(List<ComponentProductApproving> approvingList) {
        mapper.insertBatchSomeColumn(approvingList);
    }
    public List<ComponentProductApproving> getListByMainId(Integer mainId) {
        QueryWrapper<ComponentProductApproving> query = Wrappers.query();
        query.eq("main_id",mainId);
        return mapper.selectList(query);
    }
}
src/main/java/com/whyc/service/ComponentProductHistoryService.java
@@ -1,5 +1,7 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.dto.Response;
import com.whyc.mapper.ComponentProductHistoryMapper;
import com.whyc.pojo.ComponentProductHistory;
@@ -17,4 +19,14 @@
        int bl=mapper.insertBatchSomeColumn(list);
        return new Response().setII(1,true,bl,bl>0?"添加关联成功":"添加关联失败");
    }
    public List<ComponentProductHistory> getListByParentModel(String parentModel, int currentVersion) {
        QueryWrapper<ComponentProductHistory> query = Wrappers.query();
        query.eq("parent_model",parentModel).le("s_version",currentVersion).ge("e_version",currentVersion);
        return mapper.selectList(query);
    }
    public void updateVersionBatch(List<ComponentProductHistory> cphList) {
        mapper.updateVersionBatch(cphList);
    }
}
src/main/java/com/whyc/service/WorksheetLinkService.java
@@ -17,6 +17,8 @@
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@Service
@@ -36,6 +38,12 @@
    @Autowired
    private ProductBomHistoryService historyService;
    @Autowired
    private ComponentProductHistoryService cphService;
    @Autowired
    private ComponentProductApprovingService cpAService;
    @Transactional
    public void audit(WorksheetLink link) {
@@ -75,7 +83,7 @@
    }
    @Transactional
    public void approve(WorksheetLink link) {
    public void approve(WorksheetLink link, Integer componentProductFlag) {
        link.setDealTime(new Date());
        //更新节点信息
        linkMapper.updateById(link);
@@ -99,124 +107,225 @@
                //说明是项目经理提交的,驳回即终止
                mainService.updateEndStatusById(link.getMainId(),"总经理驳回,驳回原因:"+link.getDealReason(),0);
            }
        }else{
        }else {
            //审批通过,更新主表状态
            mainService.updateEndStatusById(link.getMainId(),"完结",5);
            //将产品文件复制至正式路径
            QueryWrapper<ProductBomApproving> query = Wrappers.query();
            query.eq("main_id",link.getMainId());
            List<ProductBomApproving> approvingList = approvingMapper.selectList(query);
            mainService.updateEndStatusById(link.getMainId(), "完结", 5);
            if (componentProductFlag == null) { //产品审批
                //将产品文件复制至正式路径
                QueryWrapper<ProductBomApproving> query = Wrappers.query();
                query.eq("main_id", link.getMainId());
                List<ProductBomApproving> approvingList = approvingMapper.selectList(query);
            //增加->增加部件(增加记录,同时所有eVersion+1)
            //修改->修改部件图纸,修改部件非图纸(增加记录,同时修改非原部件的所有eVersion+1)
            //删除? TODO 需要约定逻辑
                //增加->增加部件(增加记录,同时所有eVersion+1)
                //修改->修改部件图纸,修改部件非图纸(增加记录,同时修改非原部件的所有eVersion+1)
                //删除? TODO 需要约定逻辑
            //查询部件最新的版本号
            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一致
            //增加所有部件,排查出相关的原部件,非也是更新
            List<ProductBomHistory> currentHistoryList = historyService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion);
            List<String> currentSubNameList = currentHistoryList.stream().map(ProductBomHistory::getSubName).collect(Collectors.toList());
            List<ProductBomHistory> newHistoryList = new LinkedList<>();
            approvingList.forEach(approvingBom->{
                if(currentSubNameList.contains(approvingBom.getSubName())){
                    approvingBom.setVersion(1);
                }else{
                    approvingBom.setVersion(0);
                //查询部件最新的版本号
                ProductBom product = bomService.getProduct(approvingList.get(0).getParentModel());
                int currentVersion = -1;
                if (product != null) {
                    currentVersion = product.getVersion();
                }
                //转化为productBomHistory
                ProductBomHistory his = new ProductBomHistory();
                his.setCategory(approvingBom.getCategory());
                his.setCreateDate(approvingBom.getCreateDate());
                his.setDwgUrl(approvingBom.getDwgUrl());
                his.setEVersion(nextVersion);
                his.setFileUrl(approvingBom.getFileUrl());
                his.setMaterial(approvingBom.getMaterial());
                his.setNotes(approvingBom.getNotes());
                his.setParentCode(approvingBom.getParentCode());
                his.setParentModel(approvingBom.getParentModel());
                his.setParentName(approvingBom.getParentName());
                his.setParentVersion(approvingBom.getParentVersion());
                his.setPictureUrl(approvingBom.getPictureUrl());
                his.setProducer(approvingBom.getProducer());
                his.setQuantity(approvingBom.getQuantity());
                his.setSubCode(approvingBom.getSubCode());
                his.setSubModel(approvingBom.getSubModel());
                his.setSubName(approvingBom.getSubName());
                his.setSurfaceDetail(approvingBom.getSurfaceDetail());
                his.setSVersion(nextVersion);
                his.setThickness(approvingBom.getThickness());
                his.setType(approvingBom.getType());
                his.setUnit(approvingBom.getUnit());
                his.setUpUserId(approvingBom.getUpUserId());
                Integer nextVersion = currentVersion + 1;
                //更新到product_bom_history,增加进去的需要sVersion和eVersion一致
                //增加所有部件,排查出相关的原部件,非也是更新
                List<ProductBomHistory> currentHistoryList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), currentVersion);
                List<String> currentSubNameList = currentHistoryList.stream().map(ProductBomHistory::getSubName).collect(Collectors.toList());
                newHistoryList.add(his);
            });
            //本次审核中子件被修改的子件集合
            List<String> approvingUpdateSubNameList = approvingList.stream().filter(approvingBom -> approvingBom.getVersion() == 1).map(ProductBomApproving::getSubName).collect(Collectors.toList());
            historyService.addBatch(newHistoryList);
            /*更新产品的当前版本,更新到最新的版本*/
            //当前版本的所有bom的eVersion更新,排除被修改的子件
            List<ProductBomHistory> newVersionCurrentHistoryList = currentHistoryList.stream()
                    .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName()))
                    .collect(Collectors.toList());
            newVersionCurrentHistoryList.forEach(history->{history.setEVersion(nextVersion);});
            if(newVersionCurrentHistoryList.size()!=0) {
                historyService.updateVersionBatch(newVersionCurrentHistoryList);
            }
            /*更新到product_bom*/
            //查询新的版本
            List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion);
            bomService.updateNewBom(newBomList);
            /*String projectDir = CommonUtil.getProjectDir();
            FileUtil.copyDir()*/
            /*将产品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);
                List<ProductBomHistory> newHistoryList = new LinkedList<>();
                approvingList.forEach(approvingBom -> {
                    if (currentSubNameList.contains(approvingBom.getSubName())) {
                        approvingBom.setVersion(1);
                    } else {
                        approvingBom.setVersion(0);
                    }
                    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();
                    //转化为productBomHistory
                    ProductBomHistory his = new ProductBomHistory();
                    his.setCategory(approvingBom.getCategory());
                    his.setCreateDate(approvingBom.getCreateDate());
                    his.setDwgUrl(approvingBom.getDwgUrl());
                    his.setEVersion(nextVersion);
                    his.setFileUrl(approvingBom.getFileUrl());
                    his.setMaterial(approvingBom.getMaterial());
                    his.setNotes(approvingBom.getNotes());
                    his.setParentCode(approvingBom.getParentCode());
                    his.setParentModel(approvingBom.getParentModel());
                    his.setParentName(approvingBom.getParentName());
                    his.setParentVersion(approvingBom.getParentVersion());
                    his.setPictureUrl(approvingBom.getPictureUrl());
                    his.setProducer(approvingBom.getProducer());
                    his.setQuantity(approvingBom.getQuantity());
                    his.setSubCode(approvingBom.getSubCode());
                    his.setSubModel(approvingBom.getSubModel());
                    his.setSubName(approvingBom.getSubName());
                    his.setSurfaceDetail(approvingBom.getSurfaceDetail());
                    his.setSVersion(nextVersion);
                    his.setThickness(approvingBom.getThickness());
                    his.setType(approvingBom.getType());
                    his.setUnit(approvingBom.getUnit());
                    his.setUpUserId(approvingBom.getUpUserId());
                    newHistoryList.add(his);
                });
                //本次审核中子件被修改的子件集合
                List<String> approvingUpdateSubNameList = approvingList.stream().filter(approvingBom -> approvingBom.getVersion() == 1).map(ProductBomApproving::getSubName).collect(Collectors.toList());
                historyService.addBatch(newHistoryList);
                /*更新产品的当前版本,更新到最新的版本*/
                //当前版本的所有bom的eVersion更新,排除被修改的子件
                List<ProductBomHistory> newVersionCurrentHistoryList = currentHistoryList.stream()
                        .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName()))
                        .collect(Collectors.toList());
                newVersionCurrentHistoryList.forEach(history -> {
                    history.setEVersion(nextVersion);
                });
                if (newVersionCurrentHistoryList.size() != 0) {
                    historyService.updateVersionBatch(newVersionCurrentHistoryList);
                }
            });
            //更新正式bom的对应url
            bomService.updateUrl(fileBomApprovingList);
                //更新散件表当前版本,更新eVersion
                List<ComponentProductHistory> cphList = cphService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion);
                cphService.updateVersionBatch(cphList);
                /*更新到product_bom*/
                //查询新的版本
                List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion);
                bomService.updateNewBom(newBomList);
                /*String projectDir = CommonUtil.getProjectDir();
                FileUtil.copyDir()*/
                /*将产品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);
            }else{ //更新散装件-产品关系
                //查找到对应的散装件-产品关系数据
                List<ComponentProductApproving> cpAList = cpAService.getListByMainId(link.getMainId());
                //查询部件最新的版本号
                ProductBom product = bomService.getProduct(cpAList.get(0).getParentModel());
                int currentVersion = -1;
                if (product != null) {
                    currentVersion = product.getVersion();
                }
                Integer nextVersion = currentVersion + 1;
                //关联/接触关联,更新版本
                //替换,更新版本,同时bom表历史中对应的subName 版本号不变(排除更新)
                Map<Integer, List<ComponentProductApproving>> linkTypeMap = cpAList.stream().collect(Collectors.groupingBy(ComponentProductApproving::getLinkType));
                List<ComponentProductApproving> addedList = new LinkedList<>();
                List<ComponentProductApproving> replacedList = new LinkedList<>();
                List<ComponentProductApproving> removedList = new LinkedList<>();
                linkTypeMap.forEach((linkType,list)->{
                    if(linkType == 1){
                        addedList.addAll(list);
                    }else if(linkType == 2){
                        replacedList.addAll(list);
                    }else{
                        removedList.addAll(list);
                    }
                });
                List<ComponentProductHistory> newHistoryList = new LinkedList<>();
                //查询最新版本生效的相关散装件
                List<ComponentProductHistory> nowHistoryList = cphService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion);
                //查询历史中最新版本生效的bom
                List<ProductBomHistory> nowBomHistoryList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion);
                /*
                对于关联的,判断当前版本中是否存在替换关系,存在,则直接下个版本插入关联;
                同时,其他当前版本的相关散装件-产品记录更新版本,排除存在的替换关系
                */
                /*
                对于替换的,判断当前版本中是否存在关联关系,存在,直接下个版本替换,记录插入;
                同时,当前版本的相关散装件-产品记录更新版本,排除存在的关联关系;
                同时,bom表更新到下个版本时,排除被替换件
                */
                //对于解除关联的,当前版本的相关散装件-产品记录更新版本,排除解除关联的记录
                //处理思路:先解除关联,再替换,再关联
                if(removedList.size()!=0){
                    removedList.forEach(remove -> {
                        nowHistoryList.forEach(nowHistory -> {
                            if (remove.getComponentId().intValue() == nowHistory.getComponentId()) {
                                nowHistoryList.remove(nowHistory);
                            }
                        });
                    });
                }
                //处理替换
                if(replacedList.size()!=0){
                    replacedList.forEach(replace -> {
                        //当前生效的散装件-产品列表
                        nowHistoryList.forEach(nowHistory -> {
                            if (replace.getComponentId().intValue() == nowHistory.getComponentId()) {
                                nowHistoryList.remove(nowHistory);
                            }
                        });
                        //下个版本新增的散装件-产品列表
                        ComponentProductHistory newHistory = new ComponentProductHistory();
                        newHistory.setComponentId(replace.getComponentId());
                        newHistory.setParentModel(replace.getParentModel());
                        newHistory.setSubName(replace.getSubName());
                        newHistory.setCreateTime(new Date());
                        newHistory.setLinkType(2);
                        newHistory.setSVersion(nextVersion);
                        newHistory.setEVersion(nextVersion);
                        newHistoryList.add(newHistory);
                        //当前生效的bom列表
                        nowBomHistoryList.forEach(nowBomHistory->{
                            if(replace.getSubName().equals(nowBomHistory.getSubName())){
                                nowBomHistoryList.remove(nowBomHistory);
                            }
                        });
                    });
                }
                //处理关联
                addedList.forEach(add -> {
                    nowHistoryList.forEach(nowHistory -> {
                        if (add.getComponentId().intValue() == nowHistory.getComponentId()) {
                            nowHistoryList.remove(nowHistory);
                        }
                    });
                });
                //处理完成,进行表单数据更新,分为nowHistoryList,newHistoryList,nowBomHistoryList
            }
        }
    }
src/main/resources/mapper/ComponentProductHistoryMapper.xml
@@ -3,4 +3,9 @@
<mapper namespace="com.whyc.mapper.ComponentProductHistoryMapper">
    <update id="updateVersionBatch">
        <foreach collection="list" item="his" separator=";">
            update db_doc.tb_component_product_history set e_version = e_version+1 where id = #{his.id}
        </foreach>
    </update>
</mapper>