Parcourir la source

BOM预处理调整。

tangdi il y a 3 ans
Parent
commit
d308be93a3

+ 97 - 39
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -21,6 +21,7 @@ using Hangfire.Storage.Monitoring;
 using Business.BookManagement.Dto;
 using Volo.Abp.ObjectMapping;
 using Volo.Abp.Application.Services;
+using ZstdSharp.Unsafe;
 
 namespace Business.ResourceExamineManagement
 {
@@ -31,30 +32,22 @@ namespace Business.ResourceExamineManagement
     public class ResourceExamineAppService : ApplicationService, IResourceExamineAppService
     {
         #region 服务
-        //private IRepository<ic_item, long> _ic_item;
-        //private IRepository<ic_bom, long> _ic_bom;
-
-        ///// <summary>
-        ///// 工艺路径
-        ///// </summary>
-        //private IRepository<mes_technique, long> _mes_technique;
-
-        ///// <summary>
-        ///// 工序
-        ///// </summary>
-        //private IRepository<mes_process, long> _mes_process;
-
-        ///// <summary>
-        ///// 工艺关联工序
-        ///// </summary>
-        //private IRepository<mes_tech_process, long> _mes_tech_process;
-
-        ///// <summary>
-        ///// 排程占用记录
-        ///// </summary>
-        //private IRepository<mes_schedule_occupy, long> _mes_schedule_occupy;
-
+        /// <summary>
+        /// 工艺路径
+        /// </summary>
         private readonly IMongoDB<mes_technique> _mes_technique;
+        /// <summary>
+        /// 物料详情
+        /// </summary>
+        private readonly IMongoDB<ic_item> _ic_item;
+        /// <summary>
+        /// 物料BOM
+        /// </summary>
+        private readonly IMongoDB<ic_bom> _ic_bom;
+        /// <summary>
+        /// 物料BOM明细
+        /// </summary>
+        private readonly IMongoDB<ic_bom_child> _ic_bom_child;
         #endregion
 
         /// <summary>
@@ -63,10 +56,16 @@ namespace Business.ResourceExamineManagement
         /// <param name="icitem"></param>
         /// <param name="icbom"></param>
         public ResourceExamineAppService(
-            IMongoDB<mes_technique> mes_technique
+            IMongoDB<mes_technique> mes_technique,
+            IMongoDB<ic_item> ic_item,
+            IMongoDB<ic_bom> ic_bom,
+            IMongoDB<ic_bom_child> ic_bom_child
             )
         {
             _mes_technique = mes_technique;
+            _ic_item = ic_item;
+            _ic_bom = ic_bom;
+            _ic_bom_child = ic_bom_child;
         }
 
         /// <summary>
@@ -88,21 +87,6 @@ namespace Business.ResourceExamineManagement
         }
 
 
-        /// <summary>
-        /// BOM预处理
-        /// </summary>
-        /// <param name="orderid">订单行id</param>
-        /// <param name="BomId">Bom主键</param>
-        /// <param name="Quantity">需要数量</param>
-        public async Task BomPretreatmentAsync(long? orderid, long? BomId, int Quantity)
-        {
-            //if (BomId == null)
-            //{
-            //    //throw new bu
-            //}
-
-            //var query = (await _ic_bom.GetQueryableAsync()).WhereIf(true, a => a.bom_id == BomId).ToList();
-        }
 
         /// <summary>
         /// 产能计算
@@ -130,5 +114,79 @@ namespace Business.ResourceExamineManagement
             // 订单状态为 初始或下达工单
             // List =>数量满足Quantity && 生成工单结束日期最早
         }
+
+        public async Task BomPretreatmentAsync(long? orderid, long? BomId, int Quantity)
+        {
+            if (orderid == null)
+            {
+                //throw new bu
+            }
+            if (BomId == null)
+            {
+                //throw new bu
+            }
+
+            //var query = (await _ic_bom.GetQueryableAsync()).WhereIf(true, a => a.bom_id == BomId).ToList();
+            //var help = new SnowFlake();
+            //var id = help.NextId();
+            var level = 0;
+            var bomlist = _ic_bom.GetAll().Result;
+            var bomchildlist = _ic_bom_child.GetAll().Result;
+            var icitemlist = _ic_item.GetAll().Result;
+            //GetBomListAsync();
+        }
+
+
+        public void GetBomList(List<ic_bom> bomlist, List<ic_bom_child> bomchildlist, List<ic_item> icitemlist, long bomId, List<BomChildExamineDto> returnlist, long? parent_id, int le)
+        {
+            int level = le++;//初始化定义level层级
+            var help = new SnowFlake();
+
+            var bom = bomlist.WhereIf(true, s => s.bom_id == bomId).FirstOrDefault();
+            if (bom == null)
+            {
+
+            }
+            var dto = new BomChildExamineDto();
+            dto.level = level;
+            dto.bom_id = bomId;
+            dto.id = help.NextId();
+            dto.parent_id = parent_id;
+            dto.item_id = bom.icitem_id;
+            dto.item_name = bom.item_name;
+            dto.item_code = bom.item_number;
+            //var bdto = ObjectMapper.Map<ic_bom,BomChildExamineDto>(bom);
+            returnlist.Add(dto);
+            var childlist = bomchildlist.WhereIf(true, a => a.bom_id == bom.bom_id).ToList();
+            foreach (var c in childlist)
+            {
+                var icitem = icitemlist.WhereIf(true, a => a.icitem_id == c.icitem_id).FirstOrDefault();
+                //如果此明细查的到BOM信息,则代表此child是一个子BOM。
+                if (c.is_bom == 1)
+                {
+                    var childBom = bomlist.WhereIf(true, a => a.icitem_id == c.icitem_id).FirstOrDefault();
+                    if (childBom != null)
+                    {
+                        GetBomList(bomlist, bomchildlist, icitemlist, childBom.bom_id, returnlist, dto.id, level);
+                    }
+                }
+                else
+                {
+                    if (icitem != null)
+                    {
+                        var childDto = new BomChildExamineDto();
+                        childDto.level = level++;
+                        childDto.bom_id = bomId;
+                        childDto.id = help.NextId();
+                        childDto.parent_id = parent_id;
+                        childDto.item_id = icitem.icitem_id;
+                        childDto.item_name = icitem.name;
+                        childDto.item_code = icitem.number;
+                        returnlist.Add(childDto);
+                    }
+                }
+            }
+
+        }
     }
 }

+ 3 - 2
MicroServices/Business/Bussiness.Model/MES/IC/ic_bom.cs

@@ -1,4 +1,5 @@
-using Business.Model;
+using Business.Core.Attributes;
+using Business.Model;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -14,7 +15,7 @@ namespace Bussiness.Model.MES.IC
     /// <summary>
     /// 物料BOM
     /// </summary>
-    [Table("ic_bom")]
+    [CollectionName("dopbase", "ic_bom")]
     public class ic_bom : BaseEntity
     {
         /// <summary>

+ 3 - 1
MicroServices/Business/Bussiness.Model/MES/IC/ic_bom_child.cs

@@ -1,4 +1,5 @@
-using Business.Model;
+using Business.Core.Attributes;
+using Business.Model;
 using Microsoft.EntityFrameworkCore;
 using System.ComponentModel;
 using System.ComponentModel.DataAnnotations;
@@ -8,6 +9,7 @@ namespace Bussiness.Model.MES.IC
     /// <summary>
     /// 物料BOM明细
     /// </summary>
+    [CollectionName("dopbase", "ic_bom_child")]
     public class ic_bom_child : BaseEntity
     {
         /// <summary>

+ 3 - 1
MicroServices/Business/Bussiness.Model/MES/IC/ic_item.cs

@@ -1,4 +1,5 @@
-using Business.Model;
+using Business.Core.Attributes;
+using Business.Model;
 using Microsoft.EntityFrameworkCore;
 using System.ComponentModel;
 using System.ComponentModel.DataAnnotations;
@@ -8,6 +9,7 @@ namespace Bussiness.Model.MES.IC
     /// <summary>
     /// 物料详情
     /// </summary>
+    [CollectionName("dopbase", "ic_item")]
     public class ic_item : BaseEntity
     {
         /// <summary>