diff --git a/Backend/Controllers/DeviceImportController.cs b/Backend/Controllers/DeviceImportController.cs index 7b03b95..0a873a8 100644 --- a/Backend/Controllers/DeviceImportController.cs +++ b/Backend/Controllers/DeviceImportController.cs @@ -800,9 +800,6 @@ namespace Backend.Controllers device.Add("@forge_dbid", idfc.forge_dbid); await backendRepository.UpdateOneByCustomTable(device, "device", $@" device_number = '{idfc.device_number}'"); } - - - } } apiResult.Code = "0000"; @@ -823,5 +820,91 @@ namespace Backend.Controllers return apiResult; } + + /// + /// 更新forge_room room_id(dbid), room_name + /// + /// + [HttpPost] + public async Task> ImportForgeRoom([FromBody] List post) + { + ApiResult apiResult = new ApiResult(); + //var device_guid_record = ""; + try + { + if (post != null) + { + if (post.Count > 0) + { + //清空device_node資料表 + await backendRepository.TruncateTable("forge_room"); + + foreach (var idfc in post) + { + // var room_name_arr = idfc.room_name.Split('_'); + string full_name = idfc.room_name; + char first = full_name[0]; + if (first != 'B' && first != 'R' && first != 'U') + { + full_name = 'U' + full_name; + } + + //var param = new { floor_name = floor_name }; + + //房間 新增Data至forge_room資料表 + Dictionary room = new Dictionary(); + room.Add("@room_id", idfc.room_id); + room.Add("@deleted", 0); + room.Add("@room_name", full_name); + room.Add("@created_at", DateTime.Now); + + await backendRepository.AddOneByCustomTableReturnId(room, "forge_room", false); + + + } + + //更新forge_room資料表 building_tag, floor_guid欄位 + string sql = @" + update forge_room a + join ( + select building_tag, floor_guid, + case when right(floor_name, 1) = 'F' then floor_name + else CONCAT(floor_name, 'F') end floor_name , priority + from ( + SELECT + a.building_tag, + a.floor_guid, a.full_name, + case when left(a.full_name, 1) = 'B' then a.full_name + when left(a.full_name, 1) = 'R' then a.full_name + when left(a.full_name, 1) = 'U' then a.full_name + else CONCAT('U', a.full_name) end as floor_name, + a.priority + FROM floor AS a + INNER JOIN building AS b ON a.building_tag = b.building_tag + WHERE a.deleted = 0 AND b.deleted = 0 + )y + )x on SUBSTRING_INDEX(a.room_name, '_', 1) = x.floor_name + set a.building_tag = x.building_tag, + a.floor_guid = x.floor_guid"; + await backendRepository.ExecuteSql(sql); + } + apiResult.Code = "0000"; + apiResult.Msg = "編輯成功"; + } + else + { + apiResult.Code = "0001"; + apiResult.Msg = "無資料輸入"; + } + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } } } diff --git a/Backend/Models/Device.cs b/Backend/Models/Device.cs index 668e3f7..2d9dd3a 100644 --- a/Backend/Models/Device.cs +++ b/Backend/Models/Device.cs @@ -270,4 +270,23 @@ namespace Backend.Models public string device_coordinate_3d { get; set; } public int forge_dbid { get; set; } } + + public class ImportForgeRoom + { + public string building_tag { get; set; } + public string floor_guid { get; set; } + public int room_id { get; set; } + public int deleted { get; set; } + public string room_name { get; set; } + public string created_at { get; set; } + } + + public class Import_floor_data + { + public string building_tag { get; set; } + public string floor_guid { get; set; } + public string floor_name { get; set; } + public int priority { get; set; } + } + } diff --git a/Backend/wwwroot/forgeDemo.html b/Backend/wwwroot/forgeDemo.html index 6bbdccb..9751333 100644 --- a/Backend/wwwroot/forgeDemo.html +++ b/Backend/wwwroot/forgeDemo.html @@ -40,7 +40,7 @@ - + @@ -240,7 +240,10 @@ //launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dGEzaHFzZmZ6cWJub3V4a3BsZGt1a3NldzRzajIxdzUtYmltc19tb2RlbHMvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8yMDIyXzEyXzMxLm53ZA'); //雙模式 - launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dGEzaHFzZmZ6cWJub3V4a3BsZGt1a3NldzRzajIxdzUtYmltc19tb2RlbHMvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8yMDIyXzEyXzMxLm53ZA=='); + //launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dGEzaHFzZmZ6cWJub3V4a3BsZGt1a3NldzRzajIxdzUtYmltc19tb2RlbHMvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8yMDIyXzEyXzMxLm53ZA=='); + + //01.06 樓層刪除燈具 + launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6LW1vZGVsX3Rlc3QxMTIxLyVFMyU4MCU5MCVFNSU4RiVCMCVFNSU4QyU5NyVFNCVCOCVBRCVFOCU4RiVCMSVFNSVBNCVBNyVFNiVBOCU5MyVFMyU4MCU5MUFSQyVFOSU5QiU5OSVFNiVBOCVBMSVFNSVCQyU4RitNRVAlRTYlOEIlODYlRTclQjMlQkIlRTclQjUlQjFfJUU1JTg4JUFBJUU3JTg3JTg4JUU1JTg1JUI3XzIwMjNfMDFfMDYubndk'); //launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dnNjb2RlX2ZvcmdlX3Rlc3QvJUUzJTgwJTkwQVJDJUUzJTgwJTkxXzIwMjJfMTJfMTMubndk');//new ARC @@ -381,6 +384,7 @@ function importDevCor() { ImportDevForCor(); + ImportForgeRoom(); } function ImportDevForCor() {//callback = null @@ -412,9 +416,38 @@ fail: function (xhr, status, error) { } }); - } + function ImportForgeRoom() { + var url = "/DeviceImport/ImportForgeRoom"; + + $.ajax({ + method: "POST", + url: url, + data: JSON.stringify(roomDataList), + cache: false, + async: false, + contentType: "application/json; charset=UTF-8", + dataType: 'json', + success: function (rel) { + if (rel.code != "0000") { + if (rel.code == "9999") { + console.log(rel.msg); + } + else { + console.log(rel.msg); + } + return; + } + else { + console.log(rel.msg); + return; + } + }, + fail: function (xhr, status, error) { + } + }); + } diff --git a/Backend/wwwroot/js/forge/ForgeDemo.js b/Backend/wwwroot/js/forge/ForgeDemo.js index de1db6d..8032001 100644 --- a/Backend/wwwroot/js/forge/ForgeDemo.js +++ b/Backend/wwwroot/js/forge/ForgeDemo.js @@ -13,7 +13,8 @@ var levels;//剖面用 var baseApiUrl = "http://localhost:3604"; var instanceTree; //var objSendData = { Data: null }; -var tagIdDevList = []; +var tagIdDevList = [];//模型設備List: device_number、device_coordinate_3d、forge_dbid +var roomDataList = [];//模型房間List: room_id、room_name function launchViewer(urn) { var av = Autodesk.Viewing; @@ -274,39 +275,36 @@ function onDocumentLoadSuccess(doc) { e.properties.forEach(function (item) { if (item.displayName == "【tag_id】") { // Tag_name tag_id 【tag_id】 if (item.displayValue != "") { - //if ((item.displayValue).indexOf('TPE_B1_ME_M10') > -1) { - console.log("--------------------------------------------------"); - console.log("Tag_name dbid: " + e.dbId); - console.log("value: " + item.displayValue); - - //myDataList.forEach((myData, index) => { - // devices.push({ id: index, position: JSON.parse(myData.device_coordinate_3d), sensorTypes: ["temperature", "humidity"] }); - //}); - //} - - let bounds = new THREE.Box3(); + ////if ((item.displayValue).indexOf('TPE_B1_LT_L1') > -1) {// TPE_B1_ME_M10 + //console.log("--------------------------------------------------"); + //console.log("Tag_name dbid: " + e.dbId); + //console.log("value: " + item.displayValue); + ////} + var str = item.displayValue.split('_'); + if (str.length == 2) { //兩段為房間 ex: U7F_01 + roomDataList.push({ room_id: e.dbId, room_name: item.displayValue }); + } + else if (str.length == 8) { //八段為設備 ex: TPE_B1_ME_M10_U7F_NA_FCU_N1 + //取得座標 + let bounds = new THREE.Box3(); + instanceTree.enumNodeFragments(e.dbId, (fragId) => { + let box = new THREE.Box3(); + fragList.getWorldBounds(fragId, box); + bounds.union(box); + }, true); + var position = bounds.center(); + ////if ((item.displayValue).indexOf('TPE_B1_LT_L1') > -1) { + //console.log("position: (" + (position.x).toFixed(2) + ", " + (position.y).toFixed(2) + ", " + (position.z).toFixed(2) + ")"); + //console.log("--------------------------------------------------"); + ////} + tagIdDevList.push({ device_number: item.displayValue, device_coordinate_3d: '{ "x": ' + (position.x).toFixed(2) + ', "y": ' + (position.y).toFixed(2) + ', "z": ' + (position.z).toFixed(2) + ' }', forge_dbid: e.dbId }); + } - instanceTree.enumNodeFragments(e.dbId, (fragId) => { - let box = new THREE.Box3(); - fragList.getWorldBounds(fragId, box); - bounds.union(box); - }, true); - var position = bounds.center(); - //if ((item.displayValue).indexOf('TPE_B1_ME_M10') > -1) { - console.log("position: (" + (position.x).toFixed(2) + ", " + (position.y).toFixed(2) + ", " + (position.z).toFixed(2) + ")"); - tagIdDevList.push({ device_number: item.displayValue, device_coordinate_3d: '{ "x": ' + (position.x).toFixed(2) + ', "y": ' + (position.y).toFixed(2) + ', "z": ' + (position.z).toFixed(2) + ' }', forge_dbid: e.dbId }); - console.log("--------------------------------------------------"); - //} } - //getFragmentWorldMatrixByNodeId(e.dbId, viewer); - //let fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); - } }); - }) - }) //---------------------- end --------------------------------------------------- @@ -792,8 +790,6 @@ function setElevatorSpeed(speed) { //0.01 ~ 1 } function movElevator() { - - let tree = viewer.model.getData().instanceTree;//三組:(749,750,751),(755,756,757),(761,762,763) let nodeId = 12112;//12104; //749; //10952; let nodeId2 = 12111;//12105; //750; @@ -908,64 +904,6 @@ function hideColor(nodeId) {//顏色改成透明 viewer.setThemingColor(nodeId, color); } -//function movElevator() { - - -// let tree = viewer.model.getData().instanceTree; -// let nodeId = 750;// 10952; -// let fragProxyZ = 0; -// var movStatus = 0; // 0=no 1=up 2=down - - -// if (fragProxy.position.z > targetFloorZ) { -// movStatus = 2 -// } -// else if (fragProxy.position.z < targetFloorZ) { -// movStatus = 1 -// } - -// if (movStatus == 0) { -// return; -// } - -// tree.enumNodeFragments(nodeId, function (frag) { -// fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); -// fragProxy.getAnimTransform(); -// //let fragPosition = new THREE.Vector3(0, 0, 15);// 一樓0 二樓15 三樓 26 -// if (movStatus == 2) { -// fragProxy.position.z -= elevatorSpeed; -// } -// else if (movStatus == 1) { -// fragProxy.position.z += elevatorSpeed; -// } - -// fragProxyZ = fragProxy.position.z; -// fragProxy.updateAnimTransform() - -// }); -// viewer.impl.sceneUpdated(true); - -// if (movStatus == 2) { -// if (fragProxyZ >= targetFloorZ) { -// requestAnimationFrame(movElevator); -// } -// } -// else if (movStatus == 1) { -// if (fragProxyZ <= targetFloorZ) { -// requestAnimationFrame(movElevator); -// } -// } - - -// //let fragPosition = new THREE.Vector3(position);// 一樓0 二樓15 三樓 26 - -// //fragProxy.position = fragPosition; - -// //fragProxy.updateAnimTransform(); - -// //viewer.impl.sceneUpdated(true); -//} - function getAllDbIds(viewer) { var instanceTree = viewer.model.getData().instanceTree; @@ -1025,10 +963,6 @@ function onButtonClicked() { this.viewer.setCutPlanes([upperCutPlaneParam, lowerCutPlaneParam]); } -function displayCuttedPlane() { - -} - /** * Autodesk.Viewing.Document.load() failuire callback. */ @@ -1082,27 +1016,7 @@ async function loadHeatmaps(model) { position: { x: 6.98, y: -2.24, z: 16.86 }, // x: 0, y: 25.03, z: -2.52 (-4.93, -3.85, 16.86) sensorTypes: ["temperature", "humidity"] } - - //{ - // id: "Oficina 5", - // //name: "Oficina-", - // position: { x: 3.35, y: -4.81, z: 12.88 }, // x: 0, y: 25, z: -2.5 (3.35, -4.81, 12.88 - // sensorTypes: ["temperature", "humidity"] - //}, - //{ - // id: "Oficina 4", - // //name: "Oficina-", - // position: { x: 37.03, y: -4.81, z: 12.88 }, // x: 0, y: 25.03, z: -2.52 (37.03, -4.81, 12.88) - // sensorTypes: ["temperature", "humidity"] - //}, - //{ - // id: "Oficina 3", - // //name: "Oficina-", - // position: { x: 2.83, y: -22.60, z: 12.88 }, // x: 0, y: 25.03, z: -2.52 (2.83, -22.60, 12.88) - // sensorTypes: ["temperature", "humidity"] - //} ]; - //冷氣N5: (6.98, -19.00, 16.86), N4: (35.85, -2.24, 16.86), N3: (6.98, -2.24, 16.86) // Initialize sensor values let sensorVals = []; @@ -1228,11 +1142,6 @@ async function loadHeatmap() { function hideObject() { //viewer.hide(4); - //viewer.hide(58); - //viewer.hide(613); - //viewer.hide(640); - //viewer.hide(560); - for (var i = 0; i < allDbIdsStr.length; i++) { viewer.hide(parseInt(allDbIdsStr[i])); } @@ -1240,11 +1149,6 @@ function hideObject() { function openObject() { //viewer.show(4); - //viewer.show(58); - //viewer.show(613); - //viewer.show(640); - //viewer.show(560); - for (var i = 0; i < allDbIdsStr.length; i++) { viewer.show(parseInt(allDbIdsStr[i])); } @@ -1252,67 +1156,11 @@ function openObject() { async function setObjectTransparent() { //setTransparency(4, 0); - //setTransparency(58, 0); - //setTransparency(613, 0); - //setTransparency(640, 0); - //setTransparency(560, 0); - //setTransparency(parseInt(515), 0); - - //for (var i = 0; i < allDbIdsStr.length; i++) { - // setTransparency(parseInt(allDbIdsStr[i]), 0); - //} - - //setTransparency(parseInt(515), 0); - //setTransparency(parseInt(516), 0); - //setTransparency(parseInt(517), 0); - //setTransparency(parseInt(518), 0); - //setTransparency(parseInt(519), 0); - //setTransparency(parseInt(399), 0); - //setTransparency(parseInt(101), 0); - //setTransparency(parseInt(100), 0); - //setTransparency(parseInt(58), 0); - - //setTransparency(parseInt(587), 0); - //setTransparency(parseInt(586), 0); - //setTransparency(parseInt(585), 0); - //setTransparency(parseInt(584), 0); - //setTransparency(parseInt(583), 0); - //setTransparency(parseInt(562), 0); - //setTransparency(parseInt(361), 0); - - //test(); - //hideColor(587); - //hideColor(586); - //hideColor(585); - //hideColor(584); - //hideColor(583); - //hideColor(562); - //hideColor(361); - setTransparentBuilding(); - } async function cancelObjectTransparent() { //setTransparency(4, 1); - //setTransparency(58, 1); - //setTransparency(613, 1); - //setTransparency(640, 1); - //setTransparency(560, 1); - //for (var i = 0; i < allDbIdsStr.length; i++) { - // setTransparency(parseInt(allDbIdsStr[i]), 1); - //} - - //setTransparency(515, 0.2); - //setTransparency(516, 0.2); - //setTransparency(517, 0.2); - //setTransparency(518, 0.2); - //setTransparency(519, 0.2); - //setTransparency(399, 0.2); - //setTransparency(101, 0.2); - //setTransparency(100, 0.2); - //setTransparency(58, 0.2); - recoverTransparentBuilding(); } @@ -1348,7 +1196,6 @@ async function test() { } - //------------ 剖面 ---------------------- async function getRemoteLevels() { const aecData = await Autodesk.Viewing.Document.getAecModelData(this.viewer.model.getDocumentNode()); @@ -1364,26 +1211,6 @@ async function getLevelsData() { this.levels = data; } -//function getCutPlaneParam(idx, n) { -// if (idx < 0 || !n) return; - -// const level = this.levels[idx]; -// if (!level) return; - -// //const precision = Autodesk.Viewing.Private.calculatePrecision( level.elevation ); -// const model = this.viewer.model; -// const globalOffset = model.getData().globalOffset; -// const units = model.getUnitString(); -// const elevRaw = Autodesk.Viewing.Private.convertUnits('ft', units, 1, level.elevation); - -// let d = elevRaw - globalOffset.z - 0.5; -// if (n == 1) -// d = -1 * d; - -// return new THREE.Vector4(0, 0, n, d); -//} - - function profile() { const upperIdx = 6; const upperCutPlaneParam = this.getCutPlaneParam(upperIdx, 1); @@ -1393,71 +1220,3 @@ function profile() { } //----------------- end ----------------------------------------------- -// 設備的dbid和3D座標 存進 資料庫 -//function ImportDevForCor() {//callback = null -// var url = "/DeviceImport/ImportDevForCor"; -// //let sendData = { -// // "device_number": pageAct.AreaTag, -// // "device_coordinate_3d": "", -// // "device_dbid": "", -// //}; -// objSendData.Data = tagIdDevList; -// //ytAjax = new YourTeam.Ajax(url, objSendData, function (res) { -// // if (!res || res.code != "0000" || !res.data) { - -// // } else { - -// // } -// //}, null, "POST").send(); - -// //$.post(url, objSendData, function (rel) { -// // if (rel.code != "0000") { -// // if (rel.code == "9999") { -// // toast_error(rel.msg); -// // } -// // else { -// // toast_warning(rel.msg); -// // } -// // return; -// // } -// // else { -// // toast_ok(rel.msg); -// // //ReloadRawDataCheckTable(); -// // } - -// //}, 'json'); - -// //headers={'content-type': 'application/json'} - -// $.ajax({ -// type: "POST", -// url: url, -// data: objSendData, -// cache: false, -// contentType: 'application/json', -// processData: false, -// success: function (rel) { -// //$("#save-building-btn").html('確定').attr("disabled", false); -// if (rel.code != "0000") { -// if (rel.code == "9999") { -// toast_error(rel.msg); -// } -// else { -// toast_warning(rel.msg); -// } -// return; -// } -// else { -// toast_ok(rel.msg); -// //buildInfoTable.ajax.reload(null, false); -// //$('#build-modal').modal('hide'); -// return; -// } -// }, -// fail: function (xhr, status, error) { -// //$("#save-building-btn").html('確定').attr("disabled", false); -// //toast_error(rel.msg); -// } -// }); - -//} \ No newline at end of file