mengshunguo 1 kuukausi sitten
vanhempi
commit
b98a33453a
1 muutettua tiedostoa jossa 60 lisäystä ja 35 poistoa
  1. 60 35
      SCADA_DAQ/Customer/Machines/SampleMachine.cs

+ 60 - 35
SCADA_DAQ/Customer/Machines/SampleMachine.cs

@@ -60,6 +60,16 @@ namespace SCADA_DAQ.Customer.Machines
         /// </summary>
         private int NumberOfTimes;
 
+        /// <summary>
+        /// 未连上服务器产量暂存
+        /// </summary>
+        private int NotConnctNumberOfTimes;
+
+        /// <summary>
+        /// 断开服务器的时间
+        /// </summary>
+        private DateTime NotConnectTime;
+
         /// <summary>
         /// 服务器连接状态
         /// </summary>
@@ -129,6 +139,10 @@ namespace SCADA_DAQ.Customer.Machines
             {
                 var connectStatus = GetInternetConStatus.GetNetConStatus(Env.ServerIP.Value);
                 ServerConncetStatus = (connectStatus == 2 || connectStatus == 3) ? true : false;
+                if (!ServerConncetStatus)
+                {
+                    NotConnectTime = DateTime.Now;
+                }
             }
         }
 
@@ -185,45 +199,56 @@ namespace SCADA_DAQ.Customer.Machines
                     NumberOfTimes++;
                     FirstTime = DateTime.Now;
                 }
-                else if (NumberOfTimes == 1 && (int)(DateTime.Now - FirstTime).TotalSeconds < 7 && ServerConncetStatus)
+                else if (NumberOfTimes == 1 && (int)(DateTime.Now - FirstTime).TotalSeconds < 5)
                 {
-                    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 (ServerConncetStatus)
                     {
-                        taskInfoItem.CurrentProduction++;
-                        if (taskInfoItem.WorkStartTime == new DateTime() && taskInfoItem.OrderState == "待生产")
-                        {
-                            taskInfoItem.WorkStartTime = DateTime.Now;
-                            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)
-                             );
-                            Log.Info($"订单{taskInfoItem.OrderId}开始生产");
-                        }
-                        else if (taskInfoItem.CurrentProduction >= taskInfoItem.ScheduledProduction)
-                        {
-                            // 结束生产 
-                            var dateDiff = (DateTime.Now - taskInfoItem.WorkStartTime).TotalSeconds.ToInt();  // 时间差/s
-                            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)
-                            );
-                            Log.Info($"订单{taskInfoItem.OrderId}生产完成");
-                        }
-                        else if(taskInfoItem.WorkStartTime != new DateTime() && taskInfoItem.OrderState == "生产中")
+                        NotConnctNumberOfTimes++;
+                        bool toBeProduced;
+                        bool inProduction;
+                        bool produced;
+                        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
                         {
-                            DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfoItem.ID}",
-                          new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfoItem.CurrentProduction)
-                            );
+                            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 >= 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 + NotConnctNumberOfTimes)
+                                 );
+                            }
+                            NumberOfTimes = 0;
+                            NotConnctNumberOfTimes = 0;
                         }
-                        NumberOfTimes = 0;
+                    }
+                    else
+                    {
+                        NotConnctNumberOfTimes++;
                     }
                 }
                 else if (NumberOfTimes == 1 && (int)(DateTime.Now - FirstTime).TotalSeconds > 5)