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; } } }