[後台] 修改niagara同步流程 改用東別去決定, 以及增加時長在資料庫上
[前台] 修改realtime combination CRUD
This commit is contained in:
parent
06cc65ff56
commit
415902eb44
@ -51,19 +51,23 @@ namespace Backend.Controllers
|
|||||||
var obixApiConfig = new Backend.Models.ObixApiConfig();
|
var obixApiConfig = new Backend.Models.ObixApiConfig();
|
||||||
EDFunction ed = new EDFunction();
|
EDFunction ed = new EDFunction();
|
||||||
obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault() + "obix/config/Program/ObixQuery/query/";
|
obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault() + "obix/config/Program/ObixQuery/query/";
|
||||||
obixApiConfig.UrlSlot =variableObix.Where(x => x.Name == "url_slot").Select(x => x.Value).FirstOrDefault();
|
//obixApiConfig.UrlSlot =variableObix.Where(x => x.Name == "url_slot").Select(x => x.Value).FirstOrDefault();
|
||||||
obixApiConfig.TagQuantity = variableObix.Where(x => x.Name == "tag_quantity").Select(x => x.Value).FirstOrDefault();
|
obixApiConfig.TagQuantity = variableObix.Where(x => x.Name == "tag_quantity").Select(x => x.Value).FirstOrDefault();
|
||||||
obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
|
obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
|
||||||
obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
|
obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
|
||||||
|
|
||||||
List<Device_value> ds;
|
var ds = new List<Device_value>();
|
||||||
|
|
||||||
string top100 = "";//" top 100 ";
|
string top100 = "";//" top 100 ";
|
||||||
webRequestService svc = new webRequestService();
|
webRequestService svc = new webRequestService();
|
||||||
string bql = obixApiConfig.UrlSlot + "bql:select " + top100 + " * from baja:Folder ";
|
var urlSlots = backendRepository.GetAllAsync<string>("select obixSlot from building where deleted = 0").Result;
|
||||||
//ds = svc.obixQuery("http://192.168.0.136:8080/obix/config/Arena/Program/ObixQuery/query/", bql);
|
foreach(var us in urlSlots)
|
||||||
//ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql);
|
{
|
||||||
ds = svc.obixQuery(obixApiConfig.ApiBase, bql, obixApiConfig.TagQuantity, obixApiConfig.UserName, obixApiConfig.Password);//三菱
|
string bql = us + "bql:select " + top100 + " * from baja:Folder ";
|
||||||
|
//ds = svc.obixQuery("http://192.168.0.136:8080/obix/config/Arena/Program/ObixQuery/query/", bql);
|
||||||
|
//ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql);
|
||||||
|
ds.AddRange(svc.obixQuery(obixApiConfig.ApiBase, bql, obixApiConfig.TagQuantity, obixApiConfig.UserName, obixApiConfig.Password));//三菱
|
||||||
|
}
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Data = ds;
|
apiResult.Data = ds;
|
||||||
@ -93,14 +97,17 @@ namespace Backend.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string ss = ds.Where(x => x.tag_name != "").FirstOrDefault().tag_name;
|
string ss = ds.Where(x => x.tag_name != "").FirstOrDefault().tag_name;
|
||||||
var building = "";
|
var data = ds.Where(x => x.tag_name != "");
|
||||||
|
List<string> building = null;
|
||||||
if (tag_quantity == "5")
|
if (tag_quantity == "5")
|
||||||
{
|
{
|
||||||
building = ss.Split("_")[0];
|
//building.Add(ss.Split("_")[0]);
|
||||||
|
building = data.GroupBy(x => x.tag_name.Split("_")[0]).Select(x => x.Key).ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
building = ss.Split("_")[1];
|
//building.Add(ss.Split("_")[1]);
|
||||||
|
building = data.GroupBy(x => x.tag_name.Split("_")[1]).Select(x => x.Key).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
string LightSwitchLevel = await niagaraDataSynchronizeRepository.getLightSwitchLevel(); //獲取照明開關 是否在 device or device_node
|
string LightSwitchLevel = await niagaraDataSynchronizeRepository.getLightSwitchLevel(); //獲取照明開關 是否在 device or device_node
|
||||||
@ -135,7 +142,7 @@ namespace Backend.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<ImpNiaItem> ds;
|
var ds = new List<ImpNiaItem>();
|
||||||
|
|
||||||
webRequestService svc = new webRequestService();
|
webRequestService svc = new webRequestService();
|
||||||
|
|
||||||
@ -146,12 +153,19 @@ namespace Backend.Controllers
|
|||||||
obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault();
|
obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault();
|
||||||
obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
|
obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
|
||||||
obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
|
obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
|
||||||
obixApiConfig.UrlSlot = variableObix.Where(x => x.Name == "url_slot").Select(x => x.Value).FirstOrDefault();
|
//obixApiConfig.UrlSlot = variableObix.Where(x => x.Name == "url_slot").Select(x => x.Value).FirstOrDefault();
|
||||||
ds = svc.obixHisQuery(obixApiConfig.ApiBase + "obix/config/Program/ObixQuery/query/", obixApiConfig.ApiBase + "obix/histories",obixApiConfig.UrlSlot, obixApiConfig.UserName,
|
|
||||||
obixApiConfig.Password);
|
|
||||||
|
|
||||||
|
var urlSlots = backendRepository.GetAllAsync<string>("select obixSlot from building where deleted = 0").Result;
|
||||||
|
foreach(var us in urlSlots)
|
||||||
|
{
|
||||||
|
var data = svc.obixHisQuery(obixApiConfig.ApiBase + "obix/config/Program/ObixQuery/query/", obixApiConfig.ApiBase + "obix/histories", us,
|
||||||
|
obixApiConfig.UserName, obixApiConfig.Password);
|
||||||
|
ds.AddRange(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
var buildings = backendRepository.GetAllAsync<string>("select building_tag from building where deleted = 0").Result;
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Data = ds.Where(x => x.device_building_tag == building.building).ToList(); ;
|
apiResult.Data = ds.Where(x => buildings.Contains(x.device_building_tag)).ToList();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -180,7 +194,7 @@ namespace Backend.Controllers
|
|||||||
//string ss = ds.Where(x => x.tag_name != "").FirstOrDefault().tag_name;
|
//string ss = ds.Where(x => x.tag_name != "").FirstOrDefault().tag_name;
|
||||||
//var building = ss.Split("_")[0];
|
//var building = ss.Split("_")[0];
|
||||||
|
|
||||||
var building = ds.FirstOrDefault().device_building_tag;
|
var building = ds.GroupBy(x => x.device_building_tag).Select(x => x.Key).ToList();
|
||||||
await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building); // insert 暫存table import_niagara_item
|
await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building); // insert 暫存table import_niagara_item
|
||||||
await niagaraDataSynchronizeRepository.DeviceItemComparison(); //insert device_item
|
await niagaraDataSynchronizeRepository.DeviceItemComparison(); //insert device_item
|
||||||
await niagaraDataSynchronizeRepository.CheckItemDiffFullNameAndCover(); // update device_item.fullname
|
await niagaraDataSynchronizeRepository.CheckItemDiffFullNameAndCover(); // update device_item.fullname
|
||||||
|
@ -262,11 +262,11 @@
|
|||||||
maxlength: 50,
|
maxlength: 50,
|
||||||
filterspace: true
|
filterspace: true
|
||||||
},
|
},
|
||||||
build_file_3d_modal: {
|
//build_file_3d_modal: {
|
||||||
required: true, extension: "nwc|nwd"
|
// required: true, extension: "nwc|nwd"
|
||||||
}
|
//}
|
||||||
},
|
},
|
||||||
messages: { build_file_3d_modal: "File must be nwc, nwd" }
|
//messages: { build_file_3d_modal: "File must be nwc, nwd" }
|
||||||
});
|
});
|
||||||
|
|
||||||
//#region 儲存區域基本資料
|
//#region 儲存區域基本資料
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
"Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201
|
"Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201
|
||||||
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
|
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
|
||||||
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
||||||
"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
|
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
|
||||||
//"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
|
"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
|
||||||
//"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel
|
//"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel
|
||||||
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
|
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
|
||||||
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
|
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
|
||||||
|
@ -445,29 +445,29 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
{
|
{
|
||||||
var sql = $@"
|
var sql = $@"
|
||||||
SELECT
|
SELECT
|
||||||
rc.combination_guid,
|
rc.combination_guid,
|
||||||
rc.full_name AS combination_full_name,
|
rc.full_name AS combination_full_name,
|
||||||
rcd.device_guid,
|
rcd.device_guid,
|
||||||
d.device_number,
|
d.device_number,
|
||||||
d.full_name AS Device_full_name,
|
d.full_name AS Device_full_name,
|
||||||
b.full_name AS Building_full_name,
|
b.full_name AS Building_full_name,
|
||||||
ms.full_name AS Main_system_full_name,
|
v1.system_key AS Main_system_full_name,
|
||||||
ss.full_name AS Sub_system_full_name
|
v2.system_key AS Sub_system_full_name
|
||||||
FROM realtime_combination_detail rcd
|
FROM realtime_combination_detail rcd
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
(SELECT
|
(SELECT
|
||||||
rc.*
|
rc.*
|
||||||
FROM realtime_combination rc
|
FROM realtime_combination rc
|
||||||
WHERE building_guid = @building_guid
|
WHERE building_tag = @building_tag
|
||||||
AND userinfo_guid = @userinfo_guid
|
AND userinfo_guid = @userinfo_guid
|
||||||
) rc ON rcd.combination_guid = rc.combination_guid
|
) rc ON rcd.combination_guid = rc.combination_guid
|
||||||
JOIN device d ON d.deleted = 0 AND d.device_guid = rcd.device_guid
|
JOIN device d ON d.deleted = 0 AND d.device_guid = rcd.device_guid
|
||||||
JOIN building b ON b.deleted = 0 AND b.building_guid = d.building_guid
|
JOIN building b ON b.deleted = 0 AND b.building_tag = d.device_building_tag
|
||||||
JOIN main_system ms ON ms.deleted = 0 AND ms.main_system_guid = d.main_system_guid
|
JOIN variable v1 ON v1.deleted = 0 AND v1.system_value = d.device_system_tag and v1.system_type = 'device_system_category_layer2'
|
||||||
JOIN sub_system ss ON ss.deleted = 0 AND ss.sub_system_guid = d.sub_system_guid
|
JOIN variable v2 ON v2.deleted = 0 AND v2.system_value = d.device_name_tag and v2.system_type = 'device_system_category_layer3'
|
||||||
WHERE rc.deleted = 0";
|
WHERE rc.deleted = 0";
|
||||||
|
|
||||||
var rawDatas = await frontendRepository.GetAllAsync<RealTimeCombinationRawData>(sql, new { building_guid = post.building_guid, userinfo_guid = myUser.userinfo_guid });
|
var rawDatas = await frontendRepository.GetAllAsync<RealTimeCombinationRawData>(sql, new { building_tag = post.building_tag, userinfo_guid = myUser.userinfo_guid });
|
||||||
|
|
||||||
var rawDatas_groups = rawDatas.GroupBy(x => x.Combination_guid).ToList();
|
var rawDatas_groups = rawDatas.GroupBy(x => x.Combination_guid).ToList();
|
||||||
|
|
||||||
@ -536,7 +536,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
combination = new Dictionary<string, object>()
|
combination = new Dictionary<string, object>()
|
||||||
{
|
{
|
||||||
{ "@combination_guid", guid},
|
{ "@combination_guid", guid},
|
||||||
{ "@building_guid", post.Building_guid},
|
{ "@building_tag", post.Building_tag},
|
||||||
{ "@userinfo_guid", myUser.userinfo_guid},
|
{ "@userinfo_guid", myUser.userinfo_guid},
|
||||||
{ "@full_name", post.Full_name},
|
{ "@full_name", post.Full_name},
|
||||||
{ "@created_by", myUser.userinfo_guid}
|
{ "@created_by", myUser.userinfo_guid}
|
||||||
|
@ -48,37 +48,37 @@ 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();
|
||||||
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(),
|
||||||
email = User.Claims.Where(a => a.Type == "email").Select(e => e.Value).FirstOrDefault(),
|
// email = User.Claims.Where(a => a.Type == "email").Select(e => e.Value).FirstOrDefault(),
|
||||||
full_name = User.Claims.Where(a => a.Type == "full_name").Select(e => e.Value).FirstOrDefault(),
|
// full_name = User.Claims.Where(a => a.Type == "full_name").Select(e => e.Value).FirstOrDefault(),
|
||||||
exp = User.Claims.Where(a => a.Type == "exp").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
|
// exp = User.Claims.Where(a => a.Type == "exp").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
|
||||||
nbf = User.Claims.Where(a => a.Type == "nbf").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
|
// nbf = User.Claims.Where(a => a.Type == "nbf").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
|
||||||
userinfo_guid = User.Claims.Where(a => a.Type == "userinfo_guid").Select(e => e.Value).FirstOrDefault(),
|
// userinfo_guid = User.Claims.Where(a => a.Type == "userinfo_guid").Select(e => e.Value).FirstOrDefault(),
|
||||||
};
|
//};
|
||||||
|
|
||||||
if (myUser.exp == 0)
|
//if (myUser.exp == 0)
|
||||||
{
|
//{
|
||||||
jwt_str = "Jwt Token不合法";
|
// jwt_str = "Jwt Token不合法";
|
||||||
jwtlife = false;
|
// jwtlife = false;
|
||||||
filterContext.Result = new JsonResult(new { HttpStatusCode.Unauthorized });
|
// filterContext.Result = new JsonResult(new { HttpStatusCode.Unauthorized });
|
||||||
}
|
//}
|
||||||
else
|
//else
|
||||||
{
|
//{
|
||||||
if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
|
// if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
|
||||||
{
|
// {
|
||||||
jwtlife = true;
|
// jwtlife = true;
|
||||||
JwtLogin jwtLoing = new JwtLogin()
|
// JwtLogin jwtLoing = new JwtLogin()
|
||||||
{
|
// {
|
||||||
account = myUser.account,
|
// account = myUser.account,
|
||||||
email = myUser.email,
|
// email = myUser.email,
|
||||||
full_name = myUser.full_name,
|
// full_name = myUser.full_name,
|
||||||
userinfo_guid = myUser.userinfo_guid
|
// userinfo_guid = myUser.userinfo_guid
|
||||||
};
|
// };
|
||||||
jwt_str = jwt.GenerateToken(jwtLoing).token;
|
// jwt_str = jwt.GenerateToken(jwtLoing).token;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
//if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
|
//if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
|
||||||
//{
|
//{
|
||||||
// jwtlife = true;
|
// jwtlife = true;
|
||||||
|
@ -195,7 +195,7 @@ namespace FrontendWebApi.Models
|
|||||||
public class PostRealTimeCombination
|
public class PostRealTimeCombination
|
||||||
{
|
{
|
||||||
public string account { get; set; }
|
public string account { get; set; }
|
||||||
public string building_guid { get; set; }
|
public string building_tag { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RealTimeCombinationRawData
|
public class RealTimeCombinationRawData
|
||||||
@ -238,7 +238,7 @@ namespace FrontendWebApi.Models
|
|||||||
|
|
||||||
public class PostSaveRealTimeCombination
|
public class PostSaveRealTimeCombination
|
||||||
{
|
{
|
||||||
public string Building_guid { get; set; }
|
public string Building_tag { get; set; }
|
||||||
public string Combination_guid { get; set; }
|
public string Combination_guid { get; set; }
|
||||||
public byte Save_type { get; set; }
|
public byte Save_type { get; set; }
|
||||||
public string Full_name { get; set; }
|
public string Full_name { get; set; }
|
||||||
|
@ -27,7 +27,7 @@ namespace Repository.BackendRepository.Implement
|
|||||||
/// <param name="ds"></param>
|
/// <param name="ds"></param>
|
||||||
/// <param name="building"></param>
|
/// <param name="building"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task InsertNiagaraTagList(List<Device_value> ds, string building, string tag_quantity)
|
public async Task InsertNiagaraTagList(List<Device_value> ds, List<string> building, string tag_quantity)
|
||||||
{
|
{
|
||||||
using (IDbConnection conn = GetDbConnection())
|
using (IDbConnection conn = GetDbConnection())
|
||||||
{
|
{
|
||||||
@ -36,25 +36,28 @@ namespace Repository.BackendRepository.Implement
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = @"CREATE TABLE IF NOT EXISTS `import_niagara_tag` (
|
foreach(var b in building)
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
{
|
||||||
`db_tags` varchar(50) DEFAULT NULL,
|
string sql = @"CREATE TABLE IF NOT EXISTS `import_niagara_tag` (
|
||||||
`niagara_tags` varchar(50) DEFAULT NULL,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`device_area_tag` varchar(50) DEFAULT NULL,
|
`db_tags` varchar(50) DEFAULT NULL,
|
||||||
`device_building_tag` varchar(50) DEFAULT NULL,
|
`niagara_tags` varchar(50) DEFAULT NULL,
|
||||||
`device_system_tag` varchar(50) DEFAULT NULL,
|
`device_area_tag` varchar(50) DEFAULT NULL,
|
||||||
`device_name_tag` varchar(50) DEFAULT NULL,
|
`device_building_tag` varchar(50) DEFAULT NULL,
|
||||||
`device_floor_tag` varchar(50) DEFAULT NULL,
|
`device_system_tag` varchar(50) DEFAULT NULL,
|
||||||
`device_master_tag` varchar(50) DEFAULT NULL,
|
`device_name_tag` varchar(50) DEFAULT NULL,
|
||||||
`device_last_name_tag` varchar(50) DEFAULT NULL,
|
`device_floor_tag` varchar(50) DEFAULT NULL,
|
||||||
`device_serial_tag` varchar(50) DEFAULT NULL,
|
`device_master_tag` varchar(50) DEFAULT NULL,
|
||||||
`atDateTime` datetime(1) DEFAULT NULL,
|
`device_last_name_tag` varchar(50) DEFAULT NULL,
|
||||||
`is_used` smallint(1) DEFAULT 0,
|
`device_serial_tag` varchar(50) DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`)
|
`atDateTime` datetime(1) DEFAULT NULL,
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
|
`is_used` smallint(1) DEFAULT 0,
|
||||||
await conn.ExecuteAsync(sql);
|
PRIMARY KEY (`id`)
|
||||||
sql = "delete from import_niagara_tag where device_building_tag = '" + building + "'";
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
|
||||||
await conn.ExecuteAsync(sql);
|
await conn.ExecuteAsync(sql);
|
||||||
|
sql = "delete from import_niagara_tag where device_building_tag = '" + b + "'";
|
||||||
|
await conn.ExecuteAsync(sql);
|
||||||
|
}
|
||||||
|
|
||||||
//N4資料groupBy後放入import_niagara_tag資料表
|
//N4資料groupBy後放入import_niagara_tag資料表
|
||||||
var ds2 = ds.GroupBy(x => new
|
var ds2 = ds.GroupBy(x => new
|
||||||
@ -170,7 +173,7 @@ namespace Repository.BackendRepository.Implement
|
|||||||
/// <param name="building"></param>
|
/// <param name="building"></param>
|
||||||
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task InsertItemFromNiagara(List<ImpNiaItem> ds, string building)
|
public async Task InsertItemFromNiagara(List<ImpNiaItem> ds, List<string> building)
|
||||||
{
|
{
|
||||||
using (IDbConnection conn = GetDbConnection())
|
using (IDbConnection conn = GetDbConnection())
|
||||||
{
|
{
|
||||||
@ -180,21 +183,24 @@ namespace Repository.BackendRepository.Implement
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
#region 刪除 import_niagara_item資料表中選取的棟別
|
#region 刪除 import_niagara_item資料表中選取的棟別
|
||||||
string sql = @"CREATE TABLE IF NOT EXISTS `import_niagara_item` (
|
foreach(var b in building)
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
{
|
||||||
`device_area_tag` varchar(50) DEFAULT NULL,
|
string sql = @"CREATE TABLE IF NOT EXISTS `import_niagara_item` (
|
||||||
`device_building_tag` varchar(50) DEFAULT NULL,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`device_system_tag` varchar(50) DEFAULT NULL,
|
`device_area_tag` varchar(50) DEFAULT NULL,
|
||||||
`device_name_tag` varchar(50) DEFAULT NULL,
|
`device_building_tag` varchar(50) DEFAULT NULL,
|
||||||
`device_point_name` varchar(50) DEFAULT NULL,
|
`device_system_tag` varchar(50) DEFAULT NULL,
|
||||||
`check_status` varchar(50) DEFAULT NULL,
|
`device_name_tag` varchar(50) DEFAULT NULL,
|
||||||
`parent_path` varchar(50) DEFAULT NULL,
|
`device_point_name` varchar(50) DEFAULT NULL,
|
||||||
`full_name` varchar(50) DEFAULT NULL,
|
`check_status` varchar(50) DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`)
|
`parent_path` varchar(50) DEFAULT NULL,
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
|
`full_name` varchar(50) DEFAULT NULL,
|
||||||
await conn.ExecuteAsync(sql);
|
PRIMARY KEY (`id`)
|
||||||
sql = "delete from import_niagara_item where device_building_tag = '" + building + "'";
|
) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
|
||||||
await conn.ExecuteAsync(sql);
|
await conn.ExecuteAsync(sql);
|
||||||
|
sql = "delete from import_niagara_item where device_building_tag = '" + b + "'";
|
||||||
|
await conn.ExecuteAsync(sql);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
ds = ds.GroupBy(x => new {
|
ds = ds.GroupBy(x => new {
|
||||||
device_area_tag = x.device_area_tag,
|
device_area_tag = x.device_area_tag,
|
||||||
@ -270,7 +276,7 @@ namespace Repository.BackendRepository.Implement
|
|||||||
using (IDbConnection conn = GetDbConnection())
|
using (IDbConnection conn = GetDbConnection())
|
||||||
{
|
{
|
||||||
conn.Open();
|
conn.Open();
|
||||||
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled, new TimeSpan(0, 0, 200)))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -398,19 +404,21 @@ namespace Repository.BackendRepository.Implement
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//device有,niagara沒有,is_link 更新成 0
|
//device有,niagara沒有,is_link 更新成 0
|
||||||
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
|
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
|
||||||
UPDATE device d LEFT JOIN import_niagara_tag m ON d.device_number = m.niagara_tags
|
UPDATE device d
|
||||||
SET d.is_link = 0
|
SET d.is_link = 0
|
||||||
WHERE m.niagara_tags IS NULL;");
|
WHERE d.is_link = 1 and not exists (select niagara_tags from import_niagara_tag where niagara_tags = d.device_number);");
|
||||||
await conn.ExecuteAsync(sb.ToString());
|
await conn.ExecuteAsync(sb.ToString(), commandTimeout: 100);
|
||||||
|
|
||||||
|
sb.Clear();
|
||||||
|
|
||||||
// device_node 有, niagara沒有, is_link 更新成 0
|
// device_node 有, niagara沒有, is_link 更新成 0
|
||||||
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
|
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
|
||||||
UPDATE device_node d LEFT JOIN import_niagara_tag m ON d.device_number = m.niagara_tags
|
UPDATE device_node d
|
||||||
SET d.is_link = 0
|
SET d.is_link = 0
|
||||||
WHERE m.niagara_tags IS NULL;");
|
WHERE d.is_link = 1 and not exists (select niagara_tags from import_niagara_tag where niagara_tags = d.device_number);");
|
||||||
await conn.ExecuteAsync(sb.ToString());
|
await conn.ExecuteAsync(sb.ToString(), commandTimeout: 100);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -738,7 +746,7 @@ namespace Repository.BackendRepository.Implement
|
|||||||
using (IDbConnection conn = GetDbConnection())
|
using (IDbConnection conn = GetDbConnection())
|
||||||
{
|
{
|
||||||
conn.Open();
|
conn.Open();
|
||||||
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled, new TimeSpan (0, 0, 200)))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -746,7 +754,7 @@ namespace Repository.BackendRepository.Implement
|
|||||||
sb.Append("update device d inner JOIN import_niagara_tag m ON m.niagara_tags = d.device_number " +
|
sb.Append("update device d inner JOIN import_niagara_tag m ON m.niagara_tags = d.device_number " +
|
||||||
"set d.full_name=m.device_full_name " +
|
"set d.full_name=m.device_full_name " +
|
||||||
"where m.device_full_name<>d.full_name;");
|
"where m.device_full_name<>d.full_name;");
|
||||||
await conn.ExecuteAsync(sb.ToString());
|
await conn.ExecuteAsync(sb.ToString(), commandTimeout: 200);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ namespace Repository.BackendRepository.Interface
|
|||||||
/// <param name="ds"></param>
|
/// <param name="ds"></param>
|
||||||
/// <param name="building"></param>
|
/// <param name="building"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task InsertNiagaraTagList(List<Device_value> ds, string building, string tag_quantity);
|
Task InsertNiagaraTagList(List<Device_value> ds, List<string> building, string tag_quantity);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -27,7 +27,7 @@ namespace Repository.BackendRepository.Interface
|
|||||||
/// <param name="ds"></param>
|
/// <param name="ds"></param>
|
||||||
/// <param name="building"></param>
|
/// <param name="building"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task InsertItemFromNiagara(List<ImpNiaItem> ds, string building);
|
Task InsertItemFromNiagara(List<ImpNiaItem> ds, List<string> building);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 比對 device
|
/// 比對 device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user