Commit afdeb36f authored by Rajashekar jadala's avatar Rajashekar jadala Committed by rbonthala-nisum-com

MT-80: Sent employee assigned role to UI (#50)

parent c8e144f5
package com.nisum.mytime.controller; package com.nisum.mytime.controller;
import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -28,229 +27,187 @@ import com.nisum.mytime.model.Location; ...@@ -28,229 +27,187 @@ import com.nisum.mytime.model.Location;
import com.nisum.mytime.model.MasterData; import com.nisum.mytime.model.MasterData;
import com.nisum.mytime.model.Shift; import com.nisum.mytime.model.Shift;
import com.nisum.mytime.model.Skill; import com.nisum.mytime.model.Skill;
import com.nisum.mytime.service.RoleMappingService;
import com.nisum.mytime.service.UserService; import com.nisum.mytime.service.UserService;
@RestController @RestController
@RequestMapping("/user") @RequestMapping("/user")
public class UserController { public class UserController {
@Autowired @Autowired
private UserService userService; private UserService userService;
@RequestMapping(value = "/employee", method = RequestMethod.GET, @Autowired
produces = MediaType.APPLICATION_JSON_VALUE) private RoleMappingService roleMappingService;
public ResponseEntity<EmployeeRoles> getEmployeeRole(
@RequestParam("emailId") String emailId) throws MyTimeException { @RequestMapping(value = "/employee", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
EmployeeRoles employeesRole = userService.getEmployeesRole(emailId); public ResponseEntity<EmployeeRoles> getEmployeeRole(@RequestParam("emailId") String emailId)
System.out.println("emailId" + emailId + "result" + employeesRole); throws MyTimeException {
return new ResponseEntity<>(employeesRole, HttpStatus.OK); EmployeeRoles employeesRole = userService.getEmployeesRole(emailId);
} String roleName = roleMappingService.getEmployeeRole(employeesRole.getEmployeeId());
if (roleName != null) {
@RequestMapping(value = "/assignEmployeeRole", method = RequestMethod.POST, employeesRole.setRole(roleName);
produces = MediaType.APPLICATION_JSON_VALUE, }
consumes = MediaType.APPLICATION_JSON_VALUE) System.out.println("emailId" + emailId + "result" + employeesRole);
public ResponseEntity<EmployeeRoles> assigingEmployeeRole( return new ResponseEntity<>(employeesRole, HttpStatus.OK);
@RequestBody EmployeeRoles employeeRoles) throws MyTimeException { }
EmployeeRoles employeeRole = userService
.assigingEmployeeRole(employeeRoles); @RequestMapping(value = "/assignEmployeeRole", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
return new ResponseEntity<>(employeeRole, HttpStatus.OK); public ResponseEntity<EmployeeRoles> assigingEmployeeRole(@RequestBody EmployeeRoles employeeRoles)
} throws MyTimeException {
EmployeeRoles employeeRole = userService.assigingEmployeeRole(employeeRoles);
@RequestMapping(value = "/updateEmployeeRole", method = RequestMethod.POST, return new ResponseEntity<>(employeeRole, HttpStatus.OK);
produces = MediaType.APPLICATION_JSON_VALUE, }
consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<EmployeeRoles> updateEmployeeRole( @RequestMapping(value = "/updateEmployeeRole", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@RequestBody EmployeeRoles employeeRoles) throws MyTimeException { public ResponseEntity<EmployeeRoles> updateEmployeeRole(@RequestBody EmployeeRoles employeeRoles)
EmployeeRoles employeeRole = userService throws MyTimeException {
.updateEmployeeRole(employeeRoles); EmployeeRoles employeeRole = userService.updateEmployeeRole(employeeRoles);
return new ResponseEntity<>(employeeRole, HttpStatus.OK); return new ResponseEntity<>(employeeRole, HttpStatus.OK);
} }
@RequestMapping(value = "/deleteEmployee", method = RequestMethod.DELETE, @RequestMapping(value = "/deleteEmployee", method = RequestMethod.DELETE, produces = MediaType.TEXT_PLAIN_VALUE)
produces = MediaType.TEXT_PLAIN_VALUE) public ResponseEntity<String> deleteEmployee(@RequestParam("empId") String empId) throws MyTimeException {
public ResponseEntity<String> deleteEmployee( userService.deleteEmployee(empId);
@RequestParam("empId") String empId) throws MyTimeException { return new ResponseEntity<>("Success", HttpStatus.OK);
userService.deleteEmployee(empId); }
return new ResponseEntity<>("Success", HttpStatus.OK);
} @RequestMapping(value = "/getUserRoles", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<EmployeeRoles>> getUserRoles() throws MyTimeException {
@RequestMapping(value = "/getUserRoles", method = RequestMethod.GET, List<EmployeeRoles> employeesRoles = userService.getEmployeeRoles();
produces = MediaType.APPLICATION_JSON_VALUE) return new ResponseEntity<>(employeesRoles, HttpStatus.OK);
public ResponseEntity<List<EmployeeRoles>> getUserRoles() }
throws MyTimeException {
List<EmployeeRoles> employeesRoles = userService.getEmployeeRoles(); @RequestMapping(value = "/getEmployeeRoleData", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
return new ResponseEntity<>(employeesRoles, HttpStatus.OK); public ResponseEntity<EmployeeRoles> getEmployeeRoleData(@RequestParam("empId") String empId)
} throws MyTimeException {
EmployeeRoles employeesRole = userService.getEmployeesRoleData(empId);
@RequestMapping(value = "/getEmployeeRoleData", method = RequestMethod.GET, return new ResponseEntity<>(employeesRole, HttpStatus.OK);
produces = MediaType.APPLICATION_JSON_VALUE) }
public ResponseEntity<EmployeeRoles> getEmployeeRoleData(
@RequestParam("empId") String empId) throws MyTimeException { @RequestMapping(value = "/getEmployeeLocations", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
EmployeeRoles employeesRole = userService.getEmployeesRoleData(empId); public ResponseEntity<List<EmployeeLocationDetails>> getEmployeeLocations(@RequestParam("employeeId") String empId)
return new ResponseEntity<>(employeesRole, HttpStatus.OK); throws MyTimeException {
} List<EmployeeLocationDetails> employeeLocationDetails = userService.getEmployeeLocationDetails(empId);
return new ResponseEntity<>(employeeLocationDetails, HttpStatus.OK);
@RequestMapping(value = "/getEmployeeLocations", method = RequestMethod.GET, }
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<EmployeeLocationDetails>> getEmployeeLocations( @RequestMapping(value = "/getManagers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@RequestParam("employeeId") String empId) throws MyTimeException { public ResponseEntity<List<EmployeeRoles>> getManagers() throws MyTimeException {
List<EmployeeLocationDetails> employeeLocationDetails = userService List<EmployeeRoles> employeesRoles = userService.getEmployeeRoles();
.getEmployeeLocationDetails(empId); List<EmployeeRoles> managers = employeesRoles.stream()
return new ResponseEntity<>(employeeLocationDetails, HttpStatus.OK); .filter(e -> ("Director".equalsIgnoreCase(e.getRole())
} || "Delivery Manager".equalsIgnoreCase(e.getRole()) || "Manager".equalsIgnoreCase(e.getRole())
|| "HR Manager".equalsIgnoreCase(e.getRole()) || "Lead".equalsIgnoreCase(e.getRole())))
@RequestMapping(value = "/getManagers", method = RequestMethod.GET, .sorted(Comparator.comparing(EmployeeRoles::getEmployeeName)).collect(Collectors.toList());
produces = MediaType.APPLICATION_JSON_VALUE) return new ResponseEntity<>(managers, HttpStatus.OK);
public ResponseEntity<List<EmployeeRoles>> getManagers() }
throws MyTimeException {
List<EmployeeRoles> employeesRoles = userService.getEmployeeRoles(); @RequestMapping(value = "/getAllShifts", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
List<EmployeeRoles> managers = employeesRoles.stream() public ResponseEntity<List<String>> getAllShifts() throws MyTimeException {
.filter(e -> ("Director".equalsIgnoreCase(e.getRole()) List<String> shifts = userService.getAllShifts().stream().filter(e -> "Y".equalsIgnoreCase(e.getActiveStatus()))
|| "Delivery Manager".equalsIgnoreCase(e.getRole()) .map(Shift::getShiftName).sorted().collect(Collectors.toList());
|| "Manager".equalsIgnoreCase(e.getRole()) return new ResponseEntity<>(shifts, HttpStatus.OK);
|| "HR Manager".equalsIgnoreCase(e.getRole()) }
|| "Lead".equalsIgnoreCase(e.getRole())))
.sorted(Comparator.comparing(EmployeeRoles::getEmployeeName)) @RequestMapping(value = "/getAllDesignations", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
.collect(Collectors.toList()); public ResponseEntity<List<String>> getAllDesignations() throws MyTimeException {
return new ResponseEntity<>(managers, HttpStatus.OK); List<String> designations = userService.getAllDesignations().stream()
} .filter(e -> "Y".equalsIgnoreCase(e.getActiveStatus())).map(Designation::getDesignationName).sorted()
.collect(Collectors.toList());
@RequestMapping(value = "/getAllShifts", method = RequestMethod.GET, return new ResponseEntity<>(designations, HttpStatus.OK);
produces = MediaType.APPLICATION_JSON_VALUE) }
public ResponseEntity<List<String>> getAllShifts() throws MyTimeException {
List<String> shifts = userService.getAllShifts().stream() @RequestMapping(value = "/getSkills", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
.filter(e -> "Y".equalsIgnoreCase(e.getActiveStatus())) public ResponseEntity<List<String>> getTechnologies() throws MyTimeException {
.map(Shift::getShiftName).sorted().collect(Collectors.toList()); List<String> technologies = userService.getTechnologies().stream()
return new ResponseEntity<>(shifts, HttpStatus.OK); .filter(e -> "Y".equalsIgnoreCase(e.getActiveStatus())).map(Skill::getSkillName).sorted()
} .collect(Collectors.toList());
return new ResponseEntity<>(technologies, HttpStatus.OK);
@RequestMapping(value = "/getAllDesignations", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) }
public ResponseEntity<List<String>> getAllDesignations()
throws MyTimeException { @RequestMapping(value = "/getLocations", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
List<String> designations = userService.getAllDesignations().stream() public ResponseEntity<List<String>> getLocations() throws MyTimeException {
.filter(e -> "Y".equalsIgnoreCase(e.getActiveStatus())) System.out.println(" userService.getLocations()" + userService.getLocations());
.map(Designation::getDesignationName).sorted() List<String> locations = userService.getLocations().stream().filter(e -> (e.isActiveStatus() == true))
.collect(Collectors.toList()); .map(Location::getLocation).sorted().collect(Collectors.toList());
return new ResponseEntity<>(designations, HttpStatus.OK); System.out.println("getLocations################ " + locations);
} return new ResponseEntity<>(locations, HttpStatus.OK);
@RequestMapping(value = "/getSkills", method = RequestMethod.GET, }
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<String>> getTechnologies() @RequestMapping(value = "/updateProfile", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
throws MyTimeException { public ResponseEntity<EmployeeRoles> updateProfile(@RequestBody EmployeeRoles employeeRoles)
List<String> technologies = userService.getTechnologies().stream() throws MyTimeException {
.filter(e -> "Y".equalsIgnoreCase(e.getActiveStatus())) EmployeeRoles employeeRole = userService.updateProfile(employeeRoles);
.map(Skill::getSkillName).sorted().collect(Collectors.toList()); return new ResponseEntity<>(employeeRole, HttpStatus.OK);
return new ResponseEntity<>(technologies, HttpStatus.OK); }
} @RequestMapping(value = "/getAccounts", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Account>> getAccounts() throws MyTimeException {
@RequestMapping(value = "/getLocations", method = RequestMethod.GET, List<Account> technologies = userService.getAccounts().stream().filter(e -> "Y".equalsIgnoreCase(e.getStatus()))
produces = MediaType.APPLICATION_JSON_VALUE) // .map(Account::getAccountName).sorted()
public ResponseEntity<List<String>> getLocations() throws MyTimeException { .collect(Collectors.toList());
System.out.println( return new ResponseEntity<>(technologies, HttpStatus.OK);
" userService.getLocations()" + userService.getLocations()); }
List<String> locations = userService.getLocations().stream()
.filter(e -> (e.isActiveStatus() == true)) @RequestMapping(value = "/getEmployeeRoleDataForSearchCriteria", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
.map(Location::getLocation).sorted() public ResponseEntity<EmployeeRoles> getEmployeeRoleDataForSearchCriteria(@RequestParam("searchId") String searchId,
.collect(Collectors.toList()); @RequestParam("searchAttribute") String searchAttribute) throws MyTimeException {
System.out.println("getLocations################ " + locations); EmployeeRoles employeesRole = userService.getEmployeeRoleDataForSearchCriteria(searchId, searchAttribute);
return new ResponseEntity<>(locations, HttpStatus.OK); return new ResponseEntity<>(employeesRole, HttpStatus.OK);
}
}
@RequestMapping(value = "/getEmployeeDetailsForAutocomplete", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/updateProfile", method = RequestMethod.POST, public ResponseEntity<List<String>> getEmployeeDetailsForAutocomplete() throws MyTimeException {
produces = MediaType.APPLICATION_JSON_VALUE, List<String> details = userService.getEmployeeDetailsForAutocomplete();
consumes = MediaType.APPLICATION_JSON_VALUE) return new ResponseEntity<>(details, HttpStatus.OK);
public ResponseEntity<EmployeeRoles> updateProfile( }
@RequestBody EmployeeRoles employeeRoles) throws MyTimeException {
EmployeeRoles employeeRole = userService.updateProfile(employeeRoles); @RequestMapping(value = "/getMasterData", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
return new ResponseEntity<>(employeeRole, HttpStatus.OK); public ResponseEntity<Map<String, List<String>>> getMasterData() throws MyTimeException {
} Map<String, List<String>> masterDataMap = new HashMap<>();
Map<String, List<MasterData>> result = userService.getMasterData().stream()
@RequestMapping(value = "/getAccounts", method = RequestMethod.GET, .filter(e -> (e.isActiveStatus() == true))
produces = MediaType.APPLICATION_JSON_VALUE) .collect(Collectors.groupingBy(MasterData::getMasterDataType));
public ResponseEntity<List<Account>> getAccounts() throws MyTimeException { for (String key : result.keySet()) {
List<Account> technologies = userService.getAccounts().stream() List<MasterData> valueList = result.get(key);
.filter(e -> "Y".equalsIgnoreCase(e.getStatus())) List<String> technologies = valueList.stream().map(MasterData::getMasterDataName).sorted()
// .map(Account::getAccountName).sorted() .collect(Collectors.toList());
.collect(Collectors.toList()); masterDataMap.put(key, technologies);
return new ResponseEntity<>(technologies, HttpStatus.OK); }
} return new ResponseEntity<>(masterDataMap, HttpStatus.OK);
@RequestMapping(value = "/getEmployeeRoleDataForSearchCriteria", }
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getEmployeeByStatus", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<EmployeeRoles> getEmployeeRoleDataForSearchCriteria( public ResponseEntity<List<EmployeeRoles>> getEmployeeByStatus(@RequestParam("status") String status) {
@RequestParam("searchId") String searchId,
@RequestParam("searchAttribute") String searchAttribute) List<EmployeeRoles> employeesRoles = userService.getEmployeesByStatus(status);
throws MyTimeException { return new ResponseEntity<>(employeesRoles, HttpStatus.OK);
EmployeeRoles employeesRole = userService }
.getEmployeeRoleDataForSearchCriteria(searchId,
searchAttribute); @RequestMapping(value = "/getDeliveryLeads", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
return new ResponseEntity<>(employeesRole, HttpStatus.OK); public ResponseEntity<List<HashMap<String, String>>> getDeliveryLeads(@RequestParam("domainId") String domainId)
} throws MyTimeException {
List<HashMap<String, String>> managers = userService.getDeliveryLeads(domainId);
@RequestMapping(value = "/getEmployeeDetailsForAutocomplete", return new ResponseEntity<>(managers, HttpStatus.OK);
method = RequestMethod.GET, }
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<String>> getEmployeeDetailsForAutocomplete() @RequestMapping(value = "/getAccountsInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
throws MyTimeException { public ResponseEntity<List<AccountInfo>> getAccountsInfo() throws MyTimeException {
List<String> details = userService.getEmployeeDetailsForAutocomplete(); List<AccountInfo> technologies = userService.getAccountsInfo().stream()
return new ResponseEntity<>(details, HttpStatus.OK); .filter(e -> "Active".equalsIgnoreCase(e.getStatus())).collect(Collectors.toList());
} return new ResponseEntity<>(technologies, HttpStatus.OK);
}
@RequestMapping(value = "/getMasterData", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getDomains", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, List<String>>> getMasterData() public ResponseEntity<List<Domains>> getDomains(@RequestParam("accountId") String accountId)
throws MyTimeException { throws MyTimeException {
Map<String, List<String>> masterDataMap = new HashMap<>(); List<Domains> domains = userService.getDomains(accountId).stream()
Map<String, List<MasterData>> result = userService.getMasterData() .filter(e -> "Active".equalsIgnoreCase(e.getStatus())).collect(Collectors.toList());
.stream().filter(e -> (e.isActiveStatus() == true)) return new ResponseEntity<>(domains, HttpStatus.OK);
.collect(Collectors.groupingBy(MasterData::getMasterDataType)); }
for (String key : result.keySet()) {
List<MasterData> valueList = result.get(key);
List<String> technologies = valueList.stream()
.map(MasterData::getMasterDataName).sorted()
.collect(Collectors.toList());
masterDataMap.put(key, technologies);
}
return new ResponseEntity<>(masterDataMap, HttpStatus.OK);
}
@RequestMapping(value = "/getEmployeeByStatus", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<EmployeeRoles>> getEmployeeByStatus(
@RequestParam("status") String status) {
List<EmployeeRoles> employeesRoles = userService
.getEmployeesByStatus(status);
return new ResponseEntity<>(employeesRoles, HttpStatus.OK);
}
@RequestMapping(value = "/getDeliveryLeads", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<HashMap<String, String>>> getDeliveryLeads(@RequestParam("domainId") String domainId)
throws MyTimeException {
List<HashMap<String, String>> managers = userService.getDeliveryLeads(domainId);
return new ResponseEntity<>(managers, HttpStatus.OK);
}
@RequestMapping(value = "/getAccountsInfo", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<AccountInfo>> getAccountsInfo() throws MyTimeException {
List<AccountInfo> technologies = userService.getAccountsInfo().stream()
.filter(e -> "Active".equalsIgnoreCase(e.getStatus()))
.collect(Collectors.toList());
return new ResponseEntity<>(technologies, HttpStatus.OK);
}
@RequestMapping(value = "/getDomains", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Domains>> getDomains(@RequestParam("accountId") String accountId)throws MyTimeException
{
List<Domains> domains=userService.getDomains(accountId).stream()
.filter(e->"Active".equalsIgnoreCase(e.getStatus())).collect(Collectors.toList());
return new ResponseEntity<>(domains, HttpStatus.OK);
}
} }
\ No newline at end of file
...@@ -24,6 +24,7 @@ public class RoleInfo implements Serializable { ...@@ -24,6 +24,7 @@ public class RoleInfo implements Serializable {
@Id @Id
private ObjectId id; private ObjectId id;
private int priority;
private String roleId; private String roleId;
private String roleName; private String roleName;
private String roleDescription; private String roleDescription;
......
...@@ -5,5 +5,8 @@ import org.springframework.data.mongodb.repository.MongoRepository; ...@@ -5,5 +5,8 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import com.nisum.mytime.model.RoleInfo; import com.nisum.mytime.model.RoleInfo;
public interface RoleInfoRepo extends MongoRepository<RoleInfo, String> { public interface RoleInfoRepo extends MongoRepository<RoleInfo, String> {
RoleInfo findByRoleName(String roleName); RoleInfo findByRoleName(String roleName);
RoleInfo findByRoleId(String roleId);
} }
\ No newline at end of file
package com.nisum.mytime.repository; package com.nisum.mytime.repository;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import com.nisum.mytime.model.RoleMappingInfo; import com.nisum.mytime.model.RoleMappingInfo;
...@@ -7,4 +9,6 @@ import com.nisum.mytime.model.RoleMappingInfo; ...@@ -7,4 +9,6 @@ import com.nisum.mytime.model.RoleMappingInfo;
public interface RoleMappingInfoRepo extends MongoRepository<RoleMappingInfo, String> { public interface RoleMappingInfoRepo extends MongoRepository<RoleMappingInfo, String> {
RoleMappingInfo findByEmployeeIdAndRoleId(String employeeId, String roleId); RoleMappingInfo findByEmployeeIdAndRoleId(String employeeId, String roleId);
List<RoleMappingInfo> findByEmployeeId(String employeeId);
} }
\ No newline at end of file
...@@ -20,61 +20,57 @@ import com.nisum.mytime.utils.MyTimeLogger; ...@@ -20,61 +20,57 @@ import com.nisum.mytime.utils.MyTimeLogger;
import com.nisum.mytime.utils.MyTimeUtils; import com.nisum.mytime.utils.MyTimeUtils;
@Component @Component
@Transactional @Transactional
public class EmployeeDataService { public class EmployeeDataService {
@Autowired @Autowired
DbConnection dbConnection; DbConnection dbConnection;
public List<EmpLoginData> fetchEmployeeLoginsBasedOnDates(long employeeId, String fromDate, String toDate) public List<EmpLoginData> fetchEmployeeLoginsBasedOnDates(long employeeId, String fromDate, String toDate)
throws MyTimeException { throws MyTimeException {
long start_ms = System.currentTimeMillis(); long start_ms = System.currentTimeMillis();
String querys=MyTimeUtils.ABESENT_STATUS_QUERY+"'"+fromDate+"'"+ MyTimeUtils.ABESENT_STATUS_QUERY1 +"'"+toDate+"'"+MyTimeUtils.ABESENT_STATUS_QUERY2+employeeId+MyTimeUtils.ABESENT_STATUS_QUERY3; String querys = null;
System.out.println("fetch employee details"+querys); if (employeeId == 0)
int countHours = 0; querys = MyTimeUtils.ABESENT_STATUS_QUERY + "'" + fromDate + "'" + MyTimeUtils.ABESENT_STATUS_QUERY1 + "'"
+ toDate + "'" + MyTimeUtils.ABESENT_STATUS_QUERY3;
else
querys = MyTimeUtils.ABESENT_STATUS_QUERY + "'" + fromDate + "'" + MyTimeUtils.ABESENT_STATUS_QUERY1 + "'"
+ toDate + "'" + MyTimeUtils.ABESENT_STATUS_QUERY2 + employeeId + MyTimeUtils.ABESENT_STATUS_QUERY3;
int countHours = 0;
List<EmpLoginData> listOfEmpLoginData = new ArrayList<>(); List<EmpLoginData> listOfEmpLoginData = new ArrayList<>();
try(Connection connection = dbConnection.getDBConnection(); try (Connection connection = dbConnection.getDBConnection();
Statement statement = connection.createStatement(); Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(querys.toString())) ResultSet resultSet = statement.executeQuery(querys.toString())) {
{ while (resultSet.next()) {
if (employeeId > 0) { EmpLoginData empLoginData = new EmpLoginData();
while (resultSet.next()) { empLoginData.setEmployeeId(resultSet.getString("EmployeeCode"));
EmpLoginData empLoginData = new EmpLoginData(); empLoginData.setEmployeeName(resultSet.getString("FirstName"));
empLoginData.setEmployeeId(resultSet.getString("EmployeeCode")); empLoginData.setDateOfLogin(resultSet.getDate("FirstLogin").toString());
empLoginData.setEmployeeName(resultSet.getString("FirstName")); empLoginData.setFirstLogin(resultSet.getTime("FirstLogin").toString());
empLoginData.setDateOfLogin(resultSet.getDate("FirstLogin").toString()); empLoginData.setLastLogout(resultSet.getTime("LastLogin").toString());
empLoginData.setFirstLogin(resultSet.getTime("FirstLogin").toString()); Time from = resultSet.getTime("FirstLogin");
empLoginData.setLastLogout(resultSet.getTime("LastLogin").toString()); Time to = resultSet.getTime("LastLogin");
Time from = resultSet.getTime("FirstLogin"); long milliseconds = to.getTime() - from.getTime();
Time to = resultSet.getTime("LastLogin"); int seconds = (int) milliseconds / 1000;
long milliseconds=to.getTime() - from.getTime(); int hours = seconds / 3600;
int seconds = (int) milliseconds / 1000; int minutes = (seconds % 3600) / 60;
int hours = seconds / 3600; seconds = (seconds % 3600) % 60;
int minutes = (seconds % 3600) / 60;
seconds = (seconds % 3600) % 60;
empLoginData.setTotalLoginTime(hours+":"+minutes+":"+seconds);
empLoginData.setTotalLoginTime(hours+":"+minutes+":"+seconds);
Date d = MyTimeUtils.tdf.parse(empLoginData.getTotalLoginTime());
countHours += d.getTime();
listOfEmpLoginData.add(empLoginData);
}
if (!listOfEmpLoginData.isEmpty()) {
listOfEmpLoginData.get(0)
.setTotalAvgTime(MyTimeUtils.tdf.format(countHours / listOfEmpLoginData.size()));
}
MyTimeLogger.getInstance().info(" Time Taken fecth Employee data based on Dates ::: " empLoginData.setTotalLoginTime(hours + ":" + minutes + ":" + seconds);
+ (System.currentTimeMillis() - start_ms)); empLoginData.setTotalLoginTime(hours + ":" + minutes + ":" + seconds);
Date d = MyTimeUtils.tdf.parse(empLoginData.getTotalLoginTime());
countHours += d.getTime();
listOfEmpLoginData.add(empLoginData);
}
if (!listOfEmpLoginData.isEmpty()) {
listOfEmpLoginData.get(0)
.setTotalAvgTime(MyTimeUtils.tdf.format(countHours / listOfEmpLoginData.size()));
}
} else if (employeeId == 0) { MyTimeLogger.getInstance().info(
" Time Taken fecth Employee data based on Dates ::: " + (System.currentTimeMillis() - start_ms));
listOfEmpLoginData = null;
MyTimeLogger.getInstance().info("Time Taken for with fecth All Employees data based on Dates ::: "
+ (System.currentTimeMillis() - start_ms));
}
} catch (Exception e) { } catch (Exception e) {
MyTimeLogger.getInstance().error(e.getMessage()); MyTimeLogger.getInstance().error(e.getMessage());
throw new MyTimeException(e.getMessage()); throw new MyTimeException(e.getMessage());
......
...@@ -10,4 +10,6 @@ public interface RoleMappingService { ...@@ -10,4 +10,6 @@ public interface RoleMappingService {
void saveUniqueEmployeeAndRole(List<String> employeeIds, String roleId) throws MyTimeException; void saveUniqueEmployeeAndRole(List<String> employeeIds, String roleId) throws MyTimeException;
WriteResult deleteRole(String employeeId, String roleId) throws MyTimeException; WriteResult deleteRole(String employeeId, String roleId) throws MyTimeException;
String getEmployeeRole(String employeeId);
} }
package com.nisum.mytime.service; package com.nisum.mytime.service;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
...@@ -12,6 +15,7 @@ import org.springframework.stereotype.Service; ...@@ -12,6 +15,7 @@ import org.springframework.stereotype.Service;
import com.mongodb.WriteResult; import com.mongodb.WriteResult;
import com.nisum.mytime.exception.handler.MyTimeException; import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.RoleMappingInfo; import com.nisum.mytime.model.RoleMappingInfo;
import com.nisum.mytime.repository.RoleInfoRepo;
import com.nisum.mytime.repository.RoleMappingInfoRepo; import com.nisum.mytime.repository.RoleMappingInfoRepo;
import com.nisum.mytime.utils.MyTimeUtils; import com.nisum.mytime.utils.MyTimeUtils;
...@@ -21,6 +25,9 @@ public class RoleMappingServiceImpl implements RoleMappingService { ...@@ -21,6 +25,9 @@ public class RoleMappingServiceImpl implements RoleMappingService {
@Autowired @Autowired
private RoleMappingInfoRepo roleMappingInfoRepo; private RoleMappingInfoRepo roleMappingInfoRepo;
@Autowired
private RoleInfoRepo roleInfoRepo;
@Autowired @Autowired
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
...@@ -49,4 +56,26 @@ public class RoleMappingServiceImpl implements RoleMappingService { ...@@ -49,4 +56,26 @@ public class RoleMappingServiceImpl implements RoleMappingService {
return mongoTemplate.upsert(query, update, RoleMappingInfo.class); return mongoTemplate.upsert(query, update, RoleMappingInfo.class);
} }
@Override
public String getEmployeeRole(String employeeId) {
Map<Integer, String> roleInfoMap = new LinkedHashMap<Integer, String>();
List<RoleMappingInfo> listOfEmployeeRoles = roleMappingInfoRepo.findByEmployeeId(employeeId);
for (RoleMappingInfo employee : listOfEmployeeRoles) {
roleInfoMap.put((roleInfoRepo.findByRoleId(employee.getRoleId())).getPriority(), employee.getRoleId());
}
roleInfoMap = roleInfoMap.entrySet().stream().sorted(Map.Entry.comparingByKey()).collect(Collectors
.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new));
String roleName = null;
if (!roleInfoMap.isEmpty()) {
Map.Entry<Integer, String> entry = roleInfoMap.entrySet().iterator().next();
roleName = entry.getValue();
} else {
roleName = null;
}
return roleName;
}
} }
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