diff --git a/FrontendWebApi/ApiControllers/BuildController.cs b/FrontendWebApi/ApiControllers/BuildController.cs index 01f40f8..c704768 100644 --- a/FrontendWebApi/ApiControllers/BuildController.cs +++ b/FrontendWebApi/ApiControllers/BuildController.cs @@ -383,7 +383,7 @@ namespace FrontendWebApi.ApiControllers apiResult.Code = "5000"; return BadRequest(apiResult); } - if (post.building_guid == null) + if (post.building_tag == null) { apiResult.Code = "9997"; return Ok(apiResult); @@ -396,13 +396,13 @@ namespace FrontendWebApi.ApiControllers var disastersql = ""; var layer3sql = ""; var sWhere = ""; - if (!String.IsNullOrEmpty(post.main_system_guid)) + if (!String.IsNullOrEmpty(post.main_system_tag)) { - main_system_guidsql = $" and d.main_system_guid = '{post.main_system_guid}'"; + main_system_guidsql = $" and d.device_system_tag = '{post.main_system_tag}'"; } - if (!String.IsNullOrEmpty(post.sub_system_guid)) + if (!String.IsNullOrEmpty(post.sub_system_tag)) { - sub_system_guidsql = $" and d.sub_system_guid = '{post.sub_system_guid}'"; + sub_system_guidsql = $" and d.device_name_tag = '{post.sub_system_tag}'"; } if (!String.IsNullOrEmpty(post.device_system_category_layer3)) { @@ -417,13 +417,13 @@ namespace FrontendWebApi.ApiControllers if (!String.IsNullOrEmpty(post.show_cctv) && post.show_cctv == "1") { var str_arr = new List(); - if (!String.IsNullOrEmpty(post.main_system_guid)) + if (!String.IsNullOrEmpty(post.main_system_tag)) { - str_arr.Add($@"d.main_system_guid = '{post.main_system_guid}'"); + str_arr.Add($@"d.device_system_tag = '{post.main_system_tag}'"); } - if (!String.IsNullOrEmpty(post.sub_system_guid)) + if (!String.IsNullOrEmpty(post.sub_system_tag)) { - str_arr.Add($@"d.sub_system_guid = '{post.sub_system_guid}'"); + str_arr.Add($@"d.device_name_tag = '{post.sub_system_tag}'"); } if (!String.IsNullOrEmpty(post.device_system_category_layer3)) { @@ -495,12 +495,12 @@ namespace FrontendWebApi.ApiControllers and d.device_name_tag = dk.device_name_tag left join device_master dm ON d.device_building_tag = dm.device_building_tag AND d.device_name_tag = dm.device_name_tag - left join device_item di ON d.sub_system_guid = di.sub_system_guid + left join device_item di ON d.device_name_tag = di.device_name_tag AND di.deleted = 0 AND di.is_show_riserDiagram = 1 {disasterjoinsql} - LEFT JOIN building_menu bm ON d.building_guid = bm.building_guid AND d.main_system_guid = bm.main_system_guid AND d.sub_system_guid = bm.sub_system_guid - where d.deleted = 0 and d.building_guid = '{post.building_guid}' {sWhere} + LEFT JOIN building_menu bm ON d.device_building_tag = bm.building_tag AND d.device_system_tag = bm.main_system_tag AND d.device_name_tag = bm.sub_system_tag + where d.deleted = 0 and d.device_building_tag = '{post.building_tag}' {sWhere} order by d.priority ASC, d.device_number ASC"; var devicelist = await backendRepository.GetAllAsync(sql); @@ -521,9 +521,9 @@ namespace FrontendWebApi.ApiControllers } //抓出該設備所需要的顯示的即時資料(平面圖) - var sql_tips = $@"SELECT di.* FROM device_item di WHERE di.deleted = 0 AND is_show = 1 AND sub_system_guid = @sub_system_guid"; + var sql_tips = $@"SELECT di.* FROM device_item di WHERE di.deleted = 0 AND is_show = 1 AND device_name_tag = @sub_system_tag"; - var device_item_floormap = await backendRepository.GetAllAsync(sql_tips, new { sub_system_guid = post.sub_system_guid }); + var device_item_floormap = await backendRepository.GetAllAsync(sql_tips, new { sub_system_tag = post.sub_system_tag }); foreach (var device in devicelist) { diff --git a/FrontendWebApi/ApiControllers/GraphManage.cs b/FrontendWebApi/ApiControllers/GraphManage.cs new file mode 100644 index 0000000..c6a20c0 --- /dev/null +++ b/FrontendWebApi/ApiControllers/GraphManage.cs @@ -0,0 +1,332 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Repository.BackendRepository.Implement; +using System.Collections.Generic; +using System.Threading.Tasks; +using System; +using System.Linq; +using FrontendWebApi.Models; +using Repository.BackendRepository.Interface; +using Repository.FrontendRepository.Interface; +using static Repository.Models.GraphManage; +using NPOI.SS.UserModel; +using Microsoft.Extensions.Hosting; +using System.IO; + +namespace FrontendWebApi.ApiControllers +{ + [Route("api/[controller]")] + [ApiController] + public class GraphManageController : MyBaseApiController + { + private readonly IBackendRepository backendRepository; + private readonly IFrontendRepository frontendRepository; + private string graph_manage_layer1 = "graph_manage_layer1"; + private string graph_manage_layer2 = "graph_manage_layer2"; + + private string graphManageFileSaveAsPath = ""; + + public GraphManageController(IBackendRepository backendRepository, IFrontendRepository frontendRepository) + { + this.backendRepository = backendRepository; + this.frontendRepository = frontendRepository; + graphManageFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "graph_manage"); + } + + [HttpPost] + public async Task>> MaiSysList() + { + ApiResult> apiResult = new ApiResult>(); + List main_system_list = new List(); + + try + { + var sqlString = @$"SELECT * + FROM variable + WHERE system_type = @graph_manage_layer1 AND deleted = 0 + ORDER BY system_priority, created_at desc"; + + var param = new { @graph_manage_layer1 = graph_manage_layer1 }; + main_system_list = await backendRepository.GetAllAsync(sqlString, param); + + apiResult.Code = "0000"; + apiResult.Data = main_system_list; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + [HttpPost] + public async Task>> SubSysList(int main_system_id) + { + ApiResult> apiResult = new ApiResult>(); + List sub_system_list = new List(); + + try + { + var sqlString = @$"SELECT v2.* + FROM variable v2 + JOIN variable v1 ON v2.system_parent_id = v1.id AND v1.system_type = @graph_manage_layer1 AND v1.deleted = 0 + WHERE v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 AND v1.id = @main_system_id + ORDER BY v2.system_priority, v2.created_at desc"; + + var param = new { @graph_manage_layer1 = graph_manage_layer1, @graph_manage_layer2 = graph_manage_layer2 }; + sub_system_list = await backendRepository.GetAllAsync(sqlString, param); + + apiResult.Code = "0000"; + apiResult.Data = sub_system_list; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + + } + [HttpPost] + public async Task>> GraManList(GraphInfo gi) + { + ApiResult> apiResult = new ApiResult>(); + List graManList = new List(); + + try + { + var sqlString = @$"SELECT * + FROM graph_manage gm + JOIN variable v2 ON gm.sub_system_id = v2.id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 + WHERE v2.id in @sub_system_id AND gm.deleted = 0 + ORDER BY gm.priority, gm.created_at desc"; + + + var param = new { @graph_manage_layer1 = graph_manage_layer1, graph_manage_layer2 = graph_manage_layer2, @sub_system_id = gi.sub_system_id }; + + graManList = await backendRepository.GetAllAsync(sqlString, param); + + if (gi.keyWord != null) + { + var wParam = new { @graph_manage_layer1 = graph_manage_layer1, graph_manage_layer2 = graph_manage_layer2, @sub_system_id = gi.sub_system_id, @keyWord = gi.keyWord }; + graManList = await backendRepository.GetAllAsync(@$"SELECT * + FROM graph_manage gm + JOIN variable v2 ON gm.sub_system_id = v2.id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 + WHERE v2.id in @sub_system_id AND gm.deleted = 0 + AND (code like '%@keyWord%' OR name like '%@keyWord%' OR oriOrgName like '%@keyWord%' OR donOrgName like '%@keyWord%') + ORDER BY gm.priority, gm.created_at desc", wParam); + } + + apiResult.Code = "0000"; + apiResult.Data = graManList; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + [HttpPost] + public async Task> DelOneGraMan(GraphInfo gi) + { + ApiResult apiResult = new ApiResult(); + + try + { + var sqlString = @$"UPDATE graph_manage SET deleted = 0 WHERE code = @code AND sub_system_id = @sub_system_id"; + + var param = new { @code = gi.code, @sub_system_id = gi.sub_system_id }; + + await backendRepository.ExecuteSql(sqlString, param); + apiResult.Code = "0000"; + apiResult.Data = "刪除成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + [HttpPost] + public async Task> EdtOneGraMan([FromForm] GraphInsInfo gii) + { + ApiResult apiResult = new ApiResult(); + + try + { + var sWhere = @$"deleted = 0 AND code = @code AND sub_system_id = @sub_system_id"; + var gm = await backendRepository.GetOneAsync("graph_manage", sWhere, new { @code = gii.code, @sub_system_id = gii.sub_system_id}); + + if (gm == null) + { + apiResult.Code = "0001"; + apiResult.Data = "無法找到圖資"; + return apiResult; + } + + Dictionary graph_manage = new Dictionary(); + + //edit file + if (gii.oriOrgName != null || gii.donOrgName != null) + { + if (!System.IO.Directory.Exists(graphManageFileSaveAsPath)) + System.IO.Directory.CreateDirectory(graphManageFileSaveAsPath); + + if (gm.oriSavName != null && gii.oriOrgName != null) + { + var new_guid = Guid.NewGuid(); + + //刪除原本檔案 + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.oriSavName)); + + var fileName = new_guid + "." + gii.oriOrgName.Split('.')[1]; + + var fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); + + using (var stream = new FileStream(fullPath, FileMode.Create)) + { + gii.oriFile.CopyTo(stream); + } + + graph_manage.Add("@oriOrgName", gii.oriOrgName); + graph_manage.Add("@oriSavName", fileName); + } + + if (gm.donSavName != null && gii.donOrgName != null) + { + var new_guid = Guid.NewGuid(); + + //刪除原本檔案 + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.donSavName)); + + var fileName = new_guid + "." + gii.donOrgName.Split('.')[1]; + + var fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); + + using (var stream = new FileStream(fullPath, FileMode.Create)) + { + gii.donFile.CopyTo(stream); + } + + graph_manage.Add("@oriOrgName", gii.donOrgName); + graph_manage.Add("@oriSavName", fileName); + } + } + + graph_manage.Add("@name", gii.name); + //graph_manage.Add("@priority", gii.priority); + + await backendRepository.UpdateOneByCustomTable(graph_manage, "graph_manage", "code='" + gii.code + "'" + "sub_system_id ='" + gii.sub_system_id + "'"); + apiResult.Code = "0000"; + apiResult.Data = "修改成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + string json = System.Text.Json.JsonSerializer.Serialize(gii); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + [HttpPost] + public async Task> SaveGraMan([FromForm] GraphInsInfo gii) + { + ApiResult apiResult = new ApiResult(); + + try + { + var sWhere = @$"deleted = 0 AND code = @code AND sub_system_id = @sub_system_id"; + var gm = await backendRepository.GetOneAsync("graph_manage", sWhere, new { @code = gii.code, @sub_system_id = gii.sub_system_id }); + + if (gm != null) + { + apiResult.Code = "0002"; + apiResult.Data = "已有相同的編碼"; + return apiResult; + } + + Dictionary graph_manage = new Dictionary(); + + //save file + if (gii.oriOrgName != null || gii.donOrgName != null) + { + if (!System.IO.Directory.Exists(graphManageFileSaveAsPath)) + System.IO.Directory.CreateDirectory(graphManageFileSaveAsPath); + + if (gii.oriOrgName != null) + { + var new_guid = Guid.NewGuid(); + + var fileName = new_guid + "." + gii.oriOrgName.Split('.')[1]; + + var fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); + + using (var stream = new FileStream(fullPath, FileMode.Create)) + { + gii.oriFile.CopyTo(stream); + } + + graph_manage.Add("@oriOrgName", gii.oriOrgName); + graph_manage.Add("@oriSavName", fileName); + } + + if (gii.donOrgName != null) + { + var new_guid = Guid.NewGuid(); + + var fileName = new_guid + "." + gii.donOrgName.Split('.')[1]; + + var fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); + + using (var stream = new FileStream(fullPath, FileMode.Create)) + { + gii.donFile.CopyTo(stream); + } + + graph_manage.Add("@oriOrgName", gii.donOrgName); + graph_manage.Add("@oriSavName", fileName); + } + } + + var newPriority = await backendRepository.GetCurrentPriority("graph_manage"); + graph_manage.Add("@name", gii.name); + graph_manage.Add("@deleted", 0); + graph_manage.Add("@priority", newPriority + 1); + + await backendRepository.AddOneByCustomTable(graph_manage, "graph_manage"); + apiResult.Code = "0000"; + apiResult.Data = "新增成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + string json = System.Text.Json.JsonSerializer.Serialize(gii); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + } +} diff --git a/FrontendWebApi/ApiControllers/MyBaseApiController.cs b/FrontendWebApi/ApiControllers/MyBaseApiController.cs index e0c665d..355e79d 100644 --- a/FrontendWebApi/ApiControllers/MyBaseApiController.cs +++ b/FrontendWebApi/ApiControllers/MyBaseApiController.cs @@ -30,6 +30,8 @@ namespace FrontendWebApi.ApiControllers protected bool jwtlife = true; public string controllerName; public string actionName; + public string main_system_type = "device_system_category_layer2"; + public string sub_system_type = "device_system_category_layer3"; public ErrorCode errorCode = new ErrorCode(); [Authorize] public override void OnActionExecuting(ActionExecutingContext filterContext) diff --git a/FrontendWebApi/FrontendWebApi.csproj b/FrontendWebApi/FrontendWebApi.csproj index 0eacf45..60f49ef 100644 --- a/FrontendWebApi/FrontendWebApi.csproj +++ b/FrontendWebApi/FrontendWebApi.csproj @@ -3,6 +3,10 @@ netcoreapp3.1 e7f9420f-8be4-4163-bb5a-13bbee6b0b36 + + + + false diff --git a/FrontendWebApi/Models/Build.cs b/FrontendWebApi/Models/Build.cs index 5591711..89e17af 100644 --- a/FrontendWebApi/Models/Build.cs +++ b/FrontendWebApi/Models/Build.cs @@ -62,9 +62,9 @@ namespace FrontendWebApi.Models public class GetSubPost { - public string main_system_guid { get; set; } - public string sub_system_guid { get; set; } - public string building_guid { get; set; } + public string main_system_tag { get; set; } + public string sub_system_tag { get; set; } + public string building_tag { get; set; } public string device_system_value { get; set; } public string device_system_category_layer3 { get; set; } public string show_cctv { get; set; } diff --git a/FrontendWebApi/Models/MyBase.cs b/FrontendWebApi/Models/MyBase.cs index 1f880d3..4a7916f 100644 --- a/FrontendWebApi/Models/MyBase.cs +++ b/FrontendWebApi/Models/MyBase.cs @@ -48,6 +48,7 @@ namespace FrontendWebApi.Models public class Variable : Actor { + public int id { get; set; } public string System_type { get; set; } public string System_key { get; set; } public string system_value { get; set; } diff --git a/Repository/Models/GraphManage.cs b/Repository/Models/GraphManage.cs new file mode 100644 index 0000000..f86b6e6 --- /dev/null +++ b/Repository/Models/GraphManage.cs @@ -0,0 +1,41 @@ +using Microsoft.AspNetCore.Http; +using System.Collections.Generic; +using System.Security; + +namespace Repository.Models +{ + public class GraphManage + { + public class GraphList + { + public string code { get; set; } + public int sub_system_id { get; set; } + public string name { get; set; } + public string oriOrgName { get; set; } + public string oriSavName { get; set; } + public string donOrgName { get; set; } + public string donSavName { get; set; } + } + + public class GraphInsInfo + { + public string code { get; set; } + public int sub_system_id { get; set; } + public string name { get; set; } + public string oriOrgName { get; set; } + public string oriSavName { get; set; } + public string donOrgName { get; set; } + public string donSavName { get; set; } + public int priority { get; set; } + public IFormFile oriFile { get; set; } + public IFormFile donFile { get; set; } + } + + public class GraphInfo + { + public string code { get; set; } + public List sub_system_id { get; set; } + public string keyWord { get; set; } + } + } +} diff --git a/z01_WinAPP/fmCheckTagName.cs b/z01_WinAPP/fmCheckTagName.cs index 4691256..3b58946 100644 --- a/z01_WinAPP/fmCheckTagName.cs +++ b/z01_WinAPP/fmCheckTagName.cs @@ -167,10 +167,8 @@ namespace tpDomeWinAPP { webRequestSvc svc = new webRequestSvc(); string bql = url_slot + "bql:select " + top100 + " * from control:ControlPoint "; - //ds = svc.obixQuery("http://60.251.164.125:8080/obix/config/Arena/Program/ObixQuery/query/", bql);//原本的 - ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql); - - + ds = svc.obixQuery("http://60.251.164.125:8080/obix/config/Arena/Program/ObixQuery/query/", bql); + //ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql); dataGridView1.DataSource = ds; dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[1].Width = 400;