Merge pull request #719 from dataease/pr@dev@feat_ds_invalid_msg

feat: 完善数据源失效消息
This commit is contained in:
fit2cloud-chenyw 2021-08-27 17:58:03 +08:00 committed by GitHub
commit 2ff07ba064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 122 additions and 11 deletions

View File

@ -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<Datasource> 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<Long> userIds = AuthUtils.userIdsByURD(authURD);
Long typeId = 8L;// 代表数据源失效
Gson gson = new Gson();
userIds.forEach(userId -> {
Map<String, Object> 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));
});
}
}

View File

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

View File

@ -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: {

View File

@ -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: '站內消息'
},

View File

@ -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: '站内消息'
},

View File

@ -55,6 +55,9 @@ export default {
},
refreshTree() {
this.$refs.dsTree && this.$refs.dsTree.queryTreeDatas()
},
msg2Current(sourceParam) {
this.$refs.dsTree && this.$refs.dsTree.markInvalid(sourceParam)
}
}
}

View File

@ -41,11 +41,11 @@
<svg-icon icon-class="datasource" class="ds-icon-scene" />
</span>
<span v-if="data.status === 'Error'">
<svg-icon icon-class="exclamationmark" class="ds-icon-scene" />
<el-tooltip v-if="data.status === 'Error'" style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;" effect="dark" :content="$t('datasource.in_valid')" placement="right">
<el-button type="text" > {{ data.name }} </el-button>
</el-tooltip>
</span>
<svg-icon icon-class="exclamationmark" class="ds-icon-scene" />
<el-tooltip v-if="data.status === 'Error'" style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;" effect="dark" :content="$t('datasource.in_valid')" placement="right">
<el-button type="text" :style="!!data.msgNode ? {'color': 'red'} : {}"> {{ data.name }} </el-button>
</el-tooltip>
</span>
<span v-if="data.type === 'folder'">
<i class="el-icon-folder" />
</span>
@ -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;
}
}
</style>

View File

@ -1,7 +1,7 @@
<template>
<de-container v-loading="$store.getters.loadingMap[$store.getters.currentPath]" style="background-color: #f7f8fa">
<de-main-container>
<ds-main />
<ds-main ref="dsMain" />
</de-main-container>
</de-container>
</template>
@ -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)
}
}
}
}
}
}
}
</script>