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
241f5a3f
Commit
241f5a3f
authored
Jan 19, 2022
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
在线Excel初稿
parent
8c3a2cf2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
263 additions
and
0 deletions
+263
-0
performance/Performance.Api/Controllers/OnlineExcelController.cs
+70
-0
performance/Performance.Api/wwwroot/Performance.Api.xml
+5
-0
performance/Performance.Services/OnlineExcel/Model/EpCellClass.cs
+32
-0
performance/Performance.Services/OnlineExcel/Model/EpChanage.cs
+33
-0
performance/Performance.Services/OnlineExcel/Model/EpCustomBorders.cs
+21
-0
performance/Performance.Services/OnlineExcel/Model/EpMerge.cs
+14
-0
performance/Performance.Services/OnlineExcel/Model/EpSheet.cs
+14
-0
performance/Performance.Services/OnlineExcel/OnlineExcelService.Read.cs
+0
-0
performance/Performance.Services/OnlineExcel/OnlineExcelService.Write.cs
+73
-0
performance/Performance.Services/Performance.Services.csproj
+1
-0
No files found.
performance/Performance.Api/Controllers/OnlineExcelController.cs
0 → 100644
View file @
241f5a3f
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Mvc
;
using
Newtonsoft.Json
;
using
Performance.DtoModels
;
using
Performance.Services
;
using
Performance.Services.OnlineExcel
;
namespace
Performance.Api.Controllers
{
[
Route
(
"api/online/excel"
)]
[
ApiController
]
public
class
OnlineExcelController
:
Controller
{
private
readonly
AllotService
_allotService
;
private
readonly
OnlineExcelService
_excelService
;
public
OnlineExcelController
(
AllotService
allotService
,
OnlineExcelService
excelService
)
{
_allotService
=
allotService
;
_excelService
=
excelService
;
}
[
Route
(
"sheet/name"
)]
[
HttpGet
]
[
AllowAnonymous
]
public
ApiResponse
SheetName
(
int
allotId
)
{
var
allot
=
_allotService
.
GetAllot
(
allotId
);
if
(
allot
==
null
)
return
new
ApiResponse
(
ResponseType
.
Fail
,
"当前绩效信息无效"
,
"当前绩效信息无效"
);
var
sheetNames
=
_excelService
.
GetExcelSheetName
(
allot
);
if
(
sheetNames
==
null
||
sheetNames
.
Count
==
0
)
return
new
ApiResponse
(
ResponseType
.
Fail
,
"未能找到有效[SHEET]"
,
"未能找到有效[SHEET]"
);
return
new
ApiResponse
(
ResponseType
.
OK
,
sheetNames
);
}
[
Route
(
"sheet/data"
)]
[
HttpGet
]
[
AllowAnonymous
]
public
ApiResponse
SheetName
(
int
allotId
,
string
sheetName
)
{
var
allot
=
_allotService
.
GetAllot
(
allotId
);
if
(
allot
==
null
)
return
new
ApiResponse
(
ResponseType
.
Fail
,
"当前绩效信息无效"
,
"当前绩效信息无效"
);
var
s
=
_excelService
.
ReadSheet
(
allot
,
sheetName
);
return
new
ApiResponse
(
ResponseType
.
OK
,
""
,
JsonConvert
.
SerializeObject
(
s
,
new
JsonSerializerSettings
{
NullValueHandling
=
NullValueHandling
.
Ignore
}));
}
[
Route
(
"sheet/chanage/{allotId}"
)]
[
HttpPost
]
[
AllowAnonymous
]
public
ApiResponse
WriteSheet
(
int
allotId
,
[
FromBody
]
EpChanage
chanage
)
{
var
allot
=
_allotService
.
GetAllot
(
allotId
);
if
(
allot
==
null
)
return
new
ApiResponse
(
ResponseType
.
Fail
,
"当前绩效信息无效"
,
"当前绩效信息无效"
);
_excelService
.
WriteSheet
(
allot
,
chanage
);
return
new
ApiResponse
(
ResponseType
.
OK
);
}
}
}
performance/Performance.Api/wwwroot/Performance.Api.xml
View file @
241f5a3f
...
@@ -2107,6 +2107,11 @@
...
@@ -2107,6 +2107,11 @@
<param
name=
"query"
></param>
<param
name=
"query"
></param>
<returns></returns>
<returns></returns>
</member>
</member>
<member
name=
"T:Performance.Api.ClearLoggerJob"
>
<summary>
删除历史日志
</summary>
</member>
<member
name=
"M:Performance.Api.ClaimService.GetUserId"
>
<member
name=
"M:Performance.Api.ClaimService.GetUserId"
>
<summary>
<summary>
获取当前请求登录ID
获取当前请求登录ID
...
...
performance/Performance.Services/OnlineExcel/Model/EpCellClass.cs
0 → 100644
View file @
241f5a3f
using
System.Collections.Generic
;
namespace
Performance.Services.OnlineExcel
{
/// <summary>
/// 单元格Class
/// </summary>
public
class
EpCellClass
{
private
List
<
string
>
_className
;
public
int
row
{
get
;
set
;
}
public
int
col
{
get
;
set
;
}
public
string
renderer
;
public
string
className
{
get
{
if
(
_className
==
null
)
return
""
;
return
string
.
Join
(
" "
,
_className
.
ToArray
());
}
}
public
void
AddClassName
(
string
name
)
{
if
(
_className
==
null
)
_className
=
new
List
<
string
>();
_className
.
Add
(
name
);
}
}
}
\ No newline at end of file
performance/Performance.Services/OnlineExcel/Model/EpChanage.cs
0 → 100644
View file @
241f5a3f
using
System
;
using
System.Collections.Generic
;
namespace
Performance.Services.OnlineExcel
{
public
enum
Operation
{
InsertRow
=
1
,
DeleteRow
=
2
,
InsertColumn
=
3
,
DeleteColumn
=
4
,
}
/// <summary>
/// 操作情况
/// </summary>
public
class
OperationRecord
{
public
DateTime
DateTime
{
get
;
set
;
}
public
Operation
Operation
{
get
;
set
;
}
public
int
From
{
get
;
set
;
}
public
int
Count
{
get
;
set
;
}
}
/// <summary>
/// 数据变更提交记录
/// </summary>
public
class
EpChanage
{
public
string
SheetName
{
get
;
set
;
}
public
OperationRecord
[]
OperationRecord
{
get
;
set
;
}
public
List
<
dynamic
>
Data
{
get
;
set
;
}
}
}
\ No newline at end of file
performance/Performance.Services/OnlineExcel/Model/EpCustomBorders.cs
0 → 100644
View file @
241f5a3f
namespace
Performance.Services.OnlineExcel
{
/// <summary>
/// 边框(弃用 影响性能)
/// </summary>
public
class
EpCustomBorders
{
public
int
row
{
get
;
set
;
}
public
int
col
{
get
;
set
;
}
public
Style
left
{
get
;
set
;
}
public
Style
right
{
get
;
set
;
}
public
Style
top
{
get
;
set
;
}
public
Style
bottom
{
get
;
set
;
}
public
class
Style
{
public
int
width
{
get
;
set
;
}
public
string
color
{
get
;
set
;
}
}
}
}
\ No newline at end of file
performance/Performance.Services/OnlineExcel/Model/EpMerge.cs
0 → 100644
View file @
241f5a3f
namespace
Performance.Services.OnlineExcel
{
/// <summary>
/// 单元格合并
/// </summary>
public
class
EpMerge
{
public
int
row
{
get
;
set
;
}
public
int
col
{
get
;
set
;
}
public
int
rowspan
{
get
;
set
;
}
public
int
colspan
{
get
;
set
;
}
}
}
\ No newline at end of file
performance/Performance.Services/OnlineExcel/Model/EpSheet.cs
0 → 100644
View file @
241f5a3f
namespace
Performance.Services.OnlineExcel
{
/// <summary>
/// 加载Excel汇总信息
/// </summary>
public
class
EpSheet
{
public
object
mergeCells
{
get
;
set
;
}
public
object
data
{
get
;
set
;
}
public
object
cell
{
get
;
set
;
}
public
object
colWidths
{
get
;
set
;
}
}
}
\ No newline at end of file
performance/Performance.Services/OnlineExcel/OnlineExcelService.Read.cs
0 → 100644
View file @
241f5a3f
This diff is collapsed.
Click to expand it.
performance/Performance.Services/OnlineExcel/OnlineExcelService.Write.cs
0 → 100644
View file @
241f5a3f
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
OfficeOpenXml
;
using
Performance.EntityModels
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
namespace
Performance.Services.OnlineExcel
{
public
partial
class
OnlineExcelService
{
public
static
Dictionary
<
Operation
,
Action
<
ExcelWorksheet
,
int
,
int
>>
OperationMapps
=
new
Dictionary
<
Operation
,
Action
<
ExcelWorksheet
,
int
,
int
>>
{
{
Operation
.
InsertRow
,
(
sheet
,
from
,
count
)
=>
sheet
.
InsertRow
(
from
,
count
,
from
+
1
)
},
{
Operation
.
DeleteRow
,
(
sheet
,
from
,
count
)
=>
sheet
.
DeleteRow
(
from
,
count
)
},
{
Operation
.
InsertColumn
,
(
sheet
,
from
,
count
)
=>
sheet
.
InsertColumn
(
from
,
count
,
from
+
1
)
},
{
Operation
.
DeleteColumn
,
(
sheet
,
from
,
count
)
=>
sheet
.
DeleteColumn
(
from
,
count
)
},
};
private
List
<
string
>
GetColumns
()
{
var
columns
=
new
List
<
string
>
{
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
,
"K"
,
"L"
,
"M"
,
"N"
,
"O"
,
"P"
,
"Q"
,
"R"
,
"S"
,
"T"
,
"U"
,
"V"
,
"W"
,
"X"
,
"Y"
,
"Z"
};
List
<
string
>
newColumns
=
new
List
<
string
>(
columns
);
foreach
(
var
column
in
columns
)
{
foreach
(
var
item
in
columns
)
{
newColumns
.
Add
(
$"
{
column
}{
item
}
"
);
}
}
return
newColumns
;
}
public
void
WriteSheet
(
per_allot
allot
,
EpChanage
chanage
)
{
FileInfo
file
=
new
FileInfo
(
allot
.
Path
);
using
(
ExcelPackage
package
=
new
ExcelPackage
(
file
))
{
foreach
(
var
sheet
in
package
.
Workbook
.
Worksheets
)
{
if
(
sheet
.
Name
!=
chanage
.
SheetName
)
continue
;
// 新增删除 行 列 信息
if
(
chanage
.
OperationRecord
!=
null
&&
chanage
.
OperationRecord
.
Length
>
0
)
{
foreach
(
var
item
in
chanage
.
OperationRecord
.
Where
(
w
=>
w
.
Count
>
0
).
OrderBy
(
w
=>
w
.
DateTime
))
{
OperationMapps
[
item
.
Operation
].
Invoke
(
sheet
,
item
.
From
,
item
.
Count
);
}
}
// 写入数据
var
columns
=
GetColumns
();
for
(
int
row
=
0
;
row
<
chanage
.
Data
.
Count
;
row
++)
{
var
tempData
=
JsonConvert
.
DeserializeObject
<
Dictionary
<
string
,
object
>>(
JsonConvert
.
SerializeObject
(
chanage
.
Data
[
row
]));
foreach
(
var
key
in
tempData
.
Keys
)
{
var
col
=
columns
.
IndexOf
(
key
);
var
cell
=
sheet
.
Cells
[
row
+
1
,
col
+
1
];
if
(!(
cell
.
Value
is
ExcelErrorValue
)
&&
string
.
IsNullOrEmpty
(
cell
.
Formula
))
cell
.
Value
=
tempData
[
key
];
}
}
_cache
.
Remove
(
$"SheetData-
{
chanage
.
SheetName
}
:
{
allot
.
Path
}
"
);
}
package
.
Save
();
}
}
}
}
\ No newline at end of file
performance/Performance.Services/Performance.Services.csproj
View file @
241f5a3f
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
<PackageReference Include="FluentScheduler" Version="5.5.1" />
<PackageReference Include="FluentScheduler" Version="5.5.1" />
<PackageReference Include="GraphQL" Version="2.4.0" />
<PackageReference Include="GraphQL" Version="2.4.0" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.2.4" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.2.4" />
<PackageReference Include="Polly" Version="7.2.2" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
...
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