jeecg自定义datagrid封装列表分页数据显示自定义字段

/**
	 * easyui AJAX请求数据
	 * @param clockin
	 * @param request
	 * @param response
	 * @param dataGrid
	 */

	@RequestMapping(params = "datagrid")
	public void datagrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		TSUser user = ResourceUtil.getSessionUser();
		List> data = new ArrayList>();
		String workNum = "";
		if(StringUtils.isNotBlank(user.getEmp())) {//如果登录者存在员工id 就只查询自己的员工信息
			JformResumeInfoEntity jformResumeInfo = jformResumeInfoService.getEntity(JformResumeInfoEntity.class, user.getEmp());
			workNum = jformResumeInfo.getWorkNum();
		}
		/**
		 *  早上
			gapTime = (
			case when datediff(MINUTE,CONVERT(VARCHAR(100),sj,23) + ' 08:00:00',sj) < -200  then '无'
			when datediff(MINUTE,CONVERT(VARCHAR(100),sj,23) + ' 08:00:00',sj) > -200  then '正常'
			     when datediff(MINUTE,CONVERT(VARCHAR(100),sj,23) + ' 08:00:00',sj) <= 0  then '正常'
					when datediff(MINUTE,CONVERT(VARCHAR(100),sj,23) + ' 08:00:00',sj) > 0  then '迟到'
			     else '其他' end 
			)
		 */
		StringBuffer sql = new StringBuffer("select a.*,b.user_no as userNo,gapTime = (datediff(MINUTE,CONVERT(VARCHAR(100),sj,23) + ' 08:00:00',sj)) from kt_jl as a,dt_user as b WHERE a.user_serial = b.user_serial ");
		if(StringUtils.isNotBlank(workNum)) {
			sql.append(" and b.user_no = '" + workNum + "'");
		}else {
			String userNo = request.getParameter("userNo");
			if(StringUtils.isNotBlank(userNo)) {
				sql.append(" and b.user_no = '" + userNo + "'");
			}
		}
		
		String sj_begin = request.getParameter("sj_begin");
		if(StringUtils.isNotBlank(sj_begin)) {
			sql.append(" and sj >= '" + sj_begin + " 00:00:00'");
		}
		String sj_end = request.getParameter("sj_end");
		if(StringUtils.isNotBlank(sj_end)) {
			sql.append(" and sj <= '" + sj_end + " 23:59:59'");
		}
		if(StringUtils.isBlank(sj_end) && StringUtils.isBlank(sj_begin) ) {
			//默认当月
			String year = DateUtilsEx.getCurrYear();
			String month = DateUtilsEx.getCurrMothe();
			/*String lostDay =  String.valueOf(DateUtilsEx.getMonthLastDay());//当月最后一天
			sql.append(" and sj BETWEEN '"+year+"-"+month+"-01 00:00:00' and '"+year+"-"+month+"-"+lostDay+" 23:59:59'");*/
			
			//默认当天
			String nowDay = String.valueOf(DateUtilsEx.getMonthNowDay());
			sql.append(" and sj BETWEEN '"+year+"-"+month+"-"+nowDay+" 00:00:00' and '"+year+"-"+month+"-"+nowDay+" 23:59:59'");
			
		}
		
		if(StringUtils.isNotBlank(dataGrid.getSort())) {
			sql.append(" order by "+ dataGrid.getSort() +" "+dataGrid.getOrder());
		}else {
			sql.append(" order by sj DESC");
		}
		//测试jdbctemplate
		data = DynamicDBUtil.findList("sql-server2008",sql.toString());
		List> showList = null;//要显示的数据
		int showLen = dataGrid.getRows();//动态得到前端需要显示多少条
		int totlePage = data.size()%showLen == 0 ? data.size()/showLen : data.size()/showLen + 1;
		if(dataGrid.getPage() == 1 ) {
			if(showLen > data.size()) {
				showLen = data.size();
			}
			showList = data.subList(0, showLen);
		}else {
			if(dataGrid.getPage() == totlePage) {
				showList = data.subList(((dataGrid.getPage()-1)*showLen),data.size());
			}else {
				showList = data.subList(((dataGrid.getPage()-1)*showLen),((dataGrid.getPage()-1)*showLen)+showLen);
			}
		}
		
		dataGrid.setResults(showList);
		dataGrid.setTotal(data.size());//总条数
		
	
		TagUtil.datagrid(response, dataGrid);
	}
	
	

 

  
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

 

 

 

你可能感兴趣的:(jeecg)