[FrontendWebApi] GetAutDemVal variable automated_demand_response 取得自動須量 api 建置 | 編輯自動須量 api 調整

This commit is contained in:
dev01 2023-01-09 19:15:40 +08:00
parent 571130c2bf
commit d7c663f50d
3 changed files with 75 additions and 2 deletions

View File

@ -1,14 +1,18 @@
using FrontendWebApi.Models; using FrontendWebApi.Models;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NPOI.SS.Formula.Functions; using NPOI.SS.Formula.Functions;
using NPOI.SS.Formula.PTG;
using Repository.BackendRepository.Interface; using Repository.BackendRepository.Interface;
using Repository.FrontendRepository.Interface; using Repository.FrontendRepository.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SqlTypes; using System.Data.SqlTypes;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Channels;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FrontendWebApi.ApiControllers namespace FrontendWebApi.ApiControllers
@ -47,5 +51,72 @@ namespace FrontendWebApi.ApiControllers
} }
return Ok(apiResult); return Ok(apiResult);
} }
[HttpPost]
[Route("api/Energe/GetAutDemVal")]
public async Task<ActionResult<ApiResult<List<Variable>>>> GetAutDemVal()
{
ApiResult<List<Variable>> apiResult = new ApiResult<List<Variable>>();
try
{
var sqlString = $@"SELECT system_value,system_key FROM variable
where system_type = 'automated_demand_response' and deleted = '0'";
var ess = await backendRepository.GetAllAsync<Variable>(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<ActionResult<ApiResult<List<int?>>>> EdiAutDemVal([FromBody] List<Variable> variables)
{
ApiResult<List<int?>> apiResult = new ApiResult<List<int?>>();
try
{
var sqlString = $@"SELECT system_value,system_key FROM variable
where system_type = 'automated_demand_response' and deleted = '0'";
var vs = await backendRepository.GetAllAsync<Variable>(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<string, object> sqlParam = new Dictionary<string, object>() {
{ "@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);
}
} }
} }

View File

@ -7,4 +7,6 @@
public string system_remark { get; set; } public string system_remark { get; set; }
public string priority { get; set; } public string priority { get; set; }
} }
} }

View File

@ -48,10 +48,10 @@ namespace FrontendWebApi.Models
public class Variable : Actor public class Variable : Actor
{ {
public int id { get; set; } public int? id { get; set; }
public string System_type { get; set; } public string System_type { get; set; }
public string System_key { get; set; } public string System_key { get; set; }
public string system_value { get; set; } public string system_value { get; set; }
public int system_parent_id { get; set; } public int? system_parent_id { get; set; }
} }
} }