diff --git a/FrontendWebApi/ApiControllers/HiNetController.cs b/FrontendWebApi/ApiControllers/HiNetController.cs
index 30b901a..c92fe46 100644
--- a/FrontendWebApi/ApiControllers/HiNetController.cs
+++ b/FrontendWebApi/ApiControllers/HiNetController.cs
@@ -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;
///
/// HiNet 企業簡訊 API for .NetCore 2.0
@@ -120,7 +122,7 @@ namespace FrontendWebApi.ApiControllers
///
public class HiNetController : MyBaseApiController
{
-
+ 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; }
///
/// 將MsgRequest結構轉為byte array
@@ -762,7 +764,7 @@ namespace FrontendWebApi.ApiControllers
///
[HttpPost]
[Route("api/HiNetMsg")]
- public ActionResult> HiNetMsg(HiNetInput input)
+ public ActionResult> HiNetMsg([FromBody] HiNetInput input)
{
ApiResult apiResult = new ApiResult(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($@"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
diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs
index 81b5f50..b22e7e8 100644
--- a/FrontendWebApi/ApiControllers/HistoryController.cs
+++ b/FrontendWebApi/ApiControllers/HistoryController.cs
@@ -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
///
[HttpPost]
[Route("api/HistoryRealTime")]
- public async Task>>> GetHistoryRealTime ([FromBody] HistoryRealTimeInput input)
+ public async Task>>> GetHistoryRealTime (PostHistoryRawDataFilter input)
{
- ApiResult> apiResult = new ApiResult>(jwt_str);
- apiResult.Data = new List();
+ ApiResult> apiResult = new ApiResult>(jwt_str);
+ apiResult.Data = new List();
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 tableName = new List();
- 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($"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($"select table_name from INFORMATION_SCHEMA.TABLES where table_name like '%{device_number}%'");
+ var device_item_infos = await frontendRepository.GetAllAsync(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(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();
- 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 ordr by timestamp";
- data.HistoryRealTime.AddRange(
- await backgroundServiceMsSqlRepository.GetAllAsync(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)
{
diff --git a/FrontendWebApi/Models/HiNet.cs b/FrontendWebApi/Models/HiNet.cs
index 0cbd5fb..96b9d80 100644
--- a/FrontendWebApi/Models/HiNet.cs
+++ b/FrontendWebApi/Models/HiNet.cs
@@ -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; }
+ }
}
diff --git a/FrontendWebApi/Models/HistoryClass.cs b/FrontendWebApi/Models/HistoryClass.cs
index 37032a9..ea0d45e 100644
--- a/FrontendWebApi/Models/HistoryClass.cs
+++ b/FrontendWebApi/Models/HistoryClass.cs
@@ -296,22 +296,5 @@ namespace FrontendWebApi.Models
public string type { get; set; }
}
- public class HistoryRealTimeInput
- {
- public List tableDeviceName { get; set; }
- public string startTime { get; set; }
- public string endTime { get; set; }
- }
-
- public class HistoryRealTimeOutput
- {
- public string deviceNumber { get; set; }
- public List HistoryRealTime { get; set; }
- }
-
- public class HistoryRealTime
- {
- public double value { get; set; }
- public DateTime timeStamp { get; set; }
- }
+
}