whycxzp
2022-09-05 aaa02f788851807d65260fbf6a3c5d91ff6afa71
对比更新
5个文件已修改
93 ■■■■ 已修改文件
src/main/java/com/whyc/mapper/ProductBomMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/ProductBom.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductBomHistoryService.java 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductBomService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ProductBomMapper.xml 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/ProductBomMapper.java
@@ -25,6 +25,6 @@
    List<ProductBom> getListByCodeAndModelList2(List<ProductBom> bomList);
    ProductBom getEnabledStandardBomListByParentCode(String parentCode);
    List<ProductBom> getEnabledBomListByParentCodeAndCustomCode(String parentCode, String customCode);
}
src/main/java/com/whyc/pojo/ProductBom.java
@@ -24,6 +24,9 @@
    private Integer materialId;
    @ApiModelProperty("bom最新版本号,同时也是生效版本号(不存在小版本手动启用)")
    private Integer subVersion;
    @ApiModelProperty("物料实体类")
    @TableField(exist = false)
    private Material materialObj;
    @ApiModelProperty("结构件类型")
    @TableField(exist = false)
@@ -317,4 +320,12 @@
    public void setConnFlag(Integer connFlag) {
        this.connFlag = connFlag;
    }
    public Material getMaterialObj() {
        return materialObj;
    }
    public void setMaterialObj(Material materialObj) {
        this.materialObj = materialObj;
    }
}
src/main/java/com/whyc/service/ProductBomHistoryService.java
@@ -417,8 +417,8 @@
                if(bom.getMaterialId().equals(baseBom.getMaterialId())){
                    if(!bom.getQuantity().equals(baseBom.getQuantity())){
                        ProductBomHistory history = new ProductBomHistory();
                        String diffSubModel = "原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity();
                        history.setNotes(diffSubModel);
                        String diffQuantity = "原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity();
                        history.setNotes(diffQuantity);
                        history.setMaterialObj(bom.getMaterialObj());
                        diffList.add(history);
                    }
@@ -448,23 +448,46 @@
     */
    public Map<String, List> parseCompare(Product baseProduct, Product product) {
        List<ProductBom> bomList = product.getBomList();
        List<ProductBom> baseBomList = new LinkedList<>();
        ProductBom baseProductBom = null;
        List<ProductBom> baseProductBomList = null;
        Map<String,List> compareMap = new HashMap<>();
        List<ProductBomHistory> diffList = new LinkedList<>();
        List<ProductBomHistory> addList = new LinkedList<>();
        List<ProductBomHistory> deleteList = new LinkedList<>();
        List<ProductBom> diffList = new LinkedList<>();
        List<ProductBom> addList = new LinkedList<>();
        List<ProductBom> deleteList = new LinkedList<>();
        //根据baseProduct的code和custom_code,查找到基准产品
        if(baseProduct == null){
            baseProductBom = bomService.getEnabledStandardBomListByParentCode(product.getParentCode());
        }else{
        //查找到基准产品
        if(baseProduct == null){ //查找上传的产品最新标准版本
            baseProductBomList = bomService.getEnabledBomListByParentCodeAndCustomCode(product.getParentCode(),"0");
        }else{ //根据baseProduct的code和custom_code
            baseProductBomList = bomService.getEnabledBomListByParentCodeAndCustomCode(baseProduct.getParentCode(),baseProduct.getCustomCode());
        }
        //对比:根据code+model定位,比较数量
        List<String> baseCodeModelList = baseProductBomList.stream().map(bom -> bom.getMaterialObj().getSubCode() + "/" + bom.getMaterialObj().getSubModel()).collect(Collectors.toList());
        Map<String, List<ProductBom>> groupedBaseBomList = baseProductBomList.stream().collect(Collectors.groupingBy(bom -> bom.getMaterialObj().getSubCode() + "/" + bom.getMaterialObj().getSubModel()));
        List<String> codeModelList = bomList.stream().map(bom -> bom.getSubCode() + "/" + bom.getSubModel()).collect(Collectors.toList());
        bomList.forEach(bom->{
            String codeModel = bom.getSubCode() + "/" + bom.getSubModel();
            if(!baseCodeModelList.contains(codeModel)){
                addList.add(bom);
            }else{
                ProductBom baseBom = groupedBaseBomList.get(codeModel).get(0);
                if(bom.getQuantity().intValue()!=baseBom.getQuantity()){
                    ProductBom diffBom = new ProductBom();
                    String diffQuantity =  "原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity();
                    diffBom.setNotes(diffQuantity);
                    diffBom.setMaterialObj(bom.getMaterialObj());
                    diffList.add(diffBom);
                }
            }
        });
        baseProductBomList.forEach(bom->{
            String codeModel = bom.getMaterialObj().getSubCode() + "/" + bom.getMaterialObj().getSubModel();
            if(!codeModelList.contains(codeModel)){
                deleteList.add(bom);
            }
        });
        compareMap.put("diffList",diffList);
        compareMap.put("addList",addList);
        compareMap.put("deleteList",deleteList);
src/main/java/com/whyc/service/ProductBomService.java
@@ -16,7 +16,6 @@
import com.whyc.util.ActionUtil;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -538,7 +537,7 @@
        return mapper.getListByCodeAndModelList2(bomList);
    }
    public ProductBom getEnabledStandardBomListByParentCode(String parentCode) {
        return mapper.getEnabledStandardBomListByParentCode(parentCode);
    public List<ProductBom> getEnabledBomListByParentCodeAndCustomCode(String parentCode, String customCode) {
        return mapper.getEnabledBomListByParentCodeAndCustomCode(parentCode,customCode);
    }
}
src/main/resources/mapper/ProductBomMapper.xml
@@ -1,6 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.whyc.mapper.ProductBomMapper">
    <resultMap id="Map_ProductBom" type="productBom">
        <result property="quantity" column="quantity"/>
        <association property="materialObj" javaType="com.whyc.pojo.Material">
            <id property="id" column="id" />
            <result property="type" column="type" />
            <result property="category" column="category"/>
            <result property="subCode" column="sub_code"/>
            <result property="subName" column="sub_name"/>
            <result property="subModel" column="sub_model"/>
            <result property="unit" column="unit"/>
            <result property="producer" column="producer"/>
            <result property="material" column="material"/>
            <result property="thickness" column="thickness"/>
            <result property="surfaceDetail" column="surface_detail"/>
            <result property="notes" column="notes"/>
            <result property="pictureUrl" column="picture_url"/>
            <result property="fileUrl" column="file_url"/>
            <result property="dwgUrl" column="dwg_url"/>
            <result property="createDate" column="create_date"/>
        </association>
    </resultMap>
    <update id="updateUrl">
        <foreach collection="list" item="item" separator=";">
            update db_doc.tb_product_bom set picture_url = #{item.pictureUrl},dwg_url = #{item.dwgUrl}
@@ -169,12 +191,12 @@
            select id,#{item.quantity} as quantity from db_doc.tb_material where sub_code = #{item.subCode} and sub_model = #{item.subModel}
        </foreach>
    </select>
    <select id="getEnabledStandardBomListByParentCode" resultType="com.whyc.pojo.ProductBom">
    <select id="getEnabledBomListByParentCodeAndCustomCode" resultMap="Map_ProductBom">
        SELECT
        b.quantity,m.*
        FROM db_doc.tb_product p,db_doc.tb_product_bom b,db_doc.tb_material m
        where p.id = b.product_id
        and b.material_id = m.id
        and p.parent_code = #{parentCode} and p.custom_code = "0"
        and p.parent_code = #{parentCode} and p.custom_code = #{customCode}
    </select>
</mapper>