完善输送线和堆垛机任务处理逻辑在CommonConveyorLine_NewCW.cs`中添加版本注释和设备属性定义,增强设备连接状态检查与命令发送逻辑。
修改 CommonConveyorLine_GWJob.cs`的任务查询逻辑,确保在特定条件下不下发新任务。在CommonConveyorLine_NewCWJob.cs中实现请求入库和出库的处理逻辑,确保任务状态更新。在 RequestInbound.cs中添加出库任务和新任务的处理逻辑,增强异常处理。
在CommonStackerCrane_NewCWJob.cs中实现堆垛机任务完成事件的处理,确保状态更新和前端通知。新增设备型号修改相关常量和 DTO 类,更新服务接口和实现逻辑,确保设备型号修改请求的正确处理。修改 Dt_TaskService.cs中的任务处理逻辑,确保出库任务的库存判断和状态更新。
已添加4个文件
已修改8个文件
2175 ■■■■■ 文件已修改
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine_NewCW.cs 342 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_NewCW/CommonConveyorLine_NewCWJob.cs 620 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_NewCW/NewCWTask/RequestInbound.cs 407 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob_NewCW/CommonStackerCrane_NewCWJob.cs 604 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Core/Const/ConfigConst.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MOM/ResponeAgingInputDto.cs 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_IStoragIntegrationServices/MOM/AgingInOrOutInput/IAgingInOrOutInputService.cs 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/RequestInTaskAsync.cs 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine_NewCW.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,342 @@
#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
/*----------------------------------------------------------------
 * å‘½åç©ºé—´ï¼šWIDESEAWCS_QuartzJob
 * åˆ›å»ºè€…:胡童庆
 * åˆ›å»ºæ—¶é—´ï¼š2024/8/2 16:13:36
 * ç‰ˆæœ¬ï¼šV1.0.0
 * æè¿°ï¼šä¸€èˆ¬è¾“送线实现类
 *
 * ----------------------------------------------------------------
 * ä¿®æ”¹äººï¼š
 * ä¿®æ”¹æ—¶é—´ï¼š
 * ç‰ˆæœ¬ï¼šV1.0.1
 * ä¿®æ”¹è¯´æ˜Žï¼š
 *
 *----------------------------------------------------------------*/
#endregion << ç‰ˆ æœ¬ æ³¨ é‡Š >>
using HslCommunication;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_QuartzJob.ConveyorLine.Enum;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
namespace WIDESEAWCS_QuartzJob
{
    [Description("常温新加输送线")]
    public class CommonConveyorLine_NewCW : IConveyorLine
    {
        #region Private Member
        /// <summary>
        /// å †åž›æœºé€šè®¯å¯¹è±¡
        /// </summary>
        private readonly BaseCommunicator _communicator;
        /// <summary>
        /// å †åž›æœºåè®®ä¿¡æ¯
        /// </summary>
        private readonly List<DeviceProDTO> _deviceProDTOs;
        /// <summary>
        /// å †åž›æœºåè®®æ˜Žç»†ä¿¡æ¯
        /// </summary>
        private readonly List<DeviceProtocolDetailDTO> _deviceProtocolDetailDTOs;
        /// <summary>
        /// è®¾å¤‡ç¼–号
        /// </summary>
        public readonly string _deviceCode;
        /// <summary>
        /// è®¾å¤‡åç§°
        /// </summary>
        public readonly string _deviceName;
        private bool _heartStatr = true;
        private bool _isConnected = true;
        #endregion
        #region Public Member
        /// <summary>
        /// è¾“送线通讯对象
        /// </summary>
        public BaseCommunicator Communicator => _communicator;
        /// <summary>
        /// è¾“送线协议信息
        /// </summary>
        public List<DeviceProDTO> DeviceProDTOs => _deviceProDTOs;
        /// <summary>
        /// è¾“送线协议明细信息
        /// </summary>
        public List<DeviceProtocolDetailDTO> DeviceProtocolDetailDTOs => _deviceProtocolDetailDTOs;
        /// <summary>
        /// è®¾å¤‡ç¼–号
        /// </summary>
        public string DeviceCode => _deviceCode;
        /// <summary>
        /// è®¾å¤‡åç§°
        /// </summary>
        public string DeviceName => _deviceName;
        /// <summary>
        /// æ˜¯å¦æœ‰æ•…éšœ
        /// </summary>
        public bool IsFault => false;
        /// <summary>
        /// é€šè®¯æ˜¯å¦å·²è¿žæŽ¥
        /// </summary>
        public bool IsConnected => Communicator.IsConnected && _isConnected;
        /// <summary>
        /// è®¾å¤‡çŠ¶æ€
        /// </summary>
        public DeviceStatus Status => DeviceStatus.Offline;
        #endregion
        #region Constructor Function
        /// <summary>
        /// æž„造函数
        /// </summary>
        /// <param name="communicator">堆垛机通讯对象</param>
        /// <param name="deviceProDTOs">堆垛机协议信息</param>
        /// <param name="deviceProtocolDetailDTOs">堆垛机协议明细信息</param>
        /// <param name="deviceCode">设备编号</param>
        /// <param name="deviceName">设备名称</param>
        public CommonConveyorLine_NewCW(BaseCommunicator communicator, List<DeviceProDTO> deviceProDTOs, List<DeviceProtocolDetailDTO> deviceProtocolDetailDTOs, string deviceCode, string deviceName)
        {
            _communicator = communicator;
            _deviceProDTOs = deviceProDTOs;
            _deviceProtocolDetailDTOs = deviceProtocolDetailDTOs;
            _deviceCode = deviceCode;
            _deviceName = deviceName;
            CheckConnect();
        }
        #endregion
        #region Private Method
        private void CheckConnect()
        {
            Task.Run(() =>
            {
                while (_heartStatr)
                {
                    try
                    {
                        DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault();
                        if (devicePro == null)
                            _isConnected = false;
                        else
                            Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
                        _isConnected = true;
                    }
                    catch (Exception ex)
                    {
                        _isConnected = false;
                    }
                    Thread.Sleep(500);
                }
            });
        }
        #endregion
        #region Public Method
        /// <summary>
        /// è¯»å–PLC协议地址的数据
        /// </summary>
        /// <typeparam name="TEnum">协议信息的枚举对象信息。</typeparam>
        /// <typeparam name="TRsult">读取数据的类型对象信息。</typeparam>
        /// <param name="value">枚举值</param>
        /// <param name="deviceChildCode">设备子编号</param>
        /// <returns>读取到的数据</returns>
        public TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum
        {
            if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络");
            DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString() && x.DeviceChildCode == deviceChildCode);
            return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
        }
        /// <summary>
        /// ä¸Žè®¾å¤‡çš„心跳
        /// </summary>
        public void Heartbeat()
        {
            throw new NotImplementedException();
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command"></param>
        /// <param name="deviceChildCode"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new()
        {
            if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络");
            DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
            if (devicePro == null)
            {
                return false;
            }
            if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command))
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// è¯»å–PLC数据,返回自定义对象
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="deviceChildCode">子设备编号</param>
        /// <returns>返回自定义对象或抛出异常</returns>
        /// <exception cref="Exception"></exception>
        public T ReadCustomer<T>(string deviceChildCode) where T : IDataTransfer, new()
        {
            if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络");
            DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == "DeviceCommand" && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
            if (devicePro == null)
            {
                throw new Exception($"【{_deviceCode}】--未找到【{deviceChildCode}】协议信息");
            }
            else
            {
                return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress);
            }
        }
        /// <summary>
        /// è¯»å–PLC数据,返回自定义对象
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="deviceChildCode">子设备编号</param>
        /// <param name="deviceProParamType">参数类型</param>
        /// <returns>返回自定义对象或抛出异常</returns>
        /// <exception cref="Exception"></exception>
        public T ReadCustomer<T>(string deviceChildCode, string deviceProParamType) where T : IDataTransfer, new()
        {
            if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络");
            DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == deviceProParamType && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
            if (devicePro == null)
            {
                throw new Exception($"未找到【{deviceChildCode}】协议信息");
            }
            else
            {
                return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress);
            }
        }
        /// <summary>
        /// æ ¹æ®å‚数名称、设备子编号写入对应的数据。
        /// </summary>
        /// <typeparam name="TEnum">参数名称枚举类型。</typeparam>
        /// <typeparam name="TValue">要写入的数据类型。</typeparam>
        /// <param name="enum">参数名称。</param>
        /// <param name="value">要写入的数据。</param>
        /// <param name="deviceChildCode">设备子编号写</param>
        /// <returns>返回写入成功或失败</returns>
        public bool SetValue<TEnum, TValue>(TEnum @enum, TValue value, string deviceChildCode)
            where TEnum : Enum
            where TValue : notnull
        {
            if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络");
            DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode);
            return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value);
        }
        /// <summary>
        /// æ ¹æ®å‚数名称、设备子编号读取对应的数据。
        /// </summary>
        /// <typeparam name="TEnum">参数名称枚举类型。</typeparam>
        /// <param name="enum">参数名称。</param>
        /// <param name="deviceChildCode">设备子编号写</param>
        /// <returns>返回写入成功或失败</returns>
        public object ReadValue<TEnum>(TEnum @enum, string deviceChildCode)
            where TEnum : Enum
        {
            if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络");
            DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode);
            return devicePro == null ? throw new Exception() : Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
        }
        //public bool IsOccupied(string deviceChildCode)
        //{
        //    if (Communicator.IsConnected)
        //    {
        //    }
        //}
        /// <summary>
        ///
        /// </summary>
        /// <param name="deviceChildCode"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public bool IsOccupied(string deviceChildCode)
        {
            if (Communicator.IsConnected)
            {
                List<DeviceProDTO> devicePros = _deviceProDTOs.Where(x => x.DeviceChildCode == deviceChildCode && x.DeviceProParamName == "InteractiveSignal").ToList();
                if (devicePros.Count == 0)
                {
                    //todo åè®®ä¿¡æ¯æœªèŽ·å–åˆ°æ—¶æŠ›å‡ºå¼‚å¸¸
                    throw new Exception();
                }
                for (int i = 0; i < devicePros.Count; i++)
                {
                    object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType);
                    //todo åè®®æ˜Žç»†ä¿¡æ¯æœªèŽ·å–åˆ°æ—¶æŠ›å‡ºå¼‚å¸¸
                    DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception();
                    deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == "InteractiveSignal" && x.ProtocalDetailValue.Equals(readStatus.ToString()));
                    if (deviceProtocolDetail != null)
                    {
                        return true;
                    }
                    return false;
                }
            }
            //todo é€šè®¯æœªè¿žæŽ¥æ—¶æŠ›å‡ºå¼‚常
            return false;
        }
        public void Dispose()
        {
            _heartStatr = false;
            _communicator.Dispose();
            GC.SuppressFinalize(this);
        }
        #endregion
    }
}
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs
@@ -231,10 +231,10 @@
                {
                    if (childDeviceCode == "1039")
                    {
                        var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList();
                        if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2"))
                        var GWTask = _taskRepository.QueryData(x => (x.Roadway.Contains("GWSC2")|| x.Roadway.Contains("GWSC3")) && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList();
                        if ((GWTask.Where(x => x.Roadway.Contains("GWSC2")).ToList().Count >= 2 && task.Roadway.Contains("GWSC2")) || (GWTask.Where(x => x.Roadway.Contains("GWSC3")).ToList().Count >= 2 && task.Roadway.Contains("GWSC3")))
                        {
                            ConsoleHelper.WriteErrorLine($"时间:【{DateTime.Now}】托盘号:【{command.ConveyorLineBarcode}】高温二已存在【{GWTask.Count}】个任务大于2个任务不可下发");
                            ConsoleHelper.WriteErrorLine($"时间:【{DateTime.Now}】托盘号:【{command.ConveyorLineBarcode}】高温{(task.Roadway.Contains("GWSC3")?"三":"二")}已存在【{GWTask.Count}】个任务大于2个任务不可下发");
                            return;
                        }
                    }
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_NewCW/CommonConveyorLine_NewCWJob.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,620 @@
#region MyRegion
#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
/*----------------------------------------------------------------
 * å‘½åç©ºé—´ï¼šWIDESEAWCS_Tasks.ConveyorLineJob
 * åˆ›å»ºè€…:胡童庆
 * åˆ›å»ºæ—¶é—´ï¼š2024/8/2 16:13:36
 * ç‰ˆæœ¬ï¼šV1.0.0
 * æè¿°ï¼š
 *
 * ----------------------------------------------------------------
 * ä¿®æ”¹äººï¼š
 * ä¿®æ”¹æ—¶é—´ï¼š
 * ç‰ˆæœ¬ï¼šV1.0.1
 * ä¿®æ”¹è¯´æ˜Žï¼š
 *
 *----------------------------------------------------------------*/
#endregion << ç‰ˆ æœ¬ æ³¨ é‡Š >>
using AutoMapper;
using HslCommunication;
using Masuit.Tools;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Quartz;
using SqlSugar;
using System.ComponentModel.Design;
using System.Reflection;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.HttpContextUser;
using WIDESEAWCS_DTO.MOM;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IProcessRepository;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
using Platform = WIDESEAWCS_Model.Models.Platform;
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public partial class CommonConveyorLine_NewCWJob : JobBase, IJob
    {
        public readonly ITaskService _taskService;
        private readonly ITaskRepository _taskRepository;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IPlatFormRepository _platFormRepository;
        private readonly ISys_ConfigService _sys_ConfigService;
        private readonly IMapper _mapper;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        private readonly IDt_needBarcodeRepository _needBarcodeRepository;
        private readonly IDeviceInfoRepository _deviceInfoRepository;
        private static List<string>? userTokenIds;
        private static List<int>? userIds;
        private static List<string> childCodeList = new List<string>();
        public CommonConveyorLine_NewCWJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, IPlatFormRepository platFormRepository, ISys_ConfigService sys_ConfigService, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService, IDt_needBarcodeRepository needBarcodeRepository, IDeviceInfoRepository deviceInfoRepository)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _mapper = mapper;
            _taskRepository = taskRepository;
            _platFormRepository = platFormRepository;
            _sys_ConfigService = sys_ConfigService;
            _stationManagerRepository = stationManagerRepository;
            _cacheService = cacheService;
            _noticeService = noticeService;
            _needBarcodeRepository = needBarcodeRepository;
            _deviceInfoRepository = deviceInfoRepository;
        }
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonConveyorLine_NewCW conveyorLine = (CommonConveyorLine_NewCW)context.JobDetail.JobDataMap.Get("JobParams");
                if (conveyorLine != null)
                {
                    #region ç«™å°æ–¹å¼
                    //List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
                    //foreach (var station in stationManagers)
                    //{
                    //    ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(station.stationChildCode);
                    //    DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString());
                    //    if (deviceProtocolDetails != null)
                    //    {
                    //        MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType);
                    //        if (method != null)
                    //        {
                    //            method.Invoke(this, new object[] { conveyorLine, command, station });
                    //        }
                    //    }
                    //}
                    #endregion ç«™å°æ–¹å¼
                    #region è·¯ç”±æ–¹å¼
                    List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
                    foreach (string childDeviceCode in childDeviceCodes)
                    {
                        ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode);
                        if (command == null) continue;
                        //if (command.InteractiveSignal == 0 && command.HasPallet != 1) continue;
                        if (command.ConveyorLineBarcode.Trim().Contains("\0")) command.ConveyorLineBarcode = "";
                        DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString());
                        if (deviceProtocolDetails != null)
                        {
                            MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType);
                            if (method != null)
                            {
                                method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode });
                            }
                        }
                        if (childDeviceCode == "1670" || childDeviceCode == "1666" || childDeviceCode == "1548" || childDeviceCode == "1448")
                        {
                            Platform platform = _platFormRepository.QueryFirst(x => x.DeviceCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active");
                            if (platform != null)
                            {
                                if (command.HasPallet != 1)
                                {
                                    MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod);
                                    if (method != null)
                                    {
                                        //var strings = platform.Location.Split(',').ToList();
                                        int count = 1;
                                        method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
                                    }
                                }
                            }
                        }
                        #region è°ƒç”¨äº‹ä»¶æ€»çº¿é€šçŸ¥å‰ç«¯
                        var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
                        if (tokenInfos == null || !tokenInfos.Any())
                        {
                            //throw new Exception(conveyorLine.DeviceName + "缓存中未找到Token缓存");
                            continue;
                        }
                        var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList();
                        var userIds = tokenInfos?.Select(x => x.UserId).ToList();
                        object obj = new
                        {
                            childDeviceCode,
                            commandAfter = command,
                        };
                        _noticeService.LineData(userIds?.FirstOrDefault(), userTokenIds, new { conveyorLine.DeviceName, data = obj });
                        #endregion è°ƒç”¨äº‹ä»¶æ€»çº¿é€šçŸ¥å‰ç«¯
                    }
                    #endregion è·¯ç”±æ–¹å¼
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(nameof(CommonConveyorLine_NewCW) + ":" + DateTime.Now + ":" + ex.ToString(),ex.StackTrace);
            }
            finally
            {
            }
            return Task.CompletedTask;
        }
        /// <summary>
        /// è¾“送线请求入库
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param>
        public void RequestInbound(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            try
            {
                var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode);
                var log = $"时间:【{DateTime.Now}】【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】任务号:【{command.ConveyorLineTaskNum}】设备编码:【{childDeviceCode}】";
                ConsoleHelper.WriteSuccessLine(log);
                //_noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                WriteInfo(conveyorLine.DeviceName, log);
                if (task == null)
                {
                    HandleNewTask(conveyorLine, command, childDeviceCode);
                }
                else
                {
                    if (childDeviceCode == "1039")
                    {
                        var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList();
                        if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2"))
                        {
                            ConsoleHelper.WriteErrorLine($"时间:【{DateTime.Now}】托盘号:【{command.ConveyorLineBarcode}】高温二已存在【{GWTask.Count}】个任务大于2个任务不可下发");
                            return;
                        }
                    }
                    ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                    bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                    if (sendFlag)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.ToString());
            }
        }
        /// <summary>
        /// è¾“送线请求入库下一地址
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestInNextAddress(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode);
            if (task != null)
            {
                if (command.ConveyorLineBarcode != task.PalletCode)
                {
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                    return;
                }
                Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
                if (newTask != null)
                {
                    ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask);
                    //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                    if (sendFlag)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        _taskService.UpdateData(newTask);
                    }
                }
            }
            //else
            //{
            //    //当前地址请求 å¯»æ‰¾å½“前地址的托盘号 ä»»åŠ¡å·çš„ä»»åŠ¡ï¼Œå¦‚å­˜åœ¨ä»»åŠ¡åˆ™é‡æ–°å†æ¬¡å†™å…¥æ–°ç›®æ ‡åœ°å€
            //    Dt_Task currentTask = _taskService.QueryExecutingCurrentConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode);
            //    if (currentTask != null)
            //    {
            //        conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(currentTask.TargetAddress), childDeviceCode);
            //    }
            //}
        }
        /// <summary>
        /// è¾“送线入库完成
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param>
        public void ConveyorLineInFinish(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            var task = _taskService.QueryExecutingTaskByBarcode(command.ConveyorLineBarcode, childDeviceCode);
            if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish)
            {
                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
                if (content.Status)
                {
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                }
                Console.Out.WriteLine(content.Serialize());
            }
        }
        /// <summary>
        /// è¾“送线请求出信息
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param>
        public void RequestOutbound(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
            if (task != null)
            {
                ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                if (sendFlag)
                {
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                    _taskService.UpdateTaskStatusToNext(task);
                    if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray)
                    {
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
        }
        /// <summary>
        /// è¾“送线请求出库下一地址
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestOutNextAddress(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode);
            if (task != null)
            {
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.MOMIP_BASE)?.ConfigValue;
                var ipAddress = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.TrayCellsStatus)?.ConfigValue;
                if (wmsBase == null || ipAddress == null)
                {
                    throw new InvalidOperationException("MOM IP æœªé…ç½®");
                }
                Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode);
                TrayCellsStatusDto trayCells = new TrayCellsStatusDto()
                {
                    Software = "WMS",
                    TrayBarcode = command.ConveyorLineBarcode,
                    EquipmentCode = stationManager.stationEquipMOM,
                    SessionId = Guid.NewGuid().ToString(),
                    EmployeeNo = "MITest",
                    SceneType = "1",
                    RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
                };
                var MOMIpAddress = wmsBase + ipAddress;
                var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.Serialize()).Result;
                WriteInfo("入站校验", $"【{childDeviceCode}】入站校验请求参数【{trayCells.Serialize()}】");
                WriteInfo("入站校验", "");
                WriteInfo("入站校验", $"【{childDeviceCode}】入站校验返回参数【{result}】");
                ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result);
                if (result1.Success || task.Remark != "NG")
                {
                    Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
                    if (newTask != null)
                    {
                        ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask);
                        //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                        if (sendFlag)
                        {
                            conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                            _taskService.UpdateData(newTask);
                        }
                    }
                }
                else
                {
                    ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                    taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode);
                    //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                    if (sendFlag)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
        }
        /// <summary>
        /// è¾“送线出库完成
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void ConveyorLineOutFinish(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            var log = $"时间:【{DateTime.Now}】【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】任务号:【{command.ConveyorLineTaskNum}】设备编码:【{childDeviceCode}】";
            ConsoleHelper.WriteSuccessLine(log);
            //_noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
            WriteInfo(conveyorLine.DeviceName, log);
            var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode);
            if (task != null)
            {
                WebResponseContent content = new WebResponseContent();
                ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                taskCommand.InteractiveSignal = command.InteractiveSignal;
                Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode);
                if (task.PalletCode != command.ConveyorLineBarcode)
                {
                    taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode);
                }
                else
                {
                    taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationLocation);
                }
                if (stationManager.stationPLC == "1018" && stationManager.stationArea == "Cache")  //更新在途数据
                {
                    dt_needBarcode needBarcode = _needBarcodeRepository.QueryFirst(x => x.productLine == stationManager.productLine && x.toArea == stationManager.stationChildCode);
                    if (needBarcode != null)
                    {
                        needBarcode.inLineNum--;
                        _needBarcodeRepository.UpdateData(needBarcode);
                    }
                }
                //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                if (sendFlag)
                {
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                    content = _taskService.UpdateTaskStatusToNext(task);
                }
            }
            else
            {
                var taskNext = _taskService.QueryExecutingConveyorLineTask(childDeviceCode, command.ConveyorLineBarcode);
                if (taskNext != null)
                {
                    WebResponseContent content = new WebResponseContent();
                    ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(taskNext);
                    taskCommand.InteractiveSignal = command.InteractiveSignal;
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode);
                    if (taskNext.PalletCode != command.ConveyorLineBarcode)
                    {
                        taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode);
                    }
                    else
                    {
                        taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationLocation);
                    }
                    if (stationManager.stationPLC == "1018" && stationManager.stationArea == "Cache")  //更新在途数据
                    {
                        dt_needBarcode needBarcode = _needBarcodeRepository.QueryFirst(x => x.productLine == stationManager.productLine && x.toArea == stationManager.stationChildCode);
                        if (needBarcode != null)
                        {
                            needBarcode.inLineNum--;
                            _needBarcodeRepository.UpdateData(needBarcode);
                        }
                    }
                    //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                    if (sendFlag)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        taskNext.ExceptionMessage = log;
                        content = _taskService.UpdateTaskStatusToNext(taskNext);
                    }
                }
            }
        }
        /// <summary>
        /// ç›‘测空托盘实盘出库
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="index">线体当前bool读取偏移地址</param>
        public async void EmptyTrayReturn(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, int index, WIDESEAWCS_Model.Models.Platform platform)
        {
            try
            {
                TaskOutboundTypeEnum taskOutboundTypeEnum;
                if (platform.PlatformType.Contains("OutTray"))
                    taskOutboundTypeEnum = TaskOutboundTypeEnum.OutTray;
                else
                    taskOutboundTypeEnum = TaskOutboundTypeEnum.Outbound;
                await CheckAndCreateTask(taskOutboundTypeEnum, childDeviceCode, index, platform);
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// æ£€æŸ¥ä»»åŠ¡å¹¶åˆ›å»ºæ–°ä»»åŠ¡
        /// </summary>
        private async Task CheckAndCreateTask(TaskOutboundTypeEnum taskType, string childDeviceCode, int index, Platform platform)
        {
            var tasks = _taskRepository.QueryData(x => x.TaskType == (int)taskType && x.TargetAddress == childDeviceCode);
            if (tasks.Count < platform.Capacity)
            {
                #region è°ƒç”¨WMS获取出库任务
                WMSTaskDTO taskDTO = new WMSTaskDTO();
                // èŽ·å–WMSip地址
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                var requestTrayOutTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTrayOutTask)?.ConfigValue;
                if (wmsBase == null || requestTrayOutTask == null)
                {
                    throw new InvalidOperationException("WMS IP æœªé…ç½®");
                }
                var wmsIpAddress = wmsBase + requestTrayOutTask;
                List<string> strings = platform.Location.Split(',').ToList();
                WriteInfo("调度执行时间记录", "【调取WMS出库接口开始时间:】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                var result = await HttpHelper.PostAsync(wmsIpAddress, new { Position = childDeviceCode, Tag = (int)taskType, AreaCdoe = platform.Stacker, AreaCdoes = strings, platform.ProductionLine }.Serialize());
                WriteInfo("调度执行时间记录", "【调取WMS出库接口结束时间:】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                // æ£€æŸ¥çŠ¶æ€å¹¶è¿”å›ž
                if (!content.Status)
                    return;
                taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                #endregion è°ƒç”¨WMS获取出库任务
                CreateAndSendTask(taskDTO);
            }
        }
        /// <summary>
        /// åˆ›å»ºä»»åŠ¡
        /// </summary>
        public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO)
        {
            var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
            if (content.Status)
            {
                Console.WriteLine($"{taskDTO.TaskType}呼叫成功");
            }
            return content;
        }
        public bool SendCommand(ConveyorLineTaskCommand_After taskCommand, CommonConveyorLine_NewCW conveyorLine, string childDeviceCode)
        {
            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode);
            Thread.Sleep(100);
            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode);
            Thread.Sleep(100);
            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode);
            for (int i = 0; i < 6; i++)
            {
                ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode);
                if (command != null)
                {
                    if (command.ConveyorLineBarcode == taskCommand.ConveyorLineBarcode && command.ConveyorLineTaskNum == taskCommand.ConveyorLineTaskNum && command.ConveyorLineTargetAddress == taskCommand.ConveyorLineTargetAddress)
                    {
                        WriteInfo(conveyorLine.DeviceName, $"时间:【{DateTime.Now}】写入任务成功写入次数{i}写入任务【{JsonConvert.SerializeObject(taskCommand)}】");
                        return true;
                    }
                    if (command.ConveyorLineTargetAddress != taskCommand.ConveyorLineTargetAddress)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode);
                        Thread.Sleep(100);
                    }
                    if (command.ConveyorLineBarcode != taskCommand.ConveyorLineBarcode)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode);
                        Thread.Sleep(100);
                    }
                    if (command.ConveyorLineTaskNum != taskCommand.ConveyorLineTaskNum)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode); Thread.Sleep(100);
                    }
                }
            }
            WriteInfo(conveyorLine.DeviceName, $"时间:【{DateTime.Now}】写入任务失败任务号【{taskCommand.ConveyorLineTaskNum}】托盘号【{taskCommand.ConveyorLineBarcode}】目标地址【{taskCommand.ConveyorLineTargetAddress}】当前节点【{childDeviceCode}】");
            return false;
        }
    }
}
#endregion
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_NewCW/NewCWTask/RequestInbound.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,407 @@
using Mapster;
using Masuit.Tools;
using Newtonsoft.Json;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_DTO.WMS;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
namespace WIDESEAWCS_Tasks
{
    public partial class CommonConveyorLine_NewCWJob
    {
        /// <summary>
        /// å¤„理出库任务
        /// </summary>
        private void HandleTaskOut(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, int ProtocalDetailValue, Dt_Task taskOut)
        {
            if (taskOut == null) return;
            var taskCommand = MapTaskCommand(taskOut, command);
            bool isOutTray = taskOut.TaskType == (int)TaskOutboundTypeEnum.OutTray;
            bool isOutboundAndOutFinish = taskOut.TaskType == (int)TaskOutboundTypeEnum.Outbound && taskOut.TaskState == (int)TaskOutStatusEnum.SC_OutFinish;
            bool isOutboundAndLineOutExecuting = taskOut.TaskType == (int)TaskOutboundTypeEnum.Outbound && taskOut.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting;
            if (isOutTray || isOutboundAndOutFinish || !isOutboundAndLineOutExecuting)
            {
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
                //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                _taskService.UpdateTaskStatusToNext(taskOut);
            }
            else if (taskOut.TaskType == (int)TaskOutboundTypeEnum.OutTray && taskOut.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting)
            {
                CompleteWmsTask(taskOut, command, conveyorLine, childDeviceCode, ProtocalDetailValue);
            }
        }
        /// <summary>
        /// å¤„理新任务
        /// </summary>
        private void HandleNewTask(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode);
            if (stationManager == null)
            {
                // Handle the case where stationManager is not found, if necessary
                Console.WriteLine($"未找到{childDeviceCode}站台");
                return;
            }
            // æ ¹æ®ç«™ç±»åž‹æ‰§è¡Œç›¸åº”的方法
            switch (stationManager.stationType)
            {
                case 8:
                case 9:
                case 11:
                case 12:
                    var task = _taskService.QueryExecutingTaskByBarcode(command.ConveyorLineBarcode, childDeviceCode);
                    if (task != null)
                    {
                        ExecuteStationAction(stationManager, conveyorLine, command, childDeviceCode);
                    }
                    break;
                case 1:
                case 6:
                case 10:
                    ExecuteStationAction(stationManager, conveyorLine, command, childDeviceCode);
                    break;
                    //case 16:
                    //    ExecuteStationAction(stationManager, conveyorLine, command, childDeviceCode);
                    //    break;
            }
            #region
            //Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode);
            //if (stationManager.stationType == 8)
            //{
            //    var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode);
            //    if (task != null)
            //    {
            //        RequestInNextAddress(conveyorLine, command, childDeviceCode);
            //    }
            //}
            //else if (stationManager.stationType == 9)
            //{
            //    var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode);
            //    if (task != null)
            //    {
            //        ConveyorLineInFinish(conveyorLine, command, childDeviceCode);
            //    }
            //}
            //else if (stationManager.stationType == 1)
            //{
            //    if (stationManager.stationArea.Contains("GW"))
            //    {
            //        var taskGW = _taskRepository.QueryFirst(x => x.TargetAddress == childDeviceCode && x.TaskState == (int)TaskOutStatusEnum.OutFinish);
            //        if (taskGW != null)
            //        {
            //            command.ConveyorLineBarcode = taskGW.PalletCode;
            //        }
            //    }
            //    RequestWmsTask(conveyorLine, command, childDeviceCode);
            //}
            //else if (stationManager.stationType == 10)
            //{
            //    var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
            //    if (task != null)
            //    {
            //        RequestOutbound(conveyorLine, command, childDeviceCode);
            //    }
            //}
            //else if (stationManager.stationType == 11)
            //{
            //    var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode);
            //    if (task != null)
            //    {
            //        RequestOutNextAddress(conveyorLine, command, childDeviceCode);
            //    }
            //}
            //else if (stationManager.stationType == 12)
            //{
            //    var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode);
            //    if (task != null)
            //    {
            //        ConveyorLineOutFinish(conveyorLine, command, childDeviceCode);
            //    }
            //}
            #endregion
        }
        private void ExecuteStationAction(Dt_StationManager stationManager, CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            switch (stationManager.stationType)
            {
                case 8:
                    RequestInNextAddress(conveyorLine, command, childDeviceCode);
                    break;
                case 9:
                    ConveyorLineInFinish(conveyorLine, command, childDeviceCode);
                    break;
                case 10:
                    RequestOutbound(conveyorLine, command, childDeviceCode);
                    break;
                case 11:
                    RequestOutNextAddress(conveyorLine, command, childDeviceCode);
                    break;
                case 12:
                    ConveyorLineOutFinish(conveyorLine, command, childDeviceCode);
                    break;
                case 6:
                    CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode);
                    break;
                case 16:
                    AbNormalStationBZTask(conveyorLine, command, childDeviceCode);
                    break;
                case 1:
                    RequestWmsTask(conveyorLine, command, childDeviceCode, stationManager);
                    break;
            }
        }
        /// <summary>
        /// æ˜ å°„任务命令
        /// </summary>
        private ConveyorLineTaskCommand_After MapTaskCommand(Dt_Task task, ConveyorLineTaskCommand_After command)
        {
            var comm = _mapper.Map<ConveyorLineTaskCommand_After>(task);
            comm.InteractiveSignal = command.InteractiveSignal;
            return comm;
        }
        /// <summary>
        /// å®ŒæˆWMS任务
        /// </summary>
        private void CompleteWmsTask(Dt_Task taskOut, ConveyorLineTaskCommand_After command, CommonConveyorLine_NewCW conveyorLine, string childDeviceCode, int ProtocalDetailValue)
        {
            if (command.ConveyorLineBarcode == "NoRead")
            {
                var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == taskOut.TargetAddress).Capacity;
                taskOut.TargetAddress = NGAddress.ToString();
            }
            var keys = new Dictionary<string, object>()
            {
                {"taskNum", taskOut.TaskNum}
            };
            var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
            var completeTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.CompleteTask)?.ConfigValue;
            if (wmsBase == null || completeTask == null)
            {
                throw new InvalidOperationException("WMS IP æœªé…ç½®");
            }
            var wmsIpAddress = wmsBase + completeTask;
            var result = HttpHelper.GetAsync(wmsIpAddress, keys).Result;
            WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
            if (content.Status)
            {
                //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                _taskService.UpdateTaskStatusToNext(taskOut);
            }
        }
        /// <summary>
        /// åˆ›å»ºå¹¶å‘送空托盘任务
        /// </summary>
        public void CreateAndSendEmptyTrayTask(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            if (command.ConveyorLineBarcode != "NoRead")
            {
                var taskDTO = CreateEmptyTrayTaskDto(command.ConveyorLineBarcode, childDeviceCode);
                if (_taskRepository.QueryFirst(x => x.PalletCode == command.ConveyorLineBarcode) != null)
                {
                    List<string> strings = new List<string>() { "1743", "1739", "1837", "1841" };
                    var taskExecuting = _taskRepository.QueryFirst(x => x.PalletCode == command.ConveyorLineBarcode && x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting && strings.Contains(x.TargetAddress));
                    if (taskExecuting != null)
                    {
                        taskExecuting.ExceptionMessage = "未接收到线体完成信号系统内部自动完成";
                        _taskService.Delete(taskExecuting);
                    }
                    ConsoleHelper.WriteErrorLine($"当前托盘存在任务:【{command.ConveyorLineBarcode}】");
                    WriteInfo(conveyorLine.DeviceName, $"当前托盘存在任务{command.ConveyorLineBarcode}");
                }
                var content = CreateAndSendTask(taskDTO);
                if (content.Status)
                {
                    var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.ConveyorLineBarcode);
                    if (task != null)
                    {
                        var taskCommand = MapTaskCommand(task, command);
                        bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                        if (sendFlag)
                        {
                            _taskService.UpdateTaskStatusToNext(task);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// åˆ›å»ºç©ºæ‰˜ç›˜ä»»åŠ¡DTO
        /// </summary>
        private WMSTaskDTO CreateEmptyTrayTaskDto(string barcode, string childDeviceCode)
        {
            var request = new RequestTaskDto()
            {
                Position = childDeviceCode,
                PalletCode = barcode,
            };
            var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
            var requestTrayInTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTrayInTask)?.ConfigValue;
            if (wmsBase == null || requestTrayInTask == null)
            {
                throw new InvalidOperationException("WMS IP æœªé…ç½®");
            }
            var wmsIpAddrss = wmsBase + requestTrayInTask;
            var result = HttpHelper.PostAsync(wmsIpAddrss, request.ToJsonString()).Result;
            if (result == null)
                return new WMSTaskDTO();
            WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
            if (!content.Status)
                return new WMSTaskDTO();
            return JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
        }
        /// <summary>
        /// è¯·æ±‚WMS任务
        /// </summary>
        private async void RequestWmsTask(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, Dt_StationManager stationManager)
        {
            try
            {
                if (command.ConveyorLineBarcode.IsNullOrEmpty()) return;
                var content = await _taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode);
                if (content.Status)
                {
                    var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode);
                    if (task != null)
                    {
                        if (childDeviceCode == "1039")
                        {
                            var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList();
                            if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2"))
                            {
                                ConsoleHelper.WriteErrorLine($"托盘号:【{command.ConveyorLineBarcode}】高温二已存在【{GWTask.Count}】个任务大于2个任务不可下发");
                                return;
                            }
                        }
                        ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                        bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                        if (sendFlag)
                        {
                            conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                            _taskService.UpdateTaskStatusToNext(task);
                        }
                    }
                }
                else
                {
                    if (content.Message != "请求过于频繁,请稍后再试" && content.Message != "无法获取目标地址")
                    {
                        WriteInfo(conveyorLine.DeviceName, content.Message);
                        conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, stationManager.stationNGChildCode, childDeviceCode);
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        ConsoleHelper.WriteErrorLine($"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{content.Message}】");
                        WriteInfo(conveyorLine.DeviceName, $"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{content.Message}】");
                    }
                    ConsoleHelper.WriteErrorLine($"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{content.Message}】");
                }
            }
            catch (Exception ex)
            {
                WriteInfo(conveyorLine.DeviceName, $"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{ex.Message}】异常行【{ex.StackTrace}】");
            }
        }
        /// <summary>
        /// é«˜æ¸©å‡ºåº“后任务完成 å¦‚果任务标识NG则将任务改为异常排出任务
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="command"></param>
        /// <param name="childDeviceCode"></param>
        /// <param name="task"></param>
        /// <exception cref="Exception"></exception>
        private void CreateAbNormalOutbound(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, Dt_Task task)
        {
            Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode);
            if (stationManager == null || string.IsNullOrWhiteSpace(stationManager.stationNGChildCode) || string.IsNullOrWhiteSpace(stationManager.stationNGLocation))
            {
                throw new Exception("未配置站台的对应NG口信息");
            }
            task.SourceAddress = task.TargetAddress;
            task.TargetAddress = stationManager.stationNGLocation;
            task.TaskState = (int)TaskOutStatusEnum.OutNew;
            task.TaskType = (int)TaskOutboundTypeEnum.InToOut;
            task.Grade = 10;    //此处 å‡ºåº“至异常排出口的任务应除火警外最优先执行
            _taskRepository.UpdateData(task);
            //Dt_Task task= _taskRepository.QueryFirst(x=>)
            //_taskRepository.QueryFirst()
        }
        /// <summary>
        /// åŒ…装异常排出口逻辑
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="command"></param>
        /// <param name="childDeviceCode"></param>
        private void AbNormalStationBZTask(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode);
            if (command.ConveyorLineBarcode.IsNullOrEmpty())
            {
                conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                return;
            }
            if (conveyorLine.ReadValue(ConveyorLineDBName_After.InteractiveSignal, childDeviceCode).ObjToInt() == 0) //托盘正反信号
            {
            }
            ;
            conveyorLine.ReadValue(ConveyorLineDBName_After.InteractiveSignal, childDeviceCode);  //托盘有无电芯信号
        }
    }
}
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob_NewCW/CommonStackerCrane_NewCWJob.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,604 @@
using Mapster;
using Newtonsoft.Json;
using Quartz;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.HttpContextUser;
using WIDESEAWCS_IProcessRepository;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfo_HtyRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonStackerCrane_NewCWJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly ITaskRepository _taskRepository;
        private readonly IRouterService _routerService;
        private readonly IProcessRepository _processRepository;
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly ITask_HtyRepository _htyRepository;
        private readonly ISys_ConfigService _sys_ConfigService;
        private static List<string>? userTokenIds;
        private static List<int>? userIds;
        public CommonStackerCrane_NewCWJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository htyRepository, ISys_ConfigService sys_ConfigService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _routerService = routerService;
            _processRepository = processRepository;
            _cacheService = cacheService;
            _noticeService = noticeService;
            _stationManagerRepository = stationManagerRepository;
            _htyRepository = htyRepository;
            _sys_ConfigService = sys_ConfigService;
        }
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonStackerCrane_NewCW commonStackerCrane = (CommonStackerCrane_NewCW)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonStackerCrane != null)
                {
                    if (!commonStackerCrane.IsEventSubscribed)
                    {
                        commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
                    }
                    if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
                    {
                        commonStackerCrane.CheckStackerCraneTaskCompleted();//防止任务完成事件监测超时,再手动触发一次
                        if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                        {
                            Dt_Task? task = GetTask(commonStackerCrane);
                            if (task != null)
                            {
                                StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
                                if (stackerCraneTaskCommand != null)
                                {
                                    var taskNum = commonStackerCrane.GetValue<StackerCraneDBName, int>(StackerCraneDBName.TaskNum);
                                    //var taskBarCode = commonStackerCrane.GetValue<StackerCraneDBName, string>(StackerCraneDBName.Barcode);
                                    ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】堆垛机任务号:【{taskNum}】任务任务号:【{task.TaskNum}】", ConsoleColor.DarkBlue);
                                    if (taskNum == 0)
                                    {
                                        ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】任务号为【{0}】,任务号不一致可以下发任务", ConsoleColor.DarkBlue);
                                        Thread.Sleep(1000);
                                        bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                        if (sendFlag)
                                        {
                                            StringBuilder builder = new StringBuilder();
                                            builder.AppendLine();
                                            builder.AppendLine($"【{commonStackerCrane.DeviceName}】堆垛机状态:【{commonStackerCrane.StackerCraneStatusDes}】,时间:【{DateTime.Now}】");
                                            builder.AppendLine($"【{commonStackerCrane.DeviceName}】手自动状态:【{commonStackerCrane.StackerCraneAutoStatusDes}】,时间:【{DateTime.Now}】");
                                            builder.AppendLine($"【{commonStackerCrane.DeviceName}】作业状态:【{commonStackerCrane.StackerCraneWorkStatusDes}】,时间:【{DateTime.Now}】");
                                            builder.AppendLine($"【{commonStackerCrane.DeviceName}】下发任务成功,【{JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}】");
                                            builder.AppendLine($"时间:【{DateTime.Now}】");
                                            builder.AppendLine();
                                            ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue);
                                            commonStackerCrane.LastTaskType = task.TaskType;
                                            _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                        }
                                    }
                                    else
                                    {
                                        ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】任务号不为【{0}】,不可以下发任务", ConsoleColor.DarkBlue);
                                    }
                                }
                            }
                        }
                    }
                    #region è°ƒç”¨äº‹ä»¶æ€»çº¿é€šçŸ¥å‰ç«¯
                    var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
                    if (tokenInfos != null && tokenInfos.Any())
                    {
                        var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList();
                        var userIds = tokenInfos?.Select(x => x.UserId).ToList();
                        object obj = new
                        {
                            commonStackerCrane.StackerCraneStatusDes,
                            commonStackerCrane.StackerCraneAutoStatusDes,
                            commonStackerCrane.StackerCraneWorkStatusDes,
                            commonStackerCrane.DeviceCode,
                            commonStackerCrane.DeviceName,
                            commonStackerCrane.CurrentTaskNum,
                            commonStackerCrane.LastTaskNum,
                        };
                        _noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonStackerCrane.DeviceName, data = obj });
                    }
                    #endregion è°ƒç”¨äº‹ä»¶æ€»çº¿é€šçŸ¥å‰ç«¯
                }
            }
            catch (Exception ex)
            {
                WriteError("CommonConveyorLineJob", "test", ex);
                ConsoleHelper.WriteErrorLine($"{ex.Message}");
                //Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
            }
            //WriteDebug("CommonConveyorLineJob", "test");
            return Task.CompletedTask;
        }
        /// <summary>
        /// ä»»åŠ¡å®Œæˆäº‹ä»¶è®¢é˜…çš„æ–¹æ³•
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e)
        {
            CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
            if (commonStackerCrane != null)
            {
                if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
                {
                    ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】堆垛机作业状态:【{(int)commonStackerCrane.StackerCraneWorkStatusValue}】时间【{DateTime.Now}】", ConsoleColor.Magenta);
                    string str = $"【{commonStackerCrane.DeviceName}】任务完成,任务号:【{e.TaskNum}】时间【{DateTime.Now}】";
                    WriteInfo(commonStackerCrane.DeviceName, str);
                    ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                    var task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum);
                    if (task == null) commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                    if (commonStackerCrane.DeviceCode.Contains("CW") && task.TaskType==(int)TaskOutboundTypeEnum.InToOut)
                    {
                        var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1017" && x.stationType == 10 && x.Roadway == commonStackerCrane.DeviceCode);
                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationinfo.stationPLC);
                        if (device != null)
                        {
                            CommonConveyorLine_NewCW conveyorLine = (CommonConveyorLine_NewCW)device;
                            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(1815), stationinfo.stationChildCode);
                            Thread.Sleep(100);
                            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, 1000, stationinfo.stationChildCode);
                        }
                        WriteInfo(commonStackerCrane.DeviceName, $"【手动出库记录】任务号【{e.TaskNum}】托盘号【{task.PalletCode}】");
                    }
                    if (commonStackerCrane.DeviceCode.Contains("GW") && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                    {
                        var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.TargetAddress);
                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == station.stationPLC);
                        if (device != null)
                        {
                            CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device;
                            var isResult = conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, task.PalletCode, task.TargetAddress);
                            if (!isResult)
                            {
                                var result = conveyorLine.GetValue<ConveyorLineDBName_After, string>(ConveyorLineDBName_After.ConveyorLineBarcode, task.TargetAddress);
                                if (result != task.PalletCode)
                                {
                                    conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, task.PalletCode, task.TargetAddress);
                                }
                            }
                        }
                        else
                            return;
                    }
                    var content = _taskService.StackCraneTaskCompleted(e.TaskNum);
                    if (commonStackerCrane.DeviceCode.Contains("CH") && task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
                    {
                        task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum);
                        Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
                        _taskService.UpdateData(newTask);
                    }
                    if ((task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && (task.TargetAddress == "002-021-001" || task.TargetAddress == "001-021-001"))|| task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm)
                    {
                        var TASKHTY = task.Adapt<Dt_Task_Hty>();
                        _taskRepository.DeleteData(task);
                        _htyRepository.AddData(TASKHTY);
                    }
                    var isWorkType = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                    str = $"{commonStackerCrane.DeviceName}】WMS|WCS任务完成:【{content.Status}】,堆垛机完成信号写入:【{isWorkType}】,任务号:【{e.TaskNum}】时间【{DateTime.Now}】";
                    WriteInfo(commonStackerCrane.DeviceName, str);
                    ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                }
            }
        }
        /// <summary>
        /// èŽ·å–ä»»åŠ¡
        /// </summary>
        /// <param name="commonStackerCrane">堆垛机对象</param>
        /// <returns></returns>
        private Dt_Task? GetTask(CommonStackerCrane_NewCW commonStackerCrane)
        {
            Dt_Task task;
            task = _taskService.QueryOutFireAlarmTask(commonStackerCrane.DeviceCode);
            if (task != null)
            {
                return task;
            }
            if (commonStackerCrane.LastTaskType == null)
            {
                task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
            }
            else
            {
                var lastTaskTypeGroup = commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup();
                if (lastTaskTypeGroup == TaskTypeGroup.OutbondGroup)
                {
                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                    if (task == null)
                    {
                        task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
                    }
                }
                else
                {
                    task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
                }
            }
            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            {
                // æ£€æŸ¥å½“前出库任务站台是否允许放货
                var occupiedStation = OutTaskStationIsOccupied(task);
                if (occupiedStation == null)
                {
                    // å¦‚果当前出库任务站台不允许放货,排除当前任务,查找其他出库任务
                    var log = $"任务号:【{task.TaskNum}】出库地址:【{task.NextAddress}】不允许放货";
                    ConsoleHelper.WriteErrorLine(log);
                    _noticeService.Logs(userTokenIds, new { commonStackerCrane.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                    WriteInfo(commonStackerCrane.DeviceName, log);
                    task = FindAnotherOutboundTask(commonStackerCrane.DeviceCode, task.TaskId);
                    if (task == null)
                    {
                        task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                    }
                }
                else
                {
                    return task;
                }
            }
            else if (task == null)
            {
                task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
            }
            return task;
        }
        /// <summary>
        /// å‡ºåº“任务判断出库站台是否被占用
        /// </summary>
        /// <param name="task">任务实体</param>
        /// <returns>如果未被占用,返回传入的任务信息,否则,返回null</returns>
        private Dt_Task? OutTaskStationIsOccupied([NotNull] Dt_Task task)
        {
            Dt_Router? router = _routerService.QueryNextRoutes(task.Roadway, task.NextAddress).FirstOrDefault();
            if (task.Roadway.Contains("GW") || task.Roadway.Contains("CW"))
            {
                if (router != null)
                {
                    IDevice? device = null;
                    if (task.Roadway.Contains("CW"))
                    {
                        device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == router.ChildPosiDeviceCode);
                        if (device != null)
                        {
                            CommonConveyorLine_NewCW conveyorLine = (CommonConveyorLine_NewCW)device;
                            if (conveyorLine.IsOccupied(task.NextAddress))//出库站台未被占用
                            {
                                return task;
                            }
                        }
                        else
                        {
                            _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{task.NextAddress}】对应的通讯对象,无法判断出库站台是否被占用");
                        }
                    }
                }
                else
                {
                    IDevice? device = null;
                    if (task.Roadway.Contains("GW"))
                    {
                        device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1015");
                        if (device != null)
                        {
                            CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device;
                            if (conveyorLine.IsOccupied(task.TargetAddress))//出库站台未被占用
                            {
                                return task;
                            }
                        }
                        else
                        {
                            _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{task.TargetAddress}】对应的通讯对象,无法判断出库站台是否被占用");
                        }
                    }
                    //_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.TargetAddress}】信息,无法校验站台");
                }
            }
            else
            {
                if ((task.NextAddress == ("002-021-001") || task.NextAddress == ("001-021-001")) && task.Roadway.Contains("JZ"))
                {
                    return task;
                }
                else
                {
                    //Dt_Router? router = _routerService.QueryNextRoutes(task.Roadway, task.NextAddress).FirstOrDefault();
                    if (router != null)
                    {
                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == router.ChildPosiDeviceCode);
                        if (device != null)
                        {
                            CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                            if (conveyorLine.IsOccupiedx(router.ChildPosi))//出库站台未被占用
                            {
                                return task;
                            }
                        }
                        else
                        {
                            _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{router.ChildPosiDeviceCode}】对应的通讯对象,无法判断出库站台是否被占用");
                        }
                    }
                    else
                    {
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.NextAddress}】信息,无法校验站台");
                    }
                }
            }
            return null;
        }
        /// <summary>
        /// æŸ¥æ‰¾å…¶ä»–出库任务的辅助方法(排除指定任务ID的任务)
        /// </summary>
        /// <param name="deviceCode">设备代码</param>
        /// <param name="excludedTaskId">要排除的任务ID</param>
        /// <returns></returns>
        private Dt_Task? FindAnotherOutboundTask(string deviceCode, int excludedTaskId)
        {
            // å…ˆèŽ·å–æ‰€æœ‰ç¬¦åˆæ¡ä»¶ï¼ˆæŽ’é™¤æŒ‡å®šä»»åŠ¡ID)的出库任务列表
            var allOutboundTasks = _taskService.QueryAllOutboundTasks(deviceCode);
            var availableTasks = allOutboundTasks?.Where(t => excludedTaskId != t.TaskId && t.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup).ToList();
            if (availableTasks == null || availableTasks.Count == 0)
            {
                return null;
            }
            // éåŽ†å¯ç”¨ä»»åŠ¡åˆ—è¡¨ï¼Œæ£€æŸ¥ä»»åŠ¡ç«™å°æ˜¯å¦å…è®¸æ”¾è´§ï¼Œæ‰¾åˆ°ç¬¬ä¸€ä¸ªå…è®¸æ”¾è´§çš„ä»»åŠ¡å°±è¿”å›ž
            foreach (var candidateTask in availableTasks)
            {
                var occupiedStation = OutTaskStationIsOccupied(candidateTask);
                if (occupiedStation != null)
                {
                    return candidateTask;
                }
                var log = $"任务号:【{candidateTask.TaskNum}】出库地址:【{candidateTask.NextAddress}】不允许放货";
                ConsoleHelper.WriteErrorLine(log);
                _noticeService.Logs(userTokenIds, new { deviceCode, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                WriteInfo(deviceCode, log);
            }
            return null;
        }
        /// <summary>
        /// ä»»åŠ¡å®žä½“è½¬æ¢æˆå‘½ä»¤Model
        /// </summary>
        /// <param name="task">任务实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
        {
            StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
            stackerCraneTaskCommand.Barcode = task.PalletCode;
            stackerCraneTaskCommand.TaskNum = task.TaskNum;
            stackerCraneTaskCommand.WorkType = 1;
            stackerCraneTaskCommand.TrayType = 0;
            stackerCraneTaskCommand.StartCommand = 1;
            stackerCraneTaskCommand.FireCommand = Convert.ToInt16(task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm ? 2 : 0);
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            {
                var value = _sys_ConfigService.GetByConfigKey(CateGoryConst.CONFIG_SYS_InStation, SysConfigKeyConst.JZNGInBoundStation).ConfigValue;
                var valueList = value.Split(',').ToList();
                if ((valueList.Contains(task.SourceAddress)) && task.Roadway.Contains("JZ"))
                {
                    string[] souredCodes = task.CurrentAddress.Split("-");
                    if (souredCodes.Length == 3)
                    {
                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(souredCodes[0]);
                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(souredCodes[1]);
                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(souredCodes[2]);
                    }
                    else
                    {
                        //数据配置错误
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"入库任务起点错误,起点:【{task.CurrentAddress}】");
                        return null;
                    }
                    string[] targetCodes = task.NextAddress.Split("-");
                    if (targetCodes.Length == 3)
                    {
                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]) % 2 != 0 ? (short)1 : (short)2;
                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                    }
                    else
                    {
                        //数据配置错误
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"入库任务终点错误,起点:【{task.NextAddress}】");
                        return null;
                    }
                }
                else
                {
                    List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.Roadway);
                    if (routers.Count > 0)
                    {
                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow);
                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn);
                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer);
                        string[] targetCodes = task.NextAddress.Split("-");
                        if (targetCodes.Length == 3)
                        {
                            stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]) % 2 != 0 ? (short)1 : (short)2;
                            stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                            stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                        }
                        else
                        {
                            //数据配置错误
                            _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"入库任务终点错误,起点:【{task.NextAddress}】");
                            return null;
                        }
                    }
                    else
                    {
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.NextAddress}】信息,无法获取对应的堆垛机取货站台信息");
                        return null;
                    }
                }
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            {
                if (task.Roadway.Contains("GW")|| task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm)
                {
                    string[] endCodes = task.NextAddress.Split("-");
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(endCodes[0]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(endCodes[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(endCodes[2]);
                    string[] sourceCodes = task.SourceAddress.Split("-");
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2;
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                }
                else
                {
                    if ( task.TaskType == (int)TaskOutboundTypeEnum.InToOut)
                    {
                        string[] endCodes = task.TargetAddress.Split("-");
                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(endCodes[0]);
                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(endCodes[1]);
                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(endCodes[2]);
                        string[] sourceCodes = task.SourceAddress.Split("-");
                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2;
                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                    }
                    else if (((task.TargetAddress == "002-021-001" || task.TargetAddress == "001-021-001") && task.Roadway.Contains("JZ")) || task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm)
                    {
                        string[] endCodes = task.NextAddress.Split("-");
                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(endCodes[0]);
                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(endCodes[1]);
                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(endCodes[2]);
                        string[] sourceCodes = task.SourceAddress.Split("-");
                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2;
                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                    }
                    else
                    {
                        List<Dt_Router> routers = _routerService.QueryNextRoutes(task.Roadway, task.TargetAddress);
                        if (routers.Count > 0)
                        {
                            stackerCraneTaskCommand.EndRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow);
                            stackerCraneTaskCommand.EndColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn);
                            stackerCraneTaskCommand.EndLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer);
                            string[] sourceCodes = task.CurrentAddress.Split("-");
                            if (sourceCodes.Length == 3)
                            {
                                stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2;
                                stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                                stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                            }
                            else
                            {
                                //数据配置错误
                                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务起点错误,起点:【{task.CurrentAddress}】");
                                return null;
                            }
                        }
                        else
                        {
                            _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.NextAddress}】信息,无法获取对应的堆垛机放货站台信息");
                            return null;
                        }
                    }
                }
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
            {
                string[] targetCodes = task.NextAddress.Split("-");
                if (targetCodes.Length == 3)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]) % 2 != 0 ? (short)1 : (short)2;
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务终点错误,起点:【{task.NextAddress}】");
                    return null;
                }
                string[] sourceCodes = task.CurrentAddress.Split("-");
                if (sourceCodes.Length == 3)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2;
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
                }
            }
            return stackerCraneTaskCommand;
        }
    }
}
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Core/Const/ConfigConst.cs
@@ -113,6 +113,11 @@
        public const string AgingOutput = "AgingOutput";
        /// <summary>
        /// æ¢åž‹
        /// </summary>
        public const string EqptRun = "EqptRun";
        /// <summary>
        /// å·¥è‰ºè·¯çº¿ç”³è¯·
        /// </summary>
        public const string ProcessApply = "ProcessApply";
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MOM/ResponeAgingInputDto.cs
@@ -91,4 +91,30 @@
        /// </summary>
        public string ParameterCode { get; set; }
    }
    public class EqptRunDTO: BasicResult
    {
        public string WipOrderNo { get; set; }
        public string ProductDesc { get; set; }
        public string FirstArticleNum { get; set; }
        public string DebugNum { get; set; }
        public string ParamVersion { get; set; }
        public string ParamRefreshFlag { get; set; }
        public string ProductType { get; set; }
        public bool ProductModel { get; set; }
        public string ParameterInfo { get; set; }
        public string IsProcessed { get; set; }
        public string PreProductNo { get; set; }
    }
}
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_IStoragIntegrationServices/MOM/AgingInOrOutInput/IAgingInOrOutInputService.cs
@@ -18,4 +18,11 @@
    /// <param name="input">出库数据</param>
    /// <returns></returns>
    Task<WebResponseContent> GetOCVOutputAsync(AgingOutputDto input);
    /// <summary>
    /// ä¿®æ”¹è®¾å¤‡åž‹å·
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    Task<WebResponseContent> Change(EqptRunDto input);
}
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs
@@ -122,4 +122,41 @@
        }
        return content;
    }
    public async Task<WebResponseContent> Change(EqptRunDto input)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            input.SessionId = Guid.NewGuid().ToString();
            input.EmployeeNo = "MITest";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); // Specify the namespace explicitly
            var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress);
            var MOMBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue;
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.EqptRun)?.ConfigValue;
            if (MOMBase == null || ipAddress == null)
            {
                throw new InvalidOperationException("WMS IP æœªé…ç½®");
            }
            var MOMIpAddress = MOMBase + ipAddress;
            var result = HttpsClient.PostAsync(MOMIpAddress, inputJson).Result;
            //var respone = JsonConvert.DeserializeObject<EqptRunDTO>(result.ToString());
            content.OK(data: result);
            LogFactory.GetLog("换型").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("换型").Info(true, input.EquipmentCode);
            LogFactory.GetLog("换型").Info(true, result);
        }
        catch (Exception err)
        {
            LogFactory.GetLog("换型").Error(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("换型").Error(true, err.StackTrace);
            content.Error(err.Message);
        }
        return content;
    }
}
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -769,6 +769,7 @@
                //    return await HandleErrorCells(input, area, serialNosError);
                //}
                #endregion
                var boxing = CreateBoxingInfo(result, input.PalletCode);
                if (boxing == null) return content.Error("组盘失败");
@@ -932,7 +933,9 @@
        }
        else
        {
            _boxingInfoRepository.DeleteData(boxing);
            _boxingInfoRepository.Db.DeleteNav<DtBoxingInfo>(x => x.Id == boxing.Id)
                                            .Include(x => x.BoxingInfoDetails)
                                            .ExecuteCommandAsync();
            return new DtBoxingInfo
            {
                PalletCode = palletCode,
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
@@ -4,6 +4,7 @@
using SqlSugar;
using WIDESEA_Common.CustomModels;
using WIDESEA_Core.Const;
using WIDESEA_DTO;
using WIDESEA_DTO.MOM;
using WIDESEA_DTO.WMS;
using WIDESEA_Model.Models;
@@ -1078,24 +1079,39 @@
        WebResponseContent content = new WebResponseContent();
        try
        {
            LogFactory.GetLog($"包装请求出库任务").Info(true, $"【请求参数】:【{JsonConvert.SerializeObject(json)}】{Environment.NewLine}{Environment.NewLine}");
            Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == json.Position && x.stationType == 12 && x.stationArea == "Call");
            if (station == null) { throw new Exception($"未找到包装站台信息,请检查传入参数{json.Position}"); }
            EqptRunDto basic = new EqptRunDto()
            {
                EquipmentModel = "0",
                Password ="",
                EmployeeNo = "82412152",
                SessionId = Guid.NewGuid().ToString(),
                RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
                Software = "包装上料",
                EquipmentCode = station.stationEquipMOM,
            };
            var result = _agingInOrOutInputService.Change(basic).Result;
            var respone = JsonConvert.DeserializeObject<EqptRunDTO>(result.Data.ToString());
            if(!result.Status || !respone.Success)
            {
                throw new Exception($"{station.productLine}获取MOM换型数据异常,异常信息{respone.MOMMessage}");
            }
            var deviceCode = SqlSugarHelper.DbWCS.Queryable<Dt_DeviceInfo>()
                .Where(x => x.DeviceStatus == "1")
                .Where(x => x.DeviceCode.Contains("CWSC")) // è¿‡æ»¤æ¡ä»¶
                .ToList().Select(x => x.DeviceCode).ToList();
            //var outBoundMateriel = AppSettings.app<OutBoundMateriel>("OutBoundMateriel");
            var outBoundMateriel = _dt_ChangeoversRepository.QueryData(x => x.Status == "1").ToList();
            List<string>? materielCodes = outBoundMateriel.Count != 0
                ? outBoundMateriel.Where(x => x.ProductionLine == station.productLine && x.ProcessCode == "CWSC3")
                                  .Select(x => x.MaterielCode)
                                  .ToList()
                : null;
            //var outBoundMateriel = _dt_ChangeoversRepository.QueryData(x => x.Status == "1").ToList();
            //List<string>? materielCodes = outBoundMateriel.Count != 0
            //    ? outBoundMateriel.Where(x => x.ProductionLine == station.productLine && x.ProcessCode == "CWSC3")
            //                      .Select(x => x.MaterielCode)
            //                      .ToList()
            //    : null;
            #region
            #region Redis缓存查询代码
            //// ä»Žç¼“存中获取库存信息
            //IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
            //List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
@@ -1115,7 +1131,7 @@
            //    .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
            //    .FirstOrDefault();
            // ä¿®æ”¹åŽçš„æŸ¥è¯¢ä»£ç 
            #endregion
            //var stockInfo = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
            //                    .Includes(x => x.LocationInfo)
            //                    .Includes(x => x.StockInfoDetails)
@@ -1128,6 +1144,7 @@
            //                    .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
            //                    .OrderBy(x => x.OutboundTime)
            //                    .FirstAsync();
            #endregion
            DtStockInfo stockInfo = null;
            var stockInfoList = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
@@ -1143,7 +1160,7 @@
            foreach (var stock in stockInfoList)
            {
                var hasMatchingDetail = await _stockInfoRepository.Db.Queryable<DtStockInfoDetail>()
                    .Where(d => d.StockId == stock.Id && materielCodes.Contains(d.MaterielCode))
                    .Where(d => d.StockId == stock.Id && respone.PreProductNo.Contains(d.MaterielCode))
                    .AnyAsync();
                if (hasMatchingDetail)
@@ -1152,7 +1169,7 @@
                    break;
                }
            }
            if (stockInfo == null) throw new Exception($"库内{station.productLine}无满足条件的库存可出库");
            if (stockInfo == null) throw new Exception($"CWSC3库内【{station.productLine}】,【物料编码{respone.PreProductNo}】无满足条件的库存可出库");
            DtLocationInfo locationInfo = _locationRepository.QueryFirst(x => x.AreaId == 5 && x.LocationCode == stockInfo.LocationCode);
@@ -1189,7 +1206,6 @@
            _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(stockInfo.LocationInfo, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum);
            LogFactory.GetLog($"包装请求出库任务").Info(true, $"【返回参数】:【{JsonConvert.SerializeObject(taskDTO)}】{Environment.NewLine}{Environment.NewLine}");
            return content.OK(data: taskDTO);
        }
        catch (Exception ex)
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/RequestInTaskAsync.cs
@@ -45,26 +45,16 @@
        try
        {
            // åˆ¤æ–­éœ€ä¸éœ€è¦åŽ»åŒ…è£…ï¼Œä¸éœ€è¦å°±åŽ»å¸¸æ¸©ä¸‰
            var stationManagers = _stationManagerRepository.QueryData(x => x.stationPLC == "1018" && x.stationArea == "Cache" && x.productLine == input.ProductionLine);
            //var stationManagers = _stationManagerRepository.QueryData(x => x.stationPLC == "1018" && x.stationArea == "Cache" && x.productLine == input.ProductionLine);
            var STATION = _stationManagerRepository.QueryFirst(x => x.stationChildCode == input.Position);
            //var STATION = _stationManagerRepository.QueryFirst(x => x.stationChildCode == input.Position);
            //var station = stationManagers.Select(x => x.stationChildCode).ToList();
            //// èŽ·å–WCSip地址相关配置
            // èŽ·å–WCSip地址相关配置
            var wcsIpAddrss = GetWCSIpAddress();
            //if (wcsIpAddrss == null)
            //{
            //    throw new InvalidOperationException("WCS IP æœªé…ç½®");
            //}
            //var abc = HttpHelper.PostAsync(wcsIpAddrss, station.ToJsonString()).Result;
            //content = JsonConvert.DeserializeObject<WebResponseContent>(abc);
            //var num = content.Data.ObjToInt();
            //如果当前库内存在比当前时间的对应产线的料 åˆ™å…¥åº“至常温3
            DtStockInfo stockInfo = _stockInfoRepository.QueryFirst(x => x.AreaCode == "CWSC3" && x.IsFull == true && x.ProductionLine == STATION.productLine && x.OutboundTime < DateTime.Now);
            if (stockInfo != null)
            //DtStockInfo stockInfo = _stockInfoRepository.QueryFirst(x => x.AreaCode == "CWSC3" && x.IsFull == true && x.ProductionLine == STATION.productLine && x.OutboundTime < DateTime.Now);
            //if (stockInfo != null)
            {
                var config = _configService.GetByConfigKey("SYS_InStacker", "CW3InStacker");
                var strings = config.ConfigValue.Split(',').ToList();
@@ -79,32 +69,34 @@
            // TODO åˆ¤æ–­åœ¨é€”数量
            var needBarcode = await SqlSugarHelper.DbWCS.Queryable<dt_needBarcode>().FirstAsync(x => x.productLine == STATION.productLine && x.fromArea == "CW");
            var needCount =  BaseDal.QueryData(x => x.TargetAddress == needBarcode.toArea).Count();
            //var count = BaseDal.QueryData(x => x.TargetAddress == stationManagers[0].Roadway).Count;
            if (needCount < needBarcode.cacheNum)
            {
                // é€è‡³åŒ…装
                List<string> strings = stationManagers.Where(x => x.stationType == 0 && x.productLine == input.ProductionLine).Select(x => x.Roadway).ToList();
                var x = await SqlSugarHelper.DbWCS.Updateable<dt_needBarcode>()
                    .SetColumns(x => x.inLineNum == x.inLineNum + 1)
                    .Where(x => x.id == needBarcode.id).ExecuteCommandHasChangeAsync();
                ConsoleHelper.WriteSuccessLine($"在途数量添加{(x ? "成功" : "失败")}数量+1,当前工序{boxing.ProcessCode},产线{input.ProductionLine}");
                LogFactory.GetLog("OCVB").InfoFormat(true, $"在途数量添加{(x ? "成功" : "失败")}数量+1,当前工序{boxing.ProcessCode},产线{input.ProductionLine}", "无参数");
                return await CreateNewTask(input, input.ProductionLine, boxing.ProcessCode, strings, 3);
            }
            else
            {
                var config = _configService.GetByConfigKey("SYS_InStacker", "CW3InStacker");
                var strings = config.ConfigValue.Split(',').ToList();
                // å…¥åº“送至常温3
                var resultContent = await CreateNewTask(input, input.ProductionLine, boxing.ProcessCode, strings);
                if (resultContent.Status)
                {
                    await _boxingInfoRepository.AddDataNavAsync(boxing);
                }
                return resultContent;
            }
            #region OCV常温3直接去包装路径不通此逻辑不需要
            //var needBarcode = await SqlSugarHelper.DbWCS.Queryable<dt_needBarcode>().FirstAsync(x => x.productLine == STATION.productLine && x.fromArea == "CW");
            //var needCount =  BaseDal.QueryData(x => x.TargetAddress == needBarcode.toArea).Count();
            //if (needCount < needBarcode.cacheNum)
            //{
            //    // é€è‡³åŒ…装
            //    List<string> strings = stationManagers.Where(x => x.stationType == 0 && x.productLine == input.ProductionLine).Select(x => x.Roadway).ToList();
            //    var x = await SqlSugarHelper.DbWCS.Updateable<dt_needBarcode>()
            //        .SetColumns(x => x.inLineNum == x.inLineNum + 1)
            //        .Where(x => x.id == needBarcode.id).ExecuteCommandHasChangeAsync();
            //    ConsoleHelper.WriteSuccessLine($"在途数量添加{(x ? "成功" : "失败")}数量+1,当前工序{boxing.ProcessCode},产线{input.ProductionLine}");
            //    LogFactory.GetLog("OCVB").InfoFormat(true, $"在途数量添加{(x ? "成功" : "失败")}数量+1,当前工序{boxing.ProcessCode},产线{input.ProductionLine}", "无参数");
            //    return await CreateNewTask(input, input.ProductionLine, boxing.ProcessCode, strings, 3);
            //}
            //else
            //{
            //    var config = _configService.GetByConfigKey("SYS_InStacker", "CW3InStacker");
            //    var strings = config.ConfigValue.Split(',').ToList();
            //    // å…¥åº“送至常温3
            //    var resultContent = await CreateNewTask(input, input.ProductionLine, boxing.ProcessCode, strings);
            //    if (resultContent.Status)
            //    {
            //        await _boxingInfoRepository.AddDataNavAsync(boxing);
            //    }
            //    return resultContent;
            //}
            #endregion
        }
        catch (Exception ex)
        {