| | |
| | | using Mapster; |
| | | using AngleSharp.Dom; |
| | | using log4net.Core; |
| | | using Mapster; |
| | | using Masuit.Tools; |
| | | using OfficeOpenXml.Table.PivotTable; |
| | | using SixLabors.Fonts.Tables.AdvancedTypographic; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Reflection.Metadata; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Cache; |
| | | using WIDESEA_Common; |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_DTO.Location; |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_IServices; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | |
| | | |
| | | try |
| | | { |
| | | var task = await GetByTaskAddress(taskDto.Position, taskDto.TargetAddress); |
| | | if (task != null) |
| | | { |
| | | return content.Error("èµ·ç¹æç»ç¹åå¨ä»»å¡"); |
| | | } |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.Roadway == "SC1"); |
| | | |
| | | var location = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "SC1", |
| | | TargetAddress = taskDto.TargetAddress, |
| | | TargetAddress = "SC1", |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = station.stationChildCode, |
| | |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | var isResult = await AddInBoundTaskAsync(taskNew, location); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ°å¢ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | return content = await SendWCSTask(taskDTO); |
| | | } |
| | | catch (Exception err) |
| | |
| | | return content; |
| | | } |
| | | |
| | | |
| | | #endregion 请æ±ä»»å¡å
¥åº |
| | | |
| | | #region æ´æ°ä»»å¡ç¶æ |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡è´§ä½ |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> UpdateExistingTask(RequestTaskDto input) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode); |
| | | if (task == null) |
| | | return content.Error($"ææªæ¾å°ã{input.PalletCode}ãçä»»å¡"); |
| | | |
| | | return content = await UpdateExistingTask(input, task); |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | return content.Error(err.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion 请æ±ä»»å¡å
¥åº |
| | | |
| | | #region 请æ±åºåº |
| | | |
| | | /// <summary> |
| | | /// è¯·æ±æçä»»å¡ |
| | | /// </summary> |
| | | /// <param name="position">ç®æ ä½ç½®</param> |
| | | /// <param name="tag">æçç±»åï¼1ï¼å®çï¼2ï¼ç©ºçï¼</param> |
| | | /// <param name="areaCode">åºåç¼ç </param> |
| | | /// <param name="roadways">å··éç¼ç éå</param> |
| | | /// <returns>è¿åç»æé</returns> |
| | | public async Task<WebResponseContent> RequestOutTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = await GetByTaskAddress(taskDto.Position, taskDto.TargetAddress); |
| | | if (task != null) |
| | | { |
| | | return content.Error("èµ·ç¹æç»ç¹åå¨ä»»å¡"); |
| | | } |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.Roadway == "SC1"); |
| | | |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "SC1", |
| | | TargetAddress = taskDto.TargetAddress, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = station.stationChildCode, |
| | | OrderNo = null, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskOutStatusEnum.OutNew, |
| | | TaskType = (int)TaskOutboundTypeEnum.Outbound, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = "1F", |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | return content = await SendWCSTask(taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion 请æ±åºåºï¼å®ç&空çï¼ |
| | | |
| | | #region 请æ±è·¨æ¥¼å±2ä»»å¡ |
| | | /// <summary> |
| | | /// 请æ±è·¨æ¥¼å±2ä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskDto"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> AcrossFloorTaskAsync(RequestAcrossFloorTaskDto taskDto) |
| | | { |
| | | WebResponseContent content=new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.TaskNum == Convert.ToInt32(taskDto.TaskNum) && x.PalletCode == taskDto.PalletCode); |
| | | if(task == null) |
| | | return content.Error("æªæ¾å°ä»»å¡"); |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "AGV", |
| | | TargetAddress = task.TargetAddress, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = taskDto.NextAddress, |
| | | OrderNo = null, |
| | | PalletCode = task.PalletCode, |
| | | SourceAddress = taskDto.NextAddress, |
| | | CurrentAddress = taskDto.NextAddress, |
| | | TaskState = (int)TaskAcrossFloorStatusEnum.SecondCarry, |
| | | TaskType = (int)TaskAcrossFloorTypeEnum.AcrossFloorCarry, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = "", |
| | | }; |
| | | var taskDTO = CreateTaskDTO(taskNew); |
| | | |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | }); |
| | | return content.OK(data: taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 请æ±è·¨æ¥¼å±ä»»å¡ |
| | | public async Task<WebResponseContent> RequestAcrossFloorTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = await GetByTaskAddress(taskDto.Position, taskDto.TargetAddress); |
| | | if (task != null) |
| | | { |
| | | return content.Error("èµ·ç¹æç»ç¹åå¨ä»»å¡"); |
| | | } |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == taskDto.Position); |
| | | |
| | | if (station != null) |
| | | { |
| | | var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == station.stationFloor); |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "AGV", |
| | | TargetAddress = taskDto.TargetAddress, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = next.stationChildCode, |
| | | OrderNo = null, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew, |
| | | TaskType = (int)TaskAcrossFloorTypeEnum.AcrossFloorCarry, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = station.stationFloor, |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | return content = await SendWCSTask(taskDTO); |
| | | } |
| | | return content.Error("æªæ¾å°æåæºç«ç¹"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 请æ±AGVæ¬è¿ä»»å¡ |
| | | public async Task<WebResponseContent> RequestAGVCarryTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = await GetByTaskAddress(taskDto.Position,taskDto.TargetAddress); |
| | | if (task != null) |
| | | { |
| | | return content.Error("èµ·ç¹æç»ç¹åå¨ä»»å¡"); |
| | | } |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == taskDto.Position); |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "AGV", |
| | | TargetAddress = taskDto.TargetAddress, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = taskDto.TargetAddress, |
| | | OrderNo = null, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskAGVCarryStatusEnum.CarryNew, |
| | | TaskType = (int)TaskAGVCarryTypeEnum.Carry, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = station.stationFloor, |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | return content = await SendWCSTask(taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ä»»å¡ç¶ææ´æ¹ |
| | | |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡ç¶æ&åºåºè§£ç |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <param name="taskState"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> UpdateTaskStatus(int taskNum, int taskState) |
| | | { |
| | |
| | | if (task == null) |
| | | return content.Error("æªæ¾å°ä»»å¡"); |
| | | |
| | | if (taskState == (int)TaskOutStatusEnum.Line_OutFinish || taskState == (int)TaskInStatusEnum.SC_InFinish) |
| | | if (taskState == (int)TaskOutStatusEnum.Line_OutFinish || taskState == (int)TaskInStatusEnum.SC_InFinish || taskState == (int)TaskRelocationStatusEnum.SC_RelocationFinish || taskState == (int)TaskAGVCarryStatusEnum.AGV_CarryFinish) |
| | | { |
| | | var taskHty = CreateHistoricalTask(task); |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | |
| | | return content; |
| | | } |
| | | |
| | | #endregion ä»»å¡ç¶ææ´æ¹ |
| | | public async Task<WebResponseContent> RequestLocationAsync(RequestTaskDto input) |
| | | { |
| | | await _semaphoreUpdate.WaitAsync(); |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == input.PalletCode); |
| | | if (task == null) |
| | | { |
| | | return content.Error("ä»»å¡å¯¹è±¡ä¸ºç©º"); |
| | | } |
| | | |
| | | task.TaskState = (int)TaskInStatusEnum.Line_InFinish; |
| | | var location = await GetEmptyLocation(task.Roadway); |
| | | if (location == null) |
| | | { |
| | | return content.Error("æ æ³è·åè´§ä½ä¿¡æ¯"); |
| | | } |
| | | int beforeStatus = location.LocationStatus; |
| | | |
| | | location.LocationStatus = (int)LocationEnum.Lock; |
| | | task.CurrentAddress = input.Position; |
| | | task.TargetAddress = location.LocationCode; |
| | | task.NextAddress = location.LocationCode; |
| | | task.TaskState = (int)TaskInStatusEnum.Line_InFinish; |
| | | // å¼å§äºå¡ |
| | | var isResult = await UpdateTaskAsync(task, location, beforeStatus); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ´æ°ä»»å¡å¤±è´¥"); |
| | | } |
| | | return content.OK(data: task); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | throw; |
| | | } |
| | | finally { _semaphoreUpdate.Release(); } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region 请æ±åºåº |
| | | |
| | | /// <summary> |
| | | /// è¯·æ±æçä»»å¡ |
| | | /// </summary> |
| | | /// <param name="position">ç®æ ä½ç½®</param> |
| | | /// <param name="tag">æçç±»åï¼1ï¼å®çï¼2ï¼ç©ºçï¼</param> |
| | | /// <param name="areaCode">åºåç¼ç </param> |
| | | /// <param name="roadways">å··éç¼ç éå</param> |
| | | /// <returns>è¿åç»æé</returns> |
| | | public async Task<WebResponseContent> RequestOutTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.Roadway == "SC1"); |
| | | |
| | | var Sourcelocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | |
| | | DtLocationInfo Targetlocation = await GetAGVEmptyCacheLocation(2); |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "SC1", |
| | | TargetAddress = Targetlocation.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = station.stationChildCode, |
| | | OrderNo = null, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskOutStatusEnum.OutNew, |
| | | TaskType = (int)TaskOutboundTypeEnum.Outbound, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = "1F", |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | var isResult = await AddTaskAsync(taskNew, Sourcelocation, Targetlocation); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ°å¢ä»»å¡å¤±è´¥"); |
| | | } |
| | | return content = await SendWCSTask(taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion 请æ±åºåºï¼å®ç&空çï¼ |
| | | |
| | | #region 请æ±è·¨æ¥¼å±2ä»»å¡ |
| | | /// <summary> |
| | | /// 请æ±è·¨æ¥¼å±2ä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskDto"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> AcrossFloorTaskAsync(RequestAcrossFloorTaskDto taskDto) |
| | | { |
| | | WebResponseContent content=new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.TaskNum == Convert.ToInt32(taskDto.TaskNum) && x.PalletCode == taskDto.PalletCode); |
| | | if(task == null) |
| | | return content.Error("æªæ¾å°ä»»å¡"); |
| | | Dt_StationManager stationManager = new Dt_StationManager(); |
| | | if (task.Floor == "1F") |
| | | { |
| | | stationManager = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == "2F"); |
| | | } |
| | | else |
| | | { |
| | | stationManager = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == "1F"); |
| | | } |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "AGV", |
| | | TargetAddress = task.TargetAddress, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = task.TargetAddress, |
| | | OrderNo = null, |
| | | PalletCode = task.PalletCode, |
| | | SourceAddress = task.SourceAddress, |
| | | CurrentAddress = stationManager.stationChildCode, |
| | | TaskState = (int)TaskAcrossFloorStatusEnum.SecondCarry, |
| | | TaskType = (int)TaskAcrossFloorTypeEnum.AcrossFloorCarry, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = stationManager.stationFloor, |
| | | }; |
| | | var taskDTO = CreateTaskDTO(taskNew); |
| | | |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | BaseDal.AddData(taskNew); |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | }); |
| | | return content.OK(data: taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 请æ±è·¨æ¥¼å±ä»»å¡ |
| | | public async Task<WebResponseContent> RequestAcrossFloorTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | LogFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "ç§»åºä»»å¡å®æ", $"111111"); |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | |
| | | var Sourcelocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | |
| | | DtLocationInfo Targetlocation = await GetAGVEmptyCacheLocation(taskDto.AreaId); |
| | | |
| | | if (Targetlocation == null || Sourcelocation == null) |
| | | { |
| | | return content.Error("èµ·ç¹æªå®ä¹æç»ç¹åºåæªæ¾å°ç©ºé²åºä½"); |
| | | } |
| | | |
| | | if (IsAcrossFloor(Sourcelocation, Targetlocation)) |
| | | { |
| | | return content.Error("忥¼å±ä¸å
许请æ±è·¨æ¥¼å±ä»»å¡"); |
| | | } |
| | | |
| | | if (Sourcelocation != null) |
| | | { |
| | | var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == Sourcelocation.Floor); |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "AGV", |
| | | TargetAddress = Targetlocation.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = next.stationChildCode, |
| | | OrderNo = null, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew, |
| | | TaskType = (int)TaskAcrossFloorTypeEnum.AcrossFloorCarry, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = Sourcelocation.Floor, |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | |
| | | var isResult = await AddTaskAsync(taskNew, Sourcelocation, Targetlocation); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ°å¢ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | return content = await SendWCSTask(taskDTO); |
| | | } |
| | | return content.Error("æªæ¾å°æåæºç«ç¹"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public async Task<WebResponseContent> RequestPointAcrossFloorTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var Sourcelocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | |
| | | var Targetlocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.TargetAddress); |
| | | |
| | | if (Targetlocation == null || Sourcelocation == null) |
| | | { |
| | | return content.Error("èµ·ç¹æç»ç¹æªå®ä¹"); |
| | | } |
| | | |
| | | if (IsAcrossFloor(Sourcelocation, Targetlocation)) |
| | | { |
| | | return content.Error("忥¼å±ä¸å
许请æ±è·¨æ¥¼å±ä»»å¡"); |
| | | } |
| | | if (Sourcelocation != null) |
| | | { |
| | | var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == Sourcelocation.Floor); |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "AGV", |
| | | TargetAddress = Targetlocation.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = next.stationChildCode, |
| | | OrderNo = null, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew, |
| | | TaskType = (int)TaskAcrossFloorTypeEnum.AcrossFloorCarry, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = Sourcelocation.Floor, |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | |
| | | var isResult = await AddTaskAsync(taskNew, Sourcelocation, Targetlocation); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ°å¢ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | return content = await SendWCSTask(taskDTO); |
| | | } |
| | | return content.Error("æªæ¾å°æåæºç«ç¹"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 请æ±AGVæ¬è¿ä»»å¡ |
| | | public async Task<WebResponseContent> RequestAGVCarryTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var Sourcelocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | |
| | | DtLocationInfo Targetlocation = await GetAGVEmptyCacheLocation(taskDto.AreaId); |
| | | |
| | | if (Targetlocation == null || Sourcelocation == null) |
| | | { |
| | | return content.Error("èµ·ç¹æªå®ä¹æç»ç¹åºåæªæ¾å°ç©ºé²åºä½"); |
| | | } |
| | | |
| | | if (!IsSamefloor(Sourcelocation, Targetlocation)) |
| | | { |
| | | return content.Error("忥¼å±ä¸å
许请æ±è·¨æ¥¼å±ä»»å¡"); |
| | | } |
| | | |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "AGV", |
| | | TargetAddress = Targetlocation.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = taskDto.TargetAddress, |
| | | OrderNo = null, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskAGVCarryStatusEnum.CarryNew, |
| | | TaskType = (int)TaskAGVCarryTypeEnum.Carry, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = Sourcelocation.Floor, |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | var isResult = await AddTaskAsync(taskNew, Sourcelocation, Targetlocation); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ°å¢ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | return content = await SendWCSTask(taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | public async Task<WebResponseContent> RequestPointAGVCarryTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var Sourcelocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | |
| | | var Targetlocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.TargetAddress); |
| | | |
| | | if (Targetlocation == null || Sourcelocation == null) |
| | | { |
| | | return content.Error("èµ·ç¹æç»ç¹æªå®ä¹"); |
| | | } |
| | | |
| | | if (!IsSamefloor(Sourcelocation, Targetlocation)) |
| | | { |
| | | return content.Error("忥¼å±ä¸å
许请æ±è·¨æ¥¼å±ä»»å¡"); |
| | | } |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "AGV", |
| | | TargetAddress = Targetlocation.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = taskDto.TargetAddress, |
| | | OrderNo = null, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskAGVCarryStatusEnum.CarryNew, |
| | | TaskType = (int)TaskAGVCarryTypeEnum.Carry, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = Sourcelocation.Floor, |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | var isResult = await AddTaskAsync(taskNew, Sourcelocation, Targetlocation); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ°å¢ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | return content = await SendWCSTask(taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region è·åAGVä»»å¡å· |
| | | |
| | |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | TaskState = task.TaskState.Value, |
| | | TaskState = task.TaskState, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | AGVTaskNum = task.AGVTaskNum, |
| | |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | TaskState = task.TaskState.Value, |
| | | TaskState = task.TaskState, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | AGVTaskNum = task.AGVTaskNum, |
| | | }; |
| | | } |
| | | |
| | | private bool IsAcrossFloor(DtLocationInfo Sourcelocation,DtLocationInfo Targetlocation) |
| | | { |
| | | return Sourcelocation.Floor == Targetlocation.Floor; |
| | | } |
| | | |
| | | private bool IsSamefloor(DtLocationInfo Sourcelocation, DtLocationInfo Targetlocation) |
| | | { |
| | | return Sourcelocation.Floor == Targetlocation.Floor; |
| | | } |
| | | private async Task DeleteStockInfoAsync(int stockId) |
| | | { |
| | |
| | | private static readonly SemaphoreSlim _semaphoreUpdate = new SemaphoreSlim(1, 1); |
| | | // æ´æ°ä»»å¡è´§ä½ |
| | | |
| | | private async Task<WebResponseContent> UpdateExistingTask(RequestTaskDto input, Dt_Task task) |
| | | { |
| | | await _semaphoreUpdate.WaitAsync(); |
| | | try |
| | | { |
| | | if (task == null) |
| | | { |
| | | return new WebResponseContent().Error("ä»»å¡å¯¹è±¡ä¸ºç©º"); |
| | | } |
| | | |
| | | try |
| | | { |
| | | // å建WebResponseContent对象 |
| | | var content = new WebResponseContent(); |
| | | |
| | | |
| | | var location = await GetEmptyLocation(task.Roadway); |
| | | 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; |
| | | |
| | | // æ´æ°ä»»å¡ä¿¡æ¯ |
| | | MapTaskProperties(task, input, toAddress, taskState); |
| | | |
| | | // å¼å§äºå¡ |
| | | var isResult = await UpdateTaskAsync(task, location, beforeStatus); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ´æ°ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | // æäº¤äºå¡ |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(data: task); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // åæ»äºå¡ |
| | | _unitOfWorkManage.RollbackTran(); |
| | | // è¿éå¯ä»¥æ·»å æ¥å¿è®°å½ |
| | | return new WebResponseContent().Error($"æ´æ°ä»»å¡æ¶åçé误: {ex.Message}"); |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | throw; |
| | | } |
| | | finally { _semaphoreUpdate.Release(); } |
| | | } |
| | | |
| | | private void MapTaskProperties(Dt_Task task, RequestTaskDto input, string toAddress, int taskState) |
| | | { |
| | | task.CurrentAddress = input.Position; |
| | | task.TargetAddress = toAddress; |
| | | task.NextAddress = toAddress; |
| | | task.TaskState = taskState; |
| | | } |
| | | |
| | | // ä¿®æ¹ä»»å¡ |
| | | private async Task<bool> UpdateTaskAsync(Dt_Task task, DtLocationInfo location, int beforeStatus) |
| | | { |
| | | bool isResult = await BaseDal.UpdateDataAsync(task); |
| | | bool isTaskDetail = await _taskExecuteDetailRepository.AddDetailAsync(task, false, TaskDescription.GetTaskUpdateDescription(task.PalletCode, task.CurrentAddress, task.TargetAddress, TaskInStatusEnum.Line_InFinish.GetIntegralRuleTypeEnumDesc())); |
| | | |
| | | LocationChangeRecordDto changeRecordDto = new LocationChangeRecordDto() |
| | | { |
| | | AfterStatus = location.LocationStatus, |
| | |
| | | bool isUpdateChange = _locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto); |
| | | bool isUpdateLo = await _locationRepository.UpdateDataAsync(location); |
| | | |
| | | return isResult && isUpdateLo && isTaskDetail; |
| | | return isResult && isUpdateLo; |
| | | } |
| | | |
| | | private async Task<bool> AddTaskAsync(Dt_Task task, DtLocationInfo Sourcelocation, DtLocationInfo Targetlocation) |
| | | { |
| | | bool isResult = await BaseDal.AddDataAsync(task) > 0; |
| | | int SourcebeforeStatus = Sourcelocation.LocationStatus; |
| | | |
| | | int TargetbeforeStatus = Targetlocation.LocationStatus; |
| | | |
| | | Sourcelocation.LocationStatus = (int)LocationEnum.InStockDisable; |
| | | |
| | | Targetlocation.LocationStatus = (int)LocationEnum.Lock; |
| | | |
| | | List<LocationChangeRecordDto> changeRecordDto = new List<LocationChangeRecordDto>() |
| | | { |
| | | new LocationChangeRecordDto() |
| | | { |
| | | AfterStatus = Sourcelocation.LocationStatus, |
| | | BeforeStatus = SourcebeforeStatus, |
| | | TaskNum = task.TaskNum.Value, |
| | | LocationId = Sourcelocation.Id, |
| | | LocationCode = Sourcelocation.LocationCode, |
| | | ChangeType = (int)StatusChangeTypeEnum.AutomaticDelivery, |
| | | }, |
| | | new LocationChangeRecordDto() |
| | | { |
| | | AfterStatus = Targetlocation.LocationStatus, |
| | | BeforeStatus = TargetbeforeStatus, |
| | | TaskNum = task.TaskNum.Value, |
| | | LocationId = Targetlocation.Id, |
| | | LocationCode = Targetlocation.LocationCode, |
| | | ChangeType = (int)StatusChangeTypeEnum.AutomaticDelivery, |
| | | }, |
| | | }; |
| | | |
| | | bool isUpdateChange = _locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto); |
| | | bool Source = await _locationRepository.UpdateDataAsync(Sourcelocation); |
| | | bool Target = await _locationRepository.UpdateDataAsync(Targetlocation); |
| | | |
| | | return isResult && Source && Target; |
| | | } |
| | | |
| | | private async Task<bool> AddInBoundTaskAsync(Dt_Task task, DtLocationInfo location) |
| | | { |
| | | bool isResult = await BaseDal.AddDataAsync(task) > 0; |
| | | int beforeStatus = location.LocationStatus; |
| | | |
| | | location.LocationStatus = (int)LocationEnum.InStockDisable; |
| | | |
| | | LocationChangeRecordDto changeRecordDto = new LocationChangeRecordDto() |
| | | { |
| | | AfterStatus = location.LocationStatus, |
| | | BeforeStatus = beforeStatus, |
| | | TaskNum = task.TaskNum.Value, |
| | | LocationId = location.Id, |
| | | LocationCode = location.LocationCode, |
| | | ChangeType = (int)StatusChangeTypeEnum.AutomaticStorage, |
| | | |
| | | }; |
| | | |
| | | bool isUpdateChange = _locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto); |
| | | bool loc = await _locationRepository.UpdateDataAsync(location); |
| | | |
| | | return isResult && loc; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åè´§ä½å· |
| | | /// </summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | List<DtLocationInfo> LocationInfoList = await _locationRepository.QueryDataAsync(x => x.RoadwayNo == roadWay && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == EnableEnum.Enable.ObjToInt()); |
| | | List<DtLocationInfo> locations = await _locationRepository.QueryDataAsync(x => x.RoadwayNo == "SC1" && x.LocationStatus == 0 && x.EnalbeStatus == 1); |
| | | |
| | | List<DtLocationInfo> LocationInfoResult = new List<DtLocationInfo>(); |
| | | foreach (DtLocationInfo item in LocationInfoList) |
| | | if (locations.Where(x => x.Row == 2).ToList().OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault() != null) |
| | | { |
| | | DtLocationInfo locationItem = new DtLocationInfo(); |
| | | |
| | | if (item.Depth == 2) |
| | | { |
| | | locationItem = _locationRepository.QueryFirst(x => x.Column == item.Column && x.RoadwayNo == item.RoadwayNo && x.Layer == item.Layer && x.Depth != item.Depth && x.Row != item.Row && (SqlFunc.Abs(x.Row - item.Row) == 1) && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == EnableEnum.Enable.ObjToInt()); |
| | | if (locationItem != null) |
| | | { |
| | | LocationInfoResult.Add(item); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | locationItem = _locationRepository.QueryFirst(x => x.Column == item.Column && x.RoadwayNo == item.RoadwayNo && x.Layer == item.Layer && x.Depth != item.Depth && x.Row != item.Row && (SqlFunc.Abs(x.Row - item.Row) == 1) && x.LocationStatus == (int)LocationEnum.InStock && x.EnalbeStatus == EnableEnum.Enable.ObjToInt()); |
| | | if (locationItem != null) |
| | | { |
| | | LocationInfoResult.Add(item); |
| | | } |
| | | } |
| | | return locations.Where(x => x.Row == 2).ToList().OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault(); |
| | | } |
| | | if (LocationInfoResult.Count < 2) |
| | | else if (locations.Where(x => x.Row == 3).ToList().OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault() != null) |
| | | { |
| | | throw new Exception("å½å空é²è´§ä½ä¸è¶³ï¼"); |
| | | return locations.Where(x => x.Row == 3).ToList().OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault(); |
| | | } |
| | | else |
| | | { |
| | | return locations.Where(x => x.Row == 1).ToList().OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public async Task<DtLocationInfo> GetAGVEmptyCacheLocation(int AreaId) |
| | | { |
| | | try |
| | | { |
| | | DtLocationInfo location = null; |
| | | switch (AreaId) |
| | | { |
| | | case 2: |
| | | location = await FromShallowToDeep(AreaId); |
| | | break; |
| | | case 3: |
| | | location = await AGVLIKU(AreaId); |
| | | break; |
| | | case 5: |
| | | case 6: |
| | | location = await FromDeepToShallow(AreaId); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | return LocationInfoResult.OrderByDescending(x => x.Depth).ThenBy(x => x.Column).ThenBy(x => x.Layer).FirstOrDefault(); |
| | | return location; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message) ; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç±æ·±å°æµ
|
| | | /// </summary> |
| | | /// <param name="AreaId"></param> |
| | | /// <returns></returns> |
| | | public async Task<DtLocationInfo> FromDeepToShallow(int AreaId) |
| | | { |
| | | try |
| | | { |
| | | List<DtLocationInfo> locations = await _locationRepository.QueryDataAsync(x => x.AreaId == AreaId && x.LocationStatus == 0 && x.EnalbeStatus == 1); |
| | | |
| | | var location = locations.OrderByDescending(x => x.Column).ThenBy(x => x.Row).FirstOrDefault(); |
| | | |
| | | return location; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç±æµ
å°æ·± |
| | | /// </summary> |
| | | /// <param name="AreaId"></param> |
| | | /// <returns></returns> |
| | | public async Task<DtLocationInfo> FromShallowToDeep(int AreaId) |
| | | { |
| | | try |
| | | { |
| | | List<DtLocationInfo> locations = await _locationRepository.QueryDataAsync(x => x.AreaId == AreaId && x.LocationStatus == 0 && x.EnalbeStatus == 1); |
| | | var location = locations.OrderBy(x => x.Column).ThenBy(x => x.Row).FirstOrDefault(); |
| | | return location; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | public async Task<DtLocationInfo> AGVLIKU(int AreaId) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | List<DtLocationInfo> locations = await _locationRepository.QueryDataAsync(x => x.AreaId == AreaId && x.LocationStatus == 0 && x.EnalbeStatus == 1); |
| | | var location = locations.OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault(); |
| | | return location; |
| | | } |
| | | catch (Exception ex) |
| | | { |