Просмотр исходного кода

20230806-添加部分监控controller

iaun 3 лет назад
Родитель
Сommit
7cb1db61e9
39 измененных файлов с 938 добавлено и 213 удалено
  1. 256 2
      src/main/java/cn/iaun/it/controller/ItMonitorController.java
  2. 39 98
      src/main/java/cn/iaun/it/controller/ItResourceController.java
  3. 4 32
      src/main/java/cn/iaun/it/controller/ItUserController.java
  4. 1 0
      src/main/java/cn/iaun/it/interceptor/PermissionInterceptor.java
  5. 10 0
      src/main/java/cn/iaun/it/mapper/ItMonitorAgentMapper.java
  6. 7 0
      src/main/java/cn/iaun/it/mapper/ItMonitorAlarmMapper.java
  7. 12 0
      src/main/java/cn/iaun/it/mapper/ItMonitorDataMapper.java
  8. 10 0
      src/main/java/cn/iaun/it/mapper/ItMonitorItemGroupMapper.java
  9. 10 0
      src/main/java/cn/iaun/it/mapper/ItMonitorItemMapper.java
  10. 10 0
      src/main/java/cn/iaun/it/mapper/ItMonitorResourceGroupMapper.java
  11. 9 0
      src/main/java/cn/iaun/it/mapper/ItMonitorResourceMapper.java
  12. 10 0
      src/main/java/cn/iaun/it/mapper/ItMonitorTemplateMapper.java
  13. 9 0
      src/main/java/cn/iaun/it/mapper/ItMonitorThresholdMapper.java
  14. 7 0
      src/main/java/cn/iaun/it/model/ItMonitorAgent.java
  15. 11 0
      src/main/java/cn/iaun/it/model/ItMonitorAgentKey.java
  16. 11 0
      src/main/java/cn/iaun/it/model/ItMonitorItem.java
  17. 7 0
      src/main/java/cn/iaun/it/model/ItMonitorItemGroup.java
  18. 7 0
      src/main/java/cn/iaun/it/model/ItMonitorResource.java
  19. 3 0
      src/main/java/cn/iaun/it/model/ItMonitorResourceGroup.java
  20. 3 0
      src/main/java/cn/iaun/it/model/ItMonitorTemplate.java
  21. 16 1
      src/main/java/cn/iaun/it/model/ItMonitorThreshold.java
  22. 25 0
      src/main/java/cn/iaun/it/model/vo/monitor/controller/ItMonitorAgentKeyReqVo.java
  23. 36 0
      src/main/java/cn/iaun/it/model/vo/monitor/controller/ItMonitorAgentReqVo.java
  24. 34 0
      src/main/java/cn/iaun/it/model/vo/monitor/controller/ItMonitorThresholdGetReqVo.java
  25. 34 0
      src/main/java/cn/iaun/it/model/vo/resource/controller/ItResourceAttributeReqVo.java
  26. 35 0
      src/main/java/cn/iaun/it/model/vo/resource/controller/ItResourceReqVo.java
  27. 30 0
      src/main/java/cn/iaun/it/model/vo/user/controller/ItUserLoginReqVo.java
  28. 15 1
      src/main/java/cn/iaun/it/service/ItMonitorService.java
  29. 129 38
      src/main/java/cn/iaun/it/service/impl/ItMonitorServiceImpl.java
  30. 6 0
      src/main/java/cn/iaun/it/util/Result.java
  31. 13 0
      src/main/resources/db/data.sql
  32. 42 41
      src/main/resources/db/schema.sql
  33. 11 0
      src/main/resources/mapper/ItMonitorAgentMapper.xml
  34. 14 0
      src/main/resources/mapper/ItMonitorDataMapper.xml
  35. 11 0
      src/main/resources/mapper/ItMonitorItemGroupMapper.xml
  36. 12 0
      src/main/resources/mapper/ItMonitorItemMapper.xml
  37. 11 0
      src/main/resources/mapper/ItMonitorResourceGroupMapper.xml
  38. 11 0
      src/main/resources/mapper/ItMonitorTemplateMapper.xml
  39. 17 0
      src/test/java/cn/iaun/it/MonitorTest.java

+ 256 - 2
src/main/java/cn/iaun/it/controller/ItMonitorController.java

@@ -1,9 +1,263 @@
 package cn.iaun.it.controller;
 
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import cn.iaun.it.model.*;
+import cn.iaun.it.model.vo.monitor.controller.ItMonitorAgentKeyReqVo;
+import cn.iaun.it.model.vo.monitor.controller.ItMonitorAgentReqVo;
+import cn.iaun.it.model.vo.monitor.controller.ItMonitorThresholdGetReqVo;
+import cn.iaun.it.service.ItMonitorService;
+import cn.iaun.it.util.MD5Util;
+import cn.iaun.it.util.MyPage;
+import cn.iaun.it.util.Result;
+import cn.iaun.it.util.ResultCode;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
 
 @RestController
 @RequestMapping("/monitor")
 public class ItMonitorController {
+    private final ItMonitorService itMonitorService;
+
+    public ItMonitorController(ItMonitorService itMonitorService) {
+        this.itMonitorService = itMonitorService;
+    }
+
+    @PostMapping("/agent/key/get")
+    public Result<List<ItMonitorAgentKey>> getItMonitorAgentKey() {
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.getAllAgentKey());
+    }
+
+    @PostMapping("/agent/key/gen")
+    public Result<String> genItMonitorAgentKey(@Validated @RequestBody ItMonitorAgentKeyReqVo request) {
+        String key = MD5Util.md5Token("agent");
+        int result = itMonitorService.addAgentKey(key, request.getRemark());
+        if (result == 1) {
+            return new Result<>(ResultCode.SUCCESS);
+        } else {
+            return new Result<>(ResultCode.FAILED);
+        }
+    }
+
+    @PostMapping("/agent/key/del/{i}")
+    public Result<?> delItMonitorAgentKey(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        int result = itMonitorService.delAgentKey(id);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/agent/key/set")
+    public Result<?> setItMonitorAgentKey(@Validated @RequestBody ItMonitorAgentKeyReqVo request) {
+        if (request.getId() == null) {
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
+        }
+        ItMonitorAgentKey itMonitorAgentKey = new ItMonitorAgentKey();
+        itMonitorAgentKey.setRemark(request.getRemark());
+        itMonitorAgentKey.setAgentKeyId(request.getId());
+        int result = itMonitorService.setAgentKey(itMonitorAgentKey);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/agent/get")
+    public Result<MyPage<ItMonitorAgent>> getItMonitorAgent(@Validated @RequestBody ItMonitorAgentReqVo request) {
+        if (request.getPageNo() == null) {
+            request.setPageNo(1);
+        }
+        if (request.getPageSize() == null) {
+            request.setPageSize(20);
+        }
+        IPage<ItMonitorAgent> pageData = itMonitorService.getAgent(request.getPageNo(), request.getPageSize(), request.getFilter());
+        MyPage<ItMonitorAgent> myPage = new MyPage<>(pageData);
+        return new Result<>(ResultCode.SUCCESS, myPage);
+    }
+
+    @PostMapping("/agent/add")
+    public Result<?> addItMonitorAgent(@Validated @RequestBody ItMonitorAgent itMonitorAgent) {
+        itMonitorAgent.setAgentId(null);
+        int result = itMonitorService.addAgent(itMonitorAgent);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/agent/del/{i}")
+    public Result<?> delItMonitorAgent(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        int result = itMonitorService.delAgent(id);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/template/get")
+    public Result<List<ItMonitorTemplate>> getItMonitorTemplate() {
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.getAllTemplate());
+    }
+
+    @PostMapping("/template/add")
+    public Result<?> addItMonitorTemplate(@Validated @RequestBody ItMonitorTemplate itMonitorTemplate) {
+        itMonitorTemplate.setTemplateId(null);
+        int result = itMonitorService.addTemplate(itMonitorTemplate);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/template/del/{i}")
+    public Result<?> delItMonitorTemplate(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        int result = itMonitorService.delTemplate(id);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/template/set")
+    public Result<?> setItMonitorTemplate(@Validated @RequestBody ItMonitorTemplate itMonitorTemplate) {
+        if (itMonitorTemplate.getTemplateId() == null) {
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
+        }
+        int result = itMonitorService.setTemplate(itMonitorTemplate);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/resource/group/get")
+    public Result<List<ItMonitorResourceGroup>> getItMonitorResourceGroup() {
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.getAllResourceGroup());
+    }
+
+    @PostMapping("/resource/group/add")
+    public Result<?> addItMonitorResourceGroup(@Validated @RequestBody ItMonitorResourceGroup itMonitorResourceGroup) {
+        itMonitorResourceGroup.setGroupId(null);
+        int result = itMonitorService.addResourceGroup(itMonitorResourceGroup);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/resource/group/del/{i}")
+    public Result<?> delItMonitorResourceGroup(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        int result = itMonitorService.delResourceGroup(id);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/resource/group/set")
+    public Result<?> setItMonitorResourceGroup(@Validated @RequestBody ItMonitorResourceGroup itMonitorResourceGroup) {
+        if (itMonitorResourceGroup.getGroupId() == null) {
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
+        }
+        int result = itMonitorService.setResourceGroup(itMonitorResourceGroup);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/resource/get/{i}")
+    public Result<List<ItMonitorResource>> getItMonitorResource(@PathVariable String i) {
+        if (i.equals("all")) {
+            return new Result<>(ResultCode.SUCCESS, itMonitorService.getAllResource());
+        }
+        Long id = Long.parseLong(i);
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.getResourceByGroupId(id));
+    }
+
+    @PostMapping("/resource/add")
+    public Result<?> addItMonitorResource(@Validated @RequestBody ItMonitorResource itMonitorResource) {
+        if (!itMonitorService.checkAgentExistByAgentId(itMonitorResource.getAgentId())
+                || !itMonitorService.checkTemplateExistByTemplateId(itMonitorResource.getTemplateId())
+                || !itMonitorService.checkResourceGroupExistByGroupId(itMonitorResource.getResourceGroupId())
+        ) {
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
+        }
+        int result = itMonitorService.addResource(itMonitorResource);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/resource/del/{i}")
+    public Result<?> delItMonitorResource(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        int result = itMonitorService.delResource(id);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/resource/set")
+    public Result<?> setItMonitorResource(ItMonitorResource itMonitorResource) { // 只允许修改名称
+        if (itMonitorResource.getResourceId() == null || itMonitorResource.getResourceName() == null || itMonitorResource.getResourceName().isEmpty()) {
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
+        }
+        itMonitorResource.setTemplateId(null);
+        itMonitorResource.setAgentId(null);
+        itMonitorResource.setResourceGroupId(null);
+        int result = itMonitorService.setResource(itMonitorResource);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/item/group/get")
+    public Result<List<ItMonitorItemGroup>> getItResourceItemGroup() {
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.getAllItemGroup());
+    }
+
+    @PostMapping("/item/group/add")
+    public Result<?> addItMonitorItemGroup(@Validated @RequestBody ItMonitorItemGroup itMonitorItemGroup) {
+        if (!itMonitorService.checkTemplateExistByTemplateId(itMonitorItemGroup.getTemplateId())
+                || itMonitorItemGroup.getInterval() <= 0 || itMonitorItemGroup.getInterval() >= 60
+        ) {
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
+        }
+        itMonitorItemGroup.setTopItemId(-1L);
+        int result = itMonitorService.addItemGroup(itMonitorItemGroup);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/item/group/del/{i}")
+    public Result<?> delItMonitorItemGroup(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        int result = itMonitorService.delItemGroup(id);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/item/group/set")
+    public Result<?> setItMonitorItemGroup(ItMonitorItemGroup itMonitorItemGroup) { // 只允许修改名称、间隔、置顶itemId
+        if (itMonitorItemGroup.getGroupId() == null || itMonitorItemGroup.getGroupName() == null || itMonitorItemGroup.getGroupName().isEmpty()
+                || (itMonitorItemGroup.getTopItemId() != -1 && !itMonitorService.checkItemExistByItemId(itMonitorItemGroup.getTopItemId(), itMonitorItemGroup.getGroupId()))
+        ) {
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
+        }
+        itMonitorItemGroup.setTemplateId(null);
+        int result = itMonitorService.setItemGroup(itMonitorItemGroup);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/item/get/{i}")
+    public Result<List<ItMonitorItem>> getItMonitorItem(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.getAllItemByGroupId(id));
+    }
+
+    @PostMapping("/item/add")
+    public Result<?> addItMonitorItem(@Validated @RequestBody ItMonitorItem itMonitorItem) {
+        if (!itMonitorService.checkItemGroupExistByGroupId(itMonitorItem.getItemGroupId())) {
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
+        }
+        itMonitorItem.setItemId(null);
+        int result = itMonitorService.addItem(itMonitorItem);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/item/del/{i}")
+    public Result<?> delItMonitorItem(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        int result = itMonitorService.delItem(id);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
+    @PostMapping("/item/set")
+    public Result<?> setItMonitorItem(@Validated @RequestBody ItMonitorItem itMonitorItem) {
+        if (itMonitorItem.getItemId() == null) {
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
+        }
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.setItem(itMonitorItem));
+    }
+
+    @PostMapping("/threshold/get")
+    public Result<List<ItMonitorThreshold>> getItThreshold(@Validated @RequestBody ItMonitorThresholdGetReqVo request) {
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.getThresholdByResourceIdAndItemId(request.getResourceId(), request.getItemId()));
+    }
+
+    @PostMapping("/threshold/set")
+    public Result<?> setItMonitorThreshold(ItMonitorThreshold itMonitorThreshold) {
+        return null;
+    }
+
+
 }

+ 39 - 98
src/main/java/cn/iaun/it/controller/ItResourceController.java

@@ -1,6 +1,8 @@
 package cn.iaun.it.controller;
 
 import cn.iaun.it.model.*;
+import cn.iaun.it.model.vo.resource.controller.ItResourceAttributeReqVo;
+import cn.iaun.it.model.vo.resource.controller.ItResourceReqVo;
 import cn.iaun.it.service.ItResourceService;
 import cn.iaun.it.util.MyPage;
 import cn.iaun.it.util.Result;
@@ -9,7 +11,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import javax.validation.constraints.NotNull;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -41,18 +42,18 @@ public class ItResourceController {
                 }
             }
             if (!exists) {
-                return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+                return new Result<>(ResultCode.FAILED_PARAM_INVALID);
             }
         }
         int result = itResourceService.addResourceType(itResourceType);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping(value = "/type/del/{i}")
     public Result<?> delItResourceType(@PathVariable String i) {
         long id = Long.parseLong(i);
         int result = itResourceService.delResourceType(id);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping(value = "/type/set")
@@ -67,11 +68,11 @@ public class ItResourceController {
                 }
             }
             if (!exists) {
-                return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+                return new Result<>(ResultCode.FAILED_PARAM_INVALID);
             }
         }
         int result = itResourceService.setResourceType(itResourceType);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping(value = "/group/get")
@@ -83,7 +84,7 @@ public class ItResourceController {
     public Result<?> addItResourceGroup(@Validated @RequestBody ItResourceGroup itResourceGroup) {
         itResourceGroup.setGroupId(null);
         int result = itResourceService.addResourceGroup(itResourceGroup);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping(value = "/group/del/{i}")
@@ -94,24 +95,24 @@ public class ItResourceController {
         if (result == 1) {
             itResourceService.deleteAttributeByGroupId(id);
         }
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping(value = "/group/set")
     public Result<?> setItResourceGroup(@Validated @RequestBody ItResourceGroup itResourceGroup) {
         int result = itResourceService.setResourceGroup(itResourceGroup);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping(value = "/attribute/get")
-    public Result<MyPage<ItResourceAttribute>> getItResourceAttribute(@Validated @RequestBody ItResourceAttributeReqData page) {
-        if (page.pageNo == null) {
-            page.pageNo = 1;
+    public Result<MyPage<ItResourceAttribute>> getItResourceAttribute(@Validated @RequestBody ItResourceAttributeReqVo page) {
+        if (page.getPageNo() == null) {
+            page.setPageNo(1);
         }
-        if (page.pageSize == null) {
-            page.pageSize = 20;
+        if (page.getPageSize() == null) {
+            page.setPageSize(20);
         }
-        IPage<ItResourceAttribute> pageData = itResourceService.getResourceAttribute(page.pageNo, page.pageSize, page.groupId);
+        IPage<ItResourceAttribute> pageData = itResourceService.getResourceAttribute(page.getPageNo(), page.getPageSize(), page.getGroupId());
         MyPage<ItResourceAttribute> myPage = new MyPage<>(pageData);
         return new Result<>(ResultCode.SUCCESS, myPage);
     }
@@ -124,7 +125,7 @@ public class ItResourceController {
             case 0:
                 itResourceAttribute.setOptions("");
                 if (itResourceAttribute.getValueType() != 0 && itResourceAttribute.getValueType() != 1) {
-                    return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+                    return new Result<>(ResultCode.FAILED_PARAM_INVALID);
                 } else if (itResourceAttribute.getValueType() == 1 && !itResourceAttribute.getDefaultValue().equals("")) { // 验证数字
                     Integer.parseInt(itResourceAttribute.getDefaultValue());
                 }
@@ -146,20 +147,20 @@ public class ItResourceController {
                         }
                     }
                     if (!exists) {
-                        return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+                        return new Result<>(ResultCode.FAILED_PARAM_INVALID);
                     }
                 }
                 break;
         }
         int result = itResourceService.addResourceAttribute(itResourceAttribute);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping(value = "/attribute/del/{i}")
     public Result<?> delItResourceAttribute(@PathVariable String i) {
         long id = Long.parseLong(i);
         int result = itResourceService.delResourceAttribute(id);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @SuppressWarnings("ResultOfMethodCallIgnored")
@@ -169,7 +170,7 @@ public class ItResourceController {
             case 0:
                 itResourceAttribute.setOptions("");
                 if (itResourceAttribute.getValueType() != 0 && itResourceAttribute.getValueType() != 1) {
-                    return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+                    return new Result<>(ResultCode.FAILED_PARAM_INVALID);
                 } else if (itResourceAttribute.getValueType() == 1 && !itResourceAttribute.getDefaultValue().equals("")) { // 验证数字
                     Integer.parseInt(itResourceAttribute.getDefaultValue());
                 }
@@ -191,23 +192,23 @@ public class ItResourceController {
                         }
                     }
                     if (!exists) {
-                        return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+                        return new Result<>(ResultCode.FAILED_PARAM_INVALID);
                     }
                 }
                 break;
         }
 
         int result = itResourceService.setResourceAttribute(itResourceAttribute);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping("/get")
-    public Result<MyPage<ItResource>> getItResource(@Validated @RequestBody ItResourceReqData page) {
-        if (page.pageNo == null) {
-            page.pageNo = 1;
+    public Result<MyPage<ItResource>> getItResource(@Validated @RequestBody ItResourceReqVo page) {
+        if (page.getPageNo() == null) {
+            page.setPageNo(1);
         }
-        if (page.pageSize == null) {
-            page.pageSize = 20;
+        if (page.getPageSize() == null) {
+            page.setPageSize(20);
         }
         IPage<ItResource> iPage = itResourceService.getResource(page.getPageNo(), page.getPageSize(), page.getTypeId());
         MyPage<ItResource> myPage = new MyPage<>(iPage);
@@ -234,7 +235,7 @@ public class ItResourceController {
             }
         }
         if (!exists) {
-            return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
         }
         // group
         List<ItResourceGroup> itResourceGroups = itResourceService.getResourceGroup();
@@ -246,18 +247,18 @@ public class ItResourceController {
             }
         }
         if (!exists) {
-            return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
         }
 
         int result = itResourceService.addResource(itResource);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping("/del/{i}")
     public Result<?> delItResource(@PathVariable String i) {
         long id = Long.parseLong(i);
         int result = itResourceService.delResource(id);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping("/set")
@@ -273,7 +274,7 @@ public class ItResourceController {
             }
         }
         if (!exists) {
-            return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
         }
         // group
         List<ItResourceGroup> itResourceGroups = itResourceService.getResourceGroup();
@@ -285,14 +286,14 @@ public class ItResourceController {
             }
         }
         if (!exists) {
-            return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
         }
         int result = itResourceService.setResource(itResource);
         if (result == 1) {
             // 清除非此groupId的数据
             itResourceService.deleteValueByResourceIdAndNEGroupId(itResource.getResourceId(), itResource.getGroupId());
         }
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping("/value/get/{i}")
@@ -305,7 +306,7 @@ public class ItResourceController {
     public Result<?> delItResourceValue(@PathVariable String i) {
         long id = Long.parseLong(i);
         int result = itResourceService.delResourceValueByResourceId(id);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
     @PostMapping("/value/set")
@@ -323,7 +324,7 @@ public class ItResourceController {
         int resourceCount = itResourceService.countResourceValueByResourceIds(resourceSet);
         // 判断传入的ID是否在数据库存在(判断数量是否对上)
         if (resourceSet.size() != resourceCount || attributeSet.size() != attributeCount) {
-            return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+            return new Result<>(ResultCode.FAILED_PARAM_INVALID);
         }
 
         HashMap<Long, Long> dbAttributeIds = itResourceService.getGroupIdByAttributeId(attributeSet);
@@ -334,71 +335,11 @@ public class ItResourceController {
             Long attributeId = itResourceValue.getAttributeId();
             // 判断groupID是否相等
             if (!dbAttributeIds.get(attributeId).equals(dbResourceIds.get(resourceId))) {
-                return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
+                return new Result<>(ResultCode.FAILED_PARAM_INVALID);
             }
         }
         int result = itResourceService.setResourceValueById(itResourceValues);
-        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
-}
-
-class ItResourceAttributeReqData {
-    Integer pageNo;
-    Integer pageSize;
-    @NotNull Long groupId;
-
-    public Integer getPageNo() {
-        return pageNo;
-    }
-
-    public void setPageNo(Integer pageNo) {
-        this.pageNo = pageNo;
-    }
-
-    public Integer getPageSize() {
-        return pageSize;
-    }
-
-    public void setPageSize(Integer pageSize) {
-        this.pageSize = pageSize;
-    }
-
-    public Long getGroupId() {
-        return groupId;
-    }
-
-    public void setGroupId(Long groupId) {
-        this.groupId = groupId;
-    }
-}
-
-class ItResourceReqData {
-    Integer pageNo;
-    Integer pageSize;
-    @NotNull Long typeId;
-
-    public Integer getPageNo() {
-        return pageNo;
-    }
-
-    public void setPageNo(Integer pageNo) {
-        this.pageNo = pageNo;
-    }
-
-    public Integer getPageSize() {
-        return pageSize;
-    }
-
-    public void setPageSize(Integer pageSize) {
-        this.pageSize = pageSize;
-    }
-
-    public Long getTypeId() {
-        return typeId;
-    }
-
-    public void setTypeId(Long typeId) {
-        this.typeId = typeId;
-    }
 }

+ 4 - 32
src/main/java/cn/iaun/it/controller/ItUserController.java

@@ -2,6 +2,7 @@ package cn.iaun.it.controller;
 
 import cn.iaun.it.model.vo.user.ItUserInfoVo;
 import cn.iaun.it.model.vo.user.ItUserLoginInfoVo;
+import cn.iaun.it.model.vo.user.controller.ItUserLoginReqVo;
 import cn.iaun.it.service.ItUserService;
 import cn.iaun.it.util.Result;
 import cn.iaun.it.util.ResultCode;
@@ -17,10 +18,10 @@ public class ItUserController {
     }
 
     @PostMapping(value = "/login")
-    public Result<ItUserLoginInfoVo> login(@RequestBody LoginRequest request) {
-        ItUserLoginInfoVo itUserLoginInfoVo = itUserService.getTokenByUserAndPassword(request.user, request.password);
+    public Result<ItUserLoginInfoVo> login(@RequestBody ItUserLoginReqVo request) {
+        ItUserLoginInfoVo itUserLoginInfoVo = itUserService.getTokenByUserAndPassword(request.getUser(), request.getPassword());
         if (itUserLoginInfoVo == null) {
-            return new Result<>(ResultCode.USER_WRONG_USER_OR_PASSWORD, null);
+            return new Result<>(ResultCode.USER_WRONG_USER_OR_PASSWORD);
         }
         return new Result<>(ResultCode.SUCCESS, itUserLoginInfoVo);
     }
@@ -29,33 +30,4 @@ public class ItUserController {
     public Result<ItUserInfoVo> info(@RequestAttribute("userId") Long userId) {
         return new Result<>(ResultCode.SUCCESS, itUserService.getUserInfoByUserId(userId));
     }
-}
-
-class LoginRequest {
-    String user;
-    String password;
-
-    @Override
-    public String toString() {
-        return "LoginRequest{" +
-                "user='" + user + '\'' +
-                ", password='" + password + '\'' +
-                '}';
-    }
-
-    public String getUser() {
-        return user;
-    }
-
-    public void setUser(String user) {
-        this.user = user;
-    }
-
-    public String getPassword() {
-        return password;
-    }
-
-    public void setPassword(String password) {
-        this.password = password;
-    }
 }

+ 1 - 0
src/main/java/cn/iaun/it/interceptor/PermissionInterceptor.java

@@ -15,6 +15,7 @@ import java.util.Map;
 public class PermissionInterceptor implements HandlerInterceptor {
     private Map<String, Long> getSys() {
         Map<String, Long> map = new HashMap<>();
+        map.put("monitor", 2L);
         map.put("resource", 3L);
         return map;
     }

+ 10 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorAgentMapper.java

@@ -0,0 +1,10 @@
+package cn.iaun.it.mapper;
+
+import cn.iaun.it.model.ItMonitorAgent;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ItMonitorAgentMapper extends BaseMapper<ItMonitorAgent> {
+    Long selectByAgentId(Long agentId);
+}

+ 7 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorAlarmMapper.java

@@ -0,0 +1,7 @@
+package cn.iaun.it.mapper;
+
+import cn.iaun.it.model.ItMonitorAlarm;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+public interface ItMonitorAlarmMapper extends BaseMapper<ItMonitorAlarm> {
+}

+ 12 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorDataMapper.java

@@ -0,0 +1,12 @@
+package cn.iaun.it.mapper;
+
+import cn.iaun.it.model.ItMonitorData;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface ItMonitorDataMapper extends BaseMapper<ItMonitorData> {
+    List<ItMonitorData> selectLatestItMonitorData(Long resourceId);
+}

+ 10 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorItemGroupMapper.java

@@ -0,0 +1,10 @@
+package cn.iaun.it.mapper;
+
+import cn.iaun.it.model.ItMonitorItemGroup;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ItMonitorItemGroupMapper extends BaseMapper<ItMonitorItemGroup> {
+    Long getByGroupId(Long groupId);
+}

+ 10 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorItemMapper.java

@@ -0,0 +1,10 @@
+package cn.iaun.it.mapper;
+
+import cn.iaun.it.model.ItMonitorItem;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ItMonitorItemMapper extends BaseMapper<ItMonitorItem> {
+    Long selectByItemId(Long itemId, Long groupId);
+}

+ 10 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorResourceGroupMapper.java

@@ -0,0 +1,10 @@
+package cn.iaun.it.mapper;
+
+import cn.iaun.it.model.ItMonitorResourceGroup;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ItMonitorResourceGroupMapper extends BaseMapper<ItMonitorResourceGroup> {
+    Long getByGroupId(Long groupId);
+}

+ 9 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorResourceMapper.java

@@ -0,0 +1,9 @@
+package cn.iaun.it.mapper;
+
+import cn.iaun.it.model.ItMonitorResource;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ItMonitorResourceMapper extends BaseMapper<ItMonitorResource> {
+}

+ 10 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorTemplateMapper.java

@@ -0,0 +1,10 @@
+package cn.iaun.it.mapper;
+
+import cn.iaun.it.model.ItMonitorTemplate;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ItMonitorTemplateMapper extends BaseMapper<ItMonitorTemplate> {
+    Long selectByTemplateId(Long templateId);
+}

+ 9 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorThresholdMapper.java

@@ -0,0 +1,9 @@
+package cn.iaun.it.mapper;
+
+import cn.iaun.it.model.ItMonitorThreshold;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ItMonitorThresholdMapper extends BaseMapper<ItMonitorThreshold> {
+}

+ 7 - 0
src/main/java/cn/iaun/it/model/ItMonitorAgent.java

@@ -1,13 +1,20 @@
 package cn.iaun.it.model;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 
+import javax.validation.constraints.NotBlank;
+
 public class ItMonitorAgent {
     @TableId(type = IdType.AUTO)
     private Long agentId;
+    @NotBlank
     private String agentName;
+    @NotBlank
+    @TableField("agent_ip")
     private String agentIP;
+    @NotBlank
     private Long agentKeyId;
 
     @Override

+ 11 - 0
src/main/java/cn/iaun/it/model/ItMonitorAgentKey.java

@@ -1,12 +1,15 @@
 package cn.iaun.it.model;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 
 public class ItMonitorAgentKey {
     @TableId(type = IdType.AUTO)
     private Long agentKeyId;
+    @TableField("`key`")
     private String key;
+    private String remark;
 
     @Override
     public String toString() {
@@ -16,6 +19,14 @@ public class ItMonitorAgentKey {
                 '}';
     }
 
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
     public Long getAgentKeyId() {
         return agentKeyId;
     }

+ 11 - 0
src/main/java/cn/iaun/it/model/ItMonitorItem.java

@@ -3,12 +3,23 @@ package cn.iaun.it.model;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
 public class ItMonitorItem {
     @TableId(type = IdType.AUTO)
     private Long itemId;
+    @NotBlank
     private String itemName;
+    @NotBlank
     private String itemKeyName;
+    @NotNull
     private Long itemGroupId;
+    @NotNull
+    @Min(0)
+    @Max(3)
     private Integer itemType;
 
     @Override

+ 7 - 0
src/main/java/cn/iaun/it/model/ItMonitorItemGroup.java

@@ -3,12 +3,19 @@ package cn.iaun.it.model;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
 public class ItMonitorItemGroup {
     @TableId(type = IdType.AUTO)
     private Long groupId;
+    @NotBlank
     private String groupName;
+    @NotNull
     private Long templateId;
+    @NotNull
     private Integer interval;
+    @NotNull
     private Long topItemId;
 
     @Override

+ 7 - 0
src/main/java/cn/iaun/it/model/ItMonitorResource.java

@@ -3,12 +3,19 @@ package cn.iaun.it.model;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
 public class ItMonitorResource {
     @TableId(type = IdType.AUTO)
     private Long resourceId;
+    @NotNull
     private Long templateId;
+    @NotNull
     private Long agentId;
+    @NotNull
     private Long resourceGroupId;
+    @NotBlank
     private String resourceName;
 
     @Override

+ 3 - 0
src/main/java/cn/iaun/it/model/ItMonitorResourceGroup.java

@@ -3,9 +3,12 @@ package cn.iaun.it.model;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 
+import javax.validation.constraints.NotBlank;
+
 public class ItMonitorResourceGroup {
     @TableId(type = IdType.AUTO)
     private Long groupId;
+    @NotBlank
     private String groupName;
 
     @Override

+ 3 - 0
src/main/java/cn/iaun/it/model/ItMonitorTemplate.java

@@ -3,9 +3,12 @@ package cn.iaun.it.model;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 
+import javax.validation.constraints.NotBlank;
+
 public class ItMonitorTemplate {
     @TableId(type = IdType.AUTO)
     private Long templateId;
+    @NotBlank
     private String templateName;
 
     @Override

+ 16 - 1
src/main/java/cn/iaun/it/model/ItMonitorThreshold.java

@@ -1,11 +1,26 @@
 package cn.iaun.it.model;
 
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
 public class ItMonitorThreshold {
+    @NotNull
     private Long itemId;
+    @NotNull
     private Long resourceId;
+    @NotNull
     private Integer alarmType;
-    private Integer thresholdType;
+    @NotNull
+    @Min(0)
+    @Max(8)
+    private Integer thresholdType; // 阈值类型:0发生变化;1大于;2小于;3大于等于;4小于等于;5等于;6不等于;7包含;8不包含
+    @NotBlank
     private String threshold;
+    @NotNull
+    @Min(1)
+    @Max(10)
     private Integer times;
 
     @Override

+ 25 - 0
src/main/java/cn/iaun/it/model/vo/monitor/controller/ItMonitorAgentKeyReqVo.java

@@ -0,0 +1,25 @@
+package cn.iaun.it.model.vo.monitor.controller;
+
+import javax.validation.constraints.NotNull;
+
+public class ItMonitorAgentKeyReqVo {
+    private Long id;
+    @NotNull
+    private String remark;
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+}

+ 36 - 0
src/main/java/cn/iaun/it/model/vo/monitor/controller/ItMonitorAgentReqVo.java

@@ -0,0 +1,36 @@
+package cn.iaun.it.model.vo.monitor.controller;
+
+import cn.iaun.it.model.ItMonitorAgent;
+
+import javax.validation.constraints.NotNull;
+
+public class ItMonitorAgentReqVo {
+    private Integer pageNo;
+    private Integer pageSize;
+    @NotNull
+    private ItMonitorAgent filter;
+
+    public Integer getPageNo() {
+        return pageNo;
+    }
+
+    public void setPageNo(Integer pageNo) {
+        this.pageNo = pageNo;
+    }
+
+    public Integer getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(Integer pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    public ItMonitorAgent getFilter() {
+        return filter;
+    }
+
+    public void setFilter(ItMonitorAgent filter) {
+        this.filter = filter;
+    }
+}

+ 34 - 0
src/main/java/cn/iaun/it/model/vo/monitor/controller/ItMonitorThresholdGetReqVo.java

@@ -0,0 +1,34 @@
+package cn.iaun.it.model.vo.monitor.controller;
+
+import javax.validation.constraints.NotNull;
+
+public class ItMonitorThresholdGetReqVo {
+    @NotNull
+    private Long resourceId;
+    @NotNull
+    private Long itemId;
+
+    @Override
+    public String toString() {
+        return "ItMonitorThresholdGetReqVo{" +
+                "resourceId=" + resourceId +
+                ", itemId=" + itemId +
+                '}';
+    }
+
+    public Long getResourceId() {
+        return resourceId;
+    }
+
+    public void setResourceId(Long resourceId) {
+        this.resourceId = resourceId;
+    }
+
+    public Long getItemId() {
+        return itemId;
+    }
+
+    public void setItemId(Long itemId) {
+        this.itemId = itemId;
+    }
+}

+ 34 - 0
src/main/java/cn/iaun/it/model/vo/resource/controller/ItResourceAttributeReqVo.java

@@ -0,0 +1,34 @@
+package cn.iaun.it.model.vo.resource.controller;
+
+import javax.validation.constraints.NotNull;
+
+public class ItResourceAttributeReqVo {
+    private Integer pageNo;
+    private Integer pageSize;
+    @NotNull
+    private Long groupId;
+
+    public Integer getPageNo() {
+        return pageNo;
+    }
+
+    public void setPageNo(Integer pageNo) {
+        this.pageNo = pageNo;
+    }
+
+    public Integer getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(Integer pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    public Long getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(Long groupId) {
+        this.groupId = groupId;
+    }
+}

+ 35 - 0
src/main/java/cn/iaun/it/model/vo/resource/controller/ItResourceReqVo.java

@@ -0,0 +1,35 @@
+package cn.iaun.it.model.vo.resource.controller;
+
+import javax.validation.constraints.NotNull;
+
+public class ItResourceReqVo {
+    private Integer pageNo;
+    private Integer pageSize;
+    @NotNull
+    private Long typeId;
+
+    public Integer getPageNo() {
+        return pageNo;
+    }
+
+    public void setPageNo(Integer pageNo) {
+        this.pageNo = pageNo;
+    }
+
+    public Integer getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(Integer pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    public Long getTypeId() {
+        return typeId;
+    }
+
+    public void setTypeId(Long typeId) {
+        this.typeId = typeId;
+    }
+
+}

+ 30 - 0
src/main/java/cn/iaun/it/model/vo/user/controller/ItUserLoginReqVo.java

@@ -0,0 +1,30 @@
+package cn.iaun.it.model.vo.user.controller;
+
+public class ItUserLoginReqVo {
+    private String user;
+    private String password;
+
+    @Override
+    public String toString() {
+        return "LoginRequest{" +
+                "user='" + user + '\'' +
+                ", password='" + password + '\'' +
+                '}';
+    }
+
+    public String getUser() {
+        return user;
+    }
+
+    public void setUser(String user) {
+        this.user = user;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+}

+ 15 - 1
src/main/java/cn/iaun/it/service/ItMonitorService.java

@@ -9,13 +9,17 @@ public interface ItMonitorService {
     // agent key
     List<ItMonitorAgentKey> getAllAgentKey();
 
-    int addAgentKey();
+    int addAgentKey(String key, String remark);
 
     int delAgentKey(Long agentKeyId);
 
+    int setAgentKey(ItMonitorAgentKey itMonitorAgentKey);
+
     // agent
     IPage<ItMonitorAgent> getAgent(Integer pageNo, Integer pageSize, ItMonitorAgent itMonitorAgent);
 
+    boolean checkAgentExistByAgentId(Long agentId);
+
     int addAgent(ItMonitorAgent itMonitorAgent);
 
     int delAgent(Long agentId);
@@ -23,6 +27,8 @@ public interface ItMonitorService {
     // 监控模板
     List<ItMonitorTemplate> getAllTemplate();
 
+    boolean checkTemplateExistByTemplateId(Long templateId);
+
     int addTemplate(ItMonitorTemplate itMonitorTemplate);
 
     int delTemplate(Long templateId);
@@ -32,6 +38,8 @@ public interface ItMonitorService {
     // 资源组
     List<ItMonitorResourceGroup> getAllResourceGroup();
 
+    boolean checkResourceGroupExistByGroupId(Long groupId);
+
     int addResourceGroup(ItMonitorResourceGroup itMonitorResourceGroup);
 
     int delResourceGroup(Long groupId);
@@ -41,6 +49,8 @@ public interface ItMonitorService {
     // 监控资源
     List<ItMonitorResource> getAllResource();
 
+    List<ItMonitorResource> getResourceByGroupId(Long groupId);
+
     int addResource(ItMonitorResource itMonitorResource);
 
     int delResource(Long resourceId);
@@ -50,6 +60,8 @@ public interface ItMonitorService {
     // 监控指标组
     List<ItMonitorItemGroup> getAllItemGroup();
 
+    boolean checkItemGroupExistByGroupId(Long groupId);
+
     int addItemGroup(ItMonitorItemGroup itMonitorItemGroup);
 
     int delItemGroup(Long groupId);
@@ -59,6 +71,8 @@ public interface ItMonitorService {
     // 监控指标
     List<ItMonitorItem> getAllItemByGroupId(Long groupId);
 
+    boolean checkItemExistByItemId(Long itemId, Long groupId);
+
     int addItem(ItMonitorItem itMonitorItem);
 
     int delItem(Long itemId);

+ 129 - 38
src/main/java/cn/iaun/it/service/impl/ItMonitorServiceImpl.java

@@ -1,20 +1,41 @@
 package cn.iaun.it.service.impl;
 
-import cn.iaun.it.mapper.ItMonitorAgentKeyMapper;
+import cn.iaun.it.mapper.*;
 import cn.iaun.it.model.*;
 import cn.iaun.it.service.ItMonitorService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import org.springframework.beans.factory.annotation.Autowired;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.stereotype.Service;
 
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 
 @Service
 public class ItMonitorServiceImpl implements ItMonitorService {
     private final ItMonitorAgentKeyMapper itMonitorAgentKeyMapper;
-
-    public ItMonitorServiceImpl(ItMonitorAgentKeyMapper itMonitorAgentKeyMapper) {
+    private final ItMonitorAgentMapper itMonitorAgentMapper;
+    private final ItMonitorTemplateMapper itMonitorTemplateMapper;
+    private final ItMonitorResourceGroupMapper itMonitorResourceGroupMapper;
+    private final ItMonitorResourceMapper itMonitorResourceMapper;
+    private final ItMonitorItemGroupMapper itMonitorItemGroupMapper;
+    private final ItMonitorItemMapper itMonitorItemMapper;
+    private final ItMonitorThresholdMapper itMonitorThresholdMapper;
+    private final ItMonitorAlarmMapper itMonitorAlarmMapper;
+    private final ItMonitorDataMapper itMonitorDataMapper;
+
+    public ItMonitorServiceImpl(ItMonitorAgentKeyMapper itMonitorAgentKeyMapper, ItMonitorAgentMapper itMonitorAgentMapper, ItMonitorTemplateMapper itMonitorTemplateMapper, ItMonitorResourceGroupMapper itMonitorResourceGroupMapper, ItMonitorResourceMapper itMonitorResourceMapper, ItMonitorItemGroupMapper itMonitorItemGroupMapper, ItMonitorItemMapper itMonitorItemMapper, ItMonitorThresholdMapper itMonitorThresholdMapper, ItMonitorAlarmMapper itMonitorAlarmMapper, ItMonitorDataMapper itMonitorDataMapper) {
         this.itMonitorAgentKeyMapper = itMonitorAgentKeyMapper;
+        this.itMonitorAgentMapper = itMonitorAgentMapper;
+        this.itMonitorTemplateMapper = itMonitorTemplateMapper;
+        this.itMonitorResourceGroupMapper = itMonitorResourceGroupMapper;
+        this.itMonitorResourceMapper = itMonitorResourceMapper;
+        this.itMonitorItemGroupMapper = itMonitorItemGroupMapper;
+        this.itMonitorItemMapper = itMonitorItemMapper;
+        this.itMonitorThresholdMapper = itMonitorThresholdMapper;
+        this.itMonitorAlarmMapper = itMonitorAlarmMapper;
+        this.itMonitorDataMapper = itMonitorDataMapper;
     }
 
     @Override
@@ -23,168 +44,238 @@ public class ItMonitorServiceImpl implements ItMonitorService {
     }
 
     @Override
-    public int addAgentKey() {
-        return 0;
+    public int addAgentKey(String key, String remark) {
+        ItMonitorAgentKey itMonitorAgentKey = new ItMonitorAgentKey();
+        itMonitorAgentKey.setKey(key);
+        itMonitorAgentKey.setRemark(remark);
+        return itMonitorAgentKeyMapper.insert(itMonitorAgentKey);
     }
 
     @Override
     public int delAgentKey(Long agentKeyId) {
-        return 0;
+        return itMonitorAgentKeyMapper.deleteById(agentKeyId);
+    }
+
+    @Override
+    public int setAgentKey(ItMonitorAgentKey itMonitorAgentKey) {
+        return itMonitorAgentKeyMapper.updateById(itMonitorAgentKey);
     }
 
     @Override
     public IPage<ItMonitorAgent> getAgent(Integer pageNo, Integer pageSize, ItMonitorAgent itMonitorAgent) {
-        return null;
+        Page<ItMonitorAgent> page = new Page<>(pageNo, pageSize);
+        QueryWrapper<ItMonitorAgent> queryWrapper = new QueryWrapper<>();
+        if (itMonitorAgent.getAgentName() != null && !itMonitorAgent.getAgentName().isEmpty()) {
+            queryWrapper.likeRight("agent_name", itMonitorAgent.getAgentName());
+        }
+        if (itMonitorAgent.getAgentIP() != null && !itMonitorAgent.getAgentIP().isEmpty()) {
+            queryWrapper.likeRight("agent_ip", itMonitorAgent.getAgentIP());
+        }
+        return itMonitorAgentMapper.selectPage(page, queryWrapper);
+    }
+
+    @Override
+    public boolean checkAgentExistByAgentId(Long agentId) {
+        return itMonitorAgentMapper.selectByAgentId(agentId) != null;
     }
 
     @Override
     public int addAgent(ItMonitorAgent itMonitorAgent) {
-        return 0;
+        return itMonitorAgentMapper.insert(itMonitorAgent);
     }
 
     @Override
     public int delAgent(Long agentId) {
-        return 0;
+        return itMonitorAgentMapper.deleteById(agentId);
     }
 
     @Override
     public List<ItMonitorTemplate> getAllTemplate() {
-        return null;
+        return itMonitorTemplateMapper.selectList(null);
+    }
+
+    @Override
+    public boolean checkTemplateExistByTemplateId(Long templateId) {
+        return itMonitorTemplateMapper.selectByTemplateId(templateId) != null;
     }
 
     @Override
     public int addTemplate(ItMonitorTemplate itMonitorTemplate) {
-        return 0;
+        return itMonitorTemplateMapper.insert(itMonitorTemplate);
     }
 
     @Override
     public int delTemplate(Long templateId) {
-        return 0;
+        return itMonitorTemplateMapper.deleteById(templateId);
     }
 
     @Override
     public int setTemplate(ItMonitorTemplate itMonitorTemplate) {
-        return 0;
+        return itMonitorTemplateMapper.updateById(itMonitorTemplate);
     }
 
     @Override
     public List<ItMonitorResourceGroup> getAllResourceGroup() {
-        return null;
+        return itMonitorResourceGroupMapper.selectList(null);
+    }
+
+    @Override
+    public boolean checkResourceGroupExistByGroupId(Long groupId) {
+        return itMonitorResourceGroupMapper.getByGroupId(groupId) != null;
     }
 
     @Override
     public int addResourceGroup(ItMonitorResourceGroup itMonitorResourceGroup) {
-        return 0;
+        return itMonitorResourceGroupMapper.insert(itMonitorResourceGroup);
     }
 
     @Override
     public int delResourceGroup(Long groupId) {
-        return 0;
+        return itMonitorResourceGroupMapper.deleteById(groupId);
     }
 
     @Override
     public int setResourceGroup(ItMonitorResourceGroup itMonitorResourceGroup) {
-        return 0;
+        return itMonitorResourceGroupMapper.updateById(itMonitorResourceGroup);
     }
 
     @Override
     public List<ItMonitorResource> getAllResource() {
-        return null;
+        return itMonitorResourceMapper.selectList(null);
+    }
+
+    @Override
+    public List<ItMonitorResource> getResourceByGroupId(Long groupId) {
+        QueryWrapper<ItMonitorResource> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("resource_group_id", groupId);
+        return itMonitorResourceMapper.selectList(queryWrapper);
     }
 
     @Override
     public int addResource(ItMonitorResource itMonitorResource) {
-        return 0;
+        return itMonitorResourceMapper.insert(itMonitorResource);
     }
 
     @Override
     public int delResource(Long resourceId) {
-        return 0;
+        return itMonitorResourceMapper.deleteById(resourceId);
     }
 
     @Override
     public int setResource(ItMonitorResource itMonitorResource) {
-        return 0;
+        return itMonitorResourceMapper.updateById(itMonitorResource);
     }
 
     @Override
     public List<ItMonitorItemGroup> getAllItemGroup() {
-        return null;
+        return itMonitorItemGroupMapper.selectList(null);
+    }
+
+    @Override
+    public boolean checkItemGroupExistByGroupId(Long groupId) {
+        return itMonitorItemGroupMapper.getByGroupId(groupId) != null;
     }
 
     @Override
     public int addItemGroup(ItMonitorItemGroup itMonitorItemGroup) {
-        return 0;
+        return itMonitorItemGroupMapper.insert(itMonitorItemGroup);
     }
 
     @Override
     public int delItemGroup(Long groupId) {
-        return 0;
+        return itMonitorItemGroupMapper.deleteById(groupId);
     }
 
     @Override
     public int setItemGroup(ItMonitorItemGroup itMonitorItemGroup) {
-        return 0;
+        return itMonitorItemGroupMapper.updateById(itMonitorItemGroup);
     }
 
     @Override
     public List<ItMonitorItem> getAllItemByGroupId(Long groupId) {
-        return null;
+        QueryWrapper<ItMonitorItem> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("item_group_id", groupId);
+        return itMonitorItemMapper.selectList(queryWrapper);
+    }
+
+    @Override
+    public boolean checkItemExistByItemId(Long itemId, Long groupId) {
+        return itMonitorItemMapper.selectByItemId(itemId, groupId) != null;
     }
 
     @Override
     public int addItem(ItMonitorItem itMonitorItem) {
-        return 0;
+        return itMonitorItemMapper.insert(itMonitorItem);
     }
 
     @Override
     public int delItem(Long itemId) {
-        return 0;
+        return itMonitorItemMapper.deleteById(itemId);
     }
 
     @Override
     public int setItem(ItMonitorItem itMonitorItem) {
-        return 0;
+        return itMonitorItemMapper.updateById(itMonitorItem);
     }
 
     @Override
     public List<ItMonitorThreshold> getThresholdByResourceIdAndItemId(Long resourceId, Long itemId) {
-        return null;
+        QueryWrapper<ItMonitorThreshold> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("resource_id", resourceId);
+        queryWrapper.eq("item_id", itemId);
+        return itMonitorThresholdMapper.selectList(queryWrapper);
     }
 
     @Override
     public int setThreshold(ItMonitorThreshold itMonitorThreshold) {
-        return 0;
+        int updateResult = itMonitorThresholdMapper.updateById(itMonitorThreshold);
+        if (updateResult == 0) {
+            return itMonitorThresholdMapper.insert(itMonitorThreshold);
+        }
     }
 
     @Override
     public int delThresholdByIds(Long itemId, Long resourceId, Integer alarmType) {
-        return 0;
+        QueryWrapper<ItMonitorThreshold> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("resource_id", resourceId);
+        queryWrapper.eq("item_id", itemId);
+        queryWrapper.eq("alarm_type", alarmType);
+        return itMonitorThresholdMapper.delete(queryWrapper);
     }
 
     @Override
     public List<ItMonitorAlarm> getAlarmByResourceId(Long resourceId) {
-        return null;
+        QueryWrapper<ItMonitorAlarm> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("resource_id", resourceId);
+        return itMonitorAlarmMapper.selectList(queryWrapper);
     }
 
     @Override
     public int setAlarm(ItMonitorAlarm itMonitorAlarm) {
-        return 0;
+        return itMonitorAlarmMapper.updateById(itMonitorAlarm);
     }
 
     @Override
     public IPage<ItMonitorData> getDataByIds(Integer pageNo, Integer pageSize, Long resourceId, Long itemId, Integer days) {
-        return null;
+        Page<ItMonitorData> page = new Page<>(pageNo, pageSize);
+        QueryWrapper<ItMonitorData> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("resource_id", resourceId);
+        queryWrapper.eq("item_id", itemId);
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(new Date());
+        calendar.add(Calendar.DATE, days * -1);
+        queryWrapper.ge("record_time", calendar.getTime());
+        return itMonitorDataMapper.selectPage(page, queryWrapper);
     }
 
     @Override
     public List<ItMonitorData> getLatestDataByResourceId(Long resourceId) {
-        return null;
+        return itMonitorDataMapper.selectLatestItMonitorData(resourceId);
     }
 
     @Override
     public int addData(ItMonitorData itMonitorData) {
-        return 0;
+        return itMonitorDataMapper.insert(itMonitorData);
     }
 
     @Override

+ 6 - 0
src/main/java/cn/iaun/it/util/Result.java

@@ -28,6 +28,12 @@ public class Result<T> {
         this.data = data;
     }
 
+    public Result(ResultCode resultCode) {
+        this.code = resultCode.getCode();
+        this.message = resultCode.getMessage();
+        this.data = null;
+    }
+
     public void success(T data) {
         ResultCode resultCode = ResultCode.SUCCESS;
         this.code = resultCode.getCode();

+ 13 - 0
src/main/resources/db/data.sql

@@ -123,3 +123,16 @@ values (1, 1, '服务器111'),
        (1, 17,
         '{"column":["插槽","品牌","规格","大小"],"data":[["1","三星","DDR4","128G"],["2","三星","DDR4","128G"],["3","三星","DDR4","128G"],["4","三星","DDR4","128G"],["5","三星","DDR4","128G"],["6","三星","DDR4","128G"],["7","三星","DDR4","128G"],["8","三星","DDR4","128G"]]}')
 ;
+
+delete
+from `it_monitor_data`;
+INSERT INTO `it_monitor_data` (`resource_id`, `item_id`, `record_time`, `data`)
+VALUES (1, 1, '2023-08-04 14:54:25', '1234');
+INSERT INTO `it_monitor_data` (`resource_id`, `item_id`, `record_time`, `data`)
+VALUES (1, 1, '2023-08-05 14:54:36', '4321');
+INSERT INTO `it_monitor_data` (`resource_id`, `item_id`, `record_time`, `data`)
+VALUES (1, 2, '2023-08-04 15:00:32', '1111');
+INSERT INTO `it_monitor_data` (`resource_id`, `item_id`, `record_time`, `data`)
+VALUES (1, 2, '2023-08-05 15:00:48', '2222');
+INSERT INTO `it_monitor_data` (`resource_id`, `item_id`, `record_time`, `data`)
+VALUES (3, 3, '2023-08-05 15:04:29', '3333');

+ 42 - 41
src/main/resources/db/schema.sql

@@ -1,19 +1,19 @@
 drop table if exists it_user;
 CREATE TABLE `it_user`
 (
-    `user_id`      BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '用户ID',
+    `user_id`      BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
     `user`         VARCHAR(255) NOT NULL COMMENT '用户名',
     `display_name` VARCHAR(255) NOT NULL COMMENT '显示名称',
     `password`     VARCHAR(255) NOT NULL COMMENT '密码',
     `phone_number` VARCHAR(255) NOT NULL COMMENT '手机号码',
-    `role_id`      BIGINT(20)   NOT NULL DEFAULT 0 COMMENT '角色ID',
+    `role_id`      BIGINT(20) NOT NULL DEFAULT 0 COMMENT '角色ID',
     PRIMARY KEY (`user_id`)
 ) COMMENT ='用户表';
 
 drop table if exists it_role;
 CREATE TABLE `it_role`
 (
-    `role_id` BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '角色ID',
+    `role_id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '角色ID',
     `name`    VARCHAR(255) NOT NULL COMMENT '角色名称',
     PRIMARY KEY (`role_id`)
 ) COMMENT ='角色表';
@@ -21,7 +21,7 @@ CREATE TABLE `it_role`
 drop table if exists it_sys;
 CREATE TABLE `it_sys`
 (
-    `sys_id` BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '系统ID',
+    `sys_id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '系统ID',
     `name`   VARCHAR(255) NOT NULL COMMENT '系统名称',
     PRIMARY KEY (`sys_id`)
 ) COMMENT ='系统表';
@@ -37,7 +37,7 @@ CREATE TABLE `it_role_permission`
 drop table if exists it_resource_group;
 create table `it_resource_group`
 (
-    `group_id`   bigint(20)   not null AUTO_INCREMENT comment '资源组ID',
+    `group_id`   bigint(20) not null AUTO_INCREMENT comment '资源组ID',
     `group_name` varchar(255) not null comment '资源组名称',
     primary key (`group_id`)
 ) comment ='资源组';
@@ -46,8 +46,8 @@ create table `it_resource_group`
 drop table if exists it_resource_attribute;
 create table `it_resource_attribute`
 (
-    `attribute_id`   bigint(20)   not null AUTO_INCREMENT comment '属性ID',
-    `group_id`       bigint(20)   not null comment '资源组ID',
+    `attribute_id`   bigint(20) not null AUTO_INCREMENT comment '属性ID',
+    `group_id`       bigint(20) not null comment '资源组ID',
     `attribute_name` varchar(255) not null comment '属性名称',
     `display_name`   varchar(255) not null comment '显示名称',
     `attribute_type` tinyint      not null comment '资源属性类型:0普通(文本、数字等),1表格,2下拉选项',
@@ -60,9 +60,9 @@ create table `it_resource_attribute`
 drop table if exists it_resource_type;
 create table `it_resource_type`
 (
-    `type_id`        bigint(20)   not null auto_increment comment '资源类型ID',
+    `type_id`        bigint(20) not null auto_increment comment '资源类型ID',
     `type_name`      varchar(255) not null comment '资源名称',
-    `parent_type_id` bigint(20)   not null default -1 comment '父类型ID',
+    `parent_type_id` bigint(20) not null default -1 comment '父类型ID',
     primary key (`type_id`)
 ) comment ='资源类型';
 
@@ -70,10 +70,10 @@ create table `it_resource_type`
 drop table if exists it_resource;
 create table `it_resource`
 (
-    `resource_id`   bigint(20)   not null auto_increment comment '资源ID',
+    `resource_id`   bigint(20) not null auto_increment comment '资源ID',
     `resource_name` varchar(255) not null comment '资源名称',
-    `type_id`       bigint(20)   not null comment '资源类型ID',
-    `group_id`      bigint(20)   not null comment '资源组ID',
+    `type_id`       bigint(20) not null comment '资源类型ID',
+    `group_id`      bigint(20) not null comment '资源组ID',
     `remark`        varchar(255) not null default '' comment '资源备注',
     primary key (`resource_id`)
 ) comment ='资源';
@@ -83,17 +83,17 @@ create table `it_resource_value`
 (
     `resource_id`     bigint(20) not null comment '资源ID',
     `attribute_id`    bigint(20) not null comment '属性ID',
-    `attribute_value` text       not null comment '资源属性的值',
+    `attribute_value` text not null comment '资源属性的值',
     primary key (`resource_id`, `attribute_id`)
 ) comment ='资源属性的值';
 
 drop TABLE if exists it_monitor_agent;
 CREATE TABLE `it_monitor_agent`
 (
-    `agent_id`     BIGINT(20)   NOT NULL AUTO_INCREMENT,
+    `agent_id`     BIGINT(20) NOT NULL AUTO_INCREMENT,
     `agent_name`   VARCHAR(255) NOT NULL DEFAULT '',
     `agent_ip`     VARCHAR(255) NOT NULL DEFAULT '',
-    `agent_key_id` BIGINT(20)   NOT NULL,
+    `agent_key_id` BIGINT(20) NOT NULL,
     PRIMARY KEY (`agent_id`)
 ) COMMENT ='agent'
 ;
@@ -101,8 +101,9 @@ CREATE TABLE `it_monitor_agent`
 drop TABLE if exists it_monitor_agent_key;
 CREATE TABLE `it_monitor_agent_key`
 (
-    `agent_key_id` BIGINT(20)   NOT NULL AUTO_INCREMENT,
+    `agent_key_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
     `key`          VARCHAR(255) NOT NULL,
+    `remark`       VARCHAR(255) NOT NULL,
     PRIMARY KEY (`agent_key_id`)
 ) COMMENT ='Agent 认证'
 ;
@@ -113,11 +114,11 @@ CREATE TABLE `it_monitor_alarm`
     `alarm_id`         BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '告警ID',
     `item_id`          BIGINT(20) NOT NULL COMMENT '指标ID',
     `resource_id`      BIGINT(20) NOT NULL COMMENT '资源ID',
-    `alarm_txt`        TEXT       NOT NULL COMMENT '告警内容',
-    `alarm_type`       INT(11)    NOT NULL COMMENT '告警级别',
-    `alarm_status`     INT(11)    NOT NULL DEFAULT '0' COMMENT '告警状态:0未处理;1已恢复;2已处理',
-    `first_alarm_time` TIMESTAMP  NOT NULL COMMENT '初次告警时间',
-    `alarm_times`      INT(11)    NOT NULL DEFAULT '0' COMMENT '连续告警次数',
+    `alarm_txt`        TEXT      NOT NULL COMMENT '告警内容',
+    `alarm_type`       INT(11) NOT NULL COMMENT '告警级别',
+    `alarm_status`     INT(11) NOT NULL DEFAULT '0' COMMENT '告警状态:0未处理;1已恢复;2已处理',
+    `first_alarm_time` TIMESTAMP NOT NULL COMMENT '初次告警时间',
+    `alarm_times`      INT(11) NOT NULL DEFAULT '0' COMMENT '连续告警次数',
     PRIMARY KEY (`alarm_id`)
 ) COMMENT ='监控-告警'
 ;
@@ -127,8 +128,8 @@ CREATE TABLE `it_monitor_data`
 (
     `resource_id` BIGINT(20) NOT NULL,
     `item_id`     BIGINT(20) NOT NULL,
-    `record_time` TIMESTAMP  NOT NULL,
-    `data`        TEXT       NOT NULL,
+    `record_time` TIMESTAMP NOT NULL,
+    `data`        TEXT      NOT NULL,
     PRIMARY KEY (`resource_id`, `item_id`, `record_time`)
 ) COMMENT ='监控-数据'
 ;
@@ -136,11 +137,11 @@ CREATE TABLE `it_monitor_data`
 drop TABLE if exists it_monitor_item;
 CREATE TABLE `it_monitor_item`
 (
-    `item_id`       BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '指标ID',
+    `item_id`       BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '指标ID',
     `item_name`     VARCHAR(255) NOT NULL COMMENT '指标名称',
     `item_key_name` VARCHAR(255) NOT NULL COMMENT '指标key',
-    `item_group_id` BIGINT(20)   NOT NULL COMMENT '指标组ID',
-    `item_type`     INT(11)      NOT NULL COMMENT '指标类型:0文本,1纯数字,2百分比,3大小(除文本外都是数字大类,前端进行细分)',
+    `item_group_id` BIGINT(20) NOT NULL COMMENT '指标组ID',
+    `item_type`     INT(11) NOT NULL COMMENT '指标类型:0文本,1纯数字,2百分比,3大小(除文本外都是数字大类,前端进行细分)',
     PRIMARY KEY (`item_id`),
     UNIQUE INDEX `item_key_name` (`item_key_name`)
 ) COMMENT ='监控指标'
@@ -149,11 +150,11 @@ CREATE TABLE `it_monitor_item`
 drop TABLE if exists it_monitor_item_group;
 CREATE TABLE `it_monitor_item_group`
 (
-    `group_id`    BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '组ID',
+    `group_id`    BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '组ID',
     `group_name`  VARCHAR(255) NOT NULL COMMENT '组名',
-    `template_id` BIGINT(20)   NOT NULL COMMENT '所属模板ID',
-    `interval`    INT(11)      NOT NULL COMMENT '间隔',
-    `top_item_id` BIGINT(20)   NOT NULL DEFAULT '-1' COMMENT '置顶指标',
+    `template_id` BIGINT(20) NOT NULL COMMENT '所属模板ID',
+    `interval`    INT(11) NOT NULL COMMENT '间隔',
+    `top_item_id` BIGINT(20) NOT NULL DEFAULT '-1' COMMENT '置顶指标',
     PRIMARY KEY (`group_id`)
 ) COMMENT ='监控指标组'
 ;
@@ -161,10 +162,10 @@ CREATE TABLE `it_monitor_item_group`
 drop TABLE if exists it_monitor_resource;
 CREATE TABLE `it_monitor_resource`
 (
-    `resource_id`       BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '资源ID',
-    `template_id`       BIGINT(20)   NOT NULL COMMENT '模板ID',
-    `agent_id`          BIGINT(20)   NOT NULL COMMENT 'Agent ID',
-    `resource_group_id` BIGINT(20)   NOT NULL COMMENT '资源组ID',
+    `resource_id`       BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '资源ID',
+    `template_id`       BIGINT(20) NOT NULL COMMENT '模板ID',
+    `agent_id`          BIGINT(20) NOT NULL COMMENT 'Agent ID',
+    `resource_group_id` BIGINT(20) NOT NULL COMMENT '资源组ID',
     `resource_name`     VARCHAR(255) NOT NULL COMMENT '资源名称',
     PRIMARY KEY (`resource_id`)
 ) COMMENT ='监控-资源表'
@@ -173,7 +174,7 @@ CREATE TABLE `it_monitor_resource`
 drop TABLE if exists it_monitor_resource_group;
 CREATE TABLE `it_monitor_resource_group`
 (
-    `group_id`   BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '组ID',
+    `group_id`   BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '组ID',
     `group_name` VARCHAR(255) NOT NULL COMMENT '组名',
     PRIMARY KEY (`group_id`)
 ) COMMENT ='监控-资源组'
@@ -182,7 +183,7 @@ CREATE TABLE `it_monitor_resource_group`
 drop TABLE if exists it_monitor_template;
 CREATE TABLE `it_monitor_template`
 (
-    `template_id`   BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '模板ID',
+    `template_id`   BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '模板ID',
     `template_name` VARCHAR(255) NOT NULL COMMENT '模板名称',
     PRIMARY KEY (`template_id`)
 ) COMMENT ='监控模板'
@@ -191,12 +192,12 @@ CREATE TABLE `it_monitor_template`
 drop TABLE if exists it_monitor_threshold;
 CREATE TABLE `it_monitor_threshold`
 (
-    `item_id`        BIGINT(20)   NOT NULL COMMENT '指标ID',
-    `resource_id`    BIGINT(20)   NOT NULL COMMENT '资源ID',
-    `alarm_type`     INT(11)      NOT NULL COMMENT '告警级别',
-    `threshold_type` INT(11)      NOT NULL COMMENT '阈值类型:0发生变化;1大于;2小于;3大于等于;4小于等于;5等于;6不等于;7包含;8不包含',
+    `item_id`        BIGINT(20) NOT NULL COMMENT '指标ID',
+    `resource_id`    BIGINT(20) NOT NULL COMMENT '资源ID',
+    `alarm_type`     INT(11) NOT NULL COMMENT '告警级别',
+    `threshold_type` INT(11) NOT NULL COMMENT '阈值类型:0发生变化;1大于;2小于;3大于等于;4小于等于;5等于;6不等于;7包含;8不包含',
     `threshold`      VARCHAR(255) NOT NULL COMMENT '阈值',
-    `times`          INT(11)      NOT NULL COMMENT '连续触发次数',
+    `times`          INT(11) NOT NULL COMMENT '连续触发次数',
     PRIMARY KEY (`item_id`, `resource_id`)
 ) COMMENT ='监控-阈值'
 ;

+ 11 - 0
src/main/resources/mapper/ItMonitorAgentMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.iaun.it.mapper.ItMonitorAgentMapper">
+
+    <select id="selectByAgentId" resultType="java.lang.Long">
+        select agent_id
+        from it_monitor_agent
+        where agent_id = #{agentId}
+        limit 1
+    </select>
+</mapper>

+ 14 - 0
src/main/resources/mapper/ItMonitorDataMapper.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.iaun.it.mapper.ItMonitorDataMapper">
+
+    <select id="selectLatestItMonitorData" resultType="cn.iaun.it.model.ItMonitorData">
+        SELECT `resource_id`, `item_id`, `record_time`, `data`
+        FROM it_monitor_data
+        WHERE (resource_id, item_id, record_time) IN
+              (SELECT `resource_id`, `item_id`, MAX(record_time)
+               FROM it_monitor_data
+               WHERE resource_id = #{resourceId}
+               GROUP BY resource_id, item_id)
+    </select>
+</mapper>

+ 11 - 0
src/main/resources/mapper/ItMonitorItemGroupMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.iaun.it.mapper.ItMonitorItemGroupMapper">
+
+    <select id="getByGroupId" resultType="java.lang.Long">
+        select group_id
+        from it_monitor_item_group
+        where group_id = #{groupId}
+        limit 1
+    </select>
+</mapper>

+ 12 - 0
src/main/resources/mapper/ItMonitorItemMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.iaun.it.mapper.ItMonitorItemMapper">
+
+    <select id="selectByItemId" resultType="java.lang.Long">
+        select item_id
+        from it_monitor_item
+        where item_id = #{itemId}
+          and item_group_id = #{groupId}
+        limit 1
+    </select>
+</mapper>

+ 11 - 0
src/main/resources/mapper/ItMonitorResourceGroupMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.iaun.it.mapper.ItMonitorResourceGroupMapper">
+
+    <select id="getByGroupId" resultType="java.lang.Long">
+        select group_id
+        from it_monitor_resource_group
+        where group_id = #{groupId}
+        limit 1
+    </select>
+</mapper>

+ 11 - 0
src/main/resources/mapper/ItMonitorTemplateMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.iaun.it.mapper.ItMonitorTemplateMapper">
+
+    <select id="selectByTemplateId" resultType="java.lang.Long">
+        select template_id
+        from it_monitor_template
+        where template_id = #{templateId}
+        limit 1
+    </select>
+</mapper>

+ 17 - 0
src/test/java/cn/iaun/it/MonitorTest.java

@@ -0,0 +1,17 @@
+package cn.iaun.it;
+
+import cn.iaun.it.service.ItMonitorService;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+public class MonitorTest {
+    @Autowired
+    private ItMonitorService itMonitorService;
+
+    @Test
+    public void getLatestDataByResourceIdTest() {
+        System.out.println(itMonitorService.getLatestDataByResourceId(1L));
+    }
+}