Merge pull request #13633 from dataease/pr@dev-v2@perf_del_auto_sync
perf: 删除自动同步游离资源逻辑
This commit is contained in:
commit
46c66b2395
@ -1,12 +0,0 @@
|
|||||||
package io.dataease.rmonitor.bo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class PerMonitorCheckBO implements Serializable {
|
|
||||||
|
|
||||||
private boolean valid;
|
|
||||||
|
|
||||||
private boolean emptyPermission;
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
package io.dataease.rmonitor.bo;
|
|
||||||
|
|
||||||
import io.dataease.model.TreeBaseModel;
|
|
||||||
import io.dataease.model.TreeResultModel;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class PerMonitorNodeBO implements TreeBaseModel<PerMonitorNodeBO>, TreeResultModel<PerMonitorNodeBO>, Serializable {
|
|
||||||
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private Long pid;
|
|
||||||
|
|
||||||
private boolean leaf;
|
|
||||||
|
|
||||||
private int extraFlag;
|
|
||||||
|
|
||||||
private List<PerMonitorNodeBO> children;
|
|
||||||
}
|
|
||||||
@ -1,120 +0,0 @@
|
|||||||
package io.dataease.rmonitor.manage;
|
|
||||||
|
|
||||||
import io.dataease.constant.DataSourceType;
|
|
||||||
import io.dataease.exception.DEException;
|
|
||||||
import io.dataease.rmonitor.bo.PerMonitorCheckBO;
|
|
||||||
import io.dataease.rmonitor.bo.PerMonitorNodeBO;
|
|
||||||
import io.dataease.rmonitor.mapper.ResourceMonitorMapper;
|
|
||||||
import io.dataease.rmonitor.mapper.entity.DatasetFreeResource;
|
|
||||||
import io.dataease.rmonitor.mapper.entity.DsFreeResource;
|
|
||||||
import io.dataease.rmonitor.mapper.entity.VisualFreeResource;
|
|
||||||
import io.dataease.utils.BeanUtils;
|
|
||||||
import io.dataease.utils.TreeUtils;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.apache.commons.collections4.MapUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Component("resourceMonitorManage")
|
|
||||||
public class ResourceMonitorManage {
|
|
||||||
|
|
||||||
|
|
||||||
@Resource(name = "resourceMonitorSyncManage")
|
|
||||||
private ResourceMonitorSyncManage resourceMonitorSyncManage;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ResourceMonitorMapper resourceMonitorMapper;
|
|
||||||
|
|
||||||
|
|
||||||
private boolean existFreeResource() {
|
|
||||||
int rCount = resourceMonitorMapper.dsCount() + resourceMonitorMapper.datasetCount() + resourceMonitorMapper.vCount();
|
|
||||||
return rCount > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, List<PerMonitorNodeBO>> freeResource() {
|
|
||||||
Map<String, List<PerMonitorNodeBO>> result = new HashMap<>();
|
|
||||||
|
|
||||||
List<DsFreeResource> dsFreeResources = resourceMonitorMapper.queryFreeDs();
|
|
||||||
if (CollectionUtils.isNotEmpty(dsFreeResources)) {
|
|
||||||
List<PerMonitorNodeBO> dsBos = dsFreeResources.stream().map(node -> {
|
|
||||||
PerMonitorNodeBO bo = BeanUtils.copyBean(new PerMonitorNodeBO(), node);
|
|
||||||
bo.setLeaf(!StringUtils.equals("folder", node.getType()));
|
|
||||||
bo.setExtraFlag(DataSourceType.valueOf(node.getType()).getFlag());
|
|
||||||
return bo;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
List<PerMonitorNodeBO> dsTree = TreeUtils.mergeTree(dsBos, PerMonitorNodeBO.class, false);
|
|
||||||
result.put("datasource", dsTree);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<DatasetFreeResource> datasetFreeResources = resourceMonitorMapper.queryFreeDataset();
|
|
||||||
if (CollectionUtils.isNotEmpty(datasetFreeResources)) {
|
|
||||||
List<PerMonitorNodeBO> datasetBos = datasetFreeResources.stream().map(node -> {
|
|
||||||
PerMonitorNodeBO bo = BeanUtils.copyBean(new PerMonitorNodeBO(), node);
|
|
||||||
bo.setLeaf(!StringUtils.equals("folder", node.getNodeType()));
|
|
||||||
return bo;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
List<PerMonitorNodeBO> datasetTree = TreeUtils.mergeTree(datasetBos, PerMonitorNodeBO.class, false);
|
|
||||||
result.put("dataset", datasetTree);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<VisualFreeResource> visualFreeResources = resourceMonitorMapper.queryFreeVusial();
|
|
||||||
if (CollectionUtils.isNotEmpty(visualFreeResources)) {
|
|
||||||
Map<String, List<VisualFreeResource>> baseMap = visualFreeResources.stream().collect(Collectors.groupingBy(VisualFreeResource::getType));
|
|
||||||
for (Map.Entry<String, List<VisualFreeResource>> entry : baseMap.entrySet()) {
|
|
||||||
List<VisualFreeResource> freeResource = entry.getValue();
|
|
||||||
List<PerMonitorNodeBO> visualBos = freeResource.stream().map(node -> {
|
|
||||||
PerMonitorNodeBO bo = BeanUtils.copyBean(new PerMonitorNodeBO(), node);
|
|
||||||
bo.setLeaf(!StringUtils.equals("folder", node.getNodeType()));
|
|
||||||
return bo;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
result.put(convertBusiFlag(entry.getKey()), TreeUtils.mergeTree(visualBos, PerMonitorNodeBO.class, false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String convertBusiFlag(String key) {
|
|
||||||
if (StringUtils.equals("dashboard", key)) {
|
|
||||||
return "panel";
|
|
||||||
} else if (StringUtils.equals("dataV", key)) {
|
|
||||||
return "screen";
|
|
||||||
} else return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean check() {
|
|
||||||
PerMonitorCheckBO checkBO = resourceMonitorSyncManage.checkXpackResource();
|
|
||||||
return checkBO.isValid() && checkBO.isEmptyPermission() && existFreeResource();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void delete() {
|
|
||||||
boolean existFree = existFreeResource();
|
|
||||||
if (!existFree) DEException.throwException("无未同步资源!");
|
|
||||||
resourceMonitorMapper.delFreeDs();
|
|
||||||
resourceMonitorMapper.delFreeDataset();
|
|
||||||
resourceMonitorMapper.delFreeVisual();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sync() {
|
|
||||||
//1、从xpack获取资源 如果xpack不存在 或者资源不为空 则直接返回 并且抛出异常“仅支持首次导入lic同步”
|
|
||||||
//2、从core获取资源
|
|
||||||
//3、根据类型分组 并组织成树形结构
|
|
||||||
//4、分别遍历每一棵树 从上到下 同步到权限体系 给默认组织
|
|
||||||
PerMonitorCheckBO checkBO = resourceMonitorSyncManage.checkXpackResource();
|
|
||||||
if (!checkBO.isValid()) DEException.throwException("缺少许可证");
|
|
||||||
if (!checkBO.isEmptyPermission()) DEException.throwException("仅支持license首次导入同步");
|
|
||||||
Map<String, List<PerMonitorNodeBO>> freeResourceMap = freeResource();
|
|
||||||
if (MapUtils.isEmpty(freeResourceMap)) DEException.throwException("无未同步资源!");
|
|
||||||
for (Map.Entry<String, List<PerMonitorNodeBO>> entry : freeResourceMap.entrySet()) {
|
|
||||||
resourceMonitorSyncManage.sync(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
package io.dataease.rmonitor.manage;
|
|
||||||
|
|
||||||
import io.dataease.exception.DEException;
|
|
||||||
import io.dataease.license.config.XpackInteract;
|
|
||||||
import io.dataease.rmonitor.bo.PerMonitorCheckBO;
|
|
||||||
import io.dataease.rmonitor.bo.PerMonitorNodeBO;
|
|
||||||
import io.dataease.rmonitor.mapper.ResourceMonitorMapper;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Component("resourceMonitorSyncManage")
|
|
||||||
public class ResourceMonitorSyncManage {
|
|
||||||
|
|
||||||
@Resource(name = "resourceMonitorMapper")
|
|
||||||
private ResourceMonitorMapper resourceMonitorMapper;
|
|
||||||
|
|
||||||
@XpackInteract(value = "resourceMonitorSyncManage", replace = true)
|
|
||||||
public void sync(String flag, List<PerMonitorNodeBO> treeNodes) {
|
|
||||||
DEException.throwException("缺失许可证");
|
|
||||||
}
|
|
||||||
|
|
||||||
@XpackInteract(value = "resourceMonitorSyncManage", replace = true)
|
|
||||||
public PerMonitorCheckBO checkXpackResource() {
|
|
||||||
return new PerMonitorCheckBO();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
package io.dataease.rmonitor.mapper;
|
|
||||||
|
|
||||||
import io.dataease.rmonitor.mapper.entity.DatasetFreeResource;
|
|
||||||
import io.dataease.rmonitor.mapper.entity.DsFreeResource;
|
|
||||||
import io.dataease.rmonitor.mapper.entity.VisualFreeResource;
|
|
||||||
import org.apache.ibatis.annotations.Delete;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface ResourceMonitorMapper {
|
|
||||||
|
|
||||||
@Select("select count(id) from core_datasource")
|
|
||||||
int dsCount();
|
|
||||||
|
|
||||||
@Select("select count(id) from core_dataset_group")
|
|
||||||
int datasetCount();
|
|
||||||
|
|
||||||
@Select("select count(id) from data_visualization_info where delete_flag = 0 and pid != -1")
|
|
||||||
int vCount();
|
|
||||||
|
|
||||||
@Select("select id, name, pid, type, status from core_datasource")
|
|
||||||
List<DsFreeResource> queryFreeDs();
|
|
||||||
|
|
||||||
@Select("select id, name, pid, node_type from core_dataset_group")
|
|
||||||
List<DatasetFreeResource> queryFreeDataset();
|
|
||||||
|
|
||||||
@Select("select id, name, pid, node_type, type from data_visualization_info where delete_flag = 0 and pid != -1")
|
|
||||||
List<VisualFreeResource> queryFreeVusial();
|
|
||||||
|
|
||||||
@Delete("delete from core_datasource")
|
|
||||||
void delFreeDs();
|
|
||||||
|
|
||||||
@Delete("delete from core_dataset_group")
|
|
||||||
void delFreeDataset();
|
|
||||||
@Delete("delete from data_visualization_info")
|
|
||||||
void delFreeVisual();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
package io.dataease.rmonitor.mapper.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class BaseFreeResource implements Serializable {
|
|
||||||
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private Long pid;
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
package io.dataease.rmonitor.mapper.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class DatasetFreeResource extends BaseFreeResource implements Serializable {
|
|
||||||
|
|
||||||
private String nodeType;
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package io.dataease.rmonitor.mapper.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class DsFreeResource extends BaseFreeResource implements Serializable {
|
|
||||||
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
private String status;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
package io.dataease.rmonitor.mapper.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class VisualFreeResource extends BaseFreeResource implements Serializable {
|
|
||||||
|
|
||||||
private String nodeType;
|
|
||||||
|
|
||||||
private String type;
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
package io.dataease.rmonitor.server;
|
|
||||||
|
|
||||||
import io.dataease.api.rmonitor.ResourceMonitorApi;
|
|
||||||
import io.dataease.rmonitor.manage.ResourceMonitorManage;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/rmonitor")
|
|
||||||
public class ResourceMonitorServer implements ResourceMonitorApi {
|
|
||||||
|
|
||||||
@Resource(name = "resourceMonitorManage")
|
|
||||||
private ResourceMonitorManage resourceMonitorManage;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean existFree() {
|
|
||||||
return resourceMonitorManage.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete() {
|
|
||||||
resourceMonitorManage.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sync() {
|
|
||||||
resourceMonitorManage.sync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,7 +3,3 @@ import request from '@/config/axios'
|
|||||||
export const validateApi = data => request.post({ url: '/license/validate', data })
|
export const validateApi = data => request.post({ url: '/license/validate', data })
|
||||||
export const buildVersionApi = () => request.get({ url: '/license/version' })
|
export const buildVersionApi = () => request.get({ url: '/license/version' })
|
||||||
export const updateInfoApi = data => request.post({ url: '/license/update', data })
|
export const updateInfoApi = data => request.post({ url: '/license/update', data })
|
||||||
|
|
||||||
export const checkFreeApi = () => request.get({ url: '/rmonitor/existFree' })
|
|
||||||
export const syncFreeApi = () => request.post({ url: '/rmonitor/sync' })
|
|
||||||
export const delFreeApi = () => request.post({ url: '/rmonitor/delete' })
|
|
||||||
|
|||||||
@ -1,18 +1,11 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import logo from '@/assets/svg/logo.svg'
|
import logo from '@/assets/svg/logo.svg'
|
||||||
import aboutBg from '@/assets/img/about-bg.png'
|
import aboutBg from '@/assets/img/about-bg.png'
|
||||||
import { ref, reactive, onMounted, h } from 'vue'
|
import { ref, reactive, onMounted } from 'vue'
|
||||||
import { useUserStoreWithOut } from '@/store/modules/user'
|
import { useUserStoreWithOut } from '@/store/modules/user'
|
||||||
import { F2CLicense } from './index'
|
import { F2CLicense } from './index'
|
||||||
import {
|
import { validateApi, buildVersionApi, updateInfoApi } from '@/api/about'
|
||||||
validateApi,
|
import { ElMessage } from 'element-plus-secondary'
|
||||||
buildVersionApi,
|
|
||||||
updateInfoApi,
|
|
||||||
checkFreeApi,
|
|
||||||
syncFreeApi,
|
|
||||||
delFreeApi
|
|
||||||
} from '@/api/about'
|
|
||||||
import { ElMessage, ElMessageBox, Action } from 'element-plus-secondary'
|
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useEmitt } from '@/hooks/web/useEmitt'
|
import { useEmitt } from '@/hooks/web/useEmitt'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useCache } from '@/hooks/web/useCache'
|
||||||
@ -129,65 +122,11 @@ const update = (licKey: string) => {
|
|||||||
ElMessage.success(t('about.update_success'))
|
ElMessage.success(t('about.update_success'))
|
||||||
const info = getLicense(response.data)
|
const info = getLicense(response.data)
|
||||||
setLicense(info)
|
setLicense(info)
|
||||||
checkFree()
|
|
||||||
} else {
|
} else {
|
||||||
ElMessage.warning(response.data.message)
|
ElMessage.warning(response.data.message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const autoSync = ref(true)
|
|
||||||
const checkFree = () => {
|
|
||||||
checkFreeApi().then(res => {
|
|
||||||
if (res.data) {
|
|
||||||
if (autoSync.value) {
|
|
||||||
syncFree()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// do something
|
|
||||||
const title = '存在未同步的资源数据,请谨慎操作!'
|
|
||||||
const childrenDomList = [h('strong', null, title)]
|
|
||||||
ElMessageBox.confirm('', {
|
|
||||||
confirmButtonType: 'primary',
|
|
||||||
type: 'warning',
|
|
||||||
autofocus: false,
|
|
||||||
dangerouslyUseHTMLString: true,
|
|
||||||
message: h('div', { class: 'free-sync-tip-box' }, childrenDomList),
|
|
||||||
showClose: false,
|
|
||||||
cancelButtonText: '删除',
|
|
||||||
cancelButtonClass: 'free-cancel-bt',
|
|
||||||
showCancelButton: false,
|
|
||||||
preButtonType: 'danger',
|
|
||||||
preButtonText: '删除',
|
|
||||||
showPreButton: true,
|
|
||||||
confirmButtonText: '同步',
|
|
||||||
callback: (action: Action) => {
|
|
||||||
if (action === 'confirm') {
|
|
||||||
syncFree()
|
|
||||||
} else {
|
|
||||||
delFree
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const delFree = () => {
|
|
||||||
delFreeApi().then(res => {
|
|
||||||
if (!res.code && !res.msg) {
|
|
||||||
ElMessage.success(t('common.delete_success'))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const syncFree = () => {
|
|
||||||
syncFreeApi().then(res => {
|
|
||||||
if (!res.code && !res.msg) {
|
|
||||||
ElMessage.success('同步成功')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
2
de-xpack
2
de-xpack
@ -1 +1 @@
|
|||||||
Subproject commit d0056943de6199f78d70b52b66174786e4d56519
|
Subproject commit 3860aabdc1f8ba63fc8bef4d20b926ff9a9d1633
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package io.dataease.api.rmonitor;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
|
|
||||||
public interface ResourceMonitorApi {
|
|
||||||
|
|
||||||
@GetMapping("/existFree")
|
|
||||||
boolean existFree();
|
|
||||||
|
|
||||||
@PostMapping("/delete")
|
|
||||||
void delete();
|
|
||||||
|
|
||||||
@PostMapping("/sync")
|
|
||||||
void sync();
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user