diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index 4153bc4..ed2451c 100644 --- a/Backend/Controllers/NiagaraDataSynchronizeController.cs +++ b/Backend/Controllers/NiagaraDataSynchronizeController.cs @@ -164,7 +164,7 @@ namespace Backend.Controllers var urlSlots = backendRepository.GetAllAsync("select obixSlot from building where deleted = 0").Result; //foreach(var us in urlSlots) //{ - var data = svc.obixHisQuery(obixApiConfig.ApiBase + "obix/config/Program/ObixQuery/query/", obixApiConfig.ApiBase + "obix/histories", "", + var data = svc.obixHisQuery_v2(obixApiConfig.ApiBase + "obix/config/Program/ObixQuery/query/", obixApiConfig.ApiBase + "obix/histories", "", obixApiConfig.UserName, obixApiConfig.Password); ds.AddRange(data); // } diff --git a/Backend/Views/NiagaraDataSynchronize/Index.cshtml b/Backend/Views/NiagaraDataSynchronize/Index.cshtml index 98cfe79..48f6bdc 100644 --- a/Backend/Views/NiagaraDataSynchronize/Index.cshtml +++ b/Backend/Views/NiagaraDataSynchronize/Index.cshtml @@ -52,6 +52,14 @@
+
+
+
+
+
+
+ + @@ -60,7 +68,7 @@ - +
point_name
@@ -79,6 +87,7 @@ var buildingId, building; var rawDataImportTable; var ds; + var dataInTable; var today = new Date(); var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate(); @@ -89,6 +98,9 @@ projectName(); rawDataImportTable = $("#niagara_data_table").DataTable({ + //paging: false, + searching: false, + destroy: true, "columns": [ { "data": "value" @@ -118,7 +130,10 @@ { v.value = v.value.replace("$3", ""); v.tag_name = v.tag_name.replace("$3", ""); - v.point_name = v.point_name.replace("$3", ""); + if (v.point_name != null) + { + v.point_name = v.point_name.replace("$3", ""); + } } }) //console.log(ds) @@ -131,6 +146,8 @@ var dateTime = date + ' ' + time; document.getElementById('loadDataText').innerText = "共 " + rel.data.length + " 筆資料 \n" + dateTime; } + dataInTable = data; + console.log("---", dataInTable); return data; } } @@ -253,5 +270,169 @@ } }, 'json'); } + + let buildingValue, systemMainId, systemMainValue, systemSubId, systemSubValue; + + document.querySelector(".building_select").addEventListener("click", (e) => { + buildingValue = e.target.dataset.value; + $(".building_select .btn-info.active").removeClass('btn-info active') + $(e.target).addClass('btn-info active'); + }) + document.querySelector(".systemSubType_select").addEventListener("click", (e) => { + systemSubId = e.target.dataset.value; + systemSubValue = e.target.dataset.systemValue; + $(".systemSubType_select .btn-info.active").removeClass('btn-info active') + $(e.target).addClass('btn-info active'); + }) + + $(function () { + // 產生所有棟別下拉式選單 + fetch("/BuildInfo/BuildInfoList", { + method: "POST" + }).then(res => res.json()).then(({ data }) => { + const buildingElement = document.querySelector(".building_select"); + + console.log(data); + let str = ""; + data.forEach(({ full_name, building_tag + }) => { + if (building_tag.includes("$3")) { + building_tag = building_tag.replace("$3", ""); + } + str += ``; + }) + buildingElement.innerHTML = str; + }); + + // 產生所有大類系統下拉式選單 + const systemMainTypeElement = document.querySelector(".systemMainType_select"); + let init_id = ''; + fetch("/SystemCategory/SystemMainList", { + method: "POST" + }).then(res => res.json()).then(({ data }) => { + //console.log(data); + init_id = data[0].id; + //console.log(init_id); + let str = ""; + data.forEach(({ id, system_key, system_value + }) => { + str += ``; + }) + systemMainTypeElement.innerHTML = str; + FetchSystenSubList(init_id); + }); + + // 產生所有小類系統下拉式選單 + systemMainTypeElement.addEventListener("click", (e) => { + systemMainId = e.target.dataset.value; + systemMainValue = e.target.dataset.systemValue; + $(".systemMainType_select .btn-info.active").removeClass('btn-info active') + $(e.target).addClass('btn-info active'); + //console.log(value); + + FetchSystenSubList(systemMainId); + }) + }); + + function FetchSystenSubList(id) { + var formData = new FormData(); + formData.append("id", parseInt(id)); + + fetch("/SystemCategory/SystemSubList", { + method: "POST", + body: formData + }).then(res => res.json()).then(({ data }) => { + const systemSubTypeElement = document.querySelector(".systemSubType_select"); + + //console.log(data); + let str = ""; + data.forEach(({ id, system_key, system_value + }) => { + str += ``; + }); + systemSubTypeElement.innerHTML = str; + }) + } + + // 查詢功能,查棟別跟大類 + const searchButton = document.querySelector("#search"); + searchButton.addEventListener("click", (e) => { + //const buildingValue = document.querySelector(".building_select").value; + //const systemMainId = document.querySelector(".systemMainType_select").value; + //const systemMainValue = document.querySelector(`option[value='${systemMainId}']`).getAttribute("data-system-value"); + //const systemSubId = document.querySelector(".systemSubType_select").value; + //const systemSubValue = document.querySelector(`option[value='${systemSubId}']`).getAttribute("data-system-value"); + + console.log("111", buildingValue, systemMainValue); + + const table_body = document.querySelector('.raw_data'); + let rawdata_table_body = ''; + let count = 1; + //dataInTable.forEach(({ tag_name, value, point_name + //}) => { + // console.log("111", buildingValue, systemMainValue, systemSubValue); + // console.log("222", tag_name.includes(`_${buildingValue}_`), tag_name.includes(`_${systemMainValue}_`), tag_name.includes(`_${systemSubValue}_`)); + // console.log("333", tag_name, value); + // console.log("444", rawdata_table_body); + + // if (tag_name.includes(`_${buildingValue}_`) && tag_name.includes(`_${systemMainValue}_`)) { + // console.log("333", tag_name, value); + // let odd_or_even = ''; + // if (count % 2 == 0) { + // odd_or_even = 'odd'; + // } else { + // odd_or_even = 'even'; + // } + + // rawdata_table_body += `${value}${tag_name}${point_name}`; + // } + + //}); + //table_body.innerHTML = rawdata_table_body; + let search_str = `_${buildingValue}_${systemMainValue}_${systemSubValue}_`; + console.log("$$$", search_str, dataInTable.filter(({ tag_name }) => tag_name.includes(search_str))) + $("#niagara_data_table").DataTable({ + //paging: false, + searching: false, + destroy: true, + "columns": [ + { + "data": "value" + }, + { + "data": "tag_name" + }, + { + "data": "point_name" + }, + ], + data: dataInTable.filter(({ tag_name }) => tag_name.includes(search_str)) + }) + }) + + const noFilterButton = document.querySelector("#no_filter"); + noFilterButton.addEventListener("click", (e) => { + $(".building_select .btn-info.active").removeClass('btn-info active'); + $(".systemMainType_select .btn-info.active").removeClass('btn-info active'); + $(".systemSubType_select .btn-info.active").removeClass('btn-info active'); + $("#niagara_data_table").DataTable({ + //paging: false, + searching: false, + destroy: true, + "columns": [ + { + "data": "value" + }, + { + "data": "tag_name" + }, + { + "data": "point_name" + }, + ], + data: dataInTable + }) + }) + } \ No newline at end of file diff --git a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs index 9842dad..cc860f5 100644 --- a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs @@ -302,6 +302,7 @@ namespace BackendWorkerService.Quartz.Jobs `count_rawdata` int(11) NULL DEFAULT NULL, `min_rawdata` decimal(15, 3) NULL DEFAULT NULL, `max_rawdata` decimal(15, 3) NULL DEFAULT NULL, + `kwh_result` decimal(15, 3) NULL DEFAULT NULL, `avg_rawdata` decimal(15, 3) NULL DEFAULT NULL, `sum_rawdata` decimal(15, 3) NULL DEFAULT NULL, `is_complete` tinyint(3) UNSIGNED NULL DEFAULT NULL COMMENT '是否完成,0:未完成 1:完成', @@ -317,6 +318,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, + kwh_result = @max_rawdata - @min_rawdata, avg_rawdata = @avg_rawdata, sum_rawdata = @sum_rawdata, is_complete = @is_complete, @@ -335,6 +337,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata, min_rawdata, max_rawdata, + kwh_result, avg_rawdata, sum_rawdata, is_complete, @@ -348,6 +351,7 @@ namespace BackendWorkerService.Quartz.Jobs @count_rawdata, @min_rawdata, @max_rawdata, + @max_rawdata - @min_rawdata, @avg_rawdata, @sum_rawdata, @is_complete, @@ -366,6 +370,7 @@ namespace BackendWorkerService.Quartz.Jobs [count_rawdata] [int] NULL, [min_rawdata] [decimal](15, 3) NULL, [max_rawdata] [decimal](15, 3) NULL, + [kwh_result] [decimal](15, 3) NULL, [avg_rawdata] [decimal](15, 3) NULL, [sum_rawdata] [decimal](15, 3) NULL, [is_complete] [tinyint] NULL, @@ -398,6 +403,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, + kwh_result = @max_rawdata - @min_rawdata, avg_rawdata = @avg_rawdata, sum_rawdata = @sum_rawdata, is_complete = @is_complete, @@ -418,6 +424,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata, min_rawdata, max_rawdata, + kwh_result, avg_rawdata, sum_rawdata, is_complete, @@ -431,6 +438,7 @@ namespace BackendWorkerService.Quartz.Jobs @count_rawdata, @min_rawdata, @max_rawdata, + @max_rawdata - @min_rawdata @avg_rawdata, @sum_rawdata, @is_complete, @@ -778,11 +786,11 @@ namespace BackendWorkerService.Quartz.Jobs if (electricArchiveWeekRawDatas.Count() > 0) { var sql = $@" - UPDATE archive_electric_meter_week SET count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, + kwh_result = @max_rawdata - @min_rawdata, avg_rawdata = @avg_rawdata, sum_rawdata = @sum_rawdata, is_complete = @is_complete, @@ -802,6 +810,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata, min_rawdata, max_rawdata, + kwh_result, avg_rawdata, sum_rawdata, is_complete, @@ -815,6 +824,7 @@ namespace BackendWorkerService.Quartz.Jobs @count_rawdata, @min_rawdata, @max_rawdata, + @max_rawdata - @min_rawdata, @avg_rawdata, @sum_rawdata, @is_complete, @@ -829,6 +839,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, + kwh_result = @max_rawdata - @min_rawdata, avg_rawdata = @avg_rawdata, sum_rawdata = @sum_rawdata, is_complete = @is_complete, @@ -849,6 +860,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata, min_rawdata, max_rawdata, + kwh_result, avg_rawdata, sum_rawdata, is_complete, @@ -862,6 +874,7 @@ namespace BackendWorkerService.Quartz.Jobs @count_rawdata, @min_rawdata, @max_rawdata, + @max_rawdata - @min_rawdata, @avg_rawdata, @sum_rawdata, @is_complete, @@ -1163,6 +1176,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, + kwh_result = @max_rawdata - @min_rawdata, avg_rawdata = @avg_rawdata, sum_rawdata = @sum_rawdata, is_complete = @is_complete, @@ -1181,6 +1195,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata, min_rawdata, max_rawdata, + kwh_result, avg_rawdata, sum_rawdata, is_complete, @@ -1194,6 +1209,7 @@ namespace BackendWorkerService.Quartz.Jobs @count_rawdata, @min_rawdata, @max_rawdata, + @max_rawdata - @min_rawdata, @avg_rawdata, @sum_rawdata, @is_complete, @@ -1207,6 +1223,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, + kwh_result = @max_rawdata - @min_rawdata, avg_rawdata = @avg_rawdata, sum_rawdata = @sum_rawdata, is_complete = @is_complete, @@ -1227,6 +1244,7 @@ namespace BackendWorkerService.Quartz.Jobs count_rawdata, min_rawdata, max_rawdata, + kwh_result, avg_rawdata, sum_rawdata, is_complete, @@ -1240,6 +1258,7 @@ namespace BackendWorkerService.Quartz.Jobs @count_rawdata, @min_rawdata, @max_rawdata, + @max_rawdata - @min_rawdata, @avg_rawdata, @sum_rawdata, @is_complete, diff --git a/Frontend/_alert.html b/Frontend/_alert.html index 54c8da9..8406a1f 100644 --- a/Frontend/_alert.html +++ b/Frontend/_alert.html @@ -774,10 +774,11 @@ function getData(type = null) { dataAlarm = []; $(loadEle).Loading("start"); - let enddate = new Date(new Date().setDate(new Date(pageAct.alr_enddate).getDate() + 1)).getTime(); + let enddate = new Date(pageAct.alr_enddate + " 23:59:59").getTime(); + let startdate = new Date(pageAct.alr_startdate + " 00:00:00").getTime(); if (pageAct.SysType == "all") { - getAllDeviceAlarmByBaja(new Date(pageAct.alr_startdate).getTime(), enddate, pageAct.return, pageAct.confirm, callBackFromAllDeviceAlert); + getAllDeviceAlarmByBaja(startdate, enddate, pageAct.return, pageAct.confirm, callBackFromAllDeviceAlert); } else { let elem = $('input[type=checkbox][data-type=sub]:checked'); @@ -788,12 +789,12 @@ elem.each(function (i, v) { if (v?.id === "other") { console.log(v?.id) - getOtherAlarmByBaja(new Date(pageAct.alr_startdate).getTime(), enddate, pageAct.return, pageAct.confirm, stackData); + getOtherAlarmByBaja(startdate, enddate, pageAct.return, pageAct.confirm, stackData); } else { pageAct.selSysMain = $(v).parent().data('main'); pageAct.selSysSub = $(v).prop('id'); - getAlarmByBaja(new Date(pageAct.alr_startdate).getTime(), enddate, pageAct.return, pageAct.confirm, pageAct.selSysMain + "_" + pageAct.selSysSub + "_AlarmClass", stackData); + getAlarmByBaja(startdate, enddate, pageAct.return, pageAct.confirm, pageAct.selSysMain + "_" + pageAct.selSysSub + "_AlarmClass", stackData); } }); } @@ -875,7 +876,7 @@ { "title": "設備名稱", "data": "sourceName_zh", - "render" : function (data) { + "render": function (data) { return allDevices.find(d => d.device_number === data)?.full_name || "" } }, @@ -921,7 +922,7 @@ ]; historyTable = new YourTeam.JqDataTables.getTableByStatic(tag, data, columns, column_defs, null, null, null, null, "tpi"); - $('#alertTable').DataTable().order([ 5, 'desc']); + $('#alertTable').DataTable().order([5, 'desc']); $(loadEle).Loading("close"); } diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html index 76c8861..3a1a282 100644 --- a/Frontend/_historyData.html +++ b/Frontend/_historyData.html @@ -284,19 +284,7 @@ $('#devPointsList').html(strHtml); if (!hisFirst) { - let start = new Date($('#his_startdate').val()); - let end = new Date(new Date().setDate(new Date($('#his_enddate input').val()).getDate() + 1)); - - if (pageAct.dateType == "today" || pageAct.dateType == "day" || pageAct.dateType == "ytd") - end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 1)); - else if (pageAct.dateType == "month") { - start = new Date($('#getmonth').val()); - end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 30)); - } - else if (pageAct.dateType != "range") - return; - - getData(formatDate(start, "date", true), formatDate(end, "date", true)); + searchDate(); } } ytAjax = new YourTeam.Ajax(url, objSendData, success, null, "POST").send(); @@ -306,8 +294,8 @@ $(loadEle).Loading("start"); var sdt = new Date(); var edt = new Date(new Date().setDate(sdt.getDate() + 1)); - start = start ?? sdt.toLocaleDateString(); - end = end ?? edt.toLocaleDateString(); + start = start + " 00:00:00" ?? sdt.toLocaleDateString(); + end = end + " 23:59:59" ?? edt.toLocaleDateString(); let sendData = { device_number: pageAct.deviceNumber, @@ -356,19 +344,7 @@ pageAct.devicePoiName = $(elem).text(); pageAct.deviceItem = deviceItem; - let start = new Date($('#his_startdate').val()); - let end = new Date(new Date().setDate(new Date($('#his_enddate input').val()).getDate() + 1)); - - if (pageAct.dateType == "today" || pageAct.dateType == "day" || pageAct.dateType == "ytd") - end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 1)); - else if (pageAct.dateType == "month") { - start = new Date($('#getmonth').val()); - end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 30)); - } - else if (pageAct.dateType != "range") - return; - - getData(formatDate(start, "date", true), formatDate(end, "date", true)); + searchDate(); } } @@ -387,10 +363,10 @@ $('#getmonth').css('display', 'none'); $('#his_startdate').val(date); - if (type == "today") - getData(formatDate(now, "date", true), formatDate(tmr, "date", true)); - else if (type == "ytd") - getData(formatDate(ytd, "date", true), formatDate(now, "date", true)); + if (type == "today") + getData(formatDate(now, "date", true), formatDate(now, "date", true)); + else if (type == "ytd") + getData(formatDate(ytd, "date", true), formatDate(ytd, "date", true)); else { $(`[onclick="setDateType('today', this)"]`).removeClass('btn-secondary'); $(`[onclick="setDateType('today', this)"]`).addClass('btn-info'); @@ -426,18 +402,21 @@ } function searchDate() { - let start = new Date($('#his_startdate').val()); - let end = new Date(new Date().setDate(new Date($('#his_enddate input').val()).getDate() + 1)); + let start = new Date($('#his_startdate').val()); + let end = new Date($('#his_enddate input').val()); if (pageAct.dateType == "today" || pageAct.dateType == "day" || pageAct.dateType == "ytd") - end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 1)); + end = start; else if (pageAct.dateType == "month") { - start = new Date($('#getmonth').val()); - end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 30)); + start = new Date($('#getmonth').val()); + end = new Date(start.valueOf()).setMonth(start.getMonth() + 1); + end = new Date(new Date(end).setDate(new Date(end).getDate() - 1)); } else if (pageAct.dateType != "range") return; + pageAct.hisStartDate = start; + pageAct.hisEndDate = end; getData(formatDate(start, "date", true), formatDate(end, "date", true)); } @@ -506,8 +485,9 @@ let token = cookies.get("JWT-Authorization"); let url = baseApiUrl + "/api/ExportHistory"; let v = {}; - v.starttime = (pageAct.dateType == "month" ? new Date($('#getmonth').val()) : new Date($('#his_startdate').val())); - v.endtime = $('#his_enddate input').val() === "" ? null : new Date($('#his_enddate input').val()); + + v.starttime = pageAct.hisStartDate; + v.endtime = pageAct.hisEndDate; v.dateType = pageAct.dateType; v.device_number = pageAct.deviceNumber; objSendData.Data = v; diff --git a/Frontend/_operation.html b/Frontend/_operation.html index 0e6f5e6..2a4fbf9 100644 --- a/Frontend/_operation.html +++ b/Frontend/_operation.html @@ -636,7 +636,7 @@ { "targets": [7], "width": "6%", "sortable": true }, { "targets": [8], "width": "15%", "sortable": false }, { "targets": [9], "width": "6%", "sortable": false }, - { "targets": [10], "width": "8%", "sortable": false }, + { "targets": [10], "width": "8%", "sortable": true }, { "targets": [11], "width": "8%", "sortable": false }, ]; @@ -653,7 +653,7 @@ "title": "異常代號", "data": "error_code", render: (data) => { - return data?.split('-')[0] || ''; + return data?.split('-')[0] || '' == null ? '' : data?.split('-')[0] || ''; } }, { @@ -755,7 +755,8 @@ { "targets": [7], "width": "15%", "sortable": false }, { "targets": [8], "width": "6%", "sortable": false }, { "targets": [9], "width": "8%", "sortable": false }, - { "targets": [10], "width": "8%", "sortable": false }, + { "targets": [10], "width": "8%", "sortable": true }, + { "targets": [11], "width": "8%", "sortable": false }, ]; columns = [ @@ -771,7 +772,7 @@ "title": "異常代號", "data": "error_code", render: (data) => { - return data?.split('-')[0] || ''; + return data?.split('-')[0] || '' == null ? '' : data?.split('-')[0] || ''; } }, { @@ -881,6 +882,7 @@ pageAct.startdate = startdate; pageAct.enddate = enddate; + if ($('#startdate').val() > $('#enddate').val()) { $('#startdate').val($('#startdate').data('val')); $('#enddate').val($('#enddate').data('val')); @@ -891,20 +893,23 @@ let ytd = displayDate(new Date(new Date().setDate(new Date().getDate() - 1)), 'date').replaceAll('/', '-') if (dateType == 'tdy') { - pageAct.startdate = new Date(displayDate(new Date(new Date().setDate(new Date().getDate())), 'date')); + pageAct.startdate = displayDate(new Date(new Date().setDate(new Date().getDate())), 'datetime').toString().replaceAll("/", "-").split(" ")[0] + "T00:00:00"; + pageAct.enddate = displayDate(new Date(new Date().setDate(new Date().getDate())), 'datetime').toString().replaceAll("/", "-").split(" ")[0] + "T23:59:59"; $('#startdate').val(today); $('#startdate').data('val', today); $('#enddate').val(today); $('#enddate').data('val', today); } else if (dateType == 'ytd') { - pageAct.startdate = new Date(displayDate(new Date(new Date().setDate(new Date().getDate() - 1)), 'date')); + pageAct.startdate = displayDate(new Date(new Date().setDate(new Date().getDate() - 1)), 'datetime').toString().replaceAll("/", "-").split(" ")[0] + "T00:00:00"; + pageAct.enddate = displayDate(new Date(new Date().setDate(new Date().getDate() - 1)), 'datetime').toString().replaceAll("/", "-").split(" ")[0] + "T23:59:59"; $('#startdate').val(ytd); $('#startdate').data('val', ytd); $('#enddate').val(ytd); $('#enddate').data('val', ytd); } else { + pageAct.enddate = displayDate(new Date(pageAct.enddate.valueOf()).setDate(pageAct.enddate.getDate()), 'date').toString().replaceAll("/", "-") + "T23:59:59"; $(`[onclick^=setDate]`).removeClass('btn-info'); $(`[onclick^=setDate]`).addClass('btn-secondary'); if ($('#startdate').val() == $('#enddate').val()) { @@ -941,6 +946,8 @@ function snSearch() { clearPageAct(); + pageAct.startdate = $('#startdate').val() + "T00:00:00"; + pageAct.enddate = $('#enddate').val() + "T23:59:59" pageAct.serial_number = $('#serial_number').val() || null; refTable(); } @@ -1007,7 +1014,6 @@ startdate: pageAct.startdate == undefined ? null : pageAct.startdate, enddate: pageAct.enddate == undefined ? null : pageAct.enddate, }; - console.log("data", objSendData.Data) ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) { if (rel.code == "0000") location.href = baseApiUrl + "/api/df?path=" + rel.data.split('/')[0] + "&fileName=" + rel.data.split('/')[1] + "&token=" + cookies.get("JWT-Authorization"); @@ -1307,8 +1313,8 @@ //fd.append("end_time", ($('#inpEndTime').val() || null) == null ? $('#inpEndTime').val() : new Date($('#inpEndTime').val()).toISOString()); //fd.append("work_time", ($('#inpWorTime').val() || null) == null ? $('#inpWorTime').val() : new Date($('#inpWorTime').val()).toISOString()); fd.append("finish_time", (parseInt($('#' + (pageAct.work_type == '1' ? 'inpStatus' : 'inpStatus_2') + ' [name=' + (pageAct.work_type == '1' ? 'inpSta' : 'inpSta_2') + ']:checked').data('value'))) == 1 ? new Date(Date.now()).toISOString() : null); - fd.append("notice", $(pageAct.work_type == "1" ? '#inpNotice' : '#inpNotice_2').val() || null); - fd.append("description", $(pageAct.work_type == "1" ? '#inpDescription' : '#inpDescription_2').val() || null); + fd.append("notice", $(pageAct.work_type == "1" ? '#inpNotice' : '#inpNotice_2').val() || ''); + fd.append("description", $(pageAct.work_type == "1" ? '#inpDescription' : '#inpDescription_2').val() || ''); //let sendData = { // location: $('#inpArea option:selected').text() + $('#inpBuilding option:selected').text() + $('#inpFloor option:selected').text(), @@ -1360,6 +1366,7 @@ clearOpeRecPageAct(); selUser(); selDevice(); + selOpeFir(); $('#ope_forImage').html(''); $('#ope_forFile').html(''); @@ -1397,7 +1404,7 @@ $(pageAct.work_type == "1" ? '#inpDescription' : '#inpDescription_2').val(res.data.description); let elemSel = $(pageAct.work_type == "1" ? '#inpFixDoCode' : '#inpFixDoCode_2').find('option:selected');; pageAct.number = elemSel.val(); - selOpeFir(); + ope_imgHtml = null; $.each(res.data.lorf, function (i, v) { @@ -1499,7 +1506,7 @@ $.each(res.data, function (i, v) { msg = v.msgText != null ? ($.trim(v.msgText.toString()).length > 0 ? v.msgText.split(':')[0] : '') : ''; - strHtml += ``; + strHtml += ``; }); if (res.count > 0) $(pageAct.work_type == '1' ? '#inpErrCode' : '#inpErrCode_2').html(strHtml); diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index 34b4c2c..e67160b 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -98,10 +98,10 @@ namespace FrontendWebApi.ApiControllers if (input.tableType == "year") { sqlGroup = $@" group by year(start_timestamp), year(end_timestamp), device_number "; - sqlAvgRawData = " round(avg(avg_rawdata), 2) as avg_rawdata, year(start_timestamp) as start_timestamp, year(end_timestamp) as end_timestamp "; + sqlAvgRawData = " round(avg(kwh_result), 2) as avg_rawdata, year(start_timestamp) as start_timestamp, year(end_timestamp) as end_timestamp "; } else - sqlAvgRawData = " round(avg_rawdata, 2) as avg_rawdata, start_timestamp, end_timestamp "; + sqlAvgRawData = " round(kwh_result, 2) as avg_rawdata, start_timestamp, end_timestamp "; var table = input.tableType == "year" ? "archive_electric_meter_month" : "archive_electric_meter_" + input.tableType + (input.tableType == "day" ? "_" + dbDateName : ""); var schema = await backendRepository.GetOneAsync($"select system_value from variable where system_type = 'project_name'"); @@ -142,6 +142,7 @@ namespace FrontendWebApi.ApiControllers {sqlWhere} {sqlGroup} ) aemm on aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} and aemm.device_number = fd.device_number order by fd.device_number, fd.date"; + Logger.LogInformation("SQL = " + sql + " startTime=" + startTime + " endTime=" + endTime + " building=" + input.building_tag + " floor_tag = " + input.floor_tag); var rawData = await backendRepository.GetAllAsync(sql, new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, dateFormat = dateFormat }); @@ -561,7 +562,7 @@ namespace FrontendWebApi.ApiControllers ms.Flush(); ms.Seek(0, SeekOrigin.Begin); Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); - return File(ms, "application/vnd.ms", "電表報表.xlsx"); + return File(ms, "application/vnd.ms", @$"電表報表{System.DateTime.Now.ToString("yyyyMMddHHmm")}.xlsx"); } [HttpPost] @@ -795,7 +796,7 @@ namespace FrontendWebApi.ApiControllers ms.Flush(); ms.Seek(0, SeekOrigin.Begin); Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); - return File(ms, "application/vnd.ms-excel", "電表報表.xlsx"); + return File(ms, "application/vnd.ms-excel", @$"電表報表{System.DateTime.Now.ToString("yyyyMMddHHmm")}.xlsx"); } public static int GetDayInMonth(string yearMonth) diff --git a/FrontendWebApi/ApiControllers/OperationController.cs b/FrontendWebApi/ApiControllers/OperationController.cs index 70679ec..92c14bd 100644 --- a/FrontendWebApi/ApiControllers/OperationController.cs +++ b/FrontendWebApi/ApiControllers/OperationController.cs @@ -351,35 +351,35 @@ namespace FrontendWebApi.ApiControllers cell = row.CreateCell(i); if (i == 0) { - cell.SetCellValue(of.system_key); + cell.SetCellValue(of.system_key ?? ""); } if (i == 1) { - cell.SetCellValue(of.name); + cell.SetCellValue(of.name ?? ""); } if (i == 2) { - cell.SetCellValue(of.contact_person); + cell.SetCellValue(of.contact_person ?? ""); } if (i == 3) { - cell.SetCellValue(of.phone); + cell.SetCellValue(of.phone ?? ""); } if (i == 4) { - cell.SetCellValue(of.email); + cell.SetCellValue(of.email ?? ""); } if (i == 5) { - cell.SetCellValue(of.tax_id_number); + cell.SetCellValue(of.tax_id_number ?? ""); } if (i == 6) { - cell.SetCellValue(of.remark); + cell.SetCellValue(of.remark ?? ""); } if (i == 7) { - cell.SetCellValue(of.Created_at); + cell.SetCellValue(of.Created_at ?? ""); } cell.CellStyle = style12; @@ -389,343 +389,352 @@ namespace FrontendWebApi.ApiControllers } else if (ee.work_type == 1) { - 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 + var sqlString = $@"select opr.*, d.full_name 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_building_tag = SUBSTRING_INDEX(SUBSTRING_INDEX(opr.fix_do_code, '_', 2), '_', -1) and d.device_floor_tag = SUBSTRING_INDEX(SUBSTRING_INDEX(opr.fix_do_code, '_', 5), '_', -1) 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) - { - 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; - #endregion - foreach (var or in operation_record.Result) - { - RowPosition += 1; - row = sheet.CreateRow(RowPosition); - for (var i = 0; i < 10; i++) - { - 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.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 != null ? ((DateTime)or.start_time).ToString("yyyy/MM/dd HH:mm:dd") : null); - } - 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 != null ? ((DateTime)or.finish_time).ToString("yyyy/MM/dd HH:mm:dd") : null); - } - if (i == 9) - { - 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"; + where opr.deleted = 0 and opr.work_type = 1 and opr.created_at >= '{ee.startdate.ToString().Split("_")[0] + "T00:00:00"}' and opr.created_at <= '{ee.enddate.ToString().Split("_")[0] + "T23:59:59"}';"; var sheet = workbook.CreateSheet("廠商資料"); var operation_record = backendRepository.GetAllAsync(sqlString); List operation_record_file = new List(); - if (operation_record.Result.Count > 0) + if (operation_record.Result != null) { - foreach (var or in operation_record.Result) + if (operation_record.Result.Count > 0) { - 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 + foreach (var or in operation_record.Result) { - cell = row.CreateCell(i); - if (i == 0) + 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; + #endregion + foreach (var or in operation_record.Result) + { + RowPosition += 1; + row = sheet.CreateRow(RowPosition); + for (var i = 0; i < 10; i++) { - 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 != null ? ((DateTime)or.start_time).ToString("yyyy/MM/dd HH:mm:ss") : null); - } - if (i == 8)//image - { - var imageNames = or.lorf.Count > 0 ? or.lorf.Select(x => x.save_file_name).ToList() : null; - if (imageNames != null) + cell = row.CreateCell(i); + if (i == 0) { - //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.SetCellValue(or.work_type_name == "null" ? "" : or.work_type_name); + } + if (i == 1) + { + cell.SetCellValue(or.location == "null" ? "" : or.location); + } + if (i == 2) + { + cell.SetCellValue(or.formId == "null" ? "" : or.formId); + } + if (i == 3) + { + cell.SetCellValue(or.device_name == "null" ? "" : or.device_name); + } + if (i == 4) + { + cell.SetCellValue(or.status_name == "null" ? "" : or.status_name); + } + if (i == 5) + { + cell.SetCellValue(or.user_full_name == "null" ? "" : or.user_full_name); + } + if (i == 6) + { + cell.SetCellValue(or.start_time != null ? ((DateTime)or.start_time).ToString("yyyy/MM/dd HH:mm:dd") : null); + } + if (i == 7) + { + var imageNames = or.lorf.Count > 0 ? or.lorf.Where(x => x.ori_file_name.Contains("JPG") || x.ori_file_name.Contains("PNG")).Select(x => x.save_file_name).ToList() : null; + if (imageNames != null) { - //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); + //insert image process + var dy1 = 10; + var dx1 = 10; - //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) + //image column + sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256) + foreach (var ins in imageNames) { - 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(); + //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); - //add 105 each new pic - dx1 += 105; + //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 != null ? ((DateTime)or.finish_time).ToString("yyyy/MM/dd HH:mm:dd") : null); + } + if (i == 9) + { + cell.SetCellValue(or.Created_at ?? ""); } - j++; - } - if (i == 9) - { - cell.SetCellValue(or.finish_time != null ? ((DateTime)or.finish_time).ToString("yyyy/MM/dd HH:mm:ss") : null); - } - if (i == 10) - { - cell.SetCellValue(or.Created_at); + cell.CellStyle = style12; } + } + } - cell.CellStyle = style12; + } + } + else if (ee.work_type == 2) + { + var sqlString = $@"select opr.*, d.full_name 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(SUBSTRING_INDEX(opr.fix_do_code, '_', 2), '_', -1) and d.device_floor_tag = SUBSTRING_INDEX(SUBSTRING_INDEX(opr.fix_do_code, '_', 5), '_', -1) + 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 and opr.created_at >= '{ee.startdate.ToString().Split("_")[0] + "T00:00:00"}' and opr.created_at <= '{ee.enddate.ToString().Split("_")[0] + "T23:59:59"}';"; + var sheet = workbook.CreateSheet("廠商資料"); + var operation_record = backendRepository.GetAllAsync(sqlString); + List operation_record_file = new List(); + + if (operation_record.Result != null) + { + 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 == "null" ? "" : or.work_type_name); + } + if (i == 1) + { + cell.SetCellValue(or.location == "null" ? "" : or.location); + } + if (i == 2) + { + cell.SetCellValue(or.error_code == "null" ? "" : or.error_code); + sheet.AutoSizeColumn(i); + } + if (i == 3) + { + cell.SetCellValue(or.formId == "null" ? "" : or.formId); + } + if (i == 4) + { + cell.SetCellValue(or.device_name == "null" ? "" : or.device_name); + } + if (i == 5) + { + cell.SetCellValue(or.status_name == "null" ? "" : or.status_name); + } + if (i == 6) + { + cell.SetCellValue(or.user_full_name == "null" ? "" : or.user_full_name); + } + if (i == 7) + { + cell.SetCellValue(or.start_time != null ? ((DateTime)or.start_time).ToString("yyyy/MM/dd HH:mm:ss") : null); + } + if (i == 8)//image + { + var imageNames = or.lorf.Count > 0 ? or.lorf.Where(x => x.ori_file_name.Contains("JPG") || x.ori_file_name.Contains("PNG")).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 != null ? ((DateTime)or.finish_time).ToString("yyyy/MM/dd HH:mm:ss") : null); + } + if (i == 10) + { + cell.SetCellValue(or.Created_at == "null" ? "" : or.Created_at); + } + + cell.CellStyle = style12; + + } } } } diff --git a/FrontendWebApi/ApiControllers/UserController.cs b/FrontendWebApi/ApiControllers/UserController.cs index 16b3b60..e129888 100644 --- a/FrontendWebApi/ApiControllers/UserController.cs +++ b/FrontendWebApi/ApiControllers/UserController.cs @@ -596,20 +596,23 @@ namespace FrontendWebApi.ApiControllers } else { + await backendRepository.ExecuteSql($"delete from role_auth where role_guid = '{post.SelectedRoleId}' and AuthCode like '%PF%'"); if (post.SaveCheckAuth.Count > 0) { foreach (var item in post.SaveCheckAuth) { #region 新增權限 - Dictionary roleAuth = new Dictionary(); - roleAuth = new Dictionary() - { - { "@role_guid", post.SelectedRoleId}, - { "@AuthCode", item}, - { "@created_by", myUser.userinfo_guid} - }; + { + Dictionary roleAuth = new Dictionary(); + roleAuth = new Dictionary() + { + { "@role_guid", post.SelectedRoleId}, + { "@AuthCode", item}, + { "@created_by", myUser.userinfo_guid} + }; - await backendRepository.AddOneByCustomTable(roleAuth, "role_auth"); + await backendRepository.AddOneByCustomTable(roleAuth, "role_auth"); + } #endregion } } diff --git a/FrontendWebApi/ApiControllers/UtilityController.cs b/FrontendWebApi/ApiControllers/UtilityController.cs index 4eb46d2..f057de4 100644 --- a/FrontendWebApi/ApiControllers/UtilityController.cs +++ b/FrontendWebApi/ApiControllers/UtilityController.cs @@ -156,6 +156,7 @@ namespace FrontendWebApi.ApiControllers return apiResult; } + [HttpPost] public async Task>> isShowBuilding() { ApiResult apiResult = new ApiResult(jwt_str); diff --git a/FrontendWebApi/wwwroot/excel/operation/保養記錄_2023-07-24.xlsx b/FrontendWebApi/wwwroot/excel/operation/保養記錄_2023-07-24.xlsx new file mode 100644 index 0000000..56e0ab7 Binary files /dev/null and b/FrontendWebApi/wwwroot/excel/operation/保養記錄_2023-07-24.xlsx differ diff --git a/FrontendWebApi/wwwroot/excel/operation/廠商資料_2023-07-24.xlsx b/FrontendWebApi/wwwroot/excel/operation/廠商資料_2023-07-24.xlsx new file mode 100644 index 0000000..3dad3c8 Binary files /dev/null and b/FrontendWebApi/wwwroot/excel/operation/廠商資料_2023-07-24.xlsx differ diff --git a/FrontendWebApi/wwwroot/excel/operation/維修_2023-07-24.xlsx b/FrontendWebApi/wwwroot/excel/operation/維修_2023-07-24.xlsx new file mode 100644 index 0000000..9f60db5 Binary files /dev/null and b/FrontendWebApi/wwwroot/excel/operation/維修_2023-07-24.xlsx differ diff --git a/FrontendWebApi/wwwroot/excel/operation/維修_2023-07-31_2023-07-31.xlsx b/FrontendWebApi/wwwroot/excel/operation/維修_2023-07-31_2023-07-31.xlsx new file mode 100644 index 0000000..e69de29 diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index 18cdf7b..4ee1e47 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -132,7 +132,7 @@ namespace Repository.BackendRepository.Implement where (device_system_tag <> 'S' and device_system_tag <> 'CWB'); update import_niagara_tag a join dic_system b - on a.device_name_tag COLLATE utf8mb4_general_ci = b.s2_code + on a.device_name_tag COLLATE utf8mb4_unicode_ci = b.s2_code COLLATE utf8mb4_unicode_ci set device_system_tag = b.s1_code -- tag 第二碼為小類(除了安全系統之外) where (device_system_tag <> 'S' and device_system_tag <> 'CWB'); -- 安全系統 第二段大類 第四段小類"); await conn.ExecuteAsync(sb.ToString());