From d7c663f50dcb8ce154f5e22b05f92a20e3a51f4d Mon Sep 17 00:00:00 2001 From: dev01 Date: Mon, 9 Jan 2023 19:15:40 +0800 Subject: [PATCH] =?UTF-8?q?[FrontendWebApi]=20GetAutDemVal=20variable=20au?= =?UTF-8?q?tomated=5Fdemand=5Fresponse=20=E5=8F=96=E5=BE=97=E8=87=AA?= =?UTF-8?q?=E5=8B=95=E9=A0=88=E9=87=8F=20api=20=E5=BB=BA=E7=BD=AE=20|=20?= =?UTF-8?q?=E7=B7=A8=E8=BC=AF=E8=87=AA=E5=8B=95=E9=A0=88=E9=87=8F=20api=20?= =?UTF-8?q?=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/EnergeManageController.cs | 71 +++++++++++++++++++ FrontendWebApi/Models/Energe.cs | 2 + FrontendWebApi/Models/MyBase.cs | 4 +- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/FrontendWebApi/ApiControllers/EnergeManageController.cs b/FrontendWebApi/ApiControllers/EnergeManageController.cs index 6dfe8fa..220c5da 100644 --- a/FrontendWebApi/ApiControllers/EnergeManageController.cs +++ b/FrontendWebApi/ApiControllers/EnergeManageController.cs @@ -1,14 +1,18 @@ using FrontendWebApi.Models; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using NPOI.SS.Formula.Functions; +using NPOI.SS.Formula.PTG; using Repository.BackendRepository.Interface; using Repository.FrontendRepository.Interface; using System; using System.Collections.Generic; using System.Data.SqlTypes; using System.IO; +using System.Linq; +using System.Threading.Channels; using System.Threading.Tasks; namespace FrontendWebApi.ApiControllers @@ -47,5 +51,72 @@ namespace FrontendWebApi.ApiControllers } return Ok(apiResult); } + + + [HttpPost] + [Route("api/Energe/GetAutDemVal")] + public async Task>>> GetAutDemVal() + { + ApiResult> apiResult = new ApiResult>(); + try + { + var sqlString = $@"SELECT system_value,system_key FROM variable + where system_type = 'automated_demand_response' and deleted = '0'"; + var ess = await backendRepository.GetAllAsync(sqlString); + + apiResult.Code = "0000"; + apiResult.Data = ess; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + return Ok(apiResult); + } + return Ok(apiResult); + } + + [HttpPost] + [Route("api/Energe/EdiAutDemVal")] + public async Task>>> EdiAutDemVal([FromBody] List variables) + { + ApiResult> apiResult = new ApiResult>(); + + try + { + var sqlString = $@"SELECT system_value,system_key FROM variable + where system_type = 'automated_demand_response' and deleted = '0'"; + var vs = await backendRepository.GetAllAsync(sqlString); + + var autDemKeys = vs.Select(x => x.System_key); + foreach (var v in variables) { + if (autDemKeys.Where(x => x == v.System_key).Count() != 0) { + Dictionary sqlParam = new Dictionary() { + { "@system_key", v.System_key}, + { "@system_value", v.system_value}, + { "@updated_by", myUser.userinfo_guid}, + { "@updated_at", DateTime.Now}, + }; + + await backendRepository.UpdateOneByCustomTable(sqlParam, "variable", $" system_type = 'automated_demand_response' AND system_key = @system_key"); + + } + } + + apiResult.Code = "0000"; + apiResult.Data = null; + apiResult.Msg = "編輯成功"; + } + catch (Exception exception) + { + + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。" + exception.Message; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + return Ok(apiResult); + } + return Ok(apiResult); + } } } diff --git a/FrontendWebApi/Models/Energe.cs b/FrontendWebApi/Models/Energe.cs index 08eddc1..b1ebbfa 100644 --- a/FrontendWebApi/Models/Energe.cs +++ b/FrontendWebApi/Models/Energe.cs @@ -7,4 +7,6 @@ public string system_remark { get; set; } public string priority { get; set; } } + + } diff --git a/FrontendWebApi/Models/MyBase.cs b/FrontendWebApi/Models/MyBase.cs index 0f64d8f..51def45 100644 --- a/FrontendWebApi/Models/MyBase.cs +++ b/FrontendWebApi/Models/MyBase.cs @@ -48,10 +48,10 @@ namespace FrontendWebApi.Models public class Variable : Actor { - public int id { get; set; } + public int? id { get; set; } public string System_type { get; set; } public string System_key { get; set; } public string system_value { get; set; } - public int system_parent_id { get; set; } + public int? system_parent_id { get; set; } } }