添加主机身份页面.
This commit is contained in:
@@ -31,24 +31,10 @@ Authorization: {{token}}
|
||||
|
||||
|
||||
### 通过 id 批量查询主机身份
|
||||
GET {{baseUrl}}/asset/host-identity/list?idList=1,2,3
|
||||
GET {{baseUrl}}/asset/host-identity/list
|
||||
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
|
||||
@@ -69,24 +55,3 @@ Authorization: {{token}}
|
||||
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": ""
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
|
||||
@@ -5,11 +5,11 @@ 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 com.orion.ops.module.asset.entity.request.host.HostIdentityCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostIdentityVO;
|
||||
import com.orion.ops.module.asset.service.HostIdentityService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -19,8 +19,6 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -67,19 +65,11 @@ public class HostIdentityController {
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "通过 id 批量查询主机身份")
|
||||
@Operation(summary = "查询主机身份")
|
||||
@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);
|
||||
public List<HostIdentityVO> getHostIdentityList() {
|
||||
return hostIdentityService.getHostIdentityList();
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@@ -98,21 +88,5 @@ public class HostIdentityController {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ GET {{baseUrl}}/asset/host-key/get?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
### 查询主机秘钥
|
||||
POST {{baseUrl}}/asset/host-key/list-all
|
||||
POST {{baseUrl}}/asset/host-key/list
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
@@ -64,10 +64,10 @@ public class HostKeyController {
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/list-all")
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "查询主机秘钥")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-key:query')")
|
||||
public List<HostKeyVO> getHostKeyListAll() {
|
||||
public List<HostKeyVO> getHostKeyList() {
|
||||
return hostKeyService.getHostKeyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
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 com.orion.ops.module.asset.entity.domain.HostIdentityDO;
|
||||
import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostIdentityVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -30,7 +31,9 @@ public interface HostIdentityConvert {
|
||||
|
||||
HostIdentityVO to(HostIdentityDO domain);
|
||||
|
||||
HostIdentityExport toExport(HostIdentityDO domain);
|
||||
HostIdentityVO to(HostIdentityCacheDTO cache);
|
||||
|
||||
HostIdentityCacheDTO toCache(HostIdentityDO domain);
|
||||
|
||||
List<HostIdentityVO> to(List<HostIdentityDO> list);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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.HostDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -15,18 +14,4 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface HostDAO extends IMapper<HostDO> {
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
*
|
||||
* @param entity entity
|
||||
* @return 查询条件
|
||||
*/
|
||||
default LambdaQueryWrapper<HostDO> queryCondition(HostDO entity) {
|
||||
return this.wrapper()
|
||||
.eq(HostDO::getId, entity.getId())
|
||||
.eq(HostDO::getName, entity.getName())
|
||||
.eq(HostDO::getCode, entity.getCode())
|
||||
.eq(HostDO::getAddress, entity.getAddress());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
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;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 主机身份 Mapper 接口
|
||||
@@ -16,18 +16,11 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface HostIdentityDAO extends IMapper<HostIdentityDO> {
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
* 设置 keyId 为 null
|
||||
*
|
||||
* @param entity entity
|
||||
* @return 查询条件
|
||||
* @param keyId keyId
|
||||
* @return effect
|
||||
*/
|
||||
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());
|
||||
}
|
||||
int setKeyWithNull(@Param("keyId") Long keyId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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;
|
||||
@@ -15,19 +14,4 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.orion.ops.module.asset.define;
|
||||
|
||||
import com.orion.lang.define.cache.CacheKeyBuilder;
|
||||
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||
import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO;
|
||||
import com.orion.ops.module.asset.entity.dto.HostKeyCacheDTO;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -22,4 +23,11 @@ public interface HostCacheKeyDefine {
|
||||
.timeout(3, TimeUnit.DAYS)
|
||||
.build();
|
||||
|
||||
CacheKeyDefine HOST_IDENTITY = new CacheKeyBuilder()
|
||||
.key("host:identity:list")
|
||||
.desc("主机身份列表")
|
||||
.type(HostIdentityCacheDTO.class)
|
||||
.timeout(3, TimeUnit.DAYS)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.orion.ops.module.asset.entity.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 主机身份缓存
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/9/21 12:00
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostIdentityCacheDTO", description = "主机身份缓存")
|
||||
public class HostIdentityCacheDTO implements Serializable {
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.orion.ops.module.asset.entity.request.host;
|
||||
|
||||
import com.orion.ops.framework.common.security.UpdatePasswordAction;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -9,7 +10,6 @@ import lombok.NoArgsConstructor;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 主机身份 更新请求对象
|
||||
@@ -23,7 +23,7 @@ import java.io.Serializable;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostIdentityUpdateRequest", description = "主机身份 更新请求对象")
|
||||
public class HostIdentityUpdateRequest implements Serializable {
|
||||
public class HostIdentityUpdateRequest implements UpdatePasswordAction {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "id")
|
||||
@@ -48,4 +48,7 @@ public class HostIdentityUpdateRequest implements Serializable {
|
||||
@Schema(description = "秘钥id")
|
||||
private Long keyId;
|
||||
|
||||
@Schema(description = "是否使用新密码")
|
||||
private Boolean useNewPassword;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.orion.ops.module.asset.entity.request.host;
|
||||
|
||||
import com.orion.ops.framework.common.security.UpdatePasswordAction;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -9,7 +10,6 @@ import lombok.NoArgsConstructor;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 主机秘钥 更新请求对象
|
||||
@@ -23,7 +23,7 @@ import java.io.Serializable;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostKeyUpdateRequest", description = "主机秘钥 更新请求对象")
|
||||
public class HostKeyUpdateRequest implements Serializable {
|
||||
public class HostKeyUpdateRequest implements UpdatePasswordAction {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "id")
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.orion.ops.module.asset.entity.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 主机身份 视图响应对象
|
||||
@@ -31,22 +34,16 @@ public class HostIdentityVO implements Serializable {
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "用户密码")
|
||||
private String password;
|
||||
|
||||
@Schema(description = "秘钥id")
|
||||
private Long keyId;
|
||||
|
||||
@Schema(description = "秘钥名称")
|
||||
private String keyName;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "修改人")
|
||||
private String updater;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
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 com.orion.ops.module.asset.entity.request.host.HostIdentityCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostIdentityVO;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -35,15 +33,6 @@ public interface HostIdentityService {
|
||||
*/
|
||||
Integer updateHostIdentityById(HostIdentityUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 更新主机身份
|
||||
*
|
||||
* @param query query
|
||||
* @param update update
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateHostIdentity(HostIdentityQueryRequest query, HostIdentityUpdateRequest update);
|
||||
|
||||
/**
|
||||
* 通过 id 查询主机身份
|
||||
*
|
||||
@@ -52,29 +41,12 @@ public interface HostIdentityService {
|
||||
*/
|
||||
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);
|
||||
List<HostIdentityVO> getHostIdentityList();
|
||||
|
||||
/**
|
||||
* 分页查询主机身份
|
||||
@@ -92,29 +64,4 @@ public interface HostIdentityService {
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,28 +3,31 @@ 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.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.security.PasswordModifier;
|
||||
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.framework.redis.core.utils.RedisLists;
|
||||
import com.orion.ops.module.asset.convert.HostIdentityConvert;
|
||||
import com.orion.ops.module.asset.dao.HostIdentityDAO;
|
||||
import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
import com.orion.ops.module.asset.define.HostCacheKeyDefine;
|
||||
import com.orion.ops.module.asset.entity.domain.HostIdentityDO;
|
||||
import com.orion.ops.module.asset.entity.domain.HostKeyDO;
|
||||
import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostIdentityVO;
|
||||
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;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 主机身份 服务实现类
|
||||
@@ -40,9 +43,14 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
@Resource
|
||||
private HostIdentityDAO hostIdentityDAO;
|
||||
|
||||
@Resource
|
||||
private HostKeyDAO hostKeyDAO;
|
||||
|
||||
@Override
|
||||
public Long createHostIdentity(HostIdentityCreateRequest request) {
|
||||
log.info("HostIdentityService-createHostIdentity request: {}", JSON.toJSONString(request));
|
||||
// 检查秘钥是否存在
|
||||
this.checkKeyIdPresent(request.getKeyId());
|
||||
// 转换
|
||||
HostIdentityDO record = HostIdentityConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
@@ -50,7 +58,11 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
// 插入
|
||||
int effect = hostIdentityDAO.insert(record);
|
||||
log.info("HostIdentityService-createHostIdentity effect: {}", effect);
|
||||
return record.getId();
|
||||
Long id = record.getId();
|
||||
// 设置缓存
|
||||
RedisLists.pushJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record));
|
||||
RedisLists.setExpire(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,29 +72,26 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
HostIdentityDO record = hostIdentityDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 检查秘钥是否存在
|
||||
this.checkKeyIdPresent(request.getKeyId());
|
||||
// 转换
|
||||
HostIdentityDO updateRecord = HostIdentityConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
this.checkHostIdentityPresent(updateRecord);
|
||||
// 设置密码
|
||||
String newPassword = PasswordModifier.getEncryptNewPassword(request);
|
||||
updateRecord.setPassword(newPassword);
|
||||
// 更新
|
||||
int effect = hostIdentityDAO.updateById(updateRecord);
|
||||
// 设置缓存
|
||||
if (!record.getName().equals(updateRecord.getName())) {
|
||||
RedisLists.removeJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record));
|
||||
RedisLists.pushJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(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) {
|
||||
// 查询
|
||||
@@ -93,30 +102,27 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HostIdentityVO> getHostIdentityByIdList(List<Long> idList) {
|
||||
// 查询
|
||||
List<HostIdentityDO> records = hostIdentityDAO.selectBatchIds(idList);
|
||||
if (records.isEmpty()) {
|
||||
return Lists.empty();
|
||||
public List<HostIdentityVO> getHostIdentityList() {
|
||||
// 查询缓存
|
||||
List<HostIdentityCacheDTO> list = RedisLists.rangeJson(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
if (list.isEmpty()) {
|
||||
// 查询数据库
|
||||
list = hostIdentityDAO.of().list(HostIdentityConvert.MAPPER::toCache);
|
||||
// 添加默认值 防止穿透
|
||||
if (list.isEmpty()) {
|
||||
list.add(HostIdentityCacheDTO.builder()
|
||||
.id(Const.NONE_ID)
|
||||
.build());
|
||||
}
|
||||
// 设置缓存
|
||||
RedisLists.pushAllJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), list);
|
||||
RedisLists.setExpire(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
}
|
||||
// 转换
|
||||
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);
|
||||
// 删除默认值
|
||||
return list.stream()
|
||||
.filter(s -> !s.getId().equals(Const.NONE_ID))
|
||||
.map(HostIdentityConvert.MAPPER::to)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,58 +130,51 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
// 条件
|
||||
LambdaQueryWrapper<HostIdentityDO> wrapper = this.buildQueryWrapper(request);
|
||||
// 查询
|
||||
return hostIdentityDAO.of(wrapper)
|
||||
DataGrid<HostIdentityVO> dataGrid = hostIdentityDAO.of(wrapper)
|
||||
.page(request)
|
||||
.dataGrid(HostIdentityConvert.MAPPER::to);
|
||||
if (dataGrid.isEmpty()) {
|
||||
return dataGrid;
|
||||
}
|
||||
// 设置秘钥名称
|
||||
List<Long> keyIdList = dataGrid.stream()
|
||||
.map(HostIdentityVO::getKeyId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (!keyIdList.isEmpty()) {
|
||||
// 查询秘钥名称
|
||||
Map<Long, String> keyNameMap = hostKeyDAO.selectBatchIds(keyIdList)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(HostKeyDO::getId, HostKeyDO::getName));
|
||||
dataGrid.forEach(s -> {
|
||||
if (s.getKeyId() == null) {
|
||||
return;
|
||||
}
|
||||
s.setKeyName(keyNameMap.get(s.getKeyId()));
|
||||
});
|
||||
}
|
||||
return dataGrid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteHostIdentityById(Long id) {
|
||||
log.info("HostIdentityService-deleteHostIdentityById id: {}", id);
|
||||
// 检查数据是否存在
|
||||
HostIdentityDO record = hostIdentityDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 删除数据库
|
||||
int effect = hostIdentityDAO.deleteById(id);
|
||||
// TODO config
|
||||
|
||||
// 删除缓存
|
||||
RedisLists.removeJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record));
|
||||
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
|
||||
*/
|
||||
@@ -185,15 +184,24 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
// 更新时忽略当前记录
|
||||
.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());
|
||||
.eq(HostIdentityDO::getName, domain.getName());
|
||||
// 检查是否存在
|
||||
boolean present = hostIdentityDAO.of(wrapper).present();
|
||||
Valid.isFalse(present, ErrorMessage.DATA_PRESENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查秘钥是否存在
|
||||
*
|
||||
* @param keyId keyId
|
||||
*/
|
||||
private void checkKeyIdPresent(Long keyId) {
|
||||
if (keyId == null) {
|
||||
return;
|
||||
}
|
||||
Valid.notNull(hostKeyDAO.selectById(keyId), ErrorMessage.KEY_ABSENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询 wrapper
|
||||
*
|
||||
@@ -203,9 +211,8 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
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())
|
||||
.like(HostIdentityDO::getName, request.getName())
|
||||
.like(HostIdentityDO::getUsername, request.getUsername())
|
||||
.eq(HostIdentityDO::getKeyId, request.getKeyId());
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,15 @@ 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.Booleans;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.security.PasswordModifier;
|
||||
import com.orion.ops.framework.common.utils.CryptoUtils;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisLists;
|
||||
import com.orion.ops.module.asset.convert.HostKeyConvert;
|
||||
import com.orion.ops.module.asset.dao.HostIdentityDAO;
|
||||
import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
import com.orion.ops.module.asset.define.HostCacheKeyDefine;
|
||||
import com.orion.ops.module.asset.entity.domain.HostKeyDO;
|
||||
@@ -22,6 +23,7 @@ import com.orion.ops.module.asset.entity.vo.HostKeyVO;
|
||||
import com.orion.ops.module.asset.service.HostKeyService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@@ -41,6 +43,9 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
@Resource
|
||||
private HostKeyDAO hostKeyDAO;
|
||||
|
||||
@Resource
|
||||
private HostIdentityDAO hostIdentityDAO;
|
||||
|
||||
@Override
|
||||
public Long createHostKey(HostKeyCreateRequest request) {
|
||||
log.info("HostKeyService-createHostKey request: {}", JSON.toJSONString(request));
|
||||
@@ -73,25 +78,17 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
HostKeyDO updateRecord = HostKeyConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
this.checkHostKeyPresent(updateRecord);
|
||||
if (Booleans.isTrue(request.getUseNewPassword())) {
|
||||
// 使用新密码
|
||||
String password = updateRecord.getPassword();
|
||||
if (Strings.isBlank(password)) {
|
||||
updateRecord.setPassword(Const.EMPTY);
|
||||
} else {
|
||||
updateRecord.setPassword(CryptoUtils.encryptAsString(password));
|
||||
}
|
||||
} else {
|
||||
updateRecord.setPassword(null);
|
||||
}
|
||||
// 设置密码
|
||||
String newPassword = PasswordModifier.getEncryptNewPassword(request);
|
||||
updateRecord.setPassword(newPassword);
|
||||
// 更新
|
||||
int effect = hostKeyDAO.updateById(updateRecord);
|
||||
log.info("HostKeyService-updateHostKeyById effect: {}", effect);
|
||||
// 设置缓存
|
||||
if (!record.getName().equals(updateRecord.getName())) {
|
||||
RedisLists.removeJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(record));
|
||||
RedisLists.pushJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(updateRecord));
|
||||
}
|
||||
log.info("HostKeyService-updateHostKeyById effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -130,6 +127,7 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
}
|
||||
// 设置缓存
|
||||
RedisLists.pushAllJson(HostCacheKeyDefine.HOST_KEY.getKey(), list);
|
||||
RedisLists.setExpire(HostCacheKeyDefine.HOST_KEY);
|
||||
}
|
||||
// 删除默认值
|
||||
return list.stream()
|
||||
@@ -151,15 +149,26 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteHostKeyById(Long id) {
|
||||
log.info("HostKeyService-deleteHostKeyById id: {}", id);
|
||||
// 检查数据是否存在
|
||||
HostKeyDO record = hostKeyDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 删除数据库
|
||||
int effect = hostKeyDAO.deleteById(id);
|
||||
// 删除关联
|
||||
hostIdentityDAO.setKeyWithNull(id);
|
||||
// TODO config
|
||||
|
||||
// 删除缓存
|
||||
RedisLists.removeJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(record));
|
||||
log.info("HostKeyService-deleteHostKeyById effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测对象是否存在
|
||||
* 检查对象是否存在
|
||||
*
|
||||
* @param domain domain
|
||||
*/
|
||||
|
||||
@@ -21,4 +21,10 @@
|
||||
id, name, username, password, key_id, create_time, update_time, creator, updater, deleted
|
||||
</sql>
|
||||
|
||||
<update id="setKeyWithNull">
|
||||
UPDATE host_identity
|
||||
SET key_id = NULL
|
||||
WHERE key_id = #{keyId}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user