生成主机身份代码.

This commit is contained in:
lijiahang
2023-09-20 12:13:02 +08:00
parent 044b859c5b
commit e9047c59c0
43 changed files with 3139 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
### 创建主机身份
POST {{baseUrl}}/asset/host-identity/create
Content-Type: application/json
Authorization: {{token}}
{
"name": "",
"username": "",
"password": "",
"keyId": ""
}
### 通过 id 更新主机身份
PUT {{baseUrl}}/asset/host-identity/update
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"name": "",
"username": "",
"password": "",
"keyId": ""
}
### 通过 id 查询主机身份
GET {{baseUrl}}/asset/host-identity/get?id=1
Authorization: {{token}}
### 通过 id 批量查询主机身份
GET {{baseUrl}}/asset/host-identity/list?idList=1,2,3
Authorization: {{token}}
### 查询主机身份
POST {{baseUrl}}/asset/host-identity/list-all
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"name": "",
"username": "",
"password": "",
"keyId": ""
}
### 分页查询主机身份
POST {{baseUrl}}/asset/host-identity/query
Content-Type: application/json
Authorization: {{token}}
{
"page": 1,
"limit": 10,
"id": "",
"name": "",
"username": "",
"password": "",
"keyId": ""
}
### 通过 id 删除主机身份
DELETE {{baseUrl}}/asset/host-identity/delete?id=1
Authorization: {{token}}
### 通过 id 批量删除主机身份
DELETE {{baseUrl}}/asset/host-identity/delete-batch?idList=1,2,3
Authorization: {{token}}
### 导出主机身份
POST {{baseUrl}}/asset/host-identity/export
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"name": "",
"username": "",
"password": "",
"keyId": ""
}
###

View File

@@ -0,0 +1,118 @@
package com.orion.ops.module.asset.controller;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.framework.common.annotation.IgnoreLog;
import com.orion.ops.framework.common.annotation.RestWrapper;
import com.orion.ops.framework.common.constant.IgnoreLogMode;
import com.orion.ops.framework.common.valid.group.Page;
import com.orion.ops.module.asset.service.*;
import com.orion.ops.module.asset.entity.vo.*;
import com.orion.ops.module.asset.entity.request.host.*;
import com.orion.ops.module.asset.entity.export.*;
import com.orion.ops.module.asset.convert.*;
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;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* 主机身份 api
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Tag(name = "asset - 主机身份服务")
@Slf4j
@Validated
@RestWrapper
@RestController
@RequestMapping("/asset/host-identity")
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
public class HostIdentityController {
@Resource
private HostIdentityService hostIdentityService;
@PostMapping("/create")
@Operation(summary = "创建主机身份")
@PreAuthorize("@ss.hasPermission('asset:host-identity:create')")
public Long createHostIdentity(@Validated @RequestBody HostIdentityCreateRequest request) {
return hostIdentityService.createHostIdentity(request);
}
@PutMapping("/update")
@Operation(summary = "通过 id 更新主机身份")
@PreAuthorize("@ss.hasPermission('asset:host-identity:update')")
public Integer updateHostIdentity(@Validated @RequestBody HostIdentityUpdateRequest request) {
return hostIdentityService.updateHostIdentityById(request);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/get")
@Operation(summary = "通过 id 查询主机身份")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-identity:query')")
public HostIdentityVO getHostIdentity(@RequestParam("id") Long id) {
return hostIdentityService.getHostIdentityById(id);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/list")
@Operation(summary = "通过 id 批量查询主机身份")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-identity:query')")
public List<HostIdentityVO> getHostIdentityList(@RequestParam("idList") List<Long> idList) {
return hostIdentityService.getHostIdentityByIdList(idList);
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/list-all")
@Operation(summary = "查询主机身份")
@PreAuthorize("@ss.hasPermission('asset:host-identity:query')")
public List<HostIdentityVO> getHostIdentityListAll(@Validated @RequestBody HostIdentityQueryRequest request) {
return hostIdentityService.getHostIdentityList(request);
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/query")
@Operation(summary = "分页查询主机身份")
@PreAuthorize("@ss.hasPermission('asset:host-identity:query')")
public DataGrid<HostIdentityVO> getHostIdentityPage(@Validated(Page.class) @RequestBody HostIdentityQueryRequest request) {
return hostIdentityService.getHostIdentityPage(request);
}
@DeleteMapping("/delete")
@Operation(summary = "通过 id 删除主机身份")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-identity:delete')")
public Integer deleteHostIdentity(@RequestParam("id") Long id) {
return hostIdentityService.deleteHostIdentityById(id);
}
@DeleteMapping("/delete-batch")
@Operation(summary = "通过 id 批量删除主机身份")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-identity:delete')")
public Integer batchDeleteHostIdentity(@RequestParam("idList") List<Long> idList) {
return hostIdentityService.batchDeleteHostIdentityByIdList(idList);
}
@PostMapping("/export")
@Operation(summary = "导出主机身份")
@PreAuthorize("@ss.hasPermission('asset:host-identity:export')")
public void exportHostIdentity(@Validated @RequestBody HostIdentityQueryRequest request,
HttpServletResponse response) throws IOException {
hostIdentityService.exportHostIdentity(request, response);
}
}

View File

@@ -0,0 +1,92 @@
### 创建主机秘钥
POST {{baseUrl}}/asset/host-key/create
Content-Type: application/json
Authorization: {{token}}
{
"name": "",
"publicKey": "",
"privateKey": "",
"password": ""
}
### 通过 id 更新主机秘钥
PUT {{baseUrl}}/asset/host-key/update
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"name": "",
"publicKey": "",
"privateKey": "",
"password": ""
}
### 通过 id 查询主机秘钥
GET {{baseUrl}}/asset/host-key/get?id=1
Authorization: {{token}}
### 通过 id 批量查询主机秘钥
GET {{baseUrl}}/asset/host-key/list?idList=1,2,3
Authorization: {{token}}
### 查询主机秘钥
POST {{baseUrl}}/asset/host-key/list-all
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"name": "",
"publicKey": "",
"privateKey": "",
"password": ""
}
### 分页查询主机秘钥
POST {{baseUrl}}/asset/host-key/query
Content-Type: application/json
Authorization: {{token}}
{
"page": 1,
"limit": 10,
"id": "",
"name": "",
"publicKey": "",
"privateKey": "",
"password": ""
}
### 通过 id 删除主机秘钥
DELETE {{baseUrl}}/asset/host-key/delete?id=1
Authorization: {{token}}
### 通过 id 批量删除主机秘钥
DELETE {{baseUrl}}/asset/host-key/delete-batch?idList=1,2,3
Authorization: {{token}}
### 导出主机秘钥
POST {{baseUrl}}/asset/host-key/export
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"name": "",
"publicKey": "",
"privateKey": "",
"password": ""
}
###

View File

@@ -0,0 +1,118 @@
package com.orion.ops.module.asset.controller;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.framework.common.annotation.IgnoreLog;
import com.orion.ops.framework.common.annotation.RestWrapper;
import com.orion.ops.framework.common.constant.IgnoreLogMode;
import com.orion.ops.framework.common.valid.group.Page;
import com.orion.ops.module.asset.service.*;
import com.orion.ops.module.asset.entity.vo.*;
import com.orion.ops.module.asset.entity.request.host.*;
import com.orion.ops.module.asset.entity.export.*;
import com.orion.ops.module.asset.convert.*;
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;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* 主机秘钥 api
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Tag(name = "asset - 主机秘钥服务")
@Slf4j
@Validated
@RestWrapper
@RestController
@RequestMapping("/asset/host-key")
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
public class HostKeyController {
@Resource
private HostKeyService hostKeyService;
@PostMapping("/create")
@Operation(summary = "创建主机秘钥")
@PreAuthorize("@ss.hasPermission('asset:host-key:create')")
public Long createHostKey(@Validated @RequestBody HostKeyCreateRequest request) {
return hostKeyService.createHostKey(request);
}
@PutMapping("/update")
@Operation(summary = "通过 id 更新主机秘钥")
@PreAuthorize("@ss.hasPermission('asset:host-key:update')")
public Integer updateHostKey(@Validated @RequestBody HostKeyUpdateRequest request) {
return hostKeyService.updateHostKeyById(request);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/get")
@Operation(summary = "通过 id 查询主机秘钥")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-key:query')")
public HostKeyVO getHostKey(@RequestParam("id") Long id) {
return hostKeyService.getHostKeyById(id);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/list")
@Operation(summary = "通过 id 批量查询主机秘钥")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-key:query')")
public List<HostKeyVO> getHostKeyList(@RequestParam("idList") List<Long> idList) {
return hostKeyService.getHostKeyByIdList(idList);
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/list-all")
@Operation(summary = "查询主机秘钥")
@PreAuthorize("@ss.hasPermission('asset:host-key:query')")
public List<HostKeyVO> getHostKeyListAll(@Validated @RequestBody HostKeyQueryRequest request) {
return hostKeyService.getHostKeyList(request);
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/query")
@Operation(summary = "分页查询主机秘钥")
@PreAuthorize("@ss.hasPermission('asset:host-key:query')")
public DataGrid<HostKeyVO> getHostKeyPage(@Validated(Page.class) @RequestBody HostKeyQueryRequest request) {
return hostKeyService.getHostKeyPage(request);
}
@DeleteMapping("/delete")
@Operation(summary = "通过 id 删除主机秘钥")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-key:delete')")
public Integer deleteHostKey(@RequestParam("id") Long id) {
return hostKeyService.deleteHostKeyById(id);
}
@DeleteMapping("/delete-batch")
@Operation(summary = "通过 id 批量删除主机秘钥")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-key:delete')")
public Integer batchDeleteHostKey(@RequestParam("idList") List<Long> idList) {
return hostKeyService.batchDeleteHostKeyByIdList(idList);
}
@PostMapping("/export")
@Operation(summary = "导出主机秘钥")
@PreAuthorize("@ss.hasPermission('asset:host-key:export')")
public void exportHostKey(@Validated @RequestBody HostKeyQueryRequest request,
HttpServletResponse response) throws IOException {
hostKeyService.exportHostKey(request, response);
}
}

View File

@@ -0,0 +1,37 @@
package com.orion.ops.module.asset.convert;
import com.orion.ops.module.asset.entity.domain.*;
import com.orion.ops.module.asset.entity.vo.*;
import com.orion.ops.module.asset.entity.request.host.*;
import com.orion.ops.module.asset.entity.export.*;
import com.orion.ops.module.asset.convert.*;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 主机身份 内部对象转换器
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Mapper
public interface HostIdentityConvert {
HostIdentityConvert MAPPER = Mappers.getMapper(HostIdentityConvert.class);
HostIdentityDO to(HostIdentityCreateRequest request);
HostIdentityDO to(HostIdentityUpdateRequest request);
HostIdentityDO to(HostIdentityQueryRequest request);
HostIdentityVO to(HostIdentityDO domain);
HostIdentityExport toExport(HostIdentityDO domain);
List<HostIdentityVO> to(List<HostIdentityDO> list);
}

View File

@@ -0,0 +1,37 @@
package com.orion.ops.module.asset.convert;
import com.orion.ops.module.asset.entity.domain.*;
import com.orion.ops.module.asset.entity.vo.*;
import com.orion.ops.module.asset.entity.request.host.*;
import com.orion.ops.module.asset.entity.export.*;
import com.orion.ops.module.asset.convert.*;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 主机秘钥 内部对象转换器
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Mapper
public interface HostKeyConvert {
HostKeyConvert MAPPER = Mappers.getMapper(HostKeyConvert.class);
HostKeyDO to(HostKeyCreateRequest request);
HostKeyDO to(HostKeyUpdateRequest request);
HostKeyDO to(HostKeyQueryRequest request);
HostKeyVO to(HostKeyDO domain);
HostKeyExport toExport(HostKeyDO domain);
List<HostKeyVO> to(List<HostKeyDO> list);
}

View File

@@ -0,0 +1,33 @@
package com.orion.ops.module.asset.dao;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
import com.orion.ops.module.asset.entity.domain.HostIdentityDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 主机身份 Mapper 接口
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Mapper
public interface HostIdentityDAO extends IMapper<HostIdentityDO> {
/**
* 获取查询条件
*
* @param entity entity
* @return 查询条件
*/
default LambdaQueryWrapper<HostIdentityDO> queryCondition(HostIdentityDO entity) {
return this.wrapper()
.eq(HostIdentityDO::getId, entity.getId())
.eq(HostIdentityDO::getName, entity.getName())
.eq(HostIdentityDO::getUsername, entity.getUsername())
.eq(HostIdentityDO::getPassword, entity.getPassword())
.eq(HostIdentityDO::getKeyId, entity.getKeyId());
}
}

View File

@@ -0,0 +1,33 @@
package com.orion.ops.module.asset.dao;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
import com.orion.ops.module.asset.entity.domain.HostKeyDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 主机秘钥 Mapper 接口
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Mapper
public interface HostKeyDAO extends IMapper<HostKeyDO> {
/**
* 获取查询条件
*
* @param entity entity
* @return 查询条件
*/
default LambdaQueryWrapper<HostKeyDO> queryCondition(HostKeyDO entity) {
return this.wrapper()
.eq(HostKeyDO::getId, entity.getId())
.eq(HostKeyDO::getName, entity.getName())
.eq(HostKeyDO::getPublicKey, entity.getPublicKey())
.eq(HostKeyDO::getPrivateKey, entity.getPrivateKey())
.eq(HostKeyDO::getPassword, entity.getPassword());
}
}

View File

@@ -0,0 +1,46 @@
package com.orion.ops.module.asset.entity.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
/**
* 主机身份 实体对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "host_identity", autoResultMap = true)
@Schema(name = "HostIdentityDO", description = "主机身份 实体对象")
public class HostIdentityDO extends BaseDO {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@Schema(description = "名称")
@TableField("name")
private String name;
@Schema(description = "用户名")
@TableField("username")
private String username;
@Schema(description = "用户密码")
@TableField("password")
private String password;
@Schema(description = "秘钥id")
@TableField("key_id")
private Long keyId;
}

View File

@@ -0,0 +1,46 @@
package com.orion.ops.module.asset.entity.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
/**
* 主机秘钥 实体对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "host_key", autoResultMap = true)
@Schema(name = "HostKeyDO", description = "主机秘钥 实体对象")
public class HostKeyDO extends BaseDO {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@Schema(description = "名称")
@TableField("name")
private String name;
@Schema(description = "公钥文本")
@TableField("public_key")
private String publicKey;
@Schema(description = "私钥文本")
@TableField("private_key")
private String privateKey;
@Schema(description = "密码")
@TableField("password")
private String password;
}

View File

@@ -0,0 +1,67 @@
package com.orion.ops.module.asset.entity.export;
import com.orion.lang.utils.time.Dates;
import com.orion.office.excel.annotation.ExportField;
import com.orion.office.excel.annotation.ExportSheet;
import com.orion.office.excel.annotation.ExportTitle;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.io.Serializable;
import java.util.*;
/**
* 主机身份 导出对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ExportTitle(title = HostIdentityExport.TITLE)
@ExportSheet(name = "主机身份", filterHeader = true, freezeHeader = true, indexToSort = true)
@Schema(name = "HostIdentityExport", description = "主机身份导出对象")
public class HostIdentityExport implements Serializable {
public static final String TITLE = "主机身份导出";
@Schema(description = "id")
@ExportField(index = 0, header = "id", width = 16)
private Long id;
@Schema(description = "名称")
@ExportField(index = 1, header = "名称", width = 16)
private String name;
@Schema(description = "用户名")
@ExportField(index = 2, header = "用户名", width = 16)
private String username;
@Schema(description = "用户密码")
@ExportField(index = 3, header = "用户密码", width = 16)
private String password;
@Schema(description = "秘钥id")
@ExportField(index = 4, header = "秘钥id", width = 16)
private Long keyId;
@ExportField(index = 5, header = "创建时间", width = 16, format = Dates.YMD_HMS)
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "修改时间")
@ExportField(index = 6, header = "修改时间", width = 16, format = Dates.YMD_HMS)
private Date updateTime;
@Schema(description = "创建人")
@ExportField(index = 7, header = "创建人", width = 16)
private String creator;
@Schema(description = "修改人")
@ExportField(index = 8, header = "修改人", width = 16)
private String updater;
}

View File

@@ -0,0 +1,67 @@
package com.orion.ops.module.asset.entity.export;
import com.orion.lang.utils.time.Dates;
import com.orion.office.excel.annotation.ExportField;
import com.orion.office.excel.annotation.ExportSheet;
import com.orion.office.excel.annotation.ExportTitle;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.io.Serializable;
import java.util.*;
/**
* 主机秘钥 导出对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ExportTitle(title = HostKeyExport.TITLE)
@ExportSheet(name = "主机秘钥", filterHeader = true, freezeHeader = true, indexToSort = true)
@Schema(name = "HostKeyExport", description = "主机秘钥导出对象")
public class HostKeyExport implements Serializable {
public static final String TITLE = "主机秘钥导出";
@Schema(description = "id")
@ExportField(index = 0, header = "id", width = 16)
private Long id;
@Schema(description = "名称")
@ExportField(index = 1, header = "名称", width = 16)
private String name;
@Schema(description = "公钥文本")
@ExportField(index = 2, header = "公钥文本", width = 16)
private String publicKey;
@Schema(description = "私钥文本")
@ExportField(index = 3, header = "私钥文本", width = 16)
private String privateKey;
@Schema(description = "密码")
@ExportField(index = 4, header = "密码", width = 16)
private String password;
@ExportField(index = 5, header = "创建时间", width = 16, format = Dates.YMD_HMS)
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "修改时间")
@ExportField(index = 6, header = "修改时间", width = 16, format = Dates.YMD_HMS)
private Date updateTime;
@Schema(description = "创建人")
@ExportField(index = 7, header = "创建人", width = 16)
private String creator;
@Schema(description = "修改人")
@ExportField(index = 8, header = "修改人", width = 16)
private String updater;
}

View File

@@ -0,0 +1,47 @@
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;
/**
* 主机身份 创建请求对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostIdentityCreateRequest", description = "主机身份 创建请求对象")
public class HostIdentityCreateRequest implements Serializable {
@NotBlank
@Size(max = 64)
@Schema(description = "名称")
private String name;
@NotBlank
@Size(max = 128)
@Schema(description = "用户名")
private String username;
@NotBlank
@Size(max = 512)
@Schema(description = "用户密码")
private String password;
@NotNull
@Schema(description = "秘钥id")
private Long keyId;
}

View File

@@ -0,0 +1,42 @@
package com.orion.ops.module.asset.entity.request.host;
import com.orion.ops.framework.common.entity.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.Size;
/**
* 主机身份 查询请求对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "HostIdentityQueryRequest", description = "主机身份 查询请求对象")
public class HostIdentityQueryRequest extends PageRequest {
@Schema(description = "id")
private Long id;
@Size(max = 64)
@Schema(description = "名称")
private String name;
@Size(max = 128)
@Schema(description = "用户名")
private String username;
@Size(max = 512)
@Schema(description = "用户密码")
private String password;
@Schema(description = "秘钥id")
private Long keyId;
}

View File

@@ -0,0 +1,51 @@
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;
/**
* 主机身份 更新请求对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostIdentityUpdateRequest", description = "主机身份 更新请求对象")
public class HostIdentityUpdateRequest implements Serializable {
@NotNull
@Schema(description = "id")
private Long id;
@NotBlank
@Size(max = 64)
@Schema(description = "名称")
private String name;
@NotBlank
@Size(max = 128)
@Schema(description = "用户名")
private String username;
@NotBlank
@Size(max = 512)
@Schema(description = "用户密码")
private String password;
@NotNull
@Schema(description = "秘钥id")
private Long keyId;
}

View File

@@ -0,0 +1,47 @@
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.Size;
import java.io.Serializable;
/**
* 主机秘钥 创建请求对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostKeyCreateRequest", description = "主机秘钥 创建请求对象")
public class HostKeyCreateRequest implements Serializable {
@NotBlank
@Size(max = 64)
@Schema(description = "名称")
private String name;
@NotBlank
@Size(max = 65535)
@Schema(description = "公钥文本")
private String publicKey;
@NotBlank
@Size(max = 65535)
@Schema(description = "私钥文本")
private String privateKey;
@NotBlank
@Size(max = 512)
@Schema(description = "密码")
private String password;
}

View File

@@ -0,0 +1,43 @@
package com.orion.ops.module.asset.entity.request.host;
import com.orion.ops.framework.common.entity.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.Size;
/**
* 主机秘钥 查询请求对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "HostKeyQueryRequest", description = "主机秘钥 查询请求对象")
public class HostKeyQueryRequest extends PageRequest {
@Schema(description = "id")
private Long id;
@Size(max = 64)
@Schema(description = "名称")
private String name;
@Size(max = 65535)
@Schema(description = "公钥文本")
private String publicKey;
@Size(max = 65535)
@Schema(description = "私钥文本")
private String privateKey;
@Size(max = 512)
@Schema(description = "密码")
private String password;
}

View File

@@ -0,0 +1,52 @@
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;
/**
* 主机秘钥 更新请求对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostKeyUpdateRequest", description = "主机秘钥 更新请求对象")
public class HostKeyUpdateRequest implements Serializable {
@NotNull
@Schema(description = "id")
private Long id;
@NotBlank
@Size(max = 64)
@Schema(description = "名称")
private String name;
@NotBlank
@Size(max = 65535)
@Schema(description = "公钥文本")
private String publicKey;
@NotBlank
@Size(max = 65535)
@Schema(description = "私钥文本")
private String privateKey;
@NotBlank
@Size(max = 512)
@Schema(description = "密码")
private String password;
}

View File

@@ -0,0 +1,52 @@
package com.orion.ops.module.asset.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.io.Serializable;
import java.util.*;
/**
* 主机身份 视图响应对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostIdentityVO", description = "主机身份 视图响应对象")
public class HostIdentityVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
private Long id;
@Schema(description = "名称")
private String name;
@Schema(description = "用户名")
private String username;
@Schema(description = "用户密码")
private String password;
@Schema(description = "秘钥id")
private Long keyId;
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "修改时间")
private Date updateTime;
@Schema(description = "创建人")
private String creator;
@Schema(description = "修改人")
private String updater;
}

View File

@@ -0,0 +1,52 @@
package com.orion.ops.module.asset.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.io.Serializable;
import java.util.*;
/**
* 主机秘钥 视图响应对象
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostKeyVO", description = "主机秘钥 视图响应对象")
public class HostKeyVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
private Long id;
@Schema(description = "名称")
private String name;
@Schema(description = "公钥文本")
private String publicKey;
@Schema(description = "私钥文本")
private String privateKey;
@Schema(description = "密码")
private String password;
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "修改时间")
private Date updateTime;
@Schema(description = "创建人")
private String creator;
@Schema(description = "修改人")
private String updater;
}

View File

@@ -0,0 +1,120 @@
package com.orion.ops.module.asset.service;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.module.asset.entity.vo.*;
import com.orion.ops.module.asset.entity.request.host.*;
import com.orion.ops.module.asset.entity.export.*;
import com.orion.ops.module.asset.convert.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* 主机身份 服务类
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
public interface HostIdentityService {
/**
* 创建主机身份
*
* @param request request
* @return id
*/
Long createHostIdentity(HostIdentityCreateRequest request);
/**
* 通过 id 更新主机身份
*
* @param request request
* @return effect
*/
Integer updateHostIdentityById(HostIdentityUpdateRequest request);
/**
* 更新主机身份
*
* @param query query
* @param update update
* @return effect
*/
Integer updateHostIdentity(HostIdentityQueryRequest query, HostIdentityUpdateRequest update);
/**
* 通过 id 查询主机身份
*
* @param id id
* @return row
*/
HostIdentityVO getHostIdentityById(Long id);
/**
* 通过 id 批量查询主机身份
*
* @param idList idList
* @return rows
*/
List<HostIdentityVO> getHostIdentityByIdList(List<Long> idList);
/**
* 查询主机身份
*
* @param request request
* @return rows
*/
List<HostIdentityVO> getHostIdentityList(HostIdentityQueryRequest request);
/**
* 查询主机身份数量
*
* @param request request
* @return count
*/
Long getHostIdentityCount(HostIdentityQueryRequest request);
/**
* 分页查询主机身份
*
* @param request request
* @return rows
*/
DataGrid<HostIdentityVO> getHostIdentityPage(HostIdentityQueryRequest request);
/**
* 通过 id 删除主机身份
*
* @param id id
* @return effect
*/
Integer deleteHostIdentityById(Long id);
/**
* 通过 id 批量删除主机身份
*
* @param idList idList
* @return effect
*/
Integer batchDeleteHostIdentityByIdList(List<Long> idList);
/**
* 删除主机身份
*
* @param request request
* @return effect
*/
Integer deleteHostIdentity(HostIdentityQueryRequest request);
/**
* 导出主机身份
*
* @param request request
* @param response response
* @throws IOException IOException
*/
void exportHostIdentity(HostIdentityQueryRequest request, HttpServletResponse response) throws IOException;
}

View File

@@ -0,0 +1,120 @@
package com.orion.ops.module.asset.service;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.module.asset.entity.vo.*;
import com.orion.ops.module.asset.entity.request.host.*;
import com.orion.ops.module.asset.entity.export.*;
import com.orion.ops.module.asset.convert.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* 主机秘钥 服务类
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
public interface HostKeyService {
/**
* 创建主机秘钥
*
* @param request request
* @return id
*/
Long createHostKey(HostKeyCreateRequest request);
/**
* 通过 id 更新主机秘钥
*
* @param request request
* @return effect
*/
Integer updateHostKeyById(HostKeyUpdateRequest request);
/**
* 更新主机秘钥
*
* @param query query
* @param update update
* @return effect
*/
Integer updateHostKey(HostKeyQueryRequest query, HostKeyUpdateRequest update);
/**
* 通过 id 查询主机秘钥
*
* @param id id
* @return row
*/
HostKeyVO getHostKeyById(Long id);
/**
* 通过 id 批量查询主机秘钥
*
* @param idList idList
* @return rows
*/
List<HostKeyVO> getHostKeyByIdList(List<Long> idList);
/**
* 查询主机秘钥
*
* @param request request
* @return rows
*/
List<HostKeyVO> getHostKeyList(HostKeyQueryRequest request);
/**
* 查询主机秘钥数量
*
* @param request request
* @return count
*/
Long getHostKeyCount(HostKeyQueryRequest request);
/**
* 分页查询主机秘钥
*
* @param request request
* @return rows
*/
DataGrid<HostKeyVO> getHostKeyPage(HostKeyQueryRequest request);
/**
* 通过 id 删除主机秘钥
*
* @param id id
* @return effect
*/
Integer deleteHostKeyById(Long id);
/**
* 通过 id 批量删除主机秘钥
*
* @param idList idList
* @return effect
*/
Integer batchDeleteHostKeyByIdList(List<Long> idList);
/**
* 删除主机秘钥
*
* @param request request
* @return effect
*/
Integer deleteHostKey(HostKeyQueryRequest request);
/**
* 导出主机秘钥
*
* @param request request
* @param response response
* @throws IOException IOException
*/
void exportHostKey(HostKeyQueryRequest request, HttpServletResponse response) throws IOException;
}

View File

@@ -0,0 +1,212 @@
package com.orion.ops.module.asset.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.collect.Lists;
import com.orion.office.excel.writer.exporting.ExcelExport;
import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.FileNames;
import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.module.asset.entity.vo.*;
import com.orion.ops.module.asset.entity.request.host.*;
import com.orion.ops.module.asset.entity.export.*;
import com.orion.ops.module.asset.convert.*;
import com.orion.ops.module.asset.entity.domain.HostIdentityDO;
import com.orion.ops.module.asset.dao.HostIdentityDAO;
import com.orion.ops.module.asset.service.HostIdentityService;
import com.orion.web.servlet.web.Servlets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
/**
* 主机身份 服务实现类
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Slf4j
@Service
public class HostIdentityServiceImpl implements HostIdentityService {
@Resource
private HostIdentityDAO hostIdentityDAO;
@Override
public Long createHostIdentity(HostIdentityCreateRequest request) {
log.info("HostIdentityService-createHostIdentity request: {}", JSON.toJSONString(request));
// 转换
HostIdentityDO record = HostIdentityConvert.MAPPER.to(request);
// 查询数据是否冲突
this.checkHostIdentityPresent(record);
// 插入
int effect = hostIdentityDAO.insert(record);
log.info("HostIdentityService-createHostIdentity effect: {}", effect);
return record.getId();
}
@Override
public Integer updateHostIdentityById(HostIdentityUpdateRequest request) {
log.info("HostIdentityService-updateHostIdentityById request: {}", JSON.toJSONString(request));
// 查询
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
HostIdentityDO record = hostIdentityDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
HostIdentityDO updateRecord = HostIdentityConvert.MAPPER.to(request);
// 查询数据是否冲突
this.checkHostIdentityPresent(updateRecord);
// 更新
int effect = hostIdentityDAO.updateById(updateRecord);
log.info("HostIdentityService-updateHostIdentityById effect: {}", effect);
return effect;
}
@Override
public Integer updateHostIdentity(HostIdentityQueryRequest query, HostIdentityUpdateRequest update) {
log.info("HostIdentityService.updateHostIdentity query: {}, update: {}", JSON.toJSONString(query), JSON.toJSONString(update));
// 条件
LambdaQueryWrapper<HostIdentityDO> wrapper = this.buildQueryWrapper(query);
// 转换
HostIdentityDO updateRecord = HostIdentityConvert.MAPPER.to(update);
// 更新
int effect = hostIdentityDAO.update(updateRecord, wrapper);
log.info("HostIdentityService.updateHostIdentity effect: {}", effect);
return effect;
}
@Override
public HostIdentityVO getHostIdentityById(Long id) {
// 查询
HostIdentityDO record = hostIdentityDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
return HostIdentityConvert.MAPPER.to(record);
}
@Override
public List<HostIdentityVO> getHostIdentityByIdList(List<Long> idList) {
// 查询
List<HostIdentityDO> records = hostIdentityDAO.selectBatchIds(idList);
if (records.isEmpty()) {
return Lists.empty();
}
// 转换
return HostIdentityConvert.MAPPER.to(records);
}
@Override
public List<HostIdentityVO> getHostIdentityList(HostIdentityQueryRequest request) {
// 条件
LambdaQueryWrapper<HostIdentityDO> wrapper = this.buildQueryWrapper(request);
// 查询
return hostIdentityDAO.of(wrapper).list(HostIdentityConvert.MAPPER::to);
}
@Override
public Long getHostIdentityCount(HostIdentityQueryRequest request) {
// 条件
LambdaQueryWrapper<HostIdentityDO> wrapper = this.buildQueryWrapper(request);
// 查询
return hostIdentityDAO.selectCount(wrapper);
}
@Override
public DataGrid<HostIdentityVO> getHostIdentityPage(HostIdentityQueryRequest request) {
// 条件
LambdaQueryWrapper<HostIdentityDO> wrapper = this.buildQueryWrapper(request);
// 查询
return hostIdentityDAO.of(wrapper)
.page(request)
.dataGrid(HostIdentityConvert.MAPPER::to);
}
@Override
public Integer deleteHostIdentityById(Long id) {
log.info("HostIdentityService-deleteHostIdentityById id: {}", id);
int effect = hostIdentityDAO.deleteById(id);
log.info("HostIdentityService-deleteHostIdentityById effect: {}", effect);
return effect;
}
@Override
public Integer batchDeleteHostIdentityByIdList(List<Long> idList) {
log.info("HostIdentityService-batchDeleteHostIdentityByIdList idList: {}", idList);
int effect = hostIdentityDAO.deleteBatchIds(idList);
log.info("HostIdentityService-batchDeleteHostIdentityByIdList effect: {}", effect);
return effect;
}
@Override
public Integer deleteHostIdentity(HostIdentityQueryRequest request) {
log.info("HostIdentityService.deleteHostIdentity request: {}", JSON.toJSONString(request));
// 条件
LambdaQueryWrapper<HostIdentityDO> wrapper = this.buildQueryWrapper(request);
// 删除
int effect = hostIdentityDAO.delete(wrapper);
log.info("HostIdentityService.deleteHostIdentity effect: {}", effect);
return effect;
}
@Override
public void exportHostIdentity(HostIdentityQueryRequest request, HttpServletResponse response) throws IOException {
log.info("HostIdentityService.exportHostIdentity request: {}", JSON.toJSONString(request));
// 条件
LambdaQueryWrapper<HostIdentityDO> wrapper = this.buildQueryWrapper(request);
// 查询
List<HostIdentityExport> rows = hostIdentityDAO.of(wrapper).list(HostIdentityConvert.MAPPER::toExport);
log.info("HostIdentityService.exportHostIdentity size: {}", rows.size());
// 导出
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelExport.create(HostIdentityExport.class)
.addRows(rows)
.write(out)
.close();
// 传输
Servlets.transfer(response, out.toByteArray(), FileNames.exportName(HostIdentityExport.TITLE));
}
/**
* 检测对象是否存在
*
* @param domain domain
*/
private void checkHostIdentityPresent(HostIdentityDO domain) {
// 构造条件
LambdaQueryWrapper<HostIdentityDO> wrapper = hostIdentityDAO.wrapper()
// 更新时忽略当前记录
.ne(HostIdentityDO::getId, domain.getId())
// 用其他字段做重复校验
.eq(HostIdentityDO::getName, domain.getName())
.eq(HostIdentityDO::getUsername, domain.getUsername())
.eq(HostIdentityDO::getPassword, domain.getPassword())
.eq(HostIdentityDO::getKeyId, domain.getKeyId());
// 检查是否存在
boolean present = hostIdentityDAO.of(wrapper).present();
Valid.isFalse(present, ErrorMessage.DATA_PRESENT);
}
/**
* 构建查询 wrapper
*
* @param request request
* @return wrapper
*/
private LambdaQueryWrapper<HostIdentityDO> buildQueryWrapper(HostIdentityQueryRequest request) {
return hostIdentityDAO.wrapper()
.eq(HostIdentityDO::getId, request.getId())
.eq(HostIdentityDO::getName, request.getName())
.eq(HostIdentityDO::getUsername, request.getUsername())
.eq(HostIdentityDO::getPassword, request.getPassword())
.eq(HostIdentityDO::getKeyId, request.getKeyId());
}
}

View File

@@ -0,0 +1,212 @@
package com.orion.ops.module.asset.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.collect.Lists;
import com.orion.office.excel.writer.exporting.ExcelExport;
import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.FileNames;
import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.module.asset.entity.vo.*;
import com.orion.ops.module.asset.entity.request.host.*;
import com.orion.ops.module.asset.entity.export.*;
import com.orion.ops.module.asset.convert.*;
import com.orion.ops.module.asset.entity.domain.HostKeyDO;
import com.orion.ops.module.asset.dao.HostKeyDAO;
import com.orion.ops.module.asset.service.HostKeyService;
import com.orion.web.servlet.web.Servlets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
/**
* 主机秘钥 服务实现类
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Slf4j
@Service
public class HostKeyServiceImpl implements HostKeyService {
@Resource
private HostKeyDAO hostKeyDAO;
@Override
public Long createHostKey(HostKeyCreateRequest request) {
log.info("HostKeyService-createHostKey request: {}", JSON.toJSONString(request));
// 转换
HostKeyDO record = HostKeyConvert.MAPPER.to(request);
// 查询数据是否冲突
this.checkHostKeyPresent(record);
// 插入
int effect = hostKeyDAO.insert(record);
log.info("HostKeyService-createHostKey effect: {}", effect);
return record.getId();
}
@Override
public Integer updateHostKeyById(HostKeyUpdateRequest request) {
log.info("HostKeyService-updateHostKeyById request: {}", JSON.toJSONString(request));
// 查询
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
HostKeyDO record = hostKeyDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
HostKeyDO updateRecord = HostKeyConvert.MAPPER.to(request);
// 查询数据是否冲突
this.checkHostKeyPresent(updateRecord);
// 更新
int effect = hostKeyDAO.updateById(updateRecord);
log.info("HostKeyService-updateHostKeyById effect: {}", effect);
return effect;
}
@Override
public Integer updateHostKey(HostKeyQueryRequest query, HostKeyUpdateRequest update) {
log.info("HostKeyService.updateHostKey query: {}, update: {}", JSON.toJSONString(query), JSON.toJSONString(update));
// 条件
LambdaQueryWrapper<HostKeyDO> wrapper = this.buildQueryWrapper(query);
// 转换
HostKeyDO updateRecord = HostKeyConvert.MAPPER.to(update);
// 更新
int effect = hostKeyDAO.update(updateRecord, wrapper);
log.info("HostKeyService.updateHostKey effect: {}", effect);
return effect;
}
@Override
public HostKeyVO getHostKeyById(Long id) {
// 查询
HostKeyDO record = hostKeyDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
return HostKeyConvert.MAPPER.to(record);
}
@Override
public List<HostKeyVO> getHostKeyByIdList(List<Long> idList) {
// 查询
List<HostKeyDO> records = hostKeyDAO.selectBatchIds(idList);
if (records.isEmpty()) {
return Lists.empty();
}
// 转换
return HostKeyConvert.MAPPER.to(records);
}
@Override
public List<HostKeyVO> getHostKeyList(HostKeyQueryRequest request) {
// 条件
LambdaQueryWrapper<HostKeyDO> wrapper = this.buildQueryWrapper(request);
// 查询
return hostKeyDAO.of(wrapper).list(HostKeyConvert.MAPPER::to);
}
@Override
public Long getHostKeyCount(HostKeyQueryRequest request) {
// 条件
LambdaQueryWrapper<HostKeyDO> wrapper = this.buildQueryWrapper(request);
// 查询
return hostKeyDAO.selectCount(wrapper);
}
@Override
public DataGrid<HostKeyVO> getHostKeyPage(HostKeyQueryRequest request) {
// 条件
LambdaQueryWrapper<HostKeyDO> wrapper = this.buildQueryWrapper(request);
// 查询
return hostKeyDAO.of(wrapper)
.page(request)
.dataGrid(HostKeyConvert.MAPPER::to);
}
@Override
public Integer deleteHostKeyById(Long id) {
log.info("HostKeyService-deleteHostKeyById id: {}", id);
int effect = hostKeyDAO.deleteById(id);
log.info("HostKeyService-deleteHostKeyById effect: {}", effect);
return effect;
}
@Override
public Integer batchDeleteHostKeyByIdList(List<Long> idList) {
log.info("HostKeyService-batchDeleteHostKeyByIdList idList: {}", idList);
int effect = hostKeyDAO.deleteBatchIds(idList);
log.info("HostKeyService-batchDeleteHostKeyByIdList effect: {}", effect);
return effect;
}
@Override
public Integer deleteHostKey(HostKeyQueryRequest request) {
log.info("HostKeyService.deleteHostKey request: {}", JSON.toJSONString(request));
// 条件
LambdaQueryWrapper<HostKeyDO> wrapper = this.buildQueryWrapper(request);
// 删除
int effect = hostKeyDAO.delete(wrapper);
log.info("HostKeyService.deleteHostKey effect: {}", effect);
return effect;
}
@Override
public void exportHostKey(HostKeyQueryRequest request, HttpServletResponse response) throws IOException {
log.info("HostKeyService.exportHostKey request: {}", JSON.toJSONString(request));
// 条件
LambdaQueryWrapper<HostKeyDO> wrapper = this.buildQueryWrapper(request);
// 查询
List<HostKeyExport> rows = hostKeyDAO.of(wrapper).list(HostKeyConvert.MAPPER::toExport);
log.info("HostKeyService.exportHostKey size: {}", rows.size());
// 导出
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelExport.create(HostKeyExport.class)
.addRows(rows)
.write(out)
.close();
// 传输
Servlets.transfer(response, out.toByteArray(), FileNames.exportName(HostKeyExport.TITLE));
}
/**
* 检测对象是否存在
*
* @param domain domain
*/
private void checkHostKeyPresent(HostKeyDO domain) {
// 构造条件
LambdaQueryWrapper<HostKeyDO> wrapper = hostKeyDAO.wrapper()
// 更新时忽略当前记录
.ne(HostKeyDO::getId, domain.getId())
// 用其他字段做重复校验
.eq(HostKeyDO::getName, domain.getName())
.eq(HostKeyDO::getPublicKey, domain.getPublicKey())
.eq(HostKeyDO::getPrivateKey, domain.getPrivateKey())
.eq(HostKeyDO::getPassword, domain.getPassword());
// 检查是否存在
boolean present = hostKeyDAO.of(wrapper).present();
Valid.isFalse(present, ErrorMessage.DATA_PRESENT);
}
/**
* 构建查询 wrapper
*
* @param request request
* @return wrapper
*/
private LambdaQueryWrapper<HostKeyDO> buildQueryWrapper(HostKeyQueryRequest request) {
return hostKeyDAO.wrapper()
.eq(HostKeyDO::getId, request.getId())
.eq(HostKeyDO::getName, request.getName())
.eq(HostKeyDO::getPublicKey, request.getPublicKey())
.eq(HostKeyDO::getPrivateKey, request.getPrivateKey())
.eq(HostKeyDO::getPassword, request.getPassword());
}
}

View File

@@ -0,0 +1,24 @@
<?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.orion.ops.module.asset.dao.HostIdentityDAO">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.orion.ops.module.asset.entity.domain.HostIdentityDO">
<id column="id" property="id"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="creator" property="creator"/>
<result column="updater" property="updater"/>
<result column="deleted" property="deleted"/>
<result column="name" property="name"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="key_id" property="keyId"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, name, username, password, key_id, create_time, update_time, creator, updater, deleted
</sql>
</mapper>

View File

@@ -0,0 +1,24 @@
<?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.orion.ops.module.asset.dao.HostKeyDAO">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.orion.ops.module.asset.entity.domain.HostKeyDO">
<id column="id" property="id"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="creator" property="creator"/>
<result column="updater" property="updater"/>
<result column="deleted" property="deleted"/>
<result column="name" property="name"/>
<result column="public_key" property="publicKey"/>
<result column="private_key" property="privateKey"/>
<result column="password" property="password"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, name, public_key, private_key, password, create_time, update_time, creator, updater, deleted
</sql>
</mapper>

View File

@@ -0,0 +1,119 @@
import axios from 'axios';
import qs from 'query-string';
import { DataGrid, Pagination } from '@/types/global';
/**
* 主机身份创建请求
*/
export interface HostIdentityCreateRequest {
name?: string;
username?: string;
password?: string;
keyId?: number;
}
/**
* 主机身份更新请求
*/
export interface HostIdentityUpdateRequest extends HostIdentityCreateRequest {
id: number;
}
/**
* 主机身份查询请求
*/
export interface HostIdentityQueryRequest extends Pagination {
id?: number;
name?: string;
username?: string;
password?: string;
keyId?: number;
}
/**
* 主机身份查询响应
*/
export interface HostIdentityQueryResponse {
id?: number;
name?: string;
username?: string;
password?: string;
keyId?: number;
createTime: number;
updateTime: number;
creator: string;
updater: string;
}
/**
* 创建主机身份
*/
export function createHostIdentity(request: HostIdentityCreateRequest) {
return axios.post('/asset/host-identity/create', request);
}
/**
* 通过 id 更新主机身份
*/
export function updateHostIdentity(request: HostIdentityUpdateRequest) {
return axios.put('/asset/host-identity/update', request);
}
/**
* 通过 id 查询主机身份
*/
export function getHostIdentity(id: number) {
return axios.get<HostIdentityQueryResponse>('/asset/host-identity/get', { params: { id } });
}
/**
* 通过 id 批量查询主机身份
*/
export function getHostIdentityList(idList: Array<number>) {
return axios.get<HostIdentityQueryResponse[]>('/asset/host-identity/list', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}
/**
* 查询主机身份
*/
export function getHostIdentityListAll(request: HostIdentityQueryRequest) {
return axios.post<Array<HostIdentityQueryResponse>>('/asset/host-identity/list-all', request);
}
/**
* 分页查询主机身份
*/
export function getHostIdentityPage(request: HostIdentityQueryRequest) {
return axios.post<DataGrid<HostIdentityQueryResponse>>('/asset/host-identity/query', request);
}
/**
* 通过 id 删除主机身份
*/
export function deleteHostIdentity(id: number) {
return axios.delete('/asset/host-identity/delete', { params: { id } });
}
/**
* 通过 id 批量删除主机身份
*/
export function batchDeleteHostIdentity(idList: Array<number>) {
return axios.delete('/asset/host-identity/delete-batch', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}
/**
* 导出主机身份
*/
export function exportHostIdentity(request: HostIdentityQueryRequest) {
return axios.post('/asset/host-identity/export', request);
}

View File

@@ -0,0 +1,119 @@
import axios from 'axios';
import qs from 'query-string';
import { DataGrid, Pagination } from '@/types/global';
/**
* 主机秘钥创建请求
*/
export interface HostKeyCreateRequest {
name?: string;
publicKey?: string;
privateKey?: string;
password?: string;
}
/**
* 主机秘钥更新请求
*/
export interface HostKeyUpdateRequest extends HostKeyCreateRequest {
id: number;
}
/**
* 主机秘钥查询请求
*/
export interface HostKeyQueryRequest extends Pagination {
id?: number;
name?: string;
publicKey?: string;
privateKey?: string;
password?: string;
}
/**
* 主机秘钥查询响应
*/
export interface HostKeyQueryResponse {
id?: number;
name?: string;
publicKey?: string;
privateKey?: string;
password?: string;
createTime: number;
updateTime: number;
creator: string;
updater: string;
}
/**
* 创建主机秘钥
*/
export function createHostKey(request: HostKeyCreateRequest) {
return axios.post('/asset/host-key/create', request);
}
/**
* 通过 id 更新主机秘钥
*/
export function updateHostKey(request: HostKeyUpdateRequest) {
return axios.put('/asset/host-key/update', request);
}
/**
* 通过 id 查询主机秘钥
*/
export function getHostKey(id: number) {
return axios.get<HostKeyQueryResponse>('/asset/host-key/get', { params: { id } });
}
/**
* 通过 id 批量查询主机秘钥
*/
export function getHostKeyList(idList: Array<number>) {
return axios.get<HostKeyQueryResponse[]>('/asset/host-key/list', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}
/**
* 查询主机秘钥
*/
export function getHostKeyListAll(request: HostKeyQueryRequest) {
return axios.post<Array<HostKeyQueryResponse>>('/asset/host-key/list-all', request);
}
/**
* 分页查询主机秘钥
*/
export function getHostKeyPage(request: HostKeyQueryRequest) {
return axios.post<DataGrid<HostKeyQueryResponse>>('/asset/host-key/query', request);
}
/**
* 通过 id 删除主机秘钥
*/
export function deleteHostKey(id: number) {
return axios.delete('/asset/host-key/delete', { params: { id } });
}
/**
* 通过 id 批量删除主机秘钥
*/
export function batchDeleteHostKey(idList: Array<number>) {
return axios.delete('/asset/host-key/delete-batch', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}
/**
* 导出主机秘钥
*/
export function exportHostKey(request: HostKeyQueryRequest) {
return axios.post('/asset/host-key/export', request);
}

View File

@@ -10,6 +10,14 @@ const ASSET: AppRouteRecordRaw = {
name: 'assetHost',
path: '/asset/host',
component: () => import('@/views/asset/host/index.vue'),
}, {
name: 'assetHostKey',
path: '/asset/host-key',
component: () => import('@/views/asset/host-key/index.vue'),
}, {
name: 'assetHostIdentity',
path: '/asset/host-identity',
component: () => import('@/views/asset/host-identity/index.vue'),
},
],
};

View File

@@ -0,0 +1,151 @@
<template>
<a-modal v-model:visible="visible"
body-class="modal-form"
title-align="start"
:title="title"
:top="80"
:align-center="false"
:draggable="true"
:mask-closable="false"
:unmount-on-close="true"
:ok-button-props="{ disabled: loading }"
:cancel-button-props="{ disabled: loading }"
:on-before-ok="handlerOk"
@close="handleClose">
<a-spin :loading="loading">
<a-form :model="formModel"
ref="formRef"
label-align="right"
:style="{ width: '460px' }"
:label-col-props="{ span: 6 }"
:wrapper-col-props="{ span: 18 }"
:rules="formRules">
<!-- 名称 -->
<a-form-item field="name" label="名称">
<a-input v-model="formModel.name" placeholder="请输入名称" />
</a-form-item>
<!-- 用户名 -->
<a-form-item field="username" label="用户名">
<a-input v-model="formModel.username" placeholder="请输入用户名" />
</a-form-item>
<!-- 用户密码 -->
<a-form-item field="password" label="用户密码">
<a-input v-model="formModel.password" placeholder="请输入用户密码" />
</a-form-item>
<!-- 秘钥id -->
<a-form-item field="keyId" label="秘钥id">
<a-input-number v-model="formModel.keyId" placeholder="请输入秘钥id" />
</a-form-item>
</a-form>
</a-spin>
</a-modal>
</template>
<script lang="ts">
export default {
name: 'asset-host-identity-form-modal'
};
</script>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import useLoading from '@/hooks/loading';
import useVisible from '@/hooks/visible';
import formRules from '../types/form.rules';
import { createHostIdentity, updateHostIdentity } from '@/api/asset/host-identity';
import { Message } from '@arco-design/web-vue';
import { } from '../types/enum.types';
import { } from '../types/const';
import { toOptions } from '@/utils/enum';
const { visible, setVisible } = useVisible();
const { loading, setLoading } = useLoading();
const title = ref<string>();
const isAddHandle = ref<boolean>(true);
const defaultForm = () => {
return {
id: undefined,
name: undefined,
username: undefined,
password: undefined,
keyId: undefined,
};
};
const formRef = ref<any>();
const formModel = reactive<Record<string, any>>(defaultForm());
const emits = defineEmits(['added', 'updated']);
// 打开新增
const openAdd = () => {
title.value = '添加主机身份';
isAddHandle.value = true;
renderForm({ ...defaultForm() });
setVisible(true);
};
// 打开修改
const openUpdate = (record: any) => {
title.value = '修改主机身份';
isAddHandle.value = false;
renderForm({ ...defaultForm(), ...record });
setVisible(true);
};
// 渲染表单
const renderForm = (record: any) => {
Object.keys(formModel).forEach(k => {
formModel[k] = record[k];
});
};
defineExpose({ openAdd, openUpdate });
// 确定
const handlerOk = async () => {
setLoading(true);
try {
// 验证参数
const error = await formRef.value.validate();
if (error) {
return false;
}
if (isAddHandle.value) {
// 新增
await createHostIdentity(formModel as any);
Message.success('创建成功');
emits('added');
} else {
// 修改
await updateHostIdentity(formModel as any);
Message.success('修改成功');
emits('updated');
}
// 清空
handlerClear();
} catch (e) {
return false;
} finally {
setLoading(false);
}
};
// 关闭
const handleClose = () => {
handlerClear();
};
// 清空
const handlerClear = () => {
setLoading(false);
setVisible(false);
};
</script>
<style lang="less" scoped>
</style>

View File

@@ -0,0 +1,209 @@
<template>
<!-- 搜索 -->
<a-card class="general-card table-search-card">
<a-query-header :model="formModel"
label-align="left"
@submit="fetchTableData"
@reset="fetchTableData">
<!-- id -->
<a-form-item field="id" label="id" label-col-flex="50px">
<a-input-number v-model="formModel.id" placeholder="请输入id" allow-clear/>
</a-form-item>
<!-- 名称 -->
<a-form-item field="name" label="名称" label-col-flex="50px">
<a-input v-model="formModel.name" placeholder="请输入名称" allow-clear/>
</a-form-item>
<!-- 用户名 -->
<a-form-item field="username" label="用户名" label-col-flex="50px">
<a-input v-model="formModel.username" placeholder="请输入用户名" allow-clear/>
</a-form-item>
<!-- 用户密码 -->
<a-form-item field="password" label="用户密码" label-col-flex="50px">
<a-input v-model="formModel.password" placeholder="请输入用户密码" allow-clear/>
</a-form-item>
<!-- 秘钥id -->
<a-form-item field="keyId" label="秘钥id" label-col-flex="50px">
<a-input-number v-model="formModel.keyId" placeholder="请输入秘钥id" allow-clear/>
</a-form-item>
</a-query-header>
</a-card>
<!-- 表格 -->
<a-card class="general-card table-card">
<template #title>
<!-- 左侧标题 -->
<div class="table-title">
主机身份列表
</div>
<!-- 右侧按钮 -->
<div class="table-bar-handle">
<a-space>
<!-- 新增 -->
<a-button type="primary"
v-permission="['asset:host-identity:create']"
@click="emits('openAdd')">
新增
<template #icon>
<icon-plus />
</template>
</a-button>
<!-- 删除 -->
<a-popconfirm position="br"
type="warning"
:content="`确认删除选中的${selectedKeys.length}条记录吗?`"
@ok="deleteSelectRows">
<a-button v-permission="['asset:host-identity:delete']"
type="secondary"
status="danger"
:disabled="selectedKeys.length === 0">
删除
<template #icon>
<icon-delete />
</template>
</a-button>
</a-popconfirm>
</a-space>
</div>
</template>
<!-- table -->
<a-table row-key="id"
class="table-wrapper-8"
ref="tableRef"
label-align="left"
:loading="loading"
:columns="columns"
v-model:selectedKeys="selectedKeys"
:row-selection="rowSelection"
:data="tableRenderData"
:pagination="pagination"
@page-change="(page) => fetchTableData(page, pagination.pageSize)"
@page-size-change="(size) => fetchTableData(pagination.current, size)"
:bordered="false">
<!-- 操作 -->
<template #handle="{ record }">
<div class="table-handle-wrapper">
<!-- 修改 -->
<a-button type="text"
size="mini"
v-permission="['asset:host-identity:update']"
@click="emits('openUpdate', record)">
修改
</a-button>
<!-- 删除 -->
<a-popconfirm content="确认删除这条记录吗?"
position="left"
type="warning"
@ok="deleteRow(record)">
<a-button v-permission="['asset:host-identity:delete']"
type="text"
size="mini"
status="danger">
删除
</a-button>
</a-popconfirm>
</div>
</template>
</a-table>
</a-card>
</template>
<script lang="ts">
export default {
name: 'asset-host-identity-table'
};
</script>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { batchDeleteHostIdentity, deleteHostIdentity, getHostIdentityPage, HostIdentityQueryRequest, HostIdentityQueryResponse } from '@/api/asset/host-identity';
import { Message } from '@arco-design/web-vue';
import useLoading from '@/hooks/loading';
import columns from '../types/table.columns';
import { defaultPagination, defaultRowSelection } from '@/types/table';
import { } from '../types/enum.types';
import { } from '../types/const';
import { toOptions } from '@/utils/enum';
const tableRenderData = ref<HostIdentityQueryResponse[]>();
const { loading, setLoading } = useLoading();
const emits = defineEmits(['openAdd', 'openUpdate']);
const pagination = reactive(defaultPagination());
const selectedKeys = ref<number[]>([]);
const rowSelection = reactive(defaultRowSelection());
const formModel = reactive<HostIdentityQueryRequest>({
id: undefined,
name: undefined,
username: undefined,
password: undefined,
keyId: undefined,
});
// 删除选中行
const deleteSelectRows = async () => {
try {
setLoading(true);
// 调用删除接口
await batchDeleteHostIdentity(selectedKeys.value);
Message.success(`成功删除${selectedKeys.value.length}条数据`);
selectedKeys.value = [];
// 重新加载数据
await fetchTableData();
} finally {
setLoading(false);
}
};
// 删除当前行
const deleteRow = async ({ id }: { id: number }) => {
try {
setLoading(true);
// 调用删除接口
await deleteHostIdentity(id);
Message.success('删除成功');
// 重新加载数据
await fetchTableData();
} finally {
setLoading(false);
}
};
// 添加后回调
const addedCallback = () => {
fetchTableData();
};
// 更新后回调
const updatedCallback = () => {
fetchTableData();
};
defineExpose({
addedCallback, updatedCallback
});
// 加载数据
const doFetchTableData = async (request: HostIdentityQueryRequest) => {
try {
setLoading(true);
const { data } = await getHostIdentityPage(request);
tableRenderData.value = data.rows;
pagination.total = data.total;
pagination.current = request.page;
pagination.pageSize = request.limit;
} finally {
setLoading(false);
}
};
// 切换页码
const fetchTableData = (page = 1, limit = pagination.pageSize, form = formModel) => {
doFetchTableData({ page, limit, ...form });
};
fetchTableData();
</script>
<style lang="less" scoped>
</style>

View File

@@ -0,0 +1,32 @@
<template>
<div class="layout-container">
<!-- 表格 -->
<host-identity-table ref="table"
@openAdd="() => modal.openAdd()"
@openUpdate="(e) => modal.openUpdate(e)" />
<!-- 添加修改模态框 -->
<host-identity-form-modal ref="modal"
@added="() => table.addedCallback()"
@updated="() => table.updatedCallback()" />
</div>
</template>
<script lang="ts">
export default {
name: 'asset-host-identity'
};
</script>
<script lang="ts" setup>
import HostIdentityTable from './components/host-identity-table.vue';
import HostIdentityFormModal from './components/host-identity-form-modal.vue';
import { ref } from 'vue';
const table = ref();
const modal = ref();
</script>
<style lang="less" scoped>
</style>

View File

@@ -0,0 +1,37 @@
import { FieldRule } from '@arco-design/web-vue';
export const name = [{
required: true,
message: '请输入名称'
}, {
maxLength: 64,
message: '名称长度不能大于64位'
}] as FieldRule[];
export const username = [{
required: true,
message: '请输入用户名'
}, {
maxLength: 128,
message: '用户名长度不能大于128位'
}] as FieldRule[];
export const password = [{
required: true,
message: '请输入用户密码'
}, {
maxLength: 512,
message: '用户密码长度不能大于512位'
}] as FieldRule[];
export const keyId = [{
required: true,
message: '请输入秘钥id'
}] as FieldRule[];
export default {
name,
username,
password,
keyId,
} as Record<string, FieldRule | FieldRule[]>;

View File

@@ -0,0 +1,73 @@
import { TableColumnData } from '@arco-design/web-vue/es/table/interface';
import { dateFormat } from '@/utils';
const columns = [
{
title: 'id',
dataIndex: 'id',
slotName: 'id',
width: 70,
align: 'left',
fixed: 'left',
}, {
title: '名称',
dataIndex: 'name',
slotName: 'name',
align: 'center',
ellipsis: true,
tooltip: true,
}, {
title: '用户名',
dataIndex: 'username',
slotName: 'username',
align: 'center',
ellipsis: true,
tooltip: true,
}, {
title: '用户密码',
dataIndex: 'password',
slotName: 'password',
align: 'center',
ellipsis: true,
tooltip: true,
}, {
title: '秘钥id',
dataIndex: 'keyId',
slotName: 'keyId',
align: 'center',
}, {
title: '创建时间',
dataIndex: 'createTime',
slotName: 'createTime',
align: 'center',
width: 180,
render: ({ record }) => {
return dateFormat(new Date(record.createTime));
},
}, {
title: '修改时间',
dataIndex: 'updateTime',
slotName: 'updateTime',
align: 'center',
width: 180,
render: ({ record }) => {
return dateFormat(new Date(record.updateTime));
},
}, {
title: '创建人',
dataIndex: 'creator',
slotName: 'creator',
}, {
title: '修改人',
dataIndex: 'updater',
slotName: 'updater',
}, {
title: '操作',
slotName: 'handle',
width: 130,
align: 'center',
fixed: 'right',
},
] as TableColumnData[];
export default columns;

View File

@@ -0,0 +1,151 @@
<template>
<a-modal v-model:visible="visible"
body-class="modal-form"
title-align="start"
:title="title"
:top="80"
:align-center="false"
:draggable="true"
:mask-closable="false"
:unmount-on-close="true"
:ok-button-props="{ disabled: loading }"
:cancel-button-props="{ disabled: loading }"
:on-before-ok="handlerOk"
@close="handleClose">
<a-spin :loading="loading">
<a-form :model="formModel"
ref="formRef"
label-align="right"
:style="{ width: '460px' }"
:label-col-props="{ span: 6 }"
:wrapper-col-props="{ span: 18 }"
:rules="formRules">
<!-- 名称 -->
<a-form-item field="name" label="名称">
<a-input v-model="formModel.name" placeholder="请输入名称" />
</a-form-item>
<!-- 公钥文本 -->
<a-form-item field="publicKey" label="公钥文本">
<a-input v-model="formModel.publicKey" placeholder="请输入公钥文本" />
</a-form-item>
<!-- 私钥文本 -->
<a-form-item field="privateKey" label="私钥文本">
<a-input v-model="formModel.privateKey" placeholder="请输入私钥文本" />
</a-form-item>
<!-- 密码 -->
<a-form-item field="password" label="密码">
<a-input v-model="formModel.password" placeholder="请输入密码" />
</a-form-item>
</a-form>
</a-spin>
</a-modal>
</template>
<script lang="ts">
export default {
name: 'asset-host-key-form-modal'
};
</script>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import useLoading from '@/hooks/loading';
import useVisible from '@/hooks/visible';
import formRules from '../types/form.rules';
import { createHostKey, updateHostKey } from '@/api/asset/host-key';
import { Message } from '@arco-design/web-vue';
import { } from '../types/enum.types';
import { } from '../types/const';
import { toOptions } from '@/utils/enum';
const { visible, setVisible } = useVisible();
const { loading, setLoading } = useLoading();
const title = ref<string>();
const isAddHandle = ref<boolean>(true);
const defaultForm = () => {
return {
id: undefined,
name: undefined,
publicKey: undefined,
privateKey: undefined,
password: undefined,
};
};
const formRef = ref<any>();
const formModel = reactive<Record<string, any>>(defaultForm());
const emits = defineEmits(['added', 'updated']);
// 打开新增
const openAdd = () => {
title.value = '添加主机秘钥';
isAddHandle.value = true;
renderForm({ ...defaultForm() });
setVisible(true);
};
// 打开修改
const openUpdate = (record: any) => {
title.value = '修改主机秘钥';
isAddHandle.value = false;
renderForm({ ...defaultForm(), ...record });
setVisible(true);
};
// 渲染表单
const renderForm = (record: any) => {
Object.keys(formModel).forEach(k => {
formModel[k] = record[k];
});
};
defineExpose({ openAdd, openUpdate });
// 确定
const handlerOk = async () => {
setLoading(true);
try {
// 验证参数
const error = await formRef.value.validate();
if (error) {
return false;
}
if (isAddHandle.value) {
// 新增
await createHostKey(formModel as any);
Message.success('创建成功');
emits('added');
} else {
// 修改
await updateHostKey(formModel as any);
Message.success('修改成功');
emits('updated');
}
// 清空
handlerClear();
} catch (e) {
return false;
} finally {
setLoading(false);
}
};
// 关闭
const handleClose = () => {
handlerClear();
};
// 清空
const handlerClear = () => {
setLoading(false);
setVisible(false);
};
</script>
<style lang="less" scoped>
</style>

View File

@@ -0,0 +1,209 @@
<template>
<!-- 搜索 -->
<a-card class="general-card table-search-card">
<a-query-header :model="formModel"
label-align="left"
@submit="fetchTableData"
@reset="fetchTableData">
<!-- id -->
<a-form-item field="id" label="id" label-col-flex="50px">
<a-input-number v-model="formModel.id" placeholder="请输入id" allow-clear/>
</a-form-item>
<!-- 名称 -->
<a-form-item field="name" label="名称" label-col-flex="50px">
<a-input v-model="formModel.name" placeholder="请输入名称" allow-clear/>
</a-form-item>
<!-- 公钥文本 -->
<a-form-item field="publicKey" label="公钥文本" label-col-flex="50px">
<a-input v-model="formModel.publicKey" placeholder="请输入公钥文本" allow-clear/>
</a-form-item>
<!-- 私钥文本 -->
<a-form-item field="privateKey" label="私钥文本" label-col-flex="50px">
<a-input v-model="formModel.privateKey" placeholder="请输入私钥文本" allow-clear/>
</a-form-item>
<!-- 密码 -->
<a-form-item field="password" label="密码" label-col-flex="50px">
<a-input v-model="formModel.password" placeholder="请输入密码" allow-clear/>
</a-form-item>
</a-query-header>
</a-card>
<!-- 表格 -->
<a-card class="general-card table-card">
<template #title>
<!-- 左侧标题 -->
<div class="table-title">
主机秘钥列表
</div>
<!-- 右侧按钮 -->
<div class="table-bar-handle">
<a-space>
<!-- 新增 -->
<a-button type="primary"
v-permission="['asset:host-key:create']"
@click="emits('openAdd')">
新增
<template #icon>
<icon-plus />
</template>
</a-button>
<!-- 删除 -->
<a-popconfirm position="br"
type="warning"
:content="`确认删除选中的${selectedKeys.length}条记录吗?`"
@ok="deleteSelectRows">
<a-button v-permission="['asset:host-key:delete']"
type="secondary"
status="danger"
:disabled="selectedKeys.length === 0">
删除
<template #icon>
<icon-delete />
</template>
</a-button>
</a-popconfirm>
</a-space>
</div>
</template>
<!-- table -->
<a-table row-key="id"
class="table-wrapper-8"
ref="tableRef"
label-align="left"
:loading="loading"
:columns="columns"
v-model:selectedKeys="selectedKeys"
:row-selection="rowSelection"
:data="tableRenderData"
:pagination="pagination"
@page-change="(page) => fetchTableData(page, pagination.pageSize)"
@page-size-change="(size) => fetchTableData(pagination.current, size)"
:bordered="false">
<!-- 操作 -->
<template #handle="{ record }">
<div class="table-handle-wrapper">
<!-- 修改 -->
<a-button type="text"
size="mini"
v-permission="['asset:host-key:update']"
@click="emits('openUpdate', record)">
修改
</a-button>
<!-- 删除 -->
<a-popconfirm content="确认删除这条记录吗?"
position="left"
type="warning"
@ok="deleteRow(record)">
<a-button v-permission="['asset:host-key:delete']"
type="text"
size="mini"
status="danger">
删除
</a-button>
</a-popconfirm>
</div>
</template>
</a-table>
</a-card>
</template>
<script lang="ts">
export default {
name: 'asset-host-key-table'
};
</script>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { batchDeleteHostKey, deleteHostKey, getHostKeyPage, HostKeyQueryRequest, HostKeyQueryResponse } from '@/api/asset/host-key';
import { Message } from '@arco-design/web-vue';
import useLoading from '@/hooks/loading';
import columns from '../types/table.columns';
import { defaultPagination, defaultRowSelection } from '@/types/table';
import { } from '../types/enum.types';
import { } from '../types/const';
import { toOptions } from '@/utils/enum';
const tableRenderData = ref<HostKeyQueryResponse[]>();
const { loading, setLoading } = useLoading();
const emits = defineEmits(['openAdd', 'openUpdate']);
const pagination = reactive(defaultPagination());
const selectedKeys = ref<number[]>([]);
const rowSelection = reactive(defaultRowSelection());
const formModel = reactive<HostKeyQueryRequest>({
id: undefined,
name: undefined,
publicKey: undefined,
privateKey: undefined,
password: undefined,
});
// 删除选中行
const deleteSelectRows = async () => {
try {
setLoading(true);
// 调用删除接口
await batchDeleteHostKey(selectedKeys.value);
Message.success(`成功删除${selectedKeys.value.length}条数据`);
selectedKeys.value = [];
// 重新加载数据
await fetchTableData();
} finally {
setLoading(false);
}
};
// 删除当前行
const deleteRow = async ({ id }: { id: number }) => {
try {
setLoading(true);
// 调用删除接口
await deleteHostKey(id);
Message.success('删除成功');
// 重新加载数据
await fetchTableData();
} finally {
setLoading(false);
}
};
// 添加后回调
const addedCallback = () => {
fetchTableData();
};
// 更新后回调
const updatedCallback = () => {
fetchTableData();
};
defineExpose({
addedCallback, updatedCallback
});
// 加载数据
const doFetchTableData = async (request: HostKeyQueryRequest) => {
try {
setLoading(true);
const { data } = await getHostKeyPage(request);
tableRenderData.value = data.rows;
pagination.total = data.total;
pagination.current = request.page;
pagination.pageSize = request.limit;
} finally {
setLoading(false);
}
};
// 切换页码
const fetchTableData = (page = 1, limit = pagination.pageSize, form = formModel) => {
doFetchTableData({ page, limit, ...form });
};
fetchTableData();
</script>
<style lang="less" scoped>
</style>

View File

@@ -0,0 +1,32 @@
<template>
<div class="layout-container">
<!-- 表格 -->
<host-key-table ref="table"
@openAdd="() => modal.openAdd()"
@openUpdate="(e) => modal.openUpdate(e)" />
<!-- 添加修改模态框 -->
<host-key-form-modal ref="modal"
@added="() => table.addedCallback()"
@updated="() => table.updatedCallback()" />
</div>
</template>
<script lang="ts">
export default {
name: 'asset-host-key'
};
</script>
<script lang="ts" setup>
import HostKeyTable from './components/host-key-table.vue';
import HostKeyFormModal from './components/host-key-form-modal.vue';
import { ref } from 'vue';
const table = ref();
const modal = ref();
</script>
<style lang="less" scoped>
</style>

View File

@@ -0,0 +1,40 @@
import { FieldRule } from '@arco-design/web-vue';
export const name = [{
required: true,
message: '请输入名称'
}, {
maxLength: 64,
message: '名称长度不能大于64位'
}] as FieldRule[];
export const publicKey = [{
required: true,
message: '请输入公钥文本'
}, {
maxLength: 65535,
message: '公钥文本长度不能大于65535位'
}] as FieldRule[];
export const privateKey = [{
required: true,
message: '请输入私钥文本'
}, {
maxLength: 65535,
message: '私钥文本长度不能大于65535位'
}] as FieldRule[];
export const password = [{
required: true,
message: '请输入密码'
}, {
maxLength: 512,
message: '密码长度不能大于512位'
}] as FieldRule[];
export default {
name,
publicKey,
privateKey,
password,
} as Record<string, FieldRule | FieldRule[]>;

View File

@@ -0,0 +1,75 @@
import { TableColumnData } from '@arco-design/web-vue/es/table/interface';
import { dateFormat } from '@/utils';
const columns = [
{
title: 'id',
dataIndex: 'id',
slotName: 'id',
width: 70,
align: 'left',
fixed: 'left',
}, {
title: '名称',
dataIndex: 'name',
slotName: 'name',
align: 'center',
ellipsis: true,
tooltip: true,
}, {
title: '公钥文本',
dataIndex: 'publicKey',
slotName: 'publicKey',
align: 'center',
ellipsis: true,
tooltip: true,
}, {
title: '私钥文本',
dataIndex: 'privateKey',
slotName: 'privateKey',
align: 'center',
ellipsis: true,
tooltip: true,
}, {
title: '密码',
dataIndex: 'password',
slotName: 'password',
align: 'center',
ellipsis: true,
tooltip: true,
}, {
title: '创建时间',
dataIndex: 'createTime',
slotName: 'createTime',
align: 'center',
width: 180,
render: ({ record }) => {
return dateFormat(new Date(record.createTime));
},
}, {
title: '修改时间',
dataIndex: 'updateTime',
slotName: 'updateTime',
align: 'center',
width: 180,
render: ({ record }) => {
return dateFormat(new Date(record.updateTime));
},
}, {
title: '创建人',
dataIndex: 'creator',
slotName: 'creator',
}, {
title: '修改人',
dataIndex: 'updater',
slotName: 'updater',
}, {
title: '操作',
slotName: 'handle',
width: 130,
align: 'center',
fixed: 'right',
},
] as TableColumnData[];
export default columns;