dengjunjie
2026-03-03 2744064f23c2233fb700970801d2ddc802f38160
优化四向车任务下发
已修改10个文件
175 ■■■■ 文件已修改
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/HKLocationInfoService.cs 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_IBasicInfoService/IHKLocationInfoService.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Model/Models/TaskInfo/Dt_Task.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/appsettings.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/HKTaskExtend.cs 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs 87 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/TaskExtend.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/TaskJob.cs 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/HKLocationInfoService.cs
@@ -1,10 +1,13 @@
using System;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.LocationEnum;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_Model.Models;
@@ -15,7 +18,19 @@
        public HKLocationInfoService(IRepository<Dt_HKLocationInfo> BaseDal) : base(BaseDal)
        {
        }
        private Dictionary<string, OrderByType> _emptyAssignOrderBy = new Dictionary<string, OrderByType>()
        {
            { nameof(Dt_HKLocationInfo.Depth), OrderByType.Desc },
            { nameof(Dt_HKLocationInfo.Layer), OrderByType.Asc },
            { nameof(Dt_HKLocationInfo.Column), OrderByType.Asc },
            { nameof(Dt_HKLocationInfo.Row), OrderByType.Asc },
        };
        public IRepository<Dt_HKLocationInfo> Repository => BaseDal;
        public Dt_HKLocationInfo? GetFreeLocationInfo(string toAreaCode)
        {
            Dt_HKLocationInfo hKLocationInfo = BaseDal.QueryFirst(x => x.WarehouseId.ToString() == toAreaCode && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt(), _emptyAssignOrderBy);
            return hKLocationInfo;
        }
    }
}
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_IBasicInfoService/IHKLocationInfoService.cs
@@ -12,5 +12,7 @@
    public interface IHKLocationInfoService : IService<Dt_HKLocationInfo>
    {
        public IRepository<Dt_HKLocationInfo> Repository { get; }
        Dt_HKLocationInfo? GetFreeLocationInfo(string toAreaCode);
    }
}
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Model/Models/TaskInfo/Dt_Task.cs
@@ -66,7 +66,7 @@
        /// </summary>
        [ImporterHeader(Name = "区域")]
        [ExporterHeader(DisplayName = "区域")]
        [SugarColumn(IsNullable = true, Length = 10, ColumnDescription = "区域")]
        [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "区域")]
        public string Roadway { get; set; }
        /// <summary>
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/appsettings.json
@@ -33,7 +33,7 @@
    "DBSeedEnable": false,
    "QuartzDBSeedEnable": false,
    "LogDeubgEnable": true, //是否记录调试日志
    "PrintSql": false, //打印SQL语句
    "PrintSql": true, //打印SQL语句
    "LogAOPEnable": true, //是否记录AOP日志
    "WebSocketEnable": true, //是否开启WebSocket服务
    "WebSocketPort": 9296 //WebSocket服务端口
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs
@@ -27,10 +27,8 @@
        {
            try
            {
                int containerType = taskDTO.containerCode.Contains("LX") ? LocationTypeEnum.LargePallet.ObjToInt() : LocationTypeEnum.SmallPallet.ObjToInt();
                //获取货位信息
                Dt_HKLocationInfo? kLSLocationInfo = _hKLocationInfoService.Repository.QueryFirst(x => x.WarehouseId.ToString() == taskDTO.toAreaCode && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.LocationType == containerType);
                if (kLSLocationInfo == null) throw new Exception($"未找到终点库区【{taskDTO.toAreaCode}】可用空货位!");
                Dt_HKLocationInfo? hKLocationInfo = _hKLocationInfoService.GetFreeLocationInfo(taskDTO.toAreaCode) ?? throw new Exception($"未找到终点库区【{taskDTO.toAreaCode}】可用空货位!"); ;
                Dt_Task dt_Task = new Dt_Task()
                {
                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
@@ -38,19 +36,19 @@
                    //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    Grade = taskDTO.taskPriority,
                    PalletCode = taskDTO.containerCode,
                    Roadway = kLSLocationInfo.RoadwayNo,
                    Roadway = hKLocationInfo.RoadwayNo,
                    TaskState = TaskStatusEnum.New.ObjToInt(),
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = kLSLocationInfo.LocationCode,
                    TargetAddress = kLSLocationInfo.LocationCode,
                    NextAddress = hKLocationInfo.LocationCode,
                    TargetAddress = hKLocationInfo.LocationCode,
                    Creater = "WMS",
                };
                kLSLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
                hKLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
                Db.Ado.BeginTran();
                BaseDal.AddData(dt_Task);
                _hKLocationInfoService.Repository.UpdateData(kLSLocationInfo);
                _hKLocationInfoService.Repository.UpdateData(hKLocationInfo);
                Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
            }
@@ -70,8 +68,7 @@
        {
            try
            {
                Dt_HKLocationInfo? hKLocationInfo = _hKLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode);
                if (hKLocationInfo == null) throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                Dt_HKLocationInfo? hKLocationInfo = _hKLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                if (hKLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不可出库!");
                Dt_Task dt_Task = new Dt_Task()
                {
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs
@@ -103,8 +103,16 @@
        #region 5 è·¨æ¥¼å±‚运输任务创建
        public WebResponseContent CarryTask(TaskDTO taskDTO, int taskType)
        {
            try
            {
            return WebResponseContent.Instance.OK();
        }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/HKTaskExtend.cs
@@ -1,19 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core;
using WIDESEAWCS_DTO.AGV.HIKROBOT;
using WIDESEAWCS_Model.Models;
namespace WIDESEAWCS_Tasks
{
    public partial class TaskJob
    {
        #region å¤„理海康AGV任务
        public void HIKROBOTTask(List<Dt_Task> tasks)
        {
            foreach (var item in tasks)
            {
                SendHIKROBOTTask(item);
            }
        }
        #endregion
        #region ä¸‹å‘海康AGV任务
        public void SendHIKROBOTTask(List<Dt_Task> tasks)
        public void SendHIKROBOTTask(Dt_Task task)
        {
            WebResponseContent content = new WebResponseContent();
            HIKROBOTTaskSubmit hIKROBOTTaskSubmit = new HIKROBOTTaskSubmit();
            try
            {
                hIKROBOTTaskSubmit.taskType = "";
                hIKROBOTTaskSubmit.targetRoute = new List<TargetRouteDto> { new TargetRouteDto() };
                hIKROBOTTaskSubmit.initPriority = task.Grade;
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            finally
        {
        }
        }
        #endregion
    }
}
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs
@@ -7,6 +7,7 @@
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.LocationEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO;
using WIDESEAWCS_DTO.RGV.FOURBOT;
@@ -128,56 +129,98 @@
        /// <param name="tasks"></param>
        public void SendCheckShapeingOkTask(List<Dt_Task> tasks)
        {
            FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
            try
            {
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("未找到四向车任务下发接口配置信息!请检查接口配置");
                List<Dt_RGVLocationInfo> rGVLocationInfos = new List<Dt_RGVLocationInfo>();
                List<Dt_StationManger> stationMangers = new List<Dt_StationManger>();
                var tasksToUpdate = new List<Dt_Task>();
                var locationsToUpdate = new List<Dt_RGVLocationInfo>();
                var stationsToUpdate = new List<Dt_StationManger>();
                #region ä»»åŠ¡ä¸‹å‘
                foreach (var item in tasks)
                {
                    try
                {
                    #region èŽ·å–è´§ä½
                    var rGVLocationInfo = _rGVLocationInfoService.GetFreeLocationInfo(item.Roadway);
                    if (rGVLocationInfo == null)
                    {
                        item.ExceptionMessage = $"未找到终点库区【{item.Roadway}】可用空货位!";
                            continue;
                    }
                    #endregion
                    else
                        var fOURBOTnewMovePodTask = new FOURBOTnewMovePodTask
                    {
                            priority = item.Grade,
                            podID = item.PalletCode,
                            destination = rGVLocationInfo.LocationCode,
                            desExt = new { unload = 1 }, // æ˜¯å¦æ”¾ä¸‹å®¹å™¨,0否1是
                            desType = 2
                        };
                        item.CurrentAddress = item.NextAddress;
                        item.NextAddress = rGVLocationInfo.LocationCode;
                        item.Roadway = rGVLocationInfo.RoadwayNo;
                        fOURBOTnewMovePodTask.priority = item.Grade;
                        fOURBOTnewMovePodTask.podID = item.PalletCode;
                        fOURBOTnewMovePodTask.destination = item.NextAddress;
                        fOURBOTnewMovePodTask.desExt = new
                        {
                            unload = 1//是否放下容器,0否1是
                        };
                        fOURBOTnewMovePodTask.desType = 2;
                        string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
                        FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                        var fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                        if (fOURBOTReturn.returnCode == 0)
                        {
                            FOURBOTnewMovePodTaskResponseData fOURBO = fOURBOTReturn.data as FOURBOTnewMovePodTaskResponseData ?? throw new Exception("未获取到四向车返回的任务ID");
                            var data = fOURBOTReturn.data.ToString();
                            var fOURBO = data.DeserializeObject<FOURBOTnewMovePodTaskResponseData>();
                            item.RGVTaskId = fOURBO.taskID;
                            item.TaskState = (int)TaskStatusEnum.Puting;
                            rGVLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
                            rGVLocationInfos.Add(rGVLocationInfo);
                            locationsToUpdate.Add(rGVLocationInfo);
                            #region é‡Šæ”¾å…¥åº“站台
                            Dt_StationManger stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
                            var stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
                            if (stationManger != null)
                            {
                            stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
                            stationMangers.Add(stationManger);
                                stationsToUpdate.Add(stationManger);
                            }
                            #endregion
                        }
                        else
                        {
                            item.ExceptionMessage = $"四向车接口返回错误:{fOURBOTReturn.returnMsg}";
                            // è®°å½•失败的任务
                    }
                }
                _taskService.Db.Ado.BeginTran();
                _taskService.UpdateData(tasks);
                _rGVLocationInfoService.UpdateData(rGVLocationInfos);
                _stationMangerService.UpdateData(stationMangers);
                _taskService.Db.Ado.CommitTran();
                    catch (Exception ex)
                    {
                        item.ExceptionMessage = $"处理任务异常:{ex.Message}";
                        WriteError($"{nameof(TaskJob)}-{item.TaskId}", ex.Message, ex);
                    }
                    tasksToUpdate.Add(item);
                }
                #endregion
                #region æ›´æ–°æ•°æ®
                // å¦‚果有需要更新的数据,才执行事务
                if (tasksToUpdate.Any() || locationsToUpdate.Any() || stationsToUpdate.Any())
                {
                    try
                    {
                        _unitOfWorkManage.BeginTran();
                        if (tasksToUpdate.Any())
                            _taskService.UpdateData(tasksToUpdate);
                        if (locationsToUpdate.Any())
                            _rGVLocationInfoService.UpdateData(locationsToUpdate);
                        if (stationsToUpdate.Any())
                            _stationMangerService.UpdateData(stationsToUpdate);
                        _unitOfWorkManage.CommitTran();
                    }
                    catch (Exception ex)
                    {
                        _unitOfWorkManage.RollbackTran();
                        WriteError(nameof(TaskJob), ex.Message, ex);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/TaskExtend.cs
@@ -39,7 +39,7 @@
                    
                    #region æŸ¥æ‰¾æµ·åº·AGV任务
                    Tasks = newTasks.Where(x => x.TaskType == (int)TaskTypeEnum.Carry || x.TaskType == (int)TaskTypeEnum.CJCarry || x.TaskType == (int)TaskTypeEnum.CJInbound || x.TaskType == (int)TaskTypeEnum.CJOutbound).ToList();
                    if (Tasks.Count > 0) SendHIKROBOTTask(Tasks);
                    if (Tasks.Count > 0) HIKROBOTTask(Tasks);
                    #endregion
                }
            }
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/TaskJob.cs
@@ -4,6 +4,7 @@
using Microsoft.VisualBasic.FileIO;
using Quartz;
using SixLabors.ImageSharp.PixelFormats;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -13,6 +14,7 @@
using System.Threading.Tasks;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoService;
@@ -31,14 +33,16 @@
        private readonly IRGVLocationInfoService _rGVLocationInfoService;
        private readonly IStationMangerService _stationMangerService;
        private readonly ITrackloginfoService _trackloginfoService;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        public TaskJob(ITaskService taskService, IApiInfoService apiInfoService, IRGVLocationInfoService rGVLocationInfoService, IStationMangerService stationMangerService, ITrackloginfoService trackloginfoService)
        public TaskJob(ITaskService taskService, IApiInfoService apiInfoService, IRGVLocationInfoService rGVLocationInfoService, IStationMangerService stationMangerService, ITrackloginfoService trackloginfoService, IUnitOfWorkManage unitOfWorkManage)
        {
            _taskService = taskService;//注入
            _apiInfoService = apiInfoService;
            _rGVLocationInfoService = rGVLocationInfoService;
            _stationMangerService = stationMangerService;
            _trackloginfoService = trackloginfoService;
            _unitOfWorkManage = unitOfWorkManage;
        }
        public Task Execute(IJobExecutionContext context)