Explorar o código

解决好些BUG

wukai hai 7 meses
pai
achega
0235c16f13

+ 3 - 3
jjt-admin/src/main/resources/application-prod.yml

@@ -54,9 +54,9 @@ spring:
     druid:
       # 主库数据源
       master:
-        url: jdbc:mysql://25.214.216.196:13306/jy2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
-        username: jy
-        password: ABcd@1234
+        url: jdbc:mysql://25.214.216.204:13306/px_riskmon?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
+        username: riskmon
+        password: riskmon@123
       # 从库数据源
       slave:
         # 从数据源开关/默认关闭

+ 80 - 0
jjt-admin/src/test/java/com/test/DateTest.java

@@ -0,0 +1,80 @@
+package com.test;
+
+
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import com.jjt.common.utils.DateUtils;
+import com.jjt.common.utils.StringUtils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.ConnectException;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.temporal.TemporalAdjuster;
+import java.time.temporal.TemporalAdjusters;
+import java.util.Date;
+
+/**
+ * Test$
+ *
+ * @author wukai
+ * @date 2024/8/22 22:13
+ */
+public class DateTest {
+    public static void main(String[] args) throws Exception {
+        Date date = DateUtils.parseDate("2024-10");
+        LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        System.err.println(localDate.with(TemporalAdjusters.firstDayOfMonth())+" 00:00:00");
+        System.err.println(localDate.with(TemporalAdjusters.lastDayOfMonth())+" 23:59:59");
+    }
+
+    public static HttpResponse response(HttpRequest request) throws Exception {
+        try (HttpResponse res = request.execute()) {
+            if (!res.isOk()) {
+                throw new RuntimeException(res.body());
+            }
+            return res;
+        }
+    }
+
+    public static String sendGet(String url, String param, String contentType, String baseAuth) {
+        StringBuilder result = new StringBuilder();
+        BufferedReader in = null;
+        try {
+            String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url;
+            URL realUrl = new URL(urlNameString);
+            URLConnection connection = realUrl.openConnection();
+            connection.setRequestProperty("Authorization", baseAuth);
+            connection.setRequestProperty("accept", "*/*");
+            connection.setRequestProperty("connection", "Keep-Alive");
+            connection.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
+            connection.connect();
+            in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result.append(line);
+            }
+        } catch (ConnectException e) {
+            e.printStackTrace();
+        } catch (SocketTimeoutException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            } catch (Exception ex) {
+            }
+        }
+        return result.toString();
+    }
+}

+ 54 - 42
jjt-biz/src/main/java/com/jjt/biz/controller/BizModelController.java

@@ -80,6 +80,9 @@ public class BizModelController extends BaseController {
 
         List<HlScore> list = hlScoreService.selectHlScoreList(search);
         Map<Long, List<HlScore>> resultMap = list.stream().collect(Collectors.groupingBy(HlScore::getModelId));
+
+        int len = 0;
+        List<String> standTime = new ArrayList<>();
         for (Long modelId : resultMap.keySet()) {
             ScoreVO vo = new ScoreVO();
             BizModel model = bizModelService.selectBizModelByModelId(modelId);
@@ -97,36 +100,55 @@ public class BizModelController extends BaseController {
                     scores.add(hs.getHlScore().floatValue());
                 }
             });
+
+            if (scoreList.size() > len) {
+                len = scoreList.size();
+                standTime = xData;
+            }
             vo.setScores(scores);
             vo.setXData(xData);
             result.add(vo);
         }
-
-//        String[] names = {"市场服务", "市场出清", "信息发布", "市场合规", "市场结算"};
-//        for (int i = 0; i < names.length; i++) {
-//            ScoreVO vo = new ScoreVO();
-//            List<LocalDateTime> times = new ArrayList<>();
-//            List<String> xData = new ArrayList<>();
-//            List<Float> scores = new ArrayList<>();
-//            LocalDateTime time = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0).minusHours(23);
-//            for (int j = 0; j < 24; j++) {
-//                time = time.plusHours(1);
-//                times.add(time);
-//                xData.add(time.getHour() + "");
-//                Float score = Float.valueOf(new Random().nextInt(50) + 50);
-//                scores.add(score);
-//            }
-//
-//            vo.setModelId((long) (i + 1));
-//            vo.setModelName(names[i]);
-//            vo.setTimes(times);
-//            vo.setScores(scores);
-//            vo.setXData(xData);
-//            result.add(vo);
-//        }
+        standTime(standTime, result);
         return result;
     }
 
+    /**
+     * 补数据
+     *
+     * @param standTime
+     * @param result
+     */
+    private void standTime(List<String> standTime, List<ScoreVO> result) {
+        for (ScoreVO vo : result) {
+            // 创建一个新的 times 和 scores 列表,以确保它们与标准时间序列对齐
+            List<String> alignedTimes = new ArrayList<>();
+            List<Float> alignedScores = new ArrayList<>();
+            // 使用一个Map来存储原始数据,以便快速查找
+            Map<String, Float> timeScoreMap = new HashMap<>();
+            List<String> times = vo.getXData();
+            List<Float> scores = vo.getScores();
+            for (int i = 0; i < times.size(); i++) {
+                timeScoreMap.put(times.get(i), scores.get(i));
+            }
+            // 遍历标准时间序列,并根据需要添加空值或实际值
+            for (String time : standTime) {
+                alignedTimes.add(time);
+                // 添加时间
+                Float score = timeScoreMap.getOrDefault(time, 100F);
+                // 如果没有对应的分数,则添加0.0f
+                alignedScores.add(score);
+            }
+
+            // 更新原有的 times 和 scores 列表
+            times.clear();
+            times.addAll(alignedTimes);
+            scores.clear();
+            scores.addAll(alignedScores);
+        }
+    }
+
+
     @ApiOperation("日健康度得分情况")
     @GetMapping("/day/history")
     public List<ScoreVO> dayHistory() {
@@ -142,6 +164,8 @@ public class BizModelController extends BaseController {
 
         List<HlScore> list = hlScoreService.selectHlScoreList(search);
         Map<Long, List<HlScore>> resultMap = list.stream().collect(Collectors.groupingBy(HlScore::getModelId));
+        int len = 0;
+        List<String> standTime = new ArrayList<>();
         for (Long modelId : resultMap.keySet()) {
             ScoreVO vo = new ScoreVO();
             BizModel model = bizModelService.selectBizModelByModelId(modelId);
@@ -155,29 +179,17 @@ public class BizModelController extends BaseController {
                 xData.add(DateUtils.parseDateToStr("MM-dd", hs.getHlDate()));
                 scores.add(hs.getHlScore().floatValue());
             });
+
+            if (scoreList.size() > len) {
+                len = scoreList.size();
+                standTime = xData;
+            }
             vo.setScores(scores);
             vo.setXData(xData);
             result.add(vo);
         }
-//        String[] names = {"市场服务", "市场出清", "信息发布", "市场合规", "市场结算"};
-//        for (int i = 0; i < names.length; i++) {
-//            ScoreVO vo = new ScoreVO();
-//            List<String> xData = new ArrayList<>();
-//            List<Float> scores = new ArrayList<>();
-//            LocalDate time = LocalDate.now().minusDays(8);
-//            for (int j = 0; j < 7; j++) {
-//                time = time.plusDays(1);
-//                xData.add(time.getMonthValue() + "-" + time.getDayOfMonth());
-//                Float score = Float.valueOf(new Random().nextInt(50) + 50);
-//                scores.add(score);
-//            }
-//
-//            vo.setModelId((long) (i + 1));
-//            vo.setModelName(names[i]);
-//            vo.setScores(scores);
-//            vo.setXData(xData);
-//            result.add(vo);
-//        }
+
+        standTime(standTime, result);
         return result;
     }
 //

+ 117 - 13
jjt-biz/src/main/java/com/jjt/biz/controller/IndexController.java

@@ -5,7 +5,6 @@ import com.jjt.biz.service.*;
 import com.jjt.biz.vo.BizAccessVO;
 import com.jjt.biz.vo.BizTypeVO;
 import com.jjt.biz.vo.HlScoreVO;
-import com.jjt.biz.vo.ScoreVO;
 import com.jjt.common.core.controller.BaseController;
 import com.jjt.common.core.domain.AjaxResult;
 import com.jjt.common.core.page.TableDataInfo;
@@ -19,11 +18,15 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -83,28 +86,120 @@ public class IndexController extends BaseController {
 
     @ApiOperation("应用健康趋势-按月")
     @GetMapping("/hl/month/{date}")
-    public AjaxResult hlMonth(@ApiParam(value = "时间 yyyy-mm", required = true) @PathVariable("date") String date) {
+    public AjaxResult hlMonth(@ApiParam(value = "时间 yyyy-mm", required = true) @PathVariable("date") Date date) {
         List<Map<String, Object>> result = new ArrayList<>();
-        int year = Integer.parseInt(date.split("-")[0]);
-        int month = Integer.parseInt(date.split("-")[1]);
-        LocalDate localDate = LocalDate.of(year, month, 1);
-        for (int i = 0; i < MODEL_NAMES.length; i++) {
+        HlScore search = new HlScore();
+        search.setHlType("2");
+        LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        Map<String, Object> params = new HashMap<>(16);
+        params.put("beginTime", localDate.with(TemporalAdjusters.firstDayOfMonth()) + " 00:00:00");
+        params.put("endTime", localDate.with(TemporalAdjusters.lastDayOfMonth()) + " 23:59:59");
+        search.setParams(params);
+        List<HlScore> list = scoreService.selectHlScoreList(search);
+        Map<Long, List<HlScore>> resultMap = list.stream().collect(Collectors.groupingBy(HlScore::getModelId));
+
+        int len = 0;
+        List<String> standTime = new ArrayList<>();
+        for (Long modelId : resultMap.keySet()) {
             Map<String, Object> map = new HashMap<>(16);
-            map.put("name", MODEL_NAMES[i]);
+            BizModel model = bizModelService.selectBizModelByModelId(modelId);
+            map.put("name", model.getModelName());
             List<String> times = new ArrayList<>();
             List<Float> scores = new ArrayList<>();
-            for (int j = 0; j < localDate.lengthOfMonth(); j++) {
-                times.add((j + 1) + "");
-                Float score = Float.valueOf(new Random().nextInt(50) + 50);
-                scores.add(score);
+            List<HlScore> scoreList = resultMap.get(modelId);
+            scoreList = scoreList.stream().sorted(Comparator.comparing(HlScore::getHlDate)).collect(Collectors.toList());
+            scoreList.forEach(hs -> {
+                times.add(DateUtils.parseDateToStr("dd", hs.getHlDate()));
+                if (hs.getHlScore() != null) {
+                    scores.add(hs.getHlScore().floatValue());
+                } else {
+                    scores.add(100f);
+                }
+            });
+
+            if (scoreList.size() > len) {
+                len = scoreList.size();
+                standTime = times;
             }
+
             map.put("time", times);
             map.put("score", scores);
             result.add(map);
         }
+        standTime(standTime, result);
         return success(result);
     }
 
+    @ApiOperation("应用健康趋势-按年")
+    @GetMapping("/hl/year/{date}")
+    public AjaxResult hlYear(@ApiParam(value = "时间 yyyy", required = true) @PathVariable("date") String date) {
+        List<Map<String, Object>> result = new ArrayList<>();
+        String sql = "SELECT a.model_name,b.hy,b.hm,b.score from biz_model a,(SELECT model_id,year(hl_date) hy,month(hl_date) hm,AVG(ifnull(hl_score,100)) score" +
+                " FROM hl_score t WHERE hl_type=2 AND year(hl_date)=? GROUP BY model_id,hy,hm) b WHERE a.model_id=b.model_id order by hm";
+        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, date);
+        Map<String, List<Map<String, Object>>> resultMap = list.stream().collect(Collectors.groupingBy(map -> (String) map.get("model_name")));
+        int len = 0;
+        List<String> standTime = new ArrayList<>();
+        for (String name : resultMap.keySet()) {
+            Map<String, Object> map = new HashMap<>(16);
+            map.put("name", name);
+            List<String> times = new ArrayList<>();
+            List<Float> scores = new ArrayList<>();
+            List<Map<String, Object>> detailList = resultMap.get(name);
+            detailList.forEach(m -> {
+                Integer hm = (Integer) m.get("hm");
+                BigDecimal score = (BigDecimal) m.get("score");
+                score = score.setScale(2, RoundingMode.HALF_UP);
+                times.add(hm + "");
+                scores.add(score.floatValue());
+            });
+            if (detailList.size() > len) {
+                len = detailList.size();
+                standTime = times;
+            }
+            map.put("time", times);
+            map.put("score", scores);
+            result.add(map);
+        }
+        standTime(standTime, result);
+        return success(result);
+    }
+
+    /**
+     * 补数据
+     *
+     * @param standTime
+     * @param result
+     */
+    private void standTime(List<String> standTime, List<Map<String, Object>> result) {
+        for (Map<String, Object> map : result) {
+            // 创建一个新的 times 和 scores 列表,以确保它们与标准时间序列对齐
+            List<String> alignedTimes = new ArrayList<>();
+            List<Float> alignedScores = new ArrayList<>();
+            // 使用一个Map来存储原始数据,以便快速查找
+            Map<String, Float> timeScoreMap = new HashMap<>();
+            List<String> times = (List<String>) map.get("time");
+            List<Float> scores = (List<Float>) map.get("score");
+            for (int i = 0; i < times.size(); i++) {
+                timeScoreMap.put(times.get(i), scores.get(i));
+            }
+            // 遍历标准时间序列,并根据需要添加空值或实际值
+            for (String time : standTime) {
+                alignedTimes.add(time);
+                // 添加时间
+                Float score = timeScoreMap.getOrDefault(time, 100F);
+                // 如果没有对应的分数,则添加0.0f
+                alignedScores.add(score);
+            }
+
+            // 更新原有的 times 和 scores 列表
+            times.clear();
+            times.addAll(alignedTimes);
+            scores.clear();
+            scores.addAll(alignedScores);
+        }
+    }
+
     @ApiOperation("应用健康趋势-按天")
     @GetMapping("/hl/day/{date}")
     public AjaxResult hlDay(@ApiParam(value = "时间(yyyy-mm-dd", required = true) @PathVariable("date") Date date) {
@@ -115,18 +210,19 @@ public class IndexController extends BaseController {
         params.put("beginTime", DateUtils.parseDateToStr("yyyy-MM-dd", date) + " 00:00:00");
         params.put("endTime", DateUtils.parseDateToStr("yyyy-MM-dd", date) + " 23:59:59");
         search.setParams(params);
-
+        int len = 0;
+        List<String> standTime = new ArrayList<>();
         List<HlScore> list = scoreService.selectHlScoreList(search);
         Map<Long, List<HlScore>> resultMap = list.stream().collect(Collectors.groupingBy(HlScore::getModelId));
         for (Long modelId : resultMap.keySet()) {
             Map<String, Object> map = new HashMap<>(16);
-            ScoreVO vo = new ScoreVO();
             BizModel model = bizModelService.selectBizModelByModelId(modelId);
             map.put("name", model.getModelName());
             List<String> times = new ArrayList<>();
             List<Float> scores = new ArrayList<>();
             List<HlScore> scoreList = resultMap.get(modelId);
             scoreList = scoreList.stream().sorted(Comparator.comparing(HlScore::getHlDate)).collect(Collectors.toList());
+
             scoreList.forEach(hs -> {
                 times.add(DateUtils.parseDateToStr("HH:mm", hs.getHlDate()));
                 if (hs.getHlScore() != null) {
@@ -135,10 +231,18 @@ public class IndexController extends BaseController {
                     scores.add(100f);
                 }
             });
+
+            if (scoreList.size() > len) {
+                len = scoreList.size();
+                standTime = times;
+            }
+
             map.put("time", times);
             map.put("score", scores);
             result.add(map);
         }
+
+        standTime(standTime, result);
         return success(result);
     }
 

+ 43 - 26
jjt-biz/src/main/java/com/jjt/risk/controller/RiskOtherController.java

@@ -230,6 +230,9 @@ public class RiskOtherController extends BaseController {
         List<HlScore> list = hlScoreService.selectHlScoreList(search);
 
         Map<Long, List<HlScore>> resultMap = list.stream().collect(Collectors.groupingBy(HlScore::getModelId));
+
+        int len = 0;
+        List<String> standTime = new ArrayList<>();
         for (Long modelId : resultMap.keySet()) {
             ScoreVO vo = new ScoreVO();
             BizModel model = bizModelService.selectBizModelByModelId(modelId);
@@ -243,6 +246,10 @@ public class RiskOtherController extends BaseController {
                 xData.add(DateUtils.parseDateToStr("MM-dd", hs.getHlDate()));
                 scores.add(hs.getHlScore().floatValue());
             });
+            if (scoreList.size() > len) {
+                len = scoreList.size();
+                standTime = xData;
+            }
             vo.setScores(scores);
             vo.setXData(xData);
             scoreVOList.add(vo);
@@ -258,34 +265,44 @@ public class RiskOtherController extends BaseController {
             topList.add(map);
         }
 
-//        List<ScoreVO> list = new ArrayList<>();
-//        String[] names = {"市场服务", "市场出清", "信息发布", "市场合规", "市场结算"};
-//        for (int i = 0; i < names.length; i++) {
-//            Map<String, Object> map = new HashMap<>(16);
-//            map.put("name", names[i]);
-//            map.put("score", Float.valueOf(new Random().nextInt(50) + 50));
-//            topList.add(map);
-//            ScoreVO vo = new ScoreVO();
-//            List<String> xData = new ArrayList<>();
-//            List<Float> scores = new ArrayList<>();
-//            LocalDate time = LocalDate.now().minusDays(31);
-//            for (int j = 0; j < 30; j++) {
-//                time = time.plusDays(1);
-//                xData.add(time.getMonthValue() + "-" + time.getDayOfMonth());
-//                Float score = Float.valueOf(new Random().nextInt(50) + 50);
-//                scores.add(score);
-//            }
-//
-//            vo.setModelId((long) (i + 1));
-//            vo.setModelName(names[i]);
-//            vo.setScores(scores);
-//            vo.setXData(xData);
-//            list.add(vo);
-//        }
-//        topList.sort(Comparator.comparing(map -> (Float) map.get("score")));
-
+        standTime(standTime, scoreVOList);
         result.put("trend", scoreVOList);
         result.put("top", topList);
         return success(result);
     }
+
+    /**
+     * 补数据
+     *
+     * @param standTime
+     * @param result
+     */
+    private void standTime(List<String> standTime, List<ScoreVO> result) {
+        for (ScoreVO vo : result) {
+            // 创建一个新的 times 和 scores 列表,以确保它们与标准时间序列对齐
+            List<String> alignedTimes = new ArrayList<>();
+            List<Float> alignedScores = new ArrayList<>();
+            // 使用一个Map来存储原始数据,以便快速查找
+            Map<String, Float> timeScoreMap = new HashMap<>();
+            List<String> times = vo.getXData();
+            List<Float> scores = vo.getScores();
+            for (int i = 0; i < times.size(); i++) {
+                timeScoreMap.put(times.get(i), scores.get(i));
+            }
+            // 遍历标准时间序列,并根据需要添加空值或实际值
+            for (String time : standTime) {
+                alignedTimes.add(time);
+                // 添加时间
+                Float score = timeScoreMap.getOrDefault(time, 100F);
+                // 如果没有对应的分数,则添加0.0f
+                alignedScores.add(score);
+            }
+
+            // 更新原有的 times 和 scores 列表
+            times.clear();
+            times.addAll(alignedTimes);
+            scores.clear();
+            scores.addAll(alignedScores);
+        }
+    }
 }

+ 2 - 2
jjt-biz/src/main/resources/mapper/hl/HlScoreMapper.xml

@@ -20,7 +20,7 @@
     <sql id="selectHlScoreVo">
         select HL_SCORE_ID,
                MODEL_ID,
-               HL_SCORE,
+               IFNULL(HL_SCORE,100) HL_SCORE,
                HL_TYPE,
                HL_DATE,
                CREATE_BY,
@@ -74,7 +74,7 @@
         where HL_SCORE_ID = #{hlScoreId}
     </select>
     <select id="selectHlScoreListLast" resultType="com.jjt.biz.vo.HlScoreVO">
-        SELECT a.*, c.hl_score_id, hl_score
+        SELECT a.*, c.hl_score_id, ifnull(hl_score,100) hl_score
         FROM biz_model a
                  JOIN (SELECT model_id, MAX(hl_score_id) AS max_hl_score_id
                        FROM hl_score