|
@@ -6,10 +6,20 @@ import com.uas.kanban.dao.DataSourceDao;
|
|
|
import com.uas.kanban.dao.PanelDao;
|
|
import com.uas.kanban.dao.PanelDao;
|
|
|
import com.uas.kanban.exception.OperationException;
|
|
import com.uas.kanban.exception.OperationException;
|
|
|
import com.uas.kanban.model.Panel;
|
|
import com.uas.kanban.model.Panel;
|
|
|
|
|
+import com.uas.kanban.model.PanelInstance;
|
|
|
|
|
+import com.uas.kanban.model.Parameter;
|
|
|
|
|
+import com.uas.kanban.service.PanelInstanceService;
|
|
|
|
|
+import com.uas.kanban.service.PanelService;
|
|
|
|
|
+import com.uas.kanban.support.DataSourceManager;
|
|
|
|
|
+import com.uas.kanban.support.KanbanParser;
|
|
|
|
|
+import com.uas.kanban.util.CollectionUtils;
|
|
|
|
|
+import me.chyxion.jdbc.NewbieJdbcSupport;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.sql.SQLException;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 面板
|
|
* 面板
|
|
@@ -18,7 +28,7 @@ import java.util.List;
|
|
|
* @since 2017/10/18 14:20
|
|
* @since 2017/10/18 14:20
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
-public class PanelServiceImpl extends BaseService<Panel> {
|
|
|
|
|
|
|
+public class PanelServiceImpl extends BaseService<Panel> implements PanelService {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private PanelDao panelDao;
|
|
private PanelDao panelDao;
|
|
@@ -26,6 +36,15 @@ public class PanelServiceImpl extends BaseService<Panel> {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DataSourceDao dataSourceDao;
|
|
private DataSourceDao dataSourceDao;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PanelInstanceService panelInstanceService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DataSourceManager dataSourceManager;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private KanbanParser kanbanParser;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Panel save(@NotEmpty("json") String json) {
|
|
public Panel save(@NotEmpty("json") String json) {
|
|
|
// TODO generate PanelInstance
|
|
// TODO generate PanelInstance
|
|
@@ -76,4 +95,33 @@ public class PanelServiceImpl extends BaseService<Panel> {
|
|
|
return super.delete(codes);
|
|
return super.delete(codes);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<Map<String, Object>> validateSQL(@NotEmpty("panelCode") String panelCode, @NotEmpty("sql") String sql, Boolean replaceParameters) throws SQLException, OperationException {
|
|
|
|
|
+ if (sql.toLowerCase().matches("([\\s]*?update|delete|insert)[\\s]+?[\\s\\S]+?")) {
|
|
|
|
|
+ throw new OperationException("不支持 update, delete, insert 操作");
|
|
|
|
|
+ }
|
|
|
|
|
+ Panel panel = panelDao.checkExist(panelCode);
|
|
|
|
|
+ // 如果需要替换 sql 中的参数
|
|
|
|
|
+ if (replaceParameters != null && replaceParameters) {
|
|
|
|
|
+ PanelInstance panelInstance = panelInstanceService.getByPanelCode(panelCode);
|
|
|
|
|
+ List<Parameter> parameters = panelInstance.fromParameters();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(parameters)) {
|
|
|
|
|
+ for (Parameter parameter : parameters) {
|
|
|
|
|
+ if (parameter.getValue() == null) {
|
|
|
|
|
+ List<Object> optionalValues = parameter.getOptionalValues();
|
|
|
|
|
+ if (CollectionUtils.isEmpty(optionalValues)) {
|
|
|
|
|
+ throw new IllegalStateException("参数没有可用值:" + parameter.getName());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 默认取第一个值
|
|
|
|
|
+ parameter.setValue(optionalValues.get(0));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ sql = kanbanParser.replaceParameters(sql, parameters, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ NewbieJdbcSupport jdbc = dataSourceManager.getJdbc(panel.getDataSourceCode());
|
|
|
|
|
+ kanbanParser.checkCount(jdbc.getDataSource().getConnection(), sql);
|
|
|
|
|
+ return jdbc.listMap(sql);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|