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
d7b4461b
Commit
d7b4461b
authored
Jun 02, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
111
parent
79a8e1b4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
8 deletions
+140
-8
Startup.cs
Edu.WebApi/Startup.cs
+4
-1
TimedTaskServices.cs
Edu.WebApi/Timers/TimedTaskServices.cs
+129
-0
TimerJobj.cs
Edu.WebApi/Timers/TimerJobj.cs
+7
-7
No files found.
Edu.WebApi/Startup.cs
View file @
d7b4461b
...
...
@@ -5,6 +5,7 @@ using System.Text.Unicode;
using
System.Threading.Tasks
;
using
Edu.Common.SignalR
;
using
Edu.ThirdCore.Message
;
using
Edu.WebApi.Timers
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Http
;
...
...
@@ -85,7 +86,9 @@ namespace Edu.WebApi
services
.
AddSenparcGlobalServices
(
Configuration
)
//Senparc.CO2NET 全局注册
.
AddSenparcWeixinServices
(
Configuration
);
//配置后台任务
//services.AddTransient(typeof(Microsoft.Extensions.Hosting.IHostedService), typeof(EmailBackgroundService));
services
.
AddHostedService
<
TimedTaskServices
>();
}
...
...
Edu.WebApi/Timers/TimedTaskServices.cs
0 → 100644
View file @
d7b4461b
using
Edu.Cache.User
;
using
Edu.Model.CacheModel
;
using
Edu.Module.Customer
;
using
Edu.Module.User
;
using
Microsoft.Extensions.Hosting
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
Edu.WebApi.Timers
{
/// <summary>
/// 定时任务
/// </summary>
public
class
TimedTaskServices
:
IHostedService
,
IDisposable
{
//定义一个定时器
private
Timer
_timer
;
/// <summary>
/// 课程顾问部和市场部数据统计
/// </summary>
private
static
readonly
MarketConsultantModule
marketConsultantModule
=
new
MarketConsultantModule
();
/// <summary>
/// 教师行为数据统计
/// </summary>
private
static
readonly
TeacherStaticModule
teacherStaticModule
=
new
TeacherStaticModule
();
/// <summary>
/// 学员数据统计处理类
/// </summary>
private
static
readonly
StudentStatModule
studentStatModule
=
new
StudentStatModule
();
private
static
int
marketconsultant_Timer
=
0
;
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
"定时任务被启动"
);
int
Interval
=
0
;
//Interval = 20;
Interval
=
1
;
//绑定定时任务
//设置延迟时间
_timer
=
new
Timer
(
DoWork
,
null
,
TimeSpan
.
Zero
,
TimeSpan
.
FromSeconds
(
60
*
Interval
));
return
Task
.
CompletedTask
;
}
public
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
"定时任务被关闭"
);
_timer
?.
Change
(
Timeout
.
Infinite
,
0
);
return
Task
.
CompletedTask
;
}
/// <summary>
/// 定时生成市场部和课程顾问部数据统计
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
private
void
DoWork
(
object
state
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
"定时任务被触发"
);
try
{
if
(
Interlocked
.
Exchange
(
ref
marketconsultant_Timer
,
1
)
==
0
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
"DealMarketConsultantData========Start"
);
var
today
=
DateTime
.
Now
;
var
currentDate
=
Common
.
ConvertHelper
.
FormatDate
(
today
);
var
startDate
=
Common
.
ConvertHelper
.
FormatDate
(
today
.
AddDays
(-
1
));
if
(!
marketConsultantModule
.
CheckConsultantDataModule
(
startDate
))
{
marketConsultantModule
.
CreateConsultantDataModule
(
today
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CreateConsultantDataModule:"
+
startDate
);
}
if
(!
marketConsultantModule
.
CheckMarketDataModule
(
startDate
))
{
marketConsultantModule
.
CreateMarketDataModule
(
today
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CreateMarketDataModule:"
+
startDate
);
}
//缓存信息
UserInfo
user
=
UserReidsCache
.
GetUserLoginInfo
(
"1"
);
if
(!
studentStatModule
.
CheckStudentStaticModule
(
startDate
))
{
studentStatModule
.
CreateStudentStaticModule
(
user
,
startDate
,
currentDate
,
isInit
:
false
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CreateStudentStaticModule:"
+
startDate
);
}
if
(!
studentStatModule
.
CheckStudentMarketModule
(
startDate
))
{
studentStatModule
.
CreateStudentMarketModule
(
user
,
startDate
,
currentDate
,
isInit
:
false
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CreateStudentMarketModule:"
+
startDate
);
}
if
(!
studentStatModule
.
CheckStudentCompanyModule
(
startDate
))
{
studentStatModule
.
CreateStudentCompanyModule
(
user
,
startDate
,
currentDate
,
isInit
:
false
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CreateStudentCompanyModule:"
+
startDate
);
}
if
(!
teacherStaticModule
.
CheckTeacherStaticExistsModule
(
startDate
))
{
teacherStaticModule
.
CreateTeacherStaticModule
(
user
,
startDate
,
currentDate
,
isInit
:
false
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CreateTeacherStaticModule:"
+
startDate
);
}
Common
.
Plugin
.
LogHelper
.
Write
(
"DealMarketConsultantData========End"
);
Interlocked
.
Exchange
(
ref
marketconsultant_Timer
,
0
);
}
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
"定时发送邮件时报错"
,
ex
.
Message
);
}
}
public
void
Dispose
()
{
Common
.
Plugin
.
LogHelper
.
Write
(
"定时任务被释放闭"
);
_timer
?.
Dispose
();
//iis会回收这个定时任务,这边在回收的时候触发一个请求,来再次唤醒该服务
Thread
.
Sleep
(
5000
);
string
url
=
"https://eduapi.oytour.com/api/login/login"
;
Common
.
Plugin
.
HttpHelper
.
HttpGet
(
url
);
}
}
}
Edu.WebApi/Timers/TimerJobj.cs
View file @
d7b4461b
...
...
@@ -145,12 +145,12 @@ namespace Edu.WebApi.Timers
finishGuest
.
Elapsed
+=
new
System
.
Timers
.
ElapsedEventHandler
(
DealGuestFinish
);
finishGuest
.
Enabled
=
true
;
marketTimer
=
new
System
.
Timers
.
Timer
()
{
Interval
=
(
1000
*
60
)
*
(
25
)
//25分钟执行一次
};
marketTimer
.
Elapsed
+=
new
System
.
Timers
.
ElapsedEventHandler
(
DealMarketConsultantData
);
marketTimer
.
Enabled
=
true
;
//
marketTimer = new System.Timers.Timer()
//
{
//
Interval = (1000 * 60) * (25) //25分钟执行一次
//
};
//
marketTimer.Elapsed += new System.Timers.ElapsedEventHandler(DealMarketConsultantData);
//
marketTimer.Enabled = true;
dealStudentProgressTimer
=
new
System
.
Timers
.
Timer
()
{
...
...
@@ -176,7 +176,7 @@ namespace Edu.WebApi.Timers
changeOrder
.
Enabled
=
false
;
examTimer
.
Enabled
=
false
;
finishGuest
.
Enabled
=
false
;
marketTimer
.
Enabled
=
false
;
//
marketTimer.Enabled = false;
dealStudentProgressTimer
.
Enabled
=
false
;
dealStudentNotMoneyTimer
.
Enabled
=
false
;
}
...
...
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