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
66d8e45a
Commit
66d8e45a
authored
May 07, 2019
by
李承祥
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
首次模板上传、医院hasconfig修改 0、无医院配置,1、含有医院配置,2、已上传模板
parent
9ee68265
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
20 deletions
+101
-20
performance/Performance.Api/Controllers/TemplateController.cs
+72
-8
performance/Performance.Services/HospitalService.cs
+8
-2
performance/Performance.Services/TemplateService.cs
+21
-10
No files found.
performance/Performance.Api/Controllers/TemplateController.cs
View file @
66d8e45a
using
System
;
using
Microsoft.AspNetCore.Hosting
;
using
System.Collections.Generic
;
using
Microsoft.AspNetCore.Http
;
using
System.Linq
;
using
Microsoft.AspNetCore.Http.Internal
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Options
;
using
Performance.DtoModels
;
using
Performance.DtoModels
;
using
Performance.DtoModels.AppSettings
;
using
Performance.EntityModels
;
using
Performance.EntityModels
;
using
Performance.Infrastructure
;
using
Performance.Infrastructure
;
using
Performance.Services
;
using
System
;
using
System.IO
;
using
System.Linq
;
namespace
Performance.Api.Controllers
namespace
Performance.Api.Controllers
{
{
[
Route
(
"api/[controller]"
)]
[
Route
(
"api/[controller]"
)]
public
class
TemplateController
:
Controller
public
class
TemplateController
:
Controller
{
{
public
TemplateController
()
private
TemplateService
templateService
;
{
}
private
HospitalService
hospitalService
;
private
IHostingEnvironment
evn
;
private
ClaimService
claim
;
public
TemplateController
(
TemplateService
templateService
,
HospitalService
hospitalService
,
IHostingEnvironment
evn
,
ClaimService
claim
)
{
this
.
templateService
=
templateService
;
this
.
hospitalService
=
hospitalService
;
this
.
evn
=
evn
;
this
.
claim
=
claim
;
}
/// <summary>
/// 上传文件
/// </summary>
/// <param name="form"></param>
/// <returns></returns>
[
Route
(
"import"
)]
[
HttpPost
]
public
ApiResponse
Import
([
FromForm
]
IFormCollection
form
)
{
var
user
=
claim
.
At
(
form
.
ToDictionary
().
GetValue
(
"token"
,
""
));
var
hospitalid
=
form
.
ToDictionary
().
GetValue
(
"hospitalid"
,
0
);
if
(
hospitalid
<=
0
)
return
new
ApiResponse
(
ResponseType
.
Fail
,
"参数错误"
,
"hospitalid无效"
);
var
file
=
((
FormFileCollection
)
form
.
Files
).
FirstOrDefault
();
if
(
file
==
null
)
return
new
ApiResponse
(
ResponseType
.
Fail
,
"参数错误"
,
"文件无效"
);
var
hospital
=
hospitalService
.
GetHopital
(
hospitalid
);
if
(
hospital
==
null
)
return
new
ApiResponse
(
ResponseType
.
Fail
,
"hospitalid不存在"
);
var
name
=
FileHelper
.
GetFileNameNoExtension
(
file
.
FileName
)
+
DateTime
.
Now
.
ToString
(
"yyyyMMddHHmmssfff"
);
var
ext
=
FileHelper
.
GetExtension
(
file
.
FileName
);
var
dpath
=
Path
.
Combine
(
evn
.
ContentRootPath
,
"FirstFiles"
,
$"
{
hospitalid
}
"
);
FileHelper
.
CreateDirectory
(
dpath
);
var
path
=
Path
.
Combine
(
dpath
,
$"
{
name
}{
ext
}
"
);
using
(
var
stream
=
file
.
OpenReadStream
())
{
byte
[]
bytes
=
new
byte
[
stream
.
Length
];
stream
.
Read
(
bytes
,
0
,
bytes
.
Length
);
if
(!
FileHelper
.
CreateFile
(
path
,
bytes
))
return
new
ApiResponse
(
ResponseType
.
Fail
,
$"
{
file
.
FileName
}
上传失败"
);
var
template
=
new
per_first
{
HospitalId
=
hospitalid
,
CreateUser
=
user
.
UserID
,
CreateDate
=
DateTime
.
Now
,
Path
=
path
,
UploadDate
=
DateTime
.
Now
,
Remark
=
"上传成功"
};
if
(
templateService
.
InsertFirst
(
template
))
templateService
.
SendEmail
(
path
,
$"
{
hospital
.
HosName
}
首次上传模板"
,
"上传成功"
);
}
return
new
ApiResponse
(
ResponseType
.
OK
);
}
}
}
}
}
\ No newline at end of file
performance/Performance.Services/HospitalService.cs
View file @
66d8e45a
...
@@ -14,13 +14,16 @@ public class HospitalService : IAutoInjection
...
@@ -14,13 +14,16 @@ public class HospitalService : IAutoInjection
private
PerforHospitalRepository
_hospitalRepository
;
private
PerforHospitalRepository
_hospitalRepository
;
private
PerforUserhospitalRepository
_joinRepository
;
private
PerforUserhospitalRepository
_joinRepository
;
private
PerforHospitalconfigRepository
_hospitalconfigRepository
;
private
PerforHospitalconfigRepository
_hospitalconfigRepository
;
private
PerforPerfirstRepository
_perfirstRepository
;
public
HospitalService
(
PerforHospitalRepository
hospitalRepository
,
public
HospitalService
(
PerforHospitalRepository
hospitalRepository
,
PerforUserhospitalRepository
joinRepository
,
PerforUserhospitalRepository
joinRepository
,
PerforHospitalconfigRepository
hospitalconfigRepository
)
PerforHospitalconfigRepository
hospitalconfigRepository
,
PerforPerfirstRepository
perfirstRepository
)
{
{
this
.
_hospitalRepository
=
hospitalRepository
;
this
.
_hospitalRepository
=
hospitalRepository
;
this
.
_joinRepository
=
joinRepository
;
this
.
_joinRepository
=
joinRepository
;
this
.
_hospitalconfigRepository
=
hospitalconfigRepository
;
this
.
_hospitalconfigRepository
=
hospitalconfigRepository
;
this
.
_perfirstRepository
=
perfirstRepository
;
}
}
/// <summary>
/// <summary>
...
@@ -39,12 +42,15 @@ public List<HospitalResponse> GetUserHopital(int userid)
...
@@ -39,12 +42,15 @@ public List<HospitalResponse> GetUserHopital(int userid)
var
hosList
=
_hospitalRepository
.
GetEntities
(
t
=>
joinList
.
Select
(
j
=>
j
.
HospitalID
).
Contains
(
t
.
ID
));
var
hosList
=
_hospitalRepository
.
GetEntities
(
t
=>
joinList
.
Select
(
j
=>
j
.
HospitalID
).
Contains
(
t
.
ID
));
var
hosId
=
hosList
?.
Select
(
item
=>
item
.
ID
).
ToList
();
var
hosId
=
hosList
?.
Select
(
item
=>
item
.
ID
).
ToList
();
//获取存在数据记录的hospital
hosId
=
_hospitalconfigRepository
.
GetEntities
(
t
=>
hosId
.
Contains
(
t
.
HospitalId
.
Value
))?.
Select
(
t
=>
t
.
HospitalId
.
Value
).
ToList
();
hosId
=
_hospitalconfigRepository
.
GetEntities
(
t
=>
hosId
.
Contains
(
t
.
HospitalId
.
Value
))?.
Select
(
t
=>
t
.
HospitalId
.
Value
).
ToList
();
//获取已经上传过模板的hospital
var
firstId
=
_perfirstRepository
.
GetEntities
(
t
=>
hosId
.
Contains
(
t
.
HospitalId
.
Value
))?.
Select
(
t
=>
t
.
HospitalId
.
Value
).
ToList
();
var
list
=
Mapper
.
Map
<
List
<
sys_hospital
>,
List
<
HospitalResponse
>>(
hosList
);
var
list
=
Mapper
.
Map
<
List
<
sys_hospital
>,
List
<
HospitalResponse
>>(
hosList
);
list
.
ForEach
(
t
=>
list
.
ForEach
(
t
=>
{
{
if
(
hosId
!=
null
&&
hosId
.
Contains
(
t
.
HosID
))
if
(
hosId
!=
null
&&
hosId
.
Contains
(
t
.
HosID
))
t
.
HasConfig
=
1
;
t
.
HasConfig
=
firstId
.
Contains
(
t
.
HosID
)
?
2
:
1
;
});
});
return
list
;
return
list
;
}
}
...
...
performance/Performance.Services/TemplateService.cs
View file @
66d8e45a
using
Microsoft.Extensions.Options
;
using
Microsoft.Extensions.Options
;
using
Performance.DtoModels.AppSettings
;
using
Performance.DtoModels.AppSettings
;
using
Performance.EntityModels
;
using
Performance.Repository
;
using
Performance.Infrastructure
;
using
Performance.Infrastructure
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
...
@@ -12,36 +14,45 @@ public class TemplateService : IAutoInjection
...
@@ -12,36 +14,45 @@ public class TemplateService : IAutoInjection
{
{
private
Application
application
;
private
Application
application
;
private
IEmailService
emailService
;
private
IEmailService
emailService
;
public
TemplateService
(
IOptions
<
Application
>
options
,
IEmailService
emailService
)
private
PerforPerfirstRepository
PerforPerfirstRepository
;
public
TemplateService
(
IOptions
<
Application
>
options
,
IEmailService
emailService
,
PerforPerfirstRepository
PerforPerfirstRepository
)
{
{
this
.
application
=
options
.
Value
;
this
.
application
=
options
.
Value
;
this
.
emailService
=
emailService
;
this
.
emailService
=
emailService
;
this
.
PerforPerfirstRepository
=
PerforPerfirstRepository
;
}
}
/// <summary>
public
bool
FirstSubmit
()
/// 添加数据 per_first
/// </summary>
/// <param name="first"></param>
/// <returns></returns>
public
bool
InsertFirst
(
per_first
first
)
{
{
return
PerforPerfirstRepository
.
Add
(
first
);
return
true
;
}
}
#
region
发送邮件
/// <summary>
/// <summary>
/// 发送邮件
/// 发送邮件
/// </summary>
/// </summary>
/// <param name="allot"></param>
/// <param name="path"></param>
/// <param name="mail"></param>
/// <param name="subject"></param>
/// <param name="subject"></param>
/// <param name="body"></param>
/// <param name="body"></param>
p
rivate
void
SendEmail
(
string
mail
,
string
subject
,
string
body
)
p
ublic
void
SendEmail
(
string
path
,
string
subject
,
string
body
)
{
{
var
message
=
new
EmailMessage
var
message
=
new
EmailMessage
{
{
To
=
application
.
Receiver
.
ToList
(),
To
=
application
.
Receiver
.
ToList
(),
Attachments
=
new
List
<
string
>
{
path
},
DisplayName
=
"溯直健康"
,
DisplayName
=
"溯直健康"
,
Subject
=
subject
,
Subject
=
subject
,
Body
=
body
Body
=
body
};
};
emailService
.
Send
Async
(
message
);
emailService
.
Send
(
message
);
}
}
#
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