dev_xd
姜玉琦 2025-06-30 18:01:33 +08:00
commit e9e2a003aa
7 changed files with 331 additions and 114 deletions

View File

@ -249,7 +249,7 @@ export default {
}
} else {
const res = await this.$api.bim.getTreeAllLeafChild(checkNode.modelId, checkNode.glid);
let nodes = res.data || [];
let nodes = (res.data || []).map((item) => item.glid);
if (nodes.length > 0) {
if (checked) {
this.visibleList = MergeArray(nodes, this.visibleList);

View File

@ -104,7 +104,90 @@ public class BimModelController {
}
}
@PostMapping("/getModelFeatureInfos/{name}")
public AjaxResult getModelInfos(@PathVariable("name") String name,@RequestBody List<Long> glids) {
if(CollectionUtil.isEmpty(glids)){
return AjaxResult.error("glids is null");
}
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < glids.size(); i++) {
stringBuilder.append("?,");
}
String key="BimModelController.getModelFeatureInfos."+name+"."+stringBuilder.toString();
if(redisService.hasKey(key)){
Object list=redisService.getCacheObject(key);
return AjaxResult.success(list);
}
String placeHolders = stringBuilder.deleteCharAt(stringBuilder.length() - 1)
.toString();
String sql="select * from model_tree where glid in ("+placeHolders+")";
String path=bimDataSource.getDbPath(name);
if(!new File(path).exists()){
return AjaxResult.error("file not found!");
}
try {
DataSource ds = bimDataSource.getDataSource(name);
PreparedStatement pss= ds.getConnection().prepareStatement(sql);
for (int i = 1; i <= glids.size(); i++) {
pss.setLong(i, glids.get(i - 1));
}
ResultSet rs = pss.executeQuery();
List<ModelTreeVo> list = new ArrayList<>();
while (rs.next()) {
ModelTreeVo modelTreeVo = new ModelTreeVo();
modelTreeVo.setId(rs.getLong("id"));
modelTreeVo.setGlid(rs.getString("glid"));
modelTreeVo.setName(rs.getString("name"));
modelTreeVo.setLevel(rs.getInt("level"));
modelTreeVo.setGroupname(rs.getString("groupname"));
modelTreeVo.setExternalId(rs.getString("externalId"));
modelTreeVo.setPGlid(rs.getString("pGlid"));
list.add(modelTreeVo);
}
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
return AjaxResult.success(list);
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
}
}
@GetMapping("/getModelFeatureInfo/{name}")
public AjaxResult getModelFeatureInfo(@PathVariable("name") String name,String externalId) {
String key="BimModelController.getModelFeatureInfo."+name+"."+externalId;
String sql="select * from model_tree where externalId =?";
String path=bimDataSource.getDbPath(name);
if(!new File(path).exists()){
return AjaxResult.error("file not found!");
}
try {
DataSource ds = bimDataSource.getDataSource(name);
PreparedStatement pss= ds.getConnection().prepareStatement(sql);
pss.setString(1,externalId);
ResultSet rs = pss.executeQuery();
List<ModelTreeVo> list = new ArrayList<>();
while (rs.next()) {
ModelTreeVo modelTreeVo = new ModelTreeVo();
modelTreeVo.setId(rs.getLong("id"));
modelTreeVo.setGlid(rs.getString("glid"));
modelTreeVo.setName(rs.getString("name"));
modelTreeVo.setLevel(rs.getInt("level"));
modelTreeVo.setGroupname(rs.getString("groupname"));
modelTreeVo.setExternalId(rs.getString("externalId"));
modelTreeVo.setPGlid(rs.getString("pGlid"));
list.add(modelTreeVo);
}
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
return AjaxResult.success(list);
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
}
}
/**
* model_tree
* @param name
@ -116,7 +199,7 @@ public class BimModelController {
if(StringUtils.isEmpty(name)){
return AjaxResult.error("name is null");
}
String key="BimModelController.getModelTreeAllLeafChild."+name+"."+pid;
String key="BimModelController.getModelTreeAllLeafChildV2."+name+"."+pid;
if(redisService.hasKey(key)){
Object list=redisService.getCacheObject(key);
return AjaxResult.success(list);
@ -131,7 +214,7 @@ public class BimModelController {
" union all\n" +
" select model_tree.* from cao join model_tree on cao.glid = model_tree.pGlid\n" +
" )\n" +
"select glid from cao where externalid<>0";
"select * from cao where externalid<>0";
}
String path=bimDataSource.getDbPath(name);
if(!new File(path).exists()){
@ -144,9 +227,17 @@ public class BimModelController {
pss.setString(1,pid);
}
ResultSet rs = pss.executeQuery();
List<String> list = new ArrayList<>();
List<ModelTreeVo> list = new ArrayList<>();
while (rs.next()) {
list.add(rs.getString("glid"));
ModelTreeVo modelTreeVo = new ModelTreeVo();
//modelTreeVo.setId(rs.getLong("id"));
modelTreeVo.setGlid(rs.getString("glid"));
modelTreeVo.setName(rs.getString("name"));
//modelTreeVo.setLevel(rs.getInt("level"));
modelTreeVo.setGroupname(rs.getString("groupname"));
modelTreeVo.setExternalId(rs.getString("externalId"));
//modelTreeVo.setPGlid(rs.getString("pGlid"));
list.add(modelTreeVo);
}
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
return AjaxResult.success(list);

View File

@ -64,3 +64,18 @@ export function getTreeAllLeafChild(name, pid) {
method: "get",
});
}
export function getModelFeatureInfos(name,glids){
return request({
url: "/manage/bim/modelInfo/getModelFeatureInfos/" + name,
method: "post",
data: glids
});
}
export function getModelFeatureInfo(name,externalId){
return request({
url: "/manage/bim/modelInfo/getModelFeatureInfo/" + name+"?externalId="+externalId,
method: "get"
});
}

View File

@ -405,3 +405,39 @@ export function fileSize(filesize) {
size = size.toFixed(2); // 保留两位小数
return size + " " + unitArr[index];
}
export function MergeArray(arr1, arr2) {
var _arr = new Array();
for (var i = 0; i < arr1.length; i++) {
_arr.push(arr1[i]);
}
for (var i = 0; i < arr2.length; i++) {
var flag = true;
for (var j = 0; j < arr1.length; j++) {
if (arr2[i] == arr1[j]) {
flag = false;
break;
}
}
if (flag) {
_arr.push(arr2[i]);
}
}
return _arr;
}
export function DelArray(array1, array2) {
var result = [];
for (var i = 0; i < array1.length; i++) {
var k = 0;
for (var j = 0; j < array2.length; j++) {
if (array1[i] != array2[j]) {
k++;
if (k == array2.length) {
result.push(array1[i]);
}
}
}
}
return result;
}

View File

@ -247,7 +247,7 @@ export default {
checkNode.modelId,
checkNode.glid
);
let nodes = res.data || [];
let nodes = (res.data || []).map((d) => d.glid);
if (nodes.length > 0) {
if (checked) {
this.visibleList = this.MergeArray(nodes, this.visibleList);

View File

@ -1,10 +1,14 @@
import { modelTreeAllChild } from "@/api/bim/bim";
import { getModelTree, getTreeAllLeafChild } from "@/api/bim/bimModel";
import { getModelTree, getTreeAllLeafChild, getModelFeatureInfo,getModelFeatureInfos } from "@/api/bim/bimModel";
import { MergeArray, DelArray } from "@/utils/index";
import { ElMessage } from "element-plus";
function selectFeature(that, featureId) {
let api = bimSelectionDlgApi;
if (that.selectItems.includes(featureId)) {
let featureInfo = getFeatureInfo(that, featureId);
let tmps = that.selectItems.filter((f) => f.featureId == featureId);
if (tmps.length > 0) {
api.Feature.setColor(featureId, "rgba(255,255,255,1)");
let index = that.selectItems.indexOf(featureId);
let index = that.selectItems.indexOf(tmps[0]);
if (index > -1) {
that.selectItems.splice(index, 1);
}
@ -13,36 +17,20 @@ function selectFeature(that, featureId) {
if (!that.showMode) {
api.Feature.setVisible(featureId, false);
}
that.selectItems.push(featureId);
that.selectItems.push(featureInfo);
}
}
function hideFeatures(that) {
let tmps = that.allBimData.filter((it) => it.id != that.plan.id);
tmps.forEach((it) => {
it.bim.forEach((it) => {
hideFeature(that, it);
});
});
}
function getHideFeatures(that, checkedKeys) {
function getHideFeatures(that) {
let result = [];
let tmps = that.allBimData.filter((it) => it.id != that.plan.id);
tmps.forEach((it) => {
it.bim.forEach((it) => {
result.push(it);
});
that.readlyParts.forEach((d) => {
result.push(d);
});
that.hideFeatures.forEach((d) => {
result.push(d);
});
if (checkedKeys.length > 0) {
tmps = that.allFeatures
.filter((d) => !checkedKeys.includes(d.glid))
.filter((d) => d != "0")
.map((d) => d.featureId);
tmps.forEach((d) => {
result.push(d);
});
}
return result;
}
@ -54,23 +42,82 @@ function hideFeature(that, featureId) {
function selectSingle(that) {
let api = bimSelectionDlgApi;
api.Public.clearHandler();
api.Feature.getByEvent(true, (n) => {
api.Feature.getByEvent(true, async (n) => {
if (n && n["id"]) {
let featureId = n.id;
let modelId = featureId.split("^")[0];
await getServerFeatureInfo(that, featureId);
selectFeature(that, featureId);
}
});
}
//将模型信息转换为构件信息
function convertFeatureInfo(o, modelId) {
o.modelId = modelId;
o.featureId = o.modelId + "^" + o.externalId;
o.name = o.name || "";
o.name = o.name.replaceAll('"', "").replaceAll("'", "").replaceAll("\\", "");
o.info = `[${o.externalId}]${o.groupname}-${o.name}`;
return o;
}
function getFeatureInfo(that, featureId) {
let tmps = that.allFeatures.filter((d) => d.featureId == featureId);
return tmps.length > 0 ? tmps[0] : null;
}
//根据FeatureId获取模型信息并存入allFeatures数组中
async function getServerFeatureInfo(that, featureId) {
if (getFeatureInfo(that, featureId)) {
return;
}
let tmps = featureId.split("^");
if (tmps.length < 2) {
return;
}
let modelId = tmps[0];
let externalId = tmps[1];
let res = await getModelFeatureInfo(modelId, externalId);
convertServerDataToFeatureInfo(that,res,modelId);
}
function convertServerDataToFeatureInfo(that,res,modelId) {
(res.data || []).forEach((o) => {
o = convertFeatureInfo(o, modelId);
if (o.externalId != "0") {
if (!that.allParts.includes(o.featureId)) {
that.allParts.push(o.featureId);
}
}
that.allFeatures.push({
featureId: o.featureId,
info: o.info,
});
});
}
async function getServerFeatureInfos(that,ids){
if(ids.length==0){
return;
}
let tmps = ids[0].split("^");
if (tmps.length < 2) {
return;
}
let modelId = tmps[0];
let externalIds=ids.map((it) => it.split("^")[1]);
let res=await getModelFeatureInfos(modelId,externalIds);
convertServerDataToFeatureInfo(that,res,modelId);
}
function clearAllSelection(that) {
that.$modal.confirm("确定清除所有已选择构件吗?").then(() => {
let api = bimSelectionDlgApi;
that.selectItems.forEach((d) => {
api.Feature.setColor(d, "rgba(255,255,255,1)");
api.Feature.setColor(d.featureId, "rgba(255,255,255,1)");
});
that.selectItems = [];
this.selEl++;
that.selEl++;
});
}
@ -78,9 +125,20 @@ function initBim(that) {
let tmps = that.allBimData.filter((it) => it.id == that.plan.id);
if (tmps.length > 0) {
tmps[0].bim.forEach((it) => {
selectFeature(that, it);
if (that.allFeatures.filter((f) => f.featureId == it.featureId).length == 0) {
that.allFeatures.push(it);
}
selectFeature(that, it.featureId);
});
}
tmps = that.allBimData.filter((it) => it.id != that.plan.id);
tmps.forEach((it) => {
it.bim.forEach((it) => {
if (that.readlyParts.filter((f) => f.featureId == it.featureId).length == 0) {
that.readlyParts.push(it.featureId);
}
});
});
}
function getSelectFeatureIds(that) {
@ -93,11 +151,11 @@ function getSelectFeatureIds(that) {
// 加载部分模型(计划中绑定的模型)
function partLoadModel(that) {
let featureIds = getSelectFeatureIds(that);
let featureInfos = getSelectFeatureIds(that);
let api = bimSelectionDlgApi;
let obj = {};
for (let i = 0; i < featureIds.length; i++) {
let it = featureIds[i];
for (let i = 0; i < featureInfos.length; i++) {
let it = featureInfos[i].featureId;
let tmps = it.split("^");
let modelId = tmps[0];
if (!obj[modelId]) {
@ -109,7 +167,7 @@ function partLoadModel(that) {
let tmps = that.models.filter((it) => it.modelId == modelId);
setTimeout(() => {
that.$refs.tree.setChecked(modelId, true, true);
}, 1000);
}, 3000);
if (tmps.length > 0) {
let url = `${window.config.modelUrl}/Tools/output/model/${modelId}/root.glt`;
that.partLoad = true;
@ -131,12 +189,13 @@ function partLoadModel(that) {
);
}
}
if (featureIds.length == 0) {
if (featureInfos.length == 0) {
setTimeout(() => {
that.$refs.tree.setChecked("root", true, true);
}, 1000);
}, 3000);
loadModels(that);
initBim(that);
let func = () => {
if (that.loadedModelCount == that.models.length) {
setTimeout(() => {
@ -152,83 +211,29 @@ function partLoadModel(that) {
//构建树形数据
function buildTreeData(that) {
that.modelTrees = [
{
title: "项目模型",
level: 0,
type: "root",
key: "root",
children: [],
hadLoad: true,
},
];
that.allFeatures = [];
that.models.forEach((d) => {
let node = {
title: d.modelName,
level: 1,
type: "model",
hasLoad: false,
modelId: d.lightweightName,
key: d.lightweightName,
externalId: "0",
glid: "",
children: [],
data: d,
};
that.modelTrees[0].children.push(node);
getModelFeatures(that, d.lightweightName, node);
getModelFeatures(that, d.lightweightName);
});
that.treeExpendedKeys.push("root");
that.$message.info("模型构件信息加载完成");
}
//获取模型所有构件
function getModelFeatures(that, modelId, node) {
let tmps = that.allBimData.filter((it) => it.id != that.plan.id);
tmps.forEach((it) => {
it.bim.forEach((it) => {
if (!that.readlyParts.includes(it)) {
that.readlyParts.push(it);
}
});
});
function getModelFeatures(that, modelId) {
//获取模型构件
modelTreeAllChild(modelId, "").then((res) => {
let objs = res.data || [];
objs.forEach((o) => {
o.modelId = modelId;
o.featureId = o.modelId + "^" + o.externalId;
o.name = o.name || "";
o.name = o.name.replaceAll('"', "").replaceAll("'", "").replaceAll("\\", "");
o.info = `[${o.externalId}]${o.groupname}-${o.name}`;
if (o.externalId == "0") {
return;
}
o = convertFeatureInfo(o, modelId);
let featureId = o.modelId + "^" + o.externalId;
if (!that.allParts.includes(featureId)) {
that.allParts.push(featureId);
}
that.allFeatures.push(o);
});
that.allFeatures = objs;
let makeTree = (tmps) => {
tmps.forEach((item) => {
item.children = objs.filter((it) => it.pglid == item.glid);
if (item.children.length > 0) {
makeTree(item.children);
}
item.hasLoad = true;
item.title = item.name;
item.key = item.glid;
item.modelId = node.modelId;
});
return tmps;
};
node.children = makeTree(objs.filter((item) => item.level == 0));
that.treeKey++;
console.log("====>", that.allFeatures);
});
that.showParts = that.allParts.filter((it) => !that.hideParts.includes(it));
}
//树上点击事件
@ -259,9 +264,10 @@ function onCheckTree(that, node, event) {
}
}
//根据选择控制构件的隐藏和显示
function setTreeNodeChecked(that, node, event) {
async function setTreeNodeChecked(that, node, event) {
let api = bimSelectionDlgApi;
let checked = event.checkedNodes.includes(node);
console.log("===>", checked, node);
if (node.type == "root") {
if (checked) {
that.models.forEach((it) => {
@ -282,15 +288,48 @@ function setTreeNodeChecked(that, node, event) {
}
} else {
api.Model.original(node.modelId);
console.log("---->", node);
let selFeatureIds = [];
if (node.leaf) {
selFeatureIds = [node.featureId];
} else {
if (!node.leafs) {
let leafs = await getNodeLeafs(that, node);
node.leafs = leafs;
}
selFeatureIds = node.leafs.map((f) => f.featureId);
}
if (checked) {
that.hideFeatures = DelArray(that.hideFeatures, selFeatureIds);
} else {
that.hideFeatures = MergeArray(that.hideFeatures, selFeatureIds);
}
}
setFeatueShowOrHide(that, event.checkedKeys);
setFeatueShowOrHide(that);
}
async function getNodeLeafs(that, node) {
const res = await getTreeAllLeafChild(node.modelId, node.glid);
return (res.data || []).map((f) => {
let o = convertFeatureInfo(f, node.modelId);
if (o.externalId != "0") {
if (!that.allParts.includes(o.featureId)) {
that.allParts.push(o.featureId);
}
}
that.allFeatures.push({
featureId: o.featureId,
info: o.info,
});
return f;
});
}
//处理构件的隐藏和显示
function setFeatueShowOrHide(that, checkedKeys) {
function setFeatueShowOrHide(that) {
let api = bimSelectionDlgApi;
//隐藏构件
let hideFeatures = getHideFeatures(that, checkedKeys);
let hideFeatures = getHideFeatures(that);
api.Feature.setVisible(hideFeatures.join("#"), false);
//标注已选择的构件
@ -323,8 +362,15 @@ function loadModels(that) {
//框选构件
function boxSelection(that) {
let api = bimSelectionDlgApi;
api.Feature.boxSelect((data) => {
data.forEach((featureId) => {
api.Feature.getByEvent(false);
ElMessage.info("右键取消选择")
api.Public.event("RIGHT_CLICK", (res) => {
api.Feature.closeBoxSelect();
that.activeMenu=-1;
});
api.Feature.boxSelect(async (data) => {
await getServerFeatureInfos(that, data);
data.forEach( (featureId) => {
selectFeature(that, featureId);
});
});
@ -333,9 +379,11 @@ function boxSelection(that) {
function hideSelection(that) {
let api = bimSelectionDlgApi;
api.Public.clearHandler();
api.Feature.getByEvent(true, (n) => {
api.Feature.getByEvent(false);
api.Feature.getByEvent(true,async (n) => {
if (n && n["id"]) {
let featureId = n.id;
await getServerFeatureInfo(that, featureId);
that.hideParts.push(featureId);
api.Feature.setVisible(featureId, false);
that.hideEl++;
@ -398,11 +446,34 @@ function getTreeChildren(that, node, resolve) {
it.modelId = data.modelId;
it.type = "data";
it.leaf = +it.externalId != 0;
let o = convertFeatureInfo(it, data.modelId);
if (that.allFeatures.filter((item) => item.featureId == it.featureId).length == 0) {
that.allFeatures.push({
featureId: it.featureId,
info: it.info,
});
}
if (o.externalId != "0") {
if (!that.allParts.includes(o.featureId)) {
that.allParts.push(o.featureId);
}
}
return it;
});
//addToAllFeatures(that, tmps);
resolve(tmps);
});
}
function addToAllFeatures(that, features) {
features.forEach((it) => {
if (!that.allFeatures.has(it.glid)) {
that.allFeatures.push(it);
}
});
}
export default {
selectSingle,
initBim,

View File

@ -26,7 +26,7 @@
</el-tab-pane>
<el-tab-pane label="已关联" name="a2">
<div class="sel-list scroll" :key="selEl">
<div v-for="(it, idx) in getSelectItems(selectItems)" :key="idx" class="div-sel-item">
<div v-for="(it, idx) in selectItems" :key="idx" class="div-sel-item">
<el-tooltip placement="bottom" :content="it.info">
<div class="sel-item-info">{{ it.info }}</div>
</el-tooltip>
@ -131,7 +131,9 @@ export default {
allFeatures: [], //
allParts: [], //ID
showParts: [], //ID
readlyParts: [], //ID
hideParts:[], //ID()
hideFeatures:[],//()
readlyParts: [], //ID()
};
},
beforeDestroy() {
@ -163,7 +165,7 @@ export default {
},
doModeChange() {
let api = bimSelectionDlgApi;
api.Feature.setVisible(this.selectItems.join("#"), this.showMode);
api.Feature.setVisible(this.selectItems.map(f=>f.featureId).join("#"), this.showMode);
},
delSelectItem(idx) {
this.$modal.confirm("确定删除吗?").then(() => {
@ -179,7 +181,7 @@ export default {
},
getSelectItems(items) {
return items.map((it) => {
return { info: it };
return this.allFeatures.find((item) => item.featureId == it);
});
},
doSave() {
@ -241,6 +243,7 @@ export default {
this.treeExpendedKeys = [];
this.allParts = [];
this.hideParts = [];
this.hideFeatures = [];
this.readlyParts = [];
this.allFeatures = [];
this.bimLoaded = false;
@ -364,6 +367,7 @@ export default {
let api = bimSelectionDlgApi;
api.Camera.stopImmersiveRoam();
api.Model.location(api.m_model.keys().toArray()[0]);
api.Feature.getByEvent(false);
api.Plugin.deleteMiniMap();
if (this.viewPoint) {
api.Camera.setViewPort(this.viewPoint);