[前台] 修改前台api, historycontroller 使用的舊格式sql 語法
This commit is contained in:
parent
defb86dbc7
commit
df02d1593b
@ -335,7 +335,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
wheres.Add("d.deleted = 0");
|
||||
if (postDevice.SelectBuildings != null && postDevice.SelectBuildings.Count() > 0)
|
||||
{
|
||||
wheres.Add("d.building_guid in @builds");
|
||||
wheres.Add("d.building_tag in @builds");
|
||||
}
|
||||
|
||||
if (postDevice.SelectFloors != null && postDevice.SelectFloors.Count() > 0)
|
||||
@ -345,7 +345,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
|
||||
if (postDevice.SelectSub != null && postDevice.SelectSub.Count() > 0)
|
||||
{
|
||||
wheres.Add("d.sub_system_guid in @syss");
|
||||
wheres.Add("d.device_name_tag in @syss");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(postDevice.Device_name))
|
||||
@ -358,18 +358,18 @@ namespace FrontendWebApi.ApiControllers
|
||||
var sql = $@"SELECT
|
||||
a.device_guid,
|
||||
b.full_name building_name,
|
||||
c.full_name main_name,
|
||||
d.full_name sub_name,
|
||||
v1.system_key main_name,
|
||||
v2.system_key sub_name,
|
||||
d.full_name sub_name,
|
||||
a.full_name device_name,
|
||||
a.device_number
|
||||
from (SELECT *
|
||||
FROM device d
|
||||
WHERE {wheres_str}) a
|
||||
join building b on b.building_guid = a.building_guid
|
||||
join main_system c on c.main_system_guid = a.main_system_guid
|
||||
join sub_system d on d.sub_system_guid = a.sub_system_guid
|
||||
order by b.priority,c.priority,d.priority,a.priority";
|
||||
join building b on b.building_tag = a.building_tag
|
||||
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_system_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";
|
||||
|
||||
var dbDevice = await backendRepository.GetAllAsync<History_GetDevice>(sql, new { builds = postDevice.SelectBuildings, floor_guid = postDevice.SelectFloors, syss = postDevice.SelectSub, device_name = postDevice.Device_name });
|
||||
apiResult.Data = dbDevice;
|
||||
@ -404,11 +404,11 @@ namespace FrontendWebApi.ApiControllers
|
||||
var dbDevice = await backendRepository.GetAllAsync<History_PostItem>(
|
||||
@$"select c.full_name building_name,b.device_number,b.full_name device_name,a.full_name item_name,a.points,a.unit
|
||||
from device_item a
|
||||
join device b on a.sub_system_guid = b.sub_system_guid
|
||||
join building c on c.building_guid = b.building_guid
|
||||
join sub_system d on d.sub_system_guid = b.sub_system_guid
|
||||
join main_system e on e.main_system_guid = b.main_system_guid
|
||||
where a.deleted = 0 and b.deleted = 0 and d.deleted = 0 and e.deleted = 0
|
||||
join device b on a.device_system_tag = b.device_system_tag
|
||||
join building c on c.building_tag = b.building_tag
|
||||
join variable v1 on v1.system_value = b.device_system_tag and v1.deleted = 0 and v1.system_type = 'device_system_category_layer2'
|
||||
join variable v2 on v2.system_value = b.device_system_tag and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3'
|
||||
where a.deleted = 0 and b.deleted = 0 and v2.deleted = 0 and v1.deleted = 0
|
||||
and a.unit is not null and b.device_number in @Device_number
|
||||
order by c.priority,b.priority
|
||||
"
|
||||
@ -808,17 +808,17 @@ namespace FrontendWebApi.ApiControllers
|
||||
{
|
||||
#region 取得區域樓層
|
||||
var sqlBuildingFloor = $@"SELECT
|
||||
b.building_guid,
|
||||
b.building_tag,
|
||||
b.full_name AS building_name,
|
||||
b.priority,
|
||||
f.floor_guid,
|
||||
f.full_name AS floor_name,
|
||||
f.priority
|
||||
FROM building b
|
||||
JOIN floor f ON f.deleted = 0 AND f.building_guid = b.building_guid
|
||||
WHERE b.building_guid IN (
|
||||
JOIN floor f ON f.deleted = 0 AND f.building_tag = b.building_tag
|
||||
WHERE b.building_tag IN (
|
||||
SELECT
|
||||
ap.building_guid
|
||||
ap.building_tag
|
||||
FROM role_auth ra
|
||||
JOIN auth_page ap ON ra.AuthCode = ap.AuthCode
|
||||
JOIN userinfo u ON u.role_guid = ra.role_guid WHERE u.account = @Account
|
||||
@ -827,7 +827,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
|
||||
var buildingFloorRawDatas = await frontendRepository.GetAllAsync<BuildingFloorRawData>(sqlBuildingFloor, post);
|
||||
|
||||
var buildingFloorRawDatas_GroupBy_building_guid = buildingFloorRawDatas.GroupBy(x => x.building_guid).ToList();
|
||||
var buildingFloorRawDatas_GroupBy_building_guid = buildingFloorRawDatas.GroupBy(x => x.building_tag).ToList();
|
||||
|
||||
List<History_Build> history_Builds = new List<History_Build>();
|
||||
foreach (var buildingFloorRawData in buildingFloorRawDatas_GroupBy_building_guid)
|
||||
@ -846,7 +846,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
|
||||
History_Build history_Build = new History_Build()
|
||||
{
|
||||
building_guid = buildingFloorRawData.Key,
|
||||
building_tag = buildingFloorRawData.Key,
|
||||
full_name = buildingFloorRawData.First().building_name,
|
||||
history_Floors = history_Floors
|
||||
};
|
||||
@ -856,22 +856,19 @@ namespace FrontendWebApi.ApiControllers
|
||||
#endregion
|
||||
|
||||
#region 取得系統大小類
|
||||
var sqlMainSubSystem = $@"SELECT
|
||||
ms.main_system_guid,
|
||||
ms.full_name AS main_name,
|
||||
ss.sub_system_guid,
|
||||
ss.full_name AS sub_name
|
||||
FROM sub_system ss
|
||||
JOIN main_system ms ON ms.deleted = 0 AND ss.main_system_guid = ms.main_system_guid
|
||||
WHERE ss.deleted = 0
|
||||
AND ss.sub_system_guid IN (
|
||||
SELECT
|
||||
ap.ShowView
|
||||
FROM role_auth ra
|
||||
JOIN auth_page ap ON ra.AuthCode = ap.AuthCode
|
||||
JOIN userinfo u ON u.role_guid = ra.role_guid WHERE u.account = @Account
|
||||
)
|
||||
ORDER BY ms.priority, ss.priority";
|
||||
var sqlMainSubSystem = $@"select
|
||||
v1.system_value as main_system_tag, v1.system_key as main_name, v2.system_value as sub_system_tag, v2.system_key as sub_name
|
||||
from variable v2
|
||||
inner join variable v1 on v2.system_parent_id = v1.id
|
||||
where v2.deleted = 0 and
|
||||
v2.system_value in (
|
||||
select ap.ShowView
|
||||
from role_auth ra
|
||||
inner join auth_page ap on ra.AuthCode = ap.AuthCode
|
||||
inner join userinfo ui on ra.role_guid = ui.role_guid
|
||||
where ui.account = @Account
|
||||
)
|
||||
order by v1.system_priority, v2.system_priority;";
|
||||
|
||||
var mainSubSystemRawDatas = await frontendRepository.GetAllAsync<HistoryDBMainSub>(sqlMainSubSystem, post);
|
||||
|
||||
@ -956,30 +953,30 @@ namespace FrontendWebApi.ApiControllers
|
||||
var device_numbers = post.HistoryItems.Select(x => x.Device_number_point.Split(":")[0]).Distinct().ToList();
|
||||
|
||||
//依據被選擇的設備找出相對應資料
|
||||
var sqlDeviceItemInfo = $@"SELECT
|
||||
b.full_name AS building_name,
|
||||
ms.full_name AS Main_system_name,
|
||||
ss.full_name AS Sub_system_name,
|
||||
temp.device_number,
|
||||
temp.device_name,
|
||||
temp.full_name AS item_name,
|
||||
temp.points,
|
||||
temp.unit
|
||||
FROM ( SELECT
|
||||
di.*,
|
||||
d.building_guid,
|
||||
d.main_system_guid,
|
||||
-- d.sub_system_guid,
|
||||
d.device_number,
|
||||
d.full_name AS device_name,
|
||||
d.priority
|
||||
FROM device_item di
|
||||
JOIN device d ON d.deleted = 0 AND di.sub_system_guid = d.sub_system_guid
|
||||
WHERE di.deleted = 0 AND di.unit IS NOT NULL AND d.device_number IN @Device_number) temp
|
||||
JOIN building b ON b.deleted = 0 AND temp.building_guid = b.building_guid
|
||||
JOIN main_system ms ON ms.deleted = 0 AND temp.main_system_guid = ms.main_system_guid
|
||||
JOIN sub_system ss ON ss.deleted = 0 AND temp.sub_system_guid = ss.sub_system_guid
|
||||
ORDER BY b.priority, ms.priority, ss.priority, temp.priority";
|
||||
var sqlDeviceItemInfo = $@"select
|
||||
b.full_name as building_name,
|
||||
v1.system_key as Main_system_name,
|
||||
v2.system_key as Sub_system_name,
|
||||
temp.device_number,
|
||||
temp.device_name,
|
||||
temp.full_name as item_name,
|
||||
temp.points,
|
||||
temp.unit
|
||||
from (
|
||||
select
|
||||
di.*,
|
||||
d.device_building_tag,
|
||||
d.device_number,
|
||||
d.full_name as device_name,
|
||||
d.priority
|
||||
from device_item di
|
||||
inner join device d on di.device_name_tag = d.device_name_tag and d.deleted = 0
|
||||
where di.deleted = 0 and di.unit is not null and d.device_number IN @Device_number
|
||||
) temp
|
||||
inner join building b on temp.device_building_tag = b.building_tag and b.deleted = 0
|
||||
inner join variable v1 on temp.device_system_tag = v1.system_value and v1.deleted = 0 and v1.system_type = 'device_system_category_layer2'
|
||||
inner join variable v2 on temp.device_name_tag = v2.system_value and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3'
|
||||
order by b.priority, v1.system_priority, v2.system_priority, temp.priority";
|
||||
|
||||
var device_item_infos = await frontendRepository.GetAllAsync<DeviceItemInfo>(sqlDeviceItemInfo, new { Device_number = device_numbers });
|
||||
|
||||
|
@ -96,7 +96,7 @@ namespace FrontendWebApi.Models
|
||||
}
|
||||
public class BuildingFloorRawData
|
||||
{
|
||||
public string building_guid { get; set; }
|
||||
public string building_tag { get; set; }
|
||||
public string building_name { get; set; }
|
||||
public string floor_guid { get; set; }
|
||||
public string floor_name { get; set; }
|
||||
@ -110,7 +110,7 @@ namespace FrontendWebApi.Models
|
||||
|
||||
public class History_Build
|
||||
{
|
||||
public string building_guid { get; set; }
|
||||
public string building_tag { get; set; }
|
||||
public string full_name { get; set; }
|
||||
public List<History_Floor> history_Floors { get; set; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user