<%--
  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="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" %>
<%!
    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;
    String year = pub.trimNull(request.getParameter("year"));
    String month = pub.trimNull(request.getParameter("month"));
    String day = pub.trimNull(request.getParameter("day"));
    if(month.length()==1){
        month="0"+month;
    }
    month="-"+month;
    if(day.length()==1){
        day="0"+day;
    }
    day="-"+day;
    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,year+month+day);
        v_list=cf.doQuery(conn,sb.toString(),null,new Object[]{year+month+day});
        if(v_list==null){
            System.out.println("查询该日期值班人员出错"+cf.getMsg());
        }

%>
<div >
    <a class="btn btn-primary radius" onclick="operList();" >
        导出
    </a>
</div>
<div class="">
    <form class="form form-horizontal" method="post" id="form1" name="form1" action="export_query.jsp" >
        <input type="hidden" value="<%=year+month+day%>" name="exportDate" id="exportDate">
        <div id="content" class="cl pd-5  bk-gray divOverflow" style="overflow:hidden;margin-bottom: 20px;height: 400px;">
            <%
                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:1000px;height:120px;float:left;margin-left: 50px;border:0.5px solid #000;position:relative;">
                <div style="width:140px;height:120px;float:left;border-right:0.5px solid #000;text-align: center;line-height: 80px;">
                    <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:140px;height:120px;line-height:120px;float:left;position: relative">
                    <p style="height:70px;line-height: 80px;margin:0px;">
                        <img src="../../images/user.png"/>
                    </p>
                    <div style="height:50px;margin:0px;">
                        <div style="height:30px;line-height: 20px;">
                                <%=user_names[n]%>
                        </div>
                         <div style="height:20px;line-height: 10px;">
                             <%=telphone%>
                         </div>

                    </div>
                </div>
                <%
                    }
                %>
                <span onclick="editUser('<%=year+month+day%>','<%=zb_type%>');" style="text-align:center;position:absolute; right:0; bottom:0;">
                     <img src="../../images/edit.png" width="20" height="15" />
                </span>
            </div>
            <%
                    }
                }
            %>
        </div>
    </form>
</div>
<script>
    function operList() {
        document.form1.submit();
    }
    function editUser(year,zb_type) {
        var url = './selectUser-t.jsp?year='+year+"&zb_type="+zb_type;
        var abc = layer.open({
            title: '选择人员',
            type: 2,
            content: url,
            area: ['1000px', '500px'],
            maxmin: true,
            end:function () {
                //searchModel1($("#check_mx_id").val());
            }
        });
    }
</script>
<%
    } catch (Exception e) {
        out.println("查询用户信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>