|
|
@@ -92,44 +92,16 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
*/
|
|
|
private List<Parameter> generateParameters(@NotEmpty("panelInstance") PanelInstance panelInstance) {
|
|
|
String panelCode = userPanelRelationDao.checkExist(panelInstance.getUserPanelRelationCode()).getPanelCode();
|
|
|
- Panel panel = panelDao.checkExist(panelCode);
|
|
|
- String dataSourceCode = panel.getDataSourceCode();
|
|
|
List<Parameter> parameters = parameterService.getByPanelCode(panelCode);
|
|
|
if (CollectionUtils.isEmpty(parameters)) {
|
|
|
return null;
|
|
|
}
|
|
|
for (Parameter parameter : parameters) {
|
|
|
parameter.mayInitValue();
|
|
|
- // 如果是 SQL 类型,需要解析参数
|
|
|
- if (parameter.getType() == Type.SQL) {
|
|
|
- try {
|
|
|
- NewbieJdbcSupport jdbc = dataSourceManager.getJdbc(dataSourceCode);
|
|
|
- parameter.setValue(getValue(jdbc, String.valueOf(parameter.getValue())));
|
|
|
- // 并且需要解析 optionalValues 里可选择的值
|
|
|
- List<Object> optionalValues = parameter.getOptionalValues();
|
|
|
- if (!CollectionUtils.isEmpty(optionalValues)) {
|
|
|
- for (int i = 0; i < optionalValues.size(); i++) {
|
|
|
- Object optionValue = optionalValues.get(i);
|
|
|
- optionalValues.set(i, getValue(jdbc, String.valueOf(optionValue)));
|
|
|
- }
|
|
|
- parameter.setOptionalValues(optionalValues);
|
|
|
- }
|
|
|
- } catch (SQLException e) {
|
|
|
- throw new IllegalStateException("参数解析错误", e);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
return parameters;
|
|
|
}
|
|
|
|
|
|
- private String getValue(@NotEmpty("jdbc") NewbieJdbcSupport jdbc, @NotEmpty("sql") String sql) {
|
|
|
- List<Map<String, Object>> listMap = jdbc.listMap(sql);
|
|
|
- if (listMap == null) {
|
|
|
- listMap = new ArrayList<>();
|
|
|
- }
|
|
|
- return JSONObject.toJSONString(listMap);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 比较参数数量、名称等是否一致
|
|
|
*
|