<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="com.wbi.util.ParamUtil" %>
<%@ page import="java.util.Map" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="org.slf4j.Logger" %>
<%@ page import="org.slf4j.LoggerFactory" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="weaver.general.StringUtil" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%

    Logger log = LoggerFactory.getLogger("CustomBusiness");
    Map<String, Object> paramMap = ParamUtil.request2Map(request);
    int id = Util.getIntValue(Util.null2String(paramMap.get("id")));
    HashMap<String, String> results = new HashMap<>();
    int requestId = -1;
    int type = -1;
    RecordSet rs = new RecordSet();
    String sql = "select lcbt , sqdlx ,spwhscpdfwj from uf_CCSPDTZ where id = ?";
    rs.executeQuery(sql, id);
    log.info("sql:{}", sql);
    log.info("id:{} ", id);
    if (rs.next()) {
        requestId = rs.getInt("lcbt");
        type = rs.getInt("sqdlx");
    } else {
        results.put("code", "0");
        results.put("msg", "审批单无数据");
        out.print(JSONObject.toJSONString(results));
    }
    log.info("requestId:{}", requestId);
    log.info("type:{}", type);
    //请休审批单PDF附件（qxspdpdffj）中。
    String qxspdpdffj = "";
    String qxspdpdffjXmdh = "";
    //天津银行国内出差审批单附件PDF（tjyxgnccspdfjpdf）中
    String tjyxgnccspdfjpdf = "";
    String tjyxgnccspdfjpdfXmdh = "";
    String errorInfo = "";
    int sqdlx = -1 ;
    ArrayList<String> fields = new ArrayList<>();
    if (6 == type || 7 == type) {
        // 总行差旅行程变更审批单 || 分行差旅行程变更审批单
        rs.executeQuery("select mainid from uf_CCBGJLB_dt1 where ccbgjllc = ?", requestId);
        rs.next();
        String mainid = rs.getString("mainid");
        log.info("mainid:{}", mainid);
        rs.executeQuery("select  ccqqlc ,sqdlx from uf_CCBGJLB where id = ?", mainid);
        rs.next();
        String ccqqlc = rs.getString("ccqqlc");
        sqdlx = rs.getInt("sqdlx");
        log.info("ccqqlc:{}", ccqqlc);
        log.info("sqdlx:{}", sqdlx);

        if (0 == sqdlx) {
            //请休假审批单-总行部门正职
            rs.executeQuery("select sqdlx , spwhscpdfwj ,xmdh from uf_CCSPDTZ where lcbt = ?", ccqqlc);
            rs.next();
            qxspdpdffj = Util.null2String(rs.getString("spwhscpdfwj"));
            String xmdh = Util.null2String(rs.getString("xmdh"));
            qxspdpdffjXmdh = xmdh;
            if (StringUtil.isEmpty(qxspdpdffj)) {

                if (errorInfo.length() > 0) {
                    errorInfo = errorInfo + "," + xmdh;

                } else {
                    errorInfo = xmdh;
                }

            }
            log.info("qxspdpdffj:{}", qxspdpdffj);
        } else if (2 == sqdlx) {
            //请休假审批单-分行行长
            rs.executeQuery("select sqdlx , spwhscpdfwj,xmdh from uf_CCSPDTZ where lcbt = ?", ccqqlc);
            rs.next();
            tjyxgnccspdfjpdf = Util.null2String(rs.getString("spwhscpdfwj"));
            log.info("tjyxgnccspdfjpdf:{}", tjyxgnccspdfjpdf);
            String xmdh = Util.null2String(rs.getString("xmdh"));
            tjyxgnccspdfjpdfXmdh = xmdh;
            if (StringUtil.isEmpty(tjyxgnccspdfjpdf)) {

                if (errorInfo.length() > 0) {
                    errorInfo = errorInfo + "," + xmdh;

                } else {
                    errorInfo = xmdh;
                }
            }
            rs.executeQuery("select glqxjspd from formtable_main_409 where requestid = ?", ccqqlc);
            rs.next();
            String glqxjspd = Util.null2String(rs.getString("glqxjspd"));
            log.info("glqxjspd:{}", glqxjspd);
            rs.executeQuery("select spwhscpdfwj,xmdh from uf_CCSPDTZ where id = ?", glqxjspd);

            rs.next();
            qxspdpdffj = Util.null2String(rs.getString("spwhscpdfwj"));
            String xmdh1 = Util.null2String(rs.getString("xmdh"));
            qxspdpdffjXmdh = xmdh1;
            if (StringUtil.isEmpty(qxspdpdffj)) {

                if (errorInfo.length() > 0) {
                    errorInfo = errorInfo + "," + xmdh1;

                } else {
                    errorInfo = xmdh1;
                }
            }
            log.info("qxspdpdffj:{}", qxspdpdffj);
        }
    } else if (8 == type) {
        tjyxgnccspdfjpdf = Util.null2String(rs.getString("spwhscpdfwj"));
        log.info("tjyxgnccspdfjpdf:{}", tjyxgnccspdfjpdf);
        rs.executeQuery("select glqxjspd from formtable_main_409 where requestid = ?", requestId);
        rs.next();
        String glqxjspd = Util.null2String(rs.getString("glqxjspd"));
        log.info("glqxjspd:{}", glqxjspd);
        rs.executeQuery("select spwhscpdfwj,xmdh from uf_CCSPDTZ where id = ?", glqxjspd);
        rs.next();
        qxspdpdffj = Util.null2String(rs.getString("spwhscpdfwj"));
        String xmdh = Util.null2String(rs.getString("xmdh"));
        qxspdpdffjXmdh = xmdh;
        if (StringUtil.isEmpty(qxspdpdffj)) {

            if (errorInfo.length() > 0) {
                errorInfo = errorInfo + "," + xmdh;

            } else {
                errorInfo = xmdh;
            }
        }
        tjyxgnccspdfjpdf = "";
    } else if (0 == type) {

    }

    // out.print(tjyxgnccspdfjpdf);
    // out.print("<br/>");
    // out.print(qxspdpdffj);

    HashMap<String, Object> result = new HashMap<>();
    HashMap<String, Object> tjyxgnccspdfjpdfspecialobj = new HashMap<>();
    ArrayList<HashMap<String, Object>> tjyxgnccspdfjpdfspecialobjList = new ArrayList<>();
    tjyxgnccspdfjpdfspecialobj.put("id", tjyxgnccspdfjpdf);
    tjyxgnccspdfjpdfspecialobj.put("name", getDocSubject(rs, tjyxgnccspdfjpdf));
    tjyxgnccspdfjpdfspecialobjList.add(tjyxgnccspdfjpdfspecialobj);
    HashMap<String, Object> tjyxgnccspdfjpdfobj = new HashMap<>();
    tjyxgnccspdfjpdfobj.put("value", tjyxgnccspdfjpdf);
    tjyxgnccspdfjpdfobj.put("specialobj", tjyxgnccspdfjpdfspecialobjList);
    result.put("tjyxgnccspdfjpdf", tjyxgnccspdfjpdfobj);
    HashMap<String, Object> qxspdpdffjspecialobj = new HashMap<>();
    ArrayList<HashMap<String, Object>> qxspdpdffjspecialobjList = new ArrayList<>();
    qxspdpdffjspecialobj.put("id", qxspdpdffj);
    qxspdpdffjspecialobj.put("name", getDocSubject(rs, qxspdpdffj));
    qxspdpdffjspecialobjList.add(qxspdpdffjspecialobj);
    HashMap<String, Object> qxspdpdffjobj = new HashMap<>();
    qxspdpdffjobj.put("value", qxspdpdffj);
    qxspdpdffjobj.put("specialobj", qxspdpdffjspecialobjList);
    result.put("qxspdpdffj", qxspdpdffjobj);
    result.put("errorInfo", errorInfo);
    result.put("errorCode", errorInfo.length() > 0 ? "1" : "0");
    result.put("type", type);
    result.put("sqdlx", sqdlx);
    result.put("qxspdpdffjXmdh", qxspdpdffjXmdh);
    result.put("tjyxgnccspdfjpdfXmdh", tjyxgnccspdfjpdfXmdh);
    out.print(JSONObject.toJSONString(result));


%>


<%!
    private boolean isEmpty(String str) {
        if ("".equals(str) || "(null)".equals(str) || str == null) {
            return true;
        } else {
            return false;
        }
    }

    private int getwfid(int requestId, RecordSet rs) {
        if (requestId <= 0) {
            return -1;
        }
        String sql = "select WORKFLOWID from WORKFLOW_REQUESTBASE where REQUESTID = ?";
        rs.executeQuery(sql, requestId);
        if (rs.next()) {
            return rs.getInt(0);
        } else {
            return -1;
        }
    }

    private String getDocSubject(RecordSet rs, String docid) {
        if (StringUtil.isEmpty(docid)) {
            return "";
        }
        String sql = "select DOCSUBJECT from DOCDETAIL where ID = ?";
        rs.executeQuery(sql, docid);
        if (rs.next()) {
            return rs.getString("DOCSUBJECT");
        } else {
            return "";
        }
    }


%>
