package weaver.interfaces.htsc.util;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.conn.RecordSet;
import weaver.hrm.resource.ResourceComInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HT_Util extends BaseBean {

    public String getszjg(String userid){
        if("".equals(userid) || "".equals(userid)){
            return  "";
        }
        String szjg ="" ;
        try{
            RecordSet rs = new RecordSet();
            String departmentid = "";
            String sql = " select departmentid from hrmresource where id="+userid;
            rs.execute(sql);
            if(rs.next()){
                departmentid = Util.null2String(rs.getString("departmentid"));
            }
            //writeLog("departmentid:"+departmentid);
            sql = " select l.id from (select t.id from HrmDepartment t where t.supdepid is null or t.supdepid = 0 start with t.id="+departmentid+" connect by prior t.supdepid=t.id ) l";
            //writeLog("sql:"+sql);
            rs.execute(sql);
            if(rs.next()){
                szjg = Util.null2String(rs.getString("id"));
            }
        }catch (Exception e){
            writeLog("e:"+e);
        }
        return szjg;
    }

    public List<String> getszqz(String userids){
        if("".equals(userids) || "".equals(userids)){
            return  null;
        }
        List<String> arraylist = new ArrayList<String>();
        try{
            RecordSet rs = new RecordSet();
            String sql = "  select distinct groupid from  hrmgroupmembers  where userid in("+userids+")";
            rs.execute(sql);
            while (rs.next())
            {
                String szjg = Util.null2String(rs.getString("groupid"));
                System.out.println("szjg:"+szjg);
                arraylist.add(szjg);
            }
        }catch (Exception e){
            writeLog("e:"+e);
        }
        return arraylist;
    }

    /***
     *
     * @param userid
     * @return
     */
    public Map<String,String> getszjginfo(String userid){
        Map<String,String> msgMap = new HashMap<String,String>();

        if("".equals(userid) || "".equals(userid)){
            return  msgMap;
        }
        try{
            RecordSet rs = new RecordSet();
            String departmentid = "";
            String sql = " select departmentid from hrmresource where id="+userid;
            rs.execute(sql);
            if(rs.next()){
                departmentid = Util.null2String(rs.getString("departmentid"));
            }
            sql = " select l.id,l.departmentname,l.departmentcode from (select t.id,t.departmentname,t.departmentcode from HrmDepartment t where t.supdepid is null or t.supdepid = 0 start with t.id="+departmentid+" connect by prior t.supdepid=t.id ) l";
            rs.execute(sql);
            if(rs.next()){
                String szjg = Util.null2String(rs.getString("id"));
                String departmentname = Util.null2String(rs.getString("departmentname"));
                String departmentcode = Util.null2String(rs.getString("departmentcode"));

                msgMap.put("szjgid",szjg);
                msgMap.put("szjgname",departmentname);
                msgMap.put("szjgcode",departmentcode);
            }
        }catch (Exception e){
            writeLog("e:"+e);
        }
        return msgMap;
    }

}
