Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
performance
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zry
performance
Commits
4d1b0846
Commit
4d1b0846
authored
Apr 01, 2019
by
李承祥
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户管理--新增,修改时增加角色管理
parent
0659e75d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
123 additions
and
4 deletions
+123
-4
performance/Performance.Api/Controllers/AccountController.cs
+30
-1
performance/Performance.DtoModels/Performance.DtoModels.csproj
+0
-1
performance/Performance.DtoModels/Request/UserRequest.cs
+12
-0
performance/Performance.DtoModels/Response/UserResponse.cs
+2
-0
performance/Performance.DtoModels/TitleValue.cs
+28
-0
performance/Performance.Services/UserService.cs
+51
-2
No files found.
performance/Performance.Api/Controllers/AccountController.cs
View file @
4d1b0846
...
...
@@ -5,6 +5,7 @@
using
Newtonsoft.Json.Linq
;
using
Performance.DtoModels
;
using
Performance.DtoModels.AppSettings
;
using
Performance.EntityModels
;
using
Performance.Infrastructure
;
using
Performance.Services
;
using
System
;
...
...
@@ -83,7 +84,7 @@ public ApiResponse<UserResponse> UpdateSelf([CustomizeValidator(RuleSet = "Self"
}
/// <summary>
///
///
用户列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
...
...
@@ -106,6 +107,7 @@ public ApiResponse<UserResponse> Insert([CustomizeValidator(RuleSet = "Insert"),
{
var
userid
=
_claim
.
At
(
request
.
Token
).
UserID
;
var
user
=
_userService
.
Insert
(
request
,
userid
);
user
.
Role
=
request
.
Role
;
return
new
ApiResponse
<
UserResponse
>(
ResponseType
.
OK
,
user
);
}
...
...
@@ -119,6 +121,7 @@ public ApiResponse<UserResponse> Insert([CustomizeValidator(RuleSet = "Insert"),
public
ApiResponse
<
UserResponse
>
Update
([
CustomizeValidator
(
RuleSet
=
"Update"
),
FromBody
]
UserRequest
request
)
{
var
user
=
_userService
.
Update
(
request
);
user
.
Role
=
request
.
Role
;
return
new
ApiResponse
<
UserResponse
>(
ResponseType
.
OK
,
user
);
}
...
...
@@ -149,5 +152,31 @@ public ApiResponse<UserResponse> Password([FromBody]PasswordRequest request)
var
user
=
_userService
.
UpdatePwd
(
request
,
userid
);
return
new
ApiResponse
<
UserResponse
>(
ResponseType
.
OK
,
user
);
}
/// <summary>
/// 角色列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[
Route
(
"rolelist"
)]
[
HttpPost
]
public
ApiResponse
<
List
<
sys_role
>>
RoleList
([
FromBody
]
ApiRequest
request
)
{
var
roleList
=
_userService
.
RoleList
();
return
new
ApiResponse
<
List
<
sys_role
>>(
ResponseType
.
OK
,
"ok"
,
roleList
);
}
/// <summary>
/// 科室列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[
Route
(
"department"
)]
[
HttpPost
]
public
ApiResponse
<
List
<
TitleValue
>>
Department
([
FromBody
]
ApiRequest
request
)
{
var
department
=
_userService
.
Department
();
return
new
ApiResponse
<
List
<
TitleValue
>>(
ResponseType
.
OK
,
"ok"
,
department
);
}
}
}
performance/Performance.DtoModels/Performance.DtoModels.csproj
View file @
4d1b0846
...
...
@@ -6,7 +6,6 @@
<ItemGroup>
<Compile Remove="PerExcel\PerComputeData.cs" />
<Compile Remove="TitleValue.cs" />
</ItemGroup>
<ItemGroup>
...
...
performance/Performance.DtoModels/Request/UserRequest.cs
View file @
4d1b0846
...
...
@@ -37,6 +37,16 @@ public class UserRequest : ApiRequest
/// 用户状态 1启用 2禁用
/// </summary>
public
Nullable
<
int
>
States
{
get
;
set
;
}
/// <summary>
/// 角色
/// </summary>
public
int
Role
{
get
;
set
;
}
/// <summary>
/// 用户科室
/// </summary>
public
string
Department
{
get
;
set
;
}
}
public
class
UserRequestValidator
:
AbstractValidator
<
UserRequest
>
...
...
@@ -54,6 +64,7 @@ public UserRequestValidator()
RuleSet
(
"Insert"
,
()
=>
{
action
();
RuleFor
(
x
=>
x
.
Role
).
NotNull
().
NotEmpty
().
GreaterThan
(
0
);
RuleFor
(
x
=>
x
.
Password
).
NotNull
().
NotEmpty
().
Length
(
4
,
20
);
});
...
...
@@ -63,6 +74,7 @@ public UserRequestValidator()
RuleFor
(
x
=>
x
.
ID
).
NotNull
().
NotEmpty
().
GreaterThan
(
0
);
RuleFor
(
x
=>
x
.
States
).
InclusiveBetween
(
1
,
2
);
RuleFor
(
x
=>
x
.
Password
).
Length
(
4
,
20
);
RuleFor
(
x
=>
x
.
Role
).
NotNull
().
NotEmpty
().
GreaterThan
(
0
);
});
RuleSet
(
"Self"
,
()
=>
...
...
performance/Performance.DtoModels/Response/UserResponse.cs
View file @
4d1b0846
...
...
@@ -15,5 +15,7 @@ public class UserResponse
public
string
Mobile
{
get
;
set
;
}
public
int
States
{
get
;
set
;
}
public
string
Hospital
{
get
;
set
;
}
public
int
Role
{
get
;
set
;
}
public
string
Department
{
get
;
set
;
}
}
}
performance/Performance.DtoModels/TitleValue.cs
0 → 100644
View file @
4d1b0846
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Performance.DtoModels
{
/// <summary>
/// title value
/// </summary>
public
class
TitleValue
<
T
>
{
/// <summary>
/// Title
/// </summary>
public
string
Title
{
get
;
set
;
}
/// <summary>
/// Value
/// </summary>
public
T
Value
{
get
;
set
;
}
}
/// <summary>
/// title value
/// </summary>
public
class
TitleValue
:
TitleValue
<
string
>
{
}
}
performance/Performance.Services/UserService.cs
View file @
4d1b0846
...
...
@@ -17,15 +17,24 @@ public class UserService : IAutoInjection
private
PerforSmsRepository
_smsRepository
;
private
PerforHospitalRepository
_hospitalRepository
;
private
PerforUserhospitalRepository
_userhospitalRepository
;
private
PerforRoleRepository
_roleRepository
;
private
PerforUserroleRepository
_userroleRepository
;
private
PerforImemployeeRepository
_employeeRepository
;
public
UserService
(
PerforSmsRepository
smsRepository
,
PerforUserRepository
userRepository
,
PerforHospitalRepository
hospitalRepository
,
PerforUserhospitalRepository
userhospitalRepository
)
PerforUserhospitalRepository
userhospitalRepository
,
PerforRoleRepository
roleRepository
,
PerforUserroleRepository
userroleRepository
,
PerforImemployeeRepository
employeeRepository
)
{
this
.
_userRepository
=
userRepository
;
this
.
_smsRepository
=
smsRepository
;
this
.
_hospitalRepository
=
hospitalRepository
;
this
.
_userhospitalRepository
=
userhospitalRepository
;
this
.
_roleRepository
=
roleRepository
;
this
.
_userroleRepository
=
userroleRepository
;
this
.
_employeeRepository
=
employeeRepository
;
}
/// <summary>
...
...
@@ -83,6 +92,9 @@ public List<UserResponse> GetUserList(int userID)
{
item
.
Hospital
=
string
.
Join
(
","
,
hoslist
.
Select
(
p
=>
p
.
HospitalID
.
Value
));
}
var
userRole
=
_userroleRepository
.
GetEntity
(
t
=>
t
.
UserID
==
userID
);
if
(
userRole
!=
null
)
item
.
Role
=
userRole
.
RoleID
;
}
}
return
result
;
...
...
@@ -98,13 +110,18 @@ public UserResponse Insert(UserRequest request, int userid)
throw
new
PerformanceException
(
"登录名重复"
);
if
(
null
!=
_userRepository
.
GetEntity
(
t
=>
t
.
Mobile
==
request
.
Mobile
))
throw
new
PerformanceException
(
"手机号重复"
);
if
(
request
.
Role
==
3
&&
string
.
IsNullOrEmpty
(
request
.
Department
))
throw
new
PerformanceException
(
"请选择科室"
);
var
user
=
Mapper
.
Map
<
sys_user
>(
request
);
user
.
CreateDate
=
DateTime
.
Now
;
user
.
CreateUser
=
userid
;
user
.
States
=
(
int
)
States
.
Enabled
;
user
.
Department
=
request
.
Department
;
if
(!
_userRepository
.
Add
(
user
))
throw
new
PerformanceException
(
"保存失败"
);
//添加用户角色关联关系
_userroleRepository
.
Add
(
new
sys_user_role
{
UserID
=
user
.
ID
,
RoleID
=
request
.
Role
});
return
Mapper
.
Map
<
UserResponse
>(
user
);
}
...
...
@@ -147,6 +164,7 @@ public bool SetHospital(SetHospitalRequest request)
/// <returns></returns>
public
UserResponse
Update
(
UserRequest
request
)
{
var
user
=
_userRepository
.
GetEntity
(
t
=>
t
.
ID
==
request
.
ID
);
if
(
null
==
user
)
throw
new
PerformanceException
(
$"用户不存在 UserId:
{
request
.
ID
}
"
);
...
...
@@ -159,12 +177,23 @@ public UserResponse Update(UserRequest request)
if
(
null
!=
vlist
&&
vlist
.
Count
()
>
0
)
throw
new
PerformanceException
(
"手机号重复"
);
if
(
request
.
Role
==
3
&&
string
.
IsNullOrEmpty
(
request
.
Department
))
throw
new
PerformanceException
(
"请选择科室"
);
//删除用户角色关联关系
var
userRole
=
_userroleRepository
.
GetEntity
(
t
=>
t
.
UserID
==
request
.
ID
);
if
(
null
!=
userRole
)
_userroleRepository
.
Remove
(
userRole
);
//添加用户角色关联关系
_userroleRepository
.
Add
(
new
sys_user_role
{
UserID
=
request
.
ID
,
RoleID
=
request
.
Role
});
user
.
Login
=
request
.
Login
;
user
.
Mobile
=
request
.
Mobile
;
user
.
RealName
=
request
.
RealName
;
user
.
Mail
=
request
.
Mail
;
user
.
States
=
request
.
States
;
user
.
Password
=
string
.
IsNullOrEmpty
(
request
.
Password
)
?
user
.
Password
:
request
.
Password
;
user
.
Department
=
request
.
Department
;
if
(!
_userRepository
.
Update
(
user
))
throw
new
PerformanceException
(
"保存失败"
);
...
...
@@ -202,7 +231,7 @@ public UserResponse UpdateSelf(UserRequest request)
}
/// <summary>
/// 修改用户
/// 修改用户
密码
/// </summary>
/// <param name="request"></param>
/// <param name="userId"></param>
...
...
@@ -222,5 +251,25 @@ public UserResponse UpdatePwd(PasswordRequest request, int userId)
throw
new
PerformanceException
(
"保存失败"
);
return
Mapper
.
Map
<
UserResponse
>(
user
);
}
/// <summary>
/// 角色列表
/// </summary>
/// <returns></returns>
public
List
<
sys_role
>
RoleList
()
{
var
role
=
_roleRepository
.
GetEntities
(
t
=>
t
.
States
==
1
).
ToList
();
return
role
;
}
/// <summary>
/// 科室列表
/// </summary>
/// <returns></returns>
public
List
<
TitleValue
>
Department
()
{
var
department
=
_employeeRepository
.
GetEntities
(
t
=>
t
.
Department
!=
""
).
Select
(
t
=>
t
.
Department
).
Distinct
();
return
department
.
Select
(
t
=>
new
TitleValue
{
Title
=
t
,
Value
=
t
}).
OrderBy
(
t
=>
t
.
Title
).
ToList
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment