From 2d2d4ccf917441412f1a49562d257ca65c2a4496 Mon Sep 17 00:00:00 2001 From: shubhang-eGov <70943369+shubhang-eGov@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:44:19 +0530 Subject: [PATCH] HCMPRE-1333- Removed dense rank query; using sequential calls to get child table data. (#1210) --- .../java/org/egov/hrms/model/Assignment.java | 2 + .../egov/hrms/model/DeactivationDetails.java | 2 + .../org/egov/hrms/model/DepartmentalTest.java | 2 + .../hrms/model/EducationalQualification.java | 2 + .../org/egov/hrms/model/EmployeeDocument.java | 2 + .../org/egov/hrms/model/Jurisdiction.java | 2 + .../egov/hrms/model/ReactivationDetails.java | 2 + .../org/egov/hrms/model/ServiceHistory.java | 4 +- .../hrms/repository/AssignmentRowMapper.java | 46 ++++++ .../DeactivationDetailsRowMapper.java | 43 ++++++ .../repository/DepartmentalTestRowMapper.java | 40 ++++++ .../hrms/repository/DocumentRowMapper.java | 44 ++++++ .../EducationalDetailsRowMapper.java | 42 ++++++ .../egov/hrms/repository/EmployeeQueries.java | 58 ++++++++ .../hrms/repository/EmployeeQueryBuilder.java | 9 +- .../hrms/repository/EmployeeRepository.java | 134 ++++++++++++++++-- .../repository/EmployeeTableRowMapper.java | 63 ++++++++ .../repository/JurisdictionRowMapper.java | 42 ++++++ .../ReactivationDetailsRowMapper.java | 40 ++++++ .../repository/ServiceHistoryRowMapper.java | 44 ++++++ .../egov/hrms/service/EmployeeService.java | 13 +- 21 files changed, 611 insertions(+), 25 deletions(-) create mode 100644 core-services/egov-hrms/src/main/java/org/egov/hrms/repository/AssignmentRowMapper.java create mode 100644 core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DeactivationDetailsRowMapper.java create mode 100644 core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DepartmentalTestRowMapper.java create mode 100644 core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DocumentRowMapper.java create mode 100644 core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EducationalDetailsRowMapper.java create mode 100644 core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeTableRowMapper.java create mode 100644 core-services/egov-hrms/src/main/java/org/egov/hrms/repository/JurisdictionRowMapper.java create mode 100644 core-services/egov-hrms/src/main/java/org/egov/hrms/repository/ReactivationDetailsRowMapper.java create mode 100644 core-services/egov-hrms/src/main/java/org/egov/hrms/repository/ServiceHistoryRowMapper.java diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/Assignment.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/Assignment.java index 9df7a4b92bd..98bb01a85b8 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/Assignment.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/Assignment.java @@ -60,6 +60,8 @@ public class Assignment { @SafeHtml private String id; + private String employeeId; + private Long position; @SafeHtml diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/DeactivationDetails.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/DeactivationDetails.java index 32b7787825f..5a1f7bc518e 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/DeactivationDetails.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/DeactivationDetails.java @@ -19,6 +19,8 @@ public class DeactivationDetails { @SafeHtml private String id; + private String employeeId; + @SafeHtml @NotNull private String reasonForDeactivation; diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/DepartmentalTest.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/DepartmentalTest.java index 6341ce3893a..dd182c40d8f 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/DepartmentalTest.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/DepartmentalTest.java @@ -60,6 +60,8 @@ public class DepartmentalTest { @SafeHtml private String id; + private String employeeId; + @SafeHtml @NotNull private String test; diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/EducationalQualification.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/EducationalQualification.java index 2071915c165..1dfd1f2bc7d 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/EducationalQualification.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/EducationalQualification.java @@ -60,6 +60,8 @@ public class EducationalQualification { @SafeHtml private String id; + private String employeeId; + @SafeHtml @NotNull private String qualification; diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/EmployeeDocument.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/EmployeeDocument.java index d93c69f4cf0..ce4d23f5822 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/EmployeeDocument.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/EmployeeDocument.java @@ -65,6 +65,8 @@ public class EmployeeDocument { @SafeHtml private String id; + private String employeeId; + @SafeHtml private String documentName; diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/Jurisdiction.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/Jurisdiction.java index 5afc27194cb..84bd08344f2 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/Jurisdiction.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/Jurisdiction.java @@ -61,6 +61,8 @@ public class Jurisdiction { @SafeHtml private String id; + private String employeeId; + @SafeHtml @NotNull @Size(min=2, max=100) diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/ReactivationDetails.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/ReactivationDetails.java index a5cb0c1a3c4..cb0f9a571f0 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/ReactivationDetails.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/ReactivationDetails.java @@ -19,6 +19,8 @@ public class ReactivationDetails { @SafeHtml private String id; + private String employeeId; + @SafeHtml @NotNull private String reasonForReactivation; diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/ServiceHistory.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/ServiceHistory.java index 56bdb6e2ca9..fda7ef85cba 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/model/ServiceHistory.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/model/ServiceHistory.java @@ -60,6 +60,8 @@ public class ServiceHistory { @SafeHtml private String id; + private String employeeId; + @SafeHtml private String serviceStatus; @@ -80,6 +82,4 @@ public class ServiceHistory { private AuditDetails auditDetails; - - } \ No newline at end of file diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/AssignmentRowMapper.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/AssignmentRowMapper.java new file mode 100644 index 00000000000..e2bfc7dc2e8 --- /dev/null +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/AssignmentRowMapper.java @@ -0,0 +1,46 @@ +package org.egov.hrms.repository; + +import org.egov.hrms.model.Assignment; +import org.egov.hrms.model.AuditDetails; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +@Component +public class AssignmentRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException { + List assignments = new ArrayList<>(); + while (rs.next()) { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("createdby")) + .createdDate(rs.getLong("createddate")) + .lastModifiedBy(rs.getString("lastmodifiedby")) + .lastModifiedDate(rs.getLong("lastmodifieddate")) + .build(); + + Assignment assignment = Assignment.builder() + .id(rs.getString("assignment_uuid")) + .employeeId(rs.getString("employeeid")) + .position(rs.getLong("position")) + .department(rs.getString("department")) + .designation(rs.getString("designation")) + .fromDate(rs.getLong("fromdate")) + .toDate(rs.getObject("todate") != null ? rs.getLong("todate") : null) + .govtOrderNumber(rs.getString("govtordernumber")) + .reportingTo(rs.getString("reportingto")) + .isHOD(rs.getBoolean("ishod")) + .isCurrentAssignment(rs.getBoolean("iscurrentassignment")) + .tenantid(rs.getString("tenantid")) + .auditDetails(auditDetails) + .build(); + assignments.add(assignment); + } + return assignments; + } +} diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DeactivationDetailsRowMapper.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DeactivationDetailsRowMapper.java new file mode 100644 index 00000000000..b651a0e700e --- /dev/null +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DeactivationDetailsRowMapper.java @@ -0,0 +1,43 @@ +package org.egov.hrms.repository; + +import org.egov.hrms.model.AuditDetails; +import org.egov.hrms.model.DeactivationDetails; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +@Component +public class DeactivationDetailsRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException { + + List deactivationDetails = new ArrayList<>(); + while (rs.next()) { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("createdby")) + .createdDate(rs.getLong("createddate")) + .lastModifiedBy(rs.getString("lastmodifiedby")) + .lastModifiedDate(rs.getLong("lastmodifieddate")) + .build(); + + DeactivationDetails deactivationDetail = DeactivationDetails.builder() + .id(rs.getString("deact_uuid")) + .reasonForDeactivation(rs.getString("reasonfordeactivation")) + .orderNo(rs.getString("ordernumber")) + .remarks(rs.getString("remarks")) + .effectiveFrom(rs.getLong("effectivefrom")) + .employeeId(rs.getString("employeeid")) + .tenantId(rs.getString("tenantid")) + .auditDetails(auditDetails) + .build(); + deactivationDetails.add(deactivationDetail); + } + return deactivationDetails; + } + +} diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DepartmentalTestRowMapper.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DepartmentalTestRowMapper.java new file mode 100644 index 00000000000..2c437527545 --- /dev/null +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DepartmentalTestRowMapper.java @@ -0,0 +1,40 @@ +package org.egov.hrms.repository; + +import org.egov.hrms.model.AuditDetails; +import org.egov.hrms.model.DepartmentalTest; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +@Component +public class DepartmentalTestRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException { + List departmentalTests = new ArrayList<>(); + while (rs.next()) { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("createdby")) + .createdDate(rs.getLong("createddate")) + .lastModifiedBy(rs.getString("lastmodifiedby")) + .lastModifiedDate(rs.getLong("lastmodifieddate")) + .build(); + DepartmentalTest departmentalTest = DepartmentalTest.builder() + .id(rs.getString("uuid")) + .test(rs.getString("testname")) + .yearOfPassing(rs.getLong("yearofpassing")) + .remarks(rs.getString("remarks")) + .employeeId(rs.getString("employeeid")) + .tenantId(rs.getString("tenantid")) + .auditDetails(auditDetails) + .build(); + departmentalTests.add(departmentalTest); + } + return departmentalTests; + } + +} diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DocumentRowMapper.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DocumentRowMapper.java new file mode 100644 index 00000000000..7bc3c1e3900 --- /dev/null +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/DocumentRowMapper.java @@ -0,0 +1,44 @@ +package org.egov.hrms.repository; + +import org.egov.hrms.model.AuditDetails; +import org.egov.hrms.model.EmployeeDocument; +import org.egov.hrms.model.enums.EmployeeDocumentReferenceType; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +@Component +public class DocumentRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException { + + List documents = new ArrayList<>(); + while (rs.next()) { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("createdby")) + .createdDate(rs.getLong("createddate")) + .lastModifiedBy(rs.getString("lastmodifiedby")) + .lastModifiedDate(rs.getLong("lastmodifieddate")) + .build(); + + EmployeeDocument document = EmployeeDocument.builder() + .id(rs.getString("docs_uuid")) + .documentName(rs.getString("documentname")) + .documentId(rs.getString("documentid")) + .referenceType(EmployeeDocumentReferenceType.valueOf(rs.getString("referencetype"))) + .referenceId(rs.getString("referenceid")) + .employeeId(rs.getString("employeeid")) + .tenantId(rs.getString("tenantid")) + .auditDetails(auditDetails) + .build(); + documents.add(document); + } + return documents; + } + +} diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EducationalDetailsRowMapper.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EducationalDetailsRowMapper.java new file mode 100644 index 00000000000..3fba9e94170 --- /dev/null +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EducationalDetailsRowMapper.java @@ -0,0 +1,42 @@ +package org.egov.hrms.repository; + +import org.egov.hrms.model.AuditDetails; +import org.egov.hrms.model.EducationalQualification; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +@Component +public class EducationalDetailsRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException { + List educationalQualifications = new ArrayList<>(); + while (rs.next()) { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("createdby")) + .createdDate(rs.getLong("createddate")) + .lastModifiedBy(rs.getString("lastmodifiedby")) + .lastModifiedDate(rs.getLong("lastmodifieddate")) + .build(); + educationalQualifications.add(EducationalQualification.builder() + .id(rs.getString("uuid")) + .qualification(rs.getString("qualification")) + .stream(rs.getString("stream")) + .yearOfPassing(rs.getLong("yearofpassing")) + .university(rs.getString("university")) + .remarks(rs.getString("remarks")) + .employeeId(rs.getString("employeeid")) + .tenantId(rs.getString("tenantid")) + .isActive(rs.getBoolean("isactive")) + .auditDetails(auditDetails) + .build()); + } + return educationalQualifications; + } +} + diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeQueries.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeQueries.java index 6b824692a34..1b52ee3d76d 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeQueries.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeQueries.java @@ -43,9 +43,67 @@ public class EmployeeQueries { + "ON employee.uuid = jurisdiction.employeeid LEFT JOIN eg_hrms_deactivationdetails deact ON employee.uuid = deact.employeeid LEFT JOIN eg_hrms_reactivationdetails react " + "ON employee.uuid = react.employeeid WHERE "; + public static final String HRMS_EMPLOYEE_TABLE_QUREY = "SELECT employee.id AS employee_id, employee.uuid AS employee_uuid, employee.code AS employee_code, " + + " employee.dateOfAppointment AS employee_doa, employee.employeestatus AS employee_status, " + + " employee.employeetype AS employee_type, employee.active AS employee_active, " + + " employee.reactivateemployee AS employee_reactive, employee.tenantid AS employee_tenantid, " + + " employee.createdby AS employee_createdby, employee.createddate AS employee_createddate, " + + " employee.lastmodifiedby AS employee_lastmodifiedby, employee.lastmodifieddate AS employee_lastmodifieddate " + + " FROM eg_hrms_employee employee " + + " WHERE "; + + public static final String SUBQUERY_EG_HRMS_ASSIGNMENT = "SELECT assignment.uuid AS assignment_uuid, assignment.employeeid, assignment.position, assignment.department, assignment.designation, " + + " assignment.fromdate, assignment.todate, assignment.govtordernumber, assignment.reportingto, " + + " assignment.ishod, assignment.iscurrentassignment, assignment.tenantid, assignment.createdby, " + + " assignment.createddate, assignment.lastmodifiedby, assignment.lastmodifieddate " + + "FROM eg_hrms_assignment assignment " + + "WHERE assignment.employeeid IN (:employeeIds); "; + + public static final String SUBQUERY_EG_HRMS_EDUCATIONALDETAILS = "SELECT education.uuid AS education_uuid, education.employeeid, education.qualification, education.stream, education.yearofpassing, " + + " education.university, education.remarks, education.isactive, education.tenantid, education.createdby, " + + " education.createddate, education.lastmodifiedby, education.lastmodifieddate " + + "FROM eg_hrms_educationaldetails education " + + "WHERE education.employeeid IN (:employeeIds); "; + + public static final String SUBQUERY_EG_HRMS_DEPARTMENTALTESTS = "SELECT depttest.uuid AS depttest_uuid, depttest.employeeid, depttest.test, depttest.yearofpassing, depttest.remarks, " + + " depttest.isactive, depttest.tenantid, depttest.createdby, depttest.createddate, " + + " depttest.lastmodifiedby, depttest.lastmodifieddate " + + "FROM eg_hrms_departmentaltests depttest " + + "WHERE depttest.employeeid IN (:employeeIds); "; + + public static final String SUBQUERY_EG_HRMS_EMPDOCUMENTS = "SELECT docs.uuid AS docs_uuid, docs.employeeid, docs.documentid, docs.documentname, docs.referencetype, docs.referenceid, " + + " docs.tenantid, docs.createdby, docs.createddate, docs.lastmodifiedby, docs.lastmodifieddate " + + "FROM eg_hrms_empdocuments docs " + + "WHERE docs.employeeid IN (:employeeIds); "; + + public static final String SUBQUERY_EG_HRMS_SERVICEHISTORY = "SELECT history.uuid AS history_uuid, history.employeeid, history.servicestatus, history.servicefrom, history.serviceto, " + + " history.ordernumber, history.iscurrentposition, history.location, history.tenantid, " + + " history.createdby, history.createddate, history.lastmodifiedby, history.lastmodifieddate " + + "FROM eg_hrms_servicehistory history " + + "WHERE history.employeeid IN (:employeeIds); "; + public static final String SUBQUERY_EG_HRMS_JURISDICTION = "SELECT jurisdiction.uuid, jurisdiction.employeeid, jurisdiction.hierarchy, jurisdiction.boundarytype, " + + " jurisdiction.boundary, jurisdiction.isactive, jurisdiction.tenantid, jurisdiction.createdby, " + + " jurisdiction.createddate, jurisdiction.lastmodifiedby, jurisdiction.lastmodifieddate " + + "FROM eg_hrms_jurisdiction jurisdiction " + + "WHERE jurisdiction.employeeid IN (:employeeIds) "; + + public static final String SUBQUERY_EG_HRMS_DEACTIVATIONDETAILS = "SELECT deact.uuid AS deact_uuid, deact.employeeid, deact.reasonfordeactivation, deact.effectivefrom, deact.ordernumber, " + + " deact.remarks, deact.tenantid, deact.createdby, deact.createddate, deact.lastmodifiedby, " + + " deact.lastmodifieddate " + + "FROM eg_hrms_deactivationdetails deact " + + "WHERE deact.employeeid IN (:employeeIds); "; + + public static final String SUBQUERY_EG_HRMS_REACTIVATIONDETAILS = "SELECT react.uuid AS react_uuid, react.employeeid, react.reasonforreactivation, react.effectivefrom, react.ordernumber, " + + " react.remarks, react.tenantid, react.createdby, react.createddate, react.lastmodifiedby, " + + " react.lastmodifieddate " + + "FROM eg_hrms_reactivationdetails react " + + "WHERE react.employeeid IN (:employeeIds); "; + public static final String HRMS_PAGINATION_WRAPPER = "SELECT * FROM " + "(SELECT *, DENSE_RANK() OVER (ORDER BY employee_uuid) offset_ FROM " + "({})" + " result) result_offset " + "WHERE offset_ > $offset AND offset_ <= $limit"; + + public static final String HRMS_PAGINATION_ADDENDUM = " ORDER BY employee.lastmodifieddate DESC LIMIT $limit OFFSET $offset"; public static final String HRMS_POSITION_SEQ = "SELECT NEXTVAL('EG_HRMS_POSITION')"; diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeQueryBuilder.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeQueryBuilder.java index 4e5e5d7bdc4..89ff19e29c4 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeQueryBuilder.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeQueryBuilder.java @@ -29,7 +29,7 @@ public class EmployeeQueryBuilder { * @return */ public String getEmployeeSearchQuery(EmployeeSearchCriteria criteria,List preparedStmtList ) { - StringBuilder builder = new StringBuilder(EmployeeQueries.HRMS_GET_EMPLOYEES); + StringBuilder builder = new StringBuilder(EmployeeQueries.HRMS_EMPLOYEE_TABLE_QUREY); addWhereClause(criteria, builder, preparedStmtList); return paginationClause(criteria, builder); } @@ -94,8 +94,7 @@ public void addWhereClause(EmployeeSearchCriteria criteria, StringBuilder builde } public String paginationClause(EmployeeSearchCriteria criteria, StringBuilder builder) { - String pagination = EmployeeQueries.HRMS_PAGINATION_WRAPPER; - pagination = pagination.replace("{}", builder.toString()); + String pagination = EmployeeQueries.HRMS_PAGINATION_ADDENDUM; if(null != criteria.getOffset()) pagination = pagination.replace("$offset", criteria.getOffset().toString()); else @@ -107,8 +106,8 @@ public String paginationClause(EmployeeSearchCriteria criteria, StringBuilder bu } else pagination = pagination.replace("$limit", defaultLimit.toString()); - - return pagination; + builder.append(pagination); + return builder.toString(); } public String getAssignmentSearchQuery(EmployeeSearchCriteria criteria, List preparedStmtList) { diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeRepository.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeRepository.java index 20bb37a813e..1663d48e111 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeRepository.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeRepository.java @@ -1,23 +1,25 @@ package org.egov.hrms.repository; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; import org.egov.common.contract.request.RequestInfo; +import org.egov.hrms.model.*; import org.egov.hrms.utils.HRMSUtils; import org.egov.hrms.web.contract.EmployeeSearchCriteria; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.stereotype.Repository; import lombok.extern.slf4j.Slf4j; -import org.egov.hrms.model.Employee; import org.springframework.util.CollectionUtils; +import static org.egov.hrms.repository.EmployeeQueries.*; + @Repository @Slf4j public class EmployeeRepository { @@ -29,7 +31,33 @@ public class EmployeeRepository { private JdbcTemplate jdbcTemplate; @Autowired - private EmployeeRowMapper rowMapper; + private EmployeeTableRowMapper employeeTableRowMapper; + + @Autowired DepartmentalTestRowMapper departmentalTestRowMapper; + + @Autowired + private JurisdictionRowMapper jurisdictionRowMapper; + + @Autowired + private NamedParameterJdbcTemplate namedParameterJdbcTemplate; + + @Autowired + private AssignmentRowMapper assignmentRowMapper; + + @Autowired + private EducationalDetailsRowMapper educationalDetailsRowMapper; + + @Autowired + private DocumentRowMapper documentRowMapper; + + @Autowired + private ServiceHistoryRowMapper serviceHistoryRowMapper; + + @Autowired + private DeactivationDetailsRowMapper deactivationDetailsRowMapper; + + @Autowired + private ReactivationDetailsRowMapper reactivationDetailsRowMapper; @Autowired private EmployeeCountRowMapper countRowMapper; @@ -46,7 +74,6 @@ public class EmployeeRepository { */ public List fetchEmployees(EmployeeSearchCriteria criteria, RequestInfo requestInfo){ List employees = new ArrayList<>(); - List preparedStmtList = new ArrayList<>(); if(hrmsUtils.isAssignmentSearchReqd(criteria)) { List empUuids = fetchEmployeesforAssignment(criteria, requestInfo); if (CollectionUtils.isEmpty(empUuids)) @@ -62,14 +89,95 @@ public List fetchEmployees(EmployeeSearchCriteria criteria, RequestInf List empUuids = fetchUnassignedEmployees(criteria, requestInfo); criteria.setUuids(empUuids); } + + return fetchEmployeesByCriteria(criteria); + } + + ListfetchEmployeesByCriteria (EmployeeSearchCriteria criteria) { + List preparedStmtList = new ArrayList<>(); String query = queryBuilder.getEmployeeSearchQuery(criteria, preparedStmtList); - try { - employees = jdbcTemplate.query(query, preparedStmtList.toArray(),rowMapper); - }catch(Exception e) { - log.error("Exception while making the db call: ",e); - log.error("query; "+query); + List employees = jdbcTemplate.query(query, preparedStmtList.toArray(), employeeTableRowMapper); + + if (CollectionUtils.isEmpty(employees)) { + return employees; } - return employees; + + List employeeIds = employees.stream().map(Employee::getUuid).collect(Collectors.toList()); + MapSqlParameterSource parameters = new MapSqlParameterSource("employeeIds", employeeIds); + + List jurisdictions = namedParameterJdbcTemplate.query(SUBQUERY_EG_HRMS_JURISDICTION, parameters, jurisdictionRowMapper); + List assignments = namedParameterJdbcTemplate.query(SUBQUERY_EG_HRMS_ASSIGNMENT, parameters, assignmentRowMapper); + List educationalQualifications = namedParameterJdbcTemplate.query(SUBQUERY_EG_HRMS_EDUCATIONALDETAILS, parameters, educationalDetailsRowMapper); + List departmentalTests = namedParameterJdbcTemplate.query(SUBQUERY_EG_HRMS_DEPARTMENTALTESTS, parameters, departmentalTestRowMapper); + List employeeDocuments = namedParameterJdbcTemplate.query(SUBQUERY_EG_HRMS_EMPDOCUMENTS, parameters, documentRowMapper); + List serviceHistories = namedParameterJdbcTemplate.query(SUBQUERY_EG_HRMS_SERVICEHISTORY, parameters,serviceHistoryRowMapper); + List deactivationDetails = namedParameterJdbcTemplate.query(SUBQUERY_EG_HRMS_DEACTIVATIONDETAILS, parameters,deactivationDetailsRowMapper); + List reactivationDetails = namedParameterJdbcTemplate.query(SUBQUERY_EG_HRMS_REACTIVATIONDETAILS, parameters, reactivationDetailsRowMapper); + + return mapEmployeeData(employees, groupByEmployeeId(assignments, Assignment::getEmployeeId), + groupByEmployeeId(jurisdictions, Jurisdiction::getEmployeeId), + groupByEmployeeId(educationalQualifications, EducationalQualification::getEmployeeId), + groupByEmployeeId(departmentalTests, DepartmentalTest::getEmployeeId), + groupByEmployeeId(employeeDocuments, EmployeeDocument::getEmployeeId), + groupByEmployeeId(serviceHistories, ServiceHistory::getEmployeeId), + groupByEmployeeId(deactivationDetails, DeactivationDetails::getEmployeeId), + groupByEmployeeId(reactivationDetails, ReactivationDetails::getEmployeeId)); + } + + private Map> groupByEmployeeId(List subTableData, Function employeeIdExtractor) { + return subTableData.stream() + .collect(Collectors.groupingBy(employeeIdExtractor)); + } + + + public List mapEmployeeData(List employees, + Map> assignmentsByEmployeeId, + Map> jurisdictionsByEmployeeId, + Map> educationalQualificationsByEmployeeId, + Map> departmentalTestsByEmployeeId, + Map> documentsByEmployeeId, + Map> serviceHistoryByEmployeeId, + Map> deactivationDetailsByEmployeeId, + Map> reactivationDetailsByEmployeeId) { + return employees.stream() + .map(employee -> { + String employeeId = employee.getUuid(); + + // Set departmental tests + List departmentalTests = departmentalTestsByEmployeeId.getOrDefault(employeeId, Collections.emptyList()); + employee.setTests(departmentalTests); + + // Set documents + List documents = documentsByEmployeeId.getOrDefault(employeeId, Collections.emptyList()); + employee.setDocuments(documents); + + // Set service history + List serviceHistory = serviceHistoryByEmployeeId.getOrDefault(employeeId, Collections.emptyList()); + employee.setServiceHistory(serviceHistory); + + // Set deactivation details + List deactivationDetails = deactivationDetailsByEmployeeId.getOrDefault(employeeId, Collections.emptyList()); + employee.setDeactivationDetails(deactivationDetails); + + // Set reactivation details + List reactivationDetails = reactivationDetailsByEmployeeId.getOrDefault(employeeId, Collections.emptyList()); + employee.setReactivationDetails(reactivationDetails); + + // Set educational qualifications + List educationalQualifications = educationalQualificationsByEmployeeId.getOrDefault(employeeId, Collections.emptyList()); + employee.setEducation(educationalQualifications); + + // Set assignments + List assignments = assignmentsByEmployeeId.getOrDefault(employeeId, Collections.emptyList()); + employee.setAssignments(assignments); + + // Set jurisdictions + List jurisdictions = jurisdictionsByEmployeeId.getOrDefault(employeeId, Collections.emptyList()); + employee.setJurisdictions(jurisdictions); + + return employee; + }) + .collect(Collectors.toList()); } private List fetchUnassignedEmployees(EmployeeSearchCriteria criteria, RequestInfo requestInfo) { diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeTableRowMapper.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeTableRowMapper.java new file mode 100644 index 00000000000..754d1c29341 --- /dev/null +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/EmployeeTableRowMapper.java @@ -0,0 +1,63 @@ +package org.egov.hrms.repository; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.hrms.model.AuditDetails; +import org.egov.hrms.model.Employee; +import org.egov.hrms.web.contract.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +@Slf4j +public class EmployeeTableRowMapper implements ResultSetExtractor> { + + @Autowired + private ObjectMapper mapper; + + @Override + public List extractData(ResultSet rs) throws SQLException, DataAccessException { + Map employeeMap = new HashMap<>(); + while (rs.next()) { + String currentId = rs.getString("employee_uuid"); + Employee currentEmployee = employeeMap.get(currentId); + + // Create Employee object if not already in the map + if (currentEmployee == null) { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("employee_createdby")) + .createdDate(rs.getLong("employee_createddate")) + .lastModifiedBy(rs.getString("employee_lastmodifiedby")) + .lastModifiedDate(rs.getLong("employee_lastmodifieddate")) + .build(); + + currentEmployee = Employee.builder() + .id(rs.getLong("employee_id")) + .uuid(rs.getString("employee_uuid")) + .tenantId(rs.getString("employee_tenantid")) + .code(rs.getString("employee_code")) + .dateOfAppointment(rs.getObject("employee_doa") != null ? rs.getLong("employee_doa") : null) + .IsActive(rs.getBoolean("employee_active")) + .employeeStatus(rs.getString("employee_status")) + .employeeType(rs.getString("employee_type")) + .reActivateEmployee(rs.getBoolean("employee_reactive")) + .user(new User()) // Empty User object; populate later if needed + .auditDetails(auditDetails) + .build(); + + employeeMap.put(currentId, currentEmployee); + } + } + return new ArrayList<>(employeeMap.values()); + } + +} diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/JurisdictionRowMapper.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/JurisdictionRowMapper.java new file mode 100644 index 00000000000..7aadc9642ee --- /dev/null +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/JurisdictionRowMapper.java @@ -0,0 +1,42 @@ +package org.egov.hrms.repository; + +import org.egov.hrms.model.AuditDetails; +import org.egov.hrms.model.Jurisdiction; +import org.springframework.stereotype.Component; +import org.springframework.jdbc.core.ResultSetExtractor; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +@Component +public class JurisdictionRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException { + + List jurisdictions = new ArrayList<>(); + while (rs.next()) { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("createdby")) + .createdDate(rs.getLong("createddate")) + .lastModifiedBy(rs.getString("lastmodifiedby")) + .lastModifiedDate(rs.getLong("lastmodifieddate")) + .build(); + Jurisdiction jurisdiction = Jurisdiction.builder() + .id(rs.getString("uuid")) + .employeeId(rs.getString("employeeid")) + .boundary(rs.getString("boundary")) + .boundaryType(rs.getString("boundarytype")) + .isActive(rs.getBoolean("isactive")) + .hierarchy(rs.getString("hierarchy")) + .tenantId(rs.getString("tenantid")) + .auditDetails(auditDetails) + .build(); + jurisdictions.add(jurisdiction); + } + return jurisdictions; + } +} + diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/ReactivationDetailsRowMapper.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/ReactivationDetailsRowMapper.java new file mode 100644 index 00000000000..b13d64baf06 --- /dev/null +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/ReactivationDetailsRowMapper.java @@ -0,0 +1,40 @@ +package org.egov.hrms.repository; + +import org.egov.hrms.model.AuditDetails; +import org.egov.hrms.model.ReactivationDetails; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +@Component +public class ReactivationDetailsRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException { + List reactivationDetails = new ArrayList<>(); + while (rs.next()) { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("createdby")) + .createdDate(rs.getLong("createddate")) + .lastModifiedBy(rs.getString("lastmodifiedby")) + .lastModifiedDate(rs.getLong("lastmodifieddate")) + .build(); + + ReactivationDetails reactivationDetail = ReactivationDetails.builder() + .id(rs.getString("uuid")) + .reasonForReactivation(rs.getString("reasonforreactivation")) + .orderNo(rs.getString("ordernumber")) + .remarks(rs.getString("remarks")) + .effectiveFrom(rs.getLong("effectivefrom")) + .employeeId(rs.getString("employeeid")) + .tenantId(rs.getString("tenantid")) + .auditDetails(auditDetails) + .build(); + reactivationDetails.add(reactivationDetail); + } + return reactivationDetails; + } +} diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/ServiceHistoryRowMapper.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/ServiceHistoryRowMapper.java new file mode 100644 index 00000000000..1c734a5e70e --- /dev/null +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/repository/ServiceHistoryRowMapper.java @@ -0,0 +1,44 @@ +package org.egov.hrms.repository; + +import org.egov.hrms.model.ServiceHistory; +import org.egov.hrms.model.AuditDetails; +import org.springframework.stereotype.Component; +import org.springframework.jdbc.core.ResultSetExtractor; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +@Component +public class ServiceHistoryRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException { + List serviceHistories = new ArrayList<>(); + while (rs.next()) { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("createdby")) + .createdDate(rs.getLong("createddate")) + .lastModifiedBy(rs.getString("lastmodifiedby")) + .lastModifiedDate(rs.getLong("lastmodifieddate")) + .build(); + ServiceHistory serviceHistory = ServiceHistory.builder() + .id(rs.getString("history_uuid")) + .serviceStatus(rs.getString("servicestatus")) + .serviceFrom(rs.getLong("servicefrom")) + .serviceTo(rs.getLong("serviceto")) + .isCurrentPosition(rs.getBoolean("iscurrentposition")) + .orderNo(rs.getString("ordernumber")) + .location(rs.getString("location")) + .employeeId(rs.getString("employeeid")) + .tenantId(rs.getString("tenantid")) + .auditDetails(auditDetails) + .build(); + serviceHistories.add(serviceHistory); + } + return serviceHistories; + } + + +} diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java index 0bfb5181737..ceb95f160be 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java @@ -306,9 +306,12 @@ private void enrichUser(Employee employee) { */ private void enrichCreateRequest(Employee employee, RequestInfo requestInfo) { + long time = new Date().getTime(); AuditDetails auditDetails = AuditDetails.builder() .createdBy(requestInfo.getUserInfo().getUuid()) - .createdDate(new Date().getTime()) + .createdDate(time) + .lastModifiedBy(requestInfo.getUserInfo().getUuid()) + .lastModifiedDate(time) .build(); employee.getJurisdictions().stream().forEach(jurisdiction -> { @@ -448,10 +451,10 @@ private void updateUser(Employee employee, RequestInfo requestInfo) { * @param existingEmployeesData */ private void enrichUpdateRequest(Employee employee, RequestInfo requestInfo, List existingEmployeesData) { - AuditDetails auditDetails = AuditDetails.builder() - .createdBy(requestInfo.getUserInfo().getUserName()) - .createdDate(new Date().getTime()) - .build(); + + AuditDetails auditDetails = employee.getAuditDetails(); + auditDetails.setLastModifiedBy(requestInfo.getUserInfo().getUuid()); + auditDetails.setLastModifiedDate(new Date().getTime()); // Find the existing employee data matching the current employee's UUID Employee existingEmpData = existingEmployeesData.stream() .filter(existingEmployee -> existingEmployee.getUuid().equals(employee.getUuid()))