Browse Source

完善产量计数逻辑

mengshunguo 1 month ago
parent
commit
dcc2b5113f
1 changed files with 47 additions and 52 deletions
  1. 47 52
      SCADA_DAQ/Customer/Machines/SampleMachine.cs

+ 47 - 52
SCADA_DAQ/Customer/Machines/SampleMachine.cs

@@ -61,9 +61,9 @@ namespace SCADA_DAQ.Customer.Machines
         private int NumberOfTimes;
 
         /// <summary>
-        /// 未连上服务器产量暂存
+        /// 产量暂存
         /// </summary>
-        private int NotConnctNumberOfTimes;
+        private int Qty;
 
         /// <summary>
         /// 断开服务器的时间
@@ -143,6 +143,10 @@ namespace SCADA_DAQ.Customer.Machines
                 {
                     NotConnectTime = DateTime.Now;
                 }
+                else
+                {
+                    NotConnectTime = DateTime.Now;
+                }
             }
         }
 
@@ -199,65 +203,56 @@ namespace SCADA_DAQ.Customer.Machines
                     NumberOfTimes++;
                     FirstTime = DateTime.Now;
                 }
-                else if (NumberOfTimes == 1 && (int)(DateTime.Now - FirstTime).TotalSeconds < 5)
+                else if (NumberOfTimes == 1 && (int)(DateTime.Now - FirstTime).TotalSeconds < 7)
                 {
-                    if (ServerConncetStatus)
+                    bool toBeProduced = false;
+                    bool inProduction = false;
+                    bool produced = false;
+                    var taskInfoItem = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
+                   .Where(t => t.WorkShopId == CustomerEnv.ProductionLineConfigValue.WorkShopId
+                       && t.ProductionLineId == CustomerEnv.ProductionLineConfigValue.ProductionLineId && t.OrderState != "已生产")
+                   .OrderBy(t => t.ID).FirstOrDefault();
+                    if (taskInfoItem == null) { return; }
+                    else
                     {
-                        NotConnctNumberOfTimes++;
-                        bool toBeProduced = false;
-                        bool inProduction = false;
-                        bool produced = false;
-                        var taskInfoItem = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
-                       .Where(t => t.WorkShopId == CustomerEnv.ProductionLineConfigValue.WorkShopId
-                           && t.ProductionLineId == CustomerEnv.ProductionLineConfigValue.ProductionLineId && t.OrderState != "已生产")
-                       .OrderBy(t => t.ID).FirstOrDefault();
-                        if (taskInfoItem == null) { return; }
-                        else
+                        if (taskInfoItem.WorkStartTime == new DateTime() && taskInfoItem.OrderState == "待生产")
                         {
-                            if (taskInfoItem.WorkStartTime == new DateTime() && taskInfoItem.OrderState == "待生产")
-                            {
-                                taskInfoItem.WorkStartTime = DateTime.Now;
-                                toBeProduced = DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfoItem.ID}",
-                               new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "生产中"),
-                               new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.WorkStartTime_Dt, taskInfoItem.WorkStartTime.Format()),
-                               new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfoItem.CurrentProduction + NotConnctNumberOfTimes)
-                                 );
-                                Log.Info($"订单{taskInfoItem.OrderId}开始生产");
-                            }
-                            else if (taskInfoItem.CurrentProduction + 1 >= taskInfoItem.ScheduledProduction)
-                            {
-                                // 结束生产 
-                                var dateDiff = (DateTime.Now - taskInfoItem.WorkStartTime).TotalSeconds.ToInt();  // 时间差/s
-                                produced = DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfoItem.ID}",
-                                    new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
-                                    new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
-                                    new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产"),
-                                    new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfoItem.CurrentProduction + 1)
-                                );
-                                Log.Info($"订单{taskInfoItem.OrderId}生产完成");
-                            }
-                            else if (taskInfoItem.WorkStartTime != new DateTime() && taskInfoItem.OrderState == "生产中")
-                            {
-                                inProduction = DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfoItem.ID}",
-                               new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfoItem.CurrentProduction + NotConnctNumberOfTimes)
-                                 );
-                            }
-                            NumberOfTimes = 0;
-                            if (toBeProduced || produced || inProduction)
-                            {
-                                NotConnctNumberOfTimes = 0;
-                            }
+                            taskInfoItem.WorkStartTime = DateTime.Now;
+                            toBeProduced = DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfoItem.ID}",
+                           new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "生产中"),
+                           new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.WorkStartTime_Dt, taskInfoItem.WorkStartTime.Format()),
+                           new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfoItem.CurrentProduction + 1)
+                             );
+                            Log.Info($"订单{taskInfoItem.OrderId}开始生产");
                         }
-                    }
-                    else
-                    {
-                        NotConnctNumberOfTimes++;
+                        else if (taskInfoItem.CurrentProduction + 1 >= taskInfoItem.ScheduledProduction)
+                        {
+                            // 结束生产 
+                            var dateDiff = (DateTime.Now - taskInfoItem.WorkStartTime).TotalSeconds.ToInt();  // 时间差/s
+                            produced = DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfoItem.ID}",
+                                new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
+                                new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
+                                new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产"),
+                                new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfoItem.CurrentProduction + 1)
+                            );
+                            Log.Info($"订单{taskInfoItem.OrderId}生产完成");
+                        }
+                        else if (taskInfoItem.WorkStartTime != new DateTime() && taskInfoItem.OrderState == "生产中")
+                        {
+                            inProduction = DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfoItem.ID}",
+                           new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfoItem.CurrentProduction + 1)
+                             );
+                        }
+                        NumberOfTimes = 0;
+                        //if (toBeProduced || produced || inProduction)
+                        //{
+                        //    Qty = 0;
+                        //}
                     }
                 }
                 else if (NumberOfTimes == 1 && (int)(DateTime.Now - FirstTime).TotalSeconds > 5)
                 {
                     NumberOfTimes = 0;
-                    FirstTime = DateTime.Now;
                 }
             }
             //log.Debug($"{DeviceConfig.DeviceID} {reg.RegName} Value Changed:{reg.OldValue}->{reg.Value}");