合併調整
This commit is contained in:
commit
7c7dc74c41
@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using FrontendWebApi.Models;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Repository.BackendRepository.Interface;
|
||||
using System.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// HiNet 企業簡訊 API for .NetCore 2.0
|
||||
@ -120,7 +122,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
/// </summary>
|
||||
public class HiNetController : MyBaseApiController<GraphManageController>
|
||||
{
|
||||
|
||||
private readonly IBackendRepository backendRepository;
|
||||
public Socket socket;
|
||||
|
||||
// 傳送型態
|
||||
@ -132,7 +134,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
// 回覆結果的訊息說明
|
||||
private StringBuilder retMessage = new StringBuilder();
|
||||
|
||||
public HiNetController() { }
|
||||
public HiNetController(IBackendRepository backendRepository) { this.backendRepository = backendRepository; }
|
||||
|
||||
/// <summary>
|
||||
/// 將MsgRequest結構轉為byte array
|
||||
@ -762,7 +764,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("api/HiNetMsg")]
|
||||
public ActionResult<ApiResult<string>> HiNetMsg(HiNetInput input)
|
||||
public ActionResult<ApiResult<string>> HiNetMsg([FromBody] HiNetInput input)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>(jwt_str);
|
||||
//if (!jwtlife)
|
||||
@ -773,15 +775,21 @@ namespace FrontendWebApi.ApiControllers
|
||||
|
||||
try
|
||||
{
|
||||
var hiair = new HiNetController();
|
||||
int retCode = hiair.StartCon("202.39.54.130", 8000, "airtest6", "95929ALz");
|
||||
string retContent = string.Empty;
|
||||
var hiNetConfig = backendRepository.GetAllAsync<KeyValue>($@"select system_key Name, system_value Value from variable where system_type = 'HiNetConfig'").Result;
|
||||
var config = new HiNetConfig();
|
||||
config.ip = hiNetConfig.Where(x => x.Name == "IP").Select(x => x.Value).FirstOrDefault();
|
||||
config.port = Int32.Parse(hiNetConfig.Where(x => x.Name == "Port").Select(x => x.Value).FirstOrDefault());
|
||||
config.account = hiNetConfig.Where(x => x.Name == "Account").Select(x => x.Value).FirstOrDefault();
|
||||
config.password = hiNetConfig.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
|
||||
int retCode = this.StartCon(config.ip, config.port, config.account, config.password);
|
||||
|
||||
string retContent = this.Get_Message();
|
||||
if (retCode == 0)
|
||||
{
|
||||
//發送文字簡訊並回傳狀態碼
|
||||
retCode = hiair.SendMsg(input.Number, input.Msg);
|
||||
retCode = this.SendMsg(input.Number, input.Msg);
|
||||
//取得messageID或文字描述
|
||||
retContent = hiair.Get_Message();
|
||||
retContent = this.Get_Message();
|
||||
apiResult.Data = retCode + " : " + retContent;
|
||||
}
|
||||
else
|
||||
|
@ -19,6 +19,7 @@ using NPOI.SS.UserModel;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using NPOI.HPSF;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace FrontendWebApi.ApiControllers
|
||||
{
|
||||
@ -972,7 +973,10 @@ namespace FrontendWebApi.ApiControllers
|
||||
d.full_name as device_name,
|
||||
d.priority
|
||||
from device_item di
|
||||
inner join device d on di.device_name_tag = d.device_name_tag and d.deleted = 0
|
||||
inner join device d on di.device_building_tag COLLATE utf8mb4_unicode_ci = d.device_building_tag
|
||||
and di.device_system_tag COLLATE utf8mb4_unicode_ci = d.device_system_tag
|
||||
and di.device_name_tag COLLATE utf8mb4_unicode_ci = d.device_name_tag
|
||||
and d.deleted = 0
|
||||
where di.deleted = 0 and di.unit is not null and d.device_number IN @Device_number
|
||||
) temp
|
||||
inner join building b on temp.device_building_tag COLLATE utf8mb4_unicode_ci = b.building_tag and b.deleted = 0
|
||||
@ -1094,16 +1098,16 @@ namespace FrontendWebApi.ApiControllers
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("api/HistoryRealTime")]
|
||||
public async Task<ActionResult<ApiResult<List<HistoryRealTimeOutput>>>> GetHistoryRealTime ([FromBody] HistoryRealTimeInput input)
|
||||
public async Task<ActionResult<ApiResult<List<HistoryRawData>>>> GetHistoryRealTime (PostHistoryRawDataFilter input)
|
||||
{
|
||||
ApiResult<List<HistoryRealTimeOutput>> apiResult = new ApiResult<List<HistoryRealTimeOutput>>(jwt_str);
|
||||
apiResult.Data = new List<HistoryRealTimeOutput>();
|
||||
ApiResult<List<HistoryRawData>> apiResult = new ApiResult<List<HistoryRawData>>(jwt_str);
|
||||
apiResult.Data = new List<HistoryRawData>();
|
||||
if (!jwtlife)
|
||||
{
|
||||
apiResult.Code = "5000";
|
||||
return BadRequest(apiResult);
|
||||
}
|
||||
if (input.tableDeviceName.Count == 0)
|
||||
if (input.HistoryItems.Count == 0)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = "沒有設備被選擇";
|
||||
@ -1112,25 +1116,59 @@ namespace FrontendWebApi.ApiControllers
|
||||
|
||||
try
|
||||
{
|
||||
List<string> tableName = new List<string>();
|
||||
foreach (var dn in input.tableDeviceName)
|
||||
//依據被選擇的設備找出相對應資料
|
||||
var sqlDeviceItemInfo = $@"select
|
||||
b.full_name as building_name,
|
||||
v1.system_key as Main_system_name,
|
||||
v2.system_key as Sub_system_name,
|
||||
temp.device_number,
|
||||
temp.device_name,
|
||||
temp.full_name as item_name,
|
||||
temp.points,
|
||||
temp.unit
|
||||
from (
|
||||
select
|
||||
di.*,
|
||||
d.device_number,
|
||||
d.full_name as device_name,
|
||||
d.priority
|
||||
from device_item di
|
||||
inner join device d on di.device_building_tag COLLATE utf8mb4_unicode_ci = d.device_building_tag
|
||||
and di.device_system_tag COLLATE utf8mb4_unicode_ci = d.device_system_tag
|
||||
and di.device_name_tag COLLATE utf8mb4_unicode_ci = d.device_name_tag
|
||||
and d.deleted = 0
|
||||
where di.deleted = 0 and di.unit is not null and d.device_number IN @Device_number
|
||||
) temp
|
||||
inner join building b on temp.device_building_tag COLLATE utf8mb4_unicode_ci = b.building_tag and b.deleted = 0
|
||||
inner join variable v1 on temp.device_system_tag COLLATE utf8mb4_unicode_ci = v1.system_value and v1.deleted = 0 and v1.system_type = 'device_system_category_layer2'
|
||||
inner join variable v2 on temp.device_name_tag COLLATE utf8mb4_unicode_ci = v2.system_value and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3'
|
||||
order by b.priority, v1.system_priority, v2.system_priority, temp.priority;";
|
||||
|
||||
foreach (var hi in input.HistoryItems)
|
||||
{
|
||||
tableName.AddRange(await backgroundServiceMsSqlRepository.GetAllAsync<string>($"select table_name from INFORMATION_SCHEMA.TABLES where table_name like '%{dn}%'"));
|
||||
var device_number = hi.Device_number_point.Split(":")[0];
|
||||
var point = hi.Device_number_point.Split(":")[1];
|
||||
//var tableName = await backgroundServiceMsSqlRepository.GetAllAsync<string>($"select table_name from INFORMATION_SCHEMA.TABLES where table_name like '%{device_number}%'");
|
||||
var device_item_infos = await frontendRepository.GetAllAsync<DeviceItemInfo>(sqlDeviceItemInfo, new { Device_number = hi.Device_number_point });
|
||||
|
||||
var device_item_info = device_item_infos.Where(x => x.Device_number == device_number && x.Points == point).FirstOrDefault();
|
||||
|
||||
var sql = $@"select '{device_item_info.Building_name}' as Building_name, '{device_item_info.Main_system_name}' as Main_system_name,
|
||||
'{device_item_info.Sub_system_name}' as Sub_system_name', {device_item_info.Device_number}' as Device_number,
|
||||
'{device_item_info.Device_name}' as Device_name, '{device_item_info.Item_name}' as Item_name, '{device_item_info.Points}' as Points,
|
||||
'{device_item_info.Unit}' as Unit, timestamp as Timestamp, round(value, 2) as Value
|
||||
from FIC_CENTER_{device_number}_{point}
|
||||
where replace(convert(varchar, [timestamp], 111), '/', '-') >= @startTime
|
||||
and replace(convert(varchar, [timestamp], 111), '/', '-') <= @endTime order by timestamp";
|
||||
apiResult.Data.AddRange(
|
||||
await backgroundServiceMsSqlRepository.GetAllAsync<HistoryRawData>(sql, new { startTime = input.Start_timstamp, endTime = input.End_timstamp })
|
||||
);
|
||||
//foreach (var tn in tableName)
|
||||
//{
|
||||
//}
|
||||
}
|
||||
|
||||
if (tableName.Count > 0)
|
||||
{
|
||||
foreach (var tn in tableName)
|
||||
{
|
||||
var data = new HistoryRealTimeOutput() { HistoryRealTime = new List<HistoryRealTime>()};
|
||||
data.deviceNumber = tn;
|
||||
var sql = $@"select timestamp as timeStamp, round(value, 2) as value from {tn} where replace(convert(varchar, [timestamp], 111), '/', '-') >= @startTime and replace(convert(varchar, [timestamp], 111), '/', '-') <= @endTime order by timestamp";
|
||||
data.HistoryRealTime.AddRange(
|
||||
await backgroundServiceMsSqlRepository.GetAllAsync<HistoryRealTime>(sql, new { startTime = input.startTime, endTime = input.endTime })
|
||||
);
|
||||
apiResult.Data.Add(data);
|
||||
}
|
||||
}
|
||||
apiResult.Data = apiResult.Data.OrderBy(x => x.Device_number).ThenBy(x => x.Timestamp).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
@ -9,4 +9,12 @@
|
||||
public string Msg { get; set; }
|
||||
public string Number { get; set; }
|
||||
}
|
||||
|
||||
public class HiNetConfig
|
||||
{
|
||||
public string account { get; set; }
|
||||
public string password { get; set; }
|
||||
public string ip { get; set; }
|
||||
public int port { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -296,22 +296,5 @@ namespace FrontendWebApi.Models
|
||||
public string type { get; set; }
|
||||
}
|
||||
|
||||
public class HistoryRealTimeInput
|
||||
{
|
||||
public List<string> tableDeviceName { get; set; }
|
||||
public string startTime { get; set; }
|
||||
public string endTime { get; set; }
|
||||
}
|
||||
|
||||
public class HistoryRealTimeOutput
|
||||
{
|
||||
public string deviceNumber { get; set; }
|
||||
public List<HistoryRealTime> HistoryRealTime { get; set; }
|
||||
}
|
||||
|
||||
public class HistoryRealTime
|
||||
{
|
||||
public double value { get; set; }
|
||||
public DateTime timeStamp { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user