<%@ page import="weaver.general.*" %>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<jsp:useBean id="bb" class="weaver.general.BaseBean" scope="page" />
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%
    User user = HrmUserVarify.getUser(request , response) ;
    int userid = user.getUID();
    RecordSet rs = new RecordSet();
    String specialUser = getUfPropValue("specialUser");
    String pOrgid = Util.null2String(getUfPropValue("defaultOrgId"),"182");


    String active = bb.getPropValue("developProp", "active");
    out.print("active:"+active);
    if (StringUtils.isNotEmpty(active)) {
        String sql = " select devvalue,prodvalue from uf_hr_prop where pkey = ?";
        rs.executeQuery(sql, new Object[]{"specialUser"});
        if (rs.next()) {
            String value = Util.null2String(rs.getString(active + "value"));
            out.print("value:"+value);
        }
    }

    out.print("specialUser:"+specialUser);
    out.print("pOrgid:"+pOrgid);

//    if(!(","+specialUser+",").contains(","+userid+",")){
//        String sql = " select id from uf_org  where charindex(',"+userid+",' , ','+convert(varchar(1000),orgfzr)+',')>0 " ;
//        rs.execute(sql);
//        while (rs.next()){
//            String id = Util.null2String(rs.getString("id"));
//            pOrgid += org.apache.commons.lang3.StringUtils.isBlank(id) ? id : ","+id ;
//        }
//    }
//    out.print("pOrgid2:"+pOrgid);

    String deptids = "";
    List<String> deptList  = new ArrayList<String>();
    String orgsql = " with cte as ( " +
            "      select id from uf_org where id in( " + pOrgid+")"+
            " 	   union all " +
            "      select air.id from uf_org as air " +
            "	   inner join cte on air.porgid = cte.id" +
            " ) " +
            " select dybm from uf_org where id in(select id from cte) and mc<>'集团军总服部' and (canceled is null or canceled<>'1') ";
    out.print("orgsql:"+orgsql);
    rs.executeQuery(orgsql);
    while(rs.next())
    {
        String dybm = rs.getString("dybm");
        out.print("dybm:"+dybm);
        if(dybm.contains(",")){
            String[] dynms = dybm.split(",");
            for(int i=0;i<dynms.length;i++){
                if(!deptList.contains(dynms[i])){
                    deptList.add(dybm);
                    deptids += org.apache.commons.lang3.StringUtils.isBlank(deptids) ? dybm : ","+dybm ;
                }
            }
        }else{
            if(!deptList.contains(dybm)){
                deptList.add(dybm);
                deptids += org.apache.commons.lang3.StringUtils.isBlank(deptids) ? dybm : ","+dybm ;
            }
        }
    }

    out.print("deptids:"+deptids);

%>


<%!
    public String getUfPropValue(String pkey) {
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();

        if (org.apache.commons.lang3.StringUtils.isEmpty(pkey)) {
            return "";
        }
        String value = "";
        String active = bb.getPropValue("developProp", "active");
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(active)) {
            String sql = " select devvalue,prodvalue from uf_hr_prop where pkey = ?";
            rs.executeQuery(sql, new Object[]{pkey});
            if (rs.next()) {
                value = Util.null2String(rs.getString(active + "value"));
            }
        }
        return value;
    }
%>



