package com.engine.htsc.doc.util;

import com.weaver.general.BaseBean;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;

import java.io.*;
import java.util.*;

/**
 * HR工具类
 */
public class HRResourceUtil {

    public static weaver.general.BaseBean bb = new weaver.general.BaseBean();



    /**
     * 根据逗号分隔id获取人员信息
     * @param userIds
     */
    public static List<Map<String,Object>> getUserInfoMap(String userIds) throws Exception{
        List<Map<String,Object>> result = new ArrayList<>();
        if(StringUtils.isNotEmpty(userIds)) {
            String[] userIdArray = userIds.split(",");
            result = getUserInfoMap(userIdArray);
        }
        return result;
    }

    /**
     *
     * @param userIdList
     * @return
     * @throws Exception
     */
    public static  List<Map<String,Object>> getUserInfoMap(List<String> userIdList) throws Exception{
        List<Map<String,Object>> result = new ArrayList<>();
        if(null!=userIdList&&userIdList.size()>0) {
            String[] userIdArray = userIdList.toArray(new String[userIdList.size()]);
            result = getUserInfoMap(userIdArray);
        }
        return result;
    }

    /**
     * 根据工号数组获取人员信息
     * @param userIdArray
     * @return
     * @throws Exception
     */
    public static List<Map<String,Object>> getUserInfoMap(String[] userIdArray) throws Exception {
        ResourceComInfo resourceComInfo = new ResourceComInfo();
        DepartmentComInfo departmentComInfo = new DepartmentComInfo();
        JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
        List<Map<String,Object>> result = new ArrayList<>();
        if (null!=userIdArray&&userIdArray.length > 0) {
            for (String userId : userIdArray) {
                System.out.println("人力HRResourceUtil 获取人员信息 userid:" + userId);
                bb.writeLog("人力HRResourceUtil 获取人员信息 userid:" + userId);
                Map<String, Object> userinfoMap = new HashMap<>();
                userinfoMap.put("lastname", resourceComInfo.getLastname(userId));
                bb.writeLog("人力HRResourceUtil 获取人员信息 lastname:" + resourceComInfo.getLastname(userId));
                userinfoMap.put("userid", userId);
                userinfoMap.put("loginid", resourceComInfo.getLoginID(userId));
                userinfoMap.put("departmentid", resourceComInfo.getDepartmentID(userId));
                userinfoMap.put("departmentname",departmentComInfo.getDepartmentname((String)userinfoMap.get("departmentid")));//部门名称
                userinfoMap.put("jobtitle",resourceComInfo.getJobTitle(userId));//岗位id
                userinfoMap.put("seclevl",resourceComInfo.getSeclevel(userId));//安全等级
                userinfoMap.put("textfield2",resourceComInfo.getTelephone(userId));//联系方式
                userinfoMap.put("workcode",resourceComInfo.getWorkcode(userId));//工号
                userinfoMap.put("belongto",resourceComInfo.getBelongTo(userId));//所属主账号
                userinfoMap.put("DataType","user");//数据类型 提供给前端判断
                result.add(userinfoMap);
            }
        }
        return result;
    }


    /**
     * 根据逗号分割id获取部门信息
     * @param depIds
     */
    public static List<Map<String,Object>> getDepartmentInfoMap(String depIds) throws Exception {
        List<Map<String,Object>> result = new ArrayList<>();
        if(StringUtils.isNotEmpty(depIds)) {
            String[] deptIdArray = depIds.split(",");
            if (deptIdArray.length > 0) {
                result = getDepartmentInfoMap(deptIdArray);
            }
        }
        return result;
    }

    /**
     * 根据部门idlist获取部门信息
     * @param depidList
     * @return
     * @throws Exception
     */
    public static List<Map<String,Object>> getDepartmentInfoMap(List<String> depidList) throws Exception {
        List<Map<String,Object>> result = new ArrayList<>();
        if(null!=depidList&&depidList.size()>0) {
            String[] deptIdArray = depidList.toArray(new String[depidList.size()]);
            result = getDepartmentInfoMap(deptIdArray);
        }
        return result;
    }

    /**
     * 根据部门array获取部门信息
     * @param depIdArray
     * @return
     * @throws Exception
     */
    public static List<Map<String,Object>> getDepartmentInfoMap(String[] depIdArray) throws Exception {
        DepartmentComInfo departmentComInfo = new DepartmentComInfo();
        List<Map<String,Object>> result = new ArrayList<>();
        if (null!=depIdArray&&depIdArray.length > 0) {
            for (String depId : depIdArray) {
                Map<String, Object> deptinfoMap = new HashMap();
                deptinfoMap.put("depId", depId);
                deptinfoMap.put("departmentname", departmentComInfo.getDepartmentname(depId));
                deptinfoMap.put("tlevel", departmentComInfo.getLevelByDepId(depId));//部门层级
                deptinfoMap.put("departmentcode", departmentComInfo.getDepartmentCode(depId));
                deptinfoMap.put("DataType","dept");//数据类型 提供给前端判断
                result.add(deptinfoMap);
            }
        }
        return result;
    }

    /**
     * Map深拷贝
     * @param obj
     * @param <T>
     * @return
     */
    public static <T> Map deepClone(Map obj){
        T clonedObj = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(obj);
            oos.close();

            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bais);
            clonedObj = (T) ois.readObject();
            ois.close();

        }catch (Exception e){
            e.printStackTrace();
        }
        return (Map) clonedObj;
    }

    /**
     * 泛微id比较 返回 in A集合   not in B集合的 ids
     * @param idsA
     * @param idsB
     * @return
     */
    public static String diffInLeftNotInRight(String idsA, String idsB) {
        String result = "";
        List<String> AList = StringUtils.isNotEmpty(idsA)? Arrays.asList(idsA.split(",")):new ArrayList<>();
        List<String> BList = StringUtils.isNotEmpty(idsB)? Arrays.asList(idsB.split(",")):new ArrayList<>();
        if(AList.size()==0) {
            return result;
        }
        if(BList.size()==0) {
            return idsA;
        }
        for(String str : AList) {
            if(BList.contains(str)) {
                continue;
            }else {
                result = result+str+",";
            }
        }
        if(StringUtils.isNotEmpty(result)) {
            result = result.substring(0,result.length()-1);
        }
        return result;
    }


    /**
     * 获取群组详细map信息
     * @param groupIds  群组id 英文逗号分割
     * @return
     */
    public static List<Map<String,Object>> getGroupInfoMap(String groupIds) {
        RecordSet rs = new RecordSet();
        List<Map<String,Object>> result = new ArrayList<>();
        if(StringUtils.isNotEmpty(groupIds)) {
            if(groupIds.endsWith(",")) {
                groupIds = groupIds.substring(0,groupIds.length()-1);
            }
            String sql = " select * from hrmgroup t where t.id in ("+ groupIds+")";
            bb.writeLog("HRResourceUtil getGroupInfoMap查询sql:"+sql);
            rs.executeQuery(sql);
            while(rs.next()) {
                Map<String,Object> record = new HashMap<>();
                String columnNames[] = rs.getColumnName();
                for(int i=0;i<columnNames.length;i++) {
                    String fieldName = columnNames[i].toLowerCase();
                    String fieldValue = Util.null2String(rs.getString(fieldName));
                    record.put(fieldName, fieldValue);
                }
                record.put("DataType","group");
                result.add(record);
            }
        }
        return result;
    }

    /**
     * 获取组织架构信息
     * @param orgIds
     * @return
     * @throws Exception
     */
    public static List<Map<String,Object>> getOrgInfoMap(String orgIds) throws Exception {
        List<Map<String,Object>> result = new ArrayList<>();
        if(StringUtils.isNotEmpty(orgIds)) {
            String[] deptIdArray = orgIds.split(",");
            if (deptIdArray.length > 0) {
                result = getOrgInfoMap(deptIdArray);
            }
        }
        return result;
    }

    /**
     * 根据组织架构id获取组织架构信息
     * @param orgIdArray
     * @return
     * @throws Exception
     */
    public static List<Map<String,Object>> getOrgInfoMap(String[] orgIdArray) throws Exception {
        DepartmentComInfo departmentComInfo = new DepartmentComInfo();
        List<Map<String,Object>> result = new ArrayList<>();
        if (null!=orgIdArray&&orgIdArray.length > 0) {
            for (String orgId : orgIdArray) {
                Map<String, Object> orginfoMap = new HashMap();
                orginfoMap.put("depId", orgId);
                orginfoMap.put("departmentname", departmentComInfo.getDepartmentname(orgId));
                orginfoMap.put("tlevel", departmentComInfo.getLevelByDepId(orgId));//部门层级
                orginfoMap.put("departmentcode", departmentComInfo.getDepartmentCode(orgId));
                orginfoMap.put("DataType","org");//数据类型 提供给前端判断
                result.add(orginfoMap);
            }
        }
        return result;
    }

    /**
     * 根据用户id获取工号list
     * @param userIds
     * @return
     * @throws Exception
     */
    public static List<String> getUserBadgeList(String userIds) throws Exception{
        List<String> result = new ArrayList<>();
        if(StringUtils.isNotEmpty(userIds)) {
            String[] userIdArray = userIds.split(",");
            result = getUserBadgeList(userIdArray);
        }
        return result;
    }

    /**
     * 根据用户id数组获取工号list
     * @param userIdArray
     * @return
     * @throws Exception
     */
    public static List<String> getUserBadgeList(String[] userIdArray) throws Exception {
        ResourceComInfo resourceComInfo = new ResourceComInfo();
        DepartmentComInfo departmentComInfo = new DepartmentComInfo();
        JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
        List<String> result = new ArrayList<>();
        if (null!=userIdArray&&userIdArray.length > 0) {
            for (String userId : userIdArray) {
                result.add(resourceComInfo.getWorkcode(userId));
            }
        }
        return result;
    }


    /**
     * 根据部门ids获取部门编码list
     * @param depIds
     * @return
     * @throws Exception
     */
    public static List<String> getDeptcodeList(String depIds) throws Exception {
        List<String> result = new ArrayList<>();
        if(StringUtils.isNotEmpty(depIds)) {
            String[] deptIdArray = depIds.split(",");
            if (deptIdArray.length > 0) {
                result = getDeptcodeList(deptIdArray);
            }
        }
        return result;
    }


    /**
     * 根据部门ids获取部门编码list
     * @param depidList
     * @return
     * @throws Exception
     */
    public static List<String> getDeptcodeList(List<String> depidList) throws Exception {
        List<String> result = new ArrayList<>();
        if(null!=depidList&&depidList.size()>0) {
            String[] deptIdArray = depidList.toArray(new String[depidList.size()]);
            result = getDeptcodeList(deptIdArray);
        }
        return result;
    }

    /**
     * 根据部门array获取部门编码list
     * @param depIdArray
     * @return
     * @throws Exception
     */
    public static List<String> getDeptcodeList(String[] depIdArray) throws Exception {
        DepartmentComInfo departmentComInfo = new DepartmentComInfo();
        List<String> result = new ArrayList<>();
        if (null!=depIdArray&&depIdArray.length > 0) {
            for (String depId : depIdArray) {
                result.add(departmentComInfo.getDepartmentCode(depId));
            }
        }
        return result;
    }


    /**
     * 根据部门ids获取部门编码list
     * @param orgIds
     * @return
     * @throws Exception
     */
    public static List<String> getOrgcodeList(String orgIds) throws Exception {
        List<String> result = new ArrayList<>();
        if(StringUtils.isNotEmpty(orgIds)) {
            String[] orgIdArray = orgIds.split(",");
            if (orgIdArray.length > 0) {
                result = getOrgcodeList(orgIdArray);
            }
        }
        return result;
    }


    /**
     * 根据组织架构ids获取部门编码list
     * @param orgidList
     * @return
     * @throws Exception
     */
    public static List<String> getOrgcodeList(List<String> orgidList) throws Exception {
        List<String> result = new ArrayList<>();
        if(null!=orgidList&&orgidList.size()>0) {
            String[] orgIdArray = orgidList.toArray(new String[orgidList.size()]);
            result = getOrgcodeList(orgIdArray);
        }
        return result;
    }

    /**
     * 根据组织架构array获取部门编码list
     * @param orgIdArray
     * @return
     * @throws Exception
     */
    public static List<String> getOrgcodeList(String[] orgIdArray) throws Exception {
        DepartmentComInfo departmentComInfo = new DepartmentComInfo();
        List<String> result = new ArrayList<>();
        if (null!=orgIdArray&&orgIdArray.length > 0) {
            for (String orgId : orgIdArray) {
                result.add(departmentComInfo.getDepartmentCode(orgId));
            }
        }
        return result;
    }


    /**
     * 获取群组老oacodelist
     * @param groupIds  群组id 英文逗号分割
     * @return
     */
    public static List<String> getGroupcodeList(String groupIds) {
        RecordSet rs = new RecordSet();
        List<String> result = new ArrayList<>();
        if(StringUtils.isNotEmpty(groupIds)) {
            if(groupIds.endsWith(",")) {
                groupIds = groupIds.substring(0,groupIds.length()-1);
            }
            String sql = " select * from hrmgroup t where t.id in ("+ groupIds+")";
            bb.writeLog("HRResourceUtil getGroupInfoMap查询sql:"+sql);
            rs.executeQuery(sql);
            while(rs.next()) {
                result.add(rs.getString("mappinggroupcode"));
            }
        }
        return result;
    }


    /**
     * 根据泛微部门id获取所有下级部ids（不包含本级)
     * @param deptId
     * @return
     */
    public static List<String> getAllSubDeptIds(String deptId) {
        RecordSet rs = new RecordSet();
        String sql = " select t.id from HRMDEPARTMENT t where t.supdepid = ? ";
        List<String> subDeptList = new ArrayList<>();
        List<String> tempList = new ArrayList<>();
        rs.executeQuery(sql,new Object[]{deptId});
        while(rs.next()) {
            subDeptList.add(rs.getString("id"));
        }
        tempList.addAll(subDeptList);
        for(String tempid : subDeptList) {
            List<String> deptlist = getAllSubDeptIds(tempid);
            if(deptlist != null )tempList.addAll(deptlist);
        }
        return tempList;
    }

    /**
     * 根据部门ids获取该部门下面的所有人员ids 排除离职人员
     * @param depIdList
     * @return
     */
    public static List<String> getAllUserIdsByDeptIds(List<String> depIdList) {
        RecordSet rs = new RecordSet();
        //将部门idlist拆分 按照每500个部门编码一个id字符串逗号分割 拼in查询条件 oracle in查询上限999
        List<String> perDepids = BeanUtil.splitByPerNum(depIdList,500);
        List<String> userIdList = new ArrayList<>();
        for(String depid : perDepids) {
            String sql = " select t1.id from hrmresource t1, hrmjobtitles t2,HRMDEPARTMENT t3 where t1.jobtitle = t2.id and t2.jobdepartmentid = t3.id and t1.status = 1 " +
                    "and t3.id in ("+depid+") ";
            bb.writeLog("HRResourseUtil根据部门id获取下面在职芸芸众生sql:"+sql);
            rs.executeQuery(sql);
            while(rs.next()) {
                userIdList.add(rs.getString("id"));
            }
        }
        return userIdList;
    }

    /**
     * 根据群组idlist获取这些群组下所有的人员id
     * @param orgIdList
     * @return
     */
    public static List<String> getAllUserIdsByGroupIds(List<String> orgIdList) {
        RecordSet rs = new RecordSet();
        List<String> perOrgIds = BeanUtil.splitByPerNum(orgIdList,500);
        List<String> userIdList = new ArrayList<>();
        for(String orgid : perOrgIds) {
            String sql = " select t.userid from hrmgroupmembers t where t.groupid in ( "+ orgid+" )";
            bb.writeLog("HRResourseUtil根据群组id获取下面在职芸芸众生sql:"+sql);
            rs.executeQuery(sql);
            while(rs.next()) {
                userIdList.add(rs.getString("userid"));
            }
        }
        bb.writeLog("HRResourseUtil getAllUserIdsByGroupIds 获取的群组userid大小:"+userIdList.size());
        return userIdList;
    }



    /**
     * 根据人员id 部门id 机构id 群组id获取下面所有的芸芸众生
     * @param userIdList 人员ids
     * @param depIdList 部门ids
     * @param orgIdList 组织架构ids
     * @param groupIdList 群组ids
     * @param excepDeptIdList 需要排除的部门ids
     * @return
     */
    public static List<String> getAllUserIdsByUserIdDepIdOrgIdGroupId(List<String> userIdList,List<String> depIdList,
                                                                      List<String> orgIdList,List<String> groupIdList,
                                                                      List<String> excepDeptIdList) {
        List<String> fianlList = new ArrayList<>();
        List<String> tempDepIdsList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(depIdList)) {
            tempDepIdsList.addAll(depIdList);
        }
        if(CollectionUtils.isNotEmpty(orgIdList)) {//如果是组织架构的部门编码，则将下面所有的部门查出来塞进去
            for(String orgId : orgIdList) {
                tempDepIdsList.addAll(getAllSubDeptIds(orgId));
            }
        }
        if(CollectionUtils.isNotEmpty(excepDeptIdList)&&CollectionUtils.isNotEmpty(tempDepIdsList)) {
            tempDepIdsList.removeAll(excepDeptIdList);//排除掉一些特殊逻辑下需要干掉的部门
        }

        //添加人
        if(CollectionUtils.isNotEmpty(userIdList)) {
            fianlList.addAll(userIdList);
        }
        //添加部门+组织架构里面的人
        if(CollectionUtils.isNotEmpty(tempDepIdsList)) {
            fianlList.addAll(getAllUserIdsByDeptIds(tempDepIdsList));
        }
        //添加群组里面的人
        if(CollectionUtils.isNotEmpty(groupIdList)) {
            fianlList.addAll(getAllUserIdsByGroupIds(groupIdList));
        }

        //去重且保持顺序
        BeanUtil.removeDuplicateWithOrder(fianlList);
        return fianlList;
    }

    /**
     * 根据用户的一个userid查询此人所有的userid
     * @param userIds 支持单个userid或多个userid逗号分割
     * @return
     */
    public static String getAllUserIdsByUserIds(String userIds) {
        RecordSet rs = new RecordSet();
        String allUserIds = "";
        String queryAllUserIdsSQL = " select t.id from hrmresource t where t.workcode in ( " +
                "select t2.workcode from hrmresource t2 where t2.id in ( "+ userIds +" ))";
        rs.executeQuery(queryAllUserIdsSQL);
        while (rs.next()) {
            allUserIds = allUserIds+rs.getString("id")+",";
        }
        if(StringUtils.isNotEmpty(allUserIds)) {
            allUserIds = allUserIds.substring(0,allUserIds.length()-1);
        }
        return allUserIds;
    }

    /**
     * 根据一个人userid返回所有主兼岗的部门ids
     * @param userIds  支持单个userid或多个userid逗号分割
     * @return
     */
    public static String getAllDepartmentIdsByUserIds(String userIds) {
        RecordSet rs = new RecordSet();
        String departmentIds = "";
        String queryAllUserIdsSQL = " select t.departmentid from hrmresource t where t.workcode in ( " +
                "select t2.workcode from hrmresource t2 where t2.id in ( "+userIds+" ))";
        rs.executeQuery(queryAllUserIdsSQL);
        while (rs.next()) {
            departmentIds = departmentIds+rs.getString("departmentid")+",";
        }
        if(StringUtils.isNotEmpty(departmentIds)) {
            departmentIds = departmentIds.substring(0,departmentIds.length()-1);
        }
        return departmentIds;
    }

    /**
     * 根据用户ids获取这些用户身份所属部门 （精确）
     * @param userIds
     * @return
     */
    public static String getExactDepartmentIdsByUserIds(String userIds) {
        RecordSet rs = new RecordSet();
        String departmentIds = "";
        String querySQL = "  select t.departmentid from hrmresource t where t.id in ("+userIds+" )";
        rs.executeQuery(querySQL);
        while (rs.next()) {
            departmentIds = departmentIds+rs.getString("departmentid")+",";
        }
        if(StringUtils.isNotEmpty(departmentIds)) {
            departmentIds = departmentIds.substring(0,departmentIds.length()-1);
        }
        return departmentIds;
    }


    /**
     * 根据用户的userid获取所在的所有群组
     * @param userId
     * @return
     */
    public static String getBelongGroupIdsByUserId(String userId) {
        RecordSet rs = new RecordSet();
        String allGroupId = "";//当前人所在的群组
        String queryBelongGroupSQL = " select t.groupid from hrmgroupmembers t where t.userid = ?";
        rs.executeQuery(queryBelongGroupSQL,new Object[] {userId});
        while (rs.next()) {
            allGroupId = allGroupId+rs.getString("groupid")+",";
        }
        if(StringUtils.isNotEmpty(allGroupId)) {
            allGroupId = allGroupId.substring(0,allGroupId.length()-1);
        }
        return allGroupId;
    }

    /**
     * 根据部门ids（逗号分割）获取所有的用户idlist
     * @param depIds
     * @return
     */
    public static List<String> getUserIdListByDepIds(String depIds) {
        RecordSet rs = new RecordSet();
        List<String> userIdList = new ArrayList<>();
        String queryCircualatePeopleSQL = " select t.id from hrmresource t where t.status = '1' and t.departmentid in ( "+ depIds +" ) order by t.departmentid,t.seclevel desc ";
        rs.executeQuery(queryCircualatePeopleSQL);
        while(rs.next()) {
            userIdList.add(rs.getString("id"));
        }
        return userIdList;
    }

    /**
     * 根据群组ids（逗号分割）获取所有的用户idlist
     * @param groupIds
     * @return
     */
    public static List<String> getUserIdListByGroupIds(String groupIds) {
        RecordSet rs = new RecordSet();
        List<String> userIdList = new ArrayList<>();
        String querySQL = "  select t.userid from hrmgroupmembers t where t.groupid in ( "+ groupIds +" )";
        rs.executeQuery(querySQL);
        while(rs.next()) {
            userIdList.add(rs.getString("userid"));
        }
        return userIdList;
    }

    /**
     * 根据群组中文名获取逗号分割的部门Ids
     * @param groupName 单个群组名
     * @return   6,5
     */
    public static String getDepartmentIdsByGroupName(String groupName) {
        RecordSet rs = new RecordSet();
        String querySQL = "";
        String depIds = "";
        if("华泰总部部门".equals(groupName)) {
            querySQL = " select t.id from HRMDEPARTMENT t,hrmdepartmentdefined t2 where t2.deptid = t.id and t2.depttypecode = 'JGLX01' and t.departmentcode not in ( " +
                       " 'ZZ323470','ZZ323471','ZZ001001','ZZ001040','ZZ323390','ZZ001109','ZZ323389','ZZ323458','ZZ323455','ZZ323257' ) ";

        }else if ("所有分公司".equals(groupName)) {
            querySQL = " select t.id from HRMDEPARTMENT t,hrmdepartmentdefined t2 where t2.deptid = t.id and t2.depttypecode in( 'JGLX03' ,'JGLX09') ";
        }else if ("所有营业部".equals(groupName)) {
            querySQL = " select t.id from HRMDEPARTMENT t,hrmdepartmentdefined t2 where t2.deptid = t.id and t2.depttypecode = 'JGLX04' ";
        }
        bb.writeLog("群组转换部门:"+groupName+" querySQL:"+querySQL);
        rs.executeQuery(querySQL);
        while(rs.next()) {
            depIds = depIds+rs.getString("id")+",";
        }
        if(StringUtils.isNotEmpty(depIds)) {
            depIds =depIds.substring(0,depIds.length()-1);
        }
        return depIds;
    }

    /**
     * 根据群组id获取逗号分割的人员Ids
     * @param groupId 单个群组Id
     * @return 5862,28302
     */
    public static String getUserIdsByGroupId(String groupId) {
        RecordSet rs = new RecordSet();
        String querySQL = " select t2.userid from hrmgroup t,hrmgroupmembers t2 where t.id = t2.groupid and t.id = ? ";
        String userIds = "";
        bb.writeLog("群组转换人员:"+groupId+" querySQL:"+querySQL);
        rs.executeQuery(querySQL,new Object[]{groupId});
        while (rs.next()) {
            userIds = userIds +rs.getString("userid")+",";
        }
        if(StringUtils.isNotEmpty(userIds)) {
            userIds = userIds.substring(0,userIds.length()-1);
        }
        return userIds;
    }




    public static void main(String args[]) {
        String a1 = "";
        String a2 = "1,2,3,13";
        String b1 = "";
        String b2 = "4,13";
        System.out.println("测试集合差异"+diffInLeftNotInRight(a1,b1));
        System.out.println("测试集合差异"+diffInLeftNotInRight(a1,b2));
        System.out.println("测试集合差异"+diffInLeftNotInRight(a2,b1));
        System.out.println("测试集合差异"+diffInLeftNotInRight(a2,b2));

        String targetGroups = "3003,3007,3005,3006";
        String hasGroupIds = "3003,3005,3006";

        String needGroupIds = HRResourceUtil.diffInLeftNotInRight(targetGroups,hasGroupIds);



        System.out.println("???");
    }

}
