JAVA實現按時間段查詢資料操作
阿新 • • 發佈:2020-08-17
html / jsp
<span style="vertical-align: -webkit-baseline-middle;font-size:16px;font-weight:bold;">開始時間:</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" style="font-size:16px;font-weight:bold;">結束時間: </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();" style="float:none;"/>
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,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,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 5 0 2 5 0 3 5 0 4 5 0 5 5 0 6 5 0 7 5 0 8 5 0 9 5 0 10 5 0 11 5 0 12 5 0 13 5 0 14 5 0 15 5 0 16 5 0 17 5 0 18 5 0 19 5 0 20 5 0 21 5 0 22 5 0 23 5 0 0 5
以上這篇JAVA實現按時間段查詢資料操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。