package weaver.interfaces.secondev.zjpicc;

import weaver.conn.RecordSet;
import weaver.file.ImageFileManager;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.hrm.company.CompanyComInfo;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.soa.workflow.request.*;

import java.io.*;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;

public class DoDataRunnable  extends BaseBean implements Runnable{
    BaseBean bb = new BaseBean();
    RequestInfo requestInfo = null;


    public DoDataRunnable(RequestInfo requestInfo){
        this.requestInfo=requestInfo;
    }

    @Override
    public void run() {
        writeLog("start----------");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        writeLog("1分钟 start===============");
        //uf_bddsxqd  变动事项清单
        // bdsx
        // sxsy
        // sfxyqxdz
        RecordSet rs = new RecordSet();
        RecordSet rs2 = new RecordSet();
        RecordSet rs3 = new RecordSet();
        String requestid = Util.null2String(requestInfo.getRequestid());
        String workflowid = requestInfo.getWorkflowid();
        String tableName = requestInfo.getRequestManager().getBillTableName().toLowerCase();
        Map mainTableDataMap = new HashMap();
        Property[] props = requestInfo.getMainTableInfo().getProperty();
        for (int i = 0; i < props.length; i++) {
            String fieldname = props[i].getName().toLowerCase();
            String fieldval = Util.null2String(props[i].getValue());
            mainTableDataMap.put(fieldname, fieldval);
        }

        DetailTable dtltable = requestInfo.getDetailTableInfo().getDetailTable(0);
        Row[] rows = dtltable.getRow();
        List sublist = new ArrayList();
        for (int i = 0; i < rows.length; i++) {
            Row row = rows[i];
            Map onerow = new HashMap();
            sublist.add(onerow);
            Cell[] cells = row.getCell();
            for (int j = 0; j < cells.length; j++) {
                Cell cell = cells[j];
                onerow.put(cell.getName().toLowerCase(), Util.null2String(cell.getValue()));
            }
        }

        //是否需要权限调整
        String sfxyqxtz = "";
        String bdsxId = Util.null2String((String) mainTableDataMap.get("bdsx"));//人事通知事项
        String YLCCJR = Util.null2String((String) mainTableDataMap.get("nigaoren"));//nigaoren
        String YLCCJRQ =  Util.null2String((String) mainTableDataMap.get("ngrq"));//nigaoren
        String YLCCJGS =  Util.null2String((String) mainTableDataMap.get("nggs"));//nigaoren
        if("".equals(YLCCJGS)){
            YLCCJGS = "-1";
        }

        rs.execute("select sxsy,sfxyqxdz,bdsx from  uf_bdsxqd where id=" + bdsxId);
        writeLog("select sxsy,,bdsx from  uf_bdsxqd where id=" + bdsxId);
        rs.next();
        String sfxyqxdz = Util.null2String(rs.getString("sfxyqxdz"));//0 是 1
        String RSTZSXMC = Util.null2String(rs.getString("bdsx"));

        writeLog("sfxyqxdz="+sfxyqxdz);
        //
        if ("0".equals(sfxyqxdz)){

            for (int i = 0; i < sublist.size(); i++) {
                Map onerow = (Map) sublist.get(i);
                String xm = Util.null2String((String) onerow.get("xm"));
                String sjywtx = Util.null2String((String) onerow.get("sjywtx"));
                String xmst0 = Util.null2String((String) onerow.get("xmst0"));
                String hrcode = Util.null2String((String) onerow.get("hrcode"));
                String gsc = docompany(Util.null2String((String) onerow.get("gsc")));
                String gscname = "";
                SubCompanyComInfo companyComInfo = new SubCompanyComInfo();
                gscname = companyComInfo.getSubCompanyname(gsc);

                String bmc = Util.null2String((String) onerow.get("bmc"));
                String bmz = Util.null2String((String) onerow.get("bmz"));
                String bmzname = "";
                String bmcname = "";
                DepartmentComInfo departmentComInfo = new DepartmentComInfo();
                try {
                    bmcname = departmentComInfo.getDepartmentName(bmc);
                    bmzname = departmentComInfo.getDepartmentName(bmz);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }

                String gszname = "";
                String gsz = "";
                String tmpgsz = Util.null2String((String) onerow.get("gsz"));
                if(!"".equals(tmpgsz)) {
                    gsz = docompany(tmpgsz);
                    gszname = companyComInfo.getSubCompanyname(gsz);
                }
 


                String qxq = Util.null2String((String) onerow.get("qxq"));
                String qxz = Util.null2String((String) onerow.get("qxz"));
                String dzhgw = Util.null2String((String) onerow.get("dzhgw"));
                String dzhzw = Util.null2String((String) onerow.get("dzhzw"));
                String dzhzj = Util.null2String((String) onerow.get("dzhzj"));
                String grsqzs = Util.null2String((String) onerow.get("grsqzs"));
                String bz = Util.null2String((String) onerow.get("bz"));




                writeLog("gsc------------>"+gsc);
                writeLog("gsz------------>"+gsz);

                String xmzw = "";
                try {
                    ResourceComInfo resourceComInfo = new ResourceComInfo();
                    xmzw = resourceComInfo.getLastname(xm);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }

                String wheresql = " and 1=1";
                String SFHRTXRY = "";
                String SFKJTXRY = "";
                String SFLPTXRY = "";
                String sflptxryVal = "";


                if ("2".equals(sjywtx)) {
                    SFLPTXRY = "是";
                    sflptxryVal = "0";
                    wheresql = wheresql + " and (sfhrtxry=1 or sfkjtxry='' or sfkjtxry is null)   and (sfkjtxry=1 or sfkjtxry='' or sfkjtxry is null)  ";
                }else{

                    if ("0".equals(sjywtx)) {
//                        wheresql = wheresql + " and (sfhrtxry=0 or sfhrtxry='' or sfhrtxry is null or sfhrtxry=1)  and (sfkjtxry=1 or sfkjtxry='' or sfkjtxry is null) ";
//                        SFHRTXRY = "是";
                        wheresql = wheresql + " and (sfkjtxry=1 or sfkjtxry='' or sfkjtxry is null) ";
                        SFHRTXRY = "是";

                    } else  if ("1".equals(sjywtx)) {
//                        wheresql = wheresql + " and (sfkjtxry=0 or sfkjtxry='' or sfkjtxry is null)";
                        wheresql = wheresql + " and (sfhrtxry=1 or sfkjtxry='' or sfkjtxry is null)";
                        SFKJTXRY = "是";
                    } else if ("0,1".equals(sjywtx)){
               //          wheresql = wheresql + " and (sfhrtxry=0 or sfhrtxry='' or sfhrtxry is null or sfhrtxry=1)";
                        SFHRTXRY = "是";
               //         wheresql = wheresql + " and (sfkjtxry=0 or sfkjtxry='' or sfkjtxry is null or sfkjtxry=1)";
                        SFKJTXRY = "是";
                    }  else if ("0,2".equals(sjywtx)){
                        SFLPTXRY = "是";
                        sflptxryVal = "0";
                        SFHRTXRY = "是";
                        wheresql = wheresql + " and (sfkjtxry=1 or sfkjtxry='' or sfkjtxry is null)  ";
                    }else{
                        wheresql = wheresql + " and (sfhrtxry=1 or sfkjtxry='' or sfkjtxry is null)   and (sfkjtxry=1 or sfkjtxry='' or sfkjtxry is null) ";

                    }
                }



                String sql = "select  xtfl,xtmc,czf,sfhrtxry,sfkjtxry,qxdzjgf,qxdzsx  from uf_xtqxtzqd  where rsbdsx="+bdsxId +wheresql;
                writeLog("sql="+sql);
                rs.execute(sql);
                while(rs.next()){
                    String xgfl = Util.null2String(rs.getString("xgfl"));
                    String xtmcid = Util.null2String(rs.getString("xtmc"));
                    String czf = Util.null2String(rs.getString("czf"));
                    String sfhrtxry = Util.null2String(rs.getString("sfhrtxry"));
                    String sfkjtxry = Util.null2String(rs.getString("sfkjtxry"));
                    String qxdzjgf = Util.null2String(rs.getString("qxdzjgf"));
                    String qxdzsx = Util.null2String(rs.getString("qxdzsx"));

                    String cwbzw = "";
                    rs3.execute("select count(1) as cnt  from uf_xtqxtzqd  where  xtmc in (select id from uf_xtqd where xtmc like 'HR系统%')    and  rsbdsx="+bdsxId +wheresql);
                    writeLog("select count(1) as cnt  from uf_xtqxtzqd  where  xtmc in (select id from uf_xtqd where xtmc like 'HR系统%')    and  rsbdsx="+bdsxId +wheresql);

                    rs3.next();
                    int tmpcnt = Util.getIntValue(rs3.getString(1));



                    rs3.execute("select * from uf_xtqd where id='"+xtmcid+"'");
                    rs3.next();
                    String xtfl = Util.null2String(rs3.getString("xtfl"));
                    String xtbm = Util.null2String(rs3.getString("xtbm"));
                    String czf_xt = Util.null2String(rs3.getString("czf"));
                    String xtzt = Util.null2String(rs3.getString("xtzt"));
                    String bz_xt = Util.null2String(rs3.getString("bz"));
                    String xtid = Util.null2String(rs3.getString("id"));
                    String xtmc = Util.null2String(rs3.getString("xtmc"));


                    if(tmpcnt>0){
                        if(xtmc.contains("HR系统")){
                            cwbzw = "优先触发" ;
                        }else{
                            cwbzw = "";
                        }
                    }else{
                        cwbzw = "触发";
                    }


                    String SCSJ = TimeUtil.getCurrentTimeString();



                    String uuid = UUID.randomUUID().toString();
                    String tt = TimeUtil.getCurrentTimeString();
                    String nowTime = TimeUtil.getCurrentTimeString();
                    SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
                    SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");
                    String currentdate = formatter1.format(new Date());
                    String currenttime = formatter2.format(new Date());
                    int modeid = 109005;

                    LocalDate dateNow = LocalDate.now();



                    String qxdzjgfname = "源";
                    if("0".equals(qxdzjgf)){
                        qxdzjgfname = "源";


                        rs3.execute("select dzjg from uf_qxtzssry where xtmc="+xtid);
                        rs3.next();
                        String dzjg = Util.null2String(rs3.getString(1));

//                        if("".equals(dzjg)){
//                            rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid);
//                        }else{
//                            if("0".equals(sflptxryVal)){
//                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsc +" and sflptxry='"+sflptxryVal+"'");
//                            }else{
//                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsc +" and sflptxry is null");
//                            }
//
//                        }
//                        rs3.next();
//                        String qxgly = Util.null2String(rs3.getString("qxgly"));

                        String qxgly = "";

                        if("".equals(dzjg)){
                            rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid);
                            rs3.next();
                            qxgly = Util.null2String(rs3.getString("qxgly"));
                        }else{
                            if("0".equals(sflptxryVal)) {
                                rs3.execute("select * from uf_qxtzssry where  xtmc=" + xtid + " and dzjg=" + gsc + " and sflptxry='" + sflptxryVal + "'");
                                rs3.next();
                                qxgly = Util.null2String(rs3.getString("qxgly"));
                                if("".equals(qxgly)){
                                    rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsc +" and sflptxry is null");
                                    rs3.next();
                                    qxgly = Util.null2String(rs3.getString("qxgly"));
                                }
                            }else{
                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsc +" and sflptxry is null");
                                rs3.next();
                                qxgly = Util.null2String(rs3.getString("qxgly"));
                            }
                        }



                        String qxglyname = "";
                        ResourceComInfo resourceComInfo = null;
                        try {
                            resourceComInfo = new ResourceComInfo();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                        qxglyname = resourceComInfo.getLastname(qxgly);


                        rs2.execute("insert into uf_qxtzqd(HRCODE,XMID,XMZW," +
                                "XMSX,GSCID,GSCMC,GSZID,GSZMC,BMCID,BMCMC,BMZID,BMZMC,QXQ,QXZ,THZGW,TZHZW,TZHZJ,BZ,SFHRTXRY" +
                                ",SFKJTXRY,SFLPTXRY,RSTZSXID,RSTZSXMC,QXFL,XTMCID,XTMCZW,CZF,QXTZJGF,QXTZJGID,QXTZJGMC,QXTZSX" +
                                ",QXGLYID,QXGLYXM,SCSJ,YLCCJR,YLCCJRQ,YLCCJGS,YLCID,CFBJW,MODEDATAMODIFYDATETIME,modeuuid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) values('"+hrcode+"','"+xm+"','"+xmzw+"'" +
                                ",'"+xmst0+"','"+gsc+"','"+gscname+"','"+gsz+"','"+gszname+"','"+bmc+"','"+bmcname+"','"+bmz+"'" +
                                ",'"+bmzname+"','"+qxq+"','"+qxz+"','"+dzhgw+"','"+dzhzw+"','"+dzhzj+"','"+bz+"'" +
                                ",'"+SFHRTXRY+"','"+SFKJTXRY+"','"+SFLPTXRY+"',"+bdsxId+",'"+RSTZSXMC+"','"+xtfl+"','"+xtid+"','"+xtmc+"'" +
                                ",'"+czf_xt+"','"+qxdzjgfname+"','"+gsc+"','"+gscname+"','"+qxdzsx+"','"+qxgly+"','"+qxglyname+"','"+SCSJ+"'" +
                                ","+YLCCJR+",'"+YLCCJRQ+"',"+YLCCJGS+","+requestid+",'"+cwbzw+"', '" + LocalDate.now() + "', '" + uuid + "'," + modeid + ", 1, 0, '" + currentdate + "','" + currenttime + "')");

                        rs2.executeQuery(" select id from  uf_qxtzqd  where modeuuid=? ", new Object[]{uuid});
                        rs2.next();
                        int billid = rs2.getInt("id");
                        ModeRightInfo moderight = new ModeRightInfo();
                        moderight.editModeDataShare(1, modeid, billid);

                    }else if("1".equals(qxdzjgf)){
                        qxdzjgfname = "目标";



                        rs3.execute("select dzjg from uf_qxtzssry where xtmc="+xtid);
                        rs3.next();
                        String dzjg = Util.null2String(rs3.getString(1));

//                        if("".equals(dzjg)){
//                            rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid);
//                        }else{
//
//                            if("0".equals(sflptxryVal)){
//                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsz +" and sflptxry='"+sflptxryVal+"'");
//                            }else{
//                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsz +" and sflptxry is null");
//                            }
//                        }
//                        rs3.next();
//
//                        String qxgly = Util.null2String(rs3.getString("qxgly"));

                        String qxgly = "";

                        if("".equals(dzjg)){
                            rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid);
                            rs3.next();
                            qxgly = Util.null2String(rs3.getString("qxgly"));
                        }else{
                            if("0".equals(sflptxryVal)) {
                                rs3.execute("select * from uf_qxtzssry where  xtmc=" + xtid + " and dzjg=" + gsz + " and sflptxry='" + sflptxryVal + "'");
                                rs3.next();
                                qxgly = Util.null2String(rs3.getString("qxgly"));
                                if("".equals(qxgly)){
                                    rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsz +" and sflptxry is null");
                                    rs3.next();
                                    qxgly = Util.null2String(rs3.getString("qxgly"));
                                }
                            }else{
                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsz +" and sflptxry is null");
                                rs3.next();
                                qxgly = Util.null2String(rs3.getString("qxgly"));
                            }
                        }




                        String qxglyname = "";
                        ResourceComInfo resourceComInfo = null;
                        try {
                            resourceComInfo = new ResourceComInfo();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                        qxglyname = resourceComInfo.getLastname(qxgly);


                        rs2.execute("insert into uf_qxtzqd(HRCODE,XMID,XMZW," +
                                "XMSX,GSCID,GSCMC,GSZID,GSZMC,BMCID,BMCMC,BMZID,BMZMC,QXQ,QXZ,THZGW,TZHZW,TZHZJ,BZ,SFHRTXRY" +
                                ",SFKJTXRY,SFLPTXRY,RSTZSXID,RSTZSXMC,QXFL,XTMCID,XTMCZW,CZF,QXTZJGF,QXTZJGID,QXTZJGMC,QXTZSX" +
                                ",QXGLYID,QXGLYXM,SCSJ,YLCCJR,YLCCJRQ,YLCCJGS,YLCID,CFBJW,MODEDATAMODIFYDATETIME,modeuuid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) values('"+hrcode+"','"+xm+"','"+xmzw+"'" +
                                ",'"+xmst0+"','"+gsc+"','"+gscname+"','"+gsz+"','"+gszname+"','"+bmc+"','"+bmcname+"','"+bmz+"'" +
                                ",'"+bmzname+"','"+qxq+"','"+qxz+"','"+dzhgw+"','"+dzhzw+"','"+dzhzj+"','"+bz+"'" +
                                ",'"+SFHRTXRY+"','"+SFKJTXRY+"','"+SFLPTXRY+"',"+bdsxId+",'"+RSTZSXMC+"','"+xtfl+"','"+xtid+"','"+xtmc+"'" +
                                ",'"+czf_xt+"','"+qxdzjgfname+"','"+gsz+"','"+gszname+"','"+qxdzsx+"','"+qxgly+"','"+qxglyname+"','"+SCSJ+"'" +
                                ","+YLCCJR+",'"+YLCCJRQ+"',"+YLCCJGS+","+requestid+",'"+cwbzw+"', '" + LocalDate.now() + "', '" + uuid + "'," + modeid + ", 1, 0, '" + currentdate + "','" + currenttime + "')");


                        rs2.executeQuery(" select id from  uf_qxtzqd  where modeuuid=? ", new Object[]{uuid});
                        rs2.next();
                        int billid = rs2.getInt("id");
                        ModeRightInfo moderight = new ModeRightInfo();
                        moderight.editModeDataShare(1, modeid, billid);

                    }else if("0,1".equals(qxdzjgf)){
                        qxdzjgfname = "源/目标";



                        rs3.execute("select dzjg from uf_qxtzssry where xtmc="+xtid);
                        rs3.next();
                        String dzjg = Util.null2String(rs3.getString(1));


                        String qxgly = "";

                        if("".equals(dzjg)){
                            rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid);
                            rs3.next();
                            qxgly = Util.null2String(rs3.getString("qxgly"));
                        }else{
                            if("0".equals(sflptxryVal)) {
                                rs3.execute("select * from uf_qxtzssry where  xtmc=" + xtid + " and dzjg=" + gsc + " and sflptxry='" + sflptxryVal + "'");
                                rs3.next();
                                qxgly = Util.null2String(rs3.getString("qxgly"));
                                if("".equals(qxgly)){
                                    rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsc +" and sflptxry is null");
                                    rs3.next();
                                    qxgly = Util.null2String(rs3.getString("qxgly"));
                                }
                            }else{
                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsc +" and sflptxry is null");
                                rs3.next();
                                qxgly = Util.null2String(rs3.getString("qxgly"));
                            }
                        }

                        String qxglyname = "";
                        ResourceComInfo resourceComInfo = null;
                        try {
                            resourceComInfo = new ResourceComInfo();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                        qxglyname = resourceComInfo.getLastname(qxgly);


                        rs2.execute("insert into uf_qxtzqd(HRCODE,XMID,XMZW," +
                                "XMSX,GSCID,GSCMC,GSZID,GSZMC,BMCID,BMCMC,BMZID,BMZMC,QXQ,QXZ,THZGW,TZHZW,TZHZJ,BZ,SFHRTXRY" +
                                ",SFKJTXRY,SFLPTXRY,RSTZSXID,RSTZSXMC,QXFL,XTMCID,XTMCZW,CZF,QXTZJGF,QXTZJGID,QXTZJGMC,QXTZSX" +
                                ",QXGLYID,QXGLYXM,SCSJ,YLCCJR,YLCCJRQ,YLCCJGS,YLCID,CFBJW,MODEDATAMODIFYDATETIME,modeuuid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) values('"+hrcode+"','"+xm+"','"+xmzw+"'" +
                                ",'"+xmst0+"','"+gsc+"','"+gscname+"','"+gsz+"','"+gszname+"','"+bmc+"','"+bmcname+"','"+bmz+"'" +
                                ",'"+bmzname+"','"+qxq+"','"+qxz+"','"+dzhgw+"','"+dzhzw+"','"+dzhzj+"','"+bz+"'" +
                                ",'"+SFHRTXRY+"','"+SFKJTXRY+"','"+SFLPTXRY+"',"+bdsxId+",'"+RSTZSXMC+"','"+xtfl+"','"+xtid+"','"+xtmc+"'" +
                                ",'"+czf_xt+"','"+qxdzjgfname+"','"+gsc+"','"+gscname+"','"+qxdzsx+"','"+qxgly+"','"+qxglyname+"','"+SCSJ+"'" +
                                ","+YLCCJR+",'"+YLCCJRQ+"',"+YLCCJGS+","+requestid+",'"+cwbzw+"', '" + LocalDate.now() + "', '" + uuid + "'," + modeid + ", 1, 0, '" + currentdate + "','" + currenttime + "')");

                        rs2.executeQuery(" select id from  uf_qxtzqd  where modeuuid=? ", new Object[]{uuid});
                        rs2.next();
                        int billid = rs2.getInt("id");
                        ModeRightInfo moderight = new ModeRightInfo();
                        moderight.editModeDataShare(1, modeid, billid);


                        rs3.execute("select dzjg from uf_qxtzssry where xtmc="+xtid);
                        rs3.next();
                        dzjg = Util.null2String(rs3.getString(1));

//                        if("".equals(dzjg)){
//                            rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid);
//                        }else{
//                            if("0".equals(sflptxryVal)){
//                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsz +" and sflptxry='"+sflptxryVal+"'");
//                            }else{
//                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsz +" and sflptxry is null");
//                            }
//                        }
//                        rs3.next();
//                        qxgly = Util.null2String(rs3.getString("qxgly"));



                        qxgly = "";

                        if("".equals(dzjg)){
                            rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid);
                            rs3.next();
                            qxgly = Util.null2String(rs3.getString("qxgly"));
                        }else{
                            if("0".equals(sflptxryVal)) {
                                rs3.execute("select * from uf_qxtzssry where  xtmc=" + xtid + " and dzjg=" + gsz + " and sflptxry='" + sflptxryVal + "'");
                                rs3.next();
                                qxgly = Util.null2String(rs3.getString("qxgly"));
                                if("".equals(qxgly)){
                                    rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsz +" and sflptxry is null");
                                    rs3.next();
                                    qxgly = Util.null2String(rs3.getString("qxgly"));
                                }
                            }else{
                                rs3.execute("select * from uf_qxtzssry where  xtmc="+xtid+" and dzjg="+gsz +" and sflptxry is null");
                                rs3.next();
                                qxgly = Util.null2String(rs3.getString("qxgly"));
                            }
                        }

                        qxglyname = "";
                        try {
                            resourceComInfo = new ResourceComInfo();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                        qxglyname = resourceComInfo.getLastname(qxgly);


                        rs2.execute("insert into uf_qxtzqd(HRCODE,XMID,XMZW," +
                                "XMSX,GSCID,GSCMC,GSZID,GSZMC,BMCID,BMCMC,BMZID,BMZMC,QXQ,QXZ,THZGW,TZHZW,TZHZJ,BZ,SFHRTXRY" +
                                ",SFKJTXRY,SFLPTXRY,RSTZSXID,RSTZSXMC,QXFL,XTMCID,XTMCZW,CZF,QXTZJGF,QXTZJGID,QXTZJGMC,QXTZSX" +
                                ",QXGLYID,QXGLYXM,SCSJ,YLCCJR,YLCCJRQ,YLCCJGS,YLCID,CFBJW,MODEDATAMODIFYDATETIME,modeuuid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) values('"+hrcode+"','"+xm+"','"+xmzw+"'" +
                                ",'"+xmst0+"','"+gsc+"','"+gscname+"','"+gsz+"','"+gszname+"','"+bmc+"','"+bmcname+"','"+bmz+"'" +
                                ",'"+bmzname+"','"+qxq+"','"+qxz+"','"+dzhgw+"','"+dzhzw+"','"+dzhzj+"','"+bz+"'" +
                                ",'"+SFHRTXRY+"','"+SFKJTXRY+"','"+SFLPTXRY+"',"+bdsxId+",'"+RSTZSXMC+"','"+xtfl+"','"+xtid+"','"+xtmc+"'" +
                                ",'"+czf_xt+"','"+qxdzjgfname+"','"+gsz+"','"+gszname+"','"+qxdzsx+"','"+qxgly+"','"+qxglyname+"','"+SCSJ+"'" +
                                ","+YLCCJR+",'"+YLCCJRQ+"',"+YLCCJGS+","+requestid+",'"+cwbzw+"', '" + LocalDate.now() + "', '" + uuid + "'," + modeid + ", 1, 0, '" + currentdate + "','" + currenttime + "')");


                        rs2.executeQuery(" select id from  uf_qxtzqd  where modeuuid=? ", new Object[]{uuid});
                        rs2.next();
                        billid = rs2.getInt("id");
                        moderight = new ModeRightInfo();
                        moderight.editModeDataShare(1, modeid, billid);
                    }

                }

            }


        }

    }


    public String docompany(String id){

        String dsid=id;
        String sql = "select SUBCOMPANYCODE,SUPSUBCOMID  from hrmsubcompany h where id="+id;
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        String code = Util.null2String(rs.getString("SUBCOMPANYCODE"));
        if(code.length()==8) {
            String hcode = code.substring(4, 8);
            if (!"0000".equals(hcode)) {
                dsid = Util.null2String(rs.getString("SUPSUBCOMID"));
            }
        }
        return dsid;
    }

}
