heteng 3 lat temu
rodzic
commit
ad48398f90

+ 153 - 3
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -25,6 +25,8 @@ using ZstdSharp.Unsafe;
 using System.Transactions;
 using NUglify.JavaScript.Syntax;
 using System.Linq.Expressions;
+using Volo.Abp.Validation.StringValues;
+using System.Runtime.CompilerServices;
 
 namespace Business.ResourceExamineManagement
 {
@@ -40,6 +42,11 @@ namespace Business.ResourceExamineManagement
         /// </summary>
         private readonly IMongoDB<mes_technique> _mes_technique;
 
+        /// <summary>
+        /// 工序
+        /// </summary>
+        private readonly IMongoDB<mes_process> _mes_process;
+
         /// <summary>
         /// 工艺关联工序
         /// </summary>
@@ -157,6 +164,9 @@ namespace Business.ResourceExamineManagement
         /// <exception cref="NotImplementedException"></exception>
         public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
         {
+            //测试代码
+            await test();
+            
             return null;
             throw new NotImplementedException();
 
@@ -167,12 +177,152 @@ namespace Business.ResourceExamineManagement
         /// <summary>
         /// 产能计算
         /// </summary>
-        /// <param name="BomId">Bom主键</param>
-        /// <param name="Quantity">需要数量</param>
-        public async Task ProductiveExamine(long? BomId, int Quantity)
+        /// <param name="tech_id">工艺路径主键</param>
+        /// <param name="packages">需要生产产品件数</param>
+        /// <param name="quantity">需要生产数量</param>
+        public async Task<DateTime> ProductiveExamine(long tech_id, int packages, int quantity)
         {
+            if (packages <=0 ||quantity <= 0)
+            {
+                throw new NotImplementedException("产能计算参数有误!");
+            }
+            #region 1、数据准备
+            //1.1、获取工艺路径数据
+            mes_technique tech = _mes_technique.GetOneByID(tech_id).Result;
+
+            //1.2、获取工艺路径关联工序数据
+            List<mes_tech_process> tech_Processes = _mes_tech_process.GetManyByCondition(x => x.tech_id == tech_id).Result;
+
+            //1.3、获取当前工艺路径下的工序数据
+            List<mes_process> process = _mes_process.GetManyByCondition(p => p.Id.IsIn(tech_Processes.Select(m => m.proc_id))).Result;
+
+            //1.3、获取工艺工序关联工位信息
+            List<mes_tech_proc_workshop> tech_Proc_Workshops = _mes_tech_proc_workshop.GetManyByCondition(x => x.tech_proc_id.IsIn<long>(tech_Processes.Select(m => m.Id))).Result;
+
+            //1.4、获取工位占用情况
+            //List<mes_schedule_occupy> schedule_Occupies = _mes_schedule_occupy.GetManyByCondition().Result;
+            #endregion
+
+            #region 计算产能,得到耗时
+            /*产能计算有两种模式:1-UPH;2-节拍时间
+             *1、根据工艺路径设置的效率计算层级,来获取参与产能计算的所有工序/子工序
+             *2、根据当前工序设置的计算模式UPH/节拍时间来计算当前工序生产所需时间T1
+             *3、当前工序生产所需时间T1*效率系数Rate得到实际的生产所需时间T2(流水线不需要*效率系数)
+             *4、当前工序实际生产所需时间T2+当前工序前置准备时间得到当前工序生产所需总时间
+             *5、所有工序生产总时间加起来得到生产所需总时间
+            */
+            //1、获取参与计算的所有工序/子工序
+            var tech_pro_list = tech_Processes.Where(p => p.level == tech.level).ToList();
+            //生产总时间(分钟)
+            decimal sumTimes = 0.00m;
+            //记录按照CT参与计算的工序的父级Id
+            List<long> exists = new List<long>();
+            foreach (var item in tech_pro_list)
+            {
+                //数据校验
+                //获取当前工序
+                var curProcess = process.FirstOrDefault(p => p.Id == item.proc_id);
+                if (item.type == 1 && item.ct == 0)
+                {
+                    throw new NotImplementedException(string.Format("工艺[{0}]下的工序[{1}]节拍时间设置有误,请调整!",tech.tech_name, curProcess.proc_name));
+                }
+                if (item.type == 2 && item.uph == 0)
+                {
+                    throw new NotImplementedException(string.Format("工艺[{0}]下的工序[{1}]UPH设置有误,请调整!", tech.tech_name, curProcess.proc_name));
+                }
+
+                if (item.parentprocid != null)//存在父子级关系
+                {
+                    //判断当前父级是否已经参与过计算
+                    if (exists.Contains(item.parentprocid.Value))
+                    {
+                        continue;
+                    }
+                    //记录父级id
+                    exists.Add(item.parentprocid.Value);
+                    //获取同一父级下的子工序
+                    var childs = tech_Processes.Where(p => p.parentprocid == item.parentprocid).ToList();
+                    decimal maxTime = 0.00m;//记录同一父级下最大耗时
+                    decimal time = 0.00m;
+                    //2、两种计算模式UPH/节拍时间
+                    if (item.type == 2)//UPH(每小时生产个数),取同一父级下最长耗时
+                    {
+                        foreach (var chd in childs)
+                        {
+                            //当前工序消耗时间
+                            time = quantity / item.uph.Value * 60 * item.effect_ratio.Value;
+                            if (time > maxTime)
+                            {
+                                maxTime = time;
+                            }
+                        }
+                        sumTimes += maxTime;
+                        continue;
+                    }
+                    //3、根据节拍时间计算
+                    //sum(CT)
+                    decimal sumCT = childs.Sum(p => p.ct.Value);
+                    //max(CT)
+                    decimal maxCT = childs.OrderByDescending(p => p.ct).FirstOrDefault().ct.Value;
+                    //sum(LT)
+                    decimal sumLT = childs.Sum(p => p.readytime.Value);
+                    //当前流水线消耗时间
+                    sumTimes += (packages - 1) * maxCT + sumCT + sumLT;
+                }
+                else{//不存在父子级关系
+                    //2、两种计算模式UPH/节拍时间
+                    if (item.type == 2)//uph
+                    {
+                        //当前工序消耗时间
+                        sumTimes += quantity / item.uph.Value * 60 * item.effect_ratio.Value + item.readytime.Value;
+                        //计算完成,进行下一次循环
+                        continue;
+                    }
+                    //节拍时间:流水线,从流水线起始工序开始计算
+                    if (item.preprocid != null)
+                    {
+                        //上-工序Id不为null,说明不是流水线起始工序,进行下一次循环
+                        continue;
+                    }
+                    List<mes_tech_process> allProcess = new List<mes_tech_process>();
+                    //递归,获取起始工序的后续工序
+                    GetNextProcess(tech_Processes, item, allProcess);
+                    //sum(CT)
+                    decimal sumCT = allProcess.Sum(p => p.ct.Value);
+                    //max(CT)
+                    decimal maxCT = allProcess.OrderByDescending(p => p.ct).FirstOrDefault().ct.Value;
+                    //sum(LT)
+                    decimal sumLT = allProcess.Sum(p => p.readytime.Value);
+                    //当前流水线消耗时间
+                    sumTimes += (packages - 1) * maxCT + sumCT + sumLT;
+                }
+            }
+            #endregion
 
+            return DateTime.Now.AddDays(1).AddMinutes((double)sumTimes);
         }
+
+        /// <summary>
+        /// 递归获取工序
+        /// </summary>
+        /// <param name="tech_Processes"></param>
+        /// <param name="item"></param>
+        /// <returns></returns>
+        private void GetNextProcess(List<mes_tech_process> tech_Processes, mes_tech_process item, List<mes_tech_process> allProcess)
+        {
+            allProcess.Add(item);
+            //判断下一工序id是否为null
+            if (item.nextprocid != null)
+            {
+                var nextProc = tech_Processes.FirstOrDefault(p => p.proc_id == item.nextprocid);
+                GetNextProcess(tech_Processes, nextProc, allProcess);
+            }
+        }
+
+
+
+
+
         /// <summary>
         /// 检查在制工单
         /// </summary>

+ 1 - 1
MicroServices/Business/Bussiness.Model/Production/mes_schedule_occupy.cs

@@ -57,7 +57,7 @@ namespace Bussiness.Model.Production
         [Description("生产组织id")]
         public long prd_org_id { get; set; }
         /// <summary>
-        /// 工作中心id
+        /// 工作中心id:工位id
         /// </summary>
         [Description("工作中心id")]
         public long work_center_id { get; set; }

+ 6 - 0
MicroServices/Business/Bussiness.Model/Tech/mes_tech_process.cs

@@ -88,6 +88,12 @@ namespace Bussiness.Model.Tech
         [Description("是否需要跟踪工序")]
         public int? mototrack { get; set; }
 
+        /// <summary>
+        /// 上一工序id
+        /// </summary>
+        [Description("上一工序id")]
+        public long? preprocid { get; set; }
+
         /// <summary>
         /// 下一工序id
         /// </summary>