Commit 342d2488 by fsn

重构角色管理的日志记录

parent b6daaa43
......@@ -13,4 +13,14 @@ public interface Dict {
*/
String UserDict = "UserDict";
/**
* 角色管理员字典
*/
String RoleDict = "RoleDict";
/**
* 删除业务的字典
*/
String DeleteDict = "DeleteDict";
}
package com.stylefeng.guns.common.constant.dictmap;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
/**
* 用于删除业务的字典
*
* @author fengshuonan
* @date 2017-05-06 15:01
*/
public class DeleteDict extends AbstractDictMap {
@Override
public void init() {
put("roleId","角色名称");
}
@Override
protected void initBeWrapped() {
putFieldWrapperMethodName("roleId","getCacheObject");
}
}
......@@ -12,18 +12,20 @@ public class RoleDict extends AbstractDictMap {
@Override
public void init() {
put("roleId","角色id");
put("id","角色id");
put("roleId","角色名称");
put("num","角色排序");
put("pid","角色的父级");
put("name","角色名称");
put("deptid","部门id");
put("deptid","部门名称");
put("tips","备注");
put("ids","资源名称");
}
@Override
protected void initBeWrapped() {
putFieldWrapperMethodName("pid","getSingleRoleName");
putFieldWrapperMethodName("deptid","getDeptName");
putFieldWrapperMethodName("roleId","getSingleRoleName");
putFieldWrapperMethodName("ids","getMenuNames");
}
}
......@@ -6,18 +6,13 @@ import com.stylefeng.guns.common.constant.cache.CacheKey;
import com.stylefeng.guns.common.constant.state.ManagerStatus;
import com.stylefeng.guns.common.constant.state.MenuStatus;
import com.stylefeng.guns.common.constant.state.Sex;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.support.StrKit;
import com.stylefeng.guns.core.util.Convert;
import com.stylefeng.guns.core.util.SpringContextHolder;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.persistence.dao.DeptMapper;
import com.stylefeng.guns.persistence.dao.DictMapper;
import com.stylefeng.guns.persistence.dao.RoleMapper;
import com.stylefeng.guns.persistence.dao.UserMapper;
import com.stylefeng.guns.persistence.model.Dept;
import com.stylefeng.guns.persistence.model.Dict;
import com.stylefeng.guns.persistence.model.Role;
import com.stylefeng.guns.persistence.model.User;
import com.stylefeng.guns.persistence.dao.*;
import com.stylefeng.guns.persistence.model.*;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
......@@ -38,6 +33,7 @@ public class ConstantFactory {
private DeptMapper deptMapper = SpringContextHolder.getBean(DeptMapper.class);
private DictMapper dictMapper = SpringContextHolder.getBean(DictMapper.class);
private UserMapper userMapper = SpringContextHolder.getBean(UserMapper.class);
private MenuMapper menuMapper = SpringContextHolder.getBean(MenuMapper.class);
public static ConstantFactory me() {
return SpringContextHolder.getBean("constantFactory");
......@@ -49,11 +45,11 @@ public class ConstantFactory {
* @author stylefeng
* @Date 2017/5/9 23:41
*/
public String getUserNameById(Integer userId){
public String getUserNameById(Integer userId) {
User user = userMapper.selectById(userId);
if(user != null){
if (user != null) {
return user.getName();
}else{
} else {
return "--";
}
}
......@@ -64,11 +60,11 @@ public class ConstantFactory {
* @author stylefeng
* @date 2017年5月16日21:55:371
*/
public String getUserAccountById(Integer userId){
public String getUserAccountById(Integer userId) {
User user = userMapper.selectById(userId);
if(user != null){
if (user != null) {
return user.getAccount();
}else{
} else {
return "--";
}
}
......@@ -132,6 +128,21 @@ public class ConstantFactory {
}
/**
* 获取菜单的名称们(多个)
*/
public String getMenuNames(String menuIds) {
Integer[] menus = Convert.toIntArray(menuIds);
StringBuilder sb = new StringBuilder();
for (int menu : menus) {
Menu menuObj = menuMapper.selectById(menu);
if (ToolUtil.isNotEmpty(menuObj) && ToolUtil.isNotEmpty(menuObj.getName())) {
sb.append(menuObj.getName()).append(",");
}
}
return StrKit.removeSuffix(sb.toString(), ",");
}
/**
* 获取性别名称
*/
public String getSexName(Integer sex) {
......@@ -155,18 +166,25 @@ public class ConstantFactory {
/**
* 查询字典
*/
public List<Dict> findInDict(Integer id){
if(ToolUtil.isEmpty(id)){
public List<Dict> findInDict(Integer id) {
if (ToolUtil.isEmpty(id)) {
return null;
}else{
} else {
EntityWrapper<Dict> wrapper = new EntityWrapper<>();
List<Dict> dicts = dictMapper.selectList(wrapper.eq("pid", id));
if(dicts == null || dicts.size() == 0){
if (dicts == null || dicts.size() == 0) {
return null;
}else{
} else {
return dicts;
}
}
}
/**
* 获取被缓存的对象(用户删除业务)
*/
public String getCacheObject(String para) {
return LogObjectHolder.me().get().toString();
}
}
......@@ -3,6 +3,7 @@ package com.stylefeng.guns.modular.system.controller;
import com.stylefeng.guns.common.annotion.Permission;
import com.stylefeng.guns.common.annotion.log.BussinessLog;
import com.stylefeng.guns.common.constant.Const;
import com.stylefeng.guns.common.constant.Dict;
import com.stylefeng.guns.common.constant.cache.Cache;
import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.constant.tips.Tip;
......@@ -117,7 +118,7 @@ public class RoleController extends BaseController {
* 角色新增
*/
@RequestMapping(value = "/add")
@BussinessLog(value = "添加角色", key = "name", dict = "RoleDict")
@BussinessLog(value = "添加角色", key = "name", dict = Dict.RoleDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip add(@Valid Role role, BindingResult result) {
......@@ -133,7 +134,7 @@ public class RoleController extends BaseController {
* 角色修改
*/
@RequestMapping(value = "/edit")
@BussinessLog(value = "修改角色", key = "name", dict = "RoleDict")
@BussinessLog(value = "修改角色", key = "name", dict = Dict.RoleDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip edit(@Valid Role role, BindingResult result) {
......@@ -151,13 +152,17 @@ public class RoleController extends BaseController {
* 删除角色
*/
@RequestMapping(value = "/remove")
@BussinessLog(value = "删除角色", key = "roleId", dict = "RoleDict")
@BussinessLog(value = "删除角色", key = "roleId", dict = Dict.DeleteDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip remove(@RequestParam Integer roleId) {
if (ToolUtil.isEmpty(roleId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
}
//缓存被删除的角色名称
LogObjectHolder.me().set(ConstantFactory.me().getSingleRoleName(roleId));
this.roleService.delRoleById(roleId);
//删除缓存
......@@ -182,7 +187,7 @@ public class RoleController extends BaseController {
* 配置权限
*/
@RequestMapping("/setAuthority")
@BussinessLog(value = "配置权限", key = "roleId", dict = "RoleDict")
@BussinessLog(value = "配置权限", key = "roleId,ids", dict = Dict.RoleDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip setAuthority(@RequestParam("roleId") Integer roleId, @RequestParam("ids") String ids) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment