diff --git a/op-modules/op-wms/src/main/java/com/op/wms/controller/BaseBomController.java b/op-modules/op-wms/src/main/java/com/op/wms/controller/BaseBomController.java index ffbc4801..4f7e3574 100644 --- a/op-modules/op-wms/src/main/java/com/op/wms/controller/BaseBomController.java +++ b/op-modules/op-wms/src/main/java/com/op/wms/controller/BaseBomController.java @@ -1,7 +1,9 @@ package com.op.wms.controller; +import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.op.wms.domain.BaseBomComponent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -40,8 +42,10 @@ public class BaseBomController extends BaseController { @GetMapping("/list") public TableDataInfo list(BaseBom baseBom) { startPage(); - List list = baseBomService.selectBaseBomList(baseBom); - return getDataTable(list); + BaseBomComponent baseBomComponent = new BaseBomComponent(); + List list = new ArrayList<>(); + List baseBoms = baseBomService.selectBaseBomComponentList(baseBomComponent); + return getDataTable(baseBoms); } /** diff --git a/op-modules/op-wms/src/main/java/com/op/wms/domain/BaseBomComponent.java b/op-modules/op-wms/src/main/java/com/op/wms/domain/BaseBomComponent.java index 7e8ddc4c..f16984a0 100644 --- a/op-modules/op-wms/src/main/java/com/op/wms/domain/BaseBomComponent.java +++ b/op-modules/op-wms/src/main/java/com/op/wms/domain/BaseBomComponent.java @@ -1,6 +1,8 @@ package com.op.wms.domain; import java.util.Date; +import java.util.List; + import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -17,7 +19,7 @@ public class BaseBomComponent extends BaseEntity { private static final long serialVersionUID = 1L; /** 主键 */ - private Long id; + private String handle; /** BOM单号 */ @Excel(name = "BOM单号") @@ -56,9 +58,8 @@ public class BaseBomComponent extends BaseEntity { private Long lossRate; /** 损耗额 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "损耗额", width = 30, dateFormat = "yyyy-MM-dd") - private Date lossAmount; + @Excel(name = "损耗额") + private Long lossAmount; /** 含损耗用量 */ @Excel(name = "含损耗用量") @@ -92,12 +93,22 @@ public class BaseBomComponent extends BaseEntity { @Excel(name = "预留字段3") private String attr3; - public void setId(Long id) { - this.id = id; + private List children; + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public void setHandle(String handle) { + this.handle = handle; } - public Long getId() { - return id; + public String getHandle() { + return handle; } public void setBomCode(String bomCode) { this.bomCode = bomCode; @@ -162,11 +173,11 @@ public class BaseBomComponent extends BaseEntity { public Long getLossRate() { return lossRate; } - public void setLossAmount(Date lossAmount) { + public void setLossAmount(Long lossAmount) { this.lossAmount = lossAmount; } - public Date getLossAmount() { + public Long getLossAmount() { return lossAmount; } public void setCilosses(Long cilosses) { @@ -229,7 +240,7 @@ public class BaseBomComponent extends BaseEntity { @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("id", getId()) + .append("handle", getHandle()) .append("bomCode", getBomCode()) .append("site", getSite()) .append("productCode", getProductCode()) diff --git a/op-modules/op-wms/src/main/java/com/op/wms/mapper/BaseBomComponentMapper.java b/op-modules/op-wms/src/main/java/com/op/wms/mapper/BaseBomComponentMapper.java index 77b82ca3..1709d771 100644 --- a/op-modules/op-wms/src/main/java/com/op/wms/mapper/BaseBomComponentMapper.java +++ b/op-modules/op-wms/src/main/java/com/op/wms/mapper/BaseBomComponentMapper.java @@ -58,4 +58,9 @@ public interface BaseBomComponentMapper { * @return 结果 */ public int deleteBaseBomComponentByIds(Long[] ids); + + //查询Bom表中的BomCodeList + List selectBomCodeList(BaseBomComponent baseBomComponent); + //查询BaseBomComponent表中的product_code + List selectProductCodeList(BaseBomComponent baseBomComponent); } diff --git a/op-modules/op-wms/src/main/java/com/op/wms/service/IBaseBomService.java b/op-modules/op-wms/src/main/java/com/op/wms/service/IBaseBomService.java index adb0c4ac..3c075240 100644 --- a/op-modules/op-wms/src/main/java/com/op/wms/service/IBaseBomService.java +++ b/op-modules/op-wms/src/main/java/com/op/wms/service/IBaseBomService.java @@ -2,6 +2,7 @@ package com.op.wms.service; import java.util.List; import com.op.wms.domain.BaseBom; +import com.op.wms.domain.BaseBomComponent; /** * BOM物料管理Service接口 @@ -25,6 +26,8 @@ public interface IBaseBomService { * @return BOM物料管理集合 */ public List selectBaseBomList(BaseBom baseBom); + //public List selectBaseBomList(BaseBom baseBom, BaseBomComponent baseBomComponent, List list); + public List selectBaseBomComponentList(BaseBomComponent baseBomComponent); /** * 新增BOM物料管理 diff --git a/op-modules/op-wms/src/main/java/com/op/wms/service/impl/BaseBomServiceImpl.java b/op-modules/op-wms/src/main/java/com/op/wms/service/impl/BaseBomServiceImpl.java index 16d6e0eb..2e736a7d 100644 --- a/op-modules/op-wms/src/main/java/com/op/wms/service/impl/BaseBomServiceImpl.java +++ b/op-modules/op-wms/src/main/java/com/op/wms/service/impl/BaseBomServiceImpl.java @@ -1,9 +1,14 @@ package com.op.wms.service.impl; +import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.utils.DateUtils; +import com.op.wms.domain.BaseBomComponent; +import com.op.wms.mapper.BaseBomComponentMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.op.wms.mapper.BaseBomMapper; @@ -20,6 +25,8 @@ import com.op.wms.service.IBaseBomService; public class BaseBomServiceImpl implements IBaseBomService { @Autowired private BaseBomMapper baseBomMapper; + @Autowired + private BaseBomComponentMapper baseBomComponentMapper; /** * 查询BOM物料管理 @@ -94,4 +101,91 @@ public class BaseBomServiceImpl implements IBaseBomService { public int deleteBaseBomByFactoryCode(String factoryCode) { return baseBomMapper.deleteBaseBomByFactoryCode(factoryCode); } + +// @Override +// public List findByTree(BaseBomComponent baseBomComponent) { +// //父 Cumc 子Component +// //查询出所有物料BOM数据 +// List bomList = baseBomComponentMapper.selectBaseBomComponentList(baseBomComponent); +// List conversionList = bomList.stream().map((baseBomComponent1) -> { +// BaseBomComponent vo = new BaseBomComponent(); +// vo.setComponent(baseBomComponent1.getComponent());//子表 +// vo.setHandle(baseBomComponent1.getHandle());//主键 +// vo.setCumc(baseBomComponent1.getCumc());//父表 +// return vo; +// }).collect(Collectors.toList()); +// //使用filter去进行拦截,进行判断 +// List baseBomComponentVos = conversionList.stream().filter(baseBomComponentVo -> 0 == BaseBomComponent.getCumc()) +// .peek(organizationVo -> organizationVo.setChildren(createChildList(organizationVo, conversionList))) +// .sorted(Comparator.comparing(BaseBomComponent::getComponent)) +// .collect(Collectors.toList()); +//// +//// return organizationVos; +// return conversionList; +// } + + /** + * @param organizationVo 父级 + * @param organizationVoList 对应的list + * @return + */ +// private static List createChildList(BaseBomComponent organizationVo, List organizationVoList) { +// return organizationVoList.stream().filter(model -> organizationVo.getHandle().equals(model.getCumc())) +// .peek(model -> model.setChildren(createChildList(model, organizationVoList))) +// .sorted((Comparator.comparing(BaseBomComponent::getComponent))).collect(Collectors.toList()); +// } + + + +// public List findByTree(BaseBomComponent baseBomComponent) { +// List node = findByTree(treeList); +// System.out.println(node); +// return node; +// } + + /** + * 递归方法转换成树形结构 + * @param baseBomComponent + * @return + */ + @Override + @DS("#header.poolName") + public List selectBaseBomComponentList(BaseBomComponent baseBomComponent){ + List trees = new ArrayList<>();//新创建 + List baseBomComponentList = baseBomComponentMapper.selectBaseBomComponentList(baseBomComponent);//查询baseBomComponent + List filterBaseBomComponentList = baseBomComponentMapper.selectBomCodeList(baseBomComponent);//查询BomCodeList + List filterCumcList = baseBomComponentMapper.selectProductCodeList(baseBomComponent);//查询BomCodeList + //查询cumc 是否存在于product_code + for (BaseBomComponent tree : baseBomComponentList) { + //找出父节点 + boolean bool1 = filterBaseBomComponentList.contains(tree.getBomCode());//查询父节点是否在bom表中 + boolean bool2 = filterCumcList.contains(tree.getCumc());//查询节点是否是父节点 + if (bool1 && bool2) { + // 调用递归方法填充子节点列表 + trees.add(findChildren(tree,baseBomComponentList));//找到孩子节点 + } + } + return trees; + } + + /** + * 递归方法 + * @param baseBomComponent 父节点对象 + * @param baseBomComponentList 所有的List + * @return + */ + + public BaseBomComponent findChildren(BaseBomComponent baseBomComponent, List baseBomComponentList) { + //父 Cumc 子Component + for (BaseBomComponent node : baseBomComponentList) { + if (baseBomComponent.getComponent().equals(node.getCumc())) { + if (baseBomComponent.getChildren() == null) { + baseBomComponent.setChildren(new ArrayList<>()); + } + // 递归调用自身 + baseBomComponent.getChildren().add(findChildren(node, baseBomComponentList)); + } + } + return baseBomComponent; + } } diff --git a/op-modules/op-wms/src/main/resources/mapper/wms/BaseBomComponentMapper.xml b/op-modules/op-wms/src/main/resources/mapper/wms/BaseBomComponentMapper.xml index 764914fc..ed58c6ac 100644 --- a/op-modules/op-wms/src/main/resources/mapper/wms/BaseBomComponentMapper.xml +++ b/op-modules/op-wms/src/main/resources/mapper/wms/BaseBomComponentMapper.xml @@ -5,7 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -32,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, bom_code, site, product_code, cumc, component, bom_hierarchy, project_no, standard_dosage, loss_rate, loss_amount, cilosses, component_unit, component_pro_flag, msi, sanka, attr1, attr2, attr3, create_by, create_time, update_by, update_time, remark from base_bom_component + select handle, bom_code, site, product_code, cumc, component, bom_hierarchy, project_no, standard_dosage, loss_rate, loss_amount, cilosses, component_unit, component_pro_flag, msi, sanka, attr1, attr2, attr3, create_by, create_time, update_by, update_time, remark from base_bom_component - where id = #{id} + where handle = #{handle} insert into base_bom_component - id, + handle, bom_code, site, product_code, @@ -93,7 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" remark, - #{id}, + #{handle}, #{bomCode}, #{site}, #{productCode}, @@ -157,7 +157,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from base_bom_component where id in - #{id} + #{handle} + + + + + \ No newline at end of file