From 06e0e3b7d61e95902a6129de2490461cd0693e1d Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期三, 15 十月 2025 15:06:40 +0800
Subject: [PATCH] 新增异步方法并优化服务调用逻辑在多个数据库文件中进行了二进制文件的修改、删除和新增操作,可能涉及数据库内容的更新或重建。在 HttpsClient.cs文件中新增了 PostNotLimitAsync方法,用于发送支持 JSON 格式的异步 HTTP POST 请求,并记录请求和响应参数。在 AgingInOrOutInputService.cs文件中,将 HttpsClient.PostAsync替换为PostNotLimitAsync,以利用新方法的功能特性。同时删除了不再需要的注释代码。
---
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Partial/TaskService.cs | 699 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 693 insertions(+), 6 deletions(-)
diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Partial/TaskService.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Partial/TaskService.cs
index d25a513..9736d13 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Partial/TaskService.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Partial/TaskService.cs
@@ -1,13 +1,700 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+锘縰sing HslCommunication;
+using Mapster;
+using Newtonsoft.Json;
+using System.Diagnostics.CodeAnalysis;
+using WIDESEAWCS_Common;
+using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Core.LogHelper;
+using WIDESEAWCS_DTO.TaskInfo;
+using WIDESEAWCS_Model.Models;
+using WIDESEAWCS_QuartzJob;
namespace WIDESEAWCS_TaskInfoService
{
public partial class TaskService
{
+ /// <summary>
+ /// 鏍规嵁鎵樼洏鍙枫�佽捣濮嬪湴鍧�鍚慦MS璇锋眰浠诲姟
+ /// </summary>
+ /// <param name="palletCode">鎵樼洏鍙�</param>
+ /// <param name="sourceAddress">璧峰鍦板潃</param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> RequestTask(string palletCode, string EquiCodeMOM, string Roadways, string area, string CurrentChildCode)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ var hasTask = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode);
+ if (hasTask != null)
+ {
+ return content.Error("褰撳墠鎵樼洏瀛樺湪浠诲姟");
+ }
+ 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;
+ if (wmsBase == null || requestTask == null)
+ {
+ throw new InvalidOperationException("WMS IP 鏈厤缃�");
+ }
+ var wmsIpAddrss = wmsBase + requestTask;
+
+ var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = palletCode, EquiCodeMOM = EquiCodeMOM, Roadways = Roadways, area = area, Position = CurrentChildCode }.ToJsonString());
+ content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+
+ if (!content.Status)
+ {
+ // wms澶辫触杩斿洖鍘籒G鍙d换鍔�
+
+ return content;
+ }
+
+ var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
+ return ReceiveByWMSTask(task);
+ }
+ catch (Exception ex)
+ {
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+ }
+
+ #region 鏍规嵁鎵樼洏鍙枫�佺珯鍙板悜WMS璇锋眰浠诲姟
+
+ /// <summary>
+ /// 鏍规嵁鎵樼洏鍙枫�佺珯鍙板悜WMS璇锋眰浠诲姟
+ /// </summary>
+ /// <param name="palletCode">鎵樼洏鍙�</param>
+ /// <param name="stationManager">绔欏彴</param>
+ /// <returns></returns>
+ 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;
+ if (wmsBase == null || requestTask == null)
+ {
+ throw new InvalidOperationException("WMS IP 鏈厤缃�");
+ }
+ var wmsIpAddrss = wmsBase + requestTask;
+
+ 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澶辫触杩斿洖鍘籒G鍙d换鍔�
+ //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 && x.Roadway == stationManager.Roadway);
+ 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 && x.Roadway == stationManager.Roadway);
+ 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 && x.Roadway==stationManager.Roadway);
+ 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());
+
+ QuartzLogger.WriteLogToFile($"鍖呰鍑哄簱", $"杩斿洖鍙傛暟銆恵JsonConvert.SerializeObject(result)}銆憑Environment.NewLine}{Environment.NewLine}");
+
+
+ content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+ if (!content.Status)
+ {
+ //鏃犳弧瓒虫潯浠跺彲鍑哄簱鑷冲寘瑁呯殑搴撳瓨
+ ConsoleHelper.WriteErrorLine(JsonConvert.SerializeObject(content));
+ QuartzLogger.WriteLogToFile($"鍖呰鍑哄簱", $"杩斿洖鍙傛暟銆恵JsonConvert.SerializeObject(content)}銆憑Environment.NewLine}{Environment.NewLine}");
+ return content;
+ }
+
+ var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
+ ConsoleHelper.WriteSuccessLine(content.Data.ToString());
+
+ content = ReceiveWMSTask(new List<WMSTaskDTO> { task });
+
+ QuartzLogger.WriteLogToFile($"鍖呰鍑哄簱", $"杩斿洖鍙傛暟銆恵JsonConvert.SerializeObject(content)}銆憑Environment.NewLine}{Environment.NewLine}");
+ ConsoleHelper.WriteErrorLine(JsonConvert.SerializeObject(content));
+ return content;
+ }
+ catch (Exception ex)
+ {
+ return content.Error(ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// 鎺ユ敹WMS浠诲姟淇℃伅
+ /// </summary>
+ /// <param name="taskDTOs">WMS浠诲姟瀵硅薄闆嗗悎</param>
+ /// <returns>杩斿洖澶勭悊缁撴灉</returns>
+ public WebResponseContent ReceiveByWMSTask([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)
+ {
+ if (task.TaskType == (int)TaskOutboundTypeEnum.InToOut && taskDTO.RoadWay.Contains("CW"))
+ {
+ var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1017" && x.stationType == 10 && x.Roadway == taskDTO.RoadWay);
+ task.TaskState = (int)TaskOutStatusEnum.OutNew;
+ task.CurrentAddress = taskDTO.SourceAddress;
+ task.NextAddress = stationinfo.stationChildCode;
+ task.SourceAddress = taskDTO.SourceAddress;
+ task.TargetAddress = taskDTO.TargetAddress;
+ }
+ else
+ {
+ var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationLocation == taskDTO.TargetAddress && x.Roadway == taskDTO.RoadWay);
+ task.TaskState = (int)TaskOutStatusEnum.OutNew;
+ task.CurrentAddress = taskDTO.RoadWay;
+ task.NextAddress = stationinfo.stationChildCode;
+ task.SourceAddress = taskDTO.SourceAddress;
+ task.TargetAddress = taskDTO.TargetAddress;
+ }
+ }
+ else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
+ {
+ var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationLocation == taskDTO.SourceAddress && x.Roadway == taskDTO.RoadWay);
+ task.TaskState = (int)TaskInStatusEnum.Line_InFinish;
+ task.SourceAddress = taskDTO.SourceAddress;
+ task.CurrentAddress = stationinfo.stationChildCode;
+ 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浠诲姟");
+
+ content = WebResponseContent.Instance.OK("鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ content = WebResponseContent.Instance.Error($"浠诲姟鎺ユ敹閿欒,閿欒淇℃伅:{ex.Message}");
+ }
+ 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浠诲姟淇℃伅
+ /// </summary>
+ /// <param name="taskDTOs">WMS浠诲姟瀵硅薄闆嗗悎</param>
+ /// <returns>杩斿洖澶勭悊缁撴灉</returns>
+ public async Task<WebResponseContent> RequestFlow(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.RequestFlow)?.ConfigValue;
+ if (wmsBase == null || requestTask == null)
+ {
+ throw new InvalidOperationException("WMS IP 鏈厤缃�");
+ }
+ var wmsIpAddrss = wmsBase + requestTask;
+
+ var result = await HttpHelper.PostAsync(wmsIpAddrss, new { EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = stationManager.stationChildCode }.ToJsonString());
+ content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+
+ if (!content.Status)
+ {
+ return content;
+ }
+ Dt_StationManager dt_Station = content.Data as Dt_StationManager;
+ //dt_Station.
+ }
+ catch (Exception ex)
+ {
+ content = WebResponseContent.Instance.Error($"浠诲姟鎺ユ敹閿欒,閿欒淇℃伅:{ex.Message}");
+ }
+ return content;
+ }
+
+ /// <summary>
+ /// 鏍规嵁鎵樼洏鍙峰拰璁惧鍙锋煡璇换鍔�
+ /// </summary>
+ /// <param name="taskNum">浠诲姟鍙�</param>
+ /// <param name="currentAddress">褰撳墠鍦板潃</param>
+ /// <returns></returns>
+ public Dt_Task QueryTaskByPalletCode(string palletCode, string Roadway)
+ {
+ return BaseDal.QueryFirst(x => x.PalletCode == palletCode && x.Roadway == Roadway, TaskOrderBy);
+ }
+
+ ///// <summary>
+ ///// 鏍规嵁璁惧缂栧彿銆佸綋鍓嶅湴鍧�鏌ヨ杈撻�佺嚎鏈墽琛岀殑浠诲姟
+ ///// </summary>
+ ///// <param name="deviceNo">璁惧缂栧彿</param>
+ ///// <param name="currentAddress">褰撳墠鍦板潃</param>
+ ///// <returns></returns>
+ //public Dt_Task QueryConveyorLineTask(string deviceNo, string currentAddress)
+ //{
+ // return BaseDal.QueryFirst(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) && x.CurrentAddress == currentAddress, TaskOrderBy);
+ //}
+
+ /// 浠诲姟瀹屾垚
+ /// </summary>
+ /// <param name="taskNum">浠诲姟缂栧彿</param>
+ /// <returns>杩斿洖澶勭悊缁撴灉</returns>
+ public WebResponseContent StackCraneTaskCompletedByStation(int taskNum)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ var task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+ if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
+
+ #region WMS鍚屾浠诲姟瀹屾垚
+
+ var keys = new Dictionary<string, object>()
+ {
+ {"taskNum", taskNum}
+ };
+ // 鑾峰彇WMSip鍦板潃
+ 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;
+ content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+
+ #endregion WMS鍚屾浠诲姟瀹屾垚
+
+ if (content.Status)
+ {
+ task.TaskState = 1; //浠诲姟瀹屾垚
+ var taskHty = task.Adapt<Dt_Task_Hty>();
+ _taskHtyRepository.AddData(taskHty);
+ BaseDal.DeleteData(task);
+ }
+
+ #region 鏇存柊浠诲姟鐘舵��
+
+ //var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.UpdateTask)?.ConfigValue;
+ //if (wmsBase == null || updateTask == null)
+ //{
+ // throw new InvalidOperationException("WMS IP 鏈厤缃�");
+ //}
+ //wmsIpAddress = wmsBase + updateTask;
+
+ //result = HttpHelper.PostAsync(wmsIpAddress, new { TaskNum = task.TaskNum, TaskState = task.TaskState }.ToJsonString()).Result;
+ //content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+
+ #endregion 鏇存柊浠诲姟鐘舵��
+
+ //content = WebResponseContent.Instance.OK();
+ }
+ catch (Exception ex)
+ {
+ content = WebResponseContent.Instance.Error($"浠诲姟瀹屾垚寮傚父,浠诲姟鍙�:銆恵taskNum}銆�");
+ QuartzLogger.WriteLogToFile($"Info_鍒嗗浠诲姟瀹屾垚", $"浠诲姟瀹屾垚寮傚父,浠诲姟鍙�:銆恵taskNum}銆戝紓甯镐俊鎭�恵ex.Message}銆憑Environment.NewLine}寮傚父淇℃伅銆恵ex.StackTrace}銆憑Environment.NewLine}");
+ }
+ QuartzLogger.WriteLogToFile($"Info_鍒嗗浠诲姟瀹屾垚", $"浠诲姟瀹屾垚,浠诲姟鍙�:銆恵taskNum}銆戣繑鍥炲弬鏁般�恵JsonConvert.SerializeObject(content)}銆憑Environment.NewLine}{Environment.NewLine}");
+ return content;
+ }
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3