´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs
@@ -13,6 +13,8 @@
using WIDESEAWCS_DTO;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_QuartzJob;
using System.Reflection.Metadata;
namespace WIDESEAWCS_TaskInfoService
{
@@ -27,18 +29,20 @@
        public WebResponseContent CreateKLSNewInTask(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            Dt_KLSLocationInfo? kLSLocationInfo = null;
            try
            {
                int containerType = taskDTO.containerCode.Contains("LLM") ? (int)LocationTypeEnum.LargePallet : (int)LocationTypeEnum.SmallPallet;
                #region ç‚¹åˆ°ç‚¹
                if (!string.IsNullOrEmpty(taskDTO.toLocationCode))
                {
                    var LocationInfo = _kLSLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点货位【{taskDTO.toLocationCode}】");
                    if (LocationInfo.LocationStatus != (int)LocationStatusEnum.Free) throw new Exception($"终点货位【{taskDTO.toLocationCode}】货位状态不为空货位");
                    kLSLocationInfo = _kLSLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点货位【{taskDTO.toLocationCode}】");
                    if (kLSLocationInfo.LocationStatus != (int)LocationStatusEnum.Free) throw new Exception($"终点货位【{taskDTO.toLocationCode}】货位状态不为空货位");
                }
                #endregion
                //获取货位信息
                Dt_KLSLocationInfo? kLSLocationInfo = _kLSLocationInfoService.GetFreeLocationInfo(taskDTO.toAreaCode, containerType) ?? throw new Exception($"未找到终点库区【{taskDTO.toAreaCode}】可用空货位!");
                else
                    kLSLocationInfo = _kLSLocationInfoService.GetFreeLocationInfo(taskDTO.toAreaCode, containerType) ?? throw new Exception($"未找到终点库区【{taskDTO.toAreaCode}】可用空货位!");
                Dt_Task dt_Task = new()
                {
                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
@@ -60,6 +64,7 @@
                content = SendKLSTask(dt_Task);
                if (!content.Status) throw new Exception(content.Message);
                dt_Task.TaskState = (int)TaskStatusEnum.Execut;
                dt_Task.Dispatchertime = DateTime.Now;
                #endregion
                try
                {
@@ -125,6 +130,7 @@
                content = SendKLSTask(dt_Task);
                if (!content.Status) throw new Exception(content.Message);
                dt_Task.TaskState = (int)TaskStatusEnum.Execut;
                dt_Task.Dispatchertime = DateTime.Now;
                #endregion
                try
                {
@@ -197,18 +203,88 @@
        }
        #endregion
        #region 5 è·¨æ¥¼å±‚运输任务创建
        #region 5 è·¨æ¥¼å±‚运输任务创建 ï¼ˆéƒ½æ˜¯ç‚¹åˆ°ç‚¹ï¼‰
        public WebResponseContent CarryTask(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StationManger? stationInfo = null;
                Dt_Task dt_Task = null;
                //入库 åˆ°ä¸€æ¥¼ä¸‰ä¸ªç«™å°çš„位置
                if (taskType == (int)TaskTypeEnum.Q3RK)//6-1楼
                {
                    var ionInfo = _stationMangerService.Repository.QueryFirst(x => x.StationCode == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点站台【{taskDTO.toLocationCode}】!");
                    var StationInfo = _stationInfo.Repository.QueryFirst(x => x.StationCode == taskDTO.fromLocationCode) ?? throw new Exception($"未找到{taskDTO.fromLocationCode}起点货位");
                    if (StationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】绑定料箱号【{StationInfo.PalletCode}】与任务料箱号【{taskDTO.containerCode}】不匹配!");
                    if (StationInfo.StationStatus != (int)LocationStatusEnum.InStock) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前状态不可以出库");
                    if (StationInfo.FloorNumber != "FF") throw new Exception($"【{taskDTO.fromLocationCode}】的楼层和任务类型楼层不匹配");
                return WebResponseContent.Instance.OK();
                    dt_Task = new Dt_Task()
                    {
                        TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        WMSTaskNum = taskDTO.taskCode,
                        Grade = taskDTO.taskPriority,
                        PalletCode = taskDTO.containerCode,
                        Roadway = "1",
                        TaskState = (int)TaskStatusEnum.New,
                        TaskType = taskType,
                        SourceAddress = taskDTO.fromLocationCode,
                        CurrentAddress = taskDTO.fromLocationCode,
                        NextAddress = taskDTO.toLocationCode,
                        TargetAddress = taskDTO.toLocationCode,
                        Creater = "WMS",
                    };
                }
                //出库
                if (taskType == (int)TaskTypeEnum.Q3CK)//1-6楼
                {
                    var StationInfo = _stationInfo.Repository.QueryFirst(x => x.StationCode == taskDTO.toLocationCode) ?? throw new Exception($"未{taskDTO.toLocationCode}终点货位");
                    if (StationInfo.StationStatus != (int)LocationStatusEnum.Free) throw new Exception($"终点库位【{taskDTO.toLocationCode}】当前状态不可以放货");
                    if (StationInfo.FloorNumber != "FF") throw new Exception($"终点库位【{taskDTO.toLocationCode}】的楼层与任务类型楼层不匹配");
                    var ionInfo = _stationMangerService.Repository.QueryFirst(x => x.StationCode == taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点站台【{taskDTO.fromLocationCode}】!");
                    if (ionInfo.Remark != taskDTO.containerCode) throw new Exception($"起点站台【{taskDTO.fromLocationCode}】绑定料箱号【{ionInfo.Remark}】与任务料箱号【{taskDTO.containerCode}】不匹配!");
                    dt_Task = new Dt_Task()
                    {
                        TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        WMSTaskNum = taskDTO.taskCode,
                        //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        Grade = taskDTO.taskPriority,
                        PalletCode = taskDTO.containerCode,
                        Roadway = "1",
                        TaskState = (int)TaskStatusEnum.New,
                        TaskType = taskType,
                        SourceAddress = taskDTO.fromLocationCode,
                        CurrentAddress = taskDTO.fromLocationCode,
                        NextAddress = taskDTO.toLocationCode,
                        TargetAddress = taskDTO.toLocationCode,
                        Creater = "WMS",
                    };
                }
                try
                {
                    Db.Ado.BeginTran();
                    BaseDal.AddData(dt_Task);
                    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)
            {
                throw new Exception(ex.Message);
                content.Error(ex.Message);
            }
            return content;
        }
        #endregion
@@ -216,15 +292,142 @@
        #region 6 è£å‰ªé€è´§
        public WebResponseContent CJCarryTaske(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            Dt_StationInfo? stationInfo = null;
            try
            {
                #region æ˜¯å¦éœ€è¦åˆ¤æ–­å¹³åº“库位状态
                var reslut = ValidateLocationForTask(taskType, taskDTO);
                if (!reslut.Status)
                {
                    throw new Exception(reslut.Message);
                }
                #endregion
                return WebResponseContent.Instance.OK();
                Dt_Task dt_Task = new Dt_Task()
                {
                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    WMSTaskNum = taskDTO.taskCode,
                    //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    Grade = taskDTO.taskPriority,
                    PalletCode = taskDTO.containerCode,
                    Roadway = "",
                    TaskState = (int)TaskStatusEnum.New,
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = taskDTO.toLocationCode,
                    TargetAddress = taskDTO.toLocationCode,
                    Creater = "WMS",
                };
                content = SendHIKROBOTTask(dt_Task);
                if (!content.Status) throw new Exception(content.Message);
                dt_Task.TaskState = (int)TaskStatusEnum.Execut;
                dt_Task.Dispatchertime = DateTime.Now;
                BaseDal.AddData(dt_Task);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
                content.Error(ex.Message);
            }
            return content;
        }
        #endregion
        #region 5空车转运
        public WebResponseContent HKF01Transport(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var stationInfo = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                if (stationInfo.StationStatus != (int)LocationStatusEnum.InStock) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不是有货!");
                if (stationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"当前库位【{taskDTO.fromLocationCode}】绑定料箱号【{stationInfo.PalletCode}】与任务的料箱号【{taskDTO.containerCode}】不匹配");
                var stationInfo2 = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点库位【{taskDTO.toLocationCode}】!");
                if (stationInfo2.StationStatus != (int)LocationStatusEnum.Free) throw new Exception($"终点库位【{taskDTO.toLocationCode}】当前库位状态不是空闲!");
                var dt_Task = new Dt_Task()
                {
                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    WMSTaskNum = taskDTO.taskCode,
                    //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    Grade = taskDTO.taskPriority,
                    PalletCode = taskDTO.containerCode,
                    Roadway = "1",
                    TaskState = (int)TaskStatusEnum.New,
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = taskDTO.toLocationCode,
                    TargetAddress = taskDTO.toLocationCode,
                    Creater = "WMS",
                };
                content = SendHIKROBOTTask(dt_Task);
                if (!content.Status) throw new Exception(content.Message);
                dt_Task.Dispatchertime = DateTime.Now;
                BaseDal.AddData(dt_Task);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        #endregion
        #region
        /// <summary>
        /// æµ·åº·ä»“位到仓位的运输任务
        /// </summary>
        /// <param name="taskDTO"></param>
        /// <param name="taskType"></param>
        /// <returns></returns>
        public WebResponseContent HKSTUPTP(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var KLocationInfo = _hKLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                if (KLocationInfo.LocationStatus != (int)LocationStatusEnum.InStock) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不是有货!");
                if (KLocationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"当前库位【{taskDTO.fromLocationCode}】绑定料箱号【{KLocationInfo.PalletCode}】与任务的料箱号【{taskDTO.containerCode}】不匹配");
                var KLocationInfo2 = _hKLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点库位【{taskDTO.toLocationCode}】!");
                if (KLocationInfo2.LocationStatus != (int)LocationStatusEnum.Free) throw new Exception($"终点库位【{taskDTO.toLocationCode}】当前库位状态不是空闲!");
                var dt_Task = new Dt_Task()
                {
                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    WMSTaskNum = taskDTO.taskCode,
                    //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    Grade = taskDTO.taskPriority,
                    PalletCode = taskDTO.containerCode,
                    Roadway = "1",
                    TaskState = (int)TaskStatusEnum.New,
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = taskDTO.toLocationCode,
                    TargetAddress = taskDTO.toLocationCode,
                    Creater = "WMS",
                };
                content = SendHIKROBOTTask(dt_Task);
                if (!content.Status) throw new Exception(content.Message);
                dt_Task.Dispatchertime = DateTime.Now;
                BaseDal.AddData(dt_Task);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        #endregion
    }