You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
4.0 KiB
116 lines
4.0 KiB
/**
|
|
* 培训管理实现类
|
|
* 提供培训管理接口的具体实现
|
|
* 遵循单一职责原则,专注于培训记录的管理
|
|
*/
|
|
package com.employeetraining.training;
|
|
|
|
import java.time.LocalDate;
|
|
import java.util.*;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.stream.Collectors;
|
|
|
|
public class TrainingManagerImpl implements TrainingManager {
|
|
// 使用线程安全的集合存储培训记录
|
|
private final Map<String, TrainingRecord> trainingRecordMap = new ConcurrentHashMap<>();
|
|
|
|
@Override
|
|
public void createTrainingRecord(TrainingRecord record) {
|
|
if (record == null) {
|
|
throw new IllegalArgumentException("Training record cannot be null");
|
|
}
|
|
if (record.getRecordId() == null || record.getRecordId().trim().isEmpty()) {
|
|
throw new IllegalArgumentException("Record ID cannot be empty");
|
|
}
|
|
trainingRecordMap.put(record.getRecordId(), record);
|
|
}
|
|
|
|
@Override
|
|
public boolean updateTrainingStatus(String recordId, TrainingRecord.TrainingStatus status) {
|
|
TrainingRecord record = trainingRecordMap.get(recordId);
|
|
if (record != null) {
|
|
record.setStatus(status);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean updateTrainingScore(String recordId, double score) {
|
|
TrainingRecord record = trainingRecordMap.get(recordId);
|
|
if (record != null && score >= 0 && score <= 100) {
|
|
record.setScore(score);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean completeTraining(String recordId, double score, String feedback) {
|
|
TrainingRecord record = trainingRecordMap.get(recordId);
|
|
if (record != null) {
|
|
record.setStatus(TrainingRecord.TrainingStatus.COMPLETED);
|
|
record.setScore(score);
|
|
record.setCompletionDate(LocalDate.now());
|
|
record.setFeedback(feedback);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Optional<TrainingRecord> findTrainingRecordById(String recordId) {
|
|
if (recordId == null) {
|
|
return Optional.empty();
|
|
}
|
|
return Optional.ofNullable(trainingRecordMap.get(recordId));
|
|
}
|
|
|
|
@Override
|
|
public List<TrainingRecord> findTrainingRecordsByEmployeeId(String employeeId) {
|
|
if (employeeId == null) {
|
|
return Collections.emptyList();
|
|
}
|
|
return trainingRecordMap.values().stream()
|
|
.filter(record -> employeeId.equals(record.getEmployeeId()))
|
|
.toList();
|
|
}
|
|
|
|
@Override
|
|
public List<TrainingRecord> findTrainingRecordsByCourseId(String courseId) {
|
|
if (courseId == null) {
|
|
return Collections.emptyList();
|
|
}
|
|
return trainingRecordMap.values().stream()
|
|
.filter(record -> courseId.equals(record.getCourseId()))
|
|
.toList();
|
|
}
|
|
|
|
@Override
|
|
public List<TrainingRecord> findTrainingRecordsByStatus(TrainingRecord.TrainingStatus status) {
|
|
if (status == null) {
|
|
return Collections.emptyList();
|
|
}
|
|
return trainingRecordMap.values().stream()
|
|
.filter(record -> status == record.getStatus())
|
|
.toList();
|
|
}
|
|
|
|
@Override
|
|
public List<TrainingRecord> findCompletedTrainingsByDateRange(LocalDate startDate, LocalDate endDate) {
|
|
if (startDate == null || endDate == null) {
|
|
return Collections.emptyList();
|
|
}
|
|
return trainingRecordMap.values().stream()
|
|
.filter(record -> record.getStatus() == TrainingRecord.TrainingStatus.COMPLETED &&
|
|
record.getCompletionDate() != null &&
|
|
!record.getCompletionDate().isBefore(startDate) &&
|
|
!record.getCompletionDate().isAfter(endDate))
|
|
.toList();
|
|
}
|
|
|
|
@Override
|
|
public List<TrainingRecord> getAllTrainingRecords() {
|
|
return new ArrayList<>(trainingRecordMap.values());
|
|
}
|
|
} |