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
d84c2e13
Commit
d84c2e13
authored
Feb 24, 2023
by
ryun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
同步添加开关
parent
235e63bc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
45 deletions
+25
-45
performance/Performance.Api/Job/AutoSyncConfigJob.cs
+25
-45
No files found.
performance/Performance.Api/Job/AutoSyncConfigJob.cs
View file @
d84c2e13
using
FluentScheduler
;
using
FluentScheduler
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
using
Performance.DtoModels
;
using
Performance.DtoModels
;
using
Performance.Infrastructure
;
using
Performance.Infrastructure
;
...
@@ -12,16 +13,18 @@ namespace Performance.Api
...
@@ -12,16 +13,18 @@ namespace Performance.Api
public
class
AutoSyncConfigJob
:
IJob
public
class
AutoSyncConfigJob
:
IJob
{
{
private
readonly
ILogger
logger
;
private
readonly
ILogger
logger
;
private
readonly
IConfiguration
_configuration
;
private
readonly
PerforPerallotRepository
perallotRepository
;
private
readonly
PerforPerallotRepository
perallotRepository
;
private
readonly
ConfigService
configService
;
private
readonly
ConfigService
configService
;
public
AutoSyncConfigJob
(
public
AutoSyncConfigJob
(
ILogger
<
AutoSyncConfigJob
>
logger
,
ILogger
<
AutoSyncConfigJob
>
logger
,
IConfiguration
configuration
,
PerforPerallotRepository
perallotRepository
,
PerforPerallotRepository
perallotRepository
,
ConfigService
configService
ConfigService
configService
)
)
{
{
this
.
logger
=
logger
;
this
.
logger
=
logger
;
_configuration
=
configuration
;
this
.
perallotRepository
=
perallotRepository
;
this
.
perallotRepository
=
perallotRepository
;
this
.
configService
=
configService
;
this
.
configService
=
configService
;
}
}
...
@@ -30,54 +33,31 @@ public void Execute()
...
@@ -30,54 +33,31 @@ public void Execute()
{
{
try
try
{
{
logger
.
LogInformation
(
"开始同步配置"
);
var
@switch
=
_configuration
.
GetValue
(
"Application:OpenAutoSyncConfig"
,
false
);
//先查询perallot所有数据
logger
.
LogInformation
(
$"同步配置开关:
{
@switch
}
"
);
var
list
=
perallotRepository
.
GetEntities
();
if
(
@switch
)
if
(
list
==
null
||
!
list
.
Any
())
return
;
var
hospitalIds
=
list
.
Select
(
t
=>
t
.
HospitalId
).
Distinct
().
OrderBy
(
t
=>
t
);
//按照医院循环
foreach
(
var
hospitalId
in
hospitalIds
)
{
{
//按年月进行倒序查询allots
logger
.
LogInformation
(
"开始同步配置"
);
var
allots
=
list
.
Where
(
w
=>
w
.
HospitalId
==
hospitalId
&&
string
.
IsNullOrEmpty
(
w
.
Path
)
&&
w
.
IsModifyConfig
!=
1
)?.
OrderByDescending
(
t
=>
t
.
Year
).
ThenByDescending
(
t
=>
t
.
Month
).
ToList
();
if
(
allots
==
null
||
!
allots
.
Any
())
continue
;
foreach
(
var
item
in
allots
)
{
configService
.
NewCopy
(
new
CopyRequest
()
{
AllotId
=
item
.
ID
,
Type
=
new
[]
{
"personnels"
,
"workItems"
,
"drugTypeDisburses"
,
"drugTypeFactors"
,
"deptTypes"
,
"agains"
,
"accountings"
,
"department"
}
});
}
#
region
旧代码
////如果allots不为null 并且 数据存在没修改过的,进行循环
//先查询perallot所有数据
//while (allots != null && allots.Any(w => w.IsModifyConfig == 0) && allots.Any(w => w.IsModifyConfig == 1))
var
list
=
perallotRepository
.
GetEntities
();
//{
if
(
list
==
null
||
!
list
.
Any
())
return
;
// //查询最近一次修改过的allot
// var prevAllot = allots.FirstOrDefault(t => t.IsModifyConfig == 1);
// //if (prevAllot == null) continue;
// //获取最近一次修改过的月份
var
hospitalIds
=
list
.
Select
(
t
=>
t
.
HospitalId
).
Distinct
().
OrderBy
(
t
=>
t
);
// var date = ConvertHelper.To<DateTime>($"{prevAllot.Year}-{prevAllot.Month}");
//按照医院循环
// //查找需要同步的allot(条件为 最近一次修改过的月份之后的所有allot)
foreach
(
var
hospitalId
in
hospitalIds
)
// var needSyncData = allots.Where(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") > date);
{
// if (needSyncData != null && needSyncData.Any())
//按年月进行倒序查询allots
// {
var
allots
=
list
.
Where
(
w
=>
w
.
HospitalId
==
hospitalId
&&
string
.
IsNullOrEmpty
(
w
.
Path
)
&&
w
.
IsModifyConfig
!=
1
)?.
OrderByDescending
(
t
=>
t
.
Year
).
ThenByDescending
(
t
=>
t
.
Month
).
ToList
();
// //开始同步查询到的allot
if
(
allots
==
null
||
!
allots
.
Any
())
continue
;
// foreach (var item in needSyncData)
// configService.NewCopy(new CopyRequest() { AllotId = item.ID, Type = new[] { "personnels", "workItems", "drugTypeDisburses", "drugTypeFactors", "deptTypes", "agains", "accountings", "department" } });
// }
// //同步完之后查询 最近一次修改过的allot 之前的第一条未修改的allot
// var noModify = allots.FirstOrDefault(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") < date && w.IsModifyConfig == 0);
// if (noModify != null)
// //最近一次修改过的月份 更改为 前的第一条数据的月份
// date = ConvertHelper.To<DateTime>($"{noModify.Year}-{noModify.Month}");
// //当次循环allots只保留 小于 最近一次修改过的月份
foreach
(
var
item
in
allots
)
// allots = allots.Where(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") <= date)?.ToList();
{
//}
configService
.
NewCopy
(
new
CopyRequest
()
{
AllotId
=
item
.
ID
,
Type
=
new
[]
{
"personnels"
,
"workItems"
,
"drugTypeDisburses"
,
"drugTypeFactors"
,
"deptTypes"
,
"agains"
,
"accountings"
,
"department"
}
});
#
endregion
}
}
logger
.
LogInformation
(
"同步配置结束"
);
}
}
logger
.
LogInformation
(
"同步配置结束"
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
...
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