Browse Source

Merge remote-tracking branch 'origin/v1.0.0' into v1.0.0

xujiaheng 3 years ago
parent
commit
bf8476e48d
22 changed files with 882 additions and 36 deletions
  1. 1 9
      src/main/java/com/persagy/apm/alarmservice/group/management/controller/GroupManagementController.java
  2. 11 0
      src/main/java/com/persagy/apm/alarmservice/group/management/model/group/ConvertGroupTool.java
  3. 3 0
      src/main/java/com/persagy/apm/alarmservice/group/management/service/GroupManagementService.java
  4. 86 22
      src/main/java/com/persagy/apm/alarmservice/group/management/service/impl/GroupManagementServiceImpl.java
  5. 92 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/controller/ObjGroupController.java
  6. 15 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/dao/ObjGroupMapper.java
  7. 73 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/ConvertObjGroupTool.java
  8. 42 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/ObjGroup.java
  9. 32 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/AddObjGroupDTO.java
  10. 19 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/DeleteObjGroupDTO.java
  11. 33 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/PageQueryObjGroupDTO.java
  12. 27 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/QueryObjGroupDTO.java
  13. 19 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/QueryObjGroupDetailDTO.java
  14. 36 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/UpdateObjGroupDTO.java
  15. 44 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/vo/ObjGroupItemVO.java
  16. 44 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/vo/ObjGroupListItemVO.java
  17. 75 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/service/IObjGroupService.java
  18. 207 0
      src/main/java/com/persagy/apm/alarmservice/group/objgroup/service/impl/ObjGroupServiceImpl.java
  19. 3 3
      src/main/resources/bootstrap.yml
  20. 1 1
      src/main/resources/db/init/data.sql
  21. 1 1
      src/main/resources/db/init/table.sql
  22. 18 0
      src/main/resources/mapper/ObjGroupMapper.xml

+ 1 - 9
src/main/java/com/persagy/apm/alarmservice/group/management/controller/GroupManagementController.java

@@ -1,27 +1,19 @@
 package com.persagy.apm.alarmservice.group.management.controller;
 
-import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupInfoVO;
 import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupTreeVO;
 import com.persagy.apm.alarmservice.group.management.service.GroupManagementService;
 import com.persagy.apm.common.response.CommonResult;
-import com.persagy.apm.common.response.PageList;
 import com.persagy.apm.common.utils.ResultHelper;
-import com.persagy.apm.alarmservice.group.management.model.equip.dto.EquipIdDTO;
-import com.persagy.apm.alarmservice.group.management.model.equip.dto.QueryEquipDTO;
-import com.persagy.apm.alarmservice.group.management.model.equip.vo.EquipListItem;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.validation.Valid;
 import java.util.List;
 
-import static com.persagy.apm.alarmservice.group.management.service.impl.GroupManagementServiceImpl.getGroupTree;
 
 /**
  * @author 易涛
@@ -39,7 +31,7 @@ public class GroupManagementController {
     @ApiOperation(value = "获取分组树")
     @PostMapping("/eq_groups/tree")
     public CommonResult<List<GroupTreeVO>> queryGroupTree(){
-        return ResultHelper.single(getGroupTree());
+        return ResultHelper.single(managementService.getGroupTree());
     }
 
 //    @ApiOperation(value = "获取分组信息")

+ 11 - 0
src/main/java/com/persagy/apm/alarmservice/group/management/model/group/ConvertGroupTool.java

@@ -2,6 +2,7 @@ package com.persagy.apm.alarmservice.group.management.model.group;
 
 import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupInfoVO;
 import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupTreeVO;
+import com.persagy.apm.alarmservice.group.objgroup.model.ObjGroup;
 import org.mapstruct.Mapper;
 import org.mapstruct.NullValueCheckStrategy;
 import org.mapstruct.NullValueMappingStrategy;
@@ -27,4 +28,14 @@ public interface ConvertGroupTool {
      * @version V1.0 2021/9/19 1:25 下午
      */
     GroupInfoVO convert2DetailDTO(GroupTreeVO groupTreeVO);
+
+    /**
+     * 分组对象转换为分组树节点
+     *
+     * @param objGroup 分组对象
+     * @return 分组树节点
+     * @author lixing
+     * @version V1.0 2021/10/19 2:57 下午
+     */
+    GroupTreeVO convert2GroupTreeVO(ObjGroup objGroup);
 }

+ 3 - 0
src/main/java/com/persagy/apm/alarmservice/group/management/service/GroupManagementService.java

@@ -5,6 +5,7 @@ import com.persagy.apm.alarmservice.group.management.model.equip.vo.EquipItem;
 import com.persagy.apm.alarmservice.group.management.model.equip.vo.EquipListItem;
 import com.persagy.apm.alarmservice.group.management.model.group.vo.EquipGroupInfoVO;
 import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupInfoVO;
+import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupTreeVO;
 import com.persagy.apm.common.model.vo.SimpleObjVO;
 import com.persagy.apm.common.response.PageList;
 
@@ -67,6 +68,8 @@ public interface GroupManagementService {
      */
     Map<String, SimpleObjVO> queryObjGroup(List<String> objIds);
 
+    List<GroupTreeVO> getGroupTree();
+
     /**
      * 定时任务删除valid为0的数据
      *

+ 86 - 22
src/main/java/com/persagy/apm/alarmservice/group/management/service/impl/GroupManagementServiceImpl.java

@@ -1,7 +1,6 @@
 package com.persagy.apm.alarmservice.group.management.service.impl;
 
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.persagy.apm.alarmservice.group.management.model.equip.dto.QueryEquipDTO;
@@ -11,12 +10,13 @@ import com.persagy.apm.alarmservice.group.management.model.group.vo.EquipGroupIn
 import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupInfoVO;
 import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupTreeVO;
 import com.persagy.apm.alarmservice.group.management.service.GroupManagementService;
+import com.persagy.apm.alarmservice.group.objgroup.model.ObjGroup;
+import com.persagy.apm.alarmservice.group.objgroup.model.dto.QueryObjGroupDTO;
+import com.persagy.apm.alarmservice.group.objgroup.service.IObjGroupService;
 import com.persagy.apm.common.context.poems.PoemsContext;
 import com.persagy.apm.common.model.vo.SimpleObjVO;
 import com.persagy.apm.common.response.PageList;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.elasticsearch.action.get.GetRequest;
 import org.elasticsearch.action.get.GetResponse;
@@ -33,16 +33,13 @@ import org.elasticsearch.rest.RestStatus;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.SearchHits;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
-import org.elasticsearch.search.sort.SortOrder;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
-import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -63,6 +60,8 @@ public class GroupManagementServiceImpl implements GroupManagementService {
 
     @Autowired
     private RestHighLevelClient client;
+    @Autowired
+    private IObjGroupService objGroupService;
 
     @Value("${elasticsearch.maxSearchCount}")
     private int maxSearchCount;
@@ -279,7 +278,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
                 return equipGroupInfoVO;
             }
 
-            if (CollectionUtils.isNotEmpty(groupTreeVO.getChildren())) {
+            if (!CollectionUtils.isEmpty(groupTreeVO.getChildren())) {
                 cascadeSearchGroupInfo(groupTreeVO.getChildren(), equipGroupInfoVO, equipFuncMap);
             }
         }
@@ -289,22 +288,87 @@ public class GroupManagementServiceImpl implements GroupManagementService {
     /**
      * 获取分组树
      *
-     * @return java.util.List<com.persagy.apm.alarmservice.group.management.model.vo.GroupTreeVO>
-     * @author 易涛
-     * @date 2021/9/8 14:44
+     * @return 分组树节点列表
+     * @author lixing
+     * @version V1.0 2021/10/19 2:40 下午
      */
-    public static List<GroupTreeVO> getGroupTree() {
-        InputStream inputStream = GroupManagementServiceImpl.class.getClassLoader()
-                .getResourceAsStream("json" + File.separator + "GroupTree.json");
-        if (inputStream == null) {
-            return null;
+    @Override
+    public List<GroupTreeVO> getGroupTree() {
+        // 不再从配置文件读取分组数据
+        //        InputStream inputStream = GroupManagementServiceImpl.class.getClassLoader()
+        //                .getResourceAsStream("json" + File.separator + "GroupTree.json");
+        //        if (inputStream == null) {
+        //            return null;
+        //        }
+        //        try {
+        //            String str = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
+        //            return JSONArray.parseArray(str, GroupTreeVO.class);
+        //        } catch (IOException ioe) {
+        //            throw new RuntimeException("json文件有误", ioe);
+        //        }
+        // 从表中查询所有分组
+        QueryObjGroupDTO queryObjGroupDTO = new QueryObjGroupDTO();
+        List<ObjGroup> objGroups = objGroupService.queryObjGroupList(queryObjGroupDTO);
+
+        if (CollectionUtils.isEmpty(objGroups)) {
+            return new ArrayList<>();
         }
-        try {
-            String str = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
-            return JSONArray.parseArray(str, GroupTreeVO.class);
-        } catch (IOException ioe) {
-            throw new RuntimeException("json文件有误", ioe);
+        // 将分组列表转换为树形结构,根节点的parentId = 0;
+        Map<String, List<ObjGroup>> objGroupMap = new HashMap<>();
+        for (ObjGroup objGroup : objGroups) {
+            String parentId = objGroup.getParentId();
+            if (!objGroupMap.containsKey(parentId)) {
+                objGroupMap.put(parentId, Lists.newArrayList(objGroup));
+            } else {
+                objGroupMap.get(parentId).add(objGroup);
+            }
+        }
+        return objGroupMap2Tree(objGroupMap);
+    }
+
+    /**
+     * 将分组的map转换为树
+     *
+     * @param objGroupMap 分组的map
+     * @return 分组树节点列表
+     * @author lixing
+     * @version V1.0 2021/10/19 2:50 下午
+     */
+    private List<GroupTreeVO> objGroupMap2Tree(Map<String, List<ObjGroup>> objGroupMap) {
+        if (CollectionUtils.isEmpty(objGroupMap)) {
+            return new ArrayList<>();
         }
+        List<GroupTreeVO> result = new ArrayList<>();
+        // 根节点parentId = 0;
+        List<ObjGroup> rootObjGroups = objGroupMap.get("0");
+        rootObjGroups.forEach(objGroup -> {
+            GroupTreeVO groupTreeVO = ConvertGroupTool.INSTANCE.convert2GroupTreeVO(objGroup);
+            result.add(groupTreeVO);
+        });
+        cascadeSetChildren(objGroupMap, result);
+        return result;
+    }
+
+    /**
+     * 级联设置子节点
+     *
+     * @param objGroupMap 分组map 分组parentId -> 分组列表
+     * @param groupTreeVOList 要设置子节点的节点列表
+     * @exception
+     * @author lixing
+     * @version V1.0 2021/10/19 3:16 下午
+     */
+    private void cascadeSetChildren(Map<String, List<ObjGroup>> objGroupMap, List<GroupTreeVO> groupTreeVOList) {
+        groupTreeVOList.forEach(groupTreeVO -> {
+            if (objGroupMap.containsKey(groupTreeVO.getId())) {
+                List<ObjGroup> sonObjGroups = objGroupMap.get(groupTreeVO.getId());
+                List<GroupTreeVO> sonNodes = sonObjGroups.stream().map(
+                        ConvertGroupTool.INSTANCE::convert2GroupTreeVO
+                ).collect(Collectors.toList());
+                groupTreeVO.setChildren(sonNodes);
+                cascadeSetChildren(objGroupMap, sonNodes);
+            }
+        });
     }
 
     @Override
@@ -364,7 +428,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
                 BeanUtils.copyProperties(groupTreeVO, groupInfoVO);
                 return groupInfoVO;
             }
-            if (CollectionUtils.isNotEmpty(groupTreeVO.getChildren())) {
+            if (!CollectionUtils.isEmpty(groupTreeVO.getChildren())) {
                 queryById(groupTreeVO.getChildren(), groupInfoVO, id);
             }
         }

+ 92 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/controller/ObjGroupController.java

@@ -0,0 +1,92 @@
+package com.persagy.apm.alarmservice.group.objgroup.controller;
+
+import com.persagy.apm.alarmservice.group.objgroup.service.IObjGroupService;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import com.persagy.apm.alarmservice.group.objgroup.model.*;
+import com.persagy.apm.alarmservice.group.objgroup.model.vo.*;
+import com.persagy.apm.alarmservice.group.objgroup.model.dto.*;
+import com.persagy.apm.common.response.*;
+import com.persagy.apm.common.utils.ResultHelper;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import javax.validation.Valid;
+import java.util.List;
+
+/**
+ * 报警对象分组控制层
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Api(tags = "报警对象分组") 
+@Validated
+@RestController
+@RequestMapping("objGroups")
+public class ObjGroupController {
+    @Autowired
+    private IObjGroupService objGroupService;
+
+	@ApiOperation(value = "创建报警对象分组")
+	@PostMapping("/create")
+	public CommonResult<ApmResponseUpsertVO> createObjGroup(
+	        @Valid @RequestBody AddObjGroupDTO addObjGroupDTO) {
+        String id = objGroupService.createObjGroup(addObjGroupDTO);
+        return ResultHelper.single(new ApmResponseUpsertVO(id));
+	}
+	
+	@ApiOperation(value = "报警对象分组详情")
+    @PostMapping("/get")
+    public CommonResult<ObjGroupItemVO> queryObjGroupDetail(
+            @Valid @RequestBody QueryObjGroupDetailDTO queryObjGroupDetailDTO) {
+        ObjGroup objGroup = objGroupService.queryObjGroupDetail(queryObjGroupDetailDTO.getId());
+        ObjGroupItemVO objGroupItemVO = ConvertObjGroupTool.INSTANCE.convert2ResponseItemDTO(objGroup);
+        return ResultHelper.single(objGroupItemVO);
+    }
+
+
+    @ApiOperation(value = "更新报警对象分组")
+    @PostMapping("/update")
+    public CommonResult<ApmResponseUpsertVO> updateObjGroup(
+            @Valid @RequestBody UpdateObjGroupDTO updateObjGroupDTO) {
+        objGroupService.updateObjGroup(updateObjGroupDTO);
+        return ResultHelper.single(new ApmResponseUpsertVO(updateObjGroupDTO.getId()));
+    }
+
+
+    @ApiOperation(value = "删除报警对象分组")
+    @PostMapping("/delete")
+    public CommonResult deleteObjGroup(
+            @RequestBody @Valid DeleteObjGroupDTO deleteObjGroupDTO) {
+        objGroupService.deleteObjGroup(deleteObjGroupDTO.getId());
+        return ResultHelper.success();
+    }
+
+
+    @ApiOperation(value = "报警对象分组列表")
+    @PostMapping("/query")
+    public CommonResult<PageList<ObjGroupListItemVO>> queryObjGroup(
+            @Valid @RequestBody QueryObjGroupDTO queryObjGroupDTO) {
+        List<ObjGroup> objGroupList = objGroupService.queryObjGroupList(queryObjGroupDTO);
+        List<ObjGroupListItemVO> resultList = ConvertObjGroupTool.INSTANCE.convert2List(objGroupList);
+        return ResultHelper.multi(resultList);
+    }
+    
+    //@ApiOperation(value = "报警对象分组列表, 分页查询")
+    //@PostMapping("/query")
+    //public CommonResult<PageList<ObjGroupListItemVO>> queryObjGroup(
+    //        @Valid @RequestBody PageQueryObjGroupDTO pageQueryObjGroupDTO) {
+    //    IPage<ObjGroup> pagedList = objGroupService.pageQueryObjGroup(pageQueryObjGroupDTO);
+    //    IPage<ObjGroupListItemVO> pagedResultList = pagedList.convert(item -> {
+    //        try {
+    //           return ConvertObjGroupTool.INSTANCE.convert2ResponseListItemDTO(item);
+    //        } catch (Exception e) {
+    //            throw new IllegalArgumentException("分页查询,ObjGroup实体类转换为列表对象发生异常", e);
+    //        }
+    //    });
+    //    return ResultHelper.multi(pagedResultList);
+    //}
+}
+

+ 15 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/dao/ObjGroupMapper.java

@@ -0,0 +1,15 @@
+package com.persagy.apm.alarmservice.group.objgroup.dao;
+
+import com.persagy.apm.alarmservice.group.objgroup.model.ObjGroup;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 报警对象分组(ObjGroup)dao层
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Mapper
+public interface ObjGroupMapper extends BaseMapper<ObjGroup>{
+
+}

+ 73 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/ConvertObjGroupTool.java

@@ -0,0 +1,73 @@
+package com.persagy.apm.alarmservice.group.objgroup.model;
+
+import org.mapstruct.*;
+import org.mapstruct.MappingTarget;
+import org.mapstruct.factory.Mappers;
+import com.persagy.apm.alarmservice.group.objgroup.model.vo.*;
+import com.persagy.apm.alarmservice.group.objgroup.model.dto.*;
+
+import java.util.List;
+
+/**
+ * 报警对象分组(ObjGroup) dto、vo、do转换工具类
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Mapper(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT,
+        nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
+public interface ConvertObjGroupTool {
+
+    ConvertObjGroupTool INSTANCE = Mappers.getMapper(ConvertObjGroupTool.class);
+    
+    /**
+    * do转换为ResponseItemVO
+    *
+    * @param objGroup do对象
+    * @return ResponseItemVO
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    ObjGroupItemVO convert2ResponseItemDTO(ObjGroup objGroup);
+    
+    /**
+    * do转换为ResponseListItemVO
+    *
+    * @param objGroup do对象
+    * @return ResponseListItemVO
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    ObjGroupListItemVO convert2ResponseListItemDTO(ObjGroup objGroup);
+
+    /**
+    * do列表转换为ResponseListItemVO列表
+    *
+    * @param objGroupList do列表
+    * @return ResponseListItemVO列表
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    List<ObjGroupListItemVO> convert2List(List<ObjGroup> objGroupList);
+    
+    /**
+    * addDTO转换为do
+    *
+    * @param addObjGroupDTO addDTO
+    * @return 要创建的do对象 
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    ObjGroup convertAddDto2Entity(AddObjGroupDTO addObjGroupDTO);
+    
+    /**
+    * updateDTO转换为实体
+    *
+    * @param objGroup 更新前的do对象
+    * @param updateObjGroupDTO updateDTO
+    * @return 更新后的do对象
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    ObjGroup convertUpdateDto2Entity(@MappingTarget ObjGroup objGroup, UpdateObjGroupDTO updateObjGroupDTO);
+}
+

+ 42 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/ObjGroup.java

@@ -0,0 +1,42 @@
+package com.persagy.apm.alarmservice.group.objgroup.model;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import com.persagy.apm.common.model.entity.AuditableEntity;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 报警对象分组(ObjGroup)实体类
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@ApiModel(description = "报警对象分组")
+public class ObjGroup extends AuditableEntity<ObjGroup> implements Serializable {
+    private static final long serialVersionUID = 775168774894672330L;
+
+    @ApiModelProperty("分组名称")
+    private String name;
+    
+    @ApiModelProperty("设备类型")
+    private String classCode;
+    
+    @ApiModelProperty("分组条件")
+    @TableField("`condition`")
+    private String condition;
+    
+    @ApiModelProperty("父节点id")
+    private String parentId;
+    
+
+    public static String PROP_NAME = "name";
+    public static String PROP_CLASS_CODE = "class_code";
+    public static String PROP_CONDITION = "condition";
+    public static String PROP_PARENT_ID = "parent_id";
+
+}

+ 32 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/AddObjGroupDTO.java

@@ -0,0 +1,32 @@
+package com.persagy.apm.alarmservice.group.objgroup.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import javax.validation.constraints.NotNull;
+import lombok.Data;
+import java.util.Date;
+
+/**
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Data
+@ApiModel(value = "创建报警对象分组入参")
+public class AddObjGroupDTO {
+    @ApiModelProperty(value = "分组名称", required = true)
+    @NotNull(message = "分组名称不能为空") // todo 更新校验规则
+    private String name;
+    
+    @ApiModelProperty(value = "设备类型", required = true)
+    @NotNull(message = "设备类型不能为空") // todo 更新校验规则
+    private String classCode;
+    
+    @ApiModelProperty(value = "分组条件", required = true)
+    @NotNull(message = "分组条件不能为空") // todo 更新校验规则
+    private String condition;
+    
+    @ApiModelProperty(value = "父节点id", required = true)
+    @NotNull(message = "父节点id不能为空") // todo 更新校验规则
+    private String parentid;
+    
+}

+ 19 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/DeleteObjGroupDTO.java

@@ -0,0 +1,19 @@
+package com.persagy.apm.alarmservice.group.objgroup.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Data
+@ApiModel(value = "删除报警对象分组入参")
+public class DeleteObjGroupDTO {
+    @NotNull(message = "id不能为空")
+    @ApiModelProperty(value = "主键", required = true)
+    private String id;
+    
+}

+ 33 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/PageQueryObjGroupDTO.java

@@ -0,0 +1,33 @@
+package com.persagy.apm.alarmservice.group.objgroup.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.Date;
+import com.persagy.apm.common.model.dto.PageDTO;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@ApiModel(value = "分页查询报警对象分组入参")
+public class PageQueryObjGroupDTO extends PageDTO {
+    @ApiModelProperty(value = "主键", required = true)
+    private String id;
+    
+    @ApiModelProperty(value = "分组名称", required = true)
+    private String name;
+    
+    @ApiModelProperty(value = "设备类型", required = true)
+    private String classCode;
+    
+    @ApiModelProperty(value = "分组条件", required = true)
+    private String condition;
+    
+    @ApiModelProperty(value = "父节点id", required = true)
+    private String parentid;
+    
+}

+ 27 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/QueryObjGroupDTO.java

@@ -0,0 +1,27 @@
+package com.persagy.apm.alarmservice.group.objgroup.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.util.Date;
+
+/**
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Data
+@ApiModel(value = "查询报警对象分组入参")
+public class QueryObjGroupDTO {
+    @ApiModelProperty(value = "分组名称", required = true)
+    private String name;
+    
+    @ApiModelProperty(value = "设备类型", required = true)
+    private String classCode;
+    
+    @ApiModelProperty(value = "分组条件", required = true)
+    private String condition;
+    
+    @ApiModelProperty(value = "父节点id", required = true)
+    private String parentid;
+    
+}

+ 19 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/QueryObjGroupDetailDTO.java

@@ -0,0 +1,19 @@
+package com.persagy.apm.alarmservice.group.objgroup.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Data
+@ApiModel(value = "获取报警对象分组详情入参")
+public class QueryObjGroupDetailDTO {
+    @NotNull(message = "主键不能为空")
+    @ApiModelProperty(value = "主键", required = true)
+    private String id;
+    
+}

+ 36 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/dto/UpdateObjGroupDTO.java

@@ -0,0 +1,36 @@
+package com.persagy.apm.alarmservice.group.objgroup.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import javax.validation.constraints.NotNull;
+import lombok.Data;
+import java.util.Date;
+
+/**
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Data
+@ApiModel(value = "更新报警对象分组入参")
+public class UpdateObjGroupDTO {
+    @ApiModelProperty(value = "主键", required = true)
+    @NotNull(message = "主键不能为空") // todo 更新校验规则
+    private String id;
+    
+    @ApiModelProperty(value = "分组名称", required = true)
+    @NotNull(message = "分组名称不能为空") // todo 更新校验规则
+    private String name;
+    
+    @ApiModelProperty(value = "设备类型", required = true)
+    @NotNull(message = "设备类型不能为空") // todo 更新校验规则
+    private String classCode;
+    
+    @ApiModelProperty(value = "分组条件", required = true)
+    @NotNull(message = "分组条件不能为空") // todo 更新校验规则
+    private String condition;
+    
+    @ApiModelProperty(value = "父节点id", required = true)
+    @NotNull(message = "父节点id不能为空") // todo 更新校验规则
+    private String parentid;
+    
+}

+ 44 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/vo/ObjGroupItemVO.java

@@ -0,0 +1,44 @@
+package com.persagy.apm.alarmservice.group.objgroup.model.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.util.Date;
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+/**
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Data
+@ApiModel(value = "报警对象分组返回结果参数")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class ObjGroupItemVO {
+    @ApiModelProperty("主键")
+    private String id;
+    
+    @ApiModelProperty("分组名称")
+    private String name;
+    
+    @ApiModelProperty("设备类型")
+    private String classCode;
+    
+    @ApiModelProperty("分组条件")
+    private String condition;
+    
+    @ApiModelProperty("父节点id")
+    private String parentid;
+    
+    @ApiModelProperty("创建人")
+    private String creator;
+    
+    @ApiModelProperty("创建时间")
+    private Date creationTime;
+    
+    @ApiModelProperty("修改人")
+    private String modifier;
+    
+    @ApiModelProperty("修改时间")
+    private Date modifiedTime;
+    
+}

+ 44 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/model/vo/ObjGroupListItemVO.java

@@ -0,0 +1,44 @@
+package com.persagy.apm.alarmservice.group.objgroup.model.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.util.Date;
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+/**
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Data
+@ApiModel(value = "报警对象分组列表返回结果参数")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class ObjGroupListItemVO {
+    @ApiModelProperty("主键")
+    private String id;
+    
+    @ApiModelProperty("分组名称")
+    private String name;
+    
+    @ApiModelProperty("设备类型")
+    private String classCode;
+    
+    @ApiModelProperty("分组条件")
+    private String condition;
+    
+    @ApiModelProperty("父节点id")
+    private String parentid;
+    
+    @ApiModelProperty("创建人")
+    private String creator;
+    
+    @ApiModelProperty("创建时间")
+    private Date creationTime;
+    
+    @ApiModelProperty("修改人")
+    private String modifier;
+    
+    @ApiModelProperty("修改时间")
+    private Date modifiedTime;
+    
+}

+ 75 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/service/IObjGroupService.java

@@ -0,0 +1,75 @@
+package com.persagy.apm.alarmservice.group.objgroup.service;
+
+import com.persagy.apm.alarmservice.group.objgroup.model.*;
+import com.persagy.apm.alarmservice.group.objgroup.model.dto.*;
+import java.util.List;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * 报警对象分组(ObjGroup) service接口
+ *
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+public interface IObjGroupService  {
+    
+    /**
+    * 创建报警对象分组
+    *
+    * @param addObjGroupDTO addDTO
+    * @return 报警对象分组主键
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    public String createObjGroup(AddObjGroupDTO addObjGroupDTO);
+    
+    /**
+    * 报警对象分组详情
+    *
+    * @param id 主键
+    * @return 报警对象分组do对象
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    public ObjGroup queryObjGroupDetail(String id);
+    
+    /**
+    * 更新报警对象分组
+    *
+    * @param updateObjGroupDTO updateDTO
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    public void updateObjGroup(UpdateObjGroupDTO updateObjGroupDTO);
+    
+    /**
+    * 删除报警对象分组
+    *
+    * @param id 主键
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    public void deleteObjGroup(String id);
+    
+    /**
+    * 查询报警对象分组
+    *
+    * @param queryObjGroupDTO queryDTO
+    * @return List<ObjGroup>
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    public List<ObjGroup> queryObjGroupList(QueryObjGroupDTO queryObjGroupDTO);
+    
+    /**
+    * 分页查询报警对象分组
+    * 
+    * @param pageQueryObjGroupDTO pageQueryDTO
+    * @return IPage<ObjGroup>
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    public IPage<ObjGroup> pageQueryObjGroup(PageQueryObjGroupDTO pageQueryObjGroupDTO);
+}

+ 207 - 0
src/main/java/com/persagy/apm/alarmservice/group/objgroup/service/impl/ObjGroupServiceImpl.java

@@ -0,0 +1,207 @@
+package com.persagy.apm.alarmservice.group.objgroup.service.impl;
+
+import com.persagy.apm.common.context.poems.PoemsContext;
+import com.persagy.apm.alarmservice.group.objgroup.dao.ObjGroupMapper;
+import com.persagy.apm.alarmservice.group.objgroup.service.IObjGroupService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+import org.apache.commons.lang.StringUtils;
+import com.persagy.apm.common.constant.enums.ValidEnum;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.persagy.apm.alarmservice.group.objgroup.model.*;
+import com.persagy.apm.alarmservice.group.objgroup.model.dto.*;
+import java.util.List;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.common.base.CaseFormat;
+import com.persagy.apm.common.model.dto.Sort;
+import org.springframework.util.CollectionUtils;
+
+/**
+ * 报警对象分组(ObjGroup) service层
+ *
+ * @author lixing
+ * @version V1.0 2021-10-19 14:25:45
+ */
+@Service
+public class ObjGroupServiceImpl extends ServiceImpl<ObjGroupMapper, ObjGroup> 
+    implements IObjGroupService {
+    
+    /**
+    * 创建报警对象分组
+    * @return 报警对象分组主键
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    @Override
+    public String createObjGroup(AddObjGroupDTO addObjGroupDTO) {
+        ObjGroup objGroup = ConvertObjGroupTool.INSTANCE.convertAddDto2Entity(addObjGroupDTO);
+        // 设置默认值
+        setDefaultValue(objGroup);
+        save(objGroup);
+        return objGroup.getId();
+    }
+    
+    /**
+     * 如果某些字段没有赋值,使用默认的值
+     *
+     * @param objGroup 报警对象分组实体
+     * @author lixing
+     * @version V1.0 2021/3/12 12:29 下午
+     */
+    private void setDefaultValue(ObjGroup objGroup) {
+        objGroup.setCreator(PoemsContext.getContext().getUserId());
+        // todo 其他默认的属性
+        
+    }
+    
+    /**
+    * 报警对象分组详情
+    * @param id 主键
+    * @return 部门do类
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    @Override
+    public ObjGroup queryObjGroupDetail(String id) {
+        ObjGroup objGroup = getById(id);
+        if (objGroup == null) {
+            throw new IllegalArgumentException("查看ObjGroup详情时发生异常,找不到要查看的记录,id=" + id);
+        }
+        return objGroup;
+    }
+    
+    /**
+    * 更新报警对象分组
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    @Override
+    public void updateObjGroup(UpdateObjGroupDTO updateObjGroupDTO) {
+        ObjGroup objGroup = getById(updateObjGroupDTO.getId());
+        objGroup = ConvertObjGroupTool.INSTANCE.convertUpdateDto2Entity(objGroup, updateObjGroupDTO);
+        objGroup.setModifier(PoemsContext.getContext().getUserId());
+        updateById(objGroup);
+    }
+    
+    /**
+     * 校验报警对象分组是否可删除
+     *
+     * @param id 报警对象分组主键
+     * @return 报警对象分组do类
+     * @author lixing
+     * @version V1.0 2021-10-19 14:25:45
+     */
+    public ObjGroup checkDeletable(String id) {
+        if (id == null) {
+            throw new IllegalArgumentException("删除ObjGroup时发生异常,主键为空");
+        }
+
+        ObjGroup objGroup = getById(id);
+
+        if (objGroup == null) {
+            throw new IllegalArgumentException("删除ObjGroup时发生异常,找不到要删除的数据,id:" + id);
+        }
+
+        return objGroup;
+    }
+    
+    /**
+    * 删除报警对象分组
+    * @param id 主键
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    @Override
+    public void deleteObjGroup(String id) {
+        // 校验是否可删除
+        ObjGroup objGroup = checkDeletable(id);
+
+        objGroup.setValid(ValidEnum.FALSE.getType());
+        updateById(objGroup);
+    }
+    
+    /**
+    * 查询报警对象分组
+    * @return List<ObjGroup>
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    @Override
+    public List<ObjGroup> queryObjGroupList(QueryObjGroupDTO queryObjGroupDTO) {
+        QueryWrapper<ObjGroup> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq(ObjGroup.PROP_VALID, ValidEnum.TRUE.getType());
+        // 默认按创建时间倒序排序
+        queryWrapper.orderBy(true, false, ObjGroup.PROP_CREATIONTIME);
+        
+        if (queryObjGroupDTO != null) {
+                                
+            if (StringUtils.isNotEmpty(queryObjGroupDTO.getName())) {
+                queryWrapper.like(ObjGroup.PROP_NAME, queryObjGroupDTO.getName());
+            }
+                                        
+            if (StringUtils.isNotEmpty(queryObjGroupDTO.getClassCode())) {
+                queryWrapper.eq(ObjGroup.PROP_CLASS_CODE, queryObjGroupDTO.getClassCode());
+            }
+                                        
+            if (StringUtils.isNotEmpty(queryObjGroupDTO.getCondition())) {
+                queryWrapper.eq(ObjGroup.PROP_CONDITION, queryObjGroupDTO.getCondition());
+            }
+                                        
+            if (StringUtils.isNotEmpty(queryObjGroupDTO.getParentid())) {
+                queryWrapper.eq(ObjGroup.PROP_PARENT_ID, queryObjGroupDTO.getParentid());
+            }
+                                            
+        }
+        
+        return list(queryWrapper);
+    }
+    
+    /**
+    * 分页查询报警对象分组
+    * @return IPage<ObjGroup>
+    * @author lixing
+    * @version V1.0 2021-10-19 14:25:45
+    */
+    @Override
+    public IPage<ObjGroup> pageQueryObjGroup(PageQueryObjGroupDTO pageQueryObjGroupDTO) {
+        QueryWrapper<ObjGroup> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq(ObjGroup.PROP_VALID, ValidEnum.TRUE.getType());
+        // 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
+        IPage<ObjGroup> pageParam = new Page<>(pageQueryObjGroupDTO.getPage(), pageQueryObjGroupDTO.getSize(),true);
+        // 排序信息
+        if(CollectionUtils.isEmpty(pageQueryObjGroupDTO.getOrders())){
+            // 默认按创建时间倒序排序
+            queryWrapper.orderBy(true, false, ObjGroup.PROP_CREATIONTIME);
+        }else {
+            List<Sort> orders = pageQueryObjGroupDTO.getOrders();
+            for(Sort sort: orders) {
+                // 将驼峰转换为下划线格式
+                sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,sort.getColumn()));
+                queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
+            }
+        }
+                
+        // todo 需判断使用like还是eq
+        if (StringUtils.isNotEmpty(pageQueryObjGroupDTO.getName())) {
+            queryWrapper.like(ObjGroup.PROP_NAME, pageQueryObjGroupDTO.getName());
+        }
+                            
+        // todo 需判断使用like还是eq
+        if (StringUtils.isNotEmpty(pageQueryObjGroupDTO.getClassCode())) {
+            queryWrapper.like(ObjGroup.PROP_CLASS_CODE, pageQueryObjGroupDTO.getClassCode());
+        }
+                            
+        // todo 需判断使用like还是eq
+        if (StringUtils.isNotEmpty(pageQueryObjGroupDTO.getCondition())) {
+            queryWrapper.like(ObjGroup.PROP_CONDITION, pageQueryObjGroupDTO.getCondition());
+        }
+                            
+        // todo 需判断使用like还是eq
+        if (StringUtils.isNotEmpty(pageQueryObjGroupDTO.getParentid())) {
+            queryWrapper.like(ObjGroup.PROP_PARENT_ID, pageQueryObjGroupDTO.getParentid());
+        }
+                                    
+        return getBaseMapper().selectPage(pageParam, queryWrapper);
+    }
+}

+ 3 - 3
src/main/resources/bootstrap.yml

@@ -14,10 +14,10 @@ mybatis-plus:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 
 
-#eureka:
+eureka:
 #  instance:
 #    prefer-ip-address: true
-#  client:
-#    register-with-eureka: false
+  client:
+    register-with-eureka: false
 
 

File diff suppressed because it is too large
+ 1 - 1
src/main/resources/db/init/data.sql


File diff suppressed because it is too large
+ 1 - 1
src/main/resources/db/init/table.sql


+ 18 - 0
src/main/resources/mapper/ObjGroupMapper.xml

@@ -0,0 +1,18 @@
+<?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="com.persagy.apm.alarmservice.group.objgroup.dao.ObjGroupMapper">
+    <resultMap id="ObjGroupMap" type="com.persagy.apm.alarmservice.group.objgroup.model.ObjGroup">
+		<result column="id" property="id" />
+		<result column="name" property="name" />
+		<result column="class_code" property="classCode" />
+		<result column="condition" property="condition" />
+		<result column="parent_id" property="parentid" />
+		<result column="ts" property="ts" />
+		<result column="creator" property="creator" />
+		<result column="creation_time" property="creationTime" />
+		<result column="modifier" property="modifier" />
+		<result column="modified_time" property="modifiedTime" />
+		<result column="valid" property="valid" />
+	</resultMap>
+</mapper>
+