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
a61ec8a5
Commit
a61ec8a5
authored
Aug 06, 2019
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/feature/extract' into feature/extract
parents
fc9614b8
d30b5594
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
29 deletions
+124
-29
performance/Performance.Services/NewExtractService.cs
+124
-29
No files found.
performance/Performance.Services/NewExtractService.cs
View file @
a61ec8a5
...
...
@@ -3,6 +3,7 @@
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
using
NPOI.HSSF.UserModel
;
using
NPOI.HSSF.Util
;
using
NPOI.SS.UserModel
;
using
NPOI.SS.Util
;
using
NPOI.XSSF.UserModel
;
...
...
@@ -42,6 +43,8 @@ public class NewExtractService : IAutoInjection
private
readonly
PerforImspecialunitRepository
perforImspecialunitRepository
;
private
readonly
PerforImdataRepository
perforImdataRepository
;
private
ICellStyle
style
;
public
NewExtractService
(
ILogger
<
ExtractService
>
logger
,
IHostingEnvironment
environment
,
PerSheetService
perSheetService
,
...
...
@@ -80,7 +83,7 @@ public class NewExtractService : IAutoInjection
public
string
ExtractData
(
int
allotId
,
string
email
,
int
hospitalId
)
{
// 获取
医院
信息
// 获取
绩效
信息
var
allot
=
perforPerallotRepository
.
GetEntity
(
t
=>
t
.
ID
==
allotId
);
if
(
allot
==
null
)
throw
new
PerformanceException
(
"AllotID错误"
);
...
...
@@ -120,6 +123,26 @@ public string ExtractData(int allotId, string email, int hospitalId)
CreateNotExistSheet
(
modulesList
,
workbook
);
#
region
单元格样式
style
=
workbook
.
CreateCellStyle
();
IFont
titleFont
=
workbook
.
CreateFont
();
titleFont
.
FontHeightInPoints
=
12
;
//设置字体大小
titleFont
.
Color
=
HSSFColor
.
Black
.
Index
;
//设置字体颜色
style
.
SetFont
(
titleFont
);
//边框
style
.
BorderBottom
=
BorderStyle
.
Thin
;
style
.
BorderLeft
=
BorderStyle
.
Thin
;
style
.
BorderRight
=
BorderStyle
.
Thin
;
style
.
BorderTop
=
BorderStyle
.
Thin
;
//前景色
style
.
FillForegroundColor
=
NPOI
.
HSSF
.
Util
.
HSSFColor
.
SkyBlue
.
Index
;
style
.
FillPattern
=
FillPattern
.
SolidForeground
;
#
endregion
for
(
int
i
=
0
;
i
<
workbook
.
NumberOfSheets
;
i
++)
{
var
sheet
=
workbook
.
GetSheetAt
(
i
);
...
...
@@ -179,21 +202,23 @@ private static void CreateNotExistSheet(List<mod_module> modulesList, IWorkbook
pairs
.
Add
(
workbook
.
GetSheetAt
(
i
).
SheetName
,
i
);
}
foreach
(
var
module
in
modulesList
.
Where
(
t
=>
t
.
SheetType
==
(
int
)
SheetType
.
Income
))
int
sheetIndex
=
0
;
foreach
(
var
module
in
modulesList
.
Where
(
t
=>
t
.
SheetType
==
(
int
)
SheetType
.
Income
)?.
OrderBy
(
t
=>
t
.
ModuleName
))
{
var
sheet
=
workbook
.
GetSheet
(
module
.
ModuleName
);
if
(
sheet
==
null
)
{
string
[]
keyArray
=
new
string
[]
{
"就诊"
,
"
开单
"
};
string
[]
keyArray
=
new
string
[]
{
"就诊"
,
"
执行
"
};
if
(
keyArray
.
Any
(
key
=>
module
.
ModuleName
.
Contains
(
key
)))
{
var
newSheet
=
workbook
.
CreateSheet
(
module
.
ModuleName
);
foreach
(
var
key
in
keyArray
)
{
var
item
=
pairs
.
FirstOrDefault
(
t
=>
t
.
Key
.
Contains
(
key
));
newSheet
.
CopySheet
(
item
.
Key
);
workbook
.
SetSheetOrder
(
module
.
ModuleName
,
item
.
Value
);
}
var
item
=
pairs
.
Where
(
t
=>
t
.
Key
.
StartsWith
(
"1."
)).
OrderByDescending
(
t
=>
t
.
Key
).
First
();
if
(
sheetIndex
==
0
)
sheetIndex
=
item
.
Value
;
var
copysheet
=
workbook
.
GetSheet
(
item
.
Key
);
var
newSheet
=
copysheet
.
CopySheet
(
item
.
Key
,
true
);
workbook
.
SetSheetOrder
(
newSheet
.
SheetName
,
sheetIndex
);
workbook
.
SetSheetName
(
sheetIndex
,
module
.
ModuleName
);
sheetIndex
++;
}
}
}
...
...
@@ -230,13 +255,13 @@ private void WriteIncome(ISheet sheet, int allotLastId, IPerSheetDataRead sheetR
var
itemList
=
perforModitemRepository
.
GetEntities
(
t
=>
t
.
ModuleId
==
module
.
Id
);
if
(
itemList
==
null
||
!
itemList
.
Any
())
return
;
var
nurseFactor
=
sheet
.
GetRow
(
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
0
);
var
doctorFactor
=
sheet
.
GetRow
(
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
1
);
var
technicianFactor
=
sheet
.
GetRow
(
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
2
);
var
head
=
sheet
.
GetRow
(
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
3
);
var
nurseFactor
=
GetOrCreate
(
sheet
,
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
0
);
var
doctorFactor
=
GetOrCreate
(
sheet
,
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
1
);
var
technicianFactor
=
GetOrCreate
(
sheet
,
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
2
);
var
head
=
GetOrCreate
(
sheet
,
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
3
);
//写入列头信息
int
cellStartIndex
=
sheetRead
.
Point
.
HeaderFirstCellNum
.
Value
+
3
;
int
cellStartIndex
=
sheetRead
.
Point
.
HeaderFirstCellNum
.
Value
+
4
;
foreach
(
var
item
in
itemList
)
{
GetOrCreate
(
head
,
cellStartIndex
).
SetCellValue
(
item
.
ItemName
);
...
...
@@ -247,6 +272,7 @@ private void WriteIncome(ISheet sheet, int allotLastId, IPerSheetDataRead sheetR
}
//查询数据
var
extractList
=
perforModextractRepository
.
GetEntities
(
t
=>
module
.
ExtractId
==
t
.
Id
);
if
(
extractList
==
null
||
extractList
.
Count
==
0
)
return
;
List
<
ExtractDto
>
allExtract
=
new
List
<
ExtractDto
>();
foreach
(
var
item
in
extractList
)
...
...
@@ -259,7 +285,7 @@ private void WriteIncome(ISheet sheet, int allotLastId, IPerSheetDataRead sheetR
var
importSheet
=
perforPersheetRepository
.
GetEntities
(
t
=>
t
.
AllotID
==
allotLastId
&&
t
.
SheetType
==
(
int
)
SheetType
.
Income
);
var
importSheetId
=
importSheet
.
Select
(
t
=>
t
.
ID
).
ToList
();
var
importData
=
perforImdataRepository
.
GetEntities
(
t
=>
importSheetId
.
Contains
(
t
.
SheetID
.
Value
));
var
rowIndex
=
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
3
;
var
rowIndex
=
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
4
;
foreach
(
var
department
in
allExtract
.
Select
(
t
=>
t
.
Department
).
Distinct
())
{
var
row
=
sheet
.
CreateRow
(
rowIndex
);
...
...
@@ -292,8 +318,9 @@ private void WriteIncome(ISheet sheet, int allotLastId, IPerSheetDataRead sheetR
var
value
=
allExtract
.
FirstOrDefault
(
t
=>
t
.
Department
==
department
&&
t
.
Category
==
headName
)?.
Value
;
newCell
.
SetCellValue
(
value
==
null
||
value
==
0
?
""
:
value
.
ToString
());
}
newCell
.
CellStyle
.
FillBackgroundColor
=
NPOI
.
HSSF
.
Util
.
HSSFColor
.
LightBlue
.
Index
;
newCell
.
CellStyle
=
style
;
}
rowIndex
++;
}
}
...
...
@@ -307,6 +334,15 @@ private ICell GetOrCreate(IRow row, int index)
return
cell
;
}
private
IRow
GetOrCreate
(
ISheet
sheet
,
int
index
)
{
var
row
=
sheet
.
GetRow
(
index
);
if
(
row
==
null
)
row
=
sheet
.
CreateRow
(
index
);
return
row
;
}
private
Dictionary
<
string
,
string
>
GetParameters
(
per_allot
allot
)
{
DateTime
beginTime
=
new
DateTime
(
allot
.
Year
,
allot
.
Month
,
1
);
...
...
@@ -327,11 +363,11 @@ private void WriteWorkload(ISheet sheet, int allotLastId, IPerSheetDataRead shee
var
itemList
=
perforModitemRepository
.
GetEntities
(
t
=>
t
.
ModuleId
==
module
.
Id
);
if
(
itemList
==
null
||
!
itemList
.
Any
())
return
;
var
head
=
sheet
.
GetRow
(
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
1
);
var
factor
=
sheet
.
GetRow
(
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
2
);
var
head
=
GetOrCreate
(
sheet
,
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
1
);
var
factor
=
GetOrCreate
(
sheet
,
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
2
);
//写入列头信息
int
cellStartIndex
=
sheetRead
.
Point
.
HeaderFirstCellNum
.
Value
+
3
;
int
cellStartIndex
=
sheetRead
.
Point
.
HeaderFirstCellNum
.
Value
+
2
;
foreach
(
var
item
in
itemList
)
{
GetOrCreate
(
head
,
cellStartIndex
).
SetCellValue
(
item
.
ItemName
);
...
...
@@ -341,18 +377,24 @@ private void WriteWorkload(ISheet sheet, int allotLastId, IPerSheetDataRead shee
//查询数据
var
extractIdList
=
itemList
.
Select
(
t
=>
t
.
ExtractId
).
Distinct
().
ToList
();
var
extractList
=
perforModextractRepository
.
GetEntities
(
t
=>
extractIdList
.
Contains
(
t
.
Id
));
if
(
extractList
==
null
||
extractList
.
Count
==
0
)
return
;
List
<
ExtractDto
>
allExtract
=
new
List
<
ExtractDto
>();
foreach
(
var
item
in
extractList
)
{
var
result
=
QueryDatabase
(
hospitalConfigList
,
item
,
allot
);
var
category
=
itemList
.
Where
(
t
=>
t
.
ExtractId
==
item
.
Id
);
if
(
category
==
null
||
category
.
Count
()
==
0
)
continue
;
foreach
(
var
moditem
in
category
)
{
var
result
=
QueryDatabase
(
hospitalConfigList
,
item
,
allot
,
moditem
.
ItemName
);
if
(
result
!=
null
)
allExtract
.
AddRange
(
result
);
}
}
//写入数据
var
importSheet
=
perforPersheetRepository
.
GetEntity
(
t
=>
t
.
AllotID
==
allotLastId
&&
t
.
SheetName
==
module
.
ModuleName
);
var
importData
=
perforImdataRepository
.
GetEntities
(
t
=>
t
.
SheetID
==
importSheet
.
ID
);
var
rowIndex
=
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
3
;
var
rowIndex
=
sheetRead
.
Point
.
HeaderFirstRowNum
.
Value
+
2
;
foreach
(
var
department
in
allExtract
.
Select
(
t
=>
t
.
Department
).
Distinct
())
{
var
row
=
sheet
.
CreateRow
(
rowIndex
);
...
...
@@ -375,12 +417,12 @@ private void WriteWorkload(ISheet sheet, int allotLastId, IPerSheetDataRead shee
var
value
=
allExtract
.
FirstOrDefault
(
t
=>
t
.
Department
==
department
&&
t
.
Category
==
headName
)?.
Value
;
newCell
.
SetCellValue
(
value
==
null
||
value
==
0
?
""
:
value
.
ToString
());
}
newCell
.
CellStyle
.
FillBackgroundColor
=
NPOI
.
HSSF
.
Util
.
HSSFColor
.
LightBlue
.
Index
;
newCell
.
CellStyle
=
style
;
}
}
}
private
List
<
ExtractDto
>
QueryDatabase
(
List
<
sys_hospitalconfig
>
hospitalConfigList
,
mod_extract
extract
,
per_allot
allot
)
private
List
<
ExtractDto
>
QueryDatabase
(
List
<
sys_hospitalconfig
>
hospitalConfigList
,
mod_extract
extract
,
per_allot
allot
,
string
category
=
null
)
{
var
config
=
hospitalConfigList
.
FirstOrDefault
(
t
=>
t
.
Type
==
extract
.
SourceType
);
var
parameters
=
GetParameters
(
allot
);
...
...
@@ -398,7 +440,7 @@ private List<ExtractDto> QueryDatabase(List<sys_hospitalconfig> hospitalConfigLi
{
foreach
(
var
item
in
result
)
{
item
.
Category
=
extract
.
EName
;
item
.
Category
=
category
;
}
}
return
result
.
ToList
();
...
...
@@ -488,9 +530,27 @@ private void WriteSpecialUnit(ISheet sheet, int hospitalId, int allotLastId, IPe
{
"调节系数"
,
(
special
,
lastAllot
)
=>
lastAllot
.
Where
(
t
=>
special
.
Department
==
t
.
Department
).
Max
(
t
=>
t
.
Adjust
)
},
};
var
modDataList
=
perforModspecialRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
);
var
modDataList
=
perforModspecialRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
)?.
OrderBy
(
t
=>
t
.
Department
).
ToList
();
var
allotDataList
=
perforImspecialunitRepository
.
GetEntities
(
t
=>
t
.
AllotID
==
allotLastId
);
if
(
modDataList
==
null
||
modDataList
.
Count
==
0
)
return
;
//取消合并单元格
int
mergedCount
=
sheet
.
NumMergedRegions
;
for
(
int
i
=
mergedCount
-
1
;
i
>=
0
;
i
--)
{
var
temp
=
sheet
.
GetMergedRegion
(
i
);
if
(
temp
.
FirstRow
>
sheetRead
.
Point
.
HeaderFirstRowNum
)
sheet
.
RemoveMergedRegion
(
i
);
}
var
modDataGroup
=
modDataList
.
GroupBy
(
t
=>
new
{
t
.
Department
}).
Select
(
group
=>
new
{
Department
=
group
.
Key
.
Department
,
Count
=
group
.
Count
()
})?.
OrderBy
(
t
=>
t
.
Department
);
int
mergedBegin
=
sheetRead
.
Point
.
DataFirstRowNum
.
Value
;
int
mergedEnd
=
sheetRead
.
Point
.
DataFirstRowNum
.
Value
;
for
(
int
i
=
0
;
i
<
modDataList
.
Count
;
i
++)
{
...
...
@@ -500,17 +560,51 @@ private void WriteSpecialUnit(ISheet sheet, int hospitalId, int allotLastId, IPe
var
rowIndex
=
sheetRead
.
Point
.
DataFirstRowNum
.
Value
+
i
;
var
importRow
=
sheet
.
CreateRow
(
rowIndex
);
int
cellIndex
=
0
;
foreach
(
var
cell
in
cellList
)
{
if
(
dictionary
.
ContainsKey
(
cell
.
StringCellValue
))
{
var
item
=
dictionary
.
First
(
t
=>
t
.
Key
==
cell
.
StringCellValue
);
var
value
=
(
item
.
Value
.
Invoke
(
modDataList
[
i
],
allotDataList
)
??
""
).
ToString
();
if
(!
new
List
<
string
>
{
"量化指标"
,
"数量"
,
"量化指标绩效分值"
}.
Contains
(
cell
.
StringCellValue
)
&&
rowIndex
==
mergedBegin
)
{
if
(
item
.
Key
==
"科室"
)
{
var
count
=
modDataGroup
.
First
(
t
=>
t
.
Department
.
ToString
()
==
value
).
Count
;
mergedEnd
=
mergedBegin
+
count
-
1
;
}
sheet
.
AddMergedRegion
(
new
CellRangeAddress
(
mergedBegin
,
mergedEnd
,
cellIndex
,
cellIndex
));
//合并单元格
var
newCell
=
importRow
.
CreateCell
(
cellIndex
);
newCell
.
SetCellValue
(
Verify
(
value
));
style
.
Alignment
=
HorizontalAlignment
.
Center
;
//水平居中
style
.
VerticalAlignment
=
VerticalAlignment
.
Center
;
//垂直居中
newCell
.
CellStyle
=
style
;
}
else
{
var
newCell
=
importRow
.
CreateCell
(
cell
.
ColumnIndex
);
newCell
.
SetCellValue
(
Verify
(
value
));
newCell
.
CellStyle
.
FillBackgroundColor
=
NPOI
.
HSSF
.
Util
.
HSSFColor
.
LightBlue
.
Index
;
newCell
.
CellStyle
=
style
;
}
}
else
{
if
(!
new
List
<
string
>
{
"量化指标"
,
"数量"
,
"量化指标绩效分值"
}.
Contains
(
cell
.
StringCellValue
)
&&
rowIndex
==
mergedBegin
)
{
sheet
.
AddMergedRegion
(
new
CellRangeAddress
(
mergedBegin
,
mergedEnd
,
cellIndex
,
cellIndex
));
//合并单元格
var
newCell
=
importRow
.
CreateCell
(
cellIndex
);
newCell
.
SetCellValue
(
""
);
style
.
Alignment
=
HorizontalAlignment
.
Center
;
//水平居中
style
.
VerticalAlignment
=
VerticalAlignment
.
Center
;
//垂直居中
newCell
.
CellStyle
=
style
;
}
}
cellIndex
++;
}
mergedBegin
=
mergedEnd
+
1
;
}
}
...
...
@@ -552,10 +646,11 @@ private void WriteAccountBasic(ISheet sheet, int allotLastId, IPerSheetDataRead
var
value
=
(
item
.
Value
.
Invoke
(
dataList
[
i
])
??
""
).
ToString
();
var
newCell
=
importRow
.
CreateCell
(
cell
.
ColumnIndex
);
newCell
.
SetCellValue
(
Verify
(
value
));
newCell
.
CellStyle
.
FillBackgroundColor
=
NPOI
.
HSSF
.
Util
.
HSSFColor
.
LightBlue
.
Index
;
newCell
.
CellStyle
=
style
;
}
}
}
#
region
校验数据格式
/// <summary>
/// 校验数据格式,并转换
...
...
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