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.
155 lines
5.0 KiB
155 lines
5.0 KiB
import java.time.LocalDate;
|
|
import java.time.Duration;
|
|
|
|
/**
|
|
* 培训课程类 - 负责课程信息管理
|
|
* 遵循单一职责原则:只负责课程数据的存储和基本验证
|
|
*/
|
|
public class TrainingCourse {
|
|
private String courseId; // 课程ID
|
|
private String courseName; // 课程名称
|
|
private String description; // 课程描述
|
|
private int durationHours; // 课程时长(小时)
|
|
private String trainer; // 培训师
|
|
private String department; // 所属部门
|
|
private String category; // 课程类别
|
|
private int credits; // 学分
|
|
private boolean active; // 是否启用
|
|
private LocalDate createdAt; // 创建时间
|
|
private String requirements; // 课程要求
|
|
private String objectives; // 课程目标
|
|
private String materials; // 课程资料
|
|
|
|
/**
|
|
* 构造函数 - 创建培训课程
|
|
*/
|
|
public TrainingCourse(String courseId, String courseName, String description,
|
|
int durationHours, String trainer, String department,
|
|
String category, int credits) {
|
|
this.courseId = courseId;
|
|
this.courseName = courseName;
|
|
this.description = description;
|
|
this.durationHours = durationHours;
|
|
this.trainer = trainer;
|
|
this.department = department;
|
|
this.category = category;
|
|
this.credits = credits;
|
|
this.active = true;
|
|
this.createdAt = LocalDate.now();
|
|
this.requirements = "";
|
|
this.objectives = "";
|
|
this.materials = "";
|
|
}
|
|
|
|
/**
|
|
* 检查课程是否可报名
|
|
* @return true如果课程可报名
|
|
*/
|
|
public boolean isEnrollable() {
|
|
return active && durationHours > 0 && credits >= 0;
|
|
}
|
|
|
|
/**
|
|
* 获取课程时长描述
|
|
* @return 课程时长描述
|
|
*/
|
|
public String getDurationDescription() {
|
|
if (durationHours < 1) {
|
|
return "少于1小时";
|
|
} else if (durationHours == 1) {
|
|
return "1小时";
|
|
} else {
|
|
return durationHours + "小时";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取课程等级(基于学分)
|
|
* @return 课程等级
|
|
*/
|
|
public String getLevel() {
|
|
if (credits <= 1) return "初级";
|
|
else if (credits <= 3) return "中级";
|
|
else return "高级";
|
|
}
|
|
|
|
// Getter和Setter方法
|
|
|
|
public String getCourseId() { return courseId; }
|
|
|
|
public String getCourseName() { return courseName; }
|
|
|
|
public void setCourseName(String courseName) {
|
|
if (courseName == null || courseName.trim().isEmpty()) {
|
|
throw new IllegalArgumentException("课程名称不能为空");
|
|
}
|
|
this.courseName = courseName;
|
|
}
|
|
|
|
public String getDescription() { return description; }
|
|
|
|
public void setDescription(String description) { this.description = description; }
|
|
|
|
public int getDurationHours() { return durationHours; }
|
|
|
|
public void setDurationHours(int durationHours) {
|
|
if (durationHours < 0) {
|
|
throw new IllegalArgumentException("课程时长不能为负数");
|
|
}
|
|
this.durationHours = durationHours;
|
|
}
|
|
|
|
public String getTrainer() { return trainer; }
|
|
|
|
public void setTrainer(String trainer) { this.trainer = trainer; }
|
|
|
|
public String getDepartment() { return department; }
|
|
|
|
public void setDepartment(String department) { this.department = department; }
|
|
|
|
public String getCategory() { return category; }
|
|
|
|
public void setCategory(String category) { this.category = category; }
|
|
|
|
public int getCredits() { return credits; }
|
|
|
|
public void setCredits(int credits) {
|
|
if (credits < 0) {
|
|
throw new IllegalArgumentException("学分不能为负数");
|
|
}
|
|
this.credits = credits;
|
|
}
|
|
|
|
public boolean isActive() { return active; }
|
|
|
|
public void setActive(boolean active) { this.active = active; }
|
|
|
|
public LocalDate getCreatedAt() { return createdAt; }
|
|
|
|
public String getRequirements() { return requirements; }
|
|
|
|
public void setRequirements(String requirements) { this.requirements = requirements; }
|
|
|
|
public String getObjectives() { return objectives; }
|
|
|
|
public void setObjectives(String objectives) { this.objectives = objectives; }
|
|
|
|
public String getMaterials() { return materials; }
|
|
|
|
public void setMaterials(String materials) { this.materials = materials; }
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "TrainingCourse{" +
|
|
"courseId='" + courseId + "'" +
|
|
", courseName='" + courseName + "'" +
|
|
", category='" + category + "'" +
|
|
", level='" + getLevel() + "'" +
|
|
", duration=" + getDurationDescription() +
|
|
", trainer='" + trainer + "'" +
|
|
", credits=" + credits +
|
|
", department='" + department + "'" +
|
|
", active=" + (active ? "启用" : "禁用") +
|
|
"}";
|
|
}
|
|
} |