2022-10-14 16:08:54 +08:00
|
|
|
|
using FrontendWebApi.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Repository.BackendRepository.Interface;
|
|
|
|
|
using Repository.FrontendRepository.Interface;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FrontendWebApi.ApiControllers
|
|
|
|
|
{
|
|
|
|
|
public class EmergencyRecordController : MyBaseApiController<EmergencyRecordController>
|
|
|
|
|
{
|
|
|
|
|
private readonly IBackendRepository backendRepository;
|
|
|
|
|
private readonly IFrontendRepository frontendRepository;
|
|
|
|
|
|
|
|
|
|
public EmergencyRecordController
|
|
|
|
|
(
|
|
|
|
|
IBackendRepository backendRepository,
|
|
|
|
|
IFrontendRepository frontendRepository
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
this.backendRepository = backendRepository;
|
|
|
|
|
this.frontendRepository = frontendRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("api/EmergencyRecord/BuildInfoList")]
|
|
|
|
|
public async Task<ActionResult<ApiResult<List<KeyValue>>>> BuildInfoList()
|
|
|
|
|
{
|
|
|
|
|
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
|
|
|
|
|
List<KeyValue> KeyValue = new List<KeyValue>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-19 11:18:38 +08:00
|
|
|
|
var sqlString = @$"select building_tag as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0";
|
2022-10-14 16:08:54 +08:00
|
|
|
|
KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString);
|
|
|
|
|
|
|
|
|
|
apiResult.Code = "0000";
|
|
|
|
|
apiResult.Data = KeyValue;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
apiResult.Code = "9999";
|
|
|
|
|
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
|
|
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(apiResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("api/EmergencyRecord/EmergencyRecordTable")]
|
|
|
|
|
public async Task<ActionResult<ApiResult<List<EmergencyRecordEventTable>>>> EmergencyRecordTable(EmergencyRecordEventPost post)
|
|
|
|
|
{
|
|
|
|
|
List<EmergencyRecordEventTable> EmergencyRecordEvent = new List<EmergencyRecordEventTable>();
|
|
|
|
|
ApiResult<List<EmergencyRecordEventTable>> apiResult = new ApiResult<List<EmergencyRecordEventTable>>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var sqlplus = "";
|
|
|
|
|
if (post.selectaType != 2)
|
|
|
|
|
{
|
|
|
|
|
sqlplus = $"and ee.type = '{post.selectaType}'";
|
|
|
|
|
}
|
|
|
|
|
if (post.dateranger != null)
|
|
|
|
|
{
|
|
|
|
|
var date = post.dateranger.Replace(" ", "").Split("-");
|
|
|
|
|
sqlplus += $"and ee.created_at between '{date[0].Replace(" / ", " - ")} 00:00:00' and '{date[1].Replace(" / ", " - ")} 23:59:59'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EmergencyRecordEvent = await backendRepository.GetAllAsync<EmergencyRecordEventTable>($@"
|
|
|
|
|
select d.device_number device_name,v.system_key disaster_name,ee.*,b.full_name building_name from emergency_event ee
|
|
|
|
|
left join (select * from variable v where v.system_type = 'disaster') v on v.system_value = ee.disaster
|
|
|
|
|
left join device d on d.device_guid = ee.device_guid
|
2023-05-19 11:18:38 +08:00
|
|
|
|
left join building b on b.building_tag = ee.building_tag
|
|
|
|
|
where ee.deleted = 0 and ee.building_tag = '{post.selectaBuild}' and ee.disaster = '{post.selectaDisaster}' {sqlplus}
|
2022-10-14 16:08:54 +08:00
|
|
|
|
");
|
|
|
|
|
apiResult.Code = "0000";
|
|
|
|
|
apiResult.Data = EmergencyRecordEvent;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
apiResult.Code = "9999";
|
|
|
|
|
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
|
|
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
|
|
|
}
|
|
|
|
|
return Ok(apiResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("api/EmergencyRecord/EmergencyItemTable")]
|
|
|
|
|
public async Task<ActionResult<ApiResult<List<EmergencyRecordItem>>>> EmergencyItemTable(string event_guid)
|
|
|
|
|
{
|
|
|
|
|
List<EmergencyRecordItem> EmergencyRecordEvent = new List<EmergencyRecordItem>();
|
|
|
|
|
ApiResult<List<EmergencyRecordItem>> apiResult = new ApiResult<List<EmergencyRecordItem>>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
EmergencyRecordEvent = await backendRepository.GetAllAsync<EmergencyRecordItem>($@"
|
|
|
|
|
select * from emergency_item where event_guid = '{event_guid}' order by created_at desc
|
|
|
|
|
");
|
|
|
|
|
apiResult.Code = "0000";
|
|
|
|
|
apiResult.Data = EmergencyRecordEvent;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
apiResult.Code = "9999";
|
|
|
|
|
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
|
|
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
|
|
|
}
|
|
|
|
|
return Ok(apiResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|