package com.engine.htsc.sfxzdj.service.impl;

import com.engine.core.impl.Service;
import com.engine.htsc.sfxzdj.service.SfxzdjService;
import com.weaver.general.TimeUtil;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetDataSource;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.GlobatTools.workflow.WorkflowCreateHandler;
import weaver.interfaces.htsc.comInfo.PropBean;

import java.text.SimpleDateFormat;
import java.util.*;

public class SfxzdjServiceImpl extends Service implements SfxzdjService {
    @Override
    public Map<String, Object> getdoneworkflow(Map<String, Object> map) {
        PropBean pb = new PropBean();
        String requestid=Util.null2String(map.get("requestid"));
        Map<String,Object> resultMap = new HashMap<>();
        String xzdcdj_xgbmhq_unnumber = pb.getPropName("xzdcdj.nodeunnumber.xzdcdj_xgbmhq");

        List<Map<String,String>> xgbmhq = getPassUserByNodeid(requestid,xzdcdj_xgbmhq_unnumber);
        resultMap.put("xgbmhq",xgbmhq);



        return resultMap;

    }

    @Override
    public Map<String, Object> getNg(Map<String, Object> map) {
        HashMap<String, Object> result = new HashMap<>();
        String nodeid = (String)map.get("nodeid");
        String workflowid = (String)map.get("workflowid");
        String requestid = (String)map.get("requestid");
        String sql = "select * from WORKFLOW_REQUESTLOG where workflowid = "+workflowid+" and requestid = "+requestid+" and  nodeid = "+nodeid + " and logtype = 2";
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        result.put("size",rs.getCounts());
        return result;
    }

    @Override
    public Map<String, Object> getZhhm(Map<String, Object> map) {
        String khhm = (String)map.get("zhhm");
        HashMap<String, Object> result = new HashMap<>();
        //测试环境
//        RecordSet rs = new RecordSet();
        RecordSetDataSource rs = new RecordSetDataSource("sfxzdj");
        String sql = " select * from JTXTDATAUSER_CLIENT where client_id = " +khhm;
        rs.execute(sql);
        if(rs.next()){
            result.put("client_id",rs.getString("client_id"));
            result.put("client_name",rs.getString("client_name"));
        }
        return result;
    }

    @Override
    public Map<String, Object> updateState(Map<String, Object> map) {
        String ids = (String)map.get("ids");
        JAVATools.writelog("更新明细表7ids" + ids);
        RecordSet rs = new RecordSet();
        PropBean pb = new PropBean();
        String tablename = pb.getPropName("sfxzdj_tablename_dt7");
        for (String id :ids.split(",") ) {
            if(StringUtils.isNotBlank(id)){
                String yySql = "select * from workflow_requestbase where  requestid = "+ id ;
                rs.execute(yySql);
                rs.next();
                String flowid = rs.getString("workflowid");
                String currentnodeid = rs.getString("currentnodeid");
                String requestname = rs.getString("requestname");
                String currentnodetype = rs.getString("currentnodetype").equals("3")?"已办结":"进行中";
                yySql = "select * from workflow_currentoperator  where nodeid = "+currentnodeid+" and requestid = "+id;
                rs.execute(yySql);
                rs.next();
                String userid = rs.getString("userid");

                String nodeSql = "select * from workflow_nodebase where id = "+currentnodeid;
                rs.execute(nodeSql);
                rs.next();
                String nodename = rs.getString("nodename");
                String updateSql = "update  "+tablename+" set zt = '"+currentnodetype+"', dqclr = '"+userid+"',jd='"+nodename+"' where lcid = '"+id+"'";
                JAVATools.writelog("更新明细表7updateSql" + updateSql);
                rs.execute(updateSql);

            }
        }
        return null;
    }

    @Override
    public Map<String, Object> triggerFlow(Map<String, Object> param) {
        PropBean pb = new PropBean();
        HashMap<String, Object> result = new HashMap<>();
        String requestids = "";
        String requestid = (String)param.get("requestid");//请求ID
        JAVATools.writelog("会签部门触发流程action开始");
        JAVATools.writelog("会签部门触发流程 requestid"+requestid);
        String tablename = pb.getPropName("sfxzdj_tablename");
        JAVATools.writelog("会签部门触发流程 tablename"+tablename);
        String usr = (String)param.get("user");//获取当前操作用户对象
        String sql = "select * from " + tablename+ " where requestid = " + requestid;
        RecordSet rs = new RecordSet();
        RecordSet deptrs = new RecordSet();
//        RecordSet deptrs = new RecordSet();
        rs.execute(sql);
        while(rs.next()){
            String mainid = rs.getString("id");
            String ngr = rs.getString("ngr");
            String cxjg = rs.getString("cxjg");//查询机关
            String szbm = rs.getString("szbm");
            String dt6Sql = "select * from "+tablename+"_dt6" + " where lcid = "+ requestid+" and to_char(dqczz) = "+usr;
            JAVATools.writelog("会签部门触发流程 dt6Sql"+dt6Sql);
            rs.execute(dt6Sql);
            while(rs.next()){
                String dt6Dqczz = rs.getString("dqczz");
                JAVATools.writelog("会签部门触发流程 dt6Dqczz"+dt6Dqczz);
                String dt6Zdclr = rs.getString("zdclr");
                JAVATools.writelog("会签部门触发流程 dt6Zdclr"+dt6Zdclr);
                String depttypecode = getcode(ngr);
                JAVATools.writelog("会签部门触发流程 depttypecode"+depttypecode);

                String Sql = "select * from hrmdepartmentdefined where deptid =  "+szbm;
                deptrs.execute(Sql);
                deptrs.next();
                String code = deptrs.getString("depttypecode");
                //判断拟稿人所在部门类型
                String  cfbm ="0";
                String sfxzdj_zbcode = pb.getPropName("sfxzdj_zbcode");
                if(sfxzdj_zbcode.indexOf(code)>-1){
                    cfbm="1";

                }
                JAVATools.writelog("会签部门触发流程 sfxzdj_zbcode"+sfxzdj_zbcode);
                if(sfxzdj_zbcode.indexOf(depttypecode)>-1){
                    //判断当前处理人是否是总部，是则生成总部用印，不是分支机构
                    String dt6depttypecode = getcode(dt6Dqczz);
                    JAVATools.writelog("会签部门触发流程 dt6depttypecode"+dt6depttypecode);
                    if(sfxzdj_zbcode.indexOf(dt6depttypecode)>-1){
                        String sfxzdj_zbworkflowid =pb.getPropName("sfxzdj_zbworkflowid");
                        String[] split = dt6Zdclr.split(",");
                        JAVATools.writelog("会签部门触发流程 split"+split.toString());
                        for (String id :split ) {
                            if (StringUtils.isNotBlank(id)) {
                                Map<String, String> hrm = getHrm(id);
                                JAVATools.writelog("会签部门触发流程 hrm"+hrm.toString());
//                                总部用印
//                                上级部门审批sjbmsp——否1
//                                内部送阅sfnbsy——是0
//                                申报文件标题sbwjbt——正文
//                                是否编号sfbh——check框0
//                                是否排版编号sfpbbh——check框0
//                                签章标记qzbj——#华泰签章标记符#
//                                审核方式shfs——并发审核1
//                                领导审批方式ldspsdfs ——依次审批0
//                                领导审批方式2ldspsdfs2——依次审批0
//                                提示1ts1——文件类型将影响流程审批，请根据具体内容选择正确的适用范围
//                                证照用途zzyongtu——仅用于办理XX事宜
//                                是否授权简化sfsqjh——否1
//                                流程类型编号lclxbh——自定义浏览按钮：总部用印申请
//                                是否送过执行秘书sfsgzxms——check框0
//                                是否送过合规审核sfsghgsh——check框0
//                                落款日期特殊要求lkrqtsyq——否1
//                                提示2ts2——所有需要用印的文件不论格式请上传入用印文件，附件仅作为说明性文档供参考

                                HashMap<String, String> map = new HashMap<>();

//                                总部用印：
//                                1、带出部门领导，根据hrmdepartmentdefined表中的deptid匹配主表所在部门，deptdirectors赋值部门领导审核bmldsh
//                                2、所在部门带出部门类型，根据hrmdepartmentdefined表中的deptid匹配所在部门，depttypecode赋值部门类型deptTypeCode
                                String deptfinedSql = "select * from hrmdepartmentdefined where  deptid = "+hrm.get("departmentid");
                                JAVATools.writelog("触发总部用印deptfinedSql"+deptfinedSql);
                                deptrs.execute(deptfinedSql);
                                JAVATools.writelog("触发总部用印deptfinedSql"+deptfinedSql);
                                if(deptrs.next()){
                                    String deptdirectors = deptrs.getString("deptdirectors");
                                    String typecode = deptrs.getString("depttypecode");
                                    if(StringUtils.isNotBlank(deptdirectors) && !deptdirectors.contains(",")){
                                        map.put("bmldsh",deptdirectors);
                                    }
                                    map.put("deptTypeCode",typecode);
                                }
//                                是否外部触发sfwbcf，check框，赋值1
//                                触发来源cfly，选择框，赋值0
                                map.put("wjlb","3");
                                map.put("wjlx","16");
                                map.put("sfwbcf","1");
                                map.put("cfly","0");
                                map.put("sjbmsp","1");
                                map.put("sfnbsy","0");
                                map.put("sbwjbt","正文");
                                map.put("sfbh","0");
                                map.put("sfpbbh","0");
                                map.put("qzbj","#华泰签章标记符#");
                                map.put("shfs","1");
                                map.put("ldspsdfs","0");
                                map.put("ldspsdfs2","0");
                                map.put("ts1","文件类型将影响流程审批，请根据具体内容选择正确的适用范围");
                                map.put("zzyongtu","仅用于办理XX事宜");
                                map.put("sfsqjh","1");
                                map.put("lclxbh","zbyy");
                                map.put("sfsgzxms","0");
                                map.put("sfsghgsh","0");
                                map.put("lkrqtsyq","1");
                                map.put("ts2","所有需要用印的文件不论格式请上传入用印文件，附件仅作为说明性文档供参考");
                                map.put("bt","关于协助"+cxjg+"查询的用印申请");
                                map.put("ngr",id);
                                map.put("szbm",hrm.get("departmentid"));
                                map.put("szjg",hrm.get("supdepid"));
                                map.put("jjcd","0");
                                map.put("lxfs",hrm.get("phone"));
                                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                                map.put("ngrq",format.format(new Date()));
                                map.put("qttzyddx",ngr);
                                map.put("gllc",requestid);
                                WorkflowCreateHandler wfl=new WorkflowCreateHandler();
                                String s = wfl.WorkflowCreateByRequestMap(id,sfxzdj_zbworkflowid,"关于协助"+cxjg+"查询的用印申请","0",map);
                                JAVATools.writelog("会签部门触发流程 requestid"+s);
                                requestids = requestids+s+",";
                                //给总部用印的拟稿人添加一个协助登记流程的通知阅读
                                addReadingUser(requestid,id);
                            }
                        }
                    }else{
                        String sfxzdj_fzworkflowid =pb.getPropName("sfxzdj_fzworkflowid");
                        String[] split = dt6Zdclr.split(",");
                        JAVATools.writelog("会签部门触发流程 split"+split.toString());

                        RecordSet deptRs = new RecordSet();
                        String deptSql = "select * from HRMDEPARTMENT where departmentcode = 'ZZ001041'";
                        deptRs.execute(deptSql);
                        deptRs.next();
                        String deptid = deptRs.getString("id");
                        for (String id :split ) {
                            if (StringUtils.isNotBlank(id)) {
//                                分支机构用印
//                                上级部门审批sjbmsp——否1
//                                内部送阅sfnbsy——是0
//                                申报文件标题sbwjbt——正文
//                                是否编号sfbh——check框0
//                                是否排版编号sfpbbh——check框0
//                                签章标记qzbj——#华泰签章标记符#
//                                审核方式shfs——并发审核1
//                                领导审批方式ldspsdfs ——依次审批0
//                                领导审批方式2ldspsdfs2——依次审批0
//                                提示1ts1——文件类型将影响流程审批，请根据具体内容选择正确的适用范围
//                                证照用途zzyongtu——仅用于办理XX事宜
//                                是否授权简化sfsqjh——否1
//                                是否送过执行秘书sfsgzxms——check框0
//                                是否送过合规审核sfsghgsh——check框0
//                                落款日期特殊要求lkrqtsyq——否1
//                                财富管理部cfglb——浏览按钮-部门：财富管理部
//                                选择流程xzlc——自定义浏览按钮：分支机构用印申请
//                                提示2ts2——所有需要用印的文件不论格式请上传入用印文件，附件仅作为说明性文档供参考
//                                流程类型编号lclxbh——自定义浏览按钮：分支机构用印申请
                                Map<String, String> hrm = getHrm(id);
                                JAVATools.writelog("会签部门触发流程 hrm"+hrm.toString());
                                HashMap<String, String> map = new HashMap<>();
                                //                        1、带出部门领导，根据hrmdepartmentdefined表中的deptid匹配主表所在部门，deptdirectors赋值部门领导审核bmldsh
//
//                        2、所在部门带出部门类型、部门类别，根据hrmdepartmentdefined表中的deptid匹配主表所在部门，depttypecode赋值部门类型deptTypeCode，deptscalelevelcode赋值部门类别bmlbcode
//                        5、带出私行中心，根据hrmdepartmentdefined表中的deptid匹配主表所在部门，sfsxzx赋值是否私行中心 sfsxzx
                                String deptfinedSql = "select * from hrmdepartmentdefined where  deptid = "+hrm.get("departmentid");
                                deptrs.execute(deptfinedSql);
                                JAVATools.writelog("触发分支机构用印deptfinedSql"+deptfinedSql);
                                if(deptrs.next()){
                                    String deptdirectors = deptrs.getString("deptdirectors");
                                    String typecode = deptrs.getString("depttypecode");
                                    String sfsxzx = deptrs.getString("sfsxzx");
                                    String deptscalelevelcode = deptrs.getString("deptscalelevelcode");

                                    if(StringUtils.isNotBlank(deptdirectors) && !deptdirectors.contains(",")){
                                        map.put("bmldsh",deptdirectors);
                                    }
                                    map.put("deptTypeCode",typecode);
                                    if(StringUtils.isNotBlank(sfsxzx)){
                                        map.put("sfsxzx",sfsxzx);
                                    }
                                    if(StringUtils.isNotBlank(deptscalelevelcode)){
                                        map.put("bmlbcode",deptscalelevelcode);
                                    }
                                }
//                        3、文件类型带出业务主管部门，根据*uf_fzjgyysyfw*表中的wjlx匹配文件类型，wjlb匹配文件类别，
//                        ywzgbm赋值业务主管部门ywzgbm，fgsglg赋值分公司管理岗位fgsglgw，ywzgbmsfbj赋值业务主管部门负责人是否必经ywzgbmfzrsfbj，
//                        sqjh赋值授权号sqh，sfsqjh赋值是否授权简化sfsqjh，ywzgbmbjns赋值业务主管部门必经内审ywzgbmbjns，
//                        fgsbjjd赋值分公司必经节点fgsbjjd
                                String uf_fzjgyysyfw_sql = "select * from uf_fzjgyysyfw where wjlx = 93 and wjlb = 2";
                                JAVATools.writelog("触发分支机构用印uf_fzjgyysyfw_sql"+uf_fzjgyysyfw_sql);
                                deptrs.execute(uf_fzjgyysyfw_sql);
                                String fgsglg = "";
                                String ywzgbm = "";
                                if(deptrs.next()){
                                    if(StringUtils.isNotBlank(deptrs.getString("ywzgbm"))){
                                        map.put("ywzgbm",deptrs.getString("ywzgbm"));
                                        ywzgbm= deptrs.getString("ywzgbm");
                                        JAVATools.writelog("触发分支机构用印ywzgbm"+ywzgbm);
                                    }
                                    if(StringUtils.isNotBlank(deptrs.getString("fgsglg"))){
                                        fgsglg= deptrs.getString("fgsglg");
                                        map.put("fgsglgw",deptrs.getString("fgsglg"));
                                    }
                                    if(StringUtils.isNotBlank(deptrs.getString("ywzgbmsfbj"))){
                                        map.put("ywzgbmfzrsfbj",deptrs.getString("ywzgbmsfbj"));
                                    }
                                    if(StringUtils.isNotBlank(deptrs.getString("sqjh"))){
                                        map.put("sqh",deptrs.getString("sqjh"));
                                    }
                                    if(StringUtils.isNotBlank(deptrs.getString("sfsqjh"))){
                                        map.put("sfsqjh",deptrs.getString("sfsqjh"));
                                    }
                                    if(StringUtils.isNotBlank(deptrs.getString("ywzgbmbjns"))){
                                        map.put("ywzgbmbjns",deptrs.getString("ywzgbmbjns"));
                                    }
                                    if(StringUtils.isNotBlank(deptrs.getString("fgsbjjd"))){
                                        map.put("fgsbjjd",deptrs.getString("fgsbjjd"));
                                    }
                                }
//                        4、带出邮寄对象，根据uf_fzjgcysjr表中ssjg匹配所在部门，sjrxm赋值寄送对象jsdx
                                String uf_fzjgcysjr_sql = "select * from uf_fzjgcysjr where ssjg = " + hrm.get("departmentid");
                                JAVATools.writelog("触发分支机构用印uf_fzjgcysjr_sql"+uf_fzjgcysjr_sql);
                                deptrs.execute(uf_fzjgcysjr_sql);
                                if(deptrs.next()){
                                    if(StringUtils.isNotBlank(deptrs.getString("sjrxm"))){
                                        map.put("jsdx",deptrs.getString("sjrxm"));
                                    }
                                }
//

//                        6、分公司带出部门负责人，根据hrmdepartmentdefined表中的deptid匹配主表所属分公司 ，deptdirectors赋值部门负责人bmfzr1。（所属分公司是sql代码带出。）
                                String fgsSql = "select DECODE(de.deptTypeCode,'JGLX04',d.supdepid,'JGLX09',d.supdepid,'JGLX03',d.id) as cid from hrmdepartment d,hrmdepartmentdefined de,hrmresource h where d.id=de.deptid and h.departmentid=de.deptid and h.id= " +id;
                                JAVATools.writelog("触发分支机构用印fgsSql"+fgsSql);
                                deptrs.execute(fgsSql);
                                if(deptrs.next() && StringUtils.isNotBlank(deptrs.getString("cid"))){
                                    String fgsfzrsql = " select * from hrmdepartmentdefined where deptid = " + deptrs.getString("cid");
                                    deptrs.execute(fgsfzrsql);
                                    deptrs.next();
                                    if(StringUtils.isNotBlank(deptrs.getString("deptdirectors"))){
                                        map.put("bmfzr1",deptrs.getString("deptdirectors"));
                                    }
                                }
//                        7、分公司管理岗带出人员，根据uf_lcgwry表中的xzlc匹配选择流程，xzgw匹配分公司管理岗位，jg匹配所属机构，ry赋值分公司管理岗人员fgsglgry
                                if(StringUtils.isNotBlank(fgsglg)){
                                    String uf_lcgwry_sql = "select * from uf_lcgwry where xzgw = '"+fgsglg+"' and jg ="+hrm.get("supdepid") +" and xzlc = 'fzjgyy'";
                                    JAVATools.writelog("触发分支机构用印uf_lcgwry_sql"+uf_lcgwry_sql);
                                    deptrs.execute(uf_lcgwry_sql);
                                    if(deptrs.next() && StringUtils.isNotBlank(deptrs.getString("ry"))){
                                        map.put("fgsglgry",deptrs.getString("ry"));
                                    }
                                }

//                        8、业务主管部门带出部门负责人,根据hrmdepartmentdefined表中的deptid匹配主表业务主管部门，deptdirectors赋值部门负责人-业务主管部门bmfzrywzgbm
                                if(StringUtils.isNotBlank(ywzgbm)){
                                    String ywzgbmSql = "select * from hrmdepartmentdefined where deptid = " + ywzgbm;
                                    JAVATools.writelog("触发分支机构用印ywzgbmSql"+ywzgbmSql);
                                    deptrs.execute(ywzgbmSql);
                                    if(deptrs.next() && StringUtils.isNotBlank(deptrs.getString("deptdirectors"))){
                                        map.put("bmfzrywzgbm",deptrs.getString("deptdirectors"));
                                    }
                                }

                                //                                是否外部触发sfwbcf，check框，赋值1
//                                触发来源cfly，选择框，赋值0
                                map.put("wjlb","2");
                                map.put("wjlx","93");
                                map.put("sfwbcf","1");
                                map.put("cfly","0");
                                map.put("cfbm",cfbm);//触发部门
                                map.put("sjbmsp","1");
                                map.put("sfnbsy","0");
                                map.put("sbwjbt","正文");
                                map.put("sfbh","0");
                                map.put("sfpbbh","0");
                                map.put("qzbj","#华泰签章标记符#");
                                map.put("shfs","1");
                                map.put("ldspsdfs","0");
                                map.put("ldspsdfs2","0");
                                map.put("ts1","文件类型将影响流程审批，请根据具体内容选择正确的适用范围");
                                map.put("zzyongtu","仅用于办理XX事宜");
                                map.put("sfsqjh","1");
                                map.put("xzlc","fzjgyy");
                                map.put("sfsgzxms","0");
                                map.put("sfsghgsh","0");
                                map.put("lkrqtsyq","1");
                                map.put("ts2","所有需要用印的文件不论格式请上传入用印文件，附件仅作为说明性文档供参考");
                                map.put("cfglb",deptid);
                                map.put("lclxbh","fzjgyy");
                                map.put("bt","关于协助"+cxjg+"查询的用印申请");
                                map.put("ngr",id);
                                map.put("szbm",hrm.get("departmentid"));
                                map.put("szjg",hrm.get("supdepid"));
                                map.put("jjcd","0");
                                map.put("lxfs",hrm.get("phone"));
                                map.put("sfzzfyjyy","1");
                                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                                map.put("ngrq",format.format(new Date()));
                                map.put("qttzyddx",ngr);
                                map.put("gllc",requestid);
                                WorkflowCreateHandler wfl=new WorkflowCreateHandler();
                                String s = wfl.WorkflowCreateByRequestMap(id, sfxzdj_fzworkflowid, "关于协助" + cxjg + "查询的用印申请", "0", map);
                                JAVATools.writelog("会签部门触发流程 requestid"+s);
                                requestids = requestids+s+",";
                                //给分支机构用印的拟稿人添加一个协助登记流程的通知阅读
                                addReadingUser(requestid,id);
                            }
                        }
                    }

                }else {
                    JAVATools.writelog("会签部门触发流程不触发");
                }
                JAVATools.writelog("会签部门触发流程 dt6Dqczz"+dt6Dqczz);
                saveDt7(requestids,tablename,mainid);
            }
        }
        result.put("msg","success");
        result.put("code","200");
        return result;

    }
    public void  saveDt7(String requestids,String tablename ,String mainid){
        RecordSet rs = new RecordSet();
        String[] split = requestids.split(",");
        for (String id:split) {
            //通过用印流程的requestid查询用印的数据保存到建模中
            if(StringUtils.isNotBlank(id)){
                String yySql = "select * from workflow_requestbase where  requestid = "+ id ;
                rs.execute(yySql);
                rs.next();
                String flowid = rs.getString("workflowid");
                String currentnodeid = rs.getString("currentnodeid");
                String requestname = rs.getString("requestname");
                String currentnodetype = rs.getString("currentnodetype").equals("3")?"已办结":"进行中";
                yySql = "select * from workflow_currentoperator  where nodeid = "+currentnodeid+" and requestid = "+id;
                rs.execute(yySql);
                rs.next();
                String userid = rs.getString("userid");
                String dt7Sql = "insert into " + tablename+"_dt7 (lcid,zt,lcbt,dqclr,mainid) values ('"+id+"','"+currentnodetype+"','"+requestname+"','"+userid+"','"+mainid+"')";
                rs.execute(dt7Sql);
            }




        }
    }
    public String getcode(String ngr){
        RecordSet rs = new RecordSet();
        String hrmSql = "select * from hrmresource where id = "+ngr;
        rs.execute(hrmSql);
        rs.next();
        String departmentid = rs.getString("departmentid");
        String deptSql = "select * from hrmdepartmentdefined where deptid =  "+departmentid;
        rs.execute(deptSql);
        rs.next();

        String depttypecode = rs.getString("depttypecode");
        return depttypecode;
    }
    public Map<String,String> getHrm(String ngr){
        HashMap<String, String> result = new HashMap<>();
        RecordSet rs = new RecordSet();
        String hrmSql = "select * from hrmresource where id = "+ngr;
        rs.execute(hrmSql);
        rs.next();
        String departmentid = rs.getString("departmentid");
        result.put("phone",rs.getString("mobile"));
        result.put("departmentid",departmentid);
        String deptSql = "select * from hrmdepartment where id =  "+departmentid;
        rs.execute(deptSql);
        rs.next();
        result.put("supdepid",rs.getString("supdepid"));
        return result;
    }

    private List<Map<String, String>> getPassUserByNodeid(String requestid, String nodenumbber) {
        RecordSet rs = new RecordSet();
        BaseBean bs = new BaseBean();
        List<Map<String,String>> userMapList = new ArrayList<>();

        ArrayList<String> useridSet = new ArrayList<String>();
        String sql = "select operator,agentorbyagentid,logtype from workflow_requestlog where requestid = '"+requestid+"'  " +
                "  and nodeid in ( select id from workflow_nodebase where unnumber='"+nodenumbber+"')   order by  to_date((operatedate || ' ' || OPERATETIME),'yyyy-MM-dd hh24:mi:ss')  asc";
        bs.writeLog("司法协助sql"+sql);
        System.out.println(sql);
        rs.executeQuery(sql);
        while(rs.next()){
            String agentorbyagentid = Util.null2String(rs.getString("agentorbyagentid"));
            if("-1".equals(agentorbyagentid)){//授权，获取原处理人
                String operator = Util.null2String(rs.getString("operator"));
                useridSet.add(operator+","+rs.getString("logtype"));
            }else{
                useridSet.add(agentorbyagentid+","+rs.getString("logtype"));
            }
        }

        for(String userid:useridSet){
            String[] split = userid.split(",");
            if(StringUtils.isNotEmpty(split[0])){
                Map<String,String> userMap = new HashMap<>();
                sql = "select t1.id as userid,t1.lastname,t2.id as deptid,t2.departmentname from hrmresource t1,hrmdepartment t2 where t1.departmentid = t2.id and t1.id = '"+split[0]+"'";
                bs.writeLog(sql);
                rs.executeQuery(sql);
                if(rs.next()){
                    userMap.put("id",Util.null2String(rs.getString("userid")));
                    userMap.put("name",Util.null2String(rs.getString("lastname")));
                    userMap.put("deptid",Util.null2String(rs.getString("deptid")));
                    userMap.put("deptname",Util.null2String(rs.getString("departmentname")));
                }
                userMap.put("logtype",split[1]);
                userMapList.add(userMap);
            }
        }

        return userMapList;
    }

    /**
     * 添加通知阅读人
     * @param requestid
     * @param userId
     */
    public void addReadingUser(String requestid,String userId){
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        String sql = "select * from workflow_requestbase where requestid = "+requestid;
        bb.writeLog("添加通知阅读人workflow_requestbase："+sql);
        rs.execute(sql);
        rs.next();
        String workflowid = rs.getString("workflowid");
        String nodeid = rs.getString("currentnodeid");
        sql = "select * from workflow_base where id = "+workflowid;
        bb.writeLog("添加通知阅读人workflow_base："+sql);
        rs.execute(sql);
        rs.next();
        String workflowtype = rs.getString("workflowtype");

        char flag = com.weaver.general.Util.getSeparator();
        String operatorgroup = "0";
        String creatertype = "0";
        String currentdate = TimeUtil.getCurrentDateString();
        String currenttime =  TimeUtil.getCurrentTimeString().substring(11,19);
        String isremarktemp = "9";
        String lastnodeid = ""+nodeid;
        String groupdetailid = "-1";
        String useridtemp = userId;//抄送人
        String Procparatemp = "" + requestid + flag + useridtemp + flag + operatorgroup + flag + workflowid + flag
                + workflowtype + flag + creatertype + flag + isremarktemp + flag + lastnodeid + flag + -1
                + flag + "0" + flag + -1 + flag + groupdetailid+flag+currentdate+flag+currenttime;
        bb.writeLog("司法协助登记抄送Procparatemp====="+Procparatemp);
        boolean executesuccess = rs.executeProc("workflow_CurrentOperator_I2", Procparatemp);
    }

}
