package com.engine.htsc.zbzysx.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.Util;
import weaver.hrm.company.DepartmentComInfo;

import java.util.Arrays;
import java.util.List;

public class ZbzysxUtil {

    /***
     *
     * @param deptid
     * @return
     */
    public String getDeptleaders(String deptid)
    {
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        DepartmentComInfo departmentComInfo = null;
        try{
            departmentComInfo = new DepartmentComInfo();
        }catch (Exception e){

        }
        String deptcode = departmentComInfo.getDepartmentCode(deptid);
        String excludeId = "ZZ001014,ZZ323472" ;

        String definUserid = "22797";  //周易
        String deptleaders = "";

        if((","+excludeId+",").contains(","+deptcode+","))
        {
            rs.executeQuery( " select deptleaders from hrmdepartmentdefined where deptid='" + deptid + "'" );
            if (rs.next()) {
                deptleaders = Util.null2String( rs.getString( "deptleaders" ) );
            }
            deptleaders += deptleaders =="" ? definUserid : ","+definUserid;
        }else{
            rs.executeQuery( "select deptleaders from hrmdepartmentdefined where deptid='" + deptid + "'" );
            if (rs.next()) {
                deptleaders = Util.null2String( rs.getString( "deptleaders" ) );
            }
        }
        bb.writeLog("deptleaders:"+deptleaders);
        return deptleaders;
    }

    /***
     *
     * @param sblb
     * @param sblx
     * @return
     */
//    public JSONArray getReplaceDatas(String sblb, String sblx)
//    {
//        RecordSet rs = new RecordSet();
//        RecordSet rs1 = new RecordSet();
//        RecordSet rs2 = new RecordSet();
//        BaseBean bb = new BaseBean();
//        JSONArray replaceDatas = new JSONArray();
//        DepartmentComInfo  departInfo = null;
//        try{
//            departInfo = new DepartmentComInfo();
//
//            String qzsydxs = "";
//            String qzsyrys = "";
//            String sql = " select qzsydx,qzsyry from uf_zysxsyfw where sblb ='" + sblb + "' and sblx='" + sblx + "'";
//            rs.executeQuery( sql );
//            if (rs.next()) {
//                qzsydxs = Util.null2String(rs.getString("qzsydx"));//强制送阅部门
//                qzsyrys = Util.null2String(rs.getString("qzsyry"));//强制送阅人员
//            }
//
//            bb.writeLog("qzsydxs:"+qzsydxs);
//            bb.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();
//                    bb.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 + " ";
//                    bb.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", "/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 + ") ";
//                bb.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", "/messager/usericon/" + workcode + "/" + workcode + ".jpg" );
//                    hrmJson.put( "id", id );
//                    hrmJson.put( "img", "/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){
//
//        }
//        return replaceDatas;
//    }


    /***
     *
     * @param sblb
     * @param sblx
     * @return
     */
    public JSONArray getReplaceDatas(String sblb,String sblx)
    {
        String ecologyContentPath = GCONST.getContextPath();
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        RecordSet rs2 = new RecordSet();
        BaseBean bb = new BaseBean();
        JSONArray replaceDatas = new JSONArray();
        DepartmentComInfo  departInfo = null;
        try{
            departInfo = new DepartmentComInfo();

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

            bb.writeLog("qzsydxs:"+qzsydxs);
            bb.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();
                    bb.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 + " ";
                    bb.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 + ") ";
                bb.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 );
                }
            }

//            String[] children = new String[0];
//            if (rs.next()) {
//                JSONObject deptJson = new JSONObject();
//                String qzsydx = Util.null2String( rs.getString( "qzsydx" ) );//强制送阅部门
//                String qzsyrys = Util.null2String( rs.getString( "qzsyry" ) );//强制送阅人员
//                if (!"".equals( qzsydx ) && !"".equals( qzsyrys )) {
//                    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 in (" + qzsydx + ") and h.status='1'";
//                    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", "/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 );
//
//                    String[] arr = qzsyrys.split( "," );
//                    String newqzsyry = "";
//                    for (String qzsyry : arr) {
//                        newqzsyry += newqzsyry == "" ? "'" + qzsyry + "'" + "" : "," + "'" + qzsyry + "'";
//                    }
//                    String sql2 = "select id,lastname,workcode,departmentid,jobtitle,mobile,pinyinlastname,messagerurl,subcompanyid1 from hrmresource where id in (" + newqzsyry + ") and status='1'";
//                    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", "/messager/usericon/" + workcode + "/" + workcode + ".jpg" );
//                        hrmJson.put( "id", id );
//                        hrmJson.put( "img", "/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 );
//                    }
//
//                } else if (!"".equals( qzsydx ) && "".equals( qzsyrys )) {
//                    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 in (" + qzsydx + ") and h.status='1'";
//                    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", qzsydxname );
//                        userJson.put( "departmentname", qzsydxname );
//                        userJson.put( "displayKeys", displayKeys );
//                        userJson.put( "icon", "/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 );
//                } else if ("".equals( qzsydx ) && !"".equals( qzsyrys )) {
//                    String[] arr = qzsyrys.split( "," );
//                    String newqzsyry = "";
//                    for (String qzsyry : arr) {
//                        newqzsyry += newqzsyry == "" ? "'" + qzsyry + "'" + "" : "," + "'" + qzsyry + "'";
//                    }
//                    String sql2 = "select id,lastname,workcode,departmentid,jobtitle,mobile,pinyinlastname,messagerurl,subcompanyid1 from hrmresource where id in (" + newqzsyry + ") and status='1'";
//                    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 subcompanyid1 = 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", "/messager/usericon/" + workcode + "/" + workcode + ".jpg" );
//                        hrmJson.put( "id", id );
//                        hrmJson.put( "img", "/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", subcompanyid1 );
//                        hrmJson.put( "subcompanyid1", subcompanyid1 );
//                        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){

        }

        return replaceDatas;
    }


    /***
     *
     * @param id
     * @return
     */
    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;
    }


}
