Commit 686af568 authored by liudong1993's avatar liudong1993

定时器 清理临时文件

parent 0269469c
......@@ -281,7 +281,7 @@ namespace Edu.Common
{
get
{
string fileExportPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExportFile");
string fileExportPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "/upfile/ExportFile");
if (!Directory.Exists(fileExportPath))
{
Directory.CreateDirectory(fileExportPath);
......
......@@ -171,7 +171,7 @@ ELSE '' END as ToAuditIdStr,
{
WhereIn += $@" and a.CreateTime<='{dmodel.EndTime.Value.ToString("yyyy-MM-dd")+" 23:59:59"}'";
}
string sql = $@"SELECT * FROM(select e.EmName,b.BName,
string sql = $@"SELECT * FROM(select e.EmName,e.BName,
case when ask.`Status`=1 then
(select ToAuditId from rb_workflow_auditrelevance audr where audr.WorkFlowId=ask.Id and audr.TemplateType=ask.TemplateType and audr.Stauts=1 ORDER BY audr.Sort ASC limit 0,1)
ELSE '' END as ToAuditIdStr,
......@@ -183,7 +183,7 @@ ELSE '' END as ToAuditIdStr,
(SELECT a.Id,a.`Status`,a.RB_BranchId,a.CreateBy,a.CreateTime,t.TemplateType,t.`Name` as TemplateName FROM rb_workflow_goout a INNER JOIN rb_workflow_template t on t.id = a.TemplateId where a.RB_GroupId={dmodel.RB_GroupId} {WhereIn}) UNION
(SELECT a.Id,a.`Status`,a.RB_BranchId,a.CreateBy,a.CreateTime,t.TemplateType,t.`Name` as TemplateName FROM rb_workflow_reissuecard a INNER JOIN rb_workflow_template t on t.id = a.TemplateId where a.RB_GroupId={dmodel.RB_GroupId} {WhereIn})
)
ask left JOIN rb_employee e on ask.CreateBy=e.EmployeeId left join rb_branch b on b.Id=ask.RB_BranchId
ask left JOIN rb_employee e on ask.CreateBy=e.EmployeeId
)t {where} ORDER BY t.CreateTime DESC";
var pageList = GetPage<Rb_Workflow_Askforleave_Extend>(pageIndex, pageSize, out count, sql).ToList();
return pageList;
......
......@@ -40,7 +40,7 @@ namespace Edu.Repository.User
{
where += $@" and t.{nameof(Rb_Workflow_SignIn.SignInTime)}<='{dmodel.EndTime + " 23:59:59"}'";
}
string sql = $@"SELECT t.*,e.EmName,b.BName FROM Rb_Workflow_SignIn t left join rb_employee e on t.EmployeeId=e.EmployeeId left join rb_branch b on b.Id=t.RB_BranchId {where} ";
string sql = $@"SELECT t.*,e.EmName,e.BName FROM Rb_Workflow_SignIn t left join rb_employee e on t.EmployeeId=e.EmployeeId {where} ";
if (dmodel.orderBy.HasValue && dmodel.orderBy == 1)
{
sql += $@" ORDER BY t.SignInTime asc";
......
......@@ -72,6 +72,16 @@ namespace Edu.WebApi
{
endpoints.MapControllers();
});
appLifetime.ApplicationStarted.Register(() =>
{
Timers.TimerJobj.RunTimer(); //网站启动完成执行
});
appLifetime.ApplicationStopped.Register(() =>
{
Timers.TimerJobj.RunStop(); //网站停止完成执行
});
}
}
}
\ No newline at end of file
using Edu.Common.Plugin;
using System;
using System.IO;
using System.Threading;
namespace Edu.WebApi.Timers
{
public class TimerJobj
{
static System.Timers.Timer timer1; //计时器
public static void RunTimer()
{
timer1 = new System.Timers.Timer();
timer1.Interval = 1000 * (60 * 60) * 3; //60分钟
timer1.Elapsed += new System.Timers.ElapsedEventHandler(ClearFile);
timer1.Enabled = true;
}
public static void RunStop()
{
timer1.Enabled = false;
}
/// <summary>
/// 防止重置
/// </summary>
private static int inTimer = 0;
/// <summary>
/// 清理文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void ClearFile(object sender, System.Timers.ElapsedEventArgs e) {
if (Interlocked.Exchange(ref inTimer, 1) == 0)
{
string rootBook = AppDomain.CurrentDomain.BaseDirectory;
try
{
LogHelper.Write("开始清理临时文件");
DirectoryInfo dir = new DirectoryInfo(rootBook + "/upfile/temporary");
DirectoryInfo[] dirArr = dir.GetDirectories();
foreach (DirectoryInfo item in dirArr)
{
if (item.CreationTime < DateTime.Now.AddDays(-1))
item.Delete(true);
}
foreach (FileInfo fi in dir.GetFiles())
{
if (fi.CreationTime < DateTime.Now.AddDays(-1))
fi.Delete();
}
#region 导出文件的
DirectoryInfo QRdir = new DirectoryInfo(rootBook + "/upfile/ExportFile");
foreach (FileInfo fi in QRdir.GetFiles())
{
if (fi.CreationTime < DateTime.Now.AddDays(-1))
fi.Delete();
}
#endregion
}
catch
{
LogHelper.Write("清理临时文件失败");
}
Interlocked.Exchange(ref inTimer, 0);
}
}
}
}
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