From 57bcaba7f0c44427cacaf7be54dc75d04618a877 Mon Sep 17 00:00:00 2001 From: shiyidong Date: Tue, 11 May 2021 02:49:23 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=BC=80=E5=85=B3,=E4=BF=AE=E6=94=B9=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=85=8D=E7=BD=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/InfConfigController.java | 22 ++++++++++--- .../dal/mysql/config/InfConfigMapper.java | 6 ++-- .../service/config/InfConfigService.java | 9 +++++ .../config/impl/InfConfigServiceImpl.java | 15 +++++++++ .../src/main/resources/application-local.yaml | 10 +++--- yudao-admin-ui/src/api/infra/config.js | 9 +++++ yudao-admin-ui/src/utils/constants.js | 9 +++++ .../src/views/infra/apiAccessLog/index.vue | 27 +++++++++++++-- .../common/enums/ConfigKeyConstants.java | 28 ++++++++++++++++ .../operatelog/core/aop/OperateLogAspect.java | 14 ++++++++ .../apollo/internals/DBConfigRepository.java | 2 +- .../ApolloApplicationContextInitializer.java | 1 + .../core/filter/ApiAccessLogFilter.java | 33 ++++++++++++++----- 13 files changed, 160 insertions(+), 25 deletions(-) create mode 100644 yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/ConfigKeyConstants.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java index b0ff2ca9ad..d23a64c6e8 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java @@ -1,13 +1,14 @@ package cn.iocoder.yudao.adminserver.modules.infra.controller.config; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.*; import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert; import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -18,13 +19,14 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import javax.validation.constraints.NotBlank; import java.io.IOException; import java.util.List; +import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; -import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE; @Api(tags = "参数配置") @RestController @@ -67,6 +69,16 @@ public class InfConfigController { return success(InfConfigConvert.INSTANCE.convert(configService.getConfig(id))); } + + @PutMapping("/update-value-by-key") + @ApiOperation(value = "根据参数键名修改参数值") + @PreAuthorize("@ss.hasPermission('infra:config:updateValueByKey')") + public CommonResult updateValueByKey(@NotBlank(message = "key 不允许为空") String key, String value) { + configService.updateValueByKey(key,value); + return success(true); + } + + @GetMapping(value = "/get-value-by-key") @ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端") @ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigMapper.java index 546ef843ac..59306dab22 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigMapper.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigService.java index 2430c329b0..e004f6b45a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigService.java @@ -32,6 +32,13 @@ public interface InfConfigService { */ void updateConfig(@Valid InfConfigUpdateReqVO reqVO); + /** + * 根据key修改value + * @param key + * @param value + */ + void updateValueByKey(String key,String value); + /** * 删除参数配置 * @@ -72,4 +79,6 @@ public interface InfConfigService { List getConfigList(@Valid InfConfigExportReqVO reqVO); + + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java index 13bc2aafc0..7578e8d529 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java @@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.List; +import java.util.Objects; import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.*; @@ -61,6 +62,20 @@ public class InfConfigServiceImpl implements InfConfigService { configProducer.sendConfigRefreshMessage(); } + @Override + public void updateValueByKey(String key, String value) { + InfConfigDO config = configMapper.selectByKey(key); + if (Objects.isNull(config)) { + throw ServiceExceptionUtil.exception(CONFIG_NOT_EXISTS); + } + InfConfigDO updateDo = new InfConfigDO(); + updateDo.setId(config.getId()); + updateDo.setValue(value); + configMapper.updateById(updateDo); + // 发送刷新消息 + configProducer.sendConfigRefreshMessage(); + } + @Override public void deleteConfig(Long id) { // 校验配置存在 diff --git a/yudao-admin-server/src/main/resources/application-local.yaml b/yudao-admin-server/src/main/resources/application-local.yaml index 53ab065605..7cadaed8c9 100644 --- a/yudao-admin-server/src/main/resources/application-local.yaml +++ b/yudao-admin-server/src/main/resources/application-local.yaml @@ -44,20 +44,20 @@ spring: datasource: master: name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT + url: jdbc:mysql://192.168.1.111:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT driver-class-name: com.mysql.jdbc.Driver username: root - password: 123456 + password: 851511 slave: # 模拟从库,可根据自己需要修改 name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT + url: jdbc:mysql://192.168.1.111:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT driver-class-name: com.mysql.jdbc.Driver username: root - password: 123456 + password: 851511 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: - host: 127.0.0.1 # 地址 + host: 192.168.1.111 # 地址 port: 6379 # 端口 database: 0 # 数据库索引 diff --git a/yudao-admin-ui/src/api/infra/config.js b/yudao-admin-ui/src/api/infra/config.js index eec1517796..284e5ec5ce 100644 --- a/yudao-admin-ui/src/api/infra/config.js +++ b/yudao-admin-ui/src/api/infra/config.js @@ -43,6 +43,15 @@ export function updateConfig(data) { }) } +// 修改参数配置 +export function updateValueByKey(data) { + return request({ + url: '/infra/config/update-value-by-key', + method: 'put', + data: data + }) +} + // 删除参数配置 export function delConfig(configId) { return request({ diff --git a/yudao-admin-ui/src/utils/constants.js b/yudao-admin-ui/src/utils/constants.js index 43bd9c4724..36f24907b2 100644 --- a/yudao-admin-ui/src/utils/constants.js +++ b/yudao-admin-ui/src/utils/constants.js @@ -66,3 +66,12 @@ export const InfApiErrorLogProcessStatusEnum = { DONE: 1, // 已处理 IGNORE: 2, // 已忽略 } + +/** + * + */ +export const InfConfigKeyEnum = { + API_LOG_KEY: 'yudao.web.api.log.enable', + DONE: 1, + IGNORE: 2, +} \ No newline at end of file diff --git a/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue b/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue index abe0fd44f6..0f41d1f5e1 100644 --- a/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue +++ b/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue @@ -36,6 +36,10 @@ + + {{enable?'关闭日志':'开启日志'}} + 导出 @@ -114,7 +118,8 @@ + \ No newline at end of file diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/ConfigKeyConstants.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/ConfigKeyConstants.java new file mode 100644 index 0000000000..97bbd65b86 --- /dev/null +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/ConfigKeyConstants.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.framework.common.enums; + +/** + * @author syidong@aliyun.com + * @date 2021/5/10 23:40 + */ +public interface ConfigKeyConstants { + + /** + * 是否开启apiLog key + */ + String YUDAO_WEB_API_LOG_ENABLE_KEY = "yudao.web.api.log.enable"; + + /** + * 是否开启api error log 日志 key + */ + String YUDAO_WEB_API_ERROR_LOG_ENABLE_KEY = "yudao.web.api.error.og.enable"; + + /** + * 是否开启operateLog key + */ + String YUDAO_OPERATE_LOG_KEY = "yudao.operateLog.enable"; + + /** + * spring value Key + */ + String SPRING_YUDAO_OPERATE_LOG_KEY = "${"+YUDAO_OPERATE_LOG_KEY+":true}"; +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-operatelog/src/main/java/cn/iocoder/yudao/framework/operatelog/core/aop/OperateLogAspect.java b/yudao-framework/yudao-spring-boot-starter-biz-operatelog/src/main/java/cn/iocoder/yudao/framework/operatelog/core/aop/OperateLogAspect.java index a7f23a3912..412efe5feb 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-operatelog/src/main/java/cn/iocoder/yudao/framework/operatelog/core/aop/OperateLogAspect.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-operatelog/src/main/java/cn/iocoder/yudao/framework/operatelog/core/aop/OperateLogAspect.java @@ -4,6 +4,7 @@ import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.servlet.ServletUtil; +import cn.iocoder.yudao.framework.common.enums.ConfigKeyConstants; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; @@ -21,6 +22,7 @@ import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Value; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -65,18 +67,30 @@ public class OperateLogAspect { */ private static final ThreadLocal> EXTS = new ThreadLocal<>(); + /** + * operateLog 开关 + */ + @Value(ConfigKeyConstants.SPRING_YUDAO_OPERATE_LOG_KEY) + private Boolean isEnable; + @Resource private OperateLogFrameworkService operateLogFrameworkService; @Around("@annotation(apiOperation)") public Object around(ProceedingJoinPoint joinPoint, ApiOperation apiOperation) throws Throwable { // 可能也添加了 @ApiOperation 注解 + if(!isEnable){ + return null; + } OperateLog operateLog = getMethodAnnotation(joinPoint, OperateLog.class); return around0(joinPoint, operateLog, apiOperation); } @Around("!@annotation(io.swagger.annotations.ApiOperation) && @annotation(operateLog)") // 兼容处理,只添加 @OperateLog 注解的情况 public Object around(ProceedingJoinPoint joinPoint, OperateLog operateLog) throws Throwable { + if(!isEnable){ + return null; + } return around0(joinPoint, operateLog, null); } diff --git a/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DBConfigRepository.java b/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DBConfigRepository.java index c88038da97..095ebb26f3 100644 --- a/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DBConfigRepository.java +++ b/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DBConfigRepository.java @@ -135,7 +135,7 @@ public class DBConfigRepository extends AbstractConfigRepository { private Properties buildProperties(List configs) { Properties properties = propertiesFactory.getPropertiesInstance(); - configs.stream().filter(ConfigRespDTO::getDeleted) // 过滤掉被删除的配置 + configs.stream().filter(item -> !item.getDeleted()) // 过滤掉被删除的配置 .forEach(config -> properties.put(config.getKey(), config.getValue())); return properties; } diff --git a/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java b/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java index b68ca76d61..e30fc24c09 100644 --- a/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java +++ b/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.framework.apollo.spring.boot; import cn.iocoder.yudao.framework.apollo.core.ConfigConsts; +import com.ctrip.framework.apollo.util.ConfigUtil; import com.google.common.base.Strings; import org.springframework.boot.SpringApplication; import org.springframework.boot.env.EnvironmentPostProcessor; diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java index 49f54fe259..1cab39a1db 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java @@ -2,17 +2,20 @@ package cn.iocoder.yudao.framework.apilog.core.filter; import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.servlet.ServletUtil; -import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService; import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; -import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; -import cn.iocoder.yudao.framework.web.config.WebProperties; -import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; +import cn.iocoder.yudao.framework.common.enums.ConfigKeyConstants; +import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; +import cn.iocoder.yudao.framework.web.config.WebProperties; +import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.filter.OncePerRequestFilter; @@ -25,6 +28,7 @@ import java.io.IOException; import java.util.Date; import java.util.Map; + /** * API 访问日志 Filter * @@ -57,15 +61,26 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { try { // 继续过滤器 filterChain.doFilter(request, response); - // 正常执行,记录日志 - createApiAccessLog(request, beginTim, queryString, requestBody, null); + // api log 开关 + if(isEnable(ConfigKeyConstants.YUDAO_WEB_API_LOG_ENABLE_KEY)){ + // 正常执行,记录日志 + createApiAccessLog(request, beginTim, queryString, requestBody, null); + } } catch (Exception ex) { - // 异常执行,记录日志 - createApiAccessLog(request, beginTim, queryString, requestBody, ex); + // api log异常日志开关 + if(isEnable(ConfigKeyConstants.YUDAO_WEB_API_ERROR_LOG_ENABLE_KEY)){ + // 异常执行,记录日志 + createApiAccessLog(request, beginTim, queryString, requestBody, ex); + } throw ex; } } + private boolean isEnable(String key){ + String enable = SpringUtil.getProperty(key); + return Boolean.parseBoolean(StrUtil.isBlank(enable)?Boolean.TRUE.toString():enable); + } + private void createApiAccessLog(HttpServletRequest request, Date beginTime, Map queryString, String requestBody, Exception ex) { ApiAccessLogCreateDTO accessLog = new ApiAccessLogCreateDTO(); From 102cafa9a64b3e24d8ac2eb847c08188e6a97742 Mon Sep 17 00:00:00 2001 From: shiyidong Date: Wed, 12 May 2021 01:09:31 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=8A=BD=E5=87=BAvue=20component=20?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=BC=80=E5=85=B3=E6=8C=89=E9=92=AE=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-admin-ui/src/main.js | 3 +- .../src/views/infra/apiAccessLog/index.vue | 28 ++++--------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/yudao-admin-ui/src/main.js b/yudao-admin-ui/src/main.js index d9978300cb..78ab14f775 100644 --- a/yudao-admin-ui/src/main.js +++ b/yudao-admin-ui/src/main.js @@ -37,7 +37,7 @@ import RightToolbar from "@/components/RightToolbar" // import hljs from 'highlight.js' // import 'highlight.js/styles/github-gist.css' import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict"; - +import { InfConfigKeyEnum } from '@/utils/constants'; // 全局方法挂载 Vue.prototype.getDicts = getDicts Vue.prototype.getConfigKey = getConfigKey @@ -49,6 +49,7 @@ Vue.prototype.selectDictLabel = selectDictLabel Vue.prototype.getDictDatas = getDictDatas Vue.prototype.getDictDataLabel = getDictDataLabel Vue.prototype.DICT_TYPE = DICT_TYPE +Vue.prototype.InfConfigKeyEnum = InfConfigKeyEnum Vue.prototype.download = download Vue.prototype.downloadExcel = downloadExcel Vue.prototype.downloadWord = downloadWord diff --git a/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue b/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue index 0f41d1f5e1..8fee22d00d 100644 --- a/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue +++ b/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue @@ -37,8 +37,10 @@ - {{enable?'关闭日志':'开启日志'}} + + import { getApiAccessLogPage, exportApiAccessLogExcel } from "@/api/infra/apiAccessLog"; -import { getConfigKey,updateValueByKey } from "@/api/infra/config"; -import { InfConfigKeyEnum } from "@/utils/constants"; +import LogSwitch from "@/components/LogSwitch"; export default { name: "ApiAccessLog", components: { + LogSwitch }, data() { return { @@ -130,8 +132,6 @@ export default { loading: true, // 显示搜索条件 showSearch: true, - // 是否开启 - enable: false, // 总条数 total: 0, // API 访问日志列表 @@ -157,25 +157,9 @@ export default { }; }, created() { - this.getEnableConfig(); this.getList(); }, methods: { - //开启关闭日志 - enableHandler(){ - let data = new FormData(); - data.append("key",InfConfigKeyEnum.API_LOG_KEY); - data.append("value",this.enable?false:true); - updateValueByKey(data).then(response => { - this.msgSuccess(this.enable?"关闭成功":"开启成功"); - this.getEnableConfig(); - }) - }, - getEnableConfig(){ - getConfigKey(InfConfigKeyEnum.API_LOG_KEY).then(response => { - this.enable = (response.data == "true"); - }) - }, /** 查询列表 */ getList() { this.loading = true; From 0259e4ffe5d1620981a42e587dba73e2b3c373da Mon Sep 17 00:00:00 2001 From: shiyidong Date: Thu, 13 May 2021 02:47:11 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=9A=84=E6=97=B6=E5=80=99=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/InfConfigController.java | 11 ++- .../convert/config/InfConfigConvert.java | 3 + .../dal/dataobject/config/InfConfigDO.java | 3 +- .../config/impl/InfConfigServiceImpl.java | 31 ++++++--- .../service/config/InfConfigServiceTest.java | 6 +- .../errorcode/SysErrorCodeServiceTest.java | 8 +-- .../src/components/LogSwitch/index.vue | 68 +++++++++++++++++++ yudao-admin-ui/src/main.js | 4 ++ yudao-admin-ui/src/utils/constants.js | 4 +- .../src/views/infra/apiAccessLog/index.vue | 14 ++-- .../src/views/infra/apiErrorLog/index.vue | 4 ++ .../src/views/system/operatelog/index.vue | 4 ++ yudao-framework/yudao-common/pom.xml | 5 ++ .../config/enums/ConfigGroupConstants.java | 13 ++++ .../common/config/enums/InfConfigEnum.java | 50 ++++++++++++++ .../config/enums}/InfConfigTypeEnum.java | 2 +- .../common/config/util/InfConfigUtil.java | 45 ++++++++++++ .../operatelog/core/aop/OperateLogAspect.java | 17 ++--- .../apollo/internals/DBConfigRepository.java | 3 +- .../core/filter/ApiAccessLogFilter.java | 10 +-- 20 files changed, 251 insertions(+), 54 deletions(-) create mode 100644 yudao-admin-ui/src/components/LogSwitch/index.vue create mode 100644 yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/config/enums/ConfigGroupConstants.java create mode 100644 yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/config/enums/InfConfigEnum.java rename {yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/enums/config => yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/config/enums}/InfConfigTypeEnum.java (80%) create mode 100644 yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/config/util/InfConfigUtil.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java index d23a64c6e8..fe2a22aded 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java @@ -1,10 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.controller.config; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.*; import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert; import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; +import cn.iocoder.yudao.framework.common.config.enums.InfConfigEnum; +import cn.iocoder.yudao.framework.common.config.util.InfConfigUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; @@ -22,6 +23,7 @@ import javax.validation.Valid; import javax.validation.constraints.NotBlank; import java.io.IOException; import java.util.List; +import java.util.Objects; import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -85,7 +87,12 @@ public class InfConfigController { public CommonResult getConfigKey(@RequestParam("key") String key) { InfConfigDO config = configService.getConfigByKey(key); if (config == null) { - return null; + InfConfigEnum initConfigEnum = InfConfigUtil.getInitConfigEnum(key); + if(Objects.nonNull(initConfigEnum)){ + config = InfConfigConvert.INSTANCE.convert(initConfigEnum); + }else{ + return null; + } } if (config.getSensitive()) { throw exception(CONFIG_GET_VALUE_ERROR_IF_SENSITIVE); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/config/InfConfigConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/config/InfConfigConvert.java index 0b076b6e0e..2002afe27f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/config/InfConfigConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/config/InfConfigConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.infra.convert.config; +import cn.iocoder.yudao.framework.common.config.enums.InfConfigEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExcelVO; @@ -24,6 +25,8 @@ public interface InfConfigConvert { InfConfigDO convert(InfConfigUpdateReqVO bean); + InfConfigDO convert(InfConfigEnum bean); + List convertList(List list); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/config/InfConfigDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/config/InfConfigDO.java index 119d069d95..3bdc9d9039 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/config/InfConfigDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/config/InfConfigDO.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -46,7 +45,7 @@ public class InfConfigDO extends BaseDO { /** * 参数类型 * - * 枚举 {@link InfConfigTypeEnum} + * 枚举 {@link cn.iocoder.yudao.framework.common.config.enums.InfConfigTypeEnum} */ @TableField("`type`") private Integer type; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java index 7578e8d529..acd9d9a663 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java @@ -1,24 +1,25 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.config.impl; -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert; -import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; -import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; +import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer; import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; +import cn.iocoder.yudao.framework.common.config.enums.InfConfigEnum; +import cn.iocoder.yudao.framework.common.config.enums.InfConfigTypeEnum; +import cn.iocoder.yudao.framework.common.config.util.InfConfigUtil; +import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; - import java.util.List; import java.util.Objects; @@ -66,12 +67,22 @@ public class InfConfigServiceImpl implements InfConfigService { public void updateValueByKey(String key, String value) { InfConfigDO config = configMapper.selectByKey(key); if (Objects.isNull(config)) { - throw ServiceExceptionUtil.exception(CONFIG_NOT_EXISTS); + InfConfigEnum initConfigEnum = InfConfigUtil.getInitConfigEnum(key); + if(Objects.isNull(initConfigEnum)){ + throw ServiceExceptionUtil.exception(CONFIG_NOT_EXISTS); + }else{ + //初始化配置 + InfConfigDO convert = InfConfigConvert.INSTANCE.convert(initConfigEnum); + convert.setValue(value); + configMapper.insert(convert); + } + }else { + InfConfigDO updateDo = new InfConfigDO(); + updateDo.setId(config.getId()); + updateDo.setValue(value); + configMapper.updateById(updateDo); } - InfConfigDO updateDo = new InfConfigDO(); - updateDo.setId(config.getId()); - updateDo.setValue(value); - configMapper.updateById(updateDo); + // 发送刷新消息 configProducer.sendConfigRefreshMessage(); } diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigServiceTest.java index 4ef105df3f..9c35b24bc8 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigServiceTest.java @@ -1,16 +1,16 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.config; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; -import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer; import cn.iocoder.yudao.adminserver.modules.infra.service.config.impl.InfConfigServiceImpl; +import cn.iocoder.yudao.framework.common.config.enums.InfConfigTypeEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import org.junit.jupiter.api.Test; @@ -23,9 +23,9 @@ import java.util.function.Consumer; import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.times; diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/errorcode/SysErrorCodeServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/errorcode/SysErrorCodeServiceTest.java index f5dbc71089..9fb8880e5b 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/errorcode/SysErrorCodeServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/errorcode/SysErrorCodeServiceTest.java @@ -1,9 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.system.service.errorcode; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.adminserver.modules.tool.framework.errorcode.core.dto.ErrorCodeAutoGenerateReqDTO; -import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.controller.errorcode.vo.SysErrorCodeCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.errorcode.vo.SysErrorCodeExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.errorcode.vo.SysErrorCodePageReqVO; @@ -12,6 +9,9 @@ import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.errorcode.SysE import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.errorcode.SysErrorCodeMapper; import cn.iocoder.yudao.adminserver.modules.system.enums.errorcode.SysErrorCodeTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.service.errorcode.impl.SysErrorCodeServiceImpl; +import cn.iocoder.yudao.adminserver.modules.tool.framework.errorcode.core.dto.ErrorCodeAutoGenerateReqDTO; +import cn.iocoder.yudao.framework.common.config.enums.InfConfigTypeEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import org.assertj.core.util.Lists; @@ -27,9 +27,9 @@ import java.util.function.Consumer; import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.ERROR_CODE_DUPLICATE; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.ERROR_CODE_NOT_EXISTS; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; import static org.junit.jupiter.api.Assertions.*; diff --git a/yudao-admin-ui/src/components/LogSwitch/index.vue b/yudao-admin-ui/src/components/LogSwitch/index.vue new file mode 100644 index 0000000000..5d5836185d --- /dev/null +++ b/yudao-admin-ui/src/components/LogSwitch/index.vue @@ -0,0 +1,68 @@ + + + diff --git a/yudao-admin-ui/src/main.js b/yudao-admin-ui/src/main.js index 78ab14f775..eaf5307013 100644 --- a/yudao-admin-ui/src/main.js +++ b/yudao-admin-ui/src/main.js @@ -33,6 +33,9 @@ import { import Pagination from "@/components/Pagination"; // 自定义表格工具扩展 import RightToolbar from "@/components/RightToolbar" + +import LogSwitch from "@/components/LogSwitch"; + // 代码高亮插件 // import hljs from 'highlight.js' // import 'highlight.js/styles/github-gist.css' @@ -73,6 +76,7 @@ Vue.prototype.msgInfo = function (msg) { // 全局组件挂载 Vue.component('Pagination', Pagination) Vue.component('RightToolbar', RightToolbar) +Vue.component('LogSwitch', LogSwitch) Vue.use(permission) // Vue.use(hljs.vuePlugin); diff --git a/yudao-admin-ui/src/utils/constants.js b/yudao-admin-ui/src/utils/constants.js index 36f24907b2..4c9ed5bdaa 100644 --- a/yudao-admin-ui/src/utils/constants.js +++ b/yudao-admin-ui/src/utils/constants.js @@ -72,6 +72,6 @@ export const InfApiErrorLogProcessStatusEnum = { */ export const InfConfigKeyEnum = { API_LOG_KEY: 'yudao.web.api.log.enable', - DONE: 1, - IGNORE: 2, + API_ERROR_LOG_KEY: 'yudao.web.api.error.log.enable', + OPERATE_LOG_KEY: 'yudao.operate.log.enable', } \ No newline at end of file diff --git a/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue b/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue index 8fee22d00d..d620e321b9 100644 --- a/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue +++ b/yudao-admin-ui/src/views/infra/apiAccessLog/index.vue @@ -36,16 +36,14 @@ - - - - 导出 + + + @@ -120,12 +118,8 @@