Convert TrafagSalesExporter from console app to Blazor Server app with MudBlazor UI
- Replaced console app with .NET 8 Blazor Server architecture - Added EF Core SQLite database (trafag_exporter.db) with auto-seed data - Models: HanaServer, Site, SharePointConfig, ExportSettings, ExportLog, SalesRecord - Services: HanaQueryService (with configurable dateFilter), ExcelExportService, SharePointUploadService, ExportOrchestrationService (with live status events), TimerBackgroundService (scheduled daily export) - MudBlazor UI pages: Dashboard (export status + manual trigger), Standorte (HANA server + site CRUD), Settings (SharePoint + timer config), Logs (filtered view) - SAP HANA queries unchanged (INV + CRN with exact SAP B1 table joins) - SharePoint upload via Microsoft Graph with app registration auth https://claude.ai/code/session_012heAXNMbbyxqYf2S2HrKLj
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Trafag Sales Exporter</title>
|
||||||
|
<base href="/" />
|
||||||
|
<link href="css/app.css" rel="stylesheet" />
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
|
||||||
|
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
|
||||||
|
<HeadOutlet @rendermode="@Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveServer" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<Routes @rendermode="@Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveServer" />
|
||||||
|
<script src="_framework/blazor.web.js"></script>
|
||||||
|
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
<MudThemeProvider Theme="_theme" />
|
||||||
|
<MudPopoverProvider />
|
||||||
|
<MudDialogProvider />
|
||||||
|
<MudSnackbarProvider />
|
||||||
|
|
||||||
|
<MudLayout>
|
||||||
|
<MudAppBar Elevation="1" Color="Color.Primary">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start"
|
||||||
|
OnClick="ToggleDrawer" />
|
||||||
|
<MudText Typo="Typo.h6" Class="ml-3">Trafag Sales Exporter</MudText>
|
||||||
|
</MudAppBar>
|
||||||
|
|
||||||
|
<MudDrawer @bind-Open="_drawerOpen" Elevation="2" ClipMode="DrawerClipMode.Always">
|
||||||
|
<NavMenu />
|
||||||
|
</MudDrawer>
|
||||||
|
|
||||||
|
<MudMainContent Class="pa-4">
|
||||||
|
@Body
|
||||||
|
</MudMainContent>
|
||||||
|
</MudLayout>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private bool _drawerOpen = true;
|
||||||
|
|
||||||
|
private readonly MudTheme _theme = new()
|
||||||
|
{
|
||||||
|
PaletteLight = new PaletteLight
|
||||||
|
{
|
||||||
|
Primary = "#1565C0",
|
||||||
|
Secondary = "#00897B",
|
||||||
|
AppbarBackground = "#1565C0"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void ToggleDrawer() => _drawerOpen = !_drawerOpen;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<MudNavMenu>
|
||||||
|
<MudNavLink Href="/" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Dashboard">
|
||||||
|
Dashboard
|
||||||
|
</MudNavLink>
|
||||||
|
<MudNavLink Href="/standorte" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.LocationOn">
|
||||||
|
Standorte
|
||||||
|
</MudNavLink>
|
||||||
|
<MudNavLink Href="/settings" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Settings">
|
||||||
|
Settings
|
||||||
|
</MudNavLink>
|
||||||
|
<MudNavLink Href="/logs" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.List">
|
||||||
|
Logs
|
||||||
|
</MudNavLink>
|
||||||
|
</MudNavMenu>
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
@page "/"
|
||||||
|
@using Microsoft.EntityFrameworkCore
|
||||||
|
@using TrafagSalesExporter.Data
|
||||||
|
@using TrafagSalesExporter.Services
|
||||||
|
@inject IDbContextFactory<AppDbContext> DbFactory
|
||||||
|
@inject ExportOrchestrationService Orchestrator
|
||||||
|
@inject TimerBackgroundService TimerService
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@implements IDisposable
|
||||||
|
|
||||||
|
<PageTitle>Dashboard</PageTitle>
|
||||||
|
|
||||||
|
<MudText Typo="Typo.h4" Class="mb-4">Dashboard</MudText>
|
||||||
|
|
||||||
|
<MudPaper Class="pa-4 mb-4" Elevation="1">
|
||||||
|
<MudStack Row AlignItems="AlignItems.Center" Spacing="4">
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.PlayArrow"
|
||||||
|
OnClick="ExportAll" Disabled="_anyRunning">
|
||||||
|
Alle exportieren
|
||||||
|
</MudButton>
|
||||||
|
<MudText Typo="Typo.body1">
|
||||||
|
@if (TimerService.NextRun < DateTime.MaxValue)
|
||||||
|
{
|
||||||
|
<MudIcon Icon="@Icons.Material.Filled.Schedule" Size="Size.Small" Class="mr-1" />
|
||||||
|
@($"Nächster automatischer Lauf: {TimerService.NextRun:dd.MM.yyyy HH:mm}")
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudIcon Icon="@Icons.Material.Filled.TimerOff" Size="Size.Small" Class="mr-1" />
|
||||||
|
@("Timer deaktiviert")
|
||||||
|
}
|
||||||
|
</MudText>
|
||||||
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudTable Items="_dashboardRows" Dense Hover Striped Loading="_loading">
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>Land</MudTh>
|
||||||
|
<MudTh>TSC</MudTh>
|
||||||
|
<MudTh>Schema</MudTh>
|
||||||
|
<MudTh>Server</MudTh>
|
||||||
|
<MudTh>Status</MudTh>
|
||||||
|
<MudTh>Zeilen</MudTh>
|
||||||
|
<MudTh>Letzter Lauf</MudTh>
|
||||||
|
<MudTh>Dauer</MudTh>
|
||||||
|
<MudTh>Aktion</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd>@context.Land</MudTd>
|
||||||
|
<MudTd>@context.TSC</MudTd>
|
||||||
|
<MudTd>@context.Schema</MudTd>
|
||||||
|
<MudTd>@context.ServerName</MudTd>
|
||||||
|
<MudTd>
|
||||||
|
@if (Orchestrator.IsExporting(context.SiteId))
|
||||||
|
{
|
||||||
|
<MudProgressCircular Size="Size.Small" Indeterminate Color="Color.Primary" Class="mr-1" />
|
||||||
|
<MudText Typo="Typo.caption">@Orchestrator.GetExportStatus(context.SiteId)</MudText>
|
||||||
|
}
|
||||||
|
else if (context.LastStatus == "OK")
|
||||||
|
{
|
||||||
|
<MudIcon Icon="@Icons.Material.Filled.CheckCircle" Color="Color.Success" Size="Size.Small" />
|
||||||
|
}
|
||||||
|
else if (context.LastStatus == "Error")
|
||||||
|
{
|
||||||
|
<MudTooltip Text="@context.ErrorMessage">
|
||||||
|
<MudIcon Icon="@Icons.Material.Filled.Error" Color="Color.Error" Size="Size.Small" />
|
||||||
|
</MudTooltip>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudText Typo="Typo.caption" Color="Color.Default">-</MudText>
|
||||||
|
}
|
||||||
|
</MudTd>
|
||||||
|
<MudTd>@(context.RowCount > 0 ? context.RowCount.ToString("N0") : "-")</MudTd>
|
||||||
|
<MudTd>@(context.LastRun.HasValue ? context.LastRun.Value.ToString("dd.MM.yyyy HH:mm:ss") : "-")</MudTd>
|
||||||
|
<MudTd>@(context.DurationSeconds > 0 ? $"{context.DurationSeconds:F1}s" : "-")</MudTd>
|
||||||
|
<MudTd>
|
||||||
|
<MudButton Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary"
|
||||||
|
StartIcon="@Icons.Material.Filled.FileDownload"
|
||||||
|
OnClick="() => ExportSingle(context.SiteId)"
|
||||||
|
Disabled="Orchestrator.IsExporting(context.SiteId)">
|
||||||
|
Export
|
||||||
|
</MudButton>
|
||||||
|
</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
</MudTable>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private List<DashboardRow> _dashboardRows = new();
|
||||||
|
private bool _loading = true;
|
||||||
|
private bool _anyRunning;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
Orchestrator.OnExportStatusChanged += HandleStatusChanged;
|
||||||
|
await LoadDataAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadDataAsync()
|
||||||
|
{
|
||||||
|
_loading = true;
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
var sites = await db.Sites.Include(s => s.HanaServer).Where(s => s.IsActive).ToListAsync();
|
||||||
|
var logs = await db.ExportLogs
|
||||||
|
.GroupBy(l => l.SiteId)
|
||||||
|
.Select(g => g.OrderByDescending(l => l.Timestamp).First())
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
_dashboardRows = sites.Select(s =>
|
||||||
|
{
|
||||||
|
var log = logs.FirstOrDefault(l => l.SiteId == s.Id);
|
||||||
|
return new DashboardRow
|
||||||
|
{
|
||||||
|
SiteId = s.Id,
|
||||||
|
Land = s.Land,
|
||||||
|
TSC = s.TSC,
|
||||||
|
Schema = s.Schema,
|
||||||
|
ServerName = s.HanaServer?.Name ?? "",
|
||||||
|
LastStatus = log?.Status ?? "",
|
||||||
|
RowCount = log?.RowCount ?? 0,
|
||||||
|
LastRun = log?.Timestamp,
|
||||||
|
DurationSeconds = log?.DurationSeconds ?? 0,
|
||||||
|
ErrorMessage = log?.ErrorMessage ?? ""
|
||||||
|
};
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
_anyRunning = _dashboardRows.Any(r => Orchestrator.IsExporting(r.SiteId));
|
||||||
|
_loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExportAll()
|
||||||
|
{
|
||||||
|
_anyRunning = true;
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await Orchestrator.ExportAllAsync();
|
||||||
|
await InvokeAsync(async () =>
|
||||||
|
{
|
||||||
|
await LoadDataAsync();
|
||||||
|
StateHasChanged();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Snackbar.Add("Export für alle Standorte gestartet", Severity.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExportSingle(int siteId)
|
||||||
|
{
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await Orchestrator.ExportSiteByIdAsync(siteId);
|
||||||
|
await InvokeAsync(async () =>
|
||||||
|
{
|
||||||
|
await LoadDataAsync();
|
||||||
|
StateHasChanged();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Snackbar.Add("Export gestartet", Severity.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void HandleStatusChanged()
|
||||||
|
{
|
||||||
|
await InvokeAsync(async () =>
|
||||||
|
{
|
||||||
|
_anyRunning = _dashboardRows.Any(r => Orchestrator.IsExporting(r.SiteId));
|
||||||
|
StateHasChanged();
|
||||||
|
if (!_anyRunning)
|
||||||
|
{
|
||||||
|
await LoadDataAsync();
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Orchestrator.OnExportStatusChanged -= HandleStatusChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DashboardRow
|
||||||
|
{
|
||||||
|
public int SiteId { get; set; }
|
||||||
|
public string Land { get; set; } = "";
|
||||||
|
public string TSC { get; set; } = "";
|
||||||
|
public string Schema { get; set; } = "";
|
||||||
|
public string ServerName { get; set; } = "";
|
||||||
|
public string LastStatus { get; set; } = "";
|
||||||
|
public int RowCount { get; set; }
|
||||||
|
public DateTime? LastRun { get; set; }
|
||||||
|
public double DurationSeconds { get; set; }
|
||||||
|
public string ErrorMessage { get; set; } = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
@page "/logs"
|
||||||
|
@using Microsoft.EntityFrameworkCore
|
||||||
|
@using TrafagSalesExporter.Data
|
||||||
|
@inject IDbContextFactory<AppDbContext> DbFactory
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject IDialogService DialogService
|
||||||
|
|
||||||
|
<PageTitle>Logs</PageTitle>
|
||||||
|
|
||||||
|
<MudText Typo="Typo.h4" Class="mb-4">Export Logs</MudText>
|
||||||
|
|
||||||
|
<MudPaper Class="pa-4 mb-4" Elevation="1">
|
||||||
|
<MudStack Row AlignItems="AlignItems.Center" Spacing="3">
|
||||||
|
<MudSelect @bind-Value="_filterLand" Label="Land" Clearable Dense Style="max-width:200px;">
|
||||||
|
@foreach (var land in _availableLands)
|
||||||
|
{
|
||||||
|
<MudSelectItem Value="@land">@land</MudSelectItem>
|
||||||
|
}
|
||||||
|
</MudSelect>
|
||||||
|
<MudSelect @bind-Value="_filterStatus" Label="Status" Clearable Dense Style="max-width:150px;">
|
||||||
|
<MudSelectItem Value="@("OK")">OK</MudSelectItem>
|
||||||
|
<MudSelectItem Value="@("Error")">Error</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
<MudDatePicker @bind-Date="_filterDate" Label="Datum" Clearable Dense Style="max-width:200px;" />
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="ApplyFilter"
|
||||||
|
StartIcon="@Icons.Material.Filled.FilterAlt">
|
||||||
|
Filtern
|
||||||
|
</MudButton>
|
||||||
|
<MudSpacer />
|
||||||
|
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="DeleteOldLogs"
|
||||||
|
StartIcon="@Icons.Material.Filled.DeleteSweep">
|
||||||
|
Alte Logs löschen
|
||||||
|
</MudButton>
|
||||||
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudTable Items="_logs" Dense Hover Striped Loading="_loading">
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>Zeitpunkt</MudTh>
|
||||||
|
<MudTh>Land</MudTh>
|
||||||
|
<MudTh>TSC</MudTh>
|
||||||
|
<MudTh>Status</MudTh>
|
||||||
|
<MudTh>Zeilen</MudTh>
|
||||||
|
<MudTh>Dauer</MudTh>
|
||||||
|
<MudTh>Dateiname</MudTh>
|
||||||
|
<MudTh>Fehler</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd>@context.Timestamp.ToString("dd.MM.yyyy HH:mm:ss")</MudTd>
|
||||||
|
<MudTd>@context.Land</MudTd>
|
||||||
|
<MudTd>@context.TSC</MudTd>
|
||||||
|
<MudTd>
|
||||||
|
@if (context.Status == "OK")
|
||||||
|
{
|
||||||
|
<MudChip T="string" Size="Size.Small" Color="Color.Success">OK</MudChip>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudChip T="string" Size="Size.Small" Color="Color.Error">Error</MudChip>
|
||||||
|
}
|
||||||
|
</MudTd>
|
||||||
|
<MudTd>@context.RowCount.ToString("N0")</MudTd>
|
||||||
|
<MudTd>@($"{context.DurationSeconds:F1}s")</MudTd>
|
||||||
|
<MudTd>@context.FileName</MudTd>
|
||||||
|
<MudTd>
|
||||||
|
@if (!string.IsNullOrEmpty(context.ErrorMessage))
|
||||||
|
{
|
||||||
|
<MudTooltip Text="@context.ErrorMessage">
|
||||||
|
<MudText Typo="Typo.caption" Color="Color.Error" Style="max-width:300px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:block;">
|
||||||
|
@context.ErrorMessage
|
||||||
|
</MudText>
|
||||||
|
</MudTooltip>
|
||||||
|
}
|
||||||
|
</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
</MudTable>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private List<ExportLog> _logs = new();
|
||||||
|
private List<string> _availableLands = new();
|
||||||
|
private string? _filterLand;
|
||||||
|
private string? _filterStatus;
|
||||||
|
private DateTime? _filterDate;
|
||||||
|
private bool _loading = true;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
_availableLands = await db.ExportLogs.Select(l => l.Land).Distinct().OrderBy(l => l).ToListAsync();
|
||||||
|
await LoadLogsAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadLogsAsync()
|
||||||
|
{
|
||||||
|
_loading = true;
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
IQueryable<ExportLog> query = db.ExportLogs.OrderByDescending(l => l.Timestamp);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(_filterLand))
|
||||||
|
query = query.Where(l => l.Land == _filterLand);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(_filterStatus))
|
||||||
|
query = query.Where(l => l.Status == _filterStatus);
|
||||||
|
|
||||||
|
if (_filterDate.HasValue)
|
||||||
|
query = query.Where(l => l.Timestamp.Date == _filterDate.Value.Date);
|
||||||
|
|
||||||
|
_logs = await query.Take(500).ToListAsync();
|
||||||
|
_loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ApplyFilter()
|
||||||
|
{
|
||||||
|
await LoadLogsAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DeleteOldLogs()
|
||||||
|
{
|
||||||
|
var result = await DialogService.ShowMessageBox(
|
||||||
|
"Alte Logs löschen",
|
||||||
|
"Logs älter als 90 Tage löschen?",
|
||||||
|
yesText: "Löschen", cancelText: "Abbrechen");
|
||||||
|
|
||||||
|
if (result != true) return;
|
||||||
|
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
var cutoff = DateTime.Now.AddDays(-90);
|
||||||
|
var oldLogs = await db.ExportLogs.Where(l => l.Timestamp < cutoff).ToListAsync();
|
||||||
|
db.ExportLogs.RemoveRange(oldLogs);
|
||||||
|
var count = await db.SaveChangesAsync();
|
||||||
|
await LoadLogsAsync();
|
||||||
|
Snackbar.Add($"{oldLogs.Count} alte Logs gelöscht", Severity.Info);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
@page "/settings"
|
||||||
|
@using Microsoft.EntityFrameworkCore
|
||||||
|
@using TrafagSalesExporter.Data
|
||||||
|
@using TrafagSalesExporter.Services
|
||||||
|
@inject IDbContextFactory<AppDbContext> DbFactory
|
||||||
|
@inject SharePointUploadService SpService
|
||||||
|
@inject TimerBackgroundService TimerService
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
|
||||||
|
<PageTitle>Settings</PageTitle>
|
||||||
|
|
||||||
|
<MudText Typo="Typo.h4" Class="mb-4">Settings</MudText>
|
||||||
|
|
||||||
|
@* SharePoint Config *@
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-2">SharePoint Konfiguration</MudText>
|
||||||
|
<MudPaper Class="pa-4 mb-6" Elevation="1">
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudTextField @bind-Value="_spConfig.SiteUrl" Label="Site URL" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudTextField @bind-Value="_spConfig.ExportFolder" Label="Export Folder" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudTextField @bind-Value="_spConfig.TenantId" Label="Tenant ID" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudTextField @bind-Value="_spConfig.ClientId" Label="Client ID" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudTextField @bind-Value="_spConfig.ClientSecret" Label="Client Secret" InputType="InputType.Password" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12">
|
||||||
|
<MudStack Row Spacing="2">
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SaveSharePoint"
|
||||||
|
StartIcon="@Icons.Material.Filled.Save">
|
||||||
|
Speichern
|
||||||
|
</MudButton>
|
||||||
|
<MudButton Variant="Variant.Outlined" Color="Color.Info" OnClick="TestSharePoint"
|
||||||
|
StartIcon="@Icons.Material.Filled.NetworkCheck" Disabled="_testingSp">
|
||||||
|
@if (_testingSp)
|
||||||
|
{
|
||||||
|
<MudProgressCircular Size="Size.Small" Indeterminate Class="mr-2" />
|
||||||
|
@("Teste...")
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@("SharePoint Verbindung testen")
|
||||||
|
}
|
||||||
|
</MudButton>
|
||||||
|
</MudStack>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
@* Export Settings *@
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-2">Export Einstellungen</MudText>
|
||||||
|
<MudPaper Class="pa-4 mb-6" Elevation="1">
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudTextField @bind-Value="_exportSettings.DateFilter" Label="Datum-Filter (ab)"
|
||||||
|
HelperText="Format: yyyy-MM-dd" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="2">
|
||||||
|
<MudNumericField @bind-Value="_exportSettings.TimerHour" Label="Timer Stunde" Min="0" Max="23" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="2">
|
||||||
|
<MudNumericField @bind-Value="_exportSettings.TimerMinute" Label="Timer Minute" Min="0" Max="59" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudSwitch @bind-Value="_exportSettings.TimerEnabled" Label="Timer aktiviert" Color="Color.Primary" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12">
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SaveExportSettings"
|
||||||
|
StartIcon="@Icons.Material.Filled.Save">
|
||||||
|
Speichern
|
||||||
|
</MudButton>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
@* Filename Preview *@
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-2">Dateiname Vorschau</MudText>
|
||||||
|
<MudPaper Class="pa-4" Elevation="1">
|
||||||
|
<MudText Typo="Typo.body1">
|
||||||
|
<MudIcon Icon="@Icons.Material.Filled.InsertDriveFile" Size="Size.Small" Class="mr-1" />
|
||||||
|
Sales_{"{TSC}"}_{DateTime.Now:yyyy-MM-dd}.xlsx
|
||||||
|
</MudText>
|
||||||
|
<MudText Typo="Typo.caption" Class="mt-1">
|
||||||
|
Beispiel: Sales_TRFR_@(DateTime.Now.ToString("yyyy-MM-dd")).xlsx
|
||||||
|
</MudText>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private SharePointConfig _spConfig = new();
|
||||||
|
private ExportSettings _exportSettings = new();
|
||||||
|
private bool _testingSp;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
_spConfig = await db.SharePointConfigs.FirstOrDefaultAsync() ?? new SharePointConfig();
|
||||||
|
_exportSettings = await db.ExportSettings.FirstOrDefaultAsync() ?? new ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveSharePoint()
|
||||||
|
{
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
var existing = await db.SharePointConfigs.FirstOrDefaultAsync();
|
||||||
|
if (existing is null)
|
||||||
|
{
|
||||||
|
db.SharePointConfigs.Add(_spConfig);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
existing.SiteUrl = _spConfig.SiteUrl;
|
||||||
|
existing.ExportFolder = _spConfig.ExportFolder;
|
||||||
|
existing.TenantId = _spConfig.TenantId;
|
||||||
|
existing.ClientId = _spConfig.ClientId;
|
||||||
|
existing.ClientSecret = _spConfig.ClientSecret;
|
||||||
|
}
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
Snackbar.Add("SharePoint Konfiguration gespeichert", Severity.Success);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task TestSharePoint()
|
||||||
|
{
|
||||||
|
_testingSp = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SpService.TestConnectionAsync(
|
||||||
|
_spConfig.TenantId, _spConfig.ClientId, _spConfig.ClientSecret, _spConfig.SiteUrl);
|
||||||
|
Snackbar.Add("SharePoint Verbindung erfolgreich!", Severity.Success);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Snackbar.Add($"Verbindung fehlgeschlagen: {ex.Message}", Severity.Error);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_testingSp = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveExportSettings()
|
||||||
|
{
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
var existing = await db.ExportSettings.FirstOrDefaultAsync();
|
||||||
|
if (existing is null)
|
||||||
|
{
|
||||||
|
db.ExportSettings.Add(_exportSettings);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
existing.DateFilter = _exportSettings.DateFilter;
|
||||||
|
existing.TimerHour = _exportSettings.TimerHour;
|
||||||
|
existing.TimerMinute = _exportSettings.TimerMinute;
|
||||||
|
existing.TimerEnabled = _exportSettings.TimerEnabled;
|
||||||
|
}
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
TimerService.Recalculate();
|
||||||
|
Snackbar.Add("Export Einstellungen gespeichert", Severity.Success);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,299 @@
|
|||||||
|
@page "/standorte"
|
||||||
|
@using Microsoft.EntityFrameworkCore
|
||||||
|
@using TrafagSalesExporter.Data
|
||||||
|
@using TrafagSalesExporter.Services
|
||||||
|
@inject IDbContextFactory<AppDbContext> DbFactory
|
||||||
|
@inject HanaQueryService HanaService
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject IDialogService DialogService
|
||||||
|
|
||||||
|
<PageTitle>Standorte</PageTitle>
|
||||||
|
|
||||||
|
<MudText Typo="Typo.h4" Class="mb-4">Standorte</MudText>
|
||||||
|
|
||||||
|
@* HANA Server Section *@
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-2">HANA Server</MudText>
|
||||||
|
<MudPaper Class="pa-4 mb-6" Elevation="1">
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add"
|
||||||
|
OnClick="AddServer" Class="mb-3">
|
||||||
|
Server hinzufügen
|
||||||
|
</MudButton>
|
||||||
|
|
||||||
|
<MudTable Items="_servers" Dense Hover Striped>
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>Name</MudTh>
|
||||||
|
<MudTh>Host</MudTh>
|
||||||
|
<MudTh>Port</MudTh>
|
||||||
|
<MudTh>Username</MudTh>
|
||||||
|
<MudTh>Aktionen</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd>@context.Name</MudTd>
|
||||||
|
<MudTd>@context.Host</MudTd>
|
||||||
|
<MudTd>@context.Port</MudTd>
|
||||||
|
<MudTd>@context.Username</MudTd>
|
||||||
|
<MudTd>
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small"
|
||||||
|
OnClick="() => EditServer(context)" />
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.NetworkCheck" Size="Size.Small" Color="Color.Info"
|
||||||
|
OnClick="() => TestServerConnection(context)" />
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error"
|
||||||
|
OnClick="() => DeleteServer(context)" />
|
||||||
|
</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
</MudTable>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
@* Sites Section *@
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-2">Standorte (Sites)</MudText>
|
||||||
|
<MudPaper Class="pa-4" Elevation="1">
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add"
|
||||||
|
OnClick="AddSite" Class="mb-3">
|
||||||
|
Neuen Standort hinzufügen
|
||||||
|
</MudButton>
|
||||||
|
|
||||||
|
<MudTable Items="_sites" Dense Hover Striped>
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>Land</MudTh>
|
||||||
|
<MudTh>TSC</MudTh>
|
||||||
|
<MudTh>Schema</MudTh>
|
||||||
|
<MudTh>Server</MudTh>
|
||||||
|
<MudTh>Aktiv</MudTh>
|
||||||
|
<MudTh>Aktionen</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd>@context.Land</MudTd>
|
||||||
|
<MudTd>@context.TSC</MudTd>
|
||||||
|
<MudTd>@context.Schema</MudTd>
|
||||||
|
<MudTd>@(context.HanaServer?.Name ?? "-")</MudTd>
|
||||||
|
<MudTd>
|
||||||
|
@if (context.IsActive)
|
||||||
|
{
|
||||||
|
<MudIcon Icon="@Icons.Material.Filled.CheckCircle" Color="Color.Success" Size="Size.Small" />
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudIcon Icon="@Icons.Material.Filled.Cancel" Color="Color.Default" Size="Size.Small" />
|
||||||
|
}
|
||||||
|
</MudTd>
|
||||||
|
<MudTd>
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small"
|
||||||
|
OnClick="() => EditSite(context)" />
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error"
|
||||||
|
OnClick="() => DeleteSite(context)" />
|
||||||
|
</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
</MudTable>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
@* Server Dialog *@
|
||||||
|
<MudDialog @bind-Visible="_serverDialogVisible" Options="_dialogOptions">
|
||||||
|
<TitleContent>
|
||||||
|
<MudText Typo="Typo.h6">@(_editingServer.Id == 0 ? "Server hinzufügen" : "Server bearbeiten")</MudText>
|
||||||
|
</TitleContent>
|
||||||
|
<DialogContent>
|
||||||
|
<MudTextField @bind-Value="_editingServer.Name" Label="Name" Required />
|
||||||
|
<MudTextField @bind-Value="_editingServer.Host" Label="Host" Required />
|
||||||
|
<MudNumericField @bind-Value="_editingServer.Port" Label="Port" />
|
||||||
|
<MudTextField @bind-Value="_editingServer.Username" Label="Username" />
|
||||||
|
<MudTextField @bind-Value="_editingServer.Password" Label="Password" InputType="InputType.Password" />
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<MudButton OnClick="() => _serverDialogVisible = false">Abbrechen</MudButton>
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SaveServer">Speichern</MudButton>
|
||||||
|
</DialogActions>
|
||||||
|
</MudDialog>
|
||||||
|
|
||||||
|
@* Site Dialog *@
|
||||||
|
<MudDialog @bind-Visible="_siteDialogVisible" Options="_dialogOptions">
|
||||||
|
<TitleContent>
|
||||||
|
<MudText Typo="Typo.h6">@(_editingSite.Id == 0 ? "Standort hinzufügen" : "Standort bearbeiten")</MudText>
|
||||||
|
</TitleContent>
|
||||||
|
<DialogContent>
|
||||||
|
<MudSelect @bind-Value="_editingSite.HanaServerId" Label="Server" Required>
|
||||||
|
@foreach (var s in _servers)
|
||||||
|
{
|
||||||
|
<MudSelectItem Value="s.Id">@s.Name</MudSelectItem>
|
||||||
|
}
|
||||||
|
</MudSelect>
|
||||||
|
<MudTextField @bind-Value="_editingSite.Schema" Label="Schema" Required />
|
||||||
|
<MudTextField @bind-Value="_editingSite.TSC" Label="TSC" Required />
|
||||||
|
<MudTextField @bind-Value="_editingSite.Land" Label="Land" Required />
|
||||||
|
<MudCheckBox @bind-Value="_editingSite.IsActive" Label="Aktiv" />
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<MudButton OnClick="() => _siteDialogVisible = false">Abbrechen</MudButton>
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SaveSite">Speichern</MudButton>
|
||||||
|
</DialogActions>
|
||||||
|
</MudDialog>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private List<HanaServer> _servers = new();
|
||||||
|
private List<Site> _sites = new();
|
||||||
|
private HanaServer _editingServer = new();
|
||||||
|
private Site _editingSite = new();
|
||||||
|
private bool _serverDialogVisible;
|
||||||
|
private bool _siteDialogVisible;
|
||||||
|
private readonly DialogOptions _dialogOptions = new() { MaxWidth = MaxWidth.Small, FullWidth = true };
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await LoadDataAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadDataAsync()
|
||||||
|
{
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
_servers = await db.HanaServers.OrderBy(s => s.Name).ToListAsync();
|
||||||
|
_sites = await db.Sites.Include(s => s.HanaServer).OrderBy(s => s.Land).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server CRUD
|
||||||
|
private void AddServer()
|
||||||
|
{
|
||||||
|
_editingServer = new HanaServer { Port = 30015 };
|
||||||
|
_serverDialogVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EditServer(HanaServer server)
|
||||||
|
{
|
||||||
|
_editingServer = new HanaServer
|
||||||
|
{
|
||||||
|
Id = server.Id,
|
||||||
|
Name = server.Name,
|
||||||
|
Host = server.Host,
|
||||||
|
Port = server.Port,
|
||||||
|
Username = server.Username,
|
||||||
|
Password = server.Password
|
||||||
|
};
|
||||||
|
_serverDialogVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveServer()
|
||||||
|
{
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
if (_editingServer.Id == 0)
|
||||||
|
{
|
||||||
|
db.HanaServers.Add(_editingServer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var existing = await db.HanaServers.FindAsync(_editingServer.Id);
|
||||||
|
if (existing is not null)
|
||||||
|
{
|
||||||
|
existing.Name = _editingServer.Name;
|
||||||
|
existing.Host = _editingServer.Host;
|
||||||
|
existing.Port = _editingServer.Port;
|
||||||
|
existing.Username = _editingServer.Username;
|
||||||
|
existing.Password = _editingServer.Password;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
_serverDialogVisible = false;
|
||||||
|
await LoadDataAsync();
|
||||||
|
Snackbar.Add("Server gespeichert", Severity.Success);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DeleteServer(HanaServer server)
|
||||||
|
{
|
||||||
|
var result = await DialogService.ShowMessageBox(
|
||||||
|
"Server löschen",
|
||||||
|
$"Server '{server.Name}' wirklich löschen?",
|
||||||
|
yesText: "Löschen", cancelText: "Abbrechen");
|
||||||
|
|
||||||
|
if (result != true) return;
|
||||||
|
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
var entity = await db.HanaServers.FindAsync(server.Id);
|
||||||
|
if (entity is not null)
|
||||||
|
{
|
||||||
|
db.HanaServers.Remove(entity);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
await LoadDataAsync();
|
||||||
|
Snackbar.Add("Server gelöscht", Severity.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task TestServerConnection(HanaServer server)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.Run(() => HanaService.TestConnection(server.Host, server.Port, server.Username, server.Password));
|
||||||
|
Snackbar.Add($"Verbindung zu '{server.Name}' erfolgreich!", Severity.Success);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Snackbar.Add($"Verbindung fehlgeschlagen: {ex.Message}", Severity.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Site CRUD
|
||||||
|
private void AddSite()
|
||||||
|
{
|
||||||
|
_editingSite = new Site
|
||||||
|
{
|
||||||
|
IsActive = true,
|
||||||
|
HanaServerId = _servers.FirstOrDefault()?.Id ?? 0
|
||||||
|
};
|
||||||
|
_siteDialogVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EditSite(Site site)
|
||||||
|
{
|
||||||
|
_editingSite = new Site
|
||||||
|
{
|
||||||
|
Id = site.Id,
|
||||||
|
HanaServerId = site.HanaServerId,
|
||||||
|
Schema = site.Schema,
|
||||||
|
TSC = site.TSC,
|
||||||
|
Land = site.Land,
|
||||||
|
IsActive = site.IsActive
|
||||||
|
};
|
||||||
|
_siteDialogVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveSite()
|
||||||
|
{
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
if (_editingSite.Id == 0)
|
||||||
|
{
|
||||||
|
db.Sites.Add(_editingSite);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var existing = await db.Sites.FindAsync(_editingSite.Id);
|
||||||
|
if (existing is not null)
|
||||||
|
{
|
||||||
|
existing.HanaServerId = _editingSite.HanaServerId;
|
||||||
|
existing.Schema = _editingSite.Schema;
|
||||||
|
existing.TSC = _editingSite.TSC;
|
||||||
|
existing.Land = _editingSite.Land;
|
||||||
|
existing.IsActive = _editingSite.IsActive;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
_siteDialogVisible = false;
|
||||||
|
await LoadDataAsync();
|
||||||
|
Snackbar.Add("Standort gespeichert", Severity.Success);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DeleteSite(Site site)
|
||||||
|
{
|
||||||
|
var result = await DialogService.ShowMessageBox(
|
||||||
|
"Standort löschen",
|
||||||
|
$"Standort '{site.Land}' wirklich löschen?",
|
||||||
|
yesText: "Löschen", cancelText: "Abbrechen");
|
||||||
|
|
||||||
|
if (result != true) return;
|
||||||
|
|
||||||
|
using var db = await DbFactory.CreateDbContextAsync();
|
||||||
|
var entity = await db.Sites.FindAsync(site.Id);
|
||||||
|
if (entity is not null)
|
||||||
|
{
|
||||||
|
db.Sites.Remove(entity);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
await LoadDataAsync();
|
||||||
|
Snackbar.Add("Standort gelöscht", Severity.Info);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<Router AppAssembly="typeof(Program).Assembly">
|
||||||
|
<Found Context="routeData">
|
||||||
|
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
|
||||||
|
<FocusOnNavigate RouteData="routeData" Selector="h1" />
|
||||||
|
</Found>
|
||||||
|
</Router>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
@using System.Net.Http
|
||||||
|
@using Microsoft.AspNetCore.Components.Forms
|
||||||
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
|
@using Microsoft.AspNetCore.Components.Web
|
||||||
|
@using Microsoft.JSInterop
|
||||||
|
@using MudBlazor
|
||||||
|
@using TrafagSalesExporter.Components
|
||||||
|
@using TrafagSalesExporter.Components.Layout
|
||||||
|
@using TrafagSalesExporter.Models
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using TrafagSalesExporter.Models;
|
||||||
|
|
||||||
|
namespace TrafagSalesExporter.Data;
|
||||||
|
|
||||||
|
public class AppDbContext : DbContext
|
||||||
|
{
|
||||||
|
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||||||
|
|
||||||
|
public DbSet<HanaServer> HanaServers => Set<HanaServer>();
|
||||||
|
public DbSet<Site> Sites => Set<Site>();
|
||||||
|
public DbSet<SharePointConfig> SharePointConfigs => Set<SharePointConfig>();
|
||||||
|
public DbSet<ExportSettings> ExportSettings => Set<ExportSettings>();
|
||||||
|
public DbSet<ExportLog> ExportLogs => Set<ExportLog>();
|
||||||
|
|
||||||
|
public static void SeedIfEmpty(AppDbContext db)
|
||||||
|
{
|
||||||
|
if (db.HanaServers.Any()) return;
|
||||||
|
|
||||||
|
var serverInternal = new HanaServer { Name = "Internal", Host = "travtrp0", Port = 30015, Username = "", Password = "" };
|
||||||
|
var serverIndia = new HanaServer { Name = "India", Host = "20.197.20.60", Port = 30015, Username = "", Password = "" };
|
||||||
|
db.HanaServers.AddRange(serverInternal, serverIndia);
|
||||||
|
db.SaveChanges();
|
||||||
|
|
||||||
|
db.Sites.AddRange(
|
||||||
|
new Site { HanaServerId = serverInternal.Id, Schema = "fr01_p", TSC = "TRFR", Land = "Frankreich", IsActive = true },
|
||||||
|
new Site { HanaServerId = serverInternal.Id, Schema = "it01_p", TSC = "TRIT", Land = "Italien", IsActive = true },
|
||||||
|
new Site { HanaServerId = serverInternal.Id, Schema = "us01_p", TSC = "TRUS", Land = "USA", IsActive = true },
|
||||||
|
new Site { HanaServerId = serverIndia.Id, Schema = "TRAFAG_LIVE", TSC = "TRIN", Land = "Indien", IsActive = true }
|
||||||
|
);
|
||||||
|
|
||||||
|
db.SharePointConfigs.Add(new SharePointConfig
|
||||||
|
{
|
||||||
|
SiteUrl = "https://trafagag.sharepoint.com/sites/WorldwideBIPlatform",
|
||||||
|
ExportFolder = "/Shared Documents/Exports/",
|
||||||
|
TenantId = "",
|
||||||
|
ClientId = "",
|
||||||
|
ClientSecret = ""
|
||||||
|
});
|
||||||
|
|
||||||
|
db.ExportSettings.Add(new ExportSettings
|
||||||
|
{
|
||||||
|
DateFilter = "2025-01-01",
|
||||||
|
TimerHour = 3,
|
||||||
|
TimerMinute = 0,
|
||||||
|
TimerEnabled = true
|
||||||
|
});
|
||||||
|
|
||||||
|
db.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace TrafagSalesExporter.Models;
|
||||||
|
|
||||||
|
public class ExportLog
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public DateTime Timestamp { get; set; }
|
||||||
|
public int SiteId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(SiteId))]
|
||||||
|
public Site? Site { get; set; }
|
||||||
|
|
||||||
|
public string Land { get; set; } = string.Empty;
|
||||||
|
public string TSC { get; set; } = string.Empty;
|
||||||
|
public string Status { get; set; } = string.Empty;
|
||||||
|
public int RowCount { get; set; }
|
||||||
|
public string? ErrorMessage { get; set; }
|
||||||
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
public double DurationSeconds { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace TrafagSalesExporter.Models;
|
||||||
|
|
||||||
|
public class ExportSettings
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string DateFilter { get; set; } = "2025-01-01";
|
||||||
|
public int TimerHour { get; set; } = 3;
|
||||||
|
public int TimerMinute { get; set; }
|
||||||
|
public bool TimerEnabled { get; set; } = true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace TrafagSalesExporter.Models;
|
||||||
|
|
||||||
|
public class HanaServer
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Host { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public int Port { get; set; } = 30015;
|
||||||
|
|
||||||
|
public string Username { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace TrafagSalesExporter.Models;
|
||||||
|
|
||||||
|
public class SharePointConfig
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string SiteUrl { get; set; } = string.Empty;
|
||||||
|
public string ExportFolder { get; set; } = string.Empty;
|
||||||
|
public string TenantId { get; set; } = string.Empty;
|
||||||
|
public string ClientId { get; set; } = string.Empty;
|
||||||
|
public string ClientSecret { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace TrafagSalesExporter.Models;
|
||||||
|
|
||||||
|
public class Site
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public int HanaServerId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(HanaServerId))]
|
||||||
|
public HanaServer? HanaServer { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Schema { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string TSC { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Land { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public bool IsActive { get; set; } = true;
|
||||||
|
}
|
||||||
@@ -1,100 +1,44 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using MudBlazor.Services;
|
||||||
|
using TrafagSalesExporter.Data;
|
||||||
using TrafagSalesExporter.Services;
|
using TrafagSalesExporter.Services;
|
||||||
|
|
||||||
namespace TrafagSalesExporter;
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
internal static class Program
|
builder.Services.AddRazorComponents()
|
||||||
|
.AddInteractiveServerComponents();
|
||||||
|
|
||||||
|
builder.Services.AddMudServices();
|
||||||
|
|
||||||
|
builder.Services.AddDbContextFactory<AppDbContext>(options =>
|
||||||
|
options.UseSqlite("Data Source=trafag_exporter.db"));
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<HanaQueryService>();
|
||||||
|
builder.Services.AddSingleton<ExcelExportService>();
|
||||||
|
builder.Services.AddSingleton<SharePointUploadService>();
|
||||||
|
builder.Services.AddSingleton<ExportOrchestrationService>();
|
||||||
|
builder.Services.AddSingleton<TimerBackgroundService>();
|
||||||
|
builder.Services.AddHostedService(sp => sp.GetRequiredService<TimerBackgroundService>());
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
private static async Task Main()
|
var dbFactory = scope.ServiceProvider.GetRequiredService<IDbContextFactory<AppDbContext>>();
|
||||||
{
|
using var db = await dbFactory.CreateDbContextAsync();
|
||||||
var config = new ConfigurationBuilder()
|
await db.Database.EnsureCreatedAsync();
|
||||||
.SetBasePath(AppContext.BaseDirectory)
|
AppDbContext.SeedIfEmpty(db);
|
||||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
var appConfig = config.Get<AppConfig>() ?? throw new InvalidOperationException("Konfiguration konnte nicht geladen werden.");
|
|
||||||
|
|
||||||
var hanaService = new HanaQueryService();
|
|
||||||
var excelService = new ExcelExportService();
|
|
||||||
var sharePointService = new SharePointUploadService(
|
|
||||||
appConfig.SharePoint.TenantId,
|
|
||||||
appConfig.SharePoint.ClientId,
|
|
||||||
appConfig.SharePoint.ClientSecret,
|
|
||||||
appConfig.SharePoint.SiteUrl,
|
|
||||||
appConfig.SharePoint.ExportFolder);
|
|
||||||
|
|
||||||
var outputDir = Path.Combine(AppContext.BaseDirectory, "output");
|
|
||||||
|
|
||||||
foreach (var site in appConfig.Sites)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Log($"Starte Standort: {site.Land} ({site.Schema})");
|
|
||||||
|
|
||||||
if (!appConfig.HanaServers.TryGetValue(site.Server, out var serverConfig))
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"HANA Server-Konfiguration '{site.Server}' nicht gefunden.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var records = hanaService.GetSalesRecords(
|
|
||||||
serverConfig.Host,
|
|
||||||
serverConfig.Port,
|
|
||||||
serverConfig.Username,
|
|
||||||
serverConfig.Password,
|
|
||||||
site.Schema,
|
|
||||||
site.TSC,
|
|
||||||
site.Land);
|
|
||||||
|
|
||||||
var filePath = excelService.CreateExcelFile(outputDir, site.TSC, DateTime.UtcNow.Date, records);
|
|
||||||
Log($"Excel erzeugt: {filePath}");
|
|
||||||
|
|
||||||
await sharePointService.UploadAsync(site.Land, filePath);
|
|
||||||
Log($"Upload abgeschlossen: {site.Land}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log($"Fehler bei Standort {site.Land}: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Log("Export beendet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void Log(string message)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AppConfig
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
public Dictionary<string, HanaServerConfig> HanaServers { get; set; } = new();
|
app.UseHsts();
|
||||||
public List<SiteConfig> Sites { get; set; } = new();
|
|
||||||
public SharePointConfig SharePoint { get; set; } = new();
|
|
||||||
public string DateFilter { get; set; } = "2025-01-01";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class HanaServerConfig
|
app.UseStaticFiles();
|
||||||
{
|
app.UseAntiforgery();
|
||||||
public string Host { get; set; } = string.Empty;
|
|
||||||
public int Port { get; set; }
|
|
||||||
public string Username { get; set; } = string.Empty;
|
|
||||||
public string Password { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SiteConfig
|
app.MapRazorComponents<TrafagSalesExporter.Components.App>()
|
||||||
{
|
.AddInteractiveServerRenderMode();
|
||||||
public string Schema { get; set; } = string.Empty;
|
|
||||||
public string Server { get; set; } = string.Empty;
|
|
||||||
public string TSC { get; set; } = string.Empty;
|
|
||||||
public string Land { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SharePointConfig
|
app.Run();
|
||||||
{
|
|
||||||
public string SiteUrl { get; set; } = string.Empty;
|
|
||||||
public string ExportFolder { get; set; } = string.Empty;
|
|
||||||
public string TenantId { get; set; } = string.Empty;
|
|
||||||
public string ClientId { get; set; } = string.Empty;
|
|
||||||
public string ClientSecret { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,163 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using TrafagSalesExporter.Data;
|
||||||
|
using TrafagSalesExporter.Models;
|
||||||
|
|
||||||
|
namespace TrafagSalesExporter.Services;
|
||||||
|
|
||||||
|
public class ExportOrchestrationService
|
||||||
|
{
|
||||||
|
private readonly IDbContextFactory<AppDbContext> _dbFactory;
|
||||||
|
private readonly HanaQueryService _hanaService;
|
||||||
|
private readonly ExcelExportService _excelService;
|
||||||
|
private readonly SharePointUploadService _sharePointService;
|
||||||
|
private readonly ILogger<ExportOrchestrationService> _logger;
|
||||||
|
|
||||||
|
public event Action? OnExportStatusChanged;
|
||||||
|
|
||||||
|
private readonly Dictionary<int, string> _runningExports = new();
|
||||||
|
private readonly object _lock = new();
|
||||||
|
|
||||||
|
public ExportOrchestrationService(
|
||||||
|
IDbContextFactory<AppDbContext> dbFactory,
|
||||||
|
HanaQueryService hanaService,
|
||||||
|
ExcelExportService excelService,
|
||||||
|
SharePointUploadService sharePointService,
|
||||||
|
ILogger<ExportOrchestrationService> logger)
|
||||||
|
{
|
||||||
|
_dbFactory = dbFactory;
|
||||||
|
_hanaService = hanaService;
|
||||||
|
_excelService = excelService;
|
||||||
|
_sharePointService = sharePointService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsExporting(int siteId)
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
return _runningExports.ContainsKey(siteId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetExportStatus(int siteId)
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
return _runningExports.TryGetValue(siteId, out var status) ? status : string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ExportAllAsync()
|
||||||
|
{
|
||||||
|
using var db = await _dbFactory.CreateDbContextAsync();
|
||||||
|
var sites = await db.Sites.Include(s => s.HanaServer).Where(s => s.IsActive).ToListAsync();
|
||||||
|
foreach (var site in sites)
|
||||||
|
{
|
||||||
|
await ExportSiteAsync(site);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ExportSiteByIdAsync(int siteId)
|
||||||
|
{
|
||||||
|
using var db = await _dbFactory.CreateDbContextAsync();
|
||||||
|
var site = await db.Sites.Include(s => s.HanaServer).FirstOrDefaultAsync(s => s.Id == siteId);
|
||||||
|
if (site is null) return;
|
||||||
|
await ExportSiteAsync(site);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExportSiteAsync(Site site)
|
||||||
|
{
|
||||||
|
if (site.HanaServer is null) return;
|
||||||
|
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
if (_runningExports.ContainsKey(site.Id)) return;
|
||||||
|
_runningExports[site.Id] = "HANA Abfrage...";
|
||||||
|
}
|
||||||
|
NotifyChanged();
|
||||||
|
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
var log = new ExportLog
|
||||||
|
{
|
||||||
|
Timestamp = DateTime.Now,
|
||||||
|
SiteId = site.Id,
|
||||||
|
Land = site.Land,
|
||||||
|
TSC = site.TSC
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var db = await _dbFactory.CreateDbContextAsync();
|
||||||
|
var settings = await db.ExportSettings.FirstOrDefaultAsync() ?? new ExportSettings();
|
||||||
|
var spConfig = await db.SharePointConfigs.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
UpdateStatus(site.Id, "HANA Abfrage...");
|
||||||
|
var records = await Task.Run(() => _hanaService.GetSalesRecords(
|
||||||
|
site.HanaServer.Host, site.HanaServer.Port,
|
||||||
|
site.HanaServer.Username, site.HanaServer.Password,
|
||||||
|
site.Schema, site.TSC, site.Land, settings.DateFilter));
|
||||||
|
|
||||||
|
UpdateStatus(site.Id, "Excel erstellen...");
|
||||||
|
var outputDir = Path.Combine(AppContext.BaseDirectory, "output");
|
||||||
|
var filePath = _excelService.CreateExcelFile(outputDir, site.TSC, DateTime.UtcNow.Date, records);
|
||||||
|
var fileName = Path.GetFileName(filePath);
|
||||||
|
|
||||||
|
if (spConfig is not null &&
|
||||||
|
!string.IsNullOrWhiteSpace(spConfig.TenantId) &&
|
||||||
|
!string.IsNullOrWhiteSpace(spConfig.ClientId) &&
|
||||||
|
!string.IsNullOrWhiteSpace(spConfig.ClientSecret))
|
||||||
|
{
|
||||||
|
UpdateStatus(site.Id, "SharePoint Upload...");
|
||||||
|
await _sharePointService.UploadAsync(
|
||||||
|
spConfig.TenantId, spConfig.ClientId, spConfig.ClientSecret,
|
||||||
|
spConfig.SiteUrl, spConfig.ExportFolder, site.Land, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
log.Status = "OK";
|
||||||
|
log.RowCount = records.Count;
|
||||||
|
log.FileName = fileName;
|
||||||
|
log.DurationSeconds = sw.Elapsed.TotalSeconds;
|
||||||
|
|
||||||
|
_logger.LogInformation("Export OK: {Land} ({TSC}) - {Rows} Zeilen in {Duration:F1}s",
|
||||||
|
site.Land, site.TSC, records.Count, sw.Elapsed.TotalSeconds);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
sw.Stop();
|
||||||
|
log.Status = "Error";
|
||||||
|
log.ErrorMessage = ex.Message;
|
||||||
|
log.FileName = string.Empty;
|
||||||
|
log.DurationSeconds = sw.Elapsed.TotalSeconds;
|
||||||
|
|
||||||
|
_logger.LogError(ex, "Export Fehler: {Land} ({TSC})", site.Land, site.TSC);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
using var db = await _dbFactory.CreateDbContextAsync();
|
||||||
|
db.ExportLogs.Add(log);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
_runningExports.Remove(site.Id);
|
||||||
|
}
|
||||||
|
NotifyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateStatus(int siteId, string status)
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
_runningExports[siteId] = status;
|
||||||
|
}
|
||||||
|
NotifyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NotifyChanged()
|
||||||
|
{
|
||||||
|
OnExportStatusChanged?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,8 @@ namespace TrafagSalesExporter.Services;
|
|||||||
|
|
||||||
public class HanaQueryService
|
public class HanaQueryService
|
||||||
{
|
{
|
||||||
public List<SalesRecord> GetSalesRecords(string host, int port, string username, string password, string schema, string tsc, string land)
|
public List<SalesRecord> GetSalesRecords(string host, int port, string username, string password,
|
||||||
|
string schema, string tsc, string land, string dateFilter)
|
||||||
{
|
{
|
||||||
var connectionString = $"ServerNode={host}:{port};UserName={username};Password={password}";
|
var connectionString = $"ServerNode={host}:{port};UserName={username};Password={password}";
|
||||||
var result = new List<SalesRecord>();
|
var result = new List<SalesRecord>();
|
||||||
@@ -13,8 +14,8 @@ public class HanaQueryService
|
|||||||
using var connection = new HanaConnection(connectionString);
|
using var connection = new HanaConnection(connectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
var invoiceQuery = GetInvoiceQuery(schema, tsc);
|
var invoiceQuery = GetInvoiceQuery(schema, tsc, dateFilter);
|
||||||
var creditNoteQuery = GetCreditNoteQuery(schema, tsc);
|
var creditNoteQuery = GetCreditNoteQuery(schema, tsc, dateFilter);
|
||||||
|
|
||||||
result.AddRange(ReadRecords(connection, invoiceQuery, land));
|
result.AddRange(ReadRecords(connection, invoiceQuery, land));
|
||||||
result.AddRange(ReadRecords(connection, creditNoteQuery, land));
|
result.AddRange(ReadRecords(connection, creditNoteQuery, land));
|
||||||
@@ -31,6 +32,13 @@ public class HanaQueryService
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TestConnection(string host, int port, string username, string password)
|
||||||
|
{
|
||||||
|
var connectionString = $"ServerNode={host}:{port};UserName={username};Password={password}";
|
||||||
|
using var connection = new HanaConnection(connectionString);
|
||||||
|
connection.Open();
|
||||||
|
}
|
||||||
|
|
||||||
private static List<SalesRecord> ReadRecords(HanaConnection connection, string query, string land)
|
private static List<SalesRecord> ReadRecords(HanaConnection connection, string query, string land)
|
||||||
{
|
{
|
||||||
var records = new List<SalesRecord>();
|
var records = new List<SalesRecord>();
|
||||||
@@ -74,7 +82,7 @@ public class HanaQueryService
|
|||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetInvoiceQuery(string schema, string tsc) => $@"
|
private static string GetInvoiceQuery(string schema, string tsc, string dateFilter) => $@"
|
||||||
SELECT
|
SELECT
|
||||||
CURRENT_TIMESTAMP AS extraction_date,
|
CURRENT_TIMESTAMP AS extraction_date,
|
||||||
'{tsc}' AS tsc,
|
'{tsc}' AS tsc,
|
||||||
@@ -119,10 +127,10 @@ LEFT JOIN {schema}.""OCRD"" sup ON itm.""CardCode"" = sup.""CardCode""
|
|||||||
LEFT JOIN {schema}.""CRD1"" sup_adr ON itm.""CardCode"" = sup_adr.""CardCode""
|
LEFT JOIN {schema}.""CRD1"" sup_adr ON itm.""CardCode"" = sup_adr.""CardCode""
|
||||||
AND sup_adr.""AdresType"" = 'B'
|
AND sup_adr.""AdresType"" = 'B'
|
||||||
LEFT JOIN {schema}.""OSLP"" emp ON h.""SlpCode"" = emp.""SlpCode""
|
LEFT JOIN {schema}.""OSLP"" emp ON h.""SlpCode"" = emp.""SlpCode""
|
||||||
WHERE h.""CANCELED"" = 'N' AND h.""DocDate"" >= '2025-01-01'
|
WHERE h.""CANCELED"" = 'N' AND h.""DocDate"" >= '{dateFilter}'
|
||||||
ORDER BY h.""DocDate"" DESC, h.""DocNum"", p.""LineNum""";
|
ORDER BY h.""DocDate"" DESC, h.""DocNum"", p.""LineNum""";
|
||||||
|
|
||||||
private static string GetCreditNoteQuery(string schema, string tsc) => $@"
|
private static string GetCreditNoteQuery(string schema, string tsc, string dateFilter) => $@"
|
||||||
SELECT
|
SELECT
|
||||||
CURRENT_TIMESTAMP AS extraction_date,
|
CURRENT_TIMESTAMP AS extraction_date,
|
||||||
'{tsc}' AS tsc,
|
'{tsc}' AS tsc,
|
||||||
@@ -162,6 +170,6 @@ LEFT JOIN {schema}.""OCRD"" sup ON itm.""CardCode"" = sup.""CardCode""
|
|||||||
LEFT JOIN {schema}.""CRD1"" sup_adr ON itm.""CardCode"" = sup_adr.""CardCode""
|
LEFT JOIN {schema}.""CRD1"" sup_adr ON itm.""CardCode"" = sup_adr.""CardCode""
|
||||||
AND sup_adr.""AdresType"" = 'B'
|
AND sup_adr.""AdresType"" = 'B'
|
||||||
LEFT JOIN {schema}.""OSLP"" emp ON h.""SlpCode"" = emp.""SlpCode""
|
LEFT JOIN {schema}.""OSLP"" emp ON h.""SlpCode"" = emp.""SlpCode""
|
||||||
WHERE h.""CANCELED"" = 'N' AND h.""DocDate"" >= '2025-01-01'
|
WHERE h.""CANCELED"" = 'N' AND h.""DocDate"" >= '{dateFilter}'
|
||||||
ORDER BY h.""DocDate"" DESC, h.""DocNum"", p.""LineNum""";
|
ORDER BY h.""DocDate"" DESC, h.""DocNum"", p.""LineNum""";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,40 +5,41 @@ namespace TrafagSalesExporter.Services;
|
|||||||
|
|
||||||
public class SharePointUploadService
|
public class SharePointUploadService
|
||||||
{
|
{
|
||||||
private readonly GraphServiceClient _graphClient;
|
public async Task UploadAsync(string tenantId, string clientId, string clientSecret,
|
||||||
private readonly string _siteUrl;
|
string siteUrl, string exportFolder, string land, string localFilePath)
|
||||||
private readonly string _exportFolder;
|
|
||||||
|
|
||||||
public SharePointUploadService(string tenantId, string clientId, string clientSecret, string siteUrl, string exportFolder)
|
|
||||||
{
|
{
|
||||||
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
|
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
|
||||||
_graphClient = new GraphServiceClient(credential, ["https://graph.microsoft.com/.default"]);
|
var graphClient = new GraphServiceClient(credential, ["https://graph.microsoft.com/.default"]);
|
||||||
_siteUrl = siteUrl;
|
|
||||||
_exportFolder = exportFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UploadAsync(string land, string localFilePath)
|
var uri = new Uri(siteUrl);
|
||||||
{
|
|
||||||
var uri = new Uri(_siteUrl);
|
|
||||||
var sitePath = uri.AbsolutePath;
|
var sitePath = uri.AbsolutePath;
|
||||||
var site = await _graphClient.Sites[$"{uri.Host}:{sitePath}"].GetAsync();
|
var site = await graphClient.Sites[$"{uri.Host}:{sitePath}"].GetAsync();
|
||||||
|
|
||||||
if (site?.Id is null)
|
if (site?.Id is null)
|
||||||
{
|
|
||||||
throw new InvalidOperationException("SharePoint Site konnte nicht gefunden werden.");
|
throw new InvalidOperationException("SharePoint Site konnte nicht gefunden werden.");
|
||||||
}
|
|
||||||
|
|
||||||
var drive = await _graphClient.Sites[site.Id].Drive.GetAsync();
|
var drive = await graphClient.Sites[site.Id].Drive.GetAsync();
|
||||||
if (drive?.Id is null)
|
if (drive?.Id is null)
|
||||||
{
|
|
||||||
throw new InvalidOperationException("SharePoint Dokumentenbibliothek konnte nicht gefunden werden.");
|
throw new InvalidOperationException("SharePoint Dokumentenbibliothek konnte nicht gefunden werden.");
|
||||||
}
|
|
||||||
|
|
||||||
var fileName = Path.GetFileName(localFilePath);
|
var fileName = Path.GetFileName(localFilePath);
|
||||||
var folderPath = $"{_exportFolder.Trim('/').Trim()}";
|
var folderPath = exportFolder.Trim('/').Trim();
|
||||||
var remotePath = $"{folderPath}/{land}/{fileName}";
|
var remotePath = $"{folderPath}/{land}/{fileName}";
|
||||||
|
|
||||||
await using var stream = File.OpenRead(localFilePath);
|
await using var stream = File.OpenRead(localFilePath);
|
||||||
await _graphClient.Drives[drive.Id].Root.ItemWithPath(remotePath).Content.PutAsync(stream);
|
await graphClient.Drives[drive.Id].Root.ItemWithPath(remotePath).Content.PutAsync(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task TestConnectionAsync(string tenantId, string clientId, string clientSecret, string siteUrl)
|
||||||
|
{
|
||||||
|
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
|
||||||
|
var graphClient = new GraphServiceClient(credential, ["https://graph.microsoft.com/.default"]);
|
||||||
|
|
||||||
|
var uri = new Uri(siteUrl);
|
||||||
|
var sitePath = uri.AbsolutePath;
|
||||||
|
var site = await graphClient.Sites[$"{uri.Host}:{sitePath}"].GetAsync();
|
||||||
|
|
||||||
|
if (site?.Id is null)
|
||||||
|
throw new InvalidOperationException("SharePoint Site konnte nicht gefunden werden.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using TrafagSalesExporter.Data;
|
||||||
|
|
||||||
|
namespace TrafagSalesExporter.Services;
|
||||||
|
|
||||||
|
public class TimerBackgroundService : BackgroundService
|
||||||
|
{
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
private readonly ILogger<TimerBackgroundService> _logger;
|
||||||
|
private DateTime _nextRun = DateTime.MaxValue;
|
||||||
|
|
||||||
|
public DateTime NextRun => _nextRun;
|
||||||
|
|
||||||
|
public TimerBackgroundService(IServiceProvider serviceProvider, ILogger<TimerBackgroundService> logger)
|
||||||
|
{
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Recalculate()
|
||||||
|
{
|
||||||
|
_ = RecalculateNextRunAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RecalculateNextRunAsync()
|
||||||
|
{
|
||||||
|
var dbFactory = _serviceProvider.GetRequiredService<IDbContextFactory<AppDbContext>>();
|
||||||
|
using var db = await dbFactory.CreateDbContextAsync();
|
||||||
|
var settings = await db.ExportSettings.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (settings is null || !settings.TimerEnabled)
|
||||||
|
{
|
||||||
|
_nextRun = DateTime.MaxValue;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var now = DateTime.Now;
|
||||||
|
var todayRun = new DateTime(now.Year, now.Month, now.Day, settings.TimerHour, settings.TimerMinute, 0);
|
||||||
|
_nextRun = todayRun <= now ? todayRun.AddDays(1) : todayRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
await RecalculateNextRunAsync();
|
||||||
|
|
||||||
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(30), stoppingToken);
|
||||||
|
|
||||||
|
if (DateTime.Now < _nextRun) continue;
|
||||||
|
|
||||||
|
_logger.LogInformation("Timer-Export gestartet um {Time}", DateTime.Now);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var orchestrator = _serviceProvider.GetRequiredService<ExportOrchestrationService>();
|
||||||
|
await orchestrator.ExportAllAsync();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Fehler beim Timer-Export");
|
||||||
|
}
|
||||||
|
|
||||||
|
await RecalculateNextRunAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
@@ -8,17 +7,14 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ClosedXML" Version="0.104.2" />
|
<PackageReference Include="ClosedXML" Version="0.104.2" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.11">
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Graph" Version="5.80.0" />
|
<PackageReference Include="Microsoft.Graph" Version="5.80.0" />
|
||||||
<PackageReference Include="Azure.Identity" Version="1.13.1" />
|
<PackageReference Include="Azure.Identity" Version="1.13.1" />
|
||||||
|
<PackageReference Include="MudBlazor" Version="7.15.0" />
|
||||||
<PackageReference Include="Sap.Data.Hana.v2" Version="2.22.26" />
|
<PackageReference Include="Sap.Data.Hana.v2" Version="2.22.26" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="appsettings.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,30 +1,8 @@
|
|||||||
{
|
{
|
||||||
"HanaServers": {
|
"Logging": {
|
||||||
"Internal": {
|
"LogLevel": {
|
||||||
"Host": "travtrp0",
|
"Default": "Information",
|
||||||
"Port": 30015,
|
"Microsoft.AspNetCore": "Warning"
|
||||||
"Username": "",
|
|
||||||
"Password": ""
|
|
||||||
},
|
|
||||||
"India": {
|
|
||||||
"Host": "20.197.20.60",
|
|
||||||
"Port": 30015,
|
|
||||||
"Username": "",
|
|
||||||
"Password": ""
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"Sites": [
|
|
||||||
{ "Schema": "fr01_p", "Server": "Internal", "TSC": "TRFR", "Land": "Frankreich" },
|
|
||||||
{ "Schema": "it01_p", "Server": "Internal", "TSC": "TRIT", "Land": "Italien" },
|
|
||||||
{ "Schema": "us01_p", "Server": "Internal", "TSC": "TRUS", "Land": "USA" },
|
|
||||||
{ "Schema": "TRAFAG_LIVE", "Server": "India", "TSC": "TRIN", "Land": "Indien" }
|
|
||||||
],
|
|
||||||
"SharePoint": {
|
|
||||||
"SiteUrl": "https://trafagag.sharepoint.com/sites/WorldwideBIPlatform",
|
|
||||||
"ExportFolder": "/Shared Documents/Exports/",
|
|
||||||
"TenantId": "",
|
|
||||||
"ClientId": "",
|
|
||||||
"ClientSecret": ""
|
|
||||||
},
|
|
||||||
"DateFilter": "2025-01-01"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
html, body {
|
||||||
|
font-family: 'Roboto', sans-serif;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user