fix:产品物料BOM组成新增时,校验整体是否存在闭环。
This commit is contained in:
@@ -82,7 +82,7 @@ public class MdProductBomController extends BaseController
|
||||
return AjaxResult.error("产品不能作为自身的BOM物料!");
|
||||
}
|
||||
|
||||
return toAjax(mdProductBomService.insertMdProductBom(mdProductBom));
|
||||
return mdProductBomService.insertMdProductBom(mdProductBom);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,4 +58,10 @@ public interface MdProductBomMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteMdProductBomByBomIds(Long[] bomIds);
|
||||
|
||||
/**
|
||||
* 查询所有产品BOM数据
|
||||
* @return
|
||||
*/
|
||||
List<MdProductBom> selectAll();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ktg.mes.md.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ktg.common.core.domain.AjaxResult;
|
||||
import com.ktg.mes.md.domain.MdProductBom;
|
||||
|
||||
/**
|
||||
@@ -29,11 +31,11 @@ public interface IMdProductBomService
|
||||
|
||||
/**
|
||||
* 新增产品BOM关系
|
||||
*
|
||||
*
|
||||
* @param mdProductBom 产品BOM关系
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertMdProductBom(MdProductBom mdProductBom);
|
||||
public AjaxResult insertMdProductBom(MdProductBom mdProductBom);
|
||||
|
||||
/**
|
||||
* 修改产品BOM关系
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.ktg.mes.md.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ktg.common.core.domain.AjaxResult;
|
||||
import com.ktg.common.utils.DateUtils;
|
||||
import com.ktg.common.utils.MapCircleUtils;
|
||||
import com.ktg.mes.md.domain.MdItem;
|
||||
import com.ktg.mes.md.service.IMdItemService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ktg.mes.md.mapper.MdProductBomMapper;
|
||||
@@ -20,6 +25,9 @@ public class MdProductBomServiceImpl implements IMdProductBomService
|
||||
@Autowired
|
||||
private MdProductBomMapper mdProductBomMapper;
|
||||
|
||||
@Autowired
|
||||
private IMdItemService itemService;
|
||||
|
||||
/**
|
||||
* 查询产品BOM关系
|
||||
*
|
||||
@@ -46,15 +54,30 @@ public class MdProductBomServiceImpl implements IMdProductBomService
|
||||
|
||||
/**
|
||||
* 新增产品BOM关系
|
||||
*
|
||||
*
|
||||
* @param mdProductBom 产品BOM关系
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertMdProductBom(MdProductBom mdProductBom)
|
||||
public AjaxResult insertMdProductBom(MdProductBom mdProductBom)
|
||||
{
|
||||
// 首先构建图数据
|
||||
MapCircleUtils mapCircleUtils = MapCircleUtils.createInstance();
|
||||
List<MdProductBom> mdProductBoms = selectBomAll();
|
||||
// 将相关数据构建成图结构
|
||||
mdProductBoms.forEach(item -> {
|
||||
mapCircleUtils.addEdge(item.getItemId(), item.getBomItemId());
|
||||
});
|
||||
mapCircleUtils.addEdge(mdProductBom.getItemId(), mdProductBom.getBomItemId());
|
||||
// 查询图结构是否存在闭环
|
||||
if (mapCircleUtils.hasCycle()) {
|
||||
// 存在闭环,无法新增
|
||||
return AjaxResult.error("BOM物料存在闭环,无法新增");
|
||||
}
|
||||
|
||||
// 不存在闭环,可以新增
|
||||
mdProductBom.setCreateTime(DateUtils.getNowDate());
|
||||
return mdProductBomMapper.insertMdProductBom(mdProductBom);
|
||||
return AjaxResult.success(mdProductBomMapper.insertMdProductBom(mdProductBom));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,4 +116,8 @@ public class MdProductBomServiceImpl implements IMdProductBomService
|
||||
{
|
||||
return mdProductBomMapper.deleteMdProductBomByBomId(bomId);
|
||||
}
|
||||
|
||||
public List<MdProductBom> selectBomAll() {
|
||||
return mdProductBomMapper.selectAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectMdProductBomVo"/>
|
||||
where bom_id = #{bomId}
|
||||
</select>
|
||||
|
||||
<select id="selectAll" resultType="com.ktg.mes.md.domain.MdProductBom" resultMap="MdProductBomResult">
|
||||
<include refid="selectMdProductBomVo"/>
|
||||
</select>
|
||||
|
||||
<insert id="insertMdProductBom" parameterType="MdProductBom" useGeneratedKeys="true" keyProperty="bomId">
|
||||
insert into md_product_bom
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
||||
Reference in New Issue
Block a user