Explorar el Código

排产校验提交

zhengly hace 2 años
padre
commit
ceb18e58e3

+ 39 - 15
MicroServices/Business/Business.Application/ResourceExamineManagement/ProductionScheduleAppService.cs

@@ -15,6 +15,7 @@ using System.Transactions;
 using Volo.Abp.Application.Services;
 using Volo.Abp.MultiTenancy;
 using Microsoft.Extensions.Configuration;
+using MongoDB.Driver.Linq;
 
 namespace Business.ResourceExamineManagement
 {
@@ -82,6 +83,10 @@ namespace Business.ResourceExamineManagement
         /// </summary>
         private ISqlRepository<ResourceOccupancyTime> _resourceOccupancyTime;
         /// <summary>
+        /// 加班设置表
+        /// </summary>
+        private ISqlRepository<GeneralizedCodeMaster> _generalizedCodeMaster;
+        /// <summary>
         /// 节假日记录表
         /// </summary>
         private ISqlRepository<HolidayMaster> _holidayMaster;
@@ -132,6 +137,7 @@ namespace Business.ResourceExamineManagement
             ISqlRepository<ShopCalendarWorkCtr> shopCalendarWorkCtr,
             ISqlRepository<QualityLineWorkDetail> qualityLineWorkDetail,
             ISqlRepository<HolidayMaster> holidayMaster,
+            ISqlRepository<GeneralizedCodeMaster> generalizedCodeMaster,
             ICurrentTenant currentTenant
             )
         {
@@ -148,6 +154,7 @@ namespace Business.ResourceExamineManagement
             _shopCalendarWorkCtr = shopCalendarWorkCtr;
             _qualityLineWorkDetail = qualityLineWorkDetail;
             _holidayMaster = holidayMaster;
+            _generalizedCodeMaster = generalizedCodeMaster;
             _currentTenant = currentTenant;
         }
         #endregion
@@ -161,11 +168,16 @@ namespace Business.ResourceExamineManagement
             IConfiguration configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
             domain = configuration.GetConnectionString("Factory_id");
 
-            //获取需要排产的工单
-            //List<WorkOrdMaster> workOrds = new List<WorkOrdMaster>();
+            //获取提前期
+            var generalizedCodeMaster = _generalizedCodeMaster.Select(x => x.FldName == "SystemConfig" && x.Val == "WorkOrderLockPeriod" && x.Domain == domain).FirstOrDefault();
+            decimal Udecil = 0;
+            if (generalizedCodeMaster != null)
+            {
+                Udecil = generalizedCodeMaster.UDeci1;
+            }
             //排产取4周工单排产
             DateTime dateTime = DateTime.Now.AddDays(30);
-            DateTime date = DateTime.Now;
+            DateTime date = DateTime.Now.AddDays((double)Udecil);
             var workOrds = _workOrdMaster.Select(x => x.IsActive && x.Domain == domain && x.OrdDate < dateTime && x.OrdDate > date && x.Status == "初始").ToList();
             await DoProductShcedule(workOrds, domain);
         }
@@ -226,32 +238,39 @@ namespace Business.ResourceExamineManagement
                 //var curSchedules = dbSchedules.Where(p => curLines.Contains(p.Line)).ToList();
                 allResults.AddRange(scheduleMasters);
 
-                //计算当前物料排产开始产线
-                List<WorkOrdRoutingDto> routingDtos = ProcPretreatment(item, workOrdRoutings.Where(p => p.WorkOrd == item.WorkOrd).ToList(), prodLines, allResults);
-
-                //排产前的数据校验
-                if (routingDtos.Count == 0)//没有维护主工序
+                #region 校验
+                //工单工艺多产线关键工序、物料对应的生产线信息:物料,工序对应的生产线、工作日历数据
+                var workOrdRouting = workOrdRoutings.Where(x => x.WorkOrd == item.WorkOrd && x.ParentOp == 0).ToList();
+                if (workOrdRouting.Count == 0)
                 {
                     //记录排产异常原因
-                    new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "工单<" + item.WorkOrd + ">的工序数据维护错误", _currentTenant.Id.ToString());
+                    new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "工单<" + item.WorkOrd + ">的工单工艺流程数据维护为空", _currentTenant.Id.ToString());
                     continue;
                 }
-                //校验每层级工序是否都维护了产线
-                if (routingDtos.Exists(p => string.IsNullOrEmpty(p.Line)))
+                //TODO:多个关键工序校验
+
+                //物料对应生产线校验
+                var ProdLineDetails = prodLines.Where(x => x.Part == item.ItemNum).ToList();
+                if (ProdLineDetails.Count == 0)
                 {
                     //记录排产异常原因
-                    new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "工单<" + item.WorkOrd + ">的产线数据维护错误", _currentTenant.Id.ToString());
+                    new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "工单<" + item.WorkOrd + ">的生产线物料数据维护为空", _currentTenant.Id.ToString());
                     continue;
                 }
+                var calendarsList = calendars.Where(x => ProdLineDetails.Select(p => p.Line).Contains(x.ProdLine) || string.IsNullOrEmpty(x.ProdLine)).ToList();
                 //校验每个层级是否维护了工作日历
                 bool flag = false;
-                foreach (var rut in routingDtos)
+                foreach (var rut in ProdLineDetails)
                 {
-                    var lineCals = calendars.Where(p => p.ProdLine == rut.Line).ToList();
+                    var lineCals = calendarsList.Where(p => p.ProdLine == rut.Line).ToList();
                     //当前产线未配置工作日历取标准无产线工作日历使用
                     if (lineCals.Count == 0)
                     {
                         lineCals = calendars.Where(p => string.IsNullOrEmpty(p.ProdLine)).ToList();
+                        if (lineCals.Count == 0)
+                        {
+                            break;
+                        }
                     }
                     if (lineCals.Select(p => p.WeekDay).Distinct().Count() != 7)
                     {
@@ -262,9 +281,14 @@ namespace Business.ResourceExamineManagement
                 if (flag)
                 {
                     //记录排产异常原因
-                    new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "工单<" + item.WorkOrd + ">的产线工作日历数据维护错误", _currentTenant.Id.ToString());
+                    new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "工单<" + item.WorkOrd + ">的<" + item.ProdLine + ">工作日历数据维护错误", _currentTenant.Id.ToString());
                     continue;
                 }
+                #endregion
+
+
+                //计算当前物料排产开始产线
+                List<WorkOrdRoutingDto> routingDtos = ProcPretreatment(item, workOrdRoutings.Where(p => p.WorkOrd == item.WorkOrd).ToList(), prodLines, allResults);
 
                 //产线排产
                 LineSchedule(item, routingDtos.OrderBy(p => p.level).ToList(), periodSequenceDtls, scheduleMasters);