对接文档
https://weapp.eteams.cn/build/techdoc/wdoc/index.html#/public/repository/91f5067f-775e-48f4-93a2-ce84ca0b9c2e/doc/194965353510469632
组织查询(通用)
java
复制代码
@RestController
@RequestMapping("/api/secondev/hrm")
@RequiredArgsConstructor
public class DepartmentController {
private final HrmCommonDepartmentService hrmCommonDepartmentService;
@GetMapping("/list")
public List<HrmDepartment> list(@RequestParam Map<String,String> params ){
System.out.println(params);
HrmOrgCondition hrmOrgCondition =new HrmOrgCondition();
hrmOrgCondition.setTenantKey("tet4f7sfrj");//租户KEY 必填
hrmOrgCondition.setIds(ConverterUtil.toList(params.get("ids"),Long.class)); //查询部门ID
hrmOrgCondition.setParentOrgIds(ConverterUtil.toList(params.get("parentOrgIds"),Long.class));//根据部门ID查出下级部门
hrmOrgCondition.setStatusList(ConverterUtil.toList(params.get("statusList"),Integer.class));//部门启用状态 默认启用 1启用 0停用 传入1,0为全部查询
hrmOrgCondition.setTypeList(ConverterUtil.toList(params.get("typeList"),String.class));//查询类型 subcompany 分部,department部门, 默认不过滤
//hrmOrgCondition.setNameLikeList(Arrays.asList(nameLikeList));//部门名称模糊查询 //params.get("nameLinkList")
List<HrmDepartment> objects = hrmCommonDepartmentService.queryOrgsByCondidtion(hrmOrgCondition, HrmConditionResultType.BEAN.name());
return objects;
}
}
查询下级部门、分部
java
复制代码
@RestController
@RequestMapping("/api/secondev/hrm")
@RequiredArgsConstructor
public class DepartmentController {
private final HrmCommonDepartmentService hrmCommonDepartmentService;
/**
* 查询下级分部列表
* @param params
* @return
*/
@GetMapping("/subordinateList")
public List<HrmDepartmentComInfo> subordinateList(@RequestParam Map<String,String> params ){
System.out.println(params);
HrmOrgRelationCodition hrmOrgCondition =new HrmOrgRelationCodition();
hrmOrgCondition.setTenantKey("tet4f7sfrj");//租户KEY 必填
hrmOrgCondition.setIds(ConverterUtil.toList(params.get("ids"),Long.class)); //查询部门ID 或分部
hrmOrgCondition.setQueryType(HrmOrgRelationQueryType.org_all_child_department);
List<HrmDepartmentComInfo> objects = hrmCommonDepartmentService.findOrgRelationByCondtion(hrmOrgCondition);
return objects;
}
/**
* HrmOrgRelationQueryType参数说明
*
* org_direct_subcompany: 直接上级分部
*
* 如果id为分部,返回当前分部的上级分部;
* 如果id为部门,获取当前部门归属分部,返回归属分部的上级分部;
*
* org_direct_department: 直接上级部门
*
* 如果id为分部,返回 null
* 如果id为部门,返回当前部门的上级部门
*
* org_direct_child_sucompany:直接下级分部
*
* org_all_child_subcompany: 查询所有下级分部
*
* org_direct_child_department:直接下级部门
*
* org_all_child_department: 查询所有下级部门
*
* org_all_child_org: 查询所有下级组织
*
* org_allSuper_subcompany: 所有上级分部
*
* org_allSuper_department: 所有上级部门
*
* org_allSuper_org: 查询所有上级组织
* @param params
* @return
*/
}
查询人员信息
java
复制代码
@RestController
@RequestMapping("/api/secondev/hrm")
@RequiredArgsConstructor
public class DepartmentController {
private final HrmCommonEmployeeService hrmCommonEmployeeService;
@GetMapping("/getPersonnelMsg")
public List<SimpleEmployee> getPersonnelMsg(@RequestParam Map<String,String> params){
HrmEmployeIdFilterMeta hrmEmployeIdFilterMeta = new HrmEmployeIdFilterMeta();
List<SimpleEmployee> employeeByIdsFilterMeta = hrmCommonEmployeeService.getEmployeeByIdsFilterMeta(ConverterUtil.toList(params.get("ids"), Long.class), "tet4f7sfrj", hrmEmployeIdFilterMeta);
return employeeByIdsFilterMeta;
}
}
封装工具类
java
复制代码
public class ConverterUtil {
// 将输入转换为 List<T>,根据实际需要处理逗号分隔的情况
public static <T> List<T> toList(String input, Class<T> type) {
// 如果输入为空或仅包含空格,返回 null
if (input == null || input.trim().isEmpty()) {
return null;
}
List<T> resultList = new ArrayList<>();
// 如果没有逗号,则将整个输入作为单个元素
if (!input.contains(",")) {
resultList.add(convertToType(input, type));
} else {
// 否则,根据逗号分隔处理输入
String[] items = input.split(",");
for (String item : items) {
resultList.add(convertToType(item.trim(), type));
}
}
return resultList;
}
// 根据类型转换输入字符串为目标类型
private static <T> T convertToType(String input, Class<T> type) {
try {
if (type == Integer.class) return type.cast(Integer.parseInt(input));
if (type == Long.class) return type.cast(Long.parseLong(input));
if (type == Double.class) return type.cast(Double.parseDouble(input));
if (type == String.class) return type.cast(input);
if (type == Boolean.class) return type.cast(Boolean.parseBoolean(input));
if (type == Float.class) return type.cast(Float.parseFloat(input));
{
throw new IllegalArgumentException("Unsupported type: " + type.getName());
}
} catch (Exception e) {
throw new IllegalArgumentException("Error converting input: " + input + " to " + type.getName(), e);
}
}
public static void main(String[] args) {
// 测试整数类型
List<Integer> intList = toList("1,2,3,4", Integer.class);
System.out.println(intList); // 输出:[1, 2, 3, 4]
// 测试长整型类型
List<Long> longList = toList("1000000000", Long.class);
System.out.println(longList); // 输出:[1000000000, 2000000000]
// 测试浮点型
List<Double> doubleList = toList("1.23,4.56,7.89", Double.class);
System.out.println(doubleList); // 输出:[1.23, 4.56, 7.89]
// 测试布尔类型
List<Boolean> booleanList = toList("true,false,true", Boolean.class);
System.out.println(booleanList); // 输出:[true, false, true]
// 测试没有逗号的情况
List<String> singleItemList = toList("hello", String.class);
System.out.println(singleItemList); // 输出:[hello]
// 测试组合类型
List<String> complexList = toList("apple,banana,orange", String.class);
System.out.println(complexList); // 输出:[apple, banana, orange]
// 测试空字符串输入
List<String> emptyList = toList("", String.class);
System.out.println(emptyList); // 输出:null
// 测试 null 输入
List<String> nullList = toList(null, String.class);
System.out.println(nullList); // 输出:null
}
}