From a0a0df2e824b6fe7e5a3c0afce78127fecf84fc9 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期一, 03 十一月 2025 08:23:05 +0800
Subject: [PATCH] ERP接口代码更新,WCS代码优化,出入库分配优化

---
 项目代码/WCS/WCSServices/WIDESEAWCS_Tasks/成品仓/ConveyorLineJob_CPH.cs |  156 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 115 insertions(+), 41 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPH.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPH.cs"
index d134c26..b11f4c0 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPH.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPH.cs"
@@ -1,10 +1,11 @@
 锘縰sing Microsoft.AspNetCore.Components.Routing;
 using Newtonsoft.Json;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
+using Org.BouncyCastle.Tls;
 using Quartz;
-using SqlSugar.Extensions;
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -12,6 +13,7 @@
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Communicator;
 using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_ITaskInfoRepository;
@@ -39,6 +41,8 @@
         private readonly IRouterService _routerService;
         private readonly IRouterExtension _routerExtension;
         private readonly List<Dt_WarehouseDevice> warehouseDevices;
+        private static object lockObj = 0;//
+        private static List<string> strings = new List<string>();
 
         public ConveyorLineJob_CPH(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension)
         {
@@ -50,7 +54,14 @@
             _routerRepository = routerRepository;
             _routerService = routerService;
             _routerExtension = routerExtension;
-
+            string boxCodes = AppSettings.Get("BoxCodes");
+            if (!string.IsNullOrEmpty(boxCodes) && strings.Count<=0)
+            {
+                foreach (string s in boxCodes.Split(","))
+                {
+                    strings.Add(s);
+                }
+            }
             string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
             if (!string.IsNullOrEmpty(warehouseDevicesStr))
             {
@@ -64,53 +75,116 @@
 
         public Task Execute(IJobExecutionContext context)
         {
-            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
-            if (flag && value != null)
+            lock (lockObj)
             {
-                //鑾峰彇褰撳墠璁惧
-                OtherDevice device = (OtherDevice)value;
-                List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).Distinct().ToList();
-                List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
-                foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
+                if (lockObj.ToString()=="0")
                 {
-                    DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
-                    DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
-                    if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProRead != null && deviceProWrite != null)
+                    lockObj = 1;
+                    Task task = Task.Run(() =>
                     {
-                        R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
-                        //鐮佸灈鐜嚎璇锋眰浠诲姟 
-                        if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.R_BoxCode) && conveyorLineInfoRead.R_Request==1)
+                        try
                         {
-                            //WebResponseContent content = _taskService.RequestWMSTaskSimple(conveyorLineInfoRead.R_BoxCode, item.StationCode);
-                            ////鍚慦MS璇锋眰浠诲姟
-                            //if (true)
-                            //{
-
-                            //}
-                            
-                        }
-                    }
-                    else if(item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && deviceProRead != null)
-                    {
-                        R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
-                        //鑾峰彇鐮佸灈鍙d换鍔℃洿鏂颁换鍔$姸鎬�
-                        if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo > 0)
-                        {
-                            Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.R_TaskNo && x.NextAddress==item.StationCode && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt());
-                            if (task != null)
+                            while (true)
                             {
-                                task.CurrentAddress = item.StationCode;
-                                task.NextAddress = task.TargetAddress;
-                                task.DeviceCode = item.StackerCraneCode;
-                                _taskService.UpdateTask(task, TaskStatusEnum.MD_Executing);
+                                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
+                                if (flag && value != null)
+                                {
+                                    //鑾峰彇褰撳墠璁惧
+                                    OtherDevice device = (OtherDevice)value;
+                                    List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
+                                    Dt_StationManger? RequestIn = stationMangers.FirstOrDefault(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt());
+                                    if (RequestIn != null)
+                                    {
+                                        DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == RequestIn.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+                                        DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == RequestIn.StationCode && x.DeviceProParamType == nameof(W_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+                                        if (deviceProRead != null && deviceProWrite != null)
+                                        {
+                                            R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
+                                            //鐮佸灈鐜嚎璇锋眰浠诲姟 
+                                            if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.R_BoxCode) && conveyorLineInfoRead.R_Request == 1)
+                                            {
+                                                //WebResponseContent content = _taskService.MESBoxCodeNotice(conveyorLineInfoRead.R_BoxCode);
+                                                ////鍚慦MS璇锋眰浠诲姟
+                                                //if (true)
+                                                //{
+
+                                                //}
+                                                //string[] strings = conveyorLineInfoRead.R_BoxCode.Split("-");
+                                                //if (strings.Length==2)
+                                                //{
+                                                #region todo:涓存椂閫昏緫
+                                                //鍐欏叆鎵ц鏁版嵁
+                                                if (strings.FirstOrDefault(x=>x == conveyorLineInfoRead.R_BoxCode)!=null)
+                                                {
+                                                    device.SetValue(W_CLineCPHDB.W_TaskNo, 100 + 5, RequestIn.StationCode);
+                                                    device.SetValue(W_CLineCPHDB.W_Channel, 5, RequestIn.StationCode);
+                                                    device.SetValue(W_CLineCPHDB.W_Long, 450, RequestIn.StationCode);
+                                                    device.SetValue(W_CLineCPHDB.W_Wide, 360, RequestIn.StationCode);
+                                                    device.SetValue(W_CLineCPHDB.W_High, 400, RequestIn.StationCode);
+                                                    device.SetValue(W_CLineCPHDB.W_TMID, conveyorLineInfoRead.R_BoxCode, RequestIn.StationCode);
+                                                    device.SetValue(W_CLineCPHDB.W_Request, 1, RequestIn.StationCode);
+                                                    WebResponseContent content = _taskService.MESBoxCodeNotice(conveyorLineInfoRead.R_BoxCode);
+                                                    if (content.Message.Contains("true"))
+                                                    {
+                                                        strings.Remove(conveyorLineInfoRead.R_BoxCode);
+                                                        WriteInfo(RequestIn.StationName, content.Message);
+                                                    }
+                                                    else
+                                                    {
+                                                        WriteError(RequestIn.StationName, content.Message);
+                                                    }
+                                                }
+                                                else
+                                                {
+                                                    WriteError(RequestIn.StationName, $"鏈壘鍒版潯鐮亄conveyorLineInfoRead.R_BoxCode}鏁版嵁");
+                                                }
+                                                #endregion
+                                                //}
+                                                //else
+                                                //{
+                                                //    WriteError(RequestIn.StationName, $"鏁版嵁鎴彇閿欒锛歿strings}");
+                                                //}
+                                            }
+                                        }
+                                        else
+                                        {
+                                            WriteError(RequestIn.StationName, $"鏈壘鍒拌澶囧瓙缂栧彿{RequestIn.StationCode}鐨勫崗璁俊鎭�");
+                                        }
+                                    }
+                                    foreach (var item in stationMangers.Where(x=>x.StationType==StationTypeEnum.StationType_OnlyOutbound.ObjToInt()))
+                                    {
+                                        DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+                                        if (deviceProRead != null)
+                                        {
+                                            R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
+                                            //鑾峰彇鐮佸灈鍙d换鍔℃洿鏂颁换鍔$姸鎬�
+                                            if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo > 0)
+                                            {
+                                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.R_TaskNo && x.NextAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt());
+                                                if (task != null)
+                                                {
+                                                    task.CurrentAddress = item.StationCode;
+                                                    task.NextAddress = task.TargetAddress;
+                                                    task.DeviceCode = item.StackerCraneCode;
+                                                    _taskService.UpdateTask(task, TaskStatusEnum.MD_Executing);
+                                                }
+                                            }
+                                        }
+                                    }
+                                    Thread.Sleep(100);
+                                }
                             }
                         }
-                    }
-                    else
-                    {
-                        WriteError(item.StationName, $"鏈壘鍒拌澶囧瓙缂栧彿{item.StationCode}鐨勫崗璁俊鎭�");
-                    }
+                        catch (Exception ex)
+                        {
+
+                            lockObj = 0;
+                            WriteError(nameof(ConveyorLineJob_CPH), $"閿欒淇℃伅锛歿ex.Message}");
+                        }
+                        
+                    });
                 }
+                
             }
             return Task.CompletedTask;
         }

--
Gitblit v1.9.3