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;
|
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;
|
|
|
|
|
public NiagaraDataSynchronizeController(IBackendRepository backendRepository, INiagaraDataSynchronizeRepository niagaraDataSynchronizeRepository)
|
|
|
|
|
{
|
|
|
|
|
this.backendRepository = backendRepository;
|
|
|
|
|
//this.deviceImportRepository = deviceImportRepository;
|
|
|
|
|
this.niagaraDataSynchronizeRepository = niagaraDataSynchronizeRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2022-12-22 10:11:31 +08:00
|
|
|
|
string url_slot = "slot:/TPE/B1|";//三菱
|
|
|
|
|
//string url_slot = "slot:/NTPC/B1|";//wsp
|
|
|
|
|
|
2022-11-30 18:22:40 +08:00
|
|
|
|
string top100 = "";//" top 100 ";
|
2022-11-02 17:26:18 +08:00
|
|
|
|
webRequestService svc = new webRequestService();
|
|
|
|
|
string bql = url_slot + "bql:select " + top100 + " * from control:ControlPoint ";
|
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);
|
2022-12-22 10:11:31 +08:00
|
|
|
|
ds = svc.obixQuery("http://192.168.0.136:8080/obix/config/Program/ObixQuery/query/", bql);//三菱
|
|
|
|
|
//ds = svc.obixQuery("http://192.168.0.136:8081/obix/config/Program/ObixQuery/query/", bql);//wsp
|
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>();
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-12-31 16:49:47 +08:00
|
|
|
|
var building = ds.FirstOrDefault().building;
|
2022-11-02 17:26:18 +08:00
|
|
|
|
await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building);
|
|
|
|
|
await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building);
|
|
|
|
|
await niagaraDataSynchronizeRepository.DeviceComparison();
|
|
|
|
|
await niagaraDataSynchronizeRepository.DeviceItemComparison();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|