diff --git a/BPASmartClient.AGV/AGVHelper.cs b/BPASmartClient.AGV/AGVHelper.cs index acb342e1..e4b50fd8 100644 --- a/BPASmartClient.AGV/AGVHelper.cs +++ b/BPASmartClient.AGV/AGVHelper.cs @@ -8,6 +8,7 @@ using System.Web; using Newtonsoft.Json; using System.Net.Http; using System.Configuration; +using System.Security.Cryptography; namespace BPASmartClient.AGV { @@ -15,10 +16,10 @@ namespace BPASmartClient.AGV { public static AGVHelper _Instance { get; set; } public static AGVHelper GetInstance => _Instance ?? (_Instance = new AGVHelper()); - - public AGVHelper() + + public AGVHelper() { - + } /// /// 获取配置文件信息 @@ -39,7 +40,7 @@ namespace BPASmartClient.AGV return null; } public string HttpRequest(string url, string head, string body) - { + { return PostData(url, head, body); } public string PostData(string url, string head, string body) @@ -71,10 +72,28 @@ namespace BPASmartClient.AGV return retString;//返回响应报文 } /// + /// MD5哈希摘要转16进制 + /// + /// + /// + public string MD5Deal(string body) + { + //如果启用签名 用MD5 哈希摘要 再转16进制 + MD5 md5 = MD5.Create(); + byte[] bte = md5.ComputeHash(Encoding.UTF8.GetBytes(body)); + StringBuilder build = new StringBuilder(); + for (int i = 0; i < bte.Length; i++) + { + build.Append(bte[i].ToString("X")); + } + + return build.ToString(); + } + /// /// AGV去1号线体装桶 /// /// - public string AgvToLineOneLoadRoller(string robotJobId) + public string AgvToLineOneLoadRoller(string robotJobId) { //string url = AGVRequestUrl.GetInstance.TaskSendUrl; ////请求报文头 @@ -85,7 +104,7 @@ namespace BPASmartClient.AGV //HttpRequestHeaderModel.GetInstance.version = "2.8"; //string head = JsonConvert.SerializeObject(HttpRequestHeaderModel.GetInstance); ////请求报文体 - //AGVModel.GetInstance.robotJobId =robotJobId ;//上游提供 + //AGVModel.GetInstance.robotJobId = robotJobId;//上游提供 //AGVModel.GetInstance.warehouseId = 123; //仓库编号 //AGVModel.GetInstance.jobPriority = 1;//任务执行的优先级 //AGVModel.GetInstance.jobPriorityType = 1;//0:根据优先级来执行,1:强制执行 @@ -100,7 +119,8 @@ namespace BPASmartClient.AGV //AGV_PointRollerJobData.GetInstance.enableIOUnload = true;//下料交互方式 false:接口交互 true:光电交互 //AGVModel.GetInstance.jobData = AGV_PointRollerJobData.GetInstance; //string body = JsonConvert.SerializeObject(AGVModel.GetInstance); - //// string newBody = String.Join(",\r\n", bodyData.Split(','));//格式处理,看需求 + //// string newBody = String.Join(",\r\n", body.Split(','));//格式处理,看需求 + ////货位到货位 ////AGV_SlotRollerJobData.GetInstance.startSlotCode = "";//起点槽位编号 ////AGV_SlotRollerJobData.GetInstance.endSlotCode = "";//目的槽位编号 @@ -110,6 +130,8 @@ namespace BPASmartClient.AGV ////AGV_SlotRollerJobData.GetInstance.enableIOUnload = true;//下料交互方式 false:接口交互 true:光电交互 ////AGVModel.GetInstance.jobData = AGV_SlotRollerJobData.GetInstance; ////string body = JsonConvert.SerializeObject(AGVModel.GetInstance); + ////启用签名 + ////url = url + "?sign=" + MD5Deal(body); //string data = HttpRequest(url, head, body); //object objData = JsonConvert.DeserializeObject(data); //if (objData != null && objData is HttpResponseModel response) @@ -157,6 +179,8 @@ namespace BPASmartClient.AGV ////AGV_SlotRollerJobData.GetInstance.enableIOUnload=true;//下料交互方式 false:接口交互 true:光电交互 ////AGVModel.GetInstance.jobData = AGV_SlotRollerJobData.GetInstance; ////string body = JsonConvert.SerializeObject(AGVModel.GetInstance); + ////启用签名 + ////url = url + "?sign=" + MD5Deal(body); //string data= HttpRequest(url, head, body); //object objData= JsonConvert.DeserializeObject(data); //if (objData != null && objData is HttpResponseModel response) @@ -204,6 +228,8 @@ namespace BPASmartClient.AGV ////AGV_SlotRollerJobData.GetInstance.enableIOUnload=true;//下料交互方式 false:接口交互 true:光电交互 ////AGVModel.GetInstance.jobData = AGV_SlotRollerJobData.GetInstance; ////string body = JsonConvert.SerializeObject(AGVModel.GetInstance); + ////启用签名 + ////url = url + "?sign=" + MD5Deal(body); //string data = HttpRequest(url, head, body); //object objData = JsonConvert.DeserializeObject(data); //if (objData != null && objData is HttpResponseModel response) @@ -251,6 +277,8 @@ namespace BPASmartClient.AGV ////AGV_SlotRollerJobData.GetInstance.enableIOUnload=true;//下料交互方式 false:接口交互 true:光电交互 ////AGVModel.GetInstance.jobData = AGV_SlotRollerJobData.GetInstance; ////string body = JsonConvert.SerializeObject(AGVModel.GetInstance); + ////启用签名 + ////url = url + "?sign=" + MD5Deal(body); //string data = HttpRequest(url, head, body); //object objData = JsonConvert.DeserializeObject(data); //if (objData != null && objData is HttpResponseModel response) @@ -298,6 +326,8 @@ namespace BPASmartClient.AGV ////AGV_SlotRollerJobData.GetInstance.enableIOUnload=true;//下料交互方式 false:接口交互 true:光电交互 ////AGVModel.GetInstance.jobData = AGV_SlotRollerJobData.GetInstance; ////string body = JsonConvert.SerializeObject(AGVModel.GetInstance); + ////启用签名 + ////url = url + "?sign=" + MD5Deal(body); //string data = HttpRequest(url, head, body); //object objData = JsonConvert.DeserializeObject(data); //if (objData != null && objData is HttpResponseModel response) @@ -345,6 +375,8 @@ namespace BPASmartClient.AGV ////AGV_SlotRollerJobData.GetInstance.enableIOUnload=true;//下料交互方式 false:接口交互 true:光电交互 ////AGVModel.GetInstance.jobData = AGV_SlotRollerJobData.GetInstance; ////string body = JsonConvert.SerializeObject(AGVModel.GetInstance); + ////启用签名 + ////url = url + "?sign=" + MD5Deal(body); //string data = HttpRequest(url, head, body); //object objData = JsonConvert.DeserializeObject(data); //if (objData != null && objData is HttpResponseModel response) @@ -392,6 +424,8 @@ namespace BPASmartClient.AGV ////AGV_SlotRollerJobData.GetInstance.enableIOUnload=true;//下料交互方式 false:接口交互 true:光电交互 ////AGVModel.GetInstance.jobData = AGV_SlotRollerJobData.GetInstance; ////string body = JsonConvert.SerializeObject(AGVModel.GetInstance); + ////启用签名 + ////url = url + "?sign=" + MD5Deal(body); //string data = HttpRequest(url, head, body); //object objData = JsonConvert.DeserializeObject(data); //if (objData != null && objData is HttpResponseModel response) @@ -439,6 +473,8 @@ namespace BPASmartClient.AGV ////AGV_SlotRollerJobData.GetInstance.enableIOUnload=true;//下料交互方式 false:接口交互 true:光电交互 ////AGVModel.GetInstance.jobData = AGV_SlotRollerJobData.GetInstance; ////string body = JsonConvert.SerializeObject(AGVModel.GetInstance); + ////启用签名 + ////url = url + "?sign=" + MD5Deal(body); //string data = HttpRequest(url, head, body); //object objData = JsonConvert.DeserializeObject(data); //if (objData != null && objData is HttpResponseModel response) @@ -465,6 +501,8 @@ namespace BPASmartClient.AGV AGVTaskCancelModel.GetInstance.robotJobId = robotJobId; AGVTaskCancelModel.GetInstance.warehouseId = 123;//仓库编号 string body = JsonConvert.SerializeObject(AGVTaskCancelModel.GetInstance); + //启用签名 + //url = url + "?sign=" + MD5Deal(body); string data = HttpRequest(url, head, body); object objData = JsonConvert.DeserializeObject(data); if (objData != null && objData is HttpResponseModel response) @@ -490,7 +528,9 @@ namespace BPASmartClient.AGV //请求报文体 AGVTaskCompleteNotifyModel.GetInstance.robotJobId = robotJobId; AGVTaskCompleteNotifyModel.GetInstance.warehouseId = 123;//仓库编号 - string body=JsonConvert.SerializeObject(AGVTaskCompleteNotifyModel.GetInstance); + string body = JsonConvert.SerializeObject(AGVTaskCompleteNotifyModel.GetInstance); + //启用签名 + //url = url + "?sign=" + MD5Deal(body); string data = HttpRequest(url, head, body); object objData = JsonConvert.DeserializeObject(data); if (objData != null && objData is HttpResponseModel response) @@ -506,7 +546,7 @@ namespace BPASmartClient.AGV /// 任务编号 /// 消息编号 /// - public string UpDownFeedBack(string agvCode,string jobId,string msgId) + public string UpDownFeedBack(string agvCode, string jobId, string msgId) { string url = AGVRequestUrl.GetInstance.TaskCompleteUrl; //请求报文头 @@ -518,9 +558,11 @@ namespace BPASmartClient.AGV string head = JsonConvert.SerializeObject(HttpRequestHeaderModel.GetInstance); //请求报文体 AGVLoadInteracteModel.GetInstance.agvCode = agvCode; - AGVLoadInteracteModel.GetInstance.jobId = jobId; - AGVLoadInteracteModel.GetInstance.msgId= msgId; - string body=JsonConvert.SerializeObject(AGVLoadInteracteModel.GetInstance); + AGVLoadInteracteModel.GetInstance.jobId = jobId; + AGVLoadInteracteModel.GetInstance.msgId = msgId; + string body = JsonConvert.SerializeObject(AGVLoadInteracteModel.GetInstance); + //启用签名 + //url = url + "?sign=" + MD5Deal(body); string data = HttpRequest(url, head, body); object objData = JsonConvert.DeserializeObject(data); if (objData != null && objData is HttpResponseModel response) diff --git a/BPASmartClient.AgvApi/Factory.cs b/BPASmartClient.AgvApi/Factory.cs index 80054d82..cf469c4f 100644 --- a/BPASmartClient.AgvApi/Factory.cs +++ b/BPASmartClient.AgvApi/Factory.cs @@ -13,12 +13,12 @@ namespace BPASmartClient.AgvApi public Task SendReport(object obj) { - return HubCallerClient?.Caller.SendAsync("Report", obj); + return HubCallerClient?.Caller.SendAsync("Report", obj);//Invoke客户端Report名称的方法 } public Task SendUpstreamrequest(object obj) { - return HubCallerClient?.Caller.SendAsync("Upstreamrequest", obj); + return HubCallerClient?.Caller.SendAsync("Upstreamrequest", obj);//Invoke客户端Upstreamrequest名称的方法 } } diff --git a/BPASmartClient.AgvApi/PersonHub.cs b/BPASmartClient.AgvApi/PersonHub.cs index 15c8dce4..5dc365a1 100644 --- a/BPASmartClient.AgvApi/PersonHub.cs +++ b/BPASmartClient.AgvApi/PersonHub.cs @@ -2,6 +2,9 @@ namespace BPASmartClient.AgvApi { + /// + /// 服务端 + /// public class PersonHub : Hub { diff --git a/BPASmartClient.AgvApi/Program.cs b/BPASmartClient.AgvApi/Program.cs index 353c3635..019185fb 100644 --- a/BPASmartClient.AgvApi/Program.cs +++ b/BPASmartClient.AgvApi/Program.cs @@ -11,7 +11,7 @@ builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddSignalR(); +builder.Services.AddSignalR();//עSignalR var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/BPASmartClient.CustomResource/Pages/Model/AlarmInfo.cs b/BPASmartClient.CustomResource/Pages/Model/AlarmInfo.cs index 253b09dd..91b14921 100644 --- a/BPASmartClient.CustomResource/Pages/Model/AlarmInfo.cs +++ b/BPASmartClient.CustomResource/Pages/Model/AlarmInfo.cs @@ -9,8 +9,8 @@ namespace BPASmartClient.CustomResource.Pages.Model public class AlarmInfo { public AlarmInfo() - { - + { + } /// /// 1 号滚筒线故障 diff --git a/BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs b/BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs index bbe6b854..86c6f4cb 100644 --- a/BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs +++ b/BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs @@ -44,6 +44,7 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel private void DoNavChanged(object obj) { + ActionManage.GetInstance.Send("RecipeIsChange"); for (int i = 0; i < menuModels.Count; i++) { var res = menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.ToggleWindowPath == obj.ToString()); diff --git a/BPASmartClient.HubHelper/HubHelper.cs b/BPASmartClient.HubHelper/HubHelper.cs index c5443b3a..a687570a 100644 --- a/BPASmartClient.HubHelper/HubHelper.cs +++ b/BPASmartClient.HubHelper/HubHelper.cs @@ -2,6 +2,9 @@ namespace BPASmartClient.HubHelper { + /// + /// 客户端 + /// public class HubHelper { private volatile static HubHelper _Instance; @@ -17,10 +20,9 @@ namespace BPASmartClient.HubHelper { hubConnection = new HubConnectionBuilder().WithAutomaticReconnect().WithUrl($"http://{ip}:{port}/personhub").Build();//连接 - hubConnection.On("Report", (s) => { Report?.Invoke(s); }); - - hubConnection.On("Upstreamrequest", (s) => { Upstreamrequest?.Invoke(s); }); + hubConnection.On("Report", (s) => { Report?.Invoke(s); });//客户端注册方法 + hubConnection.On("Upstreamrequest", (s) => { Upstreamrequest?.Invoke(s); });//客户端注册方法 try { hubConnection.StartAsync(); diff --git a/FryPot_DosingSystem/App.xaml.cs b/FryPot_DosingSystem/App.xaml.cs index 5f7987ef..1d596b2b 100644 --- a/FryPot_DosingSystem/App.xaml.cs +++ b/FryPot_DosingSystem/App.xaml.cs @@ -38,7 +38,7 @@ namespace FryPot_DosingSystem mv.Show(); DeviceOperate deviceOperate = DeviceOperate.GetInstance;//开启实时PLC数据读取 DosingLogicControl logigControl = DosingLogicControl.GetInstance;//开启逻辑控制任务程序 - HubHelper.GetInstance.Connect("192.168.1.130", 8089); + HubHelper.GetInstance.Connect("192.168.1.14", 8089); AlarmHelper.Init(); } else diff --git a/FryPot_DosingSystem/Model/RecipeModel.cs b/FryPot_DosingSystem/Model/RecipeModel.cs index 053bab08..be152b2d 100644 --- a/FryPot_DosingSystem/Model/RecipeModel.cs +++ b/FryPot_DosingSystem/Model/RecipeModel.cs @@ -25,7 +25,7 @@ namespace FryPot_DosingSystem.Model /// 配方下发状况信息 /// private string _recipeSetInfo; - public string RecipeSetInfo { get { return _recipeSetInfo; } set { _recipeSetInfo = value; OnPropertyChanged(); } } + public string RecipeSetInfo { get { return _recipeSetInfo; } set { _recipeSetInfo = value; OnPropertyChanged(); } } public ObservableCollection materialCollection { get; set; } = new ObservableCollection(); } diff --git a/FryPot_DosingSystem/View/NewRecipeView.xaml b/FryPot_DosingSystem/View/NewRecipeView.xaml index 891894a2..aa62f481 100644 --- a/FryPot_DosingSystem/View/NewRecipeView.xaml +++ b/FryPot_DosingSystem/View/NewRecipeView.xaml @@ -211,11 +211,21 @@ BorderBrush="Aqua" VerticalAlignment="Center" FontSize="16" TextChanged="TextBox_TextChanged"> - - - - - + + + + + + + + + + + + + + diff --git a/FryPot_DosingSystem/View/RecipeSendDownView.xaml b/FryPot_DosingSystem/View/RecipeSendDownView.xaml index 7681694a..e5581ac2 100644 --- a/FryPot_DosingSystem/View/RecipeSendDownView.xaml +++ b/FryPot_DosingSystem/View/RecipeSendDownView.xaml @@ -19,6 +19,7 @@ + @@ -109,7 +110,7 @@ - + diff --git a/FryPot_DosingSystem/ViewModel/NewRecipeViewModel.cs b/FryPot_DosingSystem/ViewModel/NewRecipeViewModel.cs index 2355d788..d74cac2a 100644 --- a/FryPot_DosingSystem/ViewModel/NewRecipeViewModel.cs +++ b/FryPot_DosingSystem/ViewModel/NewRecipeViewModel.cs @@ -37,6 +37,7 @@ namespace FryPot_DosingSystem.ViewModel public RelayCommand AddRecipe { get; set; } public RelayCommand RemoveRecipe { get; set; } public RelayCommand Comfirm { get; set; } + public RelayCommand SaveAs { get; set; } public NewRecipeViewModel() { Json.Read(); @@ -59,23 +60,24 @@ namespace FryPot_DosingSystem.ViewModel } } }), "EditRecipe"); + AddRecipe = new RelayCommand(() => { - for (int i = 0; i < RecipeRollerNum; i++) + for (int i = 0; i < RecipeRollerNum; i++) + { + pr1: + string materialCode = Guid.NewGuid().ToString();//原料唯一ID ,后期需要根据实际要求更改 + var res = materials.FirstOrDefault(p => p.MaterialCode == materialCode); + if (res == null) { - pr1: - string materialCode = Guid.NewGuid().ToString();//原料唯一ID ,后期需要根据实际要求更改 - var res = materials.FirstOrDefault(p => p.MaterialCode == materialCode); - if (res == null) - { - materials.Add(new MaterialType() { MaterialCode = materialCode }); - } - else - { - goto pr1; - } + materials.Add(new MaterialType() { MaterialCode = materialCode }); + } + else + { + goto pr1; } - + } + }); RemoveRecipe = new RelayCommand(code => { @@ -116,7 +118,34 @@ namespace FryPot_DosingSystem.ViewModel ActionManage.GetInstance.Send("CloseNewRecipeView"); } }); + SaveAs = new RelayCommand(() => + { + var bom = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == RecipeName); + if (bom == null)//配方名称更改 + { + if (RecipeRollerNum != 0) + { + prop: string recipeID = Guid.NewGuid().ToString();//配方唯一ID,后期根据实际要求更改 + var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeId == recipeID); + if (res == null) + { + Json.Data.Recipes.Add(new NewRecipeModel { RecipeId = recipeID, RecipeName = RecipeName, materialCollection = materials });//配方添加 + } + else + { + goto prop; + } + MessageLog.GetInstance.ShowUserLog("新建配方成功"); + } + else + { + MessageLog.GetInstance.ShowUserLog("新建配方无效【配方中没有添加原料】"); + } + ActionManage.GetInstance.Send("CloseNewRecipeView"); + } + ActionManage.GetInstance.Send("CloseNewRecipeView"); + }); } } } diff --git a/FryPot_DosingSystem/ViewModel/RecipeSetViewModel.cs b/FryPot_DosingSystem/ViewModel/RecipeSetViewModel.cs index be2f8d68..2d332d47 100644 --- a/FryPot_DosingSystem/ViewModel/RecipeSetViewModel.cs +++ b/FryPot_DosingSystem/ViewModel/RecipeSetViewModel.cs @@ -10,6 +10,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; namespace FryPot_DosingSystem.ViewModel { @@ -44,14 +45,32 @@ namespace FryPot_DosingSystem.ViewModel { Json.Read(); recipeModels = Json.Data.Recipes; + int count = recipeModels.Count; + ActionManage.GetInstance.CancelRegister("RecipeIsChange"); + ActionManage.GetInstance.Register(new Action(() => + { + bool b = Json.Data.Recipes.Count==count ? true : false; + if (!b) + { + MessageBoxResult result = MessageBox.Show("配方数据未保存,是否保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information); + if (result == MessageBoxResult.OK) + { + Json.Save();//保存配方 + count = recipeModels.Count; + } + } + + }), "RecipeIsChange"); NewRecipe = new Action(() => { NewRecipeView nrv = new NewRecipeView(); nrv.ShowDialog(); MessageLog.GetInstance.Show("新建配方"); }); - SaveRecipe = new Action(() => { + SaveRecipe = new Action(() => + { Json.Save(); + count = recipeModels.Count; }); EditRecipeCommand = new RelayCommand((Id) => { @@ -67,11 +86,12 @@ namespace FryPot_DosingSystem.ViewModel { if (Id != null && Id is String strId) { - var res= recipeModels.FirstOrDefault(p => p.RecipeId == strId); + var res = recipeModels.FirstOrDefault(p => p.RecipeId == strId); if (res != null && res is NewRecipeModel nes) { recipeModels.Remove(res);//删除配方 Json.Save();//保存配方 + count = recipeModels.Count; } } }); diff --git a/TestDemo/Form1.cs b/TestDemo/Form1.cs index 152a2884..48e90390 100644 --- a/TestDemo/Form1.cs +++ b/TestDemo/Form1.cs @@ -16,7 +16,7 @@ namespace TestDemo { AGVToUpSystem aGVToUpSystem = new AGVToUpSystem(); string value = JsonConvert.SerializeObject(aGVToUpSystem); - string url = $"http://192.168.1.130:8089/apicallback/quicktron/robotjob/report?sign={value}"; + string url = $"http://192.168.1.14:8089/apicallback/quicktron/robotjob/report?sign={value}"; var res = APIHelper.GetInstance.HttpRequest(url, "", aGVToUpSystem, RequestType.POST); } @@ -25,7 +25,7 @@ namespace TestDemo Upstreamrequest aGVToUpSystem = new Upstreamrequest(); string value = JsonConvert.SerializeObject(aGVToUpSystem); - string url = $"http://192.168.1.130:8089/apicallback/quicktron/robotjob/upstreamrequest?sign={value}"; + string url = $"http://192.168.1.14:8089/apicallback/quicktron/robotjob/upstreamrequest?sign={value}"; var res = APIHelper.GetInstance.HttpRequest(url, "", aGVToUpSystem, RequestType.POST); } }