1
huangxiaoqiang
3 天以前 ec9c9add38591d7c7a2708ac43ed6b3fce1a4063
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs
@@ -2,6 +2,7 @@
using Mapster;
using Newtonsoft.Json;
using SqlSugar;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
@@ -12,8 +13,11 @@
using WIDESEAWCS_Model.BasicInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
{
@@ -63,31 +67,7 @@
            var RGVName = string.Empty;
            if (stationManager.stationFloor == "1F")
            {
                var deviceCode = _deviceInfoRepository.Db.Queryable<Dt_DeviceInfo>().Where(x => x.DeviceStatus == "1" && x.DeviceRemark == "1F").Where(x => x.DeviceCode.Contains("RGV")).ToList().Select(x => x.DeviceCode).ToList();
                if (deviceCode != null && deviceCode.Count() > 0)
                {
                    if (deviceCode.Contains("RGV01") && deviceCode.Contains("RGV02"))
                    {
                        var RGVOne = _taskRepository.QueryData(x => x.RGVName == "RGV01").ToList();
                        var RGVTwo = _taskRepository.QueryData(x => x.RGVName == "RGV02").ToList();
                        if (RGVOne.Count > RGVTwo.Count)
                        {
                            RGVName = "RGV01";
                        }
                        else
                        {
                            RGVName = "RGV02";
                        }
                    }
                    else
                    {
                        RGVName = deviceCode[0];
                    }
                }
                else
                {
                    RGVName = "RGV01";
                }
                RGVName = stationManager.RGVName;
            }
            else
            {
@@ -100,44 +80,108 @@
                TaskState = (int)TaskInStatusEnum.InNew,
                SourceAddress = childDeviceCode,
                Dispatchertime = DateTime.Now,
                Grade = 1, // è®¾ç½®é»˜è®¤ä¼˜å…ˆçº§ä¸º1
                Grade = 1,
                Creater = "System",
                Floor = stationManager.stationFloor,
                RGVName = stationManager.RGVName != null ? stationManager.RGVName : RGVName,
                RGVName = RGVName,
                SourceStation = stationManager.remark,
                TargetStation = 0,
            };
            _taskRepository.AddData(task);
        }
        private void RequestWMSTask(CommonConveyorLine conveyorLine,  Dt_StationManager stationManager)
        {
            var Barcode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.ConveyorLineBarcode, stationManager.stationNextChildCode);
            if (Barcode == "")
            {
                conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal,Convert.ToSByte(3), stationManager.stationChildCode);
            }
            var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode);
            if (task != null)
            if (stationManager.stationChildCode == "3002")
            {
                var newTask = _taskRepository.QueryFirst(x => x.TargetAddress == "3004");
                if (newTask != null)
                {
                    return;
                }
                DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault();
                var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 10);
                string Barcode = Encoding.UTF8.GetString(x);
                if (Barcode == null || Barcode==""|| Barcode.Trim().Contains("\0"))
                {
                    conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode);
                }
                var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode && x.TaskState == (int)TaskInStatusEnum.HoistNew);
                if (task != null)
                {
                    ConveyorLineTaskCommandWrite taskCommand = new ConveyorLineTaskCommandWrite()
                    {
                        TaskNum = Convert.ToInt16(task.TaskNum),
                        TargetAddress = Convert.ToInt16(task.NextAddress),
                        WriteInteractiveSignal = task.TaskType == (int)TaskOutboundTypeEnum.Outbound ? (byte)Convert.ToSByte(2) : (byte)Convert.ToSByte(1)
                    };
                    var result = SendCommand(taskCommand, conveyorLine, stationManager.stationChildCode);
                    if (result)
                    {
                        task.TaskState = (int)TaskInStatusEnum.HoistInExecuting;
                        _taskRepository.UpdateData(task);
                    }
                }
                else
                {
                    var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                    var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                    var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue;
                    WMSTaskDTO taskDTO = new WMSTaskDTO()
                    {
                        TPbarcode = Barcode,
                        WhCode = "1001",
                        BeginPoint = stationManager.stationChildCode
                    };
                    if (wmsBase == null || requestTask == null)
                    {
                        throw new InvalidOperationException("WMS IP æœªé…ç½®");
                    }
                    var wmsIpAddress = wmsBase + requestTask;
                    var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, taskDTO.ToJsonString()).Result;
                }
            }
            else
            {
                //var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                //var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                //var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue;
                //var keys = new Dictionary<string, object>()
                //{
                //    {"TPbarcode", Barcode},
                //    {"WhCode", "1001"},
                //    {"BeginPoint", stationManager.stationChildCode}
                //};
                //if (wmsBase == null || requestTask == null)
                //{
                //    throw new InvalidOperationException("WMS IP æœªé…ç½®");
                //}
                //var wmsIpAddress = wmsBase + requestTask;
                //var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, keys.ToString()).Result;
            }
                DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationNextChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault();
                var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 10);
                string Barcode = Encoding.UTF8.GetString(x);
                if (Barcode == null || Barcode == "" || Barcode.Trim().Contains("\0"))
                {
                    conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode);
                }
                var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode);
                if (task != null)
                {
                }
                else
                {
                    var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                    var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                    var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue;
                    WMSTaskDTO taskDTO = new WMSTaskDTO()
                    {
                        TPbarcode = Barcode,
                        WhCode = "1001",
                        BeginPoint = stationManager.stationChildCode
                    };
                    if (wmsBase == null || requestTask == null)
                    {
                        throw new InvalidOperationException("WMS IP æœªé…ç½®");
                    }
                    var wmsIpAddress = wmsBase + requestTask;
                    var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, taskDTO.ToJsonString()).Result;
                }
            }
        }
    }
}