Commit 1ae5b46c by zhouhaibao

feat(strategy): 添加ROP接口参数支持并优化枚举值获取

- 在SopEnumDataSourceService中新增ropApiParams参数用于ROP接口调用
- 修改fetchEnumValuesFromRop方法支持传入参数进行数据解析
- 将JSON解析方式从parseArray改为parseObject以支持动态字段提取
- 在SopStrategyMetaConditionVariable实体类中添加ropApiResParam字段
- 更新数据库映射文件支持新字段的持久化操作
- 在StrategySopQueryService中传递ROP响应参数给枚举值获取服务
1 parent 8ad58348
...@@ -81,4 +81,9 @@ public class SopStrategyMetaConditionVariable { ...@@ -81,4 +81,9 @@ public class SopStrategyMetaConditionVariable {
@Column(name = "updated_date") @Column(name = "updated_date")
@ApiModelProperty(value = "更新时间") @ApiModelProperty(value = "更新时间")
private Date updatedDate; private Date updatedDate;
@Column(name = "rop_api_res_param")
private String ropApiResParam;
} }
\ No newline at end of file \ No newline at end of file
...@@ -37,10 +37,12 @@ public class SopEnumDataSourceService { ...@@ -37,10 +37,12 @@ public class SopEnumDataSourceService {
* @param variableCode 变量编码 * @param variableCode 变量编码
* @param enumDataSource 枚举数据来源 * @param enumDataSource 枚举数据来源
* @param ropApiMethod ROP接口方法名 * @param ropApiMethod ROP接口方法名
* @param ropApiParams ROP接口参数
*
* @return 枚举值DTO列表 * @return 枚举值DTO列表
*/ */
@Cacheable(value = "enumValues", key = "#variableCode") @Cacheable(value = "enumValues", key = "#variableCode")
public List<SopEnumValueDTO> getEnumValues(String variableCode, String enumDataSource, String ropApiMethod) { public List<SopEnumValueDTO> getEnumValues(String variableCode, String enumDataSource, String ropApiMethod,String ropApiParams) {
log.info("获取枚举值, variableCode:{}, enumDataSource:{}, ropApiMethod:{}", variableCode, enumDataSource, ropApiMethod); log.info("获取枚举值, variableCode:{}, enumDataSource:{}, ropApiMethod:{}", variableCode, enumDataSource, ropApiMethod);
if (StrUtil.equals(FIXED_DATA_SOURCE, enumDataSource)) { if (StrUtil.equals(FIXED_DATA_SOURCE, enumDataSource)) {
...@@ -53,17 +55,17 @@ public class SopEnumDataSourceService { ...@@ -53,17 +55,17 @@ public class SopEnumDataSourceService {
return new ArrayList<>(); return new ArrayList<>();
} }
return fetchEnumValuesFromRop(ropApiMethod); return fetchEnumValuesFromRop(ropApiMethod, ropApiParams);
} }
/** /**
* 从ROP接口获取枚举值 * 从ROP接口获取枚举值 若调用失败,使用模拟数据作为降级方案
* 若调用失败,使用模拟数据作为降级方案
* *
* @param ropApiMethod ROP接口方法名 * @param ropApiMethod ROP接口方法名
* @param ropApiParams
* @return 枚举值DTO列表 * @return 枚举值DTO列表
*/ */
private List<SopEnumValueDTO> fetchEnumValuesFromRop(String ropApiMethod) { private List<SopEnumValueDTO> fetchEnumValuesFromRop(String ropApiMethod, String ropApiParams) {
List<SopEnumValueDTO> enumValues = new ArrayList<>(); List<SopEnumValueDTO> enumValues = new ArrayList<>();
try { try {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
...@@ -72,7 +74,11 @@ public class SopEnumDataSourceService { ...@@ -72,7 +74,11 @@ public class SopEnumDataSourceService {
if (ropResponse != null && "0".equals(ropResponse.getCode())) { if (ropResponse != null && "0".equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue); String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
List<Map> dataList = JSONObject.parseArray(data, Map.class); // 【修改点】:将 parseArray 改为 parseObject,解析为 JSONObject
JSONObject jsonObject = JSONObject.parseObject(data);
// 【修改点】:从对象中获取 "enums" 对应的数组,并转换为 List<Map>
List<Map> dataList = jsonObject.getJSONArray(ropApiParams).toJavaList(Map.class);
enumValues = parseRopResponseData(dataList); enumValues = parseRopResponseData(dataList);
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -322,7 +322,9 @@ public class StrategySopQueryService { ...@@ -322,7 +322,9 @@ public class StrategySopQueryService {
List<SopEnumValueDTO> ropEnumValues = sopEnumDataSourceService.getEnumValues( List<SopEnumValueDTO> ropEnumValues = sopEnumDataSourceService.getEnumValues(
variable.getVariableCode(), variable.getVariableCode(),
variable.getEnumDataSource(), variable.getEnumDataSource(),
variable.getRopApiMethod()); variable.getRopApiMethod(),
variable.getRopApiResParam()
);
if (CollUtil.isNotEmpty(ropEnumValues)) { if (CollUtil.isNotEmpty(ropEnumValues)) {
return ropEnumValues; return ropEnumValues;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<result column="sql_fragment" property="sqlFragment"/> <result column="sql_fragment" property="sqlFragment"/>
<result column="enum_data_source" property="enumDataSource"/> <result column="enum_data_source" property="enumDataSource"/>
<result column="rop_api_method" property="ropApiMethod"/> <result column="rop_api_method" property="ropApiMethod"/>
<result column="rop_api_res_param" property="ropApiResParam"/>
<result column="sort_order" property="sortOrder"/> <result column="sort_order" property="sortOrder"/>
<result column="status" property="status"/> <result column="status" property="status"/>
<result column="deleted_flag" property="deletedFlag"/> <result column="deleted_flag" property="deletedFlag"/>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!