feat: 部门增加编码

This commit is contained in:
Argo 2019-07-15 10:29:42 +08:00
parent 5f940611aa
commit 3ba18ac948
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
23 changed files with 54 additions and 37 deletions

View File

@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.11" />
<PackageReference Include="Longbow.Configuration" Version="2.2.4" />
<PackageReference Include="Longbow.Tasks" Version="1.5.0" />
<PackageReference Include="Longbow.Tasks" Version="1.6.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />

Binary file not shown.

View File

@ -36,8 +36,8 @@ namespace Bootstrap.Admin.Query
var ret = new QueryData<object>();
ret.total = data.Count();
data = Order == "asc" ? data.OrderBy(t => t.GroupName) : data.OrderByDescending(t => t.GroupName);
ret.rows = data.Skip(Offset).Take(Limit).Select(g => new { g.Id, g.GroupName, g.Description });
ret.rows = data.Skip(Offset).Take(Limit).Select(g => new { g.Id, g.GroupCode, g.GroupName, g.Description });
return ret;
}
}
}
}

View File

@ -47,6 +47,10 @@
<label class="control-label" for="groupName">部门名称</label>
<input type="text" class="form-control" id="groupName" placeholder="不可为空50字以内" maxlength="50" data-valid="true" />
</div>
<div class="form-group col-sm-6">
<label class="control-label" for="groupCode">部门编码</label>
<input type="text" class="form-control" id="groupCode" placeholder="不可为空50字以内" maxlength="50" data-valid="true" />
</div>
<div class="form-group col-sm-6">
<input type="hidden" id="groupID" />
<label class="control-label" for="groupDesc">部门描述</label>

View File

@ -11,6 +11,7 @@ $(function () {
dataBinder: {
map: {
Id: "#groupID",
GroupCode: "#groupCode",
GroupName: "#groupName",
Description: "#groupDesc"
},
@ -67,6 +68,7 @@ $(function () {
sortName: 'GroupName',
queryParams: function (params) { return $.extend(params, { groupName: $("#txt_search_name").val(), description: $("#txt_group_desc").val() }); }, //传递参数(*
columns: [
{ title: "部门编码", field: "GroupCode", sortable: true },
{ title: "部门名称", field: "GroupName", sortable: true },
{ title: "部门描述", field: "Description", sortable: false }
],

View File

@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security" Version="1.6.0-preview-1" />
<PackageReference Include="MongoDB.Driver" Version="2.8.1" />
</ItemGroup>

View File

@ -230,16 +230,30 @@ namespace Bootstrap.DataAccess.MongoDB
md.UnmapMember(m => m.Menus);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapGroup)))
{
BsonClassMap.RegisterClassMap<BootstrapGroup>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Group)))
{
BsonClassMap.RegisterClassMap<DataAccess.Group>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
md.UnmapMember(group => group.Checked);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Group)))
{
BsonClassMap.RegisterClassMap<Group>(md =>
{
md.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Role)))
{
BsonClassMap.RegisterClassMap<DataAccess.Role>(md =>

View File

@ -1,4 +1,5 @@
using MongoDB.Driver;
using Bootstrap.Security;
using MongoDB.Driver;
using System.Collections.Generic;
using System.Linq;
@ -34,6 +35,7 @@ namespace Bootstrap.DataAccess.MongoDB
{
DbManager.Groups.InsertOne(new Group()
{
GroupCode = p.GroupCode,
GroupName = p.GroupName,
Description = p.Description,
Roles = new List<string>()
@ -134,14 +136,13 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override IEnumerable<string> RetrievesByUserName(string userName)
public override IEnumerable<BootstrapGroup> RetrievesByUserName(string userName)
{
var groups = new List<string>();
var groups = new List<BootstrapGroup>();
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.UserName == userName);
var group = GroupHelper.Retrieves();
groups.AddRange(user.Groups.Select(r => group.FirstOrDefault(rl => rl.Id == r).GroupName));
if (groups.Count == 0) groups.Add("Default");
groups.AddRange(group.Where(g => user.Groups.Any(ug => ug == g.Id)));
return groups;
}
}

View File

@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.7" />
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.8-preview-1" />
<PackageReference Include="Longbow.Data" Version="2.3.3" />
<PackageReference Include="Longbow.Logging" Version="2.2.9" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />

View File

@ -1,4 +1,5 @@
using Bootstrap.Security.DataAccess;
using Bootstrap.Security;
using Bootstrap.Security.DataAccess;
using PetaPoco;
using System;
using System.Collections.Generic;
@ -10,18 +11,8 @@ namespace Bootstrap.DataAccess
///
/// </summary>
[TableName("Groups")]
public class Group
public class Group : BootstrapGroup
{
/// <summary>
/// 获得/设置 群组主键ID
/// </summary>
public string Id { get; set; }
/// <summary>
/// 获得/设置 群组名称
/// </summary>
public string GroupName { get; set; }
/// <summary>
/// 获得/设置 群组描述
/// </summary>
@ -84,7 +75,7 @@ namespace Bootstrap.DataAccess
public virtual IEnumerable<Group> RetrievesByUserId(string userId)
{
var db = DbManager.Create();
return db.Fetch<Group>($"select g.ID, g.GroupName, g.Description, case ug.GroupID when g.ID then 'checked' else '' end Checked from {db.Provider.EscapeSqlIdentifier("Groups")} g left join UserGroup ug on g.ID = ug.GroupID and UserID = @0", userId);
return db.Fetch<Group>($"select g.ID, g.GroupCode, g.GroupName, g.Description, case ug.GroupID when g.ID then 'checked' else '' end Checked from {db.Provider.EscapeSqlIdentifier("Groups")} g left join UserGroup ug on g.ID = ug.GroupID and UserID = @0", userId);
}
/// <summary>
@ -95,7 +86,7 @@ namespace Bootstrap.DataAccess
public virtual IEnumerable<Group> RetrievesByRoleId(string roleId)
{
var db = DbManager.Create();
return db.Fetch<Group>($"select g.ID, g.GroupName, g.Description, case rg.GroupID when g.ID then 'checked' else '' end Checked from {db.Provider.EscapeSqlIdentifier("Groups")} g left join RoleGroup rg on g.ID = rg.GroupID and RoleID = @0", roleId);
return db.Fetch<Group>($"select g.ID, g.GroupCode, g.GroupName, g.Description, case rg.GroupID when g.ID then 'checked' else '' end Checked from {db.Provider.EscapeSqlIdentifier("Groups")} g left join RoleGroup rg on g.ID = rg.GroupID and RoleID = @0", roleId);
}
/// <summary>
@ -157,6 +148,6 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public virtual IEnumerable<string> RetrievesByUserName(string userName) => DbHelper.RetrieveGroupsByUserName(userName);
public virtual IEnumerable<BootstrapGroup> RetrievesByUserName(string userName) => DbHelper.RetrieveGroupsByUserName(userName);
}
}

View File

@ -1,4 +1,5 @@
using Bootstrap.Security.DataAccess;
using Bootstrap.Security;
using Bootstrap.Security.DataAccess;
using Longbow.Cache;
using Longbow.Data;
using System.Collections.Generic;
@ -100,6 +101,6 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<string> RetrievesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbContextManager.Create<Group>().RetrievesByUserName(userName), RetrieveGroupsByUserNameDataKey);
public static IEnumerable<BootstrapGroup> RetrievesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbContextManager.Create<Group>().RetrievesByUserName(userName), RetrieveGroupsByUserNameDataKey);
}
}

View File

@ -1,5 +1,6 @@
Groups = [
{
"GroupCode": "001",
"GroupName": "Admin",
"Description": "系统默认组",
"Roles": []

View File

@ -107,7 +107,7 @@ INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category) VALUES (@
INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category) VALUES (@@identity - 2, '图标集', 10, 'fa fa-dashboard', '~/Admin/FAIcon', '0');
DELETE FROM `Groups` WHERE GroupName = 'Admin';
INSERT INTO `Groups` (GroupName, Description) VALUES ('Admin', '系统默认组');
INSERT INTO `Groups` (GroupCode, GroupName, Description) VALUES ('001', 'Admin', '系统默认组');
DELETE FROM Roles where RoleName in ('Administrators', 'Default');
INSERT INTO Roles (RoleName, Description) VALUES ('Administrators', '系统管理员');

View File

@ -93,6 +93,7 @@ CREATE TABLE Logs(
CREATE TABLE `Groups`(
ID INTEGER PRIMARY KEY Auto_increment,
GroupCode VARCHAR (50) NOT NULL,
GroupName VARCHAR (50) NOT NULL,
Description VARCHAR (500) NULL
);

View File

@ -107,7 +107,7 @@ INSERT INTO Navigations (ParentId, Name, "order", Icon, Url, Category) VALUES (c
INSERT INTO Navigations (ParentId, Name, "order", Icon, Url, Category) VALUES (currval('navigations_id_seq') - 3, '图标集', 10, 'fa fa-dashboard', '~/Admin/FAIcon', '0');
DELETE FROM GROUPS WHERE GroupName = 'Admin';
INSERT INTO Groups (GroupName, Description) VALUES ('Admin', '系统默认组');
INSERT INTO Groups (GroupCode, GroupName, Description) VALUES ('001', 'Admin', '系统默认组');
DELETE FROM Roles where RoleName in ('Administrators', 'Default');
INSERT INTO Roles (RoleName, Description) VALUES ('Administrators', '系统管理员');

View File

@ -93,6 +93,7 @@ CREATE TABLE Logs(
CREATE TABLE Groups(
ID SERIAL PRIMARY KEY,
GroupCode VARCHAR (50) NOT NULL,
GroupName VARCHAR (50) NOT NULL,
Description VARCHAR (500) NULL
);

View File

@ -112,7 +112,7 @@ INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (last_insert_rowid() - 1, '下拉框', 20, 'fa fa-bars', 'http://longbowenterprise.gitee.io/longbow-select/', '0');
DELETE FROM GROUPS WHERE GroupName = 'Admin';
INSERT INTO [Groups] ([GroupName], [Description]) VALUES ('Admin', '系统默认组');
INSERT INTO [Groups] ([GroupCode], [GroupName], [Description]) VALUES ('001', 'Admin', '系统默认组');
DELETE FROM Roles where RoleName in ('Administrators', 'Default');
INSERT INTO [Roles] ([RoleName], [Description]) VALUES ('Administrators', '系统管理员');

View File

@ -93,6 +93,7 @@ CREATE TABLE Logs(
CREATE TABLE Groups(
ID INTEGER PRIMARY KEY,
GroupCode VARCHAR (50) NOT NULL,
GroupName VARCHAR (50) NOT NULL COLLATE NOCASE,
Description VARCHAR (500) NULL
);

View File

@ -110,7 +110,7 @@ INSERT [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VA
INSERT [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (@@Identity - 2, N'图标集', 10, N'fa fa-dashboard', N'~/Admin/FAIcon', N'0')
DELETE FROM GROUPS WHERE GroupName = 'Admin'
INSERT [dbo].[Groups] ([GroupName], [Description]) VALUES ('Admin', N'系统默认组')
INSERT [dbo].[Groups] ([GroupCode], [GroupName], [Description]) VALUES ('001', 'Admin', N'系统默认组')
DELETE FROM Roles where RoleName in ('Administrators', 'Default')
INSERT [dbo].[Roles] ([RoleName], [Description]) VALUES (N'Administrators', N'系统管理员')

View File

@ -302,6 +302,7 @@ SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Groups](
[ID] [int] IDENTITY(1,1) NOT NULL,
[GroupCode] [nvarchar](50) NOT NULL,
[GroupName] [nvarchar](50) NOT NULL,
[Description] [nvarchar](500) NULL,
CONSTRAINT [PK_Groups] PRIMARY KEY CLUSTERED

View File

@ -32,7 +32,7 @@ namespace Bootstrap.Admin.Api.SqlServer
[Fact]
public async void PostAndDelete_Ok()
{
var ret = await Client.PostAsJsonAsync<Group, bool>("", new Group() { GroupName = "UnitTest-Group", Description = "UnitTest-Desc" });
var ret = await Client.PostAsJsonAsync<Group, bool>("", new Group() { GroupCode = "002", GroupName = "UnitTest-Group", Description = "UnitTest-Desc" });
Assert.True(ret);
var ids = GroupHelper.Retrieves().Where(d => d.GroupName == "UnitTest-Group").Select(d => d.Id);

View File

@ -1,6 +1,4 @@
using System;
using System.Linq;
using UnitTest;
using System.Linq;
using Xunit;
namespace Bootstrap.DataAccess.SqlServer
@ -17,7 +15,7 @@ namespace Bootstrap.DataAccess.SqlServer
[Fact]
public void SaveAndDelete_Ok()
{
var g = new Group() { GroupName = "UnitTest", Description = "UnitTestSave" };
var g = new Group() { GroupCode = "002", GroupName = "UnitTest", Description = "UnitTestSave" };
// insert
Assert.True(GroupHelper.Save(g));

Binary file not shown.