diff --git a/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java index aecb307469..05b437a764 100644 --- a/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java +++ b/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java @@ -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); diff --git a/backend/src/main/java/io/dataease/commons/constants/ParamConstants.java b/backend/src/main/java/io/dataease/commons/constants/ParamConstants.java index f075b5149c..745b7e274a 100644 --- a/backend/src/main/java/io/dataease/commons/constants/ParamConstants.java +++ b/backend/src/main/java/io/dataease/commons/constants/ParamConstants.java @@ -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"); diff --git a/backend/src/main/java/io/dataease/controller/sys/SystemParameterController.java b/backend/src/main/java/io/dataease/controller/sys/SystemParameterController.java index 39a34846c7..799c69e045 100644 --- a/backend/src/main/java/io/dataease/controller/sys/SystemParameterController.java +++ b/backend/src/main/java/io/dataease/controller/sys/SystemParameterController.java @@ -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) { systemParameterService.editMail(systemParameter); } + @PostMapping("/edit/basic") + public void editBasic(@RequestBody List systemParameter) { + systemParameterService.editBasic(systemParameter); + } + @PostMapping("/testConnection") public void testConnection(@RequestBody HashMap hashMap) { systemParameterService.testConnection(hashMap); @@ -77,4 +96,6 @@ public class SystemParameterController { } + + } diff --git a/backend/src/main/java/io/dataease/controller/sys/response/BasicInfo.java b/backend/src/main/java/io/dataease/controller/sys/response/BasicInfo.java new file mode 100644 index 0000000000..19df51477f --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/sys/response/BasicInfo.java @@ -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; + +} diff --git a/backend/src/main/java/io/dataease/service/message/SysMsgService.java b/backend/src/main/java/io/dataease/service/message/SysMsgService.java index 5e587b1fb9..a15cf4101f 100644 --- a/backend/src/main/java/io/dataease/service/message/SysMsgService.java +++ b/backend/src/main/java/io/dataease/service/message/SysMsgService.java @@ -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 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; diff --git a/backend/src/main/java/io/dataease/service/system/SystemParameterService.java b/backend/src/main/java/io/dataease/service/system/SystemParameterService.java index ead28b0c6a..0e3c77a4bc 100644 --- a/backend/src/main/java/io/dataease/service/system/SystemParameterService.java +++ b/backend/src/main/java/io/dataease/service/system/SystemParameterService.java @@ -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 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 paramList = this.getParamList(type); @@ -89,6 +108,8 @@ public class SystemParameterService { return result; } + + public void editMail(List parameters) { List paramList = this.getParamList(ParamConstants.Classify.MAIL.getValue()); boolean empty = paramList.size() <= 0; @@ -112,6 +133,21 @@ public class SystemParameterService { }); } + public void editBasic(List 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 getParamList(String type) { SystemParameterExample example = new SystemParameterExample(); example.createCriteria().andParamKeyLike(type + "%"); diff --git a/backend/src/main/resources/db/migration/V27__de1.4.sql b/backend/src/main/resources/db/migration/V27__de1.4.sql index bc80aa04ef..75098407a6 100644 --- a/backend/src/main/resources/db/migration/V27__de1.4.sql +++ b/backend/src/main/resources/db/migration/V27__de1.4.sql @@ -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; \ No newline at end of file diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 9aaba1031a..66a91a15c0 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -5,11 +5,12 @@ diff --git a/frontend/src/api/system/basic.js b/frontend/src/api/system/basic.js new file mode 100644 index 0000000000..21d30b7bc6 --- /dev/null +++ b/frontend/src/api/system/basic.js @@ -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 + + }) +} diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 68b3a24ce7..27fd8c95d1 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -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', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 90bae6cee2..e4a8ce9497 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -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密碼', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 66da4cb2ad..9125c205b9 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -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: '数值区间', diff --git a/frontend/src/utils/auth.js b/frontend/src/utils/auth.js index dbefb1bcb2..e8093dcd03 100644 --- a/frontend/src/utils/auth.js +++ b/frontend/src/utils/auth.js @@ -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 +} + diff --git a/frontend/src/utils/request.js b/frontend/src/utils/request.js index 7495787389..1d0a00cf50 100644 --- a/frontend/src/utils/request.js +++ b/frontend/src/utils/request.js @@ -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 diff --git a/frontend/src/views/system/SysParam/BasicSetting.vue b/frontend/src/views/system/SysParam/BasicSetting.vue new file mode 100644 index 0000000000..b71c23e7cc --- /dev/null +++ b/frontend/src/views/system/SysParam/BasicSetting.vue @@ -0,0 +1,144 @@ + + + + + diff --git a/frontend/src/views/system/SysParam/index.vue b/frontend/src/views/system/SysParam/index.vue index 9d163a9d73..737a170bad 100644 --- a/frontend/src/views/system/SysParam/index.vue +++ b/frontend/src/views/system/SysParam/index.vue @@ -2,6 +2,10 @@ + + + + @@ -22,17 +26,17 @@