use of com.jun.plugin.system.common.aop.annotation.LogAnnotation in project jun_springboot_api_service by wujun728.
the class RoleController method bindDept.
@PostMapping("/role/bindDept")
@ApiOperation(value = "绑定角色部门接口")
@LogAnnotation(title = "角色管理", action = "绑定角色部门信息")
@RequiresPermissions("sys:role:bindDept")
public DataResult bindDept(@RequestBody SysRole vo) {
if (StringUtils.isEmpty(vo.getId())) {
return DataResult.fail("id不能为空");
}
if (roleService.getById(vo.getId()) == null) {
return DataResult.fail("获取角色失败");
}
// 先删除所有绑定
sysRoleDeptService.remove(Wrappers.<SysRoleDeptEntity>lambdaQuery().eq(SysRoleDeptEntity::getRoleId, vo.getId()));
// 如果不是自定义
if (vo.getDataScope() != 2) {
vo.setDepts(null);
}
if (!CollectionUtils.isEmpty(vo.getDepts())) {
List<SysRoleDeptEntity> list = new ArrayList<>();
for (String deptId : vo.getDepts()) {
SysRoleDeptEntity sysRoleDeptEntity = new SysRoleDeptEntity();
sysRoleDeptEntity.setDeptId(deptId);
sysRoleDeptEntity.setRoleId(vo.getId());
list.add(sysRoleDeptEntity);
}
sysRoleDeptService.saveBatch(list);
}
roleService.updateById(new SysRole().setId(vo.getId()).setDataScope(vo.getDataScope()));
return DataResult.success();
}
use of com.jun.plugin.system.common.aop.annotation.LogAnnotation in project jun_springboot_api_service by wujun728.
the class SysLogAspect method saveSysLog.
/**
* 把日志保存
*/
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
SysLog sysLog = new SysLog();
LogAnnotation logAnnotation = method.getAnnotation(LogAnnotation.class);
if (logAnnotation != null) {
// 注解上的描述
sysLog.setOperation(logAnnotation.title() + "-" + logAnnotation.action());
}
// 请求的方法名
String className = joinPoint.getTarget().getClass().getName();
String methodName = signature.getName();
sysLog.setMethod(className + "." + methodName + "()");
log.info("请求{}.{}耗时{}毫秒", className, methodName, time);
try {
// 请求的参数
Object[] args = joinPoint.getArgs();
String params = null;
if (args.length != 0) {
params = JSON.toJSONString(args);
}
sysLog.setParams(params);
} catch (Exception e) {
log.error("sysLog,exception:{}", e, e);
}
// 获取request
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
// 设置IP地址
sysLog.setIp(IPUtils.getIpAddr(request));
log.info("Ip{},接口地址{},请求方式{},入参:{}", sysLog.getIp(), request.getRequestURL(), request.getMethod(), sysLog.getParams());
// 用户名
String userId = httpSessionService.getCurrentUserId();
String username = httpSessionService.getCurrentUsername();
sysLog.setUsername(username);
sysLog.setUserId(userId);
sysLog.setTime((int) time);
log.info(sysLog.toString());
sysLogMapper.insert(sysLog);
}
Aggregations