Untitled
unknown
java
10 months ago
2.0 kB
17
Indexable
package com.insuretech.claims.fraud;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.util.Map;
@Service
public class FraudDetectionService {
@Autowired
private WebClient webClient; // Configured for SageMaker endpoint
@Cacheable(value = "fraudScores", key = "#claimId") // Redis-backed cache for optimization
public Mono<Double> scoreClaimFraud(String claimId, Map<String, Object> claimData) {
// Enrich with features: e.g., claim amount, location anomaly, telematics velocity
Map<String, Object> features = enrichFeatures(claimData);
// Reactive call to ML model (non-blocking for high throughput)
return webClient.post()
.uri("/predict") // SageMaker endpoint
.bodyValue(features)
.retrieve()
.bodyToMono(Double.class)
.doOnNext(score -> {
if (score > 0.8) { // Threshold for high-risk
// Trigger alert via SNS (async)
publishAlert(claimId, score);
}
})
.onErrorReturn(0.0); // Fallback for resilience
}
private Map<String, Object> enrichFeatures(Map<String, Object> claimData) {
// Simulate anomaly detection: e.g., velocity check
Double amount = (Double) claimData.get("amount");
String location = (String) claimData.get("location");
double anomalyScore = (amount > 10000 && "high-risk-area".equals(location)) ? 0.5 : 0.0;
claimData.put("anomalyBase", anomalyScore);
return claimData;
}
private void publishAlert(String claimId, Double score) {
// Async publish to SNS for notifications (decoupled)
// Implementation omitted for brevity
}
}Editor is loading...
Leave a Comment