Merge branch 'master' of https://gitea.mjm-staging.developers-homelab.net/BIMS/BIMS
This commit is contained in:
commit
985aaed080
@ -120,6 +120,7 @@ namespace Backend.Controllers
|
|||||||
await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName();
|
await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName();
|
||||||
await niagaraDataSynchronizeRepository.InsertBuildingMenu();
|
await niagaraDataSynchronizeRepository.InsertBuildingMenu();
|
||||||
await niagaraDataSynchronizeRepository.InsertSubSystemFloor();
|
await niagaraDataSynchronizeRepository.InsertSubSystemFloor();
|
||||||
|
await this.DeviceDisasterAsync();
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
@ -221,5 +222,32 @@ namespace Backend.Controllers
|
|||||||
|
|
||||||
return apiResult;
|
return apiResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task DeviceDisasterAsync()
|
||||||
|
{
|
||||||
|
var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
|
||||||
|
var variableObix = await backendRepository.GetAllAsync<Backend.Models.KeyValue>(sqlObix);
|
||||||
|
var obixApiConfig = new Models.ObixApiConfig();
|
||||||
|
obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault();
|
||||||
|
obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
|
||||||
|
obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
|
||||||
|
obixApiConfig.TagQuantity = variableObix.Where(x => x.Name == "tag_quantity").Select(x => x.Value).FirstOrDefault();
|
||||||
|
|
||||||
|
if (obixApiConfig.TagQuantity == "5")
|
||||||
|
{
|
||||||
|
List<Device_value_disaster> dv = new List<Device_value_disaster>();
|
||||||
|
List<string> urlSlots = await backendRepository.GetAllAsync<string>("select obixSlot from building where deleted = 0");
|
||||||
|
List<string> disasterTag = await backendRepository.GetAllAsync<string>("select system_value from variable where system_type = 'disaster' and deleted = 0");
|
||||||
|
webRequestService svc = new webRequestService();
|
||||||
|
foreach(var dt in disasterTag)
|
||||||
|
{
|
||||||
|
string bql = "neql:hs:geoAddr=\"ER" + dt + "\"";
|
||||||
|
dv.AddRange(svc.obixDevDisaster(obixApiConfig.ApiBase + "obix/config/Arena/Program/ObixQuery/query/", bql, obixApiConfig.TagQuantity, obixApiConfig.UserName,
|
||||||
|
obixApiConfig.Password, dt));
|
||||||
|
}
|
||||||
|
|
||||||
|
await niagaraDataSynchronizeRepository.DeviceDisasterAysnc(dv);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
Backend/Models/DeviceDisaster.cs
Normal file
13
Backend/Models/DeviceDisaster.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
namespace Backend.Models
|
||||||
|
{
|
||||||
|
public class DeviceDisasterOutput
|
||||||
|
{
|
||||||
|
public string device_guid { get; set; }
|
||||||
|
public string device_building_tag { get; set; }
|
||||||
|
public string device_system_tag { get; set; }
|
||||||
|
public string device_name_tag { get; set; }
|
||||||
|
public string device_floor_tag { get; set; }
|
||||||
|
public string device_serial_tag { get; set; }
|
||||||
|
public string device_number { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -327,6 +327,69 @@ namespace Backend.Services.Implement
|
|||||||
|
|
||||||
return result.Where(x => x.full_name != null).ToList();
|
return result.Where(x => x.full_name != null).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Device_value_disaster> obixDevDisaster(string urlString, string bql, string tag_quantity, string acc, string pass, string dt)
|
||||||
|
{
|
||||||
|
List<Device_value_disaster> result = new List<Device_value_disaster>();
|
||||||
|
//String username = "obixUser";
|
||||||
|
//String password = "Admin123456";
|
||||||
|
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(acc + ":" + pass));
|
||||||
|
String API_Url = urlString;
|
||||||
|
|
||||||
|
HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create(API_Url);
|
||||||
|
Postrequest.Method = "POST";
|
||||||
|
Postrequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||||
|
Postrequest.PreAuthenticate = true;
|
||||||
|
|
||||||
|
using (var streamWriter = new StreamWriter(Postrequest.GetRequestStream()))
|
||||||
|
{
|
||||||
|
string json = "<str val='" + bql + "'/>";
|
||||||
|
|
||||||
|
streamWriter.Write(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpWebResponse response = (HttpWebResponse)Postrequest.GetResponse();
|
||||||
|
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
|
||||||
|
|
||||||
|
XmlDocument xmlDoc = new XmlDocument();
|
||||||
|
xmlDoc.LoadXml(responseString);
|
||||||
|
|
||||||
|
string jsonText = JsonConvert.SerializeXmlNode(xmlDoc);
|
||||||
|
var data = Welcome.FromJson(jsonText);
|
||||||
|
|
||||||
|
if (data.Obj.Str != null)
|
||||||
|
{
|
||||||
|
foreach (var item in data.Obj.Str)
|
||||||
|
{
|
||||||
|
Device_value_disaster row = new Device_value_disaster();
|
||||||
|
row.value = item.Val;
|
||||||
|
string[] s1 = item.Val.Split(',');
|
||||||
|
string[] s2 = s1[0].Split('/');
|
||||||
|
row.tag_name = "";
|
||||||
|
row.disasterValue = dt;
|
||||||
|
|
||||||
|
for (int i = 0; i < s2.Length; i++)
|
||||||
|
{
|
||||||
|
if (i == s2.Length - 2)
|
||||||
|
{
|
||||||
|
row.point_name = s2[i];
|
||||||
|
}
|
||||||
|
else if (i == 1)
|
||||||
|
{
|
||||||
|
row.tag_name += s2[i];
|
||||||
|
}
|
||||||
|
else if (i > 1 && i < s2.Length - 2)
|
||||||
|
{
|
||||||
|
row.tag_name += "_" + s2[i].Replace("$3", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.Add(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//private static void getRefData(string urlString, string encoded, List<control_point> conPoint, List<ImpNiaItem> result, Welcome data ) //obixHistory data
|
//private static void getRefData(string urlString, string encoded, List<control_point> conPoint, List<ImpNiaItem> result, Welcome data ) //obixHistory data
|
||||||
//{
|
//{
|
||||||
// foreach (var item in data.Obj.Ref)
|
// foreach (var item in data.Obj.Ref)
|
||||||
|
@ -858,5 +858,57 @@ namespace Repository.BackendRepository.Implement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DeviceDisasterAysnc(List<Device_value_disaster> dv)
|
||||||
|
{
|
||||||
|
using (IDbConnection conn = GetDbConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append("select * from device_disaster");
|
||||||
|
var deviceDisaster = (await conn.QueryAsync<DeviceDisasterOutput>(sb.ToString())).ToList();
|
||||||
|
sb.Clear();
|
||||||
|
sb.Append("select * from device where deleted = 0");
|
||||||
|
var device = (await conn.QueryAsync<DeviceDisasterOutput>(sb.ToString())).ToList();
|
||||||
|
dv = dv.Where(x => device.Any(d => d.device_number == x.value.Split('/')[6])).ToList();
|
||||||
|
|
||||||
|
sb.Clear();
|
||||||
|
foreach (var d in dv.Where(x => deviceDisaster.Any(dd => dd.device_number == x.value.Split('/')[6])))
|
||||||
|
{
|
||||||
|
string device_number = d.value.Split('/')[6];
|
||||||
|
sb.Append($"update device_disaster set device_system_value = '{d.disasterValue}' where device_number = '{device_number}'; ");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var d in dv.Where(x => !deviceDisaster.Any(dd => dd.device_number == x.value.Split('/')[6])))
|
||||||
|
{
|
||||||
|
string device_number = d.value.Split('/')[6];
|
||||||
|
string device_guid = device.Where(x => x.device_number == device_number).Select(x => x.device_guid).FirstOrDefault();
|
||||||
|
string device_system_tag = device.Where(x => x.device_number == device_number).Select(x => x.device_system_tag).FirstOrDefault();
|
||||||
|
string device_name_tag = device.Where(x => x.device_number == device_number).Select(x => x.device_name_tag).FirstOrDefault();
|
||||||
|
sb.Append($@"
|
||||||
|
insert into device_disaster
|
||||||
|
(device_guid, device_system_value, device_building_tag, device_system_tag, device_name_tag, device_floor_tag, device_serial_tag, device_number)
|
||||||
|
values ({device_guid}, {d.disasterValue}, {device_number.Split('_')[0]}, {device_number.Split('_')[1]}, {device_system_tag}, {device_name_tag},
|
||||||
|
{device_number.Split('_')[2]}, {device_number.Split('_')[4]}, {device_number}); ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(sb.ToString()))
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,5 +70,6 @@ namespace Repository.BackendRepository.Interface
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task InsertSubSystemFloor();
|
Task InsertSubSystemFloor();
|
||||||
|
Task DeviceDisasterAysnc(List<Device_value_disaster> dv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,4 +131,25 @@ namespace Repository.Models
|
|||||||
public string displayName { get; set; }
|
public string displayName { get; set; }
|
||||||
public bool isHistory { get; set; }
|
public bool isHistory { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DeviceDisasterOutput
|
||||||
|
{
|
||||||
|
public string device_guid { get; set; }
|
||||||
|
public string device_building_tag { get; set; }
|
||||||
|
public string device_system_tag { get; set; }
|
||||||
|
public string device_name_tag { get; set; }
|
||||||
|
public string device_floor_tag { get; set; }
|
||||||
|
public string device_serial_tag { get; set; }
|
||||||
|
public string device_number { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Device_value_disaster
|
||||||
|
{
|
||||||
|
public string value { get; set; }
|
||||||
|
public string tag_name { get; set; }
|
||||||
|
public string point_name { get; set; }
|
||||||
|
public string building { get; set; }
|
||||||
|
public string displayName { get; set; }
|
||||||
|
public string disasterValue { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user