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
ca565237
Commit
ca565237
authored
Jun 03, 2021
by
lcx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
人员字典分页,人员字典文件下载
parent
e0dc34a8
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
232 additions
and
40 deletions
+232
-40
performance/Performance.Api/Controllers/PersonController.cs
+39
-4
performance/Performance.Api/Filters/RequestRateLimitingMiddleware.cs
+9
-10
performance/Performance.Api/Startup.cs
+4
-4
performance/Performance.Api/wwwroot/Performance.Api.xml
+8
-1
performance/Performance.Api/wwwroot/Performance.DtoModels.xml
+1
-1
performance/Performance.DtoModels/Request/PersonParamsRequest.cs
+25
-0
performance/Performance.Infrastructure/Models/PageList.cs
+2
-2
performance/Performance.Repository/PerforPeremployeeRepository.cs
+26
-0
performance/Performance.Services/PersonService.cs
+118
-18
No files found.
performance/Performance.Api/Controllers/PersonController.cs
View file @
ca565237
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
FluentValidation.AspNetCore
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.StaticFiles
;
using
Performance.DtoModels
;
using
Performance.EntityModels
;
using
Performance.Infrastructure
;
using
Performance.Services
;
namespace
Performance.Api.Controllers
...
...
@@ -27,13 +30,21 @@ public PersonController(PersonService personService, ClaimService claimService)
/// 获取所有员工记录
/// </summary>
/// <param name="allotId"></param>
/// <param name="request"></param>
/// <returns></returns>
[
Route
(
"person/list/{allotId}"
)]
[
HttpPost
]
public
ApiResponse
GetPersons
(
int
allotId
)
public
ApiResponse
GetPersons
(
[
FromRoute
]
int
allotId
,
[
FromBody
]
PersonParamsRequest
request
)
{
var
list
=
personService
.
GetPersons
(
allotId
,
claimService
.
GetUserId
());
return
new
ApiResponse
(
ResponseType
.
OK
,
list
);
var
list
=
personService
.
GetPersons
(
allotId
,
claimService
.
GetUserId
(),
request
);
return
new
ApiResponse
(
ResponseType
.
OK
,
new
{
list
.
CurrentPage
,
list
.
TotalPages
,
list
.
PageSize
,
list
.
TotalCount
,
list
});
}
/// <summary>
...
...
@@ -80,6 +91,30 @@ public ApiResponse DeletePerson(int employeeId)
}
/// <summary>
/// 下载当前测算表
/// </summary>
/// <returns></returns>
[
Route
(
"person/list/download/{allotId}"
)]
[
HttpPost
]
public
IActionResult
DownloadCurrentCalculationTable
([
FromRoute
]
int
allotId
)
{
var
filepath
=
personService
.
GetPersonDictFile
(
allotId
,
claimService
.
GetUserId
());
if
(!
FileHelper
.
IsExistFile
(
filepath
))
throw
new
PerformanceException
(
"获取人员字典失败"
);
var
memoryStream
=
new
MemoryStream
();
using
(
var
stream
=
new
FileStream
(
filepath
,
FileMode
.
Open
))
{
stream
.
CopyToAsync
(
memoryStream
).
Wait
();
}
memoryStream
.
Seek
(
0
,
SeekOrigin
.
Begin
);
var
provider
=
new
FileExtensionContentTypeProvider
();
FileInfo
fileInfo
=
new
FileInfo
(
filepath
);
var
memi
=
provider
.
Mappings
[
".xlsx"
];
return
File
(
memoryStream
,
memi
,
Path
.
GetFileName
(
fileInfo
.
Name
));
}
/// <summary>
/// 获取所有科室记录
/// </summary>
/// <param name="hospitalId"></param>
...
...
@@ -206,7 +241,7 @@ public ApiResponse BathSavePerson(int allotId, int hospitalId, SaveCollectData r
if
(
result
)
return
new
ApiResponse
(
ResponseType
.
OK
);
else
return
new
ApiResponse
(
ResponseType
.
Error
,
"出勤天数或预留比例格式错误"
);
return
new
ApiResponse
(
ResponseType
.
Error
,
"出勤天数或预留比例格式错误"
);
}
/// <summary>
...
...
performance/Performance.Api/Filters/RequestRateLimitingMiddleware.cs
View file @
ca565237
...
...
@@ -16,7 +16,7 @@ namespace Performance.Api
{
public
class
RequestRateLimitingMiddleware
{
private
readonly
int
Limit
;
private
readonly
int
Limit
=
1
;
private
readonly
ILogger
logger
;
private
readonly
RequestDelegate
next
;
private
readonly
IMemoryCache
requestStore
;
...
...
@@ -34,15 +34,14 @@ public class RequestRateLimitingMiddleware
this
.
next
=
next
;
this
.
requestStore
=
requestStore
;
this
.
httpContextAccessor
=
httpContextAccessor
;
if
(
options
==
null
)
throw
new
ArgumentNullException
(
nameof
(
options
));
this
.
options
=
options
.
Value
;
Limit
=
options
.
Value
.
Limit
;
if
(
options
!=
null
)
Limit
=
options
.
Value
.
Limit
;
}
public
async
Task
Invoke
(
HttpContext
context
)
{
if
(
options
.
Endpoints
==
null
||
!
options
.
Endpoints
.
Any
(
t
=>
context
.
Request
.
Path
.
ToString
().
StartsWith
(
t
)))
if
(
options
==
null
||
options
.
Endpoints
==
null
||
!
options
.
Endpoints
.
Any
(
t
=>
context
.
Request
.
Path
.
ToString
().
StartsWith
(
t
)))
await
next
(
context
);
var
ip
=
httpContextAccessor
.
HttpContext
.
Connection
.
RemoteIpAddress
.
ToString
();
...
...
@@ -69,7 +68,7 @@ public class RequestRateLimitingMiddleware
else
{
// X-RateLimit-RetryAfter:超出限制后能够再次正常访问的时间。
context
.
Response
.
Headers
[
"X-RateLimit-RetryAfter"
]
=
cacheOptions
.
AbsoluteExpiration
?.
ToString
();
//
context.Response.Headers["X-RateLimit-RetryAfter"] = cacheOptions.AbsoluteExpiration?.ToString();
context
.
Response
.
StatusCode
=
StatusCodes
.
Status200OK
;
context
.
Response
.
ContentType
=
"application/json; charset=utf-8"
;
var
response
=
new
ApiResponse
...
...
@@ -90,10 +89,10 @@ public class RequestRateLimitingMiddleware
{
hitCount
++;
requestStore
.
Set
(
requestKey
,
hitCount
,
cacheOptions
);
// X-RateLimit-Limit:同一个时间段所允许的请求的最大数目
context
.
Response
.
Headers
[
"X-RateLimit-Limit"
]
=
Limit
.
ToString
();
// X-RateLimit-Remaining:在当前时间段内剩余的请求的数量。
context
.
Response
.
Headers
[
"X-RateLimit-Remaining"
]
=
(
Limit
-
hitCount
).
ToString
();
//
//
X-RateLimit-Limit:同一个时间段所允许的请求的最大数目
//
context.Response.Headers["X-RateLimit-Limit"] = Limit.ToString();
//
//
X-RateLimit-Remaining:在当前时间段内剩余的请求的数量。
//
context.Response.Headers["X-RateLimit-Remaining"] = (Limit - hitCount).ToString();
await
next
(
context
);
}
}
...
...
performance/Performance.Api/Startup.cs
View file @
ca565237
...
...
@@ -101,15 +101,15 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app
.
UseStatusCodePagesWithReExecute
(
"/error/{0}"
);
}
app
.
UseMiddleware
<
RequestRateLimitingMiddleware
>();
app
.
UseCors
(
"SignalrCore"
);
app
.
UseSignalR
(
routes
=>
routes
.
MapHub
<
AllotLogHub
>(
"/performance/allotLogHub"
));
app
.
UseMvc
();
app
.
UseSwaggerSetup
(
Configuration
);
app
.
UseMiddleware
<
RequestRateLimitingMiddleware
>();
app
.
UseMvc
();
}
private
void
JsonOptions
(
MvcJsonOptions
json
)
...
...
performance/Performance.Api/wwwroot/Performance.Api.xml
View file @
ca565237
...
...
@@ -1101,11 +1101,12 @@
</summary>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.PersonController.GetPersons(System.Int32)"
>
<member
name=
"M:Performance.Api.Controllers.PersonController.GetPersons(System.Int32
,Performance.DtoModels.PersonParamsRequest
)"
>
<summary>
获取所有员工记录
</summary>
<param
name=
"allotId"
></param>
<param
name=
"request"
></param>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.PersonController.CreatePerson(Performance.DtoModels.PerEmployeeResponse)"
>
...
...
@@ -1129,6 +1130,12 @@
<param
name=
"employeeId"
></param>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.PersonController.DownloadCurrentCalculationTable(System.Int32)"
>
<summary>
下载当前测算表
</summary>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.PersonController.GetDepartments(System.Int32)"
>
<summary>
获取所有科室记录
...
...
performance/Performance.Api/wwwroot/Performance.DtoModels.xml
View file @
ca565237
...
...
@@ -1851,7 +1851,7 @@
</member>
<member
name=
"P:Performance.DtoModels.AccoungingRequest.Type"
>
<summary>
1 返回accounting列表 2 返回核算单元
3 返回核算单元类型
1 返回accounting列表 2 返回核算单元
类型 3 返回核算单元
</summary>
</member>
<member
name=
"P:Performance.DtoModels.AccoungingRequest.UnitType"
>
...
...
performance/Performance.DtoModels/Request/PersonParamsRequest.cs
0 → 100644
View file @
ca565237
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Performance.DtoModels
{
public
class
PersonParamsRequest
{
public
const
int
MaxPageSize
=
50
;
public
int
PageNumber
{
get
;
set
;
}
=
1
;
private
int
_pageSize
=
10
;
public
int
PageSize
{
get
{
return
_pageSize
;
}
set
{
_pageSize
=
value
>
MaxPageSize
?
MaxPageSize
:
value
;
}
}
public
string
SearchQuery
{
get
;
set
;
}
}
}
performance/Performance.Infrastructure/Models/PageList.cs
View file @
ca565237
using
System
;
using
Newtonsoft.Json
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
Performance.Infrastructure.Models
{
...
...
performance/Performance.Repository/PerforPeremployeeRepository.cs
0 → 100644
View file @
ca565237
//-----------------------------------------------------------------------
// <copyright file=" per_employee.cs">
// * FileName: per_employee.cs
// </copyright>
//-----------------------------------------------------------------------
using
System
;
using
System.Linq
;
using
System.Linq.Expressions
;
using
Performance.EntityModels
;
using
Performance.Infrastructure.Models
;
namespace
Performance.Repository
{
/// <summary>
/// per_employee Repository
/// </summary>
public
partial
class
PerforPeremployeeRepository
:
PerforRepository
<
per_employee
>
{
public
new
PageList
<
per_employee
>
GetEntitiesForPaging
(
int
pageNumber
,
int
pageSize
,
Expression
<
Func
<
per_employee
,
bool
>>
exp
)
{
IQueryable
<
per_employee
>
queryableAuthors
=
context
.
Set
<
per_employee
>().
Where
(
exp
);
return
PageList
<
per_employee
>.
Create
(
queryableAuthors
,
pageNumber
,
pageSize
);
}
}
}
performance/Performance.Services/PersonService.cs
View file @
ca565237
using
AutoMapper
;
using
Microsoft.EntityFrameworkCore.Internal
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
using
NPOI.SS.UserModel
;
using
NPOI.XSSF.UserModel
;
using
Performance.DtoModels
;
using
Performance.DtoModels.AppSettings
;
using
Performance.EntityModels
;
using
Performance.Infrastructure
;
using
Performance.Infrastructure.Models
;
using
Performance.Repository
;
using
Performance.Services.ExtractExcelService
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Linq.Expressions
;
using
System.Text
;
...
...
@@ -27,6 +33,7 @@ public class PersonService : IAutoInjection
private
readonly
PerforRoleRepository
perforRoleRepository
;
private
readonly
PerforAgsecondallotRepository
agsecondallotRepository
;
private
readonly
Application
application
;
private
readonly
IHostingEnvironment
evn
;
private
readonly
Dictionary
<
string
,
(
string
,
string
)>
dict
=
new
Dictionary
<
string
,
(
string
,
string
)>
{
...
...
@@ -48,7 +55,9 @@ public class PersonService : IAutoInjection
PerforUserroleRepository
perforUserroleRepository
,
PerforRoleRepository
perforRoleRepository
,
PerforAgsecondallotRepository
agsecondallotRepository
,
IOptions
<
Application
>
application
)
IOptions
<
Application
>
application
,
IHostingEnvironment
evn
)
{
this
.
logger
=
logger
;
this
.
perdeptdicRepository
=
perdeptdicRepository
;
...
...
@@ -59,6 +68,7 @@ public class PersonService : IAutoInjection
this
.
perforRoleRepository
=
perforRoleRepository
;
this
.
agsecondallotRepository
=
agsecondallotRepository
;
this
.
application
=
application
.
Value
;
this
.
evn
=
evn
;
}
/// <summary>
...
...
@@ -183,6 +193,34 @@ public List<per_employee> GetPersons(int allotId, int userId)
}
/// <summary>
/// 获取所有员工记录分页
/// </summary>
/// <param name="allotId"></param>
/// <returns></returns>
public
PageList
<
per_employee
>
GetPersons
(
int
allotId
,
int
userId
,
PersonParamsRequest
request
)
{
var
(
dept
,
unittype
)
=
GetDeptByUser
(
userId
);
Expression
<
Func
<
per_employee
,
bool
>>
exp
=
t
=>
t
.
AllotId
==
allotId
;
if
(!
string
.
IsNullOrEmpty
(
dept
)
&&
unittype
.
Any
())
{
exp
=
exp
.
And
(
t
=>
t
.
AccountingUnit
==
dept
&&
unittype
.
Contains
(
t
.
UnitType
));
}
if
(
request
!=
null
&&
!
string
.
IsNullOrEmpty
(
request
.
SearchQuery
))
{
exp
=
exp
.
And
(
t
=>
true
&&
(
t
.
AccountingUnit
.
Contains
(
request
.
SearchQuery
)
||
t
.
DoctorName
.
Contains
(
request
.
SearchQuery
)
||
t
.
Department
.
Contains
(
request
.
SearchQuery
)));
}
var
result
=
new
List
<
per_employee
>();
var
list
=
peremployeeRepository
.
GetEntitiesForPaging
(
request
.
PageNumber
,
request
.
PageSize
,
exp
);
if
(
list
!=
null
&&
list
.
Any
())
result
=
list
.
OrderBy
(
w
=>
w
.
IsVerify
).
ThenBy
(
t
=>
t
.
Id
).
ToList
();
return
new
PageList
<
per_employee
>(
result
,
list
?.
TotalCount
??
0
,
request
.
PageNumber
,
request
.
PageSize
);
}
/// <summary>
/// 新增员工信息
/// </summary>
/// <param name="request"></param>
...
...
@@ -601,9 +639,9 @@ private string[] GetUnitType(int userId)
public
HandsonTable
GetBatchPersonStructrue
(
int
hospitalId
)
{
var
result
=
new
HandsonTable
((
int
)
SheetType
.
Unidentifiable
,
Person
.
Select
(
t
=>
t
.
Value
).
ToArray
(),
Person
.
Select
(
t
=>
new
collect_permission
var
result
=
new
HandsonTable
((
int
)
SheetType
.
Unidentifiable
,
Person
.
Select
(
t
=>
t
.
Item2
).
ToArray
(),
Person
.
Select
(
t
=>
new
collect_permission
{
HeadName
=
t
.
Value
,
HeadName
=
t
.
Item2
,
Visible
=
1
}).
ToList
());
...
...
@@ -681,7 +719,9 @@ public HandsonTable GetDepartmentHands(int hospitalId)
public
bool
BathSavePerson
(
int
AllotId
,
int
HospitalId
,
SaveCollectData
request
)
{
var
dicData
=
CreateDataRow
(
request
,
Person
);
var
dict
=
new
Dictionary
<
string
,
string
>();
Person
.
ForEach
(
t
=>
dict
.
Add
(
t
.
Item1
,
t
.
Item2
));
var
dicData
=
CreateDataRow
(
request
,
dict
);
List
<
per_employee
>
employees
=
new
List
<
per_employee
>();
var
persons
=
peremployeeRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
HospitalId
&&
t
.
AllotId
==
AllotId
);
foreach
(
var
item
in
dicData
)
...
...
@@ -864,20 +904,20 @@ private void DeptDicList(int HospitalId, List<per_dept_dic> deptDics, DeptdicHan
return
result
;
}
public
static
Dictionary
<
string
,
string
>
Person
{
get
;
}
=
new
Dictionary
<
string
,
string
>
{
{
nameof
(
per_employee
.
AccountingUnit
),
"核算单元"
}
,
{
nameof
(
per_employee
.
Department
),
"科室名称"
}
,
{
nameof
(
per_employee
.
DoctorName
),
"姓名"
}
,
{
nameof
(
per_employee
.
PersonnelNumber
),
"员工工号"
}
,
{
nameof
(
per_employee
.
JobCategory
),
"正式/临聘"
}
,
{
nameof
(
per_employee
.
Duty
),
"职务"
}
,
{
nameof
(
per_employee
.
JobTitle
),
"职称"
}
,
{
nameof
(
per_employee
.
UnitType
),
"人员类别"
}
,
{
nameof
(
per_employee
.
AttendanceDay
),
"出勤天数"
}
,
{
nameof
(
per_employee
.
ReservedRatio
),
"预留比例"
}
,
{
nameof
(
per_employee
.
BankCard
),
"银行卡号"
}
,
{
nameof
(
per_employee
.
Remark
),
"备注"
}
,
public
static
List
<(
string
,
string
,
Func
<
per_employee
,
object
>)>
Person
{
get
;
}
=
new
List
<(
string
,
string
,
Func
<
per_employee
,
object
>)
>
{
(
nameof
(
per_employee
.
AccountingUnit
),
"核算单元"
,
t
=>
t
.
AccountingUnit
)
,
(
nameof
(
per_employee
.
Department
),
"科室名称"
,
t
=>
t
.
Department
)
,
(
nameof
(
per_employee
.
DoctorName
),
"姓名"
,
t
=>
t
.
DoctorName
)
,
(
nameof
(
per_employee
.
PersonnelNumber
),
"员工工号"
,
t
=>
t
.
PersonnelNumber
)
,
(
nameof
(
per_employee
.
JobCategory
),
"正式/临聘"
,
t
=>
t
.
JobCategory
)
,
(
nameof
(
per_employee
.
Duty
),
"职务"
,
t
=>
t
.
Duty
)
,
(
nameof
(
per_employee
.
JobTitle
),
"职称"
,
t
=>
t
.
JobTitle
)
,
(
nameof
(
per_employee
.
UnitType
),
"人员类别"
,
t
=>
t
.
UnitType
)
,
(
nameof
(
per_employee
.
AttendanceDay
),
"出勤天数"
,
t
=>
t
.
AttendanceDay
)
,
(
nameof
(
per_employee
.
ReservedRatio
),
"预留比例"
,
t
=>
t
.
ReservedRatio
)
,
(
nameof
(
per_employee
.
BankCard
),
"银行卡号"
,
t
=>
t
.
BankCard
)
,
(
nameof
(
per_employee
.
Remark
),
"备注"
,
t
=>
t
.
Remark
)
,
};
private
static
Dictionary
<
string
,
string
>
DeptDic
{
get
;
}
=
new
Dictionary
<
string
,
string
>
...
...
@@ -893,5 +933,65 @@ private void DeptDicList(int HospitalId, List<per_dept_dic> deptDics, DeptdicHan
{
nameof
(
DeptdicResponse
.
LogisticsAccounting
),
"行政后勤"
},
{
nameof
(
DeptdicResponse
.
SpecialAccounting
),
"特殊核算组"
}
};
public
string
GetPersonDictFile
(
int
allotId
,
int
userId
)
{
var
allot
=
perallotRepository
.
GetEntity
(
t
=>
t
.
ID
==
allotId
);
if
(
allot
==
null
)
throw
new
PerformanceException
(
"绩效记录不存在"
);
var
data
=
GetPersons
(
allotId
,
userId
)
??
new
List
<
per_employee
>();
var
dpath
=
Path
.
Combine
(
evn
.
ContentRootPath
,
"Files"
,
"Dictionary"
,
$"
{
allot
.
HospitalId
}
"
);
FileHelper
.
CreateDirectory
(
dpath
);
string
filename
=
$"
{
allot
.
Year
}{
allot
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)}
人员字典-
{
DateTime
.
Now
.
ToString
(
"yyyyMMddhhmmss"
)}
.xlsx"
;
string
filepath
=
Path
.
Combine
(
dpath
,
filename
);
FileStream
stream
=
new
FileStream
(
filepath
,
FileMode
.
Create
);
try
{
XSSFWorkbook
workbook
=
new
XSSFWorkbook
();
ExcelStyle
excelStyle
=
new
ExcelStyle
(
workbook
);
var
style
=
excelStyle
.
SetBgkColorAndFormat
(
excelStyle
.
GetCellStyle
());
ISheet
sheet
=
workbook
.
CreateSheet
(
"人员字典"
);
var
header
=
sheet
.
CreateRow
(
0
);
int
cellIndex
=
0
;
foreach
(
var
column
in
Person
.
Select
(
t
=>
t
.
Item2
))
{
var
cell
=
header
.
CreateCell
(
cellIndex
);
cell
.
SetCellValue
(
column
);
cell
.
CellStyle
=
style
;
cellIndex
++;
}
int
startIndex
=
1
;
foreach
(
var
item
in
data
)
{
var
row
=
sheet
.
CreateRow
(
startIndex
);
cellIndex
=
0
;
foreach
(
var
field
in
Person
.
Select
(
t
=>
t
.
Item3
))
{
var
cell
=
row
.
CreateCell
(
cellIndex
);
cell
.
SetCellOValue
(
field
?.
Invoke
(
item
));
cell
.
CellStyle
=
style
;
cellIndex
++;
}
startIndex
++;
}
workbook
.
Write
(
stream
);
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
"写入异常"
+
ex
);
}
finally
{
stream
.
Close
();
}
return
filepath
;
}
}
}
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