Skip to content

Commit

Permalink
HCMPRE-1333- Removed dense rank query; using sequential calls to get …
Browse files Browse the repository at this point in the history
…child table data. (#1210)
  • Loading branch information
shubhang-eGov authored Dec 16, 2024
1 parent 183f6e9 commit 2d2d4cc
Show file tree
Hide file tree
Showing 21 changed files with 611 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class Assignment {
@SafeHtml
private String id;

private String employeeId;

private Long position;

@SafeHtml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class DeactivationDetails {
@SafeHtml
private String id;

private String employeeId;

@SafeHtml
@NotNull
private String reasonForDeactivation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class DepartmentalTest {
@SafeHtml
private String id;

private String employeeId;

@SafeHtml
@NotNull
private String test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class EducationalQualification {
@SafeHtml
private String id;

private String employeeId;

@SafeHtml
@NotNull
private String qualification;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class EmployeeDocument {
@SafeHtml
private String id;

private String employeeId;

@SafeHtml
private String documentName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class Jurisdiction {
@SafeHtml
private String id;

private String employeeId;

@SafeHtml
@NotNull
@Size(min=2, max=100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ReactivationDetails {
@SafeHtml
private String id;

private String employeeId;

@SafeHtml
@NotNull
private String reasonForReactivation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class ServiceHistory {
@SafeHtml
private String id;

private String employeeId;

@SafeHtml
private String serviceStatus;

Expand All @@ -80,6 +82,4 @@ public class ServiceHistory {

private AuditDetails auditDetails;



}
Original file line number Diff line number Diff line change
@@ -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<List<Assignment>> {

@Override
public List<Assignment> extractData(ResultSet rs) throws SQLException {
List<Assignment> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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<List<DeactivationDetails>> {

@Override
public List<DeactivationDetails> extractData(ResultSet rs) throws SQLException {

List<DeactivationDetails> 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;
}

}
Original file line number Diff line number Diff line change
@@ -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<List<DepartmentalTest>> {

@Override
public List<DepartmentalTest> extractData(ResultSet rs) throws SQLException {
List<DepartmentalTest> 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;
}

}
Original file line number Diff line number Diff line change
@@ -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<List<EmployeeDocument>> {

@Override
public List<EmployeeDocument> extractData(ResultSet rs) throws SQLException {

List<EmployeeDocument> 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;
}

}
Original file line number Diff line number Diff line change
@@ -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<List<EducationalQualification>> {

@Override
public List<EducationalQualification> extractData(ResultSet rs) throws SQLException {
List<EducationalQualification> 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;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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')";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class EmployeeQueryBuilder {
* @return
*/
public String getEmployeeSearchQuery(EmployeeSearchCriteria criteria,List <Object> 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);
}
Expand Down Expand Up @@ -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
Expand All @@ -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<Object> preparedStmtList) {
Expand Down
Loading

0 comments on commit 2d2d4cc

Please sign in to comment.