|
|
@@ -438,6 +438,32 @@ public class PtlSchemeServiceImpl extends ServiceImpl<PtlSchemeMapper, PtlScheme
|
|
|
// 3. 关联账号必须可用 (useStatus == "0") 且可报价 (quoteStatus == "0")
|
|
|
// 过滤后如果某保司没有任何有效协议,会被下面的 removeIf 自动排除
|
|
|
if (CollUtil.isNotEmpty(companyList)) {
|
|
|
+ // 1. 收集所有需要校验的归属账号 id(去重)
|
|
|
+ List<String> attributionIds = companyList.stream()
|
|
|
+ .flatMap(c -> Optional.ofNullable(c.getAgreements()).orElse(Collections.emptyList()).stream())
|
|
|
+ .map(PtlAgreement::getAttributionId)
|
|
|
+ .filter(StrUtil::isNotBlank)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 2. 并行批量查询归属账号,构建 id -> 账号信息 索引(避免逐协议串行 RPC)
|
|
|
+ Map<String, PtlAgreementAttribution> attributionMap;
|
|
|
+ if (CollUtil.isNotEmpty(attributionIds)) {
|
|
|
+ attributionMap = attributionIds.parallelStream().collect(HashMap::new, (map, id) -> {
|
|
|
+ try {
|
|
|
+ HttpResult<PtlAgreementAttribution> res = platformClient.getAgreementAttribution2(id);
|
|
|
+ if (res.getCode() == 200 && res.getData() != null) {
|
|
|
+ map.put(id, res.getData());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("批量查询协议归属账号[{}]异常,默认保留", id, e);
|
|
|
+ }
|
|
|
+ }, HashMap::putAll);
|
|
|
+ } else {
|
|
|
+ attributionMap = Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 基于索引做协议 + 账号状态过滤(无远程调用)
|
|
|
for (EsmInsCompany company : companyList) {
|
|
|
List<PtlAgreement> agreements = company.getAgreements();
|
|
|
if (CollUtil.isEmpty(agreements)) {
|
|
|
@@ -450,21 +476,14 @@ public class PtlSchemeServiceImpl extends ServiceImpl<PtlSchemeMapper, PtlScheme
|
|
|
// 归属账号状态
|
|
|
.filter(agreement -> {
|
|
|
String attributionId = agreement.getAttributionId();
|
|
|
- if (attributionId == null || attributionId.isEmpty()) {
|
|
|
+ if (StrUtil.isBlank(attributionId)) {
|
|
|
return true; // 没有关联账号,不做账号校验
|
|
|
}
|
|
|
- try {
|
|
|
- com.jzg.commons.core.page.HttpResult<PtlAgreementAttribution> res =
|
|
|
- platformClient.getAgreementAttribution2(attributionId);
|
|
|
- if (res.getCode() != 200 || res.getData() == null) {
|
|
|
- return true; // 查不到账号信息,默认保留
|
|
|
- }
|
|
|
- PtlAgreementAttribution attr = res.getData();
|
|
|
- return "0".equals(attr.getUseStatus()) && "0".equals(attr.getQuoteStatus());
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("查询协议[{}]的归属账号异常,默认保留", agreement.getId(), e);
|
|
|
- return true;
|
|
|
+ PtlAgreementAttribution attr = attributionMap.get(attributionId);
|
|
|
+ if (attr == null) {
|
|
|
+ return true; // 查不到账号信息,默认保留
|
|
|
}
|
|
|
+ return "0".equals(attr.getUseStatus()) && "0".equals(attr.getQuoteStatus());
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
company.setAgreements(validAgreements);
|
|
|
@@ -498,21 +517,22 @@ public class PtlSchemeServiceImpl extends ServiceImpl<PtlSchemeMapper, PtlScheme
|
|
|
|
|
|
List<PtlSchemeRulesAttrLink> ptlSchemeRulesAttrLinks = ptlSchemeRulesAttrLinkMapper.selectList(new LambdaQueryWrapper<PtlSchemeRulesAttrLink>().in(PtlSchemeRulesAttrLink::getSchemeId, ptlSchemeIds));
|
|
|
|
|
|
- // 将规则根据schemeId聚合转换成Map
|
|
|
-// Map<String, List<PtlSchemeRulesAttrLink>> ptlSchemeRulesAttrLinkMap = ptlSchemeRulesAttrLinks.stream()
|
|
|
-// .collect(Collectors.groupingBy(PtlSchemeRulesAttrLink::getSchemeId));
|
|
|
-
|
|
|
ValidateSchemeRuleVo validateSchemeRuleVo = new ValidateSchemeRuleVo();
|
|
|
validateSchemeRuleVo.builderQuoteVo(schemeRuleFilterVo, redissonClient);
|
|
|
validateSchemeRuleVo.setAttrLinks(ptlSchemeRulesAttrLinks);
|
|
|
HttpResult<List<String>> esmInsCompanyHttpResult = costsRuleClient.validateSchemeRule(validateSchemeRuleVo);
|
|
|
List<String> insSchemeIds = esmInsCompanyHttpResult.getData();
|
|
|
+ if (CollUtil.isEmpty(insSchemeIds)) {
|
|
|
+ AssertionUtils.isFail(true, "没有可报价的保险公司");
|
|
|
+ }
|
|
|
+ // 用 HashSet 提升 contains 查找效率(O(1))
|
|
|
+ Set<String> insSchemeIdSet = new HashSet<>(insSchemeIds);
|
|
|
//开始过滤保险公司
|
|
|
//1.过滤方案
|
|
|
- ptlSchemes.removeIf(ptlScheme -> !insSchemeIds.contains(ptlScheme.getId()));
|
|
|
- List<String> companyIds = ptlSchemes.stream().map(ptlScheme -> ptlScheme.getCompanyId()).collect(Collectors.toList());
|
|
|
+ ptlSchemes.removeIf(ptlScheme -> !insSchemeIdSet.contains(ptlScheme.getId()));
|
|
|
+ Set<String> companyIdSet = ptlSchemes.stream().map(PtlScheme::getCompanyId).collect(Collectors.toSet());
|
|
|
// 移除不匹配方案的保司,以及空协议的保司
|
|
|
- companyList.removeIf(company -> !companyIds.contains(company.getId()) || CollUtil.isEmpty(company.getAgreements()));
|
|
|
+ companyList.removeIf(company -> !companyIdSet.contains(company.getId()) || CollUtil.isEmpty(company.getAgreements()));
|
|
|
List<PtlAgreementInsCompanyVo> resVo = new ArrayList<>();
|
|
|
companyList.forEach(company -> {
|
|
|
PtlAgreementInsCompanyVo vo = new PtlAgreementInsCompanyVo();
|
|
|
@@ -524,28 +544,14 @@ public class PtlSchemeServiceImpl extends ServiceImpl<PtlSchemeMapper, PtlScheme
|
|
|
|
|
|
ValidateDispatchRuleVo dispatchRuleVos = new ValidateDispatchRuleVo();
|
|
|
dispatchRuleVos.setQuoteVo(validateSchemeRuleVo.getQuoteVo());
|
|
|
- //2.协议调度规则数据拼接
|
|
|
- String finalSystemCode = systemCode;
|
|
|
- companyList.forEach(company -> {
|
|
|
- PtlAgreementDispatchQuery query = new PtlAgreementDispatchQuery();
|
|
|
- query.setCompanyId(company.getId());
|
|
|
- HttpResult agreementDispatch = orgClient.getAgreementDispatch(query);
|
|
|
- if (agreementDispatch.getCode() == 200) {
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- List<PtlAgreementDispatchVo.DispatchVo> vos = new ArrayList<>();
|
|
|
- Map<String, Object> data = (Map<String, Object>) agreementDispatch.getData();
|
|
|
-
|
|
|
- Object dispatchVosObj = data.get("dispatchVos");
|
|
|
- if (dispatchVosObj instanceof List) {
|
|
|
- List<Map<String, Object>> dispatchVos = (List<Map<String, Object>>) dispatchVosObj;
|
|
|
- for (Map<String, Object> map : dispatchVos) {
|
|
|
- PtlAgreementDispatchVo.DispatchVo obj = mapper.convertValue(map, PtlAgreementDispatchVo.DispatchVo.class);
|
|
|
- vos.add(obj);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 根据section 分组 进行拆分 规则
|
|
|
- for (PtlAgreementDispatchVo.DispatchVo vo : vos) {
|
|
|
+ //2.协议调度规则数据拼接(一次批量查询所有保司,避免逐保司重复的全表/字典查询与串行 RPC)
|
|
|
+ List<String> allCompanyIds = companyList.stream().map(EsmInsCompany::getId).collect(Collectors.toList());
|
|
|
+ try {
|
|
|
+ HttpResult agreementDispatch = orgClient.getAgreementDispatchByCompanyIds(allCompanyIds);
|
|
|
+ if (agreementDispatch != null && agreementDispatch.getCode() == 200 && agreementDispatch.getData() != null) {
|
|
|
+ PtlAgreementDispatchVo dispatchVoResult = new ObjectMapper().convertValue(agreementDispatch.getData(), PtlAgreementDispatchVo.class);
|
|
|
+ List<ValidateDispatchRuleVo.DispatchAttrVo> dispatchAttrVos = new ArrayList<>();
|
|
|
+ for (PtlAgreementDispatchVo.DispatchVo vo : dispatchVoResult.getDispatchVos()) {
|
|
|
List<PtlAgreementDispatchRulesAttrLink> attrLinks = vo.getAttrLinks();
|
|
|
Map<String, List<PtlAgreementDispatchRulesAttrLink>> grouped = attrLinks.stream().collect(Collectors.groupingBy(link -> Optional.ofNullable(link.getSection()).orElse("0"), LinkedHashMap::new, Collectors.toList()));
|
|
|
ValidateDispatchRuleVo.DispatchAttrVo dispatchAttrVo = new ValidateDispatchRuleVo.DispatchAttrVo();
|
|
|
@@ -553,20 +559,36 @@ public class PtlSchemeServiceImpl extends ServiceImpl<PtlSchemeMapper, PtlScheme
|
|
|
dispatchAttrVo.setDispatchName(vo.getDispatchName());
|
|
|
dispatchAttrVo.setCompanyId(vo.getCompanyId());
|
|
|
dispatchAttrVo.setSectionGroups(grouped);
|
|
|
- dispatchRuleVos.getDispatchAttrVos().add(dispatchAttrVo);
|
|
|
+ dispatchAttrVos.add(dispatchAttrVo);
|
|
|
}
|
|
|
+ dispatchRuleVos.getDispatchAttrVos().addAll(dispatchAttrVos);
|
|
|
}
|
|
|
- });
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("批量查询协议调度异常", e);
|
|
|
+ }
|
|
|
//
|
|
|
// 3. 校验调度数据
|
|
|
HttpResult httpResult = costsRuleClient.validateDispatchRule(dispatchRuleVos);
|
|
|
if (httpResult.getCode() == 200) {
|
|
|
// 返回了调度id 通过调度id 查询动作
|
|
|
List<PtlAgreementDispatchVo.DispatchVo> agreementDispatchAction = ptlAgreementDispatchService.getAgreementDispatchAction((List<String>) httpResult.getData());
|
|
|
+ // 构建 保司id -> DispatchVo 索引(companyId 可能为逗号分隔的多保司)
|
|
|
+ Map<String, PtlAgreementDispatchVo.DispatchVo> dispatchByCompany = new HashMap<>();
|
|
|
+ for (PtlAgreementDispatchVo.DispatchVo dispatch : agreementDispatchAction) {
|
|
|
+ if (dispatch.getCompanyId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (String cid : dispatch.getCompanyId().split(",")) {
|
|
|
+ String trimCid = cid.trim();
|
|
|
+ if (!trimCid.isEmpty()) {
|
|
|
+ dispatchByCompany.put(trimCid, dispatch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
// 如果动作中存在替换协议则 保司标志置为调度
|
|
|
resVo.forEach(company -> {
|
|
|
company.setIsDispatch(0);
|
|
|
- PtlAgreementDispatchVo.DispatchVo ptlAgreementDispatchVo = agreementDispatchAction.stream().filter(x -> x.getCompanyId().contains(company.getId())).findFirst().orElse(null);
|
|
|
+ PtlAgreementDispatchVo.DispatchVo ptlAgreementDispatchVo = dispatchByCompany.get(company.getId());
|
|
|
if (ptlAgreementDispatchVo != null) {
|
|
|
PtlAgreementDispatchAction action1 = ptlAgreementDispatchVo.getActions().stream().filter(action -> action.getActionCode().equals(ActionEnum.SPECIFY_AGREEMENT.getCode())).findFirst().orElse(null);
|
|
|
if (action1 != null) {
|