whycxzp
2022-10-18 9d7ac939e4a1653aaa3a457235dc7b5d88361a0f
产品bom对比升级
7个文件已修改
97 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/ProductController.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/ProductBomHistoryMapper.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/ProductBomMapper.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductBomHistoryService.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductBomService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ProductBomHistoryMapper.xml 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ProductBomMapper.xml 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/ProductController.java
@@ -111,4 +111,13 @@
    public Response getLockedByProductId( @RequestParam int productId){
        return service.getLockedByProductId(productId);
    }
    /*@GetMapping("manualUpdate")
    @Transactional
    public void manualUpdate(){
        //material属性转移到bom和bomHistory
        bomHistoryService.updateMaterialField2BomHistory();
        bomService.updateMaterialField2Bom();
    }*/
}
src/main/java/com/whyc/mapper/ProductBomHistoryMapper.java
@@ -18,4 +18,9 @@
    //查询产品丝印锁定状态
    List<AttachLock> selectInAttachLock(int productId);
    List<ProductBomHistory> selectListWithMaterialField();
    void updateMaterialField2BomHistoryBatch(List<ProductBomHistory> bomHistoryList);
}
src/main/java/com/whyc/mapper/ProductBomMapper.java
@@ -30,4 +30,9 @@
    //6.在productBom中插入pHsitoryBom查询出的数据
    int insertBomSelectBomH(Integer id,Integer subVersionMax);
    List<ProductBom> selectListWithMaterialField();
    void updateMaterialField2BomBatch(List<ProductBom> bomList);
}
src/main/java/com/whyc/service/ProductBomHistoryService.java
@@ -452,13 +452,40 @@
        List<ProductBomHistory> addList = new LinkedList<>();
        List<ProductBomHistory> deleteList = new LinkedList<>();
        //物料id,对比字段:数量
        String separator = "&&&&&";
        baseBomHistoryList.forEach(baseBom->{
            bomHistoryList.forEach(bom->{
                StringBuilder diffStr = new StringBuilder();
                if(bom.getMaterialId().equals(baseBom.getMaterialId())){
                    if(!bom.getQuantity().equals(baseBom.getQuantity())){
                        String diffQuantity = separator+"原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity();
                        diffStr.append(diffQuantity);
                    }
                    if(!bom.getProducer().equals(baseBom.getProducer())){
                        String diffProducer = separator+"原生产商:"+baseBom.getProducer()+"/新生产商:"+bom.getProducer();
                        diffStr.append(diffProducer);
                    }
                    if(!bom.getMaterial().equals(baseBom.getMaterial())){
                        String diffMaterial = separator+"原封装类型|材质:"+baseBom.getMaterial()+"/新封装类型|材质:"+bom.getMaterial();
                        diffStr.append(diffMaterial);
                    }
                    if(!bom.getThickness().equals(baseBom.getThickness())){
                        String diffThickness = separator+"原元件编号|料厚:"+baseBom.getThickness()+"/新元件编号|料厚:"+bom.getThickness();
                        diffStr.append(diffThickness);
                    }
                    if(!bom.getSurfaceDetail().equals(baseBom.getSurfaceDetail())){
                        String diffSurfaceDetail = separator+"原表面处理|物料详情:"+baseBom.getSurfaceDetail()+"/新表面处理|物料详情:"+bom.getSurfaceDetail();
                        diffStr.append(diffSurfaceDetail);
                    }
                    if(!bom.getNotes().equals(baseBom.getNotes())){
                        String diffNotes = separator+"原备注:"+baseBom.getNotes()+"/新备注:"+bom.getNotes();
                        diffStr.append(diffNotes);
                    }
                    String diff = diffStr.toString();
                    if(!diff.equals("")) {
                        ProductBomHistory history = new ProductBomHistory();
                        String diffQuantity = "原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity();
                        history.setNotes(diffQuantity);
                        history.setNotes(diff.substring(5));
                        history.setMaterialObj(bom.getMaterialObj());
                        diffList.add(history);
                    }
@@ -544,4 +571,10 @@
        //query2.eq("product_id",productId).le("sub_s_version",latestSubVersion).ge("sub_e_version",latestSubVersion);
        return mapper.getBomListByProductIdAndSubVersion(productId,latestSubVersion);
    }
    public void updateMaterialField2BomHistory() {
        List<ProductBomHistory> bomHistoryList = mapper.selectListWithMaterialField();
        mapper.updateMaterialField2BomHistoryBatch(bomHistoryList);
    }
}
src/main/java/com/whyc/service/ProductBomService.java
@@ -602,4 +602,8 @@
        return mapper.getEnabledBomListByParentCodeAndCustomCode(parentCode,customCode);
    }
    public void updateMaterialField2Bom() {
        List<ProductBom> bomList = mapper.selectListWithMaterialField();
        mapper.updateMaterialField2BomBatch(bomList);
    }
}
src/main/resources/mapper/ProductBomHistoryMapper.xml
@@ -116,7 +116,27 @@
        where apply_material_code=#{parentCode}
    </select>
    <select id="getBomListByProductIdAndSubVersion" resultMap="Map_ProductBomHistory">
        SELECT h.product_id,h.material_id,h.quantity,m.*
        <!--SELECT h.product_id,h.material_id,h.quantity,m.*-->
        SELECT
            h.product_id,
            h.material_id,
            h.quantity,
            h.category,
            h.producer,
            h.material,
            h.thickness,
            h.surface_detail,
            h.notes,
            m.id,
            m.type,
            m.sub_code,
            m.sub_name,
            m.sub_model,
            m.unit,
            m.picture_url,
            m.file_url,
            m.dwg_url,
            m.create_date
        FROM tb_product_bom_history h,tb_material m
        where product_id = #{productId}
        and sub_s_version &lt;= #{subVersion}
src/main/resources/mapper/ProductBomMapper.xml
@@ -31,6 +31,18 @@
            where parent_model = #{item.parentModel} and sub_model = #{item.subModel} and id !=0
        </foreach>
    </update>
    <update id="updateMaterialField2BomBatch">
        <foreach collection="list" item="his" separator=";">
            update tb_product_bom set
            category = #{his.category},
            producer = #{his.producer},
            material = #{his.material},
            thickness = #{his.thickness},
            surface_detail = #{his.surfaceDetail},
            notes = #{his.notes}
            where id = #{his.id}
        </foreach>
    </update>
    <select id="searchCadDrawer" resultType="ProductBom" parameterType="ProductBom">
@@ -202,6 +214,9 @@
        and p.parent_code = #{parentCode} and p.custom_code = #{customCode}
        and p.version!=-1
    </select>
    <select id="selectListWithMaterialField" resultType="com.whyc.pojo.ProductBom">
        select h.id,m.* from tb_product_bom h,tb_material m where h.material_id = m.id;
    </select>
    <insert id="insertBomSelectBomH">
        insert into tb_product_bom(product_id,material_id,sub_version,quantity)
        select product_id,material_id,#{subVersionMax},quantity from tb_product_bom_history where tb_product_bom_history.product_id=#{id}