[後端] 修改水電表api

This commit is contained in:
dev02 2023-06-08 11:39:17 +08:00
parent 8e727303d4
commit 330b1964f2

View File

@ -75,9 +75,21 @@ namespace FrontendWebApi.ApiControllers
string sqlGroup = ""; string sqlGroup = "";
string sqlAvgRawData = ""; string sqlAvgRawData = "";
string dbDateName = startTime.Split("-")[0].ToString().PadLeft(4, '0') + startTime.Split("-")[1].ToString().PadLeft(2, '0'); string dbDateName = startTime.Split("-")[0].ToString().PadLeft(4, '0') + startTime.Split("-")[1].ToString().PadLeft(2, '0');
string buildingSql = "";
string tag_quantity = await backendRepository.GetOneAsync<string>("select system_value from variable where system_type = 'obixConfig' and system_key = 'tag_quantity' and deleted = 0");
if (tag_quantity == "5")
buildingSql = " and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag ";
else
buildingSql = " and SUBSTRING_INDEX(SUBSTRING_INDEX(device_number, '_', 2), '_', -1) = @building_tag ";
if (input.floor_tag.Count > 0) if (input.floor_tag.Count > 0)
{
if (tag_quantity == "5")
sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag "; sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag ";
else
sqlWhere = $@" and substring_index(substring_index(device_number, '_', 5), '_', -1) in @floor_tag ";
}
if (input.tableType == "year") if (input.tableType == "year")
{ {
@ -104,7 +116,7 @@ namespace FrontendWebApi.ApiControllers
( (
select device_number select device_number
from {table} from {table}
where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' {buildingSql}
{sqlWhere} {sqlWhere}
group by device_number group by device_number
) dn ) dn
@ -113,7 +125,7 @@ namespace FrontendWebApi.ApiControllers
left join ( left join (
select device_number, {sqlAvgRawData} select device_number, {sqlAvgRawData}
from {table} from {table}
where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' {buildingSql}
{sqlWhere} {sqlGroup} {sqlWhere} {sqlGroup}
) aemm on aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} and aemm.device_number = fd.device_number ) aemm on aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} and aemm.device_number = fd.device_number
order by fd.device_number, fd.date"; order by fd.device_number, fd.date";