whycxzp
2022-08-25 e8200d6698814ecdf28a319804000b999e63d882
物料-产品审批
10个文件已修改
328 ■■■■■ 已修改文件
src/main/java/com/whyc/dto/WorksheetMainDTO.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/MaterialProductHistoryMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/MaterialProductApproving.java 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/MaterialProductHistory.java 47 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/MaterialProductHistoryService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductHistoryService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductService.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/WorksheetLinkService.java 194 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/WorksheetMainService.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/MaterialProductHistoryMapper.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/WorksheetMainDTO.java
@@ -12,7 +12,7 @@
    private WorksheetMain main;
    private List<MaterialProductApproving> addedList;
    private List<MaterialProductApproving> replacedList;
    //private List<MaterialProductApproving> replacedList;
    private List<MaterialProductApproving> removedList;
    public WorksheetMain getMain() {
@@ -31,13 +31,13 @@
        this.addedList = addedList;
    }
    public List<MaterialProductApproving> getReplacedList() {
        return replacedList;
    }
    //public List<MaterialProductApproving> getReplacedList() {
    //    return replacedList;
    //}
    public void setReplacedList(List<MaterialProductApproving> replacedList) {
        this.replacedList = replacedList;
    }
    //public void setReplacedList(List<MaterialProductApproving> replacedList) {
    //    this.replacedList = replacedList;
    //}
    public List<MaterialProductApproving> getRemovedList() {
        return removedList;
src/main/java/com/whyc/mapper/MaterialProductHistoryMapper.java
@@ -1,5 +1,6 @@
package com.whyc.mapper;
import com.whyc.pojo.MaterialProductApproving;
import com.whyc.pojo.MaterialProductHistory;
import java.util.List;
@@ -9,4 +10,6 @@
    List<MaterialProductHistory> getLatestExistListByMaterialId(Integer MaterialId);
    void updateVersionSubtractBatch(List<MaterialProductApproving> removedList);
}
src/main/java/com/whyc/pojo/MaterialProductApproving.java
@@ -10,10 +10,14 @@
public class MaterialProductApproving {
    private Integer id;
    @ApiModelProperty("物料id")
    @ApiModelProperty("临时替代物料id")
    private Integer materialId;
    @ApiModelProperty("产品id")
    private String productId;
    //@ApiModelProperty("产品id")
    //private Integer productId;
    @ApiModelProperty("母料编码")
    private String parentCode;
    @ApiModelProperty("定制表单号")
    private String customCode;
    @ApiModelProperty("子件编码")
    private String subCode;
    @ApiModelProperty("子件数量")
@@ -22,6 +26,8 @@
    private Integer linkType;
    @ApiModelProperty("主表id")
    private Integer mainId;
    @ApiModelProperty("版本号")
    private Integer version;
    @TableField(exist = false)
    private Material material;
@@ -42,12 +48,20 @@
        this.materialId = materialId;
    }
    public String getProductId() {
        return productId;
    public String getParentCode() {
        return parentCode;
    }
    public void setProductId(String productId) {
        this.productId = productId;
    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }
    public String getCustomCode() {
        return customCode;
    }
    public void setCustomCode(String customCode) {
        this.customCode = customCode;
    }
    public String getSubCode() {
@@ -89,4 +103,12 @@
    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }
    public Integer getVersion() {
        return version;
    }
    public void setVersion(Integer version) {
        this.version = version;
    }
}
src/main/java/com/whyc/pojo/MaterialProductHistory.java
@@ -11,10 +11,14 @@
public class MaterialProductHistory {
    private Integer id;
    @ApiModelProperty("物料id")
    @ApiModelProperty("临时替代物料id")
    private Integer materialId;
    @ApiModelProperty("产品id")
    private String productId;
    //@ApiModelProperty("产品id")
    //private String productId;
    @ApiModelProperty("母料编码")
    private String parentCode;
    @ApiModelProperty("定制表单号")
    private String customCode;
    @ApiModelProperty("子件编码")
    private String subCode;
    @ApiModelProperty("子件数量")
@@ -22,7 +26,10 @@
    private Date createTime;
    @ApiModelProperty("关联类型:1(关联)")
    private Integer linkType;
    private Integer version;
    @ApiModelProperty("起始版本号")
    private Integer sVersion;
    @ApiModelProperty("终止版本号")
    private Integer eVersion;
    public Integer getId() {
        return id;
@@ -40,12 +47,20 @@
        this.materialId = materialId;
    }
    public String getProductId() {
        return productId;
    public String getParentCode() {
        return parentCode;
    }
    public void setProductId(String productId) {
        this.productId = productId;
    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }
    public String getCustomCode() {
        return customCode;
    }
    public void setCustomCode(String customCode) {
        this.customCode = customCode;
    }
    public String getSubCode() {
@@ -56,12 +71,20 @@
        this.subCode = subCode;
    }
    public Integer getVersion() {
        return version;
    public Integer getSVersion() {
        return sVersion;
    }
    public void setVersion(Integer version) {
        this.version = version;
    public void setSVersion(Integer sVersion) {
        this.sVersion = sVersion;
    }
    public Integer getEVersion() {
        return eVersion;
    }
    public void setEVersion(Integer eVersion) {
        this.eVersion = eVersion;
    }
    public Date getCreateTime() {
src/main/java/com/whyc/service/MaterialProductHistoryService.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.dto.Response;
import com.whyc.mapper.MaterialProductHistoryMapper;
import com.whyc.pojo.MaterialProductApproving;
import com.whyc.pojo.MaterialProductHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -37,4 +38,13 @@
    public List<MaterialProductHistory> getLatestExistListByMaterialId(Integer MaterialId) {
        return mapper.getLatestExistListByMaterialId(MaterialId);
    }
    /**
     *  解除关联:
     *  终止版本-1即可
     * @param removedList 解除关联列表
     */
    public void updateVersionSubtractBatch(List<MaterialProductApproving> removedList) {
        mapper.updateVersionSubtractBatch(removedList);
    }
}
src/main/java/com/whyc/service/ProductHistoryService.java
@@ -48,4 +48,11 @@
                .eq("custom_code",customCode).eq("enabled",anotherStatus);
        mapper.update(null,update);
    }
    public ProductHistory getEnabledByParentCodeAndCustomCode(String parentCode, String customCode) {
        QueryWrapper<ProductHistory> query = Wrappers.query();
        query.eq("parent_code",parentCode).eq("custom_code",customCode).eq("enabled",1)
                .last(" limit 1");
        return mapper.selectOne(query);
    }
}
src/main/java/com/whyc/service/ProductService.java
@@ -46,6 +46,12 @@
        return mapper.selectOne(query);
    }
    public Product getVersion(Integer productId) {
        QueryWrapper<Product> query = Wrappers.query();
        query.eq("product_id",productId);
        return mapper.selectOne(query);
    }
    public int updateVersion(String parentCode, String customCode, Integer nextVersion) {
        UpdateWrapper<Product> update = Wrappers.update();
        update.set("version",nextVersion).eq("parent_code",parentCode).eq("custom_code",customCode);
src/main/java/com/whyc/service/WorksheetLinkService.java
@@ -47,7 +47,7 @@
    private ProductBomApprovingService pbaService;
    @Autowired
    private MaterialProductHistoryService cphService;
    private MaterialProductHistoryService mphService;
    @Autowired
    private MaterialProductApprovingService cpAService;
@@ -383,10 +383,10 @@
            }
            else if(type.intValue() == EnumWorksheetType.Material.getType()){ //物料
                List<MaterialApproving> approvingList = mAService.getListByMainId(link.getMainId());
                List<Material> MaterialList = new LinkedList<>();
                List<Material> materialList = new LinkedList<>();
                //区分是新增还是删除
                Integer MaterialId = approvingList.get(0).getMaterialId();
                if(MaterialId==null) { //新增
                Integer materialId = approvingList.get(0).getMaterialId();
                if(materialId==null) { //新增
                    //将物料从审批表中转移到正式表
                    approvingList.forEach(approve -> {
                        Material material = new Material();
@@ -400,12 +400,12 @@
                        material.setNotes(approve.getNotes());
                        material.setCreateDate(new Date());
                        material.setStatus(1);
                        MaterialList.add(material);
                        materialList.add(material);
                    });
                    mService.insertBatch(MaterialList);
                    mService.insertBatch(materialList);
                }else{ //删除
                    List<Integer> MaterialIdList = approvingList.stream().map(MaterialApproving::getMaterialId).collect(Collectors.toList());
                    mService.deleteBatch(MaterialIdList);
                    List<Integer> materialIdList = approvingList.stream().map(MaterialApproving::getMaterialId).collect(Collectors.toList());
                    mService.deleteBatch(materialIdList);
                }
                //更新物料审批子表中type为完结
                mAService.endStatus(link.getMainId());
@@ -413,170 +413,36 @@
            else if(type.intValue() == EnumWorksheetType.MaterialProduct.getType()){ //更新物料-产品关系
                //查找到对应的物料-产品关系数据
                List<MaterialProductApproving> cpAList = cpAService.getListByMainId(link.getMainId());
                //查询部件最新的版本号
                //lxw修改
                //ProductBom product = bomService.getProduct(cpAList.get(0).getParentModel());
                ProductBom product=new ProductBom();
                int currentVersion = -1;
                if (product != null) {
                    currentVersion = product.getVersion();
                }
                Integer nextVersion = currentVersion + 1;
                //关联/接触关联,更新版本
                //替换,更新版本,同时bom表历史中对应的subName 版本号不变(排除更新)
                //当前版本
                int version = cpAList.get(0).getVersion();
                //新增关联/移除关联
                Map<Integer, List<MaterialProductApproving>> linkTypeMap = cpAList.stream().collect(Collectors.groupingBy(MaterialProductApproving::getLinkType));
                List<MaterialProductApproving> addedList = new LinkedList<>();
                List<MaterialProductApproving> replacedList = new LinkedList<>();
                List<MaterialProductHistory> addedList = new LinkedList<>();
                List<MaterialProductApproving> removedList = new LinkedList<>();
                linkTypeMap.forEach((linkType,list)->{
                    if(linkType == 1){
                        addedList.addAll(list);
                    }else if(linkType == 2){
                        replacedList.addAll(list);
                        list.forEach(approving->{
                            MaterialProductHistory his = new MaterialProductHistory();
                            his.setParentCode(approving.getParentCode());
                            his.setCustomCode(approving.getCustomCode());
                            his.setSVersion(approving.getVersion());
                            his.setEVersion(approving.getVersion());
                            his.setSubCode(approving.getSubCode());
                            his.setQuantity(approving.getQuantity());
                            his.setMaterialId(approving.getMaterialId());
                            his.setLinkType(1);
                            his.setCreateTime(new Date());
                            addedList.add(his);
                        });
                    }else{
                        removedList.addAll(list);
                    }
                });
                List<MaterialProductHistory> newHistoryList = new LinkedList<>();
                //查询最新版本生效的相关物料
                //lxw注释
                //List<MaterialProductHistory> nowHistoryList = cphService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion);
                List<MaterialProductHistory> nowHistoryList =new ArrayList<>();
                //查询历史中最新版本生效的bom
                //List<ProductBomHistory> nowBomHistoryList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion);
                List<ProductBomHistory> nowBomHistoryList = new ArrayList<>();
                /*
                对于关联的,判断当前版本中是否存在替换关系,存在,则直接下个版本插入关联;
                同时,其他当前版本的相关物料-产品记录更新版本,排除存在的替换关系
                */
                /*
                对于替换的,判断当前版本中是否存在关联关系,存在,直接下个版本替换,记录插入;
                同时,当前版本的相关物料-产品记录更新版本,排除存在的关联关系;
                同时,bom表更新到下个版本时,排除被替换件
                */
                //对于解除关联的,当前版本的相关物料-产品记录更新版本,排除解除关联的记录
                //处理思路:先解除关联,再替换,再关联
                if(removedList.size()!=0){
                    removedList.forEach(remove -> {
                        /*nowHistoryList.forEach(nowHistory -> {
                            if (remove.getMaterialId().intValue() == nowHistory.getMaterialId()) {
                                nowHistoryList.remove(nowHistory);
                            }
                        });*/
                        Iterator<MaterialProductHistory> iterator = nowHistoryList.iterator();
                        while (iterator.hasNext()){
                            MaterialProductHistory next = iterator.next();
                            //lxw注释
                            /*if(remove.getMaterialId().intValue() == next.getMaterialId()
                                &&remove.getSubName().equals(next.getSubName())
                            ){
                                iterator.remove();
                                break;
                            }*/
                        }
                    });
                }
                //处理替换
                if(replacedList.size()!=0){
                    replacedList.forEach(replace -> {
                        //当前生效的物料-产品列表
                        /*nowHistoryList.forEach(nowHistory -> {
                            if (replace.getMaterialId().intValue() == nowHistory.getMaterialId()) {
                                nowHistoryList.remove(nowHistory);
                            }
                        });*/
                        if(nowHistoryList.size()!=0) {
                            Iterator<MaterialProductHistory> iterator = nowHistoryList.iterator();
                            while (iterator.hasNext()) {
                                MaterialProductHistory next = iterator.next();
                                //lxw注释
                                /*if (replace.getMaterialId().intValue() == next.getMaterialId()
                                        && replace.getSubName().equals(next.getSubName())
                                ) {
                                    iterator.remove();
                                    break;
                                }*/
                            }
                        }
                        //下个版本新增替换的物料-产品列表
                        MaterialProductHistory newHistory = new MaterialProductHistory();
                        newHistory.setMaterialId(replace.getMaterialId());
                        //lxw注释
                        //newHistory.setParentModel(replace.getParentModel());
                        //newHistory.setSubName(replace.getSubName());
                        newHistory.setQuantity(replace.getQuantity());
                        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);
                            }
                        });*/
                        Iterator<ProductBomHistory> iterator1 = nowBomHistoryList.iterator();
                        while (iterator1.hasNext()){
                            //lxw注释
                            /*if(replace.getSubName().equals(iterator1.next().getSubName())){
                                iterator1.remove();
                                break;
                            }*/
                        }
                    });
                }
                //处理关联
                addedList.forEach(add -> {
                    /*nowHistoryList.forEach(nowHistory -> {
                        if (add.getMaterialId().intValue() == nowHistory.getMaterialId()) {
                            nowHistoryList.remove(nowHistory);
                        }
                    });*/
                    if(nowHistoryList.size()!=0) {
                        Iterator<MaterialProductHistory> iterator = nowHistoryList.iterator();
                        while (iterator.hasNext()) {
                            MaterialProductHistory next = iterator.next();
                            //lxw注释
                            /*if (add.getMaterialId().intValue() == next.getMaterialId()
                                    && add.getSubName().equals(next.getSubName())
                            ) {
                                iterator.remove();
                                break;
                            }*/
                        }
                    }
                    MaterialProductHistory newHistory = new MaterialProductHistory();
                    newHistory.setMaterialId(add.getMaterialId());
                    //newHistory.setParentModel(add.getParentModel());
                    //newHistory.setSubName(add.getSubName());
                    newHistory.setQuantity(add.getQuantity());
                    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));
                //lxw注释
                //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
                //lxw注释
                //List<ProductBomHistory> newBomList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), nextVersion);
                //bomService.updateNewBom(newBomList);
                //新增关联
                mphService.insertBatch(addedList);
                //移除关联
                mphService.updateVersionSubtractBatch(removedList);
            }
            else if(type.intValue() == EnumWorksheetType.ProductSoftware.getType()){ //软件下载
                //转移记录到正式表
src/main/java/com/whyc/service/WorksheetMainService.java
@@ -196,7 +196,7 @@
        List<MaterialProductApproving> approvingList = new LinkedList<>();
        WorksheetMain main = mainDTO.getMain();
        List<MaterialProductApproving> addedList = mainDTO.getAddedList();
        List<MaterialProductApproving> replacedList = mainDTO.getReplacedList();
        //List<MaterialProductApproving> replacedList = mainDTO.getReplacedList();
        List<MaterialProductApproving> removedList = mainDTO.getRemovedList();
        main.setType(EnumWorksheetType.MaterialProduct.getType());
@@ -252,13 +252,13 @@
            });
            approvingList.addAll(addedList);
        }
        if(replacedList!=null && replacedList.size()!=0){
        /*if(replacedList!=null && replacedList.size()!=0){
            replacedList.forEach(item->{
                item.setMainId(main.getId());
                item.setLinkType(2);
            });
            approvingList.addAll(replacedList);
        }
        }*/
        if(removedList!=null && removedList.size()!=0){
            removedList.forEach(item->{
                item.setMainId(main.getId());
src/main/resources/mapper/MaterialProductHistoryMapper.xml
@@ -8,6 +8,11 @@
            update db_doc.tb_Material_product_history set e_version = e_version+1 where id = #{his.id}
        </foreach>
    </update>
    <update id="updateVersionSubtractBatch">
        <foreach collection="list" item="his" separator=";">
            update db_doc.tb_Material_product_history set e_version = e_version-1 where id = #{his.id}
        </foreach>
    </update>
    <select id="getLatestExistListByMaterialId" resultType="com.whyc.pojo.MaterialProductHistory">
        SELECT
        h.*