cambios
This commit is contained in:
parent
e7372f2ae6
commit
4b5b3ae3d9
3 changed files with 113 additions and 86 deletions
|
@ -58,105 +58,73 @@ namespace BLL.Integracion_DGA
|
|||
responseData = await _apiService.GetApiResponseAsync(apiUrlTagViews, headers);
|
||||
TagviewsResponse tagviews = JsonSerializer.Deserialize<TagviewsResponse>(responseData, options);
|
||||
|
||||
List<string> listTagsID = new List<string>();
|
||||
foreach (Column tag in tagviews.Columns)
|
||||
{
|
||||
listTagsID.Add(tag.Uid);
|
||||
}
|
||||
List<string> listTagsID = tagviews.Columns.Select(x => x.Uid).ToList();
|
||||
|
||||
HistoricRequest historicRequest = new HistoricRequest();
|
||||
historicRequest.DataSource = NexusApiUrl.DataSource;
|
||||
historicRequest.Resolution = NexusApiUrl.Resolution;
|
||||
historicRequest.Uids = listTagsID;
|
||||
historicRequest.StartTs = dateStart.ToUnixTimeSeconds();
|
||||
historicRequest.EndTs = dateEnd.ToUnixTimeSeconds();
|
||||
HistoricRequest historicRequest = new HistoricRequest
|
||||
{
|
||||
DataSource = NexusApiUrl.DataSource,
|
||||
Resolution = NexusApiUrl.Resolution,
|
||||
Uids = listTagsID,
|
||||
StartTs = dateStart.ToUnixTimeSeconds(),
|
||||
EndTs = dateEnd.ToUnixTimeSeconds()
|
||||
};
|
||||
|
||||
WriteLineAndLog($"Obteniendo Tagviews Historic");
|
||||
string apiUrlHistoric = $"{apiUrlBase}/api/Documents/tagviews/{item.uid}/historic";
|
||||
responseData = await _apiService.PostApiResponseAsync(apiUrlHistoric, headers, historicRequest);
|
||||
List<HistoricResponse> historicResponse = JsonSerializer.Deserialize<List<HistoricResponse>>(responseData, options);
|
||||
|
||||
List<DgaMacroResultado> listDgaMacroResultados = new List<DgaMacroResultado>();
|
||||
foreach (Column tag in tagviews.Columns)
|
||||
{
|
||||
IEnumerable<HistoricResponse> filter = historicResponse.Where(h => h.Uid == tag.Uid);
|
||||
foreach (HistoricResponse historic in filter)
|
||||
{
|
||||
TimeZoneInfo zonaHorariaChile = TimeZoneInfo.FindSystemTimeZoneById("Pacific SA Standard Time");
|
||||
DateTime now = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(historic.TimeStamp);
|
||||
DateTime fechaHoraChile = TimeZoneInfo.ConvertTimeFromUtc(now, zonaHorariaChile);
|
||||
|
||||
if (item.name == "API - DGA - CAUDALES")
|
||||
{
|
||||
var caudalData = tagviews.Columns
|
||||
.SelectMany(tag =>
|
||||
historicResponse.Where(h => h.Uid == tag.Uid)
|
||||
.Select(h => new DGAInsert
|
||||
{
|
||||
TAG = tag.Name,
|
||||
VALOR = h.Value?.ToString(),
|
||||
FECHAMEDICION = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
new DateTime(1970, 1, 1).AddSeconds(h.TimeStamp).ToUniversalTime(),
|
||||
zonaHorariaChile)
|
||||
})
|
||||
).ToList();
|
||||
|
||||
DgaMacroResultado dgaMacroResultado = new DgaMacroResultado();
|
||||
dgaMacroResultado.TagName = $"SCADA001.{tag.Name}.F_CV";
|
||||
dgaMacroResultado.Value = historic.Value;
|
||||
//dgaMacroResultado.TimeStamp = new DateTime(historic.TimeStamp);
|
||||
dgaMacroResultado.TimeStamp = fechaHoraChile;
|
||||
|
||||
listDgaMacroResultados.Add(dgaMacroResultado);
|
||||
await _jobs.InsertarDgaCaudal(caudalData);
|
||||
}
|
||||
else if (item.name == "API - DGA - NIVELES")
|
||||
{
|
||||
var nivelData = tagviews.Columns
|
||||
.SelectMany(tag =>
|
||||
historicResponse.Where(h => h.Uid == tag.Uid)
|
||||
.Select(h => new DGAInsert
|
||||
{
|
||||
TAG = tag.Name,
|
||||
VALOR = h.Value?.ToString(),
|
||||
FECHAMEDICION = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
new DateTime(1970, 1, 1).AddSeconds(h.TimeStamp).ToUniversalTime(),
|
||||
zonaHorariaChile)
|
||||
})
|
||||
).ToList();
|
||||
|
||||
await _jobs.InsertarDgaNivel(nivelData);
|
||||
}
|
||||
|
||||
/**************/
|
||||
WriteLineAndLog($"Inicia Envio DGA", ConsoleColor.Green);
|
||||
WriteLineAndLog($"\t Descargar datos historian: Insertar DgaMacroResultado");
|
||||
var resultMacro = await _jobs.InsertarDgaMacroResultado(listDgaMacroResultados);
|
||||
|
||||
WriteLineAndLog($"\t Descargar datos historian: Insertar DgaSensorResultado");
|
||||
List<DgaSensorResultado> listDgaSensorResultado = listDgaMacroResultados.Select(item => new DgaSensorResultado
|
||||
else if (item.name == "API - DGA")
|
||||
{
|
||||
TagName = item.TagName,
|
||||
TimeStamp = item.TimeStamp,
|
||||
Value = item.Value,
|
||||
Quality = item.Quality
|
||||
}).ToList();
|
||||
|
||||
var resultSensor = await _jobs.InsertarDgaSensorResultado(listDgaSensorResultado);
|
||||
|
||||
WriteLineAndLog($"\t Calculo DGA");
|
||||
var resultCalculo = await _jobs.SpCalculoDga();
|
||||
|
||||
WriteLineAndLog($"\t descargar datos suma reversibilidad : Insertar DgaMacroResultadoSupFlujSuma");
|
||||
List<DgaMacroResultadoSupFlujSuma> listDgaMacroResultadoSupFlujSuma = listDgaMacroResultados.Select(item => new DgaMacroResultadoSupFlujSuma
|
||||
var nivelData = tagviews.Columns
|
||||
.SelectMany(tag =>
|
||||
historicResponse.Where(h => h.Uid == tag.Uid)
|
||||
.Select(h => new
|
||||
{
|
||||
TagName = item.TagName,
|
||||
TimeStamp = item.TimeStamp,
|
||||
Value = item.Value,
|
||||
Quality = item.Quality
|
||||
}).ToList();
|
||||
|
||||
var resultSupFlujSuma = await _jobs.InsertarDgaMacroResultadoSupFlujSuma(listDgaMacroResultadoSupFlujSuma);
|
||||
|
||||
WriteLineAndLog($"\t Calculo Suma");
|
||||
var resultCalculoDgaSup = await _jobs.SpCalculoDgaSupFlujSumaSnreversibilidad();
|
||||
|
||||
|
||||
WriteLineAndLog($"\t Traspaso datos achird");
|
||||
var result = await _jobs.SpTraspasoDatosAchird();
|
||||
WriteLineAndLog($"Fin Envio DGA", ConsoleColor.Green);
|
||||
/**************/
|
||||
/**************/
|
||||
WriteLineAndLog($"Inicio Envio DGA Sup Fluj", ConsoleColor.Green);
|
||||
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaMacroResultadoSupFluj");
|
||||
List<DgaMacroResultadoSupFluj> listDgaMacroResultadoSupFluj = listDgaMacroResultados.Select(item => new DgaMacroResultadoSupFluj
|
||||
{
|
||||
TagName = item.TagName,
|
||||
TimeStamp = item.TimeStamp,
|
||||
Value = item.Value,
|
||||
Quality = item.Quality
|
||||
}).ToList();
|
||||
|
||||
var resultSensorSup = await _jobsSupFluj.InsertarDgaMacroResultadoSupFluj(listDgaMacroResultadoSupFluj);
|
||||
|
||||
WriteLineAndLog($"\t Calculo Suma");
|
||||
var resultCalculoSup = await _jobsSupFluj.SpCalculoDgaSupFluj();
|
||||
|
||||
|
||||
WriteLineAndLog($"\t Traspaso datos achird");
|
||||
var resultAchirdSup = await _jobsSupFluj.SpTraspasoDatosAchirdSupFluj();
|
||||
WriteLineAndLog($"Fin Envio DGA Sup Fluj", ConsoleColor.Green);
|
||||
/**************/
|
||||
/**************/
|
||||
TAG = tag.Name,
|
||||
NIVEL_FREATICO = h.Value?.ToString(),
|
||||
FECHAMEDICION = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
new DateTime(1970, 1, 1).AddSeconds(h.TimeStamp).ToUniversalTime(),
|
||||
zonaHorariaChile)
|
||||
})
|
||||
).ToList();
|
||||
}
|
||||
}
|
||||
WriteLineAndLog($"FIN Proceso DGA");
|
||||
}
|
||||
|
|
|
@ -141,5 +141,49 @@ namespace DAL
|
|||
throw new Exception($"Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> InsertarDgaCaudal(List<DGAInsert> dgaMacroResultados)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
// 1. Truncar la tabla antes de insertar
|
||||
await connection.ExecuteAsync("TRUNCATE TABLE DGA_CAUDAL");
|
||||
// 2. Insertar la lista de registros
|
||||
string sql = "INSERT INTO DGA_CAUDAL (TAG, CAUDAL, FECHAMEDICION) VALUES (@TAG, @VALOR, @FECHAMEDICION)";
|
||||
// Esto inserta todos los elementos de la lista en la tabla
|
||||
await connection.ExecuteAsync(sql, dgaMacroResultados);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> InsertarDgaNivel(List<DGAInsert> dgaMacroResultados)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
// 1. Truncar la tabla antes de insertar
|
||||
await connection.ExecuteAsync("TRUNCATE TABLE DGA_NIVEL");
|
||||
// 2. Insertar la lista de registros
|
||||
string sql = "INSERT INTO DGA_NIVEL (TAG, NIVEL_FREATICO, FECHAMEDICION) VALUES (@TAG, @VALOR, @FECHAMEDICION)";
|
||||
// Esto inserta todos los elementos de la lista en la tabla
|
||||
await connection.ExecuteAsync(sql, dgaMacroResultados);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
15
SHARED/DTO/Integracion_DGA/DGAInsert.cs
Normal file
15
SHARED/DTO/Integracion_DGA/DGAInsert.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTO.Integracion_DGA
|
||||
{
|
||||
public partial class DGAInsert
|
||||
{
|
||||
public string TAG { get; set; } = string.Empty;
|
||||
public string? VALOR { get; set; }
|
||||
public DateTime FECHAMEDICION { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue