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
03cfac74
Commit
03cfac74
authored
Apr 03, 2019
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口调整
parent
ac20c91e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
43 deletions
+63
-43
performance/Performance.Api/Controllers/AccountController.cs
+2
-16
performance/Performance.DtoModels/Request/SetDepartmentRequest.cs
+5
-6
performance/Performance.DtoModels/Request/UserRequest.cs
+7
-0
performance/Performance.Services/UserService.cs
+49
-21
No files found.
performance/Performance.Api/Controllers/AccountController.cs
View file @
03cfac74
...
...
@@ -126,20 +126,6 @@ public ApiResponse<UserResponse> Update([CustomizeValidator(RuleSet = "Update"),
}
/// <summary>
/// 设置用户管辖医院
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[
Route
(
"sethospital"
)]
[
HttpPost
]
public
ApiResponse
SetHospital
([
FromBody
]
SetHospitalRequest
request
)
{
if
(!
_userService
.
SetHospital
(
request
))
return
new
ApiResponse
(
ResponseType
.
Fail
);
return
new
ApiResponse
(
ResponseType
.
OK
);
}
/// <summary>
/// 修改用户密码
/// </summary>
/// <param name="request"></param>
...
...
@@ -173,9 +159,9 @@ public ApiResponse<List<sys_role>> RoleList([FromBody]ApiRequest request)
/// <returns></returns>
[
Route
(
"department"
)]
[
HttpPost
]
public
ApiResponse
<
List
<
TitleValue
>>
Department
([
FromBody
]
Api
Request
request
)
public
ApiResponse
<
List
<
TitleValue
>>
Department
([
FromBody
]
SetDepartment
Request
request
)
{
var
department
=
_userService
.
Department
();
var
department
=
_userService
.
Department
(
request
.
HospitalID
);
return
new
ApiResponse
<
List
<
TitleValue
>>(
ResponseType
.
OK
,
"ok"
,
department
);
}
}
...
...
performance/Performance.DtoModels/Request/Set
Hospital
Request.cs
→
performance/Performance.DtoModels/Request/Set
Department
Request.cs
View file @
03cfac74
...
...
@@ -8,17 +8,16 @@ namespace Performance.DtoModels
/// <summary>
/// 登录请求
/// </summary>
public
class
Set
Hospital
Request
:
ApiRequest
public
class
Set
Department
Request
:
ApiRequest
{
public
int
UserID
{
get
;
set
;
}
public
int
[]
HosIDArray
{
get
;
set
;
}
public
int
HospitalID
{
get
;
set
;
}
}
public
class
Set
HospitalRequestValidator
:
AbstractValidator
<
SetHospital
Request
>
public
class
Set
DepartmentRequestValidator
:
AbstractValidator
<
SetDepartment
Request
>
{
public
Set
Hospital
RequestValidator
()
public
Set
Department
RequestValidator
()
{
RuleFor
(
x
=>
x
.
User
ID
).
GreaterThan
(
0
);
RuleFor
(
x
=>
x
.
Hospital
ID
).
GreaterThan
(
0
);
}
}
}
performance/Performance.DtoModels/Request/UserRequest.cs
View file @
03cfac74
...
...
@@ -44,6 +44,11 @@ public class UserRequest : ApiRequest
public
int
Role
{
get
;
set
;
}
/// <summary>
/// 用户医院ID
/// </summary>
public
int
[]
HosIDArray
{
get
;
set
;
}
/// <summary>
/// 用户科室
/// </summary>
public
string
Department
{
get
;
set
;
}
...
...
@@ -66,6 +71,7 @@ public UserRequestValidator()
action
();
RuleFor
(
x
=>
x
.
Role
).
NotNull
().
NotEmpty
().
GreaterThan
(
0
);
RuleFor
(
x
=>
x
.
Password
).
NotNull
().
NotEmpty
().
Length
(
4
,
20
);
RuleFor
(
x
=>
x
.
HosIDArray
).
NotNull
().
NotEmpty
().
Must
(
f
=>
f
.
Length
>
0
);
});
RuleSet
(
"Update"
,
()
=>
...
...
@@ -75,6 +81,7 @@ public UserRequestValidator()
RuleFor
(
x
=>
x
.
States
).
InclusiveBetween
(
1
,
2
);
RuleFor
(
x
=>
x
.
Password
).
Length
(
4
,
20
);
RuleFor
(
x
=>
x
.
Role
).
NotNull
().
NotEmpty
().
GreaterThan
(
0
);
RuleFor
(
x
=>
x
.
HosIDArray
).
NotNull
().
NotEmpty
().
Must
(
f
=>
f
.
Length
>
0
);
});
RuleSet
(
"Self"
,
()
=>
...
...
performance/Performance.Services/UserService.cs
View file @
03cfac74
using
AutoMapper
;
using
Microsoft.Extensions.Options
;
using
Newtonsoft.Json.Linq
;
using
Performance.DtoModels
;
using
Performance.DtoModels.AppSettings
;
using
Performance.EntityModels
;
using
Performance.Repository
;
using
System
;
...
...
@@ -13,6 +15,7 @@ namespace Performance.Services
{
public
class
UserService
:
IAutoInjection
{
private
Application
application
;
private
PerforUserRepository
_userRepository
;
private
PerforSmsRepository
_smsRepository
;
private
PerforHospitalRepository
_hospitalRepository
;
...
...
@@ -20,14 +23,18 @@ public class UserService : IAutoInjection
private
PerforRoleRepository
_roleRepository
;
private
PerforUserroleRepository
_userroleRepository
;
private
PerforImemployeeRepository
_employeeRepository
;
public
UserService
(
PerforSmsRepository
smsRepository
,
private
PerforPerallotRepository
_perforPerallotRepository
;
public
UserService
(
IOptions
<
Application
>
application
,
PerforSmsRepository
smsRepository
,
PerforUserRepository
userRepository
,
PerforHospitalRepository
hospitalRepository
,
PerforUserhospitalRepository
userhospitalRepository
,
PerforRoleRepository
roleRepository
,
PerforUserroleRepository
userroleRepository
,
PerforImemployeeRepository
employeeRepository
)
PerforImemployeeRepository
employeeRepository
,
PerforPerallotRepository
perforPerallotRepository
)
{
this
.
application
=
application
.
Value
;
this
.
_userRepository
=
userRepository
;
this
.
_smsRepository
=
smsRepository
;
this
.
_hospitalRepository
=
hospitalRepository
;
...
...
@@ -35,6 +42,7 @@ public class UserService : IAutoInjection
this
.
_roleRepository
=
roleRepository
;
this
.
_userroleRepository
=
userroleRepository
;
this
.
_employeeRepository
=
employeeRepository
;
this
.
_perforPerallotRepository
=
perforPerallotRepository
;
}
/// <summary>
...
...
@@ -106,12 +114,18 @@ public List<UserResponse> GetUserList(int userID)
/// <param name="request"></param>
public
UserResponse
Insert
(
UserRequest
request
,
int
userid
)
{
int
[]
roleArray
=
new
int
[]
{
application
.
NurseRole
,
application
.
DirectorRole
};
if
(
null
!=
_userRepository
.
GetEntity
(
t
=>
t
.
Login
==
request
.
Login
))
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
(
"请选择科室"
);
if
(
roleArray
.
Contains
(
request
.
Role
)
&&
request
.
HosIDArray
.
Length
>
1
)
throw
new
PerformanceException
(
"二次绩效管理员只支持单家医院"
);
if
(
roleArray
.
Contains
(
request
.
Role
)
&&
string
.
IsNullOrEmpty
(
request
.
Department
))
throw
new
PerformanceException
(
"二次绩效管理员科室不能为空"
);
var
user
=
Mapper
.
Map
<
sys_user
>(
request
);
user
.
CreateDate
=
DateTime
.
Now
;
user
.
CreateUser
=
userid
;
...
...
@@ -122,6 +136,9 @@ public UserResponse Insert(UserRequest request, int userid)
throw
new
PerformanceException
(
"保存失败"
);
//添加用户角色关联关系
_userroleRepository
.
Add
(
new
sys_user_role
{
UserID
=
user
.
ID
,
RoleID
=
request
.
Role
});
//添加用户医院
SetHospital
(
request
.
ID
,
request
.
HosIDArray
);
return
Mapper
.
Map
<
UserResponse
>(
user
);
}
...
...
@@ -130,27 +147,27 @@ public UserResponse Insert(UserRequest request, int userid)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public
bool
SetHospital
(
SetHospitalRequest
request
)
public
bool
SetHospital
(
int
userId
,
int
[]
hosIDArray
)
{
var
user
=
_userRepository
.
GetEntity
(
t
=>
t
.
ID
==
request
.
UserID
);
var
user
=
_userRepository
.
GetEntity
(
t
=>
t
.
ID
==
userId
);
if
(
null
==
user
)
throw
new
PerformanceException
(
$"用户不存在 UserId:
{
request
.
UserID
}
"
);
var
userHospital
=
_userhospitalRepository
.
GetUserHospital
(
request
.
UserID
);
throw
new
PerformanceException
(
$"用户不存在 UserId:
{
userId
}
"
);
var
userHospital
=
_userhospitalRepository
.
GetUserHospital
(
userId
);
bool
rmResult
=
true
,
addResult
=
true
;
//获取需要删除的医院
var
rmHospital
=
userHospital
.
Where
(
t
=>
!
request
.
H
osIDArray
.
Contains
(
t
.
HospitalID
.
Value
));
var
rmHospital
=
userHospital
.
Where
(
t
=>
!
h
osIDArray
.
Contains
(
t
.
HospitalID
.
Value
));
if
(
rmHospital
!=
null
&&
rmHospital
.
Count
()
>
0
)
rmResult
=
_userhospitalRepository
.
RemoveRange
(
rmHospital
.
ToArray
());
//获取需要新增的医院
var
addHospital
=
request
.
H
osIDArray
.
Where
(
t
=>
!
userHospital
.
Select
(
u
=>
u
.
HospitalID
).
Contains
(
t
));
var
addHospital
=
h
osIDArray
.
Where
(
t
=>
!
userHospital
.
Select
(
u
=>
u
.
HospitalID
).
Contains
(
t
));
if
(
addHospital
!=
null
&&
addHospital
.
Count
()
>
0
)
{
var
allHospital
=
_hospitalRepository
.
GetEntities
();
//获取有效医院ID
var
array
=
addHospital
.
Where
(
t
=>
allHospital
.
Select
(
h
=>
h
.
ID
).
Contains
(
t
))
.
Select
(
t
=>
new
sys_user_hospital
{
UserID
=
request
.
UserID
,
HospitalID
=
t
}).
ToArray
();
.
Select
(
t
=>
new
sys_user_hospital
{
UserID
=
userId
,
HospitalID
=
t
}).
ToArray
();
addResult
=
_userhospitalRepository
.
AddRange
(
array
);
}
...
...
@@ -164,7 +181,7 @@ public bool SetHospital(SetHospitalRequest request)
/// <returns></returns>
public
UserResponse
Update
(
UserRequest
request
)
{
int
[]
roleArray
=
new
int
[]
{
application
.
NurseRole
,
application
.
DirectorRole
};
var
user
=
_userRepository
.
GetEntity
(
t
=>
t
.
ID
==
request
.
ID
);
if
(
null
==
user
)
throw
new
PerformanceException
(
$"用户不存在 UserId:
{
request
.
ID
}
"
);
...
...
@@ -177,15 +194,11 @@ public UserResponse Update(UserRequest request)
if
(
null
!=
vlist
&&
vlist
.
Count
()
>
0
)
throw
new
PerformanceException
(
"手机号重复"
);
if
(
r
equest
.
Role
==
3
&&
string
.
IsNullOrEmpty
(
request
.
Department
))
throw
new
PerformanceException
(
"
请选择科室
"
);
if
(
r
oleArray
.
Contains
(
request
.
Role
)
&&
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
});
if
(
roleArray
.
Contains
(
request
.
Role
)
&&
request
.
HosIDArray
.
Length
>
1
)
throw
new
PerformanceException
(
"二次绩效管理员只支持单家医院"
);
user
.
Login
=
request
.
Login
;
user
.
Mobile
=
request
.
Mobile
;
...
...
@@ -197,6 +210,16 @@ public UserResponse Update(UserRequest request)
if
(!
_userRepository
.
Update
(
user
))
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
});
//添加用户医院
SetHospital
(
request
.
ID
,
request
.
HosIDArray
);
return
Mapper
.
Map
<
UserResponse
>(
user
);
}
...
...
@@ -266,10 +289,15 @@ public List<sys_role> RoleList()
/// 科室列表
/// </summary>
/// <returns></returns>
public
List
<
TitleValue
>
Department
()
public
List
<
TitleValue
>
Department
(
int
hospitalID
)
{
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
();
var
allotList
=
_perforPerallotRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalID
);
if
(
allotList
!=
null
)
{
var
department
=
_employeeRepository
.
GetEntities
(
t
=>
t
.
Department
!=
""
&&
allotList
.
Select
(
s
=>
s
.
ID
).
ToList
().
Contains
(
t
.
AllotID
.
Value
));
return
department
.
Select
(
t
=>
new
TitleValue
{
Title
=
t
.
Department
,
Value
=
t
.
Department
}).
OrderBy
(
t
=>
t
.
Title
).
Distinct
().
ToList
();
}
return
new
List
<
TitleValue
>();
}
}
}
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