You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using Module.DB.Model;
using Newtonsoft.Json;
using RailSee.RealTimeDBO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Module.Common;
namespace Module.DB.SQLServerDAL
{
public class DataClear
{
private AlarmInfo alarmRecordService = new AlarmInfo();
private AssignmentInfo assignmentInfoService = new AssignmentInfo();
RedisHelper redis = new RedisHelper(2); //指定连接的库默认是0
public void SqlDataClear()
{
string strJson = redis.GetStrValue("CurrentTimeInfo");
if (strJson != null)
{
MJsonTime jsonResult = JsonConvert.DeserializeObject<MJsonTime>(strJson);
if (jsonResult != null)
{
double dResult = GetTime(Convert.ToDateTime(jsonResult.f_curr_time));
if (dResult >= 180)
{
alarmRecordService.DeleteAllAlarmInfo(jsonResult.f_curr_time, DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss"));
assignmentInfoService.DeleteAllAssignmentInfo(jsonResult.f_curr_time, DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss"));
MJsonTime mJsonTime = new MJsonTime();
mJsonTime.f_curr_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Task<bool> jsonResultToRedis = redis.SetStrValueAsync("CurrentTimeInfo", mJsonTime);
}
}
}
else
{
MJsonTime mJsonTime = new MJsonTime();
mJsonTime.f_curr_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Task<bool> jsonResultToRedis = redis.SetStrValueAsync("CurrentTimeInfo", mJsonTime);
}
}
public static double GetTime(DateTime timeA)
{
//timeA 表示需要计算
DateTime timeB = DateTime.Now; //获取当前时间
TimeSpan ts = timeB - timeA; //计算时间差
double time = ts.TotalDays; //将时间差转换为天
return time;
}
}
}