fix(aihr): scope dashboard metrics to tenant
This commit is contained in:
+16
-10
@@ -9,6 +9,7 @@ import org.dromara.aihr.domain.AihrDashboardDto.PipelineSummaryResponse;
|
||||
import org.dromara.aihr.domain.AihrDashboardDto.RiskResponse;
|
||||
import org.dromara.aihr.domain.AihrDashboardDto.StageResponse;
|
||||
import org.dromara.aihr.domain.AihrDashboardDto.TrainingRecordResponse;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -80,7 +81,7 @@ public class AihrDashboardService {
|
||||
if (!tableExists("aihr_interview_result")) {
|
||||
return new InterviewStats(0);
|
||||
}
|
||||
return new InterviewStats(count("SELECT COUNT(*) FROM aihr_interview_result WHERE tenant_id = ?", TENANT_ID));
|
||||
return new InterviewStats(count("SELECT COUNT(*) FROM aihr_interview_result WHERE tenant_id = ?", tenantId()));
|
||||
}
|
||||
|
||||
private List<RiskResponse> risks(PracticeStats practice, KnowledgeStats knowledge, CandidateStats candidate, ModelStats models) {
|
||||
@@ -113,7 +114,7 @@ public class AihrDashboardService {
|
||||
WHERE tenant_id = ? AND finished_time IS NOT NULL
|
||||
ORDER BY finished_time DESC, id DESC
|
||||
LIMIT 5
|
||||
""", this::trainingRecord, TENANT_ID);
|
||||
""", this::trainingRecord, tenantId());
|
||||
} catch (DataAccessException e) {
|
||||
return List.of();
|
||||
}
|
||||
@@ -143,7 +144,7 @@ public class AihrDashboardService {
|
||||
SUM(CASE WHEN DATE(finished_time) = CURRENT_DATE THEN 1 ELSE 0 END) today
|
||||
FROM aihr_practice_session
|
||||
WHERE tenant_id = ? AND finished_time IS NOT NULL
|
||||
""", (rs, rowNum) -> new PracticeStats(rs.getInt("total"), rs.getInt("pending_review"), rs.getInt("today")), TENANT_ID);
|
||||
""", (rs, rowNum) -> new PracticeStats(rs.getInt("total"), rs.getInt("pending_review"), rs.getInt("today")), tenantId());
|
||||
} catch (DataAccessException e) {
|
||||
return new PracticeStats(0, 0, 0);
|
||||
}
|
||||
@@ -154,9 +155,9 @@ public class AihrDashboardService {
|
||||
return new KnowledgeStats(0, 0, 0);
|
||||
}
|
||||
return new KnowledgeStats(
|
||||
count("SELECT COUNT(*) FROM aihr_knowledge_attach WHERE tenant_id = ?", TENANT_ID),
|
||||
count("SELECT COUNT(*) FROM aihr_knowledge_attach WHERE tenant_id = ? AND status = 2", TENANT_ID),
|
||||
count("SELECT COUNT(*) FROM aihr_knowledge_fragment WHERE tenant_id = ?", TENANT_ID)
|
||||
count("SELECT COUNT(*) FROM aihr_knowledge_attach WHERE tenant_id = ?", tenantId()),
|
||||
count("SELECT COUNT(*) FROM aihr_knowledge_attach WHERE tenant_id = ? AND status = 2", tenantId()),
|
||||
count("SELECT COUNT(*) FROM aihr_knowledge_fragment WHERE tenant_id = ?", tenantId())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -179,7 +180,7 @@ public class AihrDashboardService {
|
||||
rs.getInt("organized"),
|
||||
rs.getInt("stored"),
|
||||
rs.getInt("today_new")
|
||||
), TENANT_ID);
|
||||
), tenantId());
|
||||
} catch (DataAccessException e) {
|
||||
return new CaseStats(0, 0, 0, 0, 0);
|
||||
}
|
||||
@@ -195,7 +196,7 @@ public class AihrDashboardService {
|
||||
SUM(CASE WHEN status = '待审核' THEN 1 ELSE 0 END) pending
|
||||
FROM aihr_candidate_material
|
||||
WHERE tenant_id = ?
|
||||
""", (rs, rowNum) -> new CandidateStats(rs.getInt("total"), rs.getInt("pending")), TENANT_ID);
|
||||
""", (rs, rowNum) -> new CandidateStats(rs.getInt("total"), rs.getInt("pending")), tenantId());
|
||||
} catch (DataAccessException e) {
|
||||
return new CandidateStats(0, 0);
|
||||
}
|
||||
@@ -209,7 +210,7 @@ public class AihrDashboardService {
|
||||
SELECT COUNT(*)
|
||||
FROM aihr_org_snapshot
|
||||
WHERE tenant_id = ? AND employment_status = 'active'
|
||||
""", TENANT_ID));
|
||||
""", tenantId()));
|
||||
}
|
||||
|
||||
private ModelStats modelStats() {
|
||||
@@ -220,7 +221,7 @@ public class AihrDashboardService {
|
||||
SELECT COUNT(*)
|
||||
FROM aihr_model_config
|
||||
WHERE tenant_id = ? AND category = 'asr' AND enabled = 1
|
||||
""", TENANT_ID) > 0);
|
||||
""", tenantId()) > 0);
|
||||
}
|
||||
|
||||
private boolean tableExists(String tableName) {
|
||||
@@ -245,6 +246,11 @@ public class AihrDashboardService {
|
||||
}
|
||||
}
|
||||
|
||||
private String tenantId() {
|
||||
String tenantId = LoginHelper.getTenantId();
|
||||
return tenantId == null || tenantId.isBlank() ? TENANT_ID : tenantId;
|
||||
}
|
||||
|
||||
private static String statusState(String status, int score) {
|
||||
if (score > 0 && score < 70) {
|
||||
return "danger";
|
||||
|
||||
Reference in New Issue
Block a user