生成主机身份代码.

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>