package weaver.interfaces.htsc.cus;

import weaver.conn.RecordSet;

public class DepartmentUtils {

  /**
   * 获取泛微部门编码
   *
   * @param deptCode
   * @return
   */
  public static int getDeptId(String deptCode) {
    int id = 0;
    String sql = String.format("select id from %s where departmentcode=?", "hrmdepartment");
    RecordSet rs = new RecordSet();
    rs.executeQuery(sql, deptCode);
    while (rs.next()) {
      id = rs.getInt("id");
      break;
    }
    return id;
  }

  /**
   * 获取华泰部门编码
   *
   * @param deptId
   * @return
   */
  public static String getDeptCode(int deptId) {
    String deptCode = "";
    String sql = "select departmentcode from hrmdepartment where id=?";
    RecordSet rs = new RecordSet();
    rs.executeQuery(sql, deptId);
    while (rs.next()) {
      deptCode = rs.getString("departmentcode");
      break;
    }
    return deptCode;
  }

  /**
   * 获取华泰部门类型
   *
   * @param deptId
   * @return
   */
  public static String getDeptTypeCode(int deptId) {
    String deptTypeCode = "";
    String sql = "select depttypecode from hrmdepartmentdefined where deptid=?";
    RecordSet rs = new RecordSet();
    rs.executeQuery(sql, deptId);
    while (rs.next()) {
      deptTypeCode = rs.getString("depttypecode");
      break;
    }
    return deptTypeCode;
  }

  /**
   * 是否总部
   *
   * @param deptCode
   * @return
   */
  public static boolean isTop(String deptCode) {
    boolean result = false;
    int deptId = getDeptId(deptCode);
    String deptTypeCode = getDeptTypeCode(deptId);
    if ("JGLX01".equals(deptTypeCode)) {
      result = true;
    }
    return result;
  }

  /**
   * 是否分支机构
   *
   * @param deptCode
   * @return
   */
  public static boolean isBranch(String deptCode) {
    boolean result = false;
    int deptId = getDeptId(deptCode);
    String deptTypeCode = getDeptTypeCode(deptId);
    if ("JGLX03".equals(deptTypeCode) || "JGLX04".equals(deptTypeCode) || "JGLX09"
        .equals(deptTypeCode)) {
      result = true;
    }
    return result;
  }

  /**
   * 是否子公司
   *
   * @param deptCode
   * @return
   */
  public static boolean isSub(String deptCode) {
    boolean result = false;
    int deptId = getDeptId(deptCode);
    String deptTypeCode = getDeptTypeCode(deptId);
    if ("JGLX07".equals(deptTypeCode) || "JGLX08".equals(deptTypeCode) || "JGLX10"
        .equals(deptTypeCode) || "JGLX11".equals(deptTypeCode) || "JGLX14".equals(deptTypeCode)
        || "JGLX15"
        .equals(deptTypeCode) || "JGLX16".equals(deptTypeCode) || "JGLX17"
        .equals(deptTypeCode) || "JGLX18".equals(deptTypeCode) || "JGLX19".equals(deptTypeCode)
        || "JGLX20"
        .equals(deptTypeCode) || "JGLX22"
        .equals(deptTypeCode)) {
      result = true;
    }
    return result;
  }

  /**
   * 是否联合子公司
   *
   * @param deptTypeCode
   * @return
   */
  public static boolean isLHBranch(String deptTypeCode) {
    boolean result = false;
    if ("JGLX07".equals(deptTypeCode)) {
      result = true;
    }
    return result;
  }

  /**
   * 是否联合子公司部门
   *
   * @param deptTypeCode
   * @return
   */
  public static boolean isLHBranchDept(String deptTypeCode) {
    boolean result = false;
    if ("JGLX08".equals(deptTypeCode)) {
      result = true;
    }
    return result;
  }
}
