diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/domain/BaseDO.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/domain/BaseDO.java index 72fb91f9..caea89ca 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/domain/BaseDO.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/domain/BaseDO.java @@ -20,6 +20,8 @@ import java.util.Date; @Data public class BaseDO implements Serializable { + private static final long serialVersionUID = 1L; + @Schema(description = "创建时间") @TableField(fill = FieldFill.INSERT) private Date createTime; diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-export.java.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-export.java.vm index 7435f498..64adece0 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-export.java.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-export.java.vm @@ -27,6 +27,8 @@ import java.math.*; @Schema(name = "${type}Export", description = "$!{table.comment}导出对象") public class ${type}Export implements Serializable { + private static final long serialVersionUID = 1L; + public static final String TITLE = "$!{table.comment}导出"; #foreach($field in ${table.fields}) diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-request-create.java.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-request-create.java.vm index 706e1041..99ac467a 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-request-create.java.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-request-create.java.vm @@ -28,6 +28,8 @@ import java.math.*; @Schema(name = "${type}CreateRequest", description = "$!{table.comment} 创建请求对象") public class ${type}CreateRequest implements Serializable { + private static final long serialVersionUID = 1L; + #foreach($field in ${table.fields}) #if("$!field.propertyName" != "id") #if("$field.propertyType" == "String") diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-request-update.java.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-request-update.java.vm index 5c4791d7..8e2e91d1 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-request-update.java.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-entity-request-update.java.vm @@ -27,6 +27,8 @@ import java.math.*; @AllArgsConstructor @Schema(name = "${type}UpdateRequest", description = "$!{table.comment} 更新请求对象") public class ${type}UpdateRequest implements Serializable { + + private static final long serialVersionUID = 1L; #foreach($field in ${table.fields}) #if("$field.propertyType" == "String") diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-create.java.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-create.java.vm index d28c7f52..4610872a 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-create.java.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-create.java.vm @@ -27,6 +27,8 @@ import java.math.*; @Schema(name = "${type}CreateDTO", description = "$!{table.comment} 创建请求业务对象") public class ${type}CreateDTO implements Serializable { + private static final long serialVersionUID = 1L; + #foreach($field in ${table.fields}) #if("$!field.propertyName" != "id") #if("$field.propertyType" == "String") diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-query.java.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-query.java.vm index e8dff8c6..b2fa3549 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-query.java.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-query.java.vm @@ -24,6 +24,8 @@ import java.math.*; @AllArgsConstructor @Schema(name = "${type}QueryDTO", description = "$!{table.comment} 查询请求业务对象") public class ${type}QueryDTO implements Serializable { + + private static final long serialVersionUID = 1L; #foreach($field in ${table.fields}) #if("$field.propertyType" == "String" && "$field.metaInfo.jdbcType" != "LONGVARCHAR") diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-update.java.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-update.java.vm index 8c94f48b..4f555dc0 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-update.java.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-provider-entity-dto-update.java.vm @@ -26,6 +26,8 @@ import java.math.*; @AllArgsConstructor @Schema(name = "${type}UpdateDTO", description = "$!{table.comment} 更新请求业务对象") public class ${type}UpdateDTO implements Serializable { + + private static final long serialVersionUID = 1L; #foreach($field in ${table.fields}) #if("$field.propertyType" == "String") diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostController.http b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostController.http index 8d41545b..3c1b1adb 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostController.http +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostController.http @@ -29,17 +29,9 @@ Authorization: {{token}} ### 查询主机 -POST {{baseUrl}}/asset/host/list-all -Content-Type: application/json +GET {{baseUrl}}/asset/host/list Authorization: {{token}} -{ - "id": "", - "name": "", - "code": "", - "address": "" -} - ### 分页查询主机 POST {{baseUrl}}/asset/host/query diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostController.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostController.java index 5d08b6fa..c4dd6c01 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostController.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostController.java @@ -45,6 +45,8 @@ public class HostController { @Resource private HostConfigService hostConfigService; + // fixme host_config 设置为缓存 + @OperatorLog(HostOperatorType.CREATE) @PostMapping("/create") @Operation(summary = "创建主机") @@ -79,11 +81,11 @@ public class HostController { } @IgnoreLog(IgnoreLogMode.RET) - @PostMapping("/list-all") + @GetMapping("/list") @Operation(summary = "查询主机") @PreAuthorize("@ss.hasPermission('asset:host:query')") - public List getHostListAll(@Validated @RequestBody HostQueryRequest request) { - return hostService.getHostList(request); + public List getHostList() { + return hostService.getHostListByCache(); } @IgnoreLog(IgnoreLogMode.RET) diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostGroupController.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostGroupController.java new file mode 100644 index 00000000..fb9f7726 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostGroupController.java @@ -0,0 +1,143 @@ +// package com.orion.ops.module.asset.controller; +// +// import com.orion.lang.define.wrapper.DataGrid; +// import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog; +// import com.orion.ops.framework.common.validator.group.Page; +// import com.orion.ops.framework.log.core.annotation.IgnoreLog; +// import com.orion.ops.framework.log.core.enums.IgnoreLogMode; +// import com.orion.ops.framework.web.core.annotation.RestWrapper; +// import com.orion.ops.module.asset.define.operator.HostOperatorType; +// import com.orion.ops.module.asset.entity.request.host.*; +// import com.orion.ops.module.asset.entity.vo.HostConfigVO; +// import com.orion.ops.module.asset.entity.vo.HostVO; +// import com.orion.ops.module.asset.service.HostConfigService; +// import com.orion.ops.module.asset.service.HostService; +// 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 java.util.List; +// +// /** +// * 主机 api +// * +// * @author Jiahang Li +// * @version 1.0.0 +// * @since 2023-9-11 14:16 +// */ +// @Tag(name = "asset - 主机服务") +// @Slf4j +// @Validated +// @RestWrapper +// @RestController +// @RequestMapping("/asset/host-group") +// @SuppressWarnings({"ELValidationInJSP", "SpringElInspection"}) +// public class HostGroupController { +// +// @Resource +// private HostService hostService; +// +// @Resource +// private HostConfigService hostConfigService; +// +// @OperatorLog(HostOperatorType.CREATE) +// @PostMapping("/create") +// @Operation(summary = "创建主机") +// @PreAuthorize("@ss.hasPermission('asset:host:create')") +// public Long createHost(@Validated @RequestBody HostCreateRequest request) { +// return hostService.createHost(request); +// } +// +// @OperatorLog(HostOperatorType.UPDATE) +// @PutMapping("/update") +// @Operation(summary = "通过 id 更新主机") +// @PreAuthorize("@ss.hasPermission('asset:host:update')") +// public Integer updateHost(@Validated @RequestBody HostUpdateRequest request) { +// return hostService.updateHostById(request); +// } +// +// @IgnoreLog(IgnoreLogMode.RET) +// @GetMapping("/get") +// @Operation(summary = "通过 id 查询主机") +// @Parameter(name = "id", description = "id", required = true) +// @Parameter(name = "extra", description = "是否查询额外信息") +// @Parameter(name = "config", description = "是否查询配置信息") +// @PreAuthorize("@ss.hasPermission('asset:host:query')") +// public HostVO getHost(@RequestParam("id") Long id, +// @RequestParam(name = "extra", required = false) boolean extra, +// @RequestParam(name = "config", required = false) boolean config) { +// HostQueryRequest request = new HostQueryRequest(); +// request.setId(id); +// request.setExtra(extra); +// request.setConfig(config); +// return hostService.getHostById(request); +// } +// +// @IgnoreLog(IgnoreLogMode.RET) +// @PostMapping("/list") +// @Operation(summary = "查询主机") +// @PreAuthorize("@ss.hasPermission('asset:host:query')") +// public List getHostList() { +// return hostService.getHostListByCache(); +// } +// +// @IgnoreLog(IgnoreLogMode.RET) +// @PostMapping("/query") +// @Operation(summary = "分页查询主机") +// @PreAuthorize("@ss.hasPermission('asset:host:query')") +// public DataGrid getHostPage(@Validated(Page.class) @RequestBody HostQueryRequest request) { +// return hostService.getHostPage(request); +// } +// +// @OperatorLog(HostOperatorType.DELETE) +// @DeleteMapping("/delete") +// @Operation(summary = "通过 id 删除主机") +// @Parameter(name = "id", description = "id", required = true) +// @PreAuthorize("@ss.hasPermission('asset:host:delete')") +// public Integer deleteHost(@RequestParam("id") Long id) { +// return hostService.deleteHostById(id); +// } +// +// @IgnoreLog(IgnoreLogMode.RET) +// @GetMapping("/get-config") +// @Operation(summary = "查询主机配置") +// @Parameter(name = "hostId", description = "hostId", required = true) +// @Parameter(name = "type", description = "配置类型", required = true) +// @PreAuthorize("@ss.hasPermission('asset:host:query')") +// public HostConfigVO getHostConfig(@RequestParam("hostId") Long hostId, +// @RequestParam(name = "type") String type) { +// return hostConfigService.getHostConfig(hostId, type); +// } +// +// @IgnoreLog(IgnoreLogMode.RET) +// @GetMapping("/get-config-all") +// @Operation(summary = "查询主机配置 - 全部") +// @Parameter(name = "hostId", description = "hostId", required = true) +// @PreAuthorize("@ss.hasPermission('asset:host:query')") +// public List getHostConfig(@RequestParam("hostId") Long hostId) { +// return hostConfigService.getHostConfig(hostId); +// } +// +// @OperatorLog(HostOperatorType.UPDATE_CONFIG) +// @PutMapping("/update-config") +// @Operation(summary = "更新主机配置") +// @PreAuthorize("@ss.hasPermission('asset:host:update-config')") +// public Integer updateHostConfig(@Validated @RequestBody HostConfigUpdateRequest request) { +// return hostConfigService.updateHostConfig(request); +// } +// +// @OperatorLog(HostOperatorType.UPDATE_CONFIG_STATUS) +// @PutMapping("/update-config-status") +// @Operation(summary = "更新主机配置状态") +// @PreAuthorize("@ss.hasPermission('asset:host:update-config')") +// public Integer updateHostConfigStatus(@Validated @RequestBody HostConfigUpdateStatusRequest request) { +// return hostConfigService.updateHostConfigStatus(request); +// } +// +// } +// diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.java index 007b2103..c6497e0d 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.java @@ -62,7 +62,7 @@ public class HostKeyController { @GetMapping("/get") @Operation(summary = "查询主机秘钥详情") @Parameter(name = "id", description = "id", required = true) - @PreAuthorize("@ss.hasAnyPermission('asset:host-key:detail', 'asset:host-key:update')") + @PreAuthorize("@ss.hasAnyPermission('asset:host-key:query-detail', 'asset:host-key:update')") public HostKeyVO getHostKey(@RequestParam("id") Long id) { return hostKeyService.getHostKeyById(id); } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/HostConvert.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/HostConvert.java index c2b2c4a5..0cc3f84f 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/HostConvert.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/HostConvert.java @@ -1,6 +1,7 @@ package com.orion.ops.module.asset.convert; import com.orion.ops.module.asset.entity.domain.HostDO; +import com.orion.ops.module.asset.entity.dto.HostCacheDTO; import com.orion.ops.module.asset.entity.request.host.HostCreateRequest; import com.orion.ops.module.asset.entity.request.host.HostQueryRequest; import com.orion.ops.module.asset.entity.request.host.HostUpdateRequest; @@ -8,8 +9,6 @@ import com.orion.ops.module.asset.entity.vo.HostVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; -import java.util.List; - /** * 主机 内部对象转换器 * @@ -30,6 +29,8 @@ public interface HostConvert { HostVO to(HostDO domain); - List to(List list); + HostVO to(HostCacheDTO cache); + + HostCacheDTO toCache(HostDO domain); } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/cache/HostCacheKeyDefine.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/cache/HostCacheKeyDefine.java index a4edf024..06605f26 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/cache/HostCacheKeyDefine.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/cache/HostCacheKeyDefine.java @@ -2,6 +2,7 @@ package com.orion.ops.module.asset.define.cache; import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.CacheKeyDefine; +import com.orion.ops.module.asset.entity.dto.HostCacheDTO; import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO; import com.orion.ops.module.asset.entity.dto.HostKeyCacheDTO; @@ -16,18 +17,25 @@ import java.util.concurrent.TimeUnit; */ public interface HostCacheKeyDefine { + CacheKeyDefine HOST_INFO = new CacheKeyBuilder() + .key("host:info:list") + .desc("主机列表") + .type(HostCacheDTO.class) + .timeout(1, TimeUnit.DAYS) + .build(); + CacheKeyDefine HOST_KEY = new CacheKeyBuilder() .key("host:key:list") .desc("主机秘钥列表") .type(HostKeyCacheDTO.class) - .timeout(1, TimeUnit.HOURS) + .timeout(1, TimeUnit.DAYS) .build(); CacheKeyDefine HOST_IDENTITY = new CacheKeyBuilder() .key("host:identity:list") .desc("主机身份列表") .type(HostIdentityCacheDTO.class) - .timeout(1, TimeUnit.HOURS) + .timeout(1, TimeUnit.DAYS) .build(); } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/HostCacheDTO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/HostCacheDTO.java new file mode 100644 index 00000000..315a4708 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/HostCacheDTO.java @@ -0,0 +1,37 @@ +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-11 14:16 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "HostCacheDTO", description = "主机 缓存对象") +public class HostCacheDTO implements Serializable { + + @Schema(description = "id") + private Long id; + + @Schema(description = "主机名称") + private String name; + + @Schema(description = "主机编码") + private String code; + + @Schema(description = "主机地址") + private String address; + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/HostService.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/HostService.java index b30d517a..9634ba47 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/HostService.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/HostService.java @@ -44,10 +44,9 @@ public interface HostService { /** * 查询主机 * - * @param request request * @return rows */ - List getHostList(HostQueryRequest request); + List getHostListByCache(); /** * 分页查询主机 diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostServiceImpl.java index 56858698..1c00ff48 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostServiceImpl.java @@ -7,15 +7,19 @@ import com.orion.lang.utils.Booleans; import com.orion.lang.utils.Strings; import com.orion.lang.utils.collect.Lists; import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; +import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.utils.Valid; +import com.orion.ops.framework.redis.core.utils.RedisMaps; import com.orion.ops.framework.security.core.utils.SecurityUtils; import com.orion.ops.module.asset.convert.HostConfigConvert; import com.orion.ops.module.asset.convert.HostConvert; import com.orion.ops.module.asset.dao.HostConfigDAO; import com.orion.ops.module.asset.dao.HostDAO; +import com.orion.ops.module.asset.define.cache.HostCacheKeyDefine; import com.orion.ops.module.asset.entity.domain.HostConfigDO; import com.orion.ops.module.asset.entity.domain.HostDO; +import com.orion.ops.module.asset.entity.dto.HostCacheDTO; import com.orion.ops.module.asset.entity.request.host.HostCreateRequest; import com.orion.ops.module.asset.entity.request.host.HostQueryRequest; import com.orion.ops.module.asset.entity.request.host.HostUpdateRequest; @@ -51,6 +55,8 @@ import java.util.stream.Collectors; @Service public class HostServiceImpl implements HostService { + // FIXME 这里的收藏删除 + private static final ThreadLocal> FAVORITE_HOLDER = new ThreadLocal<>(); @Resource @@ -87,6 +93,8 @@ public class HostServiceImpl implements HostService { } // 创建配置 hostConfigService.initHostConfig(id); + // 删除缓存 + RedisMaps.delete(HostCacheKeyDefine.HOST_INFO); return id; } @@ -105,6 +113,8 @@ public class HostServiceImpl implements HostService { // 更新 int effect = hostDAO.updateById(updateRecord); log.info("HostService-updateHostById effect: {}", effect); + // 删除缓存 + RedisMaps.delete(HostCacheKeyDefine.HOST_INFO); // 更新 tag tagRelApi.setTagRel(TagTypeEnum.HOST, id, request.getTags()); return effect; @@ -123,21 +133,27 @@ public class HostServiceImpl implements HostService { } @Override - public List getHostList(HostQueryRequest request) { - try { - // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); - if (wrapper == null) { - return Lists.empty(); + public List getHostListByCache() { + // 查询缓存 + List list = RedisMaps.valuesJson(HostCacheKeyDefine.HOST_INFO); + if (list.isEmpty()) { + // 查询数据库 + list = hostDAO.of().list(HostConvert.MAPPER::toCache); + // 添加默认值 防止穿透 + if (list.isEmpty()) { + list.add(HostCacheDTO.builder() + .id(Const.NONE_ID) + .build()); } - // 查询 - List hosts = hostDAO.of(wrapper).list(HostConvert.MAPPER::to); - // 查询拓展信息 - this.setExtraInfo(request, hosts); - return hosts; - } finally { - FAVORITE_HOLDER.remove(); + // 设置缓存 + RedisMaps.putAllJson(HostCacheKeyDefine.HOST_INFO.getKey(), s -> s.getId().toString(), list); + RedisMaps.setExpire(HostCacheKeyDefine.HOST_INFO); } + // 删除默认值 + return list.stream() + .filter(s -> !s.getId().equals(Const.NONE_ID)) + .map(HostConvert.MAPPER::to) + .collect(Collectors.toList()); } @Override @@ -171,6 +187,8 @@ public class HostServiceImpl implements HostService { // 删除 int effect = hostDAO.deleteById(id); log.info("HostService-deleteHostById effect: {}", effect); + // 删除缓存 + RedisMaps.delete(HostCacheKeyDefine.HOST_INFO, id); // 删除配置 hostConfigDAO.deleteByHostId(id); // 删除 tag 引用 diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TagController.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TagController.java index 22c3b1ca..f49e0ad1 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TagController.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TagController.java @@ -45,7 +45,7 @@ public class TagController { @GetMapping("/list") @Operation(summary = "查询标签") @Parameter(name = "type", description = "type", required = true) - public List getTagListAll(@RequestParam("type") String type) { + public List getTagList(@RequestParam("type") String type) { return tagService.getTagList(type); } diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictKeyServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictKeyServiceImpl.java index 3fa60aa1..d8aae8f5 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictKeyServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictKeyServiceImpl.java @@ -69,7 +69,7 @@ public class DictKeyServiceImpl implements DictKeyService { Long id = record.getId(); log.info("DictKeyService-createDictKey id: {}, effect: {}", id, effect); // 删除缓存 - RedisMaps.delete(DictCacheKeyDefine.DICT_KEY); + RedisUtils.delete(DictCacheKeyDefine.DICT_KEY); return id; } @@ -191,8 +191,8 @@ public class DictKeyServiceImpl implements DictKeyService { // 删除配置值 dictValueService.deleteDictValueByKeyId(id); // 删除缓存 - RedisUtils.delete(DictCacheKeyDefine.DICT_KEY.getKey(), - DictCacheKeyDefine.DICT_SCHEMA.format(record.getKeyName())); + RedisMaps.delete(DictCacheKeyDefine.DICT_KEY, id); + RedisUtils.delete(DictCacheKeyDefine.DICT_SCHEMA.format(record.getKeyName())); log.info("DictKeyService-deleteDictKeyById id: {}, effect: {}", id, effect); return effect; } @@ -215,7 +215,7 @@ public class DictKeyServiceImpl implements DictKeyService { dictValueService.deleteDictValueByKeyIdList(idList); log.info("DictKeyService-deleteDictKeyByIdList effect: {}", effect); // 删除缓存 - RedisMaps.delete(DictCacheKeyDefine.DICT_KEY); + RedisMaps.delete(DictCacheKeyDefine.DICT_KEY, idList); List schemaKeys = dictKeys.stream() .map(DictKeyDO::getKeyName) .map(DictCacheKeyDefine.DICT_SCHEMA::format) diff --git a/orion-ops-ui/src/api/asset/host.ts b/orion-ops-ui/src/api/asset/host.ts index 297ce528..ac02e1f1 100644 --- a/orion-ops-ui/src/api/asset/host.ts +++ b/orion-ops-ui/src/api/asset/host.ts @@ -95,10 +95,10 @@ export function getHost(params: HostQueryRequest) { } /** - * 查询主机 + * 查询全部主机 */ -export function getHostListAll(request: HostQueryRequest) { - return axios.post>('/asset/host/list-all', request); +export function getHostList() { + return axios.get>('/asset/host/list'); } /** diff --git a/orion-ops-ui/src/components/system/menu/grant/menu-grant-table.vue b/orion-ops-ui/src/components/system/menu/grant/menu-grant-table.vue index ce97e26f..34c8c701 100644 --- a/orion-ops-ui/src/components/system/menu/grant/menu-grant-table.vue +++ b/orion-ops-ui/src/components/system/menu/grant/menu-grant-table.vue @@ -57,13 +57,13 @@ const cacheStore = useCacheStore(); - const isFirst = ref(false); + const unTriggerChange = ref(false); const menuData = ref>([]); const checkedKeys = ref>([]); // 初始化 const init = (keys: Array) => { - isFirst.value = true; + unTriggerChange.value = true; checkedKeys.value = keys; if (!menuData.value.length) { menuData.value = [...cacheStore.menus]; @@ -75,12 +75,44 @@ return checkedKeys.value; }; - defineExpose({ init, getValue }); + // 选择 + const checked = (rule: undefined | ((s: string) => boolean)) => { + unTriggerChange.value = true; + const nodes: Array = []; + flatNodes(menuData.value, nodes); + if (rule) { + const checkedNodes = nodes.filter(s => s.permission) + .filter(s => rule(s?.permission)) + .map(s => s.id) + .filter(Boolean); + checkedKeys.value = [...new Set([...checkedKeys.value, ...checkedNodes])]; + } else { + checkedKeys.value = nodes.map(s => s.id).filter(Boolean); + } + }; + + // 取消选择 + const unchecked = (rule: undefined | ((s: string) => boolean)) => { + unTriggerChange.value = true; + const nodes: Array = []; + flatNodes(menuData.value, nodes); + if (rule) { + const uncheckedNodes = nodes.filter(s => s.permission) + .filter(s => rule(s?.permission)) + .map(s => s.id) + .filter(Boolean); + checkedKeys.value = [...checkedKeys.value].filter(s => !uncheckedNodes.includes(s)); + } else { + checkedKeys.value = []; + } + }; + + defineExpose({ init, getValue, checked, unchecked }); // 监听级联变化 watch(checkedKeys, (after: Array, before: Array) => { - if (isFirst.value) { - isFirst.value = false; + if (unTriggerChange.value) { + unTriggerChange.value = false; return; } const afterLength = after.length; @@ -136,18 +168,31 @@ } }; + // 展开节点 + const flatNodes = (nodes: Array, result: Array) => { + if (!nodes || !nodes.length) { + return; + } + nodes.forEach(s => { + result.push(s); + flatNodes(s.children, result); + }); + }; + // 级联选择菜单 const checkMenu = (id: number) => { + unTriggerChange.value = true; // 查询当前节点 const node = findNode(id, menuData.value); const childrenId: number[] = []; // 获取所在子节点id flatChildrenId(node?.children, childrenId); - checkedKeys.value.push(...childrenId); + checkedKeys.value = [...new Set([...checkedKeys.value, ...childrenId])]; }; // 级联取消选择菜单 const uncheckMenu = (id: number) => { + unTriggerChange.value = true; // 查询当前节点 const node = findNode(id, menuData.value); const childrenId: number[] = []; diff --git a/orion-ops-ui/src/views/user/role/components/role-menu-grant-modal.vue b/orion-ops-ui/src/views/user/role/components/role-menu-grant-modal.vue index 16a0e118..de467bfe 100644 --- a/orion-ops-ui/src/views/user/role/components/role-menu-grant-modal.vue +++ b/orion-ops-ui/src/views/user/role/components/role-menu-grant-modal.vue @@ -4,7 +4,7 @@ title-align="start" title="分配菜单" width="80%" - :top="80" + :top="40" :body-style="{padding: '16px 16px 0 16px', 'margin-bottom': '16px'}" :align-center="false" :draggable="true" @@ -15,11 +15,29 @@ :on-before-ok="handlerOk" @close="handleClose">
- + {{ roleRecord.name }} {{ roleRecord.code }} - 菜单分配后需要用户手动刷新页面才会生效 +
+ + + +
+
+ + + +
@@ -42,6 +60,7 @@ import { useCacheStore } from '@/store'; import { getMenuList } from '@/api/system/menu'; import MenuGrantTable from '@/components/system/menu/grant/menu-grant-table.vue'; + import { quickGrantMenuOperator } from '../types/const'; const { visible, setVisible } = useVisible(); const { loading, setLoading } = useLoading(); @@ -113,7 +132,7 @@ diff --git a/orion-ops-ui/src/views/user/role/types/const.ts b/orion-ops-ui/src/views/user/role/types/const.ts index 27f1fc32..d3be1ca8 100644 --- a/orion-ops-ui/src/views/user/role/types/const.ts +++ b/orion-ops-ui/src/views/user/role/types/const.ts @@ -6,6 +6,44 @@ export const RoleStatus = { ENABLED: 1, }; +// 快速分配菜单操作 +export const quickGrantMenuOperator = [ + { + name: '', + rule: undefined + }, { + name: '查询', + rule: (perm: string) => { + return perm.includes('query') || perm.includes('view'); + } + }, { + name: '新增', + rule: (perm: string) => { + return perm.includes('add') || perm.includes('create'); + } + }, { + name: '修改', + rule: (perm: string) => { + return perm.includes('update') || perm.includes('modify'); + } + }, { + name: '删除', + rule: (perm: string) => { + return perm.includes('delete') || perm.includes('remove'); + } + }, { + name: '导入', + rule: (perm: string) => { + return perm.includes('import'); + } + }, { + name: '导出', + rule: (perm: string) => { + return perm.includes('export'); + } + }, +]; + // 角色状态 字典项 export const roleStatusKey = 'systemRoleStatus';