diff --git a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs index 83bb45a..c434925 100644 --- a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs +++ b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs @@ -158,7 +158,7 @@ namespace SlnMesnac.Business.@base } /// - /// Timer刷新任务状态, 有新任务初次下发AGV,Timer执行 + /// Timer刷新任务状态, 有新任务初次下发AGV, Timer执行 /// public void RefreshTaskState() { diff --git a/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs b/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs index 7a5b55e..a86250b 100644 --- a/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs @@ -66,8 +66,16 @@ namespace SlnMesnac.Repository.service.Impl /// public async Task UpdateAsync(AGVState record) { - bool result = await _rep.UpdateAsync(record); - return result; + try + { + bool result = await _rep.UpdateAsync(record); + return result; + } + catch (Exception ex) + { + _logger.LogError($"更新设备状态信息出现错误:{ex.Message}"); + return false; + } } /// @@ -116,7 +124,7 @@ namespace SlnMesnac.Repository.service.Impl { return _rep.DeleteById(id); } - catch(Exception ex) + catch (Exception ex) { _logger.LogError("AGV状态删除错误:" + ex.Message); return false; diff --git a/SlnMesnac.TouchSocket/AirPorthttpClient.cs b/SlnMesnac.TouchSocket/AirPorthttpClient.cs index 022c396..8f3d53b 100644 --- a/SlnMesnac.TouchSocket/AirPorthttpClient.cs +++ b/SlnMesnac.TouchSocket/AirPorthttpClient.cs @@ -127,18 +127,26 @@ namespace SlnMesnac.TouchSocket /// public AGVResponseEntity AGVAddTaskRequest(AGVRequestAddTaskEntity requestValue) { - if (_httpClient == null) + try { - _logger.LogError("http服务为空"); + if (_httpClient == null) + { + _logger.LogError("http服务为空"); + return null; + } + //序列化输入数据 + string json = Newtonsoft.Json.JsonConvert.SerializeObject(requestValue); + var context = new StringContent(json, Encoding.UTF8, "application/json"); + var httpContent = _httpClient.PostAsync($"{Url}/api/task/addTask", context).ConfigureAwait(false).GetAwaiter().GetResult().Content; + string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + //JToken responseValue = AirportAGVClient.InvokeT("POST:/api/task/addTask", null, requestValue); + return JsonStringToEntity(result); + } + catch (Exception ex) + { + _logger.LogError($"AGV下发任务请求接口异常 {ex.Message}"); return null; } - //序列化输入数据 - string json = Newtonsoft.Json.JsonConvert.SerializeObject(requestValue); - var context = new StringContent(json, Encoding.UTF8, "application/json"); - var httpContent = _httpClient.PostAsync($"{Url}/api/task/addTask", context).ConfigureAwait(false).GetAwaiter().GetResult().Content; - string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - //JToken responseValue = AirportAGVClient.InvokeT("POST:/api/task/addTask", null, requestValue); - return JsonStringToEntity(result); } /// @@ -148,18 +156,27 @@ namespace SlnMesnac.TouchSocket /// public AGVResponseEntity AGVOperationalTaskRequest(AGVRequestOperationalTaskEntity requestValue) { - if (_httpClient == null) + try { - _logger.LogError("http服务为空"); + + if (_httpClient == null) + { + _logger.LogError("http服务为空"); + return null; + } + //序列化输入数据 + string json = Newtonsoft.Json.JsonConvert.SerializeObject(requestValue); + var context = new StringContent(json, Encoding.UTF8, "application/json"); + var httpContent = _httpClient.PostAsync($"{Url}/api/task/operationalTask", context).ConfigureAwait(false).GetAwaiter().GetResult().Content; + string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + //JToken responseValue = AirportAGVClient.InvokeT("POST:/api/task/operationalTask", null, requestValue); + return JsonStringToEntity(result); + } + catch (Exception ex) + { + _logger.LogError($"取消/终止任务请求接口异常 {ex.Message}"); return null; } - //序列化输入数据 - string json = Newtonsoft.Json.JsonConvert.SerializeObject(requestValue); - var context = new StringContent(json, Encoding.UTF8, "application/json"); - var httpContent = _httpClient.PostAsync($"{Url}/api/task/operationalTask", context).ConfigureAwait(false).GetAwaiter().GetResult().Content; - string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - //JToken responseValue = AirportAGVClient.InvokeT("POST:/api/task/operationalTask", null, requestValue); - return JsonStringToEntity(result); } /// @@ -169,18 +186,27 @@ namespace SlnMesnac.TouchSocket /// public AGVResponseEntity AGVGetTaskStateDetailRequest(AGVRequestTaskStateDetailEntity requestValue) { - if (_httpClient == null) + try { - _logger.LogError("http服务为空"); + + if (_httpClient == null) + { + _logger.LogError("http服务为空"); + return null; + } + //序列化输入数据 + string json = Newtonsoft.Json.JsonConvert.SerializeObject(requestValue); + var context = new StringContent(json, Encoding.UTF8, "application/json"); + var httpContent = _httpClient.PutAsync($"{Url}/api/task/getTaskStateDetail", context).ConfigureAwait(false).GetAwaiter().GetResult().Content; + string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + //JToken responseValue = AirportAGVClient.InvokeT("PUT:/api/task/getTaskStateDetail", null, requestValue); + return JsonStringToEntity(result); + } + catch (Exception ex) + { + _logger.LogError($"查询任务状态接口异常 {ex.Message}"); return null; } - //序列化输入数据 - string json = Newtonsoft.Json.JsonConvert.SerializeObject(requestValue); - var context = new StringContent(json, Encoding.UTF8, "application/json"); - var httpContent = _httpClient.PutAsync($"{Url}/api/task/getTaskStateDetail", context).ConfigureAwait(false).GetAwaiter().GetResult().Content; - string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - //JToken responseValue = AirportAGVClient.InvokeT("PUT:/api/task/getTaskStateDetail", null, requestValue); - return JsonStringToEntity(result); } /// @@ -189,16 +215,25 @@ namespace SlnMesnac.TouchSocket /// public AGVResponseEntity> AGVAllStateRequest() { - if (_httpClient == null) + try + { + + if (_httpClient == null) + { + _logger.LogError("http服务为空"); + return null; + } + //序列化输入数据 + var httpContent = _httpClient.GetAsync($"{Url}/api/task/robot/getRobot").ConfigureAwait(false).GetAwaiter().GetResult().Content; + string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + //JToken responseValue = AirportAGVClient.InvokeT("GET:/api/task/robot/getRobot", null); + return JsonStringToEntity>(result); + } + catch (Exception ex) { - _logger.LogError("http服务为空"); + _logger.LogError($"获取所有AGV信息接口异常 {ex.Message}"); return null; } - //序列化输入数据 - var httpContent = _httpClient.GetAsync($"{Url}/api/task/robot/getRobot").ConfigureAwait(false).GetAwaiter().GetResult().Content; - string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - //JToken responseValue = AirportAGVClient.InvokeT("GET:/api/task/robot/getRobot", null); - return JsonStringToEntity>(result); } /// @@ -207,15 +242,24 @@ namespace SlnMesnac.TouchSocket /// public AGVResponseEntity AGVMapActiveRequest() { - if (_httpClient == null) + try + { + + if (_httpClient == null) + { + _logger.LogError("http服务为空"); + return null; + } + var httpContent = _httpClient.GetAsync($"{Url}/api/v1.0.0/Maps/mapActive").ConfigureAwait(false).GetAwaiter().GetResult().Content; + string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + //JToken responseValue = AirportAGVClient.InvokeT("GET:/api/v1.0.0/Maps/mapActive", null); + return JsonStringToEntity(result); + } + catch (Exception ex) { - _logger.LogError("http服务为空"); + _logger.LogError($"互殴当前激活地图接口异常 {ex.Message}"); return null; } - var httpContent = _httpClient.GetAsync($"{Url}/api/v1.0.0/Maps/mapActive").ConfigureAwait(false).GetAwaiter().GetResult().Content; - string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - //JToken responseValue = AirportAGVClient.InvokeT("GET:/api/v1.0.0/Maps/mapActive", null); - return JsonStringToEntity(result); } /// @@ -225,18 +269,27 @@ namespace SlnMesnac.TouchSocket /// public AGVResponseEntity> AGVMapPositionRequest(string requestValue) { - if (_httpClient == null) + try + { + + if (_httpClient == null) + { + _logger.LogError("http服务为空"); + return null; + } + //序列化输入数据 + string json = Newtonsoft.Json.JsonConvert.SerializeObject(requestValue); + var context = new StringContent(json, Encoding.UTF8, "application/json"); + var httpContent = _httpClient.GetAsync($"{Url}/api/v1.0.0/Positions?mapId={requestValue}").ConfigureAwait(false).GetAwaiter().GetResult().Content; + string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + //JToken responseValue = AirportAGVClient.InvokeT("GET:/api/v1.0.0/Positions?mapId={0}", null, requestValue); + return JsonStringToEntity>(result); + } + catch (Exception ex) { - _logger.LogError("http服务为空"); + _logger.LogError($"获取当前地图所有位置点接口异常 {ex.Message}"); return null; } - //序列化输入数据 - string json = Newtonsoft.Json.JsonConvert.SerializeObject(requestValue); - var context = new StringContent(json, Encoding.UTF8, "application/json"); - var httpContent = _httpClient.GetAsync($"{Url}/api/v1.0.0/Positions?mapId={requestValue}").ConfigureAwait(false).GetAwaiter().GetResult().Content; - string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - //JToken responseValue = AirportAGVClient.InvokeT("GET:/api/v1.0.0/Positions?mapId={0}", null, requestValue); - return JsonStringToEntity>(result); } /// @@ -246,24 +299,33 @@ namespace SlnMesnac.TouchSocket /// public AGVResponseEntity AGVErrorClear(string agvIp) { - if (_httpClient == null) + try { - _logger.LogError("http服务为空"); - return null; - } - string token = "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiYWRtaW4iLCJyb2xlIjoiMSIsImlzcyI6IlNpbmV2YVNlcnZlciIsImF1ZCI6IlNpbmV2YUNsaWVudCJ9.Ujn-JuQDzA_sloITF84z1pdQvvH8DQ0DSFlhz4zP44M"; - var request = new HttpRequestMessage(HttpMethod.Delete, $"http://{agvIp}/api/v1.0.0/ClearException/0"); - // 单独为此请求添加 Authorization 头部 - request.Headers.Add("Authorization", token); - // 发送请求 - var response = _httpClient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult(); - // 读取响应内容 - var httpContent = response.Content; - string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + if (_httpClient == null) + { + _logger.LogError("http服务为空"); + return null; + } + string token = "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiYWRtaW4iLCJyb2xlIjoiMSIsImlzcyI6IlNpbmV2YVNlcnZlciIsImF1ZCI6IlNpbmV2YUNsaWVudCJ9.Ujn-JuQDzA_sloITF84z1pdQvvH8DQ0DSFlhz4zP44M"; - return JsonStringToEntity(result); + var request = new HttpRequestMessage(HttpMethod.Delete, $"http://{agvIp}/api/v1.0.0/ClearException/0"); + // 单独为此请求添加 Authorization 头部 + request.Headers.Add("Authorization", token); + // 发送请求 + var response = _httpClient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult(); + // 读取响应内容 + var httpContent = response.Content; + string result = httpContent.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + return JsonStringToEntity(result); + + } + catch (Exception ex) + { + _logger.LogError($"AGV异常清楚接口异常 {ex.Message}"); + return null; + } } ///// diff --git a/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml b/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml index ce031d7..de46bd5 100644 --- a/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml +++ b/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml @@ -5,16 +5,17 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SlnMesnac.WPF.Page.ControlPage" mc:Ignorable="d" d:DesignWidth="800" Background="Transparent" Height="590"> - +