| | |
| | | using WIDESEA_Core.BaseRepository; |
| | | using AutoMapper; |
| | | using Mapster; |
| | | using AngleSharp.Dom; |
| | | using Masuit.Tools.Security; |
| | | using WIDESEA_IStorageTaskServices; |
| | | using System.Threading.Tasks; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using WIDESEA_IBusinessesRepository; |
| | | using WIDESEA_Repository; |
| | | |
| | | namespace WIDESEA_StorageSocketServices |
| | | { |
| | |
| | | private readonly IDt_Task_HtyRepository _task_HtyRepository; |
| | | private readonly IMapper _mapper; |
| | | private readonly ILocationInfoRepository _locationRepository; |
| | | private readonly IDt_TaskService _taskService; |
| | | private readonly IDt_HostLogRepository _hostLogRepository; |
| | | private bool _IsOnline=false; |
| | | |
| | | |
| | | public SocketClientService(IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger) |
| | | public SocketClientService(IDt_TaskService TaskService, IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger, ILocationInfoRepository locationInfoRepository,IDt_HostLogRepository hostLogRepository) |
| | | { |
| | | BaseDal = TaskRepository; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _logger = logger; |
| | | _taskService = TaskService; |
| | | _locationRepository = locationInfoRepository; |
| | | _hostLogRepository = hostLogRepository; |
| | | #region |
| | | //if (App.RootServices != null) |
| | | //{ |
| | | // IDt_TaskRepository? BaseDal = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(IDt_TaskRepository)) as IDt_TaskRepository; |
| | | // IDt_TaskService? _taskService = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(IDt_TaskService)) as IDt_TaskService; |
| | | // ILocationInfoRepository? _locationRepository = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(ILocationInfoRepository)) as ILocationInfoRepository; |
| | | // IDt_StationManagerRepository? _stationManagerRepository = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(IDt_StationManagerRepository)) as IDt_StationManagerRepository; |
| | | //} |
| | | #endregion |
| | | } |
| | | |
| | | public void ConnectServer(string IP, int Port) |
| | |
| | | // æ£æ¥æ¯å¦å·²è¿æ¥ï¼é¿å
éå¤å建 |
| | | if (socket != null && socket.Connected) |
| | | { |
| | | //Console.WriteLine("Socketå·²è¿æ¥ï¼æ ééå¤å建"); |
| | | ConsoleHelper.WriteErrorLine($"Socketå·²å¤äºè¿æ¥ç¶æ"); |
| | | return; |
| | | } |
| | | |
| | | //å建è´è´£éä¿¡çsocket |
| | | socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
| | | IPAddress ip = IPAddress.Parse(IP); |
| | |
| | | |
| | | _logger.LogInformation("Socketè¿æ¥æå"); |
| | | ConsoleHelper.WriteSuccessLine("Socketè¿æ¥æå"); |
| | | |
| | | _IsOnline = true; |
| | | RequestCommunication(); |
| | | DeviceStateReport("I"); |
| | | |
| | |
| | | Thread th = new Thread(Receive); |
| | | th.IsBackground = true; |
| | | th.Start(); |
| | | ConsoleHelper.WriteErrorLine($"Socketå¯å¨"); |
| | | return; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _IsOnline = false; |
| | | ConsoleHelper.WriteErrorLine($"Socketè¿æ¥å¤±è´¥{ex.Message}"); |
| | | HandleDisconnection(); |
| | | } |
| | | } |
| | | public bool Socketonline() |
| | | { |
| | | return _IsOnline; |
| | | } |
| | | void Receive() |
| | | { |
| | |
| | | } |
| | | catch |
| | | { |
| | | _IsOnline = false; |
| | | HandleDisconnection(); |
| | | |
| | | } |
| | |
| | | ReceiveCommandResponse(x); |
| | | break; |
| | | case "906": |
| | | AGVJobStartOrEndResponse(x.Substring(21, 1), x.Substring(22, 1)); |
| | | AGVJobStartOrEndResponse(x.Substring(20, 1), x.Substring(21, 1)); |
| | | break; |
| | | case "902": |
| | | DataReportResponse(x.Substring(21, 1)); |
| | | DataReportResponse(x.Substring(20, 1)); |
| | | break; |
| | | case "935": |
| | | DeviceStationStatusInvite(x.Substring(15, 5)); |
| | |
| | | RecreateGetLocation(x); |
| | | break; |
| | | case "108": |
| | | RecreateGetLocation(x.Substring(21, 1)); |
| | | EmptyOutBoundResponse(x.Substring(20, 1)); |
| | | break; |
| | | case "909": |
| | | DeviceStatusReportRequest(); |
| | |
| | | attempts--; |
| | | } while (!socket.Connected && attempts > 0); |
| | | } |
| | | |
| | | //private void CheckTimeout(object state) |
| | | //{ |
| | | // TimeSpan elapsed = DateTime.Now - _lastActivityTime; |
| | | // if (elapsed.TotalSeconds > 180) // 3åéè¶
æ¶ |
| | | // { |
| | | // Console.WriteLine("è¶
æ¶æªæ¶å°æ°æ®ï¼è§¦å909å½ä»¤å¹¶å°è¯éæ°è¿æ¥..."); |
| | | |
| | | // // 触å909å½ä»¤ |
| | | // _workTaskService.DeviceStatusReportRequest(); |
| | | |
| | | // // å°è¯éæ°è¿æ¥ |
| | | // HandleDisconnection(); |
| | | // } |
| | | //} |
| | | |
| | | public void clientSend(byte[] buffer) |
| | | { |
| | | var Y = Encoding.UTF8.GetString(buffer); |
| | |
| | | /// ä¼å
级 é¢ç |
| | | /// </summary> |
| | | public const string priority = "1"; |
| | | |
| | | /// <summary> |
| | | /// éå
¥åº |
| | | /// </summary> |
| | | public const string Restocking = "2100"; |
| | | |
| | | |
| | | public const string EmptyOutBoundconst = "2101"; |
| | | |
| | | /// <summary> |
| | | /// æçä¸ªæ° é¢ç |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "101" + BaseDal.GetSeqNo().Result.ToString("D5") + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + "1" + GetFieldsAsString(inStation); |
| | | string str = SendandReply + "101" + BaseDal.GetSeqNo().Result.ToString("D5") + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + OutStationSpare2 + "1" + GetFieldsAsString(inStation); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | try |
| | | { |
| | | string str = SendandReply + "901" + BaseDal.GetSeqNo().Result.ToString("D5") + "0" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | { |
| | | CommandID = 901, |
| | | Count=0, |
| | | Messgae=str, |
| | | }; |
| | | _hostLogRepository.AddData(hostLog); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | try |
| | | { |
| | | string str = SendandReply + "105" + BaseDal.GetSeqNo().Result.ToString("D5") + "R" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | { |
| | | CommandID = 105, |
| | | Count = 0, |
| | | Messgae = str, |
| | | }; |
| | | _hostLogRepository.AddData(hostLog); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | try |
| | | { |
| | | string str = SendandReply + "107" + BaseDal.GetSeqNo().Result.ToString("D5") + "1" + JobOrderID + priority + FormLocation + ToLocation + "O" + TrayCnt + PallteCode; |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | { |
| | | CommandID = 107, |
| | | Count = 0, |
| | | Messgae = str, |
| | | }; |
| | | _hostLogRepository.AddData(hostLog); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | public void ReceiveCommandResponse(string message) |
| | | { |
| | | var parseMessage = GetParse(message); |
| | | var lcationEnd = parseMessage.body.ToLocation; |
| | | switch (parseMessage.body.ret) |
| | | { |
| | | //OK |
| | | case "0": |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == parseMessage.body.ToLocation); |
| | | //var location = _locationRepository.QueryFirst(x => x.LocationCode == lcationEnd); |
| | | var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.ToLocation).First(); |
| | | if (location == null) |
| | | { |
| | | return; |
| | | } |
| | | if (location.LocationStatus == (int)LocationEnum.Free) |
| | | { |
| | | InsertWMSTask(parseMessage); |
| | | var task = InsertWMSTask(parseMessage); |
| | | Thread.Sleep(500); |
| | | InsertAGVTask(task); |
| | | location.LocationStatus = 1; |
| | | //SqlSugarHelper.DbWMS.Insertable(task).ExecuteCommand(); |
| | | SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommand(); |
| | | BaseDal.AddData(task); |
| | | //915 |
| | | JobReady("0"); |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | ErrorReport(Restocking, "A", "00"); |
| | | Thread.Sleep(500); |
| | | RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | //todoè´§ä½æè´§éå¤å
¥åº |
| | | return; |
| | | } |
| | |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | LogFactory.GetLog("Host102åå¤WMS101").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(parseMessage)}{Environment.NewLine}", ""); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | LogFactory.GetLog("Host906åå¤WMS905").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(status)}{Environment.NewLine}{JsonConvert.SerializeObject(message)}{Environment.NewLine}", ""); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public void DataReportResponse(string message) |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskState == (int)TaskOutStatusEnum.AGV_OutFinish || x.TaskState == (int)TaskRelocationStatusEnum.AGV_RelocationFinish || x.TaskState == (int)TaskInStatusEnum.AGV_InFinish); |
| | | if (task != null) |
| | | { |
| | | switch (task.TaskType) |
| | | { |
| | | case (int)TaskInboundTypeEnum.Inbound: |
| | | //å
¥åº |
| | | task.TaskState = (int)TaskInStatusEnum.AGV_InFinish; |
| | | if (message == "0") |
| | | { |
| | | JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode); |
| | | } |
| | | CompleteInboundTask(task); |
| | | break; |
| | | case (int)TaskOutboundTypeEnum.Outbound: |
| | | //åºåº |
| | | if (message == "0") |
| | | { |
| | | JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode); |
| | | } |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish; |
| | | CompleteOutboundTask(task); |
| | | break; |
| | | case (int)TaskRelocationTypeEnum.Relocation: |
| | | if (message == "0") |
| | | { |
| | | JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode); |
| | | } |
| | | task.TaskState = (int)TaskRelocationStatusEnum.AGV_RelocationFinish; |
| | | CompleteRelocationboundTask(task); |
| | | break; |
| | | case (int)TaskStationTypeEnum.StationToStation: |
| | | if (message == "0") |
| | | { |
| | | JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode); |
| | | } |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish; |
| | | TaskMoveHty(task); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | } |
| | | LogFactory.GetLog("Host902åå¤WMS901").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(message)}{Environment.NewLine}", ""); |
| | | #region |
| | | //Dt_Task task = BaseDal.QueryFirst(x => (x.TaskState == (int)TaskOutStatusEnum.AGV_OutFinish || x.TaskState == (int)TaskRelocationStatusEnum.AGV_RelocationFinish || x.TaskState == (int)TaskInStatusEnum.AGV_InFinish) && x.Roadway != "PDA"); |
| | | //if (task != null) |
| | | //{ |
| | | // switch (task.TaskType) |
| | | // { |
| | | // case 200: |
| | | // //å
¥åº |
| | | // if (message == "0") |
| | | // { |
| | | // JobStartOrEnd("E", task.Remark, task.TargetAddress, "O", task.PalletCode); |
| | | // } |
| | | // break; |
| | | // case 100: |
| | | // //åºåº |
| | | // if (message == "0") |
| | | // { |
| | | // JobStartOrEnd("E", task.SourceAddress, task.Remark, "O", task.PalletCode); |
| | | // } |
| | | // break; |
| | | // case 300: |
| | | // if (message == "0") |
| | | // { |
| | | // JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode); |
| | | // } |
| | | // _taskService.CompleteRelocationboundTask(task); |
| | | // break; |
| | | // case 400: |
| | | // if (message == "0") |
| | | // { |
| | | // JobStartOrEnd("E", task.Remark, task.HostName, "O", task.PalletCode); |
| | | // } |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | //} |
| | | #endregion |
| | | } |
| | | /// <summary> |
| | | /// HOSTä¸ååºåºä»»å¡ å·¥åº103 |
| | |
| | | { |
| | | //OK |
| | | case "0": |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == parseMessage.body.ToLocation); |
| | | var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.FromLocation).First(); |
| | | if (location == null) |
| | | { |
| | | return; |
| | | } |
| | | if (location.LocationStatus == (int)LocationEnum.InStock) |
| | | { |
| | | var task = InsertWMSTask(parseMessage); |
| | | BaseDal.AddData(task); |
| | | Dt_Task task = InsertWMSTask(parseMessage); |
| | | //BaseDal.AddData(task); |
| | | location.LocationStatus = 1; |
| | | SqlSugarHelper.DbWMS.Insertable(task).ExecuteCommand(); |
| | | SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommand(); |
| | | InsertAGVTask(task); |
| | | Thread.Sleep(500); |
| | | //Thread.Sleep(500); |
| | | //915 |
| | | JobReady("0"); |
| | | Thread.Sleep(500); |
| | |
| | | } |
| | | else |
| | | { |
| | | //todoè´§ä½æ 货空åºåº |
| | | ErrorReport(EmptyOutBoundconst, "A", "00"); |
| | | Thread.Sleep(500); |
| | | EmptyOutBound(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | return; |
| | | } |
| | | |
| | |
| | | default: |
| | | break; |
| | | } |
| | | LogFactory.GetLog("Host103").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(parseMessage)}{Environment.NewLine}", ""); |
| | | |
| | | } |
| | | catch (Exception) |
| | | catch (Exception ex) |
| | | { |
| | | DeviceReceiveJobResponse("1"); |
| | | } |
| | |
| | | try |
| | | { |
| | | //åå¤936 |
| | | List<OutStationStatus> outStationStatus = new List<OutStationStatus>(); |
| | | List<InStationStatus> inStationStatus = new List<InStationStatus>(); |
| | | |
| | | StationStatus stationIn = GetStationStatus("B002"); |
| | | |
| | | inStationStatus.Add(new InStationStatus() |
| | | { |
| | | StationName = "02", |
| | | StationEnable = stationIn.WorkstationO == "1" ? "0" : "1", |
| | | IsDistributionTask = "0", |
| | | PallteCode = "0000000000", |
| | | }); |
| | | inStationStatus.Add(new InStationStatus() |
| | | { |
| | | StationName = "01", |
| | | StationEnable = stationIn.WorkstationT == "1" ? "0" : "1", |
| | | IsDistributionTask = "0", |
| | | PallteCode = "0000000000", |
| | | }); |
| | | |
| | | StationStatus stationOut = GetStationStatus("B001"); |
| | | var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1"); |
| | | var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2"); |
| | | outStationStatus.Add(new OutStationStatus() |
| | | { |
| | | StationName = "04", |
| | | StationEnable = stationOut.WorkstationO == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationO == null ? "0" : "1", |
| | | Spare1 = "00" |
| | | }); |
| | | outStationStatus.Add(new OutStationStatus() |
| | | { |
| | | StationName = "03", |
| | | StationEnable = stationOut.WorkstationT == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationT == null ? "0" : "1", |
| | | Spare1 = "00" |
| | | }); |
| | | List<OutStationStatus> outStationStatus = GetOutStationStatus(stationOut); |
| | | List<InStationStatus> inStationStatus = GetInStationStatus(stationIn); |
| | | |
| | | #region |
| | | //inStationStatus.Add(new InStationStatus() |
| | | //{ |
| | | // StationName = "02", |
| | | // StationEnable = stationIn.WorkstationO == "1" ? "0" : "1", |
| | | // IsDistributionTask = "0", |
| | | // PallteCode = "0000000000", |
| | | //}); |
| | | //inStationStatus.Add(new InStationStatus() |
| | | //{ |
| | | // StationName = "01", |
| | | // StationEnable = stationIn.WorkstationT == "1" ? "0" : "1", |
| | | // IsDistributionTask = "0", |
| | | // PallteCode = "0000000000", |
| | | //}); |
| | | //var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1"); |
| | | //var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2"); |
| | | //outStationStatus.Add(new OutStationStatus() |
| | | //{ |
| | | // StationName = "04", |
| | | // StationEnable = stationOut.WorkstationO == "1" ? "0" : "1", |
| | | // IsDistributionTask = taskOutStationO == null ? "0" : "1", |
| | | // Spare1 = "00" |
| | | //}); |
| | | //outStationStatus.Add(new OutStationStatus() |
| | | //{ |
| | | // StationName = "03", |
| | | // StationEnable = stationOut.WorkstationT == "1" ? "0" : "1", |
| | | // IsDistributionTask = taskOutStationT == null ? "0" : "1", |
| | | // Spare1 = "00" |
| | | //}); |
| | | #endregion |
| | | AGVStatusRespone status = GetAGVStatus(); |
| | | HOSTAGVStatus AgvStatus = new HOSTAGVStatus() |
| | | { |
| | | RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus), |
| | | AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0", |
| | | Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1", |
| | | //Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1", |
| | | }; |
| | | if (status.RuntimeStatus == "Idle" && status.AutoStatus == "ControlMode") |
| | | { |
| | | AgvStatus.Ready = "1"; |
| | | } |
| | | else |
| | | { |
| | | AgvStatus.Ready = "0"; |
| | | } |
| | | DeviceStationStatusReport(AgvStatus, outStationStatus, inStationStatus, sSeqNo); |
| | | } |
| | | catch (Exception) |
| | |
| | | DeviceReceiveJobResponse("1"); |
| | | } |
| | | |
| | | LogFactory.GetLog("Host935").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(sSeqNo)}{Environment.NewLine}", ""); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | try |
| | | { |
| | | var parseMessage = GetParse(message); |
| | | var lcationEnd = parseMessage.body.ToLocation; |
| | | switch (parseMessage.body.ret) |
| | | { |
| | | //OK |
| | | case "0": |
| | | UpdateTaskLocation(parseMessage); |
| | | break; |
| | | var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.ToLocation).First(); |
| | | if (location == null) |
| | | { |
| | | ErrorReport("2102", "A", "00"); |
| | | Thread.Sleep(500); |
| | | RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | return; |
| | | } |
| | | if (location.LocationStatus == (int)LocationEnum.Free) |
| | | { |
| | | var task = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.PalletCode == parseMessage.body.TrayIdList.Substring(0, 10)).First(); |
| | | if (task == null) |
| | | { |
| | | location.LocationStatus = (int)LocationEnum.Lock; |
| | | var tasknew = InsertWMSTask(parseMessage); |
| | | InsertAGVTask(tasknew); |
| | | BaseDal.AddData(tasknew); |
| | | SqlSugarHelper.DbWMS.Updateable(location); |
| | | Thread.Sleep(500); |
| | | //915 |
| | | JobReady("0"); |
| | | } |
| | | else |
| | | { |
| | | var Agvtask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum.ToString()).First(); |
| | | location.LocationStatus = (int)LocationEnum.Lock; |
| | | task.TargetAddress = lcationEnd; |
| | | Agvtask.d_involed2 = lcationEnd; |
| | | SqlSugarHelper.DbWMS.Updateable(task); |
| | | SqlSugarHelper.DbWMS.Updateable(location); |
| | | SqlSugarHelper.DbAGV.Updateable(Agvtask); |
| | | Thread.Sleep(500); |
| | | //915 |
| | | JobReady("0"); |
| | | } |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | ErrorReport(Restocking, "A", "00"); |
| | | Thread.Sleep(500); |
| | | RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | return; |
| | | } |
| | | //NG |
| | | case "1": |
| | | break; |
| | |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | LogFactory.GetLog("Host106éæ°åé
åºä½").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(parseMessage)}{Environment.NewLine}", ""); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | DeviceReceiveJobResponse("1"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | if (message != null && message == "0") |
| | | { |
| | | DeviceStateReport("I"); |
| | | Thread.Sleep(500); |
| | | Thread.Sleep(2000); |
| | | JobReady("1"); |
| | | |
| | | } |
| | | LogFactory.GetLog("Host108空åºåºååº").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(message)}{Environment.NewLine}", ""); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus), |
| | | AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0", |
| | | Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1", |
| | | |
| | | }; |
| | | if (status.RuntimeStatus == "Idle" && status.AutoStatus == "ControlMode") |
| | | { |
| | | AgvStatus.Ready = "1"; |
| | | } |
| | | else |
| | | { |
| | | AgvStatus.Ready = "0"; |
| | | } |
| | | string axis = "000000"; |
| | | |
| | | DeviceStatusReportResponse(AgvStatus, axis, axis); |
| | | |
| | | LogFactory.GetLog("Hostå¿è·³").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(AgvStatus)}{Environment.NewLine}{JsonConvert.SerializeObject(status)}{Environment.NewLine}", ""); |
| | | } |
| | | #endregion |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public List<OutStationStatus> GetOutStationStatus(StationStatus stationOut) |
| | | { |
| | | List<OutStationStatus> outStationStatus = new List<OutStationStatus>(); |
| | | var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1"); |
| | | var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2"); |
| | | outStationStatus.Add(new OutStationStatus() |
| | | { |
| | | StationName = "04", |
| | | StationEnable = stationOut.WorkstationO == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationO == null ? "0" : "1", |
| | | Spare1 = "00" |
| | | }); |
| | | outStationStatus.Add(new OutStationStatus() |
| | | { |
| | | StationName = "03", |
| | | StationEnable = stationOut.WorkstationT == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationT == null ? "0" : "1", |
| | | Spare1 = "00" |
| | | }); |
| | | return outStationStatus; |
| | | } |
| | | |
| | | public List<InStationStatus> GetInStationStatus(StationStatus stationIn) |
| | | { |
| | | List<InStationStatus> inStationStatus = new List<InStationStatus>(); |
| | | var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B002::1" || x.TargetAddress == "B002::1"); |
| | | var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B002::2" || x.TargetAddress == "B002::2"); |
| | | inStationStatus.Add(new InStationStatus() |
| | | { |
| | | StationName = "02", |
| | | StationEnable = stationIn.WorkstationO == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationO == null ? "0" : "1", |
| | | PallteCode = "0000000000", |
| | | }); |
| | | inStationStatus.Add(new InStationStatus() |
| | | { |
| | | StationName = "01", |
| | | StationEnable = stationIn.WorkstationT == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationT == null ? "0" : "1", |
| | | PallteCode = "0000000000", |
| | | }); |
| | | return inStationStatus; |
| | | } |
| | | public ParseMessage SubString(string Y) |
| | | { |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | |
| | | |
| | | Console.WriteLine("æ ¡éªå¤±è´¥ï¼"); |
| | | return null; |
| | | } |
| | |
| | | #endregion |
| | | |
| | | #region ç§ææ¹æ³ |
| | | private void UpdateTaskLocation(ParseMessage parseMessage) |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.SeqNo == Convert.ToInt32(parseMessage.nSeqNo) && x.PalletCode.Contains(parseMessage.body.TrayIdList)); |
| | | if (task != null) |
| | | { |
| | | task.TargetAddress = parseMessage.body.ToLocation; |
| | | task_call agvtask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(it => it.d_involed5 == task.TaskNum).First(); |
| | | BaseDal.Update(task); |
| | | SqlSugarHelper.DbAGV.Updateable(agvtask).ExecuteCommand(); |
| | | } |
| | | |
| | | } |
| | | |
| | | private Dt_Task InsertWMSTask(ParseMessage parseMessage) |
| | | { |
| | | //var task = BaseDal.QueryFirst(x => x.PalletCode.Contains(parseMessage.body.TrayIdList)); |
| | | int taskType = 0; |
| | | int taskState = 0; |
| | | Dt_Task task = new Dt_Task(); |
| | | if (parseMessage.body.JobType == "I") |
| | | { |
| | | Dt_StationManager Instation = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.FromLocation.Substring(4, 2)); |
| | | task.SourceAddress = Instation.stationName; |
| | | task.TargetAddress = parseMessage.body.ToLocation; |
| | | task.CurrentAddress = Instation.stationName; |
| | | task.NextAddress = parseMessage.body.ToLocation; |
| | | taskType = (int)TaskInboundTypeEnum.Inbound; |
| | | taskState = (int)TaskInStatusEnum.InNew; |
| | | task.Remark = parseMessage.body.FromLocation; |
| | | |
| | | } |
| | | else if (parseMessage.body.JobType == "O") |
| | | { |
| | | task.SourceAddress = parseMessage.body.FromLocation; |
| | | Dt_StationManager Instation = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.ToLocation.Substring(4, 2)); |
| | | task.TargetAddress = Instation.stationName; |
| | | task.CurrentAddress = parseMessage.body.FromLocation; |
| | | task.NextAddress = Instation.stationName; |
| | | taskType = (int)TaskOutboundTypeEnum.Outbound; |
| | | taskState = (int)TaskOutStatusEnum.OutNew; |
| | | task.Remark = parseMessage.body.ToLocation; |
| | | } |
| | | else if (parseMessage.body.JobType == "S") |
| | | { |
| | | Dt_StationManager stationone = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.FromLocation.Substring(4, 2)); |
| | | Dt_StationManager stationtwo = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.ToLocation.Substring(4, 2)); |
| | | taskType = (int)TaskStationTypeEnum.StationToStation; |
| | | taskState = (int)TaskOutStatusEnum.OutNew; |
| | | task.SourceAddress = stationone.stationName; |
| | | task.TargetAddress = stationtwo.stationName; |
| | | task.CurrentAddress = stationone.stationName; |
| | | task.NextAddress = stationtwo.stationName; |
| | | task.Remark = parseMessage.body.FromLocation; |
| | | task.HostName = parseMessage.body.ToLocation; |
| | | task.HostName = parseMessage.body.ToLocation; |
| | | } |
| | | else if (parseMessage.body.JobType == "R") |
| | | { |
| | | taskType = (int)TaskRelocationTypeEnum.Relocation; |
| | | taskState = (int)TaskRelocationStatusEnum.RelocationNew; |
| | | |
| | | task.SourceAddress = parseMessage.body.FromLocation; |
| | | task.TargetAddress = parseMessage.body.ToLocation; |
| | | task.CurrentAddress = parseMessage.body.FromLocation; |
| | | task.NextAddress = parseMessage.body.ToLocation; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("æªç¥åºä½"); |
| | | } |
| | | return new Dt_Task() |
| | | { |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | SourceAddress = parseMessage.body.FromLocation, |
| | | TargetAddress = parseMessage.body.ToLocation, |
| | | PalletCode = parseMessage.body.TrayIdList.Substring(0, 10), |
| | | TaskType = taskType, |
| | | TaskState = taskState, |
| | | Dispatchertime = DateTime.Now, |
| | | SeqNo = Convert.ToInt32(parseMessage.nSeqNo), |
| | | CommandID = Convert.ToInt32(parseMessage.bCmdID) |
| | | }; |
| | | |
| | | |
| | | task.TaskNum = BaseDal.GetTaskNo().Result; |
| | | task.PalletCode = parseMessage.body.TrayIdList.Substring(0, 10); |
| | | task.TaskType = taskType; |
| | | task.TaskState = taskState; |
| | | task.Dispatchertime = DateTime.Now; |
| | | task.Grade = 1; |
| | | task.SeqNo = Convert.ToInt32(parseMessage.nSeqNo); |
| | | task.CommandID = Convert.ToInt32(parseMessage.bCmdID); |
| | | return task; |
| | | |
| | | } |
| | | /// <summary> |
| | |
| | | string TargetAddress = string.Empty; |
| | | if (task.TaskType == (int)TaskInboundTypeEnum.Inbound) |
| | | { |
| | | SourceAddress = task.SourceAddress; |
| | | TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress); |
| | | } |
| | | else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound) |
| | | { |
| | | SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); |
| | | TargetAddress = task.TargetAddress; |
| | | } |
| | | else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation) |
| | | { |
| | |
| | | } |
| | | task_call task_Call = new task_call() |
| | | { |
| | | d_task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? 1 : 2, |
| | | d_floor = 1, |
| | | d_task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? "1" : "2", |
| | | d_floor = "1", |
| | | d_involed1 = SourceAddress, |
| | | d_involed2 = TargetAddress, |
| | | d_involed5 = task.TaskNum, |
| | | d_involed5 = task.TaskNum.ToString(), |
| | | }; |
| | | |
| | | return SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand(); |
| | |
| | | nSeqNo = x.Substring(15, 5), |
| | | body = new ReceiveBody |
| | | { |
| | | ret = x.Substring(21, 1), |
| | | JobOrderID = x.Substring(22, 16), |
| | | priority = x.Substring(39, 1), |
| | | FromLocation = x.Substring(40, 6), |
| | | ToLocation = x.Substring(47, 6), |
| | | JobType = x.Substring(54, 1), |
| | | TrayCnt = x.Substring(55, 1), |
| | | TrayIdList = x.Substring(56) |
| | | ret = x.Substring(20, 1), |
| | | JobOrderID = x.Substring(21, 16), |
| | | priority = x.Substring(37, 1), |
| | | FromLocation = x.Substring(38, 6), |
| | | ToLocation = x.Substring(44, 6), |
| | | JobType = x.Substring(50, 1), |
| | | TrayCnt = x.Substring(51, 1), |
| | | TrayIdList = x.Substring(52) |
| | | }, |
| | | }; |
| | | } |
| | |
| | | { |
| | | return ""; |
| | | } |
| | | |
| | | char firstChar = s[0]; |
| | | return char.ToUpper(firstChar).ToString(); |
| | | } |
| | |
| | | |
| | | return result.ToString(); |
| | | } |
| | | #region å¤é¨æ¥å£æ¹æ³ |
| | | |
| | | public WebResponseContent CompleteInboundTask(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | locationInf.LocationStatus = (int)LocationEnum.InStock; |
| | | var stock = new DtStockInfo() |
| | | { |
| | | PalletCode = task.PalletCode, |
| | | LocationCode = task.TargetAddress, |
| | | CreateDate = DateTime.Now, |
| | | Creater = "system", |
| | | LocationId = locationInf.Id, |
| | | }; |
| | | _stockInfoRepository.AddData(stock); |
| | | _locationRepository.UpdateData(locationInf); |
| | | TaskMoveHty(task); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent CompleteOutboundTask(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | locationInf.LocationStatus = (int)LocationEnum.Free; |
| | | var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode); |
| | | |
| | | DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>(); |
| | | stockInfo_Hty.ModifyDate = DateTime.Now; |
| | | |
| | | AddStockInfoHty(stockInfo_Hty); |
| | | |
| | | _stockInfoRepository.DeleteData(stock); |
| | | _locationRepository.UpdateData(locationInf); |
| | | |
| | | TaskMoveHty(task); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent CompleteRelocationboundTask(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); |
| | | locationInf.LocationStatus = (int)LocationEnum.InStock; |
| | | location.LocationStatus = (int)LocationEnum.Free; |
| | | |
| | | var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode); |
| | | |
| | | stock.LocationCode = locationInf.LocationCode; |
| | | stock.LocationId = locationInf.Id; |
| | | |
| | | |
| | | _stockInfoRepository.UpdateData(stock); |
| | | _locationRepository.UpdateData(locationInf); |
| | | _locationRepository.UpdateData(location); |
| | | TaskMoveHty(task); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | public WebResponseContent TaskMoveHty(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | var taskHtyNG = CreateHistoricalTask(task); |
| | | var isTaskHtyAdd = _task_HtyRepository.AddData(taskHtyNG) > 0; |
| | | var isTaskDelete = Delete(task.TaskId); |
| | | var AgvTask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum).First(); |
| | | if (AgvTask != null) |
| | | { |
| | | SqlSugarHelper.DbAGV.Deleteable(AgvTask).ExecuteCommand(); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion å¤é¨æ¥å£æ¹æ³ |
| | | |
| | | #region private å
鍿¹æ³ |
| | | |
| | | /// <summary> |
| | | /// å建åå²ä»»å¡è®°å½ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public Dt_Task_Hty CreateHistoricalTask(Dt_Task task, bool isHand = false) |
| | | { |
| | | task.CurrentAddress = task.NextAddress; |
| | | |
| | | // å建åå²ä»»å¡ |
| | | var taskHty = _mapper.Map<Dt_Task_Hty>(task); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.TaskId = 0; |
| | | taskHty.OperateType = isHand ? (int)OperateTypeEnum.人工å é¤ : App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.SourceId = task.TaskId; |
| | | if (isHand) |
| | | { |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | } |
| | | return taskHty; |
| | | } |
| | | /// <summary> |
| | | /// å é¤ä¸ä¸ªä»»å¡ |
| | | /// </summary> |
| | | /// <param name="id">ä»»å¡ID</param> |
| | | /// <returns>æ¯å¦å 餿å</returns> |
| | | public bool Delete(int id) |
| | | { |
| | | return BaseDal.Delete(id); |
| | | } |
| | | private void AddStockInfoHty(DtStockInfo_Hty dtStock) |
| | | { |
| | | var isStockAdd = SqlSugarHelper.DbWMS.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommand(); |
| | | if (!isStockAdd) |
| | | { |
| | | throw new Exception("åºååå²ä¿¡æ¯æ·»å 失败"); |
| | | } |
| | | } |
| | | |
| | | #endregion private å
鍿¹æ³ |
| | | #endregion |
| | | } |
| | | } |