Commit b6daaa43 by fsn

重构用户管理的日志记录

parent 14bc854e
package com.stylefeng.guns.common.constant;
/**
* 字典常量
*
* @author fengshuonan
* @date 2017年5月16日21:44:56
*/
public interface Dict {
/**
* 系统管理员字典
*/
String UserDict = "UserDict";
}
......@@ -12,16 +12,16 @@ public class UserDict extends AbstractDictMap {
@Override
public void init() {
put("userId","用户id");
put("id","用户id");
put("userId","账号");
put("account","账号");
put("name","名字");
put("birthday","生日");
put("sex","性别");
put("email","电子邮件");
put("phone","电话");
put("roleid","角色id");
put("deptid","部门id");
put("roleid","角色名称");
put("deptid","部门名称");
put("roleIds","角色名称集合");
}
@Override
......@@ -29,5 +29,7 @@ public class UserDict extends AbstractDictMap {
putFieldWrapperMethodName("sex","getSexName");
putFieldWrapperMethodName("deptid","getDeptName");
putFieldWrapperMethodName("roleid","getSingleRoleName");
putFieldWrapperMethodName("userId","getUserAccountById");
putFieldWrapperMethodName("roleIds","getRoleName");
}
}
......@@ -21,7 +21,13 @@ public class DictFieldWarpperFactory {
Object result = method.invoke(me, field);
return result;
} catch (Exception e) {
throw new BussinessException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
try {
Method method = ConstantFactory.class.getMethod(methodName, Integer.class);
Object result = method.invoke(me, Integer.parseInt(field.toString()));
return result;
} catch (Exception e1) {
throw new BussinessException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
}
}
}
......
......@@ -59,6 +59,21 @@ public class ConstantFactory {
}
/**
* 根据用户id获取用户账号
*
* @author stylefeng
* @date 2017年5月16日21:55:371
*/
public String getUserAccountById(Integer userId){
User user = userMapper.selectById(userId);
if(user != null){
return user.getAccount();
}else{
return "--";
}
}
/**
* 通过角色ids获取角色名称
*/
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
......
......@@ -10,7 +10,6 @@ import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.core.support.HttpKit;
import com.stylefeng.guns.core.util.Contrast;
import com.stylefeng.guns.core.util.ToolUtil;
import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
......@@ -55,6 +54,7 @@ public class LogAop {
}
private void handle(ProceedingJoinPoint point) throws Exception {
//获取拦截的方法名
Signature sig = point.getSignature();
MethodSignature msig = null;
......@@ -96,13 +96,8 @@ public class LogAop {
msg = Contrast.contrastObj(dictClass, key, obj1, obj2);
} else {
Map<String, String> parameters = HttpKit.getRequestParameters();
String value = parameters.get(key);
if (ToolUtil.isNotEmpty(value)) {
AbstractDictMap dictMap = DictMapFactory.createDictMap(dictClass);
msg = dictMap.get(key) + ":" + value;
} else {
msg = "无";
}
AbstractDictMap dictMap = DictMapFactory.createDictMap(dictClass);
msg = Contrast.parseMutiKey(dictMap,key,parameters);
}
LogManager.me().executeLog(LogTaskFactory.bussinessLog(user.getId(), bussinessName, className, methodName, msg));
......
......@@ -70,8 +70,7 @@ public class Contrast {
*/
public static String contrastObj(String dictClass, String key, Object pojo1, Map<String, String> pojo2) {
AbstractDictMap dictMap = DictMapFactory.createDictMap(dictClass);
String value = pojo2.get(key);
String str = dictMap.get(key) + "=" + value + separator;
String str = parseMutiKey(dictMap, key, pojo2) + separator;
try {
Class clazz = pojo1.getClass();
Field[] fields = pojo1.getClass().getDeclaredFields();
......@@ -114,4 +113,38 @@ public class Contrast {
return str;
}
/**
* 解析多个key(逗号隔开的)
*
* @author stylefeng
* @Date 2017/5/16 22:19
*/
public static String parseMutiKey(AbstractDictMap dictMap, String key, Map<String, String> requests) {
StringBuilder sb = new StringBuilder();
if (key.indexOf(",") != -1) {
String[] keys = key.split(",");
for (String item : keys) {
String fieldWarpperMethodName = dictMap.getFieldWarpperMethodName(item);
String value = requests.get(item);
if (fieldWarpperMethodName != null) {
Object valueWarpper = DictFieldWarpperFactory.createFieldWarpper(value, fieldWarpperMethodName);
sb.append(dictMap.get(item) + "=" + valueWarpper + ",");
} else {
sb.append(dictMap.get(item) + "=" + value + ",");
}
}
return StrKit.removeSuffix(sb.toString(), ",");
} else {
String fieldWarpperMethodName = dictMap.getFieldWarpperMethodName(key);
String value = requests.get(key);
if (fieldWarpperMethodName != null) {
Object valueWarpper = DictFieldWarpperFactory.createFieldWarpper(value, fieldWarpperMethodName);
sb.append(dictMap.get(key) + "=" + valueWarpper);
} else {
sb.append(dictMap.get(key) + "=" + value);
}
return sb.toString();
}
}
}
\ No newline at end of file
......@@ -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.factory.ConstantFactory;
import com.stylefeng.guns.common.constant.state.ManagerStatus;
import com.stylefeng.guns.common.constant.tips.Tip;
......@@ -161,7 +162,7 @@ public class UserMgrController extends BaseController {
* 添加管理员
*/
@RequestMapping("/add")
@BussinessLog(value = "添加管理员", key = "name", dict = "UserDict")
@BussinessLog(value = "添加管理员", key = "account", dict = Dict.UserDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip add(@Valid UserDto user, BindingResult result) {
......@@ -191,7 +192,7 @@ public class UserMgrController extends BaseController {
* @throws NoPermissionException
*/
@RequestMapping("/edit")
@BussinessLog(value = "修改管理员", dict = "UserDict")
@BussinessLog(value = "修改管理员", key = "account", dict = Dict.UserDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip edit(@Valid UserDto user, BindingResult result) throws NoPermissionException {
......@@ -216,7 +217,7 @@ public class UserMgrController extends BaseController {
* 删除管理员(逻辑删除)
*/
@RequestMapping("/delete")
@BussinessLog(value = "删除管理员", key = "userId", dict = "UserDict")
@BussinessLog(value = "删除管理员", key = "userId", dict = Dict.UserDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip delete(@RequestParam Integer userId) {
......@@ -243,7 +244,7 @@ public class UserMgrController extends BaseController {
* 重置管理员的密码
*/
@RequestMapping("/reset")
@BussinessLog(value = "重置管理员密码", key = "userId", dict = "UserDict")
@BussinessLog(value = "重置管理员密码", key = "userId", dict = Dict.UserDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip reset(@RequestParam Integer userId) {
......@@ -261,7 +262,7 @@ public class UserMgrController extends BaseController {
* 冻结用户
*/
@RequestMapping("/freeze")
@BussinessLog(value = "冻结用户", key = "userId", dict = "UserDict")
@BussinessLog(value = "冻结用户", key = "userId", dict = Dict.UserDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip freeze(@RequestParam Integer userId) {
......@@ -276,7 +277,7 @@ public class UserMgrController extends BaseController {
* 解除冻结用户
*/
@RequestMapping("/unfreeze")
@BussinessLog(value = "解除冻结用户", key = "userId", dict = "UserDict")
@BussinessLog(value = "解除冻结用户", key = "userId", dict = Dict.UserDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip unfreeze(@RequestParam Integer userId) {
......@@ -291,7 +292,7 @@ public class UserMgrController extends BaseController {
* 分配角色
*/
@RequestMapping("/setRole")
@BussinessLog(value = "分配角色", key = "userId", dict = "UserDict")
@BussinessLog(value = "分配角色", key = "userId,roleIds", dict = Dict.UserDict)
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Tip setRole(@RequestParam("userId") Integer userId, @RequestParam("roleIds") String roleIds) {
......@@ -306,7 +307,9 @@ public class UserMgrController extends BaseController {
* 上传图片(上传到项目的webapp/static/img)
*/
@RequestMapping(method = RequestMethod.POST, path = "/upload")
public @ResponseBody String upload(@RequestPart("file") MultipartFile picture){
public
@ResponseBody
String upload(@RequestPart("file") MultipartFile picture) {
String pictureName = UUID.randomUUID().toString() + ".jpg";
try {
String fileSavePath = ConfigListener.getConf().get("realPath") + "static\\img\\";
......
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