2022-11-02 17:26:18 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Repository.BackendRepository.Interface;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System;
|
|
|
|
|
//using Backend.Models;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Backend.Services;
|
|
|
|
|
using Backend.Services.Implement;
|
|
|
|
|
using Repository.Models;
|
2022-12-31 16:49:47 +08:00
|
|
|
|
using System.Linq;
|
2023-01-13 17:28:23 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using NPOI.SS.Formula.Functions;
|
2023-03-02 14:24:34 +08:00
|
|
|
|
using Repository.Helper;
|
2022-11-02 17:26:18 +08:00
|
|
|
|
|
|
|
|
|
namespace Backend.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class NiagaraDataSynchronizeController : MybaseController<NiagaraDataSynchronizeController>
|
|
|
|
|
{
|
|
|
|
|
private readonly IBackendRepository backendRepository;
|
|
|
|
|
//private readonly IDeviceImportRepository deviceImportRepository;
|
|
|
|
|
private readonly INiagaraDataSynchronizeRepository niagaraDataSynchronizeRepository;
|
2023-03-02 14:24:34 +08:00
|
|
|
|
private readonly IBackEndConfigHelper backEndConfig;
|
|
|
|
|
public NiagaraDataSynchronizeController(IBackendRepository backendRepository, INiagaraDataSynchronizeRepository niagaraDataSynchronizeRepository,IBackEndConfigHelper backEndConfig)
|
2022-11-02 17:26:18 +08:00
|
|
|
|
{
|
|
|
|
|
this.backendRepository = backendRepository;
|
|
|
|
|
//this.deviceImportRepository = deviceImportRepository;
|
|
|
|
|
this.niagaraDataSynchronizeRepository = niagaraDataSynchronizeRepository;
|
2023-03-02 14:24:34 +08:00
|
|
|
|
this.backEndConfig = backEndConfig;
|
2022-11-02 17:26:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// N4匯入列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public Task<ApiResult<List<Device_value>>> RawDataList()
|
|
|
|
|
{
|
|
|
|
|
ApiResult<List<Device_value>> apiResult = new ApiResult<List<Device_value>>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<Device_value> ds;
|
2023-03-02 14:24:34 +08:00
|
|
|
|
string url_slot = backEndConfig.GetUrlSlot();
|
2023-04-11 10:28:33 +08:00
|
|
|
|
string tag_quantity = backEndConfig.Getobixtag_quantity();
|
2022-12-22 10:11:31 +08:00
|
|
|
|
|
2022-11-30 18:22:40 +08:00
|
|
|
|
string top100 = "";//" top 100 ";
|
2022-11-02 17:26:18 +08:00
|
|
|
|
webRequestService svc = new webRequestService();
|
2023-01-13 17:28:23 +08:00
|
|
|
|
string bql = url_slot + "bql:select " + top100 + " * from baja:Folder ";
|
2022-11-23 12:39:17 +08:00
|
|
|
|
//ds = svc.obixQuery("http://192.168.0.136:8080/obix/config/Arena/Program/ObixQuery/query/", bql);
|
2022-11-30 18:22:40 +08:00
|
|
|
|
//ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql);
|
2023-04-11 10:28:33 +08:00
|
|
|
|
ds = svc.obixQuery(backEndConfig.GetobixQuery(), bql, tag_quantity);//三菱
|
2022-11-02 17:26:18 +08:00
|
|
|
|
|
|
|
|
|
apiResult.Code = "0000";
|
|
|
|
|
apiResult.Data = ds;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
apiResult.Code = "9999";
|
|
|
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//return apiResult;
|
|
|
|
|
return Task.FromResult(apiResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 比對N4與資料表,有差異在同步至資料表中
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
2022-12-31 16:49:47 +08:00
|
|
|
|
public async Task<ApiResult<bool>> CompareData([FromBody] List<Device_value> ds)
|
2022-11-02 17:26:18 +08:00
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
2022-12-31 16:49:47 +08:00
|
|
|
|
|
2022-11-02 17:26:18 +08:00
|
|
|
|
ApiResult<bool> apiResult = new ApiResult<bool>();
|
2023-04-11 10:28:33 +08:00
|
|
|
|
string tag_quantity = backEndConfig.Getobixtag_quantity();
|
|
|
|
|
|
2022-11-02 17:26:18 +08:00
|
|
|
|
try
|
2023-03-28 13:48:30 +08:00
|
|
|
|
{
|
2023-04-21 02:06:32 +08:00
|
|
|
|
string ss = ds.Where(x => x.tag_name != "").FirstOrDefault().tag_name;
|
|
|
|
|
var building = ss.Split("_")[0];
|
2023-03-28 13:48:30 +08:00
|
|
|
|
string LightSwitchLevel = await niagaraDataSynchronizeRepository.getLightSwitchLevel(); //獲取照明開關 是否在 device or device_node
|
2023-04-11 10:28:33 +08:00
|
|
|
|
await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building, tag_quantity); // 匯入 MySQL table: import_niagara_tag
|
2023-03-28 13:48:30 +08:00
|
|
|
|
await niagaraDataSynchronizeRepository.DeviceComparison(LightSwitchLevel);
|
2023-02-08 15:17:03 +08:00
|
|
|
|
await niagaraDataSynchronizeRepository.CheckDiffFullNameAndCover();
|
2023-02-07 11:55:52 +08:00
|
|
|
|
await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName();
|
2022-11-02 17:26:18 +08:00
|
|
|
|
await niagaraDataSynchronizeRepository.InsertBuildingMenu();
|
|
|
|
|
await niagaraDataSynchronizeRepository.InsertSubSystemFloor();
|
|
|
|
|
result = true;
|
|
|
|
|
|
|
|
|
|
apiResult.Code = "0000";
|
|
|
|
|
apiResult.Data = result;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
apiResult.Code = "9999";
|
|
|
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return apiResult;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 17:28:23 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// N4匯入列表(device_item)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public Task<ApiResult<List<ImpNiaItem>>> RawDataDevItemList()
|
|
|
|
|
{
|
|
|
|
|
ApiResult<List<ImpNiaItem>> apiResult = new ApiResult<List<ImpNiaItem>>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<ImpNiaItem> ds;
|
2023-03-02 14:24:34 +08:00
|
|
|
|
string url_slot = backEndConfig.GetUrlSlot();
|
2023-01-13 17:28:23 +08:00
|
|
|
|
|
|
|
|
|
webRequestService svc = new webRequestService();
|
2023-03-02 14:24:34 +08:00
|
|
|
|
ds = svc.obixHisQuery(backEndConfig.GetobixHisBqlQuery(), backEndConfig.GetobixHisUrlQuery(), url_slot);//三菱
|
2023-01-13 17:28:23 +08:00
|
|
|
|
|
|
|
|
|
apiResult.Code = "0000";
|
|
|
|
|
apiResult.Data = ds;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
apiResult.Code = "9999";
|
|
|
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//return apiResult;
|
|
|
|
|
return Task.FromResult(apiResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 比對N4與資料表,有差異在同步至資料表中(device_item)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<ApiResult<bool>> DevIteComData([FromBody] List<ImpNiaItem> ds)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
ApiResult<bool> apiResult = new ApiResult<bool>();
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-04-21 02:06:32 +08:00
|
|
|
|
if (ds.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//string ss = ds.Where(x => x.tag_name != "").FirstOrDefault().tag_name;
|
|
|
|
|
//var building = ss.Split("_")[0];
|
|
|
|
|
|
|
|
|
|
var building = ds.FirstOrDefault().device_building_tag;
|
|
|
|
|
await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building); // insert 暫存table import_niagara_item
|
|
|
|
|
await niagaraDataSynchronizeRepository.DeviceItemComparison(); //insert device_item
|
|
|
|
|
await niagaraDataSynchronizeRepository.CheckItemDiffFullNameAndCover(); // update device_item.fullname
|
|
|
|
|
await niagaraDataSynchronizeRepository.ItemCheckFullNameEmptyReplaceByDeviceName(); // 檢查device_item內FullName為空的值,以points取代
|
|
|
|
|
await niagaraDataSynchronizeRepository.CheckItemIsShowHistory();
|
|
|
|
|
result = true;
|
|
|
|
|
|
|
|
|
|
apiResult.Code = "0000";
|
|
|
|
|
apiResult.Data = result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 17:28:23 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
apiResult.Code = "9999";
|
|
|
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return apiResult;
|
|
|
|
|
}
|
2022-11-02 17:26:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|