|
|
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);
|
|
|
}
|
|
|
} |