• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

atitit.判断时间重叠方法总结javac++c#.netjsphp

mysql 搞代码 4年前 (2022-01-09) 20次浏览 已收录 0个评论

atitit.判断时间重叠方法总结 java c++ c#.net js php 1. 判断时间重叠具体流程思路 1 2. 重叠算法 实际上就是日期集合跟个时间集合的的交集(乘法算法) 1 3. 代码— 1 4. 最终生成的sql 3 5. 参考 5 1. 判断时间重叠具体流程思路 先判断日期重叠,在判断时

atitit.判断时间重叠方法总结 java c++ c#.net js php

1. 判断时间重叠具体流程思路 1

2. 重叠算法 实际上就是日期集合跟个时间集合的的交集(乘法算法) 1

3. 代码— 1

4. 最终生成的sql 3

5. 参考 5

1. 判断时间重叠具体流程思路

先判断日期重叠,在判断时间区段重叠。

每个区段都有内包含,外包含,左包含,右包括…所以,or表达式需要4*4=16个..每个or 表达式包括4个and表达式( 两个日期表达式,两个时间范围表达式)

最终的最终的的表达式需要16*4=64个,,比较长的了..

2. 重叠算法 实际上就是日期集合跟个时间集合的的交集(乘法算法)

在程序设计里有。。。。。

回答

那实际上就是交、并、差。
所谓加,实际上就是求两个集合的并集
减,就是求两个集合的差集
乘,就是求两个集合的并集
它们都是从逻辑的运算推出来的

另外更正一下:乘是求两个集合的交集。

3. 代码—本文来源gaodai$ma#com搞$$代**码)网8

private void ini() {String db_start_fld = "start_time";String db_end_fld = "end_time";String db_include_exp = "db_start_fld>=ui_start and db_end_fld<=ui_end ";String db_outclude_exp = "db_start_fld=ui_end ";String db_leftinclude_exp = "db_end_fld>=ui_start and db_end_fld =ui_start and db_end_fld<=ui_end ";List dateExpList = new ArrayList() {{add(expandFunc(db_include_exp));add(expandFunc(db_outclude_exp));add(expandFunc(db_leftinclude_exp));add(expandFunc(db_ritinclude_exp));}private String expandFunc(String db_include_exp) {String db_start_fld_Datefunc = " CONVERT(varchar(100), db_start_fld, 23)";String db_end_fld_Datefunc = " CONVERT(varchar(100), db_end_fld, 23)";return db_include_exp.replaceAll("db_start_fld",db_start_fld_Datefunc).replaceAll("db_end_fld",db_end_fld_Datefunc);}};List timeExpList = new ArrayList() {{add(expandFunc(db_include_exp));add(expandFunc(db_outclude_exp));add(expandFunc(db_leftinclude_exp));add(expandFunc(db_ritinclude_exp));}private String expandFunc(String db_include_exp) {String db_start_fld_Timefunc = " CONVERT(varchar(100), db_start_fld, 8)";String db_end_fld_Timefunc = " CONVERT(varchar(100), db_end_fld, 8)";return db_include_exp.replaceAll("db_start_fld",db_start_fld_Timefunc).replaceAll("db_end_fld",db_end_fld_Timefunc);}};List finalList= new ArrayList() {{for (String dateExp : dateExpList) {for (String timeExp : timeExpList) {this.add(dateExp+" and "+timeExp.replaceAll("db_start_fld", db_start_fld).replaceAll("db_end_fld", db_end_fld));}}}};String sql=new ArrayList(){private String exec( ) {String exp_final=" 1=1 ";for (String exp : finalList) {//if(exp_final.length()==0)exp_final=exp_final + " or ( "+exp +" ) ";}return exp_final;}}.exec( );System.out.println(sql);}

4. 最终生成的sql

SELECT *FROM tabWHERE 1=1OR (CONVERT(varchar(100), db_start_fld, 23)>=ui_startAND CONVERT(varchar(100), db_end_fld, 23)=ui_startAND CONVERT(varchar(100), end_time, 8)=ui_startAND CONVERT(varchar(100), db_end_fld, 23)<=ui_endAND CONVERT(varchar(100), start_time, 8)=ui_end)OR (CONVERT(varchar(100), db_start_fld, 23)>=ui_startAND CONVERT(varchar(100), db_end_fld, 23)=ui_startAND CONVERT(varchar(100), end_time, 8) =ui_startAND CONVERT(varchar(100), db_end_fld, 23)=ui_startAND CONVERT(varchar(100), end_time, 8)<=ui_end)OR (CONVERT(varchar(100), db_start_fld, 23)=ui_endAND CONVERT(varchar(100), start_time, 8)>=ui_startAND CONVERT(varchar(100), end_time, 8)<=ui_end)OR (CONVERT(varchar(100), db_start_fld, 23)=ui_endAND CONVERT(varchar(100), start_time, 8)=ui_end)OR (CONVERT(varchar(100), db_start_fld, 23)=ui_endAND CONVERT(varchar(100), end_time, 8)>=ui_startAND CONVERT(varchar(100), end_time, 8) <=ui_end)OR (CONVERT(varchar(100), db_start_fld, 23)=ui_endAND CONVERT(varchar(100), start_time, 8)>=ui_startAND CONVERT(varchar(100), end_time, 8)=ui_startAND CONVERT(varchar(100), db_end_fld, 23) =ui_startAND CONVERT(varchar(100), end_time, 8)=ui_startAND CONVERT(varchar(100), db_end_fld, 23) <=ui_endAND CONVERT(varchar(100), start_time, 8)=ui_end)OR (CONVERT(varchar(100), db_end_fld, 23)>=ui_startAND CONVERT(varchar(100), db_end_fld, 23) =ui_startAND CONVERT(varchar(100), end_time, 8) =ui_startAND CONVERT(varchar(100), db_end_fld, 23) =ui_startAND CONVERT(varchar(100), end_time, 8)=ui_startAND CONVERT(varchar(100), db_end_fld, 23)=ui_startAND CONVERT(varchar(100), end_time, 8)=ui_startAND CONVERT(varchar(100), db_end_fld, 23)<=ui_endAND CONVERT(varchar(100), start_time, 8)=ui_end)OR (CONVERT(varchar(100), db_start_fld, 23)>=ui_startAND CONVERT(varchar(100), db_end_fld, 23)=ui_startAND CONVERT(varchar(100), end_time, 8) =ui_startAND CONVERT(varchar(100), db_end_fld, 23)=ui_startAND CONVERT(varchar(100), end_time, 8)<=ui_end)

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:atitit.判断时间重叠方法总结javac++c#.netjsphp

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址