Search in sources :

Example 6 with LogAnnotation

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();
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysPermission(com.company.project.entity.SysPermission) LogAnnotation(com.company.project.common.aop.annotation.LogAnnotation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with LogAnnotation

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LogAnnotation(com.company.project.common.aop.annotation.LogAnnotation) MethodSignature(org.aspectj.lang.reflect.MethodSignature) SysLog(com.company.project.entity.SysLog) Method(java.lang.reflect.Method)

Example 8 with LogAnnotation

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);
}
Also used : ArrayList(java.util.ArrayList) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) LogAnnotation(com.company.project.common.aop.annotation.LogAnnotation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Example 9 with LogAnnotation

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();
}
Also used : Subject(org.apache.shiro.subject.Subject) LogAnnotation(com.company.project.common.aop.annotation.LogAnnotation) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with LogAnnotation

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);
}
Also used : SysDept(com.company.project.entity.SysDept) LogAnnotation(com.company.project.common.aop.annotation.LogAnnotation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

LogAnnotation (com.company.project.common.aop.annotation.LogAnnotation)12 ApiOperation (io.swagger.annotations.ApiOperation)11 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)10 DataResult (com.company.project.common.utils.DataResult)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)2 SysLog (com.company.project.entity.SysLog)2 SysRole (com.company.project.entity.SysRole)2 ArrayList (java.util.ArrayList)2 BusinessException (com.company.project.common.exception.BusinessException)1 SysDept (com.company.project.entity.SysDept)1 SysPermission (com.company.project.entity.SysPermission)1 SysRoleDeptEntity (com.company.project.entity.SysRoleDeptEntity)1 SysUserRole (com.company.project.entity.SysUserRole)1 UserRoleOperationReqVO (com.company.project.vo.req.UserRoleOperationReqVO)1 Method (java.lang.reflect.Method)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Subject (org.apache.shiro.subject.Subject)1