|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | using AutoMapper; | 
|---|
|  |  |  | 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_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; | 
|---|
|  |  |  | 
|---|
|  |  |  | private readonly IDt_StationManagerRepository _stationManagerRepository; | 
|---|
|  |  |  | private readonly IRouterRepository _routerRepository; | 
|---|
|  |  |  | private readonly ITask_HtyRepository _taskHtyRepository; | 
|---|
|  |  |  | private readonly IDt_needBarcodeRepository _taskNeedBarcodeRepository; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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, 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, IDt_needBarcodeRepository taskNeedBarcodeRepository) : base(BaseDal) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _routerService = routerService; | 
|---|
|  |  |  | _taskExecuteDetailService = taskExecuteDetailService; | 
|---|
|  |  |  | 
|---|
|  |  |  | _stationManagerRepository = stationManagerRepository; | 
|---|
|  |  |  | _routerRepository = routerRepository; | 
|---|
|  |  |  | _taskHtyRepository = htyRepository; | 
|---|
|  |  |  | _taskNeedBarcodeRepository = taskNeedBarcodeRepository; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <returns>返回处理结果</returns> | 
|---|
|  |  |  | public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTaskDTO> taskDTOs) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 创建一个WebResponseContent对象用于存储返回结果 | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 创建一个Dt_Task类型的列表用于存储转换后的任务数据 | 
|---|
|  |  |  | List<Dt_Task> tasks = new List<Dt_Task>(); | 
|---|
|  |  |  | // 遍历传入的WMSTaskDTO列表 | 
|---|
|  |  |  | foreach (var item in taskDTOs) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 查询数据库中是否存在相同任务编号或托盘码的任务,如果存在则跳过当前循环 | 
|---|
|  |  |  | if (BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode) != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 将WMSTaskDTO对象映射为Dt_Task对象 | 
|---|
|  |  |  | Dt_Task task = _mapper.Map<Dt_Task>(item); | 
|---|
|  |  |  | // 设置任务的创建者为"WMS" | 
|---|
|  |  |  | task.Creater = "WMS"; | 
|---|
|  |  |  | // 判断任务类型是否为出库任务 | 
|---|
|  |  |  | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<Dt_Router> routers = _routerService.QueryNextRoutes(item.RoadWay, item.TargetAddress); | 
|---|
|  |  |  | if (routers.Count > 0) | 
|---|
|  |  |  | // 判断任务目标地址和路径是否满足特定条件 | 
|---|
|  |  |  | if ((task.TargetAddress == "002-021-001" || task.TargetAddress == "001-021-001") && task.Roadway.Contains("JZ")) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 设置任务状态为出库新建 | 
|---|
|  |  |  | task.TaskState = (int)TaskOutStatusEnum.OutNew; | 
|---|
|  |  |  | // 设置当前地址为源地址 | 
|---|
|  |  |  | task.CurrentAddress = item.SourceAddress; | 
|---|
|  |  |  | task.NextAddress = routers.FirstOrDefault().ChildPosi; | 
|---|
|  |  |  | // 设置下一个地址为目标地址 | 
|---|
|  |  |  | task.NextAddress = item.TargetAddress; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | routers = _routerService.QueryNextRoutes(item.SourceAddress, item.TargetAddress); | 
|---|
|  |  |  | // 查询下一个路由 | 
|---|
|  |  |  | List<Dt_Router> routers = _routerService.QueryNextRoutes(item.RoadWay, item.TargetAddress); | 
|---|
|  |  |  | if (routers.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish; | 
|---|
|  |  |  | // 设置任务状态为出库新建 | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<Dt_Router> routers = _routerService.QueryNextRoutes(item.SourceAddress, item.TargetAddress); | 
|---|
|  |  |  | if (routers.Count > 0) | 
|---|
|  |  |  | var value = _sys_ConfigService.GetByConfigKey(CateGoryConst.CONFIG_SYS_InStation, SysConfigKeyConst.JZNGInBoundStation).ConfigValue; | 
|---|
|  |  |  | var valueList = value.Split(',').ToList(); | 
|---|
|  |  |  | // 判断源地址是否不等于"1359-4" | 
|---|
|  |  |  | //if (task.SourceAddress != "1359-4" && task.SourceAddress != "1357-4") | 
|---|
|  |  |  | if (!valueList.Contains(task.SourceAddress)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = (int)TaskInStatusEnum.InNew; | 
|---|
|  |  |  | task.CurrentAddress = item.SourceAddress; | 
|---|
|  |  |  | task.NextAddress = routers.FirstOrDefault().ChildPosi; | 
|---|
|  |  |  | // 查询从源地址到目标地址的路由 | 
|---|
|  |  |  | List<Dt_Router> routers = _routerService.QueryNextRoutes(item.SourceAddress, item.TargetAddress); | 
|---|
|  |  |  | if (routers.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 设置任务状态为入库新建 | 
|---|
|  |  |  | task.TaskState = (int)TaskInStatusEnum.InNew; | 
|---|
|  |  |  | // 设置当前地址为源地址 | 
|---|
|  |  |  | task.CurrentAddress = item.SourceAddress; | 
|---|
|  |  |  | // 设置下一个地址为第一个子位置 | 
|---|
|  |  |  | task.NextAddress = routers.FirstOrDefault().ChildPosi; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.CurrentAddress = string.Empty; | 
|---|
|  |  |  | if (task.SourceAddress == "1325-6") | 
|---|
|  |  |  | // 设置当前地址为"001-021-001" | 
|---|
|  |  |  | task.CurrentAddress = "001-021-001"; | 
|---|
|  |  |  | else | 
|---|
|  |  |  | // 设置当前地址为"002-021-001" | 
|---|
|  |  |  | task.CurrentAddress = "002-021-001"; | 
|---|
|  |  |  | // 设置下一个地址为目标地址 | 
|---|
|  |  |  | task.NextAddress = item.TargetAddress; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 将转换后的任务添加到任务列表中 | 
|---|
|  |  |  | tasks.Add(task); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 将任务列表添加到数据库中 | 
|---|
|  |  |  | BaseDal.AddData(tasks); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 添加任务执行详情 | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "接收WMS任务"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 设置返回结果为成功 | 
|---|
|  |  |  | content = WebResponseContent.Instance.OK("成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 捕获异常并设置返回结果为错误信息 | 
|---|
|  |  |  | content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 返回结果 | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | return content.OK("当前托盘存在任务"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); | 
|---|
|  |  |  | var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; | 
|---|
|  |  |  | var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue; | 
|---|
|  |  |  | if (wmsBase == null || requestTask == null) | 
|---|
|  |  |  | var wmsIpAddrss = string.Empty; | 
|---|
|  |  |  | var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == sourceAddress); | 
|---|
|  |  |  | if (stationManager.stationType == 5) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new InvalidOperationException("WMS IP 未配置"); | 
|---|
|  |  |  | wmsIpAddrss = GetIpAddress(SysConfigKeyConst.WMSIP_BASE, SysConfigKeyConst.RequestInBoundTaskNG); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var wmsIpAddrss = wmsBase + requestTask; | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | wmsIpAddrss = GetIpAddress(SysConfigKeyConst.WMSIP_BASE, SysConfigKeyConst.RequestTask); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var result = await HttpHelper.PostAsync(wmsIpAddrss, new { Position = sourceAddress, PalletCode = palletCode }.ToJsonString()); | 
|---|
|  |  |  | var result = await HttpHelper.PostAsync(wmsIpAddrss, new { Position = sourceAddress, PalletCode = palletCode, stationManager.productLine }.ToJsonString()); | 
|---|
|  |  |  | content = JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | 
|---|
|  |  |  | _Task.TaskState = (int)TaskInStatusEnum.InNew; | 
|---|
|  |  |  | _Task.CurrentAddress = task.SourceAddress; | 
|---|
|  |  |  | _Task.NextAddress = station.stationNGChildCode; | 
|---|
|  |  |  | _Task.TargetAddress = station.stationNGLocation; | 
|---|
|  |  |  | _Task.Roadway = station.Roadway; | 
|---|
|  |  |  | _Task.TargetAddress = task.TargetAddress; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BaseDal.AddData(_Task); | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(_Task.TaskNum, "接收WMS任务"); | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public Dt_Task QueryConveyorLineTask(string deviceNo, string currentAddress) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) && x.CurrentAddress == currentAddress, TaskOrderBy); | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => ((TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew) || (TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish)) && x.CurrentAddress == currentAddress, TaskOrderBy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public Dt_Task QueryNextConveyorLineTask(string deviceNo, string currentAddress) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) && x.NextAddress == currentAddress, TaskOrderBy); | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => ((TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew) || (TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish)) && x.NextAddress == currentAddress, TaskOrderBy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public Dt_Task QueryBarCodeConveyorLineTask(string Barcode, string currentAddress) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) && x.CurrentAddress == currentAddress && x.PalletCode == Barcode, TaskOrderBy); | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => ((TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew) || (TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish)) && x.CurrentAddress == currentAddress && x.PalletCode == Barcode, TaskOrderBy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InFinish || x.TaskState == (int)TaskOutStatusEnum.Line_OutFinish), TaskOrderBy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 根据托盘号、当前地址查询任务 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="taskNum">任务号</param> | 
|---|
|  |  |  | /// <param name="currentAddress">当前地址</param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public Dt_Task QueryBarcodeTask(string barcode, string currentAddress) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.PalletCode == barcode && x.CurrentAddress == currentAddress, TaskOrderBy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 根据任务号、当前地址查询输送线新建的任务 | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && ((TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish) || (TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew)), TaskOrderBy); | 
|---|
|  |  |  | if (taskTypeGroup.Value == TaskTypeGroup.InboundGroup) | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish, TaskOrderBy); | 
|---|
|  |  |  | if (taskTypeGroup.Value == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && ((TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish) || (TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew)), TaskOrderBy); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && ((TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish) || (TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew)), TaskOrderBy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew, TaskOrderBy); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew && x.CurrentAddress == currentAddress, TaskOrderBy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 根据设备编号、排除的任务、当前地址按照优先级以及创建时间排序查询任务池出库类型的新增的所有任务 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="deviceNo">设备编号</param> | 
|---|
|  |  |  | /// <param name="excludedTaskId">排除的任务</param> | 
|---|
|  |  |  | /// <param name="currentAddress">当前地址</param> | 
|---|
|  |  |  | /// <returns>返回任务实体对象,可能为null</returns> | 
|---|
|  |  |  | public List<Dt_Task> QueryAllOutboundTasks(string deviceNo, string currentAddress = "") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (string.IsNullOrEmpty(currentAddress)) | 
|---|
|  |  |  | return BaseDal.QueryData(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew, TaskOrderBy); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | return BaseDal.QueryData(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew && x.CurrentAddress == currentAddress, TaskOrderBy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | BaseDal.DeleteData(task); | 
|---|
|  |  |  | _taskHtyRepository.AddData(task_Hty); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (task.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | content = StackCraneTaskCompleted(task.TaskNum); | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (task.TaskState == (int)TaskInStatusEnum.Line_InFinish) | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 入库调用接口获取货位地址 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // TODO: 调用接口获取货位地址 | 
|---|
|  |  |  | // 创建请求对象 | 
|---|
|  |  |  | var taskDto = new RequestTaskDto() | 
|---|
|  |  |  | 
|---|
|  |  |  | task.CurrentAddress = task.NextAddress; | 
|---|
|  |  |  | task.NextAddress = taskResult.TargetAddress; | 
|---|
|  |  |  | task.TargetAddress = task.NextAddress; | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion 入库调用接口获取货位地址 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (task.TaskState == (int)TaskInStatusEnum.SC_InFinish) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (App.User.UserId > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | content = StackCraneTaskCompleted(task.TaskNum); | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | task.ModifyDate = DateTime.Now; | 
|---|
|  |  |  | task.Modifier = "System"; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, App.User.UserId > 0 ? $"人工手动将任务状态从【{oldState}】跳转到【{task.TaskState}】" : $"系统自动流程,任务状态从【{oldState}】转到【{task.TaskState}】"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region  更新任务状态 | 
|---|
|  |  |  | #region 更新任务状态 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取WMSip地址 | 
|---|
|  |  |  | var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); | 
|---|
|  |  |  | var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var result = HttpHelper.PostAsync(wmsIpAddress, new { TaskNum = task.TaskNum, TaskState = task.TaskState }.ToJsonString()).Result; | 
|---|
|  |  |  | content = JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion 更新任务状态 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | content = WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region WMS同步任务完成 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var keys = new Dictionary<string, object>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | {"taskNum", taskNum} | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | task.ExceptionMessage += "   " + content.Message; | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion WMS同步任务完成 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //暂不考虑多个出库口 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting) | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{taskNum}】,任务类型:【{task.TaskType}】"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region  更新任务状态 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.UpdateTask)?.ConfigValue; | 
|---|
|  |  |  | //if (wmsBase == null || updateTask == null) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    throw new InvalidOperationException("WMS IP 未配置"); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | //wmsIpAddress = wmsBase + updateTask; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //result = HttpHelper.PostAsync(wmsIpAddress, new { TaskNum = task.TaskNum, TaskState = task.TaskState }.ToJsonString()).Result; | 
|---|
|  |  |  | //content = JsonConvert.DeserializeObject<WebResponseContent>(result); | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  | //content = WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return BaseDal.QueryFirst(x => x.PalletCode == barcode && x.NextAddress == nextAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting), TaskOrderBy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private string GetIpAddress(string baseIp, string name) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var configz = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); | 
|---|
|  |  |  | var wcsBasez = configz.Where(x => x.ConfigKey == baseIp).FirstOrDefault()?.ConfigValue; | 
|---|
|  |  |  | var address = configz.Where(x => x.ConfigKey == name).FirstOrDefault()?.ConfigValue; | 
|---|
|  |  |  | if (wcsBasez == null || address == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new InvalidOperationException("WMS IP 未配置"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return wcsBasez + address; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 重写方法 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public override WebResponseContent DeleteData(object[] key) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | foreach (var item in key) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var task = BaseDal.QueryFirst(x => x.TaskId == Convert.ToInt32(item)); | 
|---|
|  |  |  | var taskHty = task.Adapt<Dt_Task_Hty>(); | 
|---|
|  |  |  | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; | 
|---|
|  |  |  | _taskHtyRepository.AddData(taskHty); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return base.DeleteData(key); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion 重写方法 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|