import java.time.LocalDate; import java.time.LocalDateTime; /** * 培训记录类 - 负责员工培训记录管理 * 遵循单一职责原则:只负责培训记录数据的存储和状态管理 */ public class TrainingRecord { private String recordId; // 记录ID private String employeeId; // 员工ID private String courseId; // 课程ID private LocalDate enrollmentDate; // 报名日期 private LocalDate startDate; // 开始日期 private LocalDate completionDate; // 完成日期 private Double score; // 成绩 private String certificateId; // 证书ID private RecordStatus status; // 记录状态 private String trainer; // 培训师 private String notes; // 备注 private LocalDateTime createdAt; // 创建时间 private LocalDateTime updatedAt; // 更新时间 /** * 构造函数 - 创建培训记录 */ public TrainingRecord(String recordId, String employeeId, String courseId) { this.recordId = recordId; this.employeeId = employeeId; this.courseId = courseId; this.enrollmentDate = LocalDate.now(); this.status = RecordStatus.ENROLLED; this.createdAt = LocalDateTime.now(); this.updatedAt = LocalDateTime.now(); this.notes = ""; } /** * 开始培训 * @param startDate 开始日期 * @param trainer 培训师 */ public void startTraining(LocalDate startDate, String trainer) { if (this.status != RecordStatus.ENROLLED) { throw new IllegalStateException("只有已报名的记录才能开始培训"); } this.startDate = startDate; this.trainer = trainer; this.status = RecordStatus.IN_PROGRESS; this.updatedAt = LocalDateTime.now(); } /** * 完成培训 * @param completionDate 完成日期 * @param score 成绩 */ public void completeTraining(LocalDate completionDate, Double score) { if (this.status != RecordStatus.IN_PROGRESS) { throw new IllegalStateException("只有进行中的记录才能完成培训"); } if (score != null && (score < 0 || score > 100)) { throw new IllegalArgumentException("成绩必须在0-100之间"); } this.completionDate = completionDate; this.score = score; this.status = RecordStatus.COMPLETED; this.updatedAt = LocalDateTime.now(); } /** * 取消培训 * @param reason 取消原因 */ public void cancelTraining(String reason) { if (this.status == RecordStatus.COMPLETED) { throw new IllegalStateException("已完成的培训不能取消"); } this.status = RecordStatus.CANCELLED; this.notes = reason; this.updatedAt = LocalDateTime.now(); } /** * 颁发证书 * @param certificateId 证书ID * @return */ public void issueCertificate(String certificateId) { if (this.status != RecordStatus.COMPLETED) { throw new IllegalStateException("只有已完成的培训才能颁发证书"); } if (score != null && score < 60) { throw new IllegalStateException("成绩不合格,无法颁发证书"); } this.certificateId = certificateId; this.updatedAt = LocalDateTime.now(); } /** * 判断是否合格 * @return true如果成绩合格 */ public boolean isPassed() { return score != null && score >= 60; } /** * 获取培训时长(天) * @return 培训时长 */ public Long getTrainingDurationDays() { if (startDate == null || completionDate == null) { return null; } return (long) startDate.until(completionDate).getDays() + 1; } /** * 记录状态枚举 */ public enum RecordStatus { ENROLLED, // 已报名 IN_PROGRESS, // 进行中 COMPLETED, // 已完成 CANCELLED // 已取消 } // Getter和Setter方法 public String getRecordId() { return recordId; } public String getEmployeeId() { return employeeId; } public String getCourseId() { return courseId; } public LocalDate getEnrollmentDate() { return enrollmentDate; } public LocalDate getStartDate() { return startDate; } public LocalDate getCompletionDate() { return completionDate; } public Double getScore() { return score; } public String getCertificateId() { return certificateId; } public RecordStatus getStatus() { return status; } public String getTrainer() { return trainer; } public String getNotes() { return notes; } public void setNotes(String notes) { this.notes = notes; this.updatedAt = LocalDateTime.now(); } public LocalDateTime getCreatedAt() { return createdAt; } public LocalDateTime getUpdatedAt() { return updatedAt; } @Override public String toString() { return "TrainingRecord{" + "recordId='" + recordId + "'" + ", employeeId='" + employeeId + "'" + ", courseId='" + courseId + "'" + ", status='" + status.name() + "'" + ", enrollmentDate=" + enrollmentDate + "'" + ", completionDate=" + (completionDate != null ? completionDate : "未完成") + "'" + ", score=" + (score != null ? score + (isPassed() ? "(合格)" : "(不合格)") : "未评分") + "'" + ", certificateId=" + (certificateId != null ? certificateId : "未颁发") + "'" + "}"; } public void addCourse(TrainingCourse course2) { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'addCourse'"); } public String enrollEmployee(String string, String string2, String string3, String string4) { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'enrollEmployee'"); } public LocalDate getCourseTrainingRecords(String string) { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getCourseTrainingRecords'"); } }