package com.engine.htsc.itxqlc.util;


import weaver.conn.RecordSet;
import weaver.general.Util;

public class GetSupDepidUtil {

    /**
     * 一般情况，部门树深度为1(不包括分公司)
     * @param deptid
     * @return
     */
    public String getSupGeneral(String deptid) {
        try {
            RecordSet rs = new RecordSet();
            rs.executeQuery("select supdepid from hrmdepartment where id = ?",deptid);
            if (rs.next()){
                deptid = Util.null2String(rs.getString("supdepid"));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return deptid;
    }


    /**
     * 特殊情况，子公司且部门树深度2
     * @param deptid
     * @return
     */
    public String getSupSpecial(String deptid) {
        try {
            RecordSet rs = new RecordSet();
            rs.executeQuery("select supdepid from hrmdepartment where " +
                    "  id = (select supdepid from hrmdepartment where id = ?)",deptid);
            if (rs.next()){
                deptid = Util.null2String(rs.getString("supdepid"));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return deptid;
    }


    /**
     * 三级营业部获取二级营业部
     * @param parentsalecode
     * @return
     */
    public String getSecondaryDept(String parentsalecode) {
        String deptid = "";
        try {
            RecordSet rs = new RecordSet();
            rs.executeQuery("select id from hrmdepartment where departmentcode = ?",parentsalecode);
            if (rs.next()){
                deptid = Util.null2String(rs.getString("id"));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return deptid;
    }
}
