[後端] 修改後去水電表列表問題

This commit is contained in:
dev02 2023-05-12 13:02:24 +08:00
parent 938a7cdb7e
commit 7dc2e0b5ae
2 changed files with 13 additions and 8 deletions

View File

@ -64,8 +64,8 @@ namespace FrontendWebApi.ApiControllers
: null; : null;
string sqlWhere = ""; string sqlWhere = "";
if (input.floor_tag.Count > 0) if (input.floor_tag.Count > 0)
sqlWhere = $@" and substring_index(device_number, '_', 3) in @floor_tag"; sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag";
var table = "archive_electric_meter_" + input.tableType; var table = input.tableType == "year" ? "archive_electric_meter_day" : "archive_electric_meter_" + input.tableType;
var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null; var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null;
var sql = $@"select device_number, avg_rawdata, DATE_FORMAT(start_timestamp, @dateFormat) as timeStamp var sql = $@"select device_number, avg_rawdata, DATE_FORMAT(start_timestamp, @dateFormat) as timeStamp
from {table} from {table}
@ -88,8 +88,10 @@ namespace FrontendWebApi.ApiControllers
l.building_name = await backendRepository.GetOneAsync<string>("select full_name from building where building_tag = @building_tag and deleted = 0", l.building_name = await backendRepository.GetOneAsync<string>("select full_name from building where building_tag = @building_tag and deleted = 0",
new { building_tag = l.building_tag }); new { building_tag = l.building_tag });
l.total = l.rawData.Count.ToString(); l.total = l.rawData.Count.ToString();
l.price = (await backendRepository.GetOneAsync<int>("select system_value from variable where system_type = 'MeterPrice' and deleted = 0")).ToString(); l.price = input.price.HasValue
l.total_price = (l.rawData.Count * Int32.Parse(l.price)).ToString(); ? (Math.Round(input.price.Value, 2)).ToString()
: Math.Round((await backendRepository.GetOneAsync<decimal>("select system_value from variable where system_type = 'MeterPrice' and deleted = 0")), 2).ToString();
l.total_price = (l.rawData.Count * Decimal.Parse(l.price)).ToString();
} }
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -149,9 +151,9 @@ namespace FrontendWebApi.ApiControllers
: null; : null;
string sqlWhere = ""; string sqlWhere = "";
if (input.floor_tag.Count > 0) if (input.floor_tag.Count > 0)
sqlWhere = $@" and substring_index(device_number, '_', 3) in @floor_tag"; sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag";
var table = "archive_water_meter_" + input.tableType; var table = input.tableType == "year" ? "archive_water_meter_day" : "archive_water_meter_" + input.tableType;
var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : null; var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null;
var sql = $@"select device_number, avg_rawdata, DATE_FORMAT(start_timestamp, @dateFormat) as timeStamp var sql = $@"select device_number, avg_rawdata, DATE_FORMAT(start_timestamp, @dateFormat) as timeStamp
from @table from @table
where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'RCV' and substring_index(device_number, '_', 1) = @building_tag where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'RCV' and substring_index(device_number, '_', 1) = @building_tag
@ -173,7 +175,9 @@ namespace FrontendWebApi.ApiControllers
l.building_name = await backendRepository.GetOneAsync<string>("select full_name from building where building_tag = @building_tag and deleted = 0", l.building_name = await backendRepository.GetOneAsync<string>("select full_name from building where building_tag = @building_tag and deleted = 0",
new { building_tag = l.building_tag }); new { building_tag = l.building_tag });
l.total = l.rawData.Count.ToString(); l.total = l.rawData.Count.ToString();
l.price = (await backendRepository.GetOneAsync<int>("select system_value from variable where system_type = 'WaterPrice' and deleted = 0")).ToString(); l.price = input.price.HasValue
? (Math.Round(input.price.Value, 2)).ToString()
: Math.Round((await backendRepository.GetOneAsync<decimal>("select system_value from variable where system_type = 'WaterPrice' and deleted = 0")), 2).ToString();
l.total_price = (l.rawData.Count * Int32.Parse(l.price)).ToString(); l.total_price = (l.rawData.Count * Int32.Parse(l.price)).ToString();
} }

View File

@ -15,6 +15,7 @@ namespace FrontendWebApi.Models
public List<string> floor_tag { get; set; } public List<string> floor_tag { get; set; }
public string startTime { get; set; } public string startTime { get; set; }
public string endTime { get; set; } public string endTime { get; set; }
public decimal? price { get; set; }
} }
public class HydroMeterOutput public class HydroMeterOutput