|
|
@@ -19,6 +19,8 @@ import com.uas.kanban.util.ObjectUtils;
|
|
|
import com.uas.kanban.util.StringUtils;
|
|
|
import me.chyxion.jdbc.NewbieJdbcSupport;
|
|
|
import org.dom4j.DocumentException;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -58,6 +60,8 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
@Autowired
|
|
|
private KanbanParser kanbanParser;
|
|
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
@Override
|
|
|
public int update(@NotEmpty("json") String json) throws IllegalArgumentException, OperationException {
|
|
|
PanelInstance panelInstance = panelInstanceDao.parse(json);
|
|
|
@@ -108,16 +112,17 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
// 如果是 SQL 类型,需要解析参数
|
|
|
if (parameter.getType() == Type.SQL && parseSQLParameter) {
|
|
|
try {
|
|
|
- NewbieJdbcSupport jdbc = dataSourceManager.getJdbc(dataSourceCode);
|
|
|
- parameter.setValue(getValue(jdbc, String.valueOf(parameter.getValue())));
|
|
|
- // 并且需要解析 optionalValues 里可选择的值
|
|
|
+ // 需要解析 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)));
|
|
|
+ if (optionalValues.size() > 1) {
|
|
|
+ throw new IllegalArgumentException("SQL 类型的参数多于一个");
|
|
|
}
|
|
|
+ NewbieJdbcSupport jdbc = dataSourceManager.getJdbc(dataSourceCode);
|
|
|
+ Object optionValue = optionalValues.get(0);
|
|
|
+ optionalValues = getValue(jdbc, String.valueOf(optionValue));
|
|
|
parameter.setOptionalValues(optionalValues);
|
|
|
+ parameter.setValue(CollectionUtils.isEmpty(optionalValues) ? null : optionalValues.get(0));
|
|
|
}
|
|
|
} catch (SQLException e) {
|
|
|
throw new IllegalStateException("参数解析错误", e);
|
|
|
@@ -132,14 +137,19 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
*
|
|
|
* @param jdbc jdbc
|
|
|
* @param sql sql 查询语句
|
|
|
- * @return json 格式的结果
|
|
|
+ * @return 执行结果
|
|
|
*/
|
|
|
- private String getValue(@NotEmpty("jdbc") NewbieJdbcSupport jdbc, @NotEmpty("sql") String sql) {
|
|
|
+ private List<Object> getValue(@NotEmpty("jdbc") NewbieJdbcSupport jdbc, @NotEmpty("sql") String sql) {
|
|
|
List<Map<String, Object>> listMap = jdbc.listMap(sql);
|
|
|
- if (listMap == null) {
|
|
|
- listMap = new ArrayList<>();
|
|
|
+ Map<String, List<Object>> map = kanbanParser.convert(listMap);
|
|
|
+ Set<String> keySet = map.keySet();
|
|
|
+ if (CollectionUtils.isEmpty(map)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ if (keySet.size() > 1) {
|
|
|
+ logger.error("参数解析结果不止一列:" + map);
|
|
|
}
|
|
|
- return JSONObject.toJSONString(listMap);
|
|
|
+ return map.get(keySet.iterator().next());
|
|
|
}
|
|
|
|
|
|
/**
|