package com.ruoyi.im.util;
|
|
import com.ruoyi.system.domain.UserPolicy;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
public class UserPolicyUtils {
|
|
|
/**
|
* 查询指定用户是否有生效保单
|
* @param userPolicyList 保单列表
|
* @param userId 用户ID
|
* @return 是否有生效保单
|
*/
|
public static Boolean hasActivePolicyForUser(List<UserPolicy> userPolicyList, Integer userId) {
|
if (userPolicyList == null || userPolicyList.isEmpty() || userId == null) {
|
return false;
|
}
|
|
return userPolicyList.stream()
|
.filter(policy -> policy != null &&
|
policy.getUserId() != null &&
|
policy.getPolicyStatus() != null)
|
.filter(policy -> userId.equals(policy.getUserId()))
|
.anyMatch(policy -> UserPolicy.PolicyStatus.ACTIVE.equals(policy.getPolicyStatus()));
|
}
|
|
/**
|
* 统计生效保单数量
|
* @param userPolicyList 保单列表
|
* @return 生效保单数量
|
*/
|
public static long countActivePolicies(List<UserPolicy> userPolicyList) {
|
if (userPolicyList == null || userPolicyList.isEmpty()) {
|
return 0L;
|
}
|
|
return userPolicyList.stream()
|
.filter(policy -> policy != null && policy.getPolicyStatus() != null)
|
.filter(policy -> UserPolicy.PolicyStatus.ACTIVE.equals(policy.getPolicyStatus()))
|
.count();
|
}
|
|
/**
|
* 获取所有生效保单列表
|
* @param userPolicyList 保单列表
|
* @return 生效保单列表
|
*/
|
public static List<UserPolicy> getActivePolicies(List<UserPolicy> userPolicyList) {
|
if (userPolicyList == null || userPolicyList.isEmpty()) {
|
return new ArrayList<>();
|
}
|
|
return userPolicyList.stream()
|
.filter(policy -> policy != null && policy.getPolicyStatus() != null)
|
.filter(policy -> UserPolicy.PolicyStatus.ACTIVE.equals(policy.getPolicyStatus()))
|
.collect(Collectors.toList());
|
}
|
|
/**
|
* 统计各种状态的保单数量
|
* @param userPolicyList 保单列表
|
* @return 包含各种状态数量的Map
|
*/
|
public static Map<UserPolicy.PolicyStatus, Long> countPoliciesByStatus(List<UserPolicy> userPolicyList) {
|
if (userPolicyList == null || userPolicyList.isEmpty()) {
|
return new HashMap<>();
|
}
|
|
return userPolicyList.stream()
|
.filter(policy -> policy != null && policy.getPolicyStatus() != null)
|
.collect(Collectors.groupingBy(
|
UserPolicy::getPolicyStatus,
|
Collectors.counting()
|
));
|
}
|
|
/**
|
* 检查用户是否有生效保单
|
* @param userPolicyList 用户保单列表
|
* @return 是否有生效保单
|
*/
|
public static boolean hasActivePolicy(List<UserPolicy> userPolicyList) {
|
if (userPolicyList == null || userPolicyList.isEmpty()) {
|
return false;
|
}
|
|
return userPolicyList.stream()
|
.anyMatch(policy -> policy != null &&
|
policy.getPolicyStatus() != null &&
|
UserPolicy.PolicyStatus.ACTIVE.equals(policy.getPolicyStatus()));
|
}
|
|
/**
|
* 统计用户生效保单的总保额
|
* @param userPolicyList 用户保单列表
|
* @return 总保额
|
*/
|
public static BigDecimal sumActivePolicyCoverage(List<UserPolicy> userPolicyList) {
|
if (userPolicyList == null || userPolicyList.isEmpty()) {
|
return BigDecimal.ZERO;
|
}
|
|
return userPolicyList.stream()
|
.filter(policy -> policy != null &&
|
policy.getPolicyStatus() != null &&
|
UserPolicy.PolicyStatus.ACTIVE.equals(policy.getPolicyStatus()) &&
|
policy.getCoverageAmount() != null)
|
.map(UserPolicy::getCoverageAmount)
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
}
|
}
|