فهرست منبع

产能计算调整

heteng 3 سال پیش
والد
کامیت
9996097784

+ 34 - 0
MicroServices/Business/Business.Application.Contracts/ResourceExamineManagement/Dto/StartTimeDto.cs

@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.ResourceExamineManagement.Dto
+{
+    /// <summary>
+    /// 工序等待时间
+    /// </summary>
+    public class StartTimeDto
+    {
+        /// <summary>
+        /// 工艺Id
+        /// </summary>
+        public long tech_id { get; set; }
+
+        /// <summary>
+        /// 工序id
+        /// </summary>
+        public long proc_id { get; set; }
+
+        /// <summary>
+        /// 下一工序id
+        /// </summary>
+        public long? nextproc_id { get; set; }
+
+        /// <summary>
+        /// 下一工序需要等待时长,如果是最后一个工序的话,就是最后一个工序生产所需时间
+        /// </summary>
+        public decimal wait_time { get; set; }
+    }
+}

+ 46 - 105
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -249,7 +249,7 @@ namespace Business.ResourceExamineManagement
         }
 
         /// <summary>
-        /// 产能计算
+        /// 产能计算V2.0
         /// </summary>
         /// <param name="tech_id">工艺路径主键</param>
         /// <param name="packages">需要生产产品件数</param>
@@ -273,105 +273,39 @@ namespace Business.ResourceExamineManagement
             //1.3、获取工艺工序关联工位信息
             FilterDefinition<mes_tech_proc_workshop> filter1 = Builders<mes_tech_proc_workshop>.Filter.In(s => s.tech_proc_id, tech_Processes.Select(m => m.Id).ToList());
             List<mes_tech_proc_workshop> tech_Proc_Workshops = await _mes_tech_proc_workshop.GetManyByIds(filter1);
-
-            //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)
+            decimal sumTimes = 0.00m;//总耗时(分钟)
+            //工序需要等待时间记录
+            List<StartTimeDto> starts = new List<StartTimeDto>();
+            //1、获取工艺路径下的第一层级工序
+            List<mes_tech_process> fistChilds = tech_Processes.Where(p=>p.parentprocid == tech_id).OrderBy(m=>m.Id).ToList();
+            if (fistChilds.Count == 0)
             {
-                //数据校验
-                //获取当前工序
-                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)//存在父子级关系
+                throw new NotImplementedException("当前工艺路径没有配置工序,请调整!");
+            }
+            decimal curTakeTime = 0.00m;//当前工序耗时(分钟)
+            //添加第一个工序需要等待时间记录
+            StartTimeDto dto;
+            foreach (var chd in fistChilds)
+            {
+                dto = new StartTimeDto();
+                if (chd.nextprocid == 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)
-                        {
-                            //当前工序消耗时间:件数*单位数量/uph*60*效率系数+前置准备时间
-                            time = packages * chd.upp.Value / chd.uph.Value * 60 * chd.effect_ratio.Value + chd.readytime.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;
+                    //计算最后一个工序耗时
+                    curTakeTime = CalcTakeTime(chd, packages);
                 }
-                else
-                {//不存在父子级关系
-                    //2、两种计算模式UPH/节拍时间
-                    if (item.type == 2)//uph
-                    {
-                        //当前工序消耗时间:件数*单位数量/uph*60*效率系数+前置准备时间
-                        sumTimes += packages * item.upp.Value / item.uph.Value * 60 * item.effect_ratio.Value + item.readytime.Value;
-                        //计算完成,进行下一次循环
-                        continue;
-                    }
-                    //节拍时间:流水线,从流水线最后工序开始计算
-                    if (item.nextprocid != null)
-                    {
-                        //下-工序Id不为null,说明不是流水线最终工序,进行下一次循环
-                        continue;
-                    }
-                    List<mes_tech_process> allProcess = new List<mes_tech_process>();
-                    //递归,获取最终工序的上一工序
-                    GetPreProcess(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;
+                else {
+                    curTakeTime = CalcTakeTime(chd, chd.lq.Value);
                 }
+                sumTimes += curTakeTime;
+                //添加耗时记录
+                dto.tech_id = tech_id;
+                dto.proc_id = chd.proc_id;
+                dto.nextproc_id = chd.nextprocid;
+                dto.wait_time = curTakeTime;
+                starts.Add(dto);
             }
             #endregion
 
@@ -379,26 +313,33 @@ namespace Business.ResourceExamineManagement
         }
 
         /// <summary>
-        /// 递归获取工序
+        /// 计算当前工序前置准备时间
         /// </summary>
-        /// <param name="tech_Processes"></param>
-        /// <param name="item"></param>
+        /// <param name="proc"></param>
+        /// <param name="quantity">LeadQuantity to Start Next</param>
         /// <returns></returns>
-        private void GetPreProcess(List<mes_tech_process> tech_Processes, mes_tech_process item, List<mes_tech_process> allProcess)
+        private decimal CalcTakeTime(mes_tech_process proc,decimal quantity)
         {
-            allProcess.Add(item);
-            //获取上一工序
-            var preProc = tech_Processes.FirstOrDefault(p => p.nextprocid == item.proc_id);
-            if (preProc != null)
+            decimal takeTime = 0.00m;//当前工序前置准备时间(分钟)
+            if (proc.wctype == 1)//人工型
             {
-                GetPreProcess(tech_Processes, preProc, allProcess);
+                takeTime = quantity / proc.uph.Value * 60 / proc.wsinuse.Value;
+                return takeTime;
             }
+            else if (proc.wctype == 2)//流水线型
+            {
+                takeTime = quantity * proc.ct.Value;
+                return takeTime;
+            }
+            else if (proc.wctype == 3)//设备型
+            {
+                takeTime = Math.Ceiling(quantity / proc.upe.Value) * proc.ct.Value;
+                return takeTime;
+            }
+            return takeTime;
         }
 
 
-
-
-
         /// <summary>
         /// 检查在制工单
         /// </summary>

+ 1 - 1
MicroServices/Business/Bussiness.Model/Tech/mes_tech_process.cs

@@ -55,7 +55,7 @@ namespace Bussiness.Model.Tech
         public decimal? readytime { get; set; }
 
         /// <summary>
-        /// 工作中心类型WorkCenterType
+        /// 工作中心类型WorkCenterType:1-人工型;2-流水线型;3-设备型
         /// </summary>
         [Description("工作中心类型")]
         public int? wctype { get; set; }