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;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.transaction.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.ArrayList;
......@@ -31,17 +33,26 @@ public class EffectiveLoginTimeController {
@Autowired
private IEmployeeService employeeService;
@GetMapping("/updateLogins")
public List<EffectiveLoginData> getLoginData() throws MyTeamException {
@Transactional
@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<Employee> allEmployees = employeeService.getActiveEmployees();
for(Employee employee:allEmployees){
EffectiveLoginData effectiveLoginData =
effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee);
effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee,date);
loginData.add(effectiveLoginData);
}
return loginData;
}
@DeleteMapping("/deleteLogins")
public void deleteLoginDate(@RequestParam("date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date date) throws ParseException {
effectiveLoginTimeService.deleteLogins(date);
}
@GetMapping("/effectiveLogin")
public Map<String,Object> getAllEmployeesLoginData(
@RequestParam("employeeId") long employeeId,
......@@ -52,25 +63,25 @@ public class EffectiveLoginTimeController {
}
@DeleteMapping("/deleteLoginData")
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 {
effectiveLoginTimeService.deleteEmployeeLoginData(employeeId,fromDate,toDate);
ResponseDetails responseDetails = new ResponseDetails(new Date(), 904, "delete Employees Login details Successfully",
"delete Employees Login details Successfully", null, request.getRequestURI(), "Login details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@PostMapping("/syncLoginDataByDateRange")
public List<EffectiveLoginData> syncLoginDataByDateRange(@RequestParam("fromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date fromDate,
@RequestParam("toDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date toDate) throws MyTeamException {
List<EffectiveLoginData> loginData = new ArrayList<>();
List<Employee> allEmployees = employeeService.getActiveEmployees();
//allEmployees.removeIf(s -> !"40270".equalsIgnoreCase(s.getEmployeeId()));
for (Employee employee : allEmployees) {
EffectiveLoginData effectiveLoginData =
effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee, fromDate, toDate);
loginData.add(effectiveLoginData);
}
return loginData;
}
// @DeleteMapping("/deleteLoginData")
// 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 {
// effectiveLoginTimeService.deleteEmployeeLoginData(employeeId,fromDate,toDate);
// ResponseDetails responseDetails = new ResponseDetails(new Date(), 904, "delete Employees Login details Successfully",
// "delete Employees Login details Successfully", null, request.getRequestURI(), "Login details", null);
// return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
// }
// @PostMapping("/syncLoginDataByDateRange")
// public List<EffectiveLoginData> syncLoginDataByDateRange(@RequestParam("fromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date fromDate,
// @RequestParam("toDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date toDate) throws MyTeamException {
// List<EffectiveLoginData> loginData = new ArrayList<>();
// List<Employee> allEmployees = employeeService.getActiveEmployees();
// //allEmployees.removeIf(s -> !"40270".equalsIgnoreCase(s.getEmployeeId()));
// for (Employee employee : allEmployees) {
// EffectiveLoginData effectiveLoginData =
// effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee, fromDate, toDate);
// loginData.add(effectiveLoginData);
// }
// return loginData;
// }
}
......@@ -10,6 +10,7 @@ public interface EffectiveLoginDataRepo extends MongoRepository<EffectiveLoginDa
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 {
List<Employee> allEmployees = employeeService.getActiveEmployees();
for(Employee employee:allEmployees){
EffectiveLoginData effectiveLoginData =
effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee);
effectiveLoginTimeService.calculateEffectiveLoginTimeForEmpAndSave(employee,null);
}
}
}
......@@ -64,29 +64,29 @@ public class EmployeeAVGHoursScheduler {
logger.info("sendEmployessAvgHoursMailToLeadsnotification::");
SchedulersLogsDetails schedulersLogsDetails = schedulersLogsDetailsService.getCurrentSchedulerLogDetails("EmployeeAVGHoursScheduler", new Date());
if (schedulersLogsDetails == null || !"Active".equalsIgnoreCase(schedulersLogsDetails.getSchedulerStatus())) {
sendhoursExemptEmpListToLeads();
}
sendhoursExemptEmpListToLeads();
}
private void sendhoursExemptEmpListToLeads() throws MessagingException {
logger.info("sending avg hours list to managers");
SchedulersLogsDetails schedulersLogsDetails;
Mail mail = new Mail();
LocalDate dt = LocalDate.now();
LocalDate lastWeekDay = LocalDate.now().minusWeeks(1);
try {
Date friday = Date.from(dt.with(TemporalAdjusters.previous(DayOfWeek.FRIDAY)).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
Date monday = Date.from(dt.with(TemporalAdjusters.previous(DayOfWeek.MONDAY)).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
Date monday = Date.from(lastWeekDay.with(DayOfWeek.MONDAY).atStartOfDay(ZoneId.systemDefault()).toInstant());
Date sunday = Date.from(lastWeekDay.with(DayOfWeek.SUNDAY).atStartOfDay(ZoneId.systemDefault()).toInstant());
List<Employee> activeEmpList = employeeService.getActiveEmployees();
List<LoginDetailsVO> hoursExemptEmployeeList = new ArrayList<>();
activeEmpList.removeIf(e -> "At Client Location".equalsIgnoreCase(e.getEmpSubStatus() instanceof String ? (String) e.getEmpSubStatus() : null));
activeEmpList.removeIf(e -> {
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) {
String hoursMins[] = ((String) obj.get("averageTime")).split(":");
if (hoursMins != null) {
boolean isHoursExemptEmployee = new Long(hoursMins[0]) < 8;
if (isHoursExemptEmployee) {
//System.out.println(" Hours avg " + obj.get("data"));
LoginDetailsVO loginDetailsVO = new LoginDetailsVO();
loginDetailsVO.setEmployeeId(e.getEmployeeId());
loginDetailsVO.setEmployeeName(e.getEmployeeName());
......@@ -96,7 +96,9 @@ public class EmployeeAVGHoursScheduler {
StringBuilder orphanLoginSB = new StringBuilder();
effectiveLoginDataList.stream().forEach(eloginData -> {
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());
hoursExemptEmployeeList.add(loginDetailsVO);
......
......@@ -10,11 +10,13 @@ import java.util.Map;
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 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;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import javax.transaction.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -167,6 +168,7 @@ public class EmployeeService implements IEmployeeService {
// }
@Override
@Transactional
public Employee updateEmployee(Employee employeeReq, String loginEmpId) throws ParseException {
// update all emp details to inactive if employee is inactive
......@@ -241,10 +243,12 @@ public class EmployeeService implements IEmployeeService {
FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true);
options.upsert(true);
Employee employeeUpdated = mongoTemplate.findAndModify(query, update, options, Employee.class);
if (employeeReq.getEmpStatus().equals("In Active")) {
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");
return employeeUpdated;
}
......
......@@ -181,7 +181,6 @@ public class MailService implements IMailService {
@Override
public void sendExemptHoursEmployeDetailsToLeads(Mail mail, List<LoginDetailsVO> hoursExemptEmployeeList) throws MessagingException, IOException {
System.out.println(hoursExemptEmployeeList.size());
if(Optional.ofNullable(hoursExemptEmployeeList).isPresent() ) {
MimeMessage message = emailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
......
......@@ -108,9 +108,13 @@ public class MyTeamUtils {
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" +
"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";
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 ";
......@@ -205,4 +209,5 @@ public class MyTeamUtils {
"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') " +
"ORDER BY pd.TransactionDateTime";
public final static String _OLD="_old";
}
......@@ -43,7 +43,6 @@ myTeam.data.mssqldb.password=admin@123
email.leave.notification.template.file.path=email/absentMailTemplate.html
email.leave.notification.from=mytime.nisum@gmail.com
email.leave.notification.subject=Employee Leave Email Notification
email.exempt.hours.employeelist.template.file.path=email/employeesExemptHours.html
#0 * * * * ?===>for every minute
......@@ -68,13 +67,15 @@ email.project.notification.cron=00 00 15 * * 1-5
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.cron=00 00 06 * * 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
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