whycxzp
2022-10-28 7b0f3ac0a411616e1af4667fb68f09801c00d999
产品bom物料逻辑更新
4个文件已修改
49 ■■■■■ 已修改文件
src/main/java/com/whyc/mapper/MaterialMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/MaterialService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductService.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/MaterialMapper.xml 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/MaterialMapper.java
@@ -33,4 +33,7 @@
    List<Material> getMaterialVersion(@Param("subModel") String subModel);
    //根据物料id查询物料信息
    Material getMaterialById(int materialId);
    void updateDwgUrlAndPicUrl(List<Material> materialUpdateList);
}
src/main/java/com/whyc/service/MaterialService.java
@@ -477,4 +477,8 @@
        //
        //return null;
    }
    public void updateDwgUrlAndPicUrl(List<Material> materialUpdateList) {
        mapper.updateDwgUrlAndPicUrl(materialUpdateList);
    }
}
src/main/java/com/whyc/service/ProductService.java
@@ -570,7 +570,10 @@
            materialUrlList.forEach(materialUrl -> {
                String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4);
                try {
                    FileCopyUtils.copy(new File(materialUrl), new File(materialDir + File.separator + dwgName + ".dwg"));
                    File dwgFile = new File(materialDir + File.separator + dwgName + ".dwg");
                    if(!dwgFile.exists()) {
                        FileCopyUtils.copy(new File(materialUrl), dwgFile);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
@@ -579,17 +582,22 @@
            picUrlList.forEach(picUrl -> {
                String picFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1);
                try {
                    FileCopyUtils.copy(new File(picUrl), new File(materialDir + File.separator + picFullName));
                    File picFile = new File(materialDir + File.separator + picFullName);
                    if(!picFile.exists()) {
                        FileCopyUtils.copy(new File(picUrl), picFile);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
            //物料表中不存在的(依据:物料编码+物料型号),则添加到物料表中去(包含product这个物料)
            //没有图纸和图片的,更新图纸和图片;有图纸和图片的,不更新图纸和图片
            List<Material> materialExistList = mService.getListByCodeAndModelList2(bomList);
            //List<String> subCodeList = materialExistList.stream().map(Material::getSubCode).collect(Collectors.toList());
            List<String> subCodeList = materialExistList.stream().map(material -> material.getSubCode()+"/"+material.getSubModel()).collect(Collectors.toList());
            List<Material> materialList = new LinkedList<>();
            List<Material> materialUpdateList = new LinkedList<>();
            bomList.forEach(bom -> {
                if (!subCodeList.contains(bom.getSubCode()+"/"+bom.getSubModel())) {
                    Material material = new Material();
@@ -606,6 +614,19 @@
                    material.setUnit(bom.getUnit());
                    materialList.add(material);
                }else{ //物料已经存在的
                    Material material = new Material();
                    if (bom.getPictureUrl() != null) {
                        material.setPictureUrl(bom.getPictureUrl());
                    }
                    if (bom.getDwgUrl() != null) {
                        material.setDwgUrl(bom.getDwgUrl());
                    }
                    if(material.getPictureUrl()!=null || material.getDwgUrl()!=null){
                        material.setSubCode(bom.getSubCode());
                        material.setSubModel(bom.getSubModel());
                        materialUpdateList.add(material);
                    }
                }
            });
            //母料是否存在
@@ -623,6 +644,9 @@
            if(materialList.size()!=0) {
                mService.insertBatch(materialList);
            }
            if(materialUpdateList.size()!=0) {
                mService.updateDwgUrlAndPicUrl(materialUpdateList);
            }
            //更新product_history/product_bom_history/product/product_bom,
            // product的主键沿用对应product_history的
            //根据编码和型号确定物料id并对应quantity,存入数据库.
src/main/resources/mapper/MaterialMapper.xml
@@ -139,6 +139,20 @@
            update tb_material set dwg_url = #{item.notes} where sub_model = #{item.subModel}
        </foreach>
    </update>
    <update id="updateDwgUrlAndPicUrl">
        <foreach collection="list" item="item" separator=";">
            update tb_material
            <set>
                <if test="item.dwgUrl!=null">
                    dwg_url = #{item.dwgUrl},
                </if>
                <if test="item.pictureUrl!=null">
                    picture_url = #{item.pictureUrl},
                </if>
            </set>
             where sub_code = #{item.subCode} and sub_model = #{item.subModel}
        </foreach>
    </update>
    <update id="disableStatus">
        update tb_material set status = 0 where sub_code in
        <foreach collection="list" item="item" separator="," open="(" close=")">