计算引擎中使用系统自动计算参数:@time_calc

直接上代码:

 

1
2
3
4
5
6
7
8
/// <summary>
       /// auto_do_for_time_calc 按照秒计算
       /// @time_calc-86400 返回则是当前时刻往前减去86400秒(也就是一天),可用:@time_calc-200,@time_calc+500,@time_calc300
       /// select * from table  where create_time>'@time_calc-18000000' and create_time<'@time_calc-36000'  
       /// select * from table  where create_time>'2024-04-17 03:26:14' and create_time<'2024-11-11 01:26:14'
       /// </summary>
       /// <param name="sql"></param>
       /// <returns></returns>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
string auto_do_sql_for_time_calc(string sql)
{
    if (sql.contains_x("@time_calc").is_false()) return sql;
 
    Regex regex = new Regex("@time_calc[\\w\\W]*?(?=')");
 
    var matches = regex.Matches(sql);
 
    foreach (Match match in matches)
    {
        string key = match.Value;
 
        double val = key.Replace("@time_calc", "").ToDouble();
 
        sql = sql.Replace(key, DateTime.Now.AddSeconds(val).toStringX());
    }
 
    return sql;
}

  

done

posted @   liskov_design  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示