| | |
| | | using System.ComponentModel; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Linq; |
| | | using System.Net.Sockets; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 接收成品,辅料,药水WMS任务信息 |
| | | /// </summary> |
| | | /// <param name="taskDTOs">WMS任务对象集合</param> |
| | | /// <returns>返回处理结果</returns> |
| | | public WebResponseContent ReceiveWMSCPTask([NotNull] List<WMSTaskDTO> taskDTOs) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | bool flag = false; |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | List<Dt_Task> tasksOld = BaseDal.QueryData(); |
| | | List<Dt_Router> routersAll = _routerRepository.QueryData(); |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(); |
| | | foreach (var item in taskDTOs) |
| | | { |
| | | if (tasksOld.FirstOrDefault(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode) != null) |
| | | { |
| | | flag = true; |
| | | continue; |
| | | } |
| | | Dt_Task task = _mapper.Map<Dt_Task>(item); |
| | | task.Creater = "WMS"; |
| | | task.TaskState = (int)TaskStatusEnum.New; |
| | | |
| | | Dt_Router? router; |
| | | |
| | | TaskTypeGroup taskTypeGroup = item.TaskType.GetTaskTypeGroup(); |
| | | Dt_StationManger? stationManger; |
| | | if (taskTypeGroup == TaskTypeGroup.InboundGroup) |
| | | { |
| | | stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.NextAddress || x.StationDeviceCode == item.SourceAddress); |
| | | task.DeviceCode = stationManger.StationDeviceCode; |
| | | } |
| | | else |
| | | { |
| | | stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.NextAddress || x.StationDeviceCode == item.NextAddress); |
| | | task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt(); |
| | | task.DeviceCode = task.Roadway; |
| | | //出库 |
| | | } |
| | | tasks.Add(task); |
| | | } |
| | | BaseDal.AddData(tasks); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "接收WMS任务"); |
| | | |
| | | content = (flag || tasks.Count > 0) ? WebResponseContent.Instance.OK("成功") : WebResponseContent.Instance.Error("失败"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据托盘号、起始地址向WMS请求任务 |
| | | /// </summary> |
| | | /// <param name="palletCode">托盘号</param> |
| | |
| | | /// <param name="palletCode"></param> |
| | | /// <param name="sourceAddress"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSTaskSimple(string palletCode, string sourceAddress) |
| | | public WebResponseContent RequestWMSTaskSimple(string palletCode, string sourceAddress, int heightType) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTaskSimple?stationCode={sourceAddress}&palletCode={palletCode}"); |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTaskSimple?stationCode={sourceAddress}&palletCode={palletCode}&heightType={heightType}"); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | |
| | | public WebResponseContent CPRequestWMSTaskSimple(string palletCode, string sourceAddress, int heightType, string courceAddress) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/CPDeviceRequestInboundTaskSimple?stationCode={sourceAddress}&palletCode={palletCode}&heightType={heightType}&courceAddress={courceAddress}"); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString()); |
| | | if (taskDTO != null) |
| | | { |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public WebResponseContent ApplyLocation(string palletCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/ApplyLocation?palletCode={palletCode}"); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | return responseContent; |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | |
| | | public WebResponseContent LedShowTask(string stationCode, string palletCode, int taskType) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string ledApiAddress = AppSettings.Get("LEDApiAddress"); |
| | | if (string.IsNullOrEmpty(ledApiAddress)) |
| | | { |
| | | return WebResponseContent.Instance.Error("未找到LED服务地址"); |
| | | } |
| | | string ipAddress = ledApiAddress; |
| | | int port = 8888; // 默认端口 |
| | | string sendData = $"{stationCode}|{palletCode}|{taskType}"; |
| | | |
| | | using (TcpClient tcpClient = new TcpClient()) |
| | | { |
| | | tcpClient.ReceiveTimeout = 5000; |
| | | tcpClient.SendTimeout = 5000; |
| | | |
| | | tcpClient.Connect(ipAddress, port); |
| | | |
| | | NetworkStream stream = tcpClient.GetStream(); |
| | | byte[] data = Encoding.UTF8.GetBytes(sendData); |
| | | stream.Write(data, 0, data.Length); |
| | | stream.Flush(); |
| | | |
| | | Console.WriteLine($"✅ TCP数据发送成功:{sendData}"); |
| | | } |
| | | |
| | | } |
| | | catch (SocketException socketEx) |
| | | { |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"LED推送失败:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 任务手动完成 |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="NotImplementedException"></exception> |
| | | public async Task<WebResponseContent> ManualTaskCompleted(int taskNum) |
| | | { |
| | | try |
| | | { |
| | | string url = "http://localhost:9290"; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | return await Task.FromResult(WebResponseContent.Instance.Error($"未找到WCSApi地址,请检查配置文件")); |
| | | } |
| | | string response = HttpHelper.Post($"{url}/api/Task/TaskCompleted?taskNum=" + taskNum,taskNum.ToString()); |
| | | |
| | | return await Task.FromResult(JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("返回错误")); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); |
| | | } |
| | | } |
| | | } |
| | | } |