Browse Source

产能计算添加工序多分支场景

heteng 3 years ago
parent
commit
7ef71598bf

+ 45 - 36
MicroServices/Business/Business.Application/ResourceExamineManagement/ProductExamineAppService.cs

@@ -99,7 +99,7 @@ namespace Business.ResourceExamineManagement
             //1.3、获取当前工艺路径下的工序数据
             //FilterDefinition<mes_process> filter = Builders<mes_process>.Filter.In(s => s.Id, tech_Processes.Select(m => m.proc_id).ToList());
             //List<mes_process> process = await _mes_process.GetManyByIds(filter);
-            List<long> procIds = tech_Processes.Select(m => m.proc_id.Value).ToList();
+            List<long> procIds = tech_Processes.Select(m => m.proc_id.GetValueOrDefault()).ToList();
             List<mes_process> process = await _mes_process.GetManyByCondition(p => procIds.Contains(p.Id) && p.tenant_id == param.tenantId && p.factory_id == param.factoryId && !p.IsDeleted);
 
             //1.3、获取工艺工序关联工位信息
@@ -119,22 +119,6 @@ namespace Business.ResourceExamineManagement
             return sumTimes;
         }
 
-        /// <summary>
-        /// 递归:工序按照先后顺序排序-暂时不考虑两个分支合并到一个分支的情况
-        /// </summary>
-        /// <param name="Processes"></param>
-        /// <param name="processId"></param>
-        /// <param name="sortProcesses"></param>
-        private void SortProcess(List<mes_tech_process> Processes, long processId, List<mes_tech_process> sortProcesses)
-        {
-            var curProcess = Processes.Where(p => p.nextprocid == processId).FirstOrDefault();
-            if (curProcess != null)
-            {
-                sortProcesses.AddFirst(curProcess);
-                SortProcess(Processes, curProcess.proc_id.Value, sortProcesses);
-            }
-        }
-
         /// <summary>
         /// 工序预处理,按照多分支生成多条单独的工艺路径
         /// </summary>
@@ -148,9 +132,9 @@ namespace Business.ResourceExamineManagement
             List<TechProcDto> techProcDtos = new List<TechProcDto>();
             TechProcDto dto;
             //获取下一步工序id
-            List<long> nextProcIds = processes.Select(p => p.nextprocid.Value).ToList();
+            List<long> nextProcIds = processes.Where(p=>p.nextprocid != null).Select(p => p.nextprocid.GetValueOrDefault()).ToList();
             //获取起点工序
-            var startProcs = processes.Where(p => !nextProcIds.Contains(p.proc_id.Value)).ToList();
+            var startProcs = processes.Where(p => !nextProcIds.Contains(p.proc_id.GetValueOrDefault())).ToList();
             //递归处理工序返回值
             List<mes_tech_process> rtnList;
             for (int i = 0; i < startProcs.Count; i++)
@@ -158,11 +142,12 @@ namespace Business.ResourceExamineManagement
                 dto = new TechProcDto();
                 rtnList = new List<mes_tech_process>();
                 GetNextProc(startProcs[i], processes, rtnList);
-                dto.serialno = i;
+                dto.serialno = i + 1;
                 dto.processes = rtnList;
-                //dto.startTimes = CalcTakeTimeByLq(rtnList, packages);//通过Lq计算
-                dto.details = CalcTakeTimeByLqt(rtnList, packages);//通过Lqt计算
+                dto.details = CalcTakeTimeByLq(rtnList, packages);//通过Lq计算
+                //dto.details = CalcTakeTimeByLqt(rtnList, packages);//通过Lqt计算
                 dto.sumTimes = dto.details.Sum(p=>p.wait_time);
+                techProcDtos.Add(dto);
             }
             return techProcDtos;
         }
@@ -211,7 +196,7 @@ namespace Business.ResourceExamineManagement
                 }
                 else
                 {
-                    dto = CalcProcTakeTimeByLq(chd, chd.lq.Value, packages);
+                    dto = CalcProcTakeTimeByLq(chd, chd.lq.GetValueOrDefault(), packages);
                 }
                 //添加记录
                 starts.Add(dto);
@@ -231,23 +216,35 @@ namespace Business.ResourceExamineManagement
             //记录当前工序耗时
             StartTimeDto dto = new StartTimeDto();
             //添加耗时记录
-            dto.tech_id = proc.tech_id.Value;
-            dto.proc_id = proc.proc_id.Value;
+            dto.tech_id = proc.tech_id.GetValueOrDefault();
+            dto.proc_id = proc.proc_id.GetValueOrDefault();
             dto.nextproc_id = proc.nextprocid;
             if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
             {
-                dto.wait_time = quantity / proc.uph.Value * 60 / proc.wsinuse.Value;
-                dto.take_time = packages / proc.uph.Value * 60 / proc.wsinuse.Value;
+                if ( proc.uph.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
+                {
+                    throw new NotImplementedException("当前工序uph或wsinuse参数配置错误,请调整!");
+                }
+                dto.wait_time = quantity / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
+                dto.take_time = packages / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
             }
             else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
             {
-                dto.wait_time = quantity * proc.ct.Value / proc.wsinuse.Value;
-                dto.take_time = packages * proc.ct.Value / proc.wsinuse.Value;
+                if (proc.ct.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
+                {
+                    throw new NotImplementedException("当前工序ct或wsinuse参数配置错误,请调整!");
+                }
+                dto.wait_time = quantity * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
+                dto.take_time = packages * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
             }
             else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
             {
-                dto.wait_time = Math.Ceiling(quantity / proc.upe.Value / proc.wsinuse.Value) * proc.ct.Value;
-                dto.take_time = Math.Ceiling(packages / proc.upe.Value / proc.wsinuse.Value) * proc.ct.Value;
+                if (proc.upe.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0|| proc.ct.GetValueOrDefault() == 0)
+                {
+                    throw new NotImplementedException("当前工序upe或ct或wsinuse参数配置错误,请调整!");
+                }
+                dto.wait_time = Math.Ceiling(quantity / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
+                dto.take_time = Math.Ceiling(packages / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
             }
             return dto;
         }
@@ -267,8 +264,8 @@ namespace Business.ResourceExamineManagement
             {
                 dto = new StartTimeDto();
                 //添加耗时记录
-                dto.tech_id = chd.tech_id.Value;
-                dto.proc_id = chd.proc_id.Value;
+                dto.tech_id = chd.tech_id.GetValueOrDefault();
+                dto.proc_id = chd.proc_id.GetValueOrDefault();
                 dto.nextproc_id = chd.nextprocid;
 
                 //计算当前工序生产耗时
@@ -300,15 +297,27 @@ namespace Business.ResourceExamineManagement
 
             if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
             {
-                takeTiem = packages / proc.uph.Value * 60 / proc.wsinuse.Value;
+                if (proc.uph.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
+                {
+                    throw new NotImplementedException("当前工序uph或wsinuse参数配置错误,请调整!");
+                }
+                takeTiem = packages / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
             }
             else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
             {
-                takeTiem = packages * proc.ct.Value / proc.wsinuse.Value;
+                if (proc.ct.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
+                {
+                    throw new NotImplementedException("当前工序ct或wsinuse参数配置错误,请调整!");
+                }
+                takeTiem = packages * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
             }
             else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
             {
-                takeTiem = Math.Ceiling(packages / proc.upe.Value / proc.wsinuse.Value) * proc.ct.Value;
+                if (proc.upe.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0 || proc.ct.GetValueOrDefault() == 0)
+                {
+                    throw new NotImplementedException("当前工序upe或ct或wsinuse参数配置错误,请调整!");
+                }
+                takeTiem = Math.Ceiling(packages / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
             }
             return takeTiem;
         }