<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/11
  Time: 12:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.*" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="org.omg.CosCollection.IteratorInBetween" %>
<%@ page import="com.censoft.db.DBUtil" %>
<%!
    Pub pub = new Pub();
    public String getRolename(ConnectionFactory cf,Connection conn,String userid){
        StringBuffer sb = new StringBuffer();
        Hashtable ht_1=new Hashtable();
        sb.append("select t1.role_name,t1.bz from t_book_role t1 join t_book_user_role_rel t2 on t1.id=t2.role_id where t2.login_id=?");
        Vector list = cf.doQuery(conn,sb.toString(),null,new Object[]{userid});
        if(list==null){
            System.out.println("查询出错"+cf.getMsg());
            return "";
        }
        String role_id="";
        if(list.size()>0){
            for(int i=0;i<list.size();i++){
                ht_1=(Hashtable)list.get(i);
                String bz=pub.trimNull((String)ht_1.get("bz"));
                role_id+=bz+",";
            }
            return role_id;
        }else{
            return "";
        }

    }
    public String getSpStatus(ConnectionFactory cf,Connection conn,String userid){
        StringBuffer sb = new StringBuffer();
        Hashtable ht_1=new Hashtable();
        sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1 left join zc_sp t2" +
                " on t1.ly_id=t2.ly_id where 1=1 ");
        sb.append(" order by t1.add_time desc");
        Vector list = cf.doQuery(conn,sb.toString(),null,new Object[]{userid});
        if(list==null){
            System.out.println("查询出错"+cf.getMsg());
            return "";
        }
        String role_id="";
        if(list.size()>0){
            for(int i=0;i<list.size();i++){
                ht_1=(Hashtable)list.get(i);
                String bz=pub.trimNull((String)ht_1.get("bz"));
                role_id+=bz+",";
            }
            return role_id;
        }else{
            return "";
        }

    }
%>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    String page_number = pub.trimNull(request.getParameter("page_number"));
    if ("".equals(page_number)) page_number = "1";
    String page_size = pub.trimNull(request.getParameter("page_size"));
    String ly_status = pub.trimNull(request.getParameter("ly_status"));
    if ("".equals(ly_status)) ly_status = "1";
    if ("".equals(page_size)) page_size = "10";
    String login_user = (String) session.getAttribute("session_login_id");
    List list_s = new ArrayList();
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        StringBuffer sb = new StringBuffer();
        String user_role_id=getRolename(cf,conn,login_user);
        if("".equals(ly_status)||"1".equals(ly_status)){
            if(user_role_id.indexOf("csgly")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1 left join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where  t1.ly_status=? or t2.spyj_2='0'");
                list_s.add(ly_status);
            }else if(user_role_id.indexOf("cz")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? and (t2.spyj_2 is null or t2.spyj_2='')and (t2.spyj_1='1' or t2.spyj_3='0')");
                list_s.add("2");
            }else if(user_role_id.indexOf("bgsgly")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? and (t2.spyj_3 is null or t2.spyj_3='') and (t2.spyj_2='1' or t2.spyj_4='0')");
                list_s.add("2");
            }else if(user_role_id.indexOf("bgszr")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? and (t2.spyj_4 is null or t2.spyj_4='') and (t2.spyj_3='1' or t2.spyj_5='0')");
                list_s.add("2");
            }else if(user_role_id.indexOf("jz")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? and t2.is_import='0' and  t2.spyj_4='1'");
                list_s.add("2");
            }else{
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1 left join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=?  ");
                list_s.add("1");
                if(!"admin".equals(login_user)){
                    sb.append("and t1.add_user=?");
                    list_s.add(login_user);
                }
            }
        }else if("2".equals(ly_status)){
            if(user_role_id.indexOf("csgly")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where  t1.ly_status=? and t2.spyj_1='1' and (t2.spyj_2 is null or t2.spyj_2='' or t2.spyj_2!='0')");
                list_s.add("2");
            }else if(user_role_id.indexOf("cz")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? and t2.spyj_2 ='1' and (t2.spyj_3 is null or t2.spyj_3='' or t2.spyj_3!='0')");
                list_s.add("2");
            }else if(user_role_id.indexOf("bgsgly")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? and t2.spyj_3 ='1' and (t2.spyj_4 is null or t2.spyj_4='' or t2.spyj_4!='0')");
                list_s.add("2");
            }else if(user_role_id.indexOf("bgszr")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? and t2.spyj_4='1' and t2.is_import='0' and (t2.spyj_5 is null or t2.spyj_5='' or t2.spyj_5!='0')");
                list_s.add("2");
            }else if(user_role_id.indexOf("jz")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? ");
                list_s.add("");
            }else{
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where  t1.ly_status=? ");
                list_s.add("2");
                if(!"admin".equals(login_user)){
                    sb.append("and t1.add_user=?");
                    list_s.add(login_user);
                }
            }
        }else if("3".equals(ly_status)){
            if(user_role_id.indexOf("csgly")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where  t1.ly_status=? or t1.ly_status=?");
                list_s.add("3");
                list_s.add("4");
            }else if(user_role_id.indexOf("cz")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? or t1.ly_status=?");
                list_s.add("3");
                list_s.add("4");
            }else if(user_role_id.indexOf("bgsgly")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? or t1.ly_status=?");
                list_s.add("3");
                list_s.add("4");
            }else if(user_role_id.indexOf("bgszr")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? or t1.ly_status=?");
                list_s.add("3");
                list_s.add("4");
            }else if(user_role_id.indexOf("jz")>0 ){
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where (t1.ly_status=? or t1.ly_status=?) and is_import='0' ");
                list_s.add("3");
                list_s.add("4");
            }else{
                sb.append("select distinct t1.ly_id,t1.xm_id,t1.ly_dept,t1.ly_time," +
                        "t1.ly_user,t1.ly_status,t1.add_time,t2.sp_id from zc_ly t1  join zc_sp t2" +
                        " on t1.ly_id=t2.ly_id where t1.ly_status=? or t1.ly_status=?");
                list_s.add("3");
                list_s.add("4");
                if(!"admin".equals(login_user)){
                    sb.append("and t1.add_user=?");
                    list_s.add(login_user);
                }
            }
        }

        sb.append(" order by t1.add_time desc");
        v_list = cf.doPageQueryWithCount(conn, sb.toString(), page_number, page_size, null, list_s.toArray());
        if (v_list == null) {
            out.println("查询出错" + cf.getMsg());
            return;
        }

    Hashtable ht_row = (Hashtable) v_list.get(0);
    String rowCnt = pub.trimNull((String) ht_row.get("ROWCOUNT"));
%>
<div class="table-list">
    <table class="table  table-hover table-bg">
        <thead>
        <tr class="text-c">
            <th width="50px">所属项目</th>
            <th width="50px">申请人</th>
            <th width="50px">申请时间</th>
            <%if(!"3".equals(ly_status)){%>
            <th width="50px">操作</th>
            <%}%>
        </tr>
        </thead>
        <tbody>
        <%
            if (v_list != null && v_list.size() > 0) {
                    for (int i = 1; i < v_list.size(); i++) {
                        Hashtable ht = (Hashtable) v_list.get(i);
                        String ly_id_view = pub.trimNull((String) ht.get("ly_id"));
                        String sp_id_view = pub.trimNull((String) ht.get("sp_id"));
                        String action_type="update";
                        if("".equals(sp_id_view)){
                            action_type="add";
                            sp_id_view= DBUtil.getUUID();
                        }
                        String xm_id_view = pub.trimNull((String) ht.get("xm_id"));
                        String ly_dept_view = pub.trimNull((String) ht.get("ly_dept"));
                        String ly_time_view = pub.trimNull((String) ht.get("ly_time"));
                        String ly_user_view = pub.trimNull((String) ht.get("ly_user"));
                        String url="./list_ly-t.jsp?ly_status="+ly_status+"&ly_id="+ly_id_view+"&sp_id="+sp_id_view+"&action="+action_type;
                        %>
                        <tr <%if(i%2==0){%>id="tr_doub"<%}else{%>id="tr_single"<%}%> class="text-c">
                            <td>
                                <a href="javascript:void(0);" onclick="viewSp('<%=url%>')"><%=xm_id_view%></a>
                            </td>
                            <td><%=ly_user_view%>
                            </td>
                            <td><%=ly_time_view%>
                            </td>
                            <%if(!"3".equals(ly_status)){%>
                                <td>
                                    <a href="javascript:void(0);" onclick="nahui('chexiao','<%=sp_id_view%>','<%=ly_id_view%>')">拿回</a>
                                </td>
                            <%}%>
                        </tr>
                        <%
                    }
            }
        %>
        </tbody>
    </table>
</div>
<jsp:include page="/common/page_ajax.jsp" >
    <jsp:param name="page_number" value="<%=page_number%>" />
    <jsp:param name="rowCnt" value="<%=rowCnt%>" />
    <jsp:param name="page_size" value="<%=page_size%>" />
</jsp:include>
<%
    } catch (Exception e) {
        out.println("查询异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>