| | |
| | | private readonly ILocationInfoRepository _locationRepository; |
| | | private readonly IDt_TaskRepository BaseDal; |
| | | private readonly IDt_TaskService _taskService; |
| | | private readonly IStockInfoRepository _stockInfoRepository; |
| | | private readonly ISys_ConfigService _configService; |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | private readonly LogFactory LogFactory = new LogFactory(); |
| | | public SocketClientService _Socket { get; set; } |
| | |
| | | private readonly IDt_DeviceInfoRepository _deviceInfoRepository; |
| | | private readonly IDt_HandAutomaticRepository _handAutomaticRepository; |
| | | |
| | | public AGVService(ILocationInfoRepository locationRepository, IDt_TaskRepository taskRepository, IStockInfoRepository stockInfoRepository, ISys_ConfigService configService, IDt_StationManagerRepository stationManagerRepository, IDt_DeviceInfoRepository deviceInfoRepository, IMapper mapper, SocketClientService socketClientService, IDt_TaskService taskService, IDt_HandAutomaticRepository handAutomaticRepository) |
| | | public AGVService(ILocationInfoRepository locationRepository, IDt_TaskRepository taskRepository, IDt_StationManagerRepository stationManagerRepository, IDt_DeviceInfoRepository deviceInfoRepository, IMapper mapper, SocketClientService socketClientService, IDt_TaskService taskService, IDt_HandAutomaticRepository handAutomaticRepository) |
| | | { |
| | | _locationRepository = locationRepository; |
| | | BaseDal = taskRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _configService = configService; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _deviceInfoRepository = deviceInfoRepository; |
| | | _mapper = mapper; |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var HandAutomatic = _handAutomaticRepository.QueryFirst(x => true && x.HandAutomatic == "Automatic"); |
| | | if (HandAutomatic == null) |
| | | var location = _locationRepository.QueryData(x => x.LocationStatus==(int)LocationEnum.Free).ToList(); |
| | | if (location.Count == 0) |
| | | { |
| | | return content.Error("å½å䏿¯èªå¨æ¨¡å¼ä¸å¯ä¸åä»»å¡"); |
| | | return content.Error("åºå
æ å¯ç¨åºä½"); |
| | | } |
| | | Dt_StationManager Instation = _stationManagerRepository.QueryFirst(x => x.stationName == aGVDTO.SourceAddress && x.stationType == 1); |
| | | List<Dt_StationManager> Outstation = _stationManagerRepository.QueryData(x => x.stationType == 2).ToList(); |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var HandAutomatic = _handAutomaticRepository.QueryFirst(x => true && x.HandAutomatic == "Automatic"); |
| | | if (HandAutomatic == null) |
| | | { |
| | | _Socket.DeviceAutoStatusReport("1"); |
| | | return content.OK(); |
| | | } |
| | | //var HandAutomatic = _handAutomaticRepository.QueryFirst(x => true && x.HandAutomatic == "Automatic"); |
| | | //if (HandAutomatic == null) |
| | | //{ |
| | | // _Socket.DeviceAutoStatusReport("1"); |
| | | // return content.OK(); |
| | | //} |
| | | Dt_DeviceInfo device = _deviceInfoRepository.QueryFirst(x => x.DeviceName == Status.AGVName); |
| | | if (device != null) |
| | | { |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == aGVDTO.TaskNum); |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == Convert.ToInt32(aGVDTO.TaskNum)); |
| | | if (task != null) |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | switch (task.TaskType) |
| | | { |
| | | LogFactory.GetLog("AGVå¨ä½ç¶æåæ´PDAä»»å¡").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(aGVDTO)}", ""); |
| | | if (aGVDTO.Status == "Start") |
| | | { |
| | | _taskService.TaskStatus(task); |
| | | return content.OK(); |
| | | } |
| | | else if (aGVDTO.Status == "Unload") |
| | | { |
| | | return _taskService.TaskComplete(task.TaskNum); |
| | | } |
| | | else |
| | | { |
| | | return content.OK(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | switch (task.TaskType) |
| | | { |
| | | case (int)TaskInboundTypeEnum.Inbound: |
| | | //å
¥åº |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationName == task.SourceAddress); |
| | | if (aGVDTO.Status == "Start") |
| | | case (int)TaskInboundTypeEnum.Inbound: |
| | | //å
¥åº |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationName == task.SourceAddress); |
| | | if (aGVDTO.Status == "Start") |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _taskService.TaskStatus(task); |
| | | return content.OK(); |
| | | } |
| | | else |
| | | { |
| | | _Socket.JobStartOrEnd(aGVDTO.Status.Substring(0, 1), "0000" + station.HostName, task.TargetAddress, "I", task.PalletCode); |
| | | task.TaskState = (int)TaskInStatusEnum.AGV_InExecuting; |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), "0000" + station.HostName, task.TargetAddress, "I", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), "0000" + station.HostName, task.TargetAddress, "I", task.PalletCode); |
| | | _Socket.PalletActionReportPDA("0000" + station.HostName, task.TargetAddress, "I", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), "0000" + station.HostName, task.TargetAddress, "I", task.PalletCode); |
| | | Thread.Sleep(2000); |
| | | _Socket.PalletActionReport("0000" + station.HostName, task.TargetAddress, "I", task.PalletCode); |
| | | task.TaskState = (int)TaskInStatusEnum.AGV_InFinish; |
| | | _taskService.CompleteInboundTask(task); |
| | | } |
| | | break; |
| | | case (int)TaskOutboundTypeEnum.Outbound: |
| | | //åºåº |
| | | var stationOut = _stationManagerRepository.QueryFirst(x => x.stationName == task.TargetAddress); |
| | | if (aGVDTO.Status == "Start") |
| | | task.TaskState = (int)TaskInStatusEnum.AGV_InFinish; |
| | | _taskService.CompleteInboundTask(task); |
| | | } |
| | | break; |
| | | case (int)TaskOutboundTypeEnum.Outbound: |
| | | //åºåº |
| | | var stationOut = _stationManagerRepository.QueryFirst(x => x.stationName == task.TargetAddress); |
| | | if (aGVDTO.Status == "Start") |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _taskService.TaskStatus(task); |
| | | return content.OK(); |
| | | } |
| | | else |
| | | { |
| | | _Socket.JobStartOrEnd(aGVDTO.Status.Substring(0, 1), task.SourceAddress, "0000" + stationOut.HostName, "O", task.PalletCode); |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutExecuting; |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), task.SourceAddress, "0000" + stationOut.HostName, "O", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), task.SourceAddress, "0000" + stationOut.HostName, "O", task.PalletCode); |
| | | _Socket.PalletActionReportPDA(task.SourceAddress, "0000" + stationOut.HostName, "O", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), task.SourceAddress, "0000" + stationOut.HostName, "O", task.PalletCode); |
| | | Thread.Sleep(2000); |
| | | _Socket.PalletActionReport(task.SourceAddress, "0000" + stationOut.HostName, "O", task.PalletCode); |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish; |
| | | _taskService.CompleteOutboundTask(task); |
| | | } |
| | | break; |
| | | case (int)TaskRelocationTypeEnum.Relocation: |
| | | if (aGVDTO.Status == "Start") |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish; |
| | | _taskService.CompleteOutboundTask(task); |
| | | } |
| | | break; |
| | | case (int)TaskRelocationTypeEnum.Relocation: |
| | | if (aGVDTO.Status == "Start") |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _taskService.TaskStatus(task); |
| | | return content.OK(); |
| | | } |
| | | else |
| | | { |
| | | _Socket.JobStartOrEnd(aGVDTO.Status.Substring(0, 1), task.SourceAddress, task.TargetAddress, "R", task.PalletCode); |
| | | task.TaskState = (int)TaskRelocationStatusEnum.AGV_RelocationExecuting; |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), task.SourceAddress, task.TargetAddress, "R", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), task.SourceAddress, task.TargetAddress, "R", task.PalletCode); |
| | | _Socket.PalletActionReportPDA(task.SourceAddress, task.TargetAddress, "R", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), task.SourceAddress, task.TargetAddress, "R", task.PalletCode); |
| | | Thread.Sleep(2000); |
| | | _Socket.PalletActionReport(task.SourceAddress, task.TargetAddress, "R", task.PalletCode); |
| | | task.TaskState = (int)TaskRelocationStatusEnum.AGV_RelocationFinish; |
| | | _taskService.CompleteRelocationboundTask(task); |
| | | } |
| | | break; |
| | | case (int)TaskStationTypeEnum.StationToStation: |
| | | var stationIn = _stationManagerRepository.QueryFirst(x => x.stationName == task.SourceAddress); |
| | | var stationout = _stationManagerRepository.QueryFirst(x => x.stationName == task.TargetAddress); |
| | | if (aGVDTO.Status == "Start") |
| | | task.TaskState = (int)TaskRelocationStatusEnum.AGV_RelocationFinish; |
| | | _taskService.CompleteRelocationboundTask(task); |
| | | } |
| | | break; |
| | | case (int)TaskStationTypeEnum.StationToStation: |
| | | var stationIn = _stationManagerRepository.QueryFirst(x => x.stationName == task.SourceAddress); |
| | | var stationout = _stationManagerRepository.QueryFirst(x => x.stationName == task.TargetAddress); |
| | | if (aGVDTO.Status == "Start") |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _taskService.TaskStatus(task); |
| | | return content.OK(); |
| | | } |
| | | else |
| | | { |
| | | _Socket.JobStartOrEnd(aGVDTO.Status.Substring(0, 1), "0000" + stationIn.HostName, "0000" + stationout.HostName, "S", task.PalletCode); |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutExecuting; |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), "0000" + stationIn.HostName, "0000" + stationout.HostName, "S", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), "0000" + stationIn.HostName, "0000" + stationout.HostName, "S", task.PalletCode); |
| | | _Socket.PalletActionReportPDA("0000" + stationIn.HostName, "0000" + stationout.HostName, "S", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), "0000" + stationIn.HostName, "0000" + stationout.HostName, "S", task.PalletCode); |
| | | Thread.Sleep(2000); |
| | | _Socket.PalletActionReport("0000" + stationIn.HostName, "0000" + stationout.HostName, "S", task.PalletCode); |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish; |
| | | _taskService.TaskMoveHty(task); |
| | | } |
| | | break; |
| | | default: break; |
| | | } |
| | | BaseDal.Update(task); |
| | | LogFactory.GetLog("AGVå¨ä½ç¶æåæ´").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(aGVDTO)}", ""); |
| | | return content.OK(); |
| | | } |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish; |
| | | _taskService.TaskMoveHty(task); |
| | | } |
| | | break; |
| | | case (int)TaskFireAlarmTypeEnum.FireAlarmOut: |
| | | if (aGVDTO.Status == "Start") |
| | | { |
| | | _taskService.AddStcokHty(task.PalletCode, task.SourceAddress); |
| | | task.TaskState = (int)TaskFireAlarmStatusEnum.AGV_FireAlarmExecuting; |
| | | BaseDal.Update(task); |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | { |
| | | |
| | | } |
| | | else |
| | | { |
| | | |
| | | var stationFireAlarm = _stationManagerRepository.QueryFirst(x => x.stationName == task.TargetAddress); |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _Socket.PalletActionReportFrie(task.SourceAddress, "0000" + stationFireAlarm.HostName, "F", task.PalletCode); ; |
| | | } |
| | | task.TaskState = (int)TaskFireAlarmStatusEnum.AGV_FireAlarmFinish; |
| | | _taskService.TaskMoveHty(task); |
| | | } |
| | | break; |
| | | case (int)TaskOutboundTypeEnum.OutQuality: |
| | | //æ½æ£ |
| | | var stationC = _stationManagerRepository.QueryFirst(x => x.stationName == task.TargetAddress); |
| | | if (aGVDTO.Status == "Start") |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _taskService.TaskStatus(task); |
| | | return content.OK(); |
| | | } |
| | | else |
| | | { |
| | | _Socket.JobStartOrEnd(aGVDTO.Status.Substring(0, 1), task.SourceAddress, "0000" + stationC.HostName, "C", task.PalletCode); |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutExecuting; |
| | | } |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | return content.OK(); |
| | | } |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), task.SourceAddress, "0000" + stationC.HostName, "C", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _taskService.TaskComplete(task.TaskNum); |
| | | _Socket.PalletActionReportPDA(task.SourceAddress, "0000" + stationC.HostName, "O", task.PalletCode); |
| | | } |
| | | else |
| | | { |
| | | _Socket.PalletActionReport(aGVDTO.Status.Substring(0, 1), task.SourceAddress, "0000" + stationC.HostName, "C", task.PalletCode); |
| | | Thread.Sleep(2000); |
| | | _Socket.PalletActionReport(task.SourceAddress, "0000" + stationC.HostName, "C", task.PalletCode); |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish; |
| | | _taskService.CompleteOutboundTask(task); |
| | | } |
| | | } |
| | | break; |
| | | case (int)TaskInboundTypeEnum.InQuality: |
| | | //æ½æ£ |
| | | if (aGVDTO.Status == "Start") |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _taskService.TaskStatus(task); |
| | | return content.OK(); |
| | | } |
| | | } |
| | | else if (aGVDTO.Status == "Loadel") |
| | | { |
| | | return content.OK(); |
| | | } |
| | | else |
| | | { |
| | | if (task.Roadway == "PDA") |
| | | { |
| | | _taskService.TaskComplete(task.TaskNum); |
| | | } |
| | | } |
| | | break; |
| | | default: break; |
| | | } |
| | | BaseDal.Update(task); |
| | | LogFactory.GetLog("AGVå¨ä½ç¶æåæ´").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(aGVDTO)}", ""); |
| | | return content.OK(); |
| | | } |
| | | else |
| | | { |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.TaskNum == aGVDTO.TaskNum); |
| | | var task = BaseDal.QueryFirst(x => x.TaskNum ==Convert.ToInt32( aGVDTO.TaskNum)); |
| | | if (task != null) |
| | | { |
| | | |
| | | string HostType = string.Empty; |
| | | if (task.TaskType == (int)TaskInboundTypeEnum.Inbound) |
| | | { |
| | | HostType = "I"; |
| | | } |
| | | else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound) |
| | | { |
| | | HostType = "O"; |
| | | } |
| | | else if (task.TaskType == (int)TaskOutboundTypeEnum.OutQuality) |
| | | { |
| | | HostType = "C"; |
| | | } |
| | | else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation) |
| | | { |
| | | HostType = "R"; |
| | | } |
| | | else if (task.TaskType == (int)TaskStationTypeEnum.StationToStation) |
| | | { |
| | | HostType = "S"; |
| | | } |
| | | switch (aGVDTO.Message) |
| | | { |
| | | case "RepeatInbound": |
| | | |
| | | //空åºåº |
| | | case "0000400": |
| | | _Socket.EmptyOutBound(task.SourceAddress, "0000" + StationParse(task.TargetAddress), task.PalletCode); |
| | | _taskService.AddStcokHty(task.PalletCode, task.SourceAddress); |
| | | _taskService.TaskMoveHty(task); |
| | | _Socket.AddErrorMessage("2101", "AGV", ""); |
| | | break; |
| | | case "EmptyOutbound": |
| | | |
| | | //éå
¥åº |
| | | case "0000200": |
| | | _Socket.RecreateGetLocation("0000" + StationParse(task.SourceAddress), task.TargetAddress, HostType, task.PalletCode); |
| | | _Socket.AddErrorMessage("2100", "AGV", ""); |
| | | break; |
| | | default: break; |
| | | } |
| | | } |
| | | LogFactory.GetLog("AGVå¼å¸¸ä¿¡æ¯").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(aGVDTO)}", ""); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public string StationParse(string station) |
| | | { |
| | | var Station = SqlSugarHelper.DbWMS.Queryable<Dt_StationManager>().Where(x => x.stationName == station).First(); |
| | | if (Station != null) |
| | | { |
| | | return Station.HostName; |
| | | } |
| | | else |
| | | { |
| | | return ""; |
| | | } |
| | | } |
| | | #endregion å¤é¨æ¥å£æ¹æ³ |
| | | } |
| | | } |