| | |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | using AutoMapper; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Newtonsoft.Json; |
| | | using NPOI.SS.Formula.Functions; |
| | | using SqlSugar; |
| | |
| | | using WIDESEAWCS_DTO.Agv; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_IBasicInfoService; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | |
| | | private readonly IRouterRepository _routerRepository; |
| | | private readonly IApiInfoRepository _apiInfoRepository; |
| | | private readonly ILocationInfoRepository _locationInfoRepository; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | |
| | | |
| | | public List<int> TaskRelocationTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 900 && x < 1000).ToList(); |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository,ILocationInfoRepository locationInfoRepository,IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository,ILocationInfoRepository locationInfoRepository,IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _cacheService = cacheService; |
| | |
| | | _apiInfoRepository = apiInfoRepository; |
| | | _locationInfoRepository = locationInfoRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _locationInfoService = locationInfoService; |
| | | } |
| | | static object lock_taskReceive = new object(); |
| | | /// <summary> |
| | |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(); |
| | | //ä¸åä»»å¡ç» |
| | | string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode; |
| | | foreach (var item in taskDTO.Tasks) |
| | | foreach (var item in taskDTO.Tasks.OrderBy(x=>x.ToStationCode)) |
| | | { |
| | | if (item.ToStationCode.IsNullOrEmpty()) throw new Exception($"ä»»å¡{item.TaskCode}åºåºç®æ æä½å°ä¸è½ä¸ºç©º"); |
| | | //è·åæä½å° |
| | |
| | | task.GroupId = taskGroup; |
| | | task.TaskType = TaskTypeEnum.Outbound.ObjToInt(); |
| | | task.Roadway = locationInfo.RoadwayNo; |
| | | task.DeviceCode = "AGV"; |
| | | task.DeviceCode = stationManger.CraneCode; |
| | | task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt(); |
| | | tasks.Add(task); |
| | | } |
| | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | static object lock_containerFlow = new object(); |
| | | /// <summary> |
| | | /// 容å¨å
¥åºåå»ºä»»å¡ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent ContainerFlow(ContainerFlowDTO containerFlowDTO, string deviceCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | lock (lock_containerFlow) |
| | | { |
| | | 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 (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; |
| | | task.CurrentAddress = containerFlowDTO.SlotCode; |
| | | task.NextAddress = stationManger.StationCode; |
| | | task.TargetAddress = ""; |
| | | task.WMSId = ""; |
| | | task.TaskType = TaskTypeEnum.Inbound.ObjToInt(); |
| | | task.Roadway = noInLocation.RoadwayNo; |
| | | task.DeviceCode = stationManger.StationDeviceCode; |
| | | task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt(); |
| | | //æ·»å ä»»å¡ |
| | | BaseDal.AddData(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "å建å
¥åºä»»å¡"); |
| | | content.OK("æå"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error($"é误信æ¯:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | static object lock_requestInTask = new object(); |
| | | /// <summary> |
| | | /// ç³è¯·å
¥åº |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestInTask(string stationCode,string barCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | lock (lock_requestInTask) |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == barCode && x.NextAddress == stationCode && x.TaskState == TaskStatusEnum.CL_Executing.ObjToInt()); |
| | | if (task == null) throw new Exception($"{barCode}æç®±æªæ¾å°ä»»å¡!"); |
| | | Dt_LocationInfo? locationInfo = _locationInfoService.AssignLocation(); |
| | | if (locationInfo == null) throw new Exception($"å¯ç¨è´§ä½ä¸è¶³!"); |
| | | task.NextAddress = locationInfo.LocationCode; |
| | | task.TargetAddress = locationInfo.LocationCode; |
| | | task.CurrentAddress = stationCode; |
| | | task.DeviceCode = "AGV"; |
| | | task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | //æ´æ°ä»»å¡åè´§ä½æ°æ® |
| | | _unitOfWorkManage.BeginTran(); |
| | | BaseDal.UpdateData(task); |
| | | _locationInfoRepository.UpdateData(locationInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, $"åé
è´§ä½{locationInfo.LocationCode}"); |
| | | |
| | | content.OK("æå"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error($"é误信æ¯:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public static string Post(string serviceAddress, string requestJson = "", string contentType = "application/json", Dictionary<string, string>? headers = null) |
| | | { |
| | | string result = string.Empty; |
| | |
| | | task.ModifyDate = DateTime.Now; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, task.ExceptionMessage); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, task.ExceptionMessage); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | |
| | | |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"人工æ¢å¤æèµ·ä»»å¡,æ¢å¤æèµ·æ¶ä»»å¡ç¶æã{task.TaskState}ã"); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, $"人工æ¢å¤æèµ·ä»»å¡,æ¢å¤æèµ·æ¶ä»»å¡ç¶æã{task.TaskState}ã"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | |
| | | |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"人工å°ä»»å¡ç¶æä»ã{oldState}ãåæ»å°ã{task.TaskState}ã"); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, $"人工å°ä»»å¡ç¶æä»ã{oldState}ãåæ»å°ã{task.TaskState}ã"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | |
| | | AgvTaskFlowDTO agvTaskFlowDTO = new AgvTaskFlowDTO() |
| | | { |
| | | RequestId = Guid.NewGuid().ToString().Replace("-", ""), |
| | | ContainerCode = code |
| | | MissionCode = code |
| | | }; |
| | | string request = JsonConvert.SerializeObject(agvTaskFlowDTO, settings); |
| | | string response = HttpHelper.Post(url, request); |
| | |
| | | } |
| | | else if(task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//å
¥åºä»»å¡é»è¾ |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInBoundBack.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | //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}"); |
| | | Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt()) |
| | | { |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | UpdateTaskExceptionMessage(taskNum, $"æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | return content.Error($"{taskNum},æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | return content.Error($"{locationInfo.LocationCode}è´§ä½ç¶æä¸æ£ç¡®"); |
| | | } |
| | | 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}"); |
| | | task.TaskState = TaskStatusEnum.Finish.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | locationInfo.PalletCode = task.PalletCode; |
| | | _unitOfWorkManage.BeginTran(); |
| | | _locationInfoRepository.UpdateData(locationInfo); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | content.OK("ä»»å¡å®æ"); |
| | | } |