first commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.sqx.modules.sys.controller;
|
||||
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Controller公共组件
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractController {
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected SysUserEntity getUser() {
|
||||
return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
|
||||
}
|
||||
|
||||
protected Long getUserId() {
|
||||
return getUser().getUserId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.sqx.modules.sys.controller;
|
||||
|
||||
|
||||
import com.sqx.common.annotation.SysLog;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.common.validator.ValidatorUtils;
|
||||
import com.sqx.modules.sys.entity.SysConfigEntity;
|
||||
import com.sqx.modules.sys.service.SysConfigService;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/config")
|
||||
public class SysConfigController extends AbstractController {
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
/**
|
||||
* 所有配置列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:config:list")
|
||||
public Result list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = sysConfigService.queryPage(params);
|
||||
|
||||
return Result.success().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置信息
|
||||
*/
|
||||
@GetMapping("/info/{id}")
|
||||
@RequiresPermissions("sys:config:info")
|
||||
public Result info(@PathVariable("id") Long id){
|
||||
SysConfigEntity config = sysConfigService.getById(id);
|
||||
|
||||
return Result.success().put("config", config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置
|
||||
*/
|
||||
@SysLog("保存配置")
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("sys:config:save")
|
||||
public Result save(@RequestBody SysConfigEntity config){
|
||||
ValidatorUtils.validateEntity(config);
|
||||
|
||||
sysConfigService.saveConfig(config);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改配置
|
||||
*/
|
||||
@SysLog("修改配置")
|
||||
@PostMapping("/update")
|
||||
@RequiresPermissions("sys:config:update")
|
||||
public Result update(@RequestBody SysConfigEntity config){
|
||||
ValidatorUtils.validateEntity(config);
|
||||
|
||||
sysConfigService.update(config);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除配置
|
||||
*/
|
||||
@SysLog("删除配置")
|
||||
@PostMapping("/delete")
|
||||
@RequiresPermissions("sys:config:delete")
|
||||
public Result delete(@RequestBody Long[] ids){
|
||||
sysConfigService.deleteBatch(ids);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.sqx.modules.sys.controller;
|
||||
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.common.validator.ValidatorUtils;
|
||||
import com.sqx.modules.sys.entity.SysDictEntity;
|
||||
import com.sqx.modules.sys.service.SysDictService;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("sys/dict")
|
||||
public class SysDictController {
|
||||
@Autowired
|
||||
private SysDictService sysDictService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
@RequiresPermissions("sys:dict:list")
|
||||
public Result list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = sysDictService.queryPage(params);
|
||||
|
||||
return Result.success().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
@RequiresPermissions("sys:dict:info")
|
||||
public Result info(@PathVariable("id") Long id){
|
||||
SysDictEntity dict = sysDictService.getById(id);
|
||||
|
||||
return Result.success().put("dict", dict);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
@RequiresPermissions("sys:dict:save")
|
||||
public Result save(@RequestBody SysDictEntity dict){
|
||||
//校验类型
|
||||
ValidatorUtils.validateEntity(dict);
|
||||
|
||||
sysDictService.save(dict);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
@RequiresPermissions("sys:dict:update")
|
||||
public Result update(@RequestBody SysDictEntity dict){
|
||||
//校验类型
|
||||
ValidatorUtils.validateEntity(dict);
|
||||
|
||||
sysDictService.updateById(dict);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
@RequiresPermissions("sys:dict:delete")
|
||||
public Result delete(@RequestBody Long[] ids){
|
||||
sysDictService.removeByIds(Arrays.asList(ids));
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.sqx.modules.sys.controller;
|
||||
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.sys.service.SysLogService;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/sys/log")
|
||||
public class SysLogController {
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:log:list")
|
||||
public Result list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = sysLogService.queryPage(params);
|
||||
|
||||
return Result.success().put("page", page);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.sqx.modules.sys.controller;
|
||||
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import com.sqx.modules.sys.form.SysLoginForm;
|
||||
import com.sqx.modules.sys.service.SysCaptchaService;
|
||||
import com.sqx.modules.sys.service.SysUserService;
|
||||
import com.sqx.modules.sys.service.SysUserTokenService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 登录相关
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
public class SysLoginController extends AbstractController {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysUserTokenService sysUserTokenService;
|
||||
@Autowired
|
||||
private SysCaptchaService sysCaptchaService;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
@GetMapping("captcha.jpg")
|
||||
public void captcha(HttpServletResponse response, String uuid)throws IOException {
|
||||
response.setHeader("Cache-Control", "no-store, no-cache");
|
||||
response.setContentType("image/jpeg");
|
||||
|
||||
//获取图片验证码
|
||||
BufferedImage image = sysCaptchaService.getCaptcha(uuid);
|
||||
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
ImageIO.write(image, "jpg", out);
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@PostMapping("/sys/login")
|
||||
public Map<String, Object> login(@RequestBody SysLoginForm form)throws IOException {
|
||||
boolean captcha = sysCaptchaService.validate(form.getUuid(), form.getCaptcha());
|
||||
if(!captcha){
|
||||
return Result.error("验证码不正确");
|
||||
}
|
||||
|
||||
//用户信息
|
||||
SysUserEntity user = sysUserService.queryByUserName(form.getUsername());
|
||||
|
||||
//账号不存在、密码错误
|
||||
if(user == null || !user.getPassword().equals(new Sha256Hash(form.getPassword(), user.getSalt()).toHex())) {
|
||||
return Result.error("账号或密码不正确");
|
||||
}
|
||||
|
||||
//账号锁定
|
||||
if(user.getStatus() == 0){
|
||||
return Result.error("账号已被锁定,请联系管理员");
|
||||
}
|
||||
|
||||
//判断角色类型
|
||||
if(form.getAdminType()==1 && user.getIsChannel()!=null && user.getIsChannel()==1){
|
||||
return Result.error("代理账号请登录代理端!");
|
||||
}else if(form.getAdminType()==2 && user.getIsChannel()==null){
|
||||
return Result.error("管理员请登录管理端!");
|
||||
}
|
||||
|
||||
//生成token,并保存到数据库
|
||||
Result r = sysUserTokenService.createToken(user.getUserId());
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出
|
||||
*/
|
||||
@PostMapping("/sys/logout")
|
||||
public Result logout() {
|
||||
sysUserTokenService.logout(getUserId());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package com.sqx.modules.sys.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.sqx.common.annotation.SysLog;
|
||||
import com.sqx.common.exception.SqxException;
|
||||
import com.sqx.common.utils.Constant;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.sys.entity.SysMenuEntity;
|
||||
import com.sqx.modules.sys.service.ShiroService;
|
||||
import com.sqx.modules.sys.service.SysMenuService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 系统菜单
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/menu")
|
||||
public class SysMenuController extends AbstractController {
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private ShiroService shiroService;
|
||||
|
||||
/**
|
||||
* 导航菜单
|
||||
*/
|
||||
@GetMapping("/nav")
|
||||
public Result nav(){
|
||||
List<SysMenuEntity> menuList = sysMenuService.getUserMenuList(getUserId());
|
||||
Set<String> permissions = shiroService.getUserPermissions(getUserId());
|
||||
return Result.success().put("menuList", menuList).put("permissions", permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有菜单列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:menu:list")
|
||||
public List<SysMenuEntity> list(){
|
||||
List<SysMenuEntity> menuList = sysMenuService.list(new QueryWrapper<SysMenuEntity>().orderByAsc("order_num"));
|
||||
for(SysMenuEntity sysMenuEntity : menuList){
|
||||
SysMenuEntity parentMenuEntity = sysMenuService.getById(sysMenuEntity.getParentId());
|
||||
if(parentMenuEntity != null){
|
||||
sysMenuEntity.setParentName(parentMenuEntity.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return menuList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择菜单(添加、修改菜单)
|
||||
*/
|
||||
@GetMapping("/select")
|
||||
@RequiresPermissions("sys:menu:select")
|
||||
public Result select(){
|
||||
//查询列表数据
|
||||
List<SysMenuEntity> menuList = sysMenuService.queryNotButtonList();
|
||||
|
||||
//添加顶级菜单
|
||||
SysMenuEntity root = new SysMenuEntity();
|
||||
root.setMenuId(0L);
|
||||
root.setName("一级菜单");
|
||||
root.setParentId(-1L);
|
||||
root.setOpen(true);
|
||||
menuList.add(root);
|
||||
|
||||
return Result.success().put("menuList", menuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单信息
|
||||
*/
|
||||
@GetMapping("/info/{menuId}")
|
||||
@RequiresPermissions("sys:menu:info")
|
||||
public Result info(@PathVariable("menuId") Long menuId){
|
||||
SysMenuEntity menu = sysMenuService.getById(menuId);
|
||||
return Result.success().put("menu", menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@SysLog("保存菜单")
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("sys:menu:save")
|
||||
public Result save(@RequestBody SysMenuEntity menu){
|
||||
//数据校验
|
||||
verifyForm(menu);
|
||||
|
||||
sysMenuService.save(menu);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@SysLog("修改菜单")
|
||||
@PostMapping("/update")
|
||||
@RequiresPermissions("sys:menu:update")
|
||||
public Result update(@RequestBody SysMenuEntity menu){
|
||||
//数据校验
|
||||
verifyForm(menu);
|
||||
|
||||
sysMenuService.updateById(menu);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@SysLog("删除菜单")
|
||||
@PostMapping("/delete/{menuId}")
|
||||
@RequiresPermissions("sys:menu:delete")
|
||||
public Result delete(@PathVariable("menuId") long menuId){
|
||||
if(menuId <= 31){
|
||||
return Result.error("系统菜单,不能删除");
|
||||
}
|
||||
|
||||
//判断是否有子菜单或按钮
|
||||
List<SysMenuEntity> menuList = sysMenuService.queryListParentId(menuId);
|
||||
if(menuList.size() > 0){
|
||||
return Result.error("请先删除子菜单或按钮");
|
||||
}
|
||||
|
||||
sysMenuService.delete(menuId);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证参数是否正确
|
||||
*/
|
||||
private void verifyForm(SysMenuEntity menu){
|
||||
if(StringUtils.isBlank(menu.getName())){
|
||||
throw new SqxException("菜单名称不能为空");
|
||||
}
|
||||
|
||||
if(menu.getParentId() == null){
|
||||
throw new SqxException("上级菜单不能为空");
|
||||
}
|
||||
|
||||
//菜单
|
||||
if(menu.getType() == Constant.MenuType.MENU.getValue()){
|
||||
if(StringUtils.isBlank(menu.getUrl())){
|
||||
throw new SqxException("菜单URL不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
//上级菜单类型
|
||||
int parentType = Constant.MenuType.CATALOG.getValue();
|
||||
if(menu.getParentId() != 0){
|
||||
SysMenuEntity parentMenu = sysMenuService.getById(menu.getParentId());
|
||||
parentType = parentMenu.getType();
|
||||
}
|
||||
|
||||
//目录、菜单
|
||||
if(menu.getType() == Constant.MenuType.CATALOG.getValue() ||
|
||||
menu.getType() == Constant.MenuType.MENU.getValue()){
|
||||
if(parentType != Constant.MenuType.CATALOG.getValue()){
|
||||
throw new SqxException("上级菜单只能为目录类型");
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
//按钮
|
||||
if(menu.getType() == Constant.MenuType.BUTTON.getValue()){
|
||||
if(parentType != Constant.MenuType.MENU.getValue()){
|
||||
throw new SqxException("上级菜单只能为菜单类型");
|
||||
}
|
||||
return ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.sqx.modules.sys.controller;
|
||||
|
||||
import com.sqx.common.annotation.SysLog;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.common.validator.ValidatorUtils;
|
||||
import com.sqx.modules.sys.entity.SysRoleEntity;
|
||||
import com.sqx.modules.sys.service.SysRoleMenuService;
|
||||
import com.sqx.modules.sys.service.SysRoleService;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 角色管理
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/role")
|
||||
public class SysRoleController extends AbstractController {
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:role:list")
|
||||
public Result list(@RequestParam Map<String, Object> params){
|
||||
//如果不是超级管理员,则只查询自己创建的角色列表
|
||||
/*if(getUserId() != Constant.SUPER_ADMIN){
|
||||
params.put("createUserId", getUserId());
|
||||
}*/
|
||||
PageUtils page = sysRoleService.queryPage(params);
|
||||
return Result.success().put("page", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
@GetMapping("/select")
|
||||
@RequiresPermissions("sys:role:select")
|
||||
public Result select(){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
//如果不是超级管理员,则只查询自己所拥有的角色列表
|
||||
/*if(getUserId() != Constant.SUPER_ADMIN){
|
||||
map.put("create_user_id", getUserId());
|
||||
}*/
|
||||
List<SysRoleEntity> list = (List<SysRoleEntity>) sysRoleService.listByMap(map);
|
||||
|
||||
return Result.success().put("list", list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色信息
|
||||
*/
|
||||
@GetMapping("/info/{roleId}")
|
||||
@RequiresPermissions("sys:role:info")
|
||||
public Result info(@PathVariable("roleId") Long roleId){
|
||||
SysRoleEntity role = sysRoleService.getById(roleId);
|
||||
|
||||
//查询角色对应的菜单
|
||||
List<Long> menuIdList = sysRoleMenuService.queryMenuIdList(roleId);
|
||||
role.setMenuIdList(menuIdList);
|
||||
|
||||
return Result.success().put("role", role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存角色
|
||||
*/
|
||||
@SysLog("保存角色")
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("sys:role:save")
|
||||
public Result save(@RequestBody SysRoleEntity role){
|
||||
ValidatorUtils.validateEntity(role);
|
||||
|
||||
role.setCreateUserId(getUserId());
|
||||
sysRoleService.saveRole(role);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色
|
||||
*/
|
||||
@SysLog("修改角色")
|
||||
@PostMapping("/update")
|
||||
@RequiresPermissions("sys:role:update")
|
||||
public Result update(@RequestBody SysRoleEntity role){
|
||||
ValidatorUtils.validateEntity(role);
|
||||
|
||||
role.setCreateUserId(getUserId());
|
||||
sysRoleService.update(role);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
*/
|
||||
@SysLog("删除角色")
|
||||
@PostMapping("/delete")
|
||||
@RequiresPermissions("sys:role:delete")
|
||||
public Result delete(@RequestBody Long[] roleIds){
|
||||
sysRoleService.deleteBatch(roleIds);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.sqx.modules.sys.controller;
|
||||
|
||||
import com.sqx.common.annotation.SysLog;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.common.validator.Assert;
|
||||
import com.sqx.common.validator.ValidatorUtils;
|
||||
import com.sqx.common.validator.group.AddGroup;
|
||||
import com.sqx.common.validator.group.UpdateGroup;
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import com.sqx.modules.sys.form.PasswordForm;
|
||||
import com.sqx.modules.sys.service.SysUserRoleService;
|
||||
import com.sqx.modules.sys.service.SysUserService;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/user")
|
||||
public class SysUserController extends AbstractController {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
|
||||
|
||||
/**
|
||||
* 所有用户列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Result list(@RequestParam Map<String, Object> params){
|
||||
//只有超级管理员,才能查看所有管理员列表
|
||||
/*if(getUserId() != Constant.SUPER_ADMIN){
|
||||
params.put("createUserId", getUserId());
|
||||
}*/
|
||||
PageUtils page = sysUserService.queryPage(params);
|
||||
|
||||
return Result.success().put("page", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录的用户信息
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public Result info(){
|
||||
return Result.success().put("user", getUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改登录用户密码
|
||||
*/
|
||||
@SysLog("修改密码")
|
||||
public Result password(@RequestBody PasswordForm form){
|
||||
Assert.isBlank(form.getNewPassword(), "新密码不为能空");
|
||||
|
||||
//sha256加密
|
||||
String password = new Sha256Hash(form.getPassword(), getUser().getSalt()).toHex();
|
||||
//sha256加密
|
||||
String newPassword = new Sha256Hash(form.getNewPassword(), getUser().getSalt()).toHex();
|
||||
|
||||
//更新密码
|
||||
boolean flag = sysUserService.updatePassword(getUserId(), password, newPassword);
|
||||
if(!flag){
|
||||
return Result.error("原密码不正确");
|
||||
}
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
@GetMapping("/info/{userId}")
|
||||
public Result info(@PathVariable("userId") Long userId){
|
||||
SysUserEntity user = sysUserService.getById(userId);
|
||||
|
||||
//获取用户所属的角色列表
|
||||
List<Long> roleIdList = sysUserRoleService.queryRoleIdList(userId);
|
||||
user.setRoleIdList(roleIdList);
|
||||
|
||||
return Result.success().put("user", user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户
|
||||
*/
|
||||
@SysLog("保存用户")
|
||||
@PostMapping("/save")
|
||||
public Result save(@RequestBody SysUserEntity user){
|
||||
ValidatorUtils.validateEntity(user, AddGroup.class);
|
||||
|
||||
user.setCreateUserId(getUserId());
|
||||
sysUserService.saveUser(user);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@SysLog("修改用户")
|
||||
@PostMapping("/update")
|
||||
public Result update(@RequestBody SysUserEntity user){
|
||||
ValidatorUtils.validateEntity(user, UpdateGroup.class);
|
||||
|
||||
user.setCreateUserId(getUserId());
|
||||
sysUserService.update(user);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
@SysLog("删除用户")
|
||||
@PostMapping("/delete")
|
||||
public Result delete(@RequestBody Long[] userIds){
|
||||
if(ArrayUtils.contains(userIds, 1L)){
|
||||
return Result.error("系统管理员不能删除");
|
||||
}
|
||||
|
||||
if(ArrayUtils.contains(userIds, getUserId())){
|
||||
return Result.error("当前用户不能删除");
|
||||
}
|
||||
|
||||
sysUserService.deleteBatch(userIds);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
14
src/main/java/com/sqx/modules/sys/dao/SysCaptchaDao.java
Normal file
14
src/main/java/com/sqx/modules/sys/dao/SysCaptchaDao.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysCaptchaEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysCaptchaDao extends BaseMapper<SysCaptchaEntity> {
|
||||
|
||||
}
|
||||
26
src/main/java/com/sqx/modules/sys/dao/SysConfigDao.java
Normal file
26
src/main/java/com/sqx/modules/sys/dao/SysConfigDao.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysConfigEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysConfigDao extends BaseMapper<SysConfigEntity> {
|
||||
|
||||
/**
|
||||
* 根据key,查询value
|
||||
*/
|
||||
SysConfigEntity queryByKey(String paramKey);
|
||||
|
||||
/**
|
||||
* 根据key,更新value
|
||||
*/
|
||||
int updateValueByKey(@Param("paramKey") String paramKey, @Param("paramValue") String paramValue);
|
||||
|
||||
}
|
||||
14
src/main/java/com/sqx/modules/sys/dao/SysDictDao.java
Normal file
14
src/main/java/com/sqx/modules/sys/dao/SysDictDao.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysDictEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysDictDao extends BaseMapper<SysDictEntity> {
|
||||
|
||||
}
|
||||
15
src/main/java/com/sqx/modules/sys/dao/SysLogDao.java
Normal file
15
src/main/java/com/sqx/modules/sys/dao/SysLogDao.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysLogEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysLogDao extends BaseMapper<SysLogEntity> {
|
||||
|
||||
}
|
||||
27
src/main/java/com/sqx/modules/sys/dao/SysMenuDao.java
Normal file
27
src/main/java/com/sqx/modules/sys/dao/SysMenuDao.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysMenuEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysMenuDao extends BaseMapper<SysMenuEntity> {
|
||||
|
||||
/**
|
||||
* 根据父菜单,查询子菜单
|
||||
* @param parentId 父菜单ID
|
||||
*/
|
||||
List<SysMenuEntity> queryListParentId(Long parentId);
|
||||
|
||||
/**
|
||||
* 获取不包含按钮的菜单列表
|
||||
*/
|
||||
List<SysMenuEntity> queryNotButtonList();
|
||||
|
||||
}
|
||||
20
src/main/java/com/sqx/modules/sys/dao/SysRoleDao.java
Normal file
20
src/main/java/com/sqx/modules/sys/dao/SysRoleDao.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysRoleEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色管理
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysRoleDao extends BaseMapper<SysRoleEntity> {
|
||||
|
||||
/**
|
||||
* 查询用户创建的角色ID列表
|
||||
*/
|
||||
List<Long> queryRoleIdList(Long createUserId);
|
||||
}
|
||||
25
src/main/java/com/sqx/modules/sys/dao/SysRoleMenuDao.java
Normal file
25
src/main/java/com/sqx/modules/sys/dao/SysRoleMenuDao.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysRoleMenuEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色与菜单对应关系
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysRoleMenuDao extends BaseMapper<SysRoleMenuEntity> {
|
||||
|
||||
/**
|
||||
* 根据角色ID,获取菜单ID列表
|
||||
*/
|
||||
List<Long> queryMenuIdList(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据角色ID数组,批量删除
|
||||
*/
|
||||
int deleteBatch(Long[] roleIds);
|
||||
}
|
||||
32
src/main/java/com/sqx/modules/sys/dao/SysUserDao.java
Normal file
32
src/main/java/com/sqx/modules/sys/dao/SysUserDao.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserDao extends BaseMapper<SysUserEntity> {
|
||||
|
||||
/**
|
||||
* 查询用户的所有权限
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
List<String> queryAllPerms(Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户的所有菜单ID
|
||||
*/
|
||||
List<Long> queryAllMenuId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户名,查询系统用户
|
||||
*/
|
||||
SysUserEntity queryByUserName(String username);
|
||||
|
||||
}
|
||||
26
src/main/java/com/sqx/modules/sys/dao/SysUserRoleDao.java
Normal file
26
src/main/java/com/sqx/modules/sys/dao/SysUserRoleDao.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysUserRoleEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户与角色对应关系
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserRoleDao extends BaseMapper<SysUserRoleEntity> {
|
||||
|
||||
/**
|
||||
* 根据用户ID,获取角色ID列表
|
||||
*/
|
||||
List<Long> queryRoleIdList(Long userId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据角色ID数组,批量删除
|
||||
*/
|
||||
int deleteBatch(Long[] roleIds);
|
||||
}
|
||||
16
src/main/java/com/sqx/modules/sys/dao/SysUserTokenDao.java
Normal file
16
src/main/java/com/sqx/modules/sys/dao/SysUserTokenDao.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.sqx.modules.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.sys.entity.SysUserTokenEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 系统用户Token
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserTokenDao extends BaseMapper<SysUserTokenEntity> {
|
||||
|
||||
SysUserTokenEntity queryByToken(String token);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 系统验证码
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_captcha")
|
||||
public class SysCaptchaEntity {
|
||||
@TableId(type = IdType.INPUT)
|
||||
private String uuid;
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private Date expireTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_config")
|
||||
public class SysConfigEntity {
|
||||
@TableId
|
||||
private Long id;
|
||||
@NotBlank(message="参数名不能为空")
|
||||
private String paramKey;
|
||||
@NotBlank(message="参数值不能为空")
|
||||
private String paramValue;
|
||||
private String remark;
|
||||
|
||||
}
|
||||
56
src/main/java/com/sqx/modules/sys/entity/SysDictEntity.java
Normal file
56
src/main/java/com/sqx/modules/sys/entity/SysDictEntity.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_dict")
|
||||
public class SysDictEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
@NotBlank(message="字典名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
@NotBlank(message="字典类型不能为空")
|
||||
private String type;
|
||||
/**
|
||||
* 字典码
|
||||
*/
|
||||
@NotBlank(message="字典码不能为空")
|
||||
private String code;
|
||||
/**
|
||||
* 字典值
|
||||
*/
|
||||
@NotBlank(message="字典值不能为空")
|
||||
private String value;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer orderNum;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 删除标记 -1:已删除 0:正常
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
}
|
||||
36
src/main/java/com/sqx/modules/sys/entity/SysLogEntity.java
Normal file
36
src/main/java/com/sqx/modules/sys/entity/SysLogEntity.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_log")
|
||||
public class SysLogEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId
|
||||
private Long id;
|
||||
//用户名
|
||||
private String username;
|
||||
//用户操作
|
||||
private String operation;
|
||||
//请求方法
|
||||
private String method;
|
||||
//请求参数
|
||||
private String params;
|
||||
//执行时长(毫秒)
|
||||
private Long time;
|
||||
//IP地址
|
||||
private String ip;
|
||||
//创建时间
|
||||
private Date createDate;
|
||||
|
||||
}
|
||||
76
src/main/java/com/sqx/modules/sys/entity/SysMenuEntity.java
Normal file
76
src/main/java/com/sqx/modules/sys/entity/SysMenuEntity.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_menu")
|
||||
public class SysMenuEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
@TableId
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 父菜单ID,一级菜单为0
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 父菜单名称
|
||||
*/
|
||||
@TableField(exist=false)
|
||||
private String parentName;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 菜单URL
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 授权(多个用逗号分隔,如:user:list,user:create)
|
||||
*/
|
||||
private String perms;
|
||||
|
||||
/**
|
||||
* 类型 0:目录 1:菜单 2:按钮
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 菜单图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer orderNum;
|
||||
|
||||
/**
|
||||
* ztree属性
|
||||
*/
|
||||
@TableField(exist=false)
|
||||
private Boolean open;
|
||||
|
||||
@TableField(exist=false)
|
||||
private List<?> list;
|
||||
|
||||
}
|
||||
53
src/main/java/com/sqx/modules/sys/entity/SysRoleEntity.java
Normal file
53
src/main/java/com/sqx/modules/sys/entity/SysRoleEntity.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_role")
|
||||
public class SysRoleEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
@TableId
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
@NotBlank(message="角色名称不能为空")
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建者ID
|
||||
*/
|
||||
private Long createUserId;
|
||||
|
||||
@TableField(exist=false)
|
||||
private List<Long> menuIdList;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 角色与菜单对应关系
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_role_menu")
|
||||
public class SysRoleMenuEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
private Long menuId;
|
||||
|
||||
}
|
||||
112
src/main/java/com/sqx/modules/sys/entity/SysUserEntity.java
Normal file
112
src/main/java/com/sqx/modules/sys/entity/SysUserEntity.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.sqx.common.validator.group.AddGroup;
|
||||
import com.sqx.common.validator.group.UpdateGroup;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_user")
|
||||
public class SysUserEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableId
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message="用户名不能为空", groups = {AddGroup.class, UpdateGroup.class})
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@NotBlank(message="密码不能为空", groups = AddGroup.class)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 盐
|
||||
*/
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@NotBlank(message="邮箱不能为空", groups = {AddGroup.class, UpdateGroup.class})
|
||||
@Email(message="邮箱格式不正确", groups = {AddGroup.class, UpdateGroup.class})
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String mobile;
|
||||
|
||||
/**
|
||||
* 状态 0:禁用 1:正常
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 角色ID列表
|
||||
*/
|
||||
@TableField(exist=false)
|
||||
private List<Long> roleIdList;
|
||||
|
||||
/**
|
||||
* 创建者ID
|
||||
*/
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 渠道邀请码
|
||||
*/
|
||||
private String qdCode;
|
||||
|
||||
/**
|
||||
* 渠道佣金比例
|
||||
*/
|
||||
private BigDecimal qdRate;
|
||||
|
||||
/**
|
||||
* 是否是渠道
|
||||
*/
|
||||
private Integer isChannel;
|
||||
|
||||
/**
|
||||
* 员工
|
||||
*/
|
||||
private Long sysUserId;
|
||||
|
||||
/**
|
||||
* 支付宝账号
|
||||
*/
|
||||
private String zhiFuBao;
|
||||
|
||||
/**
|
||||
* 支付宝昵称
|
||||
*/
|
||||
private String zhiFuBaoName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户与角色对应关系
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_user_role")
|
||||
public class SysUserRoleEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sqx.modules.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户Token
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_user_token")
|
||||
public class SysUserTokenEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//用户ID
|
||||
@TableId(type = IdType.INPUT)
|
||||
private Long userId;
|
||||
//token
|
||||
private String token;
|
||||
//过期时间
|
||||
private Date expireTime;
|
||||
//更新时间
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
20
src/main/java/com/sqx/modules/sys/form/PasswordForm.java
Normal file
20
src/main/java/com/sqx/modules/sys/form/PasswordForm.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.sqx.modules.sys.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 密码表单
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class PasswordForm {
|
||||
/**
|
||||
* 原密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 新密码
|
||||
*/
|
||||
private String newPassword;
|
||||
|
||||
}
|
||||
18
src/main/java/com/sqx/modules/sys/form/SysLoginForm.java
Normal file
18
src/main/java/com/sqx/modules/sys/form/SysLoginForm.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.sqx.modules.sys.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 登录表单
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class SysLoginForm {
|
||||
private String username;
|
||||
private String password;
|
||||
private String captcha;
|
||||
private String uuid;
|
||||
private Integer adminType;
|
||||
|
||||
|
||||
}
|
||||
101
src/main/java/com/sqx/modules/sys/oauth2/OAuth2Filter.java
Normal file
101
src/main/java/com/sqx/modules/sys/oauth2/OAuth2Filter.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package com.sqx.modules.sys.oauth2;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.sqx.common.utils.HttpContextUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* oauth2过滤器
|
||||
*
|
||||
*/
|
||||
public class OAuth2Filter extends AuthenticatingFilter {
|
||||
|
||||
@Override
|
||||
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {
|
||||
//获取请求token
|
||||
String token = getRequestToken((HttpServletRequest) request);
|
||||
|
||||
if(StringUtils.isBlank(token)){
|
||||
return null;
|
||||
}
|
||||
|
||||
return new OAuth2Token(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
|
||||
if(((HttpServletRequest) request).getMethod().equals(RequestMethod.OPTIONS.name())){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
|
||||
//获取请求token,如果token不存在,直接返回401
|
||||
String token = getRequestToken((HttpServletRequest) request);
|
||||
if(StringUtils.isBlank(token)){
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
|
||||
|
||||
String json = new Gson().toJson(Result.error(HttpStatus.SC_UNAUTHORIZED, "invalid token"));
|
||||
|
||||
httpResponse.getWriter().print(json);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return executeLogin(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||
httpResponse.setContentType("application/json;charset=utf-8");
|
||||
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
|
||||
try {
|
||||
//处理登录失败的异常
|
||||
Throwable throwable = e.getCause() == null ? e : e.getCause();
|
||||
Result r = Result.error(HttpStatus.SC_UNAUTHORIZED, throwable.getMessage());
|
||||
|
||||
String json = new Gson().toJson(r);
|
||||
httpResponse.getWriter().print(json);
|
||||
} catch (IOException e1) {
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求的token
|
||||
*/
|
||||
private String getRequestToken(HttpServletRequest httpRequest){
|
||||
//从header中获取token
|
||||
String token = httpRequest.getHeader("token");
|
||||
|
||||
//如果header中不存在token,则从参数中获取token
|
||||
if(StringUtils.isBlank(token)){
|
||||
token = httpRequest.getParameter("token");
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
70
src/main/java/com/sqx/modules/sys/oauth2/OAuth2Realm.java
Normal file
70
src/main/java/com/sqx/modules/sys/oauth2/OAuth2Realm.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package com.sqx.modules.sys.oauth2;
|
||||
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import com.sqx.modules.sys.entity.SysUserTokenEntity;
|
||||
import com.sqx.modules.sys.service.ShiroService;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 认证
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class OAuth2Realm extends AuthorizingRealm {
|
||||
@Autowired
|
||||
private ShiroService shiroService;
|
||||
|
||||
@Override
|
||||
public boolean supports(AuthenticationToken token) {
|
||||
return token instanceof OAuth2Token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权(验证权限时调用)
|
||||
*/
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
SysUserEntity user = (SysUserEntity)principals.getPrimaryPrincipal();
|
||||
Long userId = user.getUserId();
|
||||
|
||||
//用户权限列表
|
||||
Set<String> permsSet = shiroService.getUserPermissions(userId);
|
||||
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
info.setStringPermissions(permsSet);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证(登录时调用)
|
||||
*/
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
|
||||
String accessToken = (String) token.getPrincipal();
|
||||
|
||||
//根据accessToken,查询用户信息
|
||||
SysUserTokenEntity tokenEntity = shiroService.queryByToken(accessToken);
|
||||
//token失效
|
||||
if(tokenEntity == null || tokenEntity.getExpireTime().getTime() < System.currentTimeMillis()){
|
||||
throw new IncorrectCredentialsException("token失效,请重新登录");
|
||||
}
|
||||
|
||||
//查询用户信息
|
||||
SysUserEntity user = shiroService.queryUser(tokenEntity.getUserId());
|
||||
//账号锁定
|
||||
if(user.getStatus() == 0){
|
||||
throw new LockedAccountException("账号已被锁定,请联系管理员");
|
||||
}
|
||||
|
||||
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, accessToken, getName());
|
||||
return info;
|
||||
}
|
||||
}
|
||||
26
src/main/java/com/sqx/modules/sys/oauth2/OAuth2Token.java
Normal file
26
src/main/java/com/sqx/modules/sys/oauth2/OAuth2Token.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.sqx.modules.sys.oauth2;
|
||||
|
||||
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
|
||||
/**
|
||||
* token
|
||||
*
|
||||
*/
|
||||
public class OAuth2Token implements AuthenticationToken {
|
||||
private String token;
|
||||
|
||||
public OAuth2Token(String token){
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrincipal() {
|
||||
return token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCredentials() {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
43
src/main/java/com/sqx/modules/sys/oauth2/TokenGenerator.java
Normal file
43
src/main/java/com/sqx/modules/sys/oauth2/TokenGenerator.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.sqx.modules.sys.oauth2;
|
||||
|
||||
import com.sqx.common.exception.SqxException;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 生成token
|
||||
*
|
||||
*/
|
||||
public class TokenGenerator {
|
||||
|
||||
public static String generateValue() {
|
||||
return generateValue(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
private static final char[] HexCode = "0123456789abcdef".toCharArray();
|
||||
|
||||
public static String toHexString(byte[] data) {
|
||||
if(data == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder r = new StringBuilder(data.length*2);
|
||||
for ( byte b : data) {
|
||||
r.append(HexCode[(b >> 4) & 0xF]);
|
||||
r.append(HexCode[(b & 0xF)]);
|
||||
}
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
public static String generateValue(String param) {
|
||||
try {
|
||||
MessageDigest algorithm = MessageDigest.getInstance("MD5");
|
||||
algorithm.reset();
|
||||
algorithm.update(param.getBytes());
|
||||
byte[] messageDigest = algorithm.digest();
|
||||
return toHexString(messageDigest);
|
||||
} catch (Exception e) {
|
||||
throw new SqxException("生成Token失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/main/java/com/sqx/modules/sys/redis/SysConfigRedis.java
Normal file
36
src/main/java/com/sqx/modules/sys/redis/SysConfigRedis.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.sqx.modules.sys.redis;
|
||||
|
||||
|
||||
import com.sqx.common.utils.RedisKeys;
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import com.sqx.modules.sys.entity.SysConfigEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 系统配置Redis
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class SysConfigRedis {
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
public void saveOrUpdate(SysConfigEntity config) {
|
||||
if(config == null){
|
||||
return ;
|
||||
}
|
||||
String key = RedisKeys.getSysConfigKey(config.getParamKey());
|
||||
redisUtils.set(key, config);
|
||||
}
|
||||
|
||||
public void delete(String configKey) {
|
||||
String key = RedisKeys.getSysConfigKey(configKey);
|
||||
redisUtils.delete(key);
|
||||
}
|
||||
|
||||
public SysConfigEntity get(String configKey){
|
||||
String key = RedisKeys.getSysConfigKey(configKey);
|
||||
return redisUtils.get(key, SysConfigEntity.class);
|
||||
}
|
||||
}
|
||||
25
src/main/java/com/sqx/modules/sys/service/ShiroService.java
Normal file
25
src/main/java/com/sqx/modules/sys/service/ShiroService.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import com.sqx.modules.sys.entity.SysUserTokenEntity;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* shiro相关接口
|
||||
*
|
||||
*/
|
||||
public interface ShiroService {
|
||||
/**
|
||||
* 获取用户权限列表
|
||||
*/
|
||||
Set<String> getUserPermissions(long userId);
|
||||
|
||||
SysUserTokenEntity queryByToken(String token);
|
||||
|
||||
/**
|
||||
* 根据用户ID,查询用户
|
||||
* @param userId
|
||||
*/
|
||||
SysUserEntity queryUser(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.sys.entity.SysCaptchaEntity;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*
|
||||
*/
|
||||
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,51 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.modules.sys.entity.SysConfigEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
*
|
||||
*/
|
||||
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,17 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.modules.sys.entity.SysDictEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
*
|
||||
*/
|
||||
public interface SysDictService extends IService<SysDictEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
||||
|
||||
19
src/main/java/com/sqx/modules/sys/service/SysLogService.java
Normal file
19
src/main/java/com/sqx/modules/sys/service/SysLogService.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.modules.sys.entity.SysLogEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
*
|
||||
*/
|
||||
public interface SysLogService extends IService<SysLogEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.sys.entity.SysMenuEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
*
|
||||
*/
|
||||
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,28 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.sys.entity.SysRoleMenuEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 角色与菜单对应关系
|
||||
*
|
||||
*/
|
||||
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,30 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.modules.sys.entity.SysRoleEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*
|
||||
*/
|
||||
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,27 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.sys.entity.SysUserRoleEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户与角色对应关系
|
||||
*
|
||||
*/
|
||||
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,60 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
*/
|
||||
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);
|
||||
|
||||
SysUserEntity selectSysUserByQdCode(String qdCode);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.sqx.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.sys.entity.SysUserTokenEntity;
|
||||
|
||||
/**
|
||||
* 用户Token
|
||||
*
|
||||
*/
|
||||
public interface SysUserTokenService extends IService<SysUserTokenEntity> {
|
||||
|
||||
/**
|
||||
* 生成token
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
Result createToken(long userId);
|
||||
|
||||
/**
|
||||
* 退出,修改token值
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
void logout(long userId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.sqx.modules.sys.service.impl;
|
||||
|
||||
import com.sqx.common.utils.Constant;
|
||||
import com.sqx.modules.sys.dao.SysMenuDao;
|
||||
import com.sqx.modules.sys.dao.SysUserDao;
|
||||
import com.sqx.modules.sys.dao.SysUserTokenDao;
|
||||
import com.sqx.modules.sys.entity.SysMenuEntity;
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import com.sqx.modules.sys.entity.SysUserTokenEntity;
|
||||
import com.sqx.modules.sys.service.ShiroService;
|
||||
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;
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.sqx.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.sqx.common.exception.SqxException;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.modules.sys.dao.SysCaptchaDao;
|
||||
import com.sqx.modules.sys.entity.SysCaptchaEntity;
|
||||
import com.sqx.modules.sys.service.SysCaptchaService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*
|
||||
*/
|
||||
@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 SqxException("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,96 @@
|
||||
package com.sqx.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.sqx.common.exception.SqxException;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Query;
|
||||
import com.sqx.modules.sys.dao.SysConfigDao;
|
||||
import com.sqx.modules.sys.entity.SysConfigEntity;
|
||||
import com.sqx.modules.sys.redis.SysConfigRedis;
|
||||
import com.sqx.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 SqxException("获取参数失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.sqx.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.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Query;
|
||||
import com.sqx.modules.sys.dao.SysDictDao;
|
||||
import com.sqx.modules.sys.entity.SysDictEntity;
|
||||
import com.sqx.modules.sys.service.SysDictService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service("sysDictService")
|
||||
public class SysDictServiceImpl extends ServiceImpl<SysDictDao, SysDictEntity> implements SysDictService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String name = (String)params.get("name");
|
||||
|
||||
IPage<SysDictEntity> page = this.page(
|
||||
new Query<SysDictEntity>().getPage(params),
|
||||
new QueryWrapper<SysDictEntity>()
|
||||
.like(StringUtils.isNotBlank(name),"name", name)
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sqx.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.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Query;
|
||||
import com.sqx.modules.sys.dao.SysLogDao;
|
||||
import com.sqx.modules.sys.entity.SysLogEntity;
|
||||
import com.sqx.modules.sys.service.SysLogService;
|
||||
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,99 @@
|
||||
package com.sqx.modules.sys.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.Constant;
|
||||
import com.sqx.common.utils.MapUtils;
|
||||
import com.sqx.modules.sys.dao.SysMenuDao;
|
||||
import com.sqx.modules.sys.entity.SysMenuEntity;
|
||||
import com.sqx.modules.sys.service.SysMenuService;
|
||||
import com.sqx.modules.sys.service.SysRoleMenuService;
|
||||
import com.sqx.modules.sys.service.SysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@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 getAllMenuList(null);
|
||||
}*/
|
||||
//用户菜单列表
|
||||
List<Long> menuIdList = sysUserService.queryAllMenuId(userId);
|
||||
return getAllMenuList(menuIdList);
|
||||
}
|
||||
|
||||
@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,51 @@
|
||||
package com.sqx.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.modules.sys.dao.SysRoleMenuDao;
|
||||
import com.sqx.modules.sys.entity.SysRoleMenuEntity;
|
||||
import com.sqx.modules.sys.service.SysRoleMenuService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 角色与菜单对应关系
|
||||
*
|
||||
*/
|
||||
@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,113 @@
|
||||
package com.sqx.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.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Query;
|
||||
import com.sqx.modules.sys.dao.SysRoleDao;
|
||||
import com.sqx.modules.sys.entity.SysRoleEntity;
|
||||
import com.sqx.modules.sys.service.SysRoleMenuService;
|
||||
import com.sqx.modules.sys.service.SysRoleService;
|
||||
import com.sqx.modules.sys.service.SysUserRoleService;
|
||||
import com.sqx.modules.sys.service.SysUserService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*
|
||||
*/
|
||||
@Service("sysRoleService")
|
||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleDao, SysRoleEntity> implements SysRoleService {
|
||||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@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 = sysUserService.queryAllMenuId(role.getCreateUserId());
|
||||
|
||||
//判断是否越权
|
||||
if(!menuIdList.containsAll(role.getMenuIdList())){
|
||||
throw new SqxException("新增角色的权限,已超出你的权限范围");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.sqx.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.MapUtils;
|
||||
import com.sqx.modules.sys.dao.SysUserRoleDao;
|
||||
import com.sqx.modules.sys.entity.SysUserRoleEntity;
|
||||
import com.sqx.modules.sys.service.SysUserRoleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户与角色对应关系
|
||||
*
|
||||
*/
|
||||
@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,147 @@
|
||||
package com.sqx.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.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Query;
|
||||
import com.sqx.modules.sys.dao.SysUserDao;
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import com.sqx.modules.sys.service.SysRoleService;
|
||||
import com.sqx.modules.sys.service.SysUserRoleService;
|
||||
import com.sqx.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;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
@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");
|
||||
Object isChannel = params.get("isChannel");
|
||||
Object sysUserId = params.get("sysUserId");
|
||||
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)
|
||||
.eq(isChannel!=null,"is_channel",isChannel)
|
||||
.eq(sysUserId!=null,"sys_user_id",sysUserId)
|
||||
.isNull(sysUserId==null,"sys_user_id")
|
||||
.isNull(isChannel==null,"is_channel")
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@SuppressWarnings("AlibabaTransactionMustHaveRollback")
|
||||
@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 SqxException("新增用户所选角色,不是本人创建");
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserEntity selectSysUserByQdCode(String qdCode){
|
||||
return baseMapper.selectOne(new QueryWrapper<SysUserEntity>().isNull("sys_user_id").eq("qd_code", qdCode));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.sqx.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.sys.dao.SysUserTokenDao;
|
||||
import com.sqx.modules.sys.entity.SysUserTokenEntity;
|
||||
import com.sqx.modules.sys.oauth2.TokenGenerator;
|
||||
import com.sqx.modules.sys.service.SysUserTokenService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Service("sysUserTokenService")
|
||||
public class SysUserTokenServiceImpl extends ServiceImpl<SysUserTokenDao, SysUserTokenEntity> implements SysUserTokenService {
|
||||
//12小时后过期
|
||||
private final static int EXPIRE = 3600 * 12;
|
||||
|
||||
|
||||
@Override
|
||||
public Result 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);
|
||||
}
|
||||
|
||||
Result r = Result.success().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