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.

179 lines
7.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 邮件服务类 - 负责邮件通知功能
* 遵循单一职责原则:只负责邮件发送相关的业务逻辑
*/
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("========================================");
}
}