Commit d7b4461b authored by 黄奎's avatar 黄奎

111

parent 79a8e1b4
......@@ -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>();
}
......
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);
}
}
}
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment