| Line 1140... |
Line 1140... |
| 1140 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x->x.isActive()).collect(Collectors.toMap(x->x.getEmailId(), x->x));
|
1140 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x->x.isActive()).collect(Collectors.toMap(x->x.getEmailId(), x->x));
|
| 1141 |
|
1141 |
|
| 1142 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
1142 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
| 1143 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x->x.getEmailId(), x->x));
|
1143 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x->x.getEmailId(), x->x));
|
| 1144 |
|
1144 |
|
| 1145 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now());
|
1145 |
Map<Integer, List<EmployeeAttendance>> employeeAttendancesMap = employeeAttendanceRepository.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now())
|
| 1146 |
//Get punchouts only
|
1146 |
.stream().collect(Collectors.groupingBy(x->x.getUserId()));
|
| 1147 |
List<EmployeeAttendance> employeeAttendancesOut = IntStream.range(1, employeeAttendances.size()).filter(x->x%2==1).mapToObj(i->employeeAttendances.get(i)).collect(Collectors.toList());
|
- |
|
| 1148 |
|
1147 |
|
| 1149 |
Map<Integer, Optional<EmployeeAttendance>> employeeEveningAttendanceMap = employeeAttendancesOut.stream().collect(Collectors.groupingBy(EmployeeAttendance::getUserId,
|
- |
|
| 1150 |
Collectors.maxBy(Comparator.comparing(EmployeeAttendance::getCreateTimestamp)
|
- |
|
| 1151 |
)));
|
- |
|
| 1152 |
|
- |
|
| 1153 |
for(AuthUser authUser: authUsers) {
|
1148 |
for(AuthUser authUser: authUsers) {
|
| 1154 |
User user = userMap.get(authUser.getEmailId());
|
1149 |
User user = userMap.get(authUser.getEmailId());
|
| - |
|
1150 |
String body = null;
|
| 1155 |
Optional<EmployeeAttendance> employeeAttendanceOptional = employeeEveningAttendanceMap.get(user.getId());
|
1151 |
List<EmployeeAttendance> employeeAttendances = employeeAttendancesMap.get(user.getId());
|
| 1156 |
if(employeeAttendanceOptional!=null
|
1152 |
if(employeeAttendances==null ) {
|
| - |
|
1153 |
body = String.format("Dear %s,\n No attendance has been registered by you today. You have been marked absent for the day. You may contact your manager and get it regularise.\n\nRegards\nHR Team", authUser.getFullName());
|
| - |
|
1154 |
} else {
|
| - |
|
1155 |
List<LocalDateTime> punchTimes = employeeAttendances.stream().sorted(Comparator.comparing(EmployeeAttendance::getCreateTimestamp)).map(x->x.getCreateTimestamp()).collect(Collectors.toList());
|
| - |
|
1156 |
if(punchTimes.size()==1) {
|
| - |
|
1157 |
//body = String.format("Dear %s,\n Pls note that you haven't punched out yet. You have been marked absent for half the day. You may contact your manager and get it regularise.\n\nRegards\nHR Team", authUser.getFullName());
|
| - |
|
1158 |
} else {
|
| - |
|
1159 |
LocalDateTime firstPunch = punchTimes.get(0);
|
| 1157 |
&& employeeAttendanceOptional.orElseGet(null)!=null
|
1160 |
LocalDateTime lastPunch = punchTimes.get(punchTimes.size()-1);
|
| 1158 |
&& employeeAttendanceOptional.get().getCreateTimestamp().isBefore(eveningTime)) {
|
1161 |
boolean hoursCompleted = lastPunch.isAfter(firstPunch.plusHours(8).plusMinutes(30));
|
| - |
|
1162 |
if(!hoursCompleted) {
|
| 1159 |
String body = String.format("Dear %s,\n Pls note that you have punched your attendance before 6pm. You have been marked absent for half the day. You may contact your manager and get it regularise.\n\nRegards\nHR Team", authUser.getFullName());
|
1163 |
body = String.format("Dear %s,\n Pls note that you have punched your attendance before 6pm. You have been marked absent for half the day. You may contact your manager and get it regularise.\n\nRegards\nHR Team", authUser.getFullName());
|
| - |
|
1164 |
}
|
| - |
|
1165 |
}
|
| - |
|
1166 |
|
| - |
|
1167 |
}
|
| - |
|
1168 |
if(body != null) {
|
| 1160 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { authUser.getEmailId() }, new String[] { "jyoti.rawat@smartdukaan.com" }, "Attendance Alert",
|
1169 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { authUser.getEmailId() }, new String[] { "jyoti.rawat@smartdukaan.com" }, "Attendance Alert",
|
| 1161 |
body);
|
1170 |
body);
|
| 1162 |
}
|
1171 |
}
|
| 1163 |
}
|
1172 |
}
|
| 1164 |
|
1173 |
|