yanjinhui
6 天以前 c71c0e3e641f54f8c1deec44bb570b4f1b2ee07e
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RGVTaskMethods.cs
@@ -31,6 +31,14 @@
            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()
                {
@@ -45,6 +53,7 @@
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = stationManger.RGVStationCode,
                    TargetAddress = "",
                    Dispatchertime=DateTime.Now,
                    Creater = "WMS",
                };
                BaseDal.AddData(dt_Task);
@@ -75,8 +84,14 @@
            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)),
@@ -90,6 +105,7 @@
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = taskDTO.toLocationCode,
                    TargetAddress = taskDTO.toLocationCode,
                    Dispatchertime = DateTime.Now,
                    Creater = "WMS",
                };
                rGVLocationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt();
@@ -120,7 +136,96 @@
                };
                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);
            }
        }
    }
}