[WebApi]歷史資料2調整成隨棟別變動
[Backend]同步邏輯調整 [BGService]歸檔調整過濾項及新設備預設最後歸檔日
This commit is contained in:
parent
57ea689560
commit
b86a6ff42f
@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
using Repository.BackendRepository.Interface;
|
using Repository.BackendRepository.Interface;
|
||||||
|
using Repository.Extension;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -52,6 +52,7 @@ namespace Backend.Controllers
|
|||||||
WHERE A.deleted = 0
|
WHERE A.deleted = 0
|
||||||
ORDER BY A.priority ASC, A.created_at DESC";
|
ORDER BY A.priority ASC, A.created_at DESC";
|
||||||
buildInfo = await backendRepository.GetAllAsync<BuildInfo>(sqlString);
|
buildInfo = await backendRepository.GetAllAsync<BuildInfo>(sqlString);
|
||||||
|
buildInfo.ForEach(x => x.building_tag = x.building_tag.ConvertNormal()); // 字串轉換
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Data = buildInfo;
|
apiResult.Data = buildInfo;
|
||||||
@ -75,7 +76,7 @@ namespace Backend.Controllers
|
|||||||
public async Task<ApiResult<string>> SaveBuildInfo([FromForm] BuildInfo post)
|
public async Task<ApiResult<string>> SaveBuildInfo([FromForm] BuildInfo post)
|
||||||
{
|
{
|
||||||
ApiResult<string> apiResult = new ApiResult<string>();
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
|
post.building_tag = post.building_tag.ConvertN4(); // 字串轉換
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//判斷監控主機IP是否重複
|
//判斷監控主機IP是否重複
|
||||||
@ -317,6 +318,7 @@ namespace Backend.Controllers
|
|||||||
public async Task<ApiResult<string>> DeleteOneBuild(string tag)
|
public async Task<ApiResult<string>> DeleteOneBuild(string tag)
|
||||||
{
|
{
|
||||||
var apiResult = new ApiResult<string>();
|
var apiResult = new ApiResult<string>();
|
||||||
|
tag = tag.ConvertN4();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sWhere = @$"deleted = @Deleted AND building_tag = @Tag";
|
string sWhere = @$"deleted = @Deleted AND building_tag = @Tag";
|
||||||
|
@ -13,6 +13,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using NPOI.SS.Formula.Functions;
|
using NPOI.SS.Formula.Functions;
|
||||||
using Repository.Helper;
|
using Repository.Helper;
|
||||||
using Microsoft.AspNetCore.Routing.Matching;
|
using Microsoft.AspNetCore.Routing.Matching;
|
||||||
|
using Repository.Extension;
|
||||||
|
|
||||||
namespace Backend.Controllers
|
namespace Backend.Controllers
|
||||||
{
|
{
|
||||||
@ -170,6 +171,7 @@ namespace Backend.Controllers
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
var buildings = backendRepository.GetAllAsync<string>("select building_tag from building where deleted = 0").Result;
|
var buildings = backendRepository.GetAllAsync<string>("select building_tag from building where deleted = 0").Result;
|
||||||
|
ds.ForEach(x => x.device_building_tag = x.device_building_tag.ConvertN4());
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Data = ds.Where(x => buildings.Contains(x.device_building_tag)).ToList();
|
apiResult.Data = ds.Where(x => buildings.Contains(x.device_building_tag)).ToList();
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ namespace Backend.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 前次成功日期;下次重新歸檔日期
|
/// 前次成功日期;下次重新歸檔日期
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public System.DateTime archive_lastDate { get; set; }
|
public System.DateTime? archive_lastDate { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 前次執行日期
|
/// 前次執行日期
|
||||||
@ -279,7 +279,7 @@ namespace Backend.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 前次成功日期;下次重新歸檔日期
|
/// 前次成功日期;下次重新歸檔日期
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public System.DateTime archive_lastDate { get; set; }
|
public System.DateTime archive_lastDate { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 前次執行日期
|
/// 前次執行日期
|
||||||
|
@ -81,8 +81,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
JObject archiveJsonResult = new JObject();
|
JObject archiveJsonResult = new JObject();
|
||||||
#endregion
|
#endregion
|
||||||
#region 找出所有電錶設備 與前次成功日期
|
#region 找出所有電錶設備 與前次成功日期
|
||||||
var sWhere_E4 = @$"device_name_tag = '{electricMeterGuid}' and deleted = 0 ";
|
var sWhere_E4 = @$"device_name_tag = '{electricMeterGuid}' and deleted = 0 and is_link = 1";
|
||||||
var sWhere_W1 = @$"device_name_tag = '{waterMeterGuid}' and deleted = 0 ";
|
var sWhere_W1 = @$"device_name_tag = '{waterMeterGuid}' and deleted = 0 and is_link = 1";
|
||||||
var electricMeters = await backgroundServiceRepository.GetAllAsync<Device>("device", sWhere_E4);
|
var electricMeters = await backgroundServiceRepository.GetAllAsync<Device>("device", sWhere_E4);
|
||||||
var waterMeters = await backgroundServiceRepository.GetAllAsync<Device>("device", sWhere_W1);
|
var waterMeters = await backgroundServiceRepository.GetAllAsync<Device>("device", sWhere_W1);
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
#endregion 找出所有電錶設備
|
#endregion 找出所有電錶設備
|
||||||
|
|
||||||
#region 找出所有電錶系統的點位
|
#region 找出所有電錶系統的點位
|
||||||
var sPointWhere = "is_needArchive = 1 and deleted = 0 AND device_name_tag = @sub_system_guid";
|
var sPointWhere = "is_needArchive = 1 and deleted = 0 and is_link = 1 AND device_name_tag = @sub_system_guid";
|
||||||
var electricPoints = await backgroundServiceRepository.GetAllAsync<Device_item>("device_item", sPointWhere, new { sub_system_guid = electricMeterGuid });
|
var electricPoints = await backgroundServiceRepository.GetAllAsync<Device_item>("device_item", sPointWhere, new { sub_system_guid = electricMeterGuid });
|
||||||
var waterPoints = await backgroundServiceRepository.GetAllAsync<Device_item>("device_item", sPointWhere, new { sub_system_guid = waterMeterGuid });
|
var waterPoints = await backgroundServiceRepository.GetAllAsync<Device_item>("device_item", sPointWhere, new { sub_system_guid = waterMeterGuid });
|
||||||
#endregion 找出所有電錶系統的點位
|
#endregion 找出所有電錶系統的點位
|
||||||
@ -115,7 +115,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
deviceNumberPoint.DeviceNumber = electricMeter.Device_number;
|
deviceNumberPoint.DeviceNumber = electricMeter.Device_number;
|
||||||
deviceNumberPoint.Point = point.points;
|
deviceNumberPoint.Point = point.points;
|
||||||
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", electricMeter.Device_number, point.points);
|
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", electricMeter.Device_number, point.points);
|
||||||
deviceNumberPoint.archive_lastDate = electricMeter.archive_lastDate;
|
deviceNumberPoint.archive_lastDate = electricMeter.archive_lastDate ?? DateTime.Now.AddDays(-1);
|
||||||
electricDeviceNumberPoints.Add(deviceNumberPoint);
|
electricDeviceNumberPoints.Add(deviceNumberPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
deviceNumberPoint.DeviceNumber = waterMeter.Device_number;
|
deviceNumberPoint.DeviceNumber = waterMeter.Device_number;
|
||||||
deviceNumberPoint.Point = point.points;
|
deviceNumberPoint.Point = point.points;
|
||||||
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", waterMeter.Device_number, point.points);
|
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", waterMeter.Device_number, point.points);
|
||||||
deviceNumberPoint.archive_lastDate = waterMeter.archive_lastDate;
|
deviceNumberPoint.archive_lastDate = waterMeter.archive_lastDate ?? DateTime.Now.AddDays(-1);
|
||||||
waterDeviceNumberPoints.Add(deviceNumberPoint);
|
waterDeviceNumberPoints.Add(deviceNumberPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1129,7 +1129,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
from (SELECT *
|
from (SELECT *
|
||||||
FROM device d
|
FROM device d
|
||||||
WHERE {wheres_str}) a
|
WHERE {wheres_str}) a
|
||||||
join building b on b.building_tag = a.device_building_tag
|
join building b on b.building_tag = a.device_building_tag and b.deleted = 0
|
||||||
join variable v1 on v1.system_value = a.device_system_tag and v1.deleted = 0 and v1.system_type = 'device_system_category_layer2'
|
join variable v1 on v1.system_value = a.device_system_tag and v1.deleted = 0 and v1.system_type = 'device_system_category_layer2'
|
||||||
join variable v2 on v2.system_value = a.device_name_tag and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3'
|
join variable v2 on v2.system_value = a.device_name_tag and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3'
|
||||||
order by b.priority,v1.system_priority,v2.system_priority,a.priority,a.device_serial_tag";
|
order by b.priority,v1.system_priority,v2.system_priority,a.priority,a.device_serial_tag";
|
||||||
|
@ -655,18 +655,10 @@ SET FOREIGN_KEY_CHECKS = 1;";
|
|||||||
and d.device_name_tag = m.device_name_tag
|
and d.device_name_tag = m.device_name_tag
|
||||||
and d.points = m.device_point_name
|
and d.points = m.device_point_name
|
||||||
and d.full_name = m.full_name
|
and d.full_name = m.full_name
|
||||||
SET d.is_link = case when device_point_name is null then 0 else 1 end;
|
and m.device_building_tag collate utf8mb4_0900_ai_ci = d.device_building_tag
|
||||||
|
SET d.is_link = case when device_point_name is null then 0 else 1 end,
|
||||||
|
d.parent_path = m.parent_path;
|
||||||
|
|
||||||
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
|
|
||||||
and d.full_name = m.full_name
|
|
||||||
and d.is_show_history = m.is_history
|
|
||||||
SET d.is_show_history = case when device_point_name is null then 0 else 1 end
|
|
||||||
where (m.is_history = 1 or d.is_show_history);
|
|
||||||
");
|
");
|
||||||
|
|
||||||
await conn.ExecuteAsync(sb.ToString());
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
@ -984,9 +976,20 @@ SET FOREIGN_KEY_CHECKS = 1;";
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
//先全部關閉
|
//先全部關閉
|
||||||
//sb.Append("update device_item set is_show_history=0;");
|
//sb.Append("update device_item set is_show_history=0;");
|
||||||
sb.Append("update device_item set is_show_history = 0 " +
|
sb.Append(@"UPDATE device_item d
|
||||||
"WHERE(device_system_tag, device_name_tag, points, full_name, is_show_history) NOT IN " +
|
SET is_show_history = CASE
|
||||||
"(select distinct device_system_tag, device_name_tag, device_point_name, full_name, is_history From import_niagara_item where is_history = 1);");
|
WHEN EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM import_niagara_item m
|
||||||
|
WHERE m.device_system_tag = d.device_system_tag
|
||||||
|
AND m.device_name_tag = d.device_name_tag
|
||||||
|
AND m.device_point_name = d.points
|
||||||
|
AND m.full_name = d.full_name
|
||||||
|
AND m.is_history = 1
|
||||||
|
) THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END;
|
||||||
|
");
|
||||||
await conn.ExecuteAsync(sb.ToString());
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
Loading…
Reference in New Issue
Block a user