From 5cd01f2caf11e17efc915f7316c78aeddf4832f2 Mon Sep 17 00:00:00 2001 From: Tongg Date: Mon, 21 Apr 2025 17:11:23 +0800 Subject: [PATCH] fix: Optimize configuration items --- Model/Entity/AgileJsonConfigEntity.cs | 159 ++++++------------- Model/Services/SOCClientService.cs | 23 +-- ViewModel/Configuration/AlgorithmConfigVM.cs | 118 +++++++++++++- ViewModel/Grading/GradingLoadingVM.cs | 2 +- Views/Configuration/AlgorithmConfigPage.xaml | 24 ++- 5 files changed, 185 insertions(+), 141 deletions(-) diff --git a/Model/Entity/AgileJsonConfigEntity.cs b/Model/Entity/AgileJsonConfigEntity.cs index 0636609..b587b70 100644 --- a/Model/Entity/AgileJsonConfigEntity.cs +++ b/Model/Entity/AgileJsonConfigEntity.cs @@ -1,5 +1,6 @@ using System.ComponentModel; using System.Runtime.CompilerServices; +using HandyControl.Collections; using SparkClient.ViewModel.Configuration; namespace SparkClient.Model.Entity; @@ -8,29 +9,46 @@ public class AgileJsonConfigEntity { public readonly List Keys; - public AgileJsonConfigEntity(List keys) + + private ManualObservableCollection _runKey; + public ManualObservableCollection RunKey { + get => _runKey; + set + { + _runKey = value; + OnPropertyChanged(nameof(RunKey)); + } + + } + public AgileJsonConfigEntity( List keys) { Shape = "圆形"; + ModeValue = "999"; + SpecValue = "999"; Keys = keys; - JsonKeys = keys; - ModeList = GetRunModelList(); - SpceList = GetRunSpecList(); - _mode = ModeList.FirstOrDefault(); - _spec = SpceList.FirstOrDefault(); + RunKey = new ManualObservableCollection(keys); } - private Param _mode; - public Param Mode + + private string _modeValue; + public string ModeValue { - get => _mode; - set => SetField(ref _mode, value); + get => _modeValue; + set + { + SetField(ref _modeValue, value); + OnPropertyChanged(nameof(ModeValue)); + } } - - private Param _spec; - public Param Spec + private string _specValue; + public string SpecValue { - get => _spec; - set => SetField(ref _spec, value); + get => _specValue; + set + { + SetField(ref _specValue, value); + OnPropertyChanged(nameof(SpecValue)); + } } private string _shape; @@ -48,6 +66,8 @@ public class AgileJsonConfigEntity set { SetField(ref _jsonKey, value); + OnPropertyChanged(nameof(JsonKey)); + FilterItems(value); } } @@ -57,28 +77,21 @@ public class AgileJsonConfigEntity get => _value; set => SetField(ref _value, value); } - - private List _jsonKeys; - - public List JsonKeys - { - get => _jsonKeys; - set => SetField(ref _jsonKeys, value); - } - - private List _modeList; - - public List ModeList + private void FilterItems(string key) { - get => _modeList; - set => SetField(ref _modeList, value); - } - private List _specList; - - public List SpceList - { - get => _specList; - set => SetField(ref _specList, value); + RunKey.CanNotify = false; + RunKey.Clear(); + foreach (var data in Keys) + { + if (data.ToLower().Contains(key.ToLower())) + { + RunKey.Add(data); + } + } + if(RunKey.Count <= 0) + RunKey.Add(key); + RunKey.CanNotify = true; + } @@ -95,77 +108,5 @@ public class AgileJsonConfigEntity OnPropertyChanged(name); return true; } - public List GetRunModelList() - { - return new List - { - new Param() - { - Value = "0", - Name = "实验室模式" - }, - new Param() - { - Value = "1", - Name = "工厂模式" - } - }; - } - - public List GetRunSpecList() - { - return new List - { - new Param() - { - Value = "P8-P8", - Name = "P8-P8" - }, - new Param() - { - Value = "P8-P8-S1", - Name = "P8-P8-S1" - }, - new Param() - { - Value = "P8-P8-S2", - Name = "P8-P8-S2" - }, - new Param() - { - Value = "P8-P8-S3", - Name = "P8-P8-S3" - }, - new Param() - { - Value = "P8-P8-S4", - Name = "P8-P8-S4" - }, - new Param() - { - Value = "P8-P8-S5", - Name = "P8-P8-S5" - }, - new Param() - { - Value = "P8-P8-S6", - Name = "P8-P8-S6" - }, - new Param() - { - Value = "P8-P8-S7", - Name = "P8-P8-S7" - }, - new Param() - { - Value = "P8-P8-S8", - Name = "P8-P8-S8" - } - }; - } + } -public class Param -{ - public string Value { get; set; } - public string Name { get; set; } -} \ No newline at end of file diff --git a/Model/Services/SOCClientService.cs b/Model/Services/SOCClientService.cs index 49bd3b6..1e10016 100644 --- a/Model/Services/SOCClientService.cs +++ b/Model/Services/SOCClientService.cs @@ -203,23 +203,26 @@ namespace SparkClient.Model.Services { throw new Exception("No data found for the specified keys."); } - + + StringBuilder sbParams = new StringBuilder(); foreach (DataRow row in table.Rows) { string key = row["Key"].ToString() ?? string.Empty; string value = row["Value"].ToString() ?? string.Empty; - if (key == "light_level" && int.TryParse(value, out int parsedLightLevel)) - { - lightLevel = parsedLightLevel; // 光照度 - } - else if (key == "half_circle") - { - halfCircle = value; // 半圆 - } + // if (key == "light_level" && int.TryParse(value, out int parsedLightLevel)) + // { + // lightLevel = parsedLightLevel; // 光照度 + // } + // else if (key == "half_circle") + // { + // halfCircle = value; // 半圆 + // } + sbParams.Append($"{key}={value}&"); } - string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}"; + // string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}"; + string url = $"{_baseUrl}/collect_images?{sbParams.ToString().Substring(0, sbParams.ToString().Length - 1)}"; var result = SendGetRequestAsync(url); diff --git a/ViewModel/Configuration/AlgorithmConfigVM.cs b/ViewModel/Configuration/AlgorithmConfigVM.cs index 03ba158..161f4e7 100644 --- a/ViewModel/Configuration/AlgorithmConfigVM.cs +++ b/ViewModel/Configuration/AlgorithmConfigVM.cs @@ -35,9 +35,32 @@ public class AlgorithmConfigVM : BaseViewModel } } + private ObservableCollection _modeList; + public ObservableCollection ModeList + { + get => _modeList; + set + { + _modeList = value; + OnPropertyChanged(nameof(ModeList)); + } + } + + private ObservableCollection _specList; + public ObservableCollection SpecList + { + get => _specList; + set { + _specList = value; + OnPropertyChanged(nameof(ModeList)); + } + } public List _jsonKeysBak; - + public List JsonKeysBak + { + get => _jsonKeysBak; + } private bool _isEnabled; public bool IsEnabled { get { return _isEnabled; } set { _isEnabled = value; OnPropertyChanged(nameof(IsEnabled)); } } @@ -48,6 +71,8 @@ public class AlgorithmConfigVM : BaseViewModel SaveAlgorithmDataCommand = new RelayCommand(SaveAlgorithmData); BeautifyJsonCommand = new RelayCommand(BeautifyJson); UglifyJsonCommand = new RelayCommand(UglifyJson); + ModeList = GetRunModelList(); + SpecList = GetRunSpecList(); InitAlgorithmData(null); IsEnabledByRole(); _jsonKeysBak = GetNestedKeys(JObject.Parse(AlgorithmConfigJson)); @@ -69,15 +94,20 @@ public class AlgorithmConfigVM : BaseViewModel { AgileJsonConfigEntities.Add(new AgileJsonConfigEntity(_jsonKeysBak) { - Mode = baseData.ModeList.Find(e => e.Value.Equals(row["Mode"].ToSafeString())), - Spec = baseData.SpceList.Find(e => e.Value.Equals(row["Spec"].ToSafeString())), + ModeValue = row["Mode"].ToSafeString(), + SpecValue = row["Spec"].ToSafeString(), Shape = row["Shape"].ToSafeString(), JsonKey = row["JsonKey"].ToSafeString(), Value = row["Value"].ToSafeString() }); - } catch { } + } + catch (Exception ex) + { + Logger.Error(ex.Message); + } } } + } [Log] private bool CheckAndSaveAgileJson() @@ -89,10 +119,10 @@ public class AlgorithmConfigVM : BaseViewModel if (string.IsNullOrWhiteSpace(row.JsonKey) || string.IsNullOrWhiteSpace(row.Value) || string.IsNullOrWhiteSpace(row.Shape)) continue; - if (row.Mode == null || row.Spec == null) + if (row.ModeValue.IsNullOrEmpty()|| row.SpecValue.IsNullOrEmpty()) continue; insertSql.Add($"INSERT INTO AGILE_ALGORITHM_CONFIG (GUID, Mode, Spec, Shape, JsonKey, Value)" + - $@"VALUES ('{row.GenerateSign()}',{row.Mode.Value},'{row.Spec.Value}','{row.Shape}','{row.JsonKey}','{row.Value}');"); + $@"VALUES ('{row.GenerateSign()}',{row.ModeValue},'{row.SpecValue}','{row.Shape}','{row.JsonKey}','{row.Value}');"); finalSaveData.Add(row); } @@ -204,6 +234,7 @@ public class AlgorithmConfigVM : BaseViewModel // 命令实现 public ICommand AddCommand => new RelayCommand((param) => { + string data = GetAlgorithmConfig("P8 P8"); AgileJsonConfigEntities.Add(new AgileJsonConfigEntity(_jsonKeysBak)); }); @@ -341,6 +372,77 @@ public class AlgorithmConfigVM : BaseViewModel return AlgorithmConfigJson; } - + public ObservableCollection GetRunModelList() + { + return new ObservableCollection + { + new Param() + { + Value = "0", + Name = "实验室模式" + }, + new Param() + { + Value = "1", + Name = "工厂模式" + } + }; + } + + public ObservableCollection GetRunSpecList() + { + return new ObservableCollection + { + new Param() + { + Value = "P8-P8", + Name = "P8-P8" + }, + new Param() + { + Value = "P8-P8-S1", + Name = "P8-P8-S1" + }, + new Param() + { + Value = "P8-P8-S2", + Name = "P8-P8-S2" + }, + new Param() + { + Value = "P8-P8-S3", + Name = "P8-P8-S3" + }, + new Param() + { + Value = "P8-P8-S4", + Name = "P8-P8-S4" + }, + new Param() + { + Value = "P8-P8-S5", + Name = "P8-P8-S5" + }, + new Param() + { + Value = "P8-P8-S6", + Name = "P8-P8-S6" + }, + new Param() + { + Value = "P8-P8-S7", + Name = "P8-P8-S7" + }, + new Param() + { + Value = "P8-P8-S8", + Name = "P8-P8-S8" + } + }; + } +} +public class Param +{ + public string Value { get; set; } + public string Name { get; set; } } - diff --git a/ViewModel/Grading/GradingLoadingVM.cs b/ViewModel/Grading/GradingLoadingVM.cs index dae741e..da4cf44 100644 --- a/ViewModel/Grading/GradingLoadingVM.cs +++ b/ViewModel/Grading/GradingLoadingVM.cs @@ -229,7 +229,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable if(type == 0) { - await SOCClientService.Service.OpenPump(true); + await SOCClientService.Service.OpenPump(true); // if (!StatusCodes.Success.Equals(openpupmStatus)) // { // new MessageBox().Show("气泵开启失败!"); diff --git a/Views/Configuration/AlgorithmConfigPage.xaml b/Views/Configuration/AlgorithmConfigPage.xaml index b4b7fa3..3678809 100644 --- a/Views/Configuration/AlgorithmConfigPage.xaml +++ b/Views/Configuration/AlgorithmConfigPage.xaml @@ -137,11 +137,10 @@ - + @@ -158,12 +157,10 @@ - + @@ -172,8 +169,9 @@ - +