From 81f6ac9523ec63fc99a9d38845972eb83cb54205 Mon Sep 17 00:00:00 2001
From: Ling0925 <2449858657a@gmail.com>
Date: Wed, 22 May 2024 17:19:22 +0800
Subject: [PATCH] =?UTF-8?q?Add=20=E8=A7=92=E8=89=B2=E6=9D=83=E9=99=90?=
=?UTF-8?q?=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
LoginWindow.xaml | 4 +-
Model/ResultModel/RulePermissonResult.cs | 20 +++
Model/RulePermissonModel.cs | 32 ++++
Pages/PermissionConfigPage.xaml | 104 ++++++++++---
Pages/PermissionConfigPage.xaml.cs | 187 ++++++++++++++++++++++-
Util/DBHelper.Rule.cs | 45 ++++++
Util/DBHelper.cs | 15 +-
ViewModel/PermissonConfigViewModel.cs | 83 ++++++++++
8 files changed, 467 insertions(+), 23 deletions(-)
create mode 100644 Model/ResultModel/RulePermissonResult.cs
create mode 100644 Model/RulePermissonModel.cs
create mode 100644 Util/DBHelper.Rule.cs
diff --git a/LoginWindow.xaml b/LoginWindow.xaml
index a8b5ff0..98485cd 100644
--- a/LoginWindow.xaml
+++ b/LoginWindow.xaml
@@ -18,12 +18,12 @@
-
+
-
+
diff --git a/Model/ResultModel/RulePermissonResult.cs b/Model/ResultModel/RulePermissonResult.cs
new file mode 100644
index 0000000..d103290
--- /dev/null
+++ b/Model/ResultModel/RulePermissonResult.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CeramicProjectTool.Model.ResultModel
+{
+ public class RulePermissonResult
+ {
+ public int PermissonId { get; set; }
+ public int RuleId { get; set; }
+ public int FeatureId { get; set; }
+ public string RuleName { get; set; }
+ public string FeatureName { get; set; }
+
+ public bool IsEnabled { get; set; }
+
+ }
+}
diff --git a/Model/RulePermissonModel.cs b/Model/RulePermissonModel.cs
new file mode 100644
index 0000000..902d5e7
--- /dev/null
+++ b/Model/RulePermissonModel.cs
@@ -0,0 +1,32 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CeramicProjectTool.Model
+{
+ /*
+ ###CSharp Code Generate###
+ nr_z_quanxian
+ Create by User(EMAIL) 2024/5/22 14:11:44
+
+nr_z_quanxian
+----------------
+id PKInteger //<<自增长>>
+jsid Integer
+gnid Integer
+
+*/
+ [SugarTable("nr_z_quanxian")]
+ public class RulePermissonModel
+ {
+ [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
+ public int Id { get; set; }
+ [SugarColumn(ColumnName = "jsid")]
+ public int RuleId { get; set; }
+ [SugarColumn(ColumnName = "gnid")]
+ public int FeatureId { get; set; }
+ }
+}
diff --git a/Pages/PermissionConfigPage.xaml b/Pages/PermissionConfigPage.xaml
index e2fdbd8..4f0d680 100644
--- a/Pages/PermissionConfigPage.xaml
+++ b/Pages/PermissionConfigPage.xaml
@@ -7,24 +7,92 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="权限配置" Loaded="Page_Loaded">
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Pages/PermissionConfigPage.xaml.cs b/Pages/PermissionConfigPage.xaml.cs
index a9bab87..eabb60e 100644
--- a/Pages/PermissionConfigPage.xaml.cs
+++ b/Pages/PermissionConfigPage.xaml.cs
@@ -2,6 +2,7 @@
using CeramicProjectTool.ViewModel;
using System;
using System.Collections.Generic;
+using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -35,7 +36,7 @@ namespace CeramicProjectTool.Pages
LoadData();
}
- private void LoadData(string searchText = "")
+ private async void LoadData(string searchText = "")
{
Task> task;
if (string.IsNullOrWhiteSpace(searchText))
@@ -48,13 +49,36 @@ namespace CeramicProjectTool.Pages
task = viewModel.GetPermissons(searchText);
}
- task.ContinueWith((t) =>
+ _ = task.ContinueWith((t) =>
{
permissonData.Dispatcher.Invoke(() =>
{
permissonData.ItemsSource = t.Result;
});
});
+ await task;
+ var ruleTask = viewModel.GetRules();
+ _ = ruleTask.ContinueWith(ruleTask =>
+ {
+ RuleListView.Dispatcher.Invoke(() =>
+ {
+ RuleListView.ItemsSource = ruleTask.Result;
+ RuleListView.SelectedIndex = 0;
+ });
+ });
+
+ await ruleTask;
+ var moduleTask = viewModel.GetMkList();
+ _ = moduleTask.ContinueWith(muduleTask =>
+ {
+ ModuleList.Dispatcher.Invoke(() =>
+ {
+ ModuleList.ItemsSource = muduleTask.Result;
+ ModuleList.SelectedIndex = 0;
+
+ });
+ });
+
}
private void searchBox_TextInput(object sender, TextCompositionEventArgs e)
@@ -74,5 +98,164 @@ namespace CeramicProjectTool.Pages
}
}
}
+
+ private void RuleListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ var datas = ((ListView)sender).ItemsSource as List;
+ var selectedIndex = ((ListView)sender).SelectedIndex;
+ if (selectedIndex != -1)
+ {
+ viewModel.selectRule = datas[selectedIndex];
+ LoadPermisson();
+
+ }
+
+ }
+
+ private void invokePermissonBtn_Click(object sender, RoutedEventArgs e)
+ {
+ var selected = ModulePermissonList.Children;
+ List rulePermissons = new List();
+ foreach (var item in selected)
+ {
+ if (item is CheckBox checkBox)
+ {
+ if (checkBox.IsChecked ?? false)
+ {
+ var featureId = (int)checkBox.Tag;
+ var rule = viewModel.selectRule;
+ //var module = viewModel.selectMudole;
+ var rulePermisson = new RulePermissonModel
+ {
+ RuleId = rule.Id,
+ FeatureId = featureId
+ };
+ rulePermissons.Add(rulePermisson);
+ }
+
+ }
+ }
+ if (rulePermissons.Count > 0)
+ {
+ viewModel.UpdateRulePermisson(rulePermissons);
+ LoadPermisson();
+ }
+
+ }
+
+ private void reinvokePermissonBtn_Click(object sender, RoutedEventArgs e)
+ {
+ var selected = RulePermissonList.Children;
+ List rulePermissons = new List();
+ foreach (var item in selected)
+ {
+ if (item is CheckBox checkBox)
+ {
+ if (checkBox.IsChecked ?? false)
+ {
+ var permissonId = (int)checkBox.Tag;
+ rulePermissons.Add(permissonId);
+ }
+
+ }
+ }
+ if (rulePermissons.Count > 0)
+ {
+ viewModel.DeleteRulePermisson(rulePermissons);
+ LoadPermisson();
+
+ }
+ }
+
+
+ private void ModuleList_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ var datas = ((ComboBox)sender).ItemsSource as List;
+ var selectedIndex = ((ComboBox)sender).SelectedIndex;
+ if (selectedIndex != -1)
+ {
+ var mkModel = datas?[selectedIndex == -1 ? 0 : selectedIndex];
+ viewModel.selectMudole = mkModel;
+ LoadPermisson();
+ }
+
+ }
+
+
+ private async void LoadPermisson()
+ {
+ viewModel.isSelectAll = false;
+ var rule = viewModel.selectRule;
+ var module = viewModel.selectMudole;
+ if (rule == null || module == null)
+ {
+ return;
+ }
+ var rulePremissonTask = viewModel.GetPermissonsByRule(rule.RuleName, module.ModuleName);
+ _ = rulePremissonTask.ContinueWith((t) =>
+ {
+ var result = t.Result;
+ viewModel.rulePermissons = result;
+ RulePermissonList.Dispatcher.Invoke(() =>
+ {
+ RulePermissonList.Children.Clear();
+ result.ForEach(item =>
+ {
+ var checkBox = new CheckBox
+ {
+ Tag = item.PermissonId,
+ Content = item.FeatureName,
+ //IsChecked = item.IsEnabled
+ };
+ RulePermissonList.Children.Add(checkBox);
+ });
+ });
+ });
+ await rulePremissonTask;
+ var modulePremissonTask = viewModel.GetPermissons(module.ModuleName);
+ _ = modulePremissonTask.ContinueWith((t) =>
+ {
+ var result = t.Result;
+ ModulePermissonList.Dispatcher.Invoke(() =>
+ {
+
+ ModulePermissonList.Children.Clear();
+ result.ForEach(item =>
+ {
+ var exist = viewModel.CheckPermissonExist(item.Feature);
+ if (!exist)
+ {
+ var checkBox = new CheckBox
+ {
+ Tag = item.Id,
+ Content = item.Feature,
+ IsChecked = false
+ };
+ ModulePermissonList.Children.Add(checkBox);
+ }
+
+ });
+ });
+ });
+ }
+ //private bool isAllSelected = false;
+ private void selectAllModulePermissonBtn_Click(object sender, RoutedEventArgs e)
+ {
+ viewModel.isSelectAll = !viewModel.isSelectAll;
+ foreach (var item in ModulePermissonList.Children)
+ {
+ if (item is CheckBox checkBox)
+ {
+ if (checkBox.IsEnabled)
+ {
+ ModulePermissonList.Dispatcher.Invoke(() =>
+ {
+ checkBox.IsChecked = viewModel.isSelectAll;
+ });
+ }
+
+ }
+ }
+ }
}
}
diff --git a/Util/DBHelper.Rule.cs b/Util/DBHelper.Rule.cs
new file mode 100644
index 0000000..1568abc
--- /dev/null
+++ b/Util/DBHelper.Rule.cs
@@ -0,0 +1,45 @@
+using CeramicProjectTool.Model;
+using CeramicProjectTool.Model.ResultModel;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CeramicProjectTool.Util
+{
+ public partial class DBHelper
+ {
+ public static async Task> GetPermissonsByRule(string ruleName, string moduleName)
+ {
+
+ /*
+ nr_z_quanxian rp
+ nr_sys_gn p
+ nr_z_yhjs r
+
+ select * from nr_z_quanxian a
+ left join nr_sys_gn b on a.gnid = b.id
+ left join nr_z_yhjs c on a.jsid = c.id
+ */
+ var result = await _db.Queryable((rp, p, r)
+ => new JoinQueryInfos(
+ JoinType.Left, rp.FeatureId == p.Id,
+ JoinType.Left, rp.RuleId == r.Id))
+ .Where((rp, p, r) => r.RuleName == ruleName && p.ModuleName == moduleName)
+ .Select((rp, p, r) => new RulePermissonResult
+ {
+ FeatureId = p.Id,
+ RuleId = r.Id,
+ PermissonId = rp.Id,
+ RuleName = r.RuleName,
+ FeatureName = p.Feature,
+ IsEnabled = true
+ })
+ .ToListAsync();
+ return result;
+ }
+
+ }
+}
diff --git a/Util/DBHelper.cs b/Util/DBHelper.cs
index da95845..01cf4ba 100644
--- a/Util/DBHelper.cs
+++ b/Util/DBHelper.cs
@@ -1,4 +1,5 @@
-using System;
+using CeramicProjectTool.Model;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -9,6 +10,17 @@ namespace CeramicProjectTool.Util
public static partial class DBHelper
{
private static SqlSugar.SqlSugarClient _db;
+ public static SqlSugar.SqlSugarClient Db
+ {
+ get
+ {
+ if (_db == null)
+ {
+ Init();
+ }
+ return _db;
+ }
+ }
public static bool isInit = false;
public static void Init()
{
@@ -30,6 +42,7 @@ namespace CeramicProjectTool.Util
DBHelper.connStr = $"Data Source={dbConfig["dbSource"]};Initial Catalog={dbConfig["dbName"]};User ID={dbConfig["dbUserName"]};Password={dbConfig["dbUserPwd"]}";
}
+
public static string connStr = "";
}
diff --git a/ViewModel/PermissonConfigViewModel.cs b/ViewModel/PermissonConfigViewModel.cs
index 932a2fc..2769fcc 100644
--- a/ViewModel/PermissonConfigViewModel.cs
+++ b/ViewModel/PermissonConfigViewModel.cs
@@ -1,5 +1,7 @@
using CeramicProjectTool.Model;
+using CeramicProjectTool.Model.ResultModel;
using CeramicProjectTool.Util;
+using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -18,7 +20,12 @@ namespace CeramicProjectTool.ViewModel
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
+ public ModuleModel selectMudole;
+ public RuleModel selectRule;
+ public bool isSelectAll = false;
+
+ public List? rulePermissons;
public Task> GetPermissons()
{
var result = DBHelper.GetPermissons();
@@ -29,5 +36,81 @@ namespace CeramicProjectTool.ViewModel
var result = DBHelper.GetPermissonsByModule(searchText);
return result;
}
+
+ public Task> GetRules()
+ {
+ var result = DBHelper.GetRules();
+ return result;
+ }
+
+ public async Task> GetPermissonsByRule(string ruleName, string moduleName)
+ {
+ var result = await DBHelper.GetPermissonsByRule(ruleName, moduleName);
+ return result;
+ }
+
+ public Task> GetMkList()
+ {
+ Task> modelList = DBHelper.GetModuleList();
+
+ return modelList;
+ //modelList.ContinueWith((task) =>
+ //{
+ // ModelListView.Dispatcher.Invoke(() =>
+ // {
+ // ModelListView.ItemsSource = task.Result;
+ // });
+ //});
+ }
+
+ internal void UpdateRulePermisson(List rulePermisson)
+ {
+ var _db = DBHelper.Db;
+
+ try
+ {
+ _db.Ado.BeginTran();
+ //_db.Deleteable().Where(x => x.RuleId == rulePermisson[0].RuleId).ExecuteCommand();
+ _db.Insertable(rulePermisson).ExecuteCommand();
+ _db.Ado.CommitTran();
+ }
+ catch (Exception ex)
+ {
+ _db.Ado.RollbackTran();
+ throw ex;
+ }
+ }
+ internal void DeleteRulePermisson(List rulePermissonId)
+ {
+ var _db = DBHelper.Db;
+
+ try
+ {
+ _db.Ado.BeginTran();
+ _db.Deleteable().Where(x => rulePermissonId.Contains(x.Id)).ExecuteCommand();
+ //_db.Insertable(rulePermisson).ExecuteCommand();
+ _db.Ado.CommitTran();
+ }
+ catch (Exception ex)
+ {
+ _db.Ado.RollbackTran();
+ throw ex;
+ }
+ }
+ internal bool CheckPermissonExist(string featureName)
+ {
+ bool isExist = false;
+ //rulePermissons.ForEach(item =>
+ foreach (var item in rulePermissons)
+ {
+ if (item.FeatureName == featureName)
+ {
+ isExist = true;
+ break;
+ }
+ }
+
+ return isExist;
+ }
}
}