dengjunjie
2026-03-06 b834b2c0977af30a5040c9b8416d930608fc845d
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -18,12 +18,18 @@
using AutoMapper;
using SqlSugar;
using System.Diagnostics.CodeAnalysis;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.LocationEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO;
using WIDESEAWCS_DTO.AGV.HIKROBOT;
using WIDESEAWCS_DTO.RGV.FOURBOT;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_DTO.WMS;
using WIDESEAWCS_IBasicInfoService;
@@ -36,12 +42,15 @@
{
    public partial class TaskService : ServiceBase<Dt_Task, IRepository<Dt_Task>>, ITaskService
    {
        private readonly ITrackloginfoService _trackloginfoService;
        private readonly IRouterService _routerService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IHKLocationInfoService _hKLocationInfoService;
        private readonly IKLSLocationInfoService _kLSLocationInfoService;
        private readonly IRGVLocationInfoService _rGVLocationInfoService;
        private readonly IRepository<Dt_TaskExecuteDetail> _taskExecuteDetailRepository;
        private readonly IApiInfoService _apiInfoService;
        private readonly IStationMangerService _stationMangerService;
        private readonly IMapper _mapper;
        private Dictionary<string, OrderByType> _taskOrderBy = new()
@@ -61,7 +70,7 @@
        /// </summary>
        public IRepository<Dt_Task> Repository => BaseDal;
        public TaskService(IRepository<Dt_Task> BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, IRepository<Dt_TaskExecuteDetail> taskExecuteDetailRepository, IMapper mapper, IKLSLocationInfoService kLSLocationInfoService, IRGVLocationInfoService rGVLocationInfoService, IHKLocationInfoService hKLocationInfoService) : base(BaseDal)
        public TaskService(IRepository<Dt_Task> BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, IRepository<Dt_TaskExecuteDetail> taskExecuteDetailRepository, IMapper mapper, IKLSLocationInfoService kLSLocationInfoService, IRGVLocationInfoService rGVLocationInfoService, IHKLocationInfoService hKLocationInfoService, IApiInfoService apiInfoService, ITrackloginfoService trackloginfoService, IStationMangerService stationMangerService) : base(BaseDal)
        {
            _routerService = routerService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -70,6 +79,9 @@
            _kLSLocationInfoService = kLSLocationInfoService;
            _rGVLocationInfoService = rGVLocationInfoService;
            _hKLocationInfoService = hKLocationInfoService;
            _apiInfoService = apiInfoService;
            _trackloginfoService = trackloginfoService;
            _stationMangerService=stationMangerService;
        }
        public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTasksDTO> taskDTOs)
        {
@@ -86,10 +98,35 @@
                        {
                            continue;
                        }
                        if (item.taskType == TaskTypeEnum.MLInbound.ObjToInt())
                            CreateKLSNewInTask(task, item.taskType);
                        else if (item.taskType == TaskTypeEnum.MLOutbound.ObjToInt())
                            CreateKLSNewOutTask(task, item.taskType);
                        switch (item.taskType)
                        {
                            case (int)TaskTypeEnum.MLInbound:
                                CreateKLSNewInTask(task, item.taskType);
                                break;
                            case (int)TaskTypeEnum.MLOutbound:
                                CreateKLSNewOutTask(task, item.taskType);
                                break;
                            case (int)TaskTypeEnum.CPInbound:
                                CreateRGVNewInTask(task, item.taskType);
                                break;
                            case (int)TaskTypeEnum.CPOutbound:
                                CreateRGVNewOutTask(task, item.taskType);
                                break;
                            case (int)TaskTypeEnum.CJInbound:
                                CreateHKNewInTask(task, item.taskType);
                                break;
                            case (int)TaskTypeEnum.CJOutbound:
                                CreateHKNewOutTask(task, item.taskType);
                                break;
                            case (int)TaskTypeEnum.Carry:
                                CarryTask(task, item.taskType);
                                break;
                            case (int)TaskTypeEnum.CJCarry:
                                CJCarryTaske(task, item.taskType);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
@@ -99,6 +136,280 @@
            }
            return content;
        }
        /// <summary>
        /// å–消任务
        /// </summary>
        /// <param name="taskCode">任务号</param>
        /// <param name="containerCode">料箱条码</param>
        /// <returns></returns>
        public WebResponseContent CancelWMSTask(WMSCancelTask wMSCancelTask)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_Task dt_Task = BaseDal.QueryFirst(x => x.WMSTaskNum == wMSCancelTask.TaskCode);
                if (dt_Task == null) throw new Exception("未查询到任务号相关任务");
                // åˆ¤æ–­å½“前任务是否为凯乐士任务
                bool isGALAXISTask = dt_Task.TaskType == (int)TaskTypeEnum.MLInbound ||
                                    dt_Task.TaskType == (int)TaskTypeEnum.MLOutbound;
                //四向车
                bool isAGV = dt_Task.TaskType == (int)TaskTypeEnum.CPInbound || dt_Task.TaskType == (int)TaskTypeEnum.CPOutbound;
                //海康
                bool isHK = dt_Task.TaskType == (int)TaskTypeEnum.Carry || dt_Task.TaskType == (int)TaskTypeEnum.CJInbound || dt_Task.TaskType == (int)TaskTypeEnum.CJInbound || dt_Task.TaskType == (int)TaskTypeEnum.CJOutbound;
                //这里将状态改变了198取消任务
                dt_Task.TaskType = TaskStatusEnum.WMSCancel.ObjToInt();
                #region å‡¯ä¹å£«
                if (isGALAXISTask)
                {
                    var KLS = new CancelGALAXISTask
                    {
                        taskId = dt_Task.WMSTaskNum,
                        reportTime = DateTime.Now.ToString()
                    };
                    Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(CancelGALAXISTask));
                    if (apiInfo == null) throw new Exception("未找到凯乐士AGV任务下发接口配置信息!请检查接口配置");
                    string response = HttpHelper.Post(apiInfo.ApiAddress, KLS.Serialize());
                    GALAXISReturn agvContent = response.DeserializeObject<GALAXISReturn>();
                    if (agvContent.success == true && agvContent.code == 0)
                    {
                        //直接移入历史
                        BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动完成);
                        return content.OK("取消任务成功", dt_Task);
                    }
                    else
                    {
                        return content.Error($"任务失败{agvContent.data.returnInfo}");
                    }
                }
                #endregion
                #region å››å‘车
                if (isAGV)
                {
                    CancelSXCTake cancelSXCTake = new CancelSXCTake
                    {
                        taskID = dt_Task.RGVTaskId
                    };
                    Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(CancelSXCTake));
                    if (apiInfo == null) throw new Exception("未找到四向车AGV任务下发接口配置信息!请检查接口配置");
                    string response = HttpHelper.Post(apiInfo.ApiAddress, cancelSXCTake.Serialize());
                    FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                    if (fOURBOTReturn.returnCode == 0 && fOURBOTReturn.returnUserMsg == "成功")
                    {
                        //直接移入历史
                        BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动完成);
                        return content.OK("取消任务成功", dt_Task);
                    }
                    else
                    {
                        return content.Error($"任务失败{fOURBOTReturn.data}");
                    }
                }
                #endregion
                #region æµ·åº·
                if (isHK)
                {
                    CancelHIKROBOTTask cancelHIKROBOTTask = new CancelHIKROBOTTask
                    {
                        robotTaskCode = dt_Task.WMSTaskNum,
                        cancelType = "CANCEL"//原软取消,DROP人工介入(原硬取消)
                    };
                    Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(CancelHIKROBOTTask));
                    if (apiInfo == null) throw new Exception("未找到四向车AGV任务下发接口配置信息!请检查接口配置");
                    string response = HttpHelper.Post(apiInfo.ApiAddress, cancelHIKROBOTTask.Serialize());
                    HIKROBOTReturn hIKROBOTReturn = response.DeserializeObject<HIKROBOTReturn>();
                    if (hIKROBOTReturn.code == "SUCCESS" && hIKROBOTReturn.message == "成功")
                    {
                        //直接移入历史
                        BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动完成);
                        return content.OK("取消任务成功", dt_Task);
                    }
                    else
                    {
                        return content.Error($"任务失败{hIKROBOTReturn.data}");
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// ä¿®æ”¹ä»»åŠ¡ä¼˜å…ˆçº§
        /// </summary>
        /// <param name="updateTaskPriority"></param>
        /// <returns></returns>
        public WebResponseContent UpdateWMSTaskPriority(WMSUpdateTaskPriority updateTaskPriority)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_Task dt_Task = BaseDal.QueryFirst(x => x.WMSTaskNum == updateTaskPriority.taskCode);
                if (dt_Task == null) throw new Exception("未查询到任务号相关任务");
                // åˆ¤æ–­å½“前任务是否为凯乐士任务
                bool isGALAXISTask = dt_Task.TaskType == (int)TaskTypeEnum.MLInbound ||
                                    dt_Task.TaskType == (int)TaskTypeEnum.MLOutbound;
                //四向车
                bool isAGV = dt_Task.TaskType == (int)TaskTypeEnum.CPInbound || dt_Task.TaskType == (int)TaskTypeEnum.CPOutbound;
                //海康
                bool isHK = dt_Task.TaskType == (int)TaskTypeEnum.Carry || dt_Task.TaskType == (int)TaskTypeEnum.CJInbound || dt_Task.TaskType == (int)TaskTypeEnum.CJInbound || dt_Task.TaskType == (int)TaskTypeEnum.CJOutbound;
                //修改原本任务优先级
                dt_Task.Grade = updateTaskPriority.taskPriority;
                #region å‡¯ä¹å£«
                if (isGALAXISTask)
                {
                    var updateGALAXISTaskGrade = new UpdateGALAXISTaskGrade
                    {
                        taskId = dt_Task.WMSTaskNum,
                        reportTime = DateTime.Now.ToString(),
                        district = dt_Task.Roadway,//任务库区
                        priorityCode = updateTaskPriority.taskPriority,
                    };
                    Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(UpdateGALAXISTaskGrade));
                    if (apiInfo == null) throw new Exception("未找到凯乐士AGV任务下发接口配置信息!请检查接口配置");
                    string response = HttpHelper.Post(apiInfo.ApiAddress, updateGALAXISTaskGrade.Serialize());
                    GALAXISReturn agvContent = response.DeserializeObject<GALAXISReturn>();
                    if (agvContent.success == true && agvContent.code == 0)
                    {
                        BaseDal.UpdateData(dt_Task);
                        return content.OK("修改任务优先级成功", dt_Task);
                    }
                    else
                    {
                        return content.Error($"任务失败{agvContent.data.returnInfo}");
                    }
                }
                #endregion
                #region å››å‘车
                if (isAGV)
                {
                    var request = new UpdateAgvSXCTake
                    {
                        taskID = dt_Task.RGVTaskId,
                        priority = updateTaskPriority.taskPriority
                    };
                    Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(UpdateAgvSXCTake));
                    if (apiInfo == null) throw new Exception("未找到四向车AGV任务下发接口配置信息!请检查接口配置");
                    string response = HttpHelper.Post(apiInfo.ApiAddress, request.Serialize());
                    FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                    if (fOURBOTReturn.returnCode == 0 && fOURBOTReturn.returnUserMsg == "成功")
                    {
                        BaseDal.UpdateData(dt_Task);
                        return content.OK("修改任务优先级成功", dt_Task);
                    }
                    else
                    {
                        return content.Error($"任务失败{fOURBOTReturn.data}");
                    }
                }
                #endregion
                #region æµ·åº·
                if (isHK)
                {
                    var request = new HIKROBOTTaskGrade
                    {
                        robotTaskCode = dt_Task.WMSTaskNum,//任务号
                        initPriority = updateTaskPriority.taskPriority//优先级
                    };
                    Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(HIKROBOTTaskGrade));
                    if (apiInfo == null) throw new Exception("未找到四向车AGV任务下发接口配置信息!请检查接口配置");
                    string response = HttpHelper.Post(apiInfo.ApiAddress, request.Serialize());
                    HIKROBOTReturn hIKROBOTReturn = response.DeserializeObject<HIKROBOTReturn>();
                    if (hIKROBOTReturn.code == "SUCCESS0" && hIKROBOTReturn.message == "成功")
                    {
                        BaseDal.UpdateData(dt_Task);
                        return content.OK("修改任务优先级成功", dt_Task);
                    }
                    else
                    {
                        return content.Error($"任务失败{hIKROBOTReturn.data}");
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// ä¿®æ”¹åº“位分区
        /// </summary>
        /// <returns></returns>
        public WebResponseContent ModifyWMSLayoutZone(WMSUpdateLocationArea wMSUpdateLocationArea)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var rgv = new List<Dt_RGVLocationInfo>();
                var kls = new List<Dt_KLSLocationInfo>();
                var hk = new List<Dt_HKLocationInfo>();
                if (wMSUpdateLocationArea.WarehouseId == 1)
                {
                    var rgvList = _rGVLocationInfoService.Repository.QueryData(x => wMSUpdateLocationArea.LocationCodes.Contains(x.LocationCode)).ToList();
                    foreach (var item in rgvList)
                    {
                        item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    rgv.AddRange(rgvList);
                }
                if (wMSUpdateLocationArea.WarehouseId == 2)
                {
                    var KLSLocationInfoList = _kLSLocationInfoService.Repository.QueryData(x => wMSUpdateLocationArea.LocationCodes.Contains(x.LocationCode)).ToList();
                    foreach (var item in KLSLocationInfoList)
                    {
                        item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    kls.AddRange(KLSLocationInfoList);
                }
                if (wMSUpdateLocationArea.WarehouseId == 3)
                {
                    var hkList = _hKLocationInfoService.Repository.QueryData(x => wMSUpdateLocationArea.LocationCodes.Contains(x.LocationCode)).ToList();
                    foreach (var item in hkList)
                    {
                        item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    hk.AddRange(hkList);
                }
                Db.Ado.BeginTran();
                _rGVLocationInfoService.UpdateData(rgv);
                _kLSLocationInfoService.UpdateData(kls);
                _hKLocationInfoService.UpdateData(hk);
                Db.Ado.CommitTran();
                content.OK();
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        private void UpdateLocationCode(object LocationInfo, string updateAreaCode)
        {
        }
        /// <summary>
        /// æŽ¥æ”¶WMS任务信息
        /// </summary>
@@ -636,5 +947,146 @@
                return Db.Ado.GetScalar($"SELECT NEXT VALUE FOR {sequenceName}").ObjToInt();
            }
        }
        /// <summary>
        /// åŒºåŸŸåº“位信息查询
        /// </summary>
        /// <param name="AreaCode"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException">区域号</exception>
        public WebResponseContent LocationInquiry(string AreaCode)
        {
            if (AreaCode == null)
            {
                //查询输送线空托缓存信息时返回空位数量
            }
            return WebResponseContent.Instance.OK();
        }
        /// <summary>
        /// åœ°å›¾åŒæ­¥
        /// </summary>
        /// <param name="mapSynchronizationDto"></param>
        /// <returns></returns>
        public WebResponseContent MapSynchronize(MapSynchronizationDto mapSynchronizationDto)
        {
            return WebResponseContent.Instance;
        }
        /// <summary>
        /// å‡ºå…¥åº“完成
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent InandoutCompleted(WMSInOutBoundCompleteFeedback wMSInOutBoundCompleteFeedback)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// æ–™ç®±éªŒè¯
        /// </summary>
        /// <param name="taskCode">任务号</param>
        /// <param name="containerCode">容器编码</param>
        /// <returns></returns>
        public WebResponseContent MaterialBoxInspection(string taskCode, string containerCode)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// wcs移库数据回传
        /// </summary>
        /// <param name="wMSMoveLocationFeedback"></param>
        public WebResponseContent WcsMovingDataBack(WMSMoveLocationFeedback wMSMoveLocationFeedback)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// å®¹å™¨æµåŠ¨è¯·æ±‚
        /// </summary>
        /// <param name="wMSContainerFlow"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent ContainerRequest(WMSContainerFlow wMSContainerFlow)
        {
            try
            {
                Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == wMSContainerFlow.slotCode) ?? throw new Exception($"未找到站台【{wMSContainerFlow.slotCode}】信息");
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == "releaseStation") ?? throw new Exception("未找到站点容器释放接口配置信息!请检查接口配置");
                if (wMSContainerFlow.direction == "200")
                {
                    stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
                    FOURBOToccupyStation fOURBOToccupyStation = new FOURBOToccupyStation()
                    {
                        stationCode = wMSContainerFlow.slotCode,
                    };
                    string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOToccupyStation.Serialize());
                    FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                    if (fOURBOTReturn.returnCode != 0) throw new Exception(fOURBOTReturn.returnUserMsg);
                    _stationMangerService.UpdateData(stationManger);
                }
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// è´¨æ£€ç»“果反馈
        /// </summary>
        /// <param name="iQC"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent IQCResult(IQCResultDTO iQC)
        {
            try
            {
                Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == iQC.StationCode) ?? throw new Exception($"未找到站台【{iQC.StationCode}】信息");
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOToccupyStation)) ?? throw new Exception("未找到站点容器上架接口配置信息!请检查接口配置");
                FOURBOToccupyStation fOURBOToccupyStation = new FOURBOToccupyStation()
                {
                    stationCode = iQC.StationCode,
                    podID = iQC.ContainerCode,
                };
                string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOToccupyStation.Serialize());
                FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                if (fOURBOTReturn.returnCode != 0) throw new Exception(fOURBOTReturn.returnUserMsg);
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// æ‰¹é‡æ›´æ–°å‚¨ä½çŠ¶æ€
        /// </summary>
        /// <param name="fOURBOTStorageStatusNotify"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent multiSetNodeStatus(FOURBOTStorageStatusNotify fOURBOTStorageStatusNotify)
        {
            try
            {
                var Agvlocation = _rGVLocationInfoService.Repository.QueryData(x => fOURBOTStorageStatusNotify.storageCode.Contains(x.LocationCode));
                foreach (var item in Agvlocation)
                {
                    item.LocationStatus = (int)(fOURBOTStorageStatusNotify.disable == 0 ? EnableStatusEnum.Normal : EnableStatusEnum.Disable);
                }
                _rGVLocationInfoService.UpdateData(Agvlocation);
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
    }
}