[後端] 增加loading顯示, 排程try catch

This commit is contained in:
dev02 2023-07-18 11:10:38 +08:00
parent 060dc97391
commit c468efe0fc
6 changed files with 170 additions and 90 deletions

View File

@ -762,11 +762,14 @@
return; return;
} }
else { else {
$('#floor-modal').modal();
$("#BuildName").html(selected_build_guid_top_name); $("#BuildName").html(selected_build_guid_top_name);
$("#floor_name_modal").val(rel.data.full_name); $("#floor_name_modal").val(rel.data.full_name);
@*$("#map_file_preview_modal").attr("data-original", rel.data.mapUrl);*@ if (rel.data.mapUrl)
loadURLToInputFiled(rel.data.mapUrl, rel.data.initMapName + ".svg");
$('#floor-modal').modal(); else
$('#floor_map_file_modal')[0].value = "";
} }
}, 'json'); }, 'json');
}); });
@ -977,6 +980,27 @@
} }
//#endregion //#endregion
function loadURLToInputFiled(url, filesName){
getImgURL(url, (imgBlob)=>{
// Load img blob to input
// WIP: UTF8 character error
let fileName = filesName
let file = new File([imgBlob], fileName,{type:"image/svg+xml", lastModified:new Date().getTime()}, 'utf-8');
let container = new DataTransfer();
container.items.add(file);
$('#floor_map_file_modal')[0].files = container.files;
})
}
// xmlHTTP return blob respond
function getImgURL(url, callback){
var xhr = new XMLHttpRequest();
xhr.onload = function() {
callback(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}
</script> </script>
} }

View File

@ -140,6 +140,7 @@
//#endregion //#endregion
function SynchronizeData() { function SynchronizeData() {
showSpinner();
document.getElementById('loadDataText').innerText = "同步中..."; document.getElementById('loadDataText').innerText = "同步中...";
if (ds.length > 0) { if (ds.length > 0) {
//比對資料有差異的話再同步到device等資料表 //比對資料有差異的話再同步到device等資料表
@ -154,12 +155,13 @@
url: url_synchronize_data, url: url_synchronize_data,
data: JSON.stringify(ds), data: JSON.stringify(ds),
cache: false, cache: false,
async: false, async: true,
contentType: "application/json; charset=UTF-8", contentType: "application/json; charset=UTF-8",
dataType: 'json', dataType: 'json',
success: function (rel) { success: function (rel) {
if (rel.code != "0000") { if (rel.code != "0000") {
toast_error(rel.msg); toast_error(rel.msg);
showSpinner();
document.getElementById('loadDataText').innerText = "比對資料出錯了!"; document.getElementById('loadDataText').innerText = "比對資料出錯了!";
return; return;
} }
@ -208,10 +210,12 @@
success: function (rel) { success: function (rel) {
if (rel.code != "0000") { if (rel.code != "0000") {
toast_error(rel.msg); toast_error(rel.msg);
showSpinner();
document.getElementById('loadDataText').innerText = "比對資料出錯了!"; document.getElementById('loadDataText').innerText = "比對資料出錯了!";
return; return;
} }
hideSpinner();
console.log(rel); console.log(rel);
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date + ' ' + time; var dateTime = date + ' ' + time;

View File

@ -27,6 +27,11 @@
</head> </head>
<body class="mod-bg-1 mod-nav-link"> <body class="mod-bg-1 mod-nav-link">
<!-- BEGIN Page Wrapper --> <!-- BEGIN Page Wrapper -->
<div id="spinner" class="justify-content-center text-center loading hide">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="page-wrapper"> <div class="page-wrapper">
<div class="page-inner"> <div class="page-inner">
<!-- BEGIN Left Aside --> <!-- BEGIN Left Aside -->

View File

@ -46,4 +46,35 @@ label.error {
.t-gray { .t-gray {
color:var(--bims-gray) !important; color:var(--bims-gray) !important;
}
/* Absolute Center Spinner */
.loading {
position: fixed;
z-index: 999;
display: block;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 50px;
height: 50px;
}
/* Transparent Overlay */
.loading:before {
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: radial-gradient(rgba(0, 0, 0, .5), rgba(0, 0, 0, .5));
background: -webkit-radial-gradient(rgba(0, 0, 0, .5), rgba(0, 0, 0, .5));
}
.loading.hide {
display: none;
} }

View File

@ -222,3 +222,11 @@ function SaveSpinner(status) { //1:Spinner 0:還原儲存
$(document).ready(function () { $(document).ready(function () {
}); });
function showSpinner() {
$("#spinner").removeClass("hide");
}
function hideSpinner() {
$("#spinner").addClass("hide");
}

View File

@ -786,6 +786,7 @@ namespace BackendWorkerService.Services.Implement
} }
catch (Exception exception) catch (Exception exception)
{ {
throw exception; throw exception;
} }
@ -795,28 +796,98 @@ namespace BackendWorkerService.Services.Implement
private List<Dictionary<string, object>> ArrangeRawData(DeviceNumberPoint deviceNumberPoint, JObject jsonResult) private List<Dictionary<string, object>> ArrangeRawData(DeviceNumberPoint deviceNumberPoint, JObject jsonResult)
{ {
List<Dictionary<string, object>> arrangeRawDatas = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> arrangeRawDatas = new List<Dictionary<string, object>>();
var histories = jsonResult["obj"]["list"]; try
var rawdateCount = Convert.ToInt32(jsonResult["obj"]["int"]["@val"].ToString());
if (rawdateCount == 0)
{ {
return null; var histories = jsonResult["obj"]["list"];
} var rawdateCount = Convert.ToInt32(jsonResult["obj"]["int"]["@val"].ToString());
if (histories != null && histories.HasValues) if (rawdateCount == 0)
{ {
if (rawdateCount > 1) return null;
{ //多筆資料 }
foreach (var history in histories)
{ if (histories != null && histories.HasValues)
{
if (rawdateCount > 1)
{ //多筆資料
foreach (var history in histories)
{
Dictionary<string, object> arrangeRawData = new Dictionary<string, object>();
arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
arrangeRawData.Add("@point", deviceNumberPoint.Point);
//時間
if (history["abstime"] != null && history["abstime"].HasValues)
{
foreach (var abstime in history["abstime"])
{
var name = abstime["@name"].ToString();
switch (name)
{
case "start":
var startTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
arrangeRawData.Add("@start_timestamp", startTimstamp);
break;
case "end":
var endTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
arrangeRawData.Add("@end_timestamp", endTimstamp);
break;
}
}
}
//區間內資料筆數
if (history["int"] != null && history["int"].HasValues)
{
var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString());
arrangeRawData.Add("@count_rawdata", count);
}
//整合數值(最大、最小、平均、總和)
if (history["real"] != null && history["real"].HasValues)
{
foreach (var real in history["real"])
{
var name = real["@name"].ToString();
switch (name)
{
case "min":
var min = Convert.ToDecimal(real["@val"].ToString());
arrangeRawData.Add("@min_rawdata", min);
break;
case "max":
var max = Convert.ToDecimal(real["@val"].ToString());
arrangeRawData.Add("@max_rawdata", max);
break;
case "avg":
var avg = Convert.ToDecimal(real["@val"].ToString());
arrangeRawData.Add("@avg_rawdata", avg);
break;
case "sum":
var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
arrangeRawData.Add("@sum_rawdata", sum);
break;
}
}
}
arrangeRawData.Add("@is_complete", 1);
arrangeRawData.Add("@repeat_times", 0);
arrangeRawData.Add("@fail_reason", null);
arrangeRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
arrangeRawDatas.Add(arrangeRawData);
}
}
else
{ //單筆資料
Dictionary<string, object> arrangeRawData = new Dictionary<string, object>(); Dictionary<string, object> arrangeRawData = new Dictionary<string, object>();
arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber); arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
arrangeRawData.Add("@point", deviceNumberPoint.Point); arrangeRawData.Add("@point", deviceNumberPoint.Point);
//時間 //時間
if (history["abstime"] != null && history["abstime"].HasValues) if (histories["obj"]["abstime"] != null && histories["obj"]["abstime"].HasValues)
{ {
foreach (var abstime in history["abstime"]) foreach (var abstime in histories["obj"]["abstime"])
{ {
var name = abstime["@name"].ToString(); var name = abstime["@name"].ToString();
switch (name) switch (name)
@ -834,16 +905,16 @@ namespace BackendWorkerService.Services.Implement
} }
//區間內資料筆數 //區間內資料筆數
if (history["int"] != null && history["int"].HasValues) if (histories["obj"]["int"] != null && histories["obj"]["int"].HasValues)
{ {
var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString()); var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString());
arrangeRawData.Add("@count_rawdata", count); arrangeRawData.Add("@count_rawdata", count);
} }
//整合數值(最大、最小、平均、總和) //整合數值(最大、最小、平均、總和)
if (history["real"] != null && history["real"].HasValues) if (histories["obj"]["real"] != null && histories["obj"]["real"].HasValues)
{ {
foreach (var real in history["real"]) foreach (var real in histories["obj"]["real"])
{ {
var name = real["@name"].ToString(); var name = real["@name"].ToString();
switch (name) switch (name)
@ -867,6 +938,7 @@ namespace BackendWorkerService.Services.Implement
} }
} }
} }
arrangeRawData.Add("@is_complete", 1); arrangeRawData.Add("@is_complete", 1);
arrangeRawData.Add("@repeat_times", 0); arrangeRawData.Add("@repeat_times", 0);
arrangeRawData.Add("@fail_reason", null); arrangeRawData.Add("@fail_reason", null);
@ -875,77 +947,13 @@ namespace BackendWorkerService.Services.Implement
arrangeRawDatas.Add(arrangeRawData); arrangeRawDatas.Add(arrangeRawData);
} }
} }
else
{ //單筆資料
Dictionary<string, object> arrangeRawData = new Dictionary<string, object>();
arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
arrangeRawData.Add("@point", deviceNumberPoint.Point);
//時間 return arrangeRawDatas;
if (histories["obj"]["abstime"] != null && histories["obj"]["abstime"].HasValues) }
{ catch (Exception ex)
foreach (var abstime in histories["obj"]["abstime"]) {
{ return arrangeRawDatas;
var name = abstime["@name"].ToString();
switch (name)
{
case "start":
var startTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
arrangeRawData.Add("@start_timestamp", startTimstamp);
break;
case "end":
var endTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
arrangeRawData.Add("@end_timestamp", endTimstamp);
break;
}
}
}
//區間內資料筆數
if (histories["obj"]["int"] != null && histories["obj"]["int"].HasValues)
{
var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString());
arrangeRawData.Add("@count_rawdata", count);
}
//整合數值(最大、最小、平均、總和)
if (histories["obj"]["real"] != null && histories["obj"]["real"].HasValues)
{
foreach (var real in histories["obj"]["real"])
{
var name = real["@name"].ToString();
switch (name)
{
case "min":
var min = Convert.ToDecimal(real["@val"].ToString());
arrangeRawData.Add("@min_rawdata", min);
break;
case "max":
var max = Convert.ToDecimal(real["@val"].ToString());
arrangeRawData.Add("@max_rawdata", max);
break;
case "avg":
var avg = Convert.ToDecimal(real["@val"].ToString());
arrangeRawData.Add("@avg_rawdata", avg);
break;
case "sum":
var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
arrangeRawData.Add("@sum_rawdata", sum);
break;
}
}
}
arrangeRawData.Add("@is_complete", 1);
arrangeRawData.Add("@repeat_times", 0);
arrangeRawData.Add("@fail_reason", null);
arrangeRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
arrangeRawDatas.Add(arrangeRawData);
}
} }
return arrangeRawDatas;
} }
} }
} }