Skip to content

Commit e253695

Browse files
feat: 添加 Repository.Enum 层 抽离数据库枚举
1 parent eea50e9 commit e253695

File tree

9 files changed

+63
-38
lines changed

9 files changed

+63
-38
lines changed

Application/Service/User.Service/RoleService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.EntityFrameworkCore;
66
using Microsoft.Extensions.DependencyInjection;
77
using Repository.Database;
8+
using Repository.Enum;
89
using Shared.Model;
910
using User.Interface;
1011
using User.Model.Role;
@@ -147,13 +148,13 @@ public async Task<bool> DeleteRoleAsync(long id)
147148

148149
public async Task<List<DtoRoleFunction>> GetRoleFunctionAsync(long roleId)
149150
{
150-
var functionList = await db.TFunction.Where(t => t.ParentId == null && t.Type == TFunction.EnumType.模块).Select(t => new DtoRoleFunction
151+
var functionList = await db.TFunction.Where(t => t.ParentId == null && t.Type == EnumFunctionType.Module).Select(t => new DtoRoleFunction
151152
{
152153
Id = t.Id,
153154
Name = t.Name.Replace(t.Parent!.Name + "-", ""),
154155
Sign = t.Sign,
155156
IsCheck = db.TFunctionAuthorize.Where(r => r.FunctionId == t.Id && r.RoleId == roleId).FirstOrDefault() != null,
156-
FunctionList = db.TFunction.Where(f => f.ParentId == t.Id && f.Type == TFunction.EnumType.功能).Select(f => new DtoRoleFunction
157+
FunctionList = db.TFunction.Where(f => f.ParentId == t.Id && f.Type == EnumFunctionType.Function).Select(f => new DtoRoleFunction
157158
{
158159
Id = f.Id,
159160
Name = f.Name.Replace(f.Parent!.Name + "-", ""),
@@ -219,13 +220,13 @@ public Task<List<DtoKeyValue>> GetRoleKVAsync()
219220
public async Task<List<DtoRoleFunction>> GetRoleFunctionChildListAsync(long roleId, long parentId)
220221
{
221222

222-
var functionList = await db.TFunction.Where(t => t.ParentId == parentId && t.Type == TFunction.EnumType.模块).Select(t => new DtoRoleFunction
223+
var functionList = await db.TFunction.Where(t => t.ParentId == parentId && t.Type == EnumFunctionType.Module).Select(t => new DtoRoleFunction
223224
{
224225
Id = t.Id,
225226
Name = t.Name.Replace(t.Parent!.Name + "-", ""),
226227
Sign = t.Sign,
227228
IsCheck = db.TFunctionAuthorize.Where(r => r.FunctionId == t.Id && r.RoleId == roleId).FirstOrDefault() != null,
228-
FunctionList = db.TFunction.Where(f => f.ParentId == t.Id && f.Type == TFunction.EnumType.功能).Select(f => new DtoRoleFunction
229+
FunctionList = db.TFunction.Where(f => f.ParentId == t.Id && f.Type == EnumFunctionType.Function).Select(f => new DtoRoleFunction
229230
{
230231
Id = f.Id,
231232
Name = f.Name.Replace(f.Parent!.Name + "-", ""),

Application/Service/User.Service/UserService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.Extensions.Caching.Distributed;
88
using Microsoft.Extensions.DependencyInjection;
99
using Repository.Database;
10+
using Repository.Enum;
1011
using Shared.Model;
1112
using System.Text;
1213
using User.Interface;
@@ -252,13 +253,13 @@ public async Task<List<DtoUserFunction>> GetUserFunctionAsync(long userId)
252253
{
253254
var roleIds = await db.TUserRole.Where(t => t.UserId == userId).Select(t => t.RoleId).ToListAsync();
254255

255-
var functionList = await db.TFunction.Where(t => t.ParentId == null && t.Type == TFunction.EnumType.模块).Select(t => new DtoUserFunction
256+
var functionList = await db.TFunction.Where(t => t.ParentId == null && t.Type == EnumFunctionType.Module).Select(t => new DtoUserFunction
256257
{
257258
Id = t.Id,
258259
Name = t.Name.Replace(t.Parent!.Name + "-", ""),
259260
Sign = t.Sign,
260261
IsCheck = db.TFunctionAuthorize.Where(r => r.FunctionId == t.Id && (roleIds.Contains(r.RoleId!.Value) || r.UserId == userId)).FirstOrDefault() != null,
261-
FunctionList = db.TFunction.Where(f => f.ParentId == t.Id && f.Type == TFunction.EnumType.功能).Select(f => new DtoUserFunction
262+
FunctionList = db.TFunction.Where(f => f.ParentId == t.Id && f.Type == EnumFunctionType.Function).Select(f => new DtoUserFunction
262263
{
263264
Id = f.Id,
264265
Name = f.Name.Replace(f.Parent!.Name + "-", ""),
@@ -381,13 +382,13 @@ public async Task<bool> SetUserRoleAsync(DtoSetUserRole setUserRole)
381382
public async Task<List<DtoUserFunction>> GetUserFunctionChildListAsync(long userId, long parentId, List<long> roleIds)
382383
{
383384

384-
var functionList = await db.TFunction.Where(t => t.ParentId == parentId && t.Type == TFunction.EnumType.模块).Select(t => new DtoUserFunction
385+
var functionList = await db.TFunction.Where(t => t.ParentId == parentId && t.Type == EnumFunctionType.Module).Select(t => new DtoUserFunction
385386
{
386387
Id = t.Id,
387388
Name = t.Name.Replace(t.Parent!.Name + "-", ""),
388389
Sign = t.Sign,
389390
IsCheck = db.TFunctionAuthorize.Where(r => r.FunctionId == t.Id && (roleIds.Contains(r.RoleId!.Value) || r.UserId == userId)).FirstOrDefault() != null,
390-
FunctionList = db.TFunction.Where(f => f.ParentId == t.Id && f.Type == TFunction.EnumType.功能).Select(f => new DtoUserFunction
391+
FunctionList = db.TFunction.Where(f => f.ParentId == t.Id && f.Type == EnumFunctionType.Function).Select(f => new DtoUserFunction
391392
{
392393
Id = f.Id,
393394
Name = f.Name.Replace(f.Parent!.Name + "-", ""),

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 berkerdong
3+
Copyright (c) 2022 Xiaodong.Zhang
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

NetEngine.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client.WebAPI", "Presentati
9191
EndProject
9292
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaskService", "Presentation\TaskService\TaskService.csproj", "{F89CF710-5D8E-420A-A5C5-8C8EAFC52FFA}"
9393
EndProject
94+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Repository.Enum", "Repository.Enum\Repository.Enum.csproj", "{0E00D13E-0CE0-4DC9-A4CB-BE1E5EDB9459}"
95+
EndProject
9496
Global
9597
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9698
Debug|Any CPU = Debug|Any CPU
@@ -241,6 +243,10 @@ Global
241243
{F89CF710-5D8E-420A-A5C5-8C8EAFC52FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
242244
{F89CF710-5D8E-420A-A5C5-8C8EAFC52FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
243245
{F89CF710-5D8E-420A-A5C5-8C8EAFC52FFA}.Release|Any CPU.Build.0 = Release|Any CPU
246+
{0E00D13E-0CE0-4DC9-A4CB-BE1E5EDB9459}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
247+
{0E00D13E-0CE0-4DC9-A4CB-BE1E5EDB9459}.Debug|Any CPU.Build.0 = Debug|Any CPU
248+
{0E00D13E-0CE0-4DC9-A4CB-BE1E5EDB9459}.Release|Any CPU.ActiveCfg = Release|Any CPU
249+
{0E00D13E-0CE0-4DC9-A4CB-BE1E5EDB9459}.Release|Any CPU.Build.0 = Release|Any CPU
244250
EndGlobalSection
245251
GlobalSection(SolutionProperties) = preSolution
246252
HideSolutionNode = FALSE

Repository.Enum/EnumFunctionType.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Repository.Enum
2+
{
3+
4+
/// <summary>
5+
/// 功能类型
6+
/// </summary>
7+
public enum EnumFunctionType
8+
{
9+
/// <summary>
10+
/// 模块
11+
/// </summary>
12+
Module = 1,
13+
14+
15+
/// <summary>
16+
/// 功能
17+
/// </summary>
18+
Function = 2
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<DebugType>embedded</DebugType>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
</PropertyGroup>
9+
10+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
11+
<NoWarn>1591;8618</NoWarn>
12+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
16+
<NoWarn>1591;8618</NoWarn>
17+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
18+
</PropertyGroup>
19+
20+
</Project>

Repository/Database/TFunction.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using Microsoft.EntityFrameworkCore;
1+
using Microsoft.EntityFrameworkCore;
22
using Repository.Bases;
3+
using Repository.Enum;
34

45
namespace Repository.Database
56
{
@@ -12,50 +13,38 @@ namespace Repository.Database
1213
public class TFunction : CD
1314
{
1415

15-
1616
/// <summary>
1717
/// 名称
1818
/// </summary>
1919
public string Name { get; set; }
2020

2121

22-
2322
/// <summary>
2423
/// 标记
2524
/// </summary>
2625
public string Sign { get; set; }
2726

2827

29-
3028
/// <summary>
3129
/// 备注
3230
/// </summary>
3331
public string? Remarks { get; set; }
3432

3533

36-
3734
/// <summary>
3835
/// 父级信息
3936
/// </summary>
4037
public long? ParentId { get; set; }
4138
public virtual TFunction? Parent { get; set; }
4239

4340

44-
4541
/// <summary>
46-
/// 类型
42+
/// 功能类型
4743
/// </summary>
48-
public EnumType Type { get; set; }
49-
public enum EnumType
50-
{
51-
模块 = 1,
52-
功能 = 2
53-
}
54-
55-
44+
public EnumFunctionType Type { get; set; }
45+
5646

5747
public virtual List<TFunctionRoute>? TFunctionRoute { get; set; }
5848

59-
6049
}
6150
}

Repository/Repository.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
<ItemGroup>
3030
<ProjectReference Include="..\Infrastructure\IdentifierGenerator\IdentifierGenerator.csproj" />
31+
<ProjectReference Include="..\Repository.Enum\Repository.Enum.csproj" />
3132
</ItemGroup>
3233

3334
</Project>

SharedService/SharedService.csproj

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)