| | |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Newtonsoft.Json; |
| | | using NPOI.SS.Formula.Functions; |
| | | using NPOI.SS.UserModel; |
| | | using NPOI.XSSF.UserModel; |
| | | using RYB_PTL_API; |
| | | using SqlSugar; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.DirectoryServices.Protocols; |
| | | using System.Linq; |
| | | using System.Net.Http.Headers; |
| | | using System.Security.Policy; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_DTO.Agv; |
| | | using WIDESEA_External.Model; |
| | | using WIDESEAWCS_BasicInfoService; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.APIEnum; |
| | | using WIDESEAWCS_Common.Helper; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | |
| | | private readonly ILocationInfoRepository _locationInfoRepository; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | private readonly ILocationStatusChangeRecordService _locationStatusChangeRecordService; |
| | | private readonly IErrorInfoRepository _errorInfoRepository; |
| | | |
| | | 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, ILocationInfoService locationInfoService,ILocationStatusChangeRecordService locationStatusChangeRecordService) : 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,ILocationStatusChangeRecordService locationStatusChangeRecordService,IErrorInfoRepository errorInfoRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _cacheService = cacheService; |
| | |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _locationInfoService = locationInfoService; |
| | | _locationStatusChangeRecordService=locationStatusChangeRecordService; |
| | | _errorInfoRepository = errorInfoRepository; |
| | | } |
| | | static object lock_taskReceive = new object(); |
| | | /// <summary> |
| | |
| | | List<Dt_Task> taskOlds = BaseDal.QueryData(x=> taskDTO.Tasks.Select(x => x.TaskDescribe.ContainerCode).Contains(x.PalletCode)); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetCanOut(taskDTO.Tasks.Select(x=>x.TaskDescribe.ContainerCode).ToList()); |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(); |
| | | //ä¸åä»»å¡ç» |
| | | string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode; |
| | | ////ä¸åä»»å¡ç» |
| | | //string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode; |
| | | foreach (var item in taskDTO.Tasks.OrderBy(x=>x.TaskDescribe.ToStationCode)) |
| | | { |
| | | if (item.TaskDescribe.ToStationCode.IsNullOrEmpty()) throw new Exception($"ä»»å¡{item.TaskCode}åºåºç®æ æä½å°ä¸è½ä¸ºç©º"); |
| | |
| | | task.CurrentAddress = locationInfo.LocationCode; |
| | | task.NextAddress = stationManger.PickStationCode; |
| | | task.TargetAddress = stationManger.PickStationCode; |
| | | task.GroupId = taskGroup; |
| | | //task.GroupId = taskGroup; |
| | | task.TaskType = TaskTypeEnum.Outbound.ObjToInt(); |
| | | task.Roadway = locationInfo.RoadwayNo; |
| | | task.DeviceCode = stationManger.CraneCode; |
| | |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// 䏿æç§å¢ä¸å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public EPLightContent Phase1PickOrderInfoRequest(List<EPLightSendDTO> lightSendDTOs) |
| | | { |
| | | EPLightContent content = new EPLightContent(); |
| | | |
| | | try |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.Phase1PickOrderInfoRequest.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | return content.Error("æªæ¾å°æç§å¢ä¸åæ¥å£ï¼è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | |
| | | bool allSuccess = true; |
| | | StringBuilder errorMessages = new StringBuilder(); |
| | | |
| | | foreach (EPLightSendDTO lightSendDTO in lightSendDTOs) |
| | | { |
| | | try |
| | | { |
| | | bool operationResult; |
| | | |
| | | // å¤çç¯å
ç±»åè½¬æ¢ |
| | | if (!int.TryParse(lightSendDTO.LIGHTTYPE, out int lightType)) |
| | | { |
| | | allSuccess = false; |
| | | errorMessages.AppendLine($"ä½ç½® {lightSendDTO.LOCATION} é误: æ æçç¯å
ç±»å '{lightSendDTO.LIGHTTYPE}'"); |
| | | continue; |
| | | } |
| | | |
| | | // å¤çå
³éç¯å
è¯·æ± |
| | | if (lightType == 2) |
| | | { |
| | | operationResult = RYB_PTL.RYB_PTL_CloseDigit5(url, lightSendDTO.LOCATION); |
| | | // TODO: å
³éç¯å
åè°å¤ç |
| | | //List<EPLightBackDTO> lightBackDTOs = new List<EPLightBackDTO>(); |
| | | //List<TaskBackLight> taskBackLights = lightSendDTOs.Select(x => new TaskBackLight() |
| | | //{ |
| | | // TagNo = "B1", |
| | | // TagCode = x.LOCATION, |
| | | //}).ToList(); |
| | | //content = WMSLightBack(taskBackLights); |
| | | } |
| | | // å¤çæ¾ç¤ºç¯å
è¯·æ± |
| | | else |
| | | { |
| | | // å¤çç¯å
é¢è²è½¬æ¢ |
| | | if (!int.TryParse(lightSendDTO.LIGHTCOLOR, out int lightColor)) |
| | | { |
| | | allSuccess = false; |
| | | errorMessages.AppendLine($"ä½ç½® {lightSendDTO.LOCATION} é误: æ æçç¯å
é¢è² '{lightSendDTO.LIGHTCOLOR}'"); |
| | | continue; |
| | | } |
| | | |
| | | operationResult = RYB_PTL.RYB_PTL_DspDigit5( |
| | | url, |
| | | |
| | | lightSendDTO.LOCATION, |
| | | lightSendDTO.QUANTITY, |
| | | lightType, |
| | | lightColor); |
| | | } |
| | | if (!operationResult) |
| | | { |
| | | allSuccess = false; |
| | | errorMessages.AppendLine($"ä½ç½® {lightSendDTO.LOCATION} æä½å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | catch (Exception ex) |
| | | { |
| | | allSuccess = false; |
| | | errorMessages.AppendLine($"ä½ç½® {lightSendDTO.LOCATION} å¤çå¼å¸¸: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | return allSuccess |
| | | ? content.OK("æææç§å¢ä¸åæä½æå") |
| | | : content.Error(errorMessages.ToString()); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// æç§å¢äº®ç¯ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (taskSendLight.TagNo=="B2") |
| | | if (taskSendLight.TagNo == "B1") |
| | | { |
| | | List<EPLightSendDTO> lightSendDTOs = new List<EPLightSendDTO>() |
| | | { |
| | | new EPLightSendDTO |
| | | { |
| | | DOCNO = taskSendLight.DocNo, |
| | | TASKNO= taskSendLight.TaskNo, |
| | | LOCATION=taskSendLight.TagCode, |
| | | QUANTITY=taskSendLight.TagQunity, |
| | | LIGHTCOLOR=taskSendLight.Color switch |
| | | { |
| | | "Blue" => "4", |
| | | "Green" => "2", |
| | | "Red" => "1", |
| | | _ => throw new Exception($"æªæ¾å°é¢è²å®ä¹") |
| | | }, |
| | | ORDERTYPE="1", |
| | | LIGHTTYPE=taskSendLight.Mode.ToString(), |
| | | } |
| | | }; |
| | | EPLightContent pLightContent = Phase1PickOrderInfoRequest(lightSendDTOs); |
| | | if (pLightContent.Result != "0") throw new Exception($"{pLightContent.Msg}"); |
| | | content.OK(); |
| | | } |
| | | else if (taskSendLight.TagNo == "B2") |
| | | { |
| | | List<EPLightSendDTO> lightSendDTOs = new List<EPLightSendDTO>() |
| | | { |
| | |
| | | "Red" => "4", |
| | | _ => throw new Exception($"æªæ¾å°é¢è²å®ä¹") |
| | | }, |
| | | ORDERTYPE=taskSendLight.Mode.ToString(), |
| | | LIGHTTYPE="1", |
| | | ORDERTYPE="1", |
| | | LIGHTTYPE=taskSendLight.Mode.ToString(), |
| | | } |
| | | }; |
| | | EPLightContent pLightContent = PickOrderInfoRequest(lightSendDTOs); |
| | |
| | | { |
| | | content.OK(); |
| | | } |
| | | |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | return content.Error($"æªæ¾å°æç§å¢ä¸åæ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | string request = JsonConvert.SerializeObject(lightSendDTOs, settings).ToUpper(); |
| | | //è°ç¨æ¥å£ |
| | | // è°ç¨æ¥å£ |
| | | string response = HttpHelper.Post(url, request); |
| | | EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"æªæ¥æ¶å°æç§å¢ä¸å䏿¥è¿åå¼"); |
| | | if (lightContent.Result != "0") throw new Exception($"æç§å¢ä¸åé误,ä¿¡æ¯:{lightContent.Msg}"); |
| | |
| | | } |
| | | return content; |
| | | } |
| | | public override WebResponseContent Export(PageDataOptions options) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string savePath = AppDomain.CurrentDomain.BaseDirectory + "ExcelExport"; |
| | | |
| | | // ç¡®ä¿ç®å½åå¨ |
| | | if (!Directory.Exists(savePath)) |
| | | Directory.CreateDirectory(savePath); |
| | | |
| | | // è·åæ°æ® |
| | | ISugarQueryable<Dt_Task> query = BaseDal.Db.Queryable<Dt_Task>(); |
| | | var dataList = query.ToList(); |
| | | var properties = typeof(Dt_Task).GetProperties(); |
| | | |
| | | string filePath = TExportHelper.GetExport(savePath, properties, dataList); |
| | | return WebResponseContent.Instance.OK(data: filePath); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// éç½®ææå¼å¸¸ä»»å¡ |
| | | /// </summary> |
| | | public WebResponseContent ResetAllExceptionTask(int taskNum) |
| | | { |
| | | // è·åå¼å¸¸ä»»å¡990ä¿®æ¹ä¸ºAGVå¾
æ§è¡300 |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | if (task.TaskState != (int)TaskStatusEnum.Exception) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任å¡ç¶æä¸å¯éç½®,ä»»å¡å·:ã{taskNum}ã,ä»»å¡ç¶æ:ã{task.TaskState}ã"); |
| | | } |
| | | task.TaskState = (int)TaskStatusEnum.AGV_Execute; |
| | | BaseDal.UpdateData(task); |
| | | //_taskExecuteDetailService.AddTaskExecuteDetail(task, $"人工éç½®å¼å¸¸ä»»å¡,éç½®åä»»å¡ç¶æã{task.TaskState}ã"); |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |