Commit 2488b53e authored by vikram singh's avatar vikram singh

Updated substatus service

parent 4aae69af
......@@ -11,6 +11,10 @@ import com.nisum.myteam.utils.MyTeamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
......@@ -101,10 +105,13 @@ public class SubStatusService implements ISubStatusService {
@Override
public List<EmployeeSubStatusVO> employeesBasedOnSubStatusForGivenDates(Date fromDate, Date toDate, String subStatus) {
List<EmployeeSubStatusVO> employees=new ArrayList<>();
employeeSubStatusRepo.findBySubStatus(subStatus).stream().filter(e->
( e.getFromDate().compareTo(fromDate)<=0 && e.getToDate().compareTo(fromDate)>=0)
|| (e.getFromDate().compareTo(fromDate)<=0 && e.getToDate().compareTo(fromDate)>=0)
)
List<EmployeeSubStatus> employeswithSubStatus=employeeSubStatusRepo.findBySubStatus(subStatus);
if(subStatus.equals("All")) {
employeswithSubStatus=employeeSubStatusRepo.findAll();
}
employeswithSubStatus.stream().filter(e->isDateCommon(e,fromDate,toDate)
)
.forEach(e->{
Employee employee=employeeRepo.findByEmployeeIdAndEmpStatus(e.getEmployeeID(), MyTeamUtils.ACTIVE);
if(employee!=null) {
......@@ -120,4 +127,21 @@ public class SubStatusService implements ISubStatusService {
return employees;
}
private boolean isDateCommon(EmployeeSubStatus e, Date fromDate, Date toDate) {
for (LocalDate datei = convert(fromDate); datei.isBefore(convert(toDate).plusDays(1)); datei = datei.plusDays(1))
for (LocalDate datej = convert(e.getFromDate()); datej.isBefore(convert(e.getToDate()).plusDays(1)); datej = datej.plusDays(1))
if(datej.equals(datei))
return true;
return false;
}
private LocalDate convert(Date date) {
Instant instant = Instant.ofEpochMilli(date.getTime());
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
return localDateTime.toLocalDate();
}
}
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