fix(aihr): fail safe on mobile identity lookup
This commit is contained in:
+13
-5
@@ -5,6 +5,7 @@ import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.aihr.domain.AihrPracticeDto.AnnotationResponse;
|
||||
import org.dromara.aihr.domain.AihrPracticeDto.CompetencyResponse;
|
||||
import org.dromara.aihr.domain.AihrPracticeDto.DailyDrillAnswerRequest;
|
||||
@@ -20,6 +21,7 @@ import org.dromara.aihr.domain.AihrPracticeDto.ReviewAdviceRequest;
|
||||
import org.dromara.aihr.domain.AihrPracticeDto.ReviewDetailResponse;
|
||||
import org.dromara.aihr.domain.AihrPracticeDto.SatisfactionRequest;
|
||||
import org.dromara.aihr.domain.AihrPracticeDto.SatisfactionResponse;
|
||||
import org.dromara.aihr.domain.AihrOrgSyncDto.OrgPersonRow;
|
||||
import org.dromara.aihr.domain.vo.AihrMobileDto.HomeResponse;
|
||||
import org.dromara.aihr.domain.vo.AihrMobileDto.IdentityResponse;
|
||||
import org.dromara.aihr.service.AihrOrgSyncService;
|
||||
@@ -48,6 +50,7 @@ import java.util.Map;
|
||||
* Mobile H5 home APIs.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/aihr/mobile")
|
||||
@SaCheckLogin
|
||||
@@ -73,11 +76,16 @@ public class AihrMobileController {
|
||||
if (phone.isBlank()) {
|
||||
return R.ok(new IdentityResponse("user", "员工端", "", "一线"));
|
||||
}
|
||||
var snapshot = orgSyncService.snapshot(phone, null, null, "active", 1, 500, 500);
|
||||
var row = snapshot.rows().stream()
|
||||
.filter(person -> "主管".equals(person.positionLevel()) || "项目经理".equals(person.positionLevel()))
|
||||
.findFirst()
|
||||
.or(() -> snapshot.rows().stream().findFirst());
|
||||
var row = java.util.Optional.<OrgPersonRow>empty();
|
||||
try {
|
||||
var snapshot = orgSyncService.snapshot(phone, null, null, "active", 1, 500, 500);
|
||||
row = snapshot.rows().stream()
|
||||
.filter(person -> "主管".equals(person.positionLevel()) || "项目经理".equals(person.positionLevel()))
|
||||
.findFirst()
|
||||
.or(() -> snapshot.rows().stream().findFirst());
|
||||
} catch (RuntimeException ex) {
|
||||
log.warn("mobile identity lookup failed, fallback to employee role(处理错误已隐藏)");
|
||||
}
|
||||
if (row.isEmpty()) {
|
||||
return R.ok(new IdentityResponse("user", "员工端", "", "一线"));
|
||||
}
|
||||
|
||||
+2
@@ -395,6 +395,8 @@ public class AihrPracticeSeedServiceTest {
|
||||
assertTrue(controllerSource.contains("mobileSeedService.practiceAlerts(supervisorScopeExtPartyId())"));
|
||||
assertTrue(controllerSource.contains("mobileSeedService.createPracticeAssignment(request, supervisorScopeExtPartyId())"));
|
||||
assertTrue(controllerSource.contains("orgSyncService.snapshot(phone, null, null, \"active\", 1, 500, 500)"));
|
||||
assertTrue(controllerSource.contains("mobile identity lookup failed, fallback to employee role"));
|
||||
assertTrue(controllerSource.contains("catch (RuntimeException ex)"));
|
||||
assertTrue(controllerSource.contains("private String supervisorScopeExtPartyId()"));
|
||||
assertTrue(controllerSource.contains("mobileSeedService.requireSupervisorIdentity(currentAppUsername())"));
|
||||
assertTrue(controllerSource.contains("@SaCheckLogin\npublic class AihrMobileController"));
|
||||
|
||||
Reference in New Issue
Block a user