Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwplvx
Aurora
提交
f283a1bb
Aurora
项目概览
lwplvx
/
Aurora
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Aurora
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f283a1bb
编写于
5月 24, 2021
作者:
S
simon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加数据访问,api,实体映射等,可以运行,接口测试不正确
上级
343bde14
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
311 addition
and
0 deletion
+311
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/Controllers/CategoryController.cs
...ra.Core/Aurora.Core.Api/Controllers/CategoryController.cs
+0
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/CoreApiModule.cs
...icorservices/Aurora.Core/Aurora.Core.Api/CoreApiModule.cs
+0
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/MoudelInit.cs
...a.Micorservices/Aurora.Core/Aurora.Core.Api/MoudelInit.cs
+0
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/AutomapperProfiles/CategoryProfile
...ore/Aurora.Core.Domain/AutomapperProfiles/CategoryProfile
+14
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/AutomapperProfiles/CategoryProfile.cs
.../Aurora.Core.Domain/AutomapperProfiles/CategoryProfile.cs
+14
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/AutomapperProfiles/xxx.cs
.../Aurora.Core/Aurora.Core.Domain/AutomapperProfiles/xxx.cs
+14
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/Entities/Category.cs
...vices/Aurora.Core/Aurora.Core.Domain/Entities/Category.cs
+0
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/Response/CategoryDto.cs
...es/Aurora.Core/Aurora.Core.Domain/Response/CategoryDto.cs
+8
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/xxx/xxx.cs
...a.Micorservices/Aurora.Core/Aurora.Core.Domain/xxx/xxx.cs
+8
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.EntityFramework/ApplicationDbContext copy.cs
.../Aurora.Core.EntityFramework/ApplicationDbContext copy.cs
+114
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.EntityFramework/ApplicationReadonlyDbContext.cs
...rora.Core.EntityFramework/ApplicationReadonlyDbContext.cs
+114
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.IService/Dto/CategoryDto.cs
...vices/Aurora.Core/Aurora.Core.IService/Dto/CategoryDto.cs
+9
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.IService/ICategoryService.cs
...ices/Aurora.Core/Aurora.Core.IService/ICategoryService.cs
+8
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Service/AutomapperProfiles/CategoryProfile.cs
...Aurora.Core.Service/AutomapperProfiles/CategoryProfile.cs
+0
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Service/CategoryService.cs
...rvices/Aurora.Core/Aurora.Core.Service/CategoryService.cs
+8
-0
未找到文件。
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/Controllers/CategoryController.cs
0 → 100644
浏览文件 @
f283a1bb
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/CoreApiModule.cs
0 → 100644
浏览文件 @
f283a1bb
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/MoudelInit.cs
0 → 100644
浏览文件 @
f283a1bb
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/AutomapperProfiles/CategoryProfile
0 → 100644
浏览文件 @
f283a1bb
using System;
using Aurora.Core.Domain.Entities;
using Aurora.Core.Domain.Response;
namespace Aurora.Core.Domain.xxx
{
public class CategoryProfile : Profile
{
protected override void Configure()
{
CreateMap<CategoryDto, Category>();
}
}
}
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/AutomapperProfiles/CategoryProfile.cs
0 → 100644
浏览文件 @
f283a1bb
using
System
;
using
Aurora.Core.Domain.Entities
;
using
Aurora.Core.Domain.Response
;
namespace
Aurora.Core.Domain.xxx
{
public
class
CategoryProfile
:
Profile
{
protected
override
void
Configure
()
{
CreateMap
<
CategoryDto
,
Category
>();
}
}
}
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/AutomapperProfiles/xxx.cs
0 → 100644
浏览文件 @
f283a1bb
using
System
;
using
Aurora.Core.Domain.Entities
;
using
Aurora.Core.Domain.Response
;
namespace
Aurora.Core.Domain.AutomapperProfiles
{
public
class
CategoryProfile
:
Profile
{
protected
override
void
Configure
()
{
CreateMap
<
CategoryDto
,
Category
>();
}
}
}
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/Entities/Category.cs
0 → 100644
浏览文件 @
f283a1bb
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/Response/CategoryDto.cs
0 → 100644
浏览文件 @
f283a1bb
using
System
;
namespace
Aurora.Core.Domain.Response
{
public
class
CategoryDto
{
}
}
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/xxx/xxx.cs
0 → 100644
浏览文件 @
f283a1bb
using
System
;
namespace
Aurora.Core.Domain.xxx
{
public
class
xxx
{
}
}
Aurora.Micorservices/Aurora.Core/Aurora.Core.EntityFramework/ApplicationDbContext copy.cs
0 → 100644
浏览文件 @
f283a1bb
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Reflection
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Aurora.Common.Entities
;
using
Aurora.Core.Domain.Entities
;
using
Aurora.Infrastructure.Tenant
;
using
Aurora.Infrastructure.User
;
using
Microsoft.EntityFrameworkCore
;
namespace
Aurora.Core.EntityFramework
{
public
class
ApplicationDbContext
:
DbContext
{
public
static
string
ConnectionString
{
get
;
set
;
}
private
readonly
ICurrentUser
currentUser
;
private
readonly
ICurrentTenant
currentTenant
;
public
ApplicationDbContext
(
DbContextOptions
<
ApplicationDbContext
>
options
,
ICurrentUserProvider
currentUserProvider
,
ICurrentTenantProvider
currentTenantProvider
)
:
base
(
options
)
{
currentUser
=
currentUserProvider
.
GetCurrentUser
();
currentTenant
=
currentTenantProvider
.
GetCurrentTenant
();
}
public
DbSet
<
Category
>
Categories
{
get
;
set
;
}
protected
override
void
OnModelCreating
(
ModelBuilder
builder
)
{
//多租户过滤
foreach
(
var
type
in
GetBaseEntityTypes
())
{
var
method
=
SetGlobalQueryMethod
.
MakeGenericMethod
(
type
);
method
.
Invoke
(
this
,
new
object
[]
{
builder
});
}
builder
.
Entity
<
Category
>().
HasKey
(
t
=>
new
{
t
.
TenantCode
});
// builder.Entity<Category>().HasIndex(p => p.TenantCode);
base
.
OnModelCreating
(
builder
);
}
private
static
IList
<
Type
>
_baseEntityTypesCache
;
private
static
IList
<
Type
>
GetBaseEntityTypes
()
{
if
(
_baseEntityTypesCache
!=
null
)
return
_baseEntityTypesCache
.
ToList
();
_baseEntityTypesCache
=
(
from
t
in
typeof
(
TenantEntityBase
).
GetTypeInfo
().
Assembly
.
DefinedTypes
where
t
.
BaseType
==
typeof
(
TenantEntityBase
)
select
t
.
AsType
()).
ToList
();
return
_baseEntityTypesCache
;
}
public
override
int
SaveChanges
()
{
UpdateCommonFileds
();
return
base
.
SaveChanges
();
}
public
override
async
Task
<
int
>
SaveChangesAsync
(
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
UpdateCommonFileds
();
return
await
base
.
SaveChangesAsync
(
cancellationToken
);
}
private
void
UpdateCommonFileds
()
{
var
nowTime
=
DateTime
.
Now
;
if
(
string
.
IsNullOrEmpty
(
currentUser
.
UserName
))
{
var
tcode
=
currentTenant
.
TenantCode
;
}
foreach
(
var
entry
in
this
.
ChangeTracker
.
Entries
<
TenantEntityBase
>().
Where
(
x
=>
x
.
State
==
EntityState
.
Added
||
x
.
State
==
EntityState
.
Modified
))
{
var
entity
=
entry
.
Entity
;
switch
(
entry
.
State
)
{
case
EntityState
.
Added
:
if
(
entity
.
TenantCode
==
""
)
entity
.
TenantCode
=
currentTenant
.
TenantCode
;
entity
.
CreateTime
=
nowTime
;
entity
.
CreateUserName
=
currentUser
.
UserName
;
break
;
case
EntityState
.
Modified
:
entity
.
ModifyTime
=
nowTime
;
entity
.
ModifyUserName
=
currentUser
.
UserName
;
break
;
}
}
this
.
ChangeTracker
.
DetectChanges
();
}
static
readonly
MethodInfo
SetGlobalQueryMethod
=
typeof
(
ApplicationDbContext
).
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
)
.
Single
(
t
=>
t
.
IsGenericMethod
&&
t
.
Name
==
"SetGlobalQuery"
);
public
void
SetGlobalQuery
<
T
>(
ModelBuilder
builder
)
where
T
:
TenantEntityBase
{
builder
.
Entity
<
T
>().
HasQueryFilter
(
e
=>
e
.
TenantCode
==
currentTenant
.
TenantCode
);
}
}
}
\ No newline at end of file
Aurora.Micorservices/Aurora.Core/Aurora.Core.EntityFramework/ApplicationReadonlyDbContext.cs
0 → 100644
浏览文件 @
f283a1bb
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Reflection
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Aurora.Common.Entities
;
using
Aurora.Core.Domain.Entities
;
using
Aurora.Infrastructure.Tenant
;
using
Aurora.Infrastructure.User
;
using
Microsoft.EntityFrameworkCore
;
namespace
Aurora.Core.EntityFramework
{
public
class
ApplicationDbContext
:
DbContext
{
public
static
string
ConnectionString
{
get
;
set
;
}
private
readonly
ICurrentUser
currentUser
;
private
readonly
ICurrentTenant
currentTenant
;
public
ApplicationDbContext
(
DbContextOptions
<
ApplicationDbContext
>
options
,
ICurrentUserProvider
currentUserProvider
,
ICurrentTenantProvider
currentTenantProvider
)
:
base
(
options
)
{
currentUser
=
currentUserProvider
.
GetCurrentUser
();
currentTenant
=
currentTenantProvider
.
GetCurrentTenant
();
}
public
DbSet
<
Category
>
Categories
{
get
;
set
;
}
protected
override
void
OnModelCreating
(
ModelBuilder
builder
)
{
//多租户过滤
foreach
(
var
type
in
GetBaseEntityTypes
())
{
var
method
=
SetGlobalQueryMethod
.
MakeGenericMethod
(
type
);
method
.
Invoke
(
this
,
new
object
[]
{
builder
});
}
builder
.
Entity
<
Category
>().
HasKey
(
t
=>
new
{
t
.
TenantCode
});
// builder.Entity<Category>().HasIndex(p => p.TenantCode);
base
.
OnModelCreating
(
builder
);
}
private
static
IList
<
Type
>
_baseEntityTypesCache
;
private
static
IList
<
Type
>
GetBaseEntityTypes
()
{
if
(
_baseEntityTypesCache
!=
null
)
return
_baseEntityTypesCache
.
ToList
();
_baseEntityTypesCache
=
(
from
t
in
typeof
(
TenantEntityBase
).
GetTypeInfo
().
Assembly
.
DefinedTypes
where
t
.
BaseType
==
typeof
(
TenantEntityBase
)
select
t
.
AsType
()).
ToList
();
return
_baseEntityTypesCache
;
}
public
override
int
SaveChanges
()
{
UpdateCommonFileds
();
return
base
.
SaveChanges
();
}
public
override
async
Task
<
int
>
SaveChangesAsync
(
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
UpdateCommonFileds
();
return
await
base
.
SaveChangesAsync
(
cancellationToken
);
}
private
void
UpdateCommonFileds
()
{
var
nowTime
=
DateTime
.
Now
;
if
(
string
.
IsNullOrEmpty
(
currentUser
.
UserName
))
{
var
tcode
=
currentTenant
.
TenantCode
;
}
foreach
(
var
entry
in
this
.
ChangeTracker
.
Entries
<
TenantEntityBase
>().
Where
(
x
=>
x
.
State
==
EntityState
.
Added
||
x
.
State
==
EntityState
.
Modified
))
{
var
entity
=
entry
.
Entity
;
switch
(
entry
.
State
)
{
case
EntityState
.
Added
:
if
(
entity
.
TenantCode
==
""
)
entity
.
TenantCode
=
currentTenant
.
TenantCode
;
entity
.
CreateTime
=
nowTime
;
entity
.
CreateUserName
=
currentUser
.
UserName
;
break
;
case
EntityState
.
Modified
:
entity
.
ModifyTime
=
nowTime
;
entity
.
ModifyUserName
=
currentUser
.
UserName
;
break
;
}
}
this
.
ChangeTracker
.
DetectChanges
();
}
static
readonly
MethodInfo
SetGlobalQueryMethod
=
typeof
(
ApplicationDbContext
).
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
)
.
Single
(
t
=>
t
.
IsGenericMethod
&&
t
.
Name
==
"SetGlobalQuery"
);
public
void
SetGlobalQuery
<
T
>(
ModelBuilder
builder
)
where
T
:
TenantEntityBase
{
builder
.
Entity
<
T
>().
HasQueryFilter
(
e
=>
e
.
TenantCode
==
currentTenant
.
TenantCode
);
}
}
}
\ No newline at end of file
Aurora.Micorservices/Aurora.Core/Aurora.Core.IService/Dto/CategoryDto.cs
0 → 100644
浏览文件 @
f283a1bb
using
System
;
using
Aurora.Core.Domain.Entities
;
namespace
Aurora.Core.Domain.Dto
{
public
class
CategoryDto
:
Category
{
}
}
Aurora.Micorservices/Aurora.Core/Aurora.Core.IService/ICategoryService.cs
0 → 100644
浏览文件 @
f283a1bb
using
System
;
namespace
Aurora.Core.IService
{
public
class
ICategoryService
{
}
}
Aurora.Micorservices/Aurora.Core/Aurora.Core.Service/AutomapperProfiles/CategoryProfile.cs
0 → 100644
浏览文件 @
f283a1bb
Aurora.Micorservices/Aurora.Core/Aurora.Core.Service/CategoryService.cs
0 → 100644
浏览文件 @
f283a1bb
using
System
;
namespace
Aurora.Core.Service
{
public
class
Class1
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录