Commit ed2d5cc3 authored by Vijay Akula's avatar Vijay Akula

Leave notification changes

parent b5b23ffa
......@@ -17,12 +17,12 @@ import com.nisum.myteam.utils.MyTeamDateUtils;
import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.utils.constants.EmpSubStatus;
import com.nisum.myteam.utils.constants.Shifts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.mail.MessagingException;
import java.io.IOException;
import java.time.LocalDateTime;
......@@ -32,10 +32,10 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Component
public class LeaveNotificationScheduler {
private static final Logger logger = LoggerFactory.getLogger(LeaveNotificationScheduler.class);
//private static final Logger logger = LoggerFactory.getLogger(LeaveNotificationScheduler.class);
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
......@@ -58,84 +58,97 @@ public class LeaveNotificationScheduler {
private SubStatusService subStatusService;
@Scheduled(cron = "${email.leave.notification.shift1.cron}")
//@Scheduled(cron = "${email.leave.notification.shift1.cron}")
@Scheduled(cron = "0 * * * * ?")
public void scheduleLeaveMailForShift1Empls() throws IOException, MessagingException, MyTeamException {
//Shift 1(9:00 AM - 6:00 PM)
logger.info(Shifts.SHIFT1.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
log.info(Shifts.SHIFT1.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
sendMailToAbsentees(Shifts.SHIFT1.getShiftType());
}
@Scheduled(cron = "${email.leave.notification.shift2.cron}")
// @Scheduled(cron = "${email.leave.notification.shift2.cron}")
public void scheduleLeaveMailForShift2Empls() throws IOException, MessagingException, MyTeamException {
//Shift-2(2:00 PM - 11:00 PM)--General Shift
logger.info(Shifts.SHIFT2.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
log.info(Shifts.SHIFT2.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
sendMailToAbsentees(Shifts.SHIFT2.getShiftType());
}
@Scheduled(cron = "${email.leave.notification.shift3.cron}")
// @Scheduled(cron = "${email.leave.notification.shift3.cron}")
public void scheduleLeaveMailForShift3Empls() throws IOException, MessagingException, MyTeamException {
//Shift 3(10:00 PM - 6:00 AM)
logger.info(Shifts.SHIFT3.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
log.info(Shifts.SHIFT3.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
sendMailToAbsentees(Shifts.SHIFT3.getShiftType());
}
@Scheduled(cron = "${email.leave.notification.shift4.cron}")
// @Scheduled(cron = "${email.leave.notification.shift4.cron}")
public void scheduleLeaveMailForShift4Empls() throws IOException, MessagingException, MyTeamException {
//Shift 4(7:30 AM - 3:30 PM)
logger.info(Shifts.SHIFT4.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
log.info(Shifts.SHIFT4.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
sendMailToAbsentees(Shifts.SHIFT4.getShiftType());
}
@Scheduled(cron = "${email.leave.notification.shift5.cron}")
// @Scheduled(cron = "${email.leave.notification.shift5.cron}")
public void scheduleLeaveMailForShift5Empls() throws IOException, MessagingException, MyTeamException {
//Shift 5(11:30 AM - 7:30 PM)
logger.info(Shifts.SHIFT5.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
log.info(Shifts.SHIFT5.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
sendMailToAbsentees(Shifts.SHIFT5.getShiftType());
}
private void sendMailToAbsentees(String shift) throws IOException, MessagingException, MyTeamException {
Map<String, Object> model = new HashMap<String, Object>();
String currentDate = dateTimeFormatter.format(LocalDateTime.now());
String functionalGroupName;
final String mailSubject = String.valueOf("Date::").concat(MyTeamDateUtils.FormatTodaysDate() + "::").concat(environment.getProperty("email.leave.notification.subject"));
Employee employee;
String empSubStatus;
Employee employee=new Employee();
String empSubStatus="";
try {
if (!MyTeamDateUtils.isTodayHoliday(environment.getProperty("email.holidays.list.2019", "14-01-2019,21-03-2019,19-04-2019,05-06-2019,12-08-2019,15-08-2019,02-09-2019,02-10-2019,08-10-2019,25-12-2019"))) {
log.info("Inside not holiday");
List<AttendenceData> attendenceList = attendanceService.getAttendanciesReport(currentDate, shift);
List<AttendenceData> absentiesList = attendenceList.stream()
.filter(attendance -> attendance.getPresent().equalsIgnoreCase(MyTeamUtils.ABSENT)).collect(Collectors.toList());
for (AttendenceData absentee : absentiesList) {
//model.put("employeeName", );//mail.setModel(model);
System.out.println("inside loop");
Mail mail = new Mail();
mail.setFrom(environment.getProperty("email.leave.notification.from"));
mail.setSubject(mailSubject);
employee = employeeService.getEmployeeById(absentee.getEmployeeId());
EmployeeSubStatus subStatus = subStatusService.getCurrentSubStatus(employee.getEmployeeId());
empSubStatus = (String) subStatus.getSubStatus();
if (empSubStatus == null)
empSubStatus = "";
try {
employee = employeeService.getEmployeeById(absentee.getEmployeeId());
System.out.println("employee Details::"+employee);
EmployeeSubStatus subStatusObj = subStatusService.getCurrentSubStatus(employee.getEmployeeId());
System.out.println("Emplyee SubStatusObj::" + subStatusObj);
if (subStatusObj != null) {
if (subStatusObj.getSubStatus() != null) {
empSubStatus = (String) subStatusObj.getSubStatus();
System.out.println("The empSubssttatus::" + empSubStatus);
} else {
empSubStatus = "";
}
}
System.out.println("After IF");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("The final empSubStatus::"+empSubStatus);
if (employee.getEmpStatus().equalsIgnoreCase(EmployeeStatus.ACTIVE.getStatus()) &&
(!empSubStatus.equalsIgnoreCase(EmpSubStatus.LONG_LEAVE.getLeaveType()) &&
!empSubStatus.equalsIgnoreCase(EmpSubStatus.MATERNITY_LEAVE.getLeaveType()) &&
!empSubStatus.equalsIgnoreCase(EmpSubStatus.ONSITE_TRAVEL.getLeaveType()) &&
!empSubStatus.equalsIgnoreCase(EmpSubStatus.AT_CLIENT_LOCATION.getLeaveType()))) {
logger.info("Mail Notification is sending to:" + absentee.getEmployeeName() + "::" + absentee.getEmailId());
log.info("Mail Notification is sending to:" + absentee.getEmployeeName() + "::" + absentee.getEmailId());
mail.setEmpName(absentee.getEmployeeName());
mail.setTo(absentee.getEmailId());//mail.setEmpName("Prayas");//mail.setTo("pjain@nisum.com");
......
......@@ -112,7 +112,7 @@ public class MailService implements IMailService {
helper.setCc(mail.getCc());//helper.setBcc(mail.getBcc());//log.info("Mail Content::"+content);//log.info("The Mail Object::"+mail);
}
emailSender.send(message);
//emailSender.send(message);
}
public void sendProjectNotification(Mail mail) throws MessagingException, IOException
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment