From 7dc2e0b5aea7be2238760c7f760ef393e00961ce Mon Sep 17 00:00:00 2001 From: dev02 Date: Fri, 12 May 2023 13:02:24 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=BE=8C=E5=8E=BB=E6=B0=B4=E9=9B=BB=E8=A1=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/HydroMeterController.cs | 20 +++++++++++-------- FrontendWebApi/Models/HydroMeter.cs | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) 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