---
title: "1. 人员sql片段"
docId: "230126385488723968"
source: "https://weapp.eteams.cn/build/techdoc/wdoc/index.html#/public/repository/91f5067f-775e-48f4-93a2-ce84ca0b9c2e/doc/230126385488723968"
---
## 1. 人员查询sql片段（HrmOrgEmpCondition入参方式）

```
com.weaver.common.hrm.util.sql.HrmSqlBuilderUtil#builderEmpAndExtraSql
```

- 入参说明
  
  | 参数 | 类型 | 说明 |
  | --- | --- | --- |
  | condition | HrmOrgEmpCondition | 查询条件 |
  | select | string | 查询字段名 |
- HrmOrgEmpCondition
  
  | 参数 | 类型 | 说明 |
  | --- | --- | --- |
  | departmentIds | List | 指定部门 |
  | subcompanyIds | List | 指定分部 |
  | ids | List | 人员id |
  | locationIds | List | 办公地点id列表 |
  | userStatusList | List | 人员状态 ： normal 在职、unavailable离职 ；**默认在职** |
  | containSubordinates | boolean | 含下级（指定分部或部门有效） |
  | tenantKey | string | 租户key,必须提供 |
  | loginStatusList | List | 登录状态；normal 已激活，invited 未激活 |
  | typeList | List | 指定类型；默认内部人员；inside 内部人员，external 外部联系人 |
  | jobsetLevelList |  | 职等id |
  | inCludeDelete |  | 是否包含删除人员，默认否 |
  | onlyOtherDepartment | boolean | 仅查询兼职 |
  | noAccount | boolean | 是否不查询无账号 |
  | nameList | List | 人员名称 |
  | secLevelRange | HrmCommonRange<Integer> | 人员安全级别区间；仅开启启用安全级别有效 |
  | sqlwhere | string | 自定义sql片段 |
  | channelList | List | 群组id |
- 示例
  
  ```java
  select id from {$publicdb}.employee where PERMANENTLY_DELETE=0 and type='inside' and TENANT_key='1122' and status='normal' and  ( department  in  (112233,456) )  and accounttype=0 union all select id from {$publicdb}.employee where PERMANENTLY_DELETE=0 and type='inside' and TENANT_key='1122' and status='normal' and id in (select employee_id from {$publicdb}.hrm_extra_organization where  TENANT_KEY='1122'  and  status=1 and if_base_info=0  and  ( department_id  in  (112233,456) ) ) and accounttype=0 union all select id from {$publicdb}.hrm_extra_organization where if_base_info=0 and tenant_key='1122' and status=1 and  ( department_id  in  (112233,456) )
  ```

### 2. 人员查询sql片段（HrmSqlBuilderCondition 入参方式）

```java
com.weaver.common.hrm.util.sql.HrmSqlBuilderUtil#builderEmpSql
```

- 入参说明
  
  | 参数 | 类型 | 说明 |
  | --- | --- | --- |
  | aliasColumn | string | 废弃，提供null即可 |
  | tenantKey | string | 租户 |
  | condition | HrmSqlBuilderCondition | 查询条件 |
  
    - HrmSqlBuilderCondition说明
      
      | 参数 | 类型 | 说明 |
      | --- | --- | --- |
      | type | string | 人员类型；具体看 [人员表结构](https://weapp.eteams.cn/build/techdoc/wdoc/index.html#/public/repository/8eac53f9-0c8b-45ae-9138-d6089a3f97e4/doc/959047681735565313) 的type字段 |
      | userStatusList | List<UserStatus> | 人员状态；具体看 [人员表结构](https://weapp.eteams.cn/build/techdoc/wdoc/index.html#/public/repository/8eac53f9-0c8b-45ae-9138-d6089a3f97e4/doc/959047681735565313) 的status字段 |
      | orgIds | List<Long> | 组织id列表；可以是部门或者分部 |
      | orgQueryType | HrmOrgRelationQueryType | 组织查询类型， org_all_child_department 所有下级部门 org_all_child_subcompany 所有下级分部 org_all_child_org 所有下级组织 org_allSuper_department 所有上级部门 org_allSuper_subcompany 所有上级分部 org_allSuper_org 所有上级组织 |
      | orgContainSelf | boolean | 组织是否要包含自身 |

### 2. 人员上下级片段

```java
com.weaver.common.hrm.util.sql.HrmEmpLinkSqlBuilderUtil#buildOrgRelationSql
```

- 入参说明
  
  | 参数 | 类型 | 说明 |
  | --- | --- | --- |
  | condition | HrmComEmpRelCondition | 条件 |
  | tenantKey | string | 租户标识 |
- 条件（HrmComEmpRelCondition）
  
  | 参数 | 类型 | 说明 |
  | --- | --- | --- |
  | ids | List<Long> | 人员id列表 |
  | queryType | HrmEmpRelationType | 查询类型 |
  | onlyNormal | boolean | 是否仅查询在职人员 |
- 查询类型（HrmEmpRelationType）
  
    - direct_superior 直接上级
    - direct_subordinates 直接下级
    - all_subordinates 所有下级
- 返回类型
  
  | 类型 | 说明 |
  | --- | --- |
  | string | sql片段 |
  |  |  |
- 返回示例：

```sql
select emp.id from {$publicdb}.employee emp left join {$publicdb}.emp_link elink on emp.id=elink.pid where emp.type='inside' and emp.PERMANENTLY_DELETE=0 and  (elink.cid in (5112866049462921957) and elink.tenant_key='tx32g1i3bj' and elink.relation in ('othersenior','senior') and elink.DEPTH=1 and emp.tenant_key='tx32g1i3bj' and emp.status='1') 
```
