刘磊
2025-06-10 87b6fc65bc3b6cce03af04758db82236d29bc7e5
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/RequestChangeLocation.cs
@@ -43,79 +43,6 @@
                    throw new Exception("当前库位已存在任务");
                }
                switch (result.MoveType)
                {
                    case 1:
                        CreateMoveTask(location);
                        break;
                    case 5:
                        CreateFireTask(location);
                        break;
                    default:
                        throw new Exception("无效的移库申请类型");
                }
                #region ç«è­¦å‡ºåº“
                //if (result.MoveType == 5)
                //{
                //    Console.WriteLine($"分容检测柜火警触发:库位{result.LocationID}");
                //    //查找消防站台
                //    var station = _stationManagerRepository.QueryFirst(t => t.Roadway == location.RoadwayNo
                //         && t.stationType == (int)StationManager.FireStation
                //         /*&& t. == "Enable"*/);
                //    if (station == null)
                //    {
                //        throw new Exception("消防站台未配置!");
                //    }
                //    //查找库存信息
                //    var barcodeData = _stockInfoRepository.QueryFirst(t => t.LocationCode == location.LocationCode);
                //    //托盘码
                //    string barcode = string.Empty;
                //    if (barcodeData != null)
                //    {
                //        barcode = barcodeData.PalletCode;
                //    }
                //    else
                //    {
                //        //无库存信息,生成随机托盘码
                //        barcode = "M" + DateTime.Now.ToString("MMddHHmmss") + "-" + new Random().Next(100, 1000);
                //    }
                //    int taskNum = _taskRepository.GetTaskNo().Result;
                //    Dt_Task task = new Dt_Task
                //    {
                //        CreateDate = DateTime.Now,
                //        Creater = "HK",
                //        CurrentAddress = result.LocationID,
                //        Grade = 1,
                //        Dispatchertime = DateTime.Now,
                //        PalletCode = barcode,
                //        Roadway = location.RoadwayNo,
                //        SourceAddress = result.LocationID,
                //        TaskState = (int)TaskOutStatusEnum.OutNew,
                //        TaskType = 500,
                //        TargetAddress = station.stationLocation,
                //        NextAddress = station.stationChildCode,
                //        TaskNum = taskNum, //_taskRepository.GetTaskNo().Result,
                //        TaskId = 0,
                //    };
                //    // å°è¯•添加新任务
                //    WMSTaskDTO taskDTO = new WMSTaskDTO()
                //    {
                //        TaskNum = task.TaskNum.Value,
                //        Grade = 1,
                //        PalletCode = task.PalletCode,
                //        RoadWay = task.Roadway,
                //        SourceAddress = task.SourceAddress,
                //        TargetAddress = task.TargetAddress,
                //        TaskState = task.TaskState.Value,
                //        Id = 0,
                //        TaskType = 500,
                //    };
                //}
                #endregion
                LogFactory.GetLog("分容移库申请").Info(true, $"\r\r--------------------------------------");
                LogFactory.GetLog("分容移库申请").Info(true, result.ToJsonString());
                return content.OK();
@@ -128,172 +55,5 @@
            }
        }
        private void CreateMoveTask(DtLocationInfo location)
        {
            Console.WriteLine($"分容申请移库:库位{location.LocationCode}");
            //查找可用库位
            DtLocationInfo CanRelocation = _locationRepository.QueryFirst(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == location.RoadwayNo && x.EnalbeStatus == 1 && x.LocationType == 2 && x.Remark == "1");
            if (CanRelocation == null) throw new Exception("申请移库失败:无可用库位");
            //查找库存信息
            var stockInfo = _stockInfoRepository.QueryFirst(x => x.LocationCode == location.LocationCode && x.LocationInfo.RoadwayNo == location.RoadwayNo);
            if (stockInfo == null) throw new Exception("申请移库失败:无库存记录");
            //修改移库目标库位状态
            CanRelocation.LocationStatus = (int)LocationEnum.FreeDisable;
            int taskNum = _taskRepository.GetTaskNo().Result;
            Dt_Task task = new Dt_Task
            {
                CreateDate = DateTime.Now,
                Creater = "HK",
                CurrentAddress = location.LocationCode,
                Grade = 1,
                Dispatchertime = DateTime.Now,
                PalletCode = stockInfo.PalletCode,
                Roadway = location.RoadwayNo,
                SourceAddress = location.LocationCode,
                TaskState = (int)TaskStatus.Created,
                TaskType = (int)TaskRelocationTypeEnum.Relocation,
                TargetAddress = CanRelocation.LocationCode,
                NextAddress = CanRelocation.LocationCode,
                TaskNum = taskNum, //_taskRepository.GetTaskNo().Result,
                TaskId = 0,
            };
            // å°è¯•添加新任务
            WMSTaskDTO taskDTO = new WMSTaskDTO()
            {
                TaskNum = task.TaskNum.Value,
                Grade = 1,
                PalletCode = task.PalletCode,
                RoadWay = task.Roadway,
                SourceAddress = task.SourceAddress,
                TargetAddress = task.TargetAddress,
                TaskState = task.TaskState.Value,
                Id = 0,
                TaskType = task.TaskType,
            };
            var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue;
            var ReceiveByWMSTask = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveByWMSTask)?.ConfigValue;
            if (ReceiveByWMSTask == null || ipAddress == null)
            {
                throw new Exception("WMS IP æœªé…ç½®");
            }
            var wmsIpAddrss = ipAddress + ReceiveByWMSTask;
            var respon = HttpHelper.Post(wmsIpAddrss, JsonConvert.SerializeObject(taskDTO));   //http://localhost:9291/api/Task/ReceiveTask,
            if (respon != null)
            {
                WebResponseContent respone = JsonConvert.DeserializeObject<WebResponseContent>(respon.ToString());
                if (respone.Status)
                {
                    //添加WMS任务 å¹¶ä¿®æ”¹åº“位状态
                    var taskId = _taskRepository.AddData(task);
                    _locationRepository.UpdateData(CanRelocation);
                }
                else
                {
                    throw new Exception("WCS处理失败:" + respone.Message);
                }
            }
            else
            {
                throw new Exception("WCS处理失败");
            }
        }
        private void CreateFireTask(DtLocationInfo location)
        {
            Console.WriteLine($"分容检测柜火警触发:库位{location.LocationCode}");
            //查找消防站台
            var station = _stationManagerRepository.QueryFirst(t => t.Roadway == location.RoadwayNo
                 && t.stationType == (int)StationManager.FireStation
                 /*&& t. == "Enable"*/);
            if (station == null)
            {
                throw new Exception("消防站台未配置!");
            }
            //查找库存信息
            var barcodeData = _stockInfoRepository.QueryFirst(t => t.LocationCode == location.LocationCode);
            //托盘码
            string barcode = string.Empty;
            if (barcodeData != null)
            {
                barcode = barcodeData.PalletCode;
            }
            else
            {
                //无库存信息,生成随机托盘码
                barcode = "M" + DateTime.Now.ToString("MMddHHmmss") + "-" + new Random().Next(100, 1000);
            }
            int taskNum = _taskRepository.GetTaskNo().Result;
            Dt_Task task = new Dt_Task
            {
                CreateDate = DateTime.Now,
                Creater = "HK",
                CurrentAddress = location.LocationCode,
                Grade = 1,
                Dispatchertime = DateTime.Now,
                PalletCode = barcode,
                Roadway = location.RoadwayNo,
                SourceAddress = location.LocationCode,
                TaskState = (int)TaskOutStatusEnum.OutNew,
                TaskType = 500,
                TargetAddress = station.stationLocation,
                NextAddress = station.stationChildCode,
                TaskNum = taskNum, //_taskRepository.GetTaskNo().Result,
                TaskId = 0,
            };
            // å°è¯•添加新任务
            WMSTaskDTO taskDTO = new WMSTaskDTO()
            {
                TaskNum = task.TaskNum.Value,
                Grade = 1,
                PalletCode = task.PalletCode,
                RoadWay = task.Roadway,
                SourceAddress = task.SourceAddress,
                TargetAddress = task.TargetAddress,
                TaskState = task.TaskState.Value,
                Id = 0,
                TaskType = 500,
            };
            var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue;
            var ReceiveByWMSTask = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveByWMSTask)?.ConfigValue;
            if (ReceiveByWMSTask == null || ipAddress == null)
            {
                throw new Exception("WMS IP æœªé…ç½®");
            }
            var wmsIpAddrss = ipAddress + ReceiveByWMSTask;
            var respon = HttpHelper.Post(wmsIpAddrss, JsonConvert.SerializeObject(taskDTO));   //http://localhost:9291/api/Task/ReceiveTask,
            if (respon != null)
            {
                WebResponseContent respone = JsonConvert.DeserializeObject<WebResponseContent>(respon.ToString());
                if (respone.Status)
                {
                    var taskId = _taskRepository.AddData(task);
                }
                else
                {
                    throw new Exception("WCS处理失败:" + respone.Message);
                }
            }
            else
            {
                throw new Exception("WCS处理失败");
            }
        }
    }
}