Compare commits

...

No commits in common. 'master' and 'main' have entirely different histories.
master ... main

Binary file not shown.

@ -1,174 +0,0 @@
import java.time.LocalDate;
/**
* -
*
*/
public class Certificate {
private String certificateId; // 证书ID
private String employeeId; // 员工ID
private String courseId; // 课程ID
private String courseName; // 课程名称
private LocalDate issueDate; // 颁发日期
private LocalDate expiryDate; // 过期日期
private String issuer; // 颁发机构
private String trainer; // 培训师
private double score; // 成绩
private boolean active; // 是否有效
private String certificateNumber; // 证书编号
private String description; // 证书描述
/**
* -
*/
public Certificate(String certificateId, String employeeId, String courseId,
String courseName, String issuer, String trainer, double score) {
this.certificateId = certificateId;
this.employeeId = employeeId;
this.courseId = courseId;
this.courseName = courseName;
this.issuer = issuer;
this.trainer = trainer;
this.score = score;
this.issueDate = LocalDate.now();
this.active = true;
this.certificateNumber = generateCertificateNumber(certificateId, employeeId);
this.description = "";
}
/**
*
*/
private String generateCertificateNumber(String certificateId, String employeeId) {
LocalDate now = LocalDate.now();
return String.format("CERT-%s-%s-%d",
employeeId, certificateId, now.getYear() * 10000 + now.getMonthValue() * 100 + now.getDayOfMonth());
}
/**
*
* @param years
*/
public void setValidYears(int years) {
if (years <= 0) {
throw new IllegalArgumentException("有效期必须大于0");
}
this.expiryDate = issueDate.plusYears(years);
}
/**
*
* @return true
*/
public boolean isExpired() {
if (expiryDate == null) {
return false; // 没有设置过期日期的证书永不过期
}
return LocalDate.now().isAfter(expiryDate);
}
/**
*
* @param reason
*/
public void revokeCertificate(String reason) {
this.active = false;
this.description = reason;
}
/**
*
*/
public void reinstateCertificate() {
if (!isExpired()) {
this.active = true;
} else {
throw new IllegalStateException("已过期的证书无法恢复");
}
}
/**
*
* @return
*/
public String getStatusDescription() {
if (!active) {
return "已吊销";
} else if (isExpired()) {
return "已过期";
} else {
return "有效";
}
}
/**
*
* @return null
*/
public Long getRemainingValidDays() {
if (expiryDate == null || isExpired()) {
return null;
}
return (long) LocalDate.now().until(expiryDate).getDays();
}
/**
*
* @return
*/
public String getScoreGrade() {
if (score >= 90) return "优秀";
else if (score >= 80) return "良好";
else if (score >= 70) return "中等";
else if (score >= 60) return "及格";
else return "不及格";
}
// Getter和Setter方法
public String getCertificateId() { return certificateId; }
public String getEmployeeId() { return employeeId; }
public String getCourseId() { return courseId; }
public String getCourseName() { return courseName; }
public void setCourseName(String courseName) { this.courseName = courseName; }
public LocalDate getIssueDate() { return issueDate; }
public LocalDate getExpiryDate() { return expiryDate; }
public String getIssuer() { return issuer; }
public void setIssuer(String issuer) { this.issuer = issuer; }
public String getTrainer() { return trainer; }
public void setTrainer(String trainer) { this.trainer = trainer; }
public double getScore() { return score; }
public boolean isActive() { return active; }
public String getCertificateNumber() { return certificateNumber; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
@Override
public String toString() {
return "Certificate{" +
"certificateId='" + certificateId + "'" +
", certificateNumber='" + certificateNumber + "'" +
", courseName='" + courseName + "'" +
", employeeId='" + employeeId + "'" +
", score=" + score + "(" + getScoreGrade() + ")" +
", issueDate=" + issueDate + "'" +
", expiryDate=" + (expiryDate != null ? expiryDate : "永不过期") + "'" +
", status=" + getStatusDescription() + "'" +
"}";
}
}

Binary file not shown.

@ -1,179 +0,0 @@
/**
* -
*
*/
public class EmailService {
/**
*
* @param employeeId ID
* @param employeeName
* @param employeeEmail
* @param department
* @param hireDate
*/
public void sendWelcomeEmail(String employeeId, String employeeName, String employeeEmail,
String department, String hireDate) {
String subject = "欢迎加入我们的团队!";
String content = String.format(
"尊敬的 %s 先生/女士:\n\n" +
"恭喜您成功加入我们的团队!\n" +
"员工ID%s\n" +
"部门:%s\n" +
"入职日期:%s\n\n" +
"我们期待您的贡献!如有任何问题,请随时联系人力资源部门。\n\n" +
"此致\n" +
"人力资源部",
employeeName, employeeId, department, hireDate
);
sendEmail(employeeEmail, subject, content);
}
/**
*
* @param employeeId ID
* @param employeeName
* @param employeeEmail
* @param lastWorkingDay
*/
public void sendFarewellEmail(String employeeId, String employeeName, String employeeEmail,
String lastWorkingDay) {
String subject = "离职通知确认";
String content = String.format(
"尊敬的 %s 先生/女士:\n\n" +
"感谢您在公司工作期间的贡献。\n" +
"员工ID%s\n" +
"最后工作日:%s\n\n" +
"祝您未来一切顺利!\n\n" +
"此致\n" +
"人力资源部",
employeeName, employeeId, lastWorkingDay
);
sendEmail(employeeEmail, subject, content);
}
/**
*
* @param employeeId ID
* @param employeeName
* @param employeeEmail
* @param oldSalary
* @param newSalary
* @param effectiveDate
*/
public void sendSalaryAdjustmentEmail(String employeeId, String employeeName, String employeeEmail,
double oldSalary, double newSalary, String effectiveDate) {
String subject = "薪资调整通知";
double changeAmount = newSalary - oldSalary;
double changePercentage = (changeAmount / oldSalary) * 100;
String content = String.format(
"尊敬的 %s 先生/女士:\n\n" +
"很高兴通知您,您的薪资已进行调整。\n" +
"员工ID%s\n" +
"调整前薪资:%.2f\n" +
"调整后薪资:%.2f\n" +
"调整金额:%.2f (%.2f%%)\n" +
"生效日期:%s\n\n" +
"感谢您的努力工作!\n\n" +
"此致\n" +
"人力资源部",
employeeName, employeeId, oldSalary, newSalary,
changeAmount, changePercentage, effectiveDate
);
sendEmail(employeeEmail, subject, content);
}
/**
*
* @param employeeId ID
* @param employeeName
* @param employeeEmail
* @param oldPosition
* @param newPosition
* @param effectiveDate
*/
public void sendPositionChangeEmail(String employeeId, String employeeName, String employeeEmail,
String oldPosition, String newPosition, String effectiveDate) {
String subject = "职位变动通知";
String content = String.format(
"尊敬的 %s 先生/女士:\n\n" +
"很高兴通知您,您的职位已进行调整。\n" +
"员工ID%s\n" +
"原职位:%s\n" +
"新职位:%s\n" +
"生效日期:%s\n\n" +
"祝贺您!\n\n" +
"此致\n" +
"人力资源部",
employeeName, employeeId, oldPosition, newPosition, effectiveDate
);
sendEmail(employeeEmail, subject, content);
}
/**
*
* @param employeeId ID
* @param employeeName
* @param employeeEmail
* @param courseName
* @param trainingDate
* @param trainer
*/
public void sendTrainingNotificationEmail(String employeeId, String employeeName, String employeeEmail,
String courseName, String trainingDate, String trainer) {
String subject = "培训课程通知";
String content = String.format(
"尊敬的 %s 先生/女士:\n\n" +
"您已被安排参加以下培训课程:\n" +
"员工ID%s\n" +
"课程名称:%s\n" +
"培训日期:%s\n" +
"培训师:%s\n\n" +
"请提前做好准备。\n\n" +
"此致\n" +
"培训部门",
employeeName, employeeId, courseName, trainingDate, trainer
);
sendEmail(employeeEmail, subject, content);
}
/**
*
* @param employeeId ID
* @param employeeName
* @param employeeEmail
* @param certificateName
* @param issueDate
*/
public void sendCertificateEmail(String employeeId, String employeeName, String employeeEmail,
String certificateName, String issueDate) {
String subject = "证书发放通知";
String content = String.format(
"尊敬的 %s 先生/女士:\n\n" +
"恭喜您获得以下证书:\n" +
"员工ID%s\n" +
"证书名称:%s\n" +
"发放日期:%s\n\n" +
"您的证书已生成,可在系统中查看和下载。\n\n" +
"此致\n" +
"培训部门",
employeeName, employeeId, certificateName, issueDate
);
sendEmail(employeeEmail, subject, content);
}
/**
*
* API
*/
private void sendEmail(String toEmail, String subject, String content) {
// 模拟邮件发送过程
System.out.println("========================================");
System.out.println("【邮件已发送】");
System.out.println("收件人: " + toEmail);
System.out.println("主题: " + subject);
System.out.println("内容:\n" + content);
System.out.println("========================================");
}
}

Binary file not shown.

@ -1,142 +0,0 @@
import java.time.LocalDate;
/**
* -
*
*/
public class Employee {
private String id; // 员工ID
private String name; // 员工姓名
private double salary; // 薪资
private String department; // 部门
private String position; // 职位
private LocalDate hireDate; // 入职日期
private LocalDate birthDate; // 出生日期
private String email; // 邮箱(新增属性)
private boolean active; // 是否在职
/**
* -
*/
public Employee(String id, String name, double salary, String department,
String position, LocalDate hireDate, LocalDate birthDate, String email) {
this.id = id;
this.name = name;
this.salary = salary;
this.department = department;
this.position = position;
this.hireDate = hireDate;
this.birthDate = birthDate;
this.active = true;
setEmail(email); // 使用setter进行邮箱验证
}
/**
* -
* @param email
* @throws IllegalArgumentException
*/
public void setEmail(String email) {
if (isValidEmail(email)) {
this.email = email;
} else {
throw new IllegalArgumentException("无效的邮箱格式: " + email);
}
}
/**
*
* @param email
* @return true
*/
private boolean isValidEmail(String email) {
if (email == null || email.trim().isEmpty()) {
return false;
}
// 基本的邮箱格式验证正则表达式
String emailRegex = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$";
return email.matches(emailRegex);
}
/**
*
* @return
*/
public int getAge() {
LocalDate now = LocalDate.now();
int age = now.getYear() - birthDate.getYear();
if (now.getMonthValue() < birthDate.getMonthValue() ||
(now.getMonthValue() == birthDate.getMonthValue() &&
now.getDayOfMonth() < birthDate.getDayOfMonth())) {
age--;
}
return age;
}
/**
*
* @return
*/
public int getTenure() {
LocalDate now = LocalDate.now();
int tenure = now.getYear() - hireDate.getYear();
if (now.getMonthValue() < hireDate.getMonthValue() ||
(now.getMonthValue() == hireDate.getMonthValue() &&
now.getDayOfMonth() < hireDate.getDayOfMonth())) {
tenure--;
}
return tenure;
}
// Getter和Setter方法 - 遵循单一职责原则,只负责属性的访问和修改
public String getId() { return id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public double getSalary() { return salary; }
public void setSalary(double salary) {
if (salary >= 0) {
this.salary = salary;
} else {
throw new IllegalArgumentException("薪资不能为负数");
}
}
public String getDepartment() { return department; }
public void setDepartment(String department) { this.department = department; }
public String getPosition() { return position; }
public void setPosition(String position) { this.position = position; }
public LocalDate getHireDate() { return hireDate; }
public LocalDate getBirthDate() { return birthDate; }
public String getEmail() { return email; }
public boolean isActive() { return active; }
public void setActive(boolean active) { this.active = active; }
@Override
public String toString() {
return "Employee{" +
"id='" + id + "'" +
", name='" + name + "'" +
", salary=" + salary +
", department='" + department + "'" +
", position='" + position + "'" +
", hireDate=" + hireDate +
", age=" + getAge() +
", tenure=" + getTenure() + "年" +
", email='" + email + "'" +
", active=" + (active ? "在职" : "离职") +
"}";
}
}

@ -1,251 +0,0 @@
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* -
*
*/
public class EmployeeHistory {
private final String employeeId;
private final List<ChangeRecord> historyRecords;
/**
*
* @param employeeId ID
*/
public EmployeeHistory(String employeeId) {
this.employeeId = employeeId;
this.historyRecords = new ArrayList<>();
}
/**
*
* @param oldSalary
* @param newSalary
* @param reason
* @param changedBy
*/
public void recordSalaryChange(double oldSalary, double newSalary, String reason, String changedBy) {
String description = String.format("薪资从 %.2f 调整为 %.2f", oldSalary, newSalary);
ChangeRecord record = new ChangeRecord(ChangeType.SALARY_ADJUSTMENT,
description, reason, changedBy);
historyRecords.add(record);
}
/**
*
* @param oldPosition
* @param newPosition
* @param reason
* @param changedBy
*/
public void recordPositionChange(String oldPosition, String newPosition, String reason, String changedBy) {
String description = String.format("职位从 '%s' 变更为 '%s'", oldPosition, newPosition);
ChangeRecord record = new ChangeRecord(ChangeType.POSITION_CHANGE,
description, reason, changedBy);
historyRecords.add(record);
}
/**
*
* @param oldDepartment
* @param newDepartment
* @param reason
* @param changedBy
*/
public void recordDepartmentChange(String oldDepartment, String newDepartment, String reason, String changedBy) {
String description = String.format("部门从 '%s' 变更为 '%s'", oldDepartment, newDepartment);
ChangeRecord record = new ChangeRecord(ChangeType.DEPARTMENT_CHANGE,
description, reason, changedBy);
historyRecords.add(record);
}
/**
* /
* @param newStatus
* @param reason
* @param changedBy
*/
public void recordStatusChange(boolean newStatus, String reason, String changedBy) {
String description = "状态变更为 " + (newStatus ? "在职" : "离职");
ChangeRecord record = new ChangeRecord(ChangeType.STATUS_CHANGE,
description, reason, changedBy);
historyRecords.add(record);
}
/**
*
* @param fieldName
* @param oldValue
* @param newValue
* @param changedBy
*/
public void recordInfoChange(String fieldName, String oldValue, String newValue, String changedBy) {
String description = String.format("%s 从 '%s' 变更为 '%s'", fieldName, oldValue, newValue);
ChangeRecord record = new ChangeRecord(ChangeType.INFO_CHANGE,
description, "信息更新", changedBy);
historyRecords.add(record);
}
/**
*
* @param courseName
* @param certificateId ID
* @param score
* @param changedBy
*/
public void recordTrainingCompletion(String courseName, String certificateId, double score, String changedBy) {
String description = String.format("完成课程 '%s'证书ID: %s成绩: %.2f",
courseName, certificateId, score);
ChangeRecord record = new ChangeRecord(ChangeType.TRAINING_COMPLETION,
description, "培训完成", changedBy);
historyRecords.add(record);
}
/**
*
* @return
*/
public List<ChangeRecord> getAllHistory() {
List<ChangeRecord> sortedRecords = new ArrayList<>(historyRecords);
sortedRecords.sort(Comparator.comparing(ChangeRecord::getChangeTime).reversed());
return sortedRecords;
}
/**
*
* @param changeType
* @return
*/
public List<ChangeRecord> getHistoryByType(ChangeType changeType) {
return historyRecords.stream()
.filter(record -> record.getChangeType() == changeType)
.sorted(Comparator.comparing(ChangeRecord::getChangeTime).reversed())
.collect(Collectors.toList());
}
/**
*
* @param startTime
* @param endTime
* @return
*/
public List<ChangeRecord> getHistoryByTimeRange(LocalDateTime startTime, LocalDateTime endTime) {
return historyRecords.stream()
.filter(record -> !record.getChangeTime().isBefore(startTime) &&
!record.getChangeTime().isAfter(endTime))
.sorted(Comparator.comparing(ChangeRecord::getChangeTime).reversed())
.collect(Collectors.toList());
}
/**
* N
* @param n
* @return N
*/
public List<ChangeRecord> getLatestHistory(int n) {
List<ChangeRecord> sortedRecords = new ArrayList<>(historyRecords);
sortedRecords.sort(Comparator.comparing(ChangeRecord::getChangeTime).reversed());
return sortedRecords.stream().limit(n).collect(Collectors.toList());
}
/**
*
* @return
*/
public int getSalaryChangeCount() {
return (int) historyRecords.stream()
.filter(record -> record.getChangeType() == ChangeType.SALARY_ADJUSTMENT)
.count();
}
/**
*
* @return
*/
public int getPositionChangeCount() {
return (int) historyRecords.stream()
.filter(record -> record.getChangeType() == ChangeType.POSITION_CHANGE)
.count();
}
/**
*
* @return
*/
public int getDepartmentChangeCount() {
return (int) historyRecords.stream()
.filter(record -> record.getChangeType() == ChangeType.DEPARTMENT_CHANGE)
.count();
}
/**
*
* @return
*/
public int getTrainingCompletionCount() {
return (int) historyRecords.stream()
.filter(record -> record.getChangeType() == ChangeType.TRAINING_COMPLETION)
.count();
}
/**
* ID
* @return ID
*/
public String getEmployeeId() {
return employeeId;
}
/**
*
* @return
*/
public int getTotalRecordCount() {
return historyRecords.size();
}
/**
*
*/
public enum ChangeType {
SALARY_ADJUSTMENT, // 薪资调整
POSITION_CHANGE, // 职位变更
DEPARTMENT_CHANGE, // 部门变更
STATUS_CHANGE, // 状态变更
INFO_CHANGE, // 信息变更
TRAINING_COMPLETION // 培训完成
}
/**
*
*/
public static class ChangeRecord {
private final ChangeType changeType;
private final String description;
private final String reason;
private final String changedBy;
private final LocalDateTime changeTime;
public ChangeRecord(ChangeType changeType, String description, String reason, String changedBy) {
this.changeType = changeType;
this.description = description;
this.reason = reason;
this.changedBy = changedBy;
this.changeTime = LocalDateTime.now();
}
public ChangeType getChangeType() { return changeType; }
public String getDescription() { return description; }
public String getReason() { return reason; }
public String getChangedBy() { return changedBy; }
public LocalDateTime getChangeTime() { return changeTime; }
@Override
public String toString() {
return String.format("[%s] %s | 原因: %s | 操作人: %s | 时间: %s",
changeType.name(), description, reason, changedBy, changeTime);
}
}
}

@ -1,192 +0,0 @@
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
/**
* -
*
*/
public class EmployeeSearch {
/**
*
* @param employees
* @param minSalary
* @param maxSalary
* @return
*/
public List<Employee> searchBySalaryRange(List<Employee> employees, double minSalary, double maxSalary) {
if (minSalary > maxSalary) {
throw new IllegalArgumentException("最低薪资不能大于最高薪资");
}
return employees.stream()
.filter(e -> e.getSalary() >= minSalary && e.getSalary() <= maxSalary)
.collect(Collectors.toList());
}
/**
*
* @param employees
* @param startDate
* @param endDate
* @return
*/
public List<Employee> searchByHireDateRange(List<Employee> employees, LocalDate startDate, LocalDate endDate) {
if (startDate.isAfter(endDate)) {
throw new IllegalArgumentException("开始日期不能晚于结束日期");
}
return employees.stream()
.filter(e -> (!e.getHireDate().isBefore(startDate) && !e.getHireDate().isAfter(endDate)))
.collect(Collectors.toList());
}
/**
*
* @param employees
* @param department
* @return
*/
public List<Employee> searchByDepartment(List<Employee> employees, String department) {
if (department == null || department.trim().isEmpty()) {
throw new IllegalArgumentException("部门名称不能为空");
}
return employees.stream()
.filter(e -> e.getDepartment().equals(department))
.collect(Collectors.toList());
}
/**
*
* @param employees
* @param position
* @return
*/
public List<Employee> searchByPosition(List<Employee> employees, String position) {
if (position == null || position.trim().isEmpty()) {
throw new IllegalArgumentException("职位名称不能为空");
}
return employees.stream()
.filter(e -> e.getPosition().equals(position))
.collect(Collectors.toList());
}
/**
*
* @param employees
* @param minAge
* @param maxAge
* @return
*/
public List<Employee> searchByAgeRange(List<Employee> employees, int minAge, int maxAge) {
if (minAge > maxAge) {
throw new IllegalArgumentException("最小年龄不能大于最大年龄");
}
if (minAge < 0 || maxAge < 0) {
throw new IllegalArgumentException("年龄不能为负数");
}
return employees.stream()
.filter(e -> e.getAge() >= minAge && e.getAge() <= maxAge)
.collect(Collectors.toList());
}
/**
*
* @param employees
* @param minTenure
* @param maxTenure
* @return
*/
public List<Employee> searchByTenure(List<Employee> employees, int minTenure, int maxTenure) {
if (minTenure > maxTenure) {
throw new IllegalArgumentException("最小司龄不能大于最大司龄");
}
if (minTenure < 0 || maxTenure < 0) {
throw new IllegalArgumentException("司龄不能为负数");
}
return employees.stream()
.filter(e -> e.getTenure() >= minTenure && e.getTenure() <= maxTenure)
.collect(Collectors.toList());
}
/**
*
* @param employees
* @return
*/
public List<Employee> searchActiveEmployees(List<Employee> employees) {
return employees.stream()
.filter(Employee::isActive)
.collect(Collectors.toList());
}
/**
*
* @param employees
* @return
*/
public List<Employee> searchInactiveEmployees(List<Employee> employees) {
return employees.stream()
.filter(e -> !e.isActive())
.collect(Collectors.toList());
}
/**
*
* @param employees
* @param keyword
* @return
*/
public List<Employee> searchByNameKeyword(List<Employee> employees, String keyword) {
if (keyword == null || keyword.trim().isEmpty()) {
throw new IllegalArgumentException("搜索关键字不能为空");
}
String lowerKeyword = keyword.toLowerCase();
return employees.stream()
.filter(e -> e.getName().toLowerCase().contains(lowerKeyword))
.collect(Collectors.toList());
}
/**
*
* @param employees
* @param department
* @param minSalary
* @param maxSalary
* @return
*/
public List<Employee> searchByDepartmentAndSalaryRange(List<Employee> employees,
String department,
double minSalary,
double maxSalary) {
return employees.stream()
.filter(e -> e.getDepartment().equals(department))
.filter(e -> e.getSalary() >= minSalary && e.getSalary() <= maxSalary)
.collect(Collectors.toList());
}
/**
*
* @param employees
* @param department
* @param position
* @return
*/
public List<Employee> searchByDepartmentAndPosition(List<Employee> employees,
String department,
String position) {
return employees.stream()
.filter(e -> e.getDepartment().equals(department))
.filter(e -> e.getPosition().equals(position))
.collect(Collectors.toList());
}
public class DepartmentSalaryStats {
}
}

@ -1,230 +0,0 @@
import java.time.LocalDate;
import java.time.Period;
import java.util.*;
import java.util.stream.Collectors;
/**
* -
*
*/
public class EmployeeStatistics {
/**
*
* @param employees
* @return
*/
public double calculateTotalSalary(List<Employee> employees) {
return employees.stream()
.mapToDouble(Employee::getSalary)
.sum();
}
/**
*
* @param employees
* @return
*/
public double calculateAverageSalary(List<Employee> employees) {
if (employees.isEmpty()) {
return 0;
}
return calculateTotalSalary(employees) / employees.size();
}
/**
*
* @param employees
* @return
*/
public double getMaxSalary(List<Employee> employees) {
if (employees.isEmpty()) {
return 0;
}
return employees.stream()
.mapToDouble(Employee::getSalary)
.max()
.orElse(0);
}
/**
*
* @param employees
* @return
*/
public double getMinSalary(List<Employee> employees) {
if (employees.isEmpty()) {
return 0;
}
return employees.stream()
.mapToDouble(Employee::getSalary)
.min()
.orElse(0);
}
/**
*
* @param employees
* @return ->
*/
public Map<String, DepartmentSalaryStats> calculateDepartmentSalaryDistribution(List<Employee> employees) {
return employees.stream()
.collect(Collectors.groupingBy(Employee::getDepartment))
.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> {
List<Employee> deptEmployees = entry.getValue();
double totalSalary = deptEmployees.stream().mapToDouble(Employee::getSalary).sum();
double avgSalary = deptEmployees.isEmpty() ? 0 : totalSalary / deptEmployees.size();
double maxSalary = deptEmployees.stream().mapToDouble(Employee::getSalary).max().orElse(0);
double minSalary = deptEmployees.stream().mapToDouble(Employee::getSalary).min().orElse(0);
return new DepartmentSalaryStats(totalSalary, avgSalary, maxSalary, minSalary, deptEmployees.size());
}
));
}
/**
*
* @param employees
* @return ->
*/
public Map<String, Long> calculateAgeDistribution(List<Employee> employees) {
return employees.stream()
.collect(Collectors.groupingBy(
e -> {
int age = e.getAge();
if (age < 25) return "25岁以下";
else if (age < 35) return "25-34岁";
else if (age < 45) return "35-44岁";
else if (age < 55) return "45-54岁";
else return "55岁以上";
},
Collectors.counting()
));
}
/**
*
* @param employees
* @return ->
*/
public Map<String, Long> calculateTenureDistribution(List<Employee> employees) {
return employees.stream()
.collect(Collectors.groupingBy(
e -> {
int tenure = e.getTenure();
if (tenure < 1) return "不足1年";
else if (tenure < 3) return "1-2年";
else if (tenure < 5) return "3-4年";
else if (tenure < 10) return "5-9年";
else return "10年以上";
},
Collectors.counting()
));
}
/**
*
* @param employees
* @return ->
*/
public Map<String, Long> calculateDepartmentHeadcount(List<Employee> employees) {
return employees.stream()
.collect(Collectors.groupingBy(Employee::getDepartment, Collectors.counting()));
}
/**
*
* @param employees
* @param year
* @return
*/
public long getHireCountByYear(List<Employee> employees, int year) {
return employees.stream()
.filter(e -> e.getHireDate().getYear() == year)
.count();
}
/**
* Employee
* Employeegender
* @param employees
* @return ->
*/
// 由于Employee类中没有性别属性此方法作为示例保留
public Map<String, Long> calculateGenderDistribution(List<Employee> employees) {
// 实际实现需要在Employee类中添加gender属性
System.out.println("注意Employee类中暂未添加性别属性无法计算性别分布");
return new HashMap<>();
}
/**
* N
* @param employees
* @param n
* @return N
*/
public List<Employee> getTopNSalaryEmployees(List<Employee> employees, int n) {
if (n <= 0) {
throw new IllegalArgumentException("N必须为正整数");
}
return employees.stream()
.sorted(Comparator.comparingDouble(Employee::getSalary).reversed())
.limit(n)
.collect(Collectors.toList());
}
/**
*
* @param employees
* @return
*/
public double calculateActiveRate(List<Employee> employees) {
if (employees.isEmpty()) {
return 0;
}
long activeCount = employees.stream()
.filter(Employee::isActive)
.count();
return (double) activeCount / employees.size() * 100;
}
/**
*
*/
public static class DepartmentSalaryStats {
private final double totalSalary;
private final double averageSalary;
private final double maxSalary;
private final double minSalary;
private final int headcount;
public DepartmentSalaryStats(double totalSalary, double averageSalary,
double maxSalary, double minSalary, int headcount) {
this.totalSalary = totalSalary;
this.averageSalary = averageSalary;
this.maxSalary = maxSalary;
this.minSalary = minSalary;
this.headcount = headcount;
}
public double getTotalSalary() { return totalSalary; }
public double getAverageSalary() { return averageSalary; }
public double getMaxSalary() { return maxSalary; }
public double getMinSalary() { return minSalary; }
public int getHeadcount() { return headcount; }
@Override
public String toString() {
return "部门薪资统计{" +
"总薪资= " + totalSalary +
", 平均薪资= " + String.format("%.2f", averageSalary) +
", 最高薪资= " + maxSalary +
", 最低薪资= " + minSalary +
", 人数= " + headcount +
"}";
}
}
}

@ -1,216 +0,0 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
/**
* - 使
*/
public class EmployeeSystemDemo {
public static void main(String[] args) {
System.out.println("========================================");
System.out.println("员工管理系统演示(单一职责原则实现)");
System.out.println("========================================");
// 创建演示数据和服务
List<Employee> employees = createSampleEmployees();
// 演示基础功能
demonstrateBasicFeatures(employees);
// 演示进阶功能
demonstrateAdvancedFeatures(employees);
// 演示挑战功能
demonstrateChallengeFeatures(employees);
System.out.println("\n========================================");
System.out.println("演示完成!");
System.out.println("========================================");
}
/**
*
*/
private static List<Employee> createSampleEmployees() {
List<Employee> employees = new ArrayList<>();
employees.add(new Employee("EMP001", "张三", 15000.0, "技术部", "高级工程师",
LocalDate.of(2020, 5, 15), LocalDate.of(1990, 3, 20), "zhangsan@company.com"));
employees.add(new Employee("EMP002", "李四", 12000.0, "技术部", "工程师",
LocalDate.of(2021, 8, 10), LocalDate.of(1995, 6, 12), "lisi@company.com"));
employees.add(new Employee("EMP003", "王五", 18000.0, "技术部", "技术经理",
LocalDate.of(2018, 12, 20), LocalDate.of(1985, 11, 5), "wangwu@company.com"));
employees.add(new Employee("EMP004", "赵六", 9000.0, "人事部", "人事专员",
LocalDate.of(2022, 3, 1), LocalDate.of(1998, 2, 28), "zhaoliu@company.com"));
employees.add(new Employee("EMP005", "钱七", 13000.0, "财务部", "财务主管",
LocalDate.of(2019, 10, 8), LocalDate.of(1988, 9, 15), "qianqi@company.com"));
return employees;
}
/**
*
*/
private static void demonstrateBasicFeatures(List<Employee> employees) {
System.out.println("\n【基础功能演示】");
System.out.println("----------------------------------------");
// 1. Employee类的基本功能演示
System.out.println("1. 员工信息和邮箱验证:");
for (Employee emp : employees) {
System.out.println(emp);
}
// 2. 尝试设置无效邮箱
try {
Employee testEmp = employees.get(0);
System.out.println("\n2. 邮箱验证测试:");
System.out.println("尝试设置无效邮箱...");
testEmp.setEmail("invalid-email");
} catch (IllegalArgumentException e) {
System.out.println("验证成功:" + e.getMessage());
}
// 3. EmailService功能演示
System.out.println("\n3. 邮件通知服务演示:");
EmailService emailService = new EmailService();
// 发送入职通知
emailService.sendWelcomeEmail("EMP006", "孙八", "sunba@company.com",
"市场部", "2024-01-15");
// 发送薪资调整通知
emailService.sendSalaryAdjustmentEmail("EMP001", "张三", "zhangsan@company.com",
15000.0, 17000.0, "2024-02-01");
}
/**
*
*/
private static void demonstrateAdvancedFeatures(List<Employee> employees) {
System.out.println("\n【进阶功能演示】");
System.out.println("----------------------------------------");
// 1. EmployeeSearch功能演示
System.out.println("1. 员工搜索功能:");
EmployeeSearch search = new EmployeeSearch();
// 按薪资范围搜索
List<Employee> highSalaryEmployees = search.searchBySalaryRange(employees, 13000, 20000);
System.out.println("\n薪资13000-20000的员工");
highSalaryEmployees.forEach(System.out::println);
// 按部门搜索
List<Employee> techEmployees = search.searchByDepartment(employees, "技术部");
System.out.println("\n技术部员工");
techEmployees.forEach(System.out::println);
// 2. EmployeeStatistics功能演示
System.out.println("\n2. 员工统计功能:");
EmployeeStatistics stats = new EmployeeStatistics();
System.out.println("薪资统计:");
System.out.printf("总薪资: %.2f\n", stats.calculateTotalSalary(employees));
System.out.printf("平均薪资: %.2f\n", stats.calculateAverageSalary(employees));
System.out.printf("最高薪资: %.2f\n", stats.getMaxSalary(employees));
System.out.printf("最低薪资: %.2f\n", stats.getMinSalary(employees));
// 部门薪资分布
System.out.println("\n部门薪资分布");
Map<String, EmployeeStatistics.DepartmentSalaryStats> deptStats =
stats.calculateDepartmentSalaryDistribution(employees);
deptStats.forEach((dept, data) -> {
System.out.println(dept + ": " + data);
});
// 年龄分布
System.out.println("\n员工年龄分布");
Map<String, Long> ageDist = stats.calculateAgeDistribution(employees);
ageDist.forEach((range, count) -> {
System.out.println(range + ": " + count + "人");
});
}
/**
*
*/
private static void demonstrateChallengeFeatures(List<Employee> employees) {
System.out.println("\n【挑战功能演示】");
System.out.println("----------------------------------------");
// 1. EmployeeHistory功能演示
System.out.println("1. 员工历史记录功能:");
EmployeeHistory empHistory = new EmployeeHistory("EMP001");
// 记录各种变更
empHistory.recordSalaryChange(15000.0, 17000.0, "年度调薪", "HR-001");
empHistory.recordPositionChange("高级工程师", "资深工程师", "晋升", "HR-001");
empHistory.recordDepartmentChange("技术部", "研发部", "部门调整", "HR-001");
// 显示历史记录
System.out.println("\n员工EMP001的历史记录");
List<EmployeeHistory.ChangeRecord> records = empHistory.getAllHistory();
for (EmployeeHistory.ChangeRecord record : records) {
System.out.println(record);
}
// 2. 培训管理系统功能演示
System.out.println("\n创建培训课程");
TrainingCourse course1 = new TrainingCourse("COURSE001", "Java高级编程",
"Java企业级开发高级技术", 20, "张讲师", "技术部", "技术培训", 3);
TrainingCourse course2 = new TrainingCourse("COURSE002", "项目管理基础",
"项目管理理论与实践", 15, "李讲师", "管理部", "管理培训", 2);
TrainingManagementSystem trainingSystem = new TrainingManagementSystem();
trainingSystem.addCourse(course1);
trainingSystem.addCourse(course2);
// 员工报名
System.out.println("\n员工报名课程");
String recordId1 = trainingSystem.enrollEmployee("EMP001", "COURSE001",
"张三", "zhangsan@company.com");
// 开始培训
System.out.println("\n开始培训");
trainingSystem.startTraining(recordId1, LocalDate.now().minusDays(5));
// 完成培训(成绩合格,自动颁发证书)
System.out.println("\n完成培训并颁发证书");
trainingSystem.completeTraining(recordId1, LocalDate.now(), 92.5,
"张三", "zhangsan@company.com");
// 查看证书
List<TrainingRecord> trainingRecords = trainingSystem.getCourseTrainingRecords("COURSE001");
Certificate certificate = null;
if (!trainingRecords.isEmpty()) {
TrainingRecord record = trainingRecords.get(0);
certificate = trainingSystem.getCertificate(record.getCertificateId());
System.out.println("\n颁发的证书信息");
System.out.println(certificate);
}
// 生成培训报告
System.out.println("\n培训系统统计报告");
Map<String, Object> report = trainingSystem.generateTrainingReport();
report.forEach((key, value) -> {
System.out.println(key + ": " + value);
});
// 3. 综合演示:员工培训历史记录
System.out.println("\n3. 综合功能演示 - 员工培训历史:");
EmployeeHistory empTrainingHistory = new EmployeeHistory("EMP001");
String certId = certificate != null ? certificate.getCertificateId() : "CERT-N/A";
empTrainingHistory.recordTrainingCompletion("Java高级编程", certId, 92.5, "TRAIN-001");
System.out.println("\n员工培训完成记录");
List<EmployeeHistory.ChangeRecord> changeRecords =
empTrainingHistory.getHistoryByType(EmployeeHistory.ChangeType.TRAINING_COMPLETION);
changeRecords.forEach(System.out::println);
}
}

@ -1,155 +0,0 @@
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 ? "启用" : "禁用") +
"}";
}
}

@ -1,422 +0,0 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* -
*
*/
public class TrainingManagementSystem {
// 数据存储
private final Map<String, TrainingCourse> courses;
private final Map<String, TrainingRecord> trainingRecords;
private final Map<String, Certificate> certificates;
private final EmailService emailService;
private final Map<String, List<TrainingRecord>> employeeRecords; // 员工培训记录映射
/**
*
*/
public TrainingManagementSystem() {
this.courses = new HashMap<>();
this.trainingRecords = new HashMap<>();
this.certificates = new HashMap<>();
this.emailService = new EmailService();
this.employeeRecords = new HashMap<>();
}
// ====================== 课程管理功能 ======================
/**
*
* @param course
* @return true
*/
public boolean addCourse(TrainingCourse course) {
if (courses.containsKey(course.getCourseId())) {
System.out.println("课程ID已存在: " + course.getCourseId());
return false;
}
courses.put(course.getCourseId(), course);
System.out.println("课程添加成功: " + course.getCourseName());
return true;
}
/**
*
* @param courseId ID
* @return null
*/
public TrainingCourse getCourse(String courseId) {
return courses.get(courseId);
}
/**
*
* @param course
* @return true
*/
public boolean updateCourse(TrainingCourse course) {
if (!courses.containsKey(course.getCourseId())) {
System.out.println("课程不存在: " + course.getCourseId());
return false;
}
courses.put(course.getCourseId(), course);
System.out.println("课程更新成功: " + course.getCourseName());
return true;
}
/**
*
* @param courseId ID
* @return true
*/
public boolean deleteCourse(String courseId) {
if (!courses.containsKey(courseId)) {
System.out.println("课程不存在: " + courseId);
return false;
}
// 检查是否有相关的培训记录
boolean hasRecords = trainingRecords.values().stream()
.anyMatch(record -> record.getCourseId().equals(courseId));
if (hasRecords) {
System.out.println("无法删除课程:存在相关的培训记录");
return false;
}
courses.remove(courseId);
System.out.println("课程删除成功: " + courseId);
return true;
}
/**
*
* @return
*/
public List<TrainingCourse> getActiveCourses() {
return courses.values().stream()
.filter(TrainingCourse::isActive)
.collect(Collectors.toList());
}
/**
*
* @param department
* @return
*/
public List<TrainingCourse> getCoursesByDepartment(String department) {
return courses.values().stream()
.filter(course -> course.getDepartment().equals(department))
.collect(Collectors.toList());
}
// ====================== 培训记录管理功能 ======================
/**
*
* @param employeeId ID
* @param courseId ID
* @param employeeName
* @param employeeEmail
* @return ID
*/
public String enrollEmployee(String employeeId, String courseId,
String employeeName, String employeeEmail) {
// 检查课程是否存在且可报名
TrainingCourse course = courses.get(courseId);
if (course == null || !course.isEnrollable()) {
System.out.println("课程不存在或不可报名: " + courseId);
return null;
}
// 生成记录ID
String recordId = generateRecordId(employeeId, courseId);
// 创建培训记录
TrainingRecord record = new TrainingRecord(recordId, employeeId, courseId);
trainingRecords.put(recordId, record);
// 添加到员工培训记录映射
employeeRecords.computeIfAbsent(employeeId, k -> new ArrayList<>()).add(record);
// 发送报名通知邮件
emailService.sendTrainingNotificationEmail(employeeId, employeeName, employeeEmail,
course.getCourseName(), LocalDate.now().toString(), course.getTrainer());
System.out.println("员工报名成功: " + employeeId + " -> " + course.getCourseName());
return recordId;
}
/**
*
* @param recordId ID
* @param startDate
* @return true
*/
public boolean startTraining(String recordId, LocalDate startDate) {
TrainingRecord record = trainingRecords.get(recordId);
if (record == null) {
System.out.println("培训记录不存在: " + recordId);
return false;
}
try {
TrainingCourse course = courses.get(record.getCourseId());
record.startTraining(startDate, course.getTrainer());
System.out.println("培训开始成功: " + recordId);
return true;
} catch (Exception e) {
System.out.println("培训开始失败: " + e.getMessage());
return false;
}
}
/**
*
* @param recordId ID
* @param completionDate
* @param score
* @param employeeName
* @param employeeEmail
* @return true
*/
public boolean completeTraining(String recordId, LocalDate completionDate, double score,
String employeeName, String employeeEmail) {
TrainingRecord record = trainingRecords.get(recordId);
if (record == null) {
System.out.println("培训记录不存在: " + recordId);
return false;
}
try {
record.completeTraining(completionDate, score);
// 如果成绩合格,自动颁发证书
if (record.isPassed()) {
issueCertificate(recordId, employeeName, employeeEmail);
}
System.out.println("培训完成成功: " + recordId);
return true;
} catch (Exception e) {
System.out.println("培训完成失败: " + e.getMessage());
return false;
}
}
/**
*
* @param recordId ID
* @param reason
* @return true
*/
public boolean cancelTraining(String recordId, String reason) {
TrainingRecord record = trainingRecords.get(recordId);
if (record == null) {
System.out.println("培训记录不存在: " + recordId);
return false;
}
try {
record.cancelTraining(reason);
System.out.println("培训取消成功: " + recordId);
return true;
} catch (Exception e) {
System.out.println("培训取消失败: " + e.getMessage());
return false;
}
}
// ====================== 证书管理功能 ======================
/**
*
* @param recordId ID
* @param employeeName
* @param employeeEmail
* @return ID
*/
public String issueCertificate(String recordId, String employeeName, String employeeEmail) {
TrainingRecord record = trainingRecords.get(recordId);
if (record == null) {
System.out.println("培训记录不存在: " + recordId);
return null;
}
TrainingCourse course = courses.get(record.getCourseId());
try {
// 生成证书ID
String certificateId = generateCertificateId(record.getEmployeeId(), course.getCourseId());
// 创建证书
Certificate certificate = new Certificate(certificateId,
record.getEmployeeId(),
course.getCourseId(),
course.getCourseName(),
"公司培训部门",
course.getTrainer(),
record.getScore());
// 设置证书有效期默认3年
certificate.setValidYears(3);
// 颁发证书
record.issueCertificate(certificateId);
certificates.put(certificateId, certificate);
// 发送证书通知邮件
emailService.sendCertificateEmail(record.getEmployeeId(), employeeName, employeeEmail,
course.getCourseName(), LocalDate.now().toString());
System.out.println("证书颁发成功: " + certificateId);
return certificateId;
} catch (Exception e) {
System.out.println("证书颁发失败: " + e.getMessage());
return null;
}
}
/**
*
* @param certificateId ID
* @return
*/
public Certificate getCertificate(String certificateId) {
return certificates.get(certificateId);
}
/**
*
* @param certificateId ID
* @param reason
* @return true
*/
public boolean revokeCertificate(String certificateId, String reason) {
Certificate certificate = certificates.get(certificateId);
if (certificate == null) {
System.out.println("证书不存在: " + certificateId);
return false;
}
certificate.revokeCertificate(reason);
System.out.println("证书吊销成功: " + certificateId);
return true;
}
// ====================== 查询功能 ======================
/**
*
* @param employeeId ID
* @return
*/
public List<TrainingRecord> getEmployeeTrainingRecords(String employeeId) {
return employeeRecords.getOrDefault(employeeId, new ArrayList<>());
}
/**
*
* @param employeeId ID
* @return
*/
public List<Certificate> getEmployeeActiveCertificates(String employeeId) {
return certificates.values().stream()
.filter(cert -> cert.getEmployeeId().equals(employeeId) &&
cert.isActive() && !cert.isExpired())
.collect(Collectors.toList());
}
/**
*
* @param courseId ID
* @return
*/
public List<TrainingRecord> getCourseTrainingRecords(String courseId) {
return trainingRecords.values().stream()
.filter(record -> record.getCourseId().equals(courseId))
.collect(Collectors.toList());
}
/**
*
* @return
*/
public Map<String, Object> generateTrainingReport() {
Map<String, Object> report = new HashMap<>();
// 总课程数
report.put("totalCourses", courses.size());
// 启用课程数
report.put("activeCourses", getActiveCourses().size());
// 总培训记录数
report.put("totalRecords", trainingRecords.size());
// 各状态记录数
Map<TrainingRecord.RecordStatus, Long> statusCount = trainingRecords.values().stream()
.collect(Collectors.groupingBy(TrainingRecord::getStatus, Collectors.counting()));
report.put("statusCount", statusCount);
// 总证书数
report.put("totalCertificates", certificates.size());
// 有效证书数
long activeCertificates = certificates.values().stream()
.filter(cert -> cert.isActive() && !cert.isExpired())
.count();
report.put("activeCertificates", activeCertificates);
// 平均成绩
Double averageScore = trainingRecords.values().stream()
.filter(record -> record.getScore() != null)
.mapToDouble(TrainingRecord::getScore)
.average()
.orElse(0);
report.put("averageScore", averageScore);
return report;
}
// ====================== 辅助方法 ======================
/**
* ID
*/
private String generateRecordId(String employeeId, String courseId) {
return String.format("REC-%s-%s-%d",
employeeId, courseId, System.currentTimeMillis());
}
/**
* ID
*/
private String generateCertificateId(String employeeId, String courseId) {
return String.format("CERT-%s-%s-%d",
employeeId, courseId, System.currentTimeMillis());
}
/**
*
* @return
*/
public int getEmployeeCount() {
return employeeRecords.size();
}
/**
*
* @param days
* @return
*/
public List<Certificate> getExpiringCertificates(int days) {
LocalDate futureDate = LocalDate.now().plusDays(days);
return certificates.values().stream()
.filter(cert -> cert.isActive() &&
cert.getExpiryDate() != null &&
!cert.isExpired() &&
cert.getExpiryDate().isBefore(futureDate))
.collect(Collectors.toList());
}
}

@ -1,189 +0,0 @@
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'");
}
}

@ -0,0 +1,2 @@
# 456
Loading…
Cancel
Save