From 66640d970f1a96e928a964e854b867ca10a5b2d8 Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 25 May 2023 18:28:11 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E5=8F=B0][=E5=BE=8C=E7=AB=AF]=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9deivce=5Fitem=20=E7=8D=B2=E5=8F=96=E8=B3=87?= =?UTF-8?q?=E6=96=99=E5=95=8F=E9=A1=8C=20[=E5=89=8D=E5=8F=B0][=E5=BE=8C?= =?UTF-8?q?=E7=AB=AF]=20=E4=BF=AE=E6=94=B9alert=E5=8F=96=E6=B3=95=20[?= =?UTF-8?q?=E5=89=8D=E7=AB=AF]=20=E4=BF=AE=E6=94=B9alert.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/DeviceManageController.cs | 2 +- .../Controllers/SystemCategoryController.cs | 33 ++++++++++------ Frontend/_alert.html | 39 +++++++++++-------- .../ApiControllers/AlertController.cs | 16 ++++++-- FrontendWebApi/Models/Alert.cs | 1 + 5 files changed, 58 insertions(+), 33 deletions(-) diff --git a/Backend/Controllers/DeviceManageController.cs b/Backend/Controllers/DeviceManageController.cs index c810839..ceb04f3 100644 --- a/Backend/Controllers/DeviceManageController.cs +++ b/Backend/Controllers/DeviceManageController.cs @@ -1662,7 +1662,7 @@ namespace Backend.Controllers try { - string sWhere = "deleted = 0 AND device_name_tag = @Sub_system_tag and device_building_tag = @device_building_tag"; + string sWhere = "deleted = 0 AND device_name_tag = @Sub_system_tag and device_building_tag = @device_building_tag and is_link = 1 and is_controll = 1"; object param = new { Sub_system_tag = input.sub_system_tag, device_building_tag = input.building_tag }; diff --git a/Backend/Controllers/SystemCategoryController.cs b/Backend/Controllers/SystemCategoryController.cs index 641391b..9246230 100644 --- a/Backend/Controllers/SystemCategoryController.cs +++ b/Backend/Controllers/SystemCategoryController.cs @@ -501,26 +501,37 @@ namespace Backend.Controllers try { + var main_tag = await backendRepository.GetOneAsync($@"SELECT system_value FROM variable WHERE id = @id", new { id = device_Item.device_system_tag }); + var sub_tag = await backendRepository.GetOneAsync($@"SELECT system_value FROM variable WHERE id = @id", new { id = device_Item.device_name_tag }); //檢查是否有未刪除的區域選單 - if(device_Item.is_show_riserDiagram == 1) + if (device_Item.is_show_riserDiagram == 1) { - var sql_show_riserDiagram = $@"SELECT * FROM device_item di - WHERE di.id = @id AND di.deleted = 0 AND is_show_riserDiagram = 1"; + var sql_show_riserDiagram = $@"SELECT di.id FROM device_item di + WHERE di.id != @id AND di.deleted = 0 AND is_show_riserDiagram = 1 and device_system_tag = @device_system_tag + and device_name_tag = @device_name_tag"; - var is_show_riserDiagram = await backendRepository.GetAllAsync(sql_show_riserDiagram, new { id = device_Item.id }); + var deviceItemId = await backendRepository.GetAllAsync(sql_show_riserDiagram, + new { id = device_Item.id, device_system_tag = main_tag, device_name_tag = sub_tag }); - if (is_show_riserDiagram.Count() > 0) + if (deviceItemId.Count() > 0) { - apiResult.Code = "9998"; - apiResult.Msg = "請先取消已選擇顯示於昇位圖點位。"; - return apiResult; + foreach (var id in deviceItemId) + { + Dictionary Device_itemDic = new Dictionary() + { + { "@is_show_riserDiagram", false}, + { "@updated_by", myUserInfo.Userinfo_guid}, + { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + + await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "id='" + id + "'"); + } } } if (device_Item.id == 0) { - var main_tag = await backendRepository.GetOneAsync($@"SELECT system_value FROM variable WHERE id = @id", new { id = device_Item.device_system_tag }); - var sub_tag = await backendRepository.GetOneAsync($@"SELECT system_value FROM variable WHERE id = @id", new { id = device_Item.device_name_tag }); + //新增 Dictionary Device_itemDic = new Dictionary() { @@ -586,7 +597,7 @@ namespace Backend.Controllers FROM device_item di JOIN variable sv ON di.device_name_tag = sv.system_value JOIN variable mv ON sv.system_parent_id = mv.id AND di.device_system_tag = mv.system_value - WHERE sv.id = @id AND di.deleted = @Deleted and di.device_building_tag = @building_tag"; + WHERE sv.id = @id AND di.deleted = @Deleted and di.device_building_tag = @building_tag and di.is_link = 1"; object param = new { Deleted = 0, id = id, building_tag = building_tag.Split("/")[1] }; diff --git a/Frontend/_alert.html b/Frontend/_alert.html index 89551d1..9a930f1 100644 --- a/Frontend/_alert.html +++ b/Frontend/_alert.html @@ -219,6 +219,7 @@ pageAct.selAllSysSub = false; first = true; let dataAlarm = []; + var historyTable = null; $(function () { initDropzone(); @@ -651,8 +652,11 @@ } }); } + else { + $('#alertTable').DataTable().clear().draw(); + $(loadEle).Loading("close"); + } } - $(loadEle).Loading("close"); } function stackData(res) { @@ -663,7 +667,8 @@ } function callBackFromAllDeviceAlert(res) { - refTable(res.data); + AlertList(res.data); + if (historyTable != null) { let t = $('#alertTable').dataTable(); @@ -674,7 +679,7 @@ } function callBackFromOneDeviceAlert(res) { - refTable(res); + AlertList(res); if (historyTable != null) { let t = $('#alertTable').dataTable(); @@ -686,14 +691,8 @@ } function refTable(data) { - console.log(data) let tag = "#alertTable"; - $.each(data, function (i, v) { - // console.log(v.uuid.$val, v.uuid) - v.formId = AlertList(v.uuid.$val || v.uuid); - }); - let column_defs = [ { "targets": [0], "width": "5%", "sortable": true }, { "targets": [1], "width": "5%", "sortable": true }, @@ -771,19 +770,25 @@ ]; historyTable = new YourTeam.JqDataTables.getTableByStatic(tag, data, columns, column_defs, null, null, null, null, "tpi"); + $(loadEle).Loading("close"); } - function AlertList(errCode) { - objSendData.Data = { uuid: errCode }; - let a = null + function AlertList(data) { + objSendData.Data = []; + $.each(data, function (i, v) { + objSendData.Data.push({ uuid: v.uuid.$val || v.uuid }) + }); + url = baseApiUrl + "/Alert/AlertList"; ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) { - if (rel.code == "0000") - a = rel.data; - // console.log(rel) + if (rel.code == "0000") { + $.each(rel.data, function (i, v) { + let index = data.findIndex(x => (x.uuid.$val || x.uuid) === v.uuid); + data[index].formId = v.formId; + }); + refTable(data) + } }, null, "POST").send(); - - return a; } function selDevice() { diff --git a/FrontendWebApi/ApiControllers/AlertController.cs b/FrontendWebApi/ApiControllers/AlertController.cs index 802a09f..338625c 100644 --- a/FrontendWebApi/ApiControllers/AlertController.cs +++ b/FrontendWebApi/ApiControllers/AlertController.cs @@ -10,6 +10,8 @@ using System.IO; using System.Data.SqlTypes; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using NPOI.HSSF.Record.Chart; +using System.Linq; namespace FrontendWebApi.ApiControllers { @@ -169,13 +171,19 @@ namespace FrontendWebApi.ApiControllers } [HttpPost] - public async Task> AlertList([FromBody] FindFormId alerts) + public async Task>> AlertList([FromBody] List alerts) { - ApiResult apiResult = new ApiResult(); + ApiResult> apiResult = new ApiResult>(); try { - var sqlString = $@"select formId from operation_record where error_code = @error_code and deleted = 0 limit 1"; - var formId = await backendRepository.GetOneAsync(sqlString, new { @error_code = alerts.uuid }); + var formId = new List(); + foreach(var fi in alerts) + { + var sqlString = $@"select error_code uuid, formId from operation_record where error_code = @error_code and deleted = 0 limit 1"; + var data = await backendRepository.GetOneAsync(sqlString, new { @error_code = fi.uuid }); + if (data != null) + formId.Add(data); + } apiResult.Code = "0000"; apiResult.Data = formId; diff --git a/FrontendWebApi/Models/Alert.cs b/FrontendWebApi/Models/Alert.cs index 258d09b..6542fd5 100644 --- a/FrontendWebApi/Models/Alert.cs +++ b/FrontendWebApi/Models/Alert.cs @@ -33,6 +33,7 @@ namespace FrontendWebApi.Models public class FindFormId { public string uuid { get; set; } + public string formId { get; set; } } }