2026-06-08 06:41:17 +03:30
|
|
|
using JobsMedical.Web.Data;
|
|
|
|
|
using JobsMedical.Web.Models;
|
2026-06-08 08:36:12 +03:30
|
|
|
using JobsMedical.Web.Services;
|
2026-06-08 06:41:17 +03:30
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace JobsMedical.Web.Pages.Admin;
|
|
|
|
|
|
|
|
|
|
/// <summary>Every crawled item with its outcome (queued / published / flagged / discarded),
|
|
|
|
|
/// filterable by status and source — the full audit trail of ingestion.</summary>
|
|
|
|
|
[Authorize(Roles = "Admin")]
|
|
|
|
|
public class IngestedModel : PageModel
|
|
|
|
|
{
|
|
|
|
|
private readonly AppDbContext _db;
|
|
|
|
|
public IngestedModel(AppDbContext db) => _db = db;
|
|
|
|
|
|
|
|
|
|
public List<RawListing> Items { get; private set; } = new();
|
|
|
|
|
public int Total { get; private set; }
|
|
|
|
|
public Dictionary<RawListingStatus, int> Counts { get; private set; } = new();
|
2026-06-08 08:36:12 +03:30
|
|
|
[TempData] public string? Message { get; set; }
|
2026-06-08 06:41:17 +03:30
|
|
|
|
|
|
|
|
[BindProperty(SupportsGet = true)] public string? Status { get; set; } // new|flagged|published|discarded|all
|
|
|
|
|
[BindProperty(SupportsGet = true)] public string? Source { get; set; }
|
|
|
|
|
|
|
|
|
|
public async Task OnGetAsync()
|
|
|
|
|
{
|
|
|
|
|
Counts = await _db.RawListings.GroupBy(r => r.Status)
|
|
|
|
|
.Select(g => new { g.Key, C = g.Count() }).ToDictionaryAsync(x => x.Key, x => x.C);
|
|
|
|
|
|
|
|
|
|
var q = _db.RawListings.AsNoTracking().AsQueryable();
|
|
|
|
|
|
|
|
|
|
var st = Status?.ToLowerInvariant() switch
|
|
|
|
|
{
|
|
|
|
|
"new" => (RawListingStatus?)RawListingStatus.New,
|
|
|
|
|
"flagged" => RawListingStatus.Flagged,
|
|
|
|
|
"published" => RawListingStatus.Normalized,
|
|
|
|
|
"discarded" => RawListingStatus.Discarded,
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
if (st is not null) q = q.Where(r => r.Status == st);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(Source)) q = q.Where(r => r.SourceChannel.Contains(Source));
|
|
|
|
|
|
|
|
|
|
Total = await q.CountAsync();
|
|
|
|
|
Items = await q.OrderByDescending(r => r.FetchedAt).Take(200).ToListAsync();
|
|
|
|
|
}
|
2026-06-08 08:36:12 +03:30
|
|
|
|
|
|
|
|
/// <summary>
|
2026-06-08 11:25:32 +03:30
|
|
|
/// ARCHIVE (never delete) everything published from ingestion: the aggregated Shift/Job/Talent
|
|
|
|
|
/// posts are flipped to Archived (hidden from the site but kept for analytics); the raw crawl
|
|
|
|
|
/// rows are retained untouched as the permanent archive.
|
2026-06-08 08:36:12 +03:30
|
|
|
/// </summary>
|
2026-06-08 11:25:32 +03:30
|
|
|
public async Task<IActionResult> OnPostArchivePublishedAsync()
|
2026-06-08 08:36:12 +03:30
|
|
|
{
|
2026-06-08 11:25:32 +03:30
|
|
|
var shifts = await _db.Shifts
|
|
|
|
|
.Where(s => s.Source == ShiftSource.Aggregated && s.Status != ShiftStatus.Archived)
|
|
|
|
|
.ExecuteUpdateAsync(u => u.SetProperty(s => s.Status, ShiftStatus.Archived));
|
|
|
|
|
var jobs = await _db.JobOpenings
|
|
|
|
|
.Where(j => j.Source == ShiftSource.Aggregated && j.Status != ShiftStatus.Archived)
|
|
|
|
|
.ExecuteUpdateAsync(u => u.SetProperty(j => j.Status, ShiftStatus.Archived));
|
|
|
|
|
var talent = await _db.TalentListings
|
|
|
|
|
.Where(t => t.Source == ShiftSource.Aggregated && t.Status != ShiftStatus.Archived)
|
|
|
|
|
.ExecuteUpdateAsync(u => u.SetProperty(t => t.Status, ShiftStatus.Archived));
|
2026-06-08 08:36:12 +03:30
|
|
|
|
|
|
|
|
string P(int n) => JalaliDate.ToPersianDigits(n.ToString());
|
2026-06-08 11:25:32 +03:30
|
|
|
Message = $"بایگانی شد (از سایت پنهان، در پایگاهداده نگهداری شد): {P(shifts)} شیفت، {P(jobs)} استخدام، {P(talent)} آمادهبهکار.";
|
2026-06-08 08:36:12 +03:30
|
|
|
return RedirectToPage(new { Status });
|
|
|
|
|
}
|
2026-06-08 06:41:17 +03:30
|
|
|
}
|