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