From f62aa1f7f7f3426dcfb15b1dfaf26563e6386b9c Mon Sep 17 00:00:00 2001 From: hzj <826100833@qq.com> Date: Tue, 1 Jul 2025 11:03:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E7=89=88=E6=9C=AC=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GlobalBusinessExceptionHandler.java | 506 +++++++++--------- .../impl/LargeScreenCountServiceImpl.java | 10 + 2 files changed, 263 insertions(+), 253 deletions(-) diff --git a/event_smart/src/main/java/com/njcn/gather/event/transientes/handler/GlobalBusinessExceptionHandler.java b/event_smart/src/main/java/com/njcn/gather/event/transientes/handler/GlobalBusinessExceptionHandler.java index 4f117f15..67b60f3b 100644 --- a/event_smart/src/main/java/com/njcn/gather/event/transientes/handler/GlobalBusinessExceptionHandler.java +++ b/event_smart/src/main/java/com/njcn/gather/event/transientes/handler/GlobalBusinessExceptionHandler.java @@ -1,255 +1,255 @@ -//package com.njcn.gather.event.transientes.handler; -// -//import cn.hutool.core.text.StrFormatter; -//import cn.hutool.core.util.StrUtil; -//import com.njcn.common.pojo.enums.response.CommonResponseEnum; -//import com.njcn.common.pojo.exception.BusinessException; -//import com.njcn.common.pojo.response.HttpResult; -//import com.njcn.common.utils.LogUtil; -//import com.njcn.web.utils.HttpResultUtil; -//import com.njcn.web.utils.HttpServletUtil; -//import com.njcn.web.utils.ReflectCommonUtil; -//import lombok.AllArgsConstructor; -//import lombok.extern.slf4j.Slf4j; -//import org.json.JSONException; -//import org.springframework.validation.ObjectError; -//import org.springframework.web.HttpMediaTypeNotSupportedException; -//import org.springframework.web.bind.MethodArgumentNotValidException; -//import org.springframework.web.bind.annotation.ExceptionHandler; -//import org.springframework.web.bind.annotation.RestControllerAdvice; -//import org.springframework.web.util.NestedServletException; -// -//import javax.annotation.Resource; -//import javax.servlet.http.HttpServletRequest; -//import javax.validation.ConstraintViolation; -//import javax.validation.ConstraintViolationException; -//import java.util.ArrayList; -//import java.util.List; -//import java.util.concurrent.*; -//import java.util.stream.Collectors; -//import java.util.stream.Stream; -// -///** -// * 全局通用业务异常处理器 -// * -// * @author hongawen -// * @version 1.0.0 -// * @date 2021年04月20日 18:04 -// */ -//@Slf4j -//@AllArgsConstructor -//@RestControllerAdvice -//public class GlobalBusinessExceptionHandler { -// -// -// -// private final ThreadPoolExecutor executor = new ThreadPoolExecutor( -// 4, 8, 30, TimeUnit.SECONDS, -// new LinkedBlockingQueue<>(100), -// // 队列满时由主线程执行 -// new ThreadPoolExecutor.CallerRunsPolicy() -// ); -// -// -// /** -// * 捕获业务功能异常,通常为业务数据抛出的异常 -// * -// * @param businessException 业务异常 -// */ -// @ExceptionHandler(BusinessException.class) -// public HttpResult handleBusinessException(BusinessException businessException) { -// String operate = ReflectCommonUtil.getMethodDescribeByException(businessException); -// // recodeBusinessExceptionLog(businessException, businessException.getMessage()); -// return HttpResultUtil.assembleBusinessExceptionResult(businessException, null, operate); -// } -// -// -// /** -// * 空指针异常捕捉 -// * -// * @param nullPointerException 空指针异常 -// */ -// @ExceptionHandler(NullPointerException.class) -// public HttpResult handleNullPointerException(NullPointerException nullPointerException) { -// LogUtil.logExceptionStackInfo(CommonResponseEnum.NULL_POINTER_EXCEPTION.getMessage(), nullPointerException); -// //recodeBusinessExceptionLog(nullPointerException, CommonResponseEnum.NULL_POINTER_EXCEPTION.getMessage()); -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NULL_POINTER_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(nullPointerException)); -// } -// -// /** -// * 算数运算异常 -// * -// * @param arithmeticException 算数运算异常,由于除数为0引起的异常 -// */ -// @ExceptionHandler(ArithmeticException.class) -// public HttpResult handleArithmeticException(ArithmeticException arithmeticException) { -// LogUtil.logExceptionStackInfo(CommonResponseEnum.ARITHMETIC_EXCEPTION.getMessage(), arithmeticException); -// // recodeBusinessExceptionLog(arithmeticException, CommonResponseEnum.ARITHMETIC_EXCEPTION.getMessage()); -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.ARITHMETIC_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(arithmeticException)); -// } -// -// /** -// * 类型转换异常捕捉 -// * -// * @param classCastException 类型转换异常 -// */ -// @ExceptionHandler(ClassCastException.class) -// public HttpResult handleClassCastException(ClassCastException classCastException) { -// LogUtil.logExceptionStackInfo(CommonResponseEnum.CLASS_CAST_EXCEPTION.getMessage(), classCastException); -// // recodeBusinessExceptionLog(classCastException, CommonResponseEnum.CLASS_CAST_EXCEPTION.getMessage()); -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.CLASS_CAST_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(classCastException)); -// } -// -// -// /** -// * 索引下标越界异常捕捉 -// * -// * @param indexOutOfBoundsException 索引下标越界异常 -// */ -// @ExceptionHandler(IndexOutOfBoundsException.class) -// public HttpResult handleIndexOutOfBoundsException(IndexOutOfBoundsException indexOutOfBoundsException) { -// LogUtil.logExceptionStackInfo(CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION.getMessage(), indexOutOfBoundsException); -// // recodeBusinessExceptionLog(indexOutOfBoundsException, CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION.getMessage()); -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(indexOutOfBoundsException)); -// } -// -// /** -// * 前端请求后端,请求中参数的媒体方式不支持异常 -// * -// * @param httpMediaTypeNotSupportedException 请求中参数的媒体方式不支持异常 -// */ -// @ExceptionHandler(HttpMediaTypeNotSupportedException.class) -// public HttpResult httpMediaTypeNotSupportedExceptionHandler(HttpMediaTypeNotSupportedException httpMediaTypeNotSupportedException) { -// LogUtil.logExceptionStackInfo(CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION.getMessage(), httpMediaTypeNotSupportedException); -// // 然后提取错误提示信息进行返回 -// // recodeBusinessExceptionLog(httpMediaTypeNotSupportedException, CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION.getMessage()); -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(httpMediaTypeNotSupportedException)); -// } -// -// /** -// * 前端请求后端,参数校验异常捕捉 -// * RequestBody注解参数异常 -// * -// * @param methodArgumentNotValidException 参数校验异常 -// */ -// @ExceptionHandler(MethodArgumentNotValidException.class) -// public HttpResult methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException methodArgumentNotValidException) { -// // 从异常对象中拿到allErrors数据 -// String messages = methodArgumentNotValidException.getBindingResult().getAllErrors() -// .stream().map(ObjectError::getDefaultMessage).collect(Collectors.joining(";")); -// // 然后提取错误提示信息进行返回 -// LogUtil.njcnDebug(log, "参数校验异常,异常为:{}", messages); -// // recodeBusinessExceptionLog(methodArgumentNotValidException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage()); -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION, messages, ControllerUtil.getMethodArgumentNotValidException(methodArgumentNotValidException)); -// } -// -// /** -// * 前端请求后端,参数校验异常捕捉 -// * PathVariable注解、RequestParam注解参数异常 -// * -// * @param constraintViolationException 参数校验异常 -// */ -// @ExceptionHandler(ConstraintViolationException.class) -// public HttpResult constraintViolationExceptionExceptionHandler(ConstraintViolationException constraintViolationException) { -// String exceptionMessage = constraintViolationException.getMessage(); -// StringBuilder messages = new StringBuilder(); -// if (exceptionMessage.indexOf(StrUtil.COMMA) > 0) { -// String[] tempMessage = exceptionMessage.split(StrUtil.COMMA); -// Stream.of(tempMessage).forEach(message -> { -// messages.append(message.substring(message.indexOf(StrUtil.COLON) + 2)).append(';'); -// }); -// } else { -// messages.append(exceptionMessage.substring(exceptionMessage.indexOf(StrUtil.COLON) + 2)); -// } -// // 然后提取错误提示信息进行返回 -// LogUtil.njcnDebug(log, "参数校验异常,异常为:{}", messages); -// // recodeBusinessExceptionLog(constraintViolationException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage()); -// List> constraintViolationList = new ArrayList<>(constraintViolationException.getConstraintViolations()); -// ConstraintViolation constraintViolation = constraintViolationList.get(0); -// Class rootBeanClass = constraintViolation.getRootBeanClass(); -// //判断校验参数异常捕获的根源是controller还是service处 -// if (rootBeanClass.getName().endsWith("Controller")) { -// String methodName = constraintViolation.getPropertyPath().toString().substring(0, constraintViolation.getPropertyPath().toString().indexOf(StrUtil.DOT)); -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION, messages.toString(), ReflectCommonUtil.getMethodDescribeByClassAndMethodName(rootBeanClass, methodName)); -// } else { -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION, messages.toString(), ReflectCommonUtil.getMethodDescribeByException(constraintViolationException)); -// } -// -// } -// -// -// /** -// * 索引下标越界异常捕捉 -// * -// * @param illegalArgumentException 参数校验异常 -// */ -// @ExceptionHandler(IllegalArgumentException.class) -// public HttpResult handleIndexOutOfBoundsException(IllegalArgumentException illegalArgumentException) { -// LogUtil.logExceptionStackInfo(CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION.getMessage(), illegalArgumentException); -// // recodeBusinessExceptionLog(illegalArgumentException, CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION.getMessage()); -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION, illegalArgumentException.getMessage(), ReflectCommonUtil.getMethodDescribeByException(illegalArgumentException)); -// } -// -// -// /** -// * 未声明异常捕捉 -// * -// * @param exception 未声明异常 -// */ -// @ExceptionHandler(Exception.class) -// public HttpResult handleException(Exception exception) { -// //针对fallbackFactory降级异常特殊处理 -// Exception tempException = exception; -// String exceptionCause = CommonResponseEnum.UN_DECLARE.getMessage(); -// String code = CommonResponseEnum.UN_DECLARE.getCode(); -// if (exception instanceof NestedServletException) { -// Throwable cause = exception.getCause(); -// if (cause instanceof AssertionError) { -// if (cause.getCause() instanceof BusinessException) { -// tempException = (BusinessException) cause.getCause(); -// BusinessException tempBusinessException = (BusinessException) cause.getCause(); -// exceptionCause = tempBusinessException.getMessage(); -// code = tempBusinessException.getCode(); -// } +package com.njcn.gather.event.transientes.handler; + +import cn.hutool.core.text.StrFormatter; +import cn.hutool.core.util.StrUtil; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.LogUtil; +import com.njcn.web.utils.HttpResultUtil; +import com.njcn.web.utils.HttpServletUtil; +import com.njcn.web.utils.ReflectCommonUtil; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.json.JSONException; +import org.springframework.validation.ObjectError; +import org.springframework.web.HttpMediaTypeNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.util.NestedServletException; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * 全局通用业务异常处理器 + * + * @author hongawen + * @version 1.0.0 + * @date 2021年04月20日 18:04 + */ +@Slf4j +@AllArgsConstructor +@RestControllerAdvice +public class GlobalBusinessExceptionHandler { + + + + private final ThreadPoolExecutor executor = new ThreadPoolExecutor( + 4, 8, 30, TimeUnit.SECONDS, + new LinkedBlockingQueue<>(100), + // 队列满时由主线程执行 + new ThreadPoolExecutor.CallerRunsPolicy() + ); + + + /** + * 捕获业务功能异常,通常为业务数据抛出的异常 + * + * @param businessException 业务异常 + */ + @ExceptionHandler(BusinessException.class) + public HttpResult handleBusinessException(BusinessException businessException) { + String operate = ReflectCommonUtil.getMethodDescribeByException(businessException); + // recodeBusinessExceptionLog(businessException, businessException.getMessage()); + return HttpResultUtil.assembleBusinessExceptionResult(businessException, null, operate); + } + + + /** + * 空指针异常捕捉 + * + * @param nullPointerException 空指针异常 + */ + @ExceptionHandler(NullPointerException.class) + public HttpResult handleNullPointerException(NullPointerException nullPointerException) { + LogUtil.logExceptionStackInfo(CommonResponseEnum.NULL_POINTER_EXCEPTION.getMessage(), nullPointerException); + //recodeBusinessExceptionLog(nullPointerException, CommonResponseEnum.NULL_POINTER_EXCEPTION.getMessage()); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NULL_POINTER_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(nullPointerException)); + } + + /** + * 算数运算异常 + * + * @param arithmeticException 算数运算异常,由于除数为0引起的异常 + */ + @ExceptionHandler(ArithmeticException.class) + public HttpResult handleArithmeticException(ArithmeticException arithmeticException) { + LogUtil.logExceptionStackInfo(CommonResponseEnum.ARITHMETIC_EXCEPTION.getMessage(), arithmeticException); + // recodeBusinessExceptionLog(arithmeticException, CommonResponseEnum.ARITHMETIC_EXCEPTION.getMessage()); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.ARITHMETIC_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(arithmeticException)); + } + + /** + * 类型转换异常捕捉 + * + * @param classCastException 类型转换异常 + */ + @ExceptionHandler(ClassCastException.class) + public HttpResult handleClassCastException(ClassCastException classCastException) { + LogUtil.logExceptionStackInfo(CommonResponseEnum.CLASS_CAST_EXCEPTION.getMessage(), classCastException); + // recodeBusinessExceptionLog(classCastException, CommonResponseEnum.CLASS_CAST_EXCEPTION.getMessage()); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.CLASS_CAST_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(classCastException)); + } + + + /** + * 索引下标越界异常捕捉 + * + * @param indexOutOfBoundsException 索引下标越界异常 + */ + @ExceptionHandler(IndexOutOfBoundsException.class) + public HttpResult handleIndexOutOfBoundsException(IndexOutOfBoundsException indexOutOfBoundsException) { + LogUtil.logExceptionStackInfo(CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION.getMessage(), indexOutOfBoundsException); + // recodeBusinessExceptionLog(indexOutOfBoundsException, CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION.getMessage()); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(indexOutOfBoundsException)); + } + + /** + * 前端请求后端,请求中参数的媒体方式不支持异常 + * + * @param httpMediaTypeNotSupportedException 请求中参数的媒体方式不支持异常 + */ + @ExceptionHandler(HttpMediaTypeNotSupportedException.class) + public HttpResult httpMediaTypeNotSupportedExceptionHandler(HttpMediaTypeNotSupportedException httpMediaTypeNotSupportedException) { + LogUtil.logExceptionStackInfo(CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION.getMessage(), httpMediaTypeNotSupportedException); + // 然后提取错误提示信息进行返回 + // recodeBusinessExceptionLog(httpMediaTypeNotSupportedException, CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION.getMessage()); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(httpMediaTypeNotSupportedException)); + } + + /** + * 前端请求后端,参数校验异常捕捉 + * RequestBody注解参数异常 + * + * @param methodArgumentNotValidException 参数校验异常 + */ + @ExceptionHandler(MethodArgumentNotValidException.class) + public HttpResult methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException methodArgumentNotValidException) { + // 从异常对象中拿到allErrors数据 + String messages = methodArgumentNotValidException.getBindingResult().getAllErrors() + .stream().map(ObjectError::getDefaultMessage).collect(Collectors.joining(";")); + // 然后提取错误提示信息进行返回 + LogUtil.njcnDebug(log, "参数校验异常,异常为:{}", messages); + // recodeBusinessExceptionLog(methodArgumentNotValidException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage()); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION, messages, ControllerUtil.getMethodArgumentNotValidException(methodArgumentNotValidException)); + } + + /** + * 前端请求后端,参数校验异常捕捉 + * PathVariable注解、RequestParam注解参数异常 + * + * @param constraintViolationException 参数校验异常 + */ + @ExceptionHandler(ConstraintViolationException.class) + public HttpResult constraintViolationExceptionExceptionHandler(ConstraintViolationException constraintViolationException) { + String exceptionMessage = constraintViolationException.getMessage(); + StringBuilder messages = new StringBuilder(); + if (exceptionMessage.indexOf(StrUtil.COMMA) > 0) { + String[] tempMessage = exceptionMessage.split(StrUtil.COMMA); + Stream.of(tempMessage).forEach(message -> { + messages.append(message.substring(message.indexOf(StrUtil.COLON) + 2)).append(';'); + }); + } else { + messages.append(exceptionMessage.substring(exceptionMessage.indexOf(StrUtil.COLON) + 2)); + } + // 然后提取错误提示信息进行返回 + LogUtil.njcnDebug(log, "参数校验异常,异常为:{}", messages); + // recodeBusinessExceptionLog(constraintViolationException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage()); + List> constraintViolationList = new ArrayList<>(constraintViolationException.getConstraintViolations()); + ConstraintViolation constraintViolation = constraintViolationList.get(0); + Class rootBeanClass = constraintViolation.getRootBeanClass(); + //判断校验参数异常捕获的根源是controller还是service处 + if (rootBeanClass.getName().endsWith("Controller")) { + String methodName = constraintViolation.getPropertyPath().toString().substring(0, constraintViolation.getPropertyPath().toString().indexOf(StrUtil.DOT)); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION, messages.toString(), ReflectCommonUtil.getMethodDescribeByClassAndMethodName(rootBeanClass, methodName)); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION, messages.toString(), ReflectCommonUtil.getMethodDescribeByException(constraintViolationException)); + } + + } + + + /** + * 索引下标越界异常捕捉 + * + * @param illegalArgumentException 参数校验异常 + */ + @ExceptionHandler(IllegalArgumentException.class) + public HttpResult handleIndexOutOfBoundsException(IllegalArgumentException illegalArgumentException) { + LogUtil.logExceptionStackInfo(CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION.getMessage(), illegalArgumentException); + // recodeBusinessExceptionLog(illegalArgumentException, CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION.getMessage()); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION, illegalArgumentException.getMessage(), ReflectCommonUtil.getMethodDescribeByException(illegalArgumentException)); + } + + + /** + * 未声明异常捕捉 + * + * @param exception 未声明异常 + */ + @ExceptionHandler(Exception.class) + public HttpResult handleException(Exception exception) { + //针对fallbackFactory降级异常特殊处理 + Exception tempException = exception; + String exceptionCause = CommonResponseEnum.UN_DECLARE.getMessage(); + String code = CommonResponseEnum.UN_DECLARE.getCode(); + if (exception instanceof NestedServletException) { + Throwable cause = exception.getCause(); + if (cause instanceof AssertionError) { + if (cause.getCause() instanceof BusinessException) { + tempException = (BusinessException) cause.getCause(); + BusinessException tempBusinessException = (BusinessException) cause.getCause(); + exceptionCause = tempBusinessException.getMessage(); + code = tempBusinessException.getCode(); + } + } + } + LogUtil.logExceptionStackInfo(exceptionCause, tempException); + // recodeBusinessExceptionLog(exception, exceptionCause); + //判断方法上是否有自定义注解,做特殊处理 +// Method method = ReflectCommonUtil.getMethod(exception); +// if (!Objects.isNull(method)){ +// if(method.isAnnotationPresent(ReturnMsg.class)){ +// return HttpResultUtil.assembleResult(code, null, StrFormatter.format("{}",exceptionCause)); // } // } -// LogUtil.logExceptionStackInfo(exceptionCause, tempException); -// // recodeBusinessExceptionLog(exception, exceptionCause); -// //判断方法上是否有自定义注解,做特殊处理 -//// Method method = ReflectCommonUtil.getMethod(exception); -//// if (!Objects.isNull(method)){ -//// if(method.isAnnotationPresent(ReturnMsg.class)){ -//// return HttpResultUtil.assembleResult(code, null, StrFormatter.format("{}",exceptionCause)); -//// } -//// } -// return HttpResultUtil.assembleResult(code, null, StrFormatter.format("{}{}{}", ReflectCommonUtil.getMethodDescribeByException(tempException), StrUtil.C_COMMA, exceptionCause)); -// } -// -// -// /** -// * json解析异常 -// * -// * @param jsonException json参数 -// */ -// @ExceptionHandler(JSONException.class) -// public HttpResult handleIndexOutOfBoundsException(JSONException jsonException) { -// LogUtil.logExceptionStackInfo(CommonResponseEnum.JSON_CONVERT_EXCEPTION.getMessage(), jsonException); -// // recodeBusinessExceptionLog(jsonException, CommonResponseEnum.JSON_CONVERT_EXCEPTION.getMessage()); -// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.JSON_CONVERT_EXCEPTION, jsonException.getMessage(), ReflectCommonUtil.getMethodDescribeByException(jsonException)); -// } -///* -// private void recodeBusinessExceptionLog(Exception businessException, String methodDescribe) { -// HttpServletRequest httpServletRequest = HttpServletUtil.getRequest(); -// Future future = executor.submit(() -> { -// HttpServletUtil.setRequest(httpServletRequest); -// sysLogAuditService.recodeBusinessExceptionLog(businessException, methodDescribe); -// }); -// try { -// // 抛出 ExecutionException -// future.get(); -// } catch (ExecutionException | InterruptedException e) { -// log.error("保存审计日志异常,异常为:" + e.getMessage()); -// } -// }*/ -// -//} + return HttpResultUtil.assembleResult(code, null, StrFormatter.format("{}{}{}", ReflectCommonUtil.getMethodDescribeByException(tempException), StrUtil.C_COMMA, exceptionCause)); + } + + + /** + * json解析异常 + * + * @param jsonException json参数 + */ + @ExceptionHandler(JSONException.class) + public HttpResult handleIndexOutOfBoundsException(JSONException jsonException) { + LogUtil.logExceptionStackInfo(CommonResponseEnum.JSON_CONVERT_EXCEPTION.getMessage(), jsonException); + // recodeBusinessExceptionLog(jsonException, CommonResponseEnum.JSON_CONVERT_EXCEPTION.getMessage()); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.JSON_CONVERT_EXCEPTION, jsonException.getMessage(), ReflectCommonUtil.getMethodDescribeByException(jsonException)); + } +/* + private void recodeBusinessExceptionLog(Exception businessException, String methodDescribe) { + HttpServletRequest httpServletRequest = HttpServletUtil.getRequest(); + Future future = executor.submit(() -> { + HttpServletUtil.setRequest(httpServletRequest); + sysLogAuditService.recodeBusinessExceptionLog(businessException, methodDescribe); + }); + try { + // 抛出 ExecutionException + future.get(); + } catch (ExecutionException | InterruptedException e) { + log.error("保存审计日志异常,异常为:" + e.getMessage()); + } + }*/ + +} diff --git a/event_smart/src/main/java/com/njcn/gather/event/transientes/service/impl/LargeScreenCountServiceImpl.java b/event_smart/src/main/java/com/njcn/gather/event/transientes/service/impl/LargeScreenCountServiceImpl.java index 20a65cc9..61c4a05e 100644 --- a/event_smart/src/main/java/com/njcn/gather/event/transientes/service/impl/LargeScreenCountServiceImpl.java +++ b/event_smart/src/main/java/com/njcn/gather/event/transientes/service/impl/LargeScreenCountServiceImpl.java @@ -53,6 +53,7 @@ import java.time.LocalDateTime; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Description: @@ -81,6 +82,7 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService { private final PqsUsersetService pqsUsersetService; private final PqsUserService pqsUserService; private final PqLinedetailMapper pqLinedetailMapper; + private final List WAVETYPE_LIST= Stream.of(1,3).collect(Collectors.toList()); @Value("${SYS_TYPE_ZT}") private String sysTypeZt; @@ -183,12 +185,14 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService { for(List itemIds : listIds){ List temp = pqsEventdetailService.lambdaQuery() .between(PqsEventdetail::getTimeid,startTime, endTime) + .in(PqsEventdetail::getWavetype,WAVETYPE_LIST) .in(PqsEventdetail::getLineid,listIds).list(); eventdetails.addAll(temp); } }else { List temp = pqsEventdetailService.lambdaQuery() .between(PqsEventdetail::getTimeid, startTime, endTime) + .in(PqsEventdetail::getWavetype,WAVETYPE_LIST) .in(PqsEventdetail::getLineid,deptslineIds).list(); eventdetails.addAll(temp); } @@ -286,12 +290,14 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService { for(List itemIds : listIds){ List temp = pqsEventdetailService.lambdaQuery() .between(PqsEventdetail::getTimeid, startTime, endTime) + .in(PqsEventdetail::getWavetype,WAVETYPE_LIST) .in(PqsEventdetail::getLineid,listIds).list(); eventdetails.addAll(temp); } }else { List temp = pqsEventdetailService.lambdaQuery() .between(PqsEventdetail::getTimeid, startTime, endTime) + .in(PqsEventdetail::getWavetype,WAVETYPE_LIST) .in(PqsEventdetail::getLineid,deptslineIds).list(); eventdetails.addAll(temp); } @@ -382,6 +388,7 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService { queryWrapper.lambda() .between(PqsEventdetail::getTimeid, startTime, endTime) + .in(PqsEventdetail::getWavetype,WAVETYPE_LIST) .and(ew->{ for(List pList: idPartitions){ ew.or(w->w.in(PqsEventdetail::getLineid, pList)); @@ -393,6 +400,7 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService { queryWrapper.lambda() .between(PqsEventdetail::getTimeid, startTime, endTime) .in(PqsEventdetail::getLineid, deptslineIds) + .in(PqsEventdetail::getWavetype,WAVETYPE_LIST) .orderByDesc(PqsEventdetail::getTimeid); } //查询需要发送短息处理的部门反推监测点 @@ -473,6 +481,7 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.between(PqsEventdetail::getTimeid, startTime, endTime) .in(PqsEventdetail::getLineid, deptslineIds) + .in(PqsEventdetail::getWavetype,WAVETYPE_LIST) .and(wrapper -> wrapper.eq(PqsEventdetail::getLookFlag, 0).or().isNull(PqsEventdetail::getLookFlag)); if (Objects.nonNull(largeScreenCountParam.getEventDeep())) { if (largeScreenCountParam.getEventDeep() == 0) { @@ -556,6 +565,7 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService { List deptslineIds = v.stream().map(PqsDeptsline::getLineIndex).collect(Collectors.toList()); List eventdetails = pqsEventdetailService.lambdaQuery() .between(PqsEventdetail::getTimeid, startTime, endTime) + .in(PqsEventdetail::getWavetype,WAVETYPE_LIST) .in(PqsEventdetail::getLineid, deptslineIds).list(); mapCountVO.setEventCount(eventdetails.size()); List change = change(eventdetails);