dengjunjie
2026-03-12 38072f522dd49da33b22f604fb6b262e884b8a32
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs
@@ -5,29 +5,172 @@
using System.Threading.Tasks;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Core;
using WIDESEAWCS_DTO.TaskInfo;
using SqlSugar.Extensions;
using WIDESEAWCS_DTO.WMS;
using WIDESEAWCS_Common.LocationEnum;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
namespace WIDESEAWCS_TaskInfoService
{
    public partial class TaskService
    {
      /// <summary>
      /// åˆ›å»ºå…¥åº“任务
      /// </summary>
      /// <param name="taskDTO"></param>
      /// <returns></returns>
        public WebResponseContent CreateNewInTask(TaskDTO taskDTO)
        #region å‡¯ä¹å£«ä»»åŠ¡åˆ›å»º
        /// <summary>
        /// åˆ›å»ºå‡¯ä¹å£«AGV入库任务
        /// </summary>
        /// <param name="taskDTO"></param>
        /// <returns></returns>
        public WebResponseContent CreateKLSNewInTask(TaskDTO taskDTO, int taskType)
        {
         try
         {
            WebResponseContent content = new WebResponseContent();
            try
            {
                int containerType = taskDTO.containerCode.Contains("LLM") ? LocationTypeEnum.LargePallet.ObjToInt() : LocationTypeEnum.SmallPallet.ObjToInt();
                #region ç‚¹åˆ°ç‚¹
                if (!string.IsNullOrEmpty(taskDTO.toLocationCode))
                {
                    var LocationInfo = _kLSLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点货位【{taskDTO.toLocationCode}】");
                    if (LocationInfo.LocationStatus != LocationStatusEnum.Free.ObjToInt()) throw new Exception($"终点货位【{taskDTO.toLocationCode}】货位状态不为空货位");
                }
                #endregion
                //获取货位信息
            //List<Dt_KLSLocationInfo> kLSLocationInfos=
                return WebResponseContent.Instance.OK();
         }
         catch (Exception ex)
         {
            return WebResponseContent.Instance.Error(ex.Message);
         }
                Dt_KLSLocationInfo? kLSLocationInfo = _kLSLocationInfoService.GetFreeLocationInfo(taskDTO.toAreaCode, containerType) ?? throw new Exception($"未找到终点库区【{taskDTO.toAreaCode}】可用空货位!");
                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 = kLSLocationInfo.RoadwayNo,
                    TaskState = TaskStatusEnum.New.ObjToInt(),
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = kLSLocationInfo.LocationCode,
                    TargetAddress = kLSLocationInfo.LocationCode,
                    Creater = "WMS",
                };
                kLSLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
                try
                {
                    Db.Ado.BeginTran();
                    BaseDal.AddData(dt_Task);
                    _kLSLocationInfoService.Repository.UpdateData(kLSLocationInfo);
                    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);
            }
        }
        /// <summary>
        /// åˆ›å»ºå‡¯ä¹å£«AGV出库任务
        /// </summary>
        /// <param name="taskDTO"></param>
        /// <param name="taskType"></param>
        /// <returns></returns>
        public WebResponseContent CreateKLSNewOutTask(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_KLSLocationInfo? kLSLocationInfo = _kLSLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                if (kLSLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) 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 = kLSLocationInfo.RoadwayNo,
                    TaskState = TaskStatusEnum.New.ObjToInt(),
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = taskDTO.toLocationCode,
                    TargetAddress = taskDTO.toLocationCode,
                    Creater = "WMS",
                };
                kLSLocationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt();
                try
                {
                    Db.Ado.BeginTran();
                    BaseDal.AddData(dt_Task);
                    _kLSLocationInfoService.Repository.UpdateData(kLSLocationInfo);
                    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
        #region 5 è·¨æ¥¼å±‚运输任务创建
        public WebResponseContent CarryTask(TaskDTO taskDTO, int taskType)
        {
            try
            {
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
        #region 6 è£å‰ªé€è´§
        public WebResponseContent CJCarryTaske(TaskDTO taskDTO, int taskType)
        {
            try
            {
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
    }
}