Compare commits

...

6 Commits

9 changed files with 120 additions and 10 deletions

View File

@ -8,7 +8,6 @@
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,7 @@
namespace Application
{
public interface ICalendarioService
{
Task<double?> ObterEventoLimiteColetaAsync(DateTime dataReferencia, CancellationToken ct = default);
}
}

View File

@ -5,7 +5,6 @@ using System.Text;
using System.Threading.Channels;
using System.Xml.Linq;
using Domain;
using Infrastructure;
namespace Application
{
@ -57,7 +56,7 @@ namespace Application
Tipo.ToString(),
Esc(Perfil),
Esc(Ponto),
DiaNum.ToString(CultureInfo.InvariantCulture),
DateTime.FromOADate(DiaNum).ToString("dd/MM/yyyy"),
Minuto.ToString(),
Esc(Status),
Esc(Mensagem),

View File

@ -1,4 +1,4 @@
namespace Infrastructure
namespace Application
{
public class SoapFaultException : Exception
{

View File

@ -1,6 +1,6 @@
using System.Xml.Linq;
namespace Infrastructure
namespace Application
{
public static class SoapHelper
{

View File

@ -0,0 +1,96 @@
using System.Text.Json;
using System.Globalization;
using Application;
namespace Infrastructure
{
public class CalendarioService : ICalendarioService
{
private const string Url = "https://www.ccee.org.br/en/web/guest/calendario?p_p_id=com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn&p_p_lifecycle=2&p_p_cacheability=cacheLevelPage&doAsUserId=&p_p_resource_id=calendarBookings";
public async Task<double?> ObterEventoLimiteColetaAsync(DateTime dataReferencia, CancellationToken ct = default)
{
var year = dataReferencia.Year;
var month = dataReferencia.Month - 1;
var dayFinal = DateTime.DaysInMonth(year, month + 1);
var values = new Dictionary<string, string>
{
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_calendarIds"] = "55985",
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_endTimeDay"] = dayFinal.ToString(),
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_endTimeHour"] = "23",
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_endTimeMinute"] = "59",
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_endTimeMonth"] = month.ToString(),
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_endTimeYear"] = year.ToString(),
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_eventsPerPage"] = "-1",
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_startTimeDay"] = "1",
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_startTimeHour"] = "0",
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_startTimeMinute"] = "0",
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_startTimeMonth"] = month.ToString(),
["_com_liferay_calendar_web_portlet_CalendarPortlet_INSTANCE_urjn_startTimeYear"] = year.ToString(),
};
try
{
using var client = new HttpClient();
using var content = new FormUrlEncodedContent(values);
var resp = await client.PostAsync(Url, content, ct);
var resposta = await resp.Content.ReadAsStringAsync(ct);
var alvo = $"Data limite para coleta diária dos dados de medição no SCDE";
try
{
using var doc = JsonDocument.Parse(resposta);
double? encontrado = null;
double? startTimeDay = null;
void SearchJson(JsonElement el)
{
if (encontrado != null) return;
if (el.ValueKind == JsonValueKind.Object)
{
// Verifica se alguma propriedade contém o texto alvo
foreach (var prop in el.EnumerateObject())
{
if (prop.Value.ValueKind == JsonValueKind.String)
{
var s = prop.Value.GetString() ?? "";
if (s.Contains(alvo, StringComparison.OrdinalIgnoreCase))
{
// Encontrou o evento, extrair dados do mesmo objeto
if (el.TryGetProperty("startTimeDay", out var day))
startTimeDay = day.GetInt32();
if (startTimeDay != null)
encontrado = startTimeDay;
return;
}
}
}
foreach (var prop in el.EnumerateObject())
SearchJson(prop.Value);
}
else if (el.ValueKind == JsonValueKind.Array)
{
foreach (var item in el.EnumerateArray())
SearchJson(item);
}
}
SearchJson(doc.RootElement);
if (encontrado != null) return encontrado;
}
catch { }
return null;
}
catch
{
return null;
}
}
}
}

View File

@ -13,6 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\Application\Application.csproj" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,6 @@
using System.Globalization;
using Domain;
using Microsoft.VisualBasic;
using Npgsql;
using NpgsqlTypes;

View File

@ -6,15 +6,22 @@ class Program
static async Task Main()
{
DateTime inicio = DateTime.Now;
string PG_CONN_STRING_PROD = "Server = smart-energia-dev-pgsql.cykff7tj7mik.us-east-1.rds.amazonaws.com; Port = 5432; Database = smartenergiaprod; Username = postgres; Password = VfHml#Z78!%kvvNM; Timeout = 60; CommandTimeout = 60; ApplicationName = new_med_5_min; Connection Lifetime = 120; Minimum Pool Size = 2; Maximum Pool Size = 4;";
string PG_CONN_STRING_PROD = "Server = smart-energia-dev-pgsql.cykff7tj7mik.us-east-1.rds.amazonaws.com; Port = 5432; Database = smartenergiaprod; Username = postgres; Password = VfHml#Z78!%kvvNM; Timeout = 60; CommandTimeout = 60; ApplicationName = new_med_5_min; Connection Lifetime = 120; Minimum Pool Size = 1; Maximum Pool Size = 1;";
// string PG_CONN_STRING_PROD = "Server = 192.168.10.248; Port = 5432; Database = smartenergiadev; Username = postgres; Password = gds21; Timeout = 60; CommandTimeout = 60; ApplicationName = new_med_5_min; Connection Lifetime = 120; Minimum Pool Size = 2; Maximum Pool Size = 4;";
string ACCESS_CONN_STRING = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\srv-dados\documentos\Middle\Informativo Setorial\Modelo Word\BD1_dados cadastrais e faturas.accdb;Jet OLEDB:Database Password=gds21";
string caminhoLog = $@"\\srv-dados\documentos\Back\Carteira x.x\Codigo\Erros\log_erros_{inicio:MM_dd_HH_mm}.csv";
//DateTime dataIni = new DateTime(inicio.Year, inicio.Month, 1);
//DateTime dataFim = new DateTime(inicio.Year, inicio.Month, inicio.Day);
var calendarioService = new CalendarioService();
var evento = await calendarioService.ObterEventoLimiteColetaAsync(inicio, CancellationToken.None);
//agosto finalizado
DateTime dataIni = new DateTime(inicio.Year, 09, 01);
DateTime dataFim = new DateTime(inicio.Year, 10, 01);
DateTime dataIni = new DateTime(inicio.Year, inicio.Month, 01);
DateTime dataFim = inicio.Date;
if (dataFim.Day <= evento + 1)
{
dataIni = dataIni.AddMonths(-1);
}
// Configuração de dependências (pode usar um container DI depois)
var postgresRepo = new PostgresRepository(PG_CONN_STRING_PROD);