fix(aihr): merge supervisor project scopes
This commit is contained in:
+17
-10
@@ -2247,7 +2247,6 @@ public class AihrPracticeSeedService {
|
||||
FROM aihr_org_snapshot
|
||||
WHERE tenant_id = ? AND """ + identityWhere + """
|
||||
AND employment_status = 'active'
|
||||
LIMIT 1
|
||||
""", (rs, rowNum) -> rs.getString("position_level"), args.toArray());
|
||||
if (positionLevels.stream().noneMatch(AihrPracticeSeedService::canSeeProject)) {
|
||||
throw new ServiceException("无主管权限,无法访问主管功能");
|
||||
@@ -2277,33 +2276,41 @@ public class AihrPracticeSeedService {
|
||||
FROM aihr_org_snapshot
|
||||
WHERE tenant_id = ? AND """ + ownerWhere + """
|
||||
AND employment_status = 'active'
|
||||
LIMIT 1
|
||||
""", (rs, rowNum) -> new OrgScopeRow(rs.getString("project_code"), rs.getString("position_level")), ownerArgs.toArray());
|
||||
if (owners.isEmpty()) {
|
||||
return TeamScope.scoped(List.of());
|
||||
}
|
||||
OrgScopeRow row = owners.stream()
|
||||
List<String> projectCodes = owners.stream()
|
||||
.filter(scope -> canSeeProject(scope.positionLevel()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (row == null) {
|
||||
.map(OrgScopeRow::projectCode)
|
||||
.filter(projectCode -> !isBlank(projectCode))
|
||||
.distinct()
|
||||
.toList();
|
||||
if (projectCodes.isEmpty()) {
|
||||
return TeamScope.scoped(List.of(owner));
|
||||
}
|
||||
String projectInClause = inClause(projectCodes.size());
|
||||
List<Object> projectArgs = new ArrayList<>();
|
||||
projectArgs.add(tenantId());
|
||||
projectArgs.addAll(projectCodes);
|
||||
List<String> ids = jdbcTemplate.query("""
|
||||
SELECT ext_party_id
|
||||
FROM aihr_org_snapshot
|
||||
WHERE tenant_id = ? AND project_code = ? AND employment_status = 'active'
|
||||
WHERE tenant_id = ? AND project_code IN (%s) AND employment_status = 'active'
|
||||
ORDER BY position_level, person_name, ext_party_id
|
||||
""", (rs, rowNum) -> rs.getString("ext_party_id"), tenantId(), row.projectCode());
|
||||
""".formatted(projectInClause), (rs, rowNum) -> rs.getString("ext_party_id"), projectArgs.toArray());
|
||||
if (hasPhone) {
|
||||
ids = new ArrayList<>(new LinkedHashSet<>(ids));
|
||||
List<Object> phoneArgs = new ArrayList<>();
|
||||
phoneArgs.add(tenantId());
|
||||
phoneArgs.addAll(projectCodes);
|
||||
ids.addAll(jdbcTemplate.query("""
|
||||
SELECT person_phone
|
||||
FROM aihr_org_snapshot
|
||||
WHERE tenant_id = ? AND project_code = ? AND employment_status = 'active'
|
||||
WHERE tenant_id = ? AND project_code IN (%s) AND employment_status = 'active'
|
||||
AND person_phone IS NOT NULL AND person_phone <> ''
|
||||
ORDER BY position_level, person_name, ext_party_id
|
||||
""", (rs, rowNum) -> rs.getString("person_phone"), tenantId(), row.projectCode()));
|
||||
""".formatted(projectInClause), (rs, rowNum) -> rs.getString("person_phone"), phoneArgs.toArray()));
|
||||
ids = new ArrayList<>(new LinkedHashSet<>(ids));
|
||||
}
|
||||
return TeamScope.scoped(ids);
|
||||
|
||||
+48
-14
@@ -248,6 +248,7 @@ public class AihrPracticeSeedServiceTest {
|
||||
AihrPracticeSeedService service = new AihrPracticeSeedService(new ObjectMapper(), jdbcTemplate, null, null);
|
||||
|
||||
assertEquals("13900001111", service.requireSupervisorIdentity("13900001111"));
|
||||
assertFalse(jdbcTemplate.authorizationSql.contains("LIMIT 1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -358,6 +359,17 @@ public class AihrPracticeSeedServiceTest {
|
||||
assertEquals(List.of("000000", "EMP-SUP", "EMP-1", "SUP-PHONE", "EMP-PHONE-1", 200), jdbcTemplate.assignmentsArgs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void practiceTeamSnapshotMergesAllSupervisorProjects() throws Exception {
|
||||
TeamSnapshotJdbcTemplate jdbcTemplate = new TeamSnapshotJdbcTemplate(true, true);
|
||||
AihrPracticeSeedService service = new AihrPracticeSeedService(new ObjectMapper(), jdbcTemplate, null, null);
|
||||
|
||||
invokePracticeTeamSnapshot(service, "SUP-PHONE", 200);
|
||||
|
||||
assertTrue(jdbcTemplate.membersSql.contains("ext_party_id IN (?,?,?,?,?,?,?,?)"));
|
||||
assertTrue(jdbcTemplate.recordsSql.contains("ext_party_id IN (?,?,?,?,?,?,?,?)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void markReviewedInitializesAssignmentTableBeforeSessionUpdate() {
|
||||
ReviewAssignmentOrderJdbcTemplate jdbcTemplate = new ReviewAssignmentOrderJdbcTemplate();
|
||||
@@ -749,7 +761,7 @@ public class AihrPracticeSeedServiceTest {
|
||||
assignmentSql = sql;
|
||||
return List.of();
|
||||
}
|
||||
if (sql.contains("SELECT project_code") && sql.contains("LIMIT 1")) {
|
||||
if (sql.contains("SELECT project_code")) {
|
||||
return mapRows(rowMapper, List.of(Map.of(
|
||||
"project_code", "P1",
|
||||
"position_level", ownerLevel
|
||||
@@ -803,7 +815,7 @@ public class AihrPracticeSeedServiceTest {
|
||||
reviewArgs = List.of(args);
|
||||
return List.of();
|
||||
}
|
||||
if (sql.contains("SELECT project_code") && sql.contains("LIMIT 1")) {
|
||||
if (sql.contains("SELECT project_code")) {
|
||||
ownerSql = sql;
|
||||
ownerArgs = List.of(args);
|
||||
if (ownerLevel == null) {
|
||||
@@ -933,6 +945,7 @@ public class AihrPracticeSeedServiceTest {
|
||||
|
||||
private static final class TeamSnapshotJdbcTemplate extends JdbcTemplate {
|
||||
private final boolean orgSnapshotAvailable;
|
||||
private final boolean multipleProjects;
|
||||
private String membersSql = "";
|
||||
private List<Object> membersArgs = List.of();
|
||||
private String recordsSql = "";
|
||||
@@ -941,7 +954,12 @@ public class AihrPracticeSeedServiceTest {
|
||||
private List<Object> assignmentsArgs = List.of();
|
||||
|
||||
private TeamSnapshotJdbcTemplate(boolean orgSnapshotAvailable) {
|
||||
this(orgSnapshotAvailable, false);
|
||||
}
|
||||
|
||||
private TeamSnapshotJdbcTemplate(boolean orgSnapshotAvailable, boolean multipleProjects) {
|
||||
this.orgSnapshotAvailable = orgSnapshotAvailable;
|
||||
this.multipleProjects = multipleProjects;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -969,22 +987,38 @@ public class AihrPracticeSeedServiceTest {
|
||||
public <T> List<T> query(String sql, RowMapper<T> rowMapper, Object... args) {
|
||||
try {
|
||||
if (sql.contains("SELECT project_code, position_level")) {
|
||||
return mapRows(rowMapper, List.of(Map.of(
|
||||
"project_code", "P1",
|
||||
"position_level", "主管"
|
||||
)));
|
||||
return mapRows(rowMapper, multipleProjects
|
||||
? List.of(
|
||||
Map.of("project_code", "P1", "position_level", "主管"),
|
||||
Map.of("project_code", "P2", "position_level", "项目经理")
|
||||
)
|
||||
: List.of(Map.of("project_code", "P1", "position_level", "主管")));
|
||||
}
|
||||
if (sql.contains("SELECT ext_party_id") && sql.contains("ORDER BY position_level")) {
|
||||
return mapRows(rowMapper, List.of(
|
||||
Map.of("ext_party_id", "EMP-SUP"),
|
||||
Map.of("ext_party_id", "EMP-1")
|
||||
));
|
||||
return mapRows(rowMapper, multipleProjects
|
||||
? List.of(
|
||||
Map.of("ext_party_id", "EMP-SUP-1"),
|
||||
Map.of("ext_party_id", "EMP-1"),
|
||||
Map.of("ext_party_id", "EMP-SUP-2"),
|
||||
Map.of("ext_party_id", "EMP-2")
|
||||
)
|
||||
: List.of(
|
||||
Map.of("ext_party_id", "EMP-SUP"),
|
||||
Map.of("ext_party_id", "EMP-1")
|
||||
));
|
||||
}
|
||||
if (sql.contains("SELECT person_phone") && sql.contains("ORDER BY position_level")) {
|
||||
return mapRows(rowMapper, List.of(
|
||||
Map.of("person_phone", "SUP-PHONE"),
|
||||
Map.of("person_phone", "EMP-PHONE-1")
|
||||
));
|
||||
return mapRows(rowMapper, multipleProjects
|
||||
? List.of(
|
||||
Map.of("person_phone", "SUP-PHONE-1"),
|
||||
Map.of("person_phone", "EMP-PHONE-1"),
|
||||
Map.of("person_phone", "SUP-PHONE-2"),
|
||||
Map.of("person_phone", "EMP-PHONE-2")
|
||||
)
|
||||
: List.of(
|
||||
Map.of("person_phone", "SUP-PHONE"),
|
||||
Map.of("person_phone", "EMP-PHONE-1")
|
||||
));
|
||||
}
|
||||
if (sql.contains("FROM aihr_org_snapshot") && sql.contains("AS name")) {
|
||||
membersSql = sql;
|
||||
|
||||
Reference in New Issue
Block a user