JAVA实现按时间段查询数据操作的方法
小编给大家分享一下JAVA实现按时间段查询数据操作的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
html / jsp
<span >开始时间:</span> <input name="startTime" id="startTime" type="text" class="Wdate" onfocus="WdatePicker()" style="height: 34px; line-height: 34px; border-radius: 4px; border: 1px solid #ccc; font-size: 14px;"><span class="ml10 mr8" >结束时间: </span><input name="endTime" id="endTime" type="text" class="Wdate" onfocus="WdatePicker()" style="height: 34px; line-height: 34px; border-radius: 4px; border: 1px solid #ccc; font-size: 14px;"><input type="submit" class="btn btn-query" id="findTime" value="查询" onClick="toFindTime();" />
js方法:
function timeCheckInfo(page,startTime,endTime,officeVal){ var startTime=$("#startTime").val(); var endTime=$("#endTime").val(); $.ajax({ url: "../../security/base/peoplesafeimg!findPortFolioByTime.action", type: "post", data:{ pagenum:page, startTime:startTime, endTime:endTime, deptid:officeid, // 处室ID来源于默认(页面传值)和下拉框选择 lenian 2018 06 29 depotid:depotid }, dataType: "json", success: function (data) { //alert(JSON.stringify(data)); var dataset = data[0].result; $(dataset).each(function(i,val) { }); }, error:function(){ alert("查询数据失败") } }); }
PeoplesafeimgAction.java
/** * @author lenian 2018 06 12 * 根据时间查询人员画像机务处、运输处、货运处工作量数据并展示 * @param page * @param startTime * @param endTime * @return */public String findPortFolioByTime(){ page.setPageNo(pagenum); page = (Page<Map<String, Object>>) peopleSafeImgManager.getPortFolioByTime(page, startTime, endTime, deptid, depotid); JSONArray jsonArray = JSONArray.fromObject(page); renderTextJSONGBK(jsonArray.toString()); return null;}PeopleSafeImgManager.java/** * @author lenian 2018 06 12 * 根据时间查询人员画像机务处、运输处、货运处工作量数据并展示 * @param page * @param startTime * @param endTime * @return */@SuppressWarnings("unchecked")public Page<Map<String, Object>> getPortFolioByTime(Page<Map<String, Object>> page, String startTime, String endTime, Long deptid, Long depotid) { String depotName = null; // 判断当站段登录时,传到后台的depotid为空 if (depotid == null) { Long depot_id = SessionManager.getDepartmentId(); Department department = departmentManager.getObjectById(depot_id); depotName = department.getName();//站段 } else if (depotid != null && depotid != 0) { // 当处室登录,选择其中某个站段进行了查询 Department department = departmentManager.getObjectById(depotid); depotName = department.getName();//站段 } // 根据处室将数据区分开来 lenian 2018 06 25 Department deparent = departmentManager.getObjectById(deptid); // 当处室登录,并且depotid==0,表示查询所有(注:以上操作可示为参数的准备) String sql; if (depotid != null && depotid == 0) { sql = "select spp.id,\n" + " sei.name,\n" + " spp.id_card,\n" + " to_char(spp.time, 'yyyy-MM-dd') time,\n" + " spp.ins,\n" + " spp.outs,\n" + " spp.score,\n" + " spp.minute,\n" + " spp.column_number,\n" + " spp.channel_number\n" + " from Security_Portrait_Portfolio spp, Security_Employee_Info sei\n" + " where spp.id_card = sei.idcard_num(+) and sei.office_name = '"+ deparent.getName() +"'"; } else { // 1、当处室登录,选择其中某个站段进行了查询; 2、站段登录,获取当前站段ID sql = "select spp.id,\n" + " sei.name,\n" + " spp.id_card,\n" + " to_char(spp.time, 'yyyy-MM-dd') time,\n" + " spp.ins,\n" + " spp.outs,\n" + " spp.score,\n" + " spp.minute,\n" + " spp.column_number,\n" + " spp.channel_number\n" + " from Security_Portrait_Portfolio spp, Security_Employee_Info sei\n" + " where spp.id_card = sei.idcard_num(+) and spp.depot = '"+ depotName +"' and sei.office_name = '"+ deparent.getName() +"'"; } if (StrUtils.stringQuery(startTime) && StrUtils.stringQuery(endTime)) { sql += "and to_char(spp.time, 'yyyy-MM-dd') between '"+ startTime +"' and '"+ endTime +"'"; } sql += "order by spp.create_time desc"; SQLQuery query = dao.getSession().createSQLQuery(sql); Integer count = Integer.parseInt(dao.getSession() .createSQLQuery("select count(1) from (" + sql + ")") .uniqueResult().toString()); if (page.isAutoCount()) { page.setTotalCount(count); } if (page.isFirstSetted()) { query.setFirstResult(page.getFirst()); } if (page.isPageSizeSetted()) { query.setMaxResults(page.getPageSize()); } query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); page.setResult(query.list()); return page;}
补充知识:Java 实现判断时间是否在某个区间内(如是否在23点到凌晨4点之间)
最近遇到一个需求,就是判断一个时间是否在23点到凌晨4点之间,这个时间段是可以修改的。在网上收了一下发现没有符合我的需求的,就自己琢磨了一下,感觉这样算还是可以的。
思路:
如上图的那个圆形的钟表,可以从开始时间剪断,把钟表的环铺平,此时就变成了一个刻度尺,这样就好比较了
代码块
测试代码:
public static void main(String[] args) { int start = 23; int end = 4; int emp = 24 - start; for (int d = 0; d < 24; d++) { System.out.println((start + emp) % 24 + "\t" + (d + emp) % 24 + "\t" + (end + emp) % 24); }}
输出:
0 1 50 2 50 3 50 4 50 5 50 6 50 7 50 8 50 9 50 10 50 11 50 12 50 13 50 14 50 15 50 16 50 17 50 18 50 19 50 20 50 21 50 22 50 23 50 0 5
看完了这篇文章,相信你对JAVA实现按时间段查询数据操作的方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。