| | |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_IServices; |
| | | using WIDESEA_IStoragIntegrationServices; |
| | | using WIDESEA_StorageTaskRepository; |
| | | using WIDESEA_StoragIntegrationServices; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_BasicInfoService; |
| | |
| | | private readonly ISys_ConfigService _configService; |
| | | private readonly IDt_PalletStockInfoRepository _palletStockInfoRepository; |
| | | private readonly IDt_PalletStockInfo_htyRepository _palletStockInfo_HtyRepository; |
| | | private readonly IDt_CarBodyRepository _carBodyRepository; |
| | | private readonly IDt_CarBodyInfoRepository _carBodyRepository; |
| | | private readonly IDt_BDCConfigurationRepository _bdcConfigurationRepository; |
| | | private readonly IDt_BDCConfigurationService _bdcConfigurationService; |
| | | private readonly IDt_RoadWayRepository _roadWayRepository; |
| | |
| | | ITaskExecuteDetailRepository taskExecuteDetailRepository, |
| | | ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository, |
| | | IDt_StationManagerRepository stationManagerRepository, |
| | | ISys_ConfigService configService, IDt_PalletStockInfoRepository palletStockInfoRepository, IDt_PalletStockInfo_htyRepository palletStockInfo_HtyRepository, IDt_CarBodyRepository carBodyRepository, IDt_BDCConfigurationRepository bdcConfigurationRepository, IDt_BDCConfigurationService bDCConfigurationService, IDt_RoadWayRepository roadWayRepository, IDt_RoadWayInfoRepository roadWayInfoRepository) : base(BaseDal) |
| | | ISys_ConfigService configService, IDt_PalletStockInfoRepository palletStockInfoRepository, IDt_PalletStockInfo_htyRepository palletStockInfo_HtyRepository, IDt_CarBodyInfoRepository carBodyRepository, IDt_BDCConfigurationRepository bdcConfigurationRepository, IDt_BDCConfigurationService bDCConfigurationService, IDt_RoadWayRepository roadWayRepository, IDt_RoadWayInfoRepository roadWayInfoRepository) : base(BaseDal) |
| | | |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var stationInfo = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway); |
| | | |
| | | //if( stationInfo == null ) throw new Exception ("æªé
置任å¡ç«å°")ï¼ |
| | | |
| | | // è·ååºä½ä¿¡æ¯ |
| | | var locationInf = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress && x.RoadwayNo == task.Roadway); |
| | | var locationInf = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress && x.RoadwayNo == stationInfo.RoadwayNo); |
| | | |
| | | int lastStatus = locationInf.LocationStatus; |
| | | // æ´æ°ç®æ ä½ç½®ç¶æä¸ºåºåä¸ |
| | |
| | | var taskHty = CreateHistoricalTask(task); |
| | | |
| | | //è·åç»çä¿¡æ¯ |
| | | var carBody = await _carBodyRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode); |
| | | var carBody = await _carBodyRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode && x.RFID == task.PVI); |
| | | |
| | | // æ ¹æ®å建åºåå®ä¾æ¨¡å |
| | | //var boxDetail = boxinginfo.BoxingInfoDetails.Adapt<List<Dt_PalletStockInfoDetail>>(); |
| | | Dt_PalletStockInfo palletStockInfo = new Dt_PalletStockInfo |
| | | { |
| | | CreateDate = DateTime.Now, |
| | | |
| | | Creater = task.Creater, |
| | | LocationCode = task.TargetAddress, |
| | | StockStatus = 2, |
| | | PalletCode = task.PalletCode, |
| | | StockStatus = 0, |
| | | //PalletCode = task.PalletCode, |
| | | RoadwayNo = stationInfo.RoadwayNo, |
| | | LockOrder = 0, |
| | | TaskStatus = 0, |
| | | carBodyID = carBody.Id, |
| | | CarBodyInfo = carBody |
| | | }; |
| | | |
| | | // æ§è¡æ°æ®åºäºå¡ |
| | |
| | | try |
| | | { |
| | | //æ¥æ¾åºå |
| | | var stock = await _palletStockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode); |
| | | var stock = await _palletStockInfoRepository.QueryFirstNavAsync(x => x.CarBodyInfo.PalletCode == task.PalletCode); |
| | | |
| | | // æ´æ°åºä½ç¶æä¸ä»»å¡ç¶æ |
| | | (var loc, var tas) = UpdateStockAndTaskStatus(stock, task); |
| | |
| | | { |
| | | var isLocationUpdate = await _locationRepository.UpdateDataAsync(loc); //æ´æ°åºä½ |
| | | var isPalletHty = await _palletStockInfo_HtyRepository.AddDataAsync(stockInfo_Hty); //æ·»å åå²åºåè®°å½ |
| | | //var isTaskUpdated = await BaseDal.DeleteDataByIdAsync(task.TaskId); //å é¤ä»»å¡ |
| | | await BaseDal.UpdateDataAsync(task); //åæ¶å é¤ä»»å¡ï¼æ¹ä¸ºå®æç¶æï¼å¹¶WMSçé¢ç±äººå·¥ç¡®è®¤å®æ |
| | | var isTaskUpdated = await BaseDal.DeleteDataByIdAsync(task.TaskId); //å é¤ä»»å¡ |
| | | //await BaseDal.UpdateDataAsync(task); //åæ¶å é¤ä»»å¡ï¼æ¹ä¸ºå®æç¶æï¼å¹¶WMSçé¢ç±äººå·¥ç¡®è®¤å®æ |
| | | var isTaskAdd = await _task_HtyRepository.AddDataAsync(taskHty) > 0; //å å
¥åå²ä»»å¡ |
| | | var isDelete = await _palletStockInfoRepository.DeleteDataAsync(stock); //å é¤åºå |
| | | //await DeleteStockInfoDetailsAsync(stock.StockInfoDetails); //å é¤åºåæç» |
| | |
| | | |
| | | private (DtLocationInfo, Dt_Task) UpdateStockAndTaskStatus(Dt_PalletStockInfo stock, Dt_Task task) |
| | | { |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == task.Roadway); |
| | | var stationInfo = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway); |
| | | |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == stationInfo.RoadwayNo); |
| | | int lastStatus = location.LocationStatus; |
| | | location.LocationStatus = (int)LocationEnum.Free; |
| | | task.TaskState = (int)TaskOutStatusEnum.OutFinish; |
| | |
| | | // æ ¹æ®ä»»å¡ç±»åè°ç¨ç¸åºç宿任塿¹æ³ |
| | | switch (task.TaskType) |
| | | { |
| | | case (int)TaskInboundTypeEnum.InTray: |
| | | case (int)TaskInboundTypeEnum.Inbound: |
| | | LogFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "å
¥åºä»»å¡", ""); |
| | | return await CompleteInboundTaskAsync(task); |
| | |
| | | if (task == null) |
| | | return content.Error($"ææªæ¾å°ã{input.PalletCode}ãçä»»å¡"); |
| | | |
| | | return content; //= await UpdateExistingTask(input, task); |
| | | return await UpdateExistingTask(input, task); // content; |
| | | } |
| | | catch (Exception err) |
| | | { |
| | |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | var asb = await BaseDal.DeleteDataByIdAsync(task.TaskId); |
| | | |
| | | var asbHty = await _task_HtyRepository.AddDataAsync(taskHty) > 0; |
| | | if (asb && asbHty) |
| | | content.OK(); |
| | |
| | | else |
| | | { |
| | | task.TaskState = taskState; |
| | | task.Dispatchertime = DateTime.Now; |
| | | var asb = await BaseDal.UpdateDataAsync(task); |
| | | if (asb) |
| | | content.OK(); |
| | |
| | | foreach (var item in barcode) |
| | | { |
| | | // æ¥è¯¢åºåä¿¡æ¯ |
| | | var stockInfo = _palletStockInfoRepository.QueryFirst(x => x.PalletCode == item); |
| | | var stockInfo = _palletStockInfoRepository.QueryFirst(x => x.Id == item.ObjToInt()); |
| | | |
| | | if (stockInfo == null) |
| | | { |
| | | return content.Error("æªæ¥è¯¢å°å¯¹åºçåºåä¿¡æ¯"); |
| | | } |
| | | |
| | | if (stockInfo.StockStatus != 2) return content.Error($"æå®å¤±è´¥ï¼æç{item}å½åç¶æä¸å
许æå®åºåº"); |
| | | if (stockInfo.StockStatus != 0) return content.Error($"æå®å¤±è´¥ï¼æç{item}å½åç¶æä¸å
许æå®åºåº"); |
| | | |
| | | stockInfo.StockStatus = 3; |
| | | stockInfo.StockStatus = 1; |
| | | |
| | | //æ¥è¯¢åºä½æ¯å¦éå®ï¼ |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode); |
| | |
| | | return content.Error($"ã{item}ãå·²åå¨ä»»å¡"); |
| | | } |
| | | |
| | | var stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == station); |
| | | var carBody = _carBodyRepository.QueryFirst(x => x.Id == stockInfo.carBodyID); |
| | | List<Dt_StationManager> stationLists = null; |
| | | if (carBody.CarType == 1) |
| | | { |
| | | stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == stockInfo.RoadwayNo && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "3"); |
| | | } |
| | | else if (carBody.CarType == 2) |
| | | { |
| | | stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == stockInfo.RoadwayNo && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "4"); |
| | | } |
| | | else if (carBody.CarType == 3) |
| | | { |
| | | stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == stockInfo.RoadwayNo && x.stationType == 7 && x.stationStatus == "1" && x.stationArea == "3"); |
| | | } |
| | | |
| | | //if (stationInfo.Roadway != stockInfo.AreaCode) throw new Exception($"å½åæç{item}ä¸ä¸æä½ä¸ååºåï¼è¯·éæ°éæ©ï¼"); |
| | | if (stationLists == null || stationLists.Count == 0) throw new Exception("åºåºç«å°æªé
ç½®ææªå¯ç¨"); |
| | | |
| | | Dt_StationManager Outstation = null; |
| | | |
| | | //if (stationLists.Count > 1) |
| | | //{ |
| | | // var Outtask = BaseDal.QueryData(x => x.Roadway == stationLists.FirstOrDefault().Roadway && x.TaskType == (int)TaskTypeEnum.Outbound).OrderByDescending(x => x.CreateDate).FirstOrDefault(); |
| | | // if (Outtask != null) Outstation = stationLists.Where(x => x.stationChildCode != task.NextAddress && x.stationChildCode != Outtask.CurrentAddress).FirstOrDefault(); |
| | | // else Outstation = stationLists.FirstOrDefault(); |
| | | //} |
| | | //else |
| | | //{ |
| | | Outstation = stationLists.FirstOrDefault(); |
| | | //} |
| | | //var stationInfo = stationInfos.FirstOrDefault(); |
| | | |
| | | |
| | | |
| | | // å建并添å ä»»å¡å°æ°æ®åº |
| | | task = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = stationInfo.Roadway, |
| | | TargetAddress = stationInfo.stationLocation, |
| | | Roadway = Outstation.Roadway, |
| | | TargetAddress = "RB043", |
| | | Dispatchertime = DateTime.Now, |
| | | NextAddress = stationInfo.stationLocation, |
| | | NextAddress = Outstation.stationChildCode, |
| | | OrderNo = null, |
| | | PalletCode = stockInfo.PalletCode, |
| | | PalletCode = carBody.PalletCode, |
| | | PVI = carBody.PVI, |
| | | SourceAddress = stockInfo.LocationCode, |
| | | CurrentAddress = stockInfo.LocationCode, |
| | | TaskState = (int)TaskOutStatusEnum.OutNew, |
| | |
| | | TaskId = 0, |
| | | }; |
| | | |
| | | // å建任å¡ä¼ è¾ç¨çDTO对象 |
| | | var taskDTO = CreateTaskDTO(task); |
| | | |
| | | //addtask schedulingTask = new addtask |
| | | //{ |
| | | // task_id = task.AGVtaskId, |
| | | // task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? "push" : "pop", |
| | | // work_begin = task.SourceAddress, |
| | | // work_end = task.TargetAddress |
| | | //}; |
| | | // è·åWMS IPå°åç¨äºåéä»»å¡è¯·æ± |
| | | var wmsIpAddress = GetWCSIpReceiveTask(); |
| | | if (wmsIpAddress == null) |
| | | { |
| | | throw new InvalidOperationException("WMS IP æªé
ç½®"); |
| | | } |
| | | |
| | | //string address = AGV_Interface + "add_task"; |
| | | |
| | | //string result = HttpsClient.PostAsync(address, schedulingTask.ToDictionary()).Result; |
| | | var tasks = new List<WMSTaskDTO>() { taskDTO }; |
| | | // åéä»»å¡è¯·æ±å°WMS |
| | | var result = HttpHelper.PostAsync(wmsIpAddress, tasks.ToJsonString()).Result; |
| | | content = JsonConvert.DeserializeObject<WebResponseContent>(result); |
| | | if (content.Status) |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | // æ·»å ä»»å¡å°æ°æ®åº |
| | | BaseDal.AddData(task); |
| | | // æ´æ°åºä½ä½ç½®ç¶æä¸ºä¸å¯ç¨ |
| | | _locationRepository.UpdateData(location); |
| | | _palletStockInfoRepository.UpdateData(stockInfo); |
| | | |
| | | //content = JsonConvert.DeserializeObject<WebResponseContent>(result); |
| | | |
| | | //if (content.ack != 0) |
| | | //{ |
| | | // Console.WriteLine($"请æ±RCSå¼å¸¸ï¼{content.msg}"); |
| | | // LogFactory.GetLog("ä¸åAGVä»»å¡").Info(true, $"\r\r--------------------------------------"); |
| | | // LogFactory.GetLog("ä¸åAGVä»»å¡").Info(true, $"请æ±åæ°ï¼{schedulingTask.ToJsonString()}"); |
| | | // LogFactory.GetLog("ä¸åAGVä»»å¡").Info(true, $"ååºåæ°ï¼{content.ToJsonString()}"); |
| | | // throw new Exception(content.msg); |
| | | //} |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | // æ·»å ä»»å¡å°æ°æ®åº |
| | | BaseDal.AddData(task); |
| | | // æ´æ°åºä½ä½ç½®ç¶æä¸ºä¸å¯ç¨ |
| | | _locationRepository.UpdateData(location); |
| | | _palletStockInfoRepository.UpdateData(stockInfo); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | } |
| | | |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | } |
| | | return content; |
| | | } |
| | | #endregion æå®ä»»å¡åºåº |
| | | |
| | | private string GetAGVIpReceiveTask() |
| | | |
| | | /// <summary> |
| | | /// å建任å¡DTO |
| | | /// </summary> |
| | | private WMSTaskDTO CreateTaskDTO(Dt_Task task) |
| | | { |
| | | return new WMSTaskDTO |
| | | { |
| | | TaskNum = task.TaskNum.Value, |
| | | Grade = task.Grade.Value, |
| | | PalletCode = task.PalletCode, |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | TaskState = task.TaskState.Value, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | pvi = task.PVI, |
| | | NextAddress = task.NextAddress |
| | | |
| | | }; |
| | | } |
| | | |
| | | private string GetWCSIpReceiveTask() |
| | | { |
| | | var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); |
| | | var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.AGVIPAddress)?.ConfigValue; |
| | | var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.addTask)?.ConfigValue; |
| | | var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue; |
| | | var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveTask)?.ConfigValue; |
| | | if (wmsBase == null || ipAddress == null) |
| | | { |
| | | return null; |
| | | } |
| | | return wmsBase + ipAddress; |
| | | } |
| | | |
| | | #endregion æå®ä»»å¡åºåº |
| | | |
| | | #endregion å¤é¨æ¥å£æ¹æ³ |
| | | |
| | |
| | | /// <param name="taskHty">åå²ä»»å¡å¯¹è±¡</param> |
| | | /// <param name="taskId">ä»»å¡ID</param> |
| | | /// <returns></returns> |
| | | private async Task<bool> ExecuteTransaction(Dt_PalletStockInfo stock, Dt_Task_Hty taskHty, DtLocationInfo locationInfo, int taskId, Dt_CarBody boxingInfo) |
| | | private async Task<bool> ExecuteTransaction(Dt_PalletStockInfo stock, Dt_Task_Hty taskHty, DtLocationInfo locationInfo, int taskId, Dt_CarBodyInfo boxingInfo) |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | try |
| | |
| | | var isUpdateStock = true; |
| | | var isDeleteBoxing = true; |
| | | // æ·»å åºå |
| | | isUpdateStock = await _palletStockInfoRepository.AddDataNavAsync(stock); |
| | | isUpdateStock = await _palletStockInfoRepository.AddDataAsync(stock) > 0; |
| | | |
| | | //å é¤ç»çæ°æ® |
| | | if (boxingInfo != null) |
| | | { |
| | | var box = _carBodyRepository.DeleteData(boxingInfo); |
| | | //boxingInfo.CurrentStatue = 5; |
| | | //isDeleteBoxing = await _boxingInfoRepository.Db.DeleteNav<DtBoxingInfo>(x => x.Id == boxingInfo.Id) |
| | | // .Include(x => x.BoxingInfoDetails) |
| | | // .ExecuteCommandAsync(); |
| | | } |
| | | //if (boxingInfo != null) |
| | | //{ |
| | | // //var box = _carBodyRepository.DeleteData(boxingInfo); |
| | | // //boxingInfo.CurrentStatue = 5; |
| | | // //isDeleteBoxing = await _boxingInfoRepository.Db.DeleteNav<DtBoxingInfo>(x => x.Id == boxingInfo.Id) |
| | | // // .Include(x => x.BoxingInfoDetails) |
| | | // // .ExecuteCommandAsync(); |
| | | //} |
| | | // |
| | | |
| | | // æ·»å åå²ä»»å¡ |
| | |
| | | #endregion |
| | | |
| | | #region ä»»å¡è¯·æ±æ¹æ³ |
| | | |
| | | |
| | | private static readonly SemaphoreSlim _semaphoreUpdate = new SemaphoreSlim(1, 1); |
| | | // æ´æ°ä»»å¡è´§ä½ |
| | | |
| | |
| | | // å建WebResponseContent对象 |
| | | var content = new WebResponseContent(); |
| | | |
| | | // è·ååºä½ |
| | | //var location = RequestLocation(input); |
| | | //if (location == null) |
| | | //{ |
| | | // return content.Error("æ æ³è·åè´§ä½ä¿¡æ¯"); |
| | | //} |
| | | var carInfo = _carBodyRepository.QueryFirst(x => x.PalletCode == task.PalletCode ); |
| | | var stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == input.Position); |
| | | // è·ååºä½; |
| | | var location = RequestLocation(stationInfo.RoadwayNo, carInfo.CarType); |
| | | if (location == null) |
| | | { |
| | | return content.Error("æ æ³è·åè´§ä½ä¿¡æ¯"); |
| | | } |
| | | |
| | | //string toAddress = location.LocationCode; |
| | | //int taskState = (int)TaskInStatusEnum.Line_InFinish; |
| | | //int beforeStatus = location.LocationStatus; |
| | | //// æ´æ°è´§ä½ä¿¡æ¯ |
| | | //location.LocationStatus = (int)LocationEnum.Lock; |
| | | string toAddress = location.LocationCode; |
| | | int taskState = (int)TaskInStatusEnum.Line_InFinish; |
| | | int beforeStatus = location.LocationStatus; |
| | | // æ´æ°è´§ä½ä¿¡æ¯ |
| | | location.LocationStatus = (int)LocationEnum.Lock; |
| | | |
| | | // æ´æ°ä»»å¡ä¿¡æ¯ |
| | | //MapTaskProperties(task, input, toAddress, taskState); |
| | | //æ´æ°ä»»å¡ä¿¡æ¯ |
| | | MapTaskProperties(task, input, toAddress, taskState); |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | // å¼å§äºå¡ |
| | | var isResult = false; //await UpdateTaskAsync(task, location, beforeStatus); |
| | | var isResult = await UpdateTaskAsync(task, location, beforeStatus); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |