| | |
| | | #region << ç æ¬ 注 é >> |
| | | |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_TaskInfoService |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using MapsterMapper; |
| | | using Microsoft.IdentityModel.Tokens; |
| | | using SqlSugar; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using WIDESEA_Core; |
| | |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO; |
| | | using WIDESEAWCS_DTO.Stock; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | |
| | | namespace WIDESEAWCS_TaskInfoService |
| | | namespace WIDESEAWCS_TaskInfoService; |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡æå¡ - æ ¸å¿ä¸å¡é»è¾ |
| | | /// </summary> |
| | | public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | { |
| | | public class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | private readonly IRouterService _routerService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository; |
| | | private readonly IMapper _mapper; |
| | | private readonly IOutboundTaskFlowService _outboundTaskFlowService; |
| | | private readonly IInboundTaskFlowService _inboundTaskFlowService; |
| | | private readonly IRelocationTaskFlowService _relocationTaskFlowService; |
| | | private readonly IRobotTaskFlowService _robotTaskFlowService; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | | private readonly IRouterService _routerService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository; |
| | | private readonly IMapper _mapper; |
| | | private readonly IOutboundTaskFlowService _outboundTaskFlowService; |
| | | private readonly IInboundTaskFlowService _inboundTaskFlowService; |
| | | private readonly IRelocationTaskFlowService _relocationTaskFlowService; |
| | | private readonly IRobotTaskFlowService _robotTaskFlowService; |
| | | {nameof(Dt_Task.Grade),OrderByType.Desc }, |
| | | {nameof(Dt_Task.CreateDate),OrderByType.Asc}, |
| | | }; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | | {nameof(Dt_Task.Grade),OrderByType.Desc }, |
| | | {nameof(Dt_Task.CreateDate),OrderByType.Asc}, |
| | | }; |
| | | public Dictionary<string, OrderByType> TaskOrderBy |
| | | { get { return _taskOrderBy; } set { _taskOrderBy = value; } } |
| | | |
| | | public Dictionary<string, OrderByType> TaskOrderBy |
| | | { get { return _taskOrderBy; } set { _taskOrderBy = value; } } |
| | | public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskRelocationTypes => typeof(TaskRelocationTypeEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskRelocationTypes => typeof(TaskRelocationTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskRobotTypes => typeof(TaskOtherTypeEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskRobotTypes => typeof(TaskOtherTypeEnum).GetEnumIndexList(); |
| | | |
| | | public TaskService( |
| | | ITaskRepository BaseDal, |
| | | IRouterService routerService, |
| | | ITaskExecuteDetailService taskExecuteDetailService, |
| | | ITaskExecuteDetailRepository taskExecuteDetailRepository, |
| | | IMapper mapper, |
| | | IOutboundTaskFlowService outboundTaskFlowService, |
| | | IInboundTaskFlowService inboundTaskFlowService, |
| | | IRelocationTaskFlowService relocationTaskFlowService, |
| | | IRobotTaskFlowService robotTaskFlowService) : base(BaseDal) |
| | | { |
| | | _routerService = routerService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskExecuteDetailRepository = taskExecuteDetailRepository; |
| | | _mapper = mapper; |
| | | _outboundTaskFlowService = outboundTaskFlowService; |
| | | _inboundTaskFlowService = inboundTaskFlowService; |
| | | _relocationTaskFlowService = relocationTaskFlowService; |
| | | _robotTaskFlowService = robotTaskFlowService; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥æ¶WMSä»»å¡ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="taskDTOs">WMSä»»å¡å¯¹è±¡éå</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTaskDTO> taskDTOs) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | List<Dt_Task> duplicates = new List<Dt_Task>(); |
| | | foreach (var item in taskDTOs) |
| | | { |
| | | Dt_Task existingTask = BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode); |
| | | if (existingTask != null) |
| | | { |
| | | duplicates.Add(existingTask); |
| | | continue; |
| | | } |
| | | Dt_Task task = _mapper.Map<Dt_Task>(item); |
| | | task.Creater = "WMS"; |
| | | content = InitializeTaskOnReceive(task, item); |
| | | if (!content.Status) |
| | | return content; |
| | | tasks.Add(task); |
| | | } |
| | | // TOOD: è¿éæ³¨ææ·»å é误è¦è¿åé误 |
| | | BaseDal.AddData(tasks); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "æ¥æ¶WMSä»»å¡"); |
| | | |
| | | // å°éå¤ä»»å¡ä¿¡æ¯ä¹ä¸å¹¶è¿å |
| | | tasks.AddRange(duplicates); |
| | | var result = tasks; |
| | | content = WebResponseContent.Instance.OK("æå", result); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"任塿¥æ¶é误,é误信æ¯:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®æçå·ãèµ·å§å°ååWMS请æ±ä»»å¡ |
| | | /// </summary> |
| | | /// <param name="palletCode">æçå·</param> |
| | | /// <param name="sourceAddress">èµ·å§å°å</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | WMSTaskDTO taskDTO = new WMSTaskDTO() |
| | | { |
| | | TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")), |
| | | Grade = 1, |
| | | PalletCode = palletCode, |
| | | Roadway = "SC01", |
| | | SourceAddress = sourceAddress, |
| | | TargetAddress = "SC01", |
| | | TaskStatus = (int)TaskInStatusEnum.InNew, |
| | | Id = 0, |
| | | TaskType = (int)TaskInboundTypeEnum.Inbound |
| | | }; |
| | | |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æä»»å¡åç»åå§å任塿¥æ¶ä¿¡æ¯ã |
| | | /// </summary> |
| | | /// <param name="task">ä»»å¡å®ä½ã</param> |
| | | /// <param name="source">WMSåå§ä»»å¡å¯¹è±¡ã</param> |
| | | private WebResponseContent InitializeTaskOnReceive(Dt_Task task, WMSTaskDTO source) |
| | | { |
| | | switch (task.TaskType.GetTaskTypeGroup()) |
| | | { |
| | | case TaskTypeGroup.OutbondGroup: |
| | | return _outboundTaskFlowService.InitializeOnReceive(task, source); |
| | | case TaskTypeGroup.InboundGroup: |
| | | return _inboundTaskFlowService.InitializeOnReceive(task, source); |
| | | case TaskTypeGroup.RelocationGroup: |
| | | return _relocationTaskFlowService.InitializeOnReceive(task, source); |
| | | case TaskTypeGroup.OtherGroup: |
| | | return _robotTaskFlowService.InitializeOnReceive(task, source); |
| | | default: |
| | | return WebResponseContent.Instance.Error("WCSä¸åå¨å½åä»»å¡çä»»å¡ç±»å"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·ãå½åå°åæ¥è¯¢è¾éçº¿æªæ§è¡çä»»å¡ |
| | | /// </summary> |
| | | /// <param name="deviceNo">设å¤ç¼å·</param> |
| | | /// <param name="currentAddress">å½åå°å</param> |
| | | /// <returns></returns> |
| | | public Dt_Task QueryConveyorLineTask(string deviceNo, string currentAddress) |
| | | { |
| | | return BaseDal.QueryFirst(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskOutStatusEnum.SC_OutFinish) && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®ä»»å¡å·ãä¸ä¸å°åæ¥è¯¢è¾é线æ§è¡ä¸çä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <param name="nextAddress">ä¸ä¸å°å</param> |
| | | /// <returns></returns> |
| | | public Dt_Task QueryExecutingConveyorLineTask(int taskNum, string nextAddress) |
| | | { |
| | | if (string.IsNullOrEmpty(nextAddress)) |
| | | throw new ArgumentNullException(nameof(nextAddress), "ä¸ä¸å°åä¸è½ä¸ºç©º"); |
| | | |
| | | return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.NextAddress == nextAddress && (x.TaskStatus == (int)TaskInStatusEnum.Line_InExecuting || x.TaskStatus == (int)TaskOutStatusEnum.Line_OutExecuting), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®ä»»å¡å·ãå½åå°åæ¥è¯¢è¾éçº¿å®æçä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <param name="currentAddress">å½åå°å</param> |
| | | /// <returns></returns> |
| | | public Dt_Task QueryCompletedConveyorLineTask(int taskNum, string currentAddress) |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | throw new ArgumentNullException(nameof(currentAddress), "å½åå°åä¸è½ä¸ºç©º"); |
| | | |
| | | return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress && (x.TaskStatus == (int)TaskInStatusEnum.Line_InFinish || x.TaskStatus == (int)TaskOutStatusEnum.Line_OutFinish), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·ãä»»å¡ç±»ååç»(å¯é)æç
§ä¼å
级以åå建æ¶é´æåºæ¥è¯¢ä»»å¡æ± æ°å¢çä»»å¡ |
| | | /// </summary> |
| | | /// <param name="deviceNo">设å¤ç¼å·</param> |
| | | /// <param name="taskTypeGroup">ä»»å¡ç±»ååç»(å¯é)</param> |
| | | /// <returns></returns> |
| | | public Dt_Task? QuertStackerCraneTask(string deviceNo, TaskTypeGroup? taskTypeGroup = null) |
| | | { |
| | | if (taskTypeGroup == null) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskInboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); |
| | | if (taskTypeGroup.Value == TaskTypeGroup.InboundGroup) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskInStatusEnum.Line_InFinish, TaskOrderBy); |
| | | if (taskTypeGroup.Value == TaskTypeGroup.OutbondGroup) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskOutStatusEnum.OutNew, TaskOrderBy); |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·ãå½åå°åæç
§ä¼å
级以åå建æ¶é´æåºæ¥è¯¢ä»»å¡æ± æ°å¢çä»»å¡ |
| | | /// </summary> |
| | | /// <param name="deviceNo">设å¤ç¼å·</param> |
| | | /// <param name="currentAddress">å½åå°å</param> |
| | | /// <returns>è¿åä»»å¡å®ä½å¯¹è±¡ï¼å¯è½ä¸ºnull</returns> |
| | | public Dt_Task QueryStackerCraneTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskInboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskOutStatusEnum.OutNew || TaskRelocationTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskRelocationStatusEnum.RelocationNew), TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && (TaskInboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskOutStatusEnum.OutNew || TaskRelocationTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskRelocationStatusEnum.RelocationNew), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·ãå½åå°åæç
§ä¼å
级以åå建æ¶é´æåºæ¥è¯¢ä»»å¡æ± å
¥åºç±»åçæ°å¢çä»»å¡ |
| | | /// </summary> |
| | | /// <param name="deviceNo">设å¤ç¼å·</param> |
| | | /// <param name="currentAddress">å½åå°å</param> |
| | | /// <returns>è¿åä»»å¡å®ä½å¯¹è±¡ï¼å¯è½ä¸ºnull</returns> |
| | | public Dt_Task QueryStackerCraneInTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskInStatusEnum.Line_InFinish, TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskInStatusEnum.Line_InFinish && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·ãå½åå°åæç
§ä¼å
级以åå建æ¶é´æåºæ¥è¯¢ä»»å¡æ± åºåºç±»åçæ°å¢çä»»å¡ |
| | | /// </summary> |
| | | /// <param name="deviceNo">设å¤ç¼å·</param> |
| | | /// <param name="currentAddress">å½åå°å</param> |
| | | /// <returns>è¿åä»»å¡å®ä½å¯¹è±¡ï¼å¯è½ä¸ºnull</returns> |
| | | public Dt_Task QueryStackerCraneOutTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskOutStatusEnum.OutNew, TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskOutStatusEnum.OutNew && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·ãå½åå°åæç
§ä¼å
级以åå建æ¶é´æåºæ¥è¯¢ä»»å¡æ± åºåºç±»åçæ°å¢çä»»å¡ |
| | | /// </summary> |
| | | /// <param name="deviceNo">设å¤ç¼å·</param> |
| | | /// <param name="currentAddress">å½åå°å</param> |
| | | /// <returns>è¿åä»»å¡å®ä½å¯¹è±¡éåï¼å¯è½ä¸ºnull</returns> |
| | | public List<Dt_Task> QueryStackerCraneOutTasks(string deviceNo, List<string> outStationCodes) |
| | | { |
| | | return BaseDal.QueryData(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskOutStatusEnum.OutNew && outStationCodes.Contains(x.CurrentAddress), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡å¼å¸¸ä¿¡æ¯æ¾ç¤º |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <param name="message">å¼å¸¸ä¿¡æ¯</param> |
| | | public WebResponseContent UpdateTaskExceptionMessage(int taskNum, string message) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(message)) |
| | | throw new ArgumentNullException(nameof(message), "å¼å¸¸ä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | task.TaskStatus = (int)TaskOutStatusEnum.OutPending; |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | task.TaskStatus = (int)TaskInStatusEnum.InPending; |
| | | } |
| | | task.ExceptionMessage = message; |
| | | task.ModifyDate = DateTime.Now; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, task.ExceptionMessage); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡ç¶æä¿¡æ¯ï¼å¹¶åæ¥è³WMS |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <param name="status">ä»»å¡ç¶æ</param> |
| | | public void UpdateTaskStatus(int taskNum, int status) |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return; |
| | | task.TaskStatus = status; |
| | | task.ModifyDate = DateTime.Now; |
| | | BaseDal.UpdateData(task); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°ä»»å¡ç¶æä¿®æ¹ä¸ºä¸ä¸ä¸ªç¶æ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | public WebResponseContent UpdateTaskStatusToNext(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | return UpdateTaskStatusToNext(task); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°ä»»å¡ç¶æä¿®æ¹ä¸ºä¸ä¸ä¸ªç¶æ |
| | | /// </summary> |
| | | /// <param name="task">ä»»å¡å®ä½å¯¹è±¡</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent UpdateTaskStatusToNext([NotNull] Dt_Task task) |
| | | { |
| | | int oldState = task.TaskStatus; |
| | | |
| | | var result = task.TaskType.GetTaskTypeGroup() switch |
| | | { |
| | | TaskTypeGroup.OutbondGroup => _outboundTaskFlowService.MoveToNextStatus(task), |
| | | TaskTypeGroup.InboundGroup => _inboundTaskFlowService.MoveToNextStatus(task), |
| | | TaskTypeGroup.RelocationGroup => _relocationTaskFlowService.MoveToNextStatus(task), |
| | | TaskTypeGroup.OtherGroup => _robotTaskFlowService.MoveToNextStatus(task), |
| | | _ => WebResponseContent.Instance.Error($"ä»»å¡ç±»åé误,æªæ¾å°è¯¥ä»»å¡ç±»å,ä»»å¡å·:ã{task.TaskNum}ã,ä»»å¡ç±»å:ã{task.TaskType}ã") |
| | | }; |
| | | |
| | | if (!result.Status) |
| | | return result; |
| | | |
| | | // åºåºå®æçº¿ä½èç¹æ¶ï¼å¯è½éè¦æ¥æ¶å
¥åºæ°ä»»å¡ã |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup |
| | | && result.Data is List<WMSTaskDTO> wmsTasks |
| | | && wmsTasks.Count > 0) |
| | | { |
| | | WebResponseContent content = ReceiveWMSTask(wmsTasks); |
| | | if (!content.Status) |
| | | return content; |
| | | } |
| | | |
| | | // æ´æ°ä»»å¡æ°æ® |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | if (task.TaskStatus == (int)TaskOutStatusEnum.Line_OutFinish) |
| | | { |
| | | BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.èªå¨å®æ); |
| | | } |
| | | else |
| | | { |
| | | BaseDal.UpdateData(task); |
| | | } |
| | | |
| | | // è®°å½ä»»å¡æ§è¡è¯¦æ
|
| | | string logMessage = App.User.UserId > 0 |
| | | ? $"人工æå¨å°ä»»å¡ç¶æä»ã{oldState}ã跳转å°ã{task.TaskStatus}ã" |
| | | : $"ç³»ç»èªå¨æµç¨ï¼ä»»å¡ç¶æä»ã{oldState}ã转å°ã{task.TaskStatus}ã"; |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, logMessage); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®ä»»å¡å·ãå½åå°åæ´æ°ä»»å¡ä½ç½®ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <param name="currentAddress">å½åå°å</param> |
| | | /// <returns></returns> |
| | | public Dt_Task? UpdatePosition(int taskNum, string currentAddress) |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | throw new ArgumentNullException(nameof(currentAddress), "å½åå°åä¸è½ä¸ºç©º"); |
| | | |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress); |
| | | if (task == null) throw new Exception($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | |
| | | string oldCurrentPos = task.CurrentAddress; |
| | | string oldNextPos = task.NextAddress; |
| | | |
| | | |
| | | Dt_Router routers = _routerService.QueryNextRoute(oldNextPos, task.TargetAddress); |
| | | if (routers == null) throw new Exception($"æªæ¾å°è®¾å¤è·¯ç±ä¿¡æ¯"); |
| | | |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = routers.ChildPosi; |
| | | |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"ç³»ç»èªå¨æµç¨ï¼æ´æ°å½åä½ç½®ã{oldCurrentPos} ----> {task.CurrentAddress}ãåä¸ä¸ä½ç½®ã{oldNextPos} ----> {task.NextAddress}ã"); |
| | | return task; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine($"UpdatePosition æ´æ°ä»»å¡ä½ç½®å¤±è´¥,ä»»å¡å·:ã{taskNum}ã,é误信æ¯:ã{ex.Message}ã"); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡å®æ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡ç¼å·</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent StackCraneTaskCompleted(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | TaskTypeGroup taskTypeGroup = task.TaskType.GetTaskTypeGroup(); |
| | | content = taskTypeGroup switch |
| | | { |
| | | TaskTypeGroup.OutbondGroup => _outboundTaskFlowService.CompleteStackerTask(task), |
| | | TaskTypeGroup.InboundGroup => _inboundTaskFlowService.CompleteStackerTask(task), |
| | | TaskTypeGroup.RelocationGroup => _relocationTaskFlowService.CompleteStackerTask(task), |
| | | TaskTypeGroup.OtherGroup => _robotTaskFlowService.CompleteStackerTask(task), |
| | | _ => throw new Exception($"ä»»å¡ç±»åé误,æªæ¾å°è¯¥ä»»å¡ç±»å,ä»»å¡å·:ã{taskNum}ã,ä»»å¡ç±»å:ã{task.TaskType}ã") |
| | | }; |
| | | if (!content.Status) |
| | | { |
| | | return content; |
| | | } |
| | | |
| | | if (taskTypeGroup == TaskTypeGroup.OutbondGroup && task.TaskStatus == (int)TaskOutStatusEnum.SC_OutFinish) |
| | | { |
| | | BaseDal.UpdateData(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, "å åæºåºåºå®æ"); |
| | | return content; |
| | | } |
| | | |
| | | if (taskTypeGroup == TaskTypeGroup.InboundGroup && task.TaskStatus == (int)TaskInStatusEnum.SC_InFinish) |
| | | { |
| | | BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.èªå¨å®æ); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, "å åæºå
¥åºå®æ"); |
| | | return content; |
| | | } |
| | | |
| | | if (taskTypeGroup == TaskTypeGroup.RelocationGroup && task.TaskStatus == (int)TaskRelocationStatusEnum.RelocationFinish) |
| | | { |
| | | BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.èªå¨å®æ); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, "å åæºç§»åºå®æ"); |
| | | return content; |
| | | } |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"ä»»å¡å®æå¼å¸¸,ä»»å¡å·:ã{taskNum}ã"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¢å¤æèµ·ä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent TaskStatusRecovery(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | if (task.TaskStatus != (int)TaskInStatusEnum.InPending && task.TaskStatus != (int)TaskOutStatusEnum.OutPending) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任å¡ç¶æä¸å¯æ¢å¤,ä»»å¡å·:ã{taskNum}ã,ä»»å¡ç¶æ:ã{task.TaskStatus}ã"); |
| | | } |
| | | |
| | | Dt_TaskExecuteDetail taskExecuteDetail = _taskExecuteDetailRepository.QueryFirst(x => x.TaskId == task.TaskId && x.IsNormal, new Dictionary<string, OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), OrderByType.Desc } }); |
| | | if (taskExecuteDetail != null) |
| | | { |
| | | task.TaskStatus = taskExecuteDetail.TaskState; |
| | | } |
| | | else |
| | | { |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | task.TaskStatus = (int)TaskOutStatusEnum.OutNew; |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | task.TaskStatus = (int)TaskInStatusEnum.InNew; |
| | | } |
| | | //todo |
| | | } |
| | | |
| | | task.ExceptionMessage = string.Empty; |
| | | |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"人工æ¢å¤æèµ·ä»»å¡,æ¢å¤æèµ·æ¶ä»»å¡ç¶æã{task.TaskStatus}ã"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 忻任å¡ç¶æ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent RollbackTaskStatusToLast(int taskNum) |
| | | { |
| | | WebResponseContent content = new(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | |
| | | int oldState = task.TaskStatus; |
| | | Dt_TaskExecuteDetail taskExecuteDetail = _taskExecuteDetailRepository.QueryFirst(x => x.TaskId == task.TaskId && x.TaskState < task.TaskStatus && x.TaskState > 0, new Dictionary<string, OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), OrderByType.Desc } }); |
| | | if (taskExecuteDetail != null) |
| | | { |
| | | task.TaskStatus = taskExecuteDetail.TaskState; |
| | | task.CurrentAddress = taskExecuteDetail.CurrentAddress; |
| | | task.NextAddress = taskExecuteDetail.NextAddress; |
| | | } |
| | | else |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"æªæ¾å°ä»»å¡æç»ä¿¡æ¯,该任å¡ç¶æä¸å¯åæ»å°ä¸ä¸æ¥,ä»»å¡å·:ã{taskNum}ã,ä»»å¡ç¶æ:ã{task.TaskStatus}ã"); |
| | | } |
| | | |
| | | task.ExceptionMessage = string.Empty; |
| | | |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"人工å°ä»»å¡ç¶æä»ã{oldState}ãåæ»å°ã{task.TaskStatus}ã"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public override WebResponseContent DeleteData(object[] keys) |
| | | { |
| | | List<int> taskKeys = new List<int>(); |
| | | for (int i = 0; i < keys.Length; i++) |
| | | { |
| | | taskKeys.Add(Convert.ToInt32(keys[i])); |
| | | } |
| | | List<Dt_Task> tasks = BaseDal.QueryData(x => taskKeys.Contains(x.TaskId)); |
| | | BaseDal.DeleteAndMoveIntoHty(tasks, OperateTypeEnum.人工å é¤); |
| | | return WebResponseContent.Instance.OK($"æåå é¤{tasks.Count}æ¡æ°æ®"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·ãå½åå°åæç
§ä¼å
级以åå建æ¶é´æåºæ¥è¯¢ä»»å¡æ± æ°å¢çä»»å¡ |
| | | /// </summary> |
| | | /// <param name="deviceNo">设å¤ç¼å·</param> |
| | | /// <param name="currentAddress">å½åå°å</param> |
| | | /// <returns>è¿åä»»å¡å®ä½å¯¹è±¡ï¼å¯è½ä¸ºnull</returns> |
| | | public Dt_Task QueryRobotCraneTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskRobotTypes.Contains(x.TaskType) && x.TaskStatus <= (int)TaskRobotStatusEnum.RobotExecuting), TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskRobotTypes.Contains(x.TaskType) && x.CurrentAddress == currentAddress && x.TaskStatus <= (int)TaskRobotStatusEnum.RobotExecuting, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·å䏿å®ä»»å¡ç¼å·å
³èçä»»å¡ã |
| | | /// </summary> |
| | | /// <param name="taskNum">è¦è·åçä»»å¡çå¯ä¸æ è¯ç¬¦ã</param> |
| | | /// <returns>表示æå®ç¼å·ä»»å¡ç<see cref="Dt_Task"/>对象ï¼å¦æä¸åå¨è¯¥ä»»å¡åè¿å<c>null</c>ã</returns> |
| | | public Dt_Task QueryByTaskNum(int taskNum) |
| | | { |
| | | return BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥æ¶WMSæå¨å建çä»»å¡ï¼å建WCSä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskDTOs">WMSä»»å¡å¯¹è±¡éå</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent ReceiveManualTask([NotNull] List<WMSTaskDTO> taskDTOs) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | // æ¶ééå¤ä»»å¡çä¿¡æ¯ |
| | | var duplicateTasks = new List<DuplicateTaskDto>(); |
| | | // ååºéåï¼å®å
¨å é¤å¹¶æ¶é被移é¤ç项 |
| | | for (int i = taskDTOs.Count - 1; i >= 0; i--) |
| | | { |
| | | var item = taskDTOs[i]; |
| | | var exists = BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode); |
| | | if (exists != null) |
| | | { |
| | | duplicateTasks.Add(new DuplicateTaskDto |
| | | { |
| | | TaskNum = exists.TaskNum, |
| | | PalletCode = exists.PalletCode, |
| | | TaskType = exists.TaskType, |
| | | TaskStatus = exists.TaskStatus |
| | | }); |
| | | taskDTOs.RemoveAt(i); |
| | | } |
| | | } |
| | | |
| | | // è°ç¨ ReceiveWMSTask å建 WCS ä»»å¡ |
| | | content = ReceiveWMSTask(taskDTOs); |
| | | |
| | | // 妿æéå¤ä»»å¡ï¼ä¿®æ¹è¿åç»æ |
| | | if (duplicateTasks.Count > 0 && content.Status) |
| | | { |
| | | var result = new ReceiveTaskResultDto |
| | | { |
| | | Success = true, |
| | | Message = content.Message + $"ï¼å
¶ä¸{duplicateTasks.Count}个任å¡å¨WCSä¸å·²åå¨", |
| | | CreatedCount = taskDTOs.Count, |
| | | DuplicateTasks = duplicateTasks |
| | | }; |
| | | content.Data = result; |
| | | } |
| | | |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"æå¨ä»»å¡æ¥æ¶é误,é误信æ¯:{ex.Message}"); |
| | | return content; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢æå®èµ·ç¹å°åçæ°å»ºæå¨å
¥åºä»»å¡ |
| | | /// </summary> |
| | | /// <param name="sourceAddress">èµ·ç¹å°å</param> |
| | | /// <returns>ä»»å¡å®ä½</returns> |
| | | public Dt_Task QueryManualInboundTask(string sourceAddress) |
| | | { |
| | | return BaseDal.QueryFirst(x => |
| | | x.TaskType == (int)TaskInboundTypeEnum.Inbound && |
| | | x.TaskStatus == (int)TaskInStatusEnum.InNew && |
| | | x.SourceAddress == sourceAddress); |
| | | } |
| | | } |
| | | |
| | | public enum ConveyorLineDBNameNew |
| | | public TaskService( |
| | | ITaskRepository BaseDal, |
| | | IRouterService routerService, |
| | | ITaskExecuteDetailService taskExecuteDetailService, |
| | | ITaskExecuteDetailRepository taskExecuteDetailRepository, |
| | | IMapper mapper, |
| | | IOutboundTaskFlowService outboundTaskFlowService, |
| | | IInboundTaskFlowService inboundTaskFlowService, |
| | | IRelocationTaskFlowService relocationTaskFlowService, |
| | | IRobotTaskFlowService robotTaskFlowService) : base(BaseDal) |
| | | { |
| | | Barcode |
| | | } |
| | | public class ConveyorLineTaskCommandNew : DeviceCommand |
| | | { |
| | | /// <summary> |
| | | /// ä»»å¡å· |
| | | /// </summary> |
| | | public short TaskNo { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æºä½ç½® å¼å§å°å |
| | | /// </summary> |
| | | public short Source { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ç®æ ä½ç½® |
| | | /// </summary> |
| | | public short Target { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ç®±å |
| | | /// </summary> |
| | | public byte BoxType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// è¾éçº¿ç¶æ 设å¤ç©ºé²ç¶æ |
| | | /// </summary> |
| | | public byte CV_State { get; set; } |
| | | |
| | | /// <summary> |
| | | /// è¾é线é误代ç |
| | | /// </summary> |
| | | public byte CV_ERRCode { get; set; } |
| | | |
| | | /// <summary> |
| | | /// WCS就绪æ å¿ WCSä¸å宿æ¶ï¼è§¦å为1 |
| | | /// </summary> |
| | | public byte WCS_STB { get; set; } |
| | | |
| | | /// <summary> |
| | | /// WCSåºçæ å¿ WCSæ¶å°å®ææ¶ï¼è§¦å为1 |
| | | /// </summary> |
| | | public byte WCS_ACK { get; set; } |
| | | |
| | | /// <summary> |
| | | /// PLC就绪æ å¿ å®æä»»å¡æ¶ï¼è§¦å为1 |
| | | /// </summary> |
| | | public byte PLC_STB { get; set; } |
| | | |
| | | /// <summary> |
| | | /// PLCåºçæ å¿ æ¶å°ä»»å¡æ¶ï¼è§¦å为1 |
| | | /// </summary> |
| | | public byte PLC_ACK { get; set; } |
| | | |
| | | /// <summary> |
| | | /// PLCè¯·æ±æ å¿ å
¥åºç«å°ï¼å°ä½å1 |
| | | /// </summary> |
| | | public byte PLC_REQ { get; set; } |
| | | |
| | | /// <summary> |
| | | /// WCSé误代ç |
| | | /// </summary> |
| | | public byte WCS_ERRCode { get; set; } |
| | | |
| | | /// <summary> |
| | | /// WCSç¹æ®æ å¿ (æè½¬æ è¯ãå¼ºå¶æ¾è¡ã循ç¯ãç¹æ®ç³è¯·ãæ¯å¦å çãæ¯å¦å µå¡) |
| | | /// </summary> |
| | | public byte WCS_Special { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤èªå¨æ¨¡å¼ æå¨1ï¼èªå¨2 |
| | | /// </summary> |
| | | public byte Equ_Auto { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å°¾æ¿æ å¿ |
| | | /// </summary> |
| | | public byte Last_pallet { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ¡ç ï¼22个åç¬¦ï¼ |
| | | /// </summary> |
| | | [DataLength(22)] |
| | | public string Barcode { get; set; } |
| | | _routerService = routerService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskExecuteDetailRepository = taskExecuteDetailRepository; |
| | | _mapper = mapper; |
| | | _outboundTaskFlowService = outboundTaskFlowService; |
| | | _inboundTaskFlowService = inboundTaskFlowService; |
| | | _relocationTaskFlowService = relocationTaskFlowService; |
| | | _robotTaskFlowService = robotTaskFlowService; |
| | | } |
| | | } |