| | |
| | | |
| | | using AutoMapper; |
| | | using HslCommunication; |
| | | using Mapster; |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_BasicInfoService; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_DTO.WMS; |
| | | using WIDESEAWCS_ISystemServices; |
| | | using WIDESEAWCS_ITaskInfo_HtyRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | |
| | | namespace WIDESEAWCS_TaskInfoService |
| | | { |
| | | public class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | { |
| | | private readonly IRouterService _routerService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository; |
| | | private readonly ISys_ConfigService _sys_ConfigService; |
| | | private readonly IMapper _mapper; |
| | | private readonly IDt_StationManagerService _stationManagerService; |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | private readonly IRouterRepository _routerRepository; |
| | | private readonly ITask_HtyRepository _taskHtyRepository; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | |
| | | |
| | | public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList(); |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ISys_ConfigService sys_ConfigService) : 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) : base(BaseDal) |
| | | { |
| | | _routerService = routerService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskExecuteDetailRepository = taskExecuteDetailRepository; |
| | | _mapper = mapper; |
| | | _sys_ConfigService = sys_ConfigService; |
| | | _stationManagerService = stationManagerService; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _routerRepository = routerRepository; |
| | | _taskHtyRepository = htyRepository; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | task.TaskState = (int)TaskOutStatusEnum.OutNew; |
| | | task.CurrentAddress = item.SourceAddress; |
| | | task.NextAddress = routers.FirstOrDefault().ChildPosi; |
| | | } |
| | | else |
| | | { |
| | | routers = _routerService.QueryNextRoutes(item.SourceAddress, item.TargetAddress); |
| | | if (routers.Count > 0) |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish; |
| | | task.CurrentAddress = item.SourceAddress; |
| | | task.NextAddress = routers.FirstOrDefault().ChildPosi; |
| | | } |
| | | } |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | |
| | | var hasTask = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode); |
| | | if (hasTask != null) |
| | | { |
| | | return content.Error("当前托盘存在任务"); |
| | | return content.OK("当前托盘存在任务"); |
| | | } |
| | | |
| | | var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); |
| | |
| | | { |
| | | 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); |
| | | } |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | |
| | | 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); |
| | | } |
| | | } |
| | | else |
| | |
| | | var task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】"); |
| | | |
| | | #region WMS同步任务完成 |
| | | var keys = new Dictionary<string, object>() |
| | | { |
| | | {"taskNum", taskNum} |
| | | }; |
| | | // 获取WMSip地址 |
| | | var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); |
| | | var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; |
| | | var completeTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.CompleteTask)?.ConfigValue; |
| | | if (wmsBase == null || completeTask == null) |
| | | { |
| | | throw new InvalidOperationException("WMS IP 未配置"); |
| | | } |
| | | var wmsIpAddress = wmsBase + completeTask; |
| | | |
| | | var result = HttpHelper.GetAsync(wmsIpAddress, keys).Result; |
| | | content = JsonConvert.DeserializeObject<WebResponseContent>(result); |
| | | if (!content.Data.IsNullOrEmpty()) |
| | | { |
| | | if (content.Data.ToString() == "NG") |
| | | { |
| | | task.Remark = "NG"; |
| | | //BaseDal.UpdateData(task); |
| | | //_taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成,MOM返回NG"); |
| | | } |
| | | } |
| | | task.ExceptionMessage += " " + content.Message; |
| | | #endregion |
| | | |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting) |
| | | { |
| | | var routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress); |
| | | if (!routers.Any()) return WebResponseContent.Instance.Error($"未找到设备路由信息"); |
| | | if (!task.Roadway.Contains("GW")) |
| | | { |
| | | var routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress); |
| | | if (!routers.Any()) return WebResponseContent.Instance.Error($"未找到设备路由信息"); |
| | | |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>(); |
| | | task.TaskState = nextStatus; |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = routers.FirstOrDefault().ChildPosi; |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.UpdateData(task); |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>(); |
| | | task.TaskState = nextStatus; |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = routers.FirstOrDefault().ChildPosi; |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成"); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成"); |
| | | } |
| | | else |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.OutFinish; |
| | | //如高温出库后 NG 则将任务标记为NG 并在出库申请后将任务出至NG口 |
| | | if (task.Remark == "NG") |
| | | { |
| | | BaseDal.UpdateData(task); |
| | | } |
| | | else |
| | | { |
| | | BaseDal.DeleteData(task); |
| | | ConsoleHelper.WriteWarningLine($"高温出库目的地址{task.TargetAddress}"); |
| | | } |
| | | |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | _taskHtyRepository.AddData(taskHty); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成"); |
| | | } |
| | | |
| | | |
| | | //暂不考虑多个出库口 |
| | |
| | | task.TaskState = nextStatus; |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | Dt_Task_Hty task_Hty = _mapper.Map<Dt_Task_Hty>(task); |
| | | task_Hty.TaskId = 0; |
| | | |
| | | BaseDal.DeleteData(task); |
| | | _taskHtyRepository.AddData(task_Hty); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机入库完成"); |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) |
| | |
| | | } |
| | | |
| | | |
| | | #region WMS同步任务完成 |
| | | var keys = new Dictionary<string, object>() |
| | | { |
| | | {"taskNum", taskNum} |
| | | }; |
| | | // 获取WMSip地址 |
| | | var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); |
| | | var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; |
| | | var completeTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.CompleteTask)?.ConfigValue; |
| | | if (wmsBase == null || completeTask == null) |
| | | { |
| | | throw new InvalidOperationException("WMS IP 未配置"); |
| | | } |
| | | var wmsIpAddress = wmsBase + completeTask; |
| | | |
| | | var result = HttpHelper.GetAsync(wmsIpAddress, keys).Result; |
| | | content = JsonConvert.DeserializeObject<WebResponseContent>(result); |
| | | #endregion |
| | | |
| | | |
| | | #region 更新任务状态 |
| | | |
| | | var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.CompleteTask)?.ConfigValue; |
| | | var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.UpdateTask)?.ConfigValue; |
| | | if (wmsBase == null || updateTask == null) |
| | | { |
| | | throw new InvalidOperationException("WMS IP 未配置"); |
| | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public Dt_Task QueryRelocationTask(string deviceNo) |
| | | { |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.TaskType == (int)TaskRelocationTypeEnum.Relocation && x.TaskState == (int)TaskStatus.Created); |
| | | } |
| | | } |
| | | } |