Compare commits
2 Commits
5ff272e271
...
b6a70c5bbc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6a70c5bbc | ||
|
|
0a3aee0684 |
@ -0,0 +1,13 @@
|
|||||||
|
package com.awspaas.user.apps.nqms.portal.view.department.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: yuandongqiang
|
||||||
|
* @Date: 2025/9/9
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
public class Constant {
|
||||||
|
public static final String APP_ID = "com.awspaas.user.apps.nqms.portal.view.department";
|
||||||
|
public static final String COMPANY_ID = "8911e732-b42a-4556-853f-ad32761bcbee";
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package com.awspaas.user.apps.nqms.portal.view.department.controller;
|
||||||
|
|
||||||
|
import com.actionsoft.bpms.commons.htmlframework.HtmlPageTemplate;
|
||||||
|
import com.actionsoft.bpms.server.UserContext;
|
||||||
|
import com.actionsoft.bpms.server.bind.annotation.Controller;
|
||||||
|
import com.actionsoft.bpms.server.bind.annotation.Mapping;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.awspaas.user.apps.nqms.portal.view.department.service.DeptViewService;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: yuandongqiang
|
||||||
|
* @Date: 2025/9/8
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class DeptController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主页面跳转
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Mapping("com.awspaas.user.apps.nqms.portal.view.department_toPage")
|
||||||
|
public String toViewPage(UserContext ux) {
|
||||||
|
HashMap<String, Object> macroLibraries = new HashMap<>();
|
||||||
|
macroLibraries.put("sid", ux.getSessionId());
|
||||||
|
macroLibraries.put("uid", ux.getUID());
|
||||||
|
macroLibraries.put("userDeptId", ux.getDepartmentModel().getId());
|
||||||
|
macroLibraries.put("settingParam", JSON.toJSON(macroLibraries));
|
||||||
|
return HtmlPageTemplate.merge("com.awspaas.user.apps.nqms.portal.view.department", "main.html", macroLibraries);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门树
|
||||||
|
*
|
||||||
|
* @param ux 用户上下文
|
||||||
|
* @param parentId 父级部门ID
|
||||||
|
* @param keyword 关键字
|
||||||
|
* @param isFrist 是否是第一次加载
|
||||||
|
* @return 部门树
|
||||||
|
*/
|
||||||
|
@Mapping("com.awspaas.user.apps.nqms.portal.view.department_treeInitData")
|
||||||
|
public String getTreeInitData(UserContext ux, String parentId, String keyword, boolean isFrist) {
|
||||||
|
return DeptViewService.getInstance().getTreeInitData(ux, parentId, keyword, isFrist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据部门ID获取所有子部门ID(包含当前部门)
|
||||||
|
*
|
||||||
|
* @param ux 用户上下文
|
||||||
|
* @param deptIds 部门集合
|
||||||
|
* @return 子部门ID集合
|
||||||
|
*/
|
||||||
|
@Mapping("com.awspaas.user.apps.nqms.portal.view.department_getAllDeptIds")
|
||||||
|
public String getAllDeptIds(UserContext ux, List<String> deptIds) {
|
||||||
|
return DeptViewService.getInstance().getAllDeptIds(ux, deptIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,182 @@
|
|||||||
|
package com.awspaas.user.apps.nqms.portal.view.department.service;
|
||||||
|
|
||||||
|
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
|
||||||
|
import com.actionsoft.bpms.org.cache.DepartmentCache;
|
||||||
|
import com.actionsoft.bpms.org.model.DepartmentModel;
|
||||||
|
import com.actionsoft.bpms.server.UserContext;
|
||||||
|
import com.actionsoft.sdk.local.SDK;
|
||||||
|
import com.awspaas.user.apps.nqms.portal.view.department.constant.Constant;
|
||||||
|
import com.awspaas.user.apps.nqms.portal.view.department.treeUtil.TreeNode;
|
||||||
|
import jodd.util.StringUtil;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: yuandongqiang
|
||||||
|
* @Date: 2025/9/8
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
public class DeptViewService {
|
||||||
|
private DeptViewService() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class DeptInstance {
|
||||||
|
static DeptViewService instance = new DeptViewService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeptViewService getInstance() {
|
||||||
|
return DeptInstance.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门树
|
||||||
|
*
|
||||||
|
* @param ux 用户上下文
|
||||||
|
* @param parentId 父级部门ID
|
||||||
|
* @param keyword 关键字
|
||||||
|
* @param isFrist 是否是第一次加载
|
||||||
|
* @return 部门树
|
||||||
|
*/
|
||||||
|
public String getTreeInitData(UserContext ux, String parentId, String keyword, boolean isFrist) {
|
||||||
|
ResponseObject ro = ResponseObject.newOkResponse();
|
||||||
|
List<DepartmentModel> departmentModels = DepartmentCache.getListOfParentDepartment(Constant.COMPANY_ID, parentId);
|
||||||
|
String property = SDK.getAppAPI().getProperty(Constant.APP_ID, "RemoveDeptIds");
|
||||||
|
List<String> removeDept = new ArrayList<>();
|
||||||
|
if (StringUtil.isNotBlank(property)) {
|
||||||
|
removeDept = Arrays.asList(property.split(","));
|
||||||
|
}
|
||||||
|
List<TreeNode> deptTree = new ArrayList<>();
|
||||||
|
for (DepartmentModel dept : departmentModels) {
|
||||||
|
if (dept.isClosed()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (removeDept.contains(dept.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
TreeNode node = new TreeNode();
|
||||||
|
node.setId(dept.getId());
|
||||||
|
node.setLabel(dept.getName());
|
||||||
|
node.setParentId(dept.getParentDepartmentId());
|
||||||
|
String name = dept.getName();
|
||||||
|
boolean haskey = false;
|
||||||
|
if (StringUtil.isBlank(keyword)) {
|
||||||
|
haskey = true;
|
||||||
|
} else {
|
||||||
|
if (name.contains(keyword)) {
|
||||||
|
haskey = true;
|
||||||
|
} else {
|
||||||
|
haskey = isSubDeptHasKeyWord(dept.getId(), keyword, removeDept);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (haskey) {
|
||||||
|
List<DepartmentModel> sub = DepartmentCache.getSubDepartments(dept.getId());
|
||||||
|
node.setHasChild(false);
|
||||||
|
if (sub != null && sub.size() > 0) {
|
||||||
|
node.setHasChild(true);
|
||||||
|
}
|
||||||
|
deptTree.add(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isFrist) {
|
||||||
|
DepartmentModel departmentModel = ux.getDepartmentModel();
|
||||||
|
String pathIdOfCache = departmentModel.getPathIdOfCache();
|
||||||
|
List<String> pathList = Arrays.asList(pathIdOfCache.split("/"));
|
||||||
|
ro.put("openNode", pathList);
|
||||||
|
ro.put("checkedKeys", Arrays.asList(departmentModel.getId()));
|
||||||
|
}
|
||||||
|
ro.put("deptTree", deptTree);
|
||||||
|
return ro.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断自部门是否包含特定关键字
|
||||||
|
*
|
||||||
|
* @param parentId 父部门id
|
||||||
|
* @param keyword 关键字
|
||||||
|
* @param removeDept 取消查询部门
|
||||||
|
* @return 是否包含关键字
|
||||||
|
*/
|
||||||
|
public boolean isSubDeptHasKeyWord(String parentId, String keyword, List<String> removeDept) {
|
||||||
|
List<DepartmentModel> subDepartments = DepartmentCache.getListOfParentDepartment(Constant.COMPANY_ID, parentId);
|
||||||
|
List<String> ids = new ArrayList<>();
|
||||||
|
for (DepartmentModel dept : subDepartments) {
|
||||||
|
if (dept.isClosed()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (removeDept.contains(dept.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String name = dept.getName();
|
||||||
|
if (name.contains(keyword)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ids.add(dept.getId());
|
||||||
|
}
|
||||||
|
for (String id : ids) {
|
||||||
|
boolean subDeptHasKeyWord = isSubDeptHasKeyWord(id, keyword, removeDept);
|
||||||
|
if (subDeptHasKeyWord) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据部门ID获取所有子部门ID(包含当前部门)
|
||||||
|
*
|
||||||
|
* @param ux 用户上下文
|
||||||
|
* @param deptIds 部门集合
|
||||||
|
* @return 子部门ID集合
|
||||||
|
*/
|
||||||
|
public String getAllDeptIds(UserContext ux, List<String> deptIds) {
|
||||||
|
ResponseObject ro = ResponseObject.newOkResponse();
|
||||||
|
if (CollectionUtils.isEmpty(deptIds)) {
|
||||||
|
return ro.toString();
|
||||||
|
}
|
||||||
|
Set<String> allDeptIds = new HashSet<>(deptIds);
|
||||||
|
Set<String> visitedDepts = new HashSet<>(); // 防止重复访问和循环引用
|
||||||
|
for (String deptId : deptIds) {
|
||||||
|
if (deptId == null) continue;
|
||||||
|
try {
|
||||||
|
subDepts(deptId, allDeptIds, visitedDepts);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("获取子部门失败,部门ID:" + deptId + ",异常信息:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ro.setData(allDeptIds);
|
||||||
|
return ro.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子部门
|
||||||
|
* @param id 部门id
|
||||||
|
* @param allDeptIds 所有部门id
|
||||||
|
* @param visitedDepts 已访问部门id
|
||||||
|
*/
|
||||||
|
public void subDepts(String id, Set<String> allDeptIds, Set<String> visitedDepts) {
|
||||||
|
if (visitedDepts.contains(id)) {
|
||||||
|
return;
|
||||||
|
} // 防止循环引用和重复处理
|
||||||
|
visitedDepts.add(id);
|
||||||
|
|
||||||
|
List<DepartmentModel> subDepartments = DepartmentCache.getSubDepartments(id);
|
||||||
|
if (subDepartments == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DepartmentModel dept : subDepartments) {
|
||||||
|
if (dept == null || dept.getId() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allDeptIds.add(dept.getId());
|
||||||
|
subDepts(dept.getId(), allDeptIds, visitedDepts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
package com.awspaas.user.apps.nqms.portal.view.department.treeUtil;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ZHULIMIN
|
||||||
|
*/
|
||||||
|
public class TreeNode {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点名称
|
||||||
|
*/
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父节点 默认0为根节点
|
||||||
|
*/
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否有子节点
|
||||||
|
*/
|
||||||
|
private boolean hasChild;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParentId() {
|
||||||
|
return parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentId(String parentId) {
|
||||||
|
this.parentId = parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasChild() {
|
||||||
|
return hasChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHasChild(boolean hasChild) {
|
||||||
|
this.hasChild = hasChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeNode() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeNode(String id, String label, String parentId, boolean hasChild) {
|
||||||
|
this.id = id;
|
||||||
|
this.label = label;
|
||||||
|
this.parentId = parentId;
|
||||||
|
this.hasChild = hasChild;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user