Browse Source

首页接口模拟数据

wukai 8 months ago
parent
commit
4ee3fee501

+ 3 - 41
jjt-admin/src/test/java/com/test/Test.java

@@ -1,9 +1,6 @@
 package com.test;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.time.LocalDate;
 
 /**
  * Test$
@@ -13,42 +10,7 @@ import java.util.Map;
  */
 public class Test {
     public static void main(String[] args) {
-        Map<String, List<Float>> originalMap = new HashMap<>();
-        List<Float> list1 = new ArrayList<>();
-        list1.add(1f);
-        list1.add(2f);
-        list1.add(3f);
-        originalMap.put("code1", list1);
-        List<Float> list2 = new ArrayList<>();
-        list2.add(4f);
-        list2.add(5f);
-        list2.add(6f);
-        originalMap.put("code2", list2);
-        // 创建一个新的 List 来存储新的 Map 结构
-        List<Map<String, Float>> newList = new ArrayList<>();
-        // 确保两个列表长度相等
-        int size = 0;
-        for (String s : originalMap.keySet()) {
-            size = originalMap.get(s).size();
-            break;
-        }
-//        if (size != originalMap.get("code2").size()) {
-//            throw new IllegalArgumentException("Lists must be of the same size");
-//        }
-
-        // 遍历列表并创建新的 Map
-        for (int i = 0; i < size; i++) {
-            Map<String, Float> singleEntryMap = new HashMap<>();
-            for (String s : originalMap.keySet()) {
-                singleEntryMap.put(s, originalMap.get(s).get(i));
-
-            }
-            newList.add(singleEntryMap);
-        }
-
-        // 输出转换后的 List<Map<String, Float>>
-        for (Map<String, Float> map : newList) {
-            System.out.println(map);
-        }
+        LocalDate localDate = LocalDate.of(2024, 2, 1);
+        System.err.println(localDate);
     }
 }

+ 227 - 11
jjt-biz/src/main/java/com/jjt/biz/controller/IndexController.java

@@ -1,14 +1,24 @@
 package com.jjt.biz.controller;
 
+import com.jjt.biz.domain.BizObjMetrics;
+import com.jjt.biz.domain.IndexMetrics;
+import com.jjt.biz.service.IBizObjMetricsService;
+import com.jjt.biz.service.IIndexMetricsService;
 import com.jjt.common.core.controller.BaseController;
 import com.jjt.common.core.domain.AjaxResult;
+import com.jjt.common.core.page.TableDataInfo;
+import com.jjt.common.utils.DateUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.text.DecimalFormat;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.*;
 
 /**
  * 业务对象Controller
@@ -20,16 +30,222 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 @RequestMapping("/index")
 public class IndexController extends BaseController {
+    @Resource
+    private IIndexMetricsService imService;
+    @Resource
+    private IBizObjMetricsService omService;
+
+    String[] MODEL_NAMES = {"市场服务", "市场出清", "信息发布", "市场合规", "市场结算"};
+
+    @ApiOperation("巡检提示")
+    @GetMapping("/hl/check")
+    public AjaxResult hlCheck() {
+        Map<String, Object> result = new HashMap<>(16);
+        result.put("time", DateUtils.getTime());
+        result.put("model", 5);
+        result.put("metrics", new Random().nextInt(200));
+        result.put("problem", new Random().nextInt(80));
+        return AjaxResult.success(result);
+    }
+
+    @ApiOperation("当前健康度")
+    @GetMapping("/hl/curr")
+    public AjaxResult hlCurr() {
+        List<Map<String, Object>> result = new ArrayList<>();
+        for (int i = 0; i < MODEL_NAMES.length; i++) {
+            Map<String, Object> map = new HashMap<>(16);
+            map.put("name", MODEL_NAMES[i]);
+            Float score = Float.valueOf(new Random().nextInt(50) + 50);
+            map.put("score", score);
+            result.add(map);
+        }
+        return AjaxResult.success(result);
+    }
+
+    @ApiOperation("应用健康趋势-按月")
+    @GetMapping("/hl/month/{date}")
+    public AjaxResult hlMonth(@ApiParam(value = "时间 yyyy-mm", required = true) @PathVariable("date") String 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++) {
+            Map<String, Object> map = new HashMap<>(16);
+            map.put("name", MODEL_NAMES[i]);
+            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);
+            }
+            map.put("time", times);
+            map.put("score", scores);
+            result.add(map);
+        }
+        return success(result);
+    }
+
+    @ApiOperation("应用健康趋势-按天")
+    @GetMapping("/hl/day/{date}")
+    public AjaxResult hlDay(@ApiParam(value = "时间(yyyy-mm-dd", required = true) @PathVariable("date") Date date) {
+        List<Map<String, Object>> result = new ArrayList<>();
+        for (int i = 0; i < MODEL_NAMES.length; i++) {
+            Map<String, Object> map = new HashMap<>(16);
+            map.put("name", MODEL_NAMES[i]);
+            List<String> times = new ArrayList<>();
+            List<Float> scores = new ArrayList<>();
+            for (int j = 0; j < 24; j++) {
+                times.add(j + "");
+                Float score = Float.valueOf(new Random().nextInt(50) + 50);
+                scores.add(score);
+            }
+            map.put("time", times);
+            map.put("score", scores);
+            result.add(map);
+        }
+        return success(result);
+    }
+
+    @ApiOperation("运行风险预测结果")
+    @GetMapping("/risk")
+    public AjaxResult risk() {
+        Map<String, Object> result = new HashMap<>();
+        List<Map<String, Object>> list = new ArrayList<>();
+        String[] objs = {"出清node1", "出清ecs", "业务应用3", "业务应用4", "业务应用5", "业务应用6", "业务应用7"};
+        String[] ms = {"cpu使用率", "慢访问次数", "GC次数", "空间交换", "打开文件数", "交换分区访问"};
+        Random random = new Random();
+        int x = objs.length * ms.length;
+        int xx = x / 2;
+        int max = random.nextInt(xx) + 12;
+        int num = 0;
+        for (int i = 0; i < max; i++) {
+            boolean flag = random.nextInt(888) % 2 == 0;
+            int mi = random.nextInt(ms.length - 1);
+            Map<String, Object> map = new HashMap<>(16);
+            String objName = objs[i % 6];
+            String metricsName = ms[mi];
+            map.put("objName", objName);
+            map.put("metricsName", metricsName);
+            String status = "1";
+            if (flag) {
+                //风险
+                num++;
+                status = "2";
+            }
+            map.put("status", status);
+            list.add(map);
+        }
+
+        result.put("num", num);
+        result.put("data", list);
+        return success(result);
+    }
+
+    @ApiOperation("业务访问报错排名")
+    @GetMapping("/biz/access")
+    public AjaxResult access() {
+        List<Map<String, Object>> result = new ArrayList<>();
+        String[] names = {"市场出清/mysql", "市场出清/redis", "市场出清/user", "市场服务/auth", "市场结算/mysql"};
+        Random random = new Random();
+        for (int i = 0; i < names.length; i++) {
+            Map<String, Object> map = new HashMap<>(16);
+            map.put("name", names[i]);
+            map.put("total", random.nextInt(500) + 500);
+            map.put("error", random.nextInt(20));
+            result.add(map);
+        }
+        return success(result);
+    }
+
+    @ApiOperation("组件告警数排名")
+    @GetMapping("/obj/alarm")
+    public AjaxResult alarm() {
+        Map<String, Object> result = new HashMap<>();
+        String[] names = {"市场服务node-1", "市场出清后台应用", "市场合规cluster1", "市场合规cluster2", "信息发布cluster1"};
+        result.put("curr", new Random().nextInt(50) + 1);
+        Random random = new Random();
+        List<Map<String, Object>> list = new ArrayList<>();
+        for (int i = 0; i < names.length; i++) {
+            Map<String, Object> map = new HashMap<>(16);
+            map.put("name", names[i]);
+            map.put("alarm", random.nextInt(500) + 500);
+            list.add(map);
+        }
+        result.put("data", list);
+        return success(result);
+    }
+
+    @ApiOperation("指标配置列表")
+    @GetMapping("/ms/config/list")
+    public AjaxResult configList() {
+        List<IndexMetrics> list = imService.selectIndexMetricsList(new IndexMetrics());
+        return AjaxResult.success(list);
+    }
+
+    @ApiOperation("重点指标运行趋势列表")
+    @GetMapping("/ms/trend")
+    public AjaxResult msList() {
+        List<IndexMetrics> list = imService.selectIndexMetricsList(new IndexMetrics());
+        list.forEach(im -> {
+            Random r = new Random();
+            DecimalFormat df = new DecimalFormat("#0.00");
+            im.setValue(Float.parseFloat(df.format(r.nextFloat() * 100)));
+        });
+        return AjaxResult.success(list);
+    }
+
+    @ApiOperation("重点指标运行趋势图")
+    @GetMapping("/ms/trend/{objMetricsId}")
+    public AjaxResult msChat(@PathVariable("objMetricsId") Long objMetricsId) {
+        List<Map<String, Object>> trendList = new ArrayList<>();
+        LocalDateTime ed = LocalDateTime.now();
+        LocalDateTime st = ed.minusDays(7);
+        Random r = new Random();
+        DecimalFormat df = new DecimalFormat("#0.00");
+        do {
+            Map<String, Object> map = new HashMap<>(16);
+            long time = st.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+            map.put("time", time);
+            float f = r.nextFloat() * 100;
+            map.put("value", Float.parseFloat(df.format(f)));
+            st = st.plusMinutes(5);
+            trendList.add(map);
+        } while (!st.isAfter(ed));
+        return AjaxResult.success(trendList);
+    }
+
+    @ApiOperation("指标配置--选择指标列表")
+    @GetMapping("/ms/config/select")
+    public TableDataInfo list(BizObjMetrics bizObjMetrics) {
+        startPage();
+        List<BizObjMetrics> list = omService.selectBizObjMetricsList(bizObjMetrics);
+        return getDataTable(list);
+    }
 
-    @ApiOperation("选择模板")
-    @GetMapping("/tpl/select/{objId}")
-    public AjaxResult select(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId) {
+    @ApiOperation("指标配置--添加指标")
+    @GetMapping("/ms/config/add")
+    public AjaxResult selectAdd(@ApiParam(value = "指标ID数组", required = true) Long[] ids) {
+        for (int i = 0; i < ids.length; i++) {
+            Long id = ids[i];
+            IndexMetrics im = new IndexMetrics();
+            im.setObjMetricsId(id);
+            List list = imService.selectIndexMetricsList(im);
+            if (list.size() == 0) {
+                BizObjMetrics bom = omService.selectBizObjMetricsByObjMetricsId(id);
+                im.setObjId(bom.getObjId());
+                im.setObjName(bom.getObjName());
+                im.setMetricsId(bom.getMetricsId());
+                im.setMetricsName(bom.getMetricsName());
+                imService.insertIndexMetrics(im);
+            }
+        }
         return AjaxResult.success();
     }
 
-    @ApiOperation("添加模板")
-    @GetMapping("/tpl/add/{objId}")
-    public AjaxResult add(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId, @ApiParam(value = "指标ID数组", required = true) Long[] tplIds) {
-        return success();
+    @ApiOperation("指标配置--删除指标")
+    @DeleteMapping("/ms/config/del/{imIds}")
+    public AjaxResult configDel(@ApiParam(value = "指标imId", required = true) @PathVariable Long[] imIds) {
+        return AjaxResult.success(imService.deleteIndexMetricsByImIds(imIds));
     }
 }

+ 7 - 0
jjt-biz/src/main/java/com/jjt/biz/domain/BizObjMetrics.java

@@ -33,7 +33,14 @@ public class BizObjMetrics extends BaseEntity {
     @ApiModelProperty("业务对象ID")
     @Excel(name = "业务对象ID")
     private Long objId;
+    /**
+     * 业务对象ID
+     */
+    @ApiModelProperty("对象名称")
+    private String objName;
 
+    @ApiModelProperty("对象业务类型")
+    private String objType;
     /**
      * 模板ID
      */

+ 29 - 84
jjt-biz/src/main/java/com/jjt/biz/domain/IndexMetrics.java

@@ -1,12 +1,14 @@
 package com.jjt.biz.domain;
 
 import com.baomidou.mybatisplus.annotation.TableId;
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
 import com.jjt.common.annotation.Excel;
 import com.jjt.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * 首页指标配置对象 index_metrics
@@ -15,109 +17,52 @@ import com.jjt.common.core.domain.BaseEntity;
  * @date 2024-09-12
  */
 @ApiModel(value = "IndexMetrics", description = "首页指标配置")
-public class IndexMetrics extends BaseEntity
-{
+@Data
+public class IndexMetrics extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** 首页指标ID */
+    /**
+     * 首页指标ID
+     */
     @ApiModelProperty("首页指标ID")
     @TableId
     private Long imId;
 
-    /** 指标ID */
+    /**
+     * 指标ID
+     */
     @ApiModelProperty("指标ID")
     @Excel(name = "指标ID")
     private Long metricsId;
 
-    /** 指标名称 */
+    /**
+     * 指标名称
+     */
     @ApiModelProperty("指标名称")
     @Excel(name = "指标名称")
     private String metricsName;
 
-    /** 对象ID */
+    /**
+     * 对象ID
+     */
     @ApiModelProperty("对象ID")
     @Excel(name = "对象ID")
-    private String objId;
+    private Long objId;
 
-    /** 对象名称 */
+    /**
+     * 对象名称
+     */
     @ApiModelProperty("对象名称")
     @Excel(name = "对象名称")
     private String objName;
 
-    /** ID */
+    /**
+     * ID
+     */
     @ApiModelProperty("ID")
     @Excel(name = "ID")
     private Long objMetricsId;
 
-    public void setImId(Long imId)
-    {
-        this.imId = imId;
-    }
-
-    public Long getImId()
-    {
-        return imId;
-    }
-    public void setMetricsId(Long metricsId)
-    {
-        this.metricsId = metricsId;
-    }
-
-    public Long getMetricsId()
-    {
-        return metricsId;
-    }
-    public void setMetricsName(String metricsName)
-    {
-        this.metricsName = metricsName;
-    }
-
-    public String getMetricsName()
-    {
-        return metricsName;
-    }
-    public void setObjId(String objId)
-    {
-        this.objId = objId;
-    }
-
-    public String getObjId()
-    {
-        return objId;
-    }
-    public void setObjName(String objName)
-    {
-        this.objName = objName;
-    }
-
-    public String getObjName()
-    {
-        return objName;
-    }
-    public void setObjMetricsId(Long objMetricsId)
-    {
-        this.objMetricsId = objMetricsId;
-    }
-
-    public Long getObjMetricsId()
-    {
-        return objMetricsId;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("imId", getImId())
-            .append("metricsId", getMetricsId())
-            .append("metricsName", getMetricsName())
-            .append("objId", getObjId())
-            .append("objName", getObjName())
-            .append("objMetricsId", getObjMetricsId())
-            .append("createBy", getCreateBy())
-            .append("createTime", getCreateTime())
-            .append("updateBy", getUpdateBy())
-            .append("updateTime", getUpdateTime())
-            .append("remark", getRemark())
-            .toString();
-    }
+    @ApiModelProperty("当前值")
+    private Float value;
 }

+ 15 - 6
jjt-biz/src/main/resources/mapper/obj/BizObjMetricsMapper.xml

@@ -7,6 +7,8 @@
     <resultMap type="BizObjMetrics" id="BizObjMetricsResult">
         <result property="objMetricsId" column="OBJ_METRICS_ID"/>
         <result property="objId" column="OBJ_ID"/>
+        <result property="objName" column="OBJ_NAME"/>
+        <result property="objType" column="OBJ_TYPE"/>
         <result property="tplId" column="TPL_ID"/>
         <result property="metricsId" column="METRICS_ID"/>
         <result property="metricsName" column="METRICS_NAME"/>
@@ -39,7 +41,7 @@
                      a.OBJ_ID,
                      a.TPL_ID,
                      a.METRICS_ID,
-                     a.METRICS_NAME,
+                     b.METRICS_NAME,
                      a.METRICS_CODE,
                      a.DATA_EXP,
                      a.ALARM_LOW,
@@ -56,12 +58,13 @@
                      b.METRICS_NAME as METRICS_NAME_b,
                      b.METRICS_EXP,
                      b.METRICS_TYPE,
-                     b.ALARM_LOW    as ALARM_LOW_b,
-                     b.ALARM_MID    as ALARM_MID_b,
-                     b.ALARM_HIGH   as ALARM_HIGH_b
+                     c.obj_name,
+                     c.obj_type
               from biz_obj_metrics a,
-                   metrics_def b
-              where a.METRICS_ID = b.METRICS_ID) t
+                   metrics_def b,
+                   biz_obj c
+              where a.METRICS_ID = b.METRICS_ID
+                and a.obj_id = c.obj_id) t
     </sql>
 
     <select id="selectBizObjMetricsList" parameterType="BizObjMetrics" resultMap="BizObjMetricsResult">
@@ -79,6 +82,12 @@
             <if test="metricsName != null  and metricsName != ''">
                 and METRICS_NAME like concat('%', #{metricsName}, '%')
             </if>
+             <if test="objName != null  and objName != ''">
+                and OBJ_NAME like concat('%', #{objName}, '%')
+            </if>
+            <if test="objType != null  and objType != ''">
+                and OBJ_TYPE=#{objType}
+            </if>
             <if test="metricsCode != null  and metricsCode != ''">
                 and METRICS_CODE like concat(#{metricsCode}, '%')
             </if>