JAVA实现按时间段查询数据

html / jsp

开始时间:  

结束时间: 

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>) 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> getPortFolioByTime(Page> 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;
}

 

你可能感兴趣的:(time,page)