Files
2025-11-25 17:41:57 +08:00

30 lines
1.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using SqlSugar;
using System.Diagnostics;
static SqlSugarClient GesmartDb()
{
SqlSugarClient Db = new(new ConnectionConfig()
{
ConnectionString = "Server=blv-cloud-db.mysql.rds.aliyuncs.com;Database=Face;Uid=blv_rcu;Pwd=fnadiaJDIJ7546;charset=utf8;port=3307;",
DbType = SqlSugar.DbType.MySql,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
});
//用来打印Sql方便调式
Db.Aop.OnLogExecuting = (sql, pars) =>
{
Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value));
Debug.WriteLine(sql);
};
return Db;
}
using (SqlSugarClient db = GesmartDb())
{
// 直接在SQL中使用日期函数无需参数
int rowsAffected = db.Ado.ExecuteCommand(
"DELETE FROM pmslog WHERE Creationtime < DATE_SUB(CURDATE(), INTERVAL 45 DAY);"+
"DELETE FROM pmsinterface WHERE DateTime < DATE_SUB(CURDATE(), INTERVAL 45 DAY);" +
"DELETE FROM devicestatushistory WHERE CreateTime < DATE_SUB(CURDATE(), INTERVAL 45 DAY);"
);
Console.WriteLine("已经执行" + rowsAffected);
}