|
@@ -1,261 +0,0 @@
|
|
-package com.huimv.core.service.impl;
|
|
|
|
-
|
|
|
|
-import com.huimv.core.domain.SysAccountGroupEntity;
|
|
|
|
-import com.huimv.core.domain.SysGroupMenuEntity;
|
|
|
|
-import com.huimv.core.domain.SysMenuEntity;
|
|
|
|
-import com.huimv.core.repo.SysAccountGroupEntityRepository;
|
|
|
|
-import com.huimv.core.repo.SysGroupMenuEntityRepository;
|
|
|
|
-import com.huimv.core.repo.SysMenuEntityRepository;
|
|
|
|
-import com.huimv.core.service.IAuthorizeService;
|
|
|
|
-import com.huimv.core.utils.Result;
|
|
|
|
-import com.huimv.core.utils.ResultCode;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
-
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
-
|
|
|
|
-@Service
|
|
|
|
-public class AuthorizeServiceImpl implements IAuthorizeService {
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private SysAccountGroupEntityRepository sysAccountGroupRepo;
|
|
|
|
- @Autowired
|
|
|
|
- private SysGroupMenuEntityRepository sysGroupMenuRepo;
|
|
|
|
- @Autowired
|
|
|
|
- private SysMenuEntityRepository sysMenuEntityRepo;
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- @Transactional
|
|
|
|
- public Result saveAccountGroup(String accountId, String groupIds) {
|
|
|
|
- /**
|
|
|
|
- * Step1:先删除原先的账号关联权限组数据;
|
|
|
|
- * Step2:再添加新的账号关联权限组数据;
|
|
|
|
- */
|
|
|
|
- String[] groupIdArray = groupIds.split(",");
|
|
|
|
- sysAccountGroupRepo.removeAccountGroup(accountId);
|
|
|
|
-// for (int a = 0; a < groupIdArray.length; a++) {
|
|
|
|
-// sysAccountGroupRepo.removeAccountGroup(accountId,groupIdArray[a]);
|
|
|
|
-// }
|
|
|
|
- for (int a = 0; a < groupIdArray.length; a++) {
|
|
|
|
- SysAccountGroupEntity accountGroupEntity = new SysAccountGroupEntity();
|
|
|
|
- accountGroupEntity.setAccountId(Integer.parseInt(accountId));
|
|
|
|
- accountGroupEntity.setGroupId(Integer.parseInt(groupIdArray[a]));
|
|
|
|
- sysAccountGroupRepo.saveAndFlush(accountGroupEntity);
|
|
|
|
-// sysAccountGroupRepo.insert(Integer.parseInt(accountId),Integer.parseInt(groupIdArray[a]));
|
|
|
|
- }
|
|
|
|
- return new Result(10001, "保存账号关联权限组成功", true);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- @Transactional
|
|
|
|
- public Result saveGroupMenu(String groupId, String menuIds) {
|
|
|
|
- /**
|
|
|
|
- * Step1:先删除原先的权限组关联菜单数据;
|
|
|
|
- * Step2:再添加新的账号权限组关联菜单数据;
|
|
|
|
- */
|
|
|
|
-// sysGroupMenuRepo.removeGroupMenu(groupId);
|
|
|
|
- String[] menuIdsArray = menuIds.split(",");
|
|
|
|
- for (int a = 0; a < menuIdsArray.length; a++) {
|
|
|
|
- sysGroupMenuRepo.removeGroupMenu(groupId, menuIdsArray[a]);
|
|
|
|
- }
|
|
|
|
- for (int a = 0; a < menuIdsArray.length; a++) {
|
|
|
|
- SysGroupMenuEntity sysGroupMenuEntity = new SysGroupMenuEntity();
|
|
|
|
- sysGroupMenuEntity.setGroupId(Integer.parseInt(groupId));
|
|
|
|
- sysGroupMenuEntity.setMenuId(Integer.parseInt(menuIdsArray[a]));
|
|
|
|
- sysGroupMenuRepo.saveAndFlush(sysGroupMenuEntity);
|
|
|
|
- }
|
|
|
|
- return new Result(10001, "保存权限组关联菜单成功", true);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* @Override
|
|
|
|
- public Result getMyMenu(String accountName) {
|
|
|
|
- // 根据账号获取权限组(查询账号权限组关联表)
|
|
|
|
- // 根据权限组获取菜单id(查询权限组菜单官僚表)
|
|
|
|
- // 根据菜单id获取菜单全部信息(查询菜单表)
|
|
|
|
- List<SysMenuEntity> dataList = sysMenuEntityRepo.getMyMenu(accountName);
|
|
|
|
- System.out.println("dataList.size>>"+dataList.size());
|
|
|
|
- List newMenuList = new ArrayList();
|
|
|
|
- // error for (SysMenuEntity menuEntity : dataList) {
|
|
|
|
- for (int a=0;a<dataList.size();a++) {
|
|
|
|
- SysMenuEntity menuEntity = dataList.get(a);
|
|
|
|
- if (menuEntity.getParentId() == 0) {
|
|
|
|
- Map menuMap = new HashMap<>();
|
|
|
|
- menuMap.put("id", menuEntity.getId());
|
|
|
|
- menuMap.put("menuName", menuEntity.getMenuName());
|
|
|
|
- menuMap.put("parentId", menuEntity.getParentId());
|
|
|
|
- menuMap.put("url", menuEntity.getUrl());
|
|
|
|
- menuMap.put("sort", menuEntity.getSort());
|
|
|
|
- newMenuList.add(menuMap);
|
|
|
|
- dataList.remove(menuEntity);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- for (int a = 0; a < newMenuList.size(); a++) {
|
|
|
|
- Map menuMap = (Map) newMenuList.get(a);
|
|
|
|
- int id = Integer.parseInt(menuMap.get("id").toString());
|
|
|
|
- List childrenList = new ArrayList();
|
|
|
|
- for (SysMenuEntity menuEntity : dataList) {
|
|
|
|
- if (id == menuEntity.getParentId()) {
|
|
|
|
- childrenList.add(menuEntity);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (childrenList.size() > 0) {
|
|
|
|
- menuMap.put("children", childrenList);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return new Result(ResultCode.SUCCESS, newMenuList);
|
|
|
|
- }*/
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @param accountName
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public List getMyMenu_old(String accountName) {
|
|
|
|
- System.out.println(" accountName>>" + accountName);
|
|
|
|
- List<SysMenuEntity> menuEntityList = sysMenuEntityRepo.getMyMenu(accountName);
|
|
|
|
- System.out.println(" menuEntityList.size>>" + menuEntityList.size());
|
|
|
|
- List<SysMenuEntity> topList = new ArrayList();
|
|
|
|
- for (SysMenuEntity sysMenuEntity : menuEntityList) {
|
|
|
|
- if (sysMenuEntity.getParentId() == 0) {
|
|
|
|
- topList.add(sysMenuEntity);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return topList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List getMyMenu(String accountName) {
|
|
|
|
- List<SysMenuEntity> allMenuEntityList = sysMenuEntityRepo.getMyMenu(accountName);
|
|
|
|
- System.out.println("123456");
|
|
|
|
- //
|
|
|
|
- List<SysMenuEntity> myRootMenuList = new ArrayList();
|
|
|
|
- //pid(上级Id)为0的是根菜单
|
|
|
|
- for (SysMenuEntity menuEntity : allMenuEntityList) {
|
|
|
|
- if (menuEntity.getParentId() == 0) {
|
|
|
|
- myRootMenuList.add(menuEntity);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 遍历,找到二级菜单(根菜单的id和所有菜单中的pid比较)
|
|
|
|
- for (SysMenuEntity myMenuEntity : myRootMenuList) {
|
|
|
|
- /* */
|
|
|
|
- List<SysMenuEntity> child = getChild(myMenuEntity.getId(), allMenuEntityList);
|
|
|
|
- myMenuEntity.setChildren(child);
|
|
|
|
- }
|
|
|
|
- return myRootMenuList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public List<SysMenuEntity> getChild(int pid, List<SysMenuEntity> allMenuList) {
|
|
|
|
- //子菜单列表
|
|
|
|
- List<SysMenuEntity> childList = new ArrayList<>();
|
|
|
|
- for (SysMenuEntity menuEntity : allMenuList) {
|
|
|
|
- if (pid == menuEntity.getParentId()) {
|
|
|
|
- childList.add(menuEntity);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //遍历 获取子菜单的子菜单
|
|
|
|
- for (SysMenuEntity childMenu : childList) {
|
|
|
|
- List<SysMenuEntity> child = getChild(childMenu.getId(), allMenuList);
|
|
|
|
- childMenu.setChildren(child);
|
|
|
|
- }
|
|
|
|
- //递归出口 childList长度为0
|
|
|
|
- if (childList.size() == 0) {
|
|
|
|
- return new ArrayList<>();
|
|
|
|
- }
|
|
|
|
- return childList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Result getMenuByGroup(String groupId) {
|
|
|
|
- /* 根据权限组读取已关联菜单 */
|
|
|
|
- List<SysGroupMenuEntity> groupMenuEntityList = sysGroupMenuRepo.getMenuByGroup(groupId);
|
|
|
|
- if (groupMenuEntityList.size() == 0) {
|
|
|
|
- return new Result(10005, "当前权限组暂未关联任何菜单.", false);
|
|
|
|
- }
|
|
|
|
- /* 读取所有菜单 */
|
|
|
|
- List<SysMenuEntity> allMenuList = sysMenuEntityRepo.findAll();
|
|
|
|
- if (allMenuList.size() == 0) {
|
|
|
|
- return new Result(10007, "当前无任何菜单.", false);
|
|
|
|
- }
|
|
|
|
- List<SysGroupMenuEntity> newList = new ArrayList();
|
|
|
|
- StringBuilder idSb2 = new StringBuilder();
|
|
|
|
-
|
|
|
|
- for (int a = 0; a < groupMenuEntityList.size(); a++) {
|
|
|
|
- SysGroupMenuEntity groupMenuEntity = groupMenuEntityList.get(a);
|
|
|
|
- for (SysMenuEntity menuEntity : allMenuList) {
|
|
|
|
- if (menuEntity.getId().equals(groupMenuEntity.getMenuId())) {
|
|
|
|
- if (menuEntity.getParentId() == 0) {
|
|
|
|
- if (idSb2.length() > 0) {
|
|
|
|
- idSb2.append(",");
|
|
|
|
- }
|
|
|
|
- idSb2.append(groupMenuEntity.getMenuId());
|
|
|
|
- break;
|
|
|
|
- } else {
|
|
|
|
- boolean isChild = false;
|
|
|
|
- for (SysMenuEntity menuEntity2 : allMenuList) {
|
|
|
|
- if (menuEntity2.getParentId().equals(groupMenuEntity.getMenuId())) {
|
|
|
|
- isChild = true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (!isChild) {
|
|
|
|
- if (idSb2.length() > 0) {
|
|
|
|
- idSb2.append(",");
|
|
|
|
- }
|
|
|
|
- idSb2.append(groupMenuEntity.getMenuId());
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-// StringBuilder idSb = new StringBuilder();
|
|
|
|
-// for (SysGroupMenuEntity groupMenuEntity : groupMenuEntityList) {
|
|
|
|
-// if (idSb.length() > 0) {
|
|
|
|
-// idSb.append(",");
|
|
|
|
-// }
|
|
|
|
-// idSb.append(groupMenuEntity.getMenuId());
|
|
|
|
-// }
|
|
|
|
- return new Result(ResultCode.SUCCESS, idSb2.toString());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @param accountId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public Result getGroupByAccount(String accountId) {
|
|
|
|
- /* 根据账号id读取已关联权限组 */
|
|
|
|
- List<SysAccountGroupEntity> accountGroupEntityList = sysAccountGroupRepo.getGroupByAccount(accountId);
|
|
|
|
- if (accountGroupEntityList.size() == 0) {
|
|
|
|
- return new Result(10006, "当前用户账号暂未关联任何权限组.", false);
|
|
|
|
- }
|
|
|
|
- StringBuilder idSb = new StringBuilder();
|
|
|
|
- for (SysAccountGroupEntity accountGroupEntity : accountGroupEntityList) {
|
|
|
|
- if (idSb.length() > 0) {
|
|
|
|
- idSb.append(",");
|
|
|
|
- }
|
|
|
|
- idSb.append(accountGroupEntity.getGroupId());
|
|
|
|
- }
|
|
|
|
- return new Result(ResultCode.SUCCESS, idSb.toString());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Result getAccountByGroup(String groupId) {
|
|
|
|
- /* 根据账号id读取已关联权限组 */
|
|
|
|
- List<SysAccountGroupEntity> accountGroupEntityList = sysAccountGroupRepo.getAccountByGroup(groupId);
|
|
|
|
- if (accountGroupEntityList.size() == 0) {
|
|
|
|
- return new Result(10006, "当前权限组暂未关联任何用户账号.", false);
|
|
|
|
- }
|
|
|
|
- StringBuilder idSb = new StringBuilder();
|
|
|
|
- for (SysAccountGroupEntity accountGroupEntity : accountGroupEntityList) {
|
|
|
|
- if (idSb.length() > 0) {
|
|
|
|
- idSb.append(",");
|
|
|
|
- }
|
|
|
|
- idSb.append(accountGroupEntity.getAccountId());
|
|
|
|
- }
|
|
|
|
- return new Result(ResultCode.SUCCESS, idSb.toString());
|
|
|
|
- }
|
|
|
|
-}
|
|
|