[WebApi]緊急應變功能修整
This commit is contained in:
parent
687b78984e
commit
877055440c
@ -1,13 +1,17 @@
|
||||
using FrontendWebApi.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Repository.BackendRepository.Interface;
|
||||
using Repository.FrontendRepository.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FrontendWebApi.ApiControllers
|
||||
@ -27,6 +31,51 @@ namespace FrontendWebApi.ApiControllers
|
||||
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]
|
||||
[Route("api/DisasterList")]
|
||||
public async Task<ActionResult<ApiResult<List<KeyValue>>>> DisasterList()
|
||||
@ -155,7 +204,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
WHERE d.deleted = 0
|
||||
{deviceQue}
|
||||
) 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 (
|
||||
SELECT
|
||||
v.*,
|
||||
|
@ -93,7 +93,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
|
||||
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;
|
||||
|
||||
@ -118,7 +118,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得警戒值
|
||||
/// 設定警戒值
|
||||
/// </summary>
|
||||
/// <param name="post"></param>
|
||||
/// <returns></returns>
|
||||
|
@ -8,7 +8,8 @@ namespace FrontendWebApi.Models
|
||||
{
|
||||
public enum WarningValueType {
|
||||
Rain, //降雨
|
||||
Earthquake //地震
|
||||
Earthquake , //地震
|
||||
Infrared //紅外線
|
||||
}
|
||||
|
||||
public class WarningValueInput {
|
||||
|
@ -616,6 +616,14 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
'columnDefs': [
|
||||
// 隐藏第 7 列("alarm_timestamp" 列)和第 8 列(SOP 按钮列)
|
||||
{
|
||||
'targets': [7, 8],
|
||||
'visible': false,
|
||||
'searchable': false
|
||||
}
|
||||
],
|
||||
'drawCallback': function () {
|
||||
$('#alarm-device-table tbody tr td').css('padding', '5px 8px 5px 8px');
|
||||
},
|
||||
|
@ -1,12 +1,12 @@
|
||||
@{
|
||||
ViewData["MainNum"] = "4";
|
||||
ViewData["SubNum"] = "4";
|
||||
ViewData["Title"] = "紀錄查詢";
|
||||
ViewData["Title"] = "事件查詢";
|
||||
}
|
||||
|
||||
<ol class="breadcrumb page-breadcrumb">
|
||||
<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>
|
||||
</ol>
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
<div class="panel-content">
|
||||
<div class="subheader">
|
||||
<h1 class="subheader-title">
|
||||
<span>紀錄查詢</span>
|
||||
<span>事件查詢</span>
|
||||
</h1>
|
||||
</div>
|
||||
<div class="row mb-3 d-flex align-items-center px-3 justify-content-between">
|
||||
@ -273,11 +273,11 @@
|
||||
}
|
||||
else if (val.finished == 1)
|
||||
{
|
||||
val.type = "完成";
|
||||
val.finished = "完成";
|
||||
}
|
||||
else
|
||||
{
|
||||
val.type = "不執行";
|
||||
val.finished = "不執行";
|
||||
}
|
||||
})
|
||||
return data;
|
||||
@ -406,7 +406,10 @@
|
||||
$(this).parents().find('tr').css('background-color', '#fff');
|
||||
$(this).css('background-color', '#67B4AC');
|
||||
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();
|
||||
$('#emergencyitem').show();
|
||||
})
|
||||
|
@ -74,7 +74,6 @@
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-title">Navigation Title</li>-->
|
||||
|
||||
@if (ViewBag.role.Contains("EmergencyDeviceMenuIndex")
|
||||
|| ViewBag.role.Contains("EmergencyContactIndex")
|
||||
|| ViewBag.role.Contains("EmergencyRecordIndex")
|
||||
@ -114,13 +113,13 @@
|
||||
@if (ViewBag.role.Contains("EmergencyRecordIndex"))
|
||||
{
|
||||
<li class="@(ViewData["MainNum"] == "4" && ViewData["SubNum"] == "4" ? "active" : "")">
|
||||
<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>
|
||||
<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>
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
|
||||
@if (ViewBag.role.Contains("RescueDeviceFireExtinguisher"))
|
||||
@*@if (ViewBag.role.Contains("RescueDeviceFireExtinguisher"))
|
||||
{
|
||||
<li class="@(ViewData["MainNum"] == "4" && ViewData["SubNum"] == "5" ? "active" : "")">
|
||||
<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>
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
}*@
|
||||
</ul>
|
||||
</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-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">
|
||||
<h5 class="modal-title">警戒值設定</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
@ -888,7 +887,7 @@
|
||||
<tr class="disaster-title-bar">
|
||||
<td rowspan="3" class="disaster-icon"><i class="fa-solid fa-house-chimney-crack"></i></td>
|
||||
<td class="disaster-title">地震警戒設定值</td>
|
||||
<td class="disaster-value" id="eqCurName">7級</td>
|
||||
<td class="disaster-value" id="eqCurName"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
@ -917,6 +916,19 @@
|
||||
<tr>
|
||||
<td colspan="2" id="eqDesc">幾乎所有家俱都大幅移動或翻倒,部分耐震較強建築物可能損壞或倒塌。</td>
|
||||
</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>
|
||||
</table>
|
||||
|
||||
@ -1020,13 +1032,34 @@
|
||||
}
|
||||
else {
|
||||
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 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=eqRadio][value=${eqValue}]`).prop("checked", true);
|
||||
$("#rainCurName").text($(`input[name=rainRadio][value=${rainValue}]`).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() {
|
||||
let irValue = $("input[name=irCheckbox]").is(":checked");
|
||||
let eqValue = $("input[name=eqRadio]:checked").val();
|
||||
let rainValue = $("input[name=rainRadio]:checked").val();
|
||||
|
||||
if (!eqValue || !rainValue) {
|
||||
toast_error("請輸入警戒值");
|
||||
return;
|
||||
}
|
||||
|
||||
let sendData = {wvs:
|
||||
let sendData = {
|
||||
wvs:
|
||||
[
|
||||
{ type: 0, targetValue: rainValue },
|
||||
{type:1,targetValue:eqValue}
|
||||
{ type: 1, targetValue: eqValue },
|
||||
{ type: 2, targetValue: irValue }
|
||||
]
|
||||
};
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
"JwtSettings": {
|
||||
"Issuer": "Admin", //<EFBFBD>o<EFBFBD>e<EFBFBD><EFBFBD>
|
||||
"SignKey": "TaipeiDome123456", //ñ<EFBFBD><EFBFBD>//<EFBFBD>̤<EFBFBD>16<EFBFBD>r<EFBFBD><EFBFBD>
|
||||
"JwtLifeSeconds": 3600
|
||||
"JwtLifeSeconds": 86400
|
||||
},
|
||||
"FilePath": {
|
||||
"OutputForm": "C:\\jay.chang\\ibms\\FrontendWebApi\\wwwroot\\upload\\OutputForm\\", //水電報表 檔案儲存位置
|
||||
|
@ -1567,6 +1567,7 @@ namespace Repository.BackendRepository.Implement
|
||||
{
|
||||
try
|
||||
{
|
||||
await conn.ExecuteAsync("TRUNCATE TABLE device_disaster");
|
||||
stopwatchSection = new Stopwatch();
|
||||
stopwatchSection.Start();
|
||||
sb.Append("select * from device_disaster;");
|
||||
@ -1594,7 +1595,24 @@ namespace Repository.BackendRepository.Implement
|
||||
|
||||
stopwatchSection = new Stopwatch();
|
||||
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();
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user