src/main/java/com/whyc/mapper/MaterialProductHistoryMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/pojo/MaterialProductHistory.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/service/MaterialProductHistoryService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/service/ProductService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/MaterialProductHistoryMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/whyc/mapper/MaterialProductHistoryMapper.java
@@ -12,4 +12,6 @@ void updateVersionSubtractBatch(List<MaterialProductApproving> removedList); List<MaterialProductHistory> getListWithMaterialInfo(List<MaterialProductHistory> mpList); } src/main/java/com/whyc/pojo/MaterialProductHistory.java
@@ -1,5 +1,6 @@ package com.whyc.pojo; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; import org.apache.ibatis.type.Alias; @@ -30,6 +31,10 @@ private Integer sVersion; @ApiModelProperty("终止版本号") private Integer eVersion; @ApiModelProperty("子件物料实体类") @TableField(exist = false) private Material subMaterial; public Integer getId() { return id; @@ -110,4 +115,12 @@ public void setSubMaterialId(Integer subMaterialId) { this.subMaterialId = subMaterialId; } public Material getSubMaterial() { return subMaterial; } public void setSubMaterial(Material subMaterial) { this.subMaterial = subMaterial; } } src/main/java/com/whyc/service/MaterialProductHistoryService.java
@@ -55,4 +55,8 @@ .ge("e_version",version); return mapper.selectList(query); } public List<MaterialProductHistory> getListWithMaterialInfo(List<MaterialProductHistory> mpList) { return mapper.getListWithMaterialInfo(mpList); } } src/main/java/com/whyc/service/ProductService.java
@@ -288,12 +288,17 @@ String fileUrl = product.getFileUrl(); Date date = new Date(); boolean isCopyCustom = false; Product relatedProduct = null; //判断是否为依据产品复制定制的产品 if(bomList == null){ bomList = pbService.getBomByProductId(product.getId()); isCopyCustom = true; }else{ if(product.getId() != null){ //关联关系从产品id继承 relatedProduct = getById(product.getId()); } //查询产品最新的版本号 } //查询新增产品最新的版本号 ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode); ProductHistory enabledProduct = phService.getEnabledByParentCodeAndCustomCode(parentCode, customCode); int currentVersion = 0; @@ -308,12 +313,29 @@ //查询产品对应的关联关系 copyCustomProduct = getById(product.getId()); List<MaterialProductHistory> relatedList = mphService.getListByParentCodeAndCustomCodeAndVersion(copyCustomProduct.getParentCode(), copyCustomProduct.getCustomCode(), copyCustomProduct.getVersion()); relatedList.forEach(related->related.setCustomCode(product.getCustomCode())); relatedList.forEach(related->{ related.setCustomCode(product.getCustomCode()); related.setSVersion(nextVersion); related.setEVersion(nextVersion); related.setCreateTime(date); }); if(relatedList.size()!=0){ mphService.insertBatch(relatedList); } }else { if(relatedProduct == null || (relatedProduct.getParentCode().equals(product.getParentCode()) && relatedProduct.getCustomCode().equals(product.getCustomCode()) ) ) { //属于是产品升级 if (latestProduct != null && enabledProduct != null) { List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion()); if(mpList.size()!=0) { //存在关联关系 //当前的产品bom明细包含 继承的产品子件物料,继承关系保留 //设置mpList关联的物料详细信息 mpList = mphService.getListWithMaterialInfo(mpList); List<String> newBomMaterialStrList = bomList.stream().map(bom -> bom.getSubCode() + "/" + bom.getSubModel()).collect(Collectors.toList()); mpList = mpList.stream().filter(mp -> newBomMaterialStrList.contains(mp.getSubMaterial().getSubCode() + "/" + mp.getSubMaterial().getSubModel())).collect(Collectors.toList()); if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) { //最新版本生效,关联关系版本连着的 mphService.updateVersionBatch(mpList); @@ -327,6 +349,26 @@ } } } }else{ //属于不同产品继承关联关系 List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(relatedProduct.getParentCode(), relatedProduct.getCustomCode(), relatedProduct.getVersion()); if(mpList.size()!=0) { //当前的产品bom明细包含 继承的产品子件物料,保留 //设置mpList关联的物料详细信息 mpList = mphService.getListWithMaterialInfo(mpList); List<String> newBomMaterialStrList = bomList.stream().map(bom -> bom.getSubCode() + "/" + bom.getSubModel()).collect(Collectors.toList()); mpList = mpList.stream().filter(mp -> newBomMaterialStrList.contains(mp.getSubMaterial().getSubCode() + "/" + mp.getSubMaterial().getSubModel())).collect(Collectors.toList()); if(mpList.size()!=0) { mpList.forEach(mp -> { mp.setParentCode(parentCode); mp.setCustomCode(customCode); mp.setSVersion(nextVersion); mp.setEVersion(nextVersion); mp.setCreateTime(date); }); mphService.insertBatch(mpList); } } } } //将产品文件复制至正式路径 src/main/resources/mapper/MaterialProductHistoryMapper.xml
@@ -2,6 +2,20 @@ <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.whyc.mapper.MaterialProductHistoryMapper"> <resultMap id="Map_MaterialProductHistory" 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"> <result property="subCode" column="m_sub_code" /> <result property="subModel" column="sub_model"/> </association> </resultMap> <update id="updateVersionBatch"> <foreach collection="list" item="his" separator=";"> @@ -24,4 +38,10 @@ AND b.version = h.e_version AND h.material_id = #{materialId} </select> <select id="getListWithMaterialInfo" resultMap="Map_MaterialProductHistory"> SELECT mp.*,m.sub_code m_sub_code,m.sub_model FROM db_doc.tb_material_product_history mp,db_doc.tb_material m where mp.sub_material_id = m.id and mp.id in <foreach collection="list" item="item" separator="," open="(" close=")"> #{item.id} </foreach> </select> </mapper>