| | |
| | | TYPE_2_ACTM_CONTROLL(209,"控制ACTM均衡仪"), |
| | | TYPE_2_ACTM_CONTROLLPL(210,"批量控制ACTM"), |
| | | |
| | | TYPE_EXCEPTION(21, "接口调用异常"), |
| | | |
| | | ; |
| | | |
New file |
| | |
| | | package com.whyc.exception; |
| | | |
| | | import com.whyc.constant.OperationLogEnum; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.util.CommonUtil; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.ResponseStatus; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * 针对RestController层捕捉异常,结果统一返回 |
| | | */ |
| | | @RestControllerAdvice(annotations = {RestController.class, Controller.class, Service.class}) |
| | | public class CustomExceptionResultHandler { |
| | | |
| | | /**错误捕捉,状态码:202*/ |
| | | @ExceptionHandler(Exception.class) |
| | | @ResponseStatus(HttpStatus.ACCEPTED) |
| | | public Response sendErrorResponse2Defined(Exception e, HttpServletResponse response, HttpServletRequest request){ |
| | | String exceptionStr = e.toString(); |
| | | String requestURI = request.getRequestURI(); |
| | | CommonUtil.record(OperationLogEnum.TYPE_1_SYS.getType(),OperationLogEnum.TYPE_EXCEPTION.getType(),"接口请求异常", "接口调用异常:调用接口" + requestURI + "发生错误:" + exceptionStr); |
| | | return new Response().set(0, "接口请求异常,请联系软件人员进行处理.异常信息" + exceptionStr); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | private Double monWh; |
| | | |
| | | @ApiModelProperty(value = "单体状态") |
| | | private Integer monState; |
| | | private String monState; |
| | | |
| | | @ApiModelProperty(value = "故障信息") |
| | | private String monFault; |
| | |
| | | private Double monWh; |
| | | |
| | | @ApiModelProperty(value = "单体状态") |
| | | private Integer monState; |
| | | private String monState; |
| | | |
| | | @ApiModelProperty(value = "故障信息") |
| | | private Integer monFault; |
| | | private String monFault; |
| | | |
| | | |
| | | } |
| | |
| | | package com.whyc.util; |
| | | |
| | | import com.whyc.service.OperationLogService; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | /** |
| | | * 通用工具列 |
| | | */ |
| | | @Component |
| | | public class CommonUtil { |
| | | |
| | | private static OperationLogService service; |
| | | //将数转换成二进制字符串并统计1的个数 |
| | | public static int getIntToBinary(int switchState,int[] bit){ |
| | | int count=0; |
| | |
| | | return count; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | //System.out.println(getIntToBinary(511,new int[]{0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24})); |
| | | System.out.println(511&(1<<8)); |
| | | /** |
| | | * 手动记录特定日志 |
| | | */ |
| | | public static void record(int type1,int type2, String msg, String msgDetail) { |
| | | service.record(type1, type2, msg, msgDetail); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |