first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
import com.peanut.modules.sys.entity.SysUserEntity;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Controller公共组件
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
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,4 @@
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
public class InterfaceConfigController extends AbstractController {
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
|
||||
import com.peanut.common.annotation.SysLog;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.validator.ValidatorUtils;
|
||||
import com.peanut.modules.sys.entity.SysConfigEntity;
|
||||
import com.peanut.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;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/config")
|
||||
public class SysConfigController extends AbstractController {
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
/**
|
||||
* 所有配置列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:config:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = sysConfigService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置信息
|
||||
*/
|
||||
@GetMapping("/info/{id}")
|
||||
@RequiresPermissions("sys:config:info")
|
||||
public R info(@PathVariable("id") Long id){
|
||||
SysConfigEntity config = sysConfigService.getById(id);
|
||||
|
||||
return R.ok().put("config", config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置
|
||||
*/
|
||||
@SysLog("保存配置")
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("sys:config:save")
|
||||
public R save(@RequestBody SysConfigEntity config){
|
||||
ValidatorUtils.validateEntity(config);
|
||||
|
||||
sysConfigService.saveConfig(config);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改配置
|
||||
*/
|
||||
@SysLog("修改配置")
|
||||
@PostMapping("/update")
|
||||
@RequiresPermissions("sys:config:update")
|
||||
public R update(@RequestBody SysConfigEntity config){
|
||||
ValidatorUtils.validateEntity(config);
|
||||
|
||||
sysConfigService.update(config);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除配置
|
||||
*/
|
||||
@SysLog("删除配置")
|
||||
@PostMapping("/delete")
|
||||
@RequiresPermissions("sys:config:delete")
|
||||
public R delete(@RequestBody Long[] ids){
|
||||
sysConfigService.deleteBatch(ids);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.modules.sys.service.SysDictDataService;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.peanut.modules.book.entity.SysDictDataEntity;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 字典数据
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-08-04 17:25:02
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("book/sysdictdata")
|
||||
public class SysDictDataController {
|
||||
@Autowired
|
||||
private SysDictDataService sysDictDataService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
// @RequiresPermissions("book:sysdictdata:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = sysDictDataService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
// @RequiresPermissions("book:sysdictdata:info")
|
||||
public R info(@PathVariable("id") Long id){
|
||||
SysDictDataEntity sysDictData = sysDictDataService.getById(id);
|
||||
|
||||
return R.ok().put("sysDictData", sysDictData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
// @RequiresPermissions("book:sysdictdata:save")
|
||||
public R save(@RequestBody SysDictDataEntity sysDictData){
|
||||
sysDictDataService.save(sysDictData);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
// @RequiresPermissions("book:sysdictdata:update")
|
||||
public R update(@RequestBody SysDictDataEntity sysDictData){
|
||||
sysDictDataService.updateById(sysDictData);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
// @RequiresPermissions("book:sysdictdata:delete")
|
||||
public R delete(@RequestBody Long[] ids){
|
||||
sysDictDataService.removeByIds(Arrays.asList(ids));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/selectByType/{type}")
|
||||
// @RequiresPermissions("book:sysdictdata:delete")
|
||||
public R selectByType(@PathVariable("type") String type){
|
||||
|
||||
List<SysDictDataEntity> dict_label = sysDictDataService.getBaseMapper().selectList(new QueryWrapper<SysDictDataEntity>().eq("dict_label", type));
|
||||
|
||||
return R.ok().put("dataList",dict_label);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.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;
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/sys/log")
|
||||
public class SysLogController {
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:log:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = sysLogService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.sys.entity.SysUserEntity;
|
||||
import com.peanut.modules.sys.form.SysLoginForm;
|
||||
import com.peanut.modules.sys.service.SysCaptchaService;
|
||||
import com.peanut.modules.sys.service.SysUserService;
|
||||
import com.peanut.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;
|
||||
|
||||
/**
|
||||
* 登录相关
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@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 R.error("验证码不正确");
|
||||
}
|
||||
|
||||
//用户信息
|
||||
SysUserEntity user = sysUserService.queryByUserName(form.getUsername());
|
||||
|
||||
//账号不存在、密码错误
|
||||
// if(user == null || !user.getPassword().equals(new Sha256Hash(form.getPassword(), user.getSalt()).toHex())) {
|
||||
// return R.error("账号或密码不正确");
|
||||
// }
|
||||
|
||||
//账号锁定
|
||||
if(user.getStatus() == 0){
|
||||
return R.error("账号已被锁定,请联系管理员");
|
||||
}
|
||||
|
||||
//生成token,并保存到数据库
|
||||
R r = sysUserTokenService.createToken(user.getUserId());
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出
|
||||
*/
|
||||
@PostMapping("/sys/logout")
|
||||
public R logout() {
|
||||
sysUserTokenService.logout(getUserId());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
import com.peanut.common.annotation.SysLog;
|
||||
import com.peanut.common.exception.RRException;
|
||||
import com.peanut.common.utils.Constant;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.sys.entity.SysMenuEntity;
|
||||
import com.peanut.modules.sys.service.ShiroService;
|
||||
import com.peanut.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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 系统菜单
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/menu")
|
||||
public class SysMenuController extends AbstractController {
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private ShiroService shiroService;
|
||||
|
||||
/**
|
||||
* 导航菜单
|
||||
*/
|
||||
@GetMapping("/nav")
|
||||
public R nav(){
|
||||
List<SysMenuEntity> menuList = sysMenuService.getUserMenuList(getUserId());
|
||||
Set<String> permissions = shiroService.getUserPermissions(getUserId());
|
||||
return R.ok().put("menuList", menuList).put("permissions", permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有菜单列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:menu:list")
|
||||
public List<SysMenuEntity> list(){
|
||||
List<SysMenuEntity> menuList = sysMenuService.list();
|
||||
HashMap<Long, SysMenuEntity> menuMap = new HashMap<>(12);
|
||||
for (SysMenuEntity s : menuList) {
|
||||
menuMap.put(s.getMenuId(), s);
|
||||
}
|
||||
for (SysMenuEntity s : menuList) {
|
||||
SysMenuEntity parent = menuMap.get(s.getParentId());
|
||||
if (Objects.nonNull(parent)) {
|
||||
s.setParentName(parent.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return menuList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择菜单(添加、修改菜单)
|
||||
*/
|
||||
@GetMapping("/select")
|
||||
@RequiresPermissions("sys:menu:select")
|
||||
public R 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 R.ok().put("menuList", menuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单信息
|
||||
*/
|
||||
@GetMapping("/info/{menuId}")
|
||||
@RequiresPermissions("sys:menu:info")
|
||||
public R info(@PathVariable("menuId") Long menuId){
|
||||
SysMenuEntity menu = sysMenuService.getById(menuId);
|
||||
return R.ok().put("menu", menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@SysLog("保存菜单")
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("sys:menu:save")
|
||||
public R save(@RequestBody SysMenuEntity menu){
|
||||
//数据校验
|
||||
verifyForm(menu);
|
||||
|
||||
sysMenuService.save(menu);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@SysLog("修改菜单")
|
||||
@PostMapping("/update")
|
||||
@RequiresPermissions("sys:menu:update")
|
||||
public R update(@RequestBody SysMenuEntity menu){
|
||||
//数据校验
|
||||
verifyForm(menu);
|
||||
|
||||
sysMenuService.updateById(menu);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@SysLog("删除菜单")
|
||||
@PostMapping("/delete/{menuId}")
|
||||
@RequiresPermissions("sys:menu:delete")
|
||||
public R delete(@PathVariable("menuId") long menuId){
|
||||
if(menuId <= 31){
|
||||
return R.error("系统菜单,不能删除");
|
||||
}
|
||||
|
||||
//判断是否有子菜单或按钮
|
||||
List<SysMenuEntity> menuList = sysMenuService.queryListParentId(menuId);
|
||||
if(menuList.size() > 0){
|
||||
return R.error("请先删除子菜单或按钮");
|
||||
}
|
||||
|
||||
sysMenuService.delete(menuId);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证参数是否正确
|
||||
*/
|
||||
private void verifyForm(SysMenuEntity menu){
|
||||
if(StringUtils.isBlank(menu.getName())){
|
||||
throw new RRException("菜单名称不能为空");
|
||||
}
|
||||
|
||||
if(menu.getParentId() == null){
|
||||
throw new RRException("上级菜单不能为空");
|
||||
}
|
||||
|
||||
//菜单
|
||||
if(menu.getType() == Constant.MenuType.MENU.getValue()){
|
||||
if(StringUtils.isBlank(menu.getUrl())){
|
||||
throw new RRException("菜单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 RRException("上级菜单只能为目录类型");
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
//按钮
|
||||
if(menu.getType() == Constant.MenuType.BUTTON.getValue()){
|
||||
if(parentType != Constant.MenuType.MENU.getValue()){
|
||||
throw new RRException("上级菜单只能为菜单类型");
|
||||
}
|
||||
return ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
import com.peanut.common.annotation.SysLog;
|
||||
import com.peanut.common.utils.Constant;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.validator.ValidatorUtils;
|
||||
import com.peanut.modules.sys.entity.SysRoleEntity;
|
||||
import com.peanut.modules.sys.service.SysRoleMenuService;
|
||||
import com.peanut.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;
|
||||
|
||||
/**
|
||||
* 角色管理
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/role")
|
||||
public class SysRoleController extends AbstractController {
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:role:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
//如果不是超级管理员,则只查询自己创建的角色列表
|
||||
if(getUserId() != Constant.SUPER_ADMIN){
|
||||
params.put("createUserId", getUserId());
|
||||
}
|
||||
|
||||
PageUtils page = sysRoleService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
@GetMapping("/select")
|
||||
@RequiresPermissions("sys:role:select")
|
||||
public R 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 R.ok().put("list", list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色信息
|
||||
*/
|
||||
@GetMapping("/info/{roleId}")
|
||||
@RequiresPermissions("sys:role:info")
|
||||
public R info(@PathVariable("roleId") Long roleId){
|
||||
SysRoleEntity role = sysRoleService.getById(roleId);
|
||||
|
||||
//查询角色对应的菜单
|
||||
List<Long> menuIdList = sysRoleMenuService.queryMenuIdList(roleId);
|
||||
role.setMenuIdList(menuIdList);
|
||||
|
||||
return R.ok().put("role", role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存角色
|
||||
*/
|
||||
@SysLog("保存角色")
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("sys:role:save")
|
||||
public R save(@RequestBody SysRoleEntity role){
|
||||
ValidatorUtils.validateEntity(role);
|
||||
|
||||
role.setCreateUserId(getUserId());
|
||||
sysRoleService.saveRole(role);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色
|
||||
*/
|
||||
@SysLog("修改角色")
|
||||
@PostMapping("/update")
|
||||
@RequiresPermissions("sys:role:update")
|
||||
public R update(@RequestBody SysRoleEntity role){
|
||||
ValidatorUtils.validateEntity(role);
|
||||
|
||||
role.setCreateUserId(getUserId());
|
||||
sysRoleService.update(role);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
*/
|
||||
@SysLog("删除角色")
|
||||
@PostMapping("/delete")
|
||||
@RequiresPermissions("sys:role:delete")
|
||||
public R delete(@RequestBody Long[] roleIds){
|
||||
sysRoleService.deleteBatch(roleIds);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
import com.peanut.common.annotation.SysLog;
|
||||
import com.peanut.common.utils.Constant;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.validator.Assert;
|
||||
import com.peanut.common.validator.ValidatorUtils;
|
||||
import com.peanut.common.validator.group.AddGroup;
|
||||
import com.peanut.common.validator.group.UpdateGroup;
|
||||
import com.peanut.modules.sys.entity.SysUserEntity;
|
||||
import com.peanut.modules.sys.form.PasswordForm;
|
||||
import com.peanut.modules.sys.service.SysUserRoleService;
|
||||
import com.peanut.modules.sys.service.SysUserService;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/user")
|
||||
public class SysUserController extends AbstractController {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
|
||||
|
||||
/**
|
||||
* 所有用户列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:user:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
//只有超级管理员,才能查看所有管理员列表
|
||||
if(getUserId() != Constant.SUPER_ADMIN){
|
||||
params.put("createUserId", getUserId());
|
||||
}
|
||||
PageUtils page = sysUserService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录的用户信息
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public R info(){
|
||||
return R.ok().put("user", getUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改登录用户密码
|
||||
*/
|
||||
@SysLog("修改密码")
|
||||
@PostMapping("/password")
|
||||
public R 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 R.error("原密码不正确");
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
@GetMapping("/info/{userId}")
|
||||
@RequiresPermissions("sys:user:info")
|
||||
public R info(@PathVariable("userId") Long userId){
|
||||
SysUserEntity user = sysUserService.getById(userId);
|
||||
|
||||
//获取用户所属的角色列表
|
||||
List<Long> roleIdList = sysUserRoleService.queryRoleIdList(userId);
|
||||
user.setRoleIdList(roleIdList);
|
||||
|
||||
return R.ok().put("user", user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户
|
||||
*/
|
||||
@SysLog("保存用户")
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("sys:user:save")
|
||||
public R save(@RequestBody SysUserEntity user){
|
||||
ValidatorUtils.validateEntity(user, AddGroup.class);
|
||||
|
||||
user.setCreateUserId(getUserId());
|
||||
sysUserService.saveUser(user);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@SysLog("修改用户")
|
||||
@PostMapping("/update")
|
||||
@RequiresPermissions("sys:user:update")
|
||||
public R update(@RequestBody SysUserEntity user){
|
||||
ValidatorUtils.validateEntity(user, UpdateGroup.class);
|
||||
|
||||
user.setCreateUserId(getUserId());
|
||||
sysUserService.update(user);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
@SysLog("删除用户")
|
||||
@PostMapping("/delete")
|
||||
@RequiresPermissions("sys:user:delete")
|
||||
public R delete(@RequestBody Long[] userIds){
|
||||
if(ArrayUtils.contains(userIds, 1L)){
|
||||
return R.error("系统管理员不能删除");
|
||||
}
|
||||
|
||||
if(ArrayUtils.contains(userIds, getUserId())){
|
||||
return R.error("当前用户不能删除");
|
||||
}
|
||||
|
||||
sysUserService.deleteBatch(userIds);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user