fix(aihr): paginate org snapshot view
This commit is contained in:
+3
-1
@@ -30,7 +30,9 @@ public class AihrOrgSyncController {
|
||||
@RequestParam(required = false) String projectCode,
|
||||
@RequestParam(required = false) String positionLevel,
|
||||
@RequestParam(required = false) String status,
|
||||
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(required = false) Integer pageSize,
|
||||
@RequestParam(required = false, defaultValue = "200") Integer limit) {
|
||||
return R.ok(orgSyncService.snapshot(keyword, projectCode, positionLevel, status, limit));
|
||||
return R.ok(orgSyncService.snapshot(keyword, projectCode, positionLevel, status, pageNum, pageSize, limit));
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -35,6 +35,8 @@ public final class AihrOrgSyncDto {
|
||||
int total,
|
||||
int active,
|
||||
int departed,
|
||||
int pageNum,
|
||||
int pageSize,
|
||||
List<OrgProjectOption> projects,
|
||||
List<String> levels,
|
||||
List<OrgPersonRow> rows
|
||||
|
||||
+9
-5
@@ -113,16 +113,20 @@ public class AihrOrgSyncService {
|
||||
);
|
||||
}
|
||||
|
||||
public OrgSnapshotResponse snapshot(String keyword, String projectCode, String positionLevel, String status, Integer limit) {
|
||||
public OrgSnapshotResponse snapshot(String keyword, String projectCode, String positionLevel, String status,
|
||||
Integer pageNum, Integer pageSize, Integer limit) {
|
||||
requireSnapshotTable();
|
||||
int safeLimit = clamp(limit, 200, 1, MAX_PAGE_SIZE);
|
||||
int safePageNum = clamp(pageNum, 1, 1, 100000);
|
||||
int safePageSize = clamp(pageSize == null ? limit : pageSize, 20, 1, MAX_PAGE_SIZE);
|
||||
int offset = (safePageNum - 1) * safePageSize;
|
||||
List<Object> args = new ArrayList<>();
|
||||
String where = orgSnapshotWhere(keyword, projectCode, positionLevel, status, args);
|
||||
int total = countOrgRows("select count(*) from aihr_org_snapshot" + where, args);
|
||||
int active = countOrgRows("select count(*) from aihr_org_snapshot" + where + " and employment_status = 'active'", args);
|
||||
int departed = countOrgRows("select count(*) from aihr_org_snapshot" + where + " and employment_status = 'departed'", args);
|
||||
List<Object> rowArgs = new ArrayList<>(args);
|
||||
rowArgs.add(safeLimit);
|
||||
rowArgs.add(safePageSize);
|
||||
rowArgs.add(offset);
|
||||
List<OrgPersonRow> rows = jdbcTemplate.query("""
|
||||
select id, project_code, project_name, dept_name, ext_party_id, person_name,
|
||||
position_name, position_level, employment_status,
|
||||
@@ -130,7 +134,7 @@ public class AihrOrgSyncService {
|
||||
from aihr_org_snapshot
|
||||
""" + where + """
|
||||
order by project_name, dept_name, position_level, person_name
|
||||
limit ?
|
||||
limit ? offset ?
|
||||
""", (rs, rowNum) -> new OrgPersonRow(
|
||||
rs.getLong("id"),
|
||||
rs.getString("project_code"),
|
||||
@@ -143,7 +147,7 @@ public class AihrOrgSyncService {
|
||||
rs.getString("employment_status"),
|
||||
rs.getString("snapshot_date")
|
||||
), rowArgs.toArray());
|
||||
return new OrgSnapshotResponse(total, active, departed, orgProjects(), orgLevels(), rows);
|
||||
return new OrgSnapshotResponse(total, active, departed, safePageNum, safePageSize, orgProjects(), orgLevels(), rows);
|
||||
}
|
||||
|
||||
private List<JsonNode> fetchOptional(String baseUrl, String token, SyncRequest req, String resourceType,
|
||||
|
||||
Reference in New Issue
Block a user