Commit 7865ca77 authored by Md Suleman's avatar Md Suleman

effective time period changes and employee inactive changes

parent 9744b7fc
...@@ -10,10 +10,12 @@ import com.nisum.myteam.service.IEmployeeService; ...@@ -10,10 +10,12 @@ import com.nisum.myteam.service.IEmployeeService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.transaction.Transactional;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -31,17 +33,26 @@ public class EffectiveLoginTimeController { ...@@ -31,17 +33,26 @@ public class EffectiveLoginTimeController {
@Autowired @Autowired
private IEmployeeService employeeService; private IEmployeeService employeeService;
@GetMapping("/updateLogins") @Transactional
public List<EffectiveLoginData> getLoginData() throws MyTeamException { @PostMapping("/updateLogins")
public List<EffectiveLoginData> getLoginData(
@RequestParam("date")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date date) throws MyTeamException, ParseException {
effectiveLoginTimeService.deleteLogins(date);
List<EffectiveLoginData> loginData = new ArrayList<>(); List<EffectiveLoginData> loginData = new ArrayList<>();
List<Employee> allEmployees = employeeService.getActiveEmployees(); List<Employee> allEmployees = employeeService.getActiveEmployees();
for(Employee employee:allEmployees){ for(Employee employee:allEmployees){
EffectiveLoginData effectiveLoginData = EffectiveLoginData effectiveLoginData =
effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee); effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee,date);
loginData.add(effectiveLoginData); loginData.add(effectiveLoginData);
} }
return loginData; return loginData;
} }
@DeleteMapping("/deleteLogins")
public void deleteLoginDate(@RequestParam("date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date date) throws ParseException {
effectiveLoginTimeService.deleteLogins(date);
}
@GetMapping("/effectiveLogin") @GetMapping("/effectiveLogin")
public Map<String,Object> getAllEmployeesLoginData( public Map<String,Object> getAllEmployeesLoginData(
@RequestParam("employeeId") long employeeId, @RequestParam("employeeId") long employeeId,
...@@ -52,25 +63,25 @@ public class EffectiveLoginTimeController { ...@@ -52,25 +63,25 @@ public class EffectiveLoginTimeController {
} }
@DeleteMapping("/deleteLoginData") // @DeleteMapping("/deleteLoginData")
public ResponseEntity<?> deleteLoginData(@RequestParam("fromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date fromDate, // public ResponseEntity<?> deleteLoginData(@RequestParam("fromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date fromDate,
@RequestParam("toDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date toDate, @RequestParam("employeeId") String employeeId, HttpServletRequest request) throws MyTeamException { // @RequestParam("toDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date toDate, @RequestParam("employeeId") String employeeId, HttpServletRequest request) throws MyTeamException {
effectiveLoginTimeService.deleteEmployeeLoginData(employeeId,fromDate,toDate); // effectiveLoginTimeService.deleteEmployeeLoginData(employeeId,fromDate,toDate);
ResponseDetails responseDetails = new ResponseDetails(new Date(), 904, "delete Employees Login details Successfully", // ResponseDetails responseDetails = new ResponseDetails(new Date(), 904, "delete Employees Login details Successfully",
"delete Employees Login details Successfully", null, request.getRequestURI(), "Login details", null); // "delete Employees Login details Successfully", null, request.getRequestURI(), "Login details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK); // return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
} // }
@PostMapping("/syncLoginDataByDateRange") // @PostMapping("/syncLoginDataByDateRange")
public List<EffectiveLoginData> syncLoginDataByDateRange(@RequestParam("fromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date fromDate, // public List<EffectiveLoginData> syncLoginDataByDateRange(@RequestParam("fromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date fromDate,
@RequestParam("toDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date toDate) throws MyTeamException { // @RequestParam("toDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date toDate) throws MyTeamException {
List<EffectiveLoginData> loginData = new ArrayList<>(); // List<EffectiveLoginData> loginData = new ArrayList<>();
List<Employee> allEmployees = employeeService.getActiveEmployees(); // List<Employee> allEmployees = employeeService.getActiveEmployees();
//allEmployees.removeIf(s -> !"40270".equalsIgnoreCase(s.getEmployeeId())); // //allEmployees.removeIf(s -> !"40270".equalsIgnoreCase(s.getEmployeeId()));
for (Employee employee : allEmployees) { // for (Employee employee : allEmployees) {
EffectiveLoginData effectiveLoginData = // EffectiveLoginData effectiveLoginData =
effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee, fromDate, toDate); // effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee, fromDate, toDate);
loginData.add(effectiveLoginData); // loginData.add(effectiveLoginData);
} // }
return loginData; // return loginData;
} // }
} }
...@@ -10,6 +10,7 @@ public interface EffectiveLoginDataRepo extends MongoRepository<EffectiveLoginDa ...@@ -10,6 +10,7 @@ public interface EffectiveLoginDataRepo extends MongoRepository<EffectiveLoginDa
List<EffectiveLoginData> findByEmployeeId(String employeeId); List<EffectiveLoginData> findByEmployeeId(String employeeId);
List<EffectiveLoginData> findByDateBetween(Date from,Date to); List<EffectiveLoginData> findByDateBetweenOrderByDate(Date from,Date to);
void deleteByDate(Date date);
} }
...@@ -29,7 +29,7 @@ public class EffectiveLoginTimeScheduler { ...@@ -29,7 +29,7 @@ public class EffectiveLoginTimeScheduler {
List<Employee> allEmployees = employeeService.getActiveEmployees(); List<Employee> allEmployees = employeeService.getActiveEmployees();
for(Employee employee:allEmployees){ for(Employee employee:allEmployees){
EffectiveLoginData effectiveLoginData = EffectiveLoginData effectiveLoginData =
effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee); effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee,null);
} }
} }
} }
...@@ -64,29 +64,29 @@ public class EmployeeAVGHoursScheduler { ...@@ -64,29 +64,29 @@ public class EmployeeAVGHoursScheduler {
logger.info("sendEmployessAvgHoursMailToLeadsnotification::"); logger.info("sendEmployessAvgHoursMailToLeadsnotification::");
SchedulersLogsDetails schedulersLogsDetails = schedulersLogsDetailsService.getCurrentSchedulerLogDetails("EmployeeAVGHoursScheduler", new Date()); SchedulersLogsDetails schedulersLogsDetails = schedulersLogsDetailsService.getCurrentSchedulerLogDetails("EmployeeAVGHoursScheduler", new Date());
if (schedulersLogsDetails == null || !"Active".equalsIgnoreCase(schedulersLogsDetails.getSchedulerStatus())) { if (schedulersLogsDetails == null || !"Active".equalsIgnoreCase(schedulersLogsDetails.getSchedulerStatus())) {
sendhoursExemptEmpListToLeads();
} }
sendhoursExemptEmpListToLeads();
} }
private void sendhoursExemptEmpListToLeads() throws MessagingException { private void sendhoursExemptEmpListToLeads() throws MessagingException {
logger.info("sending avg hours list to managers");
SchedulersLogsDetails schedulersLogsDetails; SchedulersLogsDetails schedulersLogsDetails;
Mail mail = new Mail(); Mail mail = new Mail();
LocalDate dt = LocalDate.now(); LocalDate lastWeekDay = LocalDate.now().minusWeeks(1);
try { try {
Date friday = Date.from(dt.with(TemporalAdjusters.previous(DayOfWeek.FRIDAY)).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); Date monday = Date.from(lastWeekDay.with(DayOfWeek.MONDAY).atStartOfDay(ZoneId.systemDefault()).toInstant());
Date monday = Date.from(dt.with(TemporalAdjusters.previous(DayOfWeek.MONDAY)).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); Date sunday = Date.from(lastWeekDay.with(DayOfWeek.SUNDAY).atStartOfDay(ZoneId.systemDefault()).toInstant());
List<Employee> activeEmpList = employeeService.getActiveEmployees(); List<Employee> activeEmpList = employeeService.getActiveEmployees();
List<LoginDetailsVO> hoursExemptEmployeeList = new ArrayList<>(); List<LoginDetailsVO> hoursExemptEmployeeList = new ArrayList<>();
activeEmpList.removeIf(e -> "At Client Location".equalsIgnoreCase(e.getEmpSubStatus() instanceof String ? (String) e.getEmpSubStatus() : null));
activeEmpList.removeIf(e -> { activeEmpList.removeIf(e -> {
try { try {
Map<String, Object> obj = effectiveLoginTimeService.getEmployeesEffLoginData(new Long(e.getEmployeeId()), monday, friday); Map<String, Object> obj = effectiveLoginTimeService.getEmployeesEffLoginData(new Long(e.getEmployeeId()), monday, sunday);
if (obj != null && (String) obj.get("averageTime") != null) { if (obj != null && (String) obj.get("averageTime") != null) {
String hoursMins[] = ((String) obj.get("averageTime")).split(":"); String hoursMins[] = ((String) obj.get("averageTime")).split(":");
if (hoursMins != null) { if (hoursMins != null) {
boolean isHoursExemptEmployee = new Long(hoursMins[0]) < 8; boolean isHoursExemptEmployee = new Long(hoursMins[0]) < 8;
if (isHoursExemptEmployee) { if (isHoursExemptEmployee) {
//System.out.println(" Hours avg " + obj.get("data"));
LoginDetailsVO loginDetailsVO = new LoginDetailsVO(); LoginDetailsVO loginDetailsVO = new LoginDetailsVO();
loginDetailsVO.setEmployeeId(e.getEmployeeId()); loginDetailsVO.setEmployeeId(e.getEmployeeId());
loginDetailsVO.setEmployeeName(e.getEmployeeName()); loginDetailsVO.setEmployeeName(e.getEmployeeName());
...@@ -96,7 +96,9 @@ public class EmployeeAVGHoursScheduler { ...@@ -96,7 +96,9 @@ public class EmployeeAVGHoursScheduler {
StringBuilder orphanLoginSB = new StringBuilder(); StringBuilder orphanLoginSB = new StringBuilder();
effectiveLoginDataList.stream().forEach(eloginData -> { effectiveLoginDataList.stream().forEach(eloginData -> {
if (eloginData.getOrphanLogin() != null && !eloginData.getOrphanLogin().isEmpty()) if (eloginData.getOrphanLogin() != null && !eloginData.getOrphanLogin().isEmpty())
orphanLoginSB.append(" " + parseDate(eloginData.getDate(), "dd-MMM-yyyy") + " - " + eloginData.getOrphanLogin().stream().collect(Collectors.joining(",", "[", "]"))); orphanLoginSB.append(" " + parseDate(eloginData.getDate(), "dd-MMM-yyyy")
+ " - " + eloginData.getOrphanLogin().stream()
.collect(Collectors.joining(",", "[", "]")));
}); });
loginDetailsVO.setOrphanLogin(orphanLoginSB.toString()); loginDetailsVO.setOrphanLogin(orphanLoginSB.toString());
hoursExemptEmployeeList.add(loginDetailsVO); hoursExemptEmployeeList.add(loginDetailsVO);
......
...@@ -10,11 +10,13 @@ import java.util.Map; ...@@ -10,11 +10,13 @@ import java.util.Map;
public interface IEffectiveLoginTimeService { public interface IEffectiveLoginTimeService {
public EffectiveLoginData calculateEffectiveLoginTimeForEmpAndSave(Employee employee) throws MyTeamException; public EffectiveLoginData calculateEffectiveLoginTimeForEmpAndSave(Employee employee, Date date) throws MyTeamException;
public Map<String,Object> getEmployeesEffLoginData(long employeeId, Date fromDate, Date toDate) throws ParseException; public Map<String,Object> getEmployeesEffLoginData(long employeeId, Date fromDate, Date toDate) throws ParseException;
public void deleteEmployeeLoginData(String employeeId, Date fromDate, Date toDate) throws MyTeamException; public void deleteLogins(Date date) throws ParseException;
EffectiveLoginData calculateEffectiveLoginTimeForEmpAndSave(Employee employee, Date fromDate, Date toDate) throws MyTeamException; // public void deleteEmployeeLoginData(String employeeId, Date fromDate, Date toDate) throws MyTeamException;
//
// EffectiveLoginData calculateEffectiveLoginTimeForEmpAndSave(Employee employee, Date fromDate, Date toDate) throws MyTeamException;
} }
...@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service; ...@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import javax.transaction.Transactional;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -167,6 +168,7 @@ public class EmployeeService implements IEmployeeService { ...@@ -167,6 +168,7 @@ public class EmployeeService implements IEmployeeService {
// } // }
@Override @Override
@Transactional
public Employee updateEmployee(Employee employeeReq, String loginEmpId) throws ParseException { public Employee updateEmployee(Employee employeeReq, String loginEmpId) throws ParseException {
// update all emp details to inactive if employee is inactive // update all emp details to inactive if employee is inactive
...@@ -241,10 +243,12 @@ public class EmployeeService implements IEmployeeService { ...@@ -241,10 +243,12 @@ public class EmployeeService implements IEmployeeService {
FindAndModifyOptions options = new FindAndModifyOptions(); FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true); options.returnNew(true);
options.upsert(true); options.upsert(true);
Employee employeeUpdated = mongoTemplate.findAndModify(query, update, options, Employee.class);
if (employeeReq.getEmpStatus().equals("In Active")) { if (employeeReq.getEmpStatus().equals("In Active")) {
resourceService.makeResourceInactive(employeeReq.getEmployeeId(), employeeReq.getEndDate()); resourceService.makeResourceInactive(employeeReq.getEmployeeId(), employeeReq.getEndDate());
update.set("emailId", employeeReq.getEmailId()+MyTeamUtils._OLD);
update.set("employeeId", employeeReq.getEmployeeId()+MyTeamUtils._OLD);
} }
Employee employeeUpdated = mongoTemplate.findAndModify(query, update, options, Employee.class);
response.put("messege", "Employee has been updated"); response.put("messege", "Employee has been updated");
return employeeUpdated; return employeeUpdated;
} }
......
...@@ -181,7 +181,6 @@ public class MailService implements IMailService { ...@@ -181,7 +181,6 @@ public class MailService implements IMailService {
@Override @Override
public void sendExemptHoursEmployeDetailsToLeads(Mail mail, List<LoginDetailsVO> hoursExemptEmployeeList) throws MessagingException, IOException { public void sendExemptHoursEmployeDetailsToLeads(Mail mail, List<LoginDetailsVO> hoursExemptEmployeeList) throws MessagingException, IOException {
System.out.println(hoursExemptEmployeeList.size());
if(Optional.ofNullable(hoursExemptEmployeeList).isPresent() ) { if(Optional.ofNullable(hoursExemptEmployeeList).isPresent() ) {
MimeMessage message = emailSender.createMimeMessage(); MimeMessage message = emailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true); MimeMessageHelper helper = new MimeMessageHelper(message, true);
......
...@@ -108,8 +108,12 @@ public class MyTeamUtils { ...@@ -108,8 +108,12 @@ public class MyTeamUtils {
public final static String EMPLOYEE_YESTERDAY_LOGIN_DETAILS_QUERY = "SELECT emp.FirstName, emp.EmployeeCode, pd.TransactionDateTime, re.IOEntryStatus, re.ReaderName\n" + public final static String EMPLOYEE_YESTERDAY_LOGIN_DETAILS_QUERY = "SELECT emp.FirstName, emp.EmployeeCode, pd.TransactionDateTime, re.IOEntryStatus, re.ReaderName\n" +
"FROM ProcessData AS pd , EmployeeMaster AS emp, Readers AS re \n" + "FROM ProcessData AS pd , EmployeeMaster AS emp, Readers AS re \n" +
"WHERE emp.EmployeeMasterID = pd.EmployeeID AND re.ReaderID = pd.ReaderID AND emp.EmployeeCode = %s \n" + "WHERE emp.EmployeeMasterID = pd.EmployeeID AND re.ReaderID = pd.ReaderID AND emp.EmployeeCode = %s \n" +
"AND pd.TransactionDateTime <= CONVERT(date,GETDATE()) AND pd.TransactionDateTime >= CONVERT(date,GETDATE()-1) " + "AND pd.TransactionDateTime < CONVERT(date,GETDATE()) AND pd.TransactionDateTime >= CONVERT(date,GETDATE()-1) " +
"ORDER BY pd.TransactionDateTime"; "ORDER BY pd.TransactionDateTime";
public final static String EMPLOYEE_LOGIN_DETAILS_QUERY_OF_DATE = "SELECT emp.FirstName, emp.EmployeeCode, pd.TransactionDateTime, re.IOEntryStatus, re.ReaderName\n" +
"FROM ProcessData AS pd , EmployeeMaster AS emp, Readers AS re \n" +
"WHERE emp.EmployeeMasterID = pd.EmployeeID AND re.ReaderID = pd.ReaderID AND emp.EmployeeCode = %s\n" +
"AND pd.TransactionDateTime >= '%s' and pd.TransactionDateTime < DATEADD(day,+1,'%s') ORDER BY pd.TransactionDateTime";
public final static String UNION=" Union "; public final static String UNION=" Union ";
...@@ -205,4 +209,5 @@ public class MyTeamUtils { ...@@ -205,4 +209,5 @@ public class MyTeamUtils {
"WHERE emp.EmployeeMasterID = pd.EmployeeID AND re.ReaderID = pd.ReaderID AND emp.EmployeeCode = %s \n" + "WHERE emp.EmployeeMasterID = pd.EmployeeID AND re.ReaderID = pd.ReaderID AND emp.EmployeeCode = %s \n" +
"AND pd.TransactionDateTime BETWEEN CONVERT(datetime,'%2$s') AND CONVERT(datetime,'%3$s') " + "AND pd.TransactionDateTime BETWEEN CONVERT(datetime,'%2$s') AND CONVERT(datetime,'%3$s') " +
"ORDER BY pd.TransactionDateTime"; "ORDER BY pd.TransactionDateTime";
public final static String _OLD="_old";
} }
...@@ -43,7 +43,6 @@ myTeam.data.mssqldb.password=admin@123 ...@@ -43,7 +43,6 @@ myTeam.data.mssqldb.password=admin@123
email.leave.notification.template.file.path=email/absentMailTemplate.html email.leave.notification.template.file.path=email/absentMailTemplate.html
email.leave.notification.from=mytime.nisum@gmail.com email.leave.notification.from=mytime.nisum@gmail.com
email.leave.notification.subject=Employee Leave Email Notification email.leave.notification.subject=Employee Leave Email Notification
email.exempt.hours.employeelist.template.file.path=email/employeesExemptHours.html
#0 * * * * ?===>for every minute #0 * * * * ?===>for every minute
...@@ -68,13 +67,15 @@ email.project.notification.cron=00 00 15 * * 1-5 ...@@ -68,13 +67,15 @@ email.project.notification.cron=00 00 15 * * 1-5
email.workAnniversary.notification.from=mytime.nisum@gmail.com email.workAnniversary.notification.from=mytime.nisum@gmail.com
myTeam.exemptHours.fromemail=myerrabothu@nisum.com
myTeam.exemptHours.toemail=myerrabothu@nisum.com
email.exemptHours.notification.cron=0 10 10 ? * MON
email.workAnniversary.notification.subject=Happy Work Anniversary email.workAnniversary.notification.subject=Happy Work Anniversary
email.workAnniversary.notification.cron=00 00 06 * * 1-7 email.workAnniversary.notification.cron=00 00 06 * * 1-7
effective.login.time.cron=00 05 00 * * 1-7 effective.login.time.cron=00 05 00 * * 1-7
myTeam.exemptHours.fromemail=mytime.nisum@gmail.com
myTeam.exemptHours.toemail=msuleman@nisum.com
email.exemptHours.notification.cron=00 12 18 * * 1-7
email.exempt.hours.employeelist.template.file.path=email/employeesExemptHours.html
spring.profiles.active=development spring.profiles.active=development
message=this is from default configuration message=this is from default configuration
\ No newline at end of file
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