mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
shift assignment works
This commit is contained in:
@@ -148,6 +148,56 @@ const ShiftPlanView: React.FC = () => {
|
||||
return date.getDay() === 0 ? 7 : date.getDay();
|
||||
};
|
||||
|
||||
const debugManagerAvailability = () => {
|
||||
if (!shiftPlan || !employees.length || !availabilities.length) return;
|
||||
|
||||
const manager = employees.find(emp => emp.role === 'admin');
|
||||
if (!manager) {
|
||||
console.log('❌ Kein Manager (admin) gefunden');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('🔍 Manager-Analyse:', {
|
||||
manager: manager.name,
|
||||
managerId: manager.id,
|
||||
totalAvailabilities: availabilities.length,
|
||||
managerAvailabilities: availabilities.filter(a => a.employeeId === manager.id).length
|
||||
});
|
||||
|
||||
// Prüfe speziell die leeren Manager-Schichten
|
||||
const emptyManagerShifts = [
|
||||
'a8ef4ce0-adfd-4ec3-8c58-efa0f7347f9f',
|
||||
'a496a8d6-f7a0-4d77-96de-c165379378c4',
|
||||
'ea2d73d1-8354-4833-8c87-40f318ce8be0',
|
||||
'90eb5454-2ae2-4445-86b7-a6e0e2cf0b22'
|
||||
];
|
||||
|
||||
emptyManagerShifts.forEach(shiftId => {
|
||||
const scheduledShift = shiftPlan.scheduledShifts?.find(s => s.id === shiftId);
|
||||
if (scheduledShift) {
|
||||
const dayOfWeek = getDayOfWeek(scheduledShift.date);
|
||||
const shiftKey = `${dayOfWeek}-${scheduledShift.timeSlotId}`;
|
||||
|
||||
const managerAvailability = availabilities.find(a =>
|
||||
a.employeeId === manager.id &&
|
||||
a.dayOfWeek === dayOfWeek &&
|
||||
a.timeSlotId === scheduledShift.timeSlotId
|
||||
);
|
||||
|
||||
console.log(`📊 Schicht ${shiftId}:`, {
|
||||
date: scheduledShift.date,
|
||||
dayOfWeek,
|
||||
timeSlotId: scheduledShift.timeSlotId,
|
||||
shiftKey,
|
||||
managerAvailability: managerAvailability ? managerAvailability.preferenceLevel : 'NICHT GEFUNDEN',
|
||||
status: managerAvailability ?
|
||||
(managerAvailability.preferenceLevel === 3 ? '❌ NICHT VERFÜGBAR' : '✅ VERFÜGBAR') :
|
||||
'❌ KEINE VERFÜGBARKEITSDATEN'
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const handlePreviewAssignment = async () => {
|
||||
if (!shiftPlan) return;
|
||||
|
||||
@@ -164,6 +214,26 @@ const ShiftPlanView: React.FC = () => {
|
||||
}
|
||||
);
|
||||
|
||||
// DEBUG: Überprüfe die tatsächlichen Violations
|
||||
console.log('🔍 VIOLATIONS ANALYSIS:', {
|
||||
allViolations: result.violations,
|
||||
criticalViolations: result.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
),
|
||||
warningViolations: result.violations.filter(v =>
|
||||
v.includes('WARNING:') || v.includes('⚠️')
|
||||
),
|
||||
infoViolations: result.violations.filter(v =>
|
||||
v.includes('INFO:')
|
||||
),
|
||||
criticalCount: result.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
).length,
|
||||
canPublish: result.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
).length === 0
|
||||
});
|
||||
|
||||
setAssignmentResult(result);
|
||||
setShowAssignmentPreview(true);
|
||||
|
||||
@@ -173,48 +243,23 @@ const ShiftPlanView: React.FC = () => {
|
||||
result.resolutionReport.forEach(line => console.log(line));
|
||||
}
|
||||
|
||||
// KORRIGIERT: Entscheidung basierend auf Reparatur-Bericht statt allProblemsResolved
|
||||
const allCriticalResolved = result.resolutionReport &&
|
||||
result.resolutionReport.some(line =>
|
||||
line.includes('Alle kritischen Probleme behoben: ✅ JA')
|
||||
);
|
||||
// Entscheidung basierend auf tatsächlichen kritischen Violations
|
||||
const criticalCount = result.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
).length;
|
||||
|
||||
if (allCriticalResolved) {
|
||||
if (criticalCount === 0) {
|
||||
showNotification({
|
||||
type: 'success',
|
||||
title: 'Erfolg',
|
||||
message: 'Alle kritischen Probleme wurden behoben! Der Schichtplan kann veröffentlicht werden.'
|
||||
});
|
||||
} else {
|
||||
// Zähle nur kritische Probleme (ERROR oder ❌ KRITISCH)
|
||||
const criticalProblems = result.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
);
|
||||
|
||||
// Zähle Warnungen separat
|
||||
const warnings = result.violations.filter(v =>
|
||||
v.includes('WARNING:') || v.includes('⚠️')
|
||||
);
|
||||
|
||||
if (criticalProblems.length > 0) {
|
||||
showNotification({
|
||||
type: 'error',
|
||||
title: 'Kritische Probleme',
|
||||
message: `${criticalProblems.length} kritische Probleme müssen behoben werden`
|
||||
});
|
||||
} else if (warnings.length > 0) {
|
||||
showNotification({
|
||||
type: 'warning',
|
||||
title: 'Warnungen',
|
||||
message: `${warnings.length} Warnungen - Plan kann trotzdem veröffentlicht werden`
|
||||
});
|
||||
} else {
|
||||
showNotification({
|
||||
type: 'success',
|
||||
title: 'Erfolg',
|
||||
message: 'Keine Probleme gefunden! Der Schichtplan kann veröffentlicht werden.'
|
||||
});
|
||||
}
|
||||
showNotification({
|
||||
type: 'error',
|
||||
title: 'Kritische Probleme',
|
||||
message: `${criticalCount} kritische Probleme müssen behoben werden`
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
@@ -312,14 +357,28 @@ const ShiftPlanView: React.FC = () => {
|
||||
try {
|
||||
setReverting(true);
|
||||
|
||||
// 1. Zuerst zurücksetzen
|
||||
const updatedPlan = await shiftPlanService.revertToDraft(id);
|
||||
setShiftPlan(updatedPlan);
|
||||
|
||||
// 2. Dann ALLE Daten neu laden
|
||||
await loadShiftPlanData();
|
||||
|
||||
// 3. Assignment-Result zurücksetzen
|
||||
setAssignmentResult(null);
|
||||
|
||||
// 4. Preview schließen falls geöffnet
|
||||
setShowAssignmentPreview(false);
|
||||
|
||||
showNotification({
|
||||
type: 'success',
|
||||
title: 'Erfolg',
|
||||
message: 'Schichtplan wurde erfolgreich zurück in den Entwurfsstatus gesetzt.'
|
||||
message: 'Schichtplan wurde erfolgreich zurück in den Entwurfsstatus gesetzt. Alle Daten wurden neu geladen.'
|
||||
});
|
||||
|
||||
console.log('Scheduled shifts after revert:', {
|
||||
hasScheduledShifts: !!shiftPlan.scheduledShifts,
|
||||
count: shiftPlan.scheduledShifts?.length || 0,
|
||||
firstFew: shiftPlan.scheduledShifts?.slice(0, 3)
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
@@ -705,28 +764,56 @@ const ShiftPlanView: React.FC = () => {
|
||||
}}>
|
||||
<h2>Wochenmuster-Zuordnung</h2>
|
||||
|
||||
{/* Reparatur-Bericht anzeigen */}
|
||||
{/* Detaillierter Reparatur-Bericht anzeigen */}
|
||||
{assignmentResult.resolutionReport && (
|
||||
<div style={{
|
||||
backgroundColor: '#e8f4fd',
|
||||
border: '1px solid #b8d4f0',
|
||||
backgroundColor: '#f8f9fa',
|
||||
border: '1px solid #e9ecef',
|
||||
borderRadius: '4px',
|
||||
padding: '15px',
|
||||
marginBottom: '20px',
|
||||
fontSize: '14px'
|
||||
fontSize: '14px',
|
||||
maxHeight: '400px',
|
||||
overflow: 'auto'
|
||||
}}>
|
||||
<h4 style={{ color: '#2c3e50', marginTop: 0 }}>Reparatur-Bericht</h4>
|
||||
<div style={{ maxHeight: '200px', overflow: 'auto' }}>
|
||||
{assignmentResult.resolutionReport.map((line, index) => (
|
||||
<div key={index} style={{
|
||||
color: line.includes('✅') ? '#2ecc71' : line.includes('❌') ? '#e74c3c' : '#2c3e50',
|
||||
fontFamily: 'monospace',
|
||||
fontSize: '12px',
|
||||
marginBottom: '2px'
|
||||
}}>
|
||||
{line}
|
||||
</div>
|
||||
))}
|
||||
<h4 style={{ color: '#2c3e50', marginTop: 0, display: 'flex', alignItems: 'center', gap: '10px' }}>
|
||||
<span>📋</span> Detaillierter Reparatur-Bericht
|
||||
</h4>
|
||||
<div style={{
|
||||
fontFamily: 'monospace',
|
||||
fontSize: '12px',
|
||||
lineHeight: '1.4'
|
||||
}}>
|
||||
{assignmentResult.resolutionReport.map((line, index) => {
|
||||
let color = '#2c3e50';
|
||||
let fontWeight = 'normal';
|
||||
|
||||
if (line.includes('✅') || line.includes('ALLES KRITISCHEN PROBLEME BEHOBEN')) {
|
||||
color = '#2ecc71';
|
||||
fontWeight = 'bold';
|
||||
} else if (line.includes('❌') || line.includes('KRITISCHEN PROBLEME')) {
|
||||
color = '#e74c3c';
|
||||
fontWeight = 'bold';
|
||||
} else if (line.includes('⚠️')) {
|
||||
color = '#f39c12';
|
||||
} else if (line.includes('📊') || line.includes('🔧') || line.includes('📅') || line.includes('🚨') || line.includes('🛠️') || line.includes('💡') || line.includes('🎯')) {
|
||||
color = '#3498db';
|
||||
fontWeight = 'bold';
|
||||
} else if (line.startsWith(' •') || line.startsWith(' -')) {
|
||||
color = '#7f8c8d';
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={index} style={{
|
||||
color,
|
||||
fontWeight,
|
||||
marginBottom: line === '' ? '5px' : '2px',
|
||||
paddingLeft: line.startsWith(' ') ? '20px' : '0px'
|
||||
}}>
|
||||
{line}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -736,11 +823,10 @@ const ShiftPlanView: React.FC = () => {
|
||||
<div style={{ marginBottom: '20px' }}>
|
||||
<h4>Zusammenfassung:</h4>
|
||||
|
||||
{/* Entscheidung basierend auf Reparatur-Bericht */}
|
||||
{assignmentResult.resolutionReport &&
|
||||
assignmentResult.resolutionReport.some(line =>
|
||||
line.includes('Alle kritischen Probleme behoben: ✅ JA')
|
||||
) ? (
|
||||
{/* Entscheidung basierend auf tatsächlichen kritischen Problemen */}
|
||||
{assignmentResult.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
).length === 0 ? (
|
||||
<div style={{
|
||||
padding: '15px',
|
||||
backgroundColor: '#d4edda',
|
||||
@@ -822,33 +908,28 @@ const ShiftPlanView: React.FC = () => {
|
||||
|
||||
<button
|
||||
onClick={handlePublish}
|
||||
disabled={publishing || !(assignmentResult.resolutionReport &&
|
||||
assignmentResult.resolutionReport.some(line =>
|
||||
line.includes('Alle kritischen Probleme behoben: ✅ JA')
|
||||
))
|
||||
}
|
||||
disabled={publishing || assignmentResult.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
).length > 0}
|
||||
style={{
|
||||
padding: '10px 20px',
|
||||
backgroundColor: (assignmentResult.resolutionReport &&
|
||||
assignmentResult.resolutionReport.some(line =>
|
||||
line.includes('Alle kritischen Probleme behoben: ✅ JA')
|
||||
)) ? '#2ecc71' : '#95a5a6',
|
||||
backgroundColor: assignmentResult.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
).length === 0 ? '#2ecc71' : '#95a5a6',
|
||||
color: 'white',
|
||||
border: 'none',
|
||||
borderRadius: '4px',
|
||||
cursor: (assignmentResult.resolutionReport &&
|
||||
assignmentResult.resolutionReport.some(line =>
|
||||
line.includes('Alle kritischen Probleme behoben: ✅ JA')
|
||||
)) ? 'pointer' : 'not-allowed',
|
||||
cursor: assignmentResult.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
).length === 0 ? 'pointer' : 'not-allowed',
|
||||
fontWeight: 'bold',
|
||||
fontSize: '16px'
|
||||
}}
|
||||
>
|
||||
{publishing ? 'Veröffentliche...' : (
|
||||
(assignmentResult.resolutionReport &&
|
||||
assignmentResult.resolutionReport.some(line =>
|
||||
line.includes('Alle kritischen Probleme behoben: ✅ JA')
|
||||
))
|
||||
assignmentResult.violations.filter(v =>
|
||||
v.includes('ERROR:') || v.includes('❌ KRITISCH:')
|
||||
).length === 0
|
||||
? 'Schichtplan veröffentlichen'
|
||||
: 'Kritische Probleme müssen behoben werden'
|
||||
)}
|
||||
|
||||
@@ -864,3 +864,192 @@ export function checkAllProblemsResolved(
|
||||
|
||||
return { resolved, remaining, allResolved };
|
||||
}
|
||||
|
||||
export function createDetailedResolutionReport(
|
||||
assignments: Assignment,
|
||||
employees: Map<string, SchedulingEmployee>,
|
||||
shifts: SchedulingShift[],
|
||||
managerShifts: string[],
|
||||
repairContext: RepairContext
|
||||
): string[] {
|
||||
const report: string[] = [];
|
||||
|
||||
report.push('=== DETAILIERTER REPARATUR-BERICHT ===');
|
||||
report.push('');
|
||||
|
||||
// 1. ZUSAMMENFASSUNG
|
||||
report.push('📊 ZUSAMMENFASSUNG');
|
||||
const totalShifts = shifts.length;
|
||||
const assignedShifts = Object.values(assignments).filter(a => a.length > 0).length;
|
||||
const emptyShifts = totalShifts - assignedShifts;
|
||||
|
||||
report.push(` • Gesamtschichten: ${totalShifts}`);
|
||||
report.push(` • Zugewiesene Schichten: ${assignedShifts}`);
|
||||
report.push(` • Leere Schichten: ${emptyShifts}`);
|
||||
report.push(` • Pool-Mitarbeiter: ${repairContext.unassignedPool.length}`);
|
||||
report.push(` • Gesperrte Schichten: ${repairContext.lockedShifts.size}`);
|
||||
report.push('');
|
||||
|
||||
// 2. DURCHGEFÜHRTE AKTIONEN
|
||||
if (repairContext.warnings.length > 0) {
|
||||
report.push('🔧 DURCHGEFÜHRTE REPARATURAKTIONEN');
|
||||
repairContext.warnings.forEach((action, index) => {
|
||||
if (action.includes('zugewiesen') || action.includes('entfernt') || action.includes('getauscht') || action.includes('bewegt')) {
|
||||
report.push(` ✅ ${action}`);
|
||||
}
|
||||
});
|
||||
report.push('');
|
||||
}
|
||||
|
||||
// 3. DETAILLIERTE SCHICHTANALYSE
|
||||
report.push('📅 DETAILLIERTE SCHICHTANALYSE');
|
||||
|
||||
shifts.forEach(shift => {
|
||||
const assignment = assignments[shift.id] || [];
|
||||
const assignedEmployees = assignment.map(empId => {
|
||||
const emp = employees.get(empId);
|
||||
return emp ? `${emp.name} (${emp.role})` : 'Unbekannt';
|
||||
}).join(', ');
|
||||
|
||||
const isManagerShift = managerShifts.includes(shift.id);
|
||||
const isEmpty = assignment.length === 0;
|
||||
const hasOnlyNew = onlyNeuAssigned(assignment, employees);
|
||||
const experiencedAloneCheck = hasExperiencedAloneNotAllowed(assignment, employees);
|
||||
|
||||
let status = '✅ OK';
|
||||
if (isEmpty) status = '❌ LEER';
|
||||
else if (isManagerShift && hasOnlyNew) status = '⚠️ MANAGER + NUR NEUE';
|
||||
else if (experiencedAloneCheck.hasViolation) status = '❌ ERFAHRENER ALLEIN';
|
||||
else if (hasOnlyNew) status = '⚠️ NUR NEUE';
|
||||
|
||||
report.push(` • Schicht ${shift.id}:`);
|
||||
report.push(` - Status: ${status}`);
|
||||
report.push(` - Zugewiesene: ${assignedEmployees || 'Keine'}`);
|
||||
report.push(` - Benötigt: ${shift.requiredEmployees} Mitarbeiter`);
|
||||
report.push(` - Aktuell: ${assignment.length} Mitarbeiter`);
|
||||
if (isManagerShift) report.push(` - 💼 MANAGER-SCHICHT`);
|
||||
report.push('');
|
||||
});
|
||||
|
||||
// 4. PROBLEMANALYSE NACH TYP
|
||||
report.push('🚨 PROBLEMANALYSE NACH TYP');
|
||||
|
||||
const emptyShiftsList = shifts.filter(shift =>
|
||||
(assignments[shift.id] || []).length === 0
|
||||
);
|
||||
|
||||
const managerWithOnlyNewList = shifts.filter(shift =>
|
||||
managerShifts.includes(shift.id) &&
|
||||
isManagerShiftWithOnlyNew(assignments[shift.id] || [], employees, Array.from(employees.values()).find(e => e.role === 'manager')?.id)
|
||||
);
|
||||
|
||||
const experiencedAloneList = shifts.filter(shift => {
|
||||
const check = hasExperiencedAloneNotAllowed(assignments[shift.id] || [], employees);
|
||||
return check.hasViolation;
|
||||
});
|
||||
|
||||
const onlyNewList = shifts.filter(shift =>
|
||||
!managerShifts.includes(shift.id) &&
|
||||
onlyNeuAssigned(assignments[shift.id] || [], employees)
|
||||
);
|
||||
|
||||
if (emptyShiftsList.length > 0) {
|
||||
report.push(` ❌ LEERE SCHICHTEN (${emptyShiftsList.length}):`);
|
||||
emptyShiftsList.forEach(shift => {
|
||||
report.push(` - ${shift.id}`);
|
||||
});
|
||||
report.push('');
|
||||
}
|
||||
|
||||
if (managerWithOnlyNewList.length > 0) {
|
||||
report.push(` ⚠️ MANAGER + NUR NEUE (${managerWithOnlyNewList.length}):`);
|
||||
managerWithOnlyNewList.forEach(shift => {
|
||||
const assignment = assignments[shift.id] || [];
|
||||
const employeesList = assignment.map(empId => {
|
||||
const emp = employees.get(empId);
|
||||
return emp ? emp.name : 'Unbekannt';
|
||||
}).join(', ');
|
||||
report.push(` - ${shift.id}: ${employeesList}`);
|
||||
});
|
||||
report.push('');
|
||||
}
|
||||
|
||||
if (experiencedAloneList.length > 0) {
|
||||
report.push(` ❌ ERFAHRENER ALLEIN (${experiencedAloneList.length}):`);
|
||||
experiencedAloneList.forEach(shift => {
|
||||
const check = hasExperiencedAloneNotAllowed(assignments[shift.id] || [], employees);
|
||||
const emp = employees.get(check.employeeId!);
|
||||
report.push(` - ${shift.id}: ${emp?.name || check.employeeId}`);
|
||||
});
|
||||
report.push('');
|
||||
}
|
||||
|
||||
if (onlyNewList.length > 0) {
|
||||
report.push(` ⚠️ NUR NEUE IN SCHICHT (${onlyNewList.length}):`);
|
||||
onlyNewList.forEach(shift => {
|
||||
report.push(` - ${shift.id}`);
|
||||
});
|
||||
report.push('');
|
||||
}
|
||||
|
||||
// 5. REPARATURVERSUCHE
|
||||
report.push('🛠️ REPARATURVERSUCHE UND -ERGEBNISSE');
|
||||
|
||||
// Zähle die verschiedenen Reparaturtypen
|
||||
const assignmentActions = repairContext.warnings.filter(w =>
|
||||
w.includes('zugewiesen')
|
||||
).length;
|
||||
|
||||
const removalActions = repairContext.warnings.filter(w =>
|
||||
w.includes('entfernt')
|
||||
).length;
|
||||
|
||||
const swapActions = repairContext.warnings.filter(w =>
|
||||
w.includes('getauscht') || w.includes('bewegt')
|
||||
).length;
|
||||
|
||||
report.push(` • Zuweisungen: ${assignmentActions}`);
|
||||
report.push(` • Entfernungen: ${removalActions}`);
|
||||
report.push(` • Tausche/Bewegungen: ${swapActions}`);
|
||||
report.push(` • Gesamte Aktionen: ${repairContext.warnings.length}`);
|
||||
report.push('');
|
||||
|
||||
// 6. EMPFEHLUNGEN
|
||||
report.push('💡 EMPFEHLUNGEN ZUR PROBLEMBEHANDLUNG');
|
||||
|
||||
if (emptyShiftsList.length > 0) {
|
||||
report.push(` • Für ${emptyShiftsList.length} leere Schichten:`);
|
||||
report.push(` - Verfügbare Mitarbeiter prüfen`);
|
||||
report.push(` - Vertragskapazitäten überprüfen`);
|
||||
report.push(` - Ggf. Schichtanforderungen reduzieren`);
|
||||
report.push('');
|
||||
}
|
||||
|
||||
if (managerWithOnlyNewList.length > 0) {
|
||||
report.push(` • Für ${managerWithOnlyNewList.length} Manager+Neue-Schichten:`);
|
||||
report.push(` - Erfahrene Mitarbeiter zuweisen`);
|
||||
report.push(` - Manager-Verfügbarkeit anpassen`);
|
||||
report.push(` - Teamzusammensetzung optimieren`);
|
||||
report.push('');
|
||||
}
|
||||
|
||||
// 7. FINALE BEWERTUNG
|
||||
report.push('🎯 FINALE BEWERTUNG');
|
||||
|
||||
const totalProblems = emptyShiftsList.length + experiencedAloneList.length;
|
||||
const totalWarnings = managerWithOnlyNewList.length + onlyNewList.length;
|
||||
|
||||
if (totalProblems === 0) {
|
||||
report.push(' ✅ ALLE KRITISCHEN PROBLEME BEHOBEN');
|
||||
report.push(' Der Schichtplan kann veröffentlicht werden.');
|
||||
} else {
|
||||
report.push(` ❌ ${totalProblems} KRITISCHE PROBLEME VERBLEIBEND`);
|
||||
report.push(` ⚠️ ${totalWarnings} WARNUNGEN`);
|
||||
report.push(' Der Schichtplan kann nicht veröffentlicht werden.');
|
||||
}
|
||||
|
||||
report.push('');
|
||||
report.push('=== ENDE DES DETAILIERTEN BERICHTES ===');
|
||||
|
||||
return report;
|
||||
}
|
||||
@@ -29,7 +29,8 @@ import {
|
||||
resolveOverstaffedExperienced,
|
||||
prioritizeWarningsWithPool,
|
||||
resolveExperiencedAloneNotAllowed,
|
||||
checkAllProblemsResolved
|
||||
checkAllProblemsResolved,
|
||||
createDetailedResolutionReport
|
||||
} from './repairFunctions';
|
||||
|
||||
// Phase A: Regular employee scheduling (without manager)
|
||||
@@ -144,7 +145,7 @@ function phaseBInsertManager(
|
||||
console.log(`🎯 Phase B: Processing ${managerShifts.length} manager shifts`);
|
||||
|
||||
for (const shiftId of managerShifts) {
|
||||
//const shift = nonManagerShifts.find(s => s.id === shiftId) || { id: shiftId, requiredEmployees: 2 };
|
||||
let _shift = nonManagerShifts.find(s => s.id === shiftId) || { id: shiftId, requiredEmployees: 2 };
|
||||
|
||||
// Assign manager to his chosen shifts
|
||||
if (!assignments[shiftId].includes(manager.id)) {
|
||||
@@ -240,11 +241,12 @@ export function enhancedPhaseCRepairValidate(
|
||||
const employeeMap = new Map(employees.map(emp => [emp.id, emp]));
|
||||
const manager = employees.find(emp => emp.role === 'manager');
|
||||
|
||||
console.log('🔄 Starting Enhanced Phase C: Smart Repair & Validation');
|
||||
console.log('🔄 Starting Enhanced Phase C: Detailed Repair & Validation');
|
||||
|
||||
// 1. Manager-Schutzregel
|
||||
managerShifts.forEach(shiftId => {
|
||||
repairContext.lockedShifts.add(shiftId);
|
||||
repairContext.warnings.push(`Schicht ${shiftId} als Manager-Schicht gesperrt`);
|
||||
});
|
||||
|
||||
// 2. Überbesetzte erfahrene Mitarbeiter identifizieren und in Pool verschieben
|
||||
@@ -276,6 +278,7 @@ export function enhancedPhaseCRepairValidate(
|
||||
severity: 'error',
|
||||
message: `Leere Schicht: ${shift.id}`
|
||||
});
|
||||
repairContext.warnings.push(`Konnte leere Schicht ${shift.id} nicht beheben`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +305,7 @@ export function enhancedPhaseCRepairValidate(
|
||||
shiftId: shift.id,
|
||||
employeeId: experiencedAloneCheck.employeeId,
|
||||
severity: 'error',
|
||||
message: `Erfahrener Mitarbeiter ${emp?.name || experiencedAloneCheck.employeeId} arbeitet allein, darf aber nicht alleine arbeiten`
|
||||
message: `Erfahrener Mitarbeiter ${emp?.name || experiencedAloneCheck.employeeId} arbeitet allein in Schicht ${shift.id}`
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -325,26 +328,26 @@ export function enhancedPhaseCRepairValidate(
|
||||
managerShifts.forEach(shiftId => {
|
||||
const assignment = assignments[shiftId] || [];
|
||||
|
||||
// Manager allein -> KRITISCH (error)
|
||||
// Manager allein
|
||||
if (isManagerAlone(assignment, manager?.id)) {
|
||||
repairContext.violations.push({
|
||||
repairContext.violations.push({
|
||||
type: 'ManagerAlone',
|
||||
shiftId: shiftId,
|
||||
severity: 'error', // KRITISCH
|
||||
severity: 'error',
|
||||
message: `Manager allein in Schicht ${shiftId}`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Manager + nur Neue -> NUR WARNUNG (warning)
|
||||
// Manager + nur Neue
|
||||
if (isManagerShiftWithOnlyNew(assignment, employeeMap, manager?.id)) {
|
||||
repairContext.violations.push({
|
||||
repairContext.violations.push({
|
||||
type: 'ManagerWithOnlyNew',
|
||||
shiftId: shiftId,
|
||||
severity: 'warning', // NUR WARNUNG
|
||||
severity: 'warning',
|
||||
message: `Manager mit nur Neuen in Schicht ${shiftId}`
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Erstelle finale Violations-Liste
|
||||
const uniqueViolations = repairContext.violations.filter((v, index, self) =>
|
||||
@@ -360,56 +363,40 @@ export function enhancedPhaseCRepairValidate(
|
||||
);
|
||||
|
||||
const finalViolations = [
|
||||
// Nur ERROR-Violations als ERROR markieren
|
||||
...uniqueViolations
|
||||
.filter(v => v.severity === 'error')
|
||||
.map(v => `ERROR: ${v.message}`),
|
||||
|
||||
// WARNING-Violations als WARNING markieren
|
||||
.filter(v => v.severity === 'error')
|
||||
.map(v => `ERROR: ${v.message}`),
|
||||
...uniqueViolations
|
||||
.filter(v => v.severity === 'warning')
|
||||
.map(v => `WARNING: ${v.message}`),
|
||||
|
||||
// Andere Warnungen als INFO (Aktionen)
|
||||
.filter(v => v.severity === 'warning')
|
||||
.map(v => `WARNING: ${v.message}`),
|
||||
...uniqueWarnings.map(w => `INFO: ${w}`)
|
||||
];
|
||||
];
|
||||
|
||||
// 9. FINALE ÜBERPRÜFUNG: Prüfe ob alle kritischen Probleme gelöst wurden
|
||||
const resolutionCheck = checkAllProblemsResolved(
|
||||
// 9. DETAILLIERTER REPARATUR-BERICHT
|
||||
const resolutionReport = createDetailedResolutionReport(
|
||||
assignments,
|
||||
employeeMap,
|
||||
shifts,
|
||||
managerShifts,
|
||||
finalViolations
|
||||
repairContext
|
||||
);
|
||||
|
||||
const resolutionReport = [
|
||||
'=== REPARATUR-BERICHT ===',
|
||||
`Aufgelöste Probleme: ${resolutionCheck.resolved.length}`,
|
||||
`Verbleibende Probleme: ${resolutionCheck.remaining.length}`,
|
||||
`Alle kritischen Probleme behoben: ${resolutionCheck.allResolved ? '✅ JA' : '❌ NEIN'}`,
|
||||
'',
|
||||
'--- AUFGELÖSTE PROBLEME ---',
|
||||
...(resolutionCheck.resolved.length > 0 ? resolutionCheck.resolved : ['Keine']),
|
||||
'',
|
||||
'--- VERBLEIBENDE PROBLEME ---',
|
||||
...(resolutionCheck.remaining.length > 0 ? resolutionCheck.remaining : ['Keine']),
|
||||
'',
|
||||
'=== ENDE BERICHT ==='
|
||||
];
|
||||
// Bestimme ob alle kritischen Probleme behoben wurden
|
||||
const criticalProblems = uniqueViolations.filter(v => v.severity === 'error');
|
||||
const allProblemsResolved = criticalProblems.length === 0;
|
||||
|
||||
console.log('📊 Enhanced Phase C completed:', {
|
||||
poolSize: repairContext.unassignedPool.length,
|
||||
violations: uniqueViolations.length,
|
||||
warnings: uniqueWarnings.length,
|
||||
allProblemsResolved: resolutionCheck.allResolved
|
||||
totalActions: uniqueWarnings.length,
|
||||
criticalProblems: criticalProblems.length,
|
||||
warnings: uniqueViolations.filter(v => v.severity === 'warning').length,
|
||||
allProblemsResolved
|
||||
});
|
||||
|
||||
return {
|
||||
assignments,
|
||||
violations: finalViolations,
|
||||
resolutionReport,
|
||||
allProblemsResolved: resolutionCheck.allResolved
|
||||
allProblemsResolved
|
||||
};
|
||||
}
|
||||
|
||||
@@ -421,7 +408,7 @@ export function scheduleWithManager(
|
||||
): SchedulingResult & { resolutionReport?: string[]; allProblemsResolved?: boolean } {
|
||||
|
||||
const assignments: Assignment = {};
|
||||
//const allViolations: string[] = [];
|
||||
const allViolations: string[] = [];
|
||||
|
||||
// Initialisiere Zuweisungen
|
||||
shifts.forEach(shift => {
|
||||
@@ -444,14 +431,14 @@ export function scheduleWithManager(
|
||||
console.log('🔄 Starting Phase B: Enhanced Manager insertion');
|
||||
|
||||
// Phase B: Erweiterte Manager-Einfügung
|
||||
/*const phaseBResult = phaseBInsertManager(
|
||||
const phaseBResult = phaseBInsertManager(
|
||||
assignments,
|
||||
manager,
|
||||
managerShifts,
|
||||
employees,
|
||||
nonManagerShifts,
|
||||
constraints
|
||||
);*/
|
||||
);
|
||||
|
||||
console.log('🔄 Starting Enhanced Phase C: Smart Repair & Validation');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user