|  |  |  | 
|---|
|  |  |  | using HslCommunication; | 
|---|
|  |  |  | using Mapster; | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | using System.Text; | 
|---|
|  |  |  | using System.Threading.Tasks; | 
|---|
|  |  |  | using WIDESEAWCS_Common; | 
|---|
|  |  |  | using WIDESEAWCS_Core.Helper; | 
|---|
|  |  |  | using WIDESEAWCS_Core; | 
|---|
|  |  |  | using WIDESEAWCS_DTO.TaskInfo; | 
|---|
|  |  |  | using System.Diagnostics.CodeAnalysis; | 
|---|
|  |  |  | using WIDESEAWCS_Common; | 
|---|
|  |  |  | using WIDESEAWCS_Common.TaskEnum; | 
|---|
|  |  |  | using WIDESEAWCS_Core; | 
|---|
|  |  |  | using WIDESEAWCS_Core.Helper; | 
|---|
|  |  |  | using WIDESEAWCS_DTO.TaskInfo; | 
|---|
|  |  |  | using WIDESEAWCS_Model.Models; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob.Models; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WIDESEAWCS_TaskInfoService | 
|---|
|  |  |  | { | 
|---|
|  |  |  | public partial class TaskService | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 根据托盘号、起始地址向WMS请求任务 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // wms失败返回去NG口任务 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 根据托盘号、站台向WMS请求任务 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 根据托盘号、站台向WMS请求任务 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="palletCode">托盘号</param> | 
|---|
|  |  |  | /// <param name="sourceAddress">起始地址</param> | 
|---|
|  |  |  | /// <param name="stationManager">站台</param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public async Task<WebResponseContent> RequestTask(string palletCode, Dt_StationManager stationManager) | 
|---|
|  |  |  | public async Task<WebResponseContent> RequestTask1(string palletCode, Dt_StationManager stationManager) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | StaticVariable.isLineRun = false; | 
|---|
|  |  |  | var hasTask = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode); | 
|---|
|  |  |  | if (hasTask != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error("当前托盘存在任务"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var Station = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 6 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea); | 
|---|
|  |  |  | var tasks = await BaseDal.QueryFirstAsync(x => x.TaskType == (int)TaskOutboundTypeEnum.InToOut && x.TargetAddress == stationManager.stationLocation && x.CurrentAddress == Station.stationChildCode); | 
|---|
|  |  |  | if (tasks != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ConsoleHelper.WriteErrorLine($"【{stationManager.stationChildCode}】已存在直接出库任务任务"); | 
|---|
|  |  |  | return content.Error($"【{stationManager.stationChildCode}】已存在直接出库任务任务"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StaticVariable.isStackerRun) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (stationManager.stationType == 7) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var runTask = await BaseDal.QueryFirstAsync(x => x.CurrentAddress == Station.stationChildCode && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.TaskType == (int)TaskInboundTypeEnum.InTray); | 
|---|
|  |  |  | if (runTask != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | runTask.TargetAddress = stationManager.stationLocation; | 
|---|
|  |  |  | runTask.NextAddress = stationManager.stationChildCode; | 
|---|
|  |  |  | runTask.Grade = 3; | 
|---|
|  |  |  | runTask.TaskType = (int)TaskOutboundTypeEnum.InToOut; | 
|---|
|  |  |  | runTask.TaskState = (int)TaskOutStatusEnum.OutNew; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var config1 = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); | 
|---|
|  |  |  | var wmsBase1 = config1.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; | 
|---|
|  |  |  | var requestTask1 = config1.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.SetEmptyOutbyInToOutAsync)?.ConfigValue; | 
|---|
|  |  |  | if (wmsBase1 == null || requestTask1 == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new InvalidOperationException("WMS IP 未配置"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var wmsIpAddrss1 = wmsBase1 + requestTask1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var result1 = await HttpHelper.PostAsync(wmsIpAddrss1, new { palletCode = runTask.PalletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = Station.stationChildCode }.ToJsonString()); | 
|---|
|  |  |  | content = JsonConvert.DeserializeObject<WebResponseContent>(result1); | 
|---|
|  |  |  | if (content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | await BaseDal.UpdateDataAsync(runTask); | 
|---|
|  |  |  | ConsoleHelper.WriteSuccessLine($"【{runTask.PalletCode}直接出库至二封】"); | 
|---|
|  |  |  | return content.OK("成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | ConsoleHelper.WriteErrorLine(content.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | ConsoleHelper.WriteErrorLine($"【{Station.stationChildCode}】未找到空托盘入库任务"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (stationManager.stationType == 6) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var emptyStation = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 7 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea); | 
|---|
|  |  |  | var runTask = await BaseDal.QueryFirstAsync(x => x.NextAddress == emptyStation.stationChildCode && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.TaskType == (int)TaskInboundTypeEnum.InTray); | 
|---|
|  |  |  | if (runTask != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | runTask.SourceAddress = stationManager.stationLocation; | 
|---|
|  |  |  | runTask.CurrentAddress = stationManager.stationChildCode; | 
|---|
|  |  |  | runTask.Grade = 3; | 
|---|
|  |  |  | runTask.TaskType = (int)TaskOutboundTypeEnum.InToOut; | 
|---|
|  |  |  | runTask.TaskState = (int)TaskOutStatusEnum.OutNew; | 
|---|
|  |  |  | runTask.PalletCode = palletCode; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var config1 = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); | 
|---|
|  |  |  | var wmsBase1 = config1.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; | 
|---|
|  |  |  | var requestTask1 = config1.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.SetEmptyOutbyInToOutOneAsync)?.ConfigValue; | 
|---|
|  |  |  | if (wmsBase1 == null || requestTask1 == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new InvalidOperationException("WMS IP 未配置"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var wmsIpAddrss1 = wmsBase1 + requestTask1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var result1 = await HttpHelper.PostAsync(wmsIpAddrss1, new { palletCode = runTask.PalletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = emptyStation.stationChildCode }.ToJsonString()); | 
|---|
|  |  |  | content = JsonConvert.DeserializeObject<WebResponseContent>(result1); | 
|---|
|  |  |  | if (content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | await BaseDal.UpdateDataAsync(runTask); | 
|---|
|  |  |  | ConsoleHelper.WriteSuccessLine($"【{runTask.PalletCode}直接出库至二封】"); | 
|---|
|  |  |  | return content.OK("成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | ConsoleHelper.WriteErrorLine(content.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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.RequestInTask)?.ConfigValue; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = palletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = stationManager.stationChildCode }.ToJsonString()); | 
|---|
|  |  |  | content = JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ConsoleHelper.WriteErrorLine($"{stationManager.stationChildCode}站台请求响应信息:{content.ToJsonString()}"); | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // wms失败返回去NG口任务 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //if (stationManager.stationChildCode != stationManager.stationNGChildCode) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    WMSTaskDTO taskDTO = new WMSTaskDTO() | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        Grade = 8, | 
|---|
|  |  |  | //        PalletCode = palletCode, | 
|---|
|  |  |  | //        SourceAddress = stationManager.stationLocation, | 
|---|
|  |  |  | //        TargetAddress = stationManager.stationNGLocation, | 
|---|
|  |  |  | //        RoadWay = stationManager.Roadway, | 
|---|
|  |  |  | //        TaskNum = 1000, | 
|---|
|  |  |  | //        TaskState = (int)TaskOutStatusEnum.OutNew, | 
|---|
|  |  |  | //        TaskType = (int)TaskOutboundTypeEnum.InToOut | 
|---|
|  |  |  | //    }; | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); | 
|---|
|  |  |  | ConsoleHelper.WriteSuccessLine(content.Data.ToString()); | 
|---|
|  |  |  | return ReceiveByWMSTask(task); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | finally | 
|---|
|  |  |  | { | 
|---|
|  |  |  | StaticVariable.isLineRun = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 根据托盘号、站台向WMS请求任务 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="palletCode">托盘号</param> | 
|---|
|  |  |  | /// <param name="stationManager">站台</param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public async Task<WebResponseContent> RequestTask(string palletCode, Dt_StationManager stationManager) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | StaticVariable.isLineRun = false; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 检查当前托盘是否存在任务 | 
|---|
|  |  |  | if (await HasTask(palletCode)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error("当前托盘存在任务"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 检查是否已存在直接出库任务 | 
|---|
|  |  |  | if (await HasDirectOutboundTask(stationManager)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"【{stationManager.stationChildCode}】已存在直接出库任务任务"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StaticVariable.isStackerRun) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (stationManager.stationType == 7) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var result = await HandleStationType7(palletCode, stationManager); | 
|---|
|  |  |  | if (result != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (stationManager.stationType == 6) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var result = await HandleStationType6(palletCode, stationManager); | 
|---|
|  |  |  | if (result != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 发起请求获取入库任务 | 
|---|
|  |  |  | content = await RequestInTask(palletCode, stationManager); | 
|---|
|  |  |  | ConsoleHelper.WriteErrorLine($"{stationManager.stationChildCode}站台请求响应信息:{content.ToJsonString()}"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); | 
|---|
|  |  |  | ConsoleHelper.WriteSuccessLine(content.Data.ToString()); | 
|---|
|  |  |  | return ReceiveByWMSTask(task); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | finally | 
|---|
|  |  |  | { | 
|---|
|  |  |  | StaticVariable.isLineRun = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 检查当前托盘是否存在任务 | 
|---|
|  |  |  | private async Task<bool> HasTask(string palletCode) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var hasTask = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode); | 
|---|
|  |  |  | return hasTask != null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 检查是否已存在直接出库任务 | 
|---|
|  |  |  | private async Task<bool> HasDirectOutboundTask(Dt_StationManager stationManager) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var station = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 6 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea); | 
|---|
|  |  |  | var tasks = await BaseDal.QueryFirstAsync(x => x.TaskType == (int)TaskOutboundTypeEnum.InToOut && x.TargetAddress == stationManager.stationLocation && x.CurrentAddress == station.stationChildCode); | 
|---|
|  |  |  | return tasks != null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 处理 stationType 为 7 的情况 | 
|---|
|  |  |  | private async Task<WebResponseContent> HandleStationType7(string palletCode, Dt_StationManager stationManager) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var station = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 6 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea); | 
|---|
|  |  |  | var runTask = await BaseDal.QueryFirstAsync(x => x.CurrentAddress == station.stationChildCode && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.TaskType == (int)TaskInboundTypeEnum.InTray); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (runTask != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | runTask.TargetAddress = stationManager.stationLocation; | 
|---|
|  |  |  | runTask.NextAddress = stationManager.stationChildCode; | 
|---|
|  |  |  | runTask.Grade = 3; | 
|---|
|  |  |  | runTask.TaskType = (int)TaskOutboundTypeEnum.InToOut; | 
|---|
|  |  |  | runTask.TaskState = (int)TaskOutStatusEnum.OutNew; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var wmsIpAddrss = GetWmsIpAddress(SysConfigKeyConst.SetEmptyOutbyInToOutAsync); | 
|---|
|  |  |  | var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = runTask.PalletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = station.stationChildCode }.ToJsonString()); | 
|---|
|  |  |  | var content = JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | await BaseDal.UpdateDataAsync(runTask); | 
|---|
|  |  |  | ConsoleHelper.WriteSuccessLine($"【{runTask.PalletCode}直接出库至二封】"); | 
|---|
|  |  |  | return content.OK("成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ConsoleHelper.WriteErrorLine(content.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ConsoleHelper.WriteErrorLine($"【{station.stationChildCode}】未找到空托盘入库任务"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 处理 stationType 为 6 的情况 | 
|---|
|  |  |  | private async Task<WebResponseContent> HandleStationType6(string palletCode, Dt_StationManager stationManager) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var emptyStation = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 7 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea); | 
|---|
|  |  |  | var runTask = await BaseDal.QueryFirstAsync(x => x.NextAddress == emptyStation.stationChildCode && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.TaskType == (int)TaskInboundTypeEnum.InTray); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (runTask != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | runTask.SourceAddress = stationManager.stationLocation; | 
|---|
|  |  |  | runTask.CurrentAddress = stationManager.stationChildCode; | 
|---|
|  |  |  | runTask.Grade = 3; | 
|---|
|  |  |  | runTask.TaskType = (int)TaskOutboundTypeEnum.InToOut; | 
|---|
|  |  |  | runTask.TaskState = (int)TaskOutStatusEnum.OutNew; | 
|---|
|  |  |  | runTask.PalletCode = palletCode; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var wmsIpAddrss = GetWmsIpAddress(SysConfigKeyConst.SetEmptyOutbyInToOutAsync); | 
|---|
|  |  |  | var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = runTask.PalletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = emptyStation.stationChildCode }.ToJsonString()); | 
|---|
|  |  |  | var content = JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | await BaseDal.UpdateDataAsync(runTask); | 
|---|
|  |  |  | ConsoleHelper.WriteSuccessLine($"【{runTask.PalletCode}直接出库至二封】"); | 
|---|
|  |  |  | return content.OK("成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ConsoleHelper.WriteErrorLine(content.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取 WMS 请求地址 | 
|---|
|  |  |  | private string GetWmsIpAddress(string configKey) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 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 == configKey)?.ConfigValue; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (wmsBase == null || requestTask == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new InvalidOperationException("WMS IP 未配置"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return wmsBase + requestTask; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 发起请求获取入库任务 | 
|---|
|  |  |  | private async Task<WebResponseContent> RequestInTask(string palletCode, Dt_StationManager stationManager) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var wmsIpAddrss = GetWmsIpAddress(SysConfigKeyConst.RequestInTask); | 
|---|
|  |  |  | var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = palletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = stationManager.stationChildCode }.ToJsonString()); | 
|---|
|  |  |  | return JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion 根据托盘号、站台向WMS请求任务 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public async Task<WebResponseContent> RequestOutTaskToBZAsync(Dt_StationManager stationManager) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 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.RequestOutTaskToBZ)?.ConfigValue; | 
|---|
|  |  |  | if (wmsBase == null || requestTask == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new InvalidOperationException("WMS IP 未配置"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var wmsIpAddrss = wmsBase + requestTask; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var result = await HttpHelper.PostAsync(wmsIpAddrss, new { Position = stationManager.stationChildCode }.ToJsonString()); | 
|---|
|  |  |  | content = JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //无满足条件可出库至包装的库存 | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); | 
|---|
|  |  |  | ConsoleHelper.WriteSuccessLine(content.Data.ToString()); | 
|---|
|  |  |  | //_taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO })‘ | 
|---|
|  |  |  | content = ReceiveWMSTask(new List<WMSTaskDTO> { task }); | 
|---|
|  |  |  | //content = ReceiveByBZOtuTask(task); | 
|---|
|  |  |  | //if (content.Status) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    //相应的在途数据+1 | 
|---|
|  |  |  | //   // _taskNeedBarcodeRepository.UpdateData(); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | task.NextAddress = stationinfo.stationChildCode; | 
|---|
|  |  |  | task.TargetAddress = taskDTO.TargetAddress; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = (int)TaskStatus.Created; | 
|---|
|  |  |  | task.SourceAddress = taskDTO.SourceAddress; | 
|---|
|  |  |  | task.CurrentAddress = taskDTO.SourceAddress; | 
|---|
|  |  |  | task.NextAddress = taskDTO.TargetAddress; | 
|---|
|  |  |  | task.TargetAddress = taskDTO.TargetAddress; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BaseDal.AddData(task); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.WMSId, "接收WMS任务"); | 
|---|
|  |  |  | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 接收WMS任务信息 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="taskDTOs">WMS任务对象集合</param> | 
|---|
|  |  |  | /// <returns>返回处理结果</returns> | 
|---|
|  |  |  | public WebResponseContent ReceiveByBZOtuTask([NotNull] WMSTaskDTO taskDTO) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (BaseDal.QueryFirst(x => x.TaskNum == taskDTO.TaskNum || x.PalletCode == taskDTO.PalletCode) != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_Task task = _mapper.Map<Dt_Task>(taskDTO); | 
|---|
|  |  |  | task.Creater = "WMS"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationLocation == taskDTO.TargetAddress && x.Roadway == taskDTO.RoadWay); | 
|---|
|  |  |  | task.TaskState = (int)TaskOutStatusEnum.OutNew; | 
|---|
|  |  |  | task.CurrentAddress = stationinfo.stationChildCode; | 
|---|
|  |  |  | task.NextAddress = stationinfo.stationChildCode; | 
|---|
|  |  |  | task.SourceAddress = taskDTO.SourceAddress; | 
|---|
|  |  |  | task.TargetAddress = taskDTO.TargetAddress; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BaseDal.AddData(task); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.WMSId, "接收WMS任务"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | content = WebResponseContent.Instance.OK("成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 高温出库 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="taskDTO"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public WebResponseContent ReceiveByWMSGWTask([NotNull] WMSTaskDTO taskDTO) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (BaseDal.QueryFirst(x => x.TaskNum == taskDTO.TaskNum || x.PalletCode == taskDTO.PalletCode) != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_Task task = _mapper.Map<Dt_Task>(taskDTO); | 
|---|
|  |  |  | task.Creater = "WMS"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = (int)TaskOutStatusEnum.OutNew; | 
|---|
|  |  |  | task.CurrentAddress = taskDTO.RoadWay; | 
|---|
|  |  |  | task.NextAddress = "002-000-002"; | 
|---|
|  |  |  | task.SourceAddress = taskDTO.SourceAddress; | 
|---|
|  |  |  | task.TargetAddress = taskDTO.TargetAddress; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BaseDal.AddData(task); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.WMSId, "接收WMS任务"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | content = WebResponseContent.Instance.OK("成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 接收WMS任务信息 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_StationManager dt_Station = content.Data as Dt_StationManager; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 根据托盘号和设备号查询入库任务 | 
|---|
|  |  |  | /// 根据托盘号和设备号查询任务 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="taskNum">任务号</param> | 
|---|
|  |  |  | /// <param name="currentAddress">当前地址</param> | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    //todo | 
|---|
|  |  |  | //    //todo | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | //else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting) | 
|---|
|  |  |  | 
|---|
|  |  |  | //    throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{taskNum}】,任务类型:【{task.TaskType}】"); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region WMS同步任务完成 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var keys = new Dictionary<string, object>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | {"taskNum", taskNum} | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var result = HttpHelper.GetAsync(wmsIpAddress, keys).Result; | 
|---|
|  |  |  | content = JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion WMS同步任务完成 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = 1;  //任务完成 | 
|---|
|  |  |  | var taskHty = task.Adapt<Dt_Task_Hty>(); | 
|---|
|  |  |  | _taskHtyRepository.AddData(taskHty); | 
|---|
|  |  |  | BaseDal.DeleteData(task); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region  更新任务状态 | 
|---|
|  |  |  | #region 更新任务状态 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.UpdateTask)?.ConfigValue; | 
|---|
|  |  |  | //if (wmsBase == null || updateTask == null) | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //result = HttpHelper.PostAsync(wmsIpAddress, new { TaskNum = task.TaskNum, TaskState = task.TaskState }.ToJsonString()).Result; | 
|---|
|  |  |  | //content = JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion 更新任务状态 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //content = WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|