<%--
  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.apache.commons.lang.StringUtils" %>
<%!
    Pub pub = new Pub();
    public String getDeptName(ConnectionFactory cf,Connection conn,String dept_id){
        StringBuffer sql = new StringBuffer();
        String deptName="";
        sql.append("select t1.dept_name as dept_name_4,t2.dept_name as dept_name_3,t3.dept_name as dept_name_2,t4.dept_name as dept_name_1 from ");
        sql.append("tp_dept t1 left join tp_dept t2 on t1.p_id=t2.id");
        sql.append(" left join tp_dept t3 on t2.p_id=t3.id");
        sql.append(" left join tp_dept t4 on t3.p_id=t4.id");
        sql.append(" where t1.id=?");
        Vector v_list = cf.doQuery(conn, sql.toString(), null, new Object[]{dept_id});
        if(v_list!=null && v_list.size()>0){
            Hashtable ht = (Hashtable) v_list.get(0);
            String dept_name_4 = pub.trimNull((String) ht.get("dept_name_4"));
            String dept_name_3 = pub.trimNull((String) ht.get("dept_name_3"));
            String dept_name_2 = pub.trimNull((String) ht.get("dept_name_2"));
            String dept_name_1 = pub.trimNull((String) ht.get("dept_name_1"));
            if(!"".equals(dept_name_3)){
                deptName=dept_name_3+">"+dept_name_4;
            }else{
                deptName=dept_name_4;
            }
            if(!"".equals(dept_name_2)){
                deptName=dept_name_2+">"+dept_name_3+">"+dept_name_4;
            }
            if(!"".equals(dept_name_1)){
                deptName=dept_name_1+">"+dept_name_2+">"+dept_name_3+">"+dept_name_4;
            }
        }
        return deptName;
    }
%>
<%
    response.setCharacterEncoding("UTF-8");
    request.setCharacterEncoding("UTF-8");
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    String[] field = request.getParameterValues("zc_ids");
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=" + "excel.xls");
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        String sql="";
        StringBuffer sb = new StringBuffer();
        sb.append("select t1.*,t2.xm_id,t2.ly_dept,t2.ly_user,t2.bg_time,t2.add_time as ly_time " +
                "from zc_register t1 left join zc_ly t2 on t1.zc_id=t2.zc_id where 1=1 ");
        sb.append(" and t1.zc_id in (");
        if(field!=null&&field.length>0){
            for(int i=0;i<field.length;i++){
                if(i==field.length-1){
                    sb.append("'" + field[i] + "'");
                }else{
                    sb.append("'" + field[i] + "',");
                }
            }
        }
        sb.append(" )");
        v_list = cf.doQuery(conn, sb.toString(), null, new Object[]{});
        if (v_list == null) {
            System.out.println("查询出错"+cf.getMsg());
            return;
        }
%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache, must-revalidate">
    <meta http-equiv="expires" content="0">
    <title></title>
    <style>
        table th{border:1px solid  black}
        table td{border:1px solid  black}
    </style>
</head>
<body>
<table style="border-collapse:collapse;border:1px solid  black;">
    <thead>
    <tr class="text-c">
        <th width="50px">所属项目</th>
        <th width="50px">资产编号</th>
        <th width="50px">资产名称</th>
        <th width="50px">资产分类</th>
        <th width="50px">国标大类</th>
        <th width="50px">价值类型</th>
        <th width="50px">价格</th>
        <th width="50px">使用部门</th>
        <th width="50px">使用人</th>
        <th width="50px">资产状态</th>
        <th width="50px">领用时间</th>
        <th width="50px">入账日期</th>
    </tr>
    </thead>
    <tbody>
    <%
        if (v_list != null && v_list.size() > 0) {
            for (int i = 0; i < v_list.size(); i++) {
                Hashtable ht = (Hashtable) v_list.get(i);
                String zc_name = pub.trimNull((String) ht.get("zc_name"));
                String xm_id = pub.trimNull((String) ht.get("xm_id"));
                String zc_id = pub.trimNull((String) ht.get("zc_id"));
                //zc_id=zc_id+"'";
                String ly_dept = pub.trimNull((String) ht.get("ly_dept"));
                String ly_user = pub.trimNull((String) ht.get("ly_user"));
                String ly_time = pub.trimNull((String) ht.get("ly_time"));
                String zc_gj_type = pub.trimNull((String) ht.get("zc_gj_type"));
                String zc_fl = pub.trimNull((String) ht.get("zc_fl"));
                String jz_type = pub.trimNull((String) ht.get("jz_type"));
                String jiage = pub.trimNull((String) ht.get("jiage"));
                String cw_date = pub.trimNull((String) ht.get("cw_date"));
                String bg_time = pub.trimNull((String) ht.get("bg_time"));
                String zc_status = pub.trimNull((String) ht.get("zc_status"));
                if("0".equals(zc_status)){
                    zc_status="闲置";
                }else if("3".equals(zc_status)){
                    zc_status="领用";
                }else if("1".equals(zc_status)){
                    zc_status="已提交";
                }else if("2".equals(zc_status)){
                    zc_status="审核中";
                }else if("4".equals(zc_status)){
                    zc_status="盘点中";
                }else if("4_1".equals(zc_status)){
                    zc_status="盘点结束";
                }else if("5".equals(zc_status)){
                    zc_status="维修中";
                }else if("6".equals(zc_status)){
                    zc_status="报废";
                }
                if(!"".equals(bg_time)){
                    zc_status="变更";
                }
    %>
    <tr class="text-c">
        <td><%=xm_id%>
        </td>
        <td><%=zc_id%>
        </td>
        <td><%=zc_name%>
        </td>
        <td><%=zc_fl%>
        </td>
        <td><%=zc_gj_type%>
        </td>
        <td><%=jz_type%>
        </td>
        <td><%=jiage%>
        </td>
        <td><%=ly_dept%>
        </td>
        <td><%=ly_user%>
        </td>
        <td><%=zc_status%>
        </td>
        <td><%=ly_time%>
        </td>
        <td><%=cw_date%>
        </td>
    </tr>
            <%
            }
        }
    %>
    </tbody>
</table>
</body>
</html>

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