Pre Merge pull request !31 from syd/feature/switchLog

This commit is contained in:
syd 2021-09-28 01:23:49 +00:00 committed by Gitee
commit 5639c72607
25 changed files with 356 additions and 39 deletions

View File

@ -1,13 +1,15 @@
package cn.iocoder.yudao.adminserver.modules.infra.controller.config; 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.iocoder.yudao.adminserver.modules.infra.controller.config.vo.*; 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.convert.config.InfConfigConvert;
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; 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.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;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -18,13 +20,15 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.io.IOException; import java.io.IOException;
import java.util.List; 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; 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.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; 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 = "参数配置") @Api(tags = "参数配置")
@RestController @RestController
@ -67,13 +71,28 @@ public class InfConfigController {
return success(InfConfigConvert.INSTANCE.convert(configService.getConfig(id))); return success(InfConfigConvert.INSTANCE.convert(configService.getConfig(id)));
} }
@PutMapping("/update-value-by-key")
@ApiOperation(value = "根据参数键名修改参数值")
@PreAuthorize("@ss.hasPermission('infra:config:updateValueByKey')")
public CommonResult<Boolean> updateValueByKey(@NotBlank(message = "key 不允许为空") String key, String value) {
configService.updateValueByKey(key,value);
return success(true);
}
@GetMapping(value = "/get-value-by-key") @GetMapping(value = "/get-value-by-key")
@ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端") @ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端")
@ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class) @ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class)
public CommonResult<String> getConfigKey(@RequestParam("key") String key) { public CommonResult<String> getConfigKey(@RequestParam("key") String key) {
InfConfigDO config = configService.getConfigByKey(key); InfConfigDO config = configService.getConfigByKey(key);
if (config == null) { 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()) { if (config.getSensitive()) {
throw exception(CONFIG_GET_VALUE_ERROR_IF_SENSITIVE); throw exception(CONFIG_GET_VALUE_ERROR_IF_SENSITIVE);

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.infra.convert.config; 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.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.InfConfigCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExcelVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExcelVO;
@ -24,6 +25,8 @@ public interface InfConfigConvert {
InfConfigDO convert(InfConfigUpdateReqVO bean); InfConfigDO convert(InfConfigUpdateReqVO bean);
InfConfigDO convert(InfConfigEnum bean);
List<InfConfigExcelVO> convertList(List<InfConfigDO> list); List<InfConfigExcelVO> convertList(List<InfConfigDO> list);
} }

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config; package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; 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.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; 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`") @TableField("`type`")
private Integer type; private Integer type;

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config; 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.InfConfigExportReqVO;
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; 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.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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;

View File

@ -32,6 +32,13 @@ public interface InfConfigService {
*/ */
void updateConfig(@Valid InfConfigUpdateReqVO reqVO); 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<InfConfigDO> getConfigList(@Valid InfConfigExportReqVO reqVO); List<InfConfigDO> getConfigList(@Valid InfConfigExportReqVO reqVO);
} }

View File

@ -1,25 +1,27 @@
package cn.iocoder.yudao.adminserver.modules.infra.service.config.impl; 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.InfConfigCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; 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.InfConfigPageReqVO;
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; 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.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.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.mq.producer.config.InfConfigProducer;
import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; 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 com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Objects;
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.*; import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.*;
@ -61,6 +63,30 @@ public class InfConfigServiceImpl implements InfConfigService {
configProducer.sendConfigRefreshMessage(); configProducer.sendConfigRefreshMessage();
} }
@Override
public void updateValueByKey(String key, String value) {
InfConfigDO config = configMapper.selectByKey(key);
if (Objects.isNull(config)) {
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);
}
// 发送刷新消息
configProducer.sendConfigRefreshMessage();
}
@Override @Override
public void deleteConfig(Long id) { public void deleteConfig(Long id) {
// 校验配置存在 // 校验配置存在

View File

@ -1,16 +1,16 @@
package cn.iocoder.yudao.adminserver.modules.infra.service.config; package cn.iocoder.yudao.adminserver.modules.infra.service.config;
import cn.iocoder.yudao.adminserver.BaseDbUnitTest; 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.InfConfigCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; 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.InfConfigPageReqVO;
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; 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.dataobject.config.InfConfigDO;
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; 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.mq.producer.config.InfConfigProducer;
import cn.iocoder.yudao.adminserver.modules.infra.service.config.impl.InfConfigServiceImpl; 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.collection.ArrayUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import org.junit.jupiter.api.Test; 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.hutool.core.util.RandomUtil.randomEle;
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.*; 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.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; 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 cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;

View File

@ -1,9 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.system.service.errorcode; package cn.iocoder.yudao.adminserver.modules.system.service.errorcode;
import cn.iocoder.yudao.adminserver.BaseDbUnitTest; 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.SysErrorCodeCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.system.controller.errorcode.vo.SysErrorCodeExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.errorcode.vo.SysErrorCodeExportReqVO;
import cn.iocoder.yudao.adminserver.modules.system.controller.errorcode.vo.SysErrorCodePageReqVO; 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.dal.mysql.errorcode.SysErrorCodeMapper;
import cn.iocoder.yudao.adminserver.modules.system.enums.errorcode.SysErrorCodeTypeEnum; 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.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.collection.ArrayUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import org.assertj.core.util.Lists; 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.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_DUPLICATE;
import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.ERROR_CODE_NOT_EXISTS; 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.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; 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 cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;

View File

@ -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) { export function delConfig(configId) {
return request({ return request({

View File

@ -0,0 +1,68 @@
<template>
<el-button :type="type" plain :icon="icon" size="mini" @click="enableHandler" v-show="finish"
v-hasPermi="permissions">{{content}}</el-button>
</template>
<script>
import { updateValueByKey } from "@/api/infra/config";
export default {
name: 'LogSwitch',
data() {
return {
enable: false,
finish: false,
}
},
props: {
configKey: {
required: true,
type: String
},
closeText: {
type: String,
default: '关闭'
},
openText: {
type: String,
default: '开启'
},
permissions: {
type: Array,
default: []
}
},
computed: {
type() {
return this.enable?'info':'primary'
},
icon() {
return this.enable?'el-icon-close':'el-icon-check'
},
content() {
return this.enable?this.closeText:this.openText
},
},
created() {
this.getEnableConfig();
},
methods: {
//
enableHandler(){
let data = new FormData();
data.append("key",this.configKey);
data.append("value",this.enable?false:true);
updateValueByKey(data).then(response => {
this.msgSuccess(this.content+"成功");
this.getEnableConfig();
})
},
getEnableConfig(){
this.getConfigKey(this.configKey).then(response => {
this.enable = (response.data == "true");
this.finish = true
})
},
}
}
</script>

View File

@ -33,11 +33,14 @@ import {
import Pagination from "@/components/Pagination"; import Pagination from "@/components/Pagination";
// 自定义表格工具扩展 // 自定义表格工具扩展
import RightToolbar from "@/components/RightToolbar" import RightToolbar from "@/components/RightToolbar"
import LogSwitch from "@/components/LogSwitch";
// 代码高亮插件 // 代码高亮插件
// import hljs from 'highlight.js' // import hljs from 'highlight.js'
// import 'highlight.js/styles/github-gist.css' // import 'highlight.js/styles/github-gist.css'
import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict"; import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict";
import { InfConfigKeyEnum } from '@/utils/constants';
// 全局方法挂载 // 全局方法挂载
Vue.prototype.getDicts = getDicts Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey Vue.prototype.getConfigKey = getConfigKey
@ -49,6 +52,7 @@ Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.getDictDatas = getDictDatas Vue.prototype.getDictDatas = getDictDatas
Vue.prototype.getDictDataLabel = getDictDataLabel Vue.prototype.getDictDataLabel = getDictDataLabel
Vue.prototype.DICT_TYPE = DICT_TYPE Vue.prototype.DICT_TYPE = DICT_TYPE
Vue.prototype.InfConfigKeyEnum = InfConfigKeyEnum
Vue.prototype.download = download Vue.prototype.download = download
Vue.prototype.downloadExcel = downloadExcel Vue.prototype.downloadExcel = downloadExcel
Vue.prototype.downloadWord = downloadWord Vue.prototype.downloadWord = downloadWord
@ -72,6 +76,7 @@ Vue.prototype.msgInfo = function (msg) {
// 全局组件挂载 // 全局组件挂载
Vue.component('Pagination', Pagination) Vue.component('Pagination', Pagination)
Vue.component('RightToolbar', RightToolbar) Vue.component('RightToolbar', RightToolbar)
Vue.component('LogSwitch', LogSwitch)
Vue.use(permission) Vue.use(permission)
// Vue.use(hljs.vuePlugin); // Vue.use(hljs.vuePlugin);

View File

@ -66,3 +66,12 @@ export const InfApiErrorLogProcessStatusEnum = {
DONE: 1, // 已处理 DONE: 1, // 已处理
IGNORE: 2, // 已忽略 IGNORE: 2, // 已忽略
} }
/**
*
*/
export const InfConfigKeyEnum = {
API_LOG_KEY: 'yudao.web.api.log.enable',
API_ERROR_LOG_KEY: 'yudao.web.api.error.log.enable',
OPERATE_LOG_KEY: 'yudao.operate.log.enable',
}

View File

@ -40,6 +40,10 @@
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
v-hasPermi="['infra:api-access-log:export']">导出</el-button> v-hasPermi="['infra:api-access-log:export']">导出</el-button>
</el-col> </el-col>
<el-col :span="1.5">
<log-switch :config-key="InfConfigKeyEnum.API_LOG_KEY"
:permissions="['infra:api-access-log:export']" open-text="开启日志" close-text="关闭日志"/>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
@ -114,11 +118,8 @@
<script> <script>
import { getApiAccessLogPage, exportApiAccessLogExcel } from "@/api/infra/apiAccessLog"; import { getApiAccessLogPage, exportApiAccessLogExcel } from "@/api/infra/apiAccessLog";
export default { export default {
name: "ApiAccessLog", name: "ApiAccessLog",
components: {
},
data() { data() {
return { return {
// //
@ -212,4 +213,4 @@ export default {
} }
} }
}; };
</script> </script>

View File

@ -40,6 +40,10 @@
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
v-hasPermi="['infra:api-error-log:export']">导出</el-button> v-hasPermi="['infra:api-error-log:export']">导出</el-button>
</el-col> </el-col>
<el-col :span="1.5">
<log-switch :config-key="InfConfigKeyEnum.API_ERROR_LOG_KEY"
:permissions="['infra:api-access-log:export']" open-text="开启异常日志" close-text="关闭异常日志"/>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>

View File

@ -36,6 +36,10 @@
<el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
v-hasPermi="['system:operate-log:export']">导出</el-button> v-hasPermi="['system:operate-log:export']">导出</el-button>
</el-col> </el-col>
<el-col :span="1.5">
<log-switch :config-key="InfConfigKeyEnum.OPERATE_LOG_KEY" open-text="开启操作日志" close-text="关闭操作日志"
:permissions="['infra:api-access-log:export']"/>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>

View File

@ -32,6 +32,11 @@
<artifactId>spring-aop</artifactId> <artifactId>spring-aop</artifactId>
<scope>provided</scope> <!-- 设置为 provided只有工具类需要使用到 --> <scope>provided</scope> <!-- 设置为 provided只有工具类需要使用到 -->
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>provided</scope> <!-- 设置为 provided只有工具类需要使用到 -->
</dependency>
<dependency> <dependency>
<groupId>org.aspectj</groupId> <groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId> <artifactId>aspectjweaver</artifactId>

View File

@ -0,0 +1,13 @@
package cn.iocoder.yudao.framework.common.config.enums;
/**
* @author syidong@aliyun.com
* @date 2021/5/12 23:07
*/
public interface ConfigGroupConstants {
/**
* log 开关组名
*/
String CONFIG_LOG_SWITCH_KEY_GROUP = "config.log.switch.key.group";
}

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.framework.common.config.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author syidong@aliyun.com
* @date 2021/5/12 22:57
*/
@AllArgsConstructor
@Getter
public enum InfConfigEnum {
YUDAO_WEB_API_LOG_ENABLE_CONFIG("是否开启apiLog key"
,"yudao.web.api.log.enable"
,Boolean.TRUE.toString()
,ConfigGroupConstants.CONFIG_LOG_SWITCH_KEY_GROUP
,InfConfigTypeEnum.SYSTEM.getType()
,Boolean.FALSE
,"api log 是否开启配置")
,YUDAO_WEB_API_ERROR_LOG_ENABLE_CONFIG("是否开启api error log 日志 key"
,"yudao.web.api.error.log.enable"
,Boolean.TRUE.toString()
,ConfigGroupConstants.CONFIG_LOG_SWITCH_KEY_GROUP
,InfConfigTypeEnum.SYSTEM.getType()
,Boolean.FALSE
,"api error log 是否开启配置")
,YUDAO_OPERATE_LOG_ENABLE_CONFIG("是否开启operateLog key"
,"yudao.operate.log.enable"
,Boolean.TRUE.toString()
,ConfigGroupConstants.CONFIG_LOG_SWITCH_KEY_GROUP
,InfConfigTypeEnum.SYSTEM.getType()
,Boolean.FALSE
,"api error log 是否开启配置");
private final String name;
private final String key;
private final String value;
private final String group;
private Integer type;
private Boolean sensitive;
private String remark;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.infra.enums.config; package cn.iocoder.yudao.framework.common.config.enums;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;

View File

@ -0,0 +1,45 @@
package cn.iocoder.yudao.framework.common.config.util;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.config.enums.InfConfigEnum;
import java.util.HashMap;
import static cn.iocoder.yudao.framework.common.config.enums.InfConfigEnum.*;
/**
* @author syidong@aliyun.com
* @date 2021/5/13 0:26
*/
public class InfConfigUtil {
private static final HashMap<String, InfConfigEnum> INIT_CONFIG = new HashMap<>();
static {
INIT_CONFIG.put(YUDAO_WEB_API_LOG_ENABLE_CONFIG.getKey(),YUDAO_WEB_API_LOG_ENABLE_CONFIG);
INIT_CONFIG.put(YUDAO_WEB_API_ERROR_LOG_ENABLE_CONFIG.getKey(),YUDAO_WEB_API_ERROR_LOG_ENABLE_CONFIG);
INIT_CONFIG.put(YUDAO_OPERATE_LOG_ENABLE_CONFIG.getKey(),YUDAO_OPERATE_LOG_ENABLE_CONFIG);
}
public static InfConfigEnum getInitConfigEnum(String key) {
return INIT_CONFIG.get(key);
}
public static boolean isEnable(String key) {
String enable = SpringUtil.getProperty(key);
return Boolean.parseBoolean(StrUtil.isBlank(enable)?Boolean.TRUE.toString():enable);
}
public static boolean apiLogEnable() {
return isEnable(YUDAO_WEB_API_LOG_ENABLE_CONFIG.getKey());
}
public static boolean apiErrorLogEnable() {
return isEnable(YUDAO_WEB_API_ERROR_LOG_ENABLE_CONFIG.getKey());
}
public static boolean operateLogEnable() {
return isEnable(YUDAO_OPERATE_LOG_ENABLE_CONFIG.getKey());
}
}

View File

@ -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}";
}

View File

@ -4,6 +4,8 @@ import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import cn.iocoder.yudao.framework.common.config.util.InfConfigUtil;
import cn.iocoder.yudao.framework.common.enums.ConfigKeyConstants;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO;
@ -21,6 +23,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
@ -86,6 +89,10 @@ public class OperateLogAspect {
try { try {
// 执行原有方法 // 执行原有方法
Object result = joinPoint.proceed(); Object result = joinPoint.proceed();
// 是否记录操作日志
if(!InfConfigUtil.operateLogEnable()){
return result;
}
// 记录正常执行时的操作日志 // 记录正常执行时的操作日志
this.log(joinPoint, operateLog, apiOperation, startTime, result, null); this.log(joinPoint, operateLog, apiOperation, startTime, result, null);
return result; return result;

View File

@ -135,7 +135,8 @@ public class DBConfigRepository extends AbstractConfigRepository {
private Properties buildProperties(List<ConfigRespDTO> configs) { private Properties buildProperties(List<ConfigRespDTO> configs) {
Properties properties = propertiesFactory.getPropertiesInstance(); Properties properties = propertiesFactory.getPropertiesInstance();
configs.stream().filter(ConfigRespDTO::getDeleted) // 过滤掉被删除的配置 // 过滤掉被删除的配置
configs.stream().filter(item -> !item.getDeleted())
.forEach(config -> properties.put(config.getKey(), config.getValue())); .forEach(config -> properties.put(config.getKey(), config.getValue()));
return properties; return properties;
} }

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.framework.apollo.spring.boot; package cn.iocoder.yudao.framework.apollo.spring.boot;
import cn.iocoder.yudao.framework.apollo.core.ConfigConsts; import cn.iocoder.yudao.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.boot.env.EnvironmentPostProcessor;

View File

@ -2,17 +2,21 @@ package cn.iocoder.yudao.framework.apilog.core.filter;
import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService; import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO;
import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.config.util.InfConfigUtil;
import cn.iocoder.yudao.framework.web.config.WebProperties; import cn.iocoder.yudao.framework.common.enums.ConfigKeyConstants;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; 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.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; 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.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.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.filter.OncePerRequestFilter;
@ -25,6 +29,7 @@ import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
/** /**
* API 访问日志 Filter * API 访问日志 Filter
* *
@ -57,11 +62,17 @@ public class ApiAccessLogFilter extends OncePerRequestFilter {
try { try {
// 继续过滤器 // 继续过滤器
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
// 正常执行记录日志 // api log 开关
createApiAccessLog(request, beginTim, queryString, requestBody, null); if(InfConfigUtil.apiLogEnable()){
// 正常执行记录日志
createApiAccessLog(request, beginTim, queryString, requestBody, null);
}
} catch (Exception ex) { } catch (Exception ex) {
// 异常执行记录日志 // api log异常日志开关
createApiAccessLog(request, beginTim, queryString, requestBody, ex); if(InfConfigUtil.apiErrorLogEnable()){
// 异常执行记录日志
createApiAccessLog(request, beginTim, queryString, requestBody, ex);
}
throw ex; throw ex;
} }
} }