diff --git a/ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpBomController.java b/ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpBomController.java index eff6abb5..f1e5abaf 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpBomController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpBomController.java @@ -54,18 +54,29 @@ public class ErpBomController extends BaseController } /** - * 查询bom子列表 + * 查询bom一阶列表 */ - @RequiresPermissions("erp:bom:list") - @PostMapping("/subList") + @PostMapping("/oneLevelList") @ResponseBody - public TableDataInfo subList(ErpBom erpBom) + public TableDataInfo oneLevelList(ErpBom erpBom) { startPage(); List list = erpBomService.selectErpBomSubList(erpBom); return getDataTable(list); } + /** + * 查询bom所有阶列表 + */ + @PostMapping("/allLevelList") + @ResponseBody + public TableDataInfo allLevelList(ErpBom erpBom) + { + startPage(); + List list = erpBomService.selectErpBomAllLevelList(erpBom); + return getDataTable(list); + } + /** * 导出bom列表 */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/erp/mapper/ErpBomMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/erp/mapper/ErpBomMapper.java index de2bc3b9..861f7282 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/erp/mapper/ErpBomMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/erp/mapper/ErpBomMapper.java @@ -20,6 +20,9 @@ public interface ErpBomMapper */ public ErpBom selectErpBomById(Long id); + public ErpBom selectErpBomByOneMaterialNo(String materialNo); + + /** * 查询bom列表 * diff --git a/ruoyi-admin/src/main/java/com/ruoyi/erp/service/IErpBomService.java b/ruoyi-admin/src/main/java/com/ruoyi/erp/service/IErpBomService.java index 171ce7f3..8a13220c 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/erp/service/IErpBomService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/erp/service/IErpBomService.java @@ -30,6 +30,8 @@ public interface IErpBomService List selectErpBomSubList(ErpBom erpBom); + List selectErpBomAllLevelList(ErpBom erpBom); + /** * 新增bom * diff --git a/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpBomServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpBomServiceImpl.java index aa59f075..574d5de9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpBomServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpBomServiceImpl.java @@ -15,7 +15,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.stream.Collectors; /** * bomService业务层处理 @@ -64,6 +67,42 @@ public class ErpBomServiceImpl implements IErpBomService return erpBomMapper.selectErpBomSubList(erpBom); } + @Override + public List selectErpBomAllLevelList(ErpBom erpBom) { + List resultList = new ArrayList<>(); + // 一阶集合 + List oneLevelList = erpBomMapper.selectErpBomSubList(erpBom); + if(CollectionUtils.isNotEmpty(oneLevelList)){ + for (ErpBom bom: oneLevelList) { + resultList.add(bom); + String materialNo = bom.getMaterialNo(); + Long level = bom.getLevel(); + recursionSubBom(resultList, materialNo, level); + } + } + + return resultList; + } + + private void recursionSubBom(List resultList, String materialNo, Long level) { + ErpBom subBom = erpBomMapper.selectErpBomByOneMaterialNo(materialNo); + if(subBom!=null){ + Long subId = subBom.getId(); + ErpBom erpBom1 = new ErpBom(); + erpBom1.setParentId(subId); + List subLevelList = erpBomMapper.selectErpBomSubList(erpBom1); + if(CollectionUtils.isNotEmpty(subLevelList)){ + for (ErpBom sub: subLevelList) { + Long level1 = level+1; + sub.setLevel(level1); + resultList.add(sub); + String materialNo1 = sub.getMaterialNo(); + recursionSubBom(resultList,materialNo1,level1); + } + } + } + } + /** * 新增bom * diff --git a/ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml b/ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml index e03920e0..b6a127ed 100644 --- a/ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml @@ -270,4 +270,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select * from erp_bom where bom_no = #{bomNo} + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/erp/bom/bom.html b/ruoyi-admin/src/main/resources/templates/erp/bom/bom.html index 903538ee..093058f0 100644 --- a/ruoyi-admin/src/main/resources/templates/erp/bom/bom.html +++ b/ruoyi-admin/src/main/resources/templates/erp/bom/bom.html @@ -127,7 +127,13 @@ detailView: true, //指定父id列 onExpandRow : function(index, row, $detail) { - initChildTable(index, row, $detail); + $detail.html('

一阶

' + + '

多阶

' + ).find('table'); + // 一阶 + initOneLevelTable(index,row,$detail); + // 多阶 + initAllLevelTable(index,row,$detail); }, columns: [{ checkbox: true @@ -296,18 +302,156 @@ $.table.init(options); }); - initChildTable = function(index, row, $detail) { - var childTable = $detail.html('
').find('table'); - $(childTable).bootstrapTable({ - url: prefix + "/subList", + initOneLevelTable = function(index, row, $detail) { + $("#"+"one_level_table_"+row.id).bootstrapTable({ + url: prefix + "/oneLevelList", method: 'post', sidePagination: "server", contentType: "application/x-www-form-urlencoded", queryParams : { parentId: row.id }, - onExpandRow : function(index, row, $detail) { - initChildSonTable(index, row, $detail); + columns: [{ + field: 'id', + title: '主键id' + }, + { + field: 'level', + title: '层级', + formatter: function(value, row, index) { + return $.table.selectDictLabel(levelDatas, value); + } + }, + { + field: 'bomNo', + title: 'bom号', + formatter:function (value,row,index){ + if (value == null || value == ''){ + return '/'; + }else{ + return value + } + } + }, + { + field: 'photoUrl', + title: '图片', + formatter: function(value, row, index) { + return $.table.imageView(value); + } + }, + { + field: 'materialNo', + title: '料号', + formatter: function (value,row,index){ + if (value == null || value == ''){ + return '/'; + }else{ + return value + } + } + }, + { + field: 'materialName', + title: '物料名称', + formatter: function (value,row,index){ + if (value == null || value == ''){ + return '/'; + }else{ + return value + } + } + }, + { + field: 'materialType', + title: '物料类型', + formatter: function(value, row, index) { + return $.table.selectCategoryLabel(materialTypeDatas, value); + } + }, + { + field: 'describe', + title: '描述', + formatter: function (value,row,index){ + if (value == null || value == ''){ + return '/'; + }else{ + return value + } + } + }, + + { + field: 'brand', + title: '品牌', + formatter: function (value,row,index){ + if (value == null || value == ''){ + return '/'; + }else{ + return value + } + } + }, + { + field: 'unit', + title: '单位', + formatter: function (value,row,index){ + if (value == null || value == ''){ + return '/'; + }else{ + return value + } + } + }, + { + field: 'useNum', + title: '用量', + formatter: function (value,row,index){ + if (value == null || value == ''){ + return '/'; + }else{ + return value + } + } + }, + { + field: 'lossRate', + title: '损耗率', + formatter: function (value,row,index){ + if (value == null || value == ''){ + return '/'; + }else{ + return value + } + } + }, + { + field: 'processMethod', + title: '加工方式', + formatter: function(value, row, index) { + return $.table.selectDictLabel(processMethodDatas, value); + } + }, + { + field: 'parentId', + title: '父级id', + visible: false, + }, + { + field: 'sortNo', + title: '排序', + visible: false + }] + }); + }; + initAllLevelTable = function(index, row, $detail) { + $("#"+"all_level_table_"+row.id).bootstrapTable({ + url: prefix + "/allLevelList", + method: 'post', + sidePagination: "server", + contentType: "application/x-www-form-urlencoded", + queryParams : { + parentId: row.id }, columns: [{ field: 'id',