zentrales excel der standarte

This commit is contained in:
2026-04-13 14:25:03 +02:00
parent 474d2215a2
commit 9a93920b71
156 changed files with 1933 additions and 5 deletions
@@ -10,7 +10,21 @@ public class ExcelExportService
Directory.CreateDirectory(outputDirectory); Directory.CreateDirectory(outputDirectory);
var fileName = $"Sales_{tsc}_{fileDate:yyyy-MM-dd}.xlsx"; var fileName = $"Sales_{tsc}_{fileDate:yyyy-MM-dd}.xlsx";
var fullPath = Path.Combine(outputDirectory, fileName); var fullPath = Path.Combine(outputDirectory, fileName);
WriteWorkbook(fullPath, records);
return fullPath;
}
public string CreateConsolidatedExcelFile(string outputDirectory, DateTime fileDate, List<SalesRecord> records)
{
Directory.CreateDirectory(outputDirectory);
var fileName = $"Sales_All_{fileDate:yyyy-MM-dd}.xlsx";
var fullPath = Path.Combine(outputDirectory, fileName);
WriteWorkbook(fullPath, records);
return fullPath;
}
private static void WriteWorkbook(string fullPath, List<SalesRecord> records)
{
using var workbook = new XLWorkbook(); using var workbook = new XLWorkbook();
var ws = workbook.Worksheets.Add("Sales"); var ws = workbook.Worksheets.Add("Sales");
@@ -84,6 +98,5 @@ public class ExcelExportService
ws.Columns().AdjustToContents(); ws.Columns().AdjustToContents();
workbook.SaveAs(fullPath); workbook.SaveAs(fullPath);
return fullPath;
} }
} }
@@ -55,9 +55,39 @@ public class ExportOrchestrationService
{ {
using var db = await _dbFactory.CreateDbContextAsync(); using var db = await _dbFactory.CreateDbContextAsync();
var sites = await db.Sites.Include(s => s.HanaServer).Where(s => s.IsActive).ToListAsync(); var sites = await db.Sites.Include(s => s.HanaServer).Where(s => s.IsActive).ToListAsync();
var consolidatedRecords = new List<SalesRecord>();
foreach (var site in sites) foreach (var site in sites)
{ {
await ExportSiteAsync(site); var result = await ExportSiteAsync(site);
if (result?.Records is { Count: > 0 })
consolidatedRecords.AddRange(result.Records);
}
if (consolidatedRecords.Count > 0)
{
var spConfig = await db.SharePointConfigs.FirstOrDefaultAsync();
var outputDir = Path.Combine(AppContext.BaseDirectory, "output");
var consolidatedPath = _excelService.CreateConsolidatedExcelFile(
outputDir,
DateTime.UtcNow.Date,
consolidatedRecords
.OrderBy(r => r.Land)
.ThenBy(r => r.Tsc)
.ThenByDescending(r => r.InvoiceDate ?? DateTime.MinValue)
.ThenBy(r => r.InvoiceNumber)
.ThenBy(r => r.PositionOnInvoice)
.ToList());
if (spConfig is not null &&
!string.IsNullOrWhiteSpace(spConfig.TenantId) &&
!string.IsNullOrWhiteSpace(spConfig.ClientId) &&
!string.IsNullOrWhiteSpace(spConfig.ClientSecret))
{
await _sharePointService.UploadAsync(
spConfig.TenantId, spConfig.ClientId, spConfig.ClientSecret,
spConfig.SiteUrl, spConfig.ExportFolder, "Alle", consolidatedPath);
}
} }
} }
@@ -69,13 +99,13 @@ public class ExportOrchestrationService
await ExportSiteAsync(site); await ExportSiteAsync(site);
} }
private async Task ExportSiteAsync(Site site) private async Task<SiteExportResult?> ExportSiteAsync(Site site)
{ {
if (site.HanaServer is null) return; if (site.HanaServer is null) return null;
lock (_lock) lock (_lock)
{ {
if (_runningExports.ContainsKey(site.Id)) return; if (_runningExports.ContainsKey(site.Id)) return null;
_runningExports[site.Id] = "HANA Abfrage..."; _runningExports[site.Id] = "HANA Abfrage...";
} }
NotifyChanged(); NotifyChanged();
@@ -130,6 +160,8 @@ public class ExportOrchestrationService
_logger.LogInformation("Export OK: {Land} ({TSC}) - {Rows} Zeilen in {Duration:F1}s", _logger.LogInformation("Export OK: {Land} ({TSC}) - {Rows} Zeilen in {Duration:F1}s",
site.Land, site.TSC, records.Count, sw.Elapsed.TotalSeconds); site.Land, site.TSC, records.Count, sw.Elapsed.TotalSeconds);
return new SiteExportResult(records, filePath);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -140,6 +172,7 @@ public class ExportOrchestrationService
log.DurationSeconds = sw.Elapsed.TotalSeconds; log.DurationSeconds = sw.Elapsed.TotalSeconds;
_logger.LogError(ex, "Export Fehler: {Land} ({TSC})", site.Land, site.TSC); _logger.LogError(ex, "Export Fehler: {Land} ({TSC})", site.Land, site.TSC);
return null;
} }
finally finally
{ {
@@ -168,4 +201,6 @@ public class ExportOrchestrationService
{ {
OnExportStatusChanged?.Invoke(); OnExportStatusChanged?.Invoke();
} }
private sealed record SiteExportResult(List<SalesRecord> Records, string FilePath);
} }
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,20 @@
{
"runtimeOptions": {
"tfm": "net8.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "8.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "8.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Reflection.NullabilityInfoContext.IsSupported": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
@@ -0,0 +1 @@
{"Version":1,"ManifestType":"Build","Endpoints":[{"Route":"_content/MudBlazor/MudBlazor.min.css","AssetFile":"_content/MudBlazor/MudBlazor.min.css","Selectors":[],"ResponseHeaders":[{"Name":"Accept-Ranges","Value":"bytes"},{"Name":"Cache-Control","Value":"no-cache"},{"Name":"Content-Length","Value":"580975"},{"Name":"Content-Type","Value":"text/css"},{"Name":"ETag","Value":"\"2gItJ0j/o5RSWg7VYqCOBpSPI1dxTOG+mnEzWt7EvYw=\""},{"Name":"Last-Modified","Value":"Tue, 29 Oct 2024 20:30:12 GMT"}],"EndpointProperties":[{"Name":"integrity","Value":"sha256-2gItJ0j/o5RSWg7VYqCOBpSPI1dxTOG+mnEzWt7EvYw="}]},{"Route":"_content/MudBlazor/MudBlazor.min.js","AssetFile":"_content/MudBlazor/MudBlazor.min.js","Selectors":[],"ResponseHeaders":[{"Name":"Accept-Ranges","Value":"bytes"},{"Name":"Cache-Control","Value":"no-cache"},{"Name":"Content-Length","Value":"49823"},{"Name":"Content-Type","Value":"text/javascript"},{"Name":"ETag","Value":"\"lz0Xidl9yw53lEeYs4XMU39zSRQzpCIyWOQSAG0/0GU=\""},{"Name":"Last-Modified","Value":"Tue, 29 Oct 2024 20:30:12 GMT"}],"EndpointProperties":[{"Name":"integrity","Value":"sha256-lz0Xidl9yw53lEeYs4XMU39zSRQzpCIyWOQSAG0/0GU="}]},{"Route":"css/app.css","AssetFile":"css/app.css","Selectors":[],"ResponseHeaders":[{"Name":"Accept-Ranges","Value":"bytes"},{"Name":"Cache-Control","Value":"no-cache"},{"Name":"Content-Length","Value":"195"},{"Name":"Content-Type","Value":"text/css"},{"Name":"ETag","Value":"\"bU+FYK0pc9dGtjX/nD1BXw4QGuuwaoW9VteAk/b6dxg=\""},{"Name":"Last-Modified","Value":"Mon, 13 Apr 2026 12:12:02 GMT"}],"EndpointProperties":[{"Name":"integrity","Value":"sha256-bU+FYK0pc9dGtjX/nD1BXw4QGuuwaoW9VteAk/b6dxg="}]},{"Route":"css/app.hvcp2ompdh.css","AssetFile":"css/app.css","Selectors":[],"ResponseHeaders":[{"Name":"Accept-Ranges","Value":"bytes"},{"Name":"Cache-Control","Value":"max-age=31536000, immutable"},{"Name":"Content-Length","Value":"195"},{"Name":"Content-Type","Value":"text/css"},{"Name":"ETag","Value":"\"bU+FYK0pc9dGtjX/nD1BXw4QGuuwaoW9VteAk/b6dxg=\""},{"Name":"Last-Modified","Value":"Mon, 13 Apr 2026 12:12:02 GMT"}],"EndpointProperties":[{"Name":"fingerprint","Value":"hvcp2ompdh"},{"Name":"integrity","Value":"sha256-bU+FYK0pc9dGtjX/nD1BXw4QGuuwaoW9VteAk/b6dxg="},{"Name":"label","Value":"css/app.css"}]},{"Route":"trafag.hgfqo1w32y.jpg","AssetFile":"trafag.jpg","Selectors":[],"ResponseHeaders":[{"Name":"Accept-Ranges","Value":"bytes"},{"Name":"Cache-Control","Value":"max-age=31536000, immutable"},{"Name":"Content-Length","Value":"5352"},{"Name":"Content-Type","Value":"image/jpeg"},{"Name":"ETag","Value":"\"P7OUfvce/0qhyBFF5Hv1Neq6EMn+fr2P3HGIfg3chbw=\""},{"Name":"Last-Modified","Value":"Mon, 13 Apr 2026 12:10:33 GMT"}],"EndpointProperties":[{"Name":"fingerprint","Value":"hgfqo1w32y"},{"Name":"integrity","Value":"sha256-P7OUfvce/0qhyBFF5Hv1Neq6EMn+fr2P3HGIfg3chbw="},{"Name":"label","Value":"trafag.jpg"}]},{"Route":"trafag.jpg","AssetFile":"trafag.jpg","Selectors":[],"ResponseHeaders":[{"Name":"Accept-Ranges","Value":"bytes"},{"Name":"Cache-Control","Value":"no-cache"},{"Name":"Content-Length","Value":"5352"},{"Name":"Content-Type","Value":"image/jpeg"},{"Name":"ETag","Value":"\"P7OUfvce/0qhyBFF5Hv1Neq6EMn+fr2P3HGIfg3chbw=\""},{"Name":"Last-Modified","Value":"Mon, 13 Apr 2026 12:10:33 GMT"}],"EndpointProperties":[{"Name":"integrity","Value":"sha256-P7OUfvce/0qhyBFF5Hv1Neq6EMn+fr2P3HGIfg3chbw="}]}]}
@@ -0,0 +1 @@
{"ContentRoots":["C:\\Users\\koi\\source\\repos\\Ai\\TrafagSalesExporter\\wwwroot\\","C:\\Users\\local-admin\\.nuget\\packages\\mudblazor\\7.15.0\\staticwebassets\\"],"Root":{"Children":{"trafag.jpg":{"Children":null,"Asset":{"ContentRootIndex":0,"SubPath":"trafag.jpg"},"Patterns":null},"css":{"Children":{"app.css":{"Children":null,"Asset":{"ContentRootIndex":0,"SubPath":"css/app.css"},"Patterns":null}},"Asset":null,"Patterns":null},"_content":{"Children":{"MudBlazor":{"Children":{"MudBlazor.min.css":{"Children":null,"Asset":{"ContentRootIndex":1,"SubPath":"MudBlazor.min.css"},"Patterns":null},"MudBlazor.min.js":{"Children":null,"Asset":{"ContentRootIndex":1,"SubPath":"MudBlazor.min.js"},"Patterns":null}},"Asset":null,"Patterns":null}},"Asset":null,"Patterns":null}},"Asset":null,"Patterns":[{"ContentRootIndex":0,"Pattern":"**","Depth":0}]}}
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

Some files were not shown because too many files have changed in this diff Show More