Compare commits
4 Commits
Unificação
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| df6810922b | |||
| 001c467a7c | |||
| 6848039309 | |||
| 495130efe9 |
2
Download Faturas.Tests/divergencias.csv
Normal file
2
Download Faturas.Tests/divergencias.csv
Normal file
@ -0,0 +1,2 @@
|
||||
FaturaId Distribuidora oldConsumo_P newConsumo_P oldConsumo_FP newConsumo_FP oldDem_Reg_P newDem_Reg_P oldDem_Reg_FP newDem_Reg_FP oldEn_Reativa_Mvarh newEn_Reativa_Mvarh
|
||||
3471939 0 0,46028 0 5,23094 0 8,6592 0 11,4144 0 0,04156
|
||||
|
@ -1,19 +1,2 @@
|
||||
"ID" "Doc" "Status" "Invalidar" "Origin" "Last changed" "Submitted" "JSON" "Name"
|
||||
"3019848" "View | Raw" "SUCCESS" "" "BOT" "2025-11-11 10:31:03" "2025-11-11 10:30:41" "View | Raw" "1114467.pdf"
|
||||
"3001963" "View | Raw" "SUCCESS" "" "BOT" "2025-11-05 07:14:49" "2025-11-05 07:14:33" "View | Raw" "1104802.pdf"
|
||||
"3001801" "View | Raw" "SUCCESS" "" "BOT" "2025-11-05 05:38:54" "2025-11-05 05:38:34" "View | Raw" "1104653.pdf"
|
||||
"3001795" "View | Raw" "SUCCESS" "" "BOT" "2025-11-05 05:36:13" "2025-11-05 05:36:01" "View | Raw" "1104647.pdf"
|
||||
"2993194" "View | Raw" "SUCCESS" "" "BOT" "2025-11-04 06:28:45" "2025-11-04 06:28:29" "View | Raw" "1098537.pdf"
|
||||
"2988061" "View | Raw" "SUCCESS" "" "BOT" "2025-11-03 12:12:41" "2025-11-03 12:12:20" "View | Raw" "1095060.pdf"
|
||||
"2987758" "View | Raw" "SUCCESS" "" "BOT" "2025-11-03 11:07:52" "2025-11-03 11:07:41" "View | Raw" "1094871.pdf"
|
||||
"2987323" "View | Raw" "SUCCESS" "" "BOT" "2025-11-03 09:08:33" "2025-11-03 09:08:18" "View | Raw" "1094470.pdf"
|
||||
"2987073" "View | Raw" "SUCCESS" "" "BOT" "2025-11-03 07:37:46" "2025-11-03 07:37:34" "View | Raw" "1094220.pdf"
|
||||
"2924492" "View | Raw" "SUCCESS" "" "BOT" "2025-10-15 16:15:59" "2025-10-10 08:26:03" "View | Raw" "1062999.pdf"
|
||||
"2906853" "View | Raw" "SUCCESS" "" "BOT" "2025-10-06 12:50:24" "2025-10-06 12:50:08" "View | Raw" "1058041.pdf"
|
||||
"2906573" "View | Raw" "SUCCESS" "" "BOT" "2025-10-06 12:10:55" "2025-10-06 12:10:31" "View | Raw" "1058009.pdf"
|
||||
"2905879" "View | Raw" "SUCCESS" "" "BOT" "2025-10-06 05:58:46" "2025-10-06 05:58:29" "View | Raw" "1057526.pdf"
|
||||
"2903836" "View | Raw" "SUCCESS" "" "BOT" "2025-10-03 11:42:27" "2025-10-03 11:42:09" "View | Raw" "1056838.pdf"
|
||||
"2901834" "View | Raw" "SUCCESS" "" "BOT" "2025-10-02 10:08:21" "2025-10-02 10:08:08" "View | Raw" "1055842.pdf"
|
||||
"2901695" "View | Raw" "SUCCESS" "" "BOT" "2025-10-02 08:56:24" "2025-10-02 08:56:17" "View | Raw" "1055712.pdf"
|
||||
"2901665" "View | Raw" "SUCCESS" "" "BOT" "2025-10-02 08:42:42" "2025-10-02 08:42:34" "View | Raw" "1055684.pdf"
|
||||
"2901319" "View | Raw" "SUCCESS" "" "BOT" "2025-10-02 06:20:25" "2025-10-02 06:20:09" "View | Raw" "1055363.pdf"
|
||||
"ID ""Doc"" ""Status"" ""Invalidar"" ""Origin"" ""Last changed"" ""Submitted"" ""JSON"" ""Name""";;;;;;;;
|
||||
"3471939 ""View | Raw"" ""SUCCESS"" """" ""BOT"" ""2025-11-11 10:31:03"" ""2025-11-11 10:30:41"" ""View | Raw"" ""1114467.pdf""";;;;;;;;
|
||||
|
@ -14,13 +14,13 @@ namespace Download_Faturas.Tests
|
||||
public async Task CompareFaturaWithFaturaOld_ShouldReportDifferences()
|
||||
{
|
||||
// Sample fatura IDs to test (replace with real IDs or fetch dynamically)
|
||||
var faturaIds = LoadCsvColumn("../../../../Download Faturas.Tests/4Docs_2025_07.csv", 0);
|
||||
var faturaIds = LoadCsvColumn("../../../../Faturas.Tests/4Docs_2025_07.csv", 0);
|
||||
var differences = new List<string>
|
||||
{
|
||||
$"FaturaId\tDistribuidora\toldConsumo_P\tnewConsumo_P\toldConsumo_FP\tnewConsumo_FP\toldDem_Reg_P\tnewDem_Reg_P\toldDem_Reg_FP\tnewDem_Reg_FP\toldEn_Reativa_Mvarh\tnewEn_Reativa_Mvarh"
|
||||
};
|
||||
|
||||
using (OleDbConnection conn = new (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=X:/Middle/Informativo Setorial/Modelo Word/BD1_Testes.accdb;Jet OLEDB:Database Password=gds21"))
|
||||
using (OleDbConnection conn = new (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=X:/Middle/Informativo Setorial/Modelo Word/BD1_dados cadastrais e faturas.accdb;Jet OLEDB:Database Password=gds21"))
|
||||
{
|
||||
// Open the connection to the test database
|
||||
conn.Open();
|
||||
@ -51,7 +51,7 @@ namespace Download_Faturas.Tests
|
||||
|
||||
fatura.Processar(conn); // This will also write to DB, but we want to compare without writing
|
||||
var newVal = GetDadosTusd(conn, fatura.CodTusd);
|
||||
DeleteTusdRecords(conn, fatura.CodTusd); // Delete old TUSD records before processing
|
||||
//DeleteTusdRecords(conn, fatura.CodTusd); // Delete old TUSD records before processing
|
||||
|
||||
if (!Equals(newVal, oldVal))
|
||||
{
|
||||
@ -126,7 +126,7 @@ namespace Download_Faturas.Tests
|
||||
if (line != null)
|
||||
{
|
||||
var values = line.Split('\t');
|
||||
if (values.Length > columnIndex && (values[4] == "\"API\"" || values[4] == "\"BOT\""))
|
||||
if (values.Length > columnIndex && (values[4] == "\"\"API\"\"" || values[4] == "\"\"BOT\"\""))
|
||||
{
|
||||
columnData.Add(values[columnIndex].Replace("\"", "").Trim());
|
||||
}
|
||||
|
||||
@ -6,12 +6,18 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -144,20 +144,36 @@ namespace Faturas
|
||||
|
||||
dadosTusd.Mes = int.Parse(parsedResult.dates.reading.periodUntil.AddDays(-15).ToString("yMM"));
|
||||
|
||||
string uc = new Regex("^0+").Replace(parsedResult.locationNumber, string.Empty).Replace("/", string.Empty).Replace("-", string.Empty).Replace(".", string.Empty);
|
||||
string uc = "%" + new Regex("^0+").Replace(parsedResult.locationNumber, string.Empty).Replace("/", string.Empty).Replace("-", string.Empty).Replace(".", string.Empty) + "%";
|
||||
|
||||
// Vinculo da fatura com os dados cadastrais
|
||||
int? unidades;
|
||||
string sqlQuery = $"SELECT COUNT (Cod_Smart_unidade) FROM Dados_cadastrais WHERE Codigo_Instalacao = @uc AND unidade_gerenciada";
|
||||
string sqlQuery = $"SELECT COUNT (Cod_Smart_unidade) FROM Dados_cadastrais WHERE Codigo_Instalacao LIKE @uc AND unidade_gerenciada";
|
||||
using (OleDbCommand cmd = new (sqlQuery, conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@uc", uc);
|
||||
|
||||
unidades = (int?)cmd.ExecuteScalar();
|
||||
|
||||
}
|
||||
if (unidades == 1)
|
||||
{
|
||||
sqlQuery = $"SELECT Cod_Smart_unidade, Gestao, Cliente, Unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Perfil, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs, Data_de_Migracao FROM Dados_cadastrais WHERE Codigo_Instalacao = @uc AND unidade_gerenciada";
|
||||
sqlQuery = $"SELECT Cod_Smart_unidade, Gestao, Cliente, Unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Perfil, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs, Data_de_Migracao FROM Dados_cadastrais WHERE Codigo_Instalacao LIKE @uc AND unidade_gerenciada";
|
||||
}
|
||||
else
|
||||
{
|
||||
uc = parsedResult.locationNumber;
|
||||
sqlQuery = $"SELECT COUNT (Cod_Smart_unidade) FROM Dados_cadastrais WHERE new_number LIKE @uc AND unidade_gerenciada";
|
||||
using (OleDbCommand cmd = new(sqlQuery, conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@uc", uc);
|
||||
|
||||
unidades = (int?)cmd.ExecuteScalar();
|
||||
|
||||
}
|
||||
if (unidades == 1)
|
||||
{
|
||||
sqlQuery = $"SELECT Cod_Smart_unidade, Gestao, Cliente, Unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Perfil, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs, Data_de_Migracao FROM Dados_cadastrais WHERE new_number LIKE @uc AND unidade_gerenciada";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
55
Webhook 4docs/Migrations/20260227164052_AddJsonBodyToProcessedInvoices.Designer.cs
generated
Normal file
55
Webhook 4docs/Migrations/20260227164052_AddJsonBodyToProcessedInvoices.Designer.cs
generated
Normal file
@ -0,0 +1,55 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using Webhook_4docs;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Webhook_4docs.Migrations
|
||||
{
|
||||
[DbContext(typeof(WebhookDbContext))]
|
||||
[Migration("20260227164052_AddJsonBodyToProcessedInvoices")]
|
||||
partial class AddJsonBodyToProcessedInvoices
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Webhook_4docs.ProcessedInvoices", b =>
|
||||
{
|
||||
b.Property<int>("InvoiceId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("InvoiceId"));
|
||||
|
||||
b.Property<DateTime>("DateTimeProcessed")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("InvoicePath")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("JsonBody")
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("InvoiceId");
|
||||
|
||||
b.ToTable("ProcessedInvoices");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Webhook_4docs.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddJsonBodyToProcessedInvoices : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "JsonBody",
|
||||
table: "ProcessedInvoices",
|
||||
type: "jsonb",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "JsonBody",
|
||||
table: "ProcessedInvoices");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using Webhook_4docs;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@ -16,12 +17,12 @@ namespace Webhook_4docs.Migrations
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("ProductVersion", "9.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("ProcessedInvoices", b =>
|
||||
modelBuilder.Entity("Webhook_4docs.ProcessedInvoices", b =>
|
||||
{
|
||||
b.Property<int>("InvoiceId")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -35,6 +36,9 @@ namespace Webhook_4docs.Migrations
|
||||
b.Property<string>("InvoicePath")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("JsonBody")
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.HasColumnType("text");
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Webhook_4docs
|
||||
{
|
||||
@ -9,5 +10,6 @@ namespace Webhook_4docs
|
||||
public DateTime DateTimeProcessed { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public string? InvoicePath { get; set; }
|
||||
public JsonDocument? JsonBody { get; set; }
|
||||
}
|
||||
}
|
||||
@ -104,6 +104,7 @@ namespace Webhook_4docs
|
||||
}
|
||||
|
||||
var JsonBody = JsonDocument.Parse(requestBody).RootElement;
|
||||
var JsonBodyDocument = JsonDocument.Parse(requestBody);
|
||||
string CaminhoDB = "X:/Middle/Informativo Setorial/Modelo Word/BD1_dados cadastrais e faturas.accdb";
|
||||
|
||||
if (JsonBody.TryGetProperty("requestID", out JsonElement fatura_ID_json))
|
||||
@ -195,7 +196,8 @@ namespace Webhook_4docs
|
||||
InvoiceId = Int32.Parse(fatura_ID),
|
||||
DateTimeProcessed = DateTime.UtcNow,
|
||||
Status = status,
|
||||
InvoicePath = fatura_arquivo
|
||||
InvoicePath = fatura_arquivo,
|
||||
JsonBody = JsonBodyDocument
|
||||
};
|
||||
|
||||
logger.LogInformation("Fatura incluída no BD");
|
||||
|
||||
@ -1,9 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Webhook_4docs
|
||||
{
|
||||
public class WebhookDbContext(DbContextOptions<WebhookDbContext> options) : DbContext(options)
|
||||
{
|
||||
public DbSet<ProcessedInvoices> ProcessedInvoices { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<ProcessedInvoices>()
|
||||
.Property(p => p.JsonBody)
|
||||
.HasColumnType("jsonb")
|
||||
.HasConversion(
|
||||
v => v == null ? null : v.RootElement.GetRawText(),
|
||||
v => v == null ? null : ParseJsonDocument(v));
|
||||
}
|
||||
|
||||
private static JsonDocument ParseJsonDocument(string json)
|
||||
=> JsonDocument.Parse(json);
|
||||
}
|
||||
}
|
||||
@ -17,7 +17,7 @@
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"HttpLocalhost": {
|
||||
"Url": "http://localhost:8664/"
|
||||
"Url": "http://localhost:8662/"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user