[WebApi]緊急應變功能修整

This commit is contained in:
張家睿 2024-05-31 10:55:48 +08:00
parent 687b78984e
commit 877055440c
8 changed files with 259 additions and 146 deletions

View File

@ -1,13 +1,17 @@
using FrontendWebApi.Models; using FrontendWebApi.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Repository.BackendRepository.Interface; using Repository.BackendRepository.Interface;
using Repository.FrontendRepository.Interface; using Repository.FrontendRepository.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FrontendWebApi.ApiControllers namespace FrontendWebApi.ApiControllers
@ -27,6 +31,51 @@ namespace FrontendWebApi.ApiControllers
this.frontendRepository = frontendRepository; this.frontendRepository = frontendRepository;
} }
[HttpPost("api/Send")]
public async Task<ApiResult<List<Variable>>> SendMessageAsync(string message)
{
ApiResult<List<Variable>> apiResult = new ApiResult<List<Variable>>();
var sqlString = "SELECT * from variable WHERE system_type = 'TcpClient'";
var variables = await frontendRepository.GetAllAsync<Variable>(sqlString);
var serverAddress = variables.Where(x => x.System_key == "Address").First().system_value;
var serverPort = int.Parse(variables.Where(x => x.System_key == "Port").First().system_value);
try
{
using (var client = new TcpClient())
{
await client.ConnectAsync(serverAddress, serverPort);
using (var stream = client.GetStream())
{
var data = Encoding.UTF8.GetBytes(message);
await stream.WriteAsync(data, 0, data.Length);
//data = new byte[256];
//var bytes = await stream.ReadAsync(data, 0, data.Length);
apiResult.Code = "0000";
apiResult.Msg = "傳送指令, " + message;
return apiResult;
}
}
}
catch (SocketException ex)
{
apiResult.Code = "9999";
apiResult.Msg = ex.Message;
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
return apiResult;
}
catch (Exception ex)
{
apiResult.Code = "9999";
apiResult.Msg = ex.Message;
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
return apiResult;
}
}
[HttpPost] [HttpPost]
[Route("api/DisasterList")] [Route("api/DisasterList")]
public async Task<ActionResult<ApiResult<List<KeyValue>>>> DisasterList() public async Task<ActionResult<ApiResult<List<KeyValue>>>> DisasterList()
@ -155,7 +204,7 @@ namespace FrontendWebApi.ApiControllers
WHERE d.deleted = 0 WHERE d.deleted = 0
{deviceQue} {deviceQue}
) d ) d
left join floor on floor.full_name = d.device_floor_tag and floor.building_tag = d.device_building_tag left join floor on floor.full_name = d.device_floor_tag and floor.building_tag = d.device_building_tag and floor.deleted = 0
left join ( left join (
SELECT SELECT
v.*, v.*,

View File

@ -93,7 +93,7 @@ namespace FrontendWebApi.ApiControllers
XDocument xmlDoc = XDocument.Parse(resString); XDocument xmlDoc = XDocument.Parse(resString);
if (xmlDoc?.Root?.Name?.LocalName == "str") if (xmlDoc?.Root?.Name?.LocalName == "str" || xmlDoc?.Root?.Name?.LocalName == "bool")
{ {
result.targetValue = xmlDoc.Root.Attribute("val").Value; result.targetValue = xmlDoc.Root.Attribute("val").Value;
@ -118,7 +118,7 @@ namespace FrontendWebApi.ApiControllers
} }
/// <summary> /// <summary>
/// 取得警戒值 /// 設定警戒值
/// </summary> /// </summary>
/// <param name="post"></param> /// <param name="post"></param>
/// <returns></returns> /// <returns></returns>

View File

@ -8,7 +8,8 @@ namespace FrontendWebApi.Models
{ {
public enum WarningValueType { public enum WarningValueType {
Rain, //降雨 Rain, //降雨
Earthquake //地震 Earthquake , //地震
Infrared //紅外線
} }
public class WarningValueInput { public class WarningValueInput {

View File

@ -616,6 +616,14 @@
} }
} }
], ],
'columnDefs': [
// 隐藏第 7 列("alarm_timestamp" 列)和第 8 列SOP 按钮列)
{
'targets': [7, 8],
'visible': false,
'searchable': false
}
],
'drawCallback': function () { 'drawCallback': function () {
$('#alarm-device-table tbody tr td').css('padding', '5px 8px 5px 8px'); $('#alarm-device-table tbody tr td').css('padding', '5px 8px 5px 8px');
}, },

View File

@ -1,12 +1,12 @@
@{ @{
ViewData["MainNum"] = "4"; ViewData["MainNum"] = "4";
ViewData["SubNum"] = "4"; ViewData["SubNum"] = "4";
ViewData["Title"] = "紀錄查詢"; ViewData["Title"] = "事件查詢";
} }
<ol class="breadcrumb page-breadcrumb"> <ol class="breadcrumb page-breadcrumb">
<li class="breadcrumb-item"><a href="javascript:void(0);">首頁</a></li> <li class="breadcrumb-item"><a href="javascript:void(0);">首頁</a></li>
<li class="breadcrumb-item active">紀錄查詢</li> <li class="breadcrumb-item active">事件查詢</li>
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li> <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol> </ol>
@ -17,7 +17,7 @@
<div class="panel-content"> <div class="panel-content">
<div class="subheader"> <div class="subheader">
<h1 class="subheader-title"> <h1 class="subheader-title">
<span>紀錄查詢</span> <span>事件查詢</span>
</h1> </h1>
</div> </div>
<div class="row mb-3 d-flex align-items-center px-3 justify-content-between"> <div class="row mb-3 d-flex align-items-center px-3 justify-content-between">
@ -273,11 +273,11 @@
} }
else if (val.finished == 1) else if (val.finished == 1)
{ {
val.type = "完成"; val.finished = "完成";
} }
else else
{ {
val.type = "不執行"; val.finished = "不執行";
} }
}) })
return data; return data;
@ -406,7 +406,10 @@
$(this).parents().find('tr').css('background-color', '#fff'); $(this).parents().find('tr').css('background-color', '#fff');
$(this).css('background-color', '#67B4AC'); $(this).css('background-color', '#67B4AC');
SelectEvent = $(this).attr('guid'); SelectEvent = $(this).attr('guid');
$('#emergencyitem').find('.card-title').html("事件明細" + "-" + $(this).attr('type') + "-" + $(this).attr('device')); var title = "事件明細" + "-" + $(this).attr('type')
if ($(this).attr('device') != undefined) { title += "-" + $(this).attr('device') }
$('#emergencyitem').find('.card-title').html(title);
// $('#emergencyitem').find('.card-title').html("事件明細" + "-" + $(this).attr('type') + "-" + $(this).attr('device'));
EmergencyItemTable.ajax.reload(); EmergencyItemTable.ajax.reload();
$('#emergencyitem').show(); $('#emergencyitem').show();
}) })

View File

@ -74,7 +74,6 @@
</a> </a>
</li> </li>
<li class="nav-title">Navigation Title</li>--> <li class="nav-title">Navigation Title</li>-->
@if (ViewBag.role.Contains("EmergencyDeviceMenuIndex") @if (ViewBag.role.Contains("EmergencyDeviceMenuIndex")
|| ViewBag.role.Contains("EmergencyContactIndex") || ViewBag.role.Contains("EmergencyContactIndex")
|| ViewBag.role.Contains("EmergencyRecordIndex") || ViewBag.role.Contains("EmergencyRecordIndex")
@ -114,13 +113,13 @@
@if (ViewBag.role.Contains("EmergencyRecordIndex")) @if (ViewBag.role.Contains("EmergencyRecordIndex"))
{ {
<li class="@(ViewData["MainNum"] == "4" && ViewData["SubNum"] == "4" ? "active" : "")"> <li class="@(ViewData["MainNum"] == "4" && ViewData["SubNum"] == "4" ? "active" : "")">
<a asp-controller="EmergencyRecord" asp-action="Index" title="紀錄查詢" data-filter-tags="utilities disabled item"> <a asp-controller="EmergencyRecord" asp-action="Index" title="事件查詢" data-filter-tags="utilities disabled item">
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">紀錄查詢</span> <span class="nav-link-text" data-i18n="nav.utilities_disabled_item">事件查詢</span>
</a> </a>
</li> </li>
} }
@if (ViewBag.role.Contains("RescueDeviceFireExtinguisher")) @*@if (ViewBag.role.Contains("RescueDeviceFireExtinguisher"))
{ {
<li class="@(ViewData["MainNum"] == "4" && ViewData["SubNum"] == "5" ? "active" : "")"> <li class="@(ViewData["MainNum"] == "4" && ViewData["SubNum"] == "5" ? "active" : "")">
<a asp-controller="RescueDevice" asp-action="FireExtinguisher" title="滅火器設定" data-filter-tags="utilities disabled item"> <a asp-controller="RescueDevice" asp-action="FireExtinguisher" title="滅火器設定" data-filter-tags="utilities disabled item">
@ -135,7 +134,7 @@
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">AED裝置設定</span> <span class="nav-link-text" data-i18n="nav.utilities_disabled_item">AED裝置設定</span>
</a> </a>
</li> </li>
} }*@
</ul> </ul>
</li> </li>
@ -845,7 +844,7 @@
<!-- 警戒值設定 --> <!-- 警戒值設定 -->
<div class="modal" tabindex="-1" id="warning-value-modal" role="dialog" data-backdrop="static" data-keyboard="false"> <div class="modal" tabindex="-1" id="warning-value-modal" role="dialog" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered" style="max-width:45%;"> <div class="modal-dialog modal-dialog-centered" style="max-width:45%;">
<div class="modal-content" style="height:600px;"> <div class="modal-content" style="height:700px;">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title">警戒值設定</h5> <h5 class="modal-title">警戒值設定</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
@ -888,7 +887,7 @@
<tr class="disaster-title-bar"> <tr class="disaster-title-bar">
<td rowspan="3" class="disaster-icon"><i class="fa-solid fa-house-chimney-crack"></i></td> <td rowspan="3" class="disaster-icon"><i class="fa-solid fa-house-chimney-crack"></i></td>
<td class="disaster-title">地震警戒設定值</td> <td class="disaster-title">地震警戒設定值</td>
<td class="disaster-value" id="eqCurName">7級</td> <td class="disaster-value" id="eqCurName"></td>
</tr> </tr>
<tr> <tr>
<td colspan="2"> <td colspan="2">
@ -917,6 +916,19 @@
<tr> <tr>
<td colspan="2" id="eqDesc">幾乎所有家俱都大幅移動或翻倒,部分耐震較強建築物可能損壞或倒塌。</td> <td colspan="2" id="eqDesc">幾乎所有家俱都大幅移動或翻倒,部分耐震較強建築物可能損壞或倒塌。</td>
</tr> </tr>
<tr class="disaster-title-bar">
<td rowspan="2" class="disaster-icon"><i class="fa-solid fa-bolt"></i></td>
<td class="disaster-title">紅外線抑制</td>
<td class="disaster-value"></td>
</tr>
<tr>
<td colspan="2">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="irCheckbox" name="irCheckbox" value="open">
<label class="form-check-label" for="irCheckbox">開啟</label>
</div>
</td>
</tr>
</tbody> </tbody>
</table> </table>
@ -1020,13 +1032,34 @@
} }
else { else {
if (rel.data) { if (rel.data) {
let irValue = rel.data.filter(d => d.type == 2).map(d => d.targetValue)[0];
let eqValue = rel.data.filter(d => d.type == 1).map(d => d.targetValue)[0]; let eqValue = rel.data.filter(d => d.type == 1).map(d => d.targetValue)[0];
let rainValue = rel.data.filter(d => d.type == 0).map(d => d.targetValue)[0]; let rainValue = rel.data.filter(d => d.type == 0).map(d => d.targetValue)[0];
if (irValue == "true") {
$(`input[name=irCheckbox][value=open]`).prop("checked", true);
} else { $(`input[name=irCheckbox][value=open]`).prop("checked", false); }
$(`input[name=rainRadio][value=${rainValue}]`).prop("checked", true); $(`input[name=rainRadio][value=${rainValue}]`).prop("checked", true);
$(`input[name=eqRadio][value=${eqValue}]`).prop("checked", true); $(`input[name=eqRadio][value=${eqValue}]`).prop("checked", true);
$("#rainCurName").text($(`input[name=rainRadio][value=${rainValue}]`).next("label").text()); $("#rainCurName").text($(`input[name=rainRadio][value=${rainValue}]`).next("label").text());
$("#eqCurName").text($(`input[name=eqRadio][value=${eqValue}]`).next("label").text()); $("#eqCurName").text($(`input[name=eqRadio][value=${eqValue}]`).next("label").text());
let rainDecDict = {
1: "24小時累積雨量達80毫米以上或時雨量達40毫米以上之降雨現象。",
2: "24小時累積雨量達200毫米以上或3小時累積雨量達100毫米以上之降雨現象。",
3: "24小時累積雨量達350毫米以上之降雨現象。",
4: "24小時累積雨量達500毫米以上之降雨現象。",
};
$("#rainDesc").text(rainDecDict[rainValue] || "");
let eqDecDict = {
3: "房屋震動,碗盤門窗發出聲音,懸掛物搖擺。",
4: "房屋搖動甚烈,少數未固定物品可能傾倒掉落,少數傢俱移動,可能有輕微災害。",
5: "部分未固定物品傾倒掉落,少數傢俱可能移動或翻倒,少數門窗可能變形,部分牆壁產生裂痕。",
6: "大量傢俱大幅移動或翻倒,門窗扭曲變形,部分耐震能力較差房屋可能損壞或倒塌。",
7: "幾乎所有傢俱都大幅移動或翻倒,部分耐震較強建築物可能損壞或倒塌。",
}
$("#eqDesc").text(eqDecDict[eqValue] || "");
} }
} }
@ -1034,18 +1067,19 @@
} }
function setWarningValue() { function setWarningValue() {
let irValue = $("input[name=irCheckbox]").is(":checked");
let eqValue = $("input[name=eqRadio]:checked").val(); let eqValue = $("input[name=eqRadio]:checked").val();
let rainValue = $("input[name=rainRadio]:checked").val(); let rainValue = $("input[name=rainRadio]:checked").val();
if (!eqValue || !rainValue) { if (!eqValue || !rainValue) {
toast_error("請輸入警戒值"); toast_error("請輸入警戒值");
return; return;
} }
let sendData = {
let sendData = {wvs: wvs:
[ [
{ type: 0, targetValue: rainValue }, { type: 0, targetValue: rainValue },
{type:1,targetValue:eqValue} { type: 1, targetValue: eqValue },
{ type: 2, targetValue: irValue }
] ]
}; };

View File

@ -10,7 +10,7 @@
"JwtSettings": { "JwtSettings": {
"Issuer": "Admin", //<EFBFBD>o<EFBFBD>e<EFBFBD><EFBFBD> "Issuer": "Admin", //<EFBFBD>o<EFBFBD>e<EFBFBD><EFBFBD>
"SignKey": "TaipeiDome123456", //ñ<EFBFBD><EFBFBD>//<EFBFBD>̤<EFBFBD>16<EFBFBD>r<EFBFBD><EFBFBD> "SignKey": "TaipeiDome123456", //ñ<EFBFBD><EFBFBD>//<EFBFBD>̤<EFBFBD>16<EFBFBD>r<EFBFBD><EFBFBD>
"JwtLifeSeconds": 3600 "JwtLifeSeconds": 86400
}, },
"FilePath": { "FilePath": {
"OutputForm": "C:\\jay.chang\\ibms\\FrontendWebApi\\wwwroot\\upload\\OutputForm\\", // "OutputForm": "C:\\jay.chang\\ibms\\FrontendWebApi\\wwwroot\\upload\\OutputForm\\", //

View File

@ -1567,6 +1567,7 @@ namespace Repository.BackendRepository.Implement
{ {
try try
{ {
await conn.ExecuteAsync("TRUNCATE TABLE device_disaster");
stopwatchSection = new Stopwatch(); stopwatchSection = new Stopwatch();
stopwatchSection.Start(); stopwatchSection.Start();
sb.Append("select * from device_disaster;"); sb.Append("select * from device_disaster;");
@ -1594,7 +1595,24 @@ namespace Repository.BackendRepository.Implement
stopwatchSection = new Stopwatch(); stopwatchSection = new Stopwatch();
stopwatchSection.Start(); stopwatchSection.Start();
dv = dv.Where(x => device.Any(d => d.device_number == x.value.Split('/')[6])).ToList(); // 過濾 dv 集合,只保留設備編號有效的項目
dv = dv.Where(x =>
{
string[] parts = x.value.Split('/');
// 確認陣列長度是否足夠長並且設備編號索引為6存在於 device 集合中
if (parts.Length > 6)
{
string deviceNumber = parts[6];
return device.Any(d => d.device_number == deviceNumber);
}
else
{
// 如果陣列長度不足,或者設備編號無效,則返回 false表示不保留此項目
return false;
}
}).ToList();
//dv = dv.Where(x => device.Any(d => d.device_number == x.value.Split('/')[6])).ToList();
sb.Clear(); sb.Clear();
var updateList = dv.Where(x => deviceDisaster.Any(dd => dd.device_number == x.value.Split('/')[6] && dd.device_system_value != x.disasterValue)).ToList(); var updateList = dv.Where(x => deviceDisaster.Any(dd => dd.device_number == x.value.Split('/')[6] && dd.device_system_value != x.disasterValue)).ToList();
foreach (var d in updateList) foreach (var d in updateList)