Merge branch 'master' of https://gitea.mjm-staging.developers-homelab.net/BIMS/BIMS
This commit is contained in:
commit
b97f7ce6de
95
Backend/Controllers/NiagaraDataSynchronizeController.cs
Normal file
95
Backend/Controllers/NiagaraDataSynchronizeController.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
string url_slot = "slot:/Arena/H|";
|
||||||
|
string top100 = " top 100 ";
|
||||||
|
webRequestService svc = new webRequestService();
|
||||||
|
string bql = url_slot + "bql:select " + top100 + " * from control:ControlPoint ";
|
||||||
|
ds = svc.obixQuery("http://60.251.164.125:8080/obix/config/Arena/Program/ObixQuery/query/", bql);
|
||||||
|
|
||||||
|
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]
|
||||||
|
public async Task<ApiResult<bool>> CompareData(List<Device_value> ds, string building)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
ApiResult<bool> apiResult = new ApiResult<bool>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
97
Backend/N4.xml
Normal file
97
Backend/N4.xml
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?xml-stylesheet type='text/xsl' href='/obix/xsl'?>
|
||||||
|
<obj display="Component" xmlns="http://obix.org/ns/schema/1.0" xsi:schemaLocation="http://obix.org/ns/schema/1.0 /obix/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<str name="res" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/V1/" href="res/" />
|
||||||
|
<str name="res1" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/V2/" href="res1/" />
|
||||||
|
<str name="res2" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/V3/" href="res2/" />
|
||||||
|
<str name="res3" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/A1/" href="res3/" />
|
||||||
|
<str name="res4" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/A2/" href="res4/" />
|
||||||
|
<str name="res5" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/A3/" href="res5/" />
|
||||||
|
<str name="res6" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/P/" href="res6/" />
|
||||||
|
<str name="res7" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/Q/" href="res7/" />
|
||||||
|
<str name="res8" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/KWH/" href="res8/" />
|
||||||
|
<str name="res9" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/KVARH/" href="res9/" />
|
||||||
|
<str name="res10" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/F/" href="res10/" />
|
||||||
|
<str name="res11" val="/TPE/B1/EE/E4/R2F/NA/TPE_B1_EE_E4_R2F_NA_WHT_N1/PF/" href="res11/" />
|
||||||
|
<str name="res12" val="/TPE/B1/LT/L1/U1F/NA/TPE_B1_LT_L1_U1F_NA_EHL_N1/SSC/" href="res12/" />
|
||||||
|
<str name="res13" val="/TPE/B1/LT/L1/U1F/NA/TPE_B1_LT_L1_U1F_NA_EHL_N1/ST/" href="res13/" />
|
||||||
|
<str name="res14" val="/TPE/B1/LT/L1/U1F/NA/TPE_B1_LT_L1_U1F_NA_EHL_N2/SSC/" href="res14/" />
|
||||||
|
<str name="res15" val="/TPE/B1/LT/L1/U1F/NA/TPE_B1_LT_L1_U1F_NA_EHL_N2/ST/" href="res15/" />
|
||||||
|
<str name="res16" val="/TPE/B1/LT/L1/U1F/NA/TPE_B1_LT_L1_U1F_NA_EHL_N3/SSC/" href="res16/" />
|
||||||
|
<str name="res17" val="/TPE/B1/LT/L1/U1F/NA/TPE_B1_LT_L1_U1F_NA_EHL_N3/ST/" href="res17/" />
|
||||||
|
<str name="res18" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/SP_SSC/" href="res18/" />
|
||||||
|
<str name="res19" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/SP_MD/" href="res19/" />
|
||||||
|
<str name="res20" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/SP_Temp/" href="res20/" />
|
||||||
|
<str name="res21" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/SP_AF/" href="res21/" />
|
||||||
|
<str name="res22" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/SP_AD/" href="res22/" />
|
||||||
|
<str name="res23" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/Temp/" href="res23/" />
|
||||||
|
<str name="res24" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/AL/" href="res24/" />
|
||||||
|
<str name="res25" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/SSC/" href="res25/" />
|
||||||
|
<str name="res26" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/STA_MD/" href="res26/" />
|
||||||
|
<str name="res27" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1/ST/" href="res27/" />
|
||||||
|
<str name="res28" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/SP_SSC/" href="res28/" />
|
||||||
|
<str name="res29" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/SP_MD/" href="res29/" />
|
||||||
|
<str name="res30" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/SP_Temp/" href="res30/" />
|
||||||
|
<str name="res31" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/SP_AF/" href="res31/" />
|
||||||
|
<str name="res32" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/SP_AD/" href="res32/" />
|
||||||
|
<str name="res33" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/Temp/" href="res33/" />
|
||||||
|
<str name="res34" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/AL/" href="res34/" />
|
||||||
|
<str name="res35" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/SSC/" href="res35/" />
|
||||||
|
<str name="res36" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/STA_MD/" href="res36/" />
|
||||||
|
<str name="res37" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N2/ST/" href="res37/" />
|
||||||
|
<str name="res38" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/SP_SSC/" href="res38/" />
|
||||||
|
<str name="res39" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/SP_MD/" href="res39/" />
|
||||||
|
<str name="res40" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/SP_Temp/" href="res40/" />
|
||||||
|
<str name="res41" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/SP_AF/" href="res41/" />
|
||||||
|
<str name="res42" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/SP_AD/" href="res42/" />
|
||||||
|
<str name="res43" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/Temp/" href="res43/" />
|
||||||
|
<str name="res44" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/AL/" href="res44/" />
|
||||||
|
<str name="res45" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/SSC/" href="res45/" />
|
||||||
|
<str name="res46" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/STA_MD/" href="res46/" />
|
||||||
|
<str name="res47" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N3/ST/" href="res47/" />
|
||||||
|
<str name="res48" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/SP_SSC/" href="res48/" />
|
||||||
|
<str name="res49" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/SP_MD/" href="res49/" />
|
||||||
|
<str name="res50" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/SP_Temp/" href="res50/" />
|
||||||
|
<str name="res51" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/SP_AF/" href="res51/" />
|
||||||
|
<str name="res52" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/SP_AD/" href="res52/" />
|
||||||
|
<str name="res53" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/Temp/" href="res53/" />
|
||||||
|
<str name="res54" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/AL/" href="res54/" />
|
||||||
|
<str name="res55" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/SSC/" href="res55/" />
|
||||||
|
<str name="res56" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/STA_MD/" href="res56/" />
|
||||||
|
<str name="res57" val="/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N4/ST/" href="res57/" />
|
||||||
|
<str name="res58" val="/TPE/B1/ME/M12/R2F/NA/TPE_B1_ME_M12_R2F_NA_TH_N1/TEMP/" href="res58/" />
|
||||||
|
<str name="res59" val="/TPE/B1/ME/M12/R2F/NA/TPE_B1_ME_M12_R2F_NA_TH_N1/RH/" href="res59/" />
|
||||||
|
<str name="res60" val="/TPE/B1/ME/M12/R2F/NA/TPE_B1_ME_M12_R2F_NA_TH_N1/Or/" href="res60/" />
|
||||||
|
<str name="res61" val="/TPE/B1/ME/M12/R2F/NA/TPE_B1_ME_M12_R2F_NA_TH_N1/TRIP/" href="res61/" />
|
||||||
|
<str name="res62" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/ST/" href="res62/" />
|
||||||
|
<str name="res63" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/TRIP/" href="res63/" />
|
||||||
|
<str name="res64" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/FRC/" href="res64/" />
|
||||||
|
<str name="res65" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_RCS/" href="res65/" />
|
||||||
|
<str name="res66" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_RO/" href="res66/" />
|
||||||
|
<str name="res67" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_1F/" href="res67/" />
|
||||||
|
<str name="res68" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_2F/" href="res68/" />
|
||||||
|
<str name="res69" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_3F/" href="res69/" />
|
||||||
|
<str name="res70" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_4F/" href="res70/" />
|
||||||
|
<str name="res71" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_5F/" href="res71/" />
|
||||||
|
<str name="res72" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_6F/" href="res72/" />
|
||||||
|
<str name="res73" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_7F/" href="res73/" />
|
||||||
|
<str name="res74" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_8F/" href="res74/" />
|
||||||
|
<str name="res75" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_9F/" href="res75/" />
|
||||||
|
<str name="res76" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_10F/" href="res76/" />
|
||||||
|
<str name="res77" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_11F/" href="res77/" />
|
||||||
|
<str name="res78" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_12F/" href="res78/" />
|
||||||
|
<str name="res79" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/SP_FLS_13F/" href="res79/" />
|
||||||
|
<str name="res80" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/DuringFireemergencyreturnoperation/" href="res80/" />
|
||||||
|
<str name="res81" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/CompletionofreturnbyFireemergencyreturnoperation/" href="res81/" />
|
||||||
|
<str name="res82" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/DuringEarthquakeoperation/" href="res82/" />
|
||||||
|
<str name="res83" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/CompletionofEarthquakeoperation/" href="res83/" />
|
||||||
|
<str name="res84" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/NormalPowerSupply/" href="res84/" />
|
||||||
|
<str name="res85" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/Emergencypowersourcedetection/" href="res85/" />
|
||||||
|
<str name="res86" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/DuringEmergencypowercontroloperation/" href="res86/" />
|
||||||
|
<str name="res87" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/CompletionofreturnbyEmergencypowercontroloperation/" href="res87/" />
|
||||||
|
<str name="res88" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/UP/" href="res88/" />
|
||||||
|
<str name="res89" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/DOWN/" href="res89/" />
|
||||||
|
<str name="res90" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/DoorState/" href="res90/" />
|
||||||
|
<str name="res91" val="/TPE/B1/ELEV/EL/R2F/NA/TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1/MultiVibrator/" href="res91/" />
|
||||||
|
<str name="res92" val="/TPE/BooleanWritable/" href="res92/" />
|
||||||
|
</obj>
|
131
Backend/Services/Implement/webRequestService.cs
Normal file
131
Backend/Services/Implement/webRequestService.cs
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Repository.Models;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Repository.BackendRepository.Implement;
|
||||||
|
using Repository.BackendRepository;
|
||||||
|
|
||||||
|
namespace Backend.Services.Implement
|
||||||
|
{
|
||||||
|
public class webRequestService
|
||||||
|
{
|
||||||
|
public List<Device_value> obixQuery(string urlString, string bql)
|
||||||
|
{
|
||||||
|
List<Device_value> result = new List<Device_value>();
|
||||||
|
String username = "obixUser";
|
||||||
|
String password = "Admin123456";
|
||||||
|
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
|
||||||
|
String API_Url = urlString;
|
||||||
|
|
||||||
|
XmlDocument xmlDoc = new XmlDocument();
|
||||||
|
//xmlDoc.LoadXml(responseString);
|
||||||
|
xmlDoc.Load("N4.xml");//N4v1021
|
||||||
|
|
||||||
|
//xmlDoc.Save("N4.xml");
|
||||||
|
|
||||||
|
string jsonText = JsonConvert.SerializeXmlNode(xmlDoc);
|
||||||
|
var data = Welcome.FromJson(jsonText);
|
||||||
|
|
||||||
|
foreach (var item in data.Obj.Str)
|
||||||
|
{
|
||||||
|
Device_value row = new Device_value();
|
||||||
|
row.value = item.Val;
|
||||||
|
string[] s1 = item.Val.Split(',');
|
||||||
|
|
||||||
|
string[] s2 = s1[0].Split('/');
|
||||||
|
foreach (var ss in s2)
|
||||||
|
{
|
||||||
|
if (ss.Contains('_'))
|
||||||
|
{
|
||||||
|
string[] s3 = ss.Split('_');
|
||||||
|
if (s3.Count() > 3)
|
||||||
|
{
|
||||||
|
row.tag_name = ss;
|
||||||
|
row.point_name = s2[s2.Length - 2];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.Add(row);
|
||||||
|
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//public void getObix()
|
||||||
|
//{
|
||||||
|
// //#region 取得obix 設定
|
||||||
|
// //var obixApiConfig = new ObixApiConfig();
|
||||||
|
|
||||||
|
// //var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
|
||||||
|
|
||||||
|
// //var variableObix = await backgroundServiceRepository.GetAllAsync<KeyValue>(sqlObix);
|
||||||
|
// //obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault();
|
||||||
|
// //obixApiConfig.UserName = ed.AESDecrypt(variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault());
|
||||||
|
// //obixApiConfig.Password = ed.AESDecrypt(variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault());
|
||||||
|
|
||||||
|
// //String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(obixApiConfig.UserName + ":" + obixApiConfig.Password));
|
||||||
|
// //#endregion 取得obix 設定
|
||||||
|
|
||||||
|
|
||||||
|
// HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||||
|
// //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||||
|
// archiveMonthRequest.Method = "POST";
|
||||||
|
// archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||||
|
// archiveMonthRequest.PreAuthenticate = true;
|
||||||
|
|
||||||
|
// byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||||
|
// using (Stream reqStream = archiveMonthRequest.GetRequestStream())
|
||||||
|
// {
|
||||||
|
// reqStream.Write(byteArray, 0, byteArray.Length);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// HttpWebResponse archiveMonthResponse = (HttpWebResponse)archiveMonthRequest.GetResponse();
|
||||||
|
// var archiveMonthResponseContent = new StreamReader(archiveMonthResponse.GetResponseStream()).ReadToEnd();
|
||||||
|
|
||||||
|
// xmlDocument.LoadXml(archiveMonthResponseContent);
|
||||||
|
// string archiveMonthJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||||
|
// JObject archiveMonthJsonResult = (JObject)JsonConvert.DeserializeObject(archiveMonthJson);
|
||||||
|
|
||||||
|
// if (archiveMonthJsonResult.ContainsKey("err")) //抓取錯誤
|
||||||
|
// {
|
||||||
|
// //logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】");
|
||||||
|
// //logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveMonthJsonResult);
|
||||||
|
|
||||||
|
// Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
|
||||||
|
// archiveMonthRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||||
|
// archiveMonthRawData.Add("@point", deviceNumberPoint.Point);
|
||||||
|
// archiveMonthRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
||||||
|
// archiveMonthRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
||||||
|
// archiveMonthRawData.Add("@is_complete", 0);
|
||||||
|
// archiveMonthRawData.Add("@repeat_times", 0);
|
||||||
|
// archiveMonthRawData.Add("@fail_reason", archiveMonthJson);
|
||||||
|
|
||||||
|
// archiveMonthRawData.Add("@count_rawdata", 0);
|
||||||
|
// archiveMonthRawData.Add("@min_rawdata", 0);
|
||||||
|
// archiveMonthRawData.Add("@max_rawdata", 0);
|
||||||
|
// archiveMonthRawData.Add("@avg_rawdata", 0);
|
||||||
|
// archiveMonthRawData.Add("@sum_rawdata", 0);
|
||||||
|
// archiveMonthRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
|
||||||
|
// archiveMonthRawDatas.Add(archiveMonthRawData);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (archiveMonthJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||||
|
// {
|
||||||
|
// var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveMonthJsonResult);
|
||||||
|
// if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||||
|
// {
|
||||||
|
// archiveMonthRawDatas.AddRange(ArrangeRawDatas);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
@ -95,6 +95,7 @@ namespace Backend
|
|||||||
services.AddTransient<IUserInfoRepository, UserInfoRepository>();
|
services.AddTransient<IUserInfoRepository, UserInfoRepository>();
|
||||||
services.AddTransient<IDeviceManageRepository, DeviceManageRepository>();
|
services.AddTransient<IDeviceManageRepository, DeviceManageRepository>();
|
||||||
services.AddTransient<IDeviceImportRepository, DeviceImportRepository>();
|
services.AddTransient<IDeviceImportRepository, DeviceImportRepository>();
|
||||||
|
services.AddTransient<INiagaraDataSynchronizeRepository, NiagaraDataSynchronizeRepository>();
|
||||||
#endregion Repository ª`¤J
|
#endregion Repository ª`¤J
|
||||||
|
|
||||||
#region JWT ª`¤J
|
#region JWT ª`¤J
|
||||||
|
168
Backend/Views/NiagaraDataSynchronize/Index.cshtml
Normal file
168
Backend/Views/NiagaraDataSynchronize/Index.cshtml
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
@{
|
||||||
|
ViewData["MainNum"] = "2";
|
||||||
|
ViewData["SubNum"] = "3";
|
||||||
|
ViewData["Title"] = "Niagara資料同步";
|
||||||
|
}
|
||||||
|
|
||||||
|
<ol class="breadcrumb page-breadcrumb">
|
||||||
|
<li class="breadcrumb-item"><a href="javascript:void(0);">首頁</a></li>
|
||||||
|
<li class="breadcrumb-item">設備管理</li>
|
||||||
|
<li class="breadcrumb-item active">Niagara資料同步</li>
|
||||||
|
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
<div id="panel-5" class="panel">
|
||||||
|
<div class="panel-container show">
|
||||||
|
<div class="panel-content">
|
||||||
|
|
||||||
|
<div class="form-row align-items-center">
|
||||||
|
<div class="col-12 mb-3">
|
||||||
|
<div class="custom-control custom-radio custom-control-inline">
|
||||||
|
<input type="radio" id="Building_B" name="Building" value="B" class="custom-control-input">
|
||||||
|
<label class="custom-control-label" for="Building_B">三菱B1</label>
|
||||||
|
</div>
|
||||||
|
@*<div class="custom-control custom-radio custom-control-inline">
|
||||||
|
<input type="radio" id="Building_O" name="Building" value="O" class="custom-control-input">
|
||||||
|
<label class="custom-control-label" for="Building_O">辦公棟</label>
|
||||||
|
</div>*@
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row align-items-center">
|
||||||
|
<button id="loadDataBtn" type="button" class="btn btn-primary" onclick="LoadData()">載入資料</button>
|
||||||
|
<button id="synchornizeDataBtn" type="button" class="btn btn-dark" onclick="SynchronizeData()">同步資料</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<div class="form-row align-items-center">
|
||||||
|
<p id="loadDataText"></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-5">
|
||||||
|
<div class="card p-3 w-100">
|
||||||
|
<div class="card-header d-flex align-items-center flex-wrap">
|
||||||
|
<div class="card-title">
|
||||||
|
Niagara資料
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body row">
|
||||||
|
<div class="col-12">
|
||||||
|
<!-- datatable start -->
|
||||||
|
<table id="niagara_data_table" class="table table-bordered table-hover m-0 text-center">
|
||||||
|
<thead class="thead-themed">
|
||||||
|
<tr>
|
||||||
|
<th>value</th>
|
||||||
|
<th>tag_name</th>
|
||||||
|
<th>point_name</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<script>
|
||||||
|
var buildingId, building;
|
||||||
|
var rawDataImportTable;
|
||||||
|
var ds;
|
||||||
|
|
||||||
|
var today = new Date();
|
||||||
|
var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
ds = null;
|
||||||
|
building = "B1";
|
||||||
|
document.getElementById("Building_B").checked = true;
|
||||||
|
|
||||||
|
rawDataImportTable = $("#niagara_data_table").DataTable({
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"data": "value"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": "tag_name"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": "point_name"
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"ajax": {
|
||||||
|
"url": "/NiagaraDataSynchronize/RawDataList",
|
||||||
|
"type": "POST",
|
||||||
|
"dataSrc": function (rel) {
|
||||||
|
if (rel.code == "9999") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
document.getElementById('loadDataText').innerText = "載入資料出錯了!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = rel.data;
|
||||||
|
ds = data;
|
||||||
|
if (data == null || data.length == 0) {
|
||||||
|
this.data = [];
|
||||||
|
document.getElementById('loadDataText').innerText = "";
|
||||||
|
}
|
||||||
|
else if(data.length > 0) {
|
||||||
|
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
|
||||||
|
var dateTime = date + ' ' + time;
|
||||||
|
document.getElementById('loadDataText').innerText = "共 " + rel.data.length + " 筆資料 \n" + dateTime;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//#region 載入Niagara資料
|
||||||
|
function LoadData() {
|
||||||
|
document.getElementById('loadDataText').innerText = "Loading...";
|
||||||
|
buildingId = document.querySelector('input[name="Building"]:checked').value;
|
||||||
|
if (buildingId == "B") {
|
||||||
|
building = "B1";
|
||||||
|
rawDataImportTable.ajax.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
function SynchronizeData() {
|
||||||
|
document.getElementById('loadDataText').innerText = "同步中...";
|
||||||
|
if (ds.length > 0) {
|
||||||
|
//比對資料,有差異的話,再同步到device等資料表
|
||||||
|
var url_synchronize_data = "/NiagaraDataSynchronize/CompareData/";
|
||||||
|
|
||||||
|
var send_data = {
|
||||||
|
ds: ds,
|
||||||
|
building: building
|
||||||
|
}
|
||||||
|
$.post(url_synchronize_data, send_data, function (rel) {
|
||||||
|
if (rel.code != "0000") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
|
||||||
|
var dateTime = date + ' ' + time;
|
||||||
|
document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime;
|
||||||
|
}, 'json');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById('loadDataText').innerText = "查無資料 無法比對!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
}
|
@ -112,7 +112,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
@if (ViewBag.role.Contains("DeviceImportIndex") || ViewBag.role.Contains("DeviceManageIndex"))
|
@if (ViewBag.role.Contains("DeviceImportIndex") || ViewBag.role.Contains("DeviceManageIndex") || ViewBag.role.Contains("NiagaraDataSynchronizeIndex"))
|
||||||
{
|
{
|
||||||
<li class="@(ViewData["MainNum"] == "2" ? "active open" : "")">
|
<li class="@(ViewData["MainNum"] == "2" ? "active open" : "")">
|
||||||
<a href="#" title="設備管理" data-filter-tags="category">
|
<a href="#" title="設備管理" data-filter-tags="category">
|
||||||
@ -136,6 +136,14 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
|
@if (ViewBag.role.Contains("NiagaraDataSynchronizeIndex"))
|
||||||
|
{
|
||||||
|
<li class="@(ViewData["MainNum"] == "2" && ViewData["SubNum"] == "3" ? "active" : "")">
|
||||||
|
<a asp-controller="NiagaraDataSynchronize" asp-action="Index" title="Niagara資料同步" data-filter-tags="utilities disabled item">
|
||||||
|
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">Niagara資料同步</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ApiResult<List<Variable>>> SubSysList(int main_system_id)
|
public async Task<ApiResult<List<Variable>>> SubSysList(int main_system_tag)
|
||||||
{
|
{
|
||||||
ApiResult<List<Variable>> apiResult = new ApiResult<List<Variable>>();
|
ApiResult<List<Variable>> apiResult = new ApiResult<List<Variable>>();
|
||||||
List<Variable> sub_system_list = new List<Variable>();
|
List<Variable> sub_system_list = new List<Variable>();
|
||||||
@ -71,10 +71,10 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
var sqlString = @$"SELECT v2.*
|
var sqlString = @$"SELECT v2.*
|
||||||
FROM variable v2
|
FROM variable v2
|
||||||
JOIN variable v1 ON v2.system_parent_id = v1.id AND v1.system_type = @graph_manage_layer1 AND v1.deleted = 0
|
JOIN variable v1 ON v2.system_parent_id = v1.id AND v1.system_type = @graph_manage_layer1 AND v1.deleted = 0
|
||||||
WHERE v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 AND v1.id = @main_system_id
|
WHERE v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 AND v1.system_value = @main_system_tag
|
||||||
ORDER BY v2.system_priority, v2.created_at desc";
|
ORDER BY v2.system_priority, v2.created_at desc";
|
||||||
|
|
||||||
var param = new { @graph_manage_layer1 = graph_manage_layer1, @graph_manage_layer2 = graph_manage_layer2 };
|
var param = new { @graph_manage_layer1 = graph_manage_layer1, @graph_manage_layer2 = graph_manage_layer2, @main_system_tag = main_system_tag };
|
||||||
sub_system_list = await backendRepository.GetAllAsync<Variable>(sqlString, param);
|
sub_system_list = await backendRepository.GetAllAsync<Variable>(sqlString, param);
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
@ -99,18 +99,19 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
{
|
{
|
||||||
var sqlString = @$"SELECT *
|
var sqlString = @$"SELECT *
|
||||||
FROM graph_manage gm
|
FROM graph_manage gm
|
||||||
JOIN variable v2 ON gm.sub_system_id = v2.id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0
|
JOIN variable v1 ON v1.system_value = @main_system_tag and v1.system_type = @graph_manage_layer1 and v1.deleted = 0
|
||||||
WHERE v2.id in @sub_system_id AND gm.deleted = 0
|
JOIN variable v2 ON v1.id = v2.system_parent_id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0
|
||||||
|
WHERE v2.system_value in @sub_system_tag AND gm.deleted = 0
|
||||||
ORDER BY gm.priority, gm.created_at desc";
|
ORDER BY gm.priority, gm.created_at desc";
|
||||||
|
|
||||||
|
|
||||||
var param = new { @graph_manage_layer1 = graph_manage_layer1, graph_manage_layer2 = graph_manage_layer2, @sub_system_id = gi.sub_system_id };
|
var param = new { @graph_manage_layer1 = graph_manage_layer1, graph_manage_layer2 = graph_manage_layer2, @sub_system_tag = gi.sub_system_tag, @main_system_tag = gi.main_system_tag };
|
||||||
|
|
||||||
graManList = await backendRepository.GetAllAsync<GraphList>(sqlString, param);
|
graManList = await backendRepository.GetAllAsync<GraphList>(sqlString, param);
|
||||||
|
|
||||||
if (gi.keyWord != null)
|
if (gi.keyWord != null)
|
||||||
{
|
{
|
||||||
var wParam = new { @graph_manage_layer1 = graph_manage_layer1, graph_manage_layer2 = graph_manage_layer2, @sub_system_id = gi.sub_system_id, @keyWord = gi.keyWord };
|
var wParam = new { @graph_manage_layer1 = graph_manage_layer1, graph_manage_layer2 = graph_manage_layer2, @sub_system_tag = gi.sub_system_tag, @main_system_tag = gi.main_system_tag, @keyWord = gi.keyWord };
|
||||||
graManList = await backendRepository.GetAllAsync<GraphList>(@$"SELECT *
|
graManList = await backendRepository.GetAllAsync<GraphList>(@$"SELECT *
|
||||||
FROM graph_manage gm
|
FROM graph_manage gm
|
||||||
JOIN variable v2 ON gm.sub_system_id = v2.id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0
|
JOIN variable v2 ON gm.sub_system_id = v2.id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0
|
||||||
@ -139,9 +140,9 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sqlString = @$"UPDATE graph_manage SET deleted = 0 WHERE code = @code AND sub_system_id = @sub_system_id";
|
var sqlString = @$"UPDATE graph_manage SET deleted = 0 WHERE code = @code AND sub_system_tag = @sub_system_tag AND main_system_tag = @main_system_tag";
|
||||||
|
|
||||||
var param = new { @code = gi.code, @sub_system_id = gi.sub_system_id };
|
var param = new { @code = gi.code, @sub_system_tag = gi.sub_system_tag, @main_system_tag = gi.main_system_tag };
|
||||||
|
|
||||||
await backendRepository.ExecuteSql(sqlString, param);
|
await backendRepository.ExecuteSql(sqlString, param);
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
@ -164,8 +165,8 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sWhere = @$"deleted = 0 AND code = @code AND sub_system_id = @sub_system_id";
|
var sWhere = @$"deleted = 0 AND code = @code AND sub_system_tag = @sub_system_tag AND main_system_tag = @main_system_tag";
|
||||||
var gm = await backendRepository.GetOneAsync<GraphInsInfo>("graph_manage", sWhere, new { @code = gii.code, @sub_system_id = gii.sub_system_id});
|
var gm = await backendRepository.GetOneAsync<GraphInsInfo>("graph_manage", sWhere, new { @code = gii.code, @sub_system_tag = gii.sub_system_tag, @main_system_tag = gii.main_system_tag});
|
||||||
|
|
||||||
if (gm == null)
|
if (gm == null)
|
||||||
{
|
{
|
||||||
@ -226,9 +227,11 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
graph_manage.Add("@name", gii.name);
|
graph_manage.Add("@name", gii.name);
|
||||||
|
graph_manage.Add("@main_system_tag", gii.main_system_tag);
|
||||||
|
graph_manage.Add("@sub_system_tag", gii.sub_system_tag);
|
||||||
//graph_manage.Add("@priority", gii.priority);
|
//graph_manage.Add("@priority", gii.priority);
|
||||||
|
|
||||||
await backendRepository.UpdateOneByCustomTable(graph_manage, "graph_manage", "code='" + gii.code + "'" + "sub_system_id ='" + gii.sub_system_id + "'");
|
await backendRepository.UpdateOneByCustomTable(graph_manage, "graph_manage", "code='" + gm.code + "'" + " and sub_system_tag ='" + gm.sub_system_tag + "' and main_system_tag = '" + gm.main_system_tag + "'");
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Data = "修改成功";
|
apiResult.Data = "修改成功";
|
||||||
}
|
}
|
||||||
@ -251,8 +254,8 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sWhere = @$"deleted = 0 AND code = @code AND sub_system_id = @sub_system_id";
|
var sWhere = @$"deleted = 0 AND code = @code AND sub_system_tag = @sub_system_tag AND main_system_tag = @main_system_tag";
|
||||||
var gm = await backendRepository.GetOneAsync<GraphInsInfo>("graph_manage", sWhere, new { @code = gii.code, @sub_system_id = gii.sub_system_id });
|
var gm = await backendRepository.GetOneAsync<GraphInsInfo>("graph_manage", sWhere, new { @code = gii.code, @sub_system_tag = gii.sub_system_tag, @main_system_tag = gii.main_system_tag });
|
||||||
|
|
||||||
if (gm != null)
|
if (gm != null)
|
||||||
{
|
{
|
||||||
@ -305,6 +308,8 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
var newPriority = await backendRepository.GetCurrentPriority("graph_manage");
|
var newPriority = await backendRepository.GetCurrentPriority("graph_manage");
|
||||||
|
graph_manage.Add("@main_system_tag", gii.main_system_tag);
|
||||||
|
graph_manage.Add("@sub_system_tag", gii.sub_system_tag);
|
||||||
graph_manage.Add("@name", gii.name);
|
graph_manage.Add("@name", gii.name);
|
||||||
graph_manage.Add("@deleted", 0);
|
graph_manage.Add("@deleted", 0);
|
||||||
graph_manage.Add("@priority", newPriority + 1);
|
graph_manage.Add("@priority", newPriority + 1);
|
||||||
|
@ -15,6 +15,8 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace FrontendWebApi.ApiControllers
|
namespace FrontendWebApi.ApiControllers
|
||||||
{
|
{
|
||||||
@ -44,7 +46,6 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
ctx.Response.Headers.Add("Access-Control-Allow-Headers", "*");
|
ctx.Response.Headers.Add("Access-Control-Allow-Headers", "*");
|
||||||
ctx.Response.Headers.Add("Access-Control-Allow-Credentials", "true");
|
ctx.Response.Headers.Add("Access-Control-Allow-Credentials", "true");
|
||||||
EDFunction edFunction = new EDFunction();
|
EDFunction edFunction = new EDFunction();
|
||||||
var a = User.Claims.Select(p => new { Type = p.Type, Value = p.Value }).ToList();
|
|
||||||
myUser = new JwtGet()
|
myUser = new JwtGet()
|
||||||
{
|
{
|
||||||
account = User.Claims.Where(a => a.Type == "account").Select(e => e.Value).FirstOrDefault(),
|
account = User.Claims.Where(a => a.Type == "account").Select(e => e.Value).FirstOrDefault(),
|
||||||
@ -59,6 +60,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
{
|
{
|
||||||
jwt_str = "Jwt Token不合法";
|
jwt_str = "Jwt Token不合法";
|
||||||
jwtlife = false;
|
jwtlife = false;
|
||||||
|
filterContext.Result = new JsonResult(new { HttpStatusCode.Unauthorized });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
406
FrontendWebApi/ApiControllers/OperationController.cs
Normal file
406
FrontendWebApi/ApiControllers/OperationController.cs
Normal file
@ -0,0 +1,406 @@
|
|||||||
|
using FrontendWebApi.Models;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NPOI.SS.UserModel;
|
||||||
|
using NPOI.XSSF.UserModel;
|
||||||
|
using Repository.BackendRepository.Interface;
|
||||||
|
using Repository.FrontendRepository.Interface;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FrontendWebApi.ApiControllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class OperationController : MyBaseApiController<OperationController>
|
||||||
|
{
|
||||||
|
private readonly IBackendRepository backendRepository;
|
||||||
|
private string operationFileSaveAsPath = "";
|
||||||
|
|
||||||
|
public OperationController(IBackendRepository backendRepository)
|
||||||
|
{
|
||||||
|
this.backendRepository = backendRepository;
|
||||||
|
operationFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ApiResult<List<Variable>>> MaiSysList()
|
||||||
|
{
|
||||||
|
ApiResult<List<Variable>> apiResult = new ApiResult<List<Variable>>();
|
||||||
|
List<Variable> main_system_list = new List<Variable>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sqlString = @$"SELECT *
|
||||||
|
FROM variable
|
||||||
|
WHERE system_type = @main_system_type AND deleted = 0
|
||||||
|
ORDER BY system_priority, created_at desc";
|
||||||
|
|
||||||
|
var param = new { @main_system_type = main_system_type };
|
||||||
|
main_system_list = await backendRepository.GetAllAsync<Variable>(sqlString, param);
|
||||||
|
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Data = main_system_list;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ApiResult<List<Variable>>> SubSysList(string main_system_tag)
|
||||||
|
{
|
||||||
|
ApiResult<List<Variable>> apiResult = new ApiResult<List<Variable>>();
|
||||||
|
List<Variable> sub_system_list = new List<Variable>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sqlString = @$"SELECT v2.*
|
||||||
|
FROM variable v2
|
||||||
|
JOIN variable v1 ON v2.system_parent_id = v1.id AND v1.system_type = @main_system_type AND v1.deleted = 0
|
||||||
|
WHERE v2.system_type = @sub_system_type AND v2.deleted = 0 AND v1.system_type = @main_system_tag
|
||||||
|
ORDER BY v2.system_priority, v2.created_at desc";
|
||||||
|
|
||||||
|
var param = new { @main_system_type = main_system_type, @sub_system_type = sub_system_type, @main_system_tag = main_system_tag };
|
||||||
|
sub_system_list = await backendRepository.GetAllAsync<Variable>(sqlString, param);
|
||||||
|
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Data = sub_system_list;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 廠商資料列表(搜寻)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ofl"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<ApiResult<List<Operation_Firm>>> OpeFirList(OperationFindList ofl)
|
||||||
|
{
|
||||||
|
ApiResult<List<Operation_Firm>> apiResult = new ApiResult<List<Operation_Firm>>();
|
||||||
|
List<Operation_Firm> opList = new List<Operation_Firm>();
|
||||||
|
string sWhere = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (ofl.start_created_at != null || ofl.end_created_at != null)
|
||||||
|
{
|
||||||
|
sWhere += $@" and (of.created_at >= isnull(@start_created_at, of.created_at) AND of.created_at <= isnull(@end_created_at, of.created_at))";
|
||||||
|
}
|
||||||
|
else if (ofl.today)
|
||||||
|
{
|
||||||
|
sWhere += $@" and convert(of.created_at, DATE) = convert(NOW(), DATE)";
|
||||||
|
}
|
||||||
|
else if (ofl.yesterday)
|
||||||
|
{
|
||||||
|
sWhere += $@" and convert(of.created_at, DATE) = convert(ADDDATE(NOW(), -1), DATE)";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ofl.sub_system_tag != null || ofl.main_system_tag != null)
|
||||||
|
{
|
||||||
|
sWhere += $@" and (of.device_system_category_layer2 = isnull(@main_system_tag, device_system_category_layer2) AND of.device_system_category_layer3 = isnull(@sub_system_tag, device_system_category_layer3))";
|
||||||
|
}
|
||||||
|
|
||||||
|
var sqlString = @$"select of.*, v2.system_key
|
||||||
|
from operation_firm of
|
||||||
|
left join variable v1 on of.device_system_category_layer2 = v1.system_value and v1.system_type = @main_system_type and v1.delted = 0
|
||||||
|
left join variable v2 on v1.id = v2.system_parent_id and of.device_system_category_layer3 = v2.system_value and v2.system_type = @sub_system_type and v2.deleted = 0
|
||||||
|
where of.deleted = 0" + sWhere;
|
||||||
|
|
||||||
|
|
||||||
|
var param = new { @sub_system_type = sub_system_type, @start_created_at = ofl.start_created_at, @end_created_at = ofl.end_created_at, @today = ofl.today, @yesterday = ofl.yesterday, @sub_system_tag = ofl.sub_system_tag, @main_system_tag = ofl.main_system_tag };
|
||||||
|
opList = await backendRepository.GetAllAsync<Operation_Firm>(sqlString, param);
|
||||||
|
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Data = opList;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增一笔廠商資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="of"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<ApiResult<string>> SaveOpeFirm(Operation_Firm of)
|
||||||
|
{
|
||||||
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (of.tax_id_number != null)
|
||||||
|
{
|
||||||
|
var sWhere = "deleted = 0 AND tax_id_number = @tax_id_number";
|
||||||
|
var ofo = await backendRepository.GetOneAsync<Operation_Firm>("operation_firm", sWhere, new { @tax_id_number = of.tax_id_number });
|
||||||
|
if (ofo != null)
|
||||||
|
{
|
||||||
|
apiResult.Code = "0002";
|
||||||
|
apiResult.Data = "已有相同的统一编号";
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, object> operation_firm = new Dictionary<string, object>()
|
||||||
|
{
|
||||||
|
{ "@deleted", 0 },
|
||||||
|
{ "@device_system_category_layer2", of.device_system_category_layer2 },
|
||||||
|
{ "@device_system_category_layer3", of.device_system_category_layer3 },
|
||||||
|
{ "@name", of.name },
|
||||||
|
{ "@contact_person", of.contact_person },
|
||||||
|
{ "@phone", of.phone },
|
||||||
|
{ "@email", of.email },
|
||||||
|
{ "@tax_id_number", of.tax_id_number },
|
||||||
|
{ "@remark", of.remark },
|
||||||
|
{ "@created_by", myUser.userinfo_guid },
|
||||||
|
{ "@created_at", DateTime.Now }
|
||||||
|
};
|
||||||
|
|
||||||
|
await backendRepository.AddOneByCustomTable(operation_firm, "operation_firm");
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Data = "新增成功";
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||||
|
string json = System.Text.Json.JsonSerializer.Serialize(of);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 编辑一笔廠商資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="of"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<ApiResult<string>> EdtOneOpeFirm(Operation_Firm of)
|
||||||
|
{
|
||||||
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sWhere = @$"deleted = 0 and id = @id";
|
||||||
|
var gm = await backendRepository.GetOneAsync<Operation_Firm>("operation_firm", sWhere, new { @id = of.id });
|
||||||
|
|
||||||
|
if (gm == null)
|
||||||
|
{
|
||||||
|
apiResult.Code = "0001";
|
||||||
|
apiResult.Data = "無法找到厂商";
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (of.tax_id_number != null)
|
||||||
|
{
|
||||||
|
sWhere = "deleted = 0 AND tax_id_number = @tax_id_number and id != @id";
|
||||||
|
var ofo = await backendRepository.GetOneAsync<Operation_Firm>("operation_firm", sWhere, new { @tax_id_number = of.tax_id_number, @id = of.id });
|
||||||
|
if (ofo != null)
|
||||||
|
{
|
||||||
|
apiResult.Code = "0002";
|
||||||
|
apiResult.Data = "已有相同的统一编号";
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, object> operation_firm = new Dictionary<string, object>()
|
||||||
|
{
|
||||||
|
{ "@deleted", of.deleted },
|
||||||
|
{ "@device_system_category_layer2", of.device_system_category_layer2 },
|
||||||
|
{ "@device_system_category_layer3", of.device_system_category_layer3 },
|
||||||
|
{ "@name", of.name },
|
||||||
|
{ "@contact_person", of.contact_person },
|
||||||
|
{ "@phone", of.phone },
|
||||||
|
{ "@email", of.email },
|
||||||
|
{ "@tax_id_number", of.tax_id_number },
|
||||||
|
{ "@remark", of.remark },
|
||||||
|
{ "updated_by", myUser.userinfo_guid },
|
||||||
|
{ "updated_at", DateTime.Now }
|
||||||
|
};
|
||||||
|
|
||||||
|
await backendRepository.UpdateOneByCustomTable(operation_firm, "operation_firm", "id = '" + of.id + "'");
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Data = "修改成功";
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||||
|
string json = System.Text.Json.JsonSerializer.Serialize(of);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 汇出excel
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public FileResult ExportExcel()
|
||||||
|
{
|
||||||
|
var workbook = new XSSFWorkbook();
|
||||||
|
#region excel設定
|
||||||
|
IFont font12 = workbook.CreateFont();
|
||||||
|
font12.FontName = "新細明體";
|
||||||
|
font12.FontHeightInPoints = 12;
|
||||||
|
ICellStyle style12 = workbook.CreateCellStyle();
|
||||||
|
style12.SetFont(font12);
|
||||||
|
style12.Alignment = HorizontalAlignment.Center;
|
||||||
|
style12.VerticalAlignment = VerticalAlignment.Center;
|
||||||
|
IFont font12Times = workbook.CreateFont();
|
||||||
|
font12Times.FontName = "Times New Roman";
|
||||||
|
font12Times.FontHeightInPoints = 12;
|
||||||
|
IFont font18 = workbook.CreateFont();
|
||||||
|
font18.FontName = "新細明體";
|
||||||
|
font18.FontHeightInPoints = 18;
|
||||||
|
font18.IsBold = true;
|
||||||
|
ICellStyle styleTitle18 = workbook.CreateCellStyle();
|
||||||
|
styleTitle18.SetFont(font18);
|
||||||
|
styleTitle18.Alignment = HorizontalAlignment.Center;
|
||||||
|
styleTitle18.VerticalAlignment = VerticalAlignment.Center;
|
||||||
|
ICellStyle styleLeft12 = workbook.CreateCellStyle();
|
||||||
|
styleLeft12.SetFont(font12);
|
||||||
|
styleLeft12.Alignment = HorizontalAlignment.Left;
|
||||||
|
styleLeft12.VerticalAlignment = VerticalAlignment.Center;
|
||||||
|
ICellStyle styleLine12 = workbook.CreateCellStyle();
|
||||||
|
styleLine12.SetFont(font12);
|
||||||
|
styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
||||||
|
styleLine12.VerticalAlignment = VerticalAlignment.Center;
|
||||||
|
styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||||
|
styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||||
|
styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||||
|
styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||||
|
ICellStyle stylein12 = workbook.CreateCellStyle();
|
||||||
|
stylein12.SetFont(font12Times);
|
||||||
|
stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
|
||||||
|
stylein12.VerticalAlignment = VerticalAlignment.Center;
|
||||||
|
stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||||
|
stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||||
|
stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||||
|
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||||
|
stylein12.WrapText = true;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
var sqlString = $@"select of.*, v2.system_key
|
||||||
|
from operation_firm of
|
||||||
|
left join variable v1 on of.device_system_category_layer2 = v1.system_value and v1.system_type = @main_system_type and v1.delted = 0
|
||||||
|
left join variable v2 on v1.id = v2.system_parent_id and of.device_system_category_layer3 = v2.system_value and v2.system_type = @sub_system_type and v2.deleted = 0
|
||||||
|
where of.deleted = 0";
|
||||||
|
var sheet = workbook.CreateSheet("廠商資料");
|
||||||
|
var operation_firm = backendRepository.GetAllAsync<Operation_Firm>(sqlString, null);
|
||||||
|
int RowPosition = 0;
|
||||||
|
IRow row = sheet.CreateRow(RowPosition);
|
||||||
|
sheet.SetColumnWidth(0, 4 * 160 * 12);
|
||||||
|
sheet.SetColumnWidth(1, 4 * 160 * 12);
|
||||||
|
sheet.SetColumnWidth(3, 4 * 160 * 12);
|
||||||
|
sheet.SetColumnWidth(4, 4 * 160 * 12);
|
||||||
|
sheet.SetColumnWidth(5, 4 * 160 * 12);
|
||||||
|
sheet.SetColumnWidth(6, 4 * 160 * 12);
|
||||||
|
sheet.SetColumnWidth(7, 4 * 160 * 12);
|
||||||
|
ICell cell = row.CreateCell(0);
|
||||||
|
cell.SetCellValue("廠商類別");
|
||||||
|
cell.CellStyle = styleLine12;
|
||||||
|
cell = row.CreateCell(1);
|
||||||
|
cell.SetCellValue("廠商名稱");
|
||||||
|
cell.CellStyle = styleLine12;
|
||||||
|
cell = row.CreateCell(2);
|
||||||
|
cell.SetCellValue("聯絡人");
|
||||||
|
cell.CellStyle = styleLine12;
|
||||||
|
cell = row.CreateCell(3);
|
||||||
|
cell.SetCellValue("電話");
|
||||||
|
cell.CellStyle = styleLine12;
|
||||||
|
cell = row.CreateCell(4);
|
||||||
|
cell.SetCellValue("郵箱");
|
||||||
|
cell.CellStyle = styleLine12;
|
||||||
|
cell = row.CreateCell(5);
|
||||||
|
cell.SetCellValue("統一編號");
|
||||||
|
cell.CellStyle = styleLine12;
|
||||||
|
cell = row.CreateCell(6);
|
||||||
|
cell.SetCellValue("備注");
|
||||||
|
cell.CellStyle = styleLine12;
|
||||||
|
cell = row.CreateCell(2);
|
||||||
|
cell.SetCellValue("建立時間");
|
||||||
|
cell.CellStyle = styleLine12;
|
||||||
|
|
||||||
|
foreach (var of in operation_firm.Result)
|
||||||
|
{
|
||||||
|
RowPosition += 1;
|
||||||
|
row = sheet.CreateRow(RowPosition);
|
||||||
|
for (var a = 0; a < 8; a++)
|
||||||
|
{
|
||||||
|
cell = row.CreateCell(a);
|
||||||
|
if (a == 0)
|
||||||
|
{
|
||||||
|
cell.SetCellValue(of.system_key);
|
||||||
|
}
|
||||||
|
if (a == 1)
|
||||||
|
{
|
||||||
|
cell.SetCellValue(of.name);
|
||||||
|
}
|
||||||
|
if (a == 2)
|
||||||
|
{
|
||||||
|
cell.SetCellValue(of.contact_person);
|
||||||
|
}
|
||||||
|
if (a == 3)
|
||||||
|
{
|
||||||
|
cell.SetCellValue(of.phone);
|
||||||
|
}
|
||||||
|
if (a == 4)
|
||||||
|
{
|
||||||
|
cell.SetCellValue(of.email);
|
||||||
|
}
|
||||||
|
if (a == 5)
|
||||||
|
{
|
||||||
|
cell.SetCellValue(of.tax_id_number);
|
||||||
|
}
|
||||||
|
if (a == 2)
|
||||||
|
{
|
||||||
|
cell.SetCellValue(of.remark);
|
||||||
|
}
|
||||||
|
if (a == 7)
|
||||||
|
{
|
||||||
|
cell.SetCellValue(of.Created_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell.CellStyle = style12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var ms = new NpoiMemoryStream
|
||||||
|
{
|
||||||
|
AllowClose = false
|
||||||
|
};
|
||||||
|
workbook.Write(ms);
|
||||||
|
ms.Flush();
|
||||||
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
return File(ms, "application/vnd.ms-excel", "廠商資料.xlsx");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -35,8 +35,8 @@ namespace FrontendWebApi.Jwt
|
|||||||
//claims.Add(new Claim(JwtRegisteredClaimNames.NameId, login.CustomerNo.ToString()));
|
//claims.Add(new Claim(JwtRegisteredClaimNames.NameId, login.CustomerNo.ToString()));
|
||||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Sub, login.Username)); // User.Identity.Name
|
//claims.Add(new Claim(JwtRegisteredClaimNames.Sub, login.Username)); // User.Identity.Name
|
||||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Aud, "The Audience"));
|
//claims.Add(new Claim(JwtRegisteredClaimNames.Aud, "The Audience"));
|
||||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Exp, DateTimeOffset.UtcNow.AddSeconds(expireSeconds).ToUnixTimeSeconds().ToString()));
|
claims.Add(new Claim(JwtRegisteredClaimNames.Exp, DateTimeOffset.UtcNow.AddSeconds(lifeseconds).ToUnixTimeSeconds().ToString()));
|
||||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString())); // 必須為數字
|
claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString())); // 必須為數字
|
||||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Iat, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString())); // 必須為數字
|
//claims.Add(new Claim(JwtRegisteredClaimNames.Iat, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString())); // 必須為數字
|
||||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())); // JWT ID
|
//claims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())); // JWT ID
|
||||||
|
|
||||||
@ -69,13 +69,24 @@ namespace FrontendWebApi.Jwt
|
|||||||
var tokenHandler = new JwtSecurityTokenHandler();
|
var tokenHandler = new JwtSecurityTokenHandler();
|
||||||
|
|
||||||
var jst = new JwtSecurityToken(
|
var jst = new JwtSecurityToken(
|
||||||
issuer: issuer,//Token釋出者
|
issuer: issuer,//Token釋出者
|
||||||
//audience: _options.Value.Audience,//Token接受者
|
//audience: _options.Value.Audience,//Token接受者
|
||||||
claims: claims,//攜帶的負載
|
claims: claims,//攜帶的負載
|
||||||
notBefore: now,//當前時間token生成時間
|
notBefore: now,//當前時間token生成時間
|
||||||
expires: expires,//過期時間
|
expires: expires,//過期時間
|
||||||
signingCredentials: signingCredentials
|
signingCredentials: signingCredentials
|
||||||
);
|
);
|
||||||
|
//var jst = new SecurityTokenDescriptor
|
||||||
|
//{
|
||||||
|
// Issuer = issuer,//Token釋出者
|
||||||
|
// //Claims = claims,//攜帶的負載
|
||||||
|
// //audience: _options.Value.Audience,//Token接受者
|
||||||
|
// NotBefore = now,//當前時間token生成時間
|
||||||
|
// Expires = expires,//過期時間
|
||||||
|
// SigningCredentials = signingCredentials,
|
||||||
|
// Subject = userClaimsIdentity
|
||||||
|
//};
|
||||||
|
|
||||||
var serializeToken = tokenHandler.WriteToken(jst);
|
var serializeToken = tokenHandler.WriteToken(jst);
|
||||||
|
|
||||||
var data = new TnToken();
|
var data = new TnToken();
|
||||||
|
@ -9,7 +9,8 @@ namespace FrontendWebApi.Models
|
|||||||
public class GraphList
|
public class GraphList
|
||||||
{
|
{
|
||||||
public string code { get; set; }
|
public string code { get; set; }
|
||||||
public int sub_system_id { get; set; }
|
public string main_system_tag { get; set; }
|
||||||
|
public int sub_system_tag { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
public string oriOrgName { get; set; }
|
public string oriOrgName { get; set; }
|
||||||
public string oriSavName { get; set; }
|
public string oriSavName { get; set; }
|
||||||
@ -20,7 +21,8 @@ namespace FrontendWebApi.Models
|
|||||||
public class GraphInsInfo
|
public class GraphInsInfo
|
||||||
{
|
{
|
||||||
public string code { get; set; }
|
public string code { get; set; }
|
||||||
public int sub_system_id { get; set; }
|
public string main_system_tag { get; set; }
|
||||||
|
public string sub_system_tag { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
public string oriOrgName { get; set; }
|
public string oriOrgName { get; set; }
|
||||||
public string oriSavName { get; set; }
|
public string oriSavName { get; set; }
|
||||||
@ -34,7 +36,8 @@ namespace FrontendWebApi.Models
|
|||||||
public class GraphInfo
|
public class GraphInfo
|
||||||
{
|
{
|
||||||
public string code { get; set; }
|
public string code { get; set; }
|
||||||
public List<int> sub_system_id { get; set; }
|
public string main_system_tag { get; set; }
|
||||||
|
public List<int> sub_system_tag { get; set; }
|
||||||
public string keyWord { get; set; }
|
public string keyWord { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,32 @@ namespace FrontendWebApi.Models
|
|||||||
Fix = 2, //維修
|
Fix = 2, //維修
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Operation_Firm : Actor
|
||||||
|
{
|
||||||
|
public int id { get; set; }
|
||||||
|
public byte deleted { get; set; }
|
||||||
|
public string device_system_category_layer2 { get; set; }//系統類別(第2層)
|
||||||
|
public string device_system_category_layer3 { get; set; }//系統類別(第3層)
|
||||||
|
public string name { get; set; }//名称
|
||||||
|
public string contact_person { get; set; }//联络人
|
||||||
|
public string phone { get; set; }//电话
|
||||||
|
public string email { get; set; }//Email
|
||||||
|
public string tax_id_number { get; set; }//统一编号
|
||||||
|
public string remark { get; set; }//备注
|
||||||
|
public string system_key { get; set; }//類別名稱
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OperationFindList
|
||||||
|
{
|
||||||
|
public string serial_number { get; set; } //表单号
|
||||||
|
public DateTime? start_created_at { get; set; }//开始建立时间
|
||||||
|
public DateTime? end_created_at { get; set; }//结束建立时间
|
||||||
|
public bool today { get; set; }//今天建立时间
|
||||||
|
public bool yesterday { get; set; }//昨天建立时间
|
||||||
|
public string main_system_tag { get; set; }//大类tag
|
||||||
|
public string sub_system_tag { get; set; }//小类tag
|
||||||
|
}
|
||||||
|
|
||||||
public class Operation : Actor
|
public class Operation : Actor
|
||||||
{
|
{
|
||||||
public int Id { get; set; }//流水號
|
public int Id { get; set; }//流水號
|
||||||
|
@ -58,6 +58,7 @@ namespace FrontendWebApi
|
|||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
services.AddSingleton<JwtHelpers>();
|
||||||
services.AddControllersWithViews();
|
services.AddControllersWithViews();
|
||||||
//services.AddControllers();
|
//services.AddControllers();
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ namespace FrontendWebApi
|
|||||||
// 當驗證失敗時,回應標頭會包含 WWW-Authenticate 標頭,這裡會顯示失敗的詳細錯誤原因
|
// 當驗證失敗時,回應標頭會包含 WWW-Authenticate 標頭,這裡會顯示失敗的詳細錯誤原因
|
||||||
options.IncludeErrorDetails = true; // 預設值為 true,有時會特別關閉
|
options.IncludeErrorDetails = true; // 預設值為 true,有時會特別關閉
|
||||||
|
|
||||||
options.TokenValidationParameters = new TokenValidationParameters()
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
{
|
{
|
||||||
// 透過這項宣告,就可以從 "sub" 取值並設定給 User.Identity.Name
|
// 透過這項宣告,就可以從 "sub" 取值並設定給 User.Identity.Name
|
||||||
NameClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
|
NameClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
|
||||||
@ -140,7 +141,6 @@ namespace FrontendWebApi
|
|||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
|
|
||||||
loggerFactory.AddFile("Logs/log-{Date}.txt");
|
loggerFactory.AddFile("Logs/log-{Date}.txt");
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
|
@ -0,0 +1,507 @@
|
|||||||
|
using Dapper;
|
||||||
|
using Repository.BackendRepository.Interface;
|
||||||
|
using Repository.Helper;
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Transactions;
|
||||||
|
using Repository.Models;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Repository.BackendRepository.Implement
|
||||||
|
{
|
||||||
|
public class NiagaraDataSynchronizeRepository : BackendRepository, INiagaraDataSynchronizeRepository
|
||||||
|
{
|
||||||
|
public NiagaraDataSynchronizeRepository(IDatabaseHelper databaseHelper) : base(databaseHelper)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新import_niagara_tag資料表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ds"></param>
|
||||||
|
/// <param name="building"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task InsertNiagaraTagList(List<Device_value> ds, string building)
|
||||||
|
{
|
||||||
|
using (IDbConnection conn = GetDbConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = @"CREATE TABLE IF NOT EXISTS `import_niagara_tag` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`db_tags` varchar(50) DEFAULT NULL,
|
||||||
|
`niagara_tags` varchar(50) DEFAULT NULL,
|
||||||
|
`device_area_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_building_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_system_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_name_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_floor_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_master_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_last_name_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_serial_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`atDateTime` datetime(1) DEFAULT NULL,
|
||||||
|
`is_used` smallint(1) DEFAULT 0,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
|
||||||
|
await conn.ExecuteAsync(sql);
|
||||||
|
sql = "delete from import_niagara_tag where device_building_tag = '" + building + "'";
|
||||||
|
await conn.ExecuteAsync(sql);
|
||||||
|
|
||||||
|
//N4資料groupBy後放入import_niagara_tag資料表
|
||||||
|
var ds2 = ds.GroupBy(x => new
|
||||||
|
{
|
||||||
|
tag_name2 = x.tag_name
|
||||||
|
}).Select(x => new Device_value
|
||||||
|
{
|
||||||
|
tag_name = x.Key.tag_name2
|
||||||
|
});
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (var row in ds2)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(row.tag_name)) continue;
|
||||||
|
string[] arrTag = row.tag_name.Split('_');
|
||||||
|
|
||||||
|
sb.Append($@" insert import_niagara_tag(niagara_tags, device_area_tag, device_building_tag, device_system_tag,
|
||||||
|
device_name_tag, device_floor_tag, device_master_tag, device_last_name_tag, device_serial_tag, atDateTime) values('" +
|
||||||
|
row.tag_name + "', '" +
|
||||||
|
arrTag[0] + "', '" +
|
||||||
|
arrTag[1] + "', '" +
|
||||||
|
arrTag[2] + "', '" +
|
||||||
|
arrTag[3] + "', '" +
|
||||||
|
arrTag[4] + "', '" +
|
||||||
|
arrTag[5] + "', '" +
|
||||||
|
arrTag[6] + "', '" +
|
||||||
|
arrTag[7] + "', " +
|
||||||
|
"now());");
|
||||||
|
}
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
sb.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新import_niagara_tag資料表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ds"></param>
|
||||||
|
/// <param name="building"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task InsertItemFromNiagara(List<Device_value> ds, string building)
|
||||||
|
{
|
||||||
|
using (IDbConnection conn = GetDbConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#region 刪除 import_niagara_item資料表中選取的棟別
|
||||||
|
string sql = @"CREATE TABLE IF NOT EXISTS `import_niagara_item` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`device_area_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_building_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_system_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_name_tag` varchar(50) DEFAULT NULL,
|
||||||
|
`device_point_name` varchar(50) DEFAULT NULL,
|
||||||
|
`check_status` varchar(50) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
|
||||||
|
await conn.ExecuteAsync(sql);
|
||||||
|
sql = "delete from import_niagara_item where device_building_tag = '" + building + "'";
|
||||||
|
await conn.ExecuteAsync(sql);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
List<Device_item8> dt_item = new List<Device_item8>();
|
||||||
|
|
||||||
|
foreach (var row in ds)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(row.tag_name)) continue;
|
||||||
|
string[] arrTag = row.tag_name.Split('_');
|
||||||
|
|
||||||
|
#region for item
|
||||||
|
Device_item8 row_item = new Device_item8();
|
||||||
|
row_item.tag_name = row.tag_name;
|
||||||
|
row_item.device_area_tag = arrTag[0];
|
||||||
|
row_item.device_building_tag = arrTag[1];
|
||||||
|
row_item.device_system_tag = arrTag[2];
|
||||||
|
row_item.device_name_tag = arrTag[3];
|
||||||
|
row_item.device_floor_tag = arrTag[4];
|
||||||
|
row_item.device_master_tag = arrTag[5];
|
||||||
|
row_item.device_last_name_tag = arrTag[6];
|
||||||
|
row_item.device_serial_tag = arrTag[7];
|
||||||
|
row_item.point_name = row.point_name;
|
||||||
|
dt_item.Add(row_item);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
#region N4資料groupBy後放入import_niagara_item資料表
|
||||||
|
var ds2_item = dt_item.GroupBy(x => new
|
||||||
|
{
|
||||||
|
device_area_tag2 = x.device_area_tag,
|
||||||
|
device_building_tag2 = x.device_building_tag,
|
||||||
|
device_system_tag2 = x.device_system_tag,
|
||||||
|
device_name_tag2 = x.device_name_tag,
|
||||||
|
point_name2 = x.point_name
|
||||||
|
}).Select(x => new Device_item8
|
||||||
|
{
|
||||||
|
device_area_tag = x.Key.device_area_tag2,
|
||||||
|
device_building_tag = x.Key.device_building_tag2,
|
||||||
|
device_system_tag = x.Key.device_system_tag2,
|
||||||
|
device_name_tag = x.Key.device_name_tag2,
|
||||||
|
point_name = x.Key.point_name2
|
||||||
|
});
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (var row2 in ds2_item)
|
||||||
|
{
|
||||||
|
sb.Append($@" insert import_niagara_item(device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_point_name)
|
||||||
|
values('" +
|
||||||
|
row2.device_area_tag + "', '" +
|
||||||
|
row2.device_building_tag + "', '" +
|
||||||
|
row2.device_system_tag + "', '" +
|
||||||
|
row2.device_name_tag + "', '" +
|
||||||
|
row2.point_name + "'" +
|
||||||
|
");");
|
||||||
|
}
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
sb.Clear();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 比對 device
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task DeviceComparison()
|
||||||
|
{
|
||||||
|
using (IDbConnection conn = GetDbConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<NiagaraTags> result;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
StringBuilder sb2 = new StringBuilder();
|
||||||
|
sb.Append($@" SELECT m.*
|
||||||
|
FROM import_niagara_tag m
|
||||||
|
LEFT JOIN device d
|
||||||
|
ON m.niagara_tags = d.device_number
|
||||||
|
WHERE d.device_number IS NULL");
|
||||||
|
result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>();
|
||||||
|
|
||||||
|
sb.Clear();
|
||||||
|
//新增至device, is_link = 1
|
||||||
|
if (result.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var data in result)
|
||||||
|
{
|
||||||
|
sb.Append($@" insert device(device_guid, deleted, status, priority, is_link, device_area_tag,
|
||||||
|
device_building_tag, device_system_tag, device_name_tag, device_floor_tag, device_master,
|
||||||
|
device_last_name, device_serial_tag, device_number, device_system_category_layer3, created_at, updated_at)
|
||||||
|
values(uuid(), 0, 1, 0, 1, '" +
|
||||||
|
data.device_area_tag + "', '" +
|
||||||
|
data.device_building_tag + "', '" +
|
||||||
|
data.device_system_tag + "', '" +
|
||||||
|
data.device_name_tag + "', '" +
|
||||||
|
|
||||||
|
data.device_floor_tag + "', '" +
|
||||||
|
data.device_master_tag + "', '" +
|
||||||
|
data.device_last_name_tag + "', '" +
|
||||||
|
data.device_serial_tag + "', '" +
|
||||||
|
data.niagara_tags + "', '" +
|
||||||
|
data.device_system_tag + "', now(), now() );");
|
||||||
|
|
||||||
|
sb2.Append($@"INSERT device_kind (device_kind_guid, device_building_tag, device_system_tag, device_name_tag,
|
||||||
|
device_normal_flashing, device_close_flashing, device_error_flashing, device_error_independent,
|
||||||
|
created_by, created_at)
|
||||||
|
VALUES (uuid(), '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag +
|
||||||
|
"', 0, 0, 1, 0, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());");
|
||||||
|
}
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
await conn.ExecuteAsync(sb2.ToString());
|
||||||
|
sb.Clear();
|
||||||
|
sb2.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//device有,niagara沒有,is_link 更新成 0
|
||||||
|
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
|
||||||
|
UPDATE device d LEFT JOIN import_niagara_tag m ON d.device_number = m.niagara_tags
|
||||||
|
SET d.is_link = 0
|
||||||
|
WHERE m.niagara_tags IS NULL");
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 比對 device_item
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task DeviceItemComparison()
|
||||||
|
{
|
||||||
|
using (IDbConnection conn = GetDbConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<NiagaraTagsForItem> result;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append($@" SELECT m.*
|
||||||
|
FROM import_niagara_item m
|
||||||
|
LEFT JOIN device_item d
|
||||||
|
ON m.device_system_tag = d.device_system_tag and m.device_name_tag = d.device_name_tag and m.device_point_name = d.points
|
||||||
|
WHERE d.points IS NULL");
|
||||||
|
result = (await conn.QueryAsync<NiagaraTagsForItem>(sb.ToString())).ToList<NiagaraTagsForItem>();
|
||||||
|
|
||||||
|
sb.Clear();
|
||||||
|
//新增至device, is_link = 1
|
||||||
|
if (result.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var data in result)
|
||||||
|
{
|
||||||
|
var isControll = 0;
|
||||||
|
var isBool = 0;
|
||||||
|
if (data.device_point_name == "ER" || data.device_point_name == "AL" || data.device_point_name == "ST")
|
||||||
|
{
|
||||||
|
isControll = 1;
|
||||||
|
}
|
||||||
|
if (data.device_point_name == "ER" || data.device_point_name == "ST")
|
||||||
|
{
|
||||||
|
isBool = 1;
|
||||||
|
}
|
||||||
|
sb.Append($@"insert device_item(deleted, points, is_show, is_show_riserDiagram, is_controll, is_bool, is_link,
|
||||||
|
device_system_tag, device_name_tag, created_at, updated_at)
|
||||||
|
VALUES (0, '" +
|
||||||
|
data.device_point_name + "', 1, 0, " +
|
||||||
|
isControll + "," +
|
||||||
|
isBool + ", 1, '" +
|
||||||
|
data.device_system_tag + "', '" +
|
||||||
|
data.device_name_tag + "', " +
|
||||||
|
"now(), now());");
|
||||||
|
}
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
sb.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//device有,niagara沒有,is_link 更新成 0
|
||||||
|
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
|
||||||
|
UPDATE device_item d LEFT JOIN import_niagara_item m
|
||||||
|
ON d.device_system_tag = m.device_system_tag and d.device_name_tag = m.device_name_tag and d.points = m.device_point_name
|
||||||
|
SET d.is_link = 0
|
||||||
|
WHERE m.device_point_name IS NULL");
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增資料至 buildingMenu
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task InsertBuildingMenu()
|
||||||
|
{
|
||||||
|
using (IDbConnection conn = GetDbConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<NiagaraTags> result;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
#region comparison building_menu and import_niagara_tag
|
||||||
|
sb.Append($@" select a.* from (
|
||||||
|
select device_building_tag, device_system_tag, device_name_tag
|
||||||
|
from import_niagara_tag
|
||||||
|
group by device_building_tag, device_system_tag, device_name_tag
|
||||||
|
) AS a
|
||||||
|
LEFT JOIN building_menu b
|
||||||
|
ON a.device_building_tag = b.device_building_tag and a.device_system_tag = b.device_system_tag and a.device_name_tag = b.sub_system_tag
|
||||||
|
WHERE b.device_building_tag IS NULL");
|
||||||
|
result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>();
|
||||||
|
#endregion
|
||||||
|
sb.Clear();
|
||||||
|
|
||||||
|
if (result.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var data in result)
|
||||||
|
{
|
||||||
|
#region insert building_menu
|
||||||
|
sb.Append(@"insert building_menu(building_tag, main_system_tag, sub_system_tag, device_building_tag, device_system_tag,
|
||||||
|
is_link, created_by, created_at, updated_by, updated_at)
|
||||||
|
VALUES ('" + data.device_building_tag + "', '" +
|
||||||
|
data.device_system_tag + "', '" +
|
||||||
|
data.device_name_tag + "', '" +
|
||||||
|
data.device_building_tag + "', '" +
|
||||||
|
data.device_system_tag + "', " +
|
||||||
|
"1, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now() );");
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
sb.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//building_menu有,import_niagara_tag沒有,is_link 更新成 0
|
||||||
|
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
|
||||||
|
UPDATE building_menu b LEFT JOIN (
|
||||||
|
select device_building_tag, device_system_tag, device_name_tag
|
||||||
|
from import_niagara_tag
|
||||||
|
group by device_building_tag, device_system_tag, device_name_tag
|
||||||
|
) AS a ON b.device_building_tag = a.device_building_tag
|
||||||
|
and a.device_system_tag = b.device_system_tag and a.device_name_tag = b.sub_system_tag
|
||||||
|
SET b.is_link = 0
|
||||||
|
WHERE b.device_building_tag IS NULL");
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增資料至 subSystemFloor
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task InsertSubSystemFloor()
|
||||||
|
{
|
||||||
|
using (IDbConnection conn = GetDbConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<NiagaraTags> result;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
#region comparison sub_system_floor and import_niagara_tag
|
||||||
|
sb.Append($@" select a.* from (
|
||||||
|
select device_building_tag, device_system_tag, device_name_tag, device_floor_tag
|
||||||
|
from import_niagara_tag
|
||||||
|
group by device_building_tag, device_system_tag, device_name_tag, device_floor_tag
|
||||||
|
) AS a
|
||||||
|
LEFT JOIN sub_system_floor b
|
||||||
|
ON a.device_building_tag = b.building_tag and a.device_system_tag = b.main_system_tag and a.device_name_tag = b.sub_system_tag and a.device_floor_tag = b.floor_tag
|
||||||
|
WHERE b.building_tag IS NULL");
|
||||||
|
result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
sb.Clear();
|
||||||
|
if (result.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var data in result)
|
||||||
|
{
|
||||||
|
#region insert building_menu
|
||||||
|
sb.Append(@"insert sub_system_floor(building_tag, main_system_tag, sub_system_tag, floor_tag,
|
||||||
|
is_link, created_by, created_at, updated_by, updated_at)
|
||||||
|
VALUES ('" +
|
||||||
|
data.device_building_tag + "', '" +
|
||||||
|
data.device_system_tag + "', '" +
|
||||||
|
data.device_name_tag + "', '" +
|
||||||
|
data.device_floor_tag + "', " +
|
||||||
|
"1, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());");
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
sb.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//building_menu有,import_niagara_tag沒有,is_link 更新成 0
|
||||||
|
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
|
||||||
|
UPDATE sub_system_floor b LEFT JOIN (
|
||||||
|
select device_building_tag, device_system_tag, device_name_tag, device_floor_tag
|
||||||
|
from import_niagara_tag
|
||||||
|
group by device_building_tag, device_system_tag, device_name_tag, device_floor_tag
|
||||||
|
) AS a ON b.building_tag = a.device_building_tag
|
||||||
|
and b.main_system_tag = a.device_system_tag and b.sub_system_tag = a.device_name_tag and b.floor_tag = a.device_floor_tag
|
||||||
|
SET b.is_link = 0
|
||||||
|
WHERE b.building_tag IS NULL");
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Repository.Models;
|
||||||
|
|
||||||
|
namespace Repository.BackendRepository.Interface
|
||||||
|
{
|
||||||
|
public interface INiagaraDataSynchronizeRepository : IBackendRepository
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 同步N4至資料表 import_niagara_tag
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ds"></param>
|
||||||
|
/// <param name="building"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task InsertNiagaraTagList(List<Device_value> ds, string building);
|
||||||
|
/// <summary>
|
||||||
|
/// 同步N4至資料表 import_niagara_item
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ds"></param>
|
||||||
|
/// <param name="building"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task InsertItemFromNiagara(List<Device_value> ds, string building);
|
||||||
|
/// <summary>
|
||||||
|
/// 比對 device
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task DeviceComparison();
|
||||||
|
/// <summary>
|
||||||
|
/// 比對 device_item
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task DeviceItemComparison();
|
||||||
|
/// <summary>
|
||||||
|
/// 新增資料至 buildingMenu
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task InsertBuildingMenu();
|
||||||
|
/// <summary>
|
||||||
|
/// 新增資料至 subSystemFloor
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task InsertSubSystemFloor();
|
||||||
|
}
|
||||||
|
}
|
@ -37,4 +37,60 @@ namespace Repository.Models
|
|||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
public string File { get; set; }
|
public string File { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得niagara資料
|
||||||
|
/// </summary>
|
||||||
|
public class Device_value
|
||||||
|
{
|
||||||
|
public string name { get; set; }
|
||||||
|
public string value { get; set; }
|
||||||
|
public string tag_name { get; set; }
|
||||||
|
public string point_name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Device_item8
|
||||||
|
{
|
||||||
|
public string name { get; set; }
|
||||||
|
public string value { get; set; }
|
||||||
|
public string tag_name { get; set; }
|
||||||
|
public string device_area_tag { 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_master_tag { get; set; }
|
||||||
|
public string device_last_name_tag { get; set; }
|
||||||
|
public string device_serial_tag { get; set; }
|
||||||
|
public string point_name { get; set; }
|
||||||
|
|
||||||
|
//public string result_value { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NiagaraTags
|
||||||
|
{
|
||||||
|
public int id { get; set; }
|
||||||
|
public string db_tags { get; set; }
|
||||||
|
public string niagara_tags { get; set; }
|
||||||
|
public string device_area_tag { 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_master_tag { get; set; }
|
||||||
|
public string device_last_name_tag { get; set; }
|
||||||
|
public string device_serial_tag { get; set; }
|
||||||
|
public string atDateTime { get; set; }
|
||||||
|
public int is_used { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NiagaraTagsForItem
|
||||||
|
{
|
||||||
|
public string device_area_tag { 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_point_name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
81
Repository/Models/quickType.cs
Normal file
81
Repository/Models/quickType.cs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
|
namespace Repository.Models
|
||||||
|
{
|
||||||
|
public partial class Welcome
|
||||||
|
{
|
||||||
|
[JsonProperty("?xml")]
|
||||||
|
public Xml Xml { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("?xml-stylesheet")]
|
||||||
|
public string XmlStylesheet { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("obj")]
|
||||||
|
public Obj Obj { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class Obj
|
||||||
|
{
|
||||||
|
[JsonProperty("@display")]
|
||||||
|
public string Display { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("@xmlns")]
|
||||||
|
public Uri Xmlns { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("@xsi:schemaLocation")]
|
||||||
|
public Uri XsiSchemaLocation { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("@xmlns:xsi")]
|
||||||
|
public Uri XmlnsXsi { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("str")]
|
||||||
|
public Str[] Str { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class Str
|
||||||
|
{
|
||||||
|
[JsonProperty("@name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("@val")]
|
||||||
|
public string Val { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("@href")]
|
||||||
|
public string Href { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class Xml
|
||||||
|
{
|
||||||
|
[JsonProperty("@version")]
|
||||||
|
public string Version { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("@encoding")]
|
||||||
|
public string Encoding { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class Welcome
|
||||||
|
{
|
||||||
|
public static Welcome FromJson(string json) => JsonConvert.DeserializeObject<Welcome>(json, Models.Converter.Settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Serialize
|
||||||
|
{
|
||||||
|
public static string ToJson(this Welcome self) => JsonConvert.SerializeObject(self, Models.Converter.Settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class Converter
|
||||||
|
{
|
||||||
|
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
||||||
|
DateParseHandling = DateParseHandling.None,
|
||||||
|
Converters =
|
||||||
|
{
|
||||||
|
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user