first commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
import com.peanut.modules.book.entity.MyUserEntity;
|
||||
import com.peanut.modules.sys.entity.SysUserTokenEntity;
|
||||
import com.peanut.modules.sys.entity.SysUserEntity;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* shiro相关接口
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface ShiroService {
|
||||
/**
|
||||
* 获取用户权限列表
|
||||
*/
|
||||
Set<String> getUserPermissions(long userId);
|
||||
|
||||
SysUserTokenEntity queryByToken(String token);
|
||||
|
||||
/**
|
||||
* 根据用户ID,查询用户
|
||||
* @param userId
|
||||
*/
|
||||
SysUserEntity queryUser(Long userId);
|
||||
|
||||
/**
|
||||
* 根据app用户ID,查询用户
|
||||
* @param userId
|
||||
*/
|
||||
MyUserEntity queryAppUser(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.sys.entity.SysCaptchaEntity;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface SysCaptchaService extends IService<SysCaptchaEntity> {
|
||||
|
||||
/**
|
||||
* 获取图片验证码
|
||||
*/
|
||||
BufferedImage getCaptcha(String uuid);
|
||||
|
||||
/**
|
||||
* 验证码效验
|
||||
* @param uuid uuid
|
||||
* @param code 验证码
|
||||
* @return true:成功 false:失败
|
||||
*/
|
||||
boolean validate(String uuid, String code);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.sys.entity.SysConfigEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface SysConfigService extends IService<SysConfigEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 保存配置信息
|
||||
*/
|
||||
public void saveConfig(SysConfigEntity config);
|
||||
|
||||
/**
|
||||
* 更新配置信息
|
||||
*/
|
||||
public void update(SysConfigEntity config);
|
||||
|
||||
/**
|
||||
* 根据key,更新value
|
||||
*/
|
||||
public void updateValueByKey(String key, String value);
|
||||
|
||||
/**
|
||||
* 删除配置信息
|
||||
*/
|
||||
public void deleteBatch(Long[] ids);
|
||||
|
||||
/**
|
||||
* 根据key,获取配置的value值
|
||||
*
|
||||
* @param key key
|
||||
*/
|
||||
public String getValue(String key);
|
||||
|
||||
/**
|
||||
* 根据key,获取value的Object对象
|
||||
* @param key key
|
||||
* @param clazz Object对象
|
||||
*/
|
||||
public <T> T getConfigObject(String key, Class<T> clazz);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.book.entity.SysDictDataEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典数据
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-08-04 17:25:02
|
||||
*/
|
||||
public interface SysDictDataService extends IService<SysDictDataEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.sys.entity.SysLogEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface SysLogService extends IService<SysLogEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.sys.entity.SysMenuEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface SysMenuService extends IService<SysMenuEntity> {
|
||||
|
||||
/**
|
||||
* 根据父菜单,查询子菜单
|
||||
* @param parentId 父菜单ID
|
||||
* @param menuIdList 用户菜单ID
|
||||
*/
|
||||
List<SysMenuEntity> queryListParentId(Long parentId, List<Long> menuIdList);
|
||||
|
||||
/**
|
||||
* 根据父菜单,查询子菜单
|
||||
* @param parentId 父菜单ID
|
||||
*/
|
||||
List<SysMenuEntity> queryListParentId(Long parentId);
|
||||
|
||||
/**
|
||||
* 获取不包含按钮的菜单列表
|
||||
*/
|
||||
List<SysMenuEntity> queryNotButtonList();
|
||||
|
||||
/**
|
||||
* 获取用户菜单列表
|
||||
*/
|
||||
List<SysMenuEntity> getUserMenuList(Long userId);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
void delete(Long menuId);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.sys.entity.SysRoleMenuEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 角色与菜单对应关系
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface SysRoleMenuService extends IService<SysRoleMenuEntity> {
|
||||
|
||||
void saveOrUpdate(Long roleId, List<Long> menuIdList);
|
||||
|
||||
/**
|
||||
* 根据角色ID,获取菜单ID列表
|
||||
*/
|
||||
List<Long> queryMenuIdList(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据角色ID数组,批量删除
|
||||
*/
|
||||
int deleteBatch(Long[] roleIds);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.sys.entity.SysRoleEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface SysRoleService extends IService<SysRoleEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
void saveRole(SysRoleEntity role);
|
||||
|
||||
void update(SysRoleEntity role);
|
||||
|
||||
void deleteBatch(Long[] roleIds);
|
||||
|
||||
|
||||
/**
|
||||
* 查询用户创建的角色ID列表
|
||||
*/
|
||||
List<Long> queryRoleIdList(Long createUserId);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.sys.entity.SysUserRoleEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户与角色对应关系
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface SysUserRoleService extends IService<SysUserRoleEntity> {
|
||||
|
||||
void saveOrUpdate(Long userId, List<Long> roleIdList);
|
||||
|
||||
/**
|
||||
* 根据用户ID,获取角色ID列表
|
||||
*/
|
||||
List<Long> queryRoleIdList(Long userId);
|
||||
|
||||
/**
|
||||
* 根据角色ID数组,批量删除
|
||||
*/
|
||||
int deleteBatch(Long[] roleIds);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.sys.entity.SysUserEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface SysUserService extends IService<SysUserEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 查询用户的所有权限
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
List<String> queryAllPerms(Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户的所有菜单ID
|
||||
*/
|
||||
List<Long> queryAllMenuId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户名,查询系统用户
|
||||
*/
|
||||
SysUserEntity queryByUserName(String username);
|
||||
|
||||
/**
|
||||
* 保存用户
|
||||
*/
|
||||
void saveUser(SysUserEntity user);
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
void update(SysUserEntity user);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
void deleteBatch(Long[] userIds);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param userId 用户ID
|
||||
* @param password 原密码
|
||||
* @param newPassword 新密码
|
||||
*/
|
||||
boolean updatePassword(Long userId, String password, String newPassword);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.sys.entity.SysUserTokenEntity;
|
||||
|
||||
/**
|
||||
* 用户Token
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public interface SysUserTokenService extends IService<SysUserTokenEntity> {
|
||||
|
||||
/**
|
||||
* 生成token
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
R createToken(long userId);
|
||||
|
||||
/**
|
||||
* 退出,修改token值
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
void logout(long userId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
import com.peanut.common.utils.Constant;
|
||||
import com.peanut.modules.book.entity.MyUserEntity;
|
||||
import com.peanut.modules.book.service.MyUserService;
|
||||
import com.peanut.modules.sys.dao.SysMenuDao;
|
||||
import com.peanut.modules.sys.dao.SysUserDao;
|
||||
import com.peanut.modules.sys.dao.SysUserTokenDao;
|
||||
import com.peanut.modules.sys.entity.SysMenuEntity;
|
||||
import com.peanut.modules.sys.entity.SysUserTokenEntity;
|
||||
import com.peanut.modules.sys.service.ShiroService;
|
||||
import com.peanut.modules.sys.entity.SysUserEntity;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class ShiroServiceImpl implements ShiroService {
|
||||
@Autowired
|
||||
private SysMenuDao sysMenuDao;
|
||||
@Autowired
|
||||
private SysUserDao sysUserDao;
|
||||
@Autowired
|
||||
private SysUserTokenDao sysUserTokenDao;
|
||||
@Autowired
|
||||
private MyUserService myUserService;
|
||||
|
||||
@Override
|
||||
public Set<String> getUserPermissions(long userId) {
|
||||
List<String> permsList;
|
||||
|
||||
//系统管理员,拥有最高权限
|
||||
if(userId == Constant.SUPER_ADMIN){
|
||||
List<SysMenuEntity> menuList = sysMenuDao.selectList(null);
|
||||
permsList = new ArrayList<>(menuList.size());
|
||||
for(SysMenuEntity menu : menuList){
|
||||
permsList.add(menu.getPerms());
|
||||
}
|
||||
}else{
|
||||
permsList = sysUserDao.queryAllPerms(userId);
|
||||
}
|
||||
//用户权限列表
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for(String perms : permsList){
|
||||
if(StringUtils.isBlank(perms)){
|
||||
continue;
|
||||
}
|
||||
permsSet.addAll(Arrays.asList(perms.trim().split(",")));
|
||||
}
|
||||
return permsSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserTokenEntity queryByToken(String token) {
|
||||
return sysUserTokenDao.queryByToken(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserEntity queryUser(Long userId) {
|
||||
return sysUserDao.selectById(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyUserEntity queryAppUser(Long userId) {
|
||||
return myUserService.getBaseMapper().selectById(userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.code.kaptcha.Producer;
|
||||
import com.peanut.common.exception.RRException;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.modules.sys.dao.SysCaptchaDao;
|
||||
import com.peanut.modules.sys.service.SysCaptchaService;
|
||||
import com.peanut.modules.sys.entity.SysCaptchaEntity;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Service("sysCaptchaService")
|
||||
public class SysCaptchaServiceImpl extends ServiceImpl<SysCaptchaDao, SysCaptchaEntity> implements SysCaptchaService {
|
||||
@Autowired
|
||||
private Producer producer;
|
||||
|
||||
@Override
|
||||
public BufferedImage getCaptcha(String uuid) {
|
||||
if(StringUtils.isBlank(uuid)){
|
||||
throw new RRException("uuid不能为空");
|
||||
}
|
||||
//生成文字验证码
|
||||
String code = producer.createText();
|
||||
|
||||
SysCaptchaEntity captchaEntity = new SysCaptchaEntity();
|
||||
captchaEntity.setUuid(uuid);
|
||||
captchaEntity.setCode(code);
|
||||
//5分钟后过期
|
||||
captchaEntity.setExpireTime(DateUtils.addDateMinutes(new Date(), 5));
|
||||
this.save(captchaEntity);
|
||||
|
||||
return producer.createImage(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate(String uuid, String code) {
|
||||
SysCaptchaEntity captchaEntity = this.getOne(new QueryWrapper<SysCaptchaEntity>().eq("uuid", uuid));
|
||||
if(captchaEntity == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
//删除验证码
|
||||
this.removeById(uuid);
|
||||
|
||||
if(captchaEntity.getCode().equalsIgnoreCase(code) && captchaEntity.getExpireTime().getTime() >= System.currentTimeMillis()){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.gson.Gson;
|
||||
import com.peanut.common.exception.RRException;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
import com.peanut.modules.sys.dao.SysConfigDao;
|
||||
import com.peanut.modules.sys.redis.SysConfigRedis;
|
||||
import com.peanut.modules.sys.entity.SysConfigEntity;
|
||||
import com.peanut.modules.sys.service.SysConfigService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("sysConfigService")
|
||||
public class SysConfigServiceImpl extends ServiceImpl<SysConfigDao, SysConfigEntity> implements SysConfigService {
|
||||
@Autowired
|
||||
private SysConfigRedis sysConfigRedis;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String paramKey = (String)params.get("paramKey");
|
||||
|
||||
IPage<SysConfigEntity> page = this.page(
|
||||
new Query<SysConfigEntity>().getPage(params),
|
||||
new QueryWrapper<SysConfigEntity>()
|
||||
.like(StringUtils.isNotBlank(paramKey),"param_key", paramKey)
|
||||
.eq("status", 1)
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig(SysConfigEntity config) {
|
||||
this.save(config);
|
||||
sysConfigRedis.saveOrUpdate(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(SysConfigEntity config) {
|
||||
this.updateById(config);
|
||||
sysConfigRedis.saveOrUpdate(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateValueByKey(String key, String value) {
|
||||
baseMapper.updateValueByKey(key, value);
|
||||
sysConfigRedis.delete(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteBatch(Long[] ids) {
|
||||
for(Long id : ids){
|
||||
SysConfigEntity config = this.getById(id);
|
||||
sysConfigRedis.delete(config.getParamKey());
|
||||
}
|
||||
|
||||
this.removeByIds(Arrays.asList(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String key) {
|
||||
SysConfigEntity config = sysConfigRedis.get(key);
|
||||
if(config == null){
|
||||
config = baseMapper.queryByKey(key);
|
||||
sysConfigRedis.saveOrUpdate(config);
|
||||
}
|
||||
|
||||
return config == null ? null : config.getParamValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getConfigObject(String key, Class<T> clazz) {
|
||||
String value = getValue(key);
|
||||
if(StringUtils.isNotBlank(value)){
|
||||
return new Gson().fromJson(value, clazz);
|
||||
}
|
||||
|
||||
try {
|
||||
return clazz.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RRException("获取参数失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
import com.peanut.modules.sys.service.SysDictDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
|
||||
import com.peanut.modules.book.dao.SysDictDataDao;
|
||||
import com.peanut.modules.book.entity.SysDictDataEntity;
|
||||
|
||||
|
||||
@Service("sysDictDataService")
|
||||
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataDao, SysDictDataEntity> implements SysDictDataService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
IPage<SysDictDataEntity> page = this.page(
|
||||
new Query<SysDictDataEntity>().getPage(params),
|
||||
new QueryWrapper<SysDictDataEntity>()
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
import com.peanut.modules.sys.dao.SysLogDao;
|
||||
import com.peanut.modules.sys.service.SysLogService;
|
||||
import com.peanut.modules.sys.entity.SysLogEntity;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service("sysLogService")
|
||||
public class SysLogServiceImpl extends ServiceImpl<SysLogDao, SysLogEntity> implements SysLogService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String key = (String)params.get("key");
|
||||
|
||||
IPage<SysLogEntity> page = this.page(
|
||||
new Query<SysLogEntity>().getPage(params),
|
||||
new QueryWrapper<SysLogEntity>().like(StringUtils.isNotBlank(key),"username", key)
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.Constant;
|
||||
import com.peanut.common.utils.MapUtils;
|
||||
import com.peanut.modules.sys.dao.SysMenuDao;
|
||||
import com.peanut.modules.sys.entity.SysMenuEntity;
|
||||
import com.peanut.modules.sys.service.SysMenuService;
|
||||
import com.peanut.modules.sys.service.SysRoleMenuService;
|
||||
import com.peanut.modules.sys.service.SysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Service("sysMenuService")
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao, SysMenuEntity> implements SysMenuService {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
|
||||
@Override
|
||||
public List<SysMenuEntity> queryListParentId(Long parentId, List<Long> menuIdList) {
|
||||
List<SysMenuEntity> menuList = queryListParentId(parentId);
|
||||
if(menuIdList == null){
|
||||
return menuList;
|
||||
}
|
||||
|
||||
List<SysMenuEntity> userMenuList = new ArrayList<>();
|
||||
for(SysMenuEntity menu : menuList){
|
||||
if(menuIdList.contains(menu.getMenuId())){
|
||||
userMenuList.add(menu);
|
||||
}
|
||||
}
|
||||
return userMenuList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuEntity> queryListParentId(Long parentId) {
|
||||
return baseMapper.queryListParentId(parentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuEntity> queryNotButtonList() {
|
||||
return baseMapper.queryNotButtonList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuEntity> getUserMenuList(Long userId) {
|
||||
//系统管理员,拥有最高权限
|
||||
if(userId == Constant.SUPER_ADMIN){
|
||||
return getMenuList(null);
|
||||
}
|
||||
|
||||
//用户菜单列表
|
||||
List<Long> menuIdList = sysUserService.queryAllMenuId(userId);
|
||||
return getMenuList(menuIdList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取拥有的菜单列表
|
||||
* @param menuIdList
|
||||
* @return
|
||||
*/
|
||||
private List<SysMenuEntity> getMenuList(List<Long> menuIdList) {
|
||||
// 查询拥有的所有菜单
|
||||
List<SysMenuEntity> menus = this.baseMapper.selectList(new QueryWrapper<SysMenuEntity>()
|
||||
.in(Objects.nonNull(menuIdList), "menu_id", menuIdList).in("type", 0, 1));
|
||||
// 将id和菜单绑定
|
||||
HashMap<Long, SysMenuEntity> menuMap = new HashMap<>(12);
|
||||
for (SysMenuEntity s : menus) {
|
||||
menuMap.put(s.getMenuId(), s);
|
||||
}
|
||||
// 使用迭代器,组装菜单的层级关系
|
||||
Iterator<SysMenuEntity> iterator = menus.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
SysMenuEntity menu = iterator.next();
|
||||
SysMenuEntity parent = menuMap.get(menu.getParentId());
|
||||
if (Objects.nonNull(parent)) {
|
||||
parent.getList().add(menu);
|
||||
// 将这个菜单从当前节点移除
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return menus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long menuId){
|
||||
//删除菜单
|
||||
this.removeById(menuId);
|
||||
//删除菜单与角色关联
|
||||
sysRoleMenuService.removeByMap(new MapUtils().put("menu_id", menuId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有菜单列表
|
||||
*/
|
||||
private List<SysMenuEntity> getAllMenuList(List<Long> menuIdList){
|
||||
//查询根菜单列表
|
||||
List<SysMenuEntity> menuList = queryListParentId(0L, menuIdList);
|
||||
//递归获取子菜单
|
||||
getMenuTreeList(menuList, menuIdList);
|
||||
|
||||
return menuList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归
|
||||
*/
|
||||
private List<SysMenuEntity> getMenuTreeList(List<SysMenuEntity> menuList, List<Long> menuIdList){
|
||||
List<SysMenuEntity> subMenuList = new ArrayList<SysMenuEntity>();
|
||||
|
||||
for(SysMenuEntity entity : menuList){
|
||||
//目录
|
||||
if(entity.getType() == Constant.MenuType.CATALOG.getValue()){
|
||||
entity.setList(getMenuTreeList(queryListParentId(entity.getMenuId(), menuIdList), menuIdList));
|
||||
}
|
||||
subMenuList.add(entity);
|
||||
}
|
||||
|
||||
return subMenuList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.modules.sys.dao.SysRoleMenuDao;
|
||||
import com.peanut.modules.sys.entity.SysRoleMenuEntity;
|
||||
import com.peanut.modules.sys.service.SysRoleMenuService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 角色与菜单对应关系
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Service("sysRoleMenuService")
|
||||
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuDao, SysRoleMenuEntity> implements SysRoleMenuService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdate(Long roleId, List<Long> menuIdList) {
|
||||
//先删除角色与菜单关系
|
||||
deleteBatch(new Long[]{roleId});
|
||||
|
||||
if(menuIdList.size() == 0){
|
||||
return ;
|
||||
}
|
||||
|
||||
//保存角色与菜单关系
|
||||
for(Long menuId : menuIdList){
|
||||
SysRoleMenuEntity sysRoleMenuEntity = new SysRoleMenuEntity();
|
||||
sysRoleMenuEntity.setMenuId(menuId);
|
||||
sysRoleMenuEntity.setRoleId(roleId);
|
||||
|
||||
this.save(sysRoleMenuEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> queryMenuIdList(Long roleId) {
|
||||
return baseMapper.queryMenuIdList(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBatch(Long[] roleIds){
|
||||
return baseMapper.deleteBatch(roleIds);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.exception.RRException;
|
||||
import com.peanut.common.utils.Constant;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
import com.peanut.modules.sys.dao.SysRoleDao;
|
||||
import com.peanut.modules.sys.dao.SysUserDao;
|
||||
import com.peanut.modules.sys.service.SysRoleMenuService;
|
||||
import com.peanut.modules.sys.entity.SysRoleEntity;
|
||||
import com.peanut.modules.sys.service.SysRoleService;
|
||||
import com.peanut.modules.sys.service.SysUserRoleService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Service("sysRoleService")
|
||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleDao, SysRoleEntity> implements SysRoleService {
|
||||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
@Autowired
|
||||
private SysUserDao sysUserDao;
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String roleName = (String)params.get("roleName");
|
||||
Long createUserId = (Long)params.get("createUserId");
|
||||
|
||||
IPage<SysRoleEntity> page = this.page(
|
||||
new Query<SysRoleEntity>().getPage(params),
|
||||
new QueryWrapper<SysRoleEntity>()
|
||||
.like(StringUtils.isNotBlank(roleName),"role_name", roleName)
|
||||
.eq(createUserId != null,"create_user_id", createUserId)
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveRole(SysRoleEntity role) {
|
||||
role.setCreateTime(new Date());
|
||||
this.save(role);
|
||||
|
||||
//检查权限是否越权
|
||||
checkPrems(role);
|
||||
|
||||
//保存角色与菜单关系
|
||||
sysRoleMenuService.saveOrUpdate(role.getRoleId(), role.getMenuIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(SysRoleEntity role) {
|
||||
this.updateById(role);
|
||||
|
||||
//检查权限是否越权
|
||||
checkPrems(role);
|
||||
|
||||
//更新角色与菜单关系
|
||||
sysRoleMenuService.saveOrUpdate(role.getRoleId(), role.getMenuIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteBatch(Long[] roleIds) {
|
||||
//删除角色
|
||||
this.removeByIds(Arrays.asList(roleIds));
|
||||
|
||||
//删除角色与菜单关联
|
||||
sysRoleMenuService.deleteBatch(roleIds);
|
||||
|
||||
//删除角色与用户关联
|
||||
sysUserRoleService.deleteBatch(roleIds);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Long> queryRoleIdList(Long createUserId) {
|
||||
return baseMapper.queryRoleIdList(createUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查权限是否越权
|
||||
*/
|
||||
private void checkPrems(SysRoleEntity role){
|
||||
//如果不是超级管理员,则需要判断角色的权限是否超过自己的权限
|
||||
if(role.getCreateUserId() == Constant.SUPER_ADMIN){
|
||||
return ;
|
||||
}
|
||||
|
||||
//查询用户所拥有的菜单列表
|
||||
List<Long> menuIdList = sysUserDao.queryAllMenuId(role.getCreateUserId());
|
||||
|
||||
//判断是否越权
|
||||
if(!menuIdList.containsAll(role.getMenuIdList())){
|
||||
throw new RRException("新增角色的权限,已超出你的权限范围");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.MapUtils;
|
||||
import com.peanut.modules.sys.dao.SysUserRoleDao;
|
||||
import com.peanut.modules.sys.entity.SysUserRoleEntity;
|
||||
import com.peanut.modules.sys.service.SysUserRoleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户与角色对应关系
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Service("sysUserRoleService")
|
||||
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleDao, SysUserRoleEntity> implements SysUserRoleService {
|
||||
|
||||
@Override
|
||||
public void saveOrUpdate(Long userId, List<Long> roleIdList) {
|
||||
//先删除用户与角色关系
|
||||
this.removeByMap(new MapUtils().put("user_id", userId));
|
||||
|
||||
if(roleIdList == null || roleIdList.size() == 0){
|
||||
return ;
|
||||
}
|
||||
|
||||
//保存用户与角色关系
|
||||
for(Long roleId : roleIdList){
|
||||
SysUserRoleEntity sysUserRoleEntity = new SysUserRoleEntity();
|
||||
sysUserRoleEntity.setUserId(userId);
|
||||
sysUserRoleEntity.setRoleId(roleId);
|
||||
|
||||
this.save(sysUserRoleEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> queryRoleIdList(Long userId) {
|
||||
return baseMapper.queryRoleIdList(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBatch(Long[] roleIds){
|
||||
return baseMapper.deleteBatch(roleIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.exception.RRException;
|
||||
import com.peanut.common.utils.Constant;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
import com.peanut.modules.sys.dao.SysUserDao;
|
||||
import com.peanut.modules.sys.entity.SysUserEntity;
|
||||
import com.peanut.modules.sys.service.SysRoleService;
|
||||
import com.peanut.modules.sys.service.SysUserRoleService;
|
||||
import com.peanut.modules.sys.service.SysUserService;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Service("sysUserService")
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String username = (String)params.get("username");
|
||||
Long createUserId = (Long)params.get("createUserId");
|
||||
|
||||
IPage<SysUserEntity> page = this.page(
|
||||
new Query<SysUserEntity>().getPage(params),
|
||||
new QueryWrapper<SysUserEntity>()
|
||||
.like(StringUtils.isNotBlank(username),"username", username)
|
||||
.eq(createUserId != null,"create_user_id", createUserId)
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryAllPerms(Long userId) {
|
||||
return baseMapper.queryAllPerms(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> queryAllMenuId(Long userId) {
|
||||
return baseMapper.queryAllMenuId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserEntity queryByUserName(String username) {
|
||||
return baseMapper.queryByUserName(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveUser(SysUserEntity user) {
|
||||
user.setCreateTime(new Date());
|
||||
//sha256加密
|
||||
String salt = RandomStringUtils.randomAlphanumeric(20);
|
||||
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
|
||||
user.setSalt(salt);
|
||||
this.save(user);
|
||||
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
|
||||
//保存用户与角色关系
|
||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void update(SysUserEntity user) {
|
||||
if(StringUtils.isBlank(user.getPassword())){
|
||||
user.setPassword(null);
|
||||
}else{
|
||||
user.setPassword(new Sha256Hash(user.getPassword(), user.getSalt()).toHex());
|
||||
}
|
||||
this.updateById(user);
|
||||
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
|
||||
//保存用户与角色关系
|
||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBatch(Long[] userId) {
|
||||
this.removeByIds(Arrays.asList(userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePassword(Long userId, String password, String newPassword) {
|
||||
SysUserEntity userEntity = new SysUserEntity();
|
||||
userEntity.setPassword(newPassword);
|
||||
return this.update(userEntity,
|
||||
new QueryWrapper<SysUserEntity>().eq("user_id", userId).eq("password", password));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查角色是否越权
|
||||
*/
|
||||
private void checkRole(SysUserEntity user){
|
||||
if(user.getRoleIdList() == null || user.getRoleIdList().size() == 0){
|
||||
return;
|
||||
}
|
||||
//如果不是超级管理员,则需要判断用户的角色是否自己创建
|
||||
if(user.getCreateUserId() == Constant.SUPER_ADMIN){
|
||||
return ;
|
||||
}
|
||||
|
||||
//查询用户创建的角色列表
|
||||
List<Long> roleIdList = sysRoleService.queryRoleIdList(user.getCreateUserId());
|
||||
|
||||
//判断是否越权
|
||||
if(!roleIdList.containsAll(user.getRoleIdList())){
|
||||
throw new RRException("新增用户所选角色,不是本人创建");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.sys.dao.SysUserTokenDao;
|
||||
import com.peanut.modules.sys.entity.SysUserTokenEntity;
|
||||
import com.peanut.modules.sys.oauth2.TokenGenerator;
|
||||
import com.peanut.modules.sys.service.SysUserTokenService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Service("sysUserTokenService")
|
||||
public class SysUserTokenServiceImpl extends ServiceImpl<SysUserTokenDao, SysUserTokenEntity> implements SysUserTokenService {
|
||||
//10天后过期
|
||||
private final static int EXPIRE = 3600 * 12 * 10;
|
||||
|
||||
|
||||
@Override
|
||||
public R createToken(long userId) {
|
||||
//生成一个token
|
||||
String token = TokenGenerator.generateValue();
|
||||
|
||||
//当前时间
|
||||
Date now = new Date();
|
||||
//过期时间
|
||||
Date expireTime = new Date(now.getTime() + EXPIRE * 1000);
|
||||
|
||||
//判断是否生成过token
|
||||
SysUserTokenEntity tokenEntity = this.getById(userId);
|
||||
if(tokenEntity == null){
|
||||
tokenEntity = new SysUserTokenEntity();
|
||||
tokenEntity.setUserId(userId);
|
||||
tokenEntity.setToken(token);
|
||||
tokenEntity.setUpdateTime(now);
|
||||
tokenEntity.setExpireTime(expireTime);
|
||||
|
||||
//保存token
|
||||
this.save(tokenEntity);
|
||||
}else{
|
||||
tokenEntity.setToken(token);
|
||||
tokenEntity.setUpdateTime(now);
|
||||
tokenEntity.setExpireTime(expireTime);
|
||||
|
||||
//更新token
|
||||
this.updateById(tokenEntity);
|
||||
}
|
||||
|
||||
R r = R.ok().put("token", token).put("expire", EXPIRE);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout(long userId) {
|
||||
//生成一个token
|
||||
String token = TokenGenerator.generateValue();
|
||||
|
||||
//修改token
|
||||
SysUserTokenEntity tokenEntity = new SysUserTokenEntity();
|
||||
tokenEntity.setUserId(userId);
|
||||
tokenEntity.setToken(token);
|
||||
this.updateById(tokenEntity);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user