| | |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
| | | using SqlSugar; |
| | | using System.ComponentModel; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.Log; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_BasicInfoService; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.APIEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | using WIDESEAWCS_DTO.MES; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_DTO.WMS; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_IBasicInfoService; |
| | | using WIDESEAWCS_ISystemServices; |
| | |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | private readonly IRouterRepository _routerRepository; |
| | | private readonly ITask_HtyRepository _taskHtyRepository; |
| | | private readonly IApiInfoRepository _apiInfoRepository; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | |
| | | |
| | | |
| | | #region è·åææä»»å¡ç±»åãç¶æ |
| | | public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskRelocationboundTypes => typeof(TaskRelocationTypeEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskInboundStates => typeof(TaskInStatusEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskOutboundStates => typeof(TaskOutStatusEnum).GetEnumIndexList(); |
| | | public List<int> TaskRelocationboundStates => typeof(TaskRelocationStatusEnum).GetEnumIndexList(); |
| | | |
| | | #endregion è·åææä»»å¡ç±»åãç¶æ |
| | | |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ISys_ConfigService sys_ConfigService, IDt_StationManagerService stationManagerService, IDt_StationManagerRepository stationManagerRepository, IRouterRepository routerRepository, ITask_HtyRepository htyRepository) : base(BaseDal) |
| | | public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ISys_ConfigService sys_ConfigService, IDt_StationManagerService stationManagerService, IDt_StationManagerRepository stationManagerRepository, IRouterRepository routerRepository, ITask_HtyRepository htyRepository, IApiInfoRepository apiInfoRepository,IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) |
| | | { |
| | | _routerService = routerService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _routerRepository = routerRepository; |
| | | _taskHtyRepository = htyRepository; |
| | | _apiInfoRepository = apiInfoRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.CarryGroup) |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.OutPending; |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | task.TaskState = (int)TaskInStatusEnum.InPending; |
| | | task.TaskState = (int)TaskAGVCarryStatusEnum.AGV_CarryException; |
| | | } |
| | | task.ExceptionMessage = message; |
| | | task.ModifyDate = DateTime.Now; |
| | |
| | | int oldState = task.TaskState; |
| | | if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.OutbondGroup) |
| | | { |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>(); |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskAGVCarryStatusEnum>(); |
| | | |
| | | task.TaskState = nextStatus; |
| | | |
| | | if (task.TaskState == (int)TaskOutStatusEnum.AGV_OutFinish) |
| | | if (task.TaskState == (int)TaskAGVCarryStatusEnum.AGV_CarryFinish) |
| | | { |
| | | |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | |
| | | Dt_Task_Hty task_Hty = _mapper.Map<Dt_Task_Hty>(task); |
| | | task_Hty.TaskId = 0; |
| | | |
| | | BaseDal.DeleteData(task); |
| | | _taskHtyRepository.AddData(task_Hty); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.äººå·¥å®æ : OperateTypeEnum.èªå¨å®æ); |
| | | } |
| | | } |
| | | else if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.InboundGroup) |
| | | { |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>(); |
| | | task.TaskState = nextStatus; |
| | | |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | if (task.TaskState != (int)TaskInStatusEnum.InPending && task.TaskState != (int)TaskOutStatusEnum.OutPending) |
| | | if (task.TaskState != (int)TaskAGVCarryStatusEnum.AGV_CarryException && task.TaskState != (int)TaskAGVCarryStatusEnum.AGV_CarryException) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任å¡ç¶æä¸å¯æ¢å¤,ä»»å¡å·:ã{taskNum}ã,ä»»å¡ç¶æ:ã{task.TaskState}ã"); |
| | | } |
| | |
| | | } |
| | | else |
| | | { |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.OutNew; |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | task.TaskState = (int)TaskInStatusEnum.InNew; |
| | | } |
| | | throw new Exception($"æªæ¾å°ä»»å¡å·{taskNum}æ¢å¤ç¶æ"); |
| | | } |
| | | |
| | | task.ExceptionMessage = string.Empty; |
| | |
| | | |
| | | |
| | | #endregion éåæ¹æ³ |
| | | |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡ä¿¡æ¯åæ·»å 任塿ç»è®°å½ |
| | | /// </summary> |
| | | /// <param name="task">ä»»å¡å对象å®ä¾(æªä¿®æ¹çæ°æ®å¯¹è±¡)</param> |
| | | /// <param name="taskStatus">ä¿®æ¹åçä»»å¡ç¶æ</param> |
| | | /// <param name="deviceCode">ä¿®æ¹åç设å¤ç¼å·</param> |
| | | /// <param name="sourceAddress">ä¿®æ¹åçèµ·å§å°å</param> |
| | | /// <param name="targetAddress">ä¿®æ¹åçç®æ å°å</param> |
| | | /// <param name="currentAddress">ä¿®æ¹åçå½åå°å</param> |
| | | /// <param name="nextAddress">ä¿®æ¹åçä¸ä¸å°å</param> |
| | | public void UpdateTask(Dt_Task task, TaskAGVCarryStatusEnum taskStatus, string deviceCode = "", string sourceAddress = "", string targetAddress = "", string currentAddress = "", string nextAddress = "", string roadwayNo = "") |
| | | { |
| | | StringBuilder stringBuilder = new StringBuilder(App.User?.UserId == 0 ? $"ç³»ç»èªå¨æµç¨" : "人工æå¨æµç¨"); |
| | | if (task.SourceAddress != sourceAddress && !string.IsNullOrEmpty(sourceAddress)) |
| | | { |
| | | stringBuilder.Append($",èµ·å§å°åç±{task.SourceAddress}åæ´ä¸º{sourceAddress}"); |
| | | task.SourceAddress = sourceAddress; |
| | | } |
| | | if (task.TargetAddress != targetAddress && !string.IsNullOrEmpty(targetAddress)) |
| | | { |
| | | stringBuilder.Append($",ç®æ å°åç±{task.TargetAddress}åæ´ä¸º{targetAddress}"); |
| | | task.TargetAddress = targetAddress; |
| | | } |
| | | if (task.CurrentAddress != currentAddress && !string.IsNullOrEmpty(currentAddress)) |
| | | { |
| | | stringBuilder.Append($",å½åä½ç½®ç±{task.CurrentAddress}åæ´ä¸º{currentAddress}"); |
| | | task.CurrentAddress = currentAddress; |
| | | } |
| | | if (task.NextAddress != nextAddress && !string.IsNullOrEmpty(nextAddress)) |
| | | { |
| | | stringBuilder.Append($",ä¸ä¸ä½ç½®ç±{task.NextAddress}åæ´ä¸º{nextAddress}"); |
| | | task.NextAddress = nextAddress; |
| | | } |
| | | if (task.Roadway != roadwayNo && !string.IsNullOrEmpty(roadwayNo)) |
| | | { |
| | | stringBuilder.Append($",å··éå·ç±{task.Roadway}åæ´ä¸º{roadwayNo}"); |
| | | task.Roadway = roadwayNo; |
| | | } |
| | | if (task.TaskState != taskStatus.ObjToInt()) |
| | | { |
| | | string newStatus = $"{taskStatus}"; |
| | | try |
| | | { |
| | | List<int> enums = Enum.GetValues(typeof(TaskAGVCarryStatusEnum)).Cast<int>().ToList(); |
| | | FieldInfo? fieldInfo = typeof(TaskAGVCarryStatusEnum).GetField((taskStatus).ToString()); |
| | | if (fieldInfo != null) |
| | | { |
| | | DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>(); |
| | | if (description != null) |
| | | { |
| | | newStatus = $"{description.Description}({taskStatus})"; |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | string oldStatus = $"{task.TaskState}"; |
| | | try |
| | | { |
| | | FieldInfo? fieldInfo2 = typeof(RouterInOutType).GetField(((TaskAGVCarryStatusEnum)task.TaskState).ToString()); |
| | | if (fieldInfo2 != null) |
| | | { |
| | | DescriptionAttribute? description2 = fieldInfo2.GetCustomAttribute<DescriptionAttribute>(); |
| | | if (description2 != null) |
| | | { |
| | | oldStatus = $"{description2.Description}({task.TaskState})"; |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | stringBuilder.Append($",ä»»å¡ç¶æç±{oldStatus}åæ´ä¸º{newStatus}"); |
| | | |
| | | task.TaskState = taskStatus.ObjToInt(); |
| | | } |
| | | BaseDal.UpdateData(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, stringBuilder.ToString()); |
| | | } |
| | | |
| | | // å¨ç±»ä¸æ·»å éæé对象 |
| | | private static readonly object _taskCompleteLock = new object(); |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡å®æ |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent TaskCompleted(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | |
| | | // 使ç¨éç¡®ä¿åä¸ä»»å¡ä¸ä¼å¹¶åå¤ç |
| | | lock (_taskCompleteLock) |
| | | { |
| | | try |
| | | { |
| | | WriteLog.Write_Log("ä»»å¡å®æ", "ä»»å¡å®ææ¥å£", "ä»»å¡å·", $"ä»»å¡ï¼{taskNum}"); |
| | | |
| | | // 忬¡æ¥è¯¢ä»»å¡ç¶æï¼é²æ¢å¨éçå¾
æé´ä»»å¡ç¶æå·²æ¹å |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) |
| | | { |
| | | return content.Error($"ä»»å¡{taskNum}ä¸åå¨"); |
| | | } |
| | | //ä»»å¡å®æé»è¾ |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | content.OK("ä»»å¡å®æ"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |
| | | } |