<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.stfoa.dao.hibernate.EmployeeDAO"%>
<%@page import="com.stfoa.domain.Employee"%>
<%@page import="com.stfoa.common.util.SysConfUtil"%>
<%@page import="com.stfoa.common.util.DESUtil"%>
<%@page import="com.stfoa.common.custquery.helper.ParseJSON"%>
<%@page import="com.stfoa.Constants"%>
<%@include file="/include/taglibs.jsp"%>
<%@ taglib uri="/WEB-INF/jsp-stfhr.tld" prefix="stfhr"%>
<HTML>
<HEAD>
<%@ include file="/include/meta.jsp"%>
<%@ include file="/include/head_list.jsp"%>
<%@ include file="/include/jquery.jsp"%>
</HEAD>
<%
 session.setAttribute("progress_status","begin");
 EmployeeDAO empdao = new EmployeeDAO();
 int pageno = 1; // 当前页码
 int countperpage = SysConfUtil.getInstance().getPageSize(); //每页条数
 int totalcount = 0; //总条数
 String queryHQL = "";//最终查询语句
 String queryType = request.getParameter("queryType");//查询方式 
 String orderby = " order by emp.empCode";//默认排序方式
 if("ALL".equals(queryType)){//全部
	  queryHQL ="from com.stfoa.domain.Employee as emp where emp.empStatus=0 and emp.userType=0 "+orderby;
	  queryHQL = DESUtil.doEncrypt(queryHQL);
  }else if("CUST".equals(queryType)){//自定义
	  String queryJSON = request.getParameter("queryJSON");
      String orderbyJSON =request.getParameter("orderbyJSON");
      ParseJSON parser = new ParseJSON();
	  String queryWhere = parser.parseJsonToHQL(queryJSON).replaceAll("empfile.oaTblEmployee","emp");
	  String queryOrderby = parser.parseJsonToOrderby(orderbyJSON).replaceAll("empfile.oaTblEmployee","emp");
	  if(!"".equals(queryOrderby)){
	    orderby = " order by "+queryOrderby;  
	  }
	  queryHQL ="from com.stfoa.domain.Employee as emp "+
	  "where emp.empStatus=0 and emp.userType=0 "+queryWhere+orderby;
	  queryHQL = DESUtil.doEncrypt(queryHQL);
  }else if("PAGE".equals(queryType)){//分页
	queryHQL = request.getParameter("queryHQL"); 
	pageno = Integer.valueOf(request.getParameter("pageno"));
	countperpage = Integer.parseInt(request.getParameter("countperpage"));
	if (pageno < 1) {
	  pageno = 1;
	}
 }

 ////查询
 if(queryHQL!=null && !"".equals(queryHQL) && !"null".equals(queryHQL)){
   String hql = DESUtil.doDecrypt(queryHQL);
   //总条数
   totalcount = empdao.queryCountByHQL("select count(*) "+hql);
   //总页数
   int pagecount = ((totalcount + countperpage) - 1) / countperpage;
   if (pageno > pagecount) {
	 pageno = pagecount;
   }
   List<Employee> querylist = empdao.queryByHQLForPagination(hql,(pageno - 1) * countperpage, countperpage);
   request.setAttribute("querylist",querylist);
 }
%>
<BODY leftMargin=0 topMargin=0>
 <logic:present name="querylist">
<table cellspacing="0" onClick="sortColumn(event)" width="100%" class="sort">     
 <thead>
  <tr>
   <td type="Number" width="5%" align="center">序号</td>
   <td type="String" width="5%">编号</td>
   <td type="String" width="10%">姓名</td>
   <td type="String" width="8%">登录名</td>
   <td type="String" width="15%">部门</td>
   <td type="String" width="14%">职务</td>
   <td type="String" width="15%">岗位</td>
   <td type="String" width="8%">状态</td>
   <td type="String" width="6%">操作</td>
  </tr>
 </thead> 

 <tbody>
  <%
  int num = 0;  
  %>
 <logic:iterate id="emp" name="querylist" type="com.stfoa.domain.Employee">
  <% num++; %>
  <tr class="sort" height=24 onMouseOut="this.style.background='';" onMouseOver="this.style.background='#EEE';">
   <td class="sort" align="left"><input type="checkbox" name=myCheckBox empId="<%=emp.getEmpId()%>"><%=num%></td>
   <td class="sort"><%=emp.getEmpCode()%></td>
   <td class="sort"><%=emp.getEmpName()%></td>
   <td class="sort"><%=emp.getLoginId()%></td>
   <td class="sort"><%=emp.getOaTblDepartment().getDeptName()%></td>
   <td class="sort"><%=emp.getOaTblTitle().getTitleName()%></td>
   <td class="sort"><%=emp.getOaTblDuty().getDutyName()%></td>
   <td class="sort"><%=emp.getUseStatus()==0?Constants.HTML_USESTATUS_0:Constants.HTML_USESTATUS_1%></td>
   <td class="sort">
    <a href="javascript:editemp(<%=emp.getEmpId()%>)">
     导入
    </a>
   </td>
  </tr>
 </logic:iterate>
 </tbody>
</table>
<form action='list.jsp' method=post name=pageform style="margin:0;">
 <input type=hidden name=queryHQL value="<%=queryHQL%>">
 <input type=hidden name=queryType value=PAGE>
 <div align="right" style="font-size:9pt;" class=noprint>
  <stfhr:Pageation pageno="<%=pageno%>" countperpage="<%=countperpage%>" totalcount="<%=totalcount%>"></stfhr:Pageation>
 </div>
 </logic:present>
</BODY>
<script type="text/javascript">
 function editemp(empId){
  window.showModalDialog('../newadd/empimport.jsp?empId='+empId,self,
 'dialogWidth:860px;dialogHeight:720px;dialogTop:60;dialogLeft:160;center: yes; status=no');
 }
</script>
</HTML>
<%session.setAttribute("progress_status","end");%>
