mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 05:13:25 +08:00
Routine Update
This commit is contained in:
parent
36a466143e
commit
cd31e8791d
@ -10,13 +10,10 @@ namespace OpenAuth.App
|
||||
public class ModuleManagerApp
|
||||
{
|
||||
private IModuleRepository _repository;
|
||||
private IOrgRepository _orgRepository;
|
||||
|
||||
public ModuleManagerApp(IModuleRepository repository,
|
||||
IOrgRepository orgRepository)
|
||||
public ModuleManagerApp(IModuleRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
_orgRepository = orgRepository;
|
||||
}
|
||||
|
||||
public int GetModuleCntInOrg(int orgId)
|
||||
@ -57,16 +54,15 @@ namespace OpenAuth.App
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前组织的所有下级组织
|
||||
/// </summary>
|
||||
private int[] GetSubOrgIds(int orgId)
|
||||
public List<Module> LoadForTree(bool bAll)
|
||||
{
|
||||
var org = _orgRepository.FindSingle(u => u.Id == orgId);
|
||||
var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray();
|
||||
return orgs;
|
||||
if (bAll)
|
||||
return _repository.Find(null).ToList();
|
||||
return _repository.Find(u => u.ParentId == 0).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Module Find(int id)
|
||||
{
|
||||
var module = _repository.FindSingle(u => u.Id == id);
|
||||
@ -77,7 +73,10 @@ namespace OpenAuth.App
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(id);
|
||||
var del = _repository.FindSingle(u => u.Id == id);
|
||||
if (del == null) return;
|
||||
|
||||
_repository.Delete(u => u.CascadeId.Contains(del.CascadeId));
|
||||
}
|
||||
|
||||
public void AddOrUpdate(Module model)
|
||||
@ -85,6 +84,29 @@ namespace OpenAuth.App
|
||||
Module module = model;
|
||||
if (module.Id == 0)
|
||||
{
|
||||
string cascadeId;
|
||||
int currentCascadeId = GetMaxCascadeId(module.ParentId);
|
||||
|
||||
if (module.ParentId != 0)
|
||||
{
|
||||
var parentOrg = _repository.FindSingle(o => o.Id == module.ParentId);
|
||||
if (parentOrg != null)
|
||||
{
|
||||
cascadeId = parentOrg.CascadeId + "." + currentCascadeId;
|
||||
module.ParentName = parentOrg.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("未能找到该组织的父节点信息");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cascadeId = "0." + currentCascadeId;
|
||||
module.ParentName = "";
|
||||
}
|
||||
|
||||
module.CascadeId = cascadeId;
|
||||
_repository.Add(module);
|
||||
}
|
||||
else
|
||||
@ -94,6 +116,31 @@ namespace OpenAuth.App
|
||||
|
||||
}
|
||||
|
||||
#region 私有方法
|
||||
|
||||
//根据同一级中最大的语义ID
|
||||
private int GetMaxCascadeId(int parentId)
|
||||
{
|
||||
int currentCascadeId = 1;
|
||||
var sameLevels = _repository.Find(o => o.ParentId == parentId);
|
||||
foreach (var obj in sameLevels)
|
||||
{
|
||||
int objCascadeId = int.Parse(obj.CascadeId.Split('.').Last());
|
||||
if (currentCascadeId < objCascadeId) currentCascadeId = objCascadeId + 1;
|
||||
}
|
||||
|
||||
return currentCascadeId;
|
||||
}
|
||||
|
||||
private int[] GetSubOrgIds(int orgId)
|
||||
{
|
||||
var org = _repository.FindSingle(u => u.Id == orgId);
|
||||
var orgs = _repository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray();
|
||||
return orgs;
|
||||
}
|
||||
|
||||
#endregion 私有方法
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -109,13 +109,13 @@ namespace OpenAuth.App
|
||||
{
|
||||
int currentCascadeId = 1;
|
||||
|
||||
var maxCascadeIdOrg = _repository.Find(o => o.ParentId == parentId)
|
||||
.OrderByDescending(o => o.CascadeId).FirstOrDefault();
|
||||
if (maxCascadeIdOrg != null)
|
||||
var sameLevels = _repository.Find(o => o.ParentId == parentId);
|
||||
foreach (var obj in sameLevels)
|
||||
{
|
||||
var cascades = maxCascadeIdOrg.CascadeId.Split('.');
|
||||
currentCascadeId = int.Parse(cascades[cascades.Length - 1]) + 1;
|
||||
int objCascadeId = int.Parse(obj.CascadeId.Split('.').Last());
|
||||
if (currentCascadeId < objCascadeId) currentCascadeId = objCascadeId + 1;
|
||||
}
|
||||
|
||||
return currentCascadeId;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
return View(_app.Find(id));
|
||||
}
|
||||
|
||||
//添加或修改组织
|
||||
//添加或修改模块
|
||||
[HttpPost]
|
||||
public string Add(Module model)
|
||||
{
|
||||
@ -46,14 +46,31 @@ namespace OpenAuth.Mvc.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载组织下面的所有用户
|
||||
/// 加载模块下面的所有模块
|
||||
/// </summary>
|
||||
public string Load(int orgId, int pageCurrent = 1, int pageSize = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize));
|
||||
}
|
||||
|
||||
//获取组织下面用户个数
|
||||
/// <summary>
|
||||
/// 加载tree结构
|
||||
/// </summary>
|
||||
public string LoadForTree(bool bAll=false)
|
||||
{
|
||||
var orgs = _app.LoadForTree(bAll);
|
||||
//添加根节点
|
||||
orgs.Add(new Module
|
||||
{
|
||||
Id = 0,
|
||||
ParentId = -1,
|
||||
Name = "全部模块",
|
||||
CascadeId = "0"
|
||||
});
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
}
|
||||
|
||||
//获取模块下面模块个数
|
||||
public int GetCount(int orgId)
|
||||
{
|
||||
return _app.GetModuleCntInOrg(orgId);
|
||||
|
@ -14,121 +14,61 @@
|
||||
<tr>
|
||||
<td>
|
||||
@Html.HiddenFor(m => m.Id)
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="CascadeId" class="control-label x90">节点语义ID:</label>
|
||||
<input type="text" name="CascadeId" id="CascadeId" value="@Model.CascadeId"
|
||||
data-rule="required" size="20">
|
||||
@Html.HiddenFor(m =>m.CascadeId)
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="Name" class="control-label x90">功能模块名称:</label>
|
||||
<label for="Name" class="control-label x105">功能模块名称:</label>
|
||||
<input type="text" name="Name" id="Name" value="@Model.Name"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="Url" class="control-label x90">主页面URL:</label>
|
||||
<label for="Url" class="control-label x105">主页面URL:</label>
|
||||
<input type="text" name="Url" id="Url" value="@Model.Url"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="HotKey" class="control-label x90">热键:</label>
|
||||
<input type="text" name="HotKey" id="HotKey" value="@Model.HotKey"
|
||||
data-rule="required" size="20">
|
||||
<label for="ParentId" class="control-label x105">上级功能模块:</label>
|
||||
<input id="ParentId" name="ParentId" value="" style="display: none"/>
|
||||
<input type="text" name="ParentName" id="ParentName"
|
||||
data-toggle="selectztree" size="20" data-tree="#j_select_tree1"
|
||||
value="@Model.ParentName">
|
||||
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<label for="ParentId" class="control-label x85">父节点流水号:</label>
|
||||
|
||||
<select name="ParentId" id="ParentId" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.ParentId == 0) { <text> selected="selected" </text> }>默认</option>
|
||||
<option value="1" @if (Model.ParentId == 1) { <text> selected="selected" </text> }>状态1</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<label for="IsLeaf" class="control-label x85">是否叶子节点:</label>
|
||||
|
||||
<select name="IsLeaf" id="IsLeaf" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.IsLeaf) { <text> selected="selected" </text> }>否</option>
|
||||
<option value="1" @if (!Model.IsLeaf) { <text> selected="selected" </text> }>是</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<label for="IsAutoExpand" class="control-label x85">是否自动展开:</label>
|
||||
|
||||
<select name="IsAutoExpand" id="IsAutoExpand" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.IsAutoExpand) { <text> selected="selected" </text> }>否</option>
|
||||
<option value="1" @if (!Model.IsAutoExpand) { <text> selected="selected" </text> }>是</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="IconName" class="control-label x90">节点图标文件名称:</label>
|
||||
<label for="IconName" class="control-label x105">节点图标文件名称:</label>
|
||||
<input type="text" name="IconName" id="IconName" value="@Model.IconName"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Status" class="control-label x85">当前状态:</label>
|
||||
|
||||
<label for="Status" class="control-label x105">当前状态:</label>
|
||||
<select name="Status" id="Status" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.Status == 0) { <text> selected="selected" </text> }>默认</option>
|
||||
<option value="1" @if (Model.Status == 1) { <text> selected="selected" </text> }>状态1</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="ParentName" class="control-label x90">父节点名称:</label>
|
||||
<input type="text" name="ParentName" id="ParentName" value="@Model.ParentName"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="Vector" class="control-label x90">矢量图标:</label>
|
||||
<label for="Vector" class="control-label x105">矢量图标:</label>
|
||||
<input type="text" name="Vector" id="Vector" value="@Model.Vector"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<label for="SortNo" class="control-label x85">排序号:</label>
|
||||
|
||||
<label for="SortNo" class="control-label x105">排序号:</label>
|
||||
<select name="SortNo" id="SortNo" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.SortNo == 0) { <text> selected="selected" </text> }>默认</option>
|
||||
<option value="1" @if (Model.SortNo == 1) { <text> selected="selected" </text> }>状态1</option>
|
||||
@ -157,8 +97,8 @@
|
||||
},
|
||||
check: {
|
||||
enable: true,
|
||||
chkStyle: "checkbox",
|
||||
chkboxType: { "Y": "", "N": "" } //去掉勾选时级联
|
||||
chkStyle: "radio",
|
||||
radioType: "all"
|
||||
},
|
||||
data: {
|
||||
key: {
|
||||
@ -177,7 +117,7 @@
|
||||
onCheck: zTreeCheck
|
||||
}
|
||||
};
|
||||
$.getJSON('OrgManager/LoadOrg', function (json) {
|
||||
$.getJSON('ModuleManager/LoadForTree?bAll=true', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
@ -199,7 +139,7 @@
|
||||
var $from = $('#' + treeId).data('fromObj');
|
||||
if ($from && $from.length) $from.val(names);
|
||||
|
||||
$('#OrganizationIds').val(ids);
|
||||
$('#ParentId').val(ids);
|
||||
}
|
||||
function zTreeOnClick(event, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId);
|
||||
|
@ -92,7 +92,7 @@
|
||||
},
|
||||
],
|
||||
dataUrl: 'ModuleManager/Load?orgId=' + selectedId,
|
||||
delUrl: 'Module/Delete',
|
||||
delUrl: 'ModuleManager/Delete',
|
||||
delPK: "Id",
|
||||
fullGrid: true,
|
||||
showLinenumber: true,
|
||||
@ -133,7 +133,7 @@
|
||||
},
|
||||
callback: {onClick: zTreeOnClick}
|
||||
};
|
||||
$.getJSON('OrgManager/LoadOrg', function (json) {
|
||||
$.getJSON('ModuleManager/LoadForTree', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#@_treeId'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
|
@ -66,6 +66,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestFunction.cs" />
|
||||
<Compile Include="TestModuleApp.cs" />
|
||||
<Compile Include="TestRoleApp.cs" />
|
||||
<Compile Include="TestUserApp.cs" />
|
||||
<Compile Include="TestOrgApp.cs" />
|
||||
|
96
OpenAuth.UnitTest/TestModuleApp.cs
Normal file
96
OpenAuth.UnitTest/TestModuleApp.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.UnitTest
|
||||
{
|
||||
/// <summary>
|
||||
/// TestModuleApp 的摘要说明
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class TestModuleApp
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
private ModuleManagerApp _app = new ModuleManagerApp(new ModuleRepository());
|
||||
private string _time = DateTime.Now.ToString("HH_mm_ss_ms");
|
||||
/// <summary>
|
||||
///获取或设置测试上下文,该上下文提供
|
||||
///有关当前测试运行及其功能的信息。
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region 附加测试特性
|
||||
//
|
||||
// 编写测试时,可以使用以下附加特性:
|
||||
//
|
||||
// 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
|
||||
// [ClassInitialize()]
|
||||
// public static void MyClassInitialize(TestContext testContext) { }
|
||||
//
|
||||
// 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
|
||||
// [ClassCleanup()]
|
||||
// public static void MyClassCleanup() { }
|
||||
//
|
||||
// 在运行每个测试之前,使用 TestInitialize 来运行代码
|
||||
// [TestInitialize()]
|
||||
// public void MyTestInitialize() { }
|
||||
//
|
||||
// 在每个测试运行完之后,使用 TestCleanup 来运行代码
|
||||
// [TestCleanup()]
|
||||
// public void MyTestCleanup() { }
|
||||
//
|
||||
#endregion
|
||||
|
||||
[TestMethod]
|
||||
public void TestAddModule()
|
||||
{
|
||||
var root = Add();
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
Add(root.Id);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestDelModule()
|
||||
{
|
||||
var root = Add(0);
|
||||
_app.Delete(root.Id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestEdit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Module Add(int parent = 0)
|
||||
{
|
||||
var module = new Module()
|
||||
{
|
||||
Name = "test_" + _time,
|
||||
ParentId = parent
|
||||
};
|
||||
_app.AddOrUpdate(module);
|
||||
return module;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user