use of com.company.project.common.aop.annotation.LogAnnotation in project springboot-manager by aitangbao.
the class PermissionController method updatePermission.
@PutMapping("/permission")
@ApiOperation(value = "更新菜单权限接口")
@LogAnnotation(title = "菜单权限管理", action = "更新菜单权限")
@RequiresPermissions("sys:permission:update")
public DataResult updatePermission(@RequestBody @Valid SysPermission vo) {
if (StringUtils.isEmpty(vo.getId())) {
return DataResult.fail("id不能为空");
}
SysPermission sysPermission = permissionService.getById(vo.getId());
if (null == sysPermission) {
throw new BusinessException(BaseResponseCode.DATA_ERROR);
}
// 只有类型变更或者所属菜单变更
if (sysPermission.getType().equals(vo.getType()) || !sysPermission.getPid().equals(vo.getPid())) {
verifyFormPid(vo);
}
permissionService.updatePermission(vo);
return DataResult.success();
}
use of com.company.project.common.aop.annotation.LogAnnotation in project springboot-manager by aitangbao.
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);
}
use of com.company.project.common.aop.annotation.LogAnnotation in project springboot-manager by aitangbao.
the class SysJobController method getRecentTriggerTime.
@ApiOperation(value = "获取运行时间")
@LogAnnotation(title = "获取运行时间")
@PostMapping("/getRecentTriggerTime")
@RequiresPermissions("sysJob:add")
public DataResult getRecentTriggerTime(String cron) {
List<String> list = new ArrayList<>();
try {
CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
cronTriggerImpl.setCronExpression(cron);
// 这个是重点,一行代码搞定
List<Date> dates = TriggerUtils.computeFireTimes(cronTriggerImpl, null, 5);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (Date date : dates) {
list.add(dateFormat.format(date));
}
} catch (ParseException e) {
e.printStackTrace();
}
return DataResult.success(list);
}
use of com.company.project.common.aop.annotation.LogAnnotation in project springboot-manager by aitangbao.
the class UserController method logout.
@GetMapping("/user/logout")
@ApiOperation(value = "退出接口")
@LogAnnotation(title = "用户管理", action = "退出")
public DataResult logout() {
httpSessionService.abortUserByToken();
Subject subject = SecurityUtils.getSubject();
subject.logout();
return DataResult.success();
}
use of com.company.project.common.aop.annotation.LogAnnotation in project springboot-manager by aitangbao.
the class DeptController method getDeptAll.
@GetMapping("/depts")
@ApiOperation(value = "获取机构列表接口")
@LogAnnotation(title = "机构管理", action = "获取所有组织机构")
@RequiresPermissions("sys:dept:list")
public DataResult getDeptAll() {
List<SysDept> deptList = deptService.list();
deptList.parallelStream().forEach(entity -> {
SysDept parentDept = deptService.getById(entity.getPid());
if (parentDept != null) {
entity.setPidName(parentDept.getName());
}
});
return DataResult.success(deptList);
}
Aggregations