package com.engine.custom.archives.workflow.biz.requestForm;

import com.api.doc.detail.util.DocSecretLevelUtil;
import com.engine.hrm.biz.HrmClassifiedProtectionBiz;
import com.engine.workflow.biz.requestForm.RequestSecLevelBiz;
import com.engine.workflow.biz.requestForm.WfToDocBiz;
import oracle.sql.CLOB;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.ConnStatement;
import weaver.conn.RecordSet;
import weaver.docs.DocDetailLog;
import weaver.docs.category.DocTreeDocFieldComInfo;
import weaver.docs.docs.DocManager;
import weaver.docs.docs.DocViewer;
import weaver.general.BaseBean;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.workflow.request.RequestManager;

import java.io.Writer;
import java.util.ArrayList;
import java.util.Map;

public class SaveDocDetailBizCus extends BaseBean {
    public static Logger log = LoggerFactory.getLogger("Archives");
    private int docid;
    private int maincategory;
    private int subcategory;
    private int seccategory;
    private int doclangurage;
    private String docapprovable;
    private String docreplyable;
    private String isreply;
    private int replydocid;
    private String docsubject;
    private String docpublishtype;
    private int itemid;
    private int itemmaincategoryid;
    private int hrmresid;
    private int crmid;
    private int projectid;
    private int financeid;
    private int doccreaterid;
    private int docdepartmentid;
    private String doccreatedate;
    private String doccreatetime;
    private int doclastmoduserid;
    private String doclastmoddate;
    private String doclastmodtime;
    private int docapproveuserid;
    private String docapprovedate;
    private String docapprovetime;
    private int docarchiveuserid;
    private String docarchivedate;
    private String docarchivetime;
    private String docstatus;
    private String parentids;
    private int assetid;
    private int ownerid;
    private String keyword;
    private int accessorycount;  //附件总数
    private int replaydoccount;
    private String usertype;
    private int doctype;
    private String cancopy;
    private String canremind;
    private String orderable;
    private String docextendname;
    private String doccode;
    private int docedition;
    private int docsmalledition;
    private int doceditionid;
    private int ishistory;
    private int approveType;
    private int maindoc;
    private int readoptercanprint;
    private int docvaliduserid;
    private String docvaliddate;
    private String docvalidtime;
    private String invalidationdate;
    private String docCreaterType;
    private String docLastModUserType;
    private String docApproveUserType;
    private String docValidUserType;
    private String docInvalUserType;
    private String docArchiveUserType;
    private String docCancelUserType;
    private String docPubUserType;
    private String docReopenUserType;
    private String ownerType;
    private int canPrintedNum;
    private String fromworkflow;
    private String doccontent = "";
    private int docowner;
    private String clientIp;

    public void setDocsmalledition(int docsmalledition) {
        this.docsmalledition = docsmalledition;
    }

    public void setDocid(int docid) {
        this.docid = docid;
    }

    public void setMaincategory(int maincategory) {
        this.maincategory = maincategory;
    }

    public void setSubcategory(int subcategory) {
        this.subcategory = subcategory;
    }

    public void setSeccategory(int seccategory) {
        this.seccategory = seccategory;
    }

    public void setDoclangurage(int doclangurage) {
        this.doclangurage = doclangurage;
    }

    public void setDocapprovable(String docapprovable) {
        this.docapprovable = docapprovable;
    }

    public void setDocreplyable(String docreplyable) {
        this.docreplyable = docreplyable;
    }

    public void setIsreply(String isreply) {
        this.isreply = isreply;
    }

    public void setReplydocid(int replydocid) {
        this.replydocid = replydocid;
    }

    public void setDocsubject(String docsubject) {
        this.docsubject = docsubject;
    }

    public void setDocpublishtype(String docpublishtype) {
        this.docpublishtype = docpublishtype;
    }

    public void setItemid(int itemid) {
        this.itemid = itemid;
    }

    public void setItemmaincategoryid(int itemmaincategoryid) {
        this.itemmaincategoryid = itemmaincategoryid;
    }

    public void setHrmresid(int hrmresid) {
        this.hrmresid = hrmresid;
    }

    public void setCrmid(int crmid) {
        this.crmid = crmid;
    }

    public void setProjectid(int projectid) {
        this.projectid = projectid;
    }

    public void setFinanceid(int financeid) {
        this.financeid = financeid;
    }

    public void setDoccreaterid(int doccreaterid) {
        this.doccreaterid = doccreaterid;
    }

    public void setDocdepartmentid(int docdepartmentid) {
        this.docdepartmentid = docdepartmentid;
    }

    public void setDoccreatedate(String doccreatedate) {
        this.doccreatedate = doccreatedate;
    }

    public void setDoccreatetime(String doccreatetime) {
        this.doccreatetime = doccreatetime;
    }

    public void setDoclastmoduserid(int doclastmoduserid) {
        this.doclastmoduserid = doclastmoduserid;
    }

    public void setDoclastmoddate(String doclastmoddate) {
        this.doclastmoddate = doclastmoddate;
    }

    public void setDoclastmodtime(String doclastmodtime) {
        this.doclastmodtime = doclastmodtime;
    }

    public void setDocapproveuserid(int docapproveuserid) {
        this.docapproveuserid = docapproveuserid;
    }

    public void setDocapprovedate(String docapprovedate) {
        this.docapprovedate = docapprovedate;
    }

    public void setDocapprovetime(String docapprovetime) {
        this.docapprovetime = docapprovetime;
    }

    public void setDocarchiveuserid(int docarchiveuserid) {
        this.docarchiveuserid = docarchiveuserid;
    }

    public void setDocarchivedate(String docarchivedate) {
        this.docarchivedate = docarchivedate;
    }

    public void setDocarchivetime(String docarchivetime) {
        this.docarchivetime = docarchivetime;
    }

    public void setDocstatus(String docstatus) {
        this.docstatus = docstatus;
    }

    public void setParentids(String parentids) {
        this.parentids = parentids;
    }

    public void setAssetid(int assetid) {
        this.assetid = assetid;
    }

    public void setOwnerid(int ownerid) {
        this.ownerid = ownerid;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public void setAccessorycount(int accessorycount) {
        this.accessorycount = accessorycount;
    }

    public void setReplaydoccount(int replaydoccount) {
        this.replaydoccount = replaydoccount;
    }

    public void setUsertype(String usertype) {
        this.usertype = usertype;
    }

    public void setDoctype(int doctype) {
        this.doctype = doctype;
    }

    public void setCancopy(String cancopy) {
        this.cancopy = cancopy;
    }

    public void setCanremind(String canremind) {
        this.canremind = canremind;
    }

    public void setOrderable(String orderable) {
        this.orderable = orderable;
    }

    public void setDocextendname(String docextendname) {
        this.docextendname = docextendname;
    }

    public void setDoccode(String doccode) {
        this.doccode = doccode;
    }

    public void setDocedition(int docedition) {
        this.docedition = docedition;
    }

    public void setDoceditionid(int doceditionid) {
        this.doceditionid = doceditionid;
    }

    public void setIshistory(int ishistory) {
        this.ishistory = ishistory;
    }

    public void setApproveType(int approveType) {
        this.approveType = approveType;
    }

    public void setMaindoc(int maindoc) {
        this.maindoc = maindoc;
    }

    public void setReadoptercanprint(int readoptercanprint) {
        this.readoptercanprint = readoptercanprint;
    }

    public void setDocvaliduserid(int docvaliduserid) {
        this.docvaliduserid = docvaliduserid;
    }

    public void setDocvaliddate(String docvaliddate) {
        this.docvaliddate = docvaliddate;
    }

    public void setDocvalidtime(String docvalidtime) {
        this.docvalidtime = docvalidtime;
    }

    public void setInvalidationdate(String invalidationdate) {
        this.invalidationdate = invalidationdate;
    }

    public void setDocCreaterType(String docCreaterType) {
        this.docCreaterType = docCreaterType;
    }

    public void setDocLastModUserType(String docLastModUserType) {
        this.docLastModUserType = docLastModUserType;
    }

    public void setDocApproveUserType(String docApproveUserType) {
        this.docApproveUserType = docApproveUserType;
    }

    public void setDocValidUserType(String docValidUserType) {
        this.docValidUserType = docValidUserType;
    }

    public void setDocInvalUserType(String docInvalUserType) {
        this.docInvalUserType = docInvalUserType;
    }

    public void setDocArchiveUserType(String docArchiveUserType) {
        this.docArchiveUserType = docArchiveUserType;
    }

    public void setDocCancelUserType(String docCancelUserType) {
        this.docCancelUserType = docCancelUserType;
    }

    public void setDocPubUserType(String docPubUserType) {
        this.docPubUserType = docPubUserType;
    }

    public void setDocReopenUserType(String docReopenUserType) {
        this.docReopenUserType = docReopenUserType;
    }

    public void setOwnerType(String ownerType) {
        this.ownerType = ownerType;
    }

    public void setCanPrintedNum(int canPrintedNum) {
        this.canPrintedNum = canPrintedNum;
    }

    public void setFromworkflow(String fromworkflow) {
        this.fromworkflow = fromworkflow;
    }

    public void setDoccontent(String doccontent) {
        this.doccontent = doccontent;
    }

    public void setDocowner(int docowner) {
        this.docowner = docowner;
    }

    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }

    /*
     * 保存文档，返回docid
     */
    public int saveDoc(String requestid, RequestManager requestManager, WfToDocBizCus wfbiz, String userid) {
        ConnStatement statement  = new ConnStatement();
        DocDetailLog dlog = new DocDetailLog();

        boolean isoracle = Util.null2String(statement.getOrgindbtype()).equals("oracle");
        String sql = "";
        if (isoracle) {

            sql = "insert into DocDetail("
                    + "id,maincategory,subcategory,seccategory,doclangurage,"
                    + "docapprovable,docreplyable,isreply,replydocid,docsubject,"
                    + "docpublishtype,itemid,itemmaincategoryid,hrmresid,crmid,"
                    + "projectid,financeid,doccreaterid,docdepartmentid,doccreatedate,"
                    + "doccreatetime,doclastmoduserid,doclastmoddate,doclastmodtime,docapproveuserid,"
                    + "docapprovedate,docapprovetime,docarchiveuserid,docarchivedate,docarchivetime,"
                    + "docstatus,parentids,assetid,ownerid,keyword,"
                    + "accessorycount,replaydoccount,usertype,doctype,cancopy,"
                    + "canremind,orderable,docextendname"
                    +

                    ",doccode,docedition,doceditionid,ishistory,approveType,maindoc,"
                    + "readoptercanprint,docvaliduserid,docvaliddate,docvalidtime,invalidationdate"
                    +

                    ",docCreaterType,docLastModUserType,docApproveUserType,docValidUserType,docInvalUserType"
                    + ",docArchiveUserType,docCancelUserType,docPubUserType,docReopenUserType,ownerType"
                    + ",canPrintedNum,fromworkflow,docsmalledition" +

                    ") values(" + "?,?,?,?,?,?,?,?,?,?,"
                    + "?,?,?,?,?,?,?,?,?,?," + "?,?,?,?,?,?,?,?,?,?,"
                    + "?,?,?,?,?,?,?,?,?,?," + "?,?,?" +

                    ",?,?,?,?,?,?" + ",?,?,?,?,?" +

                    ",?,?,?,?,?" + ",?,?,?,?,?" + ",?,?,?" +

                    ")";

            try {

                statement.setStatementSql(sql);
                statement.setInt(1, docid);
                statement.setInt(2, maincategory);
                statement.setInt(3, subcategory);
                statement.setInt(4, seccategory);
                statement.setInt(5, doclangurage);
                statement.setString(6, docapprovable);
                statement.setString(7, docreplyable);
                statement.setString(8, isreply);
                statement.setInt(9, replydocid);
                statement.setString(10, docsubject);
                statement.setString(11, docpublishtype);
                statement.setInt(12, itemid);
                statement.setInt(13, itemmaincategoryid);
                statement.setInt(14, hrmresid);
                statement.setInt(15, crmid);
                statement.setInt(16, projectid);
                statement.setInt(17, financeid);
                statement.setInt(18, doccreaterid);
                statement.setInt(19, docdepartmentid);
                statement.setString(20, doccreatedate);
                statement.setString(21, doccreatetime);
                statement.setInt(22, doclastmoduserid);
                statement.setString(23, doclastmoddate);
                statement.setString(24, doclastmodtime);
                statement.setInt(25, docapproveuserid);
                statement.setString(26, docapprovedate);
                statement.setString(27, docapprovetime);
                statement.setInt(28, docarchiveuserid);
                statement.setString(29, docarchivedate);
                statement.setString(30, docarchivetime);
                statement.setString(31, docstatus);
                statement.setString(32, parentids);

                statement.setInt(33, assetid);
                statement.setInt(34, ownerid);
                statement.setString(35, keyword);
                statement.setInt(36, accessorycount);
                statement.setInt(37, replaydoccount);
                statement.setString(38, docCreaterType);

                statement.setInt(39, doctype);
                statement.setString(40, cancopy);
                statement.setString(41, canremind);
                statement.setString(42, orderable);
                statement.setString(43, docextendname);
                statement.setString(44, doccode);

                statement.setInt(45, docedition);
                statement.setInt(46, doceditionid);
                statement.setInt(47, ishistory);
                statement.setInt(48, approveType);
                statement.setInt(49, maindoc);
                statement.setInt(50, readoptercanprint);
                statement.setInt(51, docvaliduserid);

                statement.setString(52, docvaliddate);
                statement.setString(53, docvalidtime);

                statement.setString(54, invalidationdate);

                statement.setString(55, docCreaterType);
                statement.setString(56, docLastModUserType);
                statement.setString(57, docApproveUserType);
                statement.setString(58, docValidUserType);
                statement.setString(59, docInvalUserType);
                statement.setString(60, docArchiveUserType);
                statement.setString(61, docCancelUserType);
                statement.setString(62, docPubUserType);
                statement.setString(63, docReopenUserType);
                statement.setString(64, ownerType);
                statement.setInt(65, canPrintedNum);
                statement.setString(66, fromworkflow);
                statement.setInt(67, docsmalledition);

                statement.executeUpdate();

                sql = "insert into DocDetailContent (docid, doccontent) values(?,empty_clob()) ";
                statement.setStatementSql(sql);
                statement.setInt(1, docid);
                statement.executeUpdate();

                sql = "select doccontent from DocDetailContent where docid = "
                        + docid;
                statement.setStatementSql(sql, false);
                statement.executeQuery();
                statement.next();
                CLOB theclob = statement.getClob(1);

                String doccontenttemp = doccontent;
                char[] contentchar = doccontenttemp.toCharArray();
                Writer contentwrite = theclob.getCharacterOutputStream();
                contentwrite.write(contentchar);
                contentwrite.flush();
                contentwrite.close();

                dlog.resetParameter();
                dlog.setDocId(docid);
                dlog.setDocSubject(docsubject);
                dlog.setOperateType("1");
                dlog.setOperateUserid(docowner);
                dlog.setUsertype(docCreaterType);
                dlog.setClientAddress(clientIp);
                dlog.setDocCreater(docowner);
                dlog.setCreatertype(docCreaterType);
                dlog.setDocLogInfo();

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    statement.close();
                } catch (Exception ex) {
                }
            }

        } else if((statement.getDBType()).equals("postgresql")||(statement.getDBType()).equals("mysql")||Util.null2String(statement.getOrgindbtype()).equals("dm")||Util.null2String(statement.getOrgindbtype()).equals("st")||Util.null2String(statement.getOrgindbtype()).equals("jc")||Util.null2String(statement.getOrgindbtype()).equals("gs")){
            sql = "insert into DocDetail("
                    + "id,maincategory,subcategory,seccategory,doclangurage,"
                    + "docapprovable,docreplyable,isreply,replydocid,docsubject,"
                    + "docpublishtype,itemid,itemmaincategoryid,hrmresid,crmid,"
                    + "projectid,financeid,doccreaterid,docdepartmentid,doccreatedate,"
                    + "doccreatetime,doclastmoduserid,doclastmoddate,doclastmodtime,docapproveuserid,"
                    + "docapprovedate,docapprovetime,docarchiveuserid,docarchivedate,docarchivetime,"
                    + "docstatus,parentids,assetid,ownerid,keyword,"
                    + "accessorycount,replaydoccount,usertype,doctype,cancopy,"
                    + "canremind,orderable,docextendname"
                    +

                    ",doccode,docedition,doceditionid,ishistory,approveType,maindoc,"
                    + "readoptercanprint,docvaliduserid,docvaliddate,docvalidtime,invalidationdate"
                    +

                    ",docCreaterType,docLastModUserType,docApproveUserType,docValidUserType,docInvalUserType"
                    + ",docArchiveUserType,docCancelUserType,docPubUserType,docReopenUserType,ownerType"
                    + ",canPrintedNum,fromworkflow,docsmalledition" +

                    ") values(" + "?,?,?,?,?,?,?,?,?,?,"
                    + "?,?,?,?,?,?,?,?,?,?," + "?,?,?,?,?,?,?,?,?,?,"
                    + "?,?,?,?,?,?,?,?,?,?," + "?,?,?" +

                    ",?,?,?,?,?,?" + ",?,?,?,?,?" +

                    ",?,?,?,?,?" + ",?,?,?,?,?" + ",?,?,?" +

                    ")";

            try {

                statement.setStatementSql(sql);
                statement.setInt(1, docid);
                statement.setInt(2, maincategory);
                statement.setInt(3, subcategory);
                statement.setInt(4, seccategory);
                statement.setInt(5, doclangurage);
                statement.setString(6, docapprovable);
                statement.setString(7, docreplyable);
                statement.setString(8, isreply);
                statement.setInt(9, replydocid);
                statement.setString(10, docsubject);
                statement.setString(11, docpublishtype);
                statement.setInt(12, itemid);
                statement.setInt(13, itemmaincategoryid);
                statement.setInt(14, hrmresid);
                statement.setInt(15, crmid);
                statement.setInt(16, projectid);
                statement.setInt(17, financeid);
                statement.setInt(18, doccreaterid);
                statement.setInt(19, docdepartmentid);
                statement.setString(20, doccreatedate);
                statement.setString(21, doccreatetime);
                statement.setInt(22, doclastmoduserid);
                statement.setString(23, doclastmoddate);
                statement.setString(24, doclastmodtime);
                statement.setInt(25, docapproveuserid);
                statement.setString(26, docapprovedate);
                statement.setString(27, docapprovetime);
                statement.setInt(28, docarchiveuserid);
                statement.setString(29, docarchivedate);
                statement.setString(30, docarchivetime);
                statement.setString(31, docstatus);
                statement.setString(32, parentids);

                statement.setInt(33, assetid);
                statement.setInt(34, ownerid);
                statement.setString(35, keyword);
                statement.setInt(36, accessorycount);
                statement.setInt(37, replaydoccount);
                statement.setString(38, docCreaterType);

                statement.setInt(39, doctype);
                statement.setString(40, cancopy);
                statement.setString(41, canremind);
                statement.setString(42, orderable);
                statement.setString(43, docextendname);
                statement.setString(44, doccode);

                statement.setInt(45, docedition);
                statement.setInt(46, doceditionid);
                statement.setInt(47, ishistory);
                statement.setInt(48, approveType);
                statement.setInt(49, maindoc);
                statement.setInt(50, readoptercanprint);
                statement.setInt(51, docvaliduserid);

                statement.setString(52, docvaliddate);
                statement.setString(53, docvalidtime);

                statement.setString(54, invalidationdate);

                statement.setString(55, docCreaterType);
                statement.setString(56, docLastModUserType);
                statement.setString(57, docApproveUserType);
                statement.setString(58, docValidUserType);
                statement.setString(59, docInvalUserType);
                statement.setString(60, docArchiveUserType);
                statement.setString(61, docCancelUserType);
                statement.setString(62, docPubUserType);
                statement.setString(63, docReopenUserType);
                statement.setString(64, ownerType);
                statement.setInt(65, canPrintedNum);
                statement.setString(66, fromworkflow);
                statement.setInt(67, docsmalledition);

                statement.executeUpdate();

                sql = "insert into DocDetailContent (docid, doccontent) values(?,?) ";
                statement.setStatementSql(sql);
                statement.setInt(1, docid);
                statement.setString(2, doccontent);
                statement.executeUpdate();

                dlog.resetParameter();
                dlog.setDocId(docid);
                dlog.setDocSubject(docsubject);
                dlog.setOperateType("1");
                dlog.setOperateUserid(docowner);
                dlog.setUsertype(docCreaterType);
                dlog.setClientAddress(clientIp);
                dlog.setDocCreater(docowner);
                dlog.setCreatertype(docCreaterType);
                dlog.setDocLogInfo();

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    statement.close();
                } catch (Exception ex) {
                }
            }

        }else{
            sql = "insert into DocDetail("
                    + "id,maincategory,subcategory,seccategory,doclangurage,"
                    + "docapprovable,docreplyable,isreply,replydocid,docsubject,"
                    + "doccontent,docpublishtype,itemid,itemmaincategoryid,hrmresid,"
                    + "crmid,projectid,financeid,doccreaterid,docdepartmentid,"
                    + "doccreatedate,doccreatetime,doclastmoduserid,doclastmoddate,doclastmodtime,"
                    + "docapproveuserid,docapprovedate,docapprovetime,docarchiveuserid,docarchivedate,"
                    + "docarchivetime,docstatus,parentids,assetid,ownerid,"
                    + "keyword,accessorycount,replaydoccount,usertype,doctype,"
                    + "cancopy,canremind,orderable,docextendname"
                    +

                    ",doccode,docedition,doceditionid,ishistory,approveType,maindoc,"
                    + "readoptercanprint,docvaliduserid,docvaliddate,docvalidtime,invalidationdate"
                    +

                    ",docCreaterType,docLastModUserType,docApproveUserType,docValidUserType,docInvalUserType"
                    + ",docArchiveUserType,docCancelUserType,docPubUserType,docReopenUserType,ownerType"
                    + ",canPrintedNum,fromworkflow,docsmalledition" +

                    ") values(" + "?,?,?,?,?,?,?,?,?,?,"
                    + "?,?,?,?,?,?,?,?,?,?," + "?,?,?,?,?,?,?,?,?,?,"
                    + "?,?,?,?,?,?,?,?,?,?," + "?,?,?,?" +

                    ",?,?,?,?,?,?" + ",?,?,?,?,?" +

                    ",?,?,?,?,?" + ",?,?,?,?,?" + ",?,?,?" +

                    ")";

            try {

                statement.setStatementSql(sql);
                statement.setInt(1, docid);
                statement.setInt(2, maincategory);
                statement.setInt(3, subcategory);
                statement.setInt(4, seccategory);
                statement.setInt(5, doclangurage);
                statement.setString(6, docapprovable);
                statement.setString(7, docreplyable);
                statement.setString(8, isreply);
                statement.setInt(9, replydocid);
                statement.setString(10, docsubject);
                statement.setString(11, doccontent);
                statement.setString(12, docpublishtype);
                statement.setInt(13, itemid);
                statement.setInt(14, itemmaincategoryid);
                statement.setInt(15, hrmresid);
                statement.setInt(16, crmid);
                statement.setInt(17, projectid);
                statement.setInt(18, financeid);
                statement.setInt(19, doccreaterid);
                statement.setInt(20, docdepartmentid);
                statement.setString(21, doccreatedate);
                statement.setString(22, doccreatetime);
                statement.setInt(23, doclastmoduserid);
                statement.setString(24, doclastmoddate);
                statement.setString(25, doclastmodtime);
                statement.setInt(26, docapproveuserid);
                statement.setString(27, docapprovedate);
                statement.setString(28, docapprovetime);
                statement.setInt(29, docarchiveuserid);
                statement.setString(30, docarchivedate);
                statement.setString(31, docarchivetime);
                statement.setString(32, docstatus);
                statement.setString(33, parentids);

                statement.setInt(34, assetid);
                statement.setInt(35, ownerid);
                statement.setString(36, keyword);
                statement.setInt(37, accessorycount);
                statement.setInt(38, replaydoccount);
                statement.setString(39, docCreaterType);
                statement.setInt(40, doctype);
                statement.setString(41, cancopy);
                statement.setString(42, canremind);
                statement.setString(43, orderable);
                statement.setString(44, docextendname);

                statement.setString(45, doccode);
                statement.setInt(46, docedition);
                statement.setInt(47, doceditionid);
                statement.setInt(48, ishistory);
                statement.setInt(49, approveType);

                statement.setInt(50, maindoc);
                statement.setInt(51, readoptercanprint);
                statement.setInt(52, docvaliduserid);
                statement.setString(53, docvaliddate);
                statement.setString(54, docvalidtime);

                statement.setString(55, invalidationdate);

                statement.setString(56, docCreaterType);
                statement.setString(57, docLastModUserType);
                statement.setString(58, docApproveUserType);
                statement.setString(59, docValidUserType);
                statement.setString(60, docInvalUserType);
                statement.setString(61, docArchiveUserType);
                statement.setString(62, docCancelUserType);
                statement.setString(63, docPubUserType);
                statement.setString(64, docReopenUserType);
                statement.setString(65, ownerType);
                statement.setInt(66, canPrintedNum);
                statement.setString(67, fromworkflow);
                statement.setInt(68, docsmalledition);

                statement.executeUpdate();

                dlog.resetParameter();
                dlog.setDocId(docid);
                dlog.setDocSubject(docsubject);
                dlog.setOperateType("1");
                dlog.setOperateUserid(docowner);
                dlog.setUsertype(docCreaterType);
                dlog.setClientAddress(clientIp);
                dlog.setDocCreater(docowner);
                dlog.setCreatertype(docCreaterType);
                dlog.setDocLogInfo();

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    statement.close();
                } catch (Exception ex) {
                }
            }
        }


        // 保存文档属性
        saveDocProp(docid,requestid,requestManager,wfbiz);

        try {
            //保存文档信息至虚拟目录
            RecordSet rsDummyDoc = new RecordSet();
            String dummycata = "";
            String strSql="select defaultDummyCata from DocSecCategory where id="+seccategory;
            rsDummyDoc.executeSql(strSql);
            if(rsDummyDoc.next()) dummycata = Util.null2String(rsDummyDoc.getString("defaultDummyCata"));

            if(dummycata!=null && !"".equals(dummycata)){
                ArrayList dummyCataList=Util.TokenizerString(dummycata,",");
                for(int i=0;i<dummyCataList.size();i++){
                    String strDummy=(String)dummyCataList.get(i);
					int intDummy = Util.getIntValue(strDummy, -1);
                    if(!"".equals(strDummy) && intDummy > 0){
                        String importdate= TimeUtil.getCurrentDateString();
                        String importtime=TimeUtil.getOnlyCurrentTimeString();
                        DocTreeDocFieldComInfo ddfc = new DocTreeDocFieldComInfo();
                        if(!ddfc.isHaveSameOne(strDummy,""+docid)) {
                            strSql="insert into DocDummyDetail(catelogid,docid,importdate,importtime) values ("+strDummy+","+docid+",'"+importdate+"','"+importtime+"')";
                            rsDummyDoc.executeSql(strSql);
                        }
                    }
                }
            }
        }catch(Exception ex) {
            log.error("添加文档信息至虚拟目录出错：" + ex);
        }

        //更新文档密级
        if (HrmClassifiedProtectionBiz.isOpenClassification()) {
            Map<String, Object> secInfo = new RequestSecLevelBiz().getSecInfoByRequestId(Util.getIntValue(requestid));
            String secLevel = Util.null2String(secInfo.get("secLevel"));
            String secValidity = Util.null2String(secInfo.get("secValidity"));
            new DocSecretLevelUtil().modifyDocSecretLevel(docid+"", secLevel, secValidity);
        }

        // 添加文档共享信息
        DocManager DocManager = new DocManager();
        DocManager.setIsreply("0");
        DocManager.setId(docid);
        DocManager.setSeccategory(seccategory);
        DocManager.setUserid(docowner);
        DocManager.setUsertype("1");
        try {
            DocManager.AddShareInfo();
        } catch (Exception e) {
            log.error("添加文档共享信息出错：" + e);
        }
        try {
            new DocViewer().setDocShareByDoc("" + docid);
        } catch (Exception e) {
            log.error("添加文档共享信息出错：" + e);
        }
        return docid;
    }

    /**
     * 保存文档属性
     * @param docid
     * @return
     */
    public boolean saveDocProp(int docid, String requestid, RequestManager requestManager, WfToDocBizCus wfbiz){
        boolean success = true;
        String docids = docid+"";
        try{
            log.error("saveDocProp:" + docid +" "+requestid);
            RequestDocPropManagerCus requestDocPropManager=new RequestDocPropManagerCus(wfbiz);
            requestDocPropManager.changeDocProp(requestManager,docids);
        }catch (Exception e) {
            success = false;
            log.error("RequestDocPropManagerCus Error:requestid="+requestid+"###docids="+docids);
            log.error(e.getMessage());
        }
        log.error("success:"+success);
        return success;

    }
}
