Просмотр исходного кода

Merge branch 'dev' of http://123.60.180.165:4647/ZZYDOP/DOPCore into dev

tangdi 2 лет назад
Родитель
Сommit
8b2eeee61a

+ 12 - 4
MicroServices/Business/Business.Application/ReplenishmentManagement/ReplenishmentAppService.cs

@@ -826,10 +826,12 @@ namespace Business.Replenishment
             var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.RealQty > 0 
             && listShip.Contains(a.ContainerItem) && a.ShipDate >= dateBegin && a.ShipDate <= dateEnd && !recidList.Contains(a.ASNBOLShipperRecID));//瑞奇只算瑞奇排除国科海王
 
-            var DMSItemListGK = _DMS_IN_ITEMMAPPING.Select(a => planList.Where(p=>p.DistributionChannel=="国科").Select(p => p.SAPItemNumber).ToList().Contains(a.CfnERPCode));
+            var gkItemList = planList.Where(p => p.DistributionChannel == "国科").Select(p => p.SAPItemNumber).ToList();
+            var DMSItemListGK = _DMS_IN_ITEMMAPPING.Select(a => gkItemList.Contains(a.CfnERPCode));
             var shipListGK = _DMS_IN_SHIPPINGDETAIL.Select(a =>
            DMSItemListGK.Select(g=>g.CfnCode).Contains(a.UPN) && a.ParentDealerCode== "RQ000005" && a.ShipmentDate >= DateOnly.FromDateTime(dateBegin) && a.ShipmentDate <= DateOnly.FromDateTime(dateEnd));//国科
-            var DMSItemListHW = _DMS_IN_ITEMMAPPING.Select(a => planList.Where(p => p.DistributionChannel == "国科").Select(p => p.SAPItemNumber).ToList().Contains(a.CfnERPCode));
+            var hwItemList = planList.Where(p => p.DistributionChannel == "海王").Select(p => p.SAPItemNumber).ToList();
+            var DMSItemListHW = _DMS_IN_ITEMMAPPING.Select(a => hwItemList.Contains(a.CfnERPCode));
             var shipListHW = _DMS_IN_SHIPPINGDETAIL.Select(a =>
            DMSItemListHW.Select(g => g.CfnCode).Contains(a.UPN) && a.ParentDealerCode == "RQ000002" && a.ShipmentDate >= DateOnly.FromDateTime(dateBegin) && a.ShipmentDate <= DateOnly.FromDateTime(dateEnd));//海王
 
@@ -839,10 +841,14 @@ namespace Business.Replenishment
             //取本月发货出库记录
             var shipMList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.RealQty > 0 
             && listShip.Contains(a.ContainerItem) && a.ShipDate>= dateCurrent && a.ShipDate <= DateTime.Now && !recidList.Contains(a.ASNBOLShipperRecID));//瑞奇只算瑞奇排除国科海王
+            var gkCNCCodeList = DMSItemListGK.Select(g => g.CfnCode).ToList();
+            var dateOnlyCurrent = DateOnly.FromDateTime(dateCurrent);
+            var dateOnlyNow = DateOnly.FromDateTime(DateTime.Now);
             var shipMListGK = _DMS_IN_SHIPPINGDETAIL.Select(a =>
-           DMSItemListGK.Select(g => g.CfnCode).Contains(a.UPN) && a.ParentDealerCode == "RQ000005" && a.ShipmentDate >= DateOnly.FromDateTime(dateCurrent) && a.ShipmentDate <= DateOnly.FromDateTime(DateTime.Now));//国科
+           gkCNCCodeList.Contains(a.UPN) && a.ParentDealerCode == "RQ000005" && a.ShipmentDate >= dateOnlyCurrent && a.ShipmentDate <= dateOnlyNow);//国科
+            var hwCNCCodeList = DMSItemListHW.Select(g => g.CfnCode).ToList();
             var shipMListHW = _DMS_IN_SHIPPINGDETAIL.Select(a =>
-           DMSItemListHW.Select(g => g.CfnCode).Contains(a.UPN) && a.ParentDealerCode == "RQ000002" && a.ShipmentDate >= DateOnly.FromDateTime(dateCurrent) && a.ShipmentDate <= DateOnly.FromDateTime(DateTime.Now));//海王
+           hwCNCCodeList.Contains(a.UPN) && a.ParentDealerCode == "RQ000002" && a.ShipmentDate >= dateOnlyCurrent && a.ShipmentDate <= dateOnlyNow);//海王
 
             var itemGroup = shipList.GroupBy(p => p.ContainerItem)
                  .Select(p => new ASNBOLShipperDetail
@@ -1097,6 +1103,7 @@ namespace Business.Replenishment
                             rop.rop_revised = Math.Min(rop.rop_computed.Value, rop.max_stock_level.Value);
                             rop.isparam = true;
                             rop.tenant_id = input.tenant_id;
+                            rop.company_id = input.company_id;
                             rop.factory_id = input.factory_id;
                             rop.create_time = DateTime.Now;
                             rop.org_id = input.org_id;
@@ -1300,6 +1307,7 @@ namespace Business.Replenishment
                 rop.rop_revised = Math.Max(rop.rop_computed.Value, rop.max_stock_level.Value);
                 rop.isparam = true;
                 rop.tenant_id = input.tenant_id;
+                rop.company_id = input.company_id;
                 rop.factory_id = input.factory_id;
                 rop.create_time = DateTime.Now;
                 rop.org_id = input.org_id;

+ 94 - 19
MicroServices/Business/Business.Application/ResourceExamineManagement/ProductionScheduleAppService.cs

@@ -21,6 +21,7 @@ using IdentityModel.Client;
 using Amazon.Runtime;
 using Magicodes.ExporterAndImporter.Core.Extension;
 using Volo.Abp.Domain.Repositories;
+using System.Runtime.CompilerServices;
 
 namespace Business.ResourceExamineManagement
 {
@@ -335,11 +336,6 @@ namespace Business.ResourceExamineManagement
             zcWorkOrds = zcWorkOrds.OrderBy(p=>p.Priority).ToList();
             foreach (var item in zcWorkOrds)
             {
-                //如果工单预计开工日期在排产时间之后,则跳过
-                if (item.OrdDate > scheTime)
-                {
-                    continue;
-                }
                 //记录产线占用情况
                 allResults.AddRange(scheduleMasters);
                 //当前工单工艺路线主产线的关键工序
@@ -354,22 +350,70 @@ namespace Business.ResourceExamineManagement
             List<WorkOrdMstDto> workDtos = new List<WorkOrdMstDto>();
             foreach (var item in notSchedules)
             {
+                //注:特殊工单暂时只考虑连续生产,不考虑暂停
+                //特殊工单工序
                 var curOp = tsWoRoutings.Where(p => p.WorkOrd == item.WorkOrd).OrderByDescending(p => p.OP).First();
-                //剩余排产数量
-                decimal qtyNeed = item.QtyOrded - curOp.QtyComplete;
-                //剩余工作时长(分钟)
-                decimal usedTime = Math.Ceiling(qtyNeed / item.QtyOrded * item.LbrVar * 60);
                 //特殊工单排产开始时间
                 DateTime tStartTime = item.OrdDate.GetValueOrDefault();
-                //如果当前特殊工单正在生产,则开工日期为当天的下一个工作日
-                if (item.Status.ToLower() == "w" && item.JointTyped.ToUpper() != "B")
+                //获取特殊工单开始排产时间记录
+                var curRecord = timeRecords.FirstOrDefault(p=>p.WorkOrd == item.WorkOrd && p.Op == curOp.OP);
+                if (curRecord == null)
                 {
-                    DateTime nowDate = DateTime.Now.Date;
-                    //当前产线的工作日历
-                    var mLCalendars = calendars.Where(p => p.ProdLine == item.ProdLine || string.IsNullOrEmpty(p.ProdLine)).ToList();
-                    //获取下一个工作日
-                    startTime = GetNextWorkDay((int)nowDate.DayOfWeek, nowDate, mLCalendars);
+                    //添加记录
+                    inserts.Add(new WorkOrdSetupTimeRecord
+                    {
+                        Domain = item.Domain,
+                        WorkOrd = item.WorkOrd,
+                        ItemNum = item.ItemNum,
+                        Op = curOp.OP,
+                        Line = item.ProdLine,
+                        StartTime = tStartTime,
+                        CreateTime = DateTime.Now
+                    });
+                    //记录工序开始准备时间记录
+                    timeRecords.Add(new WorkOrdSetupTimeRecord
+                    {
+                        Domain = item.Domain,
+                        WorkOrd = item.WorkOrd,
+                        ItemNum = item.ItemNum,
+                        Op = curOp.OP,
+                        Line = item.ProdLine,
+                        StartTime = tStartTime,
+                        CreateTime = DateTime.Now
+                    });
                 }
+                //如果产线有准备时间记录且准备开始时间在当前时间之前,说明已在排产中,此时开始排产日期为当前时间
+                else if (curRecord != null && curRecord.StartTime < scheTime)
+                {
+                    tStartTime = scheTime;
+                }
+                //计算开始排产时间或者上次报工时间到当前时间点的预估产能
+                decimal sumTimes = 0m;
+                //工单没有报工记录
+                if (curOp.Last == null)
+                {
+                    if (curRecord == null)
+                    {
+                        //工单没有开始时间记录,取预计开工时间到当前时间的有效时长
+                        sumTimes = CalcTimeMins(tStartTime, scheTime, item.ProdLine);
+                    }
+                    else
+                    {
+                        //工单有开始时间记录,取开始时间到当前时间的有效时长
+                        sumTimes = CalcTimeMins(curRecord.StartTime, scheTime, item.ProdLine);
+                    }
+                }
+                else {
+                    //工单有报工记录,取最新报工时间到当前时间的有效时长
+                    sumTimes = CalcTimeMins(curOp.Last.GetValueOrDefault(), scheTime, item.ProdLine);
+                }
+                //计算预估数量
+                decimal planQty = Math.Ceiling(sumTimes / (item.LbrVar * 60) * item.QtyOrded);
+                //剩余排产数量 = 工单数量 - 已报工数量 - 计划数量
+                decimal qtyNeed = item.QtyOrded - curOp.QtyComplete - planQty;
+                //剩余工作时长(分钟)
+                decimal usedTime = Math.Ceiling(qtyNeed / item.QtyOrded * item.LbrVar * 60);
+                
                 workDtos.Add(new WorkOrdMstDto
                 {
                     WorkOrd = item.WorkOrd,
@@ -674,8 +718,8 @@ namespace Business.ResourceExamineManagement
             List<ScheduleResultOpMaster> curScheduleRsts = new List<ScheduleResultOpMaster>();
             //记录上一产线排产开始时间
             LineStartDto lineStart = new LineStartDto();
-            //产线开工时间默认为当前日期的下一天
-            lineStart.StartTime = DateTime.Now.Date.AddDays(1);
+            //产线开工时间默认为当前时间
+            lineStart.StartTime = scheTime;
             TimeSpan span = TimeSpan.Zero;
             //第一层级工序有几个关键工序,就有几条产线
             for (int i = 0; i < workOrdRoutings.Count; i++)
@@ -700,7 +744,7 @@ namespace Business.ResourceExamineManagement
                 //当前产线的休息时间设置
                 var mlqtyWorkDtls = qualityLines.Where(p => p.ProdLine == lineStart.Line).ToList();
                 //产线排产开始时间
-                DateTime workStartTime = lineStart.StartTime;
+                DateTime workStartTime = scheTime;
                 //记录特殊工单:获取第一天是否有特殊工单
                 List<WorkOrdMaster> fstWOMasters = tsWorkOrds.Where(p => p.ProdLine == lineStart.Line && p.OrdDate.Value.Date == workStartTime.Date).OrderBy(p => p.Priority).ToList();
                 List<WorkOrdMstDto> workDtos = new List<WorkOrdMstDto>();
@@ -718,7 +762,38 @@ namespace Business.ResourceExamineManagement
                 {
                     foreach (var item in fstWOMasters)
                     {
+                        //注:特殊工单暂时只考虑连续生产,不考虑暂停
+                        //特殊工单工序
                         var curOp = tsWoRoutings.Where(p => p.WorkOrd == item.WorkOrd).OrderByDescending(p => p.OP).First();
+                        //获取特殊工单开始排产时间记录
+                        var curRecord = timeRecords.FirstOrDefault(p => p.WorkOrd == item.WorkOrd && p.Op == curOp.OP);
+                        //if (curRecord == null)
+                        //{
+                        //    //添加记录
+                        //    inserts.Add(new WorkOrdSetupTimeRecord
+                        //    {
+                        //        Domain = item.Domain,
+                        //        WorkOrd = item.WorkOrd,
+                        //        ItemNum = item.ItemNum,
+                        //        Op = curOp.OP,
+                        //        Line = item.ProdLine,
+                        //        StartTime = tStartTime,
+                        //        CreateTime = DateTime.Now
+                        //    });
+                        //    //记录工序开始准备时间记录
+                        //    timeRecords.Add(new WorkOrdSetupTimeRecord
+                        //    {
+                        //        Domain = item.Domain,
+                        //        WorkOrd = item.WorkOrd,
+                        //        ItemNum = item.ItemNum,
+                        //        Op = curOp.OP,
+                        //        Line = item.ProdLine,
+                        //        StartTime = tStartTime,
+                        //        CreateTime = DateTime.Now
+                        //    });
+                        //}
+
+
                         //剩余排产数量
                         decimal qtyNeed = item.QtyOrded - curOp.QtyComplete;
                         //剩余工作时长(分钟)