1
yanjinhui
2026-03-24 24ac6e3688db3dbb68eb6a53dd6c6fc9f8e12d6b
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RGVTaskMethods.cs
@@ -10,6 +10,10 @@
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
{
@@ -24,19 +28,21 @@
        /// <returns></returns>
        public WebResponseContent CreateRGVNewInTask(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                //List<Dt_RGVLocationInfo>? rGVLocationInfos = _rGVLocationInfoService.Repository.QueryData(x => x.WarehouseId.ToString() == taskDTO.toAreaCode && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt());
                //if (rGVLocationInfos.Count < 1) throw new Exception($"未找到终点库区【{taskDTO.toAreaCode}】可用空货位!");
                //var rGVLocationInfo = rGVLocationInfos.OrderBy(x => x.Depth).First();
                //var rGVLocationInfo = _rGVLocationInfoService.GetFreeLocationInfo(taskDTO.toAreaCode) ?? throw new Exception($"未找到终点库区【{taskDTO.toAreaCode}】可用空货位!");
                #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
                Dt_StationManger stationManger = _stationMangerService.GetInStationInfo(taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点位置【{taskDTO.fromLocationCode}】站台信息!");
                //if (stationManger.IsOccupied == 1) throw new Exception($"起点位置【{taskDTO.fromLocationCode}】站台被占用,请释放!");
                Dt_Task dt_Task = new()
                {
                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    WMSTaskNum = taskDTO.taskCode,
                    //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    Grade = taskDTO.taskPriority,
                    PalletCode = taskDTO.containerCode,
                    Roadway = taskDTO.toAreaCode,
@@ -44,22 +50,25 @@
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = stationManger.Remark,//找入库站台对应的外形检测编号
                    NextAddress = stationManger.RGVStationCode,
                    TargetAddress = "",
                    //Remark = taskDTO.toAreaCode,
                    Creater = "WMS",
                };
                //rGVLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
                //Db.Ado.BeginTran();
                BaseDal.AddData(dt_Task);
                //_rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo);
                //Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
                return content.OK(data: new
                {
                    taskCode = taskDTO.taskCode,
                    Message = "成功!"
                });
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
                content.Data = new
                {
                    taskCode = taskDTO.taskCode,
                    Message = $"失败!{ex.Message}"
                };
                return content.Error(ex.Message);
            }
        }
        /// <summary>
@@ -70,17 +79,21 @@
        /// <returns></returns>
        public WebResponseContent CreateRGVNewOutTask(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                //Dt_Task dt_Task = BaseDal.QueryFirst(x => x.PalletCode == taskDTO.containerCode);
                //if (dt_Task != null) throw new Exception($"托盘号【{taskDTO.containerCode}】已存在任务");
                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,
                    //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    Grade = taskDTO.taskPriority,
                    PalletCode = taskDTO.containerCode,
                    Roadway = rGVLocationInfo.RoadwayNo,
@@ -93,18 +106,122 @@
                    Creater = "WMS",
                };
                rGVLocationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt();
                Db.Ado.BeginTran();
                BaseDal.AddData(dt_Task);
                _rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo);
                Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
                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)
            {
                Db.Ado.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
                content.Data = new
                {
                    taskCode = taskDTO.taskCode,
                    Message = $"失败!{ex.Message}"
                };
                return content.Error(ex.Message);
            }
        }
        #endregion
        /// <summary>
        /// ç§»åº“任务
        /// </summary>
        /// <param name="taskDTO"></param>
        /// <param name="taskType"></param>
        /// <returns></returns>
        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<FOURBOTReturn>();
                content.OK(data: fOURBOTReturn);
                if (fOURBOTReturn.returnCode != 0) throw new Exception($"下发成品移库任务错误:{fOURBOTReturn.returnMsg}");
                var data = fOURBOTReturn.data.ToString();
                var fOURBO = data.DeserializeObject<FOURBOTnewMovePodTaskResponseData>();
                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);
            }
        }
    }
}