From 5e536dc8122bd3dbe79746e0ed12a391504e5a90 Mon Sep 17 00:00:00 2001 From: dinggang <2498628697@qq.com> Date: Thu, 23 Jun 2022 18:43:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E3=80=81=E6=93=8D=E4=BD=9C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=8D=87=E7=BA=A7=EF=BC=9A=201.=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=96=B0=E5=A2=9E=E8=BF=94=E5=9B=9E=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=AD=97=E6=AE=B5=202.=E6=97=A5=E5=BF=97=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=A2=9E=E5=8A=A0=E6=94=AF=E6=8C=81=E6=8C=89=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E4=BA=BA=EF=BC=8C=E6=93=8D=E4=BD=9C=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=8F=8A=E6=93=8D=E4=BD=9C=E5=90=8D=E7=A7=B0=E6=9D=A5=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=203.=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8E=A5=E5=8F=A3=EF=BC=88=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=EF=BC=89=20=E4=BA=8C=E3=80=81=E7=BB=99=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=96=B9=E6=B3=95=E5=8A=A0=E4=B8=8A=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E8=AE=B0=E5=BD=95=E6=97=A5=E5=BF=97=20?= =?UTF-8?q?=E4=B8=89=E3=80=81=E6=97=A5=E5=BF=97=E8=A1=A8sql=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/aspect/LogOperationAspect.java | 8 ++++---- .../controller/SysLogOperationController.java | 20 +++++++++++++++++-- .../log/entity/SysLogOperationEntity.java | 4 ++++ .../impl/SysLogOperationServiceImpl.java | 9 ++++++++- .../controller/ResourceController.java | 3 +++ .../resource/entity/ResourceEntity.java | 1 - .../security/controller/LoginController.java | 3 +++ .../db/V2.0__sys_log_operation_add_col.sql | 1 + .../java/io/renren/common/utils/Result.java | 9 +++++++++ 9 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 renren-admin/src/main/resources/db/V2.0__sys_log_operation_add_col.sql diff --git a/renren-admin/src/main/java/io/renren/common/aspect/LogOperationAspect.java b/renren-admin/src/main/java/io/renren/common/aspect/LogOperationAspect.java index 84bd889f..648156e5 100644 --- a/renren-admin/src/main/java/io/renren/common/aspect/LogOperationAspect.java +++ b/renren-admin/src/main/java/io/renren/common/aspect/LogOperationAspect.java @@ -42,24 +42,23 @@ public class LogOperationAspect { try { //执行方法 Object result = point.proceed(); - //执行时长(毫秒) long time = System.currentTimeMillis() - beginTime; //保存日志 - saveLog(point, time, OperationStatusEnum.SUCCESS.value()); + saveLog(point, time, OperationStatusEnum.SUCCESS.value(), result); return result; }catch(Exception e) { //执行时长(毫秒) long time = System.currentTimeMillis() - beginTime; //保存日志 - saveLog(point, time, OperationStatusEnum.FAIL.value()); + saveLog(point, time, OperationStatusEnum.FAIL.value(), null); throw e; } } - private void saveLog(ProceedingJoinPoint joinPoint, long time, Integer status) throws Exception { + private void saveLog(ProceedingJoinPoint joinPoint, long time, Integer status, Object result) throws Exception { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = joinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes()); LogOperation annotation = method.getAnnotation(LogOperation.class); @@ -78,6 +77,7 @@ public class LogOperationAspect { log.setStatus(status); log.setRequestTime((int)time); + log.setResultData(JSON.toJSONString(result)); //请求相关信息 HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); diff --git a/renren-admin/src/main/java/io/renren/modules/log/controller/SysLogOperationController.java b/renren-admin/src/main/java/io/renren/modules/log/controller/SysLogOperationController.java index 2aca3abc..0e317de5 100644 --- a/renren-admin/src/main/java/io/renren/modules/log/controller/SysLogOperationController.java +++ b/renren-admin/src/main/java/io/renren/modules/log/controller/SysLogOperationController.java @@ -12,7 +12,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -44,7 +43,11 @@ public class SysLogOperationController { @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") , - @ApiImplicitParam(name = "status", value = "状态 0:失败 1:成功", paramType = "query", dataType="int") + @ApiImplicitParam(name = "status", value = "状态 0:失败 1:成功", paramType = "query", dataType="int"), + @ApiImplicitParam(name = "creatorName", value = "操作人", paramType = "query", dataType="String"), + @ApiImplicitParam(name = "startDate", value = "开始时间", paramType = "query", dataType="String"), + @ApiImplicitParam(name = "endDate", value = "结束时间", paramType = "query", dataType="String"), + @ApiImplicitParam(name = "operation", value = "操作名称", paramType = "query", dataType="String") }) // @RequiresPermissions("sys:log:operation") public Result> page(@ApiIgnore @RequestParam Map params){ @@ -53,6 +56,19 @@ public class SysLogOperationController { return new Result>().ok(page); } + + @GetMapping("/deleteByIds") + @ApiOperation("/删除操作记录") + @LogOperation("/删除操作记录") + public Result deleteByIds(List ids) { + try { + sysLogOperationService.deleteBatchIds(ids); + return new Result().ok(null); + } catch (Exception e) { + return new Result().error(e.getMessage()); + } + } + @GetMapping("export") @ApiOperation("导出") @LogOperation("导出") diff --git a/renren-admin/src/main/java/io/renren/modules/log/entity/SysLogOperationEntity.java b/renren-admin/src/main/java/io/renren/modules/log/entity/SysLogOperationEntity.java index 3b7899ed..df34bb34 100644 --- a/renren-admin/src/main/java/io/renren/modules/log/entity/SysLogOperationEntity.java +++ b/renren-admin/src/main/java/io/renren/modules/log/entity/SysLogOperationEntity.java @@ -52,4 +52,8 @@ public class SysLogOperationEntity extends BaseEntity { * 用户名 */ private String creatorName; + /** + * 返回结果 + */ + private String resultData; } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/log/service/impl/SysLogOperationServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/log/service/impl/SysLogOperationServiceImpl.java index a1390bc1..501496fc 100644 --- a/renren-admin/src/main/java/io/renren/modules/log/service/impl/SysLogOperationServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/log/service/impl/SysLogOperationServiceImpl.java @@ -45,9 +45,16 @@ public class SysLogOperationServiceImpl extends BaseServiceImpl getWrapper(Map params) { String status = (String) params.get("status"); + String creatorName = (String) params.get("creatorName"); + String operation = (String) params.get("operation"); + String startDate = (String) params.get("startDate"); + String endDate = (String) params.get("endDate"); QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq(StringUtils.isNotBlank(status), "status", status); + wrapper.eq(StringUtils.isNotBlank(status), "status", status) + .eq(StringUtils.isNotBlank(creatorName), "creator_name", creatorName) + .like(StringUtils.isNotBlank(operation), "operation", operation) + .between(StringUtils.isNotBlank(startDate), "", startDate, endDate); return wrapper; } diff --git a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java index 697be96d..daea105a 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java @@ -105,6 +105,7 @@ public class ResourceController { @GetMapping("/page") @ApiOperation("分页查询资源信息") + @LogOperation("分页查询资源信息") @ApiImplicitParams({ @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType = "int"), @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"), @@ -416,6 +417,8 @@ public class ResourceController { */ @GetMapping("/hls/getHls") + @ApiOperation("获取hls地址") + @LogOperation("获取hls地址") public Result getHls(String key) { Optional factory = VideoPreviewFactory.build(); if (factory.isPresent()) { diff --git a/renren-admin/src/main/java/io/renren/modules/resource/entity/ResourceEntity.java b/renren-admin/src/main/java/io/renren/modules/resource/entity/ResourceEntity.java index 92100b79..f4c9ffc6 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/entity/ResourceEntity.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/entity/ResourceEntity.java @@ -87,7 +87,6 @@ public class ResourceEntity extends BaseEntity { * 删除标志:0:正常;1:已删除;9其他 */ private Integer delFlag; - /** * 修改人 */ diff --git a/renren-admin/src/main/java/io/renren/modules/security/controller/LoginController.java b/renren-admin/src/main/java/io/renren/modules/security/controller/LoginController.java index a95f1438..43552c1e 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/controller/LoginController.java +++ b/renren-admin/src/main/java/io/renren/modules/security/controller/LoginController.java @@ -1,5 +1,6 @@ package io.renren.modules.security.controller; +import io.renren.common.annotation.LogOperation; import io.renren.common.constant.Constant; import io.renren.common.exception.ErrorCode; import io.renren.common.exception.RenException; @@ -74,6 +75,7 @@ public class LoginController { @GetMapping("login") @ApiOperation(value = "登录") + @LogOperation("登录") @ApiImplicitParams({ @ApiImplicitParam(name = "username", value = "登录名称", paramType = "query", required = true, dataType = "String"), @ApiImplicitParam(name = "password", value = "密码", paramType = "query", required = true, dataType = "String"), @@ -150,6 +152,7 @@ public class LoginController { @PostMapping("logout") @ApiOperation(value = "退出") + @LogOperation("/退出") public Result logout(HttpServletRequest request, HttpServletResponse response) { UserDetail user = SecurityUser.getUser(); diff --git a/renren-admin/src/main/resources/db/V2.0__sys_log_operation_add_col.sql b/renren-admin/src/main/resources/db/V2.0__sys_log_operation_add_col.sql new file mode 100644 index 00000000..f47b6408 --- /dev/null +++ b/renren-admin/src/main/resources/db/V2.0__sys_log_operation_add_col.sql @@ -0,0 +1 @@ +ALTER TABLE sys_log_operation ADD COLUMN result_data text NULL COMMENT '返回结果'; \ No newline at end of file diff --git a/renren-common/src/main/java/io/renren/common/utils/Result.java b/renren-common/src/main/java/io/renren/common/utils/Result.java index 80f92bf7..216fa5e2 100644 --- a/renren-common/src/main/java/io/renren/common/utils/Result.java +++ b/renren-common/src/main/java/io/renren/common/utils/Result.java @@ -86,4 +86,13 @@ public class Result implements Serializable { public void setData(T data) { this.data = data; } + + @Override + public String toString() { + return "Result{" + + "code=" + code + + ", msg='" + msg + '\'' + + ", data=" + data + + '}'; + } }