计算引擎中使用系统自动计算参数:@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  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示