fix(aihr): scope org sync to tenant
This commit is contained in:
+13
-7
@@ -9,6 +9,7 @@ import org.dromara.aihr.domain.AihrOrgSyncDto.OrgProjectOption;
|
||||
import org.dromara.aihr.domain.AihrOrgSyncDto.OrgSnapshotResponse;
|
||||
import org.dromara.aihr.domain.AihrOrgSyncDto.SyncRequest;
|
||||
import org.dromara.aihr.domain.AihrOrgSyncDto.SyncResponse;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -344,7 +345,7 @@ public class AihrOrgSyncService {
|
||||
private void saveRows(List<OrgRow> rows, boolean replaceExisting) {
|
||||
transactionTemplate.executeWithoutResult(status -> {
|
||||
if (replaceExisting) {
|
||||
jdbcTemplate.update("delete from aihr_org_snapshot where tenant_id = ?", TENANT_ID);
|
||||
jdbcTemplate.update("delete from aihr_org_snapshot where tenant_id = ?", tenantId());
|
||||
}
|
||||
jdbcTemplate.batchUpdate("""
|
||||
insert into aihr_org_snapshot
|
||||
@@ -362,7 +363,7 @@ public class AihrOrgSyncService {
|
||||
employment_status = values(employment_status),
|
||||
snapshot_date = values(snapshot_date),
|
||||
create_time = now()
|
||||
""", rows.stream().map(OrgRow::args).toList());
|
||||
""", rows.stream().map(row -> row.args(tenantId())).toList());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -437,7 +438,7 @@ public class AihrOrgSyncService {
|
||||
|
||||
private String orgSnapshotWhere(String keyword, String projectCode, String positionLevel, String status, List<Object> args) {
|
||||
StringBuilder where = new StringBuilder(" where tenant_id = ?");
|
||||
args.add(TENANT_ID);
|
||||
args.add(tenantId());
|
||||
String keywordValue = clean(keyword);
|
||||
if (!keywordValue.isBlank()) {
|
||||
String like = "%" + keywordValue + "%";
|
||||
@@ -486,7 +487,7 @@ public class AihrOrgSyncService {
|
||||
""", (rs, rowNum) -> new OrgProjectOption(
|
||||
rs.getString("project_code"),
|
||||
rs.getString("project_name")
|
||||
), TENANT_ID);
|
||||
), tenantId());
|
||||
}
|
||||
|
||||
private List<String> orgLevels() {
|
||||
@@ -496,7 +497,7 @@ public class AihrOrgSyncService {
|
||||
where tenant_id = ? and position_level is not null and position_level <> ''
|
||||
order by position_level
|
||||
limit 20
|
||||
""", (rs, rowNum) -> rs.getString("position_level"), TENANT_ID);
|
||||
""", (rs, rowNum) -> rs.getString("position_level"), tenantId());
|
||||
}
|
||||
|
||||
private void requireSnapshotTable() {
|
||||
@@ -715,11 +716,16 @@ public class AihrOrgSyncService {
|
||||
String employmentStatus,
|
||||
LocalDate snapshotDate
|
||||
) {
|
||||
Object[] args() {
|
||||
Object[] args(String tenantId) {
|
||||
return new Object[] {
|
||||
TENANT_ID, projectCode, projectName, deptName, extPartyId, personPhone, personName,
|
||||
tenantId, projectCode, projectName, deptName, extPartyId, personPhone, personName,
|
||||
positionName, positionLevel, employmentStatus, snapshotDate
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private String tenantId() {
|
||||
String tenantId = LoginHelper.getTenantId();
|
||||
return clean(tenantId).isBlank() ? TENANT_ID : tenantId.trim();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user