diff --git a/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java b/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java index 529cdb16af..0687144638 100644 --- a/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java +++ b/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java @@ -7,6 +7,7 @@ import io.dataease.base.mapper.*; import io.dataease.base.mapper.ext.ExtDataSourceMapper; import io.dataease.base.mapper.ext.query.GridExample; import io.dataease.commons.exception.DEException; +import io.dataease.commons.model.AuthURD; import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.CommonThreadPool; import io.dataease.commons.utils.LogUtil; @@ -25,6 +26,8 @@ import io.dataease.dto.dataset.DataTableInfoDTO; import io.dataease.exception.DataEaseException; import io.dataease.i18n.Translator; import io.dataease.service.dataset.DataSetGroupService; +import io.dataease.service.message.DeMsgutil; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -34,7 +37,10 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.UUID; @Service @@ -238,7 +244,8 @@ public class DatasourceService { public void updateDatasourceStatus(){ List datasources = datasourceMapper.selectByExampleWithBLOBs(new DatasourceExample()); datasources.forEach(datasource -> { - checkAndUpdateDatasourceStatus(datasource); + // checkAndUpdateDatasourceStatus(datasource); + checkAndUpdateDatasourceStatus(datasource, true); }); } @@ -255,4 +262,43 @@ public class DatasourceService { datasourceMapper.updateByPrimaryKeySelective(datasource); } } + + private void checkAndUpdateDatasourceStatus(Datasource datasource, Boolean withMsg){ + try { + DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType()); + DatasourceRequest datasourceRequest = new DatasourceRequest(); + datasourceRequest.setDatasource(datasource); + datasourceProvider.checkStatus(datasourceRequest); + datasource.setStatus("Success"); + datasourceMapper.updateByPrimaryKeySelective(datasource); + } catch (Exception e) { + Datasource temp = datasourceMapper.selectByPrimaryKey(datasource.getId()); + datasource.setStatus("Error"); + if (!StringUtils.equals(temp.getStatus(), "Error")) { + sendWebMsg(datasource); + datasourceMapper.updateByPrimaryKeySelective(datasource); + } + + } + } + + + private void sendWebMsg(Datasource datasource) { + + String id = datasource.getId(); + AuthURD authURD = AuthUtils.authURDR(id); + Set userIds = AuthUtils.userIdsByURD(authURD); + Long typeId = 8L;// 代表数据源失效 + Gson gson = new Gson(); + userIds.forEach(userId -> { + Map param = new HashMap<>(); + param.put("id", id); + param.put("name", datasource.getName()); + + + String content = "数据源【" + datasource.getName() + "】无效"; + + DeMsgutil.sendMsg(userId, typeId, 1L, content, gson.toJson(param)); + }); + } } diff --git a/backend/src/main/resources/db/migration/V26__de1.3.sql b/backend/src/main/resources/db/migration/V26__de1.3.sql new file mode 100644 index 0000000000..ef59aa58cb --- /dev/null +++ b/backend/src/main/resources/db/migration/V26__de1.3.sql @@ -0,0 +1,7 @@ +-- ---------------------------- +-- Records of sys_msg_type +-- ---------------------------- +BEGIN; +INSERT INTO `sys_msg_type` VALUES (7, 0, 'i18n_msg_type_ds_invalid', 'datasource', 'to-msg-ds'); +INSERT INTO `sys_msg_type` VALUES (8, 7, 'i18n_msg_type_ds_invalid', 'datasource', 'to-msg-ds'); +COMMIT; \ No newline at end of file diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 5cb0caf85a..cd87e7173b 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -1361,6 +1361,7 @@ export default { i18n_msg_type_dataset_sync_success: 'Dataset synchronization successful', i18n_msg_type_dataset_sync_faild: 'Dataset synchronization failed', i18n_msg_type_all: 'All type', + i18n_msg_type_ds_invalid: 'Datasource invalid', channel_inner_msg: 'On site news' }, denumberrange: { diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 18808a6284..3142165b89 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -1359,6 +1359,7 @@ export default { i18n_msg_type_dataset_sync: '數據集同步', i18n_msg_type_dataset_sync_success: '數據集同步成功', i18n_msg_type_dataset_sync_faild: '數據集同步失敗', + i18n_msg_type_ds_invalid: '數據源失效', i18n_msg_type_all: '全部類型', channel_inner_msg: '站內消息' }, diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index fdc3dbea72..b243e71fa4 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -1362,6 +1362,7 @@ export default { i18n_msg_type_dataset_sync: '数据集同步', i18n_msg_type_dataset_sync_success: '数据集同步成功', i18n_msg_type_dataset_sync_faild: '数据集同步失败', + i18n_msg_type_ds_invalid: '数据源失效', i18n_msg_type_all: '全部类型', channel_inner_msg: '站内消息' }, diff --git a/frontend/src/views/system/datasource/DsMain.vue b/frontend/src/views/system/datasource/DsMain.vue index 87f68ca22c..c2bc1495aa 100644 --- a/frontend/src/views/system/datasource/DsMain.vue +++ b/frontend/src/views/system/datasource/DsMain.vue @@ -55,6 +55,9 @@ export default { }, refreshTree() { this.$refs.dsTree && this.$refs.dsTree.queryTreeDatas() + }, + msg2Current(sourceParam) { + this.$refs.dsTree && this.$refs.dsTree.markInvalid(sourceParam) } } } diff --git a/frontend/src/views/system/datasource/DsTree.vue b/frontend/src/views/system/datasource/DsTree.vue index a0ebafc2d9..b6e13d60c7 100644 --- a/frontend/src/views/system/datasource/DsTree.vue +++ b/frontend/src/views/system/datasource/DsTree.vue @@ -41,11 +41,11 @@ - - - {{ data.name }} - - + + + {{ data.name }} + + @@ -129,6 +129,11 @@ export default { const newArr = [] for (let index = 0; index < array.length; index++) { const element = array[index] + if (this.msgNodeId) { + if (element.id === this.msgNodeId) { + element.msgNode = true + } + } if (!(element.type in types)) { types[element.type] = [] // newArr.push(...element, ...{ children: types[element.type] }) @@ -147,7 +152,7 @@ export default { return 'SQL Server' } else if (type === 'oracle') { return 'Oracle' - }else if (type === 'pg') { + } else if (type === 'pg') { return 'PostgreSQL' } }, @@ -208,6 +213,21 @@ export default { component, componentParam }) + }, + markInvalid(msgParam) { + const param = JSON.parse(msgParam) + const msgNodeId = param.id + this.msgNodeId = msgNodeId + this.$nextTick(() => { + this.tData.forEach(folder => { + const nodes = folder.children + nodes.forEach(node => { + if (node.id === msgNodeId) { + node.msgNode = true + } + }) + }) + }) } } } @@ -303,4 +323,10 @@ export default { height: 100%; overflow-y: auto; } + .msg-node-class { + color: red; + >>> i{ + color: red; + } + } diff --git a/frontend/src/views/system/datasource/index.vue b/frontend/src/views/system/datasource/index.vue index 8dce7dc8d3..1e0d024244 100644 --- a/frontend/src/views/system/datasource/index.vue +++ b/frontend/src/views/system/datasource/index.vue @@ -1,7 +1,7 @@ @@ -10,7 +10,7 @@ import DeMainContainer from '@/components/dataease/DeMainContainer' import DeContainer from '@/components/dataease/DeContainer' import DsMain from './DsMain' - +import bus from '@/utils/bus' export default { name: 'Panel', components: { DeMainContainer, DeContainer, DsMain }, @@ -22,10 +22,36 @@ export default { } }, mounted() { - + bus.$on('to-msg-ds', params => { + this.toMsgDs(params) + }) + }, + created() { + this.$store.dispatch('app/toggleSideBarHide', true) + const routerParam = this.$router.currentRoute.params + this.toMsgDs(routerParam) }, methods: { - + toMsgDs(routerParam) { + if (routerParam !== null && routerParam.msgNotification) { + const panelShareTypeIds = [7, 8] + // 说明是从消息通知跳转过来的 + if (panelShareTypeIds.includes(routerParam.msgType)) { // 是数据集同步 + if (routerParam.sourceParam) { + try { + // const msgParam = JSON.parse(routerParam.sourceParam) + // this.param = msgParam.id + // this.component = ViewTable + this.$nextTick(() => { + this.$refs.dsMain && this.$refs.dsMain.msg2Current && this.$refs.dsMain.msg2Current(routerParam.sourceParam) + }) + } catch (error) { + console.error(error) + } + } + } + } + } } }