| | |
| | | using Autofac.Core; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using Org.BouncyCastle.Asn1.Ocsp; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection.Metadata; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_DTO.Agv; |
| | |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.Agv; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_Model.Models; |
| | | |
| | | namespace WIDESEAWCS_TaskInfoService |
| | | { |
| | | public partial class TaskService |
| | | { |
| | | // å建ä¸ä¸ªä½¿ç¨å°é©¼å³°å½åæ³çåºåå设置 |
| | | JsonSerializerSettings settings = new JsonSerializerSettings |
| | | { |
| | | ContractResolver = new CamelCasePropertyNamesContractResolver() |
| | | }; |
| | | public WebResponseContent AgvSendTask(AgvTaskSendDTO taskModel, APIEnum SendTask = APIEnum.AgvSendTask) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string? apiAddress = apiInfos.FirstOrDefault(x => x.ApiCode == SendTask.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(apiAddress)) |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°åéAGV任塿¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | string response = HttpHelper.Post(apiAddress, taskModel.Serialize()); |
| | | AgvResponseContent agvContent = response.DeserializeObject<AgvResponseContent>(); |
| | | if (agvContent.Code == "0") |
| | | |
| | | string? apiAddress = _apiInfoRepository.QueryFirst(x => x.ApiCode == SendTask.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(apiAddress)) throw new Exception($"æªæ¾å°åéAGV任塿¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | string request = JsonConvert.SerializeObject(taskModel, settings); |
| | | string response = HttpHelper.Post(apiAddress, request); |
| | | WriteLog.Write_Log("AGVå
¥åºä»»å¡ä¸å", "åºåºä»»å¡ä¸åæ¥å£", "请æ±ä»»å¡", $"请æ±ï¼{request},åä¼ ï¼{response}"); |
| | | AgvResponseContent agvContent = response.DeserializeObject<AgvResponseContent>() ?? throw new Exception("AGVä»»å¡åéæªè¿åç»æ"); |
| | | if (agvContent.Success) |
| | | { |
| | | content.OK(data: agvContent.Data); |
| | | content.OK(); |
| | | } |
| | | else |
| | | { |
| | |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// AGVä»»å¡ç¶æå·æ°/AGVä»»å¡å®æ |
| | | /// AGVæ¥è¯¢è°ç¨åWMSæ
é䏿¥ |
| | | /// </summary> |
| | | /// <param name="agvUpdateModel"></param> |
| | | /// <returns></returns> |
| | | public AgvResponseContent AgvUpdateTask(AgvUpdateDTO agvUpdateModel) |
| | | public void AgvSearchStatus1(Dt_ErrorInfo e2) |
| | | { |
| | | return new AgvResponseContent(); |
| | | WriteLog.Write_Log("AGVæ¥è¯¢è°ç¨åWMSæ
é䏿¥", "AGVæ¥è¯¢è°ç¨åWMSæ
鿥å£", "请æ±", $"请æ±ï¼{e2.ToJson()}"); |
| | | if (e2 != null) |
| | | { |
| | | // æ¥è¯¢æ¯å¦æé误没æå°±æ·»å ï¼æå°±åæ¶ |
| | | List<Dt_ErrorInfo> existingErrors = _errorInfoRepository.QueryData(x => |
| | | x.RobotCode == e2.RobotCode && |
| | | x.ErrorType == 2); // åªæ¥è¯¢æ
éç±»å为2çè®°å½ |
| | | |
| | | string? ErrorBack = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSErrorBack.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(ErrorBack)) |
| | | { |
| | | return; |
| | | }else{ |
| | | // å¦ææ¯æ
é䏿¥(e2.ErrorType == 2) |
| | | if (e2.ErrorType == 2) |
| | | { |
| | | // æ£æ¥æ¯å¦å·²åå¨ç¸åæºå¨äººçæ
éè®°å½ |
| | | if (existingErrors.Count == 0) |
| | | { |
| | | _errorInfoRepository.AddData(e2); |
| | | // åéç»WMS - æ
é䏿¥ |
| | | TaskError taskError = new TaskError() |
| | | { |
| | | MsgID = e2.Id, |
| | | StationCode = e2.StationCode, |
| | | MsgCode = 1, // 1表示æ
é |
| | | Msg = e2.Message |
| | | }; |
| | | string reqErrorBack = JsonConvert.SerializeObject(taskError, settings); |
| | | HttpHelper.Post(ErrorBack, reqErrorBack); |
| | | } |
| | | // 妿已å卿
éè®°å½ï¼åä¸é夿·»å |
| | | } |
| | | // å¦ææ¯æ£å¸¸ç¶æ(e2.ErrorType == 0)ä¸å卿
éè®°å½ï¼åæ§è¡æ
éæ¢å¤ |
| | | else if (e2.ErrorType == 0 && existingErrors.Count > 0) |
| | | { |
| | | // å 餿
éè®°å½ |
| | | if (_errorInfoRepository.DeleteData(existingErrors)) |
| | | { |
| | | // åéç»WMS - æ
éæ¢å¤ |
| | | foreach (var error in existingErrors) |
| | | { |
| | | TaskError taskError = new TaskError() |
| | | { |
| | | MsgID = error.Id, |
| | | StationCode = error.StationCode, |
| | | MsgCode = 0, // 0表示æ¢å¤ |
| | | Msg = "æ
鿢å¤" |
| | | }; |
| | | string reqErrorBack = JsonConvert.SerializeObject(taskError, settings); |
| | | HttpHelper.Post(ErrorBack, reqErrorBack); |
| | | } |
| | | } |
| | | } |
| | | return; |
| | | } |
| | | |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// AGVç¶ææ¥è¯¢è°ç¨åWMSæ
é䏿¥ |
| | | /// </summary> |
| | | public void AgvSearchStatus() |
| | | { |
| | | try |
| | | { |
| | | // æ¥è¯¢æ¯å¦æä»»å¡ |
| | | List<Dt_Task> tasks = BaseDal.QueryData(); |
| | | // å¦ææ²¡æä»»å¡ï¼ç´æ¥è¿å |
| | | if (tasks == null || tasks.Count == 0) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | AgvSearchStatusDTO agvSearchStatusDTO = new AgvSearchStatusDTO(); |
| | | string? apiAddress = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.AgvSearchStatus.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(apiAddress)) throw new Exception($"æªæ¾å°AGVç¶ææ¥è¯¢æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | string? apiErrorBack = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSErrorBack.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(apiErrorBack)) throw new Exception($"æªæ¾å°WMSæ
é䏿¥,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | string request = JsonConvert.SerializeObject(agvSearchStatusDTO, settings); |
| | | string response = HttpHelper.Post(apiAddress, request); |
| | | AgvStatusContent agvContent = response.DeserializeObject<AgvStatusContent>() ?? throw new Exception("AGVç¶ææ¥è¯¢æªè¿åç»æ"); |
| | | |
| | | //è·åæææ
éä¿¡æ¯ |
| | | List <Dt_ErrorInfo> errorInfos = _errorInfoRepository.QueryData(x => x.ErrorType == 1); |
| | | int errorId = errorInfos.Count > 0 ? errorInfos.Max(x => x.Id) : 0; |
| | | List<Dt_ErrorInfo> delErrorInfos = new List<Dt_ErrorInfo>(); |
| | | List<Dt_ErrorInfo> addErrorInfos = new List<Dt_ErrorInfo>(); |
| | | //è·åä»»å¡ä¿¡æ¯ |
| | | //List<Dt_Task> tasks = BaseDal.QueryData(); |
| | | if (agvContent.Success) |
| | | { |
| | | foreach (var item in agvContent.Data.Where(x => errorInfos.Select(x => x.RobotCode).Contains(x.RobotId) && x.Status != 7)) |
| | | { |
| | | //䏿¥æ
éæ¢å¤ |
| | | Dt_ErrorInfo errorInfo = errorInfos.FirstOrDefault(x => x.RobotCode == item.RobotId); |
| | | |
| | | delErrorInfos.Add(errorInfo); |
| | | } |
| | | foreach (var item in agvContent.Data.Where(x => !x.MissionCode.IsNullOrEmpty() && !errorInfos.Select(x => x.RobotCode).Contains(x.RobotId) && x.Status == 7)) |
| | | { |
| | | Dt_Task? task = tasks.FirstOrDefault(x=>x.TaskNum == item.MissionCode.ObjToInt() || x.GroupId==item.MissionCode); |
| | | if (task != null) |
| | | { |
| | | Dt_ErrorInfo errorInfo = new Dt_ErrorInfo() |
| | | { |
| | | RobotCode = item.RobotId, |
| | | Message = "æ
é", |
| | | ErrorType = 1, |
| | | }; |
| | | if (task.TaskType==TaskTypeEnum.Inbound.ObjToInt()) |
| | | { |
| | | errorInfo.StationCode = task.CurrentAddress; |
| | | } |
| | | else |
| | | { |
| | | errorInfo.StationCode = task.NextAddress; |
| | | } |
| | | addErrorInfos.Add(errorInfo); |
| | | } |
| | | } |
| | | } |
| | | //æ°æ®åºæä½ |
| | | _unitOfWorkManage.BeginTran(); |
| | | _errorInfoRepository.DeleteData(delErrorInfos); |
| | | _errorInfoRepository.AddData(addErrorInfos); |
| | | _unitOfWorkManage.CommitTran(); |
| | | List<Dt_ErrorInfo> newErrInfos = _errorInfoRepository.QueryData(x=>x.Id > errorId && x.ErrorType == 1); |
| | | if (delErrorInfos.Count>0) |
| | | { |
| | | foreach (var item in delErrorInfos) |
| | | { |
| | | TaskError taskError = new TaskError() |
| | | { |
| | | MsgID = item.Id, |
| | | StationCode = item.StationCode, |
| | | MsgCode = 0, |
| | | Msg = "æ¢å¤" |
| | | }; |
| | | string reqErrorBack = JsonConvert.SerializeObject(taskError, settings); |
| | | HttpHelper.Post(apiErrorBack, reqErrorBack); |
| | | |
| | | } |
| | | } |
| | | if (newErrInfos.Count>0) |
| | | { |
| | | //ä¸ä¼ æ
é |
| | | foreach (var item in newErrInfos) |
| | | { |
| | | TaskError taskError = new TaskError() |
| | | { |
| | | MsgID = item.Id, |
| | | StationCode = item.StationCode, |
| | | MsgCode = 1, |
| | | Msg = item.Message |
| | | }; |
| | | string reqErrorBack = JsonConvert.SerializeObject(taskError, settings); |
| | | HttpHelper.Post(apiErrorBack, reqErrorBack); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | throw new Exception(ex.Message); |
| | | } |
| | | |
| | | } |
| | | public WebResponseContent AgvCancelTask(AgvTaskCancelDTO taskModel, APIEnum SendTask = APIEnum.AgvTaskCancel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string? apiAddress = _apiInfoRepository.QueryFirst(x => x.ApiCode == SendTask.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(apiAddress)) throw new Exception($"æªæ¾å°åéAGV任塿¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | string request = JsonConvert.SerializeObject(taskModel, settings); |
| | | string response = HttpHelper.Post(apiAddress, request); |
| | | AgvResponseContent agvContent = response.DeserializeObject<AgvResponseContent>() ?? throw new Exception("AGVä»»å¡åéæªè¿åç»æ"); |
| | | if (agvContent.Success) |
| | | { |
| | | content.OK(); |
| | | } |
| | | else |
| | | { |
| | | content.Error(agvContent.Message); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |