123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package com.bosshand.virgo.service;
- import com.bosshand.virgo.core.dao.MgrRoleDao;
- import com.bosshand.virgo.core.model.MgrRole;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.List;
- @Service
- public class RoleService {
- @Autowired
- MgrRoleDao mgrRoleDao;
- public int save(MgrRole mgrRole) {
- return mgrRoleDao.insert(mgrRole);
- }
- public int update(MgrRole mgrRole) {
- return mgrRoleDao.update(mgrRole);
- }
- public int delete(long id) {
- return mgrRoleDao.delete(id);
- }
- public List<MgrRole> getList(long projectId, long organizationId) {
- List<MgrRole> list = mgrRoleDao.getList(projectId, organizationId);
- List<Long> ids = new ArrayList<>();
- list.forEach(ls -> {
- if (ls.getParentId() == -1) {
- ids.add(ls.getId());
- }
- });
- List<MgrRole> hierarchy = new ArrayList<>();
- if (ids.size() > 0) {
- ids.forEach(ll -> hierarchy.add(getNodeTreeById(ll, list)));
- }
- return hierarchy;
- }
- private MgrRole getNodeTreeById(long id, List<MgrRole> list) {
- MgrRole node = null;
- List<MgrRole> roleList = list;
- for (MgrRole data : roleList) {
- if (data.getId() == id) {
- node = data;
- break;
- }
- }
- if (node != null) {
- node.setChildren(getChildNode(node.getId(), roleList));
- }
- return node;
- }
- private List<MgrRole> getChildNode(long parentId, List<MgrRole> list) {
- List<MgrRole> nodeList = new ArrayList<MgrRole>();
- nodeList.clear();
- for (MgrRole data : list) {
- if (data.getParentId() == parentId) {
- nodeList.add(data);
- }
- }
- if (nodeList.size() > 0) {
- for (MgrRole data : nodeList) {
- List<MgrRole> childList = getChildNode(data.getId(), list);
- data.setChildren(childList);
- }
- }
- return nodeList;
- }
- }
|