查詢日期帶時分秒00:00:00 23:59:59

ZHOU_VIP發表於2019-03-06
/**
 * 查詢合同資訊列表
 * 
 * @param request
 * @param response
 * @return
 */
@RequestMapping("contractList")
@ResponseBody
public List<OsmContract> contractList(HttpServletRequest request, HttpServletResponse response) throws Exception {
	//合同編號
	String contractid = request.getParameter("contractid");
	//合同名稱
	String contracttitle = request.getParameter("contracttitle");
	//克拉聯盟編號
	String claano =request.getParameter("claano");
	//登記開始時間
	//2018-09-12
	String beginTime = request.getParameter("beginTime");  
	//2018-09-12 00:00:00.0
	Timestamp bt = this.parseDateStr(beginTime, "00:00:00");
	//登記結束時間
	String endTime = request.getParameter("endTime");  
	Timestamp et = this.parseDateStr(endTime, "23:59:59");
	logger.info("contractid = "+contractid+", contracttitle="+contracttitle+",claano="+claano+", beginTime="+beginTime+", finishdate="+endTime);		
	contractid = (contractid == null) ? "" : contractid.trim();
	contracttitle = (contracttitle == null) ? "" : contracttitle.trim();
	beginTime = (beginTime == null) ? "" : beginTime.trim();
	endTime = (endTime == null) ? "" : endTime.trim();
	ContractQueryPara para = genDevQryParam(contractid.trim(),contracttitle.trim(),claano,bt, et);
	return contractService.queryAllOsmContractByPara(para);
}

/**
 * 解析日期字串
 * 
 * @param dateStr
 * @param timeStr
 * @return
 */
private Timestamp parseDateStr(String dateStr, String timeStr){
	if(dateStr == null || dateStr.trim().equals("")){
		return null;
	}
	dateStr = dateStr.trim();
	int dateLen = "yyyy-MM-dd".length();
	if(dateStr.length() > dateLen){
		dateStr = dateStr.substring(0, dateLen);
	}
	try{
		Date d = datetimeFormat.parse(dateStr+" "+timeStr);
		return new Timestamp(d.getTime());
	}catch(Exception e){
		logger.error("parseDateStr failed: "+dateStr, e);
		return null;
	}
}

private ContractQueryPara genDevQryParam(String contractid,String contracttitle,String claano,Timestamp bt,Timestamp et)
{
	ContractQueryPara para = new ContractQueryPara();
	para.setContractid(contractid);
	para.setContracttitle(contracttitle);
	para.setClaano(claano);
	para.setBeginDate(bt);
	para.setEndDate(et);
	return para;
}

 

相關文章