package com.engine.htsc.subcompany.tools;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.htsc.subcompany.dao.UfZgssplDao;
import com.engine.htsc.subcompany.model.ReportSequenceVO;
import com.engine.htsc.subcompany.model.UfZgsspl;
import com.engine.htsc.subcompany.model.ZgsDept;
import com.engine.htsc.subcompany.model.ZgsUser;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.cus.HTUtil;

import java.util.*;
import java.util.stream.Collectors;

public class UfzgsServiceTools {

    private final UfZgssplDao ufZgssplDao = new UfZgssplDao();

    public List<ReportSequenceVO> convertModelToVO(List<UfZgsspl> ufZgssplList, String userId, HashMap<String, String> map, String unumbercode) {
        List<ReportSequenceVO> resultList = new ArrayList<>();
        //获取人员及部门信息
        ZgsUser zgsUser = new ZgsUser(userId);
        //是否为紫金的费用承担部门
        String fycdbm = Util.null2String(map.get("fycdbm"));
        List<UfZgsspl> ufFzjgsplPhone = new ArrayList<>();
        List<UfZgsspl> ufFzjgsplCode = new ArrayList<>();
        List<UfZgsspl> ufFzjgsplRy = new ArrayList<>();
        List<UfZgsspl> ufFzjgsplFycd = new ArrayList<>();
        List<UfZgsspl> ufFzjgsplBm = new ArrayList<>();
        List<UfZgsspl> ufFzjgsplBms = new ArrayList<>();
        List<UfZgsspl> ufFzjgspljg = new ArrayList<>();
        List<UfZgsspl> ufFzjgspljgS = new ArrayList<>();
        List<UfZgsspl> UfZgssplListR = new ArrayList<>();
        //过滤审批链
        for(UfZgsspl ufZgsspl:ufZgssplList){
            //判断条件
            if(null!=ufZgsspl.getTj()&&!"".equals(ufZgsspl.getTj())){
                if(!getConitionParams(ufZgsspl.getTj(),map)){
                    continue;
                }
            }
            //判断是否符合部门 人员>费用承担部门>部门>机构
            List<String> list = Arrays.asList(ufZgsspl.getBm().split(","));
            //判断为手机费
            if (!"".equals(Util.null2String(map.get("code")))&&"LHMobileFee".equals(Util.null2String(map.get("code")))&&"code=LHMobileFee".equals(ufZgsspl.getTj())){
                ufFzjgsplPhone.add(ufZgsspl);
            }else if (ufZgsspl.getCxsprjs().equals("WK_"+zgsUser.getWorkCode())&&ufZgsspl.getBm().equals(zgsUser.getDepId())){
                ufFzjgsplRy.add(ufZgsspl);//单人，联合部分为董事会或执行委员会成员,且要是董事会或执行委员会的账号
            }else if (!"0".equals(Util.null2String(map.get("code")))&&!"".equals(Util.null2String(map.get("code")))&&list.contains(zgsUser.getDepId())&&ufZgsspl.getTj().contains("code")){
                ufFzjgsplCode.add(ufZgsspl);//费用承担部门执行委员会，董事会，部门为综合管理部
            }else if(list.contains(fycdbm)&&list.size()==1){
                ufFzjgsplFycd.add(ufZgsspl);//单个费用承担
            }else if (list.contains(zgsUser.getDepId())&&list.size()==1){
                ufFzjgsplBm.add(ufZgsspl);//单个部门
            }else if (list.contains(zgsUser.getZgsDept().getDepCode())||list.contains(zgsUser.getDepId())){
                ufFzjgsplBms.add(ufZgsspl);//多部门
            }else if (ufZgsspl.getBm().equals(zgsUser.getZgsDept().getDepTypeCode())){
                ufFzjgspljg.add(ufZgsspl);//机构中的几个部门
            }else if (ufZgsspl.getJg().equals(zgsUser.getZgsDept().getDepTypeCode())&&"".equals(Util.null2String(ufZgsspl.getBm()))){
                ufFzjgspljgS.add(ufZgsspl);//单个机构所有部门
            }
        }
        if (ufFzjgsplPhone.size()>0){
            UfZgssplListR.addAll(ufFzjgsplPhone);
        }else if (ufFzjgsplRy.size()>0){
            UfZgssplListR.addAll(ufFzjgsplRy);
        }else if (ufFzjgsplCode.size()>0){
            UfZgssplListR.addAll(ufFzjgsplCode);
        }else if (ufFzjgsplFycd.size()>0){
            UfZgssplListR.addAll(ufFzjgsplFycd);
        }else if (ufFzjgsplBm.size()>0){
            UfZgssplListR.addAll(ufFzjgsplBm);
        }else if (ufFzjgsplBms.size()>0){
            UfZgssplListR.addAll(ufFzjgsplBms);
        }else if (ufFzjgspljg.size()>0){
            UfZgssplListR.addAll(ufFzjgspljg);
        }else {
            UfZgssplListR.addAll(ufFzjgspljgS);
        }
        for(UfZgsspl ufZgsspl:UfZgssplListR){
            JAVATools.writelog("筛选审批链id为："+ufZgsspl.getId());
            ReportSequenceVO reportSequenceVO = getVo(ufZgsspl,zgsUser,map,unumbercode);
            resultList.add(reportSequenceVO);
        }
        return resultList;
    }

    protected ReportSequenceVO getVo(UfZgsspl ufZgsspl, ZgsUser zgsUser, HashMap<String, String> map, String unumbercode) {
        ReportSequenceVO reportSequenceVO = new ReportSequenceVO();
        reportSequenceVO.setNgr(Util.null2String(map.get("ngr")));
        reportSequenceVO.setHqbmfzr(Util.null2String(map.get("hqbmfzr")));
        reportSequenceVO.setZgsUser(zgsUser);
        reportSequenceVO.setZgsDept(zgsUser.getZgsDept());
        reportSequenceVO.setReportSequenceId(ufZgsspl.getId().toString());
        String xmfzr = "";
        String xmssbmfzr = "";
        //费用确认
        reportSequenceVO.setFyqr(getFyqr(Util.null2String(ufZgsspl.getFyqr()),map,zgsUser));
        if (null!=map.get("xm")&&!"".equals(map.get("xm"))){
            Map<String, Object> paras = new HashMap<>();
            paras = getProject(map.get("xm"));
            //项目负责人
            xmfzr = Util.null2String(paras.get("thxmfzr"));
            //项目所属部门负责人
            xmssbmfzr = Util.null2String(paras.get("xmfzbmfzr"));
        }
        //项目负责人（联合投行项目特有）
        reportSequenceVO.setXmfzr(getXmfzr(Util.null2String(ufZgsspl.getXmfzr()),xmfzr));
        //直接上级审核（香港特有）
        reportSequenceVO.setZjsjsh(getZjsjsh(Util.null2String(ufZgsspl.getZjsjsh()),map,zgsUser));
        //二级部门负责人
        reportSequenceVO.setEjbmfzr(getEjbmfzr(Util.null2String(ufZgsspl.getEjbmfzr()),map,zgsUser));
        //投行区域负责人（联合投行等二级部特有）
        reportSequenceVO.setThqyfzr(getThqyfzr(Util.null2String(ufZgsspl.getThqyfzr()),map,zgsUser));
        //一级部门负责人
        reportSequenceVO.setYjbmfzr(getYjbmfzr(Util.null2String(ufZgsspl.getYjbmfzr()),map,zgsUser));
        //项目所属部门负责人
        reportSequenceVO.setXmssbmfzr(getXmssbmfzr(Util.null2String(ufZgsspl.getXmssbmfzr()),xmssbmfzr));
        //财务中心会计,数据库直接配置
        reportSequenceVO.setKj(getKj(Util.null2String(ufZgsspl.getKj()),map,zgsUser));
        //财务中心经理，数据库直接配置
        reportSequenceVO.setCwjl(getCwjl(Util.null2String(ufZgsspl.getCwjl()),map,zgsUser));
        //固收业务负责人（资管特有）固收业务负责人目前配死008872
        reportSequenceVO.setGsywfzr(getGsywfzr(Util.null2String(ufZgsspl.getGsywfzr()),map,zgsUser));
        //费用承担部门负责人（紫金虚拟基金特有）
        reportSequenceVO.setFycdbmfzr(getFycdbmfzr(Util.null2String(ufZgsspl.getFycdbmfzr()),map,zgsUser));
        //分管领导
        reportSequenceVO.setFgld(getFgld(Util.null2String(ufZgsspl.getFgld()),map,zgsUser));
        //财务分管领导（联合付款特有）
        reportSequenceVO.setCwfgld(getCwfgld(Util.null2String(ufZgsspl.getCwfgld()),map,zgsUser));
        //子公司总经理
        reportSequenceVO.setZgszjl(getZgszjl(Util.null2String(ufZgsspl.getZgszjl()),map,zgsUser));
        //总裁（联合特有）
        reportSequenceVO.setZc(getZc(Util.null2String(ufZgsspl.getZc()),map,zgsUser));
        //子公司董事长
        reportSequenceVO.setZgsdsz(getZgsdsz(Util.null2String(ufZgsspl.getZgsdsz()),map,zgsUser));
        //会计处理（联合特有）
        reportSequenceVO.setKjcl(getKjcl(Util.null2String(ufZgsspl.getKjcl()),map,zgsUser));
        //出纳（暂定为空）
        reportSequenceVO.setCn(getCn(zgsUser,unumbercode,map));
        //费用岗审核
        reportSequenceVO.setFyg(getNormal(Util.null2String(ufZgsspl.getFyg())));
        //首席运营官
        reportSequenceVO.setSxyyg(getNormal(Util.null2String(ufZgsspl.getSxyyg())));
        //首席执行官
        reportSequenceVO.setSxzxg(getNormal(Util.null2String(ufZgsspl.getSxzxg())));
        //财务中心出纳
        reportSequenceVO.setCwzxcn(getNormal(Util.null2String(ufZgsspl.getCwzxcn())));
        //会签部门法律部
        reportSequenceVO.setHqbmflb(getFzrByBm(Util.null2String(ufZgsspl.getHqbmflb())));
        //会签部门风险管理部
        reportSequenceVO.setHqbmfxglb(getFzrByBm(Util.null2String(ufZgsspl.getHqbmfxglb())));
        //总部资金管理岗
        reportSequenceVO.setZbzjglg(getNormal(Util.null2String(ufZgsspl.getZbzjglg())));
        //总部资金运营部负责人
        reportSequenceVO.setZbzjyybfzr(getFzrByBm(Util.null2String(ufZgsspl.getZbzjyybfzr())));
        //集团领导
        reportSequenceVO.setJtld(getNormal(Util.null2String(ufZgsspl.getJtld())));
        //首席财务官
        reportSequenceVO.setSxcwg(getNormal(Util.null2String(ufZgsspl.getSxcwg())));
        //首席风险官
        reportSequenceVO.setSxfxg(getNormal(Util.null2String(ufZgsspl.getSxfxg())));
        //预算管理员
        reportSequenceVO.setYsgly(getNormal(Util.null2String(ufZgsspl.getYsgly())));
        //财务管理部负责人
        reportSequenceVO.setCwglbfzr(getNormal(Util.null2String(ufZgsspl.getCwglbfzr())));
        //工会主席
        reportSequenceVO.setGhzx(getNormal(Util.null2String(ufZgsspl.getGhzx())));
        return reportSequenceVO;
    }

    private Map<String, Object> getProject(String projectId) {
        Map<String, Object> result = new HashMap<>();
        HTUtil ht = new HTUtil();
        Map<String, Object> paras = new HashMap<>();
        paras.put("projectId", String.valueOf(projectId));
        String projectInfo = ht.getProjectById(paras);
        Set<String> thxmfzrSet = new HashSet<>();
        Set<String> xmfzbmfzrSet = new HashSet<>();
        if (StringUtils.isNotBlank(projectInfo)) {
            JSONObject jsonObject = JSON.parseObject(projectInfo);
            String userCodes = (String) jsonObject.get("userIds1");
            if (!StringUtils.isBlank(userCodes)) {
                String[] userCodesArr = userCodes.split(",");
                Set<String> tempSet = Arrays.stream(userCodesArr).filter(StringUtils::isNotBlank)
                        .collect(Collectors.toSet());
                for (String empCode : tempSet) {
                    thxmfzrSet.add(JAVATools.GetWorkcodetoid(empCode) + "");
                }
            }
            String promiseDeptName = (String) jsonObject.get("promiseDeptName");

            if (!StringUtils.isBlank(promiseDeptName)) {
                String[] promiseDeptNameArray = promiseDeptName.split(",");
                Set<String> tempSet = Arrays.stream(promiseDeptNameArray).filter(StringUtils::isNotBlank)
                        .collect(Collectors.toSet());
                for (String deptName : tempSet) {
                    ZgsDept zgsDept = new ZgsDept(deptName,1);
                    xmfzbmfzrSet.add(zgsDept.getDirectorId() + "");
                }
            }
        }
        //投行负责人
        if (thxmfzrSet.size() > 0) {
            result.put("thxmfzr", String.join(",", thxmfzrSet));
        }
        //项目所属部门负责人
        if (xmfzbmfzrSet.size() > 0) {
            result.put("xmfzbmfzr", String.join(",", xmfzbmfzrSet));
        }
        return result;
    }
    private int getFycdbmByMainId(int mainId, String tableName) {
        int projectId = 0;
        RecordSet rs = new RecordSet();
        String sql = String.format("select fycdbm from %s where mainid = ?", tableName);
        rs.executeQuery(sql, mainId);
        while (rs.next()) {
            projectId = rs.getInt("fycdbm");
            break;
        }
        return projectId;
    }
    //数据库直接配置人员类型
    private String getNormal(String value) {
        String hrmids="";
        if("".equals(value)){
            return hrmids;
        }
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            hrmids+=hrmids==""?hrmid:","+hrmid;
        }
        return hrmids;
    }
    //根据数据库配置部门编码匹配部门负责人
    private String getFzrByBm(String value) {
        String hrmids="";
        if("".equals(value)){
            return hrmids;
        }
        ZgsDept zgsDept = new ZgsDept(value,"1");
        hrmids = zgsDept.getDirectorId();
        return hrmids;
    }
    //费用确认
    private String getFyqr(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        String bxry = map.get("bxry");
        String ngr = map.get("ngr");
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    if(!bxry.equals(ngr)){
                        bxry = distinctByCode(bxry,ngr);
                        hrmids+=hrmids==""?bxry:","+bxry;
                    }
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }
    //项目负责人（联合投行项目特有）
    private String getXmfzr(String value,String xmfzr) {
        String hrmids="";
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    hrmids+=hrmids==""?xmfzr:","+xmfzr;
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }
    //直接上级审核（香港特有）
    private String getZjsjsh(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        String zjsjsh = zgsUser.getZgsDept().getDirectorId();
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    hrmids+=hrmids==""?zjsjsh:","+zjsjsh;
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }
    //二级部门负责人
    protected String getEjbmfzr(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";

        ZgsDept zgsDept = zgsUser.getZgsDept();
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    while (!"2".equals(zgsDept.getDepLevel())&&!"".equals(zgsDept.getDepLevel())){
                        zgsDept = new ZgsDept(zgsDept.getParentDepId());
                    }
                    hrmids+=hrmids==""?zgsDept.getDirectorId():","+zgsDept.getDirectorId();
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }
    //投行区域负责人（联合投行等二级部特有）
    protected String getThqyfzr(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        String thqyfzr = ufZgssplDao.getThfzr(zgsUser.getDepId());
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    hrmids+=hrmids==""?thqyfzr:","+thqyfzr;
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids;
    }
    //一级部门负责人
    protected String getYjbmfzr(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        ZgsDept zgsDept = zgsUser.getZgsDept();
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    while (null!=zgsDept.getDepLevel()&&!"0".equals(zgsDept.getDepLevel())&&!"1".equals(zgsDept.getDepLevel())&&!"".equals(zgsDept.getDepLevel())){
                        zgsDept = new ZgsDept(zgsDept.getParentDepId());
                    }
                    hrmids+=hrmids==""?zgsDept.getDirectorId():","+zgsDept.getDirectorId();
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }
    //项目所属部门负责人
    private String getXmssbmfzr(String value, String xmssbmfzr) {
        String hrmids="";
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    hrmids+=hrmids==""?xmssbmfzr:","+xmssbmfzr;
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids;
    }
    //财务中心会计
    protected String getKj(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    String fyhj = ufZgssplDao.getFykj(map.get("bxdd"));
                    if (!"".equals(fyhj)) {
                        hrmids += hrmids == "" ? fyhj : "," + fyhj;
                    }
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }
    //财务中心经理
    private String getCwjl(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        if("".equals(value)){
            return hrmids;
        }
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            hrmids+=hrmids==""?hrmid:","+hrmid;
        }
        return hrmids;
    }
    //固收业务负责人（资管特有）
    protected String getGsywfzr(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            hrmids+=hrmids==""?hrmid:","+hrmid;
        }
        return hrmids ;
    }
    //费用承担部门负责人（紫金虚拟基金特有）
    protected String getFycdbmfzr(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String fycdbm = map.get("fycdbm");
        String hrmids = "";
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    ZgsDept bxbmvo = new ZgsDept(fycdbm,"code");
                    if (null!=bxbmvo.getDirectorId()&&!"".equals(bxbmvo.getDirectorId())){
                        hrmids+=hrmids==""?bxbmvo.getDirectorId():","+bxbmvo.getDirectorId();
                    }
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }
    //分管领导
    protected String getFgld(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids = "";
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    if (null!=zgsUser.getZgsDept().getLeaderId()&&!"".equals(zgsUser.getZgsDept().getLeaderId())){
                        hrmids+=hrmids==""?zgsUser.getZgsDept().getLeaderId():","+zgsUser.getZgsDept().getLeaderId();
                    }
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }
    //财务分管领导（联合付款特有）
    private String getCwfgld(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        if("".equals(value)){
            return hrmids;
        }
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            hrmids+=hrmids==""?hrmid:","+hrmid;
        }
        return hrmids;
    }
    //子公司总经理
    protected String getZgszjl(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        if("".equals(value)){
            return hrmids;
        }
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            hrmids+=hrmids==""?hrmid:","+hrmid;
        }
        return hrmids;
    }
    //总裁（联合特有）
    private String getZc(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        if("".equals(value)){
            return hrmids;
        }
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            hrmids+=hrmids==""?hrmid:","+hrmid;
        }
        return hrmids;
    }
    //子公司董事长
    private String getZgsdsz(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        if("".equals(value)){
            return hrmids;
        }
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            hrmids+=hrmids==""?hrmid:","+hrmid;
        }
        return hrmids;
    }
    //会计处理（联合特有）
    protected String getKjcl(String value, HashMap<String, String> map, ZgsUser zgsUser) {

        String hrmids="";
        if("".equals(value)){
            return hrmids;
        }
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            hrmids+=hrmids==""?hrmid:","+hrmid;
        }
        return hrmids;
    }

    //子公司出纳
    protected String getCn(ZgsUser zgsUser, String unumbercode, HashMap<String, String> map) {
        String hrmids="";
        Map<String,String> cnMap = new HashMap<>();
        String code = getZgsCode(unumbercode);
        if ("zjtybx".equals(unumbercode)||"zjclbx".equals(unumbercode)||"zjtyfk".equals(unumbercode)){
            cnMap = ufZgssplDao.getZjCnMap(map.get("fycdbm"));
        }else {
            cnMap = ufZgssplDao.getCnMap(zgsUser.getDepCode(),code);
        }
        if (!"".equals(cnMap.get("cn"))) {
            hrmids += hrmids == "" ? cnMap.get("cn") : "," + cnMap.get("cn");
        }
        return hrmids;
    }


    //根据type来获取人员
    public String getHrmType(String value){
        if("".equals(value)){
            return "";
        }
        if(value.indexOf("WK_")>=0){
            String workcodeS=value.split("WK_")[1];
            String[] codeArray = workcodeS.split("_");
            String workcode = codeArray[0];
            if(codeArray.length>1){
                String deptcode = codeArray[1];
                return ufZgssplDao.getUserIdByCode(workcode,deptcode);
            }else{
                return JAVATools.GetWorkcodetoid(workcode);
            }
        }
        return "";
    }


    private String getZgsCode(String unumbercode) {
        String code = "";
        if ("lhtybx".equals(unumbercode)||"zgtybx".equals(unumbercode)||"zgstybx".equals(unumbercode)
                ||"lhclbx".equals(unumbercode)||"zgclbx".equals(unumbercode)||"zgsclbx".equals(unumbercode) ){
            code = "ZGS_CL_CN";
        }else {
            code = "ZGS_FK_CN";
        }
        return code;
    }

    //判断条件逻辑与和逻辑或 ：|| ，&&
    public static boolean getConitionParams(String tj, Map<String,String> detailmap){
        boolean flag=false;
        if("".equals(tj)){
            return true;
        }
        String value="";
        List<String> list=new ArrayList();

        String[] split=tj.split("\\|\\|");
        for (String tjsplitljy:split) {
            //开始做逻辑与操作
            String[] splitljy = tjsplitljy.split("\\&\\&");
            list=new ArrayList();
            for (String tjsplitvalue : splitljy) {
                if(tjsplitvalue.split("#").length==3){
                    list.add(tjsplitvalue.replace("#",""));
                }else {
                    list.add(tjsplitvalue);
                }
            }
            for (String tjvalue : list) {
                flag = IsConform(tjvalue, detailmap);
                if (flag == false) {
                    break;
                }
            }
            if(flag==true){
                break;
            }
        }
        return flag;
    }

    //判断是否符合要求
    public static boolean IsConform(String tj,Map<String,String> map){
        boolean flag=true;
        String[] params = getParamsSplit(tj);
        if(params==null){
            return false;
        }
        String key = params[0];
        String value = params[1];
        String conition = params[2];
        if (">=".equals(conition)){
            Double valuedouble= Util.getDoubleValue(Util.null2String(map.get(key)));
            if(!getDoubleIsNull(valuedouble)){
                flag=false;
            }
            if( valuedouble< Util.getDoubleValue(value)){
                flag=false;
            }
        }else if ("<=".equals(conition)){
            Double valuedouble= Util.getDoubleValue(Util.null2String(map.get(key)));
            if(!getDoubleIsNull(valuedouble)){
                flag=false;
            }
            if(valuedouble > Util.getDoubleValue(value)){
                flag=false;
            }
        }else if (">".equals(conition)){
            Double valuedouble= Util.getDoubleValue(Util.null2String(map.get(key)));
            if(!getDoubleIsNull(valuedouble)){
                flag=false;
            }
            if(valuedouble <= Util.getDoubleValue(value)){
                flag=false;
            }
        }else if ("<".equals(conition)){
            Double valuedouble= Util.getDoubleValue(Util.null2String(map.get(key)));
            if(!getDoubleIsNull(valuedouble)){
                flag=false;
            }
            if(valuedouble >= Util.getDoubleValue(value)){
                flag=false;
            }
        }else if ("!=".equals(conition)){
            if(Util.null2String(map.get(key)).equals(value)){
                flag=false;
            }
        }else if ("=".equals(conition)){
            if(!Util.null2String(map.get(key)).equals(value) ){
                flag=false;
            }
        }
        return  flag;
    }

    public static String[] getParamsSplit(String value){
        String[] values = new String[3];
        if(value.split(">=").length==2){
            values= JAVATools.ArrayCodyAtoB(value.split(">="),values);
            values[2]=">=";
            return values;
        }
        if(value.split("<=").length==2){
            values= JAVATools.ArrayCodyAtoB(value.split("<="),values);
            values[2]="<=";
            return values;
        }
        if(value.split(">").length==2){
            values= JAVATools.ArrayCodyAtoB(value.split(">"),values);
            values[2]=">";
            return values;
        }
        if(value.split("<").length==2){
            values= JAVATools.ArrayCodyAtoB(value.split("<"),values);
            values[2]="<";
            return values;
        }

        if(value.split("!=").length==2){
            values= JAVATools.ArrayCodyAtoB(value.split("!="),values);
            values[2]="!=";
            return values;
        }

        if(value.split("=").length==2){
            values= JAVATools.ArrayCodyAtoB(value.split("="),values);
            values[2]="=";
            return values;
        }


        return null;
    }

    public static boolean getDoubleIsNull(double i){
        boolean flag=true;
        if(i<0){
            flag=false;
        }
        return flag;
    }

    //跨界点使用code去重，去除param中包含base的部分
    private String distinctByCode(String param, String base) {
        String result = "";
        if (!"".equals(param)){
            List<Map<String,String>> baseMapList = ufZgssplDao.getUserMap(base);
            Map<String,String> baseMap = baseMapList.get(1);//parm
            List<Map<String,String>> paramMapList = ufZgssplDao.getUserMap(param);
            Map<String, String> paramMap = paramMapList.get(1);//base
            //遍历paramMap，判断baseMap是否存在paramMap中的key值，若不存在则放入结果返回
            for(String code:paramMap.keySet()){
                if(null==baseMap.get(code)||"".equals(baseMap.get(code))){
                    result+=result==""? Util.null2String(paramMap.get(code)):","+ Util.null2String(paramMap.get(code));
                }
            }
        }
        return result;
    }


}
