package com.engine.htsc.zbzysx.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.core.impl.Service;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.formmode.virtualform.VirtualFormHandler;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.Util;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.workflow.workflow.WorkflowBillComInfo;

import java.util.*;

public class SubImportantService extends Service {

    public Map<String,Object> getMember(String deptid){
        BaseBean bs = new BaseBean();
        PropBean pb = new PropBean();
        RecordSet rs = new RecordSet();
        Map<String,Object> resultMap = new HashMap<>();

        try{
            ResourceComInfo resourceComInfo = new ResourceComInfo();
            String sfsxzx = "";
            String sql = "select sfsxzx from hrmdepartmentdefined where deptid ='"+deptid+"'";
            bs.writeLog(sql);
            rs.executeQuery(sql);
            if(rs.next()){
                sfsxzx = Util.null2String(rs.getString("sfsxzx"));
            }

            String supdepid = "";
            if("0".equals(sfsxzx)){
                supdepid = deptid;
            }else{
                sql = "select t1.id from hrmdepartment t1,hrmdepartmentdefined t2 where (t1.id = '"+deptid+"' or t1.id = (select supdepid from hrmdepartment where id = '"+deptid+"')) and t2.deptid = t1.id and t2.deptScaleLevelCode = '002'";
                bs.writeLog(sql);
                rs.executeQuery(sql);
                if(rs.next()){
                    supdepid = Util.null2String(rs.getString("id"));
                }
            }

            String cwhjid = "";
            String cwhj = "";
            sql = "select id from uf_gw where gwmc = '财务会计'";
            bs.writeLog(sql);
            rs.executeQuery(sql);
            if(rs.next()){
                cwhjid = Util.null2String(rs.getString("id"));
            }
            if(StringUtils.isNotEmpty(cwhjid)){
                sql = "select ry from uf_lcgwry where xzlc = 'fzjgzysx' and jg = '"+supdepid+"' and xzgw = '"+cwhjid+"'";
                bs.writeLog(sql);
                rs.executeQuery(sql);
                if(rs.next()){
                    cwhj = Util.null2String(rs.getString("ry"));
                }
            }
            List<String> cwhjNameList = new ArrayList<>();
            for(String id:cwhj.split(",")){
                String name = resourceComInfo.getLastname(id);
                cwhjNameList.add(name);
            }

            String hgglgid = "";
            String hgglg = "";
            sql = "select id from uf_gw where gwmc = '合规管理岗'";
            bs.writeLog(sql);
            rs.executeQuery(sql);
            if(rs.next()){
                hgglgid = Util.null2String(rs.getString("id"));
            }
            if(StringUtils.isNotEmpty(hgglgid)){
                sql = "select ry from uf_lcgwry where xzlc = 'fzjgzysx' and jg = '"+supdepid+"' and xzgw = '"+hgglgid+"'";
                bs.writeLog(sql);
                rs.executeQuery(sql);
                if(rs.next()){
                    hgglg = Util.null2String(rs.getString("ry"));
                }
            }
            List<String> hgglgNameList = new ArrayList<>();
            for(String id:hgglg.split(",")){
                String name = resourceComInfo.getLastname(id);
                hgglgNameList.add(name);
            }

            resultMap.put("cwhj", cwhj);
            resultMap.put("cwhjName", StringUtils.join(cwhjNameList,","));
            resultMap.put("hgglg",hgglg);
            resultMap.put("hgglgName",StringUtils.join(hgglgNameList,","));
            resultMap.put("api_status",true);
        }catch (Exception e){
            e.printStackTrace();
            resultMap.put("api_status",false);
            resultMap.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return resultMap;
    }

    /**
     * 获得默认通知阅读对象
     * @param sblb
     * @param sblx
     * @return
     */
    public JSONObject getDefaultNotice(String sblb, String sblx){
        BaseBean bs = new BaseBean();
        PropBean pb = new PropBean();
        RecordSet rs = new RecordSet();
        JSONObject jsonData = new JSONObject();

        try{
            ResourceComInfo resourceInfo = new ResourceComInfo();
            JSONArray jsonArray2 = new JSONArray();

            String qzsydxs = "";  //强制会签部门
            String qzsyrys = ""; //强制送阅人员
            String sql = " select qzsydx,qzsyry from uf_fzjgzysxsyfw where sblb ='" + sblb + "' and sblx='" + sblx + "'";
            bs.writeLog( sql );
            rs.executeQuery( sql );
            if(rs.next()){
                qzsydxs = Util.null2String(rs.getString("qzsydx"));//强制送阅部门
                qzsyrys = Util.null2String(rs.getString("qzsyry"));//强制送阅人员
            }

            List<String> arr3 = new ArrayList<>();
            String ids = "";
            if(!"".equals(qzsydxs)){
                List<String> qzsydxList = Arrays.asList(qzsydxs.split(","));
                for(String qzsydx : qzsydxList){
                    String sql1 = "select id,lastname,departmentid from hrmresource where departmentid = "+qzsydx+" and status =1 ";
                    rs.executeQuery( sql1 );
                    while (rs.next()) {
                        JSONObject json2 = new JSONObject();
                        String id = Util.null2String( rs.getString( "id" ) );
                        ids += ids == "" ? id : "," + id;
                        String lastname = Util.null2String(rs.getString( "lastname" ));
                        json2.put( "id", id );
                        json2.put( "name", lastname );
                        jsonArray2.add( json2 );

                        String departmentid =  Util.null2String(rs.getString("departmentid"));
                        if(arr3 !=null && arr3.size() > 0){
                            if(!arr3.contains(departmentid)){
                                arr3.add(departmentid);
                            }
                        }else{
                            arr3.add(departmentid);
                        }
                    }
                }
            }

            String str1 = "";
            if(arr3 !=null && arr3.size() >0){
                for (String str : arr3)
                {
                    str1 += str1 == "" ? "dept_"+str : "," + "dept_"+str;
                }
            }

            if(!"".equals(qzsyrys)){
                List<String> qzsyryList = Arrays.asList(qzsyrys.split(","));
                for(String qzsyry : qzsyryList){
                    String qzsyryname = resourceInfo.getLastname(qzsyry);//强制送阅人员名称
                    JSONObject json3 = new JSONObject();
                    json3.put("id",qzsyry);
                    json3.put("name",qzsyryname);
                    jsonArray2.add(json3);
                }
            }
            jsonData.put( "qzsyryid", qzsyrys );

            JSONArray replaceObject  = getReplaceDatas(sblb,sblx);
            jsonData.put( "tzyddx", replaceObject );
            jsonData.put( "tzydgd", jsonArray2 );

            String strs = "";
            if(!"".equals(qzsyrys)){
                List<String> arr2 = Arrays.asList(qzsyrys.split(","));
                if(arr2!=null && arr2.size() > 0){
                    for (String str : arr2) {
                        strs += strs == "" ? "hrm_"+str : "," + "hrm_"+str;
                    }
                }
            }


            jsonData.put( "qzsydxid", ids ); // 人员汇总ID
            jsonData.put( "qzsyrys", strs ); //人员
            jsonData.put( "qzsydxs", str1 );  //部门
            bs.writeLog( "getDefaultNotice=================jsonData:" + jsonData.toJSONString() );
        }catch (Exception e){
            e.printStackTrace();
        }
        return jsonData;
    }

    public JSONArray getReplaceDatas(String sblb, String sblx)
    {
        String ecologyContentPath = GCONST.getContextPath();
        BaseBean bs = new BaseBean();
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        RecordSet rs2 = new RecordSet();
        JSONArray replaceDatas = new JSONArray();
        DepartmentComInfo departInfo = null;
        try{
            departInfo = new DepartmentComInfo();

            String qzsydxs = "";
            String qzsyrys = "";
            String sql = "select qzsydx,qzsyry from uf_fzjgzysxsyfw where sblb ='" + sblb + "' and sblx='" + sblx + "'";
            rs.executeQuery( sql );
            if (rs.next()) {
                qzsydxs = Util.null2String(rs.getString("qzsydx"));//强制送阅部门
                qzsyrys = Util.null2String(rs.getString("qzsyry"));//强制送阅人员
            }

            bs.writeLog("qzsydxs:"+qzsydxs);
            bs.writeLog("qzsyrys:"+qzsyrys);

            if (!"".equals(qzsydxs))
            {
                String[] children = new String[0];
                List<String> qzsydxList = Arrays.asList(qzsydxs.split(","));
                for(String qzsydx : qzsydxList)
                {
                    JSONObject deptJson = new JSONObject();
                    bs.writeLog("qzsydx:"+qzsydx);
                    String qzsydxname = departInfo.getDepartmentName( qzsydx );//强制送阅部门名称
                    String sql1 = " select h.id,h.lastname,h.workcode,h.pinyinlastname,h.subcompanyid1,t.supdepid from hrmresource h,hrmdepartment t where h.departmentid=t.id and h.departmentid= " + qzsydx + " and h.status='1'";
                    bs.writeLog("sql1:"+sql1);

                    rs1.executeQuery( sql1 );
                    JSONArray users = new JSONArray();
                    String ids = "";
                    String subcompanyid1 = "";
                    String supdepid = "";
                    while (rs1.next()) {
                        String[] displayKeys = {"lastnamespan", "workcodespan", "departmentidspan", "jobtitlespan"};
                        String id = Util.null2String( rs1.getString( "id" ) );
                        String lastname = Util.null2String( rs1.getString( "lastname" ) );
                        String workcode = Util.null2String( rs1.getString( "workcode" ) );
                        subcompanyid1 = Util.null2String( rs1.getString( "subcompanyid1" ) );
                        String pinyinlastname = Util.null2String( rs1.getString( "pinyinlastname" ) );
                        supdepid = Util.null2String( rs1.getString( "supdepid" ) );
                        ids += ids == "" ? id+ "" : "," + id;
                        JSONObject userJson = new JSONObject();
                        userJson.put( "departmentid", qzsydx );
                        userJson.put( "departmentidspan", qzsydx );
                        userJson.put( "departmentname", qzsydx );
                        userJson.put( "displayKeys", displayKeys );
                        userJson.put( "icon", ecologyContentPath+"/messager/usericon/" + workcode + "/" + workcode + ".jpg" );
                        userJson.put( "id", id );
                        userJson.put( "jobtitlename", getJob( id ) );
                        userJson.put( "jobtitlespan", getJob( id ) );
                        userJson.put( "lastname", lastname );
                        userJson.put( "lastnamespan", lastname );
                        userJson.put( "nodeid", "resource_" + id + "x" );
                        userJson.put( "pinyinlastname", pinyinlastname );
                        userJson.put( "subcompanyid", subcompanyid1 );
                        userJson.put( "subcompanyname", "华泰集团" );
                        userJson.put( "supsubcompanyid", "0" );
                        userJson.put( "supsubcompanyname", "" );
                        userJson.put( "type", "resource" );
                        userJson.put( "workcodespan", workcode );
                        users.add( userJson );
                    }
                    deptJson.put( "children", children );
                    deptJson.put( "crmNames", "" );
                    deptJson.put( "icon", "/images/treeimages/subCopany_Colse_wev8.gif" );
                    deptJson.put( "id", qzsydx );
                    deptJson.put( "isLeaf", false );
                    deptJson.put( "isParent", "true" );
                    deptJson.put( "lastname", qzsydxname );
                    deptJson.put( "name", qzsydxname );
                    deptJson.put( "nocheck", "Y" );
                    deptJson.put( "nodeid", "dept_" + qzsydx + "x" );
                    deptJson.put( "treeKey", "wea0-com_1x-subcom_" + subcompanyid1 + "x-dept_" + supdepid + "x-dept_" + qzsydx + "x" );
                    deptJson.put( "type", "dept" );
                    deptJson.put( "users", users );
                    replaceDatas.add( deptJson );
                }

                if(!"".equals(qzsyrys))
                {
                    String sql2 = "select id,lastname,workcode,departmentid,jobtitle,mobile,pinyinlastname,messagerurl,subcompanyid1 from hrmresource where id in (" + qzsyrys + ") and status='1'";
                    bs.writeLog("sql2:"+sql2);
                    rs2.executeQuery( sql2 );
                    while (rs2.next()) {
                        JSONObject hrmJson = new JSONObject();
                        String id = Util.null2String( rs2.getString( "id" ) );
                        String lastname = Util.null2String( rs2.getString( "lastname" ) );
                        String workcode = Util.null2String( rs2.getString( "workcode" ) );
                        String jobtitle = Util.null2String( rs2.getString( "jobtitle" ) );
                        String mobile = Util.null2String( rs2.getString( "mobile" ) );
                        String pinyinlastname = Util.null2String( rs2.getString( "pinyinlastname" ) );
                        String departmentid = Util.null2String( rs2.getString( "departmentid" ) );
                        String messagerurl = Util.null2String( rs2.getString( "messagerurl" ) );
                        String subcompanyid = Util.null2String( rs2.getString( "subcompanyid1" ) );
                        String departmentname = departInfo.getDepartmentName( departmentid );
                        hrmJson.put( "crmNames", "" + departmentname + "／华泰集团" );
                        hrmJson.put( "departmentid", departmentid );
                        hrmJson.put( "departmentidspan", departmentname );
                        hrmJson.put( "departmentname", departmentname );
                        hrmJson.put( "icon", ecologyContentPath+"/messager/usericon/" + workcode + "/" + workcode + ".jpg" );
                        hrmJson.put( "id", id );
                        hrmJson.put( "img", ecologyContentPath+"/messager/usericon/" + workcode + "/" + workcode + ".jpg" );
                        hrmJson.put( "jobtitle", jobtitle );
                        hrmJson.put( "jobtitlename", getJob( id ) );
                        hrmJson.put( "jobtitlespan", getJob( id ) );
                        hrmJson.put( "lastname", lastname );
                        hrmJson.put( "lastnamespan", lastname );
                        hrmJson.put( "messagerurl", messagerurl );
                        hrmJson.put( "mobile", mobile );
                        hrmJson.put( "name", lastname );
                        hrmJson.put( "nodeid", "resource_" + id + "x" );
                        hrmJson.put( "pinyinlastname", pinyinlastname );
                        hrmJson.put( "subcompanyid", subcompanyid );
                        hrmJson.put( "subcompanyid1", subcompanyid );
                        hrmJson.put( "subcompanyname", "华泰集团" );
                        hrmJson.put( "supsubcompanyid", "0" );
                        hrmJson.put( "supsubcompanyname", "" );
                        hrmJson.put( "type", "resource" );
                        hrmJson.put( "workcode", workcode );
                        hrmJson.put( "workcodespan", workcode );
                        replaceDatas.add( hrmJson );
                    }
                }
            }

        }catch (Exception e){
            e.printStackTrace();
            bs.writeLog("-----error-------"+e.getMessage());
        }
        return replaceDatas;
    }

    public static String getJob(String id) {
        RecordSet rs = new RecordSet();
        rs.executeQuery( "select s.jobtitlename from hrmresource h,hrmjobtitles s where h.jobtitle =s.id and h.id='" + id + "'" );
        String jobtitlename = "";
        if (rs.next()) {
            jobtitlename = Util.null2String( rs.getString( "jobtitlename" ) );
        }
        return jobtitlename;
    }

    /**
     *业务主管部门分送节点，获取下一步骤展示选项
     * @param requestid
     */
    public String getNextValue(String requestid){
        BaseBean bs = new BaseBean();
        RecordSet rs = new RecordSet();

        String result = "0,1,2,7,8,13";
        List<String> allDept = new ArrayList<>();
        String tableName = "";
        String mainid = "";
        String sql = "select t3.tablename from WORKFLOW_REQUESTBASE t1,WORKFLOW_BASE t2,WORKFLOW_BILL t3 "
                +"where t2.id = t1.workflowid and t3.id = t2.formid and t1.requestid = '"+requestid+"'";
        bs.writeLog(sql);
        rs.executeQuery(sql);
        if(rs.next()){
            tableName = Util.null2String(rs.getString("tablename"));
        }

        sql = "select id,szbm from "+tableName+" where requestid = '"+requestid+"'";
        bs.writeLog(sql);
        rs.executeQuery(sql);
        if(rs.next()){
            mainid = Util.null2String(rs.getString("id"));
            allDept.add(Util.null2String(rs.getString("szbm")));
        }

        sql = "select hqbm from "+tableName+"_dt2 where mainid = '"+mainid+"' and yhq = '1'";
        bs.writeLog(sql);
        rs.executeQuery(sql);
        while(rs.next()){
            allDept.add(Util.null2String(rs.getString("hqbm")));
        }

        Map<String,String> deptMap = new HashMap<>();
        sql = "select id,departmentcode from hrmdepartment where departmentcode in('ZZ323310','ZZ323311','ZZ001023','ZZ001016','ZZ323314')";
        bs.writeLog(sql);
        rs.executeQuery(sql);
        while(rs.next()){
            deptMap.put(Util.null2String(rs.getString("departmentcode")),Util.null2String(rs.getString("id")));
        }

        if(allDept.contains(deptMap.get("ZZ323310"))){//风险管理部
            result += ",3";
        }
        if(allDept.contains(deptMap.get("ZZ323311"))){//合规法律部
            result += ",4";
        }
        if(allDept.contains(deptMap.get("ZZ001023"))){//党群工作部
            result += ",5";
        }
        if(allDept.contains(deptMap.get("ZZ001016"))||allDept.contains(deptMap.get("ZZ323314"))){//计划财务部、资金运营部
            result += ",6";
        }

        return result;
    }

    /**
     * 获取分支机构会签部门职责（copy）
     * @param formid
     * @param requestid
     * @param workflowid
     * @return
     */
    public Map<String, Object> signDepartment(String formid, Integer requestid, String workflowid) {
        Map<String,Object> datas = new HashMap<>();
        RecordSet rs = new RecordSet();
        BaseBean bs = new BaseBean();
        try {
            bs.writeLog("===signDepartment===执行开始");
            WorkflowBillComInfo workflowBillComInfo = new WorkflowBillComInfo();
            DepartmentComInfo departmentComInfo = new DepartmentComInfo();
            String tableName = VirtualFormHandler.getRealFromName(Util.null2String(workflowBillComInfo.getTablename(formid)));
            //1.获取明细表5的值
            List<Map> dataList = new ArrayList<>();
            rs.executeQuery("select b.hqbm,b.bmzz from "+tableName+" a, "+tableName+"_dt5 b " +
                    " where a.id = b.mainid and a.requestid = ? and b.yhq = 1",requestid);
            while (rs.next()){
                Map<String,Object> specialMap = new HashMap<>();
                String hqbm = Util.null2String(rs.getString("hqbm"));
                String departmentName = departmentComInfo.getDepartmentName(hqbm);
                Integer bmzz = Util.getIntValue(rs.getString("bmzz"));
                specialMap.put("departmentId",hqbm);
                specialMap.put("departmentName",departmentName);
                specialMap.put("bmzz",bmzz);
                dataList.add(specialMap);
            }
            bs.writeLog("==明细表5数据=="+dataList.toString());
            datas.put("datas",dataList);

        }catch (Exception e){
            e.printStackTrace();
        }
        return datas;
    }

    /**
     * 获取上级部门
     * @param deptid
     * @return
     */
    public String getSupdepid (String deptid){
        RecordSet rs = new RecordSet();
        BaseBean bs = new BaseBean();

        String supdepid = "";
        String sql = "select supdepid from hrmdepartment where id = '"+deptid+"'";
        bs.writeLog(sql);
        rs.executeQuery(sql);
        if(rs.next()){
            supdepid = Util.null2String(rs.getString("supdepid"));
        }
        return supdepid;
    }

    /**
     * 获取下级部门
     * @param deptid
     * @return
     */
    public List<String> getSubordinateDeptid (String deptid){
        RecordSet rs = new RecordSet();
        BaseBean bs = new BaseBean();

        List<String> deptidList = new ArrayList<>();
        String sql = "select id from hrmdepartment where supdepid = '"+deptid+"'";
        bs.writeLog(sql);
        rs.executeQuery(sql);
        while(rs.next()){
            deptidList.add(Util.null2String(rs.getString("id")));
        }
        return deptidList;
    }


    /**
     * 根据申报类别类型获取信息
     * @param sblb
     * @param sblx
     * @return
     */
    public Map<String,Object> getInfo (String ssfgs, String sblb, String sblx){
        RecordSet rs = new RecordSet();
        BaseBean bs = new BaseBean();
        Map<String,Object> resultMap = new HashMap<>();

        String bjhqbm = "";
        String ywzgbmglg = "";
        String ywzgbmbsns = "";
        String sfdtsc = "";
        String sql = "select bjhqbm,ywzgbmglg,ywzgbmbsns,sfdtsc from uf_fzjgzysxsyfw where sblb ='" + sblb + "' and sblx='" + sblx + "'";
        bs.writeLog(sql);
        rs.executeQuery(sql);
        if(rs.next()){
            bjhqbm = Util.null2String(rs.getString("bjhqbm"));
            ywzgbmglg = Util.null2String(rs.getString("ywzgbmglg"));
            ywzgbmbsns = Util.null2String(rs.getString("ywzgbmbsns"));
            sfdtsc = Util.null2String(rs.getString("sfdtsc"));
        }

        //必经会签部门
        List<String> deptList = Arrays.asList(bjhqbm.split(","));
        List<Map<String,String>> deptMapList = new ArrayList<>();
        for(String deptid:deptList){
            if(StringUtils.isNotEmpty(deptid)){
                Map<String,String> deptMap = new HashMap<>();
                String deptName = "";
                sql = "select departmentname from hrmdepartment where id = '"+deptid+"'";
                bs.writeLog(sql);
                rs.executeQuery(sql);
                if(rs.next()){
                    deptName = Util.null2String(rs.getString("departmentname"));
                }
                deptMap.put("id",deptid);
                deptMap.put("name",(deptName));
                deptMapList.add(deptMap);
            }
        }
        resultMap.put("bjhqbm",deptMapList);

        //业务主管部门领导
        if("0".equals(sfdtsc)){
            sql = "select ywzgbmglgry,gs from uf_ywzgbmglgrypp where lcid ='fzjgzysx' and lx='" + sblx + "'";
            bs.writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                List<String> gsList = Arrays.asList(Util.null2String(rs.getString("gs")).split(","));
                if(gsList.contains(ssfgs)){
                    ywzgbmglg = Util.null2String(rs.getString("ywzgbmglgry"));
                }
            }
        }
        List<String> ldList = Arrays.asList(ywzgbmglg.split(","));
        List<Map<String,String>> ldMapList = new ArrayList<>();
        for(String userid:ldList){
            if(StringUtils.isNotEmpty(userid)){
                Map<String,String> userMap = new HashMap<>();
                String userName = "";
                sql = "select lastname from hrmresource where id = '"+userid+"'";
                bs.writeLog(sql);
                rs.executeQuery(sql);
                if(rs.next()){
                    userName = Util.null2String(rs.getString("lastname"));
                }
                userMap.put("id",userid);
                userMap.put("name",(userName));
                ldMapList.add(userMap);
            }
        }
        resultMap.put("ywzgbmglg",ldMapList);

        //业务主管部门必送内审
        List<String> nsList = Arrays.asList(ywzgbmbsns.split(","));
        List<Map<String,String>> nsMapList = new ArrayList<>();
        for(String userid:nsList){
            if(StringUtils.isNotEmpty(userid)){
                Map<String,String> userMap = new HashMap<>();
                String userName = "";
                sql = "select lastname from hrmresource where id = '"+userid+"'";
                bs.writeLog(sql);
                rs.executeQuery(sql);
                if(rs.next()){
                    userName = Util.null2String(rs.getString("lastname"));
                }
                userMap.put("id",userid);
                userMap.put("name",(userName));
                nsMapList.add(userMap);
            }
        }
        resultMap.put("ywzgbmbsns",nsMapList);

        return resultMap;
    }

    /**
     * 业务主管部门管理岗，申报类别类型范围
     * @param ywzgbm
     * @return
     */
    public Map<String,Object> getOptionRange(String ywzgbm){
        RecordSet rs = new RecordSet();
        BaseBean bs = new BaseBean();
        Map<String,Object> resultMap = new HashMap<>();

        List<String> rangeList = new ArrayList<>();
        Map<String,Set<String>> rangeMap = new HashMap<>();
        String sql = "select sblb,sblx from uf_fzjgzysxsyfw where ywzgbm = '"+ywzgbm+"'";
        bs.writeLog(sql);
        rs.executeQuery(sql);
        while(rs.next()){
            String sblb = Util.null2String(rs.getString("sblb"));
            String sblx = Util.null2String(rs.getString("sblx"));

            if(StringUtils.isNotEmpty(sblb)){
                Set<String> sblxSet = rangeMap.get(sblb);
                if(sblxSet!=null){
                    sblxSet.add(sblx);
                }else{
                    rangeList.add(sblb);
                    sblxSet = new HashSet<>();
                    sblxSet.add(sblx);
                    rangeMap.put(sblb,sblxSet);
                }
            }
        }

        resultMap.put("sblb",String.join(",",rangeList));
        resultMap.put("sblx",rangeMap);

        return resultMap;
    }

    /**
     * 获取审批过的领导
     * @param requestid
     * @return
     */
    public Map<String,Object> getPassLeader(String requestid){
        PropBean pb = new PropBean();
        RecordSet rs = new RecordSet();
        BaseBean bs = new BaseBean();
        Map<String,Object> resultMap = new HashMap<>();

        Set<String> leaderSet = new HashSet<>();
        String fzjgzysx_gsld_nodeid = pb.getNodeIdsByUnNumber("fzjgzysx_gsld0");
        String sql = "select operator,agentorbyagentid from workflow_requestlog where requestid = '"+requestid+"' and nodeid = '"+fzjgzysx_gsld_nodeid+"'";
        bs.writeLog(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"));
                leaderSet.add(operator);
            }else{
                leaderSet.add(agentorbyagentid);
            }
        }

        List<Map<String,String>> leaderMapList = new ArrayList<>();
        for(String userid:leaderSet){
            if(StringUtils.isNotEmpty(userid)){
                Map<String,String> userMap = new HashMap<>();
                String userName = "";
                sql = "select lastname from hrmresource where id = '"+userid+"'";
                bs.writeLog(sql);
                rs.executeQuery(sql);
                if(rs.next()){
                    userName = Util.null2String(rs.getString("lastname"));
                }
                userMap.put("id",userid);
                userMap.put("name",(userName));
                leaderMapList.add(userMap);
            }
        }
        resultMap.put("passLeader",leaderMapList);

        return resultMap;
    }
}
