| | |
| | | using SqlSugar; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.DirectoryServices.Protocols; |
| | | using System.Linq; |
| | | using System.Net.Http.Headers; |
| | | using System.Security.Policy; |
| | | using WIDESEA_DTO.Agv; |
| | |
| | | public WebResponseContent ReceiveWMSTask([NotNull] WMSTaskDTO taskDTO) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | string errorMsg = ""; |
| | | try |
| | | { |
| | | lock (lock_taskReceive) |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetCanOut(taskDTO.Tasks.Select(x=>x.ContainerCode).ToList()); |
| | | TasksItem? tasksItem = taskDTO.Tasks.FirstOrDefault(x => !locationInfos.Select(t => t.PalletCode).Contains(x.ContainerCode)); |
| | | if (tasksItem != null) throw new Exception($"ä»»å¡{tasksItem.TaskCode}æç®±å·{tasksItem.ContainerCode}ä¸åå¨"); |
| | | Dt_Task taskOld = BaseDal.QueryFirst(x=> taskDTO.Tasks.Select(x => x.TaskDescribe.ContainerCode).Contains(x.PalletCode)); |
| | | if (taskOld != null) throw new Exception($"æç®±{taskOld.PalletCode}"+(taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "å
¥åºä»»å¡å·²åå¨" : "åºåºä»»å¡å·²åå¨")); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetCanOut(taskDTO.Tasks.Select(x=>x.TaskDescribe.ContainerCode).ToList()); |
| | | |
| | | Dt_LocationInfo? noOutLocation = locationInfos.FirstOrDefault(x=>x.LocationStatus != LocationStatusEnum.InStock.ObjToInt() || x.EnableStatus != EnableStatusEnum.Normal.ObjToInt()); |
| | | |
| | | if (noOutLocation != null) throw new Exception($"æç®±{noOutLocation.PalletCode}è´§ä½{noOutLocation.LocationCode}ç¶æä¸å¯åºåº"); |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(); |
| | | //ä¸åä»»å¡ç» |
| | | string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode; |
| | | foreach (var item in taskDTO.Tasks.OrderBy(x=>x.ToStationCode)) |
| | | foreach (var item in taskDTO.Tasks.OrderBy(x=>x.TaskDescribe.ToStationCode)) |
| | | { |
| | | if (item.ToStationCode.IsNullOrEmpty()) throw new Exception($"ä»»å¡{item.TaskCode}åºåºç®æ æä½å°ä¸è½ä¸ºç©º"); |
| | | if (item.TaskDescribe.ToStationCode.IsNullOrEmpty()) throw new Exception($"ä»»å¡{item.TaskCode}åºåºç®æ æä½å°ä¸è½ä¸ºç©º"); |
| | | //è·åæä½å° |
| | | Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.PickStationCode == item.ToStationCode); |
| | | if (stationManger == null) throw new Exception($"ä»»å¡{item.TaskCode}åºåºç®æ æä½å°{item.ToStationCode}ä¸åå¨"); |
| | | Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.PickStationCode == item.TaskDescribe.ToStationCode); |
| | | if (stationManger == null) throw new Exception($"ä»»å¡{item.TaskCode}åºåºç®æ æä½å°{item.TaskDescribe.ToStationCode}ä¸åå¨"); |
| | | |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == item.TaskDescribe.ContainerCode); |
| | | if (locationInfo == null) |
| | | { |
| | | errorMsg += $"æç®±{item.TaskDescribe.ContainerCode}ä¸åå¨;"; |
| | | continue; |
| | | }; |
| | | |
| | | Dt_Task task = _mapper.Map<Dt_Task>(item); |
| | | Dt_LocationInfo locationInfo = locationInfos.FirstOrDefault(x=>x.PalletCode==item.ContainerCode); |
| | | |
| | | task.SourceAddress = locationInfo.LocationCode; |
| | | task.CurrentAddress = locationInfo.LocationCode; |
| | | task.NextAddress = stationManger.PickStationCode; |
| | |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "æ¥æ¶WMSä»»å¡"); |
| | | |
| | | content = tasks.Count > 0 ? content.OK("æå") : content.Error("失败"); |
| | | content = tasks.Count > 0 ? content.OK("æå!"+(errorMsg.IsNullOrEmpty()? "": errorMsg)) : content.Error("失败"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData(); |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x=>x.PalletCode== containerFlowDTO.ContainerCode); |
| | | if (locationInfo != null) throw new Exception($"æç®±å·{containerFlowDTO.ContainerCode}å·²åå¨"); |
| | | if (locationInfo != null) throw new Exception($"åºä½æç®±å·{containerFlowDTO.ContainerCode}å·²åå¨"); |
| | | if (BaseDal.QueryFirst(x=>x.PalletCode==containerFlowDTO.ContainerCode)!=null) throw new Exception($"æç®±å·{containerFlowDTO.ContainerCode}ä»»å¡å·²åå¨"); |
| | | Dt_LocationInfo? noInLocation = locationInfos.FirstOrDefault(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()); |
| | | if (noInLocation == null) throw new Exception($"å¯ç¨è´§ä½ä¸è¶³!"); |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode); |
| | | //ä¸åä»»å¡ç» |
| | | //åå»ºä»»å¡ |
| | | Dt_Task task = new Dt_Task(); |
| | | task.PalletCode = containerFlowDTO.ContainerCode; |
| | | task.SourceAddress = containerFlowDTO.SlotCode; |
| | |
| | | DateTime beginDate = DateTime.Now; |
| | | try |
| | | { |
| | | using (HttpContent httpContent = new StringContent(requestJson)) |
| | | using (HttpContent httpContent = new StringContent(string.Empty)) |
| | | { |
| | | httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); |
| | | |
| | | using HttpClient httpClient = new HttpClient(); |
| | | httpClient.Timeout = new TimeSpan(0, 0, 30); |
| | | string LoginToken = AppSettings.Get("MESLoginToken"); |
| | | headers = new Dictionary<string, string> |
| | | { |
| | | //æ£å¼ |
| | | { "LoginToken", LoginToken } |
| | | }; |
| | | if (headers != null) |
| | | { |
| | | foreach (var header in headers) |
| | | httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); |
| | | } |
| | | HttpResponseMessage responseMessage = httpClient.PostAsync(serviceAddress, httpContent).Result; |
| | | result = responseMessage.Content.ReadAsStringAsync().Result; |
| | | } |
| | |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//åºåºä»»å¡é»è¾ |
| | | if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//åºåºä»»å¡å®æé»è¾ |
| | | { |
| | | Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x=>x.PalletCode==task.PalletCode); |
| | | if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt()) |
| | |
| | | task.TaskState = TaskStatusEnum.Finish.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | locationInfo.PalletCode = ""; |
| | | //æç®±åºåºå®æä¸æ¥ç»WMS |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInOutBoundBack.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, $"æªæ¾å°WMSåºåºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | UpdateTaskExceptionMessage(taskNum, $"æªæ¾å°WMSåºåºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | return content.Error($"{taskNum},æªæ¾å°WMSåºåºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | ContainerInFinishDTO containerInFinishDTO = new ContainerInFinishDTO() |
| | | { |
| | | TaskCode = task.TaskNum.ToString(), |
| | | ContainerCode = task.PalletCode, |
| | | StationCode = task.TargetAddress, |
| | | LocationCode = task.SourceAddress, |
| | | CompleteType = 1 |
| | | }; |
| | | string request = JsonConvert.SerializeObject(containerInFinishDTO, settings); |
| | | //è°ç¨æ¥å£ |
| | | string response = HttpHelper.Post(url, request); |
| | | WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},æªæ¥æ¶å°WMSåºåºä¸æ¥è¿åå¼"); |
| | | if (wMSResponse.Code != "0") throw new Exception($"åºåºä»»å¡{task.TaskNum}WMSåºåºä¸æ¥é误,ä¿¡æ¯:{wMSResponse.Msg}"); |
| | | _unitOfWorkManage.BeginTran(); |
| | | _locationInfoRepository.UpdateData(locationInfo); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | else if(task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//å
¥åºä»»å¡é»è¾ |
| | | else if(task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//å
¥åºä»»å¡å®æé»è¾ |
| | | { |
| | | //string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInBoundBack.ToString())?.ApiAddress; |
| | | //if (string.IsNullOrEmpty(url)) |
| | | //{ |
| | | // _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | // UpdateTaskExceptionMessage(taskNum, $"æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | // return content.Error($"{taskNum},æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | //} |
| | | //ContainerInFinishDTO containerInFinishDTO = new ContainerInFinishDTO() |
| | | //{ |
| | | // TaskCode= task.TaskNum.ToString(), |
| | | // ContainerCode = task.PalletCode, |
| | | // FromStationCode = task.SourceAddress, |
| | | // ToLocationCode = task.TargetAddress |
| | | //}; |
| | | //string request = JsonConvert.SerializeObject(containerInFinishDTO, settings); |
| | | ////è°ç¨æ¥å£ |
| | | //string response = HttpHelper.Post(url, request); |
| | | //WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ??throw new Exception($"{taskNum},æªæ¥æ¶å°WMSå
¥åºä¸æ¥è¿åå¼"); |
| | | //if (wMSResponse.Code!="0") throw new Exception($"å
¥åºä»»å¡{task.TaskNum}WMSå
¥åºä¸æ¥é误,ä¿¡æ¯:{wMSResponse.Msg}"); |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInOutBoundBack.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, $"æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | UpdateTaskExceptionMessage(taskNum, $"æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | return content.Error($"{taskNum},æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | ContainerInFinishDTO containerInFinishDTO = new ContainerInFinishDTO() |
| | | { |
| | | TaskCode = task.TaskNum.ToString(), |
| | | ContainerCode = task.PalletCode, |
| | | StationCode = task.SourceAddress, |
| | | LocationCode = task.TargetAddress, |
| | | CompleteType = 2 |
| | | }; |
| | | string request = JsonConvert.SerializeObject(containerInFinishDTO, settings); |
| | | //è°ç¨æ¥å£ |
| | | string response = HttpHelper.Post(url, request); |
| | | WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},æªæ¥æ¶å°WMSå
¥åºä¸æ¥è¿åå¼"); |
| | | if (wMSResponse.Code != "0") throw new Exception($"å
¥åºä»»å¡{task.TaskNum}WMSå
¥åºä¸æ¥é误,ä¿¡æ¯:{wMSResponse.Msg}"); |
| | | Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt()) |
| | | { |
| | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// äºææç§å¢ä¸å |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | public EPLightContent PickOrderInfoRequest(List<EPLightSendDTO> lightSendDTOs) |
| | | { |
| | | EPLightContent content = new EPLightContent(); |
| | | try |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.PickOrderInfoRequest.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | return content.Error($"æªæ¾å°æç§å¢ä¸åæ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | string request = JsonConvert.SerializeObject(lightSendDTOs, settings); |
| | | //è°ç¨æ¥å£ |
| | | string response = HttpHelper.Post(url, request); |
| | | EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"æªæ¥æ¶å°æç§å¢ä¸å䏿¥è¿åå¼"); |
| | | if (lightContent.Result != "0") throw new Exception($"æç§å¢ä¸åé误,ä¿¡æ¯:{lightContent.Msg}"); |
| | | content.OK("æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// äºææç§å¢åå§å |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | public EPLightContent INITIALIZATION() |
| | | { |
| | | EPLightContent content = new EPLightContent(); |
| | | try |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.INITIALIZATION.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | return content.Error($"æªæ¾å°æç§å¢åå§åæ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | //è°ç¨æ¥å£ |
| | | string response = Post(url); |
| | | EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"æªæ¥æ¶å°æç§å¢åå§å䏿¥è¿åå¼"); |
| | | if (lightContent.Result != "0") throw new Exception($"æç§å¢åå§åé误,ä¿¡æ¯:{lightContent.Msg}"); |
| | | content.OK("æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// äºææç§å¢ç»æä½ä¸ |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | public EPLightContent ENDWORK() |
| | | { |
| | | EPLightContent content = new EPLightContent(); |
| | | try |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.ENDWORK.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | return content.Error($"æªæ¾å°æç§å¢ç»æä½ä¸æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | //è°ç¨æ¥å£ |
| | | string response = Post(url); |
| | | EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"æªæ¥æ¶å°æç§å¢ç»æä½ä¸ä¸æ¥è¿åå¼"); |
| | | if (lightContent.Result != "0") throw new Exception($"æç§å¢ç»æä½ä¸é误,ä¿¡æ¯:{lightContent.Msg}"); |
| | | content.OK("æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |