diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index 41eb223..c0ebabd 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -64,8 +64,8 @@ namespace FrontendWebApi.ApiControllers : null; string sqlWhere = ""; if (input.floor_tag.Count > 0) - sqlWhere = $@" and substring_index(device_number, '_', 3) in @floor_tag"; - var table = "archive_electric_meter_" + input.tableType; + sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag"; + 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 sql = $@"select device_number, avg_rawdata, DATE_FORMAT(start_timestamp, @dateFormat) as timeStamp from {table} @@ -88,8 +88,10 @@ namespace FrontendWebApi.ApiControllers l.building_name = await backendRepository.GetOneAsync("select full_name from building where building_tag = @building_tag and deleted = 0", new { building_tag = l.building_tag }); l.total = l.rawData.Count.ToString(); - l.price = (await backendRepository.GetOneAsync("select system_value from variable where system_type = 'MeterPrice' and deleted = 0")).ToString(); - l.total_price = (l.rawData.Count * Int32.Parse(l.price)).ToString(); + l.price = input.price.HasValue + ? (Math.Round(input.price.Value, 2)).ToString() + : Math.Round((await backendRepository.GetOneAsync("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"; @@ -149,9 +151,9 @@ namespace FrontendWebApi.ApiControllers : null; string sqlWhere = ""; if (input.floor_tag.Count > 0) - sqlWhere = $@" and substring_index(device_number, '_', 3) in @floor_tag"; - var table = "archive_water_meter_" + input.tableType; - var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : null; + sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag"; + 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" : input.tableType == "year" ? "%Y" : null; var sql = $@"select device_number, avg_rawdata, DATE_FORMAT(start_timestamp, @dateFormat) as timeStamp from @table 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("select full_name from building where building_tag = @building_tag and deleted = 0", new { building_tag = l.building_tag }); l.total = l.rawData.Count.ToString(); - l.price = (await backendRepository.GetOneAsync("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("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(); } diff --git a/FrontendWebApi/Models/HydroMeter.cs b/FrontendWebApi/Models/HydroMeter.cs index 3c63bc5..564e311 100644 --- a/FrontendWebApi/Models/HydroMeter.cs +++ b/FrontendWebApi/Models/HydroMeter.cs @@ -15,6 +15,7 @@ namespace FrontendWebApi.Models public List floor_tag { get; set; } public string startTime { get; set; } public string endTime { get; set; } + public decimal? price { get; set; } } public class HydroMeterOutput