| | |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.BasicInfo; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; |
| | | |
| | | namespace WIDESEAWCS_TaskInfoService |
| | | { |
| | | public class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | { |
| | | private readonly IMapper _mapper; |
| | | private readonly ICacheService _cacheService; |
| | | private readonly IRouterService _routerService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository; |
| | | private readonly IMapper _mapper; |
| | | private readonly IStationMangerRepository _stationMangerRepository; |
| | | private readonly IRouterRepository _routerRepository; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | |
| | | {nameof(Dt_Task.CreateDate),OrderByType.Asc}, |
| | | }; |
| | | |
| | | private List<Dt_Warehouse>? Warehouses = new List<Dt_Warehouse>(); |
| | | |
| | | public Dictionary<string, OrderByType> TaskOrderBy { get { return _taskOrderBy; } set { _taskOrderBy = value; } } |
| | | |
| | | public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskInboundTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 100 && x < 500).ToList(); |
| | | |
| | | public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 500 && x < 900).ToList(); |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper) : base(BaseDal) |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _cacheService = cacheService; |
| | | _routerService = routerService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskExecuteDetailRepository = taskExecuteDetailRepository; |
| | | _mapper = mapper; |
| | | _stationMangerRepository = stationMangerRepository; |
| | | _routerRepository = routerRepository; |
| | | |
| | | string? cacheStr = _cacheService.Get(nameof(Dt_Warehouse)); |
| | | if (!string.IsNullOrEmpty(cacheStr)) |
| | | { |
| | | Warehouses = JsonConvert.DeserializeObject<List<Dt_Warehouse>>(cacheStr); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | List<Dt_WarehouseDevice> warehouseDevices = Db.Queryable<Dt_WarehouseDevice>().ToList(); |
| | | |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | foreach (var item in taskDTOs) |
| | | { |
| | |
| | | } |
| | | Dt_Task task = _mapper.Map<Dt_Task>(item); |
| | | task.Creater = "WMS"; |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.OutNew; |
| | | task.CurrentAddress = item.SourceAddress; |
| | | task.NextAddress = item.TargetAddress; |
| | | task.TaskState = (int)TaskStatusEnum.New; |
| | | task.CurrentAddress = item.SourceAddress; |
| | | |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | List<Dt_WarehouseDevice> wades = warehouseDevices.Where(x => x.WarehouseId == item.WarehouseId).ToList(); |
| | | |
| | | Dt_Router? router = new Dt_Router(); |
| | | |
| | | if (string.IsNullOrEmpty(item.AGVArea)) |
| | | { |
| | | task.TaskState = (int)TaskInStatusEnum.InNew; task.CurrentAddress = item.SourceAddress; |
| | | task.NextAddress = item.TargetAddress; |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == item.SourceAddress || x.StackerCraneCode == item.RoadWay); |
| | | if (stationManger == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°ç«å°é
置信æ¯"); |
| | | } |
| | | |
| | | List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == item.TaskType && (stationManger.StationDeviceCode == x.StartPosi || stationManger.StackerCraneCode == x.StartPosi)); |
| | | if (routers.FirstOrDefault() == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è·¯ç±é
置信æ¯"); |
| | | } |
| | | router = routers.FirstOrDefault(); |
| | | if (routers.Count == 1) |
| | | { |
| | | task.NextAddress = router?.NextPosi ?? ""; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == item.TaskType && item.AGVArea == x.StartPosi); |
| | | if (routers.FirstOrDefault() == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è·¯ç±é
置信æ¯"); |
| | | } |
| | | router = routers.FirstOrDefault(); |
| | | |
| | | task.NextAddress = router?.NextPosi ?? ""; |
| | | } |
| | | |
| | | tasks.Add(task); |
| | | } |
| | | BaseDal.AddData(tasks); |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | WMSTaskDTO taskDTO = new WMSTaskDTO() |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationDeviceCode == sourceAddress); |
| | | if (stationManger == null) |
| | | { |
| | | 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 |
| | | }; |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°ç«å°ä¿¡æ¯"); |
| | | } |
| | | |
| | | HttpHelper.Post($"RequestInboundTask?palletCode={palletCode}&stationCode={sourceAddress}"); |
| | | |
| | | WMSTaskDTO taskDTO = new WMSTaskDTO(); |
| | | |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åWMSç³è¯·åé
è´§ä½ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <param name="roadwayNo">å··éå·</param> |
| | | /// <returns></returns> |
| | | public string? RequestAssignLocation(int taskNum, string roadwayNo) |
| | | { |
| | | string responseStr = HttpHelper.Get($"http://127.0.0.1:9293/api/Task/AssignInboundTaskLocation?taskNum={taskNum}&roadwayNo={roadwayNo}"); |
| | |
| | | public Dt_Task? QuertStackerCraneTask(string deviceNo, TaskTypeGroup? taskTypeGroup = null) |
| | | { |
| | | if (taskTypeGroup == null) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.SC_InExecute || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && x.TaskState == (int)TaskStatusEnum.New, TaskOrderBy); |
| | | if (taskTypeGroup.Value == TaskTypeGroup.InboundGroup) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.SC_InExecute, TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.SC_Execute, TaskOrderBy); |
| | | if (taskTypeGroup.Value == TaskTypeGroup.OutbondGroup) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutExecute, TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.SC_Execute, TaskOrderBy); |
| | | return null; |
| | | } |
| | | |
| | |
| | | public Dt_Task QueryStackerCraneTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.SC_InExecute || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && x.TaskState == (int)TaskStatusEnum.New, TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.SC_InExecute || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutExecute), TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && x.CurrentAddress == currentAddress && x.TaskState == (int)TaskStatusEnum.SC_Execute, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public Dt_Task QueryStackerCraneInTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.SC_InExecute, TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.SC_Execute, TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.SC_InExecute && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.SC_Execute && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public Dt_Task QueryStackerCraneOutTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutExecute, TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.SC_Execute, TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutExecute && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.SC_Execute && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <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.TaskState == (int)TaskOutStatusEnum.SC_OutExecute && outStationCodes.Contains(x.CurrentAddress), TaskOrderBy); |
| | | return BaseDal.QueryData(x => x.DeviceCode == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.SC_Execute && 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(); |
| | |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯,ä»»å¡å·:ã{taskNum}ã"); |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.OutPending; |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | task.TaskState = (int)TaskInStatusEnum.InPending; |
| | | } |
| | | task.TaskState = (int)TaskStatusEnum.Pending; |
| | | task.ExceptionMessage = message; |
| | | task.ModifyDate = DateTime.Now; |
| | | BaseDal.UpdateData(task); |
| | |
| | | { |
| | | Dt_Task 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)TaskStatusEnum.Pending) |
| | | { |
| | | 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; |
| | | } |
| | | //todo |
| | | task.TaskState = (int)TaskStatusEnum.New; |
| | | } |
| | | |
| | | task.ExceptionMessage = string.Empty; |