优化部门树查询用户接口

This commit is contained in:
thinkgem
2021-11-19 13:48:18 +08:00
parent dd850c88a0
commit 50811f8f0c
2 changed files with 18 additions and 13 deletions

View File

@@ -300,6 +300,7 @@ public class OfficeController extends BaseController {
if (StringUtils.isNotBlank(officeTypes)){
where.setOfficeType_in(officeTypes.split(","));
}
List<String> idList = ListUtils.newArrayList();
List<Office> list = officeService.findList(where);
for (int i = 0; i < list.size(); i++) {
Office e = list.get(i);
@@ -316,6 +317,7 @@ public class OfficeController extends BaseController {
continue;
}
}
idList.add(e.getId());
Map<String, Object> map = MapUtils.newHashMap();
map.put("id", e.getId());
map.put("pId", e.getParentCode());
@@ -329,20 +331,20 @@ public class OfficeController extends BaseController {
// 如果需要加载用户,则处理用户数据
if (StringUtils.inString(isLoadUser, "true", "lazy")) {
map.put("isParent", true);
// 一次性后台加载用户,若数据量比较大,建议使用懒加载
if (StringUtils.equals(isLoadUser, "true")) {
List<Map<String, Object>> userList =
empUserController.treeData(userIdPrefix, e.getOfficeCode(), e.getOfficeCode(),
companyCode, postCode, roleCode, isAll, isShowCode, ctrlPermi);
mapList.addAll(userList);
}
}
mapList.add(map);
}
// 一次性后台加载用户,若数据量比较大,建议使用懒加载
if (StringUtils.equals(isLoadUser, "true") && idList.size() > 0) {
List<Map<String, Object>> userList =
empUserController.treeData(userIdPrefix, idList.toArray(new String[idList.size()]),
companyCode, postCode, roleCode, isAll, isShowCode, ctrlPermi);
mapList.addAll(userList);
}
// 懒加载用户,点击叶子节点的时候再去加载部门(懒加载无法回显,数据量大时,建议使用 listselect 实现列表选择用户)
if (StringUtils.inString(isLoadUser, "lazy") && StringUtils.isNotBlank(parentCode)) {
List<Map<String, Object>> userList =
empUserController.treeData("u_", parentCode, parentCode,
empUserController.treeData(userIdPrefix, new String[]{parentCode},
companyCode, postCode, roleCode, isAll, isShowCode, ctrlPermi);
mapList.addAll(userList);
}

View File

@@ -394,7 +394,6 @@ public class EmpUserController extends BaseController {
/**
* 根据机构查询用户树格式
* @param idPrefix id前缀默认 u_
* @param pId 父级编码,默认 0
* @param officeCode 机构Code
* @param companyCode 公司Code
* @param postCode 岗位Code
@@ -406,13 +405,17 @@ public class EmpUserController extends BaseController {
@RequiresPermissions("user")
@RequestMapping(value = "treeData")
@ResponseBody
public List<Map<String, Object>> treeData(String idPrefix, String pId,
String officeCode, String companyCode, String postCode, String roleCode,
public List<Map<String, Object>> treeData(String idPrefix,
String[] officeCode, String companyCode, String postCode, String roleCode,
Boolean isAll, String isShowCode, String ctrlPermi) {
List<Map<String, Object>> mapList = ListUtils.newArrayList();
EmpUser empUser = new EmpUser();
Employee employee = empUser.getEmployee();
employee.getOffice().setOfficeCode(officeCode);
if (officeCode != null && officeCode.length == 1) {
employee.getOffice().setOfficeCode(officeCode[0]);
}else {
employee.getOffice().setId_in(officeCode);
}
employee.getOffice().setIsQueryChildren(false);
employee.getCompany().setCompanyCode(companyCode);
employee.getCompany().setIsQueryChildren(false);
@@ -428,7 +431,7 @@ public class EmpUserController extends BaseController {
EmpUser e = list.get(i);
Map<String, Object> map = MapUtils.newHashMap();
map.put("id", ObjectUtils.defaultIfNull(idPrefix, "u_") + e.getId());
map.put("pId", StringUtils.defaultIfBlank(pId, "0"));
map.put("pId", StringUtils.defaultIfBlank(e.getEmployee().getOffice().getOfficeCode(), "0"));
map.put("name", StringUtils.getTreeNodeName(isShowCode, e.getLoginCode(), e.getUserName()));
mapList.add(map);
}