| | |
| | | using log4net.Core; |
| | | using Masuit.Tools; |
| | | using System.Collections.Generic; |
| | | using WIDESEA_Comm.AGVTask; |
| | | using WIDESEA_Comm.WCSInterface.Requst; |
| | | using WIDESEA_Common; |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_IStorageBasicRepository; |
| | | using WIDESEA_StorageBasicRepository; |
| | | using WIDESEA_StorageTaskRepository; |
| | | using WIDESEA_StoragIntegrationServices; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | |
| | | /// </summary> |
| | | /// <param name="input">è¯·æ±æ¨¡å</param> |
| | | /// <returns>å
å«ä»»å¡ä¿¡æ¯çååºå
容</returns> |
| | | public async Task<WebResponseContent> RequestInTask(RequestTaskDto input) |
| | | public async Task<WebResponseContent> RequestInTask(SaveModel saveModel) |
| | | { |
| | | // å建ä¸ä¸ªWebResponseContent对象 |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string palletCode = saveModel.MainData["palletCode"].ToString(); |
| | | string station = saveModel.MainData["station"].ToString(); |
| | | |
| | | // è°ç¨BaseDal.QueryFirstAsyncæ¹æ³ï¼æ¥è¯¢ä»»å¡ |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode); |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode); |
| | | if (task != null) |
| | | { |
| | | { |
| | | WMSTaskDTO taskDTO = CreateTaskDTO(task); |
| | | return content.OK(data: taskDTO); |
| | | } |
| | | throw new Exception($"æç{palletCode}å·²åå¨ä»»å¡"); |
| | | } |
| | | |
| | | var stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == station); |
| | | if (stationInfo == null) |
| | | { |
| | | throw new Exception($"ç«å°{station}ä¸åå¨"); |
| | | } |
| | | |
| | | var boxingInfo = _boxingInfoRepository.QueryFirst(x => x.PalletCode == palletCode); |
| | | if (boxingInfo == null) |
| | | { |
| | | throw new Exception($"æç{palletCode}ç»çä¿¡æ¯ä¸åå¨"); |
| | | } |
| | | if (boxingInfo.CurrentStatue != 1) |
| | | { |
| | | throw new Exception($"æç{palletCode}å½åç¶æä¸å
许å
¥åº"); |
| | | } |
| | | // è·ååºä½ |
| | | var location = RequestLocation(stationInfo.Roadway); |
| | | if (location == null) |
| | | { |
| | | return content.Error("æ æ³è·åè´§ä½ä¿¡æ¯æåºä½å·²æ»¡"); |
| | | } |
| | | |
| | | string agvId = Guid.NewGuid().ToString().Replace("-", "").Take(16); |
| | | var newtask = new Dt_Task |
| | | { |
| | | CurrentAddress = input.Position, |
| | | CurrentAddress = station, |
| | | Grade = 1, |
| | | Roadway = input.Roadways, |
| | | TargetAddress = input.Roadways, |
| | | Roadway = stationInfo.Roadway, |
| | | TargetAddress = location.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = input.Roadways, |
| | | NextAddress = stationInfo.Roadway, |
| | | OrderNo = null, |
| | | PalletCode = "", |
| | | SourceAddress = input.Position, |
| | | PalletCode = palletCode, |
| | | SourceAddress = stationInfo.stationLocation, |
| | | TaskState = (int)TaskInStatusEnum.InNew, |
| | | TaskType = (int)TaskInboundTypeEnum.Inbound, |
| | | TaskNum = await BaseDal.GetTaskNo(), |
| | | Creater = "Systeam" |
| | | Creater = "Systeam", |
| | | AGVtaskId = agvId, |
| | | }; |
| | | |
| | | // å°è¯æ·»å æ°ä»»å¡ |
| | | if (newtask == null) return content.Error(); |
| | | var taskId = await BaseDal.AddDataAsync(newtask); |
| | | bool isResult = taskId > 0; |
| | | if (isResult) |
| | | addtask schedulingTask = new addtask |
| | | { |
| | | // å建WMSä»»å¡ |
| | | WMSTaskDTO taskDTO = new WMSTaskDTO() |
| | | { |
| | | TaskNum = newtask.TaskNum.Value, |
| | | Grade = newtask.Grade.Value, |
| | | PalletCode = newtask.PalletCode, |
| | | RoadWay = newtask.Roadway, |
| | | SourceAddress = newtask.SourceAddress, |
| | | TargetAddress = newtask.TargetAddress, |
| | | TaskState = newtask.TaskState.Value, |
| | | Id = 0, |
| | | TaskType = newtask.TaskType, |
| | | }; |
| | | task_id = newtask.AGVtaskId, |
| | | task_type = newtask.TaskType == (int)TaskTypeEnum.Inbound ? "push" : "pop", |
| | | work_begin = newtask.SourceAddress, |
| | | work_end = newtask.TargetAddress |
| | | }; |
| | | |
| | | //inWheelsInfo.Wheels_CurrentStatue = "1"; |
| | | //_InWheels_MesRepository.UpdateData(inWheelsInfo); |
| | | string address = AGV_Interface + "add_task"; |
| | | |
| | | content.OK(data: taskDTO); |
| | | string result = HttpsClient.PostAsync(address, schedulingTask.ToDictionary()).Result; |
| | | |
| | | 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); |
| | | } |
| | | else |
| | | content.Error("æ·»å ä»»å¡å¤±è´¥"); |
| | | return content; |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | BaseDal.AddData(newtask); |
| | | location.LocationStatus = (int)LocationEnum.InStockDisable; |
| | | _locationRepository.UpdateData(location); |
| | | boxingInfo.CurrentStatue = 3; |
| | | _boxingInfoRepository.UpdateData(boxingInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | content.OK("ç³è¯·å
¥åºæåï¼è¯·çå¾
AGVåæ"); |
| | | } |
| | | catch (Exception err) |
| | | catch (Exception er) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | // 妿åçå¼å¸¸ï¼åè°ç¨content.Erroræ¹æ³ï¼è®°å½é误信æ¯ï¼å¹¶è¾åºéè¯¯ä¿¡æ¯ |
| | | content.Error(err.Message); |
| | | Console.WriteLine(err.Message); |
| | | content.Error($"å
¥åºç³è¯·å¤±è´¥ï¼{er.Message}"); |
| | | Console.WriteLine(er.Message); |
| | | } |
| | | // è¿åcontent |
| | | return content; |
| | |
| | | /// <param name="requestTask"></param> |
| | | /// <param name="locationInfos"></param> |
| | | /// <returns></returns> |
| | | public DtLocationInfo RequestLocation(RequestTaskDto requestTask, List<DtLocationInfo> locationInfos = null) |
| | | public DtLocationInfo RequestLocation(string roadwayNo) |
| | | { |
| | | lock (objLOCK) |
| | | { |
| | | try |
| | | { |
| | | //List<DtLocationInfo> locations = new List<DtLocationInfo>(); |
| | | if (locationInfos == null || locationInfos.Count == 0) |
| | | { |
| | | locationInfos = _locationRepository.QueryData(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == "SC1" && x.EnalbeStatus == 1 && x.LocationType == 1); |
| | | } |
| | | List<DtLocationInfo> locations = new List<DtLocationInfo>(); |
| | | locations = _locationRepository.QueryData(x => x.RoadwayNo == roadwayNo && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1); //&& x.LocationType == 1 |
| | | |
| | | var location = GetEmptyLocation(locationInfos); |
| | | |
| | | if (location != null) |
| | | { |
| | | if (location.Depth == 2) |
| | | { |
| | | int row = location.Row; |
| | | int relativeLine = row % 2 == 1 ? row + 1 : row - 1; |
| | | |
| | | var insideLocation = _locationRepository.QueryFirst(x => x.Row == relativeLine && x.Layer == location.Layer && x.Column == location.Column); |
| | | |
| | | if (insideLocation.LocationStatus != (int)LocationEnum.Free /*|| insideLocation.EnalbeStatus ==*/ ) |
| | | { |
| | | locationInfos.Remove(location); |
| | | if (locationInfos.Count == 0) return null; |
| | | RequestLocation(requestTask, locationInfos); |
| | | } |
| | | } |
| | | } |
| | | var location = GetEmptyLocation(locations); |
| | | if (location == null) |
| | | { |
| | | return null; |
| | | throw new Exception("åºä½å·²æ»¡"); |
| | | } |
| | | return location; |
| | | } |
| | |
| | | |
| | | private DtLocationInfo GetEmptyLocation(List<DtLocationInfo> dtLocationInfos) |
| | | { |
| | | var locationinfo = dtLocationInfos.Where(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == "SC1" && x.EnalbeStatus == 1 && x.LocationType == 1).OrderBy(x => x.Layer).ThenByDescending(x => x.Depth).ThenBy(x => x.Row).ThenBy(x => x.Column).FirstOrDefault(); |
| | | var locationinfo = dtLocationInfos.Where(x => x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1).OrderBy(x => x.Layer).ThenByDescending(x => x.Depth).ThenBy(x => x.Row).ThenBy(x => x.Column).FirstOrDefault(); |
| | | |
| | | return locationinfo; |
| | | } |
| | |
| | | #endregion è·åè´§ä½ |
| | | #endregion åºä½åé
|
| | | |
| | | public WebResponseContent confirmTask(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var taskInfo = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (taskInfo != null) |
| | | { |
| | | BaseDal.DeleteData(taskInfo); |
| | | } |
| | | |
| | | content.OK("ç¡®è®¤å®æ"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error($"确认å¼å¸¸:{ex.Message}"); |
| | | } |
| | | |
| | | return content; |
| | | } |
| | | |
| | | } |