From 8f392cc88b0768b74efca3b68785cf5aa1c38e70 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期三, 06 十一月 2024 14:28:20 +0800
Subject: [PATCH] 代码更新

---
 wcs-server-hbf/WIDESEA_WCS/SchedulerExecute/Equipment/F_GFSB_UPTask.cs |  165 ++++++++++++++++++++++++++++--------------------------
 1 files changed, 85 insertions(+), 80 deletions(-)

diff --git a/wcs-server-hbf/WIDESEA_WCS/SchedulerExecute/Equipment/F_GFSB_UPTask.cs b/wcs-server-hbf/WIDESEA_WCS/SchedulerExecute/Equipment/F_GFSB_UPTask.cs
index 71992aa..8f55668 100644
--- a/wcs-server-hbf/WIDESEA_WCS/SchedulerExecute/Equipment/F_GFSB_UPTask.cs
+++ b/wcs-server-hbf/WIDESEA_WCS/SchedulerExecute/Equipment/F_GFSB_UPTask.cs
@@ -4,10 +4,12 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading;
+using System.Threading.Tasks;
 using WIDESEA_Common;
 using WIDESEA_Common.LoctionEnum;
 using WIDESEA_Common.Tools;
 using WIDESEA_Core.EFDbContext;
+using WIDESEA_Core.Extensions;
 using WIDESEA_Entity.DomainModels;
 using WIDESEA_Services.IRepositories;
 using WIDESEA_Services.Repositories;
@@ -27,101 +29,104 @@
         {
             if (Interlocked.Exchange(ref _readGFBUPSignalsoF, 1) == 0)
             {
-
-                try
+                Task.Run(() =>
                 {
-                    VOLContext Context = new VOLContext();
-                    Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
-                    Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
-                    Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
-                    List<string> TBSBS = new List<string> { "杈婂垎鏈鸿礋鏋�1", "杈婂垎鏈鸿礋鏋�2", "杈婂垎鏈鸿礋鏋�3", "杈婂垎鏈鸿礋鏋�4" };
-
-                    foreach (var TBSB in TBSBS)
+                    try
                     {
-                        PLCClient plc = WCSService.Clients.Find(v => v.PLCName == TBSB);
-                        if (plc == null)
-                        {
-                            //WriteLog.GetLog("GFF涓婃枡鍛煎彨").Write($"璁惧锛歿TBSB} 鍐呭锛氭湭杩炴帴PLC 鏃堕棿璁板綍: { DateTime.Now }" , "GFF涓婃枡鍛煎彨");
-                            continue;
-                        }
+                        VOLContext Context = new VOLContext();
+                        Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
+                        Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
+                        Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
+                        List<string> TBSBS = new List<string> { "杈婂垎鏈鸿礋鏋�1", "杈婂垎鏈鸿礋鏋�2", "杈婂垎鏈鸿礋鏋�3", "杈婂垎鏈鸿礋鏋�4" };
 
-                        //褰撳墠璁惧鏈夋病鏈変笂鏂欒姹�
-                        OperateResult<bool> GYR_RFX = plc.MelsecPLCClient.MelsecMcNetClient.ReadBool("D5493.0");
-                        Int16 tf = Convert.ToInt16(GYR_RFX.Content);
-                        if (GYR_RFX.Content)
+                        foreach (var TBSB in TBSBS)
                         {
-                            //鏌ョ湅褰撳墠杈婂垎鏈鸿澶囨槸鍚︽湁AGV浠诲姟
-                            var SBtask = agvRepository.FindFirst(f => f.agv_toaddress == plc.EquipType);
-                            //鏈夌粨鏉熸湰娆″惊鐜�
-                            if (SBtask != null) { continue; }
-                            List<base_routing_table> Routing_Table = routingRepository.Find(d => d.route_end == plc.EquipType);
-                            List<base_ware_location> loctionList = new List<base_ware_location>();
-                            foreach (var item in Routing_Table)
+                            PLCClient plc = WCSService.Clients.Find(v => v.PLCName == TBSB);
+                            if (plc == null)
                             {
-                                base_ware_location ware_Locations = locRepository.FindFirst(d => d.upper_code == item.route_began && d.status == 1 && d.location_state == LoctionStateEnum.LocationState_Stored.ToString() && d.logic_col == 1 && d.task == 2);
-                                if (ware_Locations == null)
-                                {
-                                    continue;
-                                }
-                                loctionList.Add(ware_Locations);
+                                //WriteLog.GetLog("GFF涓婃枡鍛煎彨").Write($"璁惧锛歿TBSB} 鍐呭锛氭湭杩炴帴PLC 鏃堕棿璁板綍: { DateTime.Now }" , "GFF涓婃枡鍛煎彨");
+                                continue;
                             }
 
-                            if (loctionList.Count != 0)
+                            //褰撳墠璁惧鏈夋病鏈変笂鏂欒姹�
+                            OperateResult<bool> GYR_RFX = plc.MelsecPLCClient.MelsecMcNetClient.ReadBool("D5493.0");
+                            Int16 tf = Convert.ToInt16(GYR_RFX.Content);
+                            if (GYR_RFX.Content)
                             {
-                                base_ware_location Location = loctionList.OrderBy(d => d.update_time).FirstOrDefault();
+                                //鏌ョ湅褰撳墠杈婂垎鏈鸿澶囨槸鍚︽湁AGV浠诲姟
+                                var SBtask = agvRepository.FindFirst(f => f.agv_toaddress == plc.EquipType);
+                                //鏈夌粨鏉熸湰娆″惊鐜�
+                                if (SBtask != null) { continue; }
+                                #region 璁板綍涓婃枡璇锋眰淇″彿
+                                WriteLog.GetLog().Write($"{plc.PLCName}涓婃枡璇锋眰锛歿GYR_RFX.Content}---{DateTime.Now}", $"璐熸瀬妫嶅垎涓婃枡璇锋眰");
+                                #endregion
+                                List<base_routing_table> Routing_Table = routingRepository.Find(d => d.route_end == plc.EquipType);
+                                List<base_ware_location> loctionList = new List<base_ware_location>();
+                                foreach (var item in Routing_Table)
+                                {
+                                    base_ware_location ware_Locations = locRepository.FindFirst(d => d.upper_code == item.route_began && d.status == 1 && d.location_state == LoctionStateEnum.LocationState_Stored.ToString() && d.logic_col == 1 && d.task == 2);
+                                    if (ware_Locations == null)
+                                    {
+                                        continue;
+                                    }
+                                    loctionList.Add(ware_Locations);
+                                }
 
-                                //鐢熸垚杈婂垎鏈轰笂鏂欎换鍔�
-                                dt_agvtask agvtask = new dt_agvtask()
+                                if (loctionList.Count != 0)
                                 {
-                                    agv_id = Guid.NewGuid(),
-                                    agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
-                                    agv_fromaddress = Location.upper_code,
-                                    agv_toaddress = plc.EquipType,
-                                    agv_code = "璐熸瀬AGV璋冨害",
-                                    agv_remark = "杈婂垎涓婃枡浠诲姟",
-                                    agv_taskstate = AGVTaskStateEnum.Create.ToString(),
-                                    agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
-                                    agv_worktype = 1,//宸ヤ綔绫诲瀷
-                                    agv_materielid = "",
-                                    agv_qty = 1,
-                                    agv_createtime = DateTime.Now,
-                                    agv_grade = 0,//浠诲姟浼樺厛绾�
-                                    agv_userid = "WCS",
-                                    agv_barcode = "",
-                                };
-                        
-                                //Location.update_time = DateTime.Now;
-                                Location.task = 1;
-                                Location.logic_col = 1;
-                                var entry = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
-                                if (entry != null)
-                                {
-                                    entry.State = EntityState.Detached;
+                                    base_ware_location Location = loctionList.OrderBy(d => d.update_time).FirstOrDefault();
+
+                                    //鐢熸垚杈婂垎鏈轰笂鏂欎换鍔�
+                                    dt_agvtask agvtask = new dt_agvtask()
+                                    {
+                                        agv_id = Guid.NewGuid(),
+                                        agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
+                                        agv_fromaddress = Location.upper_code,
+                                        agv_toaddress = plc.EquipType,
+                                        agv_code = "璐熸瀬AGV璋冨害",
+                                        agv_remark = "杈婂垎涓婃枡浠诲姟",
+                                        agv_taskstate = AGVTaskStateEnum.Create.ToString(),
+                                        agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
+                                        agv_worktype = 1,//宸ヤ綔绫诲瀷
+                                        agv_materielid = "",
+                                        agv_qty = 1,
+                                        agv_createtime = DateTime.Now,
+                                        agv_grade = 0,//浠诲姟浼樺厛绾�
+                                        agv_userid = "WCS",
+                                        agv_barcode = "",
+                                    };
+
+                                    //Location.update_time = DateTime.Now;
+                                    Location.task = 1;
+                                    Location.logic_col = 1;
+                                    var entry = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
+                                    if (entry != null)
+                                    {
+                                        entry.State = EntityState.Detached;
+                                    }
+                                    int a = locRepository.Update(Location, d => new { d.task, d.logic_col }, true);
+                                    if (a == 1)
+                                    {
+                                        agvRepository.Add(agvtask, true);
+                                    }
+
                                 }
-                               int a= locRepository.Update(Location, d => new { d.task, d.logic_col }, true);
-                                if (a==1)
-                                {
-                                    agvRepository.Add(agvtask, true);
-                                    WriteDBLog.Info($"銆恵TBSB}銆戜笂鏂欎换鍔$敓鎴�").Write($"鐢熸垚浠诲姟:{agvtask.agv_tasknum},璧风偣璐т綅銆恵Location.upper_code}銆戠姸鎬侊細鎵樼洏鍏夌數妫�娴嬶細{Location.tpgd},鐘舵�侊細{Location.location_state},鏇存柊鏃堕棿锛歿Location.wireless_time}", $"銆恵TBSB}銆戜笂鏂欎换鍔$敓鎴�");
-                                    WriteDBLog.Info($"銆恵TBSB}銆戜笂鏂欎换鍔$敓鎴�").Write($"----------------浠诲姟鐢熸垚鎴愬姛  {DateTime.Now} -------------- {Environment.NewLine}", $"銆恵TBSB}銆戜笂鏂欎换鍔$敓鎴�");
-                                }
-                               
+
+
                             }
-               
 
                         }
-
                     }
-                }
-                catch (Exception ex)
-                {
-
-                    throw;
-                }
-                finally
-                {
-                    Interlocked.Exchange(ref _readGFBUPSignalsoF, 0);
-                }
+                    catch (Exception ex)
+                    {
+                        WriteLog.GetLog().Write($"璐熸瀬妫嶅垎涓婃枡锛歿DateTime.Now} --------------{ex}", $"璐熸瀬妫嶅垎涓婃枡璋冨害");
+                    }
+                    finally
+                    {
+                        Interlocked.Exchange(ref _readGFBUPSignalsoF, 0);
+                    }
+                });
+               
             }
         }
 

--
Gitblit v1.9.3