修改匯出流程

This commit is contained in:
dev02 2022-11-28 16:51:11 +08:00
parent 2c3704f5a6
commit 06d0e84782
4 changed files with 26 additions and 13 deletions

View File

@ -84,6 +84,7 @@
initApp.buildNavigation($('#js_nested_list'));
loadTable(null);
$(`[onclick="setDateType('today')"]`).click();
});
function initList() {
@ -186,12 +187,12 @@
var edt = new Date(new Date().setDate(sdt.getDate() + 1));
start = start ?? sdt.toLocaleDateString();
end = end ?? edt.toLocaleDateString();
getHistoryDataByBaja(pageAct.deviceNumber + "_" + pageAct.deviceItem,
new Date(start).getTime(),
new Date(end).getTime(),
pageAct.deviceName,
"Mitsubishi_Sup",
callBackFromHistory);
// getHistoryDataByBaja(pageAct.deviceNumber + "_" + pageAct.deviceItem,
//new Date(start).getTime(),
//new Date(end).getTime(),
//pageAct.deviceName,
// "Mitsubishi_Sup",
// callBackFromHistory);
}
function callBackFromHistory(res) {
@ -262,7 +263,7 @@
if (pageAct.dateType == "day")
end = new Date(new Date().setDate(start.getDate() + 1));
else if (pageAct.dateType == "month") {
else if (pageAct.dateType == "month") {
start = new Date($('#getmonth').val());
end = new Date(new Date().setDate(start.getDate() + 30));
}
@ -290,7 +291,7 @@
let column_defs = [
{ "targets": [0], "width": "20%", "sortable": true },
{ "targets": [1], "width": "20%", "sortable": true },
{ "targets": [2], "width": "20%", "sortable": true },
{ "targets": [2], "width": "20%", "sortable": true }
];
let columns = [
@ -308,17 +309,25 @@
"render": function (date) {
return displayDate(date, "datetime");
}
},
}
];
historyTable = new YourTeam.JqDataTables.getTableByStatic(tag, data, columns, column_defs, null, null, null, null, "tpi");
}
function exportExcel() {
let url = baseApiUrl + "/History/OpeExportExcel";
objSendData.Data = $('#historyTable').dataTable().fnGetData();;
objSendData.Data = $('#historyTable').dataTable().fnGetData();
$.each(objSendData.Data, function (i, v) {
v.starttime = (pageAct.dateType == "month" ? new Date($('#getmonth').val()) : new Date($('#startdate').val()));
v.endtime = $('#enddate input').val() === "" ? null : new Date($('#enddate input').val());
v.dateType = pageAct.dateType;
});
ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) {
location.href = baseApiUrl + "/api/df?fileName=" + rel.data + "&token=" + localStorage.getItem("JWT-Authorization");
if (rel.code == "0000")
location.href = baseApiUrl + "/api/df?fileName=" + rel.data + "&token=" + localStorage.getItem("JWT-Authorization");
}, null, "POST").send();
}
</script>

View File

@ -55,7 +55,8 @@ namespace FrontendWebApi.ApiControllers
try
{
var fileName = "廠商資料.xlsx";
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 filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "history");
if (!System.IO.Directory.Exists(filePath))

View File

@ -268,5 +268,8 @@ namespace FrontendWebApi.Models
public string deviceName { get; set; }
public int value { get; set; }
public DateTime timestamp { get; set; }
public DateTime starttime { get; set; }
public DateTime? endtime { get; set; }
public string dateType { get; set; }
}
}