| | |
| | | |
| | | using AutoMapper; |
| | | using HslCommunication.Enthernet; |
| | | using Microsoft.AspNetCore.Mvc.RazorPages; |
| | | using NetTaste; |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Diagnostics; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Reflection; |
| | | using System.Reflection.Metadata; |
| | | using System.Security.Policy; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Comm.Http; |
| | | using WIDESEA_Common.Log; |
| | | using WIDESEA_DTO.Agv; |
| | | using WIDESEAWCS_Common.APIEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Utilities; |
| | | using WIDESEAWCS_DTO.Enum; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.BasicInfo; |
| | | using WIDESEAWCS_DTO.System; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_ISystemServices; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using static Microsoft.IO.RecyclableMemoryStreamManager; |
| | | using WIDESEAWCS_TaskInfoRepository; |
| | | 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 ITask_HtyService _task_HtyService; |
| | | private readonly IPlatformStationService _PlatformStationService; |
| | | private readonly IMapper _mapper; |
| | | private readonly IStationMangerRepository _stationMangerRepository; |
| | | private readonly IRouterRepository _routerRepository; |
| | | private readonly IApiInfoRepository _apiInfoRepository; |
| | | private List<Dt_ApiInfo> apiInfos; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | | {nameof(Dt_Task.Grade),OrderByType.Desc }, |
| | | {nameof(Dt_Task.TaskNum),OrderByType.Asc}, |
| | | {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 >= 500 && x < 900).ToList(); |
| | | |
| | | public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 100 && x < 500).ToList(); |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ITask_HtyService task_HtyService, IPlatformStationService platformStation) : base(BaseDal) |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _cacheService = cacheService; |
| | | _routerService = routerService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskExecuteDetailRepository = taskExecuteDetailRepository; |
| | | _task_HtyService = task_HtyService; |
| | | _PlatformStationService = platformStation; |
| | | _mapper = mapper; |
| | | _stationMangerRepository = stationMangerRepository; |
| | | _routerRepository = routerRepository; |
| | | _apiInfoRepository = apiInfoRepository; |
| | | |
| | | string? cacheStr = _cacheService.Get(nameof(Dt_Warehouse)); |
| | | if (!string.IsNullOrEmpty(cacheStr)) |
| | | { |
| | | Warehouses = JsonConvert.DeserializeObject<List<Dt_Warehouse>>(cacheStr); |
| | | } |
| | | |
| | | |
| | | string? apiInfoStr = _cacheService.Get("apiInfos"); |
| | | if (!string.IsNullOrEmpty(apiInfoStr)) |
| | | { |
| | | List<Dt_ApiInfo>? infos = JsonConvert.DeserializeObject<List<Dt_ApiInfo>>(apiInfoStr); |
| | | if (infos == null || infos.Count == 0) |
| | | { |
| | | apiInfos = new List<Dt_ApiInfo>(); |
| | | } |
| | | else |
| | | { |
| | | apiInfos = infos; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public string urlWMSTask = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlWMSTask"]; |
| | | public string urlTaskCompleted = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlTaskCompleted"]; |
| | | public string urlWMSMovelibraryTask = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlWMSMovelibraryTask"]; |
| | | public string urlRelocationTaskCompleted = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlRelocationTaskCompleted"]; |
| | | /*public string urlQueryinventory = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlQueryinventory"]; |
| | | public string urlEmptyOutbound = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlEmptyOutbound"]; |
| | | public string urlRawmaterialout = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlRawmaterialout"]; |
| | | public string urlPalletQueryinventory = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlPalletQueryinventory"];*/ |
| | | public WebResponseContent TaskCompleted(int taskNum) |
| | | { |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task != null) |
| | | { |
| | | task.TaskState = TaskStatusEnum.Finish.ObjToInt(); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成); |
| | | } |
| | | string? url = apiInfos.FirstOrDefault(x => x.ApiCode == APIEnum.FeedBackWMSTaskCompleted.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"未找到WMS任务完成接口,请检查接口配置"); |
| | | UpdateTaskExceptionMessage(taskNum, $"未找到WMS任务完成接口,请检查接口配置"); |
| | | return WebResponseContent.Instance.Error($"{taskNum},未找到WMS任务完成接口,请检查接口配置"); |
| | | } |
| | | string responseStr = HttpHelper.Get(url + "?taskNum=" + taskNum); |
| | | WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(responseStr) ?? WebResponseContent.Instance.Error($"{taskNum},未接收到任务完成返回值"); |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | public WebResponseContent AgvCarrying(int row, int startColumn, int endColumn, int startlayer, int targetLayer) |
| | | { |
| | | try |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | for (int i = startColumn; i <= endColumn; i++) |
| | | { |
| | | string column = i.ToString(); |
| | | if (i < 10) |
| | | { |
| | | column = "0" + i.ToString(); |
| | | } |
| | | string layer = targetLayer.ToString(); |
| | | if (targetLayer < 10) |
| | | { |
| | | layer = "0" + targetLayer.ToString(); |
| | | } |
| | | Dt_Task task = new Dt_Task() |
| | | { |
| | | WarehouseId = 7, |
| | | TaskNum = DateTime.Now.ToString("yyMMddHHmm").ObjToInt() + i, |
| | | PalletCode = DateTime.Now.ToString("yyMMddHHmm") + i, |
| | | PalletType = 0, |
| | | DeviceCode = "AGV_CP", |
| | | Roadway = "AGV_CP", |
| | | TaskType = 999, |
| | | SourceAddress = string.Format($"AGV_CP-00{row}-0{column}-00{startlayer}-01"), |
| | | CurrentAddress = string.Format($"AGV_CP-00{row}-0{column}-00{startlayer}-01"), |
| | | TargetAddress = string.Format($"AGV_CP-00{row}-0{column}-00{layer}-01"), |
| | | NextAddress = string.Format($"AGV_CP-00{row}-0{column}-00{layer}-01"), |
| | | Grade = 0, |
| | | WMSId = 0, |
| | | AgvTaskNum = "CP" + DateTime.Now.ToString("yyMMddHHmm").ObjToInt() + i, |
| | | TaskState = TaskStatusEnum.New.ObjToInt(), |
| | | Remark = "测试空框" |
| | | }; |
| | | tasks.Add(task); |
| | | } |
| | | BaseDal.AddData(tasks); |
| | | return WebResponseContent.Instance.OK(""); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 接收WMS任务信息 |
| | | /// </summary> |
| | | /// <param name="taskDTOs">WMS任务对象集合</param> |
| | | /// <returns>返回处理结果</returns> |
| | | public WebResponseContent ReceiveWMSTask([NotNull]List<Dt_Task> taskDTOs) |
| | | public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTaskDTO> taskDTOs) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | bool flag = false; |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | List<Dt_Task> tasksOld = BaseDal.QueryData(); |
| | | List<Dt_Router> routersAll = _routerRepository.QueryData(); |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(); |
| | | foreach (var item in taskDTOs) |
| | | { |
| | | if (BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode) != null) |
| | | if (tasksOld.FirstOrDefault(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode) != null) |
| | | { |
| | | flag = true; |
| | | continue; |
| | | } |
| | | Dt_Task task = _mapper.Map<Dt_Task>(item); |
| | | task.TaskState = (int)TaskOutStatusEnum.OutNew; |
| | | task.Roadway = (item.Roadway == "1") ? "SC01" : |
| | | (item.Roadway == "2") ? "SC02" : |
| | | (item.Roadway == "3") ? "SC03" : |
| | | (item.Roadway == "4") ? "SC04" : |
| | | (item.Roadway == "5") ? "SC05" : |
| | | (item.Roadway == "6") ? "SC06" : task.Roadway; |
| | | task.TaskType = (int)TaskOutboundTypeEnum.Outbound; |
| | | task.CreateDate = DateTime.Now; |
| | | task.CurrentAddress= _PlatformStationService.GetSCName(task.Roadway); |
| | | Dt_Task task = _mapper.Map<Dt_Task>(item); |
| | | task.Creater = "WMS"; |
| | | task.TaskState = (int)TaskStatusEnum.New; |
| | | |
| | | Dt_Router? router; |
| | | |
| | | TaskTypeGroup taskTypeGroup = item.TaskType.GetTaskTypeGroup(); |
| | | Dt_StationManger? stationManger; |
| | | if (taskTypeGroup == TaskTypeGroup.InboundGroup) |
| | | { |
| | | stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.NextAddress || x.StationDeviceCode == item.SourceAddress); |
| | | task.DeviceCode = stationManger.StationDeviceCode; |
| | | List<Dt_Router> routers = routersAll.Where(x => x.InOutType == item.TaskType && (item.NextAddress == x.NextPosi || item.RoadWay == x.StartPosi /*|| item.RoadWay == x.ChildPosiDeviceCode || item.RoadWay == x.ChildPosi*/)).ToList(); |
| | | router = routers.FirstOrDefault(); |
| | | if (router == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到路由配置信息"); |
| | | } |
| | | task.SourceAddress = router.StartPosi; |
| | | task.CurrentAddress = task.SourceAddress; |
| | | } |
| | | else |
| | | { |
| | | stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.NextAddress || x.StationDeviceCode == item.NextAddress); |
| | | task.DeviceCode = stationManger.StationDeviceCode; |
| | | List<Dt_Router> routers = routersAll.Where(x => x.InOutType == item.TaskType && (item.NextAddress == x.StartPosi || item.RoadWay == x.StartPosi /*|| item.RoadWay == x.ChildPosiDeviceCode || item.RoadWay == x.ChildPosi*/)).ToList(); |
| | | router = routers.FirstOrDefault(); |
| | | if (router == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到路由配置信息"); |
| | | } |
| | | //task.NextAddress = stationManger.StackerCraneStationCode; |
| | | task.TargetAddress = router.NextPosi; |
| | | //出库 |
| | | } |
| | | tasks.Add(task); |
| | | } |
| | | BaseDal.AddData(tasks); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "接收WMS任务"); |
| | | content = WebResponseContent.Instance.OK("成功"); |
| | | |
| | | content = (flag || tasks.Count > 0) ? WebResponseContent.Instance.OK("成功") : WebResponseContent.Instance.Error("失败"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | WriteLog.GetLog("接收任务").Write(JsonConvert.SerializeObject(content), "接收任务"); |
| | | } |
| | | return content; |
| | | } |
| | |
| | | /// <param name="palletCode">托盘号</param> |
| | | /// <param name="sourceAddress">起始地址</param> |
| | | /// <returns></returns> |
| | | public class GenerateInv |
| | | { |
| | | public string PalletCode { get; set; } |
| | | } |
| | | |
| | | public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress,int GoodsType) |
| | | public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress, string materielBoxCode = "") |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | //task.CurrentAddress = _PlatformStationService.GetSCName(task.Roadway); |
| | | //Dt_Task taskDTO = new Dt_Task() |
| | | //{ |
| | | // TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")), |
| | | // Grade = 1, |
| | | // PalletCode = palletCode, |
| | | // Roadway = "SC04", |
| | | // SourceAddress = "R04-002-0037-001-01", |
| | | // TargetAddress = "R04-001-0036-001-01", |
| | | // TaskState = (int)TaskInStatusEnum.InNew, |
| | | // TaskType = (int)TaskInboundTypeEnum.Inbound, |
| | | // CurrentAddress = sourceAddress, |
| | | // NextAddress = "1019", |
| | | // WMSId=0, |
| | | // Creater="system", |
| | | // //PalletCodequantity= GoodsType, |
| | | // PalletCodequantity= 1, |
| | | // Station_storey=1 |
| | | //}; |
| | | //BaseDal.AddData(taskDTO); |
| | | ////ReceiveWMSTask(new List<Dt_Task> { taskDTO }); |
| | | //return content = content = WebResponseContent.Instance.OK(); |
| | | |
| | | GenerateInv generate = new GenerateInv() |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == sourceAddress); |
| | | if (stationManger == null) |
| | | { |
| | | PalletCode = palletCode |
| | | }; |
| | | |
| | | |
| | | content = HttpHelper.Post<WebResponseContent>($"{urlWMSTask}", generate); |
| | | Dt_Task task = new Dt_Task(); |
| | | if (content != null) |
| | | return WebResponseContent.Instance.Error($"未找到站台信息"); |
| | | } |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | if (content.Status) |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = ""; |
| | | if (!string.IsNullOrEmpty(materielBoxCode)) |
| | | { |
| | | responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTask?stationCode={sourceAddress}&roadwayNo={stationManger.StackerCraneCode}&palletCode={palletCode}&materielBoxCode={materielBoxCode}"); |
| | | } |
| | | else |
| | | { |
| | | responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTask?stationCode={sourceAddress}&roadwayNo={stationManger.StackerCraneCode}&palletCode={palletCode}"); |
| | | } |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString()); |
| | | if (taskDTO != null) |
| | | { |
| | | task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToString()); |
| | | |
| | | |
| | | task.TaskState = (int)TaskInStatusEnum.InNew; |
| | | task.TaskType = (int)TaskInboundTypeEnum.Inbound; |
| | | task.Roadway = (task.Roadway == "1") ? "SC01" : |
| | | (task.Roadway == "2") ? "SC02" : |
| | | (task.Roadway == "3") ? "SC03" : |
| | | (task.Roadway == "4") ? "SC04" : |
| | | (task.Roadway == "5") ? "SC05" : |
| | | (task.Roadway == "6") ? "SC06" : task.Roadway; |
| | | task.CurrentAddress = sourceAddress; |
| | | task.CreateDate = DateTime.Now; |
| | | BaseDal.AddData(task); |
| | | return content = WebResponseContent.Instance.OK(); |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | | } |
| | | return content = WebResponseContent.Instance.Error(); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content = WebResponseContent.Instance.Error(ex.Message); |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据深库位向wms申请判断浅库位是否有货,是否需要进行移库操作 |
| | | /// </summary> |
| | | /// <param name="palletCode">托盘号</param> |
| | | /// <param name="sourceAddress">起始地址</param> |
| | | /// <returns></returns> |
| | | public Dt_Task RequestWMSTaskMovelibrary(Dt_Task _Task) |
| | | public WebResponseContent RequestWMSZHTask(string agvTaskCode, string palletCode, string palletType, string materialLot) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | content = HttpHelper.Get<WebResponseContent>($"{urlWMSMovelibraryTask}?TaskNum={_Task.TaskNum}&SourceAddress={_Task.SourceAddress}"); |
| | | Dt_Task task = new Dt_Task(); |
| | | if (content != null) |
| | | try |
| | | { |
| | | if (content.Status) |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.AgvTaskNum == agvTaskCode); |
| | | if (task != null) |
| | | { |
| | | if(content.Data != null) |
| | | { |
| | | task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToString()); |
| | | if (task.TaskNum != _Task.TaskNum) |
| | | { |
| | | return WebResponseContent.Instance.Error($"任务号{task.TaskNum}对应任务已存在"); |
| | | } |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = ""; |
| | | if (string.IsNullOrEmpty(materialLot)) |
| | | { |
| | | return content.Error("物料批次为空"); |
| | | |
| | | task.TaskState = (int)TaskRelocationTypeEnum.Relocation; |
| | | task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02"; |
| | | task.TaskNum = task.TaskNum; |
| | | task.Grade = 3; |
| | | task.TaskType= (int)TaskRelocationTypeEnum.Relocation; |
| | | BaseDal.AddData(task); |
| | | return task; |
| | | } |
| | | } |
| | | responseStr = HttpHelper.Get($"{address}/api/Task/RequestZHInboundTask?agvTaskCode={agvTaskCode}&palletCode={palletCode}&palletType={palletType}&materialLot={materialLot}"); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString()); |
| | | if (taskDTO != null) |
| | | { |
| | | taskDTO.AGVTaskNum = agvTaskCode; |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return null; |
| | | WriteLog.GetLog("PLC日志").Write($"失败信息:{content.Message}", "移库信息"); |
| | | content.Error(responseContent.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | return _Task; |
| | | } |
| | | |
| | | /// <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.TaskState == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据任务号,修改任务状态,下一地址,与当前地址 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="nextAddress">下一地址</param> |
| | | /// <returns></returns> |
| | | public Dt_Task QueryExeupConveyorLineTask(int taskNum, string nextAddress) |
| | | { |
| | | return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.NextAddress == nextAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据任务号、当前地址查询输送线完成的任务 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns></returns> |
| | | public bool QueryOutConveyorLineTask(int taskNum) |
| | | { |
| | | Dt_Task dt_Task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && (x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting), TaskOrderBy); |
| | | dt_Task.TaskState = (int)TaskOutStatusEnum.Line_OutFinish; |
| | | if (BaseDal.UpdateData(dt_Task)) |
| | | catch (Exception ex) |
| | | { |
| | | return true; |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | else |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 查询该站台是否被占用 |
| | | /// |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <param name="palletCode"></param> |
| | | /// <param name="sourceAddress"></param> |
| | | /// <returns></returns> |
| | | public bool OutConveyorLineTask(PlatformStation platform) |
| | | public WebResponseContent RequestWMSTaskSimple(string palletCode, string sourceAddress) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task dt_Task = BaseDal.QueryFirst(x => x.NextAddress == platform.Station_code && (x.TaskState == (int)TaskOutStatusEnum.Line_OutRgvFinish && x.TaskState == (int)TaskOutStatusEnum.AGV_OutExecuting), TaskOrderBy); |
| | | if (dt_Task == null) |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | List<string> Platack = _PlatformStationService.GetPlatform2(platform.ChildPosiDeviceCode); |
| | | |
| | | Dt_Task dt_Tasks = BaseDal.QueryFirst(x => Platack.Contains(x.CurrentAddress) && (x.TaskState == (int)TaskOutStatusEnum.Line_OutFinish), TaskOrderBy); |
| | | if(dt_Tasks != null) |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTaskSimple?stationCode={sourceAddress}&palletCode={palletCode}"); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString()); |
| | | if (taskDTO != null) |
| | | { |
| | | dt_Tasks.TaskState = (int)TaskOutStatusEnum.Line_OutRgvFinish; |
| | | dt_Tasks.NextAddress = platform.Station_code; |
| | | BaseDal.UpdateData(dt_Tasks); |
| | | return true; |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | | } |
| | | return false; |
| | | |
| | | } |
| | | catch (Exception) |
| | | catch (Exception ex) |
| | | { |
| | | return false; |
| | | throw; |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="palletCode"></param> |
| | | /// <param name="sourceAddress"></param> |
| | | /// <param name="roadway"></param> |
| | | /// <returns></returns> |
| | | //public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress, string roadway) |
| | | //{ |
| | | // WebResponseContent content = new WebResponseContent(); |
| | | // try |
| | | // { |
| | | // string address = AppSettings.Get("WMSApiAddress"); |
| | | // if (string.IsNullOrEmpty(address)) |
| | | // { |
| | | // return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | // } |
| | | // string responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTask?stationCode={sourceAddress}&roadwayNo={roadway}&palletCode={palletCode}"); |
| | | // WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | // if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | // { |
| | | // WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString()); |
| | | // if (taskDTO != null) |
| | | // { |
| | | // content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | // } |
| | | // } |
| | | |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // content = WebResponseContent.Instance.Error(ex.Message); |
| | | // } |
| | | // return content; |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="sourceAddress"></param> |
| | | /// <param name="palletCode"></param> |
| | | /// <param name="heightType"></param> |
| | | /// <param name="roadways"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress, int heightType, List<string> roadways) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = HttpHelper.Post($"{address}/api/Task/DeviceRequestInboundTaskByRoadways?stationCode={sourceAddress}&palletCode={palletCode}&heightType={heightType}", roadways.Serialize()); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString()); |
| | | if (taskDTO != null) |
| | | { |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 分配巷道 |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <param name="roadwayNos"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSAssignRoadway(int taskNum, List<string> roadwayNos) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = HttpHelper.Post($"{address}/api/Task/AssignRoadway?taskNum={taskNum}", roadwayNos.Serialize()); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | return responseContent; |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="roadwayNos"></param> |
| | | /// <param name="palletCode"></param> |
| | | /// <param name="heightType"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSAssignRoadway(List<string> roadwayNos, string palletCode, int heightType) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = HttpHelper.Post($"{address}/api/Task/AssignRoadwayByHeightAndCode?palletCode={palletCode}&heightType={heightType}", roadwayNos.Serialize()); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | return responseContent; |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 分配巷道 |
| | | /// </summary> |
| | | /// <param name="roadwayNos"></param> |
| | | /// <param name="taskNum"></param> |
| | | /// <param name="heightType"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSAssignRoadway(List<string> roadwayNos, int taskNum, int heightType) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = HttpHelper.Post($"{address}/api/Task/AssignRoadway?taskNum={taskNum}&heightType={heightType}", roadwayNos.Serialize()); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | return responseContent; |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 分配巷道 |
| | | /// </summary> |
| | | /// <param name="roadwayNos"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSAssignRoadway(List<string> roadwayNos) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到WMSApi地址"); |
| | | } |
| | | string responseStr = HttpHelper.Post($"{address}/api/Task/SingleAssignRoadway", roadwayNos.Serialize()); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | return responseContent; |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 向WMS申请分配货位 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="roadwayNo">巷道号</param> |
| | | /// <returns></returns> |
| | | public string? RequestAssignLocation(int taskNum, string roadwayNo) |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) throw new Exception("未找到WMSApi地址"); |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/AssignInboundTaskLocation?taskNum={taskNum}&roadwayNo={roadwayNo}"); |
| | | |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | return responseContent.Data.ToString(); |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 向WMS申请分配货位 |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <param name="roadwayNo"></param> |
| | | /// <param name="heightType"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public string? RequestAssignLocationByHeight(int taskNum, string roadwayNo, int heightType) |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) throw new Exception("未找到WMSApi地址"); |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/AssignInboundTaskLocation?taskNum={taskNum}&roadwayNo={roadwayNo}&heightType={heightType}"); |
| | | |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | return responseContent.Data.ToString(); |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <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.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) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew, TaskOrderBy); |
| | | if (taskTypeGroup == null) |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && x.TaskState == (int)TaskStatusEnum.New, TaskOrderBy); |
| | | if (taskTypeGroup.Value == TaskTypeGroup.InboundGroup) |
| | | 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.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.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); |
| | | return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && x.TaskState == (int)TaskStatusEnum.SC_Execute, 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); |
| | | } |
| | | public Dt_Task IngStackerCraneTask(string deviceNo) |
| | | { |
| | | //string deviceNot = deviceNo == "SC01" ? "1" : "2"; |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.TaskState == (int)TaskInStatusEnum.SC_InExecuting); |
| | | } |
| | | |
| | | public Dt_Task IngStackerCraneTask2(string deviceNo) |
| | | { |
| | | //string deviceNot = deviceNo == "SC01" ? "1" : "2"; |
| | | try |
| | | { |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | 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.Line_InFinish, 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.Line_InFinish && 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.OutNew, 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.OutNew && 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.OutNew && outStationCodes.Contains(x.CurrentAddress), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据出库货位查询是否有当前浅货位任务 |
| | | /// </summary> |
| | | /// <param name="deviceNo">设备编号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns>返回任务实体对象集合,可能为null</returns> |
| | | public List<Dt_Task> QueryStationIsOccupiedOutTasks(string deviceNo, string SourceAddress) |
| | | { |
| | | return BaseDal.QueryData(x => x.Roadway == deviceNo && SourceAddress.Contains(x.SourceAddress), TaskOrderBy); |
| | | return BaseDal.QueryData(x => x.DeviceCode == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.SC_Execute && outStationCodes.Contains(x.CurrentAddress), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | 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); |
| | |
| | | } |
| | | |
| | | /// <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.TaskState = 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; |
| | | } |
| | | |
| | | public WebResponseContent UpdateTaskStatusToNext2(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.TaskType == (int)TaskInboundTypeEnum.Inbound) |
| | | { |
| | | if (task.TaskState == (int)TaskInStatusEnum.Line_InExecuting) |
| | | { |
| | | task.TaskState=(int)TaskInStatusEnum.Line_InFinish; |
| | | BaseDal.UpdateData(task); |
| | | return content = WebResponseContent.Instance.OK(); |
| | | } |
| | | } |
| | | |
| | | return content = WebResponseContent.Instance.Error(); |
| | | } |
| | | 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) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | int oldState = task.TaskState; |
| | | if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound) |
| | | { |
| | | if (task.TaskState >= (int)TaskOutStatusEnum.OutFinish) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>(); |
| | | |
| | | task.TaskState = nextStatus; |
| | | if (task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting) |
| | | { |
| | | task.Dispatchertime = DateTime.Now; |
| | | } |
| | | } |
| | | else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound) |
| | | { |
| | | if (task.TaskState >= (int)TaskInStatusEnum.InFinish) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>(); |
| | | task.TaskState = nextStatus; |
| | | if (task.TaskState == (int)TaskInStatusEnum.SC_InExecuting) |
| | | { |
| | | task.Dispatchertime = DateTime.Now; |
| | | } |
| | | /*if (task.TaskState == (int)TaskRelocationTypeEnum.Relocation) |
| | | { |
| | | Random random = new Random(); |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = $"{random.Next(1, 100).ToString().PadLeft(3, '0')}-{random.Next(1, 100).ToString().PadLeft(3, '0')}-{random.Next(1, 100).ToString().PadLeft(3, '0')}"; |
| | | task.TargetAddress = task.NextAddress; |
| | | }*/ |
| | | } |
| | | /*else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound) |
| | | { |
| | | if (task.TaskState <= (int)TaskRelocationStatusEnum.SC_RelocationFinish) |
| | | { |
| | | |
| | | return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | int nextStatus = (int)TaskRelocationStatusEnum.SC_RelocationExecuting; |
| | | task.TaskState = nextStatus; |
| | | if (task.TaskState == (int)TaskRelocationStatusEnum.SC_RelocationExecuting) |
| | | { |
| | | task.Dispatchertime = DateTime.Now; |
| | | } |
| | | }*/ |
| | | else |
| | | { |
| | | throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{task.TaskNum}】,任务类型:【{task.TaskType}】"); |
| | | } |
| | | |
| | | if (task.TaskState <= 0) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, App.User.UserId > 0 ? $"人工手动将任务状态从【{oldState}】跳转到【{task.TaskState}】" : $"系统自动流程,任务状态从【{oldState}】转到【{task.TaskState}】"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据任务号、当前地址更新任务位置信息 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns></returns> |
| | | public Dt_Task? UpdatePosition(int taskNum, string currentAddress) |
| | | { |
| | | try |
| | | { |
| | | 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; |
| | | |
| | | List<Dt_Router> routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress); |
| | | if (!routers.Any()) throw new Exception($"未找到设备路由信息"); |
| | | |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = routers.FirstOrDefault().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) |
| | | { |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 任务完成 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务编号</param> |
| | | /// <returns>返回处理结果</returns> |
| | | public class GenerateInv2 |
| | | { |
| | | public string PalletCode { get; set; } |
| | | public string SourceAddress { get; set; } |
| | | public string TargetAddress { get; set; } |
| | | } |
| | | 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}】"); |
| | | |
| | | if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TaskState == (int)TaskOutStatusEnum.AGV_OutExecuting) |
| | | { |
| | | //content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}"); |
| | | task.TaskState = (int)TaskOutStatusEnum.OutFinish; |
| | | task.ModifyDate = DateTime.Now; |
| | | BaseDal.DeleteData(task); |
| | | _task_HtyService.AddTaskHty(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"出库完成"); |
| | | } |
| | | else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting) |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish; |
| | | BaseDal.UpdateData(task); |
| | | } |
| | | else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting) |
| | | { |
| | | //content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}"); |
| | | task.TaskState = (int)TaskInStatusEnum.InFinish; |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.DeleteData(task); |
| | | _task_HtyService.AddTaskHty(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"入库完成"); |
| | | |
| | | }else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound && task.TaskState == (int)TaskInStatusEnum.RGV_InExecuting) |
| | | { |
| | | task.TaskState = (int)TaskInStatusEnum.Line_InExecuting; |
| | | BaseDal.UpdateData(task); |
| | | } |
| | | |
| | | /* else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation) |
| | | { |
| | | GenerateInv2 generate = new GenerateInv2() |
| | | { |
| | | PalletCode = task.PalletCode, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress |
| | | |
| | | }; |
| | | content = HttpHelper.Post<WebResponseContent>($"{urlRelocationTaskCompleted}", generate); |
| | | task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish; |
| | | task.ModifyDate = DateTime.Now; |
| | | BaseDal.DeleteData(task); |
| | | _task_HtyService.AddTaskHty(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"移库完成"); |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OtherGroup) |
| | | { |
| | | |
| | | }*/ |
| | | else |
| | | { |
| | | throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{taskNum}】,任务类型:【{task.TaskType}】"); |
| | | } |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"任务完成异常,任务号:【{taskNum}】"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 恢复挂起任务 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | |
| | | { |
| | | 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; |
| | |
| | | return content; |
| | | } |
| | | |
| | | //public WebResponseContent SendSecureReplyToAgv(int taskNum) |
| | | //{ |
| | | // try |
| | | // { |
| | | // Dt_Task WaitToTask = BaseDal.QueryFirst(x => x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt() && x.TaskNum == taskNum); |
| | | // AgvSecureReplyDTO replyDTO = new AgvSecureReplyDTO() |
| | | // { |
| | | // ReqCode = Guid.NewGuid().ToString().Replace("-", ""), //WaitToTask.TaskNum.ToString(), |
| | | // taskCode = WaitToTask.AgvTaskNum, |
| | | // }; |
| | | // WebResponseContent content = AgvSecureReply(replyDTO); |
| | | // if (content.Status) |
| | | // { |
| | | // WaitToTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt(); |
| | | // } |
| | | // else |
| | | // { |
| | | // WaitToTask.TaskState = TaskStatusEnum.Exception.ObjToInt(); |
| | | // WaitToTask.ExceptionMessage = content.Message; |
| | | // } |
| | | // UpdateData(WaitToTask); |
| | | |
| | | // return WebResponseContent.Instance.OK(); |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // return WebResponseContent.Instance.Error(ex.Message); |
| | | // } |
| | | //} |
| | | /// <summary> |
| | | /// 删除数据 |
| | | /// //判断移库货位任务是否已存在,如存在先执行 |
| | | /// </summary> |
| | | /// <param name="keys">主键数组</param>|| platforms.Contains(x.TargetAddress) |
| | | public Dt_Task QueryStackerExistTask(string PalletCode, string locationCode) |
| | | { |
| | | return BaseDal.QueryFirst(x => x.PalletCode == PalletCode && x.SourceAddress == locationCode); |
| | | } |
| | | /// <summary> |
| | | /// 接受WMS手动完成任务 |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DeleteData(object[] keys) |
| | | public WebResponseContent RecWMSTaskCompleted(int taskNum) |
| | | { |
| | | try |
| | | { |
| | | List<Dt_Task> tasks = BaseDal.QureyDataByIds(keys); |
| | | foreach (Dt_Task task in tasks) |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task != null) |
| | | { |
| | | _task_HtyService.AddTaskHty(task); |
| | | task.TaskState = TaskStatusEnum.Finish.ObjToInt(); |
| | | BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.人工完成); |
| | | } |
| | | |
| | | |
| | | if (typeof(Dt_Task).GetNavigatePro() == null) |
| | | return BaseDal.DeleteDataByIds(keys) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error(); |
| | | else |
| | | { |
| | | if (keys != null) |
| | | { |
| | | Type detailType = typeof(Dt_Task).GetDetailType(); |
| | | string name = typeof(Dt_Task).GetMainIdByDetail(); |
| | | List<object> dynamicDelKeys = new List<object>(); |
| | | |
| | | for (int i = 0; i < keys.Length; i++) |
| | | { |
| | | dynamicDelKeys.Add(keys[i]); |
| | | } |
| | | ((SqlSugarClient)BaseDal.Db).BeginTran(); |
| | | |
| | | if (dynamicDelKeys.Count > 0) |
| | | BaseDal.Db.Deleteable<object>().AS(detailType.Name).Where($"{name} in (@id)", new { id = dynamicDelKeys.ToArray() }).ExecuteCommandHasChange(); |
| | | |
| | | BaseDal.DeleteDataByIds(keys); |
| | | |
| | | ((SqlSugarClient)BaseDal.Db).CommitTran(); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error("参数错误"); |
| | | } |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ((SqlSugarClient)BaseDal.Db).RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据rgv设备编号,查找rgv可下发的任务 |
| | | /// </summary> |
| | | /// <param name="platforms"></param> |
| | | /// <returns></returns> |
| | | public Dt_Task QueryRgvCraneTask(List<string> platforms) |
| | | { |
| | | return BaseDal.QueryFirst(x => (platforms.Contains(x.NextAddress) && (x.TaskState == (int)TaskInStatusEnum.InNew || x.TaskState == (int)TaskOutStatusEnum.Line_OutRgvFinish)), TaskOrderBy); |
| | | } |
| | | |
| | | //堆垛机任务完成 |
| | | public List<Dt_Task> StackerCraneOutTask() |
| | | { |
| | | return BaseDal.QueryData(x =>x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |