feat: 设置主机分组内元素.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
### 创建主机分组
|
||||
POST {{baseUrl}}/asset/host-group/create
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"parentId": -1,
|
||||
"name": ""
|
||||
}
|
||||
|
||||
|
||||
### 查询主机分组
|
||||
GET {{baseUrl}}/asset/host-group/tree
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 修改名称
|
||||
PUT {{baseUrl}}/asset/host-group/rename
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": "",
|
||||
"name": ""
|
||||
}
|
||||
|
||||
|
||||
### 移动位置
|
||||
PUT {{baseUrl}}/asset/host-group/move
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": "",
|
||||
"targetId": "",
|
||||
"position": ""
|
||||
}
|
||||
|
||||
|
||||
### 删除主机分组
|
||||
DELETE {{baseUrl}}/asset/host-group/delete?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package com.orion.ops.module.asset.controller;
|
||||
|
||||
import com.orion.lang.define.wrapper.HttpWrapper;
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.asset.define.operator.HostOperatorType;
|
||||
import com.orion.ops.module.asset.service.HostService;
|
||||
import com.orion.ops.module.asset.convert.HostGroupConvert;
|
||||
import com.orion.ops.module.asset.define.operator.HostGroupOperatorType;
|
||||
import com.orion.ops.module.asset.entity.vo.HostGroupTreeVO;
|
||||
import com.orion.ops.module.infra.api.DataGroupApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupUpdateDTO;
|
||||
import com.orion.ops.module.infra.api.DataGroupRelApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.*;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 主机分组 api
|
||||
@@ -37,43 +40,46 @@ import java.util.List;
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
public class HostGroupController {
|
||||
|
||||
@Resource
|
||||
private HostService hostService;
|
||||
|
||||
@Resource
|
||||
private DataGroupApi dataGroupApi;
|
||||
|
||||
// TODO 配置权限
|
||||
// TODO 配置操作日志类型
|
||||
// TODO 拖拽
|
||||
// TODO http
|
||||
// TODO 聚合查询关联
|
||||
@Resource
|
||||
private DataGroupRelApi dataGroupRelApi;
|
||||
|
||||
@OperatorLog(HostOperatorType.CREATE)
|
||||
@OperatorLog(HostGroupOperatorType.CREATE)
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建主机分组")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:create')")
|
||||
public Long createHostGroup(@Validated @RequestBody DataGroupCreateDTO request) {
|
||||
public Long updateGroupHost(@Validated @RequestBody DataGroupCreateDTO request) {
|
||||
return dataGroupApi.createDataGroup(DataGroupTypeEnum.HOST, request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/tree")
|
||||
@Operation(summary = "创建主机分组")
|
||||
@Operation(summary = "查询主机分组")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:query')")
|
||||
public List<DataGroupDTO> queryHostGroup() {
|
||||
return dataGroupApi.getDataGroupTree(DataGroupTypeEnum.HOST);
|
||||
public List<HostGroupTreeVO> queryHostGroup() {
|
||||
List<DataGroupDTO> rows = dataGroupApi.getDataGroupTree(DataGroupTypeEnum.HOST);
|
||||
return HostGroupConvert.MAPPER.toList(rows);
|
||||
}
|
||||
|
||||
@OperatorLog(HostOperatorType.UPDATE)
|
||||
@OperatorLog(HostGroupOperatorType.RENAME)
|
||||
@PutMapping("/rename")
|
||||
@Operation(summary = "修改名称")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:update')")
|
||||
public Integer updateHostGroupName(@Validated @RequestBody DataGroupUpdateDTO request) {
|
||||
public Integer updateHostGroupName(@Validated @RequestBody DataGroupRenameDTO request) {
|
||||
return dataGroupApi.renameDataGroup(request);
|
||||
}
|
||||
|
||||
@OperatorLog(HostOperatorType.DELETE)
|
||||
@OperatorLog(HostGroupOperatorType.MOVE)
|
||||
@PutMapping("/move")
|
||||
@Operation(summary = "移动位置")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:update')")
|
||||
public Integer moveHostGroup(@Validated @RequestBody DataGroupMoveDTO request) {
|
||||
return dataGroupApi.moveDataGroup(request);
|
||||
}
|
||||
|
||||
@OperatorLog(HostGroupOperatorType.DELETE)
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除主机分组")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:delete')")
|
||||
@@ -81,5 +87,23 @@ public class HostGroupController {
|
||||
return dataGroupApi.deleteDataGroupById(id);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/rel-list")
|
||||
@Operation(summary = "查询分组主机")
|
||||
@Parameter(name = "groupId", description = "groupId", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:query-rel')")
|
||||
public Set<Long> queryHostGroupRel(@RequestParam("groupId") Long groupId) {
|
||||
return dataGroupRelApi.getGroupRelList(DataGroupTypeEnum.HOST, groupId);
|
||||
}
|
||||
|
||||
@OperatorLog(HostGroupOperatorType.UPDATE_REL)
|
||||
@PostMapping("/update-rel")
|
||||
@Operation(summary = "修改分组主机")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:update-rel')")
|
||||
public HttpWrapper<?> updateGroupHost(@Validated @RequestBody DataGroupRelUpdateDTO request) {
|
||||
dataGroupRelApi.updateGroupRel(request);
|
||||
return HttpWrapper.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orion.ops.module.asset.convert;
|
||||
|
||||
import com.orion.ops.module.asset.entity.vo.HostGroupTreeVO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机配置 内部对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-11 14:16
|
||||
*/
|
||||
@Mapper
|
||||
public interface HostGroupConvert {
|
||||
|
||||
HostGroupConvert MAPPER = Mappers.getMapper(HostGroupConvert.class);
|
||||
|
||||
List<HostGroupTreeVO> toList(List<DataGroupDTO> list);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.orion.ops.module.asset.define.operator;
|
||||
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.Module;
|
||||
import com.orion.ops.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
|
||||
import com.orion.ops.framework.biz.operator.log.core.model.OperatorType;
|
||||
|
||||
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.*;
|
||||
|
||||
/**
|
||||
* 主机分组 操作日志类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/10/10 17:30
|
||||
*/
|
||||
@Module("asset:host-group")
|
||||
public class HostGroupOperatorType extends InitializingOperatorTypes {
|
||||
|
||||
public static final String CREATE = "host-group:create";
|
||||
|
||||
public static final String RENAME = "host-group:rename";
|
||||
|
||||
public static final String MOVE = "host-group:move";
|
||||
|
||||
public static final String DELETE = "host-group:delete";
|
||||
|
||||
public static final String UPDATE_REL = "host-group:update-rel";
|
||||
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(L, CREATE, "创建主机分组 <sb>${name}</sb>"),
|
||||
new OperatorType(L, RENAME, "重命名主机分组 <sb>${before}</sb> -> <sb>${name}</sb>"),
|
||||
new OperatorType(L, MOVE, "移动主机分组 <sb>${source}</sb> 到 <sb>${target}(${position})</sb>"),
|
||||
new OperatorType(H, DELETE, "删除主机分组 <sb>${name}</sb>"),
|
||||
new OperatorType(M, UPDATE_REL, "修改分组内主机 <sb>${name}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.orion.ops.module.asset.entity.request.host;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机分组引用 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-20 11:55
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostGroupRelUpdateRequest", description = "主机分组引用 更新请求对象")
|
||||
public class HostGroupRelUpdateRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "分组id")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "主机id")
|
||||
private List<Long> hostIdList;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.orion.ops.module.asset.entity.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机秘钥 视图响应对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-20 11:55
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostGroupTreeVO", description = "主机秘钥 视图响应对象")
|
||||
public class HostGroupTreeVO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@JsonProperty("key")
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "父id")
|
||||
private Long parentId;
|
||||
|
||||
@JsonProperty("title")
|
||||
@Schema(description = "组名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "子节点")
|
||||
private List<HostGroupTreeVO> children;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user