Commit 284c25a1 authored by dqjdda's avatar dqjdda
Browse files

Merge branch '2.4dev' into 2.4opt

parents 175a2eb6 ccca30fc
...@@ -20,7 +20,7 @@ public class UserQueryCriteria implements Serializable { ...@@ -20,7 +20,7 @@ public class UserQueryCriteria implements Serializable {
@Query(propName = "id", type = Query.Type.IN, joinName = "dept") @Query(propName = "id", type = Query.Type.IN, joinName = "dept")
private Set<Long> deptIds; private Set<Long> deptIds;
@Query(blurry = "email,username") @Query(blurry = "email,username,nickName")
private String blurry; private String blurry;
@Query @Query
......
...@@ -66,11 +66,8 @@ public class MenuServiceImpl implements MenuService { ...@@ -66,11 +66,8 @@ public class MenuServiceImpl implements MenuService {
@Override @Override
public List<MenuDto> findByRoles(List<RoleSmallDto> roles) { public List<MenuDto> findByRoles(List<RoleSmallDto> roles) {
Set<Menu> menus = new LinkedHashSet<>(); Set<Long> roleIds = roles.stream().map(RoleSmallDto::getId).collect(Collectors.toSet());
for (RoleSmallDto role : roles) { LinkedHashSet<Menu> menus = menuRepository.findByRoles_IdInAndTypeNotOrderBySortAsc(roleIds, 2);
List<Menu> menus1 = new ArrayList<>(menuRepository.findByRoles_IdAndTypeIsNotInOrderBySortAsc(role.getId(), 2));
menus.addAll(menus1);
}
return menus.stream().map(menuMapper::toDto).collect(Collectors.toList()); return menus.stream().map(menuMapper::toDto).collect(Collectors.toList());
} }
......
package me.zhengjie.modules.system.service.impl; package me.zhengjie.modules.system.service.impl;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Role; import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.exception.EntityExistException; import me.zhengjie.exception.EntityExistException;
import me.zhengjie.modules.system.repository.RoleRepository; import me.zhengjie.modules.system.repository.RoleRepository;
...@@ -7,17 +8,17 @@ import me.zhengjie.modules.system.service.RoleService; ...@@ -7,17 +8,17 @@ import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.RoleDto; import me.zhengjie.modules.system.service.dto.RoleDto;
import me.zhengjie.modules.system.service.dto.RoleQueryCriteria; import me.zhengjie.modules.system.service.dto.RoleQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleSmallDto; import me.zhengjie.modules.system.service.dto.RoleSmallDto;
import me.zhengjie.modules.system.service.dto.UserDto;
import me.zhengjie.modules.system.service.mapper.RoleMapper; import me.zhengjie.modules.system.service.mapper.RoleMapper;
import me.zhengjie.modules.system.service.mapper.RoleSmallMapper; import me.zhengjie.modules.system.service.mapper.RoleSmallMapper;
import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.*;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -144,6 +145,20 @@ public class RoleServiceImpl implements RoleService { ...@@ -144,6 +145,20 @@ public class RoleServiceImpl implements RoleService {
return Collections.min(roleDtos.stream().map(RoleDto::getLevel).collect(Collectors.toList())); return Collections.min(roleDtos.stream().map(RoleDto::getLevel).collect(Collectors.toList()));
} }
@Override
@Cacheable(key = "'loadPermissionByUser:' + #p0.username")
public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDto user) {
Set<Role> roles = roleRepository.findByUsers_Id(user.getId());
Set<String> permissions = roles.stream().filter(role -> StringUtils.isNotBlank(role.getPermission())).map(Role::getPermission).collect(Collectors.toSet());
permissions.addAll(
roles.stream().flatMap(role -> role.getMenus().stream())
.filter(menu -> StringUtils.isNotBlank(menu.getPermission()))
.map(Menu::getPermission).collect(Collectors.toSet())
);
return permissions.stream().map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());
}
@Override @Override
public void download(List<RoleDto> roles, HttpServletResponse response) throws IOException { public void download(List<RoleDto> roles, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
......
package me.zhengjie.modules.system.service.impl; package me.zhengjie.modules.system.service.impl;
import me.zhengjie.modules.monitor.service.RedisService;
import me.zhengjie.modules.system.domain.User; import me.zhengjie.modules.system.domain.User;
import me.zhengjie.exception.EntityExistException; import me.zhengjie.exception.EntityExistException;
import me.zhengjie.exception.EntityNotFoundException; import me.zhengjie.exception.EntityNotFoundException;
...@@ -42,17 +41,17 @@ public class UserServiceImpl implements UserService { ...@@ -42,17 +41,17 @@ public class UserServiceImpl implements UserService {
private final UserMapper userMapper; private final UserMapper userMapper;
private final RedisService redisService; private final RedisUtils redisUtils;
private final UserAvatarRepository userAvatarRepository; private final UserAvatarRepository userAvatarRepository;
@Value("${file.avatar}") @Value("${file.avatar}")
private String avatar; private String avatar;
public UserServiceImpl(UserRepository userRepository, UserMapper userMapper, RedisService redisService, UserAvatarRepository userAvatarRepository) { public UserServiceImpl(UserRepository userRepository, UserMapper userMapper, RedisUtils redisUtils, UserAvatarRepository userAvatarRepository) {
this.userRepository = userRepository; this.userRepository = userRepository;
this.userMapper = userMapper; this.userMapper = userMapper;
this.redisService = redisService; this.redisUtils = redisUtils;
this.userAvatarRepository = userAvatarRepository; this.userAvatarRepository = userAvatarRepository;
} }
...@@ -116,9 +115,9 @@ public class UserServiceImpl implements UserService { ...@@ -116,9 +115,9 @@ public class UserServiceImpl implements UserService {
// 如果用户的角色改变了,需要手动清理下缓存 // 如果用户的角色改变了,需要手动清理下缓存
if (!resources.getRoles().equals(user.getRoles())) { if (!resources.getRoles().equals(user.getRoles())) {
String key = "role::loadPermissionByUser:" + user.getUsername(); String key = "role::loadPermissionByUser:" + user.getUsername();
redisService.delete(key); redisUtils.del(key);
key = "role::findByUsers_Id:" + user.getId(); key = "role::findByUsers_Id:" + user.getId();
redisService.delete(key); redisUtils.del(key);
} }
user.setUsername(resources.getUsername()); user.setUsername(resources.getUsername());
...@@ -128,6 +127,19 @@ public class UserServiceImpl implements UserService { ...@@ -128,6 +127,19 @@ public class UserServiceImpl implements UserService {
user.setDept(resources.getDept()); user.setDept(resources.getDept());
user.setJob(resources.getJob()); user.setJob(resources.getJob());
user.setPhone(resources.getPhone()); user.setPhone(resources.getPhone());
user.setNickName(resources.getNickName());
user.setSex(resources.getSex());
userRepository.save(user);
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void updateCenter(User resources) {
User user = userRepository.findById(resources.getId()).orElseGet(User::new);
user.setNickName(resources.getNickName());
user.setPhone(resources.getPhone());
user.setSex(resources.getSex());
userRepository.save(user); userRepository.save(user);
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
spring: spring:
datasource: datasource:
druid: druid:
type: com.alibaba.druid.pool.DruidDataSource db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false url: jdbc:log4jdbc:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: root username: root
...@@ -44,13 +44,16 @@ spring: ...@@ -44,13 +44,16 @@ spring:
#jwt #jwt
jwt: jwt:
header: Authorization header: Authorization
secret: mySecret # 令牌前缀
# token 过期时间/毫秒,6小时 1小时 = 3600000 毫秒 token-start-with: Bearer
expiration: 21600000 # 必须使用最少88位的Base64对该令牌进行编码
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
# 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
token-validity-in-seconds: 14400000
# 在线用户key # 在线用户key
online: online-token online-key: online-token
# 验证码 # 验证码
codeKey: code-key code-key: code-key
#是否允许生成代码,生产环境设置为false #是否允许生成代码,生产环境设置为false
generator: generator:
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
spring: spring:
datasource: datasource:
druid: druid:
type: com.alibaba.druid.pool.DruidDataSource db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false url: jdbc:log4jdbc:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: root username: root
...@@ -46,13 +46,16 @@ spring: ...@@ -46,13 +46,16 @@ spring:
#jwt #jwt
jwt: jwt:
header: Authorization header: Authorization
secret: mySecret # 令牌前缀
# token 过期时间 2个小时 token-start-with: Bearer
expiration: 7200000 # 必须使用最少88位的Base64对该令牌进行编码
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
# 令牌过期时间 此处单位/毫秒 ,默认2小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
token-validity-in-seconds: 7200000
# 在线用户key # 在线用户key
online: online-token online-key: online-token
# 验证码 # 验证码
codeKey: code-key code-key: code-key
#是否允许生成代码,生产环境设置为false #是否允许生成代码,生产环境设置为false
generator: generator:
......
# 用户加密方式变动,改为 BCryptPasswordEncoder方式: SHA-256 +随机盐+密钥对密码进行加密,替换后的明文密码为 123456
update user set `password` = "$2a$10$HhxyGZy.ulf3RvAwaHUGb.k.2i9PBpv4YbLMJWp8pES7pPhTyRCF." WHERE `password` = "e10adc3949ba59abbe56e057f20f883e"
\ No newline at end of file
...@@ -257,7 +257,6 @@ INSERT INTO `menu` VALUES (3, b'0', '角色管理', 'system/role/index', 1, 3, ' ...@@ -257,7 +257,6 @@ INSERT INTO `menu` VALUES (3, b'0', '角色管理', 'system/role/index', 1, 3, '
INSERT INTO `menu` VALUES (5, b'0', '菜单管理', 'system/menu/index', 1, 5, 'menu', 'menu', b'0', b'0', 'Menu', '2018-12-18 15:17:28', 'menu:list', 1); INSERT INTO `menu` VALUES (5, b'0', '菜单管理', 'system/menu/index', 1, 5, 'menu', 'menu', b'0', b'0', 'Menu', '2018-12-18 15:17:28', 'menu:list', 1);
INSERT INTO `menu` VALUES (6, b'0', '系统监控', NULL, 0, 10, 'monitor', 'monitor', b'0', b'0', NULL, '2018-12-18 15:17:48', NULL, 0); INSERT INTO `menu` VALUES (6, b'0', '系统监控', NULL, 0, 10, 'monitor', 'monitor', b'0', b'0', NULL, '2018-12-18 15:17:48', NULL, 0);
INSERT INTO `menu` VALUES (7, b'0', '操作日志', 'monitor/log/index', 6, 11, 'log', 'logs', b'0', b'0', 'Log', '2018-12-18 15:18:26', NULL, 1); INSERT INTO `menu` VALUES (7, b'0', '操作日志', 'monitor/log/index', 6, 11, 'log', 'logs', b'0', b'0', 'Log', '2018-12-18 15:18:26', NULL, 1);
INSERT INTO `menu` VALUES (8, b'0', '系统缓存', 'monitor/redis/index', 6, 15, 'redis', 'redis', b'0', b'0', 'Redis', '2018-12-18 15:19:01', 'redis:list', 1);
INSERT INTO `menu` VALUES (9, b'0', 'SQL监控', 'monitor/sql/index', 6, 18, 'sqlMonitor', 'druid', b'0', b'0', 'Sql', '2018-12-18 15:19:34', NULL, 1); INSERT INTO `menu` VALUES (9, b'0', 'SQL监控', 'monitor/sql/index', 6, 18, 'sqlMonitor', 'druid', b'0', b'0', 'Sql', '2018-12-18 15:19:34', NULL, 1);
INSERT INTO `menu` VALUES (10, b'0', '组件管理', NULL, 0, 50, 'zujian', 'components', b'0', b'0', NULL, '2018-12-19 13:38:16', NULL, 0); INSERT INTO `menu` VALUES (10, b'0', '组件管理', NULL, 0, 50, 'zujian', 'components', b'0', b'0', NULL, '2018-12-19 13:38:16', NULL, 0);
INSERT INTO `menu` VALUES (11, b'0', '图标库', 'components/icons/index', 10, 51, 'icon', 'icon', b'0', b'0', 'Icons', '2018-12-19 13:38:49', NULL, 1); INSERT INTO `menu` VALUES (11, b'0', '图标库', 'components/icons/index', 10, 51, 'icon', 'icon', b'0', b'0', 'Icons', '2018-12-19 13:38:49', NULL, 1);
...@@ -603,7 +602,6 @@ INSERT INTO `roles_menus` VALUES (3, 1); ...@@ -603,7 +602,6 @@ INSERT INTO `roles_menus` VALUES (3, 1);
INSERT INTO `roles_menus` VALUES (5, 1); INSERT INTO `roles_menus` VALUES (5, 1);
INSERT INTO `roles_menus` VALUES (6, 1); INSERT INTO `roles_menus` VALUES (6, 1);
INSERT INTO `roles_menus` VALUES (7, 1); INSERT INTO `roles_menus` VALUES (7, 1);
INSERT INTO `roles_menus` VALUES (8, 1);
INSERT INTO `roles_menus` VALUES (9, 1); INSERT INTO `roles_menus` VALUES (9, 1);
INSERT INTO `roles_menus` VALUES (10, 1); INSERT INTO `roles_menus` VALUES (10, 1);
INSERT INTO `roles_menus` VALUES (11, 1); INSERT INTO `roles_menus` VALUES (11, 1);
...@@ -670,7 +668,6 @@ INSERT INTO `roles_menus` VALUES (2, 2); ...@@ -670,7 +668,6 @@ INSERT INTO `roles_menus` VALUES (2, 2);
INSERT INTO `roles_menus` VALUES (3, 2); INSERT INTO `roles_menus` VALUES (3, 2);
INSERT INTO `roles_menus` VALUES (5, 2); INSERT INTO `roles_menus` VALUES (5, 2);
INSERT INTO `roles_menus` VALUES (6, 2); INSERT INTO `roles_menus` VALUES (6, 2);
INSERT INTO `roles_menus` VALUES (8, 2);
INSERT INTO `roles_menus` VALUES (9, 2); INSERT INTO `roles_menus` VALUES (9, 2);
INSERT INTO `roles_menus` VALUES (10, 2); INSERT INTO `roles_menus` VALUES (10, 2);
INSERT INTO `roles_menus` VALUES (11, 2); INSERT INTO `roles_menus` VALUES (11, 2);
...@@ -728,7 +725,7 @@ CREATE TABLE `user` ( ...@@ -728,7 +725,7 @@ CREATE TABLE `user` (
-- ---------------------------- -- ----------------------------
-- Records of user -- Records of user
-- ---------------------------- -- ----------------------------
INSERT INTO `user` VALUES (1, NULL, 'admin@eladmin.net', 1, 'e10adc3949ba59abbe56e057f20f883e', 'admin', 2, '18888888888', 11, '2018-08-23 09:11:56', '2019-05-18 17:34:21'); INSERT INTO `user` VALUES (1, NULL, 'admin@eladmin.net', 1, '$2a$10$fP.426qKaTmix50Oln8L.uav55gELhAd0Eg66Av4oG86u8km7D/Ky', 'admin', 2, '18888888888', 11, '2018-08-23 09:11:56', '2019-05-18 17:34:21');
INSERT INTO `user` VALUES (3, NULL, 'test@eladmin.net', 1, 'e10adc3949ba59abbe56e057f20f883e', 'test', 2, '17777777777', 12, '2018-12-27 20:05:26', '2019-04-01 09:15:24'); INSERT INTO `user` VALUES (3, NULL, 'test@eladmin.net', 1, 'e10adc3949ba59abbe56e057f20f883e', 'test', 2, '17777777777', 12, '2018-12-27 20:05:26', '2019-04-01 09:15:24');
-- ---------------------------- -- ----------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment