dengjunjie
5 天以前 f56f8d4bf3bf088579a169519ef2547d40586f76
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -57,6 +57,7 @@
        private readonly IApiInfoService _apiInfoService;
        private readonly IStationMangerService _stationMangerService;
        private readonly IStationInfoService _stationInfo;
        private readonly ITaskErrorMessageService _taskErrorMessageService;
        private readonly IMapper _mapper;
        private Dictionary<string, OrderByType> _taskOrderBy = new()
@@ -76,7 +77,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, IApiInfoService apiInfoService, ITrackloginfoService trackloginfoService, IStationMangerService stationMangerService, IStationInfoService stationInfo) : 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, IStationInfoService stationInfo, ITaskErrorMessageService taskErrorMessageService) : base(BaseDal)
        {
            _routerService = routerService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -89,6 +90,7 @@
            _trackloginfoService = trackloginfoService;
            _stationMangerService = stationMangerService;
            _stationInfo = stationInfo;
            _taskErrorMessageService = taskErrorMessageService;
        }
        public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTasksDTO> taskDTOs)
        {
@@ -189,9 +191,9 @@
                                content = HKF01Transport(task, item.taskType);
                                break;
                            case (int)TaskTypeEnum.F04:
                            case (int)TaskTypeEnum.F03:
                            case (int)TaskTypeEnum.F02:
                            case (int)TaskTypeEnum.RK3F:
                            case (int)TaskTypeEnum.F02:
                            case (int)TaskTypeEnum.F03:
                            case (int)TaskTypeEnum.CK3F:
                                content = CJCarryTaske(task, item.taskType);
                                objects.Add(content.Data);
@@ -1237,11 +1239,11 @@
        public WebResponseContent InboundElevatorExit(string LocationCode, string containerCode)
        {
            WebResponseContent content = new WebResponseContent();
            inboundElevatorExitDTO inboundElevator=new inboundElevatorExitDTO();
            inboundElevatorExitDTO inboundElevator = new inboundElevatorExitDTO();
            try
            {
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(inboundElevatorExitDTO)) ?? throw new Exception("未找到4F提升机出口托盘号上报WMS接口配置信息!请检查接口配置");
                inboundElevator.containerCode= containerCode;
                inboundElevator.containerCode = containerCode;
                inboundElevator.toLocationCode = LocationCode;
                string response = HttpHelper.Post(apiInfo.ApiAddress, inboundElevator.Serialize());
                content.OK(data: response);
@@ -1278,6 +1280,7 @@
                string dataJson = wMSReturn.result.ToString();
                Exists? exists = JsonConvert.DeserializeObject<Exists>(dataJson);
                if (exists == null) throw new Exception($"WMS返回结果的result转换失败");
                if (exists.taskExists) return WebResponseContent.Instance.OK();
                return WebResponseContent.Instance.OK(exists.errorAreaCode);
            }
            catch (Exception ex)
@@ -1299,6 +1302,41 @@
            throw new NotImplementedException();
        }
        /// <summary>
        /// å¹³åº“货位上下架容器
        /// </summary>
        /// <param name="wMSUpOrDown"></param>
        /// <returns></returns>
        public WebResponseContent UpOrDownContainer(WMSUpOrDownContainerDTO wMSUpOrDown)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StationInfo stationInfo = _stationInfo.Repository.QueryFirst(x => x.StationCode == wMSUpOrDown.locationCode) ?? throw new Exception($"未找到货位【{wMSUpOrDown.locationCode}】信息");
                if (wMSUpOrDown.direction == 1)
                {
                    stationInfo.StationStatus = LocationStatusEnum.InStock.ObjToInt();
                    stationInfo.PalletCode = wMSUpOrDown.containerCode;
                }
                else
                {
                    stationInfo.StationStatus = LocationStatusEnum.Free.ObjToInt();
                    stationInfo.PalletCode = "";
                }
                _stationInfo.UpdateData(stationInfo);
                content.OK();
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            finally
            {
                _trackloginfoService.AddTrackLog(wMSUpOrDown, content, "平库货位上下架容器", "", "");
            }
            return content;
        }
        /// <summary>
        /// å®¹å™¨æµåŠ¨è¯·æ±‚
        /// </summary>
        /// <param name="wMSContainerFlow"></param>
@@ -1306,6 +1344,7 @@
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent ContainerRequest(WMSContainerFlow wMSContainerFlow)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == wMSContainerFlow.slotCode) ?? throw new Exception($"未找到站台【{wMSContainerFlow.slotCode}】信息");
@@ -1313,20 +1352,26 @@
                if (wMSContainerFlow.direction == "200")
                {
                    stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
                    stationManger.Remark = "";
                    FOURBOToccupyStation fOURBOToccupyStation = new FOURBOToccupyStation()
                    {
                        stationCode = wMSContainerFlow.slotCode,
                    };
                    string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOToccupyStation.Serialize());
                    FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                    content.OK(data: fOURBOTReturn);
                    if (fOURBOTReturn.returnCode != 0) throw new Exception(fOURBOTReturn.returnUserMsg);
                    _stationMangerService.UpdateData(stationManger);
                }
                return WebResponseContent.Instance.OK();
                return content.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
                return content.Error(ex.Message);
            }
            finally
            {
                _trackloginfoService.AddTrackLog(wMSContainerFlow, content, "容器流动请求", "", "");
            }
        }
        /// <summary>
@@ -1379,11 +1424,21 @@
                //task.TaskState = (int)TaskStatusEnum.Execut;
                //BaseDal.UpdateData(task);
                #endregion
                #region ä¸Šæž¶ä¸­éœ€è¦å°†ç«™å°çŠ¶æ€æ”¹ä¸ºå ç”¨ ç»‘定容器编码
                stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
                stationManger.Remark = iQC.ContainerCode;
                _stationMangerService.UpdateData(stationManger);
                #endregion
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
                _trackloginfoService.AddTrackLog(iQC, content, "IQC质检结果反馈", "", "");
            }
        }
@@ -1395,6 +1450,7 @@
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent multiSetNodeStatus(FOURBOTStorageStatusNotify fOURBOTStorageStatusNotify)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var Agvlocation = _rGVLocationInfoService.Repository.QueryData(x => fOURBOTStorageStatusNotify.storageCode.Contains(x.LocationCode));
@@ -1403,12 +1459,16 @@
                    item.EnableStatus = (int)(fOURBOTStorageStatusNotify.disable == 0 ? EnableStatusEnum.Normal : EnableStatusEnum.Disable);
                }
                _rGVLocationInfoService.UpdateData(Agvlocation);
                return WebResponseContent.Instance.OK();
                return content.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
                _trackloginfoService.AddTrackLog(fOURBOTStorageStatusNotify, content, "批量更新储位状态", "", "");
            }
        }
@@ -1438,6 +1498,71 @@
            }
        }
        /// <summary>
        /// æ ¡éªŒä»»åŠ¡ç›¸å…³çš„åº“ä½çŠ¶æ€å’Œç»‘å®šå…³ç³»
        /// </summary>
        /// <param name="taskType">任务类型</param>
        /// <param name="taskDTO">任务DTO</param>
        /// <returns>返回起点库位和终点库位信息</returns>
        /// <exception cref="Exception">校验失败时抛出异常</exception>
        private WebResponseContent ValidateLocationForTask(int taskType, TaskDTO taskDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                #region
                // å…¥åº“类任务(需要校验终点库位)
                if (taskType == (int)TaskTypeEnum.CK3F || taskType == (int)TaskTypeEnum.F03)
                {
                    var toStation = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.toLocationCode)
                          ?? throw new Exception($"未找到终点库位【{taskDTO.toLocationCode}】!");
                    if (toStation.StationStatus != (int)LocationStatusEnum.Free)
                        throw new Exception($"终点库位【{taskDTO.toLocationCode}】库位状态不可入库!");
                }
                // å‡ºåº“类任务(需要校验起点库位)
                else if (taskType == (int)TaskTypeEnum.RK3F || taskType == (int)TaskTypeEnum.F04)
                {
                    var fromStation = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.fromLocationCode)
                        ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                    if (fromStation.StationStatus != (int)LocationStatusEnum.InStock)
                        throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不可出库!");
                    if (fromStation.PalletCode != taskDTO.containerCode)
                        throw new Exception($"起点库位【{taskDTO.fromLocationCode}】绑定料箱号【{fromStation.PalletCode}】与任务料箱号【{taskDTO.containerCode}】不匹配!");
                }
                // ç§»åº“类任务(需要同时校验起点和终点)
                else if (taskType == (int)TaskTypeEnum.F02)
                {
                    // æ ¡éªŒç»ˆç‚¹åº“位
                    var toStation = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.toLocationCode)
                        ?? throw new Exception($"未找到终点库位【{taskDTO.toLocationCode}】!");
                    if (toStation.StationStatus != (int)LocationStatusEnum.Free)
                        throw new Exception($"终点库位【{taskDTO.toLocationCode}】库位状态不可入库!");
                    // æ ¡éªŒèµ·ç‚¹åº“位
                    var fromStation = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.fromLocationCode)
                        ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                    if (fromStation.StationStatus != (int)LocationStatusEnum.InStock)
                        throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不可出库!");
                    if (fromStation.PalletCode != taskDTO.containerCode)
                        throw new Exception($"起点库位【{taskDTO.fromLocationCode}】绑定料箱号【{fromStation.PalletCode}】与任务料箱号【{taskDTO.containerCode}】不匹配!");
                }
                #endregion
                return content.OK();
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
    }