review: 重构代码.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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})
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<HostVO> getHostListAll(@Validated @RequestBody HostQueryRequest request) {
|
||||
return hostService.getHostList(request);
|
||||
public List<HostVO> getHostList() {
|
||||
return hostService.getHostListByCache();
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
|
||||
@@ -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<HostVO> getHostList() {
|
||||
// return hostService.getHostListByCache();
|
||||
// }
|
||||
//
|
||||
// @IgnoreLog(IgnoreLogMode.RET)
|
||||
// @PostMapping("/query")
|
||||
// @Operation(summary = "分页查询主机")
|
||||
// @PreAuthorize("@ss.hasPermission('asset:host:query')")
|
||||
// public DataGrid<HostVO> 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<HostConfigVO> 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);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<HostVO> to(List<HostDO> list);
|
||||
HostVO to(HostCacheDTO cache);
|
||||
|
||||
HostCacheDTO toCache(HostDO domain);
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -44,10 +44,9 @@ public interface HostService {
|
||||
/**
|
||||
* 查询主机
|
||||
*
|
||||
* @param request request
|
||||
* @return rows
|
||||
*/
|
||||
List<HostVO> getHostList(HostQueryRequest request);
|
||||
List<HostVO> getHostListByCache();
|
||||
|
||||
/**
|
||||
* 分页查询主机
|
||||
|
||||
@@ -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<List<Long>> 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<HostVO> getHostList(HostQueryRequest request) {
|
||||
try {
|
||||
// 条件
|
||||
LambdaQueryWrapper<HostDO> wrapper = this.buildQueryWrapper(request);
|
||||
if (wrapper == null) {
|
||||
return Lists.empty();
|
||||
public List<HostVO> getHostListByCache() {
|
||||
// 查询缓存
|
||||
List<HostCacheDTO> 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<HostVO> 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 引用
|
||||
|
||||
@@ -45,7 +45,7 @@ public class TagController {
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "查询标签")
|
||||
@Parameter(name = "type", description = "type", required = true)
|
||||
public List<TagVO> getTagListAll(@RequestParam("type") String type) {
|
||||
public List<TagVO> getTagList(@RequestParam("type") String type) {
|
||||
return tagService.getTagList(type);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String> schemaKeys = dictKeys.stream()
|
||||
.map(DictKeyDO::getKeyName)
|
||||
.map(DictCacheKeyDefine.DICT_SCHEMA::format)
|
||||
|
||||
@@ -95,10 +95,10 @@ export function getHost(params: HostQueryRequest) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询主机
|
||||
* 查询全部主机
|
||||
*/
|
||||
export function getHostListAll(request: HostQueryRequest) {
|
||||
return axios.post<Array<HostQueryResponse>>('/asset/host/list-all', request);
|
||||
export function getHostList() {
|
||||
return axios.get<Array<HostQueryResponse>>('/asset/host/list');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,13 +57,13 @@
|
||||
|
||||
const cacheStore = useCacheStore();
|
||||
|
||||
const isFirst = ref(false);
|
||||
const unTriggerChange = ref(false);
|
||||
const menuData = ref<Array<MenuQueryResponse>>([]);
|
||||
const checkedKeys = ref<Array<number>>([]);
|
||||
|
||||
// 初始化
|
||||
const init = (keys: Array<number>) => {
|
||||
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<MenuQueryResponse> = [];
|
||||
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<MenuQueryResponse> = [];
|
||||
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<number>, before: Array<number>) => {
|
||||
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<MenuQueryResponse>, result: Array<MenuQueryResponse>) => {
|
||||
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[] = [];
|
||||
|
||||
@@ -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">
|
||||
<div class="role-menu-wrapper">
|
||||
<a-alert class="mb8 usn">
|
||||
<a-alert class="usn mb8">
|
||||
<span>{{ roleRecord.name }} {{ roleRecord.code }}</span>
|
||||
<span class="mx8">-</span>
|
||||
<span>菜单分配后需要用户手动刷新页面才会生效</span>
|
||||
</a-alert>
|
||||
<div class="usn mb8">
|
||||
<a-space>
|
||||
<template v-for="opt of quickGrantMenuOperator" :key="opt.name">
|
||||
<a-button size="mini" type="text" @click="() => { table.checked(opt.rule) }">
|
||||
{{ '全选' + opt.name }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-space>
|
||||
</div>
|
||||
<div class="usn mb8">
|
||||
<a-space>
|
||||
<template v-for="opt of quickGrantMenuOperator" :key="opt.name">
|
||||
<a-button size="mini" type="text" @click="() => { table.unchecked(opt.rule) }">
|
||||
{{ '反选' + opt.name }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-space>
|
||||
</div>
|
||||
<!-- 菜单 -->
|
||||
<menu-grant-table ref="table" />
|
||||
</div>
|
||||
@@ -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 @@
|
||||
<style lang="less" scoped>
|
||||
.role-menu-wrapper {
|
||||
width: 100%;
|
||||
max-height: calc(100vh - 285px);
|
||||
max-height: calc(100vh - 230px);
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user