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
2a50eb79
Commit
2a50eb79
authored
May 09, 2019
by
李承祥
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
写入excel时,校验数据类型;excel列头问题修改
parent
cc249204
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
4 deletions
+42
-4
performance/Performance.Api/Controllers/TemplateController.cs
+5
-2
performance/Performance.Services/ExtractService.cs
+37
-2
No files found.
performance/Performance.Api/Controllers/TemplateController.cs
View file @
2a50eb79
using
FluentValidation.AspNetCore
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Http.Internal
;
...
...
@@ -78,7 +79,9 @@ public ApiResponse Import([FromForm] IFormCollection form)
Remark
=
"上传成功"
};
if
(
templateService
.
InsertFirst
(
template
))
{
templateService
.
SendEmail
(
path
,
$"
{
hospital
.
HosName
}
首次上传模板"
,
"上传成功"
);
}
}
return
new
ApiResponse
(
ResponseType
.
OK
);
}
...
...
@@ -90,9 +93,9 @@ public ApiResponse Import([FromForm] IFormCollection form)
/// <returns></returns>
[
Route
(
"extractdata"
)]
[
HttpPost
]
public
ApiResponse
ExtractData
([
FromBody
]
Api
Request
request
)
public
ApiResponse
ExtractData
([
CustomizeValidator
(
RuleSet
=
"Delete"
),
FromBody
]
Hospital
Request
request
)
{
var
filePath
=
extractService
.
ExtractData
(
24
);
var
filePath
=
extractService
.
ExtractData
(
request
.
ID
);
return
new
ApiResponse
(
ResponseType
.
OK
,
"OK"
,
filePath
);
}
}
...
...
performance/Performance.Services/ExtractService.cs
View file @
2a50eb79
...
...
@@ -14,6 +14,7 @@
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Text.RegularExpressions
;
namespace
Performance.Services
{
...
...
@@ -135,6 +136,16 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee
// }
//}
var
maxHeaderRowNumber
=
sheet
.
PerHeader
.
Max
(
t
=>
t
.
PointRow
);
sheet
.
PerHeader
.
ForEach
(
t
=>
{
if
(
t
.
IsHasChildren
)
{
var
maxnum
=
t
.
Children
.
Max
(
c
=>
c
.
PointRow
);
maxHeaderRowNumber
=
maxHeaderRowNumber
>
maxnum
?
maxHeaderRowNumber
:
maxnum
;
}
});
if
(
sheet
.
SheetType
==
SheetType
.
Workload
)
maxHeaderRowNumber
+=
1
;
//清空数据行
for
(
int
i
=
maxHeaderRowNumber
+
1
;
i
<
importSheet
.
LastRowNum
+
1
;
i
++)
{
...
...
@@ -174,7 +185,7 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee
if
(
headInfo
!=
null
)
{
var
value
=
(
keyValues
[
item
].
Invoke
(
dataList
[
i
])
??
""
).
ToString
();
importRow
.
CreateCell
(
headInfo
.
PointCell
).
SetCellValue
(
value
);
importRow
.
CreateCell
(
headInfo
.
PointCell
).
SetCellValue
(
Verify
(
value
)
);
}
}
}
...
...
@@ -196,7 +207,7 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee
var
headInfo
=
sheet
.
PerHeader
.
FirstOrDefault
(
t
=>
t
.
CellValue
==
data
.
ColumnName
);
if
(
headInfo
!=
null
)
{
importRow
.
CreateCell
(
headInfo
.
PointCell
).
SetCellValue
(
data
.
Value
.
ToString
(
));
importRow
.
CreateCell
(
headInfo
.
PointCell
).
SetCellValue
(
Verify
(
data
.
Value
.
ToString
()
));
}
}
}
...
...
@@ -283,5 +294,29 @@ private List<PerSheet> GetFileData(string path)
}
return
sheetList
;
}
/// <summary>
/// 校验数据格式,并转换
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public
dynamic
Verify
(
string
obj
)
{
try
{
//判断值是否为double类型
if
(!
string
.
IsNullOrEmpty
(
obj
)
&&
Regex
.
Match
(
obj
.
Trim
(),
@"([1-9]\d*\.?\d*)|(0\.\d*[1-9])|0"
).
ToString
()
==
obj
.
Trim
())
return
ConvertHelper
.
To
<
double
>(
obj
);
//判断值是否为日期格式
else
if
(!
string
.
IsNullOrEmpty
(
obj
)
&&
Regex
.
Match
(
obj
.
Trim
(),
@"(19|20)\d{2}(-|/)[01]?\d(-|/)[0123]?\d( [012]?\d\:\d{2}\:\d{2})?"
).
ToString
()
==
obj
.
Trim
())
return
ConvertHelper
.
To
<
DateTime
>(
obj
).
ToString
(
"yyyy/MM/dd"
);
else
return
obj
;
}
catch
{
return
obj
;
}
}
}
}
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