修改一些bug
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
package co.yixiang.modules.monitor.config;
|
||||
|
||||
import co.yixiang.modules.monitor.service.VisitsService;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 初始化站点统计
|
||||
* @author Zheng Jie
|
||||
*/
|
||||
@Component
|
||||
public class VisitsInitialization implements ApplicationRunner {
|
||||
|
||||
private final VisitsService visitsService;
|
||||
|
||||
public VisitsInitialization(VisitsService visitsService) {
|
||||
this.visitsService = visitsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args){
|
||||
System.out.println("--------------- 初始化站点统计,如果存在今日统计则跳过 ---------------");
|
||||
visitsService.save();
|
||||
System.out.println("--------------- 初始化站点统计完成 ---------------");
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package co.yixiang.modules.monitor.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* pv 与 ip 统计
|
||||
*
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-13
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name = "visits")
|
||||
public class Visits implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true)
|
||||
private String date;
|
||||
|
||||
@Column(name = "pv_counts")
|
||||
private Long pvCounts;
|
||||
|
||||
@Column(name = "ip_counts")
|
||||
private Long ipCounts;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "create_time")
|
||||
private Timestamp createTime;
|
||||
|
||||
@Column(name = "week_day")
|
||||
private String weekDay;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package co.yixiang.modules.monitor.domain.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-10
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RedisVo implements Serializable {
|
||||
|
||||
@NotBlank
|
||||
private String key;
|
||||
|
||||
@NotBlank
|
||||
private String value;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package co.yixiang.modules.monitor.rest;
|
||||
|
||||
import co.yixiang.annotation.AnonymousAccess;
|
||||
import co.yixiang.annotation.Limit;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author /
|
||||
* 接口限流测试类
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/limit")
|
||||
@Api(tags = "系统:限流测试管理")
|
||||
public class LimitController {
|
||||
|
||||
private static final AtomicInteger ATOMIC_INTEGER = new AtomicInteger();
|
||||
|
||||
/**
|
||||
* 测试限流注解,下面配置说明该接口 60秒内最多只能访问 10次,保存到redis的键名为 limit_test,
|
||||
*/
|
||||
@GetMapping
|
||||
@AnonymousAccess
|
||||
@ApiOperation("测试")
|
||||
@Limit(key = "test", period = 60, count = 10, name = "testLimit", prefix = "limit")
|
||||
public int testLimit() {
|
||||
return ATOMIC_INTEGER.incrementAndGet();
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package co.yixiang.modules.monitor.rest;
|
||||
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.modules.monitor.domain.vo.RedisVo;
|
||||
import co.yixiang.modules.monitor.service.RedisService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-10
|
||||
*/
|
||||
@Api(tags = "redis缓存管理")
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
public class RedisController {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Log("查询Redis缓存")
|
||||
@GetMapping(value = "/redis")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','REDIS_ALL','REDIS_SELECT')")
|
||||
public ResponseEntity getRedis(String key, Pageable pageable){
|
||||
return new ResponseEntity(redisService.findByKey(key,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("删除Redis缓存")
|
||||
@DeleteMapping(value = "/redis")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','REDIS_ALL','REDIS_DELETE')")
|
||||
public ResponseEntity delete(@RequestBody RedisVo resources){
|
||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||
redisService.delete(resources.getKey());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("清空Redis缓存")
|
||||
@DeleteMapping(value = "/redis/all")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','REDIS_ALL','REDIS_DELETE')")
|
||||
public ResponseEntity deleteAll(){
|
||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||
redisService.flushdb();
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package co.yixiang.modules.monitor.rest;
|
||||
|
||||
import co.yixiang.modules.monitor.service.VisitsService;
|
||||
import co.yixiang.utils.RequestHolder;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/visits")
|
||||
@Api(tags = "系统:访问记录管理")
|
||||
public class VisitsController {
|
||||
|
||||
private final VisitsService visitsService;
|
||||
|
||||
public VisitsController(VisitsService visitsService) {
|
||||
this.visitsService = visitsService;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("创建访问记录")
|
||||
public ResponseEntity<Object> create(){
|
||||
visitsService.count(RequestHolder.getHttpServletRequest());
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation("查询")
|
||||
public ResponseEntity<Object> get(){
|
||||
return new ResponseEntity<>(visitsService.get(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/chartData")
|
||||
@ApiOperation("查询图表数据")
|
||||
public ResponseEntity<Object> getChartData(){
|
||||
return new ResponseEntity<>(visitsService.getChartData(),HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package co.yixiang.modules.monitor.service;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* 可自行扩展
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-10
|
||||
*/
|
||||
public interface RedisService {
|
||||
|
||||
/**
|
||||
* findById
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
Page findByKey(String key, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询验证码的值
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
String getCodeVal(String key);
|
||||
|
||||
/**
|
||||
* 保存验证码
|
||||
* @param key
|
||||
* @param val
|
||||
*/
|
||||
void saveCode(String key, Object val);
|
||||
|
||||
/**
|
||||
* delete
|
||||
* @param key
|
||||
*/
|
||||
void delete(String key);
|
||||
|
||||
/**
|
||||
* 清空所有缓存
|
||||
*/
|
||||
void flushdb();
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package co.yixiang.modules.monitor.service;
|
||||
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-13
|
||||
*/
|
||||
public interface VisitsService {
|
||||
|
||||
/**
|
||||
* 提供给定时任务,每天0点执行
|
||||
*/
|
||||
void save();
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param request /
|
||||
*/
|
||||
@Async
|
||||
void count(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
* @return /
|
||||
*/
|
||||
Object get();
|
||||
|
||||
/**
|
||||
* getChartData
|
||||
* @return /
|
||||
*/
|
||||
Object getChartData();
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package co.yixiang.modules.monitor.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* @author Zhang houying
|
||||
* @date 2019-11-03
|
||||
*/
|
||||
@Data
|
||||
public class ServerDTO implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String address;
|
||||
|
||||
private Integer port;
|
||||
|
||||
private String state;
|
||||
|
||||
/** CPU使用率 */
|
||||
private Float cpuRate;
|
||||
|
||||
/** CPU内核数 */
|
||||
private Integer cpuCore;
|
||||
|
||||
/** 内存总数 */
|
||||
private Float memTotal;
|
||||
|
||||
/** 内存使用量 */
|
||||
private Float memUsed;
|
||||
|
||||
/** 磁盘总量 */
|
||||
private Float diskTotal;
|
||||
|
||||
/** 磁盘使用量 */
|
||||
private Float diskUsed;
|
||||
|
||||
/** 交换区总量 */
|
||||
private Float swapTotal;
|
||||
|
||||
/** 交换区使用量 */
|
||||
private Float swapUsed;
|
||||
|
||||
private Integer sort;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package co.yixiang.modules.monitor.service.dto;
|
||||
|
||||
import co.yixiang.annotation.Query;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Zhang houying
|
||||
* @date 2019-11-03
|
||||
*/
|
||||
@Data
|
||||
public class ServerQueryCriteria{
|
||||
|
||||
@Query(blurry = "name,address")
|
||||
private String blurry;
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package co.yixiang.modules.monitor.service.impl;
|
||||
|
||||
import co.yixiang.modules.monitor.domain.vo.RedisVo;
|
||||
import co.yixiang.modules.monitor.service.RedisService;
|
||||
import co.yixiang.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-10
|
||||
*/
|
||||
@Service
|
||||
public class RedisServiceImpl implements RedisService {
|
||||
|
||||
@Autowired
|
||||
RedisTemplate redisTemplate;
|
||||
|
||||
@Value("${loginCode.expiration}")
|
||||
private Long expiration;
|
||||
|
||||
@Override
|
||||
public Page<RedisVo> findByKey(String key, Pageable pageable){
|
||||
List<RedisVo> redisVos = new ArrayList<>();
|
||||
if(!"*".equals(key)){
|
||||
key = "*" + key + "*";
|
||||
}
|
||||
for (Object s : redisTemplate.keys(key)) {
|
||||
// 过滤掉权限的缓存
|
||||
if (s.toString().indexOf("role::loadPermissionByUser") != -1
|
||||
|| s.toString().indexOf("user::loadUserByUsername") != -1
|
||||
|| s.toString().indexOf("wechat") != -1
|
||||
|| s.toString().indexOf("wxpay") != -1
|
||||
|| s.toString().indexOf("site_url") != -1) {
|
||||
continue;
|
||||
}
|
||||
DataType dataType = redisTemplate.type(s.toString());
|
||||
if(!dataType.code().equals("string")) continue;
|
||||
RedisVo redisVo = new RedisVo(s.toString(),redisTemplate.opsForValue().get(s.toString()).toString());
|
||||
redisVos.add(redisVo);
|
||||
}
|
||||
Page<RedisVo> page = new PageImpl<RedisVo>(
|
||||
PageUtil.toPage(pageable.getPageNumber(),pageable.getPageSize(),redisVos),
|
||||
pageable,
|
||||
redisVos.size());
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String key) {
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushdb() {
|
||||
redisTemplate.getConnectionFactory().getConnection().flushDb();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCodeVal(String key) {
|
||||
try {
|
||||
String value = redisTemplate.opsForValue().get(key).toString();
|
||||
return value;
|
||||
}catch (Exception e){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveCode(String key, Object val) {
|
||||
redisTemplate.opsForValue().set(key,val);
|
||||
redisTemplate.expire(key,expiration, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package co.yixiang.modules.monitor.service.impl;
|
||||
|
||||
import co.yixiang.logging.service.mapper.LogMapper;
|
||||
import co.yixiang.modules.monitor.domain.Visits;
|
||||
import co.yixiang.modules.monitor.service.VisitsService;
|
||||
import co.yixiang.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-13
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class VisitsServiceImpl implements VisitsService {
|
||||
|
||||
|
||||
private final LogMapper logMapper;
|
||||
|
||||
public VisitsServiceImpl(LogMapper logMapper) {
|
||||
this.logMapper = logMapper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
// Visits visits = logMapper.findByDate(localDate.toString());
|
||||
// if(visits == null){
|
||||
// visits = new Visits();
|
||||
// visits.setWeekDay(StringUtils.getWeekDay());
|
||||
// visits.setPvCounts(1L);
|
||||
// visits.setIpCounts(1L);
|
||||
// visits.setDate(localDate.toString());
|
||||
// logMapper.insert(visits);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void count(HttpServletRequest request) {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
// Visits visits = visitsRepository.findByDate(localDate.toString());
|
||||
// visits.setPvCounts(visits.getPvCounts()+1);
|
||||
// long ipCounts = logRepository.findIp(localDate.toString(), localDate.plusDays(1).toString());
|
||||
// visits.setIpCounts(ipCounts);
|
||||
// visitsRepository.save(visits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get() {
|
||||
Map<String,Object> map = new HashMap<>(4);
|
||||
LocalDate localDate = LocalDate.now();
|
||||
// Visits visits = visitsRepository.findByDate(localDate.toString());
|
||||
// List<Visits> list = visitsRepository.findAllVisits(localDate.minusDays(6).toString(),localDate.plusDays(1).toString());
|
||||
//
|
||||
// long recentVisits = 0, recentIp = 0;
|
||||
// for (Visits data : list) {
|
||||
// recentVisits += data.getPvCounts();
|
||||
// recentIp += data.getIpCounts();
|
||||
// }
|
||||
// map.put("newVisits",visits.getPvCounts());
|
||||
// map.put("newIp",visits.getIpCounts());
|
||||
// map.put("recentVisits",recentVisits);
|
||||
// map.put("recentIp",recentIp);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getChartData() {
|
||||
Map<String,Object> map = new HashMap<>(3);
|
||||
// LocalDate localDate = LocalDate.now();
|
||||
// List<Visits> list = visitsRepository.findAllVisits(localDate.minusDays(6).toString(),localDate.plusDays(1).toString());
|
||||
// map.put("weekDays",list.stream().map(Visits::getWeekDay).collect(Collectors.toList()));
|
||||
// map.put("visitsData",list.stream().map(Visits::getPvCounts).collect(Collectors.toList()));
|
||||
// map.put("ipData",list.stream().map(Visits::getIpCounts).collect(Collectors.toList()));
|
||||
return map;
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
package co.yixiang.modules.system.service;
|
||||
import co.yixiang.common.service.BaseService;
|
||||
import co.yixiang.modules.system.domain.Menu;
|
||||
import co.yixiang.modules.system.domain.vo.MenuVo;
|
||||
import co.yixiang.modules.system.service.dto.MenuDto;
|
||||
import co.yixiang.modules.system.service.dto.MenuQueryCriteria;
|
||||
import co.yixiang.modules.system.service.dto.RoleSmallDto;
|
||||
@ -60,7 +61,7 @@ public interface MenuService extends BaseService<Menu>{
|
||||
* @param menuDtos /
|
||||
* @return /
|
||||
*/
|
||||
Object buildMenus(List<MenuDto> menuDtos);
|
||||
List<MenuVo> buildMenus(List<MenuDto> menuDtos);
|
||||
|
||||
/**
|
||||
* 获取菜单树
|
||||
|
@ -20,47 +20,33 @@ import java.util.List;
|
||||
@Data
|
||||
public class MenuDto implements Serializable {
|
||||
|
||||
/** ID */
|
||||
private Long id;
|
||||
|
||||
/** 是否外链 */
|
||||
private Boolean iFrame;
|
||||
private Integer type;
|
||||
|
||||
private String permission;
|
||||
|
||||
/** 菜单名称 */
|
||||
private String name;
|
||||
|
||||
/** 组件 */
|
||||
private String component;
|
||||
|
||||
/** 上级菜单ID */
|
||||
private Long pid;
|
||||
|
||||
/** 排序 */
|
||||
private Long sort;
|
||||
|
||||
/** 图标 */
|
||||
private String icon;
|
||||
|
||||
/** 链接地址 */
|
||||
private String path;
|
||||
|
||||
/** 缓存 */
|
||||
private String component;
|
||||
|
||||
private Long pid;
|
||||
|
||||
private Boolean iFrame;
|
||||
|
||||
private Boolean cache;
|
||||
|
||||
/** 是否隐藏 */
|
||||
private Boolean hidden;
|
||||
|
||||
/** 组件名称 */
|
||||
private String componentName;
|
||||
|
||||
/** 创建日期 */
|
||||
private Timestamp createTime;
|
||||
|
||||
/** 权限 */
|
||||
private String permission;
|
||||
private String icon;
|
||||
|
||||
private List<MenuDto> children;
|
||||
|
||||
/** 类型 */
|
||||
private Integer type;
|
||||
private Timestamp createTime;
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
public Object buildMenus(List<MenuDto> menuDtos) {
|
||||
public List<MenuVo> buildMenus(List<MenuDto> menuDtos) {
|
||||
List<MenuVo> list = new LinkedList<>();
|
||||
menuDtos.forEach(menuDTO -> {
|
||||
if (menuDTO!=null){
|
||||
@ -170,7 +170,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
||||
if(menuDtoList !=null && menuDtoList.size()!=0){
|
||||
menuVo.setAlwaysShow(true);
|
||||
menuVo.setRedirect("noredirect");
|
||||
menuVo.setChildren((List<MenuVo>) buildMenus(menuDtoList));
|
||||
menuVo.setChildren(buildMenus(menuDtoList));
|
||||
// 处理是一级菜单并且没有子菜单的情况
|
||||
} else if(menuDTO.getPid() == 0){
|
||||
MenuVo menuVo1 = new MenuVo();
|
||||
|
@ -32,6 +32,8 @@ import co.yixiang.modules.system.service.RoleService;
|
||||
import co.yixiang.modules.system.service.dto.RoleDto;
|
||||
import co.yixiang.modules.system.service.dto.RoleQueryCriteria;
|
||||
import co.yixiang.modules.system.service.mapper.RoleMapper;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
@ -65,7 +67,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
//@CacheConfig(cacheNames = "role")
|
||||
@CacheConfig(cacheNames = "role")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implements RoleService {
|
||||
|
||||
@ -75,7 +77,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
||||
private final DeptMapper deptMapper;
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
@Cacheable
|
||||
public Map<String, Object> queryAll(RoleQueryCriteria criteria, Pageable pageable) {
|
||||
getPage(pageable);
|
||||
PageInfo<Role> page = new PageInfo<>(queryAll(criteria));
|
||||
@ -87,7 +89,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
||||
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
@Cacheable
|
||||
public List<Role> queryAll(RoleQueryCriteria criteria){
|
||||
return baseMapper.selectList(QueryHelpPlus.getPredicate(Role.class, criteria));
|
||||
}
|
||||
@ -115,6 +117,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
||||
* @param id 用户ID
|
||||
* @return /
|
||||
*/
|
||||
// @Cacheable(key = "'findByUsers_Id:' + #p0")
|
||||
@Override
|
||||
public List<RoleSmallDto> findByUsersId(Long id) {
|
||||
List<Role> roles = roleMapper.selectListByUserId(id);
|
||||
@ -155,6 +158,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
||||
* @param roleDto /
|
||||
*/
|
||||
@Override
|
||||
// @CacheEvict(allEntries = true)
|
||||
public void updateMenu(Role resources, RoleDto roleDto) {
|
||||
Role role =generator.convert(roleDto,Role.class);
|
||||
role.setMenus(resources.getMenus());
|
||||
@ -168,13 +172,14 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
||||
* @return 权限信息
|
||||
*/
|
||||
@Override
|
||||
//@Cacheable(key = "'loadPermissionByUser:' + #p0.username")
|
||||
// @Cacheable(key = "'loadPermissionByUser:' + #p0.username")
|
||||
public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDto user) {
|
||||
Set<Role> roles = roleMapper.findByUsers_Id(user.getId());
|
||||
for (Role role : roles) {
|
||||
Set<Menu> menuSet = menuMapper.findMenuByRoleId(role.getId());
|
||||
role.setMenus(menuSet);
|
||||
Set<Dept> deptSet = deptMapper.findDeptByRoleId(role.getId());
|
||||
role.setDepts(deptSet);
|
||||
}
|
||||
Set<String> permissions = roles.stream().filter(role -> StringUtils.isNotBlank(role.getPermission())).map(Role::getPermission).collect(Collectors.toSet());
|
||||
permissions.addAll(
|
||||
|
Reference in New Issue
Block a user