From 68ef0a1685d52ef9ed72d622b6db5e0cc6009019 Mon Sep 17 00:00:00 2001 From: dev01 Date: Tue, 16 May 2023 12:15:38 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=9C=96=E8=B3=87=E7=AE=A1=E7=90=86]=20?= =?UTF-8?q?=E8=B3=87=E6=96=99=E7=B5=90=E6=A7=8B=E8=AA=BF=E6=95=B4=20|=20AP?= =?UTF-8?q?I=20=E8=AA=BF=E6=95=B4=20|=20[=E6=AD=B7=E5=8F=B2=E8=B3=87?= =?UTF-8?q?=E6=96=99]=20API=20GetDevice=20=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/GraphManageController.cs | 76 +++++++++---------- .../ApiControllers/HistoryController.cs | 6 +- FrontendWebApi/Models/GraphManage.cs | 17 +++++ 3 files changed, 58 insertions(+), 41 deletions(-) diff --git a/FrontendWebApi/ApiControllers/GraphManageController.cs b/FrontendWebApi/ApiControllers/GraphManageController.cs index 7d86f02..981dee6 100644 --- a/FrontendWebApi/ApiControllers/GraphManageController.cs +++ b/FrontendWebApi/ApiControllers/GraphManageController.cs @@ -40,21 +40,21 @@ namespace FrontendWebApi.ApiControllers /// /// [HttpPost] - public async Task>> VarList() + public async Task>> GraphManageTreeList() { - ApiResult> apiResult = new ApiResult>(); - List variables = new List(); + ApiResult> apiResult = new ApiResult>(); + List gmTree = new List(); try { - var sqlString = @$"select * from variable - where system_type = 'graph_manage_layer' and deleted = 0 + var sqlString = @$"select * from graph_manage_tree + where deleted = 0 order by id asc"; - - variables = await backendRepository.GetAllAsync(sqlString); + + gmTree = await backendRepository.GetAllAsync(sqlString); apiResult.Code = "0000"; - apiResult.Data = variables; + apiResult.Data = gmTree; } catch (Exception exception) { @@ -72,25 +72,24 @@ namespace FrontendWebApi.ApiControllers /// /// [HttpPost] - public async Task> SaveVar([FromBody] GraphVar gv) + public async Task> SaveGraphManageTree([FromBody] GraphManageTree gmTree) { ApiResult apiResult = new ApiResult(); try { - Dictionary variable = new Dictionary(); - var system_priority = backendRepository.GetOneAsync("select system_priority from variable where system_type = @graph_manage_layer and deleted = 0 order by system_priority desc limit 1", new { graph_manage_layer = graph_manage_layer }).Result; - variable.Add("@deleted", 0); - variable.Add("@system_type", graph_manage_layer); - variable.Add("@system_key", gv.system_key); - variable.Add("@system_parent_id", gv.system_parent_id); - variable.Add("@system_remark", "圖資管理-" + gv.system_key); - variable.Add("@system_priority", Int32.Parse(system_priority) + 1); + Dictionary newGmTree = new Dictionary(); + var system_priority = backendRepository.GetOneAsync("select priority from graph_manage_tree where deleted = 0 order by priority desc limit 1").Result; + newGmTree.Add("@deleted", 0); + newGmTree.Add("@name", gmTree.name); + newGmTree.Add("@parent_id", gmTree.parent_id); + newGmTree.Add("@remark", "圖資管理-" + gmTree.name); + newGmTree.Add("@priority", Int32.Parse(system_priority) + 1); + + newGmTree.Add("@created_by", myUser.userinfo_guid); + newGmTree.Add("@created_at", DateTime.Now); - variable.Add("@created_by", myUser.userinfo_guid); - variable.Add("@created_at", DateTime.Now); - - var id = await backendRepository.AddOneByCustomTableReturnId(variable, "variable"); + var id = await backendRepository.AddOneByCustomTableReturnId(newGmTree, "graph_manage_tree"); apiResult.Code = "0000"; apiResult.Data = id.ToString(); } @@ -98,7 +97,7 @@ namespace FrontendWebApi.ApiControllers { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - string json = System.Text.Json.JsonSerializer.Serialize(gv); + string json = System.Text.Json.JsonSerializer.Serialize(gmTree); Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -112,10 +111,10 @@ namespace FrontendWebApi.ApiControllers /// /// [HttpPost] - public async Task> EditVar([FromBody] GraphVar gv) + public async Task> EditGraphManageTree([FromBody] GraphManageTree gmTree) { ApiResult apiResult = new ApiResult(); - var gm = await backendRepository.GetOneAsync("select * from variable where id = @id and deleted = 0", new { @id = gv.id }); + var gm = await backendRepository.GetOneAsync("select * from graph_manage_tree where id = @id and deleted = 0", new { @id = gmTree.id }); if (gm == null) { @@ -126,13 +125,14 @@ namespace FrontendWebApi.ApiControllers try { - Dictionary variable = new Dictionary(); + Dictionary newGmTree = new Dictionary(); - variable.Add("@system_key", gv.system_key); - variable.Add("@updated_by", myUser.userinfo_guid); - variable.Add("@updated_at", DateTime.Now); + newGmTree.Add("@name", gmTree.name); + newGmTree.Add("@remark", "圖資管理-" + gmTree.name); + newGmTree.Add("@updated_by", myUser.userinfo_guid); + newGmTree.Add("@updated_at", DateTime.Now); - await backendRepository.UpdateOneByCustomTable(variable, "variable", "id = " + gv.id); + await backendRepository.UpdateOneByCustomTable(newGmTree, "graph_manage_tree", "id = " + gmTree.id); apiResult.Code = "0000"; apiResult.Data = "編輯成功"; } @@ -140,7 +140,7 @@ namespace FrontendWebApi.ApiControllers { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - string json = System.Text.Json.JsonSerializer.Serialize(gv); + string json = System.Text.Json.JsonSerializer.Serialize(gmTree); Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -154,15 +154,15 @@ namespace FrontendWebApi.ApiControllers /// /// [HttpPost] - public async Task> DelVar([FromBody] GraphVar gv) + public async Task> DelGraphManageTree([FromBody] GraphManageTree gmTree) { ApiResult apiResult = new ApiResult(); try { - var sqlString = @$"UPDATE variable SET deleted = 1, updated_at = @time, updated_by = @user WHERE id = @id"; + var sqlString = @$"UPDATE graph_manage_tree SET deleted = 1, updated_at = @time, updated_by = @user WHERE id = @id"; - var param = new { @id = gv.id, @time = DateTime.Now, @user = myUser.userinfo_guid }; + var param = new { @id = gmTree.id, @time = DateTime.Now, @user = myUser.userinfo_guid }; await backendRepository.ExecuteSql(sqlString, param); apiResult.Code = "0000"; @@ -185,21 +185,21 @@ namespace FrontendWebApi.ApiControllers List graManList = new List(); try { - var param = new { layer_id = gi.layer_id , graph_manage_layer = graph_manage_layer }; + var param = new { layer_id = gi.layer_id , graph_manage_layer = graph_manage_layer, keyWord = gi.keyWord }; if (gi.keyWord != null && !string.IsNullOrEmpty(gi.keyWord)) { graManList = await backendRepository.GetAllAsync(@$"SELECT gm.* FROM graph_manage gm - JOIN variable v1 ON v1.id = @layer_id and v1.system_type = @graph_manage_layer and v1.deleted = 0 + JOIN graph_manage_tree gmtree ON gmtree.id = @layer_id and gmtree.deleted = 0 WHERE gm.deleted = 0 - AND (gm.code like '%{gi.keyWord}%' OR gm.name like '%{gi.keyWord}%' OR gm.oriOrgName like '%{gi.keyWord}%' OR gm.donOrgName like '%{gi.keyWord}%') + AND (gm.code like '%{gi.keyWord}%' OR gm.name like '%@keyWord%' OR gm.oriOrgName like '%@keyWord%' OR gm.donOrgName like '%@keyWord%') ORDER BY gm.priority, gm.created_at desc", param); } else { var sqlString = @$"SELECT gm.* FROM graph_manage gm - JOIN variable v1 ON v1.id = @layer_id and v1.system_type = @graph_manage_layer and v1.deleted = 0 + JOIN graph_manage_tree gmtree ON gmtree.id = @layer_id and gmtree.deleted = 0 WHERE gm.deleted = 0 and gm.layer_id = @layer_id ORDER BY gm.priority, gm.created_at desc"; @@ -228,7 +228,7 @@ namespace FrontendWebApi.ApiControllers { var sqlString = @$"SELECT * FROM graph_manage gm - JOIN variable v1 ON convert(v1.id, nchar) = gm.layer_id and v1.system_type = @graph_manage_layer and v1.deleted = 0 + JOIN graph_manage_tree gmtree ON convert(gmtree.id, nchar) = gm.layer_id and gmtree.deleted = 0 WHERE gm.id = @id AND gm.deleted = 0 ORDER BY gm.priority, gm.created_at desc"; diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index ff8622a..78d885b 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -343,7 +343,7 @@ namespace FrontendWebApi.ApiControllers if (postDevice.SelectFloors != null && postDevice.SelectFloors.Count() > 0) { - wheres.Add("d.floor_guid in @floor_guid"); + wheres.Add("d.device_floor_tag in @floor_tag"); } if (postDevice.SelectSub != null && postDevice.SelectSub.Count() > 0) @@ -373,7 +373,7 @@ namespace FrontendWebApi.ApiControllers join variable v2 on v2.system_value = a.device_name_tag and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3' order by b.priority,v1.system_priority,v2.system_priority,a.priority"; - var dbDevice = await backendRepository.GetAllAsync(sql, new { builds = postDevice.SelectBuildings, floor_guid = postDevice.SelectFloors, syss = postDevice.SelectSub, device_name = postDevice.Device_name }); + var dbDevice = await backendRepository.GetAllAsync(sql, new { builds = postDevice.SelectBuildings, floor_tag = postDevice.SelectFloors, syss = postDevice.SelectSub, device_name = postDevice.Device_name }); apiResult.Data = dbDevice; apiResult.Code = "0000"; } @@ -863,7 +863,7 @@ namespace FrontendWebApi.ApiControllers from variable v2 inner join variable v1 on v2.system_parent_id = v1.id where v2.deleted = 0 and - v2.system_value in ( + v2.id in ( select ap.ShowView from role_auth ra inner join auth_page ap on ra.AuthCode = ap.AuthCode diff --git a/FrontendWebApi/Models/GraphManage.cs b/FrontendWebApi/Models/GraphManage.cs index 941006c..941024e 100644 --- a/FrontendWebApi/Models/GraphManage.cs +++ b/FrontendWebApi/Models/GraphManage.cs @@ -58,4 +58,21 @@ namespace FrontendWebApi.Models public string system_type { get; set; } public int system_parent_id { get; set; } } + + public class GraphManageTree + { + public int id { get; set; } + + public short deleted { get; set; } + public string name{ get; set; } + public string remark{ get; set; } + public int priority{ get; set; } + public int parent_id { get; set; } + + public string created_by { get; set; } + public DateTime created_at { get; set; } + public string updated_by { get; set; } + public DateTime? updated_at { get; set; } + + } }