<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%!
    public static String getMxId(ConnectionFactory cf,Connection conn,String date) {
        String mx_id="";
        Vector userList = cf.doQuery(conn,"select mx_id from zb_zdpb where b_time<=? and e_time>=? order by add_time desc limit 1",null,new Object[]{date,date});
        if(userList!=null && userList.size()>0){
            Hashtable ht1 = (Hashtable) userList.get(0);
            mx_id = (String) ht1.get("mx_id");
        }
        return mx_id;
    }
    public static String getZbTyTime(ConnectionFactory cf,Connection conn,String mx_id,String zb_type) {
        String time="";
        Vector userList = cf.doQuery(conn,"select b_time,e_time from zb_type where mx_id=? and zb_type=?"
                ,null,new Object[]{mx_id,zb_type});
        if(userList!=null && userList.size()>0){
            Hashtable ht1 = (Hashtable) userList.get(0);
            time = (String) ht1.get("b_time")+"-"+(String) ht1.get("e_time");
        }
        return time;
    }
    public static String getTel(ConnectionFactory cf,Connection conn,String user_name) {
        String tel="";
        Vector userList = cf.doQuery(conn,"select tel from zb_user where user_name=? "
                ,null,new Object[]{user_name});
        if(userList!=null && userList.size()>0){
            Hashtable ht1 = (Hashtable) userList.get(0);
            tel = (String) ht1.get("tel");
        }
        return tel;
    }
%>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    Date date = new Date();
    SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
    String today=sd.format(date);
    String year=today.substring(0,4);
    String month=today.substring(5,7);
    String day=today.substring(8,10);
    Hashtable ht = new Hashtable();
    StringBuffer sb = new StringBuffer();
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        sb.append("select t1.zb_user,t1.zb_type from zb_user_gl t1  where 1=1 ");
        sb.append(" and t1.year=? ");
        sb.append(" order by t1.id asc");
        String mxId=getMxId(cf,conn,today);
        v_list=cf.doQuery(conn,sb.toString(),null,new Object[]{today});
        if(v_list==null){
            System.out.println("查询该日期值班人员出错"+cf.getMsg());
        }
%>
<div class="">
    <form class="form form-horizontal" method="post" id="form1" name="form1" action="export_query.jsp" >
        <div id="content" class="cl pd-5  bk-gray divOverflow" style="overflow:hidden;margin-bottom: 20px;">
            <div style="height:40px;line-height: 40px;background-color: #d7d7d7;font-size: 18px;padding-left: 20px;">值班日期：<%=year%>年<%=month%>月<%=day%>日</div>
            <%
                if(v_list.size()>0){
                    for(int i=0;i<v_list.size();i++){
                        ht = (Hashtable)v_list.get(i);
                        String zb_type= pub.trimNull((String) ht.get("zb_type"));
                        String user_name= pub.trimNull((String) ht.get("zb_user"));
                        String time=getZbTyTime(cf,conn,mxId,zb_type);

            %>
            <div style="width:1280px;height:190px;float:left;margin-left: 50px;
            border:0.5px solid #000;position:relative;<%if(i==0){%>margin-top:5px;<%}%>">
                <div style="font-size: 16px;width:200px;height:190px;float:left;border-right:0.5px solid #000;text-align: center;line-height: 150px;">
                    <p style="height:30px;"> <%=zb_type%></p>
                    <p style="height:30px;">(<%=time%>)</p>
                </div>
                <%
                    String[] user_names=user_name.split(",");
                    for(int n=0;n<user_names.length;n++){
                        String telphone=getTel(cf,conn,user_names[n]);
                %>
                <div style="text-align:center;width:160px;height:190px;line-height:190px;float:left;position: relative">
                    <p style="height:100px;line-height: 150px;margin:0px;">
                        <img src="../../images/user.png"/>
                    </p>
                    <div style="height:70px;margin:0px;font-size: 16px;">
                        <div style="height:40px;line-height: 50px;">
                                <%=user_names[n]%>
                        </div>
                         <div style="height:30px;line-height: 20px;">
                             <%=telphone%>
                         </div>

                    </div>
                </div>
                <%
                    }
                %>
            </div>
            <%
                    }
                }
            %>
        </div>
    </form>
</div>
<%
    } catch (Exception e) {
        out.println("查询用户信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>