Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Education
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
Education
Commits
af229737
Commit
af229737
authored
Jan 08, 2021
by
liudong1993
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
周期自动生成
parent
a20d9c92
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
238 additions
and
1 deletion
+238
-1
Edu.EducationCore.csproj
Edu.EducationCore/Edu.EducationCore.csproj
+2
-1
EducationTimerServer.cs
Edu.EducationCore/EducationTimerServer.cs
+1
-0
QuarzHelper.cs
Edu.EducationCore/Helper/QuarzHelper.cs
+90
-0
RB_OKR_Period.cs
Edu.Model/Entity/OKR/RB_OKR_Period.cs
+5
-0
OKRPeriodModule.cs
Edu.Module.OKR/OKRPeriodModule.cs
+116
-0
RB_OKR_PeriodRepository.cs
Edu.Repository/OKR/RB_OKR_PeriodRepository.cs
+24
-0
No files found.
Edu.EducationCore/Edu.EducationCore.csproj
View file @
af229737
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
...
...
@@ -44,6 +44,7 @@
<ItemGroup>
<ProjectReference Include="..\Edu.Module.Course\Edu.Module.Course.csproj" />
<ProjectReference Include="..\Edu.Module.OKR\Edu.Module.OKR.csproj" />
</ItemGroup>
<ItemGroup>
...
...
Edu.EducationCore/EducationTimerServer.cs
View file @
af229737
...
...
@@ -25,6 +25,7 @@ namespace Edu.Education
protected
override
void
OnStart
(
string
[]
args
)
{
new
QuarzHelper
().
TeachingPerfTimer
().
GetAwaiter
().
GetResult
();
new
QuarzHelper
().
OKRPeriodTimer
().
GetAwaiter
().
GetResult
();
}
/// <summary>
...
...
Edu.EducationCore/Helper/QuarzHelper.cs
View file @
af229737
...
...
@@ -7,6 +7,8 @@ using Quartz.Impl;
using
System.Collections.Specialized
;
using
System.Threading.Tasks
;
using
Edu.Module.Course
;
using
Edu.Module.OKR
;
using
System.Linq
;
namespace
Edu.Education.Helper
{
...
...
@@ -49,6 +51,38 @@ namespace Edu.Education.Helper
await
scheduler
.
ScheduleJob
(
job
,
trigger
);
}
/// <summary>
/// 定时执行OKR周期生成
/// </summary>
/// <returns></returns>
public
async
Task
OKRPeriodTimer
()
{
//string cronExpression = "0 0 */1 * * ?"; //每天凌晨1点
NameValueCollection
props
=
new
NameValueCollection
{
{
"quartz.serializer.type"
,
"binary"
}
};
StdSchedulerFactory
factory
=
new
StdSchedulerFactory
(
props
);
IScheduler
scheduler
=
await
factory
.
GetScheduler
();
await
scheduler
.
Start
();
IJobDetail
job
=
JobBuilder
.
Create
<
CreateOKRPeriod
>()
.
WithIdentity
(
"job2"
,
"group2"
)
.
Build
();
ITrigger
trigger
=
TriggerBuilder
.
Create
()
.
WithIdentity
(
"trigger2"
,
"group2"
)
.
StartNow
()
.
WithSimpleSchedule
(
x
=>
x
.
WithIntervalInHours
(
2
)
.
RepeatForever
())
.
Build
();
//ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
// .WithIdentity("trigger1", "group1")
// .WithCronSchedule(cronExpression)
// .Build();
await
scheduler
.
ScheduleJob
(
job
,
trigger
);
}
}
/// <summary>
...
...
@@ -96,4 +130,60 @@ namespace Edu.Education.Helper
return
null
;
}
}
/// <summary>
/// 周期生成
/// </summary>
public
class
CreateOKRPeriod
:
IJob
{
/// <summary>
/// 这里是作业调度每次定时执行方法
/// </summary>
/// <param name="context"></param>
public
Task
Execute
(
IJobExecutionContext
context
)
{
try
{
LogHelper
.
Write
(
"创建周期...."
);
OKRPeriodModule
oKRPeriodModule
=
new
OKRPeriodModule
();
var
clist
=
oKRPeriodModule
.
GetOKRPeriodConfigList
();
foreach
(
var
dmodel
in
clist
)
{
//查询改配置下当前周期
var
list
=
oKRPeriodModule
.
GetCurrentPeriodList
(
dmodel
.
Group_Id
);
if
(
list
.
Any
())
{
var
model
=
list
.
FirstOrDefault
();
//看是否已到可生成下周期时间
if
(
dmodel
.
BeforeType
==
1
)
{
//天
var
ds
=
model
.
EndDate
-
DateTime
.
Now
;
if
(
ds
.
TotalDays
<
dmodel
.
BeforeNum
)
{
dmodel
.
EndDate
=
model
.
EndDate
;
//生成下一个周期
oKRPeriodModule
.
CreatePeriodNext
(
dmodel
);
}
}
else
{
//月
var
ds
=
DateTime
.
Now
.
AddMonths
(
dmodel
.
BeforeNum
);
if
(
ds
>
model
.
EndDate
)
{
dmodel
.
EndDate
=
model
.
EndDate
;
//生成下一个周期
oKRPeriodModule
.
CreatePeriodNext
(
dmodel
);
}
}
}
}
}
catch
(
Exception
ex
)
{
LogHelper
.
Write
(
ex
,
"CreateOKRPeriod"
);
}
return
null
;
}
}
}
Edu.Model/Entity/OKR/RB_OKR_Period.cs
View file @
af229737
...
...
@@ -36,6 +36,11 @@ namespace Edu.Model.Entity.OKR
/// </summary>
public
int
IsYear
{
get
;
set
;
}
/// <summary>
/// 是否正常配置的周期 1是 2否
/// </summary>
public
int
IsNormal
{
get
;
set
;
}
/// <summary>
/// 删除状态
/// </summary>
...
...
Edu.Module.OKR/OKRPeriodModule.cs
View file @
af229737
...
...
@@ -98,6 +98,15 @@ namespace Edu.Module.OKR
return
oKR_PeriodConfigRepository
.
GetList
(
new
RB_OKR_PeriodConfig_ViewModel
()
{
Group_Id
=
group_Id
}).
FirstOrDefault
()
??
new
RB_OKR_PeriodConfig_ViewModel
();
}
/// <summary>
/// 获取周期配置列表
/// </summary>
/// <returns></returns>
public
List
<
RB_OKR_PeriodConfig_ViewModel
>
GetOKRPeriodConfigList
()
{
return
oKR_PeriodConfigRepository
.
GetList
(
new
RB_OKR_PeriodConfig_ViewModel
()
{
});
}
/// <summary>
/// 保存OKR周期配置
/// </summary>
...
...
@@ -108,6 +117,7 @@ namespace Edu.Module.OKR
{
if
(
dmodel
.
Id
>
0
)
{
var
model
=
oKR_PeriodConfigRepository
.
GetEntity
(
dmodel
.
Id
);
Dictionary
<
string
,
object
>
keyValues
=
new
Dictionary
<
string
,
object
>()
{
{
nameof
(
RB_OKR_PeriodConfig_ViewModel
.
PeriodMonth
),
dmodel
.
PeriodMonth
},
{
nameof
(
RB_OKR_PeriodConfig_ViewModel
.
StartDate
),
dmodel
.
StartDate
},
...
...
@@ -133,6 +143,49 @@ namespace Edu.Module.OKR
};
bool
flag
=
oKR_PeriodConfigRepository
.
Update
(
keyValues
,
wheres
);
if
(
flag
)
{
#
region
是否需要重新生成周期
if
(
model
.
PeriodMonth
!=
dmodel
.
PeriodMonth
||
model
.
StartDate
!=
dmodel
.
StartDate
||
model
.
EndDate
!=
dmodel
.
EndDate
)
{
//更新所有历史周期
oKR_PeriodRepository
.
SetPeriodHistory
(
userInfo
.
Group_Id
);
//生成对应期数
oKR_PeriodRepository
.
Insert
(
new
Model
.
Entity
.
OKR
.
RB_OKR_Period
()
{
Id
=
0
,
IsYear
=
2
,
Status
=
0
,
Name
=
dmodel
.
StartDate
.
Value
.
ToString
(
"yyyy年MM月"
)
+
"-"
+
dmodel
.
EndDate
.
Value
.
ToString
(
"yyyy年MM月"
),
StartDate
=
dmodel
.
StartDate
.
Value
,
EndDate
=
dmodel
.
EndDate
.
Value
,
Group_Id
=
dmodel
.
Group_Id
,
School_Id
=
dmodel
.
School_Id
,
CreateBy
=
dmodel
.
CreateBy
,
CreateTime
=
DateTime
.
Now
,
UpdateBy
=
dmodel
.
UpdateBy
,
UpdateTime
=
DateTime
.
Now
});
}
//看最新的天数 是否满足生成下一周期
if
(
dmodel
.
BeforeType
==
1
)
{
//天
var
ds
=
dmodel
.
EndDate
.
Value
-
DateTime
.
Now
;
if
(
ds
.
TotalDays
<
dmodel
.
BeforeNum
)
{
//生成下一个周期
CreatePeriodNext
(
dmodel
);
}
}
else
{
//月
var
ds
=
DateTime
.
Now
.
AddMonths
(
dmodel
.
BeforeNum
);
if
(
ds
>
dmodel
.
EndDate
)
{
//生成下一个周期
CreatePeriodNext
(
dmodel
);
}
}
#
endregion
//记录日志
changeLogRepository
.
Insert
(
new
Model
.
Entity
.
Log
.
RB_User_ChangeLog
()
{
...
...
@@ -206,6 +259,29 @@ namespace Edu.Module.OKR
UpdateTime
=
DateTime
.
Now
});
}
//看最新的天数 是否满足生成下一周期
if
(
dmodel
.
BeforeType
==
1
)
{
//天
var
ds
=
dmodel
.
EndDate
.
Value
-
DateTime
.
Now
;
if
(
ds
.
TotalDays
<
dmodel
.
BeforeNum
)
{
//生成下一个周期
CreatePeriodNext
(
dmodel
);
}
}
else
{
//月
var
ds
=
DateTime
.
Now
.
AddMonths
(
dmodel
.
BeforeNum
);
if
(
ds
>
dmodel
.
EndDate
)
{
//生成下一个周期
CreatePeriodNext
(
dmodel
);
}
}
//记录日志
changeLogRepository
.
Insert
(
new
Model
.
Entity
.
Log
.
RB_User_ChangeLog
()
{
...
...
@@ -223,6 +299,36 @@ namespace Edu.Module.OKR
}
}
/// <summary>
/// 创建下一个周期
/// </summary>
/// <param name="dmodel"></param>
public
void
CreatePeriodNext
(
RB_OKR_PeriodConfig_ViewModel
dmodel
)
{
DateTime
STime
=
Convert
.
ToDateTime
(
dmodel
.
EndDate
.
Value
.
AddDays
(
1
).
ToString
(
"yyyy-MM-dd"
));
DateTime
ETime
=
Convert
.
ToDateTime
(
STime
.
AddMonths
((
int
)
dmodel
.
PeriodMonth
).
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd"
)
+
" 23:59:59"
);
//验证一下 当前时间周期是否存在
string
Name
=
STime
.
ToString
(
"yyyy年MM月"
)
+
"-"
+
ETime
.
ToString
(
"yyyy年MM月"
);
if
(!
oKR_PeriodRepository
.
GetList
(
new
RB_OKR_Period_ViewModel
()
{
Group_Id
=
dmodel
.
Group_Id
,
IsNormal
=
1
,
Name
=
Name
}).
Any
())
{
oKR_PeriodRepository
.
Insert
(
new
Model
.
Entity
.
OKR
.
RB_OKR_Period
()
{
Id
=
0
,
IsYear
=
2
,
Status
=
0
,
Name
=
Name
,
StartDate
=
STime
,
EndDate
=
ETime
,
Group_Id
=
dmodel
.
Group_Id
,
School_Id
=
dmodel
.
School_Id
,
CreateBy
=
dmodel
.
CreateBy
,
CreateTime
=
DateTime
.
Now
,
UpdateBy
=
dmodel
.
UpdateBy
,
UpdateTime
=
DateTime
.
Now
});
}
}
/// <summary>
/// 获取提醒设置列表
/// </summary>
...
...
@@ -552,6 +658,16 @@ namespace Edu.Module.OKR
return
list
;
}
/// <summary>
/// 获取当前周期
/// </summary>
/// <param name="GroupId"></param>
/// <returns></returns>
public
List
<
RB_OKR_Period_ViewModel
>
GetCurrentPeriodList
(
int
GroupId
)
{
return
oKR_PeriodRepository
.
GetList
(
new
RB_OKR_Period_ViewModel
()
{
Group_Id
=
GroupId
,
IsCurrent
=
1
,
IsNormal
=
1
});
}
/// <summary>
/// 获取我的目标列表
/// </summary>
...
...
Edu.Repository/OKR/RB_OKR_PeriodRepository.cs
View file @
af229737
using
Edu.Common.Enum
;
using
Edu.Model.Entity.OKR
;
using
Edu.Model.ViewModel.OKR
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
...
...
@@ -54,9 +55,32 @@ namespace Edu.Repository.OKR
{
where
+=
$@" and
{
nameof
(
RB_OKR_Period_ViewModel
.
IsYear
)}
=
{
demodel
.
IsYear
}
"
;
}
if
(
demodel
.
IsNormal
>
0
)
{
where
+=
$@" and
{
nameof
(
RB_OKR_Period_ViewModel
.
IsNormal
)}
=
{
demodel
.
IsNormal
}
"
;
}
if
(
demodel
.
IsCurrent
==
1
)
{
where
+=
$@" and
{
nameof
(
RB_OKR_Period_ViewModel
.
StartDate
)}
<='
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd"
)}
'"
;
where
+=
$@" and
{
nameof
(
RB_OKR_Period_ViewModel
.
EndDate
)}
>='
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd"
)}
'"
;
}
if
(!
string
.
IsNullOrEmpty
(
demodel
.
Name
))
{
where
+=
$@" and
{
nameof
(
RB_OKR_Period_ViewModel
.
Name
)}
='
{
demodel
.
Name
}
'"
;
}
string
sql
=
$@" select * from RB_OKR_Period where
{
where
}
order by StartDate desc,IsYear asc"
;
return
Get
<
RB_OKR_Period_ViewModel
>(
sql
).
ToList
();
}
/// <summary>
/// 更新周期全部未历史周期
/// </summary>
/// <param name="GroupId"></param>
/// <returns></returns>
public
bool
SetPeriodHistory
(
int
GroupId
)
{
string
sql
=
$" UPDATE rb_okr_period SET IsNormal =2 WHERE Group_Id=
{
GroupId
}
AND IsNormal =1 AND IsYear =2"
;
return
Execute
(
sql
)>
0
;
}
}
}
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