diff --git a/event_smart/pom.xml b/event_smart/pom.xml index c4a35093..d37fe80a 100644 --- a/event_smart/pom.xml +++ b/event_smart/pom.xml @@ -100,17 +100,21 @@ 1.0.0 + common-microservice com.njcn - common-echarts + common-web com.njcn - common-oss - + + com.google.guava + guava + 32.1.3-jre + diff --git a/event_smart/src/main/java/com/njcn/gather/event/EventSmartApplication.java b/event_smart/src/main/java/com/njcn/gather/event/EventSmartApplication.java index 48b6c3ae..c6746a64 100644 --- a/event_smart/src/main/java/com/njcn/gather/event/EventSmartApplication.java +++ b/event_smart/src/main/java/com/njcn/gather/event/EventSmartApplication.java @@ -1,12 +1,17 @@ package com.njcn.gather.event; +import com.njcn.event.file.component.WavePicComponent; import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; @Slf4j -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.njcn") +//@ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = WavePicComponent.class)) @MapperScan("com.njcn.**.mapper") public class EventSmartApplication { diff --git a/event_smart/src/main/java/com/njcn/gather/event/transientes/controller/EventGateController.java b/event_smart/src/main/java/com/njcn/gather/event/transientes/controller/EventGateController.java index 2bc9a401..a58041a7 100644 --- a/event_smart/src/main/java/com/njcn/gather/event/transientes/controller/EventGateController.java +++ b/event_smart/src/main/java/com/njcn/gather/event/transientes/controller/EventGateController.java @@ -16,6 +16,7 @@ import com.njcn.gather.event.transientes.pojo.param.MonitorTerminalParam; import com.njcn.gather.event.transientes.pojo.po.PqsDepts; import com.njcn.gather.event.transientes.pojo.po.PqsUser; import com.njcn.gather.event.transientes.pojo.po.PqsUserSet; +import com.njcn.gather.event.transientes.service.EventGateService; import com.njcn.gather.event.transientes.service.PqsDeptsService; import com.njcn.gather.event.transientes.service.PqsUserService; import com.njcn.gather.event.transientes.service.PqsUsersetService; @@ -27,6 +28,7 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; @@ -63,6 +65,7 @@ public class EventGateController extends BaseController { private final PqsUsersetService pqsUsersetService; private final PqLineMapper pqLineMapper; + private final EventGateService eventGateService; @@ -92,8 +95,8 @@ public class EventGateController extends BaseController { @ApiOperation("暂态事件波形分析") public HttpResult getTransientAnalyseWave(@RequestBody MonitorTerminalParam param){ String methodDescribe = getMethodDescribe("getTransientAnalyseWave"); - // WaveDataDTO wave = transientService.getTransientAnalyseWave(param); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + WaveDataDTO wave = eventGateService.getTransientAnalyseWave(param); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, wave, methodDescribe); } 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 67b60f3b..4f117f15 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(); - } - } - } - 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)); +//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(); +// } // } // } - 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()); - } - }*/ - -} +// 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()); +// } +// }*/ +// +//} diff --git a/event_smart/src/main/java/com/njcn/gather/event/transientes/service/impl/EventGateServiceImpl.java b/event_smart/src/main/java/com/njcn/gather/event/transientes/service/impl/EventGateServiceImpl.java index 2b8066ed..a6192d6f 100644 --- a/event_smart/src/main/java/com/njcn/gather/event/transientes/service/impl/EventGateServiceImpl.java +++ b/event_smart/src/main/java/com/njcn/gather/event/transientes/service/impl/EventGateServiceImpl.java @@ -1,106 +1,74 @@ -//package com.njcn.gather.event.transientes.service.impl; -// -//import cn.hutool.core.util.StrUtil; -//import com.njcn.common.pojo.exception.BusinessException; -//import com.njcn.common.utils.PubUtils; -//import com.njcn.event.file.pojo.dto.WaveDataDTO; -//import com.njcn.event.file.pojo.enums.WaveFileResponseEnum; -//import com.njcn.gather.event.transientes.pojo.param.MonitorTerminalParam; -//import com.njcn.gather.event.transientes.pojo.po.PqsEventdetail; -//import com.njcn.gather.event.transientes.service.EventGateService; -//import com.njcn.gather.event.transientes.service.PqsEventdetailService; -//import lombok.RequiredArgsConstructor; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.stereotype.Service; -// -//import java.io.File; -//import java.io.InputStream; -//import java.util.Objects; -// -///** -// * @Author: cdf -// * @CreateTime: 2025-06-30 -// * @Description: -// */ -//@Service -//@RequiredArgsConstructor -//@Slf4j -//public class EventGateServiceImpl implements EventGateService { -// -// private final PqsEventdetailService pqsEventdetailService; -// -// -// @Override -// public WaveDataDTO getTransientAnalyseWave(MonitorTerminalParam param) { -// WaveDataDTO waveDataDTO; -// //获取暂降事件 -// PqsEventdetail eventDetail = pqsEventdetailService.getById(param.getId()); -// LineDetailDataVO lineDetailData = new LineDetailDataVO(); -// MonitorVO monitorVO = new MonitorVO(); -// String ip; -// if (param.getSystemType() == 0) { -// lineDetailData = lineFeignClient.getLineDetailData(eventDetail.getMeasurementPointId()).getData(); -// ip = lineDetailData.getIp(); -// } else { -// param.setId(eventDetail.getMeasurementPointId()); -// monitorVO = monitorClient.getMonitorTerminal(param).getData(); -// ip = monitorVO.getIp(); -// } -// String waveName = eventDetail.getWavePath(); -// String cfgPath, datPath, cfgPath2, datPath2; -// if (generalInfo.getBusinessWaveFileStorage() == GeneralConstant.LOCAL_DISK) { -// cfgPath = generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.CFG; -// datPath = generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.DAT; -// log.info("本地磁盘波形文件路径----" + cfgPath); -// InputStream cfgStream = waveFileComponent.getFileInputStreamByFilePath(cfgPath); -// InputStream datStream = waveFileComponent.getFileInputStreamByFilePath(datPath); -// if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) { -// throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND); -// } -// waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 1); -// } else { -// cfgPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG; -// datPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT; -// //适配文件后缀小写 -// cfgPath2 = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG.toLowerCase(); -// datPath2 = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT.toLowerCase(); -// log.info("文件服务器波形文件路径----" + cfgPath); -// try ( -// InputStream cfgStream = fileStorageUtil.getFileStream(cfgPath); -// InputStream datStream = fileStorageUtil.getFileStream(datPath) -// ) { -// if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) { -// throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND); -// } -// waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 1); -// } catch (Exception e) { -// try { -// InputStream cfgStream = fileStorageUtil.getFileStream(cfgPath2); -// InputStream datStream = fileStorageUtil.getFileStream(datPath2); -// if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) { -// throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND); -// } -// waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 1); -// } catch (Exception e1) { -// throw new BusinessException(WaveFileResponseEnum.WAVE_DATA_INVALID); -// } -// -// } -// } -// waveDataDTO = waveFileComponent.getValidData(waveDataDTO); -// if (param.getSystemType() == 0) { -// waveDataDTO.setPtType(PubUtils.ptTypeName(lineDetailData.getPtType())); -// double pt1 = Double.parseDouble(lineDetailData.getPt().split(StrUtil.SLASH)[0]); -// double pt2 = Double.parseDouble(lineDetailData.getPt().split(StrUtil.SLASH)[1]); -// double ct1 = Double.parseDouble(lineDetailData.getCt().split(StrUtil.SLASH)[0]); -// double ct2 = Double.parseDouble(lineDetailData.getCt().split(StrUtil.SLASH)[1]); -// waveDataDTO.setPt(pt1 / pt2); -// waveDataDTO.setCt(ct1 / ct2); -// return waveDataDTO; -// } -// waveDataDTO.setPtType(Integer.valueOf(monitorVO.getTerminalWiringMethod())); -// waveDataDTO.setPt(monitorVO.getPt1() / monitorVO.getPt2()); -// waveDataDTO.setCt(monitorVO.getCt1() / monitorVO.getCt2()); -// return waveDataDTO; -// } -//} +package com.njcn.gather.event.transientes.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.utils.PubUtils; +import com.njcn.event.file.component.WaveFileComponent; +import com.njcn.event.file.pojo.dto.WaveDataDTO; +import com.njcn.event.file.pojo.enums.WaveFileResponseEnum; +import com.njcn.gather.event.devcie.mapper.PqLinedetailMapper; +import com.njcn.gather.event.devcie.pojo.po.PqLine; +import com.njcn.gather.event.devcie.pojo.po.PqLinedetail; +import com.njcn.gather.event.devcie.service.PqLineService; +import com.njcn.gather.event.transientes.pojo.param.MonitorTerminalParam; +import com.njcn.gather.event.transientes.pojo.po.PqsEventdetail; +import com.njcn.gather.event.transientes.service.EventGateService; +import com.njcn.gather.event.transientes.service.PqsEventdetailService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @Author: cdf + * @CreateTime: 2025-06-30 + * @Description: + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class EventGateServiceImpl implements EventGateService { + + private final PqsEventdetailService pqsEventdetailService; + private final WaveFileComponent waveFileComponent; + private final PqLineService pqLineService; + private final PqLinedetailMapper pqLinedetailMapper; + @Override + public WaveDataDTO getTransientAnalyseWave(MonitorTerminalParam param) { + WaveDataDTO waveDataDTO; + //获取暂降事件 + PqsEventdetail eventDetail = pqsEventdetailService.getById(param.getId()); + String waveName = eventDetail.getWavename(); + String cfgPath, datPath; + if (StrUtil.isBlank(waveName)) { + throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND); + } + cfgPath = "D:\\10.98.182.99\\"+waveName+".CFG"; + datPath = "D:\\10.98.182.99\\"+waveName+".DAT"; + log.info("本地磁盘波形文件路径----" + cfgPath); + InputStream cfgStream = waveFileComponent.getFileInputStreamByFilePath(cfgPath); + InputStream datStream = waveFileComponent.getFileInputStreamByFilePath(datPath); + if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) { + throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND); + } + waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 1); + + waveDataDTO = waveFileComponent.getValidData(waveDataDTO); + Integer lineid = eventDetail.getLineid(); + PqLine pqLine = pqLineService.getById(lineid); + PqLinedetail pqLinedetail = pqLinedetailMapper.selectById(lineid); + waveDataDTO.setPtType(pqLinedetail.getPttype()); + waveDataDTO.setPt(pqLine.getPt1()/ pqLine.getPt2()); + waveDataDTO.setCt(pqLine.getCt1()/ pqLine.getCt2()); + waveDataDTO.setMonitorName(pqLine.getName()); + return waveDataDTO; + + } +} diff --git a/event_smart/src/main/resources/application.yml b/event_smart/src/main/resources/application.yml index 1cacde3f..d686329e 100644 --- a/event_smart/src/main/resources/application.yml +++ b/event_smart/src/main/resources/application.yml @@ -1,3 +1,7 @@ +#当前服务的基本信息 +microservice: + ename: 12345 + name: 12345 server: port: 18093 spring: @@ -46,9 +50,9 @@ mybatis-plus: #驼峰命名 map-underscore-to-camel-case: true #配置sql日志输出 - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #关闭日志输出 -# log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl + log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl global-config: db-config: #指定主键生成策略 @@ -60,4 +64,36 @@ SYS_TYPE_WT: 983f9dfe-4f9a-4c96-89d8-7d425a1f1d6c db: type: oracle - +#文件位置配置 +business: + #处理波形数据位置 + # wavePath: D://comtrade + wavePath: /usr/local/comtrade + #处理临时数据 + #tempPath: D://file + tempPath: /usr/local/file + #文件存储的方式 + file: + storage: 3 +#oss服务器配置 +min: + io: + endpoint: http://192.168.1.13:9009 + accessKey: minio + secretKey: minio@123 + bucket: excelreport + #华为obs服务器配置 +huawei: + access-key: J9GS9EA79PZ60OK23LWP + security-key: BirGrAFDSLxU8ow5fffyXgZRAmMRb1R1AdqCI60d + obs: + bucket: test-8601 + endpoint: https://obs.cn-east-3.myhuaweicloud.com + # 单位为秒 + expire: 3600 +#线程池配置信息 +threadPool: + corePoolSize: 10 + maxPoolSize: 20 + queueCapacity: 500 + keepAliveSeconds: 60