diff --git a/Backend/Controllers/BuildInfoController.cs b/Backend/Controllers/BuildInfoController.cs index a1cea3f..e64cce8 100644 --- a/Backend/Controllers/BuildInfoController.cs +++ b/Backend/Controllers/BuildInfoController.cs @@ -104,22 +104,43 @@ namespace Backend.Controllers //新增 //抓取當前的Priority var current_priority = await backendRepository.GetCurrentPriority("building"); - var map_3d_guid = new Guid(); + var map_3d_guid = Guid.NewGuid(); - Dictionary building = new Dictionary(); - building = new Dictionary() + if (post.urn_3D != null) { - { "@building_tag", post.building_tag}, - { "@full_name", post.Full_name}, - { "@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"); + Dictionary building = new Dictionary(); + building = new Dictionary() + { + { "@building_tag", post.building_tag}, + { "@full_name", post.Full_name}, + { "@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}, + { "@urn_3D", post.urn_3D}, + { "@created_by", myUserInfo.Userinfo_guid} + }; + await backendRepository.AddOneByCustomTable(building, "building"); + } + else + { + Dictionary building = new Dictionary(); + building = new Dictionary() + { + { "@building_tag", post.building_tag}, + { "@full_name", post.Full_name}, + { "@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) { @@ -186,18 +207,38 @@ namespace Backend.Controllers if (!judgeIPAddressRepeat) { - Dictionary building = new Dictionary(); - building = new Dictionary() + if (post.urn_3D != null) { - { "@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 + "'"); + Dictionary building = new Dictionary(); + building = new Dictionary() + { + { "@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}, + { "@urn_3D", post.urn_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 + "'"); + } + else + { + Dictionary building = new Dictionary(); + building = new Dictionary() + { + { "@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) { diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index 17027ae..e19ff8c 100644 --- a/Backend/Controllers/NiagaraDataSynchronizeController.cs +++ b/Backend/Controllers/NiagaraDataSynchronizeController.cs @@ -41,11 +41,12 @@ namespace Backend.Controllers { List ds; string url_slot = "slot:/TPE/B1|"; - string top100 = " top 100 "; + string top100 = "";//" top 100 "; webRequestService svc = new webRequestService(); string bql = url_slot + "bql:select " + top100 + " * from control:ControlPoint "; //ds = svc.obixQuery("http://192.168.0.136:8080/obix/config/Arena/Program/ObixQuery/query/", bql); - ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql); + //ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql); + ds = svc.obixQuery("http://192.168.0.136:8080/obix/config/Program/ObixQuery/query/", bql); apiResult.Code = "0000"; apiResult.Data = ds; diff --git a/Backend/Controllers/OSSController.cs b/Backend/Controllers/OSSController.cs index 340574c..6a5cb26 100644 --- a/Backend/Controllers/OSSController.cs +++ b/Backend/Controllers/OSSController.cs @@ -102,7 +102,7 @@ namespace forgeSample.Controllers /// [HttpPost] [Route("api/forge/oss/objects")] - public async Task UploadObject([FromForm] UploadFile input) + public async Task UploadObject([FromForm] UploadFile input) { // save the file on the server var fileSavePath = Path.Combine(_env.WebRootPath, Path.GetFileName(input.fileToUpload.FileName)); @@ -126,10 +126,10 @@ namespace forgeSample.Controllers // cleanup System.IO.File.Delete(fileSavePath); - var a = Base64Encode((string)uploadedObj.objectId); - //var test = new TreeNode(Base64Encode((string)uploadedObj.objectId), objInfo.Value.objectKey, "object", false) + string urn = Base64Encode((string)uploadedObj.objectId); + string result = urn + "," + uploadedObj.objectKey; - return uploadedObj; + return result;//uploadedObj; } public class UploadFile diff --git a/Backend/Models/BuildModel.cs b/Backend/Models/BuildModel.cs index 4e1fa3e..8c3784d 100644 --- a/Backend/Models/BuildModel.cs +++ b/Backend/Models/BuildModel.cs @@ -20,6 +20,7 @@ namespace Backend.Models public string orgName_3D { get; set; } public string saveName_3D { get; set; } public string extName_3D { get; set; } + public string urn_3D { get; set; } //public string Created_at { get; set; } //建立時間 } diff --git a/Backend/Views/BuildInfo/Index.cshtml b/Backend/Views/BuildInfo/Index.cshtml index c73ed0c..8770485 100644 --- a/Backend/Views/BuildInfo/Index.cshtml +++ b/Backend/Views/BuildInfo/Index.cshtml @@ -45,6 +45,7 @@ var selected_build_guid_top = ""; var selected_build_guid_top_name; var selected_floor_guid = ""; + let input3Dfile = null; //#region 區域基本資料 document ready $(function () { @@ -261,121 +262,367 @@ maxlength: 50, filterspace: true }, - file_3d_modal: { - accept: "image/svg+xml" + build_file_3d_modal: { + required: true, extension: "nwc|nwd" } - } + }, + messages: { build_file_3d_modal: "File must be nwc, nwd" } }); - //#endregion //#region 儲存區域基本資料 function SaveBuild() { if ($("#build-form").valid()) { $("#save-building-btn").html('').attr("disabled", true); - var url = "/BuildInfo/SaveBuildInfo"; - 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()); + if(input3Dfile != undefined && input3Dfile != null) {//上傳3d檔案至forge平台 + var file = input3Dfile; + var formData = new FormData(); + formData.append('fileToUpload', file); + formData.append('bucketKey', "ta3hqsffzqbnouxkpldkuksew4sj21w5-bims_models");//forge上傳平台-資料夾 - maps = $('#build_file_3d_modal')[0].files; - if (maps.length > 0) { - var file_names = maps[0].name.split("."); + $.ajax({ + url: '/api/forge/oss/objects', + data: formData, + processData: false, + contentType: false, + type: 'POST', + success: function (data) { + var datas = data.split(","); + var urn = datas[0]; + let m3d_names = datas[1].split("."); - formData.append("Map3dFile", maps[0]); - formData.append("orgName_3D", file_names[0]); - formData.append("extName_3D", file_names[1]); + var url = "/BuildInfo/SaveBuildInfo"; + + var formData2 = new FormData(); + formData2.append("building_tag", $('#build_name_tag').val()); + formData2.append("Full_name", $('#build_name_modal').val()); + formData2.append("Ip_address", $('#ip_address_modal').val()); + formData2.append("Ip_port", $('#ip_port_modal').val()); + + maps = $('#build_file_3d_modal')[0].files; + if (maps.length > 0) { + var file_names = maps[0].name.split("."); + + formData2.append("Map3dFile", maps[0]); + } + formData2.append("urn_3D", urn); + formData2.append("orgName_3D", m3d_names[0]); + formData2.append("extName_3D", m3d_names[1]); + + $.ajax({ + type: "POST", + url: url, + data: formData2, + 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_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); + } + }); + + }, + fail: function (xhr, status, error) { + toast_error("上傳3d模型檔失敗!"); + $("#save-building-btn").html('確定').attr("disabled", false); + } + }); } + else { + toast_warning("無3d模型檔案!"); + var url = "/BuildInfo/SaveBuildInfo"; - $.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); + 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 = $('#build_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]); + } + + $.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; - } - }, - fail: function (xhr, status, error) { - $("#save-building-btn").html('確定').attr("disabled", false); - } - }); + }); + } + + //var url = "/BuildInfo/SaveBuildInfo"; + + //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 = $('#build_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]); + //} + + //$.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_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); + // } + //}); + } } function EditBuild() { if ($("#build-form").valid()) { $("#save-building-btn").html('').attr("disabled", true); - var url = "/BuildInfo/EditBuildInfo"; - var formData = new FormData(); + if (input3Dfile != undefined && input3Dfile != null) {//上傳3d檔案至forge平台 + var file = input3Dfile; + var formData = new FormData(); + formData.append('fileToUpload', file); + formData.append('bucketKey', "ta3hqsffzqbnouxkpldkuksew4sj21w5-bims_models");//forge上傳平台-資料夾 - 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()); + $.ajax({ + url: '/api/forge/oss/objects', + data: formData, + processData: false, + contentType: false, + type: 'POST', + success: function (data) { + var datas = data.split(","); + var urn = datas[0]; + let m3d_names = datas[1].split("."); - maps = $('#build_file_3d_modal')[0].files; - if (maps.length > 0) { - var file_names = maps[0].name.split("."); + var url = "/BuildInfo/EditBuildInfo"; + var formData2 = new FormData(); - formData.append("Map3dFile", maps[0]); - formData.append("orgName_3D", file_names[0]); - formData.append("extName_3D", file_names[1]); + formData2.append("building_tag", selected_build_guid); + formData2.append("Full_name", $('#build_name_modal').val()); + formData2.append("Ip_address", $('#ip_address_modal').val()); + formData2.append("Ip_port", $('#ip_port_modal').val()); + + maps = $('#build_file_3d_modal')[0].files; + if (maps.length > 0) { + var file_names = maps[0].name.split("."); + + formData2.append("Map3dFile", maps[0]); + //formData2.append("orgName_3D", file_names[0]); + //formData2.append("extName_3D", file_names[1]); + } + formData2.append("urn_3D", urn); + formData2.append("orgName_3D", m3d_names[0]); + formData2.append("extName_3D", m3d_names[1]); + + $.ajax({ + type: "POST", + url: url, + data: formData2, + 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_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); + } + }); + + }, + fail: function (xhr, status, error) { + toast_error("上傳3d模型檔失敗!"); + $("#save-building-btn").html('確定').attr("disabled", false); + } + }); } + else { + var url = "/BuildInfo/EditBuildInfo"; + var formData = new FormData(); - $.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); + 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 = $('#build_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]); + } + + $.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; - } - }, - fail: function (xhr, status, error) { - $("#save-building-btn").html('確定').attr("disabled", false); - } - }); + }); + } + + //var url = "/BuildInfo/EditBuildInfo"; + //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 = $('#build_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]); + //} + + //$.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_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); + // } + //}); } } //#endregion - - } \ No newline at end of file diff --git a/Backend/Views/BuildInfo/_BuildInfo.cshtml b/Backend/Views/BuildInfo/_BuildInfo.cshtml index f3fd29b..2ec7661 100644 --- a/Backend/Views/BuildInfo/_BuildInfo.cshtml +++ b/Backend/Views/BuildInfo/_BuildInfo.cshtml @@ -57,7 +57,7 @@
- +
diff --git a/Backend/wwwroot/upload/build_map/0e41ff07-7aee-4d69-86f4-608171657bc4.nwd b/Backend/wwwroot/upload/build_map/0e41ff07-7aee-4d69-86f4-608171657bc4.nwd new file mode 100644 index 0000000..dd9b1c0 Binary files /dev/null and b/Backend/wwwroot/upload/build_map/0e41ff07-7aee-4d69-86f4-608171657bc4.nwd differ diff --git a/Backend/wwwroot/upload/build_map/65494fa9-8418-4d99-9935-c8eef7b3d461.nwc b/Backend/wwwroot/upload/build_map/65494fa9-8418-4d99-9935-c8eef7b3d461.nwc new file mode 100644 index 0000000..df46449 Binary files /dev/null and b/Backend/wwwroot/upload/build_map/65494fa9-8418-4d99-9935-c8eef7b3d461.nwc differ diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html index 9e6f02c..6734e0e 100644 --- a/Frontend/_historyData.html +++ b/Frontend/_historyData.html @@ -1,13 +1,13 @@
-
+
- +
-
@@ -18,15 +18,15 @@
- - - + + +
- - + +
@@ -49,13 +49,13 @@
-
+
-
+
@@ -84,7 +84,8 @@ initApp.buildNavigation($('#js_nested_list')); loadTable(null); - $(`[onclick="setDateType('today')"]`).click(); + $(`[onclick="setDateType('day', this)"]`).click(); + $(`[onclick="setDateType('today', this)"]`).click(); }); function initList() { @@ -101,7 +102,7 @@ $.each(res.data.history_Main_Systems, function (index, val) { if (pageAct.mainStatus) { strHtml += `
  • - + ${val.full_name}
  • diff --git a/Frontend/js/style.js b/Frontend/js/style.js index 013724d..586bdbc 100644 --- a/Frontend/js/style.js +++ b/Frontend/js/style.js @@ -1561,4 +1561,14 @@ YT.Loading = function (type, ele = null, text = null, delay = 0) { $(".yt-page-loading").fadeOut(); $(ele.ele).YTAlert().hide(delay); } +} + +//change css of clicked button +function btnSelCss(elem) { + $.each($(elem).parent().find('button'), function (i, v) { + $(v).removeClass('btn-dark'); + $(v).addClass('btn-secondary'); + }); + $(elem).removeClass('btn-secondary'); + $(elem).addClass('btn-dark'); } \ No newline at end of file diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index ee5d6a7..48d7b87 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -56,7 +56,7 @@ namespace FrontendWebApi.ApiControllers try { var fileDateName = lhe.FirstOrDefault().dateType == "month" ? lhe.FirstOrDefault().starttime.ToString("yyyy-MM") : lhe.FirstOrDefault().endtime == null ? lhe.FirstOrDefault().starttime.ToString("yyyy-MM-dd") : lhe.FirstOrDefault().starttime.ToString("yyyy-MM-dd") + "_" + ((DateTime)lhe.FirstOrDefault().endtime).ToString("yyyy-MM-dd"); - var fileName = "廠商資料_"+fileDateName+".xlsx"; + var fileName = "歷史資料_"+fileDateName+".xlsx"; var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "history"); if (!System.IO.Directory.Exists(filePath)) @@ -136,13 +136,17 @@ namespace FrontendWebApi.ApiControllers cell = row.CreateCell(i); if (i == 0) { - cell.SetCellValue(he.deviceName); + cell.SetCellValue(he.type); } if (i == 1) { - cell.SetCellValue(he.value); + cell.SetCellValue(he.deviceName); } if (i == 2) + { + cell.SetCellValue(he.value); + } + if (i == 3) { cell.SetCellValue(he.timestamp.ToString("yyyy-MM-dd HH:mm") + ":00");// } diff --git a/FrontendWebApi/ApiControllers/OperationController.cs b/FrontendWebApi/ApiControllers/OperationController.cs index a0dc12c..38732c7 100644 --- a/FrontendWebApi/ApiControllers/OperationController.cs +++ b/FrontendWebApi/ApiControllers/OperationController.cs @@ -68,7 +68,7 @@ namespace FrontendWebApi.ApiControllers } [HttpPost] - public async Task>> SubSysList([FromBody] string main_system_tag) + public async Task>> SubSysList([FromBody] Find_Sub_List fsl) { ApiResult> apiResult = new ApiResult>(); List sub_system_list = new List(); @@ -78,10 +78,10 @@ namespace FrontendWebApi.ApiControllers var sqlString = @$"SELECT v2.* FROM variable v2 JOIN variable v1 ON v2.system_parent_id = v1.id AND v1.system_type = @main_system_type AND v1.deleted = 0 - WHERE v2.system_type = @sub_system_type AND v2.deleted = 0 AND v1.system_value = @main_system_tag + WHERE v2.system_type = @sub_system_type AND v2.deleted = 0 AND v1.system_value in @main_system_tag ORDER BY v2.system_priority, v2.created_at desc"; - var param = new { @main_system_type = main_system_type, @sub_system_type = sub_system_type, @main_system_tag = main_system_tag }; + var param = new { @main_system_type = main_system_type, @sub_system_type = sub_system_type, @main_system_tag = fsl.main_system_tag }; sub_system_list = await backendRepository.GetAllAsync(sqlString, param); apiResult.Code = "0000"; @@ -227,498 +227,523 @@ namespace FrontendWebApi.ApiControllers /// 汇出excel (work_type: null=廠商, 1=保養, 2=維修) /// /// - public FileResult OpeExportExcel([FromQuery] byte? work_type) + [HttpPost] + public ActionResult> OpeExportExcel([FromBody] ExportExcel ee) { - var j = 1;//row - var workbook = new XSSFWorkbook(); - #region excel設定 - IFont font12 = workbook.CreateFont(); - font12.FontName = "新細明體"; - font12.FontHeightInPoints = 12; - ICellStyle style12 = workbook.CreateCellStyle(); - style12.SetFont(font12); - style12.Alignment = HorizontalAlignment.Center; - style12.VerticalAlignment = VerticalAlignment.Center; - IFont font12Times = workbook.CreateFont(); - font12Times.FontName = "Times New Roman"; - font12Times.FontHeightInPoints = 12; - IFont font18 = workbook.CreateFont(); - font18.FontName = "新細明體"; - font18.FontHeightInPoints = 18; - font18.IsBold = true; - ICellStyle styleTitle18 = workbook.CreateCellStyle(); - styleTitle18.SetFont(font18); - styleTitle18.Alignment = HorizontalAlignment.Center; - styleTitle18.VerticalAlignment = VerticalAlignment.Center; - ICellStyle styleLeft12 = workbook.CreateCellStyle(); - styleLeft12.SetFont(font12); - styleLeft12.Alignment = HorizontalAlignment.Left; - styleLeft12.VerticalAlignment = VerticalAlignment.Center; - ICellStyle styleLine12 = workbook.CreateCellStyle(); - styleLine12.SetFont(font12); - styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; - styleLine12.VerticalAlignment = VerticalAlignment.Center; - styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; - ICellStyle stylein12 = workbook.CreateCellStyle(); - stylein12.SetFont(font12Times); - stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; - stylein12.VerticalAlignment = VerticalAlignment.Center; - stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.WrapText = true; - #endregion - - if (string.IsNullOrEmpty(work_type.ToString())) + ApiResult apiResult = new ApiResult(); + if (ee.work_type > 2 || ee.work_type < 1) { - var sqlString = $@"select ofi.*, v2.system_key - from operation_firm ofi - left join variable v1 on ofi.device_system_category_layer2 = v1.system_value and v1.system_type = @main_system_type and v1.deleted = 0 - left join variable v2 on v1.id = v2.system_parent_id and ofi.device_system_category_layer3 = v2.system_value and v2.system_type = @sub_system_type and v2.deleted = 0 - where ofi.deleted = 0"; - var sheet = workbook.CreateSheet("廠商資料"); - var operation_firm = backendRepository.GetAllAsync(sqlString, new { @main_system_type = main_system_type, @sub_system_type = sub_system_type }); - int RowPosition = 0; - #region set cell - IRow row = sheet.CreateRow(RowPosition); - sheet.SetColumnWidth(0, 4 * 160 * 12); - sheet.SetColumnWidth(1, 4 * 160 * 12); - sheet.SetColumnWidth(2, 4 * 160 * 12); - sheet.SetColumnWidth(3, 4 * 160 * 12); - sheet.SetColumnWidth(4, 4 * 160 * 12); - sheet.SetColumnWidth(5, 4 * 160 * 12); - sheet.SetColumnWidth(6, 4 * 160 * 12); - sheet.SetColumnWidth(7, 4 * 160 * 12); - ICell cell = row.CreateCell(0); - cell.SetCellValue("廠商類別"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue("廠商名稱"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(2); - cell.SetCellValue("聯絡人"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(3); - cell.SetCellValue("電話"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(4); - cell.SetCellValue("郵箱"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(5); - cell.SetCellValue("統一編號"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(6); - cell.SetCellValue("備注"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(7); - cell.SetCellValue("建立時間"); - cell.CellStyle = styleLine12; - #endregion - - if (operation_firm.Result.Count > 0) - { - foreach (var of in operation_firm.Result) - { - RowPosition += 1; - row = sheet.CreateRow(RowPosition); - for (var i = 0; i < 8; i++) - { - cell = row.CreateCell(i); - if (i == 0) - { - cell.SetCellValue(of.system_key); - } - if (i == 1) - { - cell.SetCellValue(of.name); - } - if (i == 2) - { - cell.SetCellValue(of.contact_person); - } - if (i == 3) - { - cell.SetCellValue(of.phone); - } - if (i == 4) - { - cell.SetCellValue(of.email); - } - if (i == 5) - { - cell.SetCellValue(of.tax_id_number); - } - if (i == 6) - { - cell.SetCellValue(of.remark); - } - if (i == 7) - { - cell.SetCellValue(of.Created_at); - } - - cell.CellStyle = style12; - } - } - } + apiResult.Code = "0001"; + apiResult.Msg = "沒有資料匯入"; + return apiResult; } - else if (work_type == 1) + + var fileDateName = ee.startdate == null ? "" : ee.enddate == null ? "_" + ((DateTime)ee.startdate).ToString("yyyy-MM-dd") : "_" + ((DateTime)ee.startdate).ToString("yyyy-MM-dd") + "_" + ((DateTime)ee.enddate).ToString("yyyy-MM-dd"); + var fileName = (ee.work_type == null ? "廠商資料" : ee.work_type == 1 ? "保養記錄" : ee.work_type == 2 ? "維修" : null) + fileDateName + ".xlsx"; + var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "operation"); + + if (!System.IO.Directory.Exists(filePath)) + System.IO.Directory.CreateDirectory(filePath); + try { - var sqlString = $@"select opr.*, concat(d.device_floor_tag, ' ', d.device_last_name, ' ', d.device_serial_tag) as device_name, ui.full_name as user_full_name - from operation_record opr - left join device d on opr.fix_do_code = d.device_number and d.deleted = 0 and d.device_area_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 1) - and d.device_building_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 2) and d.device_floor_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 5) - and d.device_system_tag = opr.device_system_category_layer2 and d.device_name_tag = opr.device_system_category_layer3 - left join userinfo ui on opr.work_person_id = ui.userinfo_guid - where opr.deleted = 0 and opr.work_type = 1;"; - var sheet = workbook.CreateSheet("廠商資料"); - var operation_record = backendRepository.GetAllAsync(sqlString, null); - List operation_record_file = new List(); - - if (operation_record.Result.Count > 0) + using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write)) { - foreach (var or in operation_record.Result) - { - sqlString = $@"select * from operation_record_file where record_id = @record_id"; - var param = new { @record_id = or.id }; - operation_record_file = backendRepository.GetAllAsync(sqlString, param).Result; - or.lorf = operation_record_file; - } - - int RowPosition = 0; - #region set cell - IRow row = sheet.CreateRow(RowPosition); - sheet.SetColumnWidth(0, 4 * 160 * 12); - sheet.SetColumnWidth(1, 4 * 160 * 12); - sheet.SetColumnWidth(2, 4 * 160 * 12); - sheet.SetColumnWidth(3, 4 * 160 * 12); - sheet.SetColumnWidth(4, 4 * 160 * 12); - sheet.SetColumnWidth(5, 4 * 160 * 12); - sheet.SetColumnWidth(6, 4 * 160 * 12); - sheet.SetColumnWidth(7, 4 * 160 * 12); - sheet.SetColumnWidth(8, 4 * 160 * 12); - sheet.SetColumnWidth(9, 4 * 160 * 12); - ICell cell = row.CreateCell(0); - cell.SetCellValue("項目"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue("位置"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(2); - cell.SetCellValue("表單號"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(3); - cell.SetCellValue("設備名稱"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(4); - cell.SetCellValue("狀態"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(5); - cell.SetCellValue("處理人員"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(6); - cell.SetCellValue("預計施工時間"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(7); - cell.SetCellValue("檔案上傳"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(8); - cell.SetCellValue("完成時間"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(9); - cell.SetCellValue("建立時間"); - cell.CellStyle = styleLine12; + var j = 1;//row + var workbook = new XSSFWorkbook(); + #region excel設定 + IFont font12 = workbook.CreateFont(); + font12.FontName = "新細明體"; + font12.FontHeightInPoints = 12; + ICellStyle style12 = workbook.CreateCellStyle(); + style12.SetFont(font12); + style12.Alignment = HorizontalAlignment.Center; + style12.VerticalAlignment = VerticalAlignment.Center; + IFont font12Times = workbook.CreateFont(); + font12Times.FontName = "Times New Roman"; + font12Times.FontHeightInPoints = 12; + IFont font18 = workbook.CreateFont(); + font18.FontName = "新細明體"; + font18.FontHeightInPoints = 18; + font18.IsBold = true; + ICellStyle styleTitle18 = workbook.CreateCellStyle(); + styleTitle18.SetFont(font18); + styleTitle18.Alignment = HorizontalAlignment.Center; + styleTitle18.VerticalAlignment = VerticalAlignment.Center; + ICellStyle styleLeft12 = workbook.CreateCellStyle(); + styleLeft12.SetFont(font12); + styleLeft12.Alignment = HorizontalAlignment.Left; + styleLeft12.VerticalAlignment = VerticalAlignment.Center; + ICellStyle styleLine12 = workbook.CreateCellStyle(); + styleLine12.SetFont(font12); + styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; + styleLine12.VerticalAlignment = VerticalAlignment.Center; + styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; + ICellStyle stylein12 = workbook.CreateCellStyle(); + stylein12.SetFont(font12Times); + stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; + stylein12.VerticalAlignment = VerticalAlignment.Center; + stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.WrapText = true; #endregion - foreach (var or in operation_record.Result) + + if (string.IsNullOrEmpty(ee.work_type.ToString())) { - RowPosition += 1; - row = sheet.CreateRow(RowPosition); - for (var i = 0; i < 10; i++) + var sqlString = $@"select ofi.*, v2.system_key + from operation_firm ofi + left join variable v1 on ofi.device_system_category_layer2 = v1.system_value and v1.system_type = @main_system_type and v1.deleted = 0 + left join variable v2 on v1.id = v2.system_parent_id and ofi.device_system_category_layer3 = v2.system_value and v2.system_type = @sub_system_type and v2.deleted = 0 + where ofi.deleted = 0"; + var sheet = workbook.CreateSheet("廠商資料"); + var operation_firm = backendRepository.GetAllAsync(sqlString, new { @main_system_type = main_system_type, @sub_system_type = sub_system_type }); + int RowPosition = 0; + #region set cell + IRow row = sheet.CreateRow(RowPosition); + sheet.SetColumnWidth(0, 4 * 160 * 12); + sheet.SetColumnWidth(1, 4 * 160 * 12); + sheet.SetColumnWidth(2, 4 * 160 * 12); + sheet.SetColumnWidth(3, 4 * 160 * 12); + sheet.SetColumnWidth(4, 4 * 160 * 12); + sheet.SetColumnWidth(5, 4 * 160 * 12); + sheet.SetColumnWidth(6, 4 * 160 * 12); + sheet.SetColumnWidth(7, 4 * 160 * 12); + ICell cell = row.CreateCell(0); + cell.SetCellValue("廠商類別"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue("廠商名稱"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(2); + cell.SetCellValue("聯絡人"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(3); + cell.SetCellValue("電話"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(4); + cell.SetCellValue("郵箱"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(5); + cell.SetCellValue("統一編號"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(6); + cell.SetCellValue("備注"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(7); + cell.SetCellValue("建立時間"); + cell.CellStyle = styleLine12; + #endregion + + if (operation_firm.Result.Count > 0) { - cell = row.CreateCell(i); - if (i == 0) + foreach (var of in operation_firm.Result) { - cell.SetCellValue(or.work_type_name); - } - if (i == 1) - { - cell.SetCellValue(or.location); - } - if (i == 2) - { - cell.SetCellValue(or.formId); - } - if (i == 3) - { - cell.SetCellValue(or.device_name); - } - if (i == 4) - { - cell.SetCellValue(or.status_name); - } - if (i == 5) - { - cell.SetCellValue(or.user_full_name); - } - if (i == 6) - { - cell.SetCellValue(or.start_time); - } - if (i == 7) - { - var imageNames = or.lorf.Count > 0 ? or.lorf.Select(x => x.save_file_name).ToList() : null; - if (imageNames != null) + RowPosition += 1; + row = sheet.CreateRow(RowPosition); + for (var i = 0; i < 8; i++) { - //insert image process - var dy1 = 10; - var dx1 = 10; - - //image column - sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256) - foreach (var ins in imageNames) + cell = row.CreateCell(i); + if (i == 0) { - //image initial - var extName = ins.Split('.')[1].ToUpper().Equals("JPG") ? "PNG" : ins.Split('.')[1].ToUpper(); - var fullPath = Path.Combine(operationFileSaveAsPath, ins); - var img = Image.FromFile(fullPath); - - //compress image - decimal sizeRatio = ((decimal)img.Height / img.Width); - int thumbWidth = 100; - int thumbHeight = decimal.ToInt32(sizeRatio * thumbWidth); - var thumbStream = img.GetThumbnailImage(thumbWidth, thumbHeight, () => false, IntPtr.Zero); - var memoryStream = new MemoryStream(); - thumbStream.Save(memoryStream, ImageFormat.Jpeg); - - //setting pictureType enum - int format = 0; - var drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); - format = Convert.ToInt32(Enum.Parse(typeof(PictureType), extName)); - - //set picture size and location - if (format != 0) - { - var pictureIds = workbook.AddPicture(memoryStream.ToArray(), format); - XSSFClientAnchor anchor = new XSSFClientAnchor(XSSFShape.EMU_PER_PIXEL * dx1, XSSFShape.EMU_PER_PIXEL * dy1, 0, 0, i, j, 0, 0); - anchor.AnchorType = AnchorType.DontMoveAndResize; - var picture = (XSSFPicture)drawing.CreatePicture(anchor, pictureIds); - var size = picture.GetImageDimension(); - row.HeightInPoints = size.Height; - picture.Resize(); - - //add 105 each new pic - dx1 += 105; - } + cell.SetCellValue(of.system_key); } + if (i == 1) + { + cell.SetCellValue(of.name); + } + if (i == 2) + { + cell.SetCellValue(of.contact_person); + } + if (i == 3) + { + cell.SetCellValue(of.phone); + } + if (i == 4) + { + cell.SetCellValue(of.email); + } + if (i == 5) + { + cell.SetCellValue(of.tax_id_number); + } + if (i == 6) + { + cell.SetCellValue(of.remark); + } + if (i == 7) + { + cell.SetCellValue(of.Created_at); + } + + cell.CellStyle = style12; } - - j++; } - if (i == 8) - { - cell.SetCellValue(or.finish_time); - } - if (i == 9) - { - cell.SetCellValue(or.Created_at); - } - - cell.CellStyle = style12; } } - } - } - else if (work_type == 2) - { - var sqlString = $@"select opr.*, concat(d.device_floor_tag, ' ', d.device_last_name, ' ', d.device_serial_tag) as device_name, ui.full_name as user_full_name - from operation_record opr - left join device d on opr.fix_do_code = d.device_number and d.deleted = 0 and d.device_area_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 1) - and d.device_building_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 2) and d.device_floor_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 5) - and d.device_system_tag = opr.device_system_category_layer2 and d.device_name_tag = opr.device_system_category_layer3 - left join userinfo ui on opr.work_person_id = ui.userinfo_guid - where opr.deleted = 0 and opr.work_type = 2"; - var sheet = workbook.CreateSheet("廠商資料"); - var operation_record = backendRepository.GetAllAsync(sqlString); - List operation_record_file = new List(); - - if (operation_record.Result.Count > 0) - { - foreach(var or in operation_record.Result) + else if (ee.work_type == 1) { - sqlString = $@"select * from operation_record_file where record_id = @record_id"; - var param = new { @record_id = or.id }; - operation_record_file = backendRepository.GetAllAsync(sqlString, param).Result; - or.lorf = operation_record_file; - } + var sqlString = $@"select opr.*, concat(d.device_floor_tag, ' ', d.device_last_name, ' ', d.device_serial_tag) as device_name, ui.full_name as user_full_name + from operation_record opr + left join device d on opr.fix_do_code = d.device_number and d.deleted = 0 and d.device_area_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 1) + and d.device_building_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 2) and d.device_floor_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 5) + and d.device_system_tag = opr.device_system_category_layer2 and d.device_name_tag = opr.device_system_category_layer3 + left join userinfo ui on opr.work_person_id = ui.userinfo_guid + where opr.deleted = 0 and opr.work_type = 1;"; + var sheet = workbook.CreateSheet("廠商資料"); + var operation_record = backendRepository.GetAllAsync(sqlString, null); + List operation_record_file = new List(); - int RowPosition = 0; - #region set cell - IRow row = sheet.CreateRow(RowPosition); - sheet.SetColumnWidth(0, 4 * 160 * 12); - sheet.SetColumnWidth(1, 4 * 160 * 12); - sheet.SetColumnWidth(2, 4 * 160 * 12); - sheet.SetColumnWidth(3, 4 * 160 * 12); - sheet.SetColumnWidth(4, 4 * 160 * 12); - sheet.SetColumnWidth(5, 4 * 160 * 12); - sheet.SetColumnWidth(6, 4 * 160 * 12); - sheet.SetColumnWidth(7, 4 * 160 * 12); - sheet.SetColumnWidth(8, 4 * 160 * 12); - sheet.SetColumnWidth(9, 4 * 160 * 12); - sheet.SetColumnWidth(10, 4 * 160 * 12); - ICell cell = row.CreateCell(0); - cell.SetCellValue("項目"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue("位置"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(2); - cell.SetCellValue("異常代號"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(3); - cell.SetCellValue("表單號"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(4); - cell.SetCellValue("設備名稱"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(5); - cell.SetCellValue("狀態"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(6); - cell.SetCellValue("處理人員"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(7); - cell.SetCellValue("預計施工時間"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(8); - cell.SetCellValue("檔案上傳"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(9); - cell.SetCellValue("完成時間"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(10); - cell.SetCellValue("建立時間"); - cell.CellStyle = styleLine12; - - #endregion - foreach (var or in operation_record.Result) - { - RowPosition += 1; - row = sheet.CreateRow(RowPosition); - for (var i = 0; i < 11; i++)//column + if (operation_record.Result.Count > 0) { - cell = row.CreateCell(i); - if (i == 0) + foreach (var or in operation_record.Result) { - cell.SetCellValue(or.work_type_name); + sqlString = $@"select * from operation_record_file where record_id = @record_id"; + var param = new { @record_id = or.id }; + operation_record_file = backendRepository.GetAllAsync(sqlString, param).Result; + or.lorf = operation_record_file; } - if (i == 1) + + int RowPosition = 0; + #region set cell + IRow row = sheet.CreateRow(RowPosition); + sheet.SetColumnWidth(0, 4 * 160 * 12); + sheet.SetColumnWidth(1, 4 * 160 * 12); + sheet.SetColumnWidth(2, 4 * 160 * 12); + sheet.SetColumnWidth(3, 4 * 160 * 12); + sheet.SetColumnWidth(4, 4 * 160 * 12); + sheet.SetColumnWidth(5, 4 * 160 * 12); + sheet.SetColumnWidth(6, 4 * 160 * 12); + sheet.SetColumnWidth(7, 4 * 160 * 12); + sheet.SetColumnWidth(8, 4 * 160 * 12); + sheet.SetColumnWidth(9, 4 * 160 * 12); + ICell cell = row.CreateCell(0); + cell.SetCellValue("項目"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue("位置"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(2); + cell.SetCellValue("表單號"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(3); + cell.SetCellValue("設備名稱"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(4); + cell.SetCellValue("狀態"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(5); + cell.SetCellValue("處理人員"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(6); + cell.SetCellValue("預計施工時間"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(7); + cell.SetCellValue("檔案上傳"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(8); + cell.SetCellValue("完成時間"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(9); + cell.SetCellValue("建立時間"); + cell.CellStyle = styleLine12; + #endregion + foreach (var or in operation_record.Result) { - cell.SetCellValue(or.location); - } - if (i == 2) - { - cell.SetCellValue(or.error_code); - sheet.AutoSizeColumn(i); - } - if (i == 3) - { - cell.SetCellValue(or.formId); - } - if (i == 4) - { - cell.SetCellValue(or.device_name); - } - if (i == 5) - { - cell.SetCellValue(or.status_name); - } - if (i == 6) - { - cell.SetCellValue(or.user_full_name); - } - if (i == 7) - { - cell.SetCellValue(or.start_time.ToString("yyyy/MM/dd HH:mm:ss")); - } - if (i == 8)//image - { - var imageNames = or.lorf.Count > 0 ? or.lorf.Select(x => x.save_file_name).ToList() : null; - if (imageNames != null) + RowPosition += 1; + row = sheet.CreateRow(RowPosition); + for (var i = 0; i < 10; i++) { - //insert image process - var dy1 = 10; - var dx1 = 10; - - //image column - sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256) - foreach (var ins in imageNames) + cell = row.CreateCell(i); + if (i == 0) { - //image initial - var extName = ins.Split('.')[1].ToUpper().Equals("JPG") ? "PNG" : ins.Split('.')[1].ToUpper(); - var fullPath = Path.Combine(operationFileSaveAsPath, ins); - var img = Image.FromFile(fullPath); - - //compress image - decimal sizeRatio = ((decimal)img.Height / img.Width); - int thumbWidth = 100; - int thumbHeight = decimal.ToInt32(sizeRatio * thumbWidth); - var thumbStream = img.GetThumbnailImage(thumbWidth, thumbHeight, () => false, IntPtr.Zero); - var memoryStream = new MemoryStream(); - thumbStream.Save(memoryStream, ImageFormat.Jpeg); - - //setting pictureType enum - int format = 0; - var drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); - format = Convert.ToInt32(Enum.Parse(typeof(PictureType), extName)); - - //set picture size and location - if (format != 0) - { - var pictureIds = workbook.AddPicture(memoryStream.ToArray(), format); - XSSFClientAnchor anchor = new XSSFClientAnchor(XSSFShape.EMU_PER_PIXEL * dx1, XSSFShape.EMU_PER_PIXEL * dy1, 0, 0, i, j, 0, 0); - anchor.AnchorType = AnchorType.DontMoveAndResize; - var picture = (XSSFPicture)drawing.CreatePicture(anchor, pictureIds); - var size = picture.GetImageDimension(); - row.HeightInPoints = size.Height; - picture.Resize(); - - //add 105 each new pic - dx1 += 105; - } + cell.SetCellValue(or.work_type_name); } + if (i == 1) + { + cell.SetCellValue(or.location); + } + if (i == 2) + { + cell.SetCellValue(or.formId); + } + if (i == 3) + { + cell.SetCellValue(or.device_name); + } + if (i == 4) + { + cell.SetCellValue(or.status_name); + } + if (i == 5) + { + cell.SetCellValue(or.user_full_name); + } + if (i == 6) + { + cell.SetCellValue(or.start_time); + } + if (i == 7) + { + var imageNames = or.lorf.Count > 0 ? or.lorf.Select(x => x.save_file_name).ToList() : null; + if (imageNames != null) + { + //insert image process + var dy1 = 10; + var dx1 = 10; + + //image column + sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256) + foreach (var ins in imageNames) + { + //image initial + var extName = ins.Split('.')[1].ToUpper().Equals("JPG") ? "PNG" : ins.Split('.')[1].ToUpper(); + var fullPath = Path.Combine(operationFileSaveAsPath, ins); + var img = Image.FromFile(fullPath); + + //compress image + decimal sizeRatio = ((decimal)img.Height / img.Width); + int thumbWidth = 100; + int thumbHeight = decimal.ToInt32(sizeRatio * thumbWidth); + var thumbStream = img.GetThumbnailImage(thumbWidth, thumbHeight, () => false, IntPtr.Zero); + var memoryStream = new MemoryStream(); + thumbStream.Save(memoryStream, ImageFormat.Jpeg); + + //setting pictureType enum + int format = 0; + var drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); + format = Convert.ToInt32(Enum.Parse(typeof(PictureType), extName)); + + //set picture size and location + if (format != 0) + { + var pictureIds = workbook.AddPicture(memoryStream.ToArray(), format); + XSSFClientAnchor anchor = new XSSFClientAnchor(XSSFShape.EMU_PER_PIXEL * dx1, XSSFShape.EMU_PER_PIXEL * dy1, 0, 0, i, j, 0, 0); + anchor.AnchorType = AnchorType.DontMoveAndResize; + var picture = (XSSFPicture)drawing.CreatePicture(anchor, pictureIds); + var size = picture.GetImageDimension(); + row.HeightInPoints = size.Height; + picture.Resize(); + + //add 105 each new pic + dx1 += 105; + } + } + } + + j++; + } + if (i == 8) + { + cell.SetCellValue(or.finish_time); + } + if (i == 9) + { + cell.SetCellValue(or.Created_at); + } + + cell.CellStyle = style12; } - - j++; } - if (i == 9) - { - cell.SetCellValue(or.finish_time.ToString("yyyy/MM/dd HH:mm:ss")); - } - if (i == 10) - { - cell.SetCellValue(or.Created_at); - } - - cell.CellStyle = style12; - } } + else if (ee.work_type == 2) + { + var sqlString = $@"select opr.*, concat(d.device_floor_tag, ' ', d.device_last_name, ' ', d.device_serial_tag) as device_name, ui.full_name as user_full_name + from operation_record opr + left join device d on opr.fix_do_code = d.device_number and d.deleted = 0 and d.device_area_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 1) + and d.device_building_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 2) and d.device_floor_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 5) + and d.device_system_tag = opr.device_system_category_layer2 and d.device_name_tag = opr.device_system_category_layer3 + left join userinfo ui on opr.work_person_id = ui.userinfo_guid + where opr.deleted = 0 and opr.work_type = 2"; + var sheet = workbook.CreateSheet("廠商資料"); + var operation_record = backendRepository.GetAllAsync(sqlString); + List operation_record_file = new List(); + + if (operation_record.Result.Count > 0) + { + foreach (var or in operation_record.Result) + { + sqlString = $@"select * from operation_record_file where record_id = @record_id"; + var param = new { @record_id = or.id }; + operation_record_file = backendRepository.GetAllAsync(sqlString, param).Result; + or.lorf = operation_record_file; + } + + int RowPosition = 0; + #region set cell + IRow row = sheet.CreateRow(RowPosition); + sheet.SetColumnWidth(0, 4 * 160 * 12); + sheet.SetColumnWidth(1, 4 * 160 * 12); + sheet.SetColumnWidth(2, 4 * 160 * 12); + sheet.SetColumnWidth(3, 4 * 160 * 12); + sheet.SetColumnWidth(4, 4 * 160 * 12); + sheet.SetColumnWidth(5, 4 * 160 * 12); + sheet.SetColumnWidth(6, 4 * 160 * 12); + sheet.SetColumnWidth(7, 4 * 160 * 12); + sheet.SetColumnWidth(8, 4 * 160 * 12); + sheet.SetColumnWidth(9, 4 * 160 * 12); + sheet.SetColumnWidth(10, 4 * 160 * 12); + ICell cell = row.CreateCell(0); + cell.SetCellValue("項目"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue("位置"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(2); + cell.SetCellValue("異常代號"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(3); + cell.SetCellValue("表單號"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(4); + cell.SetCellValue("設備名稱"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(5); + cell.SetCellValue("狀態"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(6); + cell.SetCellValue("處理人員"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(7); + cell.SetCellValue("預計施工時間"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(8); + cell.SetCellValue("檔案上傳"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(9); + cell.SetCellValue("完成時間"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(10); + cell.SetCellValue("建立時間"); + cell.CellStyle = styleLine12; + + #endregion + foreach (var or in operation_record.Result) + { + RowPosition += 1; + row = sheet.CreateRow(RowPosition); + for (var i = 0; i < 11; i++)//column + { + cell = row.CreateCell(i); + if (i == 0) + { + cell.SetCellValue(or.work_type_name); + } + if (i == 1) + { + cell.SetCellValue(or.location); + } + if (i == 2) + { + cell.SetCellValue(or.error_code); + sheet.AutoSizeColumn(i); + } + if (i == 3) + { + cell.SetCellValue(or.formId); + } + if (i == 4) + { + cell.SetCellValue(or.device_name); + } + if (i == 5) + { + cell.SetCellValue(or.status_name); + } + if (i == 6) + { + cell.SetCellValue(or.user_full_name); + } + if (i == 7) + { + cell.SetCellValue(or.start_time.ToString("yyyy/MM/dd HH:mm:ss")); + } + if (i == 8)//image + { + var imageNames = or.lorf.Count > 0 ? or.lorf.Select(x => x.save_file_name).ToList() : null; + if (imageNames != null) + { + //insert image process + var dy1 = 10; + var dx1 = 10; + + //image column + sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256) + foreach (var ins in imageNames) + { + //image initial + var extName = ins.Split('.')[1].ToUpper().Equals("JPG") ? "PNG" : ins.Split('.')[1].ToUpper(); + var fullPath = Path.Combine(operationFileSaveAsPath, ins); + var img = Image.FromFile(fullPath); + + //compress image + decimal sizeRatio = ((decimal)img.Height / img.Width); + int thumbWidth = 100; + int thumbHeight = decimal.ToInt32(sizeRatio * thumbWidth); + var thumbStream = img.GetThumbnailImage(thumbWidth, thumbHeight, () => false, IntPtr.Zero); + var memoryStream = new MemoryStream(); + thumbStream.Save(memoryStream, ImageFormat.Jpeg); + + //setting pictureType enum + int format = 0; + var drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); + format = Convert.ToInt32(Enum.Parse(typeof(PictureType), extName)); + + //set picture size and location + if (format != 0) + { + var pictureIds = workbook.AddPicture(memoryStream.ToArray(), format); + XSSFClientAnchor anchor = new XSSFClientAnchor(XSSFShape.EMU_PER_PIXEL * dx1, XSSFShape.EMU_PER_PIXEL * dy1, 0, 0, i, j, 0, 0); + anchor.AnchorType = AnchorType.DontMoveAndResize; + var picture = (XSSFPicture)drawing.CreatePicture(anchor, pictureIds); + var size = picture.GetImageDimension(); + row.HeightInPoints = size.Height; + picture.Resize(); + + //add 105 each new pic + dx1 += 105; + } + } + } + + j++; + } + if (i == 9) + { + cell.SetCellValue(or.finish_time.ToString("yyyy/MM/dd HH:mm:ss")); + } + if (i == 10) + { + cell.SetCellValue(or.Created_at); + } + + cell.CellStyle = style12; + + } + } + } + } + + workbook.Write(fs); } + + apiResult.Code = "0000"; + apiResult.Data = fileName; + } + catch(Exception ex) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message); + return Ok(apiResult); } - var ms = new NpoiMemoryStream - { - AllowClose = false - }; - workbook.Write(ms); - ms.Flush(); - ms.Seek(0, SeekOrigin.Begin); - - return File(ms, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "廠商資料.xlsx"); + return Ok(apiResult); } #region 廠商 @@ -749,9 +774,14 @@ namespace FrontendWebApi.ApiControllers // sWhere += $@" and convert(of.created_at, DATE) = convert(ADDDATE(NOW(), -1), DATE)"; //} - if (ofl.sub_system_tag != null || ofl.main_system_tag != null) + if (ofl.main_system_tag != null) { - sWhere += $@" and (ofi.device_system_category_layer2 = ifnull(@main_system_tag, device_system_category_layer2) AND ofi.device_system_category_layer3 = ifnull(@sub_system_tag, device_system_category_layer3))"; + sWhere += $@" and ofi.device_system_category_layer2 in @main_system_tag"; + + } + if (ofl.sub_system_tag != null) + { + sWhere += $@" and ofi.device_system_category_layer3 in @sub_system_tag"; } var sqlString = @$"select ofi.*, v2.system_key @@ -996,11 +1026,15 @@ namespace FrontendWebApi.ApiControllers // sWhere += $@" and convert(opr.created_at, DATE) = convert(ADDDATE(NOW(), -1), DATE)"; //} - if (ofl.sub_system_tag != null || ofl.main_system_tag != null) + if (ofl.main_system_tag != null) { - sWhere += $@" and (opr.device_system_category_layer2 = ifnull(@main_system_tag, opr.device_system_category_layer2) AND opr.device_system_category_layer3 = ifnull(@sub_system_tag, opr.device_system_category_layer3))"; + sWhere += $@" and opr.device_system_category_layer2 in @main_system_tag"; + + } + if (ofl.sub_system_tag != null) + { + sWhere += $@" and opr.device_system_category_layer3 in @sub_system_tag"; } - if (ofl.serial_number != null) { sWhere += $@" and opr.formId like '%@formId%'"; diff --git a/FrontendWebApi/Models/HistoryClass.cs b/FrontendWebApi/Models/HistoryClass.cs index d9a08b4..fd71eec 100644 --- a/FrontendWebApi/Models/HistoryClass.cs +++ b/FrontendWebApi/Models/HistoryClass.cs @@ -271,5 +271,6 @@ namespace FrontendWebApi.Models public DateTime starttime { get; set; } public DateTime? endtime { get; set; } public string dateType { get; set; } + public string type { get; set; } } } diff --git a/FrontendWebApi/Models/Operation.cs b/FrontendWebApi/Models/Operation.cs index 74c52fd..94712f0 100644 --- a/FrontendWebApi/Models/Operation.cs +++ b/FrontendWebApi/Models/Operation.cs @@ -44,8 +44,8 @@ namespace FrontendWebApi.Models public DateTime? end_created_at { get; set; }//结束建立时间 //public bool today { get; set; }//今天建立时间 //public bool yesterday { get; set; }//昨天建立时间 - public string main_system_tag { get; set; }//大类tag - public string sub_system_tag { get; set; }//小类tag + public List main_system_tag { get; set; }//大类tag + public List sub_system_tag { get; set; }//小类tag public byte? work_type { get; set; } // 1:保養, 2:維修 } @@ -125,4 +125,16 @@ namespace FrontendWebApi.Models public string ori_file_name { get; set; } public string save_file_name { get; set; } } + + public class Find_Sub_List + { + public List main_system_tag { get; set; } + } + + public class ExportExcel + { + public byte? work_type { get; set; } + public DateTime? startdate { get; set; } + public DateTime? enddate { get; set; } + } }