feat: 增加获取授权后的id信息,改用缓存类
parent
96efa81072
commit
e073edc3d6
@ -0,0 +1,187 @@
|
||||
package com.shxy.xymanager_service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.shxy.xymanager_common.bean.PermissionDetail;
|
||||
import com.shxy.xymanager_common.entity.*;
|
||||
import com.shxy.xymanager_dao.dao.*;
|
||||
import com.shxy.xymanager_service.service.NewCacheService;
|
||||
import com.shxy.xymanager_service.service.PermissionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class NewCacheServiceImpl implements NewCacheService {
|
||||
|
||||
@Resource
|
||||
PermissionService permissionService;
|
||||
@Resource
|
||||
DyLevelDao dyLevelDao;
|
||||
@Resource
|
||||
LinesDao linesDao;
|
||||
@Resource
|
||||
TowerDao towerDao;
|
||||
@Resource
|
||||
TerminalsDao terminalsDao;
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "permission_byuser", key = "#userId")
|
||||
public PermissionDetail getIncludeDetail(Integer userId) {
|
||||
PermissionDetail detail = permissionService.getPermissionDetail(userId);
|
||||
|
||||
// 全量
|
||||
List<DyLevel> dyList = dyLevelDao.selectByExample(new DyLevelExample());
|
||||
List<Lines> lineList = linesDao.selectByExample(new LinesExample());
|
||||
List<Towers> towerList = towerDao.selectByExample(new TowersExample());
|
||||
List<Terminals> terminalList = terminalsDao.selectByExample(new TerminalsExample());
|
||||
|
||||
HashMap<Integer, DyLevel> dyMap = new HashMap<>();
|
||||
HashMap<Integer, Lines> lineMap = new HashMap<>();
|
||||
HashMap<Integer, Towers> towerMap = new HashMap<>();
|
||||
HashMap<Integer, Terminals> terminalMap = new HashMap<>();
|
||||
// 做map
|
||||
for (DyLevel dy : dyList) {
|
||||
if (detail.hasDyId(dy.getId())) {
|
||||
dy.setInclude(true);
|
||||
}
|
||||
dyMap.put(dy.getId(), dy);
|
||||
}
|
||||
for (Lines line : lineList) {
|
||||
if (detail.hasLineId(line.getId())) {
|
||||
line.setInclude(true);
|
||||
}
|
||||
lineMap.put(line.getId(), line);
|
||||
}
|
||||
for (Towers tower : towerList) {
|
||||
if (detail.hasTowerId(tower.getId())) {
|
||||
tower.setInclude(true);
|
||||
}
|
||||
towerMap.put(tower.getId(), tower);
|
||||
}
|
||||
for (Terminals terminal : terminalList) {
|
||||
if (detail.hasTermId(terminal.getId())) {
|
||||
terminal.setInclude(true);
|
||||
}
|
||||
terminalMap.put(terminal.getId(), terminal);
|
||||
}
|
||||
|
||||
// 一层挂上一层
|
||||
for (Terminals terminal : terminalList) {
|
||||
Integer towerId = terminal.getTowerId();
|
||||
if (towerId != null) {
|
||||
Towers tower = towerMap.get(towerId);
|
||||
if (tower != null) {
|
||||
tower.getList().add(terminal);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Towers tower : towerList) {
|
||||
Integer lineId = tower.getLineid();
|
||||
if (lineId != null) {
|
||||
Lines line = lineMap.get(lineId);
|
||||
if (line != null) {
|
||||
line.getList().add(tower);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Lines line : lineList) {
|
||||
Integer dyLevelId = line.getDyLevelId();
|
||||
if (dyLevelId != null) {
|
||||
DyLevel dyLevel = dyMap.get(dyLevelId);
|
||||
if (dyLevel != null) {
|
||||
dyLevel.getList().add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 找出相关的
|
||||
detail = new PermissionDetail();
|
||||
for (DyLevel dy : dyList) {
|
||||
if (dy.checkInclude()) {
|
||||
detail.getDypList().add(dy.getId());
|
||||
}
|
||||
}
|
||||
for (Lines line : lineList) {
|
||||
if (line.checkInclude()) {
|
||||
detail.getLinepList().add(line.getId());
|
||||
}
|
||||
}
|
||||
for (Towers tower : towerList) {
|
||||
if (tower.checkInclude()) {
|
||||
detail.getTowerpList().add(tower.getId());
|
||||
}
|
||||
}
|
||||
for (Terminals terminal : terminalList) {
|
||||
if (terminal.checkInclude()) {
|
||||
detail.getTermpList().add(terminal.getId());
|
||||
}
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "fulltree")
|
||||
public List<DyLevel> getFullTree() {
|
||||
// 全量
|
||||
List<DyLevel> dyList = dyLevelDao.selectByExample(new DyLevelExample());
|
||||
List<Lines> lineList = linesDao.selectByExample(new LinesExample());
|
||||
List<Towers> towerList = towerDao.selectByExample(new TowersExample());
|
||||
List<Terminals> terminalList = terminalsDao.selectByExample(new TerminalsExample());
|
||||
if (CollectionUtil.isNotEmpty(dyList)) {
|
||||
HashMap<Integer, DyLevel> dyMap = new HashMap<>();
|
||||
HashMap<Integer, Lines> lineMap = new HashMap<>();
|
||||
HashMap<Integer, Towers> towerMap = new HashMap<>();
|
||||
HashMap<Integer, Terminals> terminalMap = new HashMap<>();
|
||||
// 做map
|
||||
for (DyLevel dy : dyList) {
|
||||
dyMap.put(dy.getId(), dy);
|
||||
}
|
||||
for (Lines line : lineList) {
|
||||
lineMap.put(line.getId(), line);
|
||||
}
|
||||
for (Towers tower : towerList) {
|
||||
towerMap.put(tower.getId(), tower);
|
||||
}
|
||||
for (Terminals terminal : terminalList) {
|
||||
terminalMap.put(terminal.getId(), terminal);
|
||||
}
|
||||
|
||||
// 一层挂上一层
|
||||
for (Terminals terminal : terminalList) {
|
||||
Integer towerId = terminal.getTowerId();
|
||||
if (towerId != null) {
|
||||
Towers tower = towerMap.get(towerId);
|
||||
if (tower != null) {
|
||||
tower.getList().add(terminal);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Towers tower : towerList) {
|
||||
Integer lineId = tower.getLineid();
|
||||
if (lineId != null) {
|
||||
Lines line = lineMap.get(lineId);
|
||||
if (line != null) {
|
||||
line.getList().add(tower);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Lines line : lineList) {
|
||||
Integer dyLevelId = line.getDyLevelId();
|
||||
if (dyLevelId != null) {
|
||||
DyLevel dyLevel = dyMap.get(dyLevelId);
|
||||
if (dyLevel != null) {
|
||||
dyLevel.getList().add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dyList;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.shxy.xymanager_service.service;
|
||||
|
||||
|
||||
import com.shxy.xymanager_common.bean.PermissionDetail;
|
||||
import com.shxy.xymanager_common.entity.DyLevel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NewCacheService {
|
||||
|
||||
PermissionDetail getIncludeDetail(Integer userId);
|
||||
|
||||
List<DyLevel> getFullTree();
|
||||
}
|
Loading…
Reference in New Issue