From 485880458e0fbf674ca30662739fcb3bbe8946e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Wed, 19 Apr 2023 16:05:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20aop=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/common/logs/aop/SysLogAspect.java | 25 +++++++++++++++---- .../web/AreaMonthlyDetailsController.java | 4 ++-- .../processflow/strategy/core/ProcessIdWorker.java | 28 ---------------------- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/logs/aop/SysLogAspect.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/logs/aop/SysLogAspect.java index 47884ef..bcecd2b 100644 --- a/hzims-biz-common/src/main/java/com/hnac/hzims/common/logs/aop/SysLogAspect.java +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/logs/aop/SysLogAspect.java @@ -50,7 +50,7 @@ public class SysLogAspect { @Autowired - private SysLogQueue sysLogQueue; + private SysLogQueue sysLogQueue; /** * 请求地址 @@ -75,6 +75,17 @@ public class SysLogAspect { /** + * 开始时间 + */ + private Long startTime = 0L; + + /** + * 结束时间 + */ + private Long endTime = 0L; + + + /** * 设置操作日志切入点 在注解的位置切入代码 */ @Pointcut("@annotation(com.hnac.hzims.common.logs.annotation.OperationAnnotation)") @@ -87,7 +98,10 @@ public class SysLogAspect { */ @Before(value = "logPointCut()") public void before(JoinPoint joinPoint) { - stopWatch.start(); + // if (!stopWatch.isRunning()) { + // stopWatch.start(); + // } + startTime = System.currentTimeMillis(); log.info("前置通知"); } @@ -224,8 +238,11 @@ public class SysLogAspect { sysLog.setOperationUserId(userId); sysLog.setTenantId(Func.toStr(AuthUtil.getTenantId(), BladeConstant.ADMIN_TENANT_ID)); sysLog.setLocalIp(WebUtil.getIP(request));// 请求IP - stopWatch.stop(); - sysLog.setCostTime(stopWatch.getTotalTimeMillis() + "ms"); + // if (stopWatch.isRunning()) { + // stopWatch.stop(); + // } + endTime = System.currentTimeMillis(); + sysLog.setCostTime((endTime - startTime) + "ms"); sysLog.setPath(requestPath); sysLog.setTitle(title); sysLog.setAction(action); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java index 17c2874..79e2618 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java @@ -207,7 +207,7 @@ public class AreaMonthlyDetailsController { @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, OperPhenomenonEntity entity, String taskIds, Date findTimeEnd) { Page operDefectEntityPage = new Page<>(page, size); - LambdaQueryWrapper queryWrapper = Condition.getQueryWrapper(new OperPhenomenonEntity(), entity); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if (StringUtil.isNotBlank(taskIds)) { queryWrapper.in(OperPhenomenonEntity::getId, Lists.newArrayList(taskIds.split(","))); } @@ -222,7 +222,7 @@ public class AreaMonthlyDetailsController { } // 区域Id if (Func.isNotEmpty(entity.getAreaId())) { - queryWrapper.eq(OperPhenomenonEntity::getCreateDept, entity.getAreaId()); + queryWrapper.eq(OperPhenomenonEntity::getCreateDept, Long.valueOf(entity.getAreaId())); } // 年份 if (Func.isNotEmpty(entity.getYearMonth())) { diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/processflow/strategy/core/ProcessIdWorker.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/processflow/strategy/core/ProcessIdWorker.java index 70aafab..e29a875 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/processflow/strategy/core/ProcessIdWorker.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/processflow/strategy/core/ProcessIdWorker.java @@ -184,32 +184,4 @@ public class ProcessIdWorker { private AtomicInteger sequencing = new AtomicInteger(1); } - public static void main(String[] args) { - - // TicketIdWorker standardTicketIdWorker = new TicketIdWorker(); - // int count = 1; - // while (count <= 1000) { - // - // System.out.println("1 ===> " + standardTicketIdWorker.getTicketCode("aa", "bb", "2304")); - // System.out.println("================================="); - // //System.out.println("2 ===》" + standardTicketIdWorker.getTicketCode("aa", "bb", "2204")); - // count++; - // - // } - - // NumberFormat numberFormatter = NumberFormat.getInstance(); - // numberFormatter.setGroupingUsed(false); - // numberFormatter.setMinimumIntegerDigits(3); - // numberFormatter.setMaximumFractionDigits(3); - // - // String format = numberFormatter.format(2); - // System.out.println(format); - - - String msg = "2021"; - String substring = msg.substring(msg.length() - 2); - System.out.println(substring); - } - - } From 5ab8e62bccfbbe98e0778b6939273b5a1a75dcf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Wed, 19 Apr 2023 16:26:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20aop=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/common/logs/aop/SysLogAspect.java | 66 +++++++++------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/logs/aop/SysLogAspect.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/logs/aop/SysLogAspect.java index bcecd2b..75e217c 100644 --- a/hzims-biz-common/src/main/java/com/hnac/hzims/common/logs/aop/SysLogAspect.java +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/logs/aop/SysLogAspect.java @@ -18,6 +18,7 @@ import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.WebUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.NamedThreadLocal; import org.springframework.stereotype.Component; import org.springframework.util.StopWatch; import org.springframework.web.context.request.RequestAttributes; @@ -52,37 +53,10 @@ public class SysLogAspect { @Autowired private SysLogQueue sysLogQueue; - /** - * 请求地址 - */ - private String requestPath = null; - - /** - * 操作人 - */ - private String userName = null; - - /** - * 请求 - */ - private HttpServletRequest request = null; - - private Long userId = -1L; + //private StopWatch stopWatch = new StopWatch(); - - private StopWatch stopWatch = new StopWatch(); - - - /** - * 开始时间 - */ - private Long startTime = 0L; - - /** - * 结束时间 - */ - private Long endTime = 0L; + private static final ThreadLocal TIME_THREADLOCAL = new NamedThreadLocal<>("Cost Time"); /** @@ -101,7 +75,8 @@ public class SysLogAspect { // if (!stopWatch.isRunning()) { // stopWatch.start(); // } - startTime = System.currentTimeMillis(); + //startTime = System.currentTimeMillis(); + TIME_THREADLOCAL.set(System.currentTimeMillis()); log.info("前置通知"); } @@ -112,8 +87,14 @@ public class SysLogAspect { @AfterReturning(value = "logPointCut()", returning = "jsonResult") public void after(JoinPoint joinPoint, Object jsonResult) { log.info("=========返回通知=============="); - request = getHttpServletRequest(); - handleLog(joinPoint, jsonResult, null); + try { + handleLog(joinPoint, jsonResult, null); + } catch (Exception e) { + log.error("异常信息:{}", e.getMessage()); + e.printStackTrace(); + } finally { + TIME_THREADLOCAL.remove(); + } } @@ -153,7 +134,14 @@ public class SysLogAspect { @AfterThrowing(pointcut = "logPointCut()", throwing = "e") public void throwing(JoinPoint joinPoint, Exception e) { log.info("=========异常通知=============="); - handleLog(joinPoint, null, e); + try { + handleLog(joinPoint, null, e); + } catch (Exception exception) { + log.error("异常信息:{}", exception.getMessage()); + e.printStackTrace(); + } finally { + TIME_THREADLOCAL.remove(); + } } @@ -218,8 +206,8 @@ public class SysLogAspect { // 获取请求的类名 String className = joinPoint.getTarget().getClass().getName(); methodName = className + "." + methodName; - request = getHttpServletRequest(); - requestPath = request.getServletPath(); + HttpServletRequest request = getHttpServletRequest(); + String requestPath = request.getServletPath(); OperationAnnotation annotation = method.getAnnotation(OperationAnnotation.class); title = annotation.title(); action = annotation.action(); @@ -227,8 +215,8 @@ public class SysLogAspect { operatorType = annotation.operatorType().getValue(); moduleName = annotation.moduleName(); // 获取当前用户信息 - userName = AuthUtil.getUserAccount(request); - userId = AuthUtil.getUserId(request); + String userName = AuthUtil.getUserAccount(request); + Long userId = AuthUtil.getUserId(request); SysLogTo sysLog = new SysLogTo(); if (StringUtils.isBlank(userName) && userId == -1) { userName = "当前用户未登录"; @@ -241,8 +229,8 @@ public class SysLogAspect { // if (stopWatch.isRunning()) { // stopWatch.stop(); // } - endTime = System.currentTimeMillis(); - sysLog.setCostTime((endTime - startTime) + "ms"); + long endTime = System.currentTimeMillis(); + sysLog.setCostTime((endTime - TIME_THREADLOCAL.get()) + "ms"); sysLog.setPath(requestPath); sysLog.setTitle(title); sysLog.setAction(action);