whycxzp
2023-09-09 d53c34e999bed9cb93f8757aed161a4b590d64d1
产品bom新增,添加两个字段-厂家规格和替料
8个文件已修改
225 ■■■■■ 已修改文件
src/main/java/com/whyc/mapper/MaterialProductHistoryMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/MaterialProductHistory.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/ProductBom.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/ProductBomHistory.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/MaterialProductHistoryService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/MaterialService.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductService.java 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/MaterialProductHistoryMapper.xml 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/MaterialProductHistoryMapper.java
@@ -2,6 +2,7 @@
import com.whyc.pojo.MaterialProductApproving;
import com.whyc.pojo.MaterialProductHistory;
import com.whyc.pojo.ProductBom;
import java.util.List;
@@ -14,4 +15,5 @@
    List<MaterialProductHistory> getListWithMaterialInfo(List<MaterialProductHistory> mpList);
    List<MaterialProductHistory> getListByParentCodeAndCustomCodeAndSubMaterialIdAndVersion(String parentCode, String customCode, List<ProductBom> bomList, int currentVersion);
}
src/main/java/com/whyc/pojo/MaterialProductHistory.java
@@ -35,6 +35,9 @@
    @ApiModelProperty("子件物料实体类")
    @TableField(exist = false)
    private Material subMaterial;
    @ApiModelProperty("子件物料实体类")
    @TableField(exist = false)
    private Material relatedSubMaterial;
    public Integer getId() {
        return id;
@@ -123,4 +126,12 @@
    public void setSubMaterial(Material subMaterial) {
        this.subMaterial = subMaterial;
    }
    public Material getRelatedSubMaterial() {
        return relatedSubMaterial;
    }
    public void setRelatedSubMaterial(Material relatedSubMaterial) {
        this.relatedSubMaterial = relatedSubMaterial;
    }
}
src/main/java/com/whyc/pojo/ProductBom.java
@@ -57,6 +57,9 @@
    @ApiModelProperty("生产商")
    private String     producer;
    @ApiModelProperty("厂家规格")
    private String producerSpecification;
    @ApiModelProperty("封装类型/材质")
    private String     material;
@@ -88,6 +91,12 @@
    @TableField(exist = false)
    private Integer dwgExist;
    //替代料的料号拼接,格式为
    // 0341000294,
    //0341000294,0341000294,
    @TableField(exist = false)
    private String relatedMaterialCodes;
    @TableField(exist = false)
    @ApiModelProperty(value = "关联的物料集合")
@@ -322,4 +331,21 @@
    public void setMaterialObj(Material materialObj) {
        this.materialObj = materialObj;
    }
    public String getProducerSpecification() {
        return producerSpecification;
    }
    public void setProducerSpecification(String producerSpecification) {
        this.producerSpecification = producerSpecification;
    }
    public String getRelatedMaterialCodes() {
        return relatedMaterialCodes;
    }
    public void setRelatedMaterialCodes(String relatedMaterialCodes) {
        this.relatedMaterialCodes = relatedMaterialCodes;
    }
}
src/main/java/com/whyc/pojo/ProductBomHistory.java
@@ -58,6 +58,9 @@
    @ApiModelProperty("生产商")
    private String     producer;
    @ApiModelProperty("厂家规格")
    private String producerSpecification;
    @ApiModelProperty("封装类型/材质")
    private String     material;
@@ -331,4 +334,12 @@
    public void setConnFlag(Integer connFlag) {
        this.connFlag = connFlag;
    }
    public String getProducerSpecification() {
        return producerSpecification;
    }
    public void setProducerSpecification(String producerSpecification) {
        this.producerSpecification = producerSpecification;
    }
}
src/main/java/com/whyc/service/MaterialProductHistoryService.java
@@ -6,6 +6,7 @@
import com.whyc.mapper.MaterialProductHistoryMapper;
import com.whyc.pojo.MaterialProductApproving;
import com.whyc.pojo.MaterialProductHistory;
import com.whyc.pojo.ProductBom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -59,4 +60,8 @@
    public List<MaterialProductHistory> getListWithMaterialInfo(List<MaterialProductHistory> mpList) {
        return mapper.getListWithMaterialInfo(mpList);
    }
    public List<MaterialProductHistory> getListByParentCodeAndCustomCodeAndSubMaterialIdAndVersion(String parentCode, String customCode, List<ProductBom> bomList, int currentVersion) {
        return mapper.getListByParentCodeAndCustomCodeAndSubMaterialIdAndVersion(parentCode,customCode,bomList,currentVersion);
    }
}
src/main/java/com/whyc/service/MaterialService.java
@@ -576,4 +576,10 @@
        }
        ExcelUtil.exportExcel("清单","物料",title,values,null,response);
    }
    public Material getLastByCode(String code) {
        QueryWrapper<Material> query = Wrappers.query();
        query.eq("sub_code",code).orderByDesc("id").last(" limit 1");
        return mapper.selectOne(query);
    }
}
src/main/java/com/whyc/service/ProductService.java
@@ -26,6 +26,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Service
@@ -224,12 +225,23 @@
                int lastRowNum = sheet.getLastRowNum();
                //取第三行,并以第三行开始
                Row row2 = sheet.getRow(1);
                //现在规定为17列
                short lastCellNum = row2.getLastCellNum();
                if(lastCellNum !=18){
                    return response.set(1, false, "上传文件的bom清单列数不对");
                }
                for (int k = 2; k < lastRowNum + 1; k++) {
                    if(k==2){
                        product.setParentCode(sheet.getRow(2).getCell(1).getStringCellValue());
                        product.setParentName(sheet.getRow(2).getCell(2).getStringCellValue());
                        product.setParentModel(sheet.getRow(2).getCell(3).getStringCellValue());
                        String parentModel = sheet.getRow(2).getCell(3).getStringCellValue();
                        String regexStr = "[\\/*?\"|:<>\\\\ \t]";
                        boolean matches = Pattern.compile(regexStr).matcher(parentModel).find();
                        if(!matches) {
                            product.setParentModel(parentModel);
                        }else{
                            return response.set(1,false,"母料型号包含非法字符:\\/*?\"|:<>或空格");
                        }
                    }
                    ProductBom bom = new ProductBom();
                    for (int j = 0; j < lastCellNum; j++) {
@@ -237,9 +249,9 @@
                        Cell cell = row.getCell(j);
                        String cellValue = null;
                        Double cellValueInt = 0d;
                        if (j == 9 || j == 0) {
                        if (j == 9 || j == 0) { //1和10列为数值
                            cellValueInt = cell.getNumericCellValue();
                        } else if (j != 15) {
                        } else if (j != 16) { //16列为图片
                            cellValue = cell.getStringCellValue();
                        }
                        if(cellValue!=null) {
@@ -291,22 +303,26 @@
                            }
                            break;
                            case 11: {
                                bom.setMaterial(cellValue);
                                bom.setProducerSpecification(cellValue);
                            }
                            break;
                            case 12: {
                                bom.setThickness(cellValue);
                                bom.setMaterial(cellValue);
                            }
                            break;
                            case 13: {
                                bom.setSurfaceDetail(cellValue);
                                bom.setThickness(cellValue);
                            }
                            break;
                            case 14: {
                                bom.setNotes(cellValue);
                                bom.setSurfaceDetail(cellValue);
                            }
                            break;
                            case 15: {
                                bom.setNotes(cellValue);
                            }
                            break;
                            case 16: {
                                /* 弃用,不适用于 图片不按顺序摆放情况
                                //图片,从0开始,到图片size为止
                                int m = k - 2;
@@ -348,6 +364,16 @@
                                    fileOutputStream.write(data);
                                    bom.setPictureUrl(picturePathFront);
                                }
                            }
                            break;
                            case 17: {
                                if(cellValue!=null && !cellValue.trim().equals("")) {
                                    if(cellValue.contains(",") || cellValue.contains(",")){
                                        bom.setRelatedMaterialCodes(cellValue);
                                    }else{
                                        return response.set(1, false, "上传文件的bom清单内替料格式不对");
                                    }
                                }
                            }
                            break;
@@ -514,6 +540,95 @@
            }
        }
        //查询是否bomList中有替料
        // 有的话,检查关联表中是否已存在或本版本已生效
        List<MaterialProductHistory> newAddedList = new LinkedList<>();
        List<MaterialProductHistory> versionUpdateList = new LinkedList<>();
        List<MaterialProductHistory> mpListInDB = mphService.getListByParentCodeAndCustomCodeAndSubMaterialIdAndVersion(parentCode,customCode,bomList,currentVersion);
        List<String> subMaterialListInDB = mpListInDB.stream().map(mp->mp.getSubMaterial().getSubCode()+"_"+mp.getSubMaterial().getSubModel()).collect(Collectors.toList());
        bomList.forEach(bom->{
            if(bom.getRelatedMaterialCodes()!=null) {
                String relatedMaterialCodes = bom.getRelatedMaterialCodes().trim();
                if (!relatedMaterialCodes.equals("")) {
                    if (subMaterialListInDB.contains(bom.getSubCode()+"_"+bom.getSubModel())) { //当前物料有替代料
                        String[] relatedList;
                        if (relatedMaterialCodes.contains(",")) {
                            relatedList = relatedMaterialCodes.split(",");
                        } else {
                            relatedList = relatedMaterialCodes.split(",");
                        }
                        for (String related : relatedList) {
                            bom.setRelatedMaterialCodes(related);
                            boolean exists = false;
                            for (MaterialProductHistory mp : mpListInDB) {
                                //物料相同,替代料相同
                                if ((mp.getSubMaterial().getSubCode()+"_"+mp.getSubMaterial().getSubModel()).equals(bom.getSubCode()+"_"+bom.getSubModel())
                                        && mp.getRelatedSubMaterial().getSubCode().equals(related)) {
                                    //只可能存在0 和 1 的情况,因为查询的是 >=上个版本
                                    if (nextVersion - mp.getEVersion() == 0) { //已存在,无需添加
                                        //break;
                                    } else if (nextVersion - mp.getEVersion() == 1) {  //更新到当前版本
                                        mp.setEVersion(nextVersion);
                                        versionUpdateList.add(mp);
                                    }
                                    exists = true;
                                }
                            }
                            if(!exists) { //不存在相邻及相同的记录版本,新增
                                MaterialProductHistory newTemp = new MaterialProductHistory();
                                newTemp.setParentCode(parentCode);
                                newTemp.setCustomCode(customCode);
                                newTemp.setSubCode(bom.getSubCode());
                                Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel());
                                newTemp.setSubMaterialId(material.getId());
                                newTemp.setSVersion(nextVersion);
                                newTemp.setEVersion(nextVersion);
                                newTemp.setQuantity(bom.getQuantity());
                                //2323-09-08 与杨红兰微信确认<就按照我上传清单的时间,系统里最新的是啥型号,就取什么型号>
                                Material relatedMaterial = mService.getLastByCode(related);
                                newTemp.setMaterialId(relatedMaterial.getId());
                                newTemp.setCreateTime(date);
                                newAddedList.add(newTemp);
                            }
                        }
                    }
                    else{
                        String[] relatedList;
                        if (relatedMaterialCodes.contains(",")) {
                            relatedList = relatedMaterialCodes.split(",");
                        } else {
                            relatedList = relatedMaterialCodes.split(",");
                        }
                        for (String related : relatedList) {
                            MaterialProductHistory newTemp = new MaterialProductHistory();
                            newTemp.setParentCode(parentCode);
                            newTemp.setCustomCode(customCode);
                            newTemp.setSubCode(bom.getSubCode());
                            Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel());
                            newTemp.setSubMaterialId(material.getId());
                            newTemp.setSVersion(nextVersion);
                            newTemp.setEVersion(nextVersion);
                            newTemp.setQuantity(bom.getQuantity());
                            //2323-09-08 与杨红兰微信确认<就按照我上传清单的时间,系统里最新的是啥型号,就取什么型号>
                            Material relatedMaterial = mService.getLastByCode(related);
                            newTemp.setMaterialId(relatedMaterial.getId());
                            newTemp.setCreateTime(date);
                            newAddedList.add(newTemp);
                        }
                    }
                }
            }
        });
        //执行更新
        if(newAddedList.size()!=0) {
            mphService.insertBatch(newAddedList);
        }
        if(versionUpdateList.size()!=0) {
            mphService.updateVersionBatch(versionUpdateList);
        }
        //将产品文件复制至正式路径
        //文件转移,未跟子件挂钩的所有图纸图片转移到产品版本下:doc_file/product/{产品型号}/standard或者{customCode}}/{version}/
        //跟子件挂钩的转移到子件图纸下:doc_file/material/
@@ -561,6 +676,7 @@
                bomHistory.setMaterial(bom.getMaterial());
                bomHistory.setNotes(bom.getNotes());
                bomHistory.setProducer(bom.getProducer());
                bomHistory.setProducerSpecification(bom.getProducerSpecification());
                bomHistory.setSurfaceDetail(bom.getSurfaceDetail());
                bomHistory.setThickness(bom.getThickness());
                bomHistory.setSubSVersion(1);
@@ -795,6 +911,7 @@
                bom.setMaterial(bomMaterial.getMaterial());
                bom.setNotes(bomMaterial.getNotes());
                bom.setProducer(bomMaterial.getProducer());
                bom.setProducerSpecification(bomMaterial.getProducerSpecification());
                bom.setSurfaceDetail(bomMaterial.getSurfaceDetail());
                bom.setThickness(bomMaterial.getThickness());
                bom.setSubVersion(1);
@@ -814,6 +931,7 @@
                bomHistory.setMaterial(bomMaterial.getMaterial());
                bomHistory.setNotes(bomMaterial.getNotes());
                bomHistory.setProducer(bomMaterial.getProducer());
                bomHistory.setProducerSpecification(bomMaterial.getProducerSpecification());
                bomHistory.setSurfaceDetail(bomMaterial.getSurfaceDetail());
                bomHistory.setThickness(bomMaterial.getThickness());
                bomHistory.setSubSVersion(1);
src/main/resources/mapper/MaterialProductHistoryMapper.xml
@@ -16,6 +16,20 @@
            <result property="subModel" column="sub_model"/>
        </association>
    </resultMap>
    <resultMap id="Map_MaterialProductHistory2" type="MaterialProductHistory">
        <id property="id" column="id"/>
        <result property="parentCode" column="parent_code"/>
        <result property="customCode" column="custom_code"/>
        <result property="subMaterialId" column="sub_material_id"/>
        <result property="sVersion" column="s_version"/>
        <result property="eVersion" column="e_version"/>
        <result property="quantity" column="quantity"/>
        <result property="materialId" column="material_id"/>
        <association property="subMaterial" javaType="Material" select="com.whyc.mapper.MaterialMapper.getMaterialById" column="sub_material_id">
        </association>
        <association property="relatedSubMaterial" javaType="Material" select="com.whyc.mapper.MaterialMapper.getMaterialById" column="material_id">
        </association>
    </resultMap>
    <update id="updateVersionBatch">
        <foreach collection="list" item="his" separator=";">
@@ -44,4 +58,22 @@
            #{item.id}
        </foreach>
    </select>
    <select id="getListByParentCodeAndCustomCodeAndSubMaterialIdAndVersion"
            resultMap="Map_MaterialProductHistory2">
        select distinct h.* from tb_material_product_history h,tb_material m where
        h.sub_material_id = m.id
        and
        <foreach collection="bomList" item="item" separator="or">
            (
            h.parent_code = #{parentCode}
            <if test="customCode !=null">
                and h.custom_code = #{customCode}
            </if>
            and m.`sub_code` = #{item.subCode}
            and m.`sub_model` = #{item.subModel}
            and h.`e_version` >= #{currentVersion}
            )
        </foreach>
        order by h.e_version desc
    </select>
</mapper>