From f95674cf15062275d23452c98a9b4a06ad7f0a97 Mon Sep 17 00:00:00 2001 From: dev01 Date: Wed, 4 Jan 2023 10:48:12 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[FrontendWebApi]=20GetUserFull=20=E7=8D=B2?= =?UTF-8?q?=E5=8F=96=E4=BD=BF=E7=94=A8=E8=80=85=E8=B3=87=E8=A8=8A=20api=20?= =?UTF-8?q?=E5=BB=BA=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FrontendWebApi/ApiControllers/UserController.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/FrontendWebApi/ApiControllers/UserController.cs b/FrontendWebApi/ApiControllers/UserController.cs index bea4da9..f889ac2 100644 --- a/FrontendWebApi/ApiControllers/UserController.cs +++ b/FrontendWebApi/ApiControllers/UserController.cs @@ -793,6 +793,17 @@ namespace FrontendWebApi.ApiControllers }); } + [HttpPost] + [Route("api/getUserFull")] + public ActionResult GetUserFull() + { + return Json(new + { + code = "0000", + data = myUser + }); + } + [HttpPost] public async Task> GetUsrRolId([FromBody] User post) { From 2568624e5203140866f3cdbe084b568923ce867e Mon Sep 17 00:00:00 2001 From: wanli Date: Wed, 4 Jan 2023 10:54:34 +0800 Subject: [PATCH 2/5] =?UTF-8?q?[Backend]=20=E6=9B=B4=E6=96=B0device=5Fnode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/DeviceImportController.cs | 56 ++++++++++--------- .../Implement/BaseRepository.cs | 35 ++++++++++++ .../Interface/IBaseRepository.cs | 12 ++++ 3 files changed, 78 insertions(+), 25 deletions(-) diff --git a/Backend/Controllers/DeviceImportController.cs b/Backend/Controllers/DeviceImportController.cs index fb0beb2..7b03b95 100644 --- a/Backend/Controllers/DeviceImportController.cs +++ b/Backend/Controllers/DeviceImportController.cs @@ -755,6 +755,7 @@ namespace Backend.Controllers public async Task> ImportDevForCor([FromBody] List post) { ApiResult apiResult = new ApiResult(); + var device_guid_record = ""; try { if (post != null) @@ -762,41 +763,46 @@ namespace Backend.Controllers if (post.Count > 0) { //清空device_node資料表 - //await backendRepository.TruncateTable("device_node"); + await backendRepository.TruncateTable("device_node"); - //int node_priority = 1; + int node_priority = 1; foreach(var idfc in post) { - //if(idfc.device_number.IndexOf("_LT_L1") > -1) - //{ - // //取得device_guid - // var sWhere = $@"where deleted = 0 and device_number = " + idfc.device_number; - // var device_guid = await backendRepository.GetOneAsync("device_node", sWhere, "device_guid"); + if (idfc.device_number.IndexOf("_LT_L1") > -1) + { + //取得device_guid + var sWhere = $@" deleted = 0 and device_number = '" + idfc.device_number + "'"; + var device_guid = await backendRepository.GetOneColAsync("device", sWhere, "device_guid"); + if(device_guid.ToString() != device_guid_record) + { + device_guid_record = device_guid.ToString(); + node_priority = 1; + } - // //燈具 - // Dictionary device = new Dictionary(); - // device.Add("@device_node_guid", Guid.NewGuid()); - // device.Add("@deleted", 0); - // device.Add("@device_guid", device_guid); - // device.Add("@device_node_coordinate_3d", idfc.device_coordinate_3d); - // device.Add("@forge_dbid", idfc.forge_dbid); - // device.Add("@priority", node_priority); - // device.Add("@created_by", myUserInfo.Userinfo_guid); - // device.Add("@created_at", DateTime.Now); + //燈具 + Dictionary device = new Dictionary(); + device.Add("@device_node_guid", Guid.NewGuid()); + device.Add("@deleted", 0); + device.Add("@device_guid", device_guid); + device.Add("@device_node_coordinate_3d", idfc.device_coordinate_3d); + device.Add("@forge_dbid", idfc.forge_dbid); + device.Add("@priority", node_priority); + device.Add("@created_by", myUserInfo.Userinfo_guid); + device.Add("@created_at", DateTime.Now); - // node_priority++; - // await backendRepository.AddOneByCustomTableReturnId(device, "device_node", false); - //} - //else - //{ + node_priority++; + await backendRepository.AddOneByCustomTableReturnId(device, "device_node", false); + } + else + { Dictionary device = new Dictionary(); device.Add("@device_coordinate_3d", idfc.device_coordinate_3d); device.Add("@forge_dbid", idfc.forge_dbid); await backendRepository.UpdateOneByCustomTable(device, "device", $@" device_number = '{idfc.device_number}'"); - //} - + } + + - } } apiResult.Code = "0000"; diff --git a/Repository/BaseRepository/Implement/BaseRepository.cs b/Repository/BaseRepository/Implement/BaseRepository.cs index 0de7f78..0543d8d 100644 --- a/Repository/BaseRepository/Implement/BaseRepository.cs +++ b/Repository/BaseRepository/Implement/BaseRepository.cs @@ -270,6 +270,41 @@ namespace Repository.BaseRepository.Implement return result; } } + /// + /// 取得單一筆資料某一欄位(排序) + /// + /// + /// + /// 填放欄位 + /// 參數值 + /// + /// + public virtual async Task GetOneColAsync(string tableName, string sWhere, string selCol, object param = null, string sOrderBy = "") + { + string result; + using (IDbConnection conn = GetDbConnection()) + { + try + { + var sql = $"SELECT {selCol} FROM {tableName}"; + if (!string.IsNullOrEmpty(sWhere)) + { + sql += $" WHERE {sWhere}"; + } + if (!string.IsNullOrEmpty(sOrderBy)) + { + sql += $" ORDER BY {sOrderBy}"; + } + + result = await conn.QueryFirstOrDefaultAsync(sql, param); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } /// /// 取得單一筆資料(根據自訂SQL, 自訂參數) diff --git a/Repository/BaseRepository/Interface/IBaseRepository.cs b/Repository/BaseRepository/Interface/IBaseRepository.cs index 1c041a0..33ff7eb 100644 --- a/Repository/BaseRepository/Interface/IBaseRepository.cs +++ b/Repository/BaseRepository/Interface/IBaseRepository.cs @@ -95,6 +95,18 @@ namespace Repository.BaseRepository.Interface /// Task GetOneAsync(string tableName, string sWhere, string selCol, object param = null, string sOrderBy = ""); /// + /// 取得單一筆資料某一欄位(排序),不需sWhere及sOrderBy填"" + /// + /// SELECT {selCol} FROM {tableName} WHERE {sWhere} ORDER BY {sOrderBy} + /// + /// + /// + /// + /// + /// 填放欄位 + /// + Task GetOneColAsync(string tableName, string sWhere, string selCol, object param = null, string sOrderBy = ""); + /// /// 取得單一筆資料(根據自訂SQL, 自訂參數) /// /// From 4c72cd822e8fbaab614361d952a0f25e421bfe80 Mon Sep 17 00:00:00 2001 From: wanli Date: Wed, 4 Jan 2023 15:12:20 +0800 Subject: [PATCH 3/5] =?UTF-8?q?[FrontendWebApi]=20=E5=8A=A0=E5=85=A5=20?= =?UTF-8?q?=E6=9F=A5=E8=A9=A2=E7=87=88=E5=85=B7=E8=A8=AD=E5=82=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/DeviceManageController.cs | 31 +++++++++++++++++++ FrontendWebApi/Models/Device.cs | 8 +++++ 2 files changed, 39 insertions(+) diff --git a/FrontendWebApi/ApiControllers/DeviceManageController.cs b/FrontendWebApi/ApiControllers/DeviceManageController.cs index 7792db6..c934a26 100644 --- a/FrontendWebApi/ApiControllers/DeviceManageController.cs +++ b/FrontendWebApi/ApiControllers/DeviceManageController.cs @@ -711,6 +711,37 @@ namespace FrontendWebApi.ApiControllers return Ok(apiResult); } + [HttpPost] + [Route("api/GetDevNodeForCor")] + public async Task>> GetDevNodeForCor([FromBody] Device p) + { + ApiResult> apiResult = new ApiResult>(); + List device = new List(); + + try + { + apiResult.Code = "0001"; + if (p != null ) + { + if (p.device_system_tag == "LT" && p.device_name_tag == "L1") + { + var d = await backendRepository.GetAllAsync($@"select device_guid,priority,device_node_coordinate_3d,forge_dbid from device_node where deleted = 0"); + + apiResult.Data = d; + apiResult.Code = "0000"; + } + } + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + return Ok(apiResult); + } + return Ok(apiResult); + } + /// /// 燈控排程列表 /// diff --git a/FrontendWebApi/Models/Device.cs b/FrontendWebApi/Models/Device.cs index 0fda044..c8db861 100644 --- a/FrontendWebApi/Models/Device.cs +++ b/FrontendWebApi/Models/Device.cs @@ -133,4 +133,12 @@ namespace FrontendWebApi.Models public string device_coordinate_3d { get; set; } public int? forge_dbid { get; set; } } + + public class DevNodeForCor + { + public string device_guid { get; set; } + public int priority { get; set; } + public string device_node_coordinate_3d { get; set; } + public int? forge_dbid { get; set; } + } } From 5cce208d6e047338f128d81d4bcdbace23017eff Mon Sep 17 00:00:00 2001 From: wanli Date: Wed, 4 Jan 2023 15:15:15 +0800 Subject: [PATCH 4/5] =?UTF-8?q?[Frontend]=20[=E7=9B=A3=E6=8E=A7=E7=B3=BB?= =?UTF-8?q?=E7=B5=B1][=E7=85=A7=E6=98=8E=E7=B3=BB=E7=B5=B1]=20=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E7=87=88=E5=85=89=EF=BC=9B=E6=96=B0=E5=A2=9E=E5=87=BD?= =?UTF-8?q?=E5=BC=8F:=20=E7=87=88=E5=85=89=E9=96=8B=E9=97=9C=E3=80=81?= =?UTF-8?q?=E7=87=88=E5=85=89=E7=9A=84=E5=BC=B7=E5=BA=A6=E5=92=8C=E9=A1=8F?= =?UTF-8?q?=E8=89=B2=E6=9B=B4=E6=94=B9=E3=80=81=E7=89=A9=E4=BB=B6=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E9=A1=8F=E8=89=B2=E5=92=8C=E9=A1=8F=E8=89=B2=E7=9A=84?= =?UTF-8?q?=E9=80=8F=E6=98=8E=E5=BA=A6=E3=80=81=E7=89=A9=E4=BB=B6=E9=80=8F?= =?UTF-8?q?=E6=98=8E=E5=BA=A6=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/_sysMonAll.html | 41 ++++++++++++++++ Frontend/js/forge/forgemodel.js | 86 ++++++++++++++++++++------------- 2 files changed, 93 insertions(+), 34 deletions(-) diff --git a/Frontend/_sysMonAll.html b/Frontend/_sysMonAll.html index add0bb0..c7473f0 100644 --- a/Frontend/_sysMonAll.html +++ b/Frontend/_sysMonAll.html @@ -45,7 +45,9 @@ setLightColor(); } if (arr.indexOf(3) != -1) { + getHotspotPoint(() => { + getLightDevice(); show3DModel(data.urn_3D); }); @@ -335,11 +337,50 @@ } + async function getLightDevice() {//callback = null + getLightData(null); + let url = baseApiUrl + "/api/GetDevNodeForCor"; + let sendData = { + "device_area_tag": pageAct.AreaTag, + "device_building_tag": pageAct.buiTag, + "device_system_tag": pageAct.sysMainTag, + "device_name_tag": pageAct.sysSubTag, + }; + objSendData.Data = sendData; + ytAjax = new YourTeam.Ajax(url, objSendData, function (res) { + if (!res || res.code != "0000" || !res.data) { + + } else { + + let myLightList = []; + $.each(res.data, (idx, data) => { + let item = {}; + item.position = {}; + if (data.device_node_coordinate_3d != null && isJSON(data.device_node_coordinate_3d)) { + item.position = JSON.parse(data.device_node_coordinate_3d); + } + $.extend(item, data); + myLightList.push(item); + }) + + console.log("2", myLightList); + setLightList(myLightList); + //callback ? callback() : ""; + } + }, null, "POST").send(); + + } + function setHotspotPoint(myDataList = []) { console.log(myDataList) getHopspotPoint(myDataList); } + async function setLightList(myDataList = []) { + console.log(myDataList); + getLightData(myDataList); + } + var parentEle = ""; onEvent("autodesk:click:sprite", "[name=forgeViewer]", function (e, obj) { forgeUnFocusAll(); diff --git a/Frontend/js/forge/forgemodel.js b/Frontend/js/forge/forgemodel.js index 76763d1..99d364f 100644 --- a/Frontend/js/forge/forgemodel.js +++ b/Frontend/js/forge/forgemodel.js @@ -5,6 +5,7 @@ var targetFloorZ; var elevatorSpeed; var selector = "#forgeViewer"; var myDataList; +var lightDataList; var lightList = [];//燈光清單 var levels;//剖面用 var lowerIdx;//剖面的下方樓層 @@ -304,6 +305,16 @@ class elevator3D { } function onDocumentLoadSuccess(doc, eleOption) { + //取得燈光清單 + if (lightDataList != undefined && lightDataList != null && lightDataList.length > 0) { + lightDataList.forEach((myData, index) => { + //if (myData.priority == 5) { + const position = JSON.parse(myData.device_node_coordinate_3d); + lightList.push({ dbid: myData.forge_dbid, spotLight: newLight(position) }); + //} + }); + } + var viewables = doc.getRoot().getDefaultGeometry(); viewer.loadDocumentNode(doc, viewables).then(i => { // documented loaded, any action? @@ -323,9 +334,10 @@ function onDocumentLoadSuccess(doc, eleOption) { $(selector).trigger("autodesk:loaded", nodeIds); }); + }); - + } // 輔助函數,使用 Promise 封裝 viewer.getProperties 函數 @@ -607,35 +619,18 @@ class ADHeatMaps { } } - -function setTransparentBuilding() { - //allDbIdsStr.forEach((dbId) => { - // setTransparency(dbId, 0.2); - //}) - - for (var i = 0; i < allDbIdsStr.length; i++) { - setTransparency(parseInt(allDbIdsStr[i]), 0.2); - } - +//全部物件 透明度: 輸入0:透明;輸入1:不透明 +function setTransparentBuilding(transparent) { + for (var i = 0; i < allDbIdsStr.length; i++) { + setTransparency(parseInt(allDbIdsStr[i]), transparent); + } } -function recoverTransparentBuilding() { - //allDbIdsStr.forEach((dbId) => { - // setTransparency(dbId, 1); - //}) - - for (var i = 0; i < allDbIdsStr.length; i++) { - setTransparency(parseInt(allDbIdsStr[i]), 1); - } -} //設定模型 透明度 function setTransparency(nodeId, opacity) { var model = viewer.model; - //var nodeId = 1633; - var fragList = viewer.model.getFragmentList(); - - var fragIds = [] + var fragIds = []; model.getData().instanceTree.enumNodeFragments( nodeId, (fragId) => { @@ -694,6 +689,14 @@ async function addHotPoint(data) { const style = new DataVizCore.ViewableStyle(viewableType, spriteColor, spriteIcon); + //取得燈光清單 + //if (lightDataList != undefined && lightDataList != null && lightDataList.length > 0) { + // lightDataList.forEach((myData, index) => { + // const position = JSON.parse(myData.device_node_coordinate_3d); + // lightList.push({ dbid: myData.forge_dbid, spotLight: newLight(position) }); + // }); + //} + //熱點 點擊事件註冊 viewer.addEventListener(DataVizCore.MOUSE_CLICK, onSpriteClicked);// SPRITE_SELECTED @@ -711,9 +714,6 @@ async function addHotPoint(data) { const viewable = new DataVizCore.SpriteViewable(myPosition, style, dbId); myData._dbId = dbId; viewableData.addViewable(viewable); - if (myData.device_number.indexOf("_LT_L1_") > -1) { - lightList.push({ dbid: myData.forge_dbid, name: myData.device_number, spotLight: newLight(myPosition) }); - } }); await viewableData.finish(); @@ -913,7 +913,7 @@ function profile() { //新增燈光 async function newLight(lightPosition) { //聚光燈 - spotLight = new THREE.SpotLight(0xff0000, 200, 20, 0.6, 0.5, 10); + var spotLight = new THREE.SpotLight(0xffffff, 200, 20, 0.6, 0.5, 10); spotLight.position.set(lightPosition.x, lightPosition.y, lightPosition.z); spotLight.castShadow = false; spotLight.visible = true; @@ -925,15 +925,11 @@ async function newLight(lightPosition) { return spotLight; } -//調整燈光參數 setLightValues(13593, 10, 10, 0.1, 0.3, 1, 0xffff00); -async function setLightValues(dbid, intensity, distance, angle, penumbra, decay, color) { +//調整燈光 強度、顏色 +async function setLightValues(dbid, intensity, color) { for (var i = 0; i < lightList.length; i++) { if (lightList[i].dbid == dbid) { lightList[i].spotLight.intensity = intensity; - lightList[i].spotLight.distance = distance; - lightList[i].spotLight.angle = angle; - lightList[i].spotLight.penumbra = penumbra; - lightList[i].spotLight.decay = decay; var tempcolor = new THREE.Color().setHex(color); lightList[i].spotLight.color = tempcolor; @@ -942,6 +938,23 @@ async function setLightValues(dbid, intensity, distance, angle, penumbra, decay, } } +//燈光開關 +function setLightOpenOrClose(value, light) { + if (value) { + light.visible = true; + } + else { + light.visible = false; + } + viewer.impl.sceneUpdated(true); +} + +//透過nodeId,更改物件顏色或顯示與否;color請填寫THREE.Vector4 +function changeColorTransparency(nodeId, color) {//變綠色 + //var color = new THREE.Vector4(0, 1, 0, 1);//綠色;前三個代表r、g、b; 亦可填入255/255 + //var color = new THREE.Vector4(0, 1, 0, 0);//不顯示顏色;最後的參數為透明度 + viewer.setThemingColor(nodeId, color); +} //======================== 外部呼叫function =========================== //紀錄熱點座標 @@ -949,6 +962,11 @@ function getHopspotPoint(data) { myDataList = data; } +//紀錄燈具座標 +async function getLightData(data) { + lightDataList = data; +} + //呼叫載入熱圖 async function toLoadHeatmap(roomArr) { const model = viewer.model; From 3c192e87deee4a8c3d5f03b8a5e034c18d3f0805 Mon Sep 17 00:00:00 2001 From: wanli Date: Wed, 4 Jan 2023 15:15:53 +0800 Subject: [PATCH 5/5] =?UTF-8?q?[Backend]=20=E6=9B=B4=E6=8F=9Bforge?= =?UTF-8?q?=E6=B8=AC=E8=A9=A6=E7=9A=84=E6=A8=A1=E5=9E=8Burn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/wwwroot/forgeDemo.html | 82 ++-------------------------------- 1 file changed, 3 insertions(+), 79 deletions(-) diff --git a/Backend/wwwroot/forgeDemo.html b/Backend/wwwroot/forgeDemo.html index 0e8b9fc..6bbdccb 100644 --- a/Backend/wwwroot/forgeDemo.html +++ b/Backend/wwwroot/forgeDemo.html @@ -184,7 +184,6 @@