Commit f9f9cb73 by jianan

前端对接问题修复25

parent e60a1dbc
...@@ -2,6 +2,8 @@ package com.yd.csf.service.service.impl; ...@@ -2,6 +2,8 @@ package com.yd.csf.service.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.TypeReference; import cn.hutool.core.lang.TypeReference;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
...@@ -189,30 +191,60 @@ public class PolicyServiceImpl extends ServiceImpl<PolicyMapper, Policy> ...@@ -189,30 +191,60 @@ public class PolicyServiceImpl extends ServiceImpl<PolicyMapper, Policy>
return CollUtil.newArrayList(); return CollUtil.newArrayList();
} }
// 使用JSON工具手动转换 // 直接使用Map来处理数据,避免复杂的类型转换
String jsonData = JSONUtil.toJsonStr(result.getData()); Object data = result.getData();
IPage<ApiRelProjectProductLaunchPageResponse> pageData = JSONUtil.toBean(jsonData, new TypeReference<IPage<ApiRelProjectProductLaunchPageResponse>>() {}, false); List<Map<String, Object>> policyProductInfoList = new ArrayList<>();
if (ObjectUtils.isEmpty(pageData.getRecords())) { try {
return CollUtil.newArrayList(); // 将数据转换为JSONObject进行解析
} JSONObject jsonObject = JSONUtil.parseObj(data);
List<ApiRelProjectProductLaunchPageResponse> productLaunchPageResponseList = pageData.getRecords();
// 获取records数组
JSONArray recordsArray = jsonObject.getJSONArray("records");
if (recordsArray != null) {
for (int i = 0; i < recordsArray.size(); i++) {
JSONObject record = recordsArray.getJSONObject(i);
List<Map<String, Object>> policyProductInfoList = CollUtil.newArrayList();
for (ApiRelProjectProductLaunchPageResponse response : productLaunchPageResponseList) {
log.info("ApiRelProjectProductLaunchPageResponse:{}", JSONUtil.toJsonStr(response));
List<ApiAttributeSettingDto> apiAttributeSettingDtoList = response.getApiAttributeSettingDtoList();
Map<String, Object> infoMap = new HashMap<>(); Map<String, Object> infoMap = new HashMap<>();
infoMap.put("productLaunchBizId", response.getProductLaunchBizId()); infoMap.put("productLaunchBizId", record.getStr("productLaunchBizId"));
infoMap.put("productName", response.getProductName()); infoMap.put("productName", record.getStr("productName"));
// 解析自定义属性 // 解析自定义属性
getInfo(apiAttributeSettingDtoList, infoMap); JSONArray attributeSettingArray = record.getJSONArray("apiAttributeSettingDtoList");
if (attributeSettingArray != null) {
getInfoFromJsonArray(attributeSettingArray, infoMap);
}
policyProductInfoList.add(infoMap); policyProductInfoList.add(infoMap);
} }
}
} catch (Exception e) {
log.error("解析Feign返回数据失败: {}", e.getMessage(), e);
return CollUtil.newArrayList();
}
return policyProductInfoList; return policyProductInfoList;
} }
/** /**
* 从JSON数组中解析自定义属性
*/
private void getInfoFromJsonArray(JSONArray attributeSettingArray, Map<String, Object> infoMap) {
if (attributeSettingArray == null || attributeSettingArray.isEmpty()) {
return;
}
for (int i = 0; i < attributeSettingArray.size(); i++) {
JSONObject attribute = attributeSettingArray.getJSONObject(i);
// 根据实际字段名设置属性
// infoMap.put("insuranceCompanyBizId", attribute.getStr("fieldName"));
// infoMap.put("insuranceCompany", attribute.getStr("fieldName"));
// infoMap.put("reconciliationCompanyBizId", attribute.getStr("fieldName"));
// infoMap.put("reconciliationCompany", attribute.getStr("fieldName"));
}
}
/**
* 从附加险列表中获取保险公司业务ID * 从附加险列表中获取保险公司业务ID
* *
* @param apiAttributeSettingDtoList * @param apiAttributeSettingDtoList
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment