Browse Source

损失电量分析代码移植修改

王波 1 month ago
parent
commit
b5cb87c68a

+ 58 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/dto/FiveLoss/exception/AdviceException.java

@@ -0,0 +1,58 @@
+package com.gyee.runeconomy.dto.FiveLoss.exception;
+
+import com.alibaba.fastjson.JSONObject;
+import com.gyee.runeconomy.dto.result.JsonResult;
+import com.gyee.runeconomy.dto.result.ResultCode;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+@Slf4j
+@RestControllerAdvice
+public class AdviceException {
+
+    /**
+     * 拦截未知的运行时异常
+     */
+    @ExceptionHandler(Exception.class)
+    public JSONObject runException(Exception e)
+    {
+        log.error(e.getMessage());
+        return JsonResult.error(ResultCode.ERROR);
+    }
+
+
+    /**
+     * 拦截未知的运行时异常
+     */
+    @ExceptionHandler(NullPointerException.class)
+    public JSONObject nullPointerException(NullPointerException e)
+    {
+        log.error(e.getMessage());
+        return JsonResult.error(ResultCode.ERROR);
+    }
+
+
+    /**
+     * 拦截自定义异常
+     */
+    @ExceptionHandler(RuntimeException.class)
+    public JSONObject runException(RuntimeException e)
+    {
+        log.error(e.getMessage());
+        return JsonResult.error(ResultCode.ERROR);
+    }
+
+
+
+    /**
+     * 拦截自定义异常
+     */
+    @ExceptionHandler(CustomException.class)
+    public JSONObject customException(CustomException e)
+    {
+        log.error(e.getMessage());
+        return JsonResult.error(e.getCode(), e.getMessage());
+    }
+
+}

+ 24 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/dto/FiveLoss/exception/CustomException.java

@@ -0,0 +1,24 @@
+package com.gyee.runeconomy.dto.FiveLoss.exception;
+
+
+import com.gyee.runeconomy.dto.result.ResultCode;
+import lombok.Data;
+
+@Data
+public class CustomException extends RuntimeException {
+
+    private Integer code;
+    private String message;
+
+    public CustomException(){}
+
+    public CustomException(ResultCode result){
+        super();
+        this.code = result.getCode();
+        this.message = result.getMessage();
+    }
+
+    public CustomException(Exception e){
+        super();
+    }
+}

+ 5 - 2
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/fiveloss/FiveLossService.java

@@ -1,15 +1,19 @@
 package com.gyee.runeconomy.service.fiveloss;
 
+
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.gyee.common.vo.benchmark.FjjxbVo;
 import com.gyee.runeconomy.dto.FiveLoss.AnnotationTool;
 import com.gyee.runeconomy.dto.FiveLoss.FixedVo;
 import com.gyee.runeconomy.dto.FiveLoss.TableTitle;
+import com.gyee.runeconomy.dto.FiveLoss.exception.CustomException;
 import com.gyee.runeconomy.dto.result.PowerPointData;
 import com.gyee.runeconomy.dto.result.ResultCode;
+import com.gyee.runeconomy.model.auto.ProEconEquipmentInfoDay1;
 import com.gyee.runeconomy.service.auto.IProEconEquipmentInfoDay1Service;
 import lombok.extern.slf4j.Slf4j;
+import lombok.val;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -18,7 +22,6 @@ import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
-
 @Slf4j
 @Service
 public class FiveLossService {
@@ -159,7 +162,7 @@ public class FiveLossService {
             log.info("======风机榜效帮计算结束.............");
             result.stream().sorted(Comparator.comparing(FjjxbVo::getId));
             /** 添加标题 **/
-            List<FixedVo> fxList = AnnotationTool.getFixedVoList(FjjxbVo.class);
+            val fxList = AnnotationTool.getFixedVoList(FjjxbVo.class);
             List<TableTitle> lt = fxList.stream().map(d -> new TableTitle(d.getName(), d.getDes())).collect(Collectors.toList());
             promise.put("title", lt);
             promise.put("data", result);