feat(scanner): Funde mit Akquise und Opportunities abgleichen

Neu gefundene Projekte mit Treffer werden einmalig per gpt-5.6-luna mit den
Akquise-Eintraegen und Opportunities der letzten N Tage (Vorgabe 14)
verglichen. Passt ein Eintrag, zeigt der Scanner "bereits beworben!" samt
Begruendung. Schalter und Zeitraum (Tage/Wochen) in Einstellungen -> Scanner,
Neupruefung von Hand im Detail.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sascha Wolf
2026-09-17 17:12:17 +02:00
co-authored by Claude Opus 5
parent 87ca52a34b
commit af3ca33743
15 changed files with 549 additions and 10 deletions
+66 -5
View File
@@ -1,13 +1,21 @@
import React from 'react';
import React, { useState } from 'react';
import { Modal } from '../ui/Modal';
import { MatchBadge, MatchStatusBadge, formatDateTime } from './scannerUi';
import type { MatchStatus, ScannerMatch } from '../../lib/scannerApi';
import { useToast } from '../Toast';
import { AlreadyAppliedBadge, MatchBadge, MatchStatusBadge, formatDateTime } from './scannerUi';
import {
scannerApi,
type MatchStatus,
type ScannerMatch,
type ScannerProject,
} from '../../lib/scannerApi';
interface MatchDetailModalProps {
match: ScannerMatch;
onClose: () => void;
onStatusChange: (status: MatchStatus) => void;
onDelete: () => void;
/** Nach "Neu prüfen" - das Projekt kann an mehreren Treffern haengen. */
onProjectChange?: (project: ScannerProject) => void;
/**
* "rejected" ist die Ansicht aus Unpassend: dort gibt es nur
* Zurueckholen und Loeschen, keine Statuskette.
@@ -27,9 +35,32 @@ export const MatchDetailModal: React.FC<MatchDetailModalProps> = ({
onClose,
onStatusChange,
onDelete,
onProjectChange,
variant = 'default',
}) => {
const project = match.Project;
const { addToast } = useToast();
const [project, setProject] = useState(match.Project);
const [isChecking, setIsChecking] = useState(false);
const recheck = async () => {
if (!project) return;
setIsChecking(true);
try {
const updated = await scannerApi.recheckApplied(project.id);
setProject(updated);
onProjectChange?.(updated);
addToast(
updated.alreadyApplied
? 'Projekt ist bereits im CRM erfasst.'
: 'Kein passender Eintrag in Akquise oder Opportunities.',
updated.alreadyApplied ? 'error' : 'success'
);
} catch (err) {
addToast(err instanceof Error ? err.message : 'Abgleich fehlgeschlagen.', 'error');
} finally {
setIsChecking(false);
}
};
return (
<Modal
@@ -52,7 +83,29 @@ export const MatchDetailModal: React.FC<MatchDetailModalProps> = ({
>
<div className="grid gap-6 lg:grid-cols-[2fr_1fr]">
<div className="min-w-0">
<h3 className="border-b border-ink-100 pb-3 text-lg text-ink-900">{project?.title}</h3>
<h3 className="flex flex-wrap items-center gap-2 border-b border-ink-100 pb-3 text-lg text-ink-900">
<span>{project?.title}</span>
{project?.alreadyApplied && <AlreadyAppliedBadge />}
</h3>
{project?.alreadyApplied && (project.appliedRefs?.length ?? 0) > 0 && (
<div className="mt-3 rounded-xl border border-red-200 bg-red-50 p-4">
<p className="text-[11px] font-extrabold uppercase tracking-wider text-red-700">
Schon im CRM erfasst
</p>
<ul className="mt-2 space-y-2 text-sm text-ink-700">
{project.appliedRefs!.map((ref) => (
<li key={`${ref.type}-${ref.id}`}>
<span className="font-bold">
{ref.type === 'acquisition' ? 'Akquise' : 'Opportunity'}: {ref.title}
</span>
{ref.consultant && <span className="text-ink-500"> · {ref.consultant}</span>}
{ref.reason && <p className="text-xs text-ink-500">{ref.reason}</p>}
</li>
))}
</ul>
</div>
)}
<dl className="mt-3 flex flex-wrap gap-x-6 gap-y-1 text-xs text-ink-400">
<div className="flex gap-1.5">
@@ -173,6 +226,14 @@ export const MatchDetailModal: React.FC<MatchDetailModalProps> = ({
>
Börse öffnen ↗
</a>
<button
onClick={recheck}
disabled={isChecking}
title="Mit Akquise und Opportunities abgleichen"
className="w-full rounded-xl border border-ink-200 py-2.5 text-sm font-bold text-ink-600 transition hover:border-brand-300 hover:text-brand-700 disabled:opacity-60"
>
{isChecking ? 'Prüfe…' : 'Auf Bewerbung prüfen'}
</button>
{variant === 'default' && (
<button
onClick={() => onStatusChange('rejected')}
+10 -1
View File
@@ -12,6 +12,7 @@ import {
primaryButtonClass,
secondaryButtonClass,
projectTimestamp,
AlreadyAppliedBadge,
} from './scannerUi';
import {
SCANNER_SETTINGS_DEFAULTS,
@@ -629,7 +630,10 @@ export const ScannerDashboard: React.FC = () => {
{match.Agent?.name ?? '—'}
</td>
<td className="max-w-md px-3 py-2.5">
<p className="truncate font-bold text-ink-900">{match.Project?.title}</p>
<div className="flex min-w-0 items-center gap-2">
<p className="truncate font-bold text-ink-900">{match.Project?.title}</p>
{match.Project?.alreadyApplied && <AlreadyAppliedBadge />}
</div>
<p className="truncate text-xs text-ink-400">
{match.Project?.location || 'Remote'}
</p>
@@ -663,6 +667,11 @@ export const ScannerDashboard: React.FC = () => {
onClose={() => setSelectedMatch(null)}
onStatusChange={(status) => changeStatus(selectedMatch, status)}
onDelete={() => setMatchToDelete(selectedMatch)}
onProjectChange={(project) =>
setMatches((prev) =>
prev.map((m) => (m.projectId === project.id ? { ...m, Project: project } : m))
)
}
/>
)}
+10 -1
View File
@@ -10,6 +10,7 @@ import {
dangerButtonClass,
formatDateTime,
secondaryButtonClass,
AlreadyAppliedBadge,
} from './scannerUi';
import { scannerApi, type ScannerMatch } from '../../lib/scannerApi';
@@ -108,7 +109,10 @@ export const ScannerRejected: React.FC = () => {
{match.Agent?.name ?? '—'}
</td>
<td className="max-w-md px-3 py-2.5">
<p className="truncate font-bold text-ink-900">{match.Project?.title}</p>
<div className="flex min-w-0 items-center gap-2">
<p className="truncate font-bold text-ink-900">{match.Project?.title}</p>
{match.Project?.alreadyApplied && <AlreadyAppliedBadge />}
</div>
<p className="truncate text-xs text-ink-400">
{match.Project?.location || 'Remote'}
</p>
@@ -142,6 +146,11 @@ export const ScannerRejected: React.FC = () => {
onClose={() => setSelectedMatch(null)}
onStatusChange={() => restore(selectedMatch)}
onDelete={() => setMatchToDelete(selectedMatch)}
onProjectChange={(project) =>
setMatches((prev) =>
prev.map((m) => (m.projectId === project.id ? { ...m, Project: project } : m))
)
}
/>
)}
+10
View File
@@ -72,6 +72,16 @@ export const MatchStatusBadge: React.FC<{ status: MatchStatus }> = ({ status })
);
};
/** Markierung aus dem Abgleich mit Akquise und Opportunities. */
export const AlreadyAppliedBadge: React.FC = () => (
<span
title="Dieses Projekt steht schon in der Akquise oder bei den Opportunities."
className="inline-flex shrink-0 items-center rounded-md border border-red-200 bg-red-50 px-2 py-0.5 text-[10px] font-extrabold uppercase tracking-wider text-red-700"
>
bereits beworben!
</span>
);
const PORTAL_STATUS_LABELS: Record<PortalStatus, { label: string; className: string; dot: string }> =
{
connected: {
+62 -1
View File
@@ -52,12 +52,16 @@ export const ScannerSettings: React.FC = () => {
const [values, setValues] = useState<ScannerSettingsValues>(SCANNER_SETTINGS_DEFAULTS);
const [isLoading, setIsLoading] = useState(true);
const [isSaving, setIsSaving] = useState(false);
/** Nur Anzeige - gespeichert werden immer Tage. */
const [periodUnit, setPeriodUnit] = useState<'days' | 'weeks'>('weeks');
const load = async () => {
setIsLoading(true);
try {
const data = await scannerApi.settings();
setValues({ ...SCANNER_SETTINGS_DEFAULTS, ...data });
const merged = { ...SCANNER_SETTINGS_DEFAULTS, ...data };
setValues(merged);
setPeriodUnit(Number(merged.applied_check_days) % 7 === 0 ? 'weeks' : 'days');
} catch (err) {
addToast(
err instanceof Error ? err.message : 'Scanner-Einstellungen nicht erreichbar.',
@@ -106,6 +110,10 @@ export const ScannerSettings: React.FC = () => {
const isScanningActive = values.scanning_active === 'true';
const emailActive = values.email_notifications_active === 'true';
const keyStored = values.openai_api_key === SECRET_MASK;
const appliedCheckActive = values.applied_check_active === 'true';
const periodDays = Math.max(1, Number.parseInt(values.applied_check_days, 10) || 14);
const periodFactor = periodUnit === 'weeks' ? 7 : 1;
const periodValue = Math.max(1, Math.round(periodDays / periodFactor));
return (
<form onSubmit={handleSubmit} className="space-y-5">
@@ -180,6 +188,59 @@ export const ScannerSettings: React.FC = () => {
</div>
</Section>
<Section
title="Abgleich mit Akquise und Opportunities"
description="Jedes neu gefundene Projekt mit Treffer wird mit den Einträgen der Akquise-Liste und den Opportunities verglichen. Ist es dort schon erfasst – auch unter anderem Titel oder von einer anderen Börse –, erscheint es im Dashboard mit „bereits beworben!“. Die KI (gpt-5.6-luna) nutzt den OpenAI-Key unten."
accent={appliedCheckActive ? 'border-l-brand-500' : 'border-l-ink-300'}
>
<Checkbox
checked={appliedCheckActive}
onChange={(checked) => setFlag('applied_check_active', checked)}
label="Abgleich aktiviert"
/>
<div className="mt-4 grid gap-4 md:grid-cols-3">
<div className="md:col-span-2">
<label className={labelClass}>Zeitraum zurück</label>
<div className="flex gap-2">
<input
type="number"
min={1}
max={periodUnit === 'weeks' ? 52 : 365}
required
disabled={!appliedCheckActive}
value={periodValue}
onChange={(event) => {
const next = Math.max(1, Number.parseInt(event.target.value, 10) || 1);
set('applied_check_days', String(Math.min(365, next * periodFactor)));
}}
className={`${inputClass} w-28`}
/>
<select
value={periodUnit}
disabled={!appliedCheckActive}
onChange={(event) => {
const unit = event.target.value as 'days' | 'weeks';
setPeriodUnit(unit);
// Der Zeitraum bleibt: "2 Wochen" wird zu "14 Tage". Nach Wochen
// gerundet wird nur, wenn die Tage nicht aufgehen.
if (unit === 'weeks') {
set('applied_check_days', String(Math.min(364, Math.max(1, Math.round(periodDays / 7)) * 7)));
}
}}
className={`${inputClass} w-36`}
>
<option value="days">Tage</option>
<option value="weeks">Wochen</option>
</select>
</div>
<p className="mt-1 text-xs text-ink-400">
Verglichen wird mit Akquise-Einträgen und Opportunities der letzten {periodDays}{' '}
{periodDays === 1 ? 'Tag' : 'Tage'} (Papierkorb ausgenommen).
</p>
</div>
</div>
</Section>
<Section
title="OpenAI"
description="Wird für die semantische Bewertung des Lebenslaufs gegen die Projektbeschreibung gebraucht (gpt-4o-mini)."
+22
View File
@@ -51,6 +51,20 @@ export interface ScannerProject {
*/
created_at?: string;
createdAt?: string;
/** Abgleich mit Akquise und Opportunities: dort schon erfasst. */
alreadyApplied?: boolean;
appliedRefs?: AppliedRef[];
/** null = noch nicht geprueft (kein Treffer bisher, Abgleich aus, KI-Fehler). */
appliedCheckAt?: string | null;
}
/** Eintrag im CRM, der zum gefundenen Projekt passt. */
export interface AppliedRef {
type: 'acquisition' | 'opportunity';
id: number;
title: string;
consultant: string | null;
reason: string;
}
export type MatchStatus = 'new' | 'reviewed' | 'applied' | 'rejected';
@@ -86,6 +100,9 @@ export interface ScannerSettings {
smtp_pass: string;
smtp_from: string;
notification_email_recipient: string;
applied_check_active: string;
/** Zeitraum in Tagen */
applied_check_days: string;
}
export const SCANNER_SETTINGS_DEFAULTS: ScannerSettings = {
@@ -102,6 +119,8 @@ export const SCANNER_SETTINGS_DEFAULTS: ScannerSettings = {
smtp_pass: '',
smtp_from: 'scanner@perinco.de',
notification_email_recipient: '',
applied_check_active: 'true',
applied_check_days: '14',
};
/** Sentinel des Backends fuer gesetzte Geheimnisse. */
@@ -186,6 +205,9 @@ export const scannerApi = {
removeMatch: (id: number) =>
apiRequest<{ message: string }>(`/scanner/matches/${id}`, { method: 'DELETE' }),
recheckApplied: (projectId: number) =>
apiRequest<ScannerProject>(`/scanner/projects/${projectId}/applied-check`, { method: 'POST' }),
// ---------- Einstellungen ----------
settings: () => apiRequest<Partial<ScannerSettings>>('/scanner/settings'),
saveSettings: (input: Partial<ScannerSettings>) =>