Merge pull request #1007 from dataease/pr@dev@feat_basic_setting

feat: 增加超时时间配置
This commit is contained in:
fit2cloud-chenyw 2021-10-22 15:08:41 +08:00 committed by GitHub
commit 1e4b40dd23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 356 additions and 43 deletions

View File

@ -56,7 +56,7 @@ public class ShiroServiceImpl implements ShiroService {
// filterChainDefinitionMap.put("/axios.map", ANON);
filterChainDefinitionMap.put("/api/auth/login", ANON);
// filterChainDefinitionMap.put("/api/auth/logout", ANON);
filterChainDefinitionMap.put("/system/requestTimeOut", ANON);
filterChainDefinitionMap.put("/api/auth/validateName", ANON);
filterChainDefinitionMap.put("/api/auth/isOpenLdap", ANON);
filterChainDefinitionMap.put("/api/auth/isOpenOidc", ANON);

View File

@ -109,6 +109,18 @@ public interface ParamConstants {
}
}
enum BASIC implements ParamConstants {
FRONT_TIME_OUT("basic.frontTimeOut"),
MSG_TIME_OUT("basic.msgTimeOut");
private String value;
public String getValue() {
return this.value;
}
private BASIC(String value) {
this.value = value;
}
}
enum BASE implements ParamConstants {
URL("base.url");

View File

@ -2,10 +2,13 @@ package io.dataease.controller.sys;
import io.dataease.base.domain.SystemParameter;
import io.dataease.commons.constants.ParamConstants;
import io.dataease.controller.sys.response.BasicInfo;
import io.dataease.controller.sys.response.MailInfo;
import io.dataease.dto.SystemParameterDTO;
import io.dataease.service.FileService;
import io.dataease.service.system.SystemParameterService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@ -35,11 +38,27 @@ public class SystemParameterController {
return systemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue());
}
@GetMapping("/basic/info")
public BasicInfo basicInfo() {
return systemParameterService.basicInfo();
}
@GetMapping("/requestTimeOut")
public Integer RequestTimeOut() {
BasicInfo basicInfo = systemParameterService.basicInfo();
return StringUtils.isNotBlank(basicInfo.getFrontTimeOut()) ? Integer.parseInt(basicInfo.getFrontTimeOut()) : 10;
}
@PostMapping("/edit/email")
public void editMail(@RequestBody List<SystemParameter> systemParameter) {
systemParameterService.editMail(systemParameter);
}
@PostMapping("/edit/basic")
public void editBasic(@RequestBody List<SystemParameter> systemParameter) {
systemParameterService.editBasic(systemParameter);
}
@PostMapping("/testConnection")
public void testConnection(@RequestBody HashMap<String, String> hashMap) {
systemParameterService.testConnection(hashMap);
@ -77,4 +96,6 @@ public class SystemParameterController {
}
}

View File

@ -0,0 +1,16 @@
package io.dataease.controller.sys.response;
import java.io.Serializable;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class BasicInfo implements Serializable{
@ApiModelProperty("请求超时时间")
private String frontTimeOut;
@ApiModelProperty("消息保留时间")
private String msgTimeOut;
}

View File

@ -16,14 +16,16 @@ import io.dataease.controller.sys.request.MsgSettingRequest;
import io.dataease.controller.sys.response.MsgGridDto;
import io.dataease.controller.sys.response.SettingTreeNode;
import io.dataease.controller.sys.response.SubscribeNode;
import io.dataease.service.system.SystemParameterService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -31,7 +33,7 @@ import java.util.stream.Collectors;
@Service
public class SysMsgService {
private static final long overDays = 30;
private static int overDays = 30;
@Resource
private SysMsgMapper sysMsgMapper;
@ -50,6 +52,9 @@ public class SysMsgService {
@Resource
private SysMsgSettingMapper sysMsgSettingMapper;
@Autowired
private SystemParameterService systemParameterService;
public List<SysMsg> query(Long userId, MsgRequest msgRequest) {
String orderClause = " create_time desc";
SysMsgExample example = new SysMsgExample();
@ -330,6 +335,10 @@ public class SysMsgService {
public Long overTime() {
String msgTimeOut = systemParameterService.basicInfo().getMsgTimeOut();
if(StringUtils.isNotBlank(msgTimeOut)) {
overDays = Integer.parseInt(msgTimeOut);
}
Long currentTime = System.currentTimeMillis();
long oneDayTime = 24 * 60 * 60 * 1000;

View File

@ -10,6 +10,7 @@ import io.dataease.commons.exception.DEException;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.commons.utils.EncryptUtils;
import io.dataease.commons.utils.LogUtil;
import io.dataease.controller.sys.response.BasicInfo;
import io.dataease.controller.sys.response.MailInfo;
import io.dataease.dto.SystemParameterDTO;
import io.dataease.i18n.Translator;
@ -47,6 +48,24 @@ public class SystemParameterService {
return extSystemParameterMapper.email();
}
public BasicInfo basicInfo() {
List<SystemParameter> paramList = this.getParamList("basic");
BasicInfo result = new BasicInfo();
if (!CollectionUtils.isEmpty(paramList)) {
for (SystemParameter param : paramList) {
if (StringUtils.equals(param.getParamKey(), ParamConstants.BASIC.FRONT_TIME_OUT.getValue())) {
/* result.setFrontTimeOut(StringUtils.isBlank(param.getParamValue()) ? 0 : Integer.parseInt(param.getParamValue())); */
result.setFrontTimeOut(param.getParamValue());
}
if (StringUtils.equals(param.getParamKey(), ParamConstants.BASIC.MSG_TIME_OUT.getValue())) {
/* result.setMsgTimeOut(StringUtils.isBlank(param.getParamValue()) ? 0 : Integer.parseInt(param.getParamValue())); */
result.setMsgTimeOut(param.getParamValue());
}
}
}
return result;
}
public MailInfo mailInfo(String type) {
List<SystemParameter> paramList = this.getParamList(type);
@ -89,6 +108,8 @@ public class SystemParameterService {
return result;
}
public void editMail(List<SystemParameter> parameters) {
List<SystemParameter> paramList = this.getParamList(ParamConstants.Classify.MAIL.getValue());
boolean empty = paramList.size() <= 0;
@ -112,6 +133,21 @@ public class SystemParameterService {
});
}
public void editBasic(List<SystemParameter> parameters) {
parameters.forEach(parameter -> {
SystemParameterExample example = new SystemParameterExample();
example.createCriteria().andParamKeyEqualTo(parameter.getParamKey());
if (systemParameterMapper.countByExample(example) > 0) {
systemParameterMapper.updateByPrimaryKey(parameter);
} else {
systemParameterMapper.insert(parameter);
}
example.clear();
});
}
public List<SystemParameter> getParamList(String type) {
SystemParameterExample example = new SystemParameterExample();
example.createCriteria().andParamKeyLike(type + "%");

View File

@ -7,5 +7,5 @@ UPDATE `chart_view` SET `render` = 'antv' WHERE `type` = 'liquid';
ALTER TABLE `panel_link` ADD COLUMN `over_time` bigint(13) NULL DEFAULT NULL COMMENT '有效截止时间' AFTER `pwd`;
BEGIN;
INSERT INTO `sys_menu` VALUES (6, 1, 0, 1, '系统参数', 'system-param', 'system/SysParam/index', 6, 'sys-tools', 'system-param', b'0', b'0', b'0', NULL, NULL, NULL, NULL, NULL);
INSERT INTO `sys_menu` VALUES (6, 1, 0, 1, '系统参数', 'system-param', 'system/SysParam/index', 6, 'sys-tools', 'system-param', b'0', b'0', b'0', 'sysparam:read', NULL, NULL, NULL, NULL);
COMMIT;

View File

@ -5,11 +5,12 @@
</template>
<script>
export default {
name: 'App',
beforeCreate() {
// document.body.className = 'blackTheme'
}
}
</script>

View File

@ -0,0 +1,19 @@
import request from '@/utils/request'
export function basicInfo() {
return request({
url: '/system/basic/info',
method: 'get',
loading: true
})
}
export function updateInfo(data) {
return request({
url: '/system/edit/basic',
method: 'post',
loading: true,
data
})
}

View File

@ -606,6 +606,11 @@ export default {
mailbox_service_settings: 'Mail Settings',
test_connection: 'Test connection',
SMTP_host: 'SMTP Host',
basic_setting: 'Basic setting',
front_time_out: 'Request timeOut(unit: second, Attention: Refresh browser takes effect after saving)',
msg_time_out: 'Message retention time(unit: day)',
empty_front: 'If empty then default value is 10s',
empty_msg: 'If empty then default value is 30 days',
SMTP_port: 'SMTP Port',
SMTP_account: 'SMTP Account',
SMTP_password: 'SMTP Password',

View File

@ -608,6 +608,11 @@ export default {
mailbox_service_settings: '郵件設置',
test_connection: '測試連接',
SMTP_host: 'SMTP主機',
basic_setting: '基礎設置',
front_time_out: '請求超時時間(單位:秒, 注意:保存後刷新瀏覽器生效)',
msg_time_out: '消息保留時間(單位:天)',
empty_front: '為空則默認取值10秒',
empty_msg: '為空則默認取值30天',
SMTP_port: 'SMTP端口',
SMTP_account: 'SMTP賬戶',
SMTP_password: 'SMTP密碼',

View File

@ -608,6 +608,13 @@ export default {
mailbox_service_settings: '邮件设置',
test_connection: '测试连接',
SMTP_host: 'SMTP主机',
basic_setting: '基础设置',
front_time_out: '请求超时时间(单位:秒, 注意:保存后刷新浏览器生效)',
msg_time_out: '消息保留时间(单位:天)',
empty_front: '为空则默认取10秒',
empty_msg: '为空则默认取30天',
front_error: '请填写0-100正整数',
msg_error: '请填写正整数',
SMTP_port: 'SMTP端口',
SMTP_account: 'SMTP账户',
SMTP_password: 'SMTP密码',
@ -1500,7 +1507,8 @@ export default {
i18n_msg_type_dataset_sync_faild: '数据集同步失败',
i18n_msg_type_ds_invalid: '数据源失效',
i18n_msg_type_all: '全部类型',
channel_inner_msg: '站内消息'
channel_inner_msg: '站内消息',
channel_email_msg: '邮件'
},
denumberrange: {
label: '数值区间',

View File

@ -48,3 +48,8 @@ export function getSysUI() {
return json ? JSON.parse(json) : null
}
export function getTimeOut() {
const val = Cookies.get('request-time-out')
return val
}

View File

@ -12,11 +12,42 @@ import { getLinkToken, setLinkToken } from '@/utils/auth'
const TokenKey = Config.TokenKey
const RefreshTokenKey = Config.RefreshTokenKey
const LinkTokenKey = Config.LinkTokenKey
import Cookies from 'js-cookie'
// create an axios instance
const service = axios.create({
const getTimeOut = () => {
let time = 10
const url = '/system/requestTimeOut'
const xhr = new XMLHttpRequest()
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
if (xhr.responseText) {
try {
const response = JSON.parse(xhr.responseText)
if (response.success) {
Cookies.set('request-time-out', response.data)
time = response.data
} else {
$error('系统异常,请联系管理员')
}
} catch (e) {
$error('系统异常,请联系管理员')
}
} else {
$error('网络异常,请联系网管')
}
}
}
xhr.open('get', url, false)
xhr.send()
return time
}
const time = getTimeOut()
let service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests
timeout: 10000 // request timeout
timeout: time ? time * 1000 : 10000
})
// request interceptor
@ -60,13 +91,36 @@ service.interceptors.request.use(
}
)
// const defaultOptions = {
// confirmButtonText: i18n.t('login.re_login')
// }
service.setTimeOut = time => {
service = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
timeout: time
})
}
// 请根据实际需求修改
service.interceptors.response.use(response => {
response.config.loading && tryHideLoading(store.getters.currentPath)
checkAuth(response)
return response.data
}, error => {
const config = error.response && error.response.config || error.config
const headers = error.response && error.response.headers || error.response || config.headers
config.loading && tryHideLoading(store.getters.currentPath)
let msg
if (error.response) {
checkAuth(error.response)
// checkPermission(error.response)
msg = error.response.data.message || error.response.data
} else {
msg = error.message
}
!config.hideMsg && (!headers['authentication-status']) && $error(msg)
return Promise.reject(error)
})
const checkAuth = response => {
// 请根据实际需求修改
if (response.headers['authentication-status'] === 'login_expire') {
const message = i18n.t('login.expires')
// store.dispatch('user/setLoginMsg', message)
@ -103,31 +157,5 @@ const checkAuth = response => {
setLinkToken(linkToken)
store.dispatch('user/setLinkToken', linkToken)
}
// 许可状态改变 刷新页面
// if (response.headers['lic-status']) {
// location.reload()
// }
}
// 请根据实际需求修改
service.interceptors.response.use(response => {
response.config.loading && tryHideLoading(store.getters.currentPath)
checkAuth(response)
return response.data
}, error => {
const config = error.response && error.response.config || error.config
const headers = error.response && error.response.headers || error.response || config.headers
config.loading && tryHideLoading(store.getters.currentPath)
let msg
if (error.response) {
checkAuth(error.response)
// checkPermission(error.response)
msg = error.response.data.message || error.response.data
} else {
msg = error.message
}
!config.hideMsg && (!headers['authentication-status']) && $error(msg)
return Promise.reject(error)
})
export default service

View File

@ -0,0 +1,144 @@
<template>
<div>
<!--基础配置表单-->
<el-form
ref="formInline"
v-loading="loading"
:model="formInline"
:rules="rules"
class="demo-form-inline"
:disabled="show"
size="small"
>
<el-row>
<el-col>
<el-form-item :label="$t('system_parameter_setting.front_time_out')" prop="frontTimeOut">
<el-input
v-model="formInline.frontTimeOut"
:placeholder="$t('system_parameter_setting.empty_front')"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('system_parameter_setting.msg_time_out')" prop="msgTimeOut">
<el-input
v-model="formInline.msgTimeOut"
:placeholder="$t('system_parameter_setting.empty_msg')"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div>
<el-button v-if="showEdit" size="small" @click="edit">{{ $t('commons.edit') }}</el-button>
<el-button v-if="showSave" type="success" :disabled="disabledSave" size="small" @click="save('formInline')">
{{ $t('commons.save') }}
</el-button>
<el-button v-if="showCancel" type="info" size="small" @click="cancel">{{ $t('commons.cancel') }}</el-button>
</div>
</div>
</template>
<script>
import { basicInfo, updateInfo } from '@/api/system/basic'
export default {
name: 'EmailSetting',
data() {
return {
formInline: {},
input: '',
visible: true,
showEdit: true,
showSave: false,
showCancel: false,
show: true,
disabledSave: false,
loading: false,
rules: {
frontTimeOut: [
{
pattern: '^([0-9]{1,2}|100)$',
message: this.$t('system_parameter_setting.front_error'),
trigger: 'blur'
}
],
msgTimeOut: [
{
pattern: '^[0-9]*$',
message: this.$t('system_parameter_setting.msg_error'),
trigger: 'blur'
}
]
}
}
},
created() {
this.query()
},
methods: {
query() {
basicInfo().then(response => {
this.formInline = response.data
this.$nextTick(() => {
this.$refs.formInline.clearValidate()
})
})
},
edit() {
this.showEdit = false
this.showSave = true
this.showCancel = true
this.show = false
},
save(formInline) {
this.showEdit = true
this.showCancel = false
this.showSave = false
this.show = true
const param = [
{ paramKey: 'basic.frontTimeOut', paramValue: this.formInline.frontTimeOut, type: 'text', sort: 1 },
{ paramKey: 'basic.msgTimeOut', paramValue: this.formInline.msgTimeOut, type: 'text', sort: 2 }
]
this.$refs[formInline].validate(valid => {
if (valid) {
updateInfo(param).then(response => {
const flag = response.success
if (flag) {
this.$success(this.$t('commons.save_success'))
window.location.reload()
} else {
this.$message.error(this.$t('commons.save_failed'))
}
})
} else {
// this.result = false
}
})
},
cancel() {
this.showEdit = true
this.showCancel = false
this.showSave = false
this.show = true
this.query()
}
}
}
</script>
<style scoped>
</style>

View File

@ -2,6 +2,10 @@
<layout-content v-loading="$store.getters.loadingMap[$store.getters.currentPath]">
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane :lazy="true" :label="$t('system_parameter_setting.basic_setting')" name="zero">
<basic-setting />
</el-tab-pane>
<el-tab-pane :lazy="true" :label="$t('system_parameter_setting.mailbox_service_settings')" name="first">
<email-setting />
</el-tab-pane>
@ -22,17 +26,17 @@
</layout-content>
</template>
<script>
import BasicSetting from './BasicSetting'
import EmailSetting from './EmailSetting'
import LayoutContent from '@/components/business/LayoutContent'
import PluginCom from '@/views/system/plugin/PluginCom'
import { pluginLoaded } from '@/api/user'
export default {
components: { EmailSetting, LayoutContent, PluginCom },
components: { BasicSetting, EmailSetting, LayoutContent, PluginCom },
data() {
return {
activeName: 'first',
activeName: 'zero',
isPluginLoaded: false
}
},