using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEAWCS_Common.LocationEnum; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Common; using WIDESEAWCS_Core; using WIDESEAWCS_DTO.WMS; using WIDESEAWCS_Model.Models; using WIDESEAWCS_Core.Helper; using HslCommunication.Core.IMessage; using WIDESEAWCS_DTO.RGV.FOURBOT; using Newtonsoft.Json; using System.Reflection.Metadata; namespace WIDESEAWCS_TaskInfoService { public partial class TaskService { #region RGV任务创建 /// /// 创建四向车入库任务 /// /// /// /// public WebResponseContent CreateRGVNewInTask(TaskDTO taskDTO, int taskType) { WebResponseContent content = new WebResponseContent(); try { #region 点到点 //if (!string.IsNullOrEmpty(taskDTO.toLocationCode)) //{ // var LocationInfo = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点货位【{taskDTO.toLocationCode}】"); // if (LocationInfo.LocationStatus != LocationStatusEnum.Free.ObjToInt()) throw new Exception($"终点货位【{taskDTO.toLocationCode}】货位状态不为空货位"); //} #endregion var rGVLocationInfo = _rGVLocationInfoService.GetInFreeLocationInfo(taskDTO.toAreaCode.ObjToInt()) ?? throw new Exception($"未找到终点库区【{taskDTO.toAreaCode}】可用空货位!"); Dt_StationManger stationManger = _stationMangerService.GetInStationInfo(taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点位置【{taskDTO.fromLocationCode}】站台信息!"); Dt_Task dt_Task = new() { TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), WMSTaskNum = taskDTO.taskCode, Grade = taskDTO.taskPriority, PalletCode = taskDTO.containerCode, Roadway = taskDTO.toAreaCode, TaskState = TaskStatusEnum.New.ObjToInt(), TaskType = taskType, SourceAddress = taskDTO.fromLocationCode, CurrentAddress = taskDTO.fromLocationCode, NextAddress = stationManger.RGVStationCode, TargetAddress = "", Creater = "WMS", }; BaseDal.AddData(dt_Task); return content.OK(data: new { taskCode = taskDTO.taskCode, Message = "成功!" }); } catch (Exception ex) { content.Data = new { taskCode = taskDTO.taskCode, Message = $"失败!{ex.Message}" }; return content.Error(ex.Message); } } /// /// 创建四向车出库任务 /// /// /// /// public WebResponseContent CreateRGVNewOutTask(TaskDTO taskDTO, int taskType) { WebResponseContent content = new WebResponseContent(); try { var stationManger = _stationMangerService.GetOutStationInfo(taskDTO.toLocationCode); if (stationManger == null) { return content.Error($"{taskDTO.toLocationCode}不是出库站台"); } Dt_RGVLocationInfo rGVLocationInfo = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!"); if (rGVLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不可出库!"); if (rGVLocationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】绑定料箱号【{rGVLocationInfo.PalletCode}】与任务料箱号【{taskDTO.containerCode}】不匹配!"); Dt_Task dt_Task = new() { TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), WMSTaskNum = taskDTO.taskCode, Grade = taskDTO.taskPriority, PalletCode = taskDTO.containerCode, Roadway = rGVLocationInfo.RoadwayNo, TaskState = TaskStatusEnum.New.ObjToInt(), TaskType = taskType, SourceAddress = taskDTO.fromLocationCode, CurrentAddress = taskDTO.fromLocationCode, NextAddress = taskDTO.toLocationCode, TargetAddress = taskDTO.toLocationCode, Creater = "WMS", }; rGVLocationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt(); try { Db.Ado.BeginTran(); BaseDal.AddData(dt_Task); _rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo); Db.Ado.CommitTran(); } catch (Exception ex) { Db.Ado.RollbackTran(); throw new Exception(ex.Message); } return content.OK(data: new { taskCode = taskDTO.taskCode, Message = "成功!" }); } catch (Exception ex) { content.Data = new { taskCode = taskDTO.taskCode, Message = $"失败!{ex.Message}" }; return content.Error(ex.Message); } } #endregion /// /// 移库任务 /// /// /// /// public WebResponseContent CreateRGVNewMoveTask(TaskDTO taskDTO, int taskType) { WebResponseContent content = new WebResponseContent(); FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new(); try { if (string.IsNullOrEmpty(taskDTO.fromLocationCode)) throw new Exception($"起点库位不能为空!"); if (string.IsNullOrEmpty(taskDTO.toLocationCode)) throw new Exception($"终点库位不能为空!"); Dt_RGVLocationInfo rGVLocationInfo = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!"); if (rGVLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不可出库!"); if (rGVLocationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】绑定料箱号【{rGVLocationInfo.PalletCode}】与任务料箱号【{taskDTO.containerCode}】不匹配!"); Dt_RGVLocationInfo rGVLocationInfo1 = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点库位【{taskDTO.toLocationCode}】!"); if (rGVLocationInfo1.LocationStatus != LocationStatusEnum.Free.ObjToInt()) throw new Exception($"终点库位【{taskDTO.toLocationCode}】当前库位状态不为空闲!"); Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("未找到四向车任务下发接口配置信息!请检查接口配置"); Dt_Task dt_Task = new() { TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), WMSTaskNum = taskDTO.taskCode, Grade = taskDTO.taskPriority, PalletCode = taskDTO.containerCode, Roadway = rGVLocationInfo.RoadwayNo, TaskState = TaskStatusEnum.New.ObjToInt(), TaskType = taskType, SourceAddress = taskDTO.fromLocationCode, CurrentAddress = taskDTO.fromLocationCode, NextAddress = taskDTO.toLocationCode, TargetAddress = taskDTO.toLocationCode, Creater = "WMS", }; rGVLocationInfo.LocationStatus = LocationStatusEnum.MoveLock.ObjToInt(); rGVLocationInfo1.LocationStatus = LocationStatusEnum.MoveLock.ObjToInt(); #region 下发四向车任务 fOURBOTnewMovePodTask = new FOURBOTnewMovePodTask { priority = dt_Task.Grade, podID = dt_Task.PalletCode, desStorageID = dt_Task.TargetAddress, desExt = new { unload = 1 }, // 是否放下容器,0否1是 desType = 2 }; fOURBOTnewMovePodTask.taskExt = new { autoToRest = 1 }; string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize()); var fOURBOTReturn = response.DeserializeObject(); content.OK(data: fOURBOTReturn); if (fOURBOTReturn.returnCode != 0) throw new Exception($"下发成品移库任务错误:{fOURBOTReturn.returnMsg}"); var data = fOURBOTReturn.data.ToString(); var fOURBO = data.DeserializeObject(); dt_Task.RGVTaskId = fOURBO.taskID; dt_Task.TaskState = TaskStatusEnum.RGV_MoveTaskSend.ObjToInt(); #endregion try { Db.Ado.BeginTran(); BaseDal.AddData(dt_Task); _rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo); _rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo1); Db.Ado.CommitTran(); } catch (Exception ex) { Db.Ado.RollbackTran(); throw new Exception(ex.Message); } return content.OK(data: new { taskCode = taskDTO.taskCode, Message = "成功!" }); } catch (Exception ex) { content.Data = new { taskCode = taskDTO.taskCode, Message = $"失败!{ex.Message}" }; return content.Error(ex.Message); } } } }