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
b2fcc28e
Commit
b2fcc28e
authored
Jun 05, 2023
by
wyc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
科室绩效详情下载
parent
12a13c86
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
87 deletions
+98
-87
performance/Performance.Api/Controllers/ComputeController.cs
+26
-0
performance/Performance.Services/ComputeService.UniteDeptDetail.cs
+72
-87
No files found.
performance/Performance.Api/Controllers/ComputeController.cs
View file @
b2fcc28e
...
...
@@ -213,6 +213,32 @@ public ApiResponse UniteDeptDetail([FromBody] UniteDeptDetailRequest request)
}
[
Route
(
"download/unite/deptdetail"
)]
[
HttpPost
]
public
IActionResult
DownloadUniteDeptdetail
([
FromBody
]
UniteDeptDetailRequest
request
)
{
request
.
UnitType
=
request
.
UnitType
.
Replace
(
"行政后勤"
,
"行政工勤"
);
if
(!
Enum
.
TryParse
(
request
.
UnitType
,
ignoreCase
:
true
,
out
UnitType
unitType
))
return
BadRequest
(
"核算组别错误"
);
var
userid
=
_claim
.
GetUserId
();
var
uniteDeptDetail
=
_computeService
.
UniteDeptDetail
(
request
.
AllotId
,
unitType
,
request
.
AccountingUnit
,
userid
);
//var ser = JsonConvert.SerializeObject(response);
//var rows = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(ser);
//Dictionary<string, object> rows = _computeService.ConvertToDictionary(response);
var
filepath
=
_computeService
.
ExcelDownload
(
uniteDeptDetail
,
"科室绩效详情"
,
request
.
AllotId
);
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
));
}
#
region
20230531
即将弃用,由新接口替代
...
...
performance/Performance.Services/ComputeService.UniteDeptDetail.cs
View file @
b2fcc28e
...
...
@@ -605,81 +605,28 @@ public void SaveUniteDeptDetailSetting(int allotId, List<UniteDeptDetailItem> re
}
#
region
科室详情下载
//public string ExcelDownload(List<Dictionary<string, object>> rows, string name, int allotId)
//{
// var perAllot = perforPerallotRepository.GetEntity(t => t.ID == allotId);
// string title = $"{perAllot.Year}年{perAllot.Month}月{name}";
// var data = new List<Dictionary<string, object>>();
// foreach (var obj in rows)
// {
// Dictionary<string, object> nobj = new Dictionary<string, object>();
// foreach (var item in obj)
// {
// var lower = item.Key.ToLower();
// if (lower.Contains("date"))
// nobj[lower] = Convert.ToDateTime(item.Value).ToString("d");
// else if (lower.Contains("detial"))
// {
// var detRows = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(item.Value.ToString());
// foreach (var detlist in detRows)
// {
// object value = null;
// foreach (var detitem in detlist)
// {
// if (detitem.Key.Equals("Value", StringComparison.OrdinalIgnoreCase))
// value = detitem.Value;
// if (detitem.Key.Equals("Title", StringComparison.OrdinalIgnoreCase))
// nobj[detitem.Value.ToString()] = value;
// }
// }
// }
// else
// nobj[lower] = item.Value;
// }
// data.Add(nobj);
// }
// var dpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files");
// if (!Directory.Exists(dpath)) Directory.CreateDirectory(dpath);
// string filepath = Path.Combine(dpath, $"{name}{DateTime.Now:yyyy年MM月dd日}");
// if (File.Exists(filepath)) File.Delete(filepath);
// using (FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate))
// using (ExcelPackage package = new ExcelPackage(fs))
// {
// var worksheet = package.Workbook.Worksheets.Add(name);
public
string
ExcelDownload
(
UniteDeptDetailResponse
uniteDeptDetail
,
string
name
,
int
allotId
)
{
var
dpath
=
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
"Files"
);
if
(!
Directory
.
Exists
(
dpath
))
Directory
.
CreateDirectory
(
dpath
);
// if (rows != null && rows.Count() > 0)
// {
// worksheet.SetValue(1, 1, title);
string
filepath
=
Path
.
Combine
(
dpath
,
$"
{
name
}{
DateTime
.
Now
:
yyyy
年
MM
月
dd
日
}
"
);
if
(
File
.
Exists
(
filepath
))
File
.
Delete
(
filepath
);
// for (int col = 0; col < headList.Count; col++)
// {
// worksheet.SetValue(2, col + 1, headList[col].Alias);
// }
// for (int col = 0; col < headList.Count; col++)
// {
// for (int row = 0; row < data.Count(); row++)
// {
// var temp = data.ElementAt(row);
using
(
FileStream
fs
=
new
FileStream
(
filepath
,
FileMode
.
OpenOrCreate
))
using
(
ExcelPackage
package
=
new
ExcelPackage
(
fs
))
{
var
maxColIndex
=
10
;
var
worksheet
=
package
.
Workbook
.
Worksheets
.
Add
(
name
);
worksheet
.
SetValue
(
1
,
1
,
uniteDeptDetail
.
Title
);
worksheet
.
Cells
[
1
,
1
,
1
,
maxColIndex
].
Merge
=
true
;
// var key = headList[col].Name;
// if (!temp.ContainsKey(key))
// key = key.ToLower();
// temp.TryGetValue(key, out object value);
// worksheet.Cells[row + 3, col + 1].Value = value ?? "";
var
rowIndex
=
1
;
xx
(
worksheet
,
maxColIndex
,
rowIndex
,
uniteDeptDetail
.
DetailItems
);
// }
// }
// #region 样式设置
// for (int row = worksheet.Dimension.Start.Row; row <= worksheet.Dimension.End.Row; row++)
// {
//#region 样式设置
//for (int row = worksheet.Dimension.Start.Row; row <= worksheet.Dimension.End.Row; row++)
//{
// worksheet.Row(row).Height = 20;
// for (int col = worksheet.Dimension.Start.Column; col <= worksheet.Dimension.End.Column; col++)
// {
...
...
@@ -687,24 +634,62 @@ public void SaveUniteDeptDetailSetting(int allotId, List<UniteDeptDetailItem> re
// worksheet.Cells[row, col].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
// worksheet.Cells[row, col].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
// }
// }
// //worksheet.Cells[1, 1, 1, headList.Count].Merge = true;
// //worksheet.Cells[1, 1, 1, headList.Count].Style.Font.Bold = true;
// //worksheet.Cells[1, 1, 1, headList.Count].Style.Font.Size = 16;
// //worksheet.Row(1).Height = 24;
// //worksheet.Cells[2, 1, 2, headList.Count].Style.Font.Bold = true;
// worksheet.View.FreezePanes(3, 1);
// worksheet.Cells.AutoFitColumns();
// for (int col = worksheet.Dimension.Start.Column; col <= worksheet.Dimension.End.Column; col++)
// {
//}
////worksheet.Cells[1, 1, 1, headList.Count].Merge = true;
////worksheet.Cells[1, 1, 1, headList.Count].Style.Font.Bold = true;
////worksheet.Cells[1, 1, 1, headList.Count].Style.Font.Size = 16;
////worksheet.Row(1).Height = 24;
////worksheet.Cells[2, 1, 2, headList.Count].Style.Font.Bold = true;
//worksheet.Cells.AutoFitColumns();
//for (int col = worksheet.Dimension.Start.Column; col <= worksheet.Dimension.End.Column; col++)
//{
// worksheet.Column(col).Width = worksheet.Column(col).Width > 20 ? 20 : worksheet.Column(col).Width;
// }
// #endregion
// }
// package.Save();
// }
// return filepath;
//}
//#endregion
package
.
Save
();
}
return
filepath
;
}
void
xx
(
ExcelWorksheet
worksheet
,
int
maxColIndex
,
int
rowIndex
,
List
<
DeptDetailItem
>
detailItems
)
{
foreach
(
var
item
in
detailItems
)
{
rowIndex
=
rowIndex
+
1
;
worksheet
.
SetValue
(
rowIndex
,
1
,
$"
{
item
.
Title
}
:
{
item
.
TotalFormat
}
"
);
worksheet
.
Cells
[
rowIndex
,
1
,
rowIndex
,
maxColIndex
].
Merge
=
true
;
if
(
item
.
Children
?.
Any
()
==
true
)
{
xx
(
worksheet
,
maxColIndex
,
rowIndex
,
item
.
Children
);
}
else
if
(
item
.
Items
?.
Any
()
==
true
)
{
rowIndex
=
rowIndex
+
1
;
var
headers
=
item
.
Items
.
FirstOrDefault
().
Keys
.
Select
(
w
=>
w
);
for
(
int
colIndex
=
0
;
colIndex
<
headers
.
Count
();
colIndex
++)
{
worksheet
.
SetValue
(
rowIndex
,
colIndex
+
1
,
headers
.
ElementAt
(
colIndex
));
if
(
colIndex
+
1
==
headers
.
Count
())
worksheet
.
Cells
[
rowIndex
,
colIndex
,
rowIndex
,
maxColIndex
].
Merge
=
true
;
}
rowIndex
=
rowIndex
+
1
;
foreach
(
var
row
in
item
.
Items
)
{
rowIndex
=
rowIndex
+
1
;
for
(
int
colIndex
=
0
;
colIndex
<
headers
.
Count
();
colIndex
++)
{
worksheet
.
SetValue
(
rowIndex
,
colIndex
+
1
,
row
[
headers
.
ElementAt
(
colIndex
)]);
if
(
colIndex
+
1
==
headers
.
Count
())
worksheet
.
Cells
[
rowIndex
,
colIndex
,
rowIndex
,
maxColIndex
].
Merge
=
true
;
}
}
}
}
}
#
endregion
}
}
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