diff --git a/Backend/Controllers/BuildInfoController.cs b/Backend/Controllers/BuildInfoController.cs index 9372572..a1cea3f 100644 --- a/Backend/Controllers/BuildInfoController.cs +++ b/Backend/Controllers/BuildInfoController.cs @@ -19,12 +19,14 @@ namespace Backend.Controllers { private readonly IBackendRepository backendRepository; private string mapFileSaveAsPath = ""; + private string buildMapFileSaveAsPath = ""; public BuildInfoController(IBackendRepository backendRepository) { this.backendRepository = backendRepository; mapFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "floor_map"); + buildMapFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "build_map"); } public IActionResult Index() @@ -44,7 +46,8 @@ namespace Backend.Controllers try { - var sqlString = @$"SELECT A.priority, A.building_tag, A.full_name, A.ip_address, A.ip_port, (SELECT COUNT(*) FROM floor f WHERE f.deleted = 0 AND f.building_tag = A.building_tag) AS 'floorNum', A.created_at + var sqlString = @$"SELECT A.priority, A.building_tag, A.full_name, A.ip_address, A.ip_port, (SELECT COUNT(*) FROM floor f WHERE f.deleted = 0 AND f.building_tag = A.building_tag) AS 'floorNum', A.created_at, + A.orgName_3D, A.extName_3D FROM building A WHERE A.deleted = 0 ORDER BY A.priority ASC, A.created_at DESC"; @@ -69,7 +72,7 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task> SaveBuildInfo(BuildInfo post) + public async Task> SaveBuildInfo([FromForm] BuildInfo post) { ApiResult apiResult = new ApiResult(); @@ -101,6 +104,7 @@ namespace Backend.Controllers //新增 //抓取當前的Priority var current_priority = await backendRepository.GetCurrentPriority("building"); + var map_3d_guid = new Guid(); Dictionary building = new Dictionary(); building = new Dictionary() @@ -110,10 +114,28 @@ namespace Backend.Controllers { "@ip_address", post.Ip_address}, { "@ip_port", post.Ip_port}, { "@priority", current_priority + 1}, + { "@orgName_3D", post.orgName_3D}, + { "@saveName_3D", map_3d_guid}, + { "@extName_3D", post.extName_3D}, { "@created_by", myUserInfo.Userinfo_guid} }; await backendRepository.AddOneByCustomTable(building, "building"); + if (post.orgName_3D != null && post.extName_3D != null) + { + var fileName = map_3d_guid + "." + post.extName_3D; + + var fullPath = Path.Combine(buildMapFileSaveAsPath, fileName); + + if (!System.IO.Directory.Exists(buildMapFileSaveAsPath)) + System.IO.Directory.CreateDirectory(buildMapFileSaveAsPath); + + using (var stream = new FileStream(fullPath, FileMode.Create)) + { + post.Map3dFile.CopyTo(stream); + } + } + apiResult.Code = "0000"; apiResult.Msg = "新增成功"; } @@ -142,7 +164,7 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task> EditBuildInfo(BuildInfo post) + public async Task> EditBuildInfo([FromForm] BuildInfo post) { ApiResult apiResult = new ApiResult(); @@ -153,6 +175,10 @@ namespace Backend.Controllers var sWhere = $@"deleted = 0 AND ip_address = @ip_address AND ip_port = @ip_port AND building_tag != @building_tag"; var buildInfos = await backendRepository.GetAllAsync("building", sWhere, new { ip_address = post.Ip_address, ip_port = post.Ip_port, building_tag = post.building_tag }); + + sWhere = $@"deleted = 0 AND building_tag = @building_tag"; + var buildInfo = await backendRepository.GetOneAsync("building", sWhere, new { building_tag = post.building_tag }); + if (buildInfos.Count == 0) { judgeIPAddressRepeat = false; @@ -166,11 +192,44 @@ namespace Backend.Controllers { "@full_name", post.Full_name}, { "@ip_address", post.Ip_address}, { "@ip_port", post.Ip_port}, + { "@orgName_3D", post.orgName_3D}, + { "@extName_3D", post.extName_3D}, { "@updated_by", myUserInfo.Userinfo_guid}, { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} }; await backendRepository.UpdateOneByCustomTable(building, "building", "building_tag='" + post.building_tag + "'"); + if (post.orgName_3D != null && post.extName_3D != null) + { + var map_3d_guid = Guid.NewGuid(); + + //刪除原本檔案 + if (buildInfo.saveName_3D != null) + { + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile(Path.Combine(buildMapFileSaveAsPath, buildInfo.saveName_3D + "." + buildInfo.extName_3D)); + } + + Dictionary build_map_3d_dic = new Dictionary(); + build_map_3d_dic = new Dictionary() + { + { "@saveName_3D", map_3d_guid} + }; + await backendRepository.UpdateOneByCustomTable(build_map_3d_dic, "building", "building_tag='" + post.building_tag + "'"); + + var fileName = map_3d_guid + "." + post.extName_3D; + + var fullPath = Path.Combine(buildMapFileSaveAsPath, fileName); + + if (!System.IO.Directory.Exists(buildMapFileSaveAsPath)) + System.IO.Directory.CreateDirectory(buildMapFileSaveAsPath); + + using (var stream = new FileStream(fullPath, FileMode.Create)) + { + post.Map3dFile.CopyTo(stream); + } + } + apiResult.Code = "0000"; apiResult.Msg = "修改成功"; } @@ -399,6 +458,9 @@ namespace Backend.Controllers { "@full_name", post.Full_name}, { "@InitMapName", post.InitMapName}, { "@floor_map_name", floor_map_guid}, + { "@orgName_3D", post.orgName_3D}, + { "@saveName_3D", post.saveName_3D}, + { "@extName_3D", post.extName_3D}, { "@priority", current_priority + 1}, { "@created_by", myUserInfo.Userinfo_guid} }; @@ -411,6 +473,9 @@ namespace Backend.Controllers var fullPath = Path.Combine(mapFileSaveAsPath, fileName); + if (!System.IO.Directory.Exists(buildMapFileSaveAsPath)) + System.IO.Directory.CreateDirectory(buildMapFileSaveAsPath); + using (var stream = new FileStream(fullPath, FileMode.Create)) { post.MapFile.CopyTo(stream); @@ -451,6 +516,9 @@ namespace Backend.Controllers var fullPath = Path.Combine(mapFileSaveAsPath, fileName); + if (!System.IO.Directory.Exists(buildMapFileSaveAsPath)) + System.IO.Directory.CreateDirectory(buildMapFileSaveAsPath); + using (var stream = new FileStream(fullPath, FileMode.Create)) { post.MapFile.CopyTo(stream); diff --git a/Backend/Controllers/BuildMenuController.cs b/Backend/Controllers/BuildMenuController.cs index cd98d76..2abdac1 100644 --- a/Backend/Controllers/BuildMenuController.cs +++ b/Backend/Controllers/BuildMenuController.cs @@ -364,6 +364,7 @@ namespace Backend.Controllers } return apiResult; } + [HttpPost] public async Task BuildMenuTable(BuildMenuTablePost post) { @@ -618,10 +619,11 @@ namespace Backend.Controllers { var sqlString = @$"select f.floor_guid Value, f.full_name Name from sub_system_floor sf - left join floor f on sf.floor_tag = f.full_name + left join floor f on sf.floor_tag = f.full_name and sf.building_tag = f.building_tag where sf.deleted = 0 and sf.status = 0 and sf.building_tag = @building_tag and sf.main_system_tag = @main_system_tag and sf.sub_system_tag = @sub_system_tag + and (f.InitMapName + f.floor_map_name) is not null ORDER BY f.priority, f.created_at"; - KeyValue = await backendRepository.GetAllAsync(sqlString, new { building_tag = post.building_tag, main_system_tag = post.main_system_tag, sub_system_type = post.sub_system_tag }); + KeyValue = await backendRepository.GetAllAsync(sqlString, new { building_tag = post.building_tag, main_system_tag = post.main_system_tag, sub_system_tag = post.sub_system_tag }); apiResult.Code = "0000"; apiResult.Data = KeyValue; @@ -635,5 +637,29 @@ namespace Backend.Controllers return apiResult; } + [HttpPost] + public async Task> GetBuildingHas3D(MenuIn post) + { + ApiResult apiResult = new ApiResult(); + List KeyValue = new List(); + try + { + var sqlString = @$"select v.id + from building b + join variable v on v.system_type = @system_type and system_key = N'是否有3D' and v.deleted = 0 + where b.building_tag = @building_tag and (b.orgName_3D + b.saveName_3D) is not null;"; + KeyValue = await backendRepository.GetAllAsync(sqlString, new { building_tag = post.building_tag, system_type = system_setting_type }); + + apiResult.Code = "0000"; + apiResult.Data = KeyValue.Count; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + return apiResult; + } } } diff --git a/Backend/Controllers/MybaseController.cs b/Backend/Controllers/MybaseController.cs index 13ea16b..4cb7fb4 100644 --- a/Backend/Controllers/MybaseController.cs +++ b/Backend/Controllers/MybaseController.cs @@ -33,6 +33,7 @@ namespace Backend.Controllers public string actionName; public string main_system_type = "device_system_category_layer2"; public string sub_system_type = "device_system_category_layer3"; + public string system_setting_type = "system_setting"; public MybaseController() { } public override void OnActionExecuting(ActionExecutingContext filterContext) diff --git a/Backend/Models/BuildModel.cs b/Backend/Models/BuildModel.cs index ab59ef2..4e1fa3e 100644 --- a/Backend/Models/BuildModel.cs +++ b/Backend/Models/BuildModel.cs @@ -16,6 +16,10 @@ namespace Backend.Models public string Ip_port { get; set; } //監控主機 IP port public string Ip_address_port { get { return Ip_address + ":" + Ip_port; } } public byte FloorNum { get; set; } //樓層數量 + public IFormFile Map3dFile { get; set; } + public string orgName_3D { get; set; } + public string saveName_3D { get; set; } + public string extName_3D { get; set; } //public string Created_at { get; set; } //建立時間 } @@ -30,6 +34,9 @@ namespace Backend.Models public string Floor_map_name { get; set; } //平面圖檔名 public IFormFile MapFile { get; set; } //平面圖檔 public int Priority { get; set; } + public string orgName_3D { get; set; } + public string saveName_3D { get; set; } + public string extName_3D { get; set; } } public class SelectedBuildFloor diff --git a/Backend/Views/BuildInfo/Index.cshtml b/Backend/Views/BuildInfo/Index.cshtml index 9e49dfb..a9a67ca 100644 --- a/Backend/Views/BuildInfo/Index.cshtml +++ b/Backend/Views/BuildInfo/Index.cshtml @@ -230,6 +230,19 @@ } //#endregion + //驗證是否有上傳 + jQuery.validator.addMethod("fileUpload", function (value, element) { + var str = value; + var result = false; + if ($("#3d_file_modal")[0].files.length > 0) { + result = true; + } + else { + result = false; + } + return result; + }, "請選擇檔案"); + //#region 區域表單驗證 var BuildInfoValidate = $("#build-form").validate({ rules: { @@ -247,6 +260,9 @@ required: true, maxlength: 50, filterspace: true + }, + file_3d_modal: { + accept: "image/svg+xml" } } }); @@ -257,33 +273,50 @@ if ($("#build-form").valid()) { $("#save-building-btn").html('').attr("disabled", true); var url = "/BuildInfo/SaveBuildInfo"; - var send_data = { - building_tag: $('#build_name_tag').val(), - Full_name: $('#build_name_modal').val(), - Ip_address: $('#ip_address_modal').val(), - Ip_port: $('#ip_port_modal').val() + + var formData = new FormData(); + formData.append("building_tag", $('#build_name_tag').val()); + formData.append("Full_name", $('#build_name_modal').val()); + formData.append("Ip_address", $('#ip_address_modal').val()); + formData.append("Ip_port", $('#ip_port_modal').val()); + + maps = $('#file_3d_modal')[0].files; + if (maps.length > 0) { + var file_names = maps[0].name.split("."); + + formData.append("Map3dFile", maps[0]); + formData.append("orgName_3D", file_names[0]); + formData.append("extName_3D", file_names[1]); } - $.post(url, send_data, function (rel) { - $("#save-building-btn").html('確定').attr("disabled", false); - if (rel.code != "0000") { - if (rel.code == "9999") { - toast_error(rel.msg); + $.ajax({ + type: "POST", + url: url, + data: formData, + cache: false, + contentType: false, + 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_warning(rel.msg); + toast_ok(rel.msg); + buildInfoTable.ajax.reload(null, false); + $('#build-modal').modal('hide'); + return; } - return; + }, + fail: function (xhr, status, error) { + $("#save-building-btn").html('確定').attr("disabled", false); } - else { - toast_ok(rel.msg); - buildInfoTable.ajax.reload(null, false); - $('#build-modal').modal('hide'); - return; - } - }, 'json') - .fail(function (xhr, status, error) { - $("#save-building-btn").html('確定').attr("disabled", false); }); } } @@ -292,33 +325,50 @@ if ($("#build-form").valid()) { $("#save-building-btn").html('').attr("disabled", true); var url = "/BuildInfo/EditBuildInfo"; - var send_data = { - building_tag: selected_build_guid, - Full_name: $('#build_name_modal').val(), - Ip_address: $('#ip_address_modal').val(), - Ip_port: $('#ip_port_modal').val() + var formData = new FormData(); + + formData.append("building_tag", selected_build_guid); + formData.append("Full_name", $('#build_name_modal').val()); + formData.append("Ip_address", $('#ip_address_modal').val()); + formData.append("Ip_port", $('#ip_port_modal').val()); + + maps = $('#file_3d_modal')[0].files; + if (maps.length > 0) { + var file_names = maps[0].name.split("."); + + formData.append("Map3dFile", maps[0]); + formData.append("orgName_3D", file_names[0]); + formData.append("extName_3D", file_names[1]); } - $.post(url, send_data, function (rel) { - $("#save-building-btn").html('確定').attr("disabled", false); - if (rel.code != "0000") { - if (rel.code == "9999") { - toast_error(rel.msg); + $.ajax({ + type: "POST", + url: url, + data: formData, + cache: false, + contentType: false, + 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_warning(rel.msg); + toast_ok(rel.msg); + buildInfoTable.ajax.reload(null, false); + $('#build-modal').modal('hide'); + return; } - return; + }, + fail: function (xhr, status, error) { + $("#save-building-btn").html('確定').attr("disabled", false); } - else { - toast_ok(rel.msg); - buildInfoTable.ajax.reload(null, false); - $('#build-modal').modal('hide'); - return; - } - }, 'json') - .fail(function (xhr, status, error) { - $("#save-building-btn").html('確定').attr("disabled", false); }); } } @@ -566,7 +616,10 @@ }, map_file_modal: { accept: "image/svg+xml" - } + }, + //file_3d_modal: { + // accept: "image/svg+xml" + //} } }); @@ -595,6 +648,7 @@ var formData = new FormData(); maps = $('#map_file_modal')[0].files + maps3D = $('#file_3d_modal')[0].files formData.append("Floor_guid", selected_floor_guid); formData.append("building_tag", selected_build_guid_top); @@ -607,6 +661,13 @@ formData.append("InitMapName", maps[0].name.replace("." + file_names[file_names.length - 1], "")); } + if(maps3D.length > 0) { + var file_names = maps3D[0].name.split(".") + + formData.append("orgName_3D", maps3D[0].name.replace("." + file_names[file_names.length - 1], "")); + formData.append("extName_3D", maps3D[1].name.replace("." + file_names[file_names.length - 1], "")); + } + $.ajax({ type: "POST", url: url, diff --git a/Backend/Views/BuildInfo/_BuildFloor.cshtml b/Backend/Views/BuildInfo/_BuildFloor.cshtml index 3c85787..57dcb29 100644 --- a/Backend/Views/BuildInfo/_BuildFloor.cshtml +++ b/Backend/Views/BuildInfo/_BuildFloor.cshtml @@ -56,6 +56,10 @@ 平面圖檔(限制SVG格式) + @* + 3D檔(限制SVG格式) + + *@ diff --git a/Backend/Views/BuildInfo/_BuildInfo.cshtml b/Backend/Views/BuildInfo/_BuildInfo.cshtml index fe932af..d0ece2c 100644 --- a/Backend/Views/BuildInfo/_BuildInfo.cshtml +++ b/Backend/Views/BuildInfo/_BuildInfo.cshtml @@ -56,6 +56,10 @@ *監控主機 PORT + + 3D檔(限制SVG格式) + + diff --git a/Backend/Views/BuildMenu/Index.cshtml b/Backend/Views/BuildMenu/Index.cshtml index 0a4592f..51f2edd 100644 --- a/Backend/Views/BuildMenu/Index.cshtml +++ b/Backend/Views/BuildMenu/Index.cshtml @@ -161,7 +161,7 @@ 2D - + 3D @@ -280,7 +280,7 @@ 2D - + 3D @@ -768,6 +768,7 @@ GetSubList($('#build_menu_main_modal').val()); GetFloorInSubSystem(); + GetBuildingHas3D(); $('#planimetric_click').attr("disabled", false); $('#build-menu-modal').modal(); } @@ -953,6 +954,7 @@ } changebuild_menu_drawing_modal(); + GetBuildingHas3D(); GetFloorInSubSystem(rel.data.left_planimetric_floor_guid); GetFloorInSubSystem(rel.data.right_planimetric_floor_guid); $('.modal-title').html("選單基本資料 - 修改"); @@ -1198,6 +1200,7 @@ main_system_tag: $('#build_menu_main_modal').val(), sub_system_tag: $('#build_menu_sub_modal').val(), }; + $.post(url, send_data, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); @@ -1215,12 +1218,34 @@ }); if (floor != null) { $('#build_menu_planimetric_floor_modal').val(floor); - $('#build_menu_planimetric_floor_modal_r').val(floor); + $('#build_menu_planimetric_floor_modal_r').val(floor); } $('[id^=drawing_1_div]').show(); + $('[id^=build_menu_planimetric_floor_modal_div]').show(); changebuild_menu_drawing_modal(); + } + } + }, 'json'); + } + function GetBuildingHas3D() { + var url = "/BuildMenu/GetBuildingHas3D"; + var send_data = { + building_tag: $('#build_menu_building_modal').val(), + }; + + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + } + else { + if (rel.data == 0) { + $('[id^=drawing_3_div]').hide(); + } + else { + $('[id^=drawing_3_div]').show(); + changebuild_menu_drawing_modal(); } } }, 'json'); diff --git a/Backend/wwwroot/upload/build_map/00000000-0000-0000-0000-000000000000.svg b/Backend/wwwroot/upload/build_map/00000000-0000-0000-0000-000000000000.svg new file mode 100644 index 0000000..c8fcefb --- /dev/null +++ b/Backend/wwwroot/upload/build_map/00000000-0000-0000-0000-000000000000.svg @@ -0,0 +1,340 @@ + + + + + + + + digital-camera + + + + digital + + 11 + hardware + photo + digicam + computer + camera + + + + + AJ Ashton + + + + + AJ Ashton + + + + + AJ Ashton + + + + image/svg+xml + + + en + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Backend/wwwroot/upload/build_map/97f47dd5-423b-4682-b93c-498a836bbcd5.svg b/Backend/wwwroot/upload/build_map/97f47dd5-423b-4682-b93c-498a836bbcd5.svg new file mode 100644 index 0000000..c8fcefb --- /dev/null +++ b/Backend/wwwroot/upload/build_map/97f47dd5-423b-4682-b93c-498a836bbcd5.svg @@ -0,0 +1,340 @@ + + + + + + + + digital-camera + + + + digital + + 11 + hardware + photo + digicam + computer + camera + + + + + AJ Ashton + + + + + AJ Ashton + + + + + AJ Ashton + + + + image/svg+xml + + + en + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file