[後端] 修改水電表參數輸入, 修改查詢sql

This commit is contained in:
dev02 2023-05-12 11:06:55 +08:00
parent e8d553a292
commit 188dc425a6
2 changed files with 12 additions and 9 deletions

View File

@ -55,15 +55,16 @@ namespace FrontendWebApi.ApiControllers
{
var startTime = input.tableType == "day" || input.tableType == "week"
? input.startTime + "-01"
: input.tableType == "month" ? input.startTime + "-01-01"
: null; ;
: input.tableType == "month" || input.tableType == "year" ? input.startTime + "-01-01"
: null;
var endTime = input.tableType == "day" || input.tableType == "week"
? input.startTime.Split("-")[0] + "-" + (Int32.Parse(input.startTime.Split("-")[1]) + 1).ToString().PadLeft(2, '0') + "-01"
: input.tableType == "month" ? (Int32.Parse(input.startTime.Split("-")[0]) + 1) + "-01-01"
: input.tableType == "year" ? input.endTime + "-01-01"
: null;
string sqlWhere = "";
if (input.floor_tag != null)
sqlWhere = $@" and substring_index(device_number, '_', 3) = @floor_tag";
if (input.floor_tag.Count > 0)
sqlWhere = $@" and substring_index(device_number, '_', 3) in @floor_tag";
var table = "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
@ -139,15 +140,16 @@ namespace FrontendWebApi.ApiControllers
{
var startTime = input.tableType == "day" || input.tableType == "week"
? input.startTime + "-01"
: input.tableType == "month" ? input.startTime + "-01-01"
: null; ;
: input.tableType == "month" || input.tableType == "month" ? input.startTime + "-01-01"
: null;
var endTime = input.tableType == "day" || input.tableType == "week"
? input.startTime.Split("-")[0] + "-" + (Int32.Parse(input.startTime.Split("-")[1]) + 1).ToString().PadLeft(2, '0') + "-01"
: input.tableType == "month" ? (Int32.Parse(input.startTime.Split("-")[0]) + 1) + "-01-01"
: input.tableType == "year" ? input.endTime + "-01-01"
: null;
string sqlWhere = "";
if (input.floor_tag != null)
sqlWhere = $@" and substring_index(device_number, '_', 3) = @floor_tag";
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;
var sql = $@"select device_number, avg_rawdata, DATE_FORMAT(start_timestamp, @dateFormat) as timeStamp

View File

@ -12,8 +12,9 @@ namespace FrontendWebApi.Models
{
public string tableType { get; set; } //day, week, month
public string building_tag { get; set; }
public string floor_tag { get; set; }
public List<string> floor_tag { get; set; }
public string startTime { get; set; }
public string endTime { get; set; }
}
public class HydroMeterOutput