From b479e1d5c51610749be67e1c964b2a3c4b6b82be Mon Sep 17 00:00:00 2001 From: keke Date: Mon, 28 Aug 2023 12:45:01 +0800 Subject: [PATCH] =?UTF-8?q?[FE=20API]=20=E6=9B=B4=E6=96=B0=E7=B8=BD?= =?UTF-8?q?=E8=A1=A8=E6=AF=94=E8=BC=83=E6=9F=A5=E8=A9=A2=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20API=20=E5=90=8D=E7=A8=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/HydroMeterController.cs | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index b5ecf12..cf1e978 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -836,7 +836,7 @@ namespace FrontendWebApi.ApiControllers } input.building_tag = fix_buildingTag.ToString().TrimEnd(',', ' '); - result.Add(ElectricList_keke(input).Result.Value.Data.ToList()); + result.Add(ElectricListEachTotal(input).Result.Value.Data.ToList()); // --- 8/24 修改到這裡囉 --- @@ -996,8 +996,8 @@ namespace FrontendWebApi.ApiControllers } [HttpPost] - [Route("api/ElectricList_keke")] - public async Task>>> ElectricList_keke([FromBody] HydroMeterInput input) + [Route("api/ElectricListEachTotal")] + public async Task>>> ElectricListEachTotal([FromBody] HydroMeterInput input) { //switch (input.Mode) @@ -1051,14 +1051,27 @@ namespace FrontendWebApi.ApiControllers string buildingSql = ""; string tag_quantity = await backendRepository.GetOneAsync("select system_value from variable where system_type = 'obixConfig' and system_key = 'tag_quantity' and deleted = 0"); + switch (input.Mode) + { + case HydroMeterInputSearchMode.All: + break; + + case HydroMeterInputSearchMode.Custom: + sqlWhere = @$" and device_number in (SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(system_value, '/', -1), '_', 8) COLLATE utf8mb4_0900_ai_ci as val FROM variable where system_type = 'dashboard_total_elec')"; + break; + + default: + break; + } + // 將棟別字串前處理 (後續 SQL 語法可以使用 IN 的格式) - //string[] parts_buildingTag = input.building_tag.Split(','); - //StringBuilder fix_buildingTag = new StringBuilder(); - //foreach (string part in parts_buildingTag) - //{ - // fix_buildingTag.Append("'").Append(part.Trim()).Append("', "); - //} - //input.building_tag = fix_buildingTag.ToString().TrimEnd(',', ' '); + string[] parts_buildingtag = input.building_tag.Split(','); + StringBuilder fix_buildingtag = new StringBuilder(); + foreach (string part in parts_buildingtag) + { + fix_buildingtag.Append("'").Append(part.Trim()).Append("', "); + } + input.building_tag = fix_buildingtag.ToString().TrimEnd(',', ' '); if (tag_quantity == "5") buildingSql = @$" and SUBSTRING_INDEX(device_number, '_', 1) in ({input.building_tag}) "; @@ -1095,7 +1108,7 @@ from ( select device_number from {table} where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' {buildingSql} - {sqlWhere} + {sqlWhere} group by device_number ) dn )