feat: 增加获取授权后的id信息,改用缓存类

dev
huangfeng 1 year ago
parent 96efa81072
commit e073edc3d6

@ -7,6 +7,7 @@ import com.shxy.xymanager_common.bean.ServiceStatus;
import com.shxy.xymanager_common.entity.DyLevel;
import com.shxy.xymanager_common.entity.TbRole;
import com.shxy.xymanager_common.exception.ApiException;
import com.shxy.xymanager_service.service.NewCacheService;
import com.shxy.xymanager_service.service.RoleService;
import io.swagger.annotations.Api;
@ -27,6 +28,8 @@ public class RoleController extends BaseController {
@Resource
RoleService service;
@Resource
NewCacheService cacheService;
@GetMapping("listAll")
@ApiOperation("查询全部列表")
@ -65,12 +68,8 @@ public class RoleController extends BaseController {
@GetMapping("getPermissionTree")
@ApiOperation("查询权限树状图")
public ResponseReult<List<DyLevel>> getPermissionTree() {
ServiceBody<List<DyLevel>> serviceBody = service.getPermissionTree();
if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
return ResponseReult.success(serviceBody.getData());
} else {
return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg());
}
List<DyLevel> list = cacheService.getFullTree();
return ResponseReult.success(list);
}
}

@ -25,7 +25,38 @@ public class PermissionDetail {
private Integer isSuper = CommonStatus.DELETE.value();
private Integer uid ;
private Integer uid;
public boolean hasDyId(Integer id) {
if (dypList.contains(id)) {
return true;
} else {
return false;
}
}
public boolean hasLineId(Integer id) {
if (linepList.contains(id)) {
return true;
} else {
return false;
}
}
public boolean hasTowerId(Integer id) {
if (towerpList.contains(id)) {
return true;
} else {
return false;
}
}
public boolean hasTermId(Integer id) {
if (termpList.contains(id)) {
return true;
} else {
return false;
}
}
}

@ -33,6 +33,21 @@ public class DyLevel implements Serializable {
@ApiModelProperty(value = "线路列表", example = "[]")
public List<Lines> list = new ArrayList<>();
private boolean include;
public boolean checkInclude() {
if (include) {
return true;
} else {
for (Lines item : list) {
if (item.checkInclude()) {
return true;
}
}
return false;
}
}
private static final long serialVersionUID = 1L;
}

@ -39,6 +39,21 @@ public class Lines implements Serializable {
@ApiModelProperty(value = "杆塔信息", example = "123456")
private List<Towers> list = new ArrayList<>();
private boolean include;
public boolean checkInclude() {
if (include) {
return true;
} else {
for (Towers item : list) {
if (item.checkInclude()) {
return true;
}
}
return false;
}
}
private static final long serialVersionUID = 1L;
}

@ -113,4 +113,14 @@ public class Terminals implements Serializable {
private static final long serialVersionUID = 1L;
private boolean include;
public boolean checkInclude() {
if (include) {
return true;
} else {
return false;
}
}
}

@ -106,6 +106,19 @@ public class Towers implements Serializable {
private Integer isfavor;
private boolean include;
public boolean checkInclude() {
if (include) {
return true;
} else {
for (Terminals item : list) {
if (item.checkInclude()) {
return true;
}
}
return false;
}
}
}

@ -18,6 +18,7 @@ import com.shxy.xymanager_service.service.CacheService;
import com.shxy.xymanager_service.service.LineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -102,6 +103,7 @@ public class LineServiceImpl implements LineService {
* @return
*/
@Override
@CacheEvict(value = "fulltree")
public ServiceBody<String> addLine(LineVo vo) {
List<Lines> lines = BeanUtil.copyToList(vo.getList(), Lines.class, CopyOptions.create().ignoreCase());
Date date = new Date();
@ -121,6 +123,7 @@ public class LineServiceImpl implements LineService {
* @return
*/
@Override
@CacheEvict(value = "fulltree")
public ServiceBody<String> deleteLine(LineIdVo vo) {
List<Integer> list = vo.getList();
if (CollectionUtil.isEmpty(list)) {
@ -146,6 +149,7 @@ public class LineServiceImpl implements LineService {
* @return
*/
@Override
@CacheEvict(value = "fulltree")
public ServiceBody<String> updateLine(UpdateLineVo vo) {
Lines lines = new Lines();
lines.setId(vo.getId());

@ -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;
}
}

@ -7,6 +7,7 @@ import com.shxy.xymanager_common.enums.PermissionDetailEnum;
import com.shxy.xymanager_dao.dao.*;
import com.shxy.xymanager_service.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -58,6 +59,7 @@ public class PermissionServiceImpl implements PermissionService {
}
@Override
@CacheEvict(value = "permission_byuser", key = "#userId")
public void changePermission(Integer userId, List<TbPermission> list) throws Exception {
TbPermissionExample example = new TbPermissionExample();
TbPermissionExample.Criteria criteria = example.createCriteria();

@ -1,21 +1,15 @@
package com.shxy.xymanager_service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.shxy.xymanager_common.bean.ServiceBody;
import com.shxy.xymanager_common.entity.*;
import com.shxy.xymanager_common.exception.ApiException;
import com.shxy.xymanager_common.exception.Asserts;
import com.shxy.xymanager_dao.dao.*;
import com.shxy.xymanager_service.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import static com.shxy.xymanager_common.constant.Constants.SUPER_ADMIN;
@ -29,17 +23,6 @@ public class RoleServiceImpl implements RoleService {
@Resource
TbRoleMapper roleMapper;
@Autowired
DyLevelDao dyLevelDao;
@Autowired
LinesDao linesDao;
@Autowired
TowerDao towerDao;
@Autowired
TerminalsDao terminalsDao;
@Override
public List<TbRole> listAll() {
@ -97,61 +80,4 @@ public class RoleServiceImpl implements RoleService {
roleMapper.deleteByPrimaryKey(id);
}
/*
*
*
* */
@Override
public ServiceBody<List<DyLevel>> getPermissionTree() {
List<DyLevel> dyLevels = dyLevelDao.selectByExample(new DyLevelExample());
List<Lines> lines = linesDao.selectByExample(new LinesExample());
List<Towers> towers = towerDao.selectByExample(new TowersExample());
List<Terminals> terminals = terminalsDao.selectByExample(new TerminalsExample());
if (CollectionUtil.isNotEmpty(dyLevels)) {
HashMap<Integer, DyLevel> dymap = new HashMap<>();
HashMap<Integer, Lines> linemap = new HashMap<>();
HashMap<Integer, Towers> towermap = new HashMap<>();
HashMap<Integer, Terminals> termmap = new HashMap<>();
for (DyLevel ditem : dyLevels) {
dymap.put(ditem.getId(), ditem);
}
for (Lines litem : lines) {
linemap.put(litem.getId(), litem);
}
for (Towers titem : towers) {
towermap.put(titem.getId(), titem);
}
for (Terminals termitem : terminals) {
termmap.put(termitem.getId(), termitem);
}
for (Terminals termitem : terminals) {
Integer towerid = termitem.getTowerId();
if (towerid != null) {
Towers towers1 = towermap.get(towerid);
if (BeanUtil.isNotEmpty(towers1)) {
towers1.getList().add(termitem);
}
}
}
for (Towers titem : towers) {
Integer lineId = titem.getLineid();
if (lineId != null) {
Lines lines1 = linemap.get(lineId);
if (BeanUtil.isNotEmpty(lines1)) {
lines1.getList().add(titem);
}
}
}
for (Lines litem : lines) {
Integer dyLevelId = litem.getDyLevelId();
if (dyLevelId != null) {
DyLevel dyLevel = dymap.get(dyLevelId);
if (BeanUtil.isNotEmpty(dyLevel)) {
dyLevel.getList().add(litem);
}
}
}
}
return Asserts.success(dyLevels);
}
}

@ -32,6 +32,7 @@ import com.shxy.xymanager_service.service.TerminalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -223,6 +224,7 @@ public class TerminalServiceImpl implements TerminalService {
* @return
*/
@Override
@CacheEvict(value = "fulltree")
public ServiceBody<String> addTerminal(TerminalVo vo) {
String cmdId = vo.getCmdid();
Terminals terminals = new Terminals();
@ -268,6 +270,7 @@ public class TerminalServiceImpl implements TerminalService {
* @return
*/
@Override
@CacheEvict(value = "fulltree")
public ServiceBody<String> updateTerminal(UpdateTerminalVo vo) {
Integer termid = vo.getId();
List<UpdateTerminalVo.Item> channelId = vo.getList();
@ -308,6 +311,7 @@ public class TerminalServiceImpl implements TerminalService {
* @return
*/
@Override
@CacheEvict(value = "fulltree")
public ServiceBody<String> deleteTerminal(TerminalIdListVo vo) {
List<Integer> list = vo.getList();
if (CollectionUtil.isEmpty(list)) {
@ -394,6 +398,7 @@ public class TerminalServiceImpl implements TerminalService {
}
@Override
@CacheEvict(value = "fulltree")
public ServiceBody<TerminalUpdateModel> updateTerminalId(TerminalIdUpdateVo vo) {
TerminalUpdateModel model = new TerminalUpdateModel();
Integer termId = vo.getTermId();

@ -22,6 +22,7 @@ import com.shxy.xymanager_service.service.CacheService;
import com.shxy.xymanager_service.service.TowerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -45,6 +46,7 @@ public class TowerServiceImpl implements TowerService {
private CacheService cacheService;
@Override
@CacheEvict(value = "fulltree")
public ServiceBody addTower(TowersVo vo) {
List<Towers> towersLst = BeanUtil.copyToList(vo.getList(), Towers.class, CopyOptions.create().ignoreCase());
Date date = new Date();
@ -91,6 +93,7 @@ public class TowerServiceImpl implements TowerService {
}
@Override
@CacheEvict(value = "fulltree")
public ServiceBody<String> deleteTower(TowerIdVo vo) {
List<Integer> list = vo.getList();
if (CollectionUtil.isEmpty(list)) {
@ -109,6 +112,7 @@ public class TowerServiceImpl implements TowerService {
}
@Override
@CacheEvict(value = "fulltree")
public ServiceBody<String> updateTower(UpdateTowerVo vo) {
Towers towers = new Towers();
towers.setId(vo.getId());

@ -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();
}

@ -1,7 +1,5 @@
package com.shxy.xymanager_service.service;
import com.shxy.xymanager_common.bean.ServiceBody;
import com.shxy.xymanager_common.entity.DyLevel;
import com.shxy.xymanager_common.entity.TbRole;
import java.util.List;
@ -16,6 +14,4 @@ public interface RoleService {
void delete(Integer id) throws Exception;
ServiceBody<List<DyLevel>> getPermissionTree() ;
}

Loading…
Cancel
Save