change - 生产BOM祖级列表

master
yinq 1 year ago
parent dd3f65b798
commit 57b0682db6

@ -46,6 +46,15 @@ public class BaseBomInfoController extends BaseController {
return getDataTable(list);
}
/**
* BOM
*/
@GetMapping("/treeList" )
public AjaxResult treeList(BaseBomInfo baseBomInfo) {
List<BaseBomInfo> list = baseBomInfoService.selectBaseBomInfoList(baseBomInfo);
return success(list);
}
/**
* BOM
*/

@ -2,11 +2,11 @@ package com.aucma.production.domain;
import java.util.Date;
import com.aucma.common.core.domain.model.TreeStringEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.aucma.common.annotation.Excel;
import com.aucma.common.core.domain.BaseEntity;
/**
* BOM base_bominfo
@ -14,7 +14,7 @@ import com.aucma.common.core.domain.BaseEntity;
* @author Yinq
* @date 2023-09-28
*/
public class BaseBomInfo extends BaseEntity {
public class BaseBomInfo extends TreeStringEntity {
private static final long serialVersionUID = 1L;
/**
@ -102,11 +102,6 @@ public class BaseBomInfo extends BaseEntity {
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date updatedTime;
/**
*
*/
@Excel(name = "工单编号")
private String orderCode;
public void setObjId(Long objId) {
this.objId = objId;
@ -220,13 +215,7 @@ public class BaseBomInfo extends BaseEntity {
return updatedTime;
}
public void setOrderCode(String orderCode) {
this.orderCode = orderCode;
}
public String getOrderCode() {
return orderCode;
}
@Override
public String toString() {
@ -245,7 +234,6 @@ public class BaseBomInfo extends BaseEntity {
.append("createdTime", getCreatedTime())
.append("updatedBy", getUpdatedBy())
.append("updatedTime", getUpdatedTime())
.append("orderCode", getOrderCode())
.toString();
}
}

@ -2,6 +2,7 @@ package com.aucma.production.mapper;
import java.util.List;
import com.aucma.production.domain.BaseBomInfo;
import org.apache.ibatis.annotations.Param;
/**
* BOMMapper
@ -19,6 +20,14 @@ public interface BaseBomInfoMapper
*/
public BaseBomInfo selectBaseBomInfoByObjId(Long objId);
/**
* BOMBOM
*
* @param materialCode BOM
* @return BOM
*/
public BaseBomInfo selectBaseBomInfoByMaterialCode(@Param("materialCode") String materialCode);
/**
* BOM
*
@ -58,4 +67,19 @@ public interface BaseBomInfoMapper
* @return
*/
public int deleteBaseBomInfoByObjIds(Long[] objIds);
/**
* IDBom
* @param materialCode
* @return
*/
List<BaseBomInfo> selectChildrenBomById(String materialCode);
/**
*
*
* @param children
* @return
*/
void updateBomChildren(@Param("depts") List<BaseBomInfo> children);
}

@ -1,6 +1,9 @@
package com.aucma.production.service.impl;
import java.util.List;
import com.aucma.common.core.domain.entity.SysDept;
import com.aucma.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.aucma.production.mapper.BaseBomInfoMapper;
@ -52,6 +55,12 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
@Override
public int insertBaseBomInfo(BaseBomInfo baseBomInfo)
{
BaseBomInfo info = baseBomInfoMapper.selectBaseBomInfoByMaterialCode(baseBomInfo.getParentId());
if (StringUtils.isNull(info)){
baseBomInfo.setAncestors(baseBomInfo.getMaterialCode());
}else {
baseBomInfo.setAncestors(info.getAncestors() + "," + baseBomInfo.getMaterialCode());
}
return baseBomInfoMapper.insertBaseBomInfo(baseBomInfo);
}
@ -64,9 +73,43 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
@Override
public int updateBaseBomInfo(BaseBomInfo baseBomInfo)
{
String parentId = baseBomInfo.getParentId();
if (StringUtils.isNull(parentId)){
baseBomInfo.setAncestors(baseBomInfo.getMaterialCode());
}else {
BaseBomInfo newParentBomInfo = baseBomInfoMapper.selectBaseBomInfoByMaterialCode(parentId);
BaseBomInfo oldBomInfo = baseBomInfoMapper.selectBaseBomInfoByMaterialCode(baseBomInfo.getMaterialCode());
if (StringUtils.isNotNull(newParentBomInfo) && StringUtils.isNotNull(oldBomInfo))
{
String newAncestors = newParentBomInfo.getAncestors() + "," + baseBomInfo.getMaterialCode();
String oldAncestors = oldBomInfo.getAncestors();
baseBomInfo.setAncestors(newAncestors);
updateBomChildren(baseBomInfo.getMaterialCode(), newAncestors, oldAncestors);
}
}
return baseBomInfoMapper.updateBaseBomInfo(baseBomInfo);
}
/**
*
*
* @param materialCode ID
* @param newAncestors ID
* @param oldAncestors ID
*/
private void updateBomChildren(String materialCode, String newAncestors, String oldAncestors) {
List<BaseBomInfo> children = baseBomInfoMapper.selectChildrenBomById(materialCode);
for (BaseBomInfo child : children)
{
child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
}
if (children.size() > 0)
{
baseBomInfoMapper.updateBomChildren(children);
}
}
/**
* BOM
*

@ -19,11 +19,12 @@
<result property="createdTime" column="created_time" />
<result property="updatedBy" column="updated_by" />
<result property="updatedTime" column="updated_time" />
<result property="orderCode" column="order_code" />
<result property="ancestors" column="ancestors" />
</resultMap>
<sql id="selectBaseBomInfoVo">
select obj_id, bom_code, material_code, material_name, material_type, standard_amount, parent_id, plant_code, product_line_code, is_flag, created_by, created_time, updated_by, updated_time, order_code from base_bominfo
select obj_id, bom_code, material_code, material_name, material_type, standard_amount, parent_id,
plant_code, product_line_code, is_flag, created_by, created_time, updated_by, updated_time, ancestors from base_bominfo
</sql>
<select id="selectBaseBomInfoList" parameterType="BaseBomInfo" resultMap="BaseBomInfoResult">
@ -42,7 +43,7 @@
<if test="createdTime != null "> and created_time = #{createdTime}</if>
<if test="updatedBy != null and updatedBy != ''"> and updated_by = #{updatedBy}</if>
<if test="updatedTime != null "> and updated_time = #{updatedTime}</if>
<if test="orderCode != null and orderCode != ''"> and order_code = #{orderCode}</if>
<if test="ancestors != null and ancestors != ''"> and ancestors like concat(concat('%', #{ancestors}), '%')</if>
</where>
</select>
@ -50,6 +51,13 @@
<include refid="selectBaseBomInfoVo"/>
where obj_id = #{objId}
</select>
<select id="selectBaseBomInfoByMaterialCode" resultMap="BaseBomInfoResult">
<include refid="selectBaseBomInfoVo"/>
where material_code = #{materialCode}
</select>
<select id="selectChildrenBomById" parameterType="String" resultMap="BaseBomInfoResult">
select * from BASE_BOMINFO where FIND_IN_SET(#{materialCode}, ancestors) <![CDATA[ <> ]]> 0
</select>
<insert id="insertBaseBomInfo" parameterType="BaseBomInfo">
<selectKey keyProperty="objId" resultType="long" order="BEFORE">
@ -71,7 +79,7 @@
<if test="createdTime != null">created_time,</if>
<if test="updatedBy != null">updated_by,</if>
<if test="updatedTime != null">updated_time,</if>
<if test="orderCode != null">order_code,</if>
<if test="ancestors != null">ancestors,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="objId != null">#{objId},</if>
@ -88,7 +96,7 @@
<if test="createdTime != null">#{createdTime},</if>
<if test="updatedBy != null">#{updatedBy},</if>
<if test="updatedTime != null">#{updatedTime},</if>
<if test="orderCode != null">#{orderCode},</if>
<if test="ancestors != null">#{ancestors},</if>
</trim>
</insert>
@ -108,10 +116,22 @@
<if test="createdTime != null">created_time = #{createdTime},</if>
<if test="updatedBy != null">updated_by = #{updatedBy},</if>
<if test="updatedTime != null">updated_time = #{updatedTime},</if>
<if test="orderCode != null">order_code = #{orderCode},</if>
<if test="ancestors != null">ancestors = #{ancestors},</if>
</trim>
where obj_id = #{objId}
</update>
<update id="updateBomChildren" parameterType="java.util.List">
update base_bominfo set ancestors =
<foreach collection="depts" item="item" index="index"
separator=" " open="case material_code" close="end">
when #{item.materialCode} then #{item.ancestors}
</foreach>
where material_code in
<foreach collection="depts" item="item" index="index"
separator="," open="(" close=")">
#{item.materialCode}
</foreach>
</update>
<delete id="deleteBaseBomInfoByObjId" parameterType="Long">
delete from base_bominfo where obj_id = #{objId}

Loading…
Cancel
Save