页面树结构

版本比较

标识

  • 该行被添加。
  • 该行被删除。
  • 格式已经改变。


...

Markdown

## <strong>创建业务视图-SQL查询</strong>

...


- <strong>接口调用-方式1</strong>

...



```java

...


/**

...


 * 创建业务视图-SQL查询示例

...


 */

...


public class

...

 CreateBizViewDemo {
	public static void main(String[] args) {

...


		String user = "admin"; // 用户名

...


		String password = "admin"; // 密码

...


		String smartbiURL = "http://10.10.31.49:11000/smartbi"; // Smartbi链接

...


		ClientConnector conn = null;

...


		try {

...


			conn = new ClientConnector(smartbiURL); //

...

 创建Smartbi链接对象
            // 建立此连接时,就对smartbi进行了登录

...


			conn.open(user, password);

...


			// POST请求的请求体

...


			// pid必须是数据源中业务视图下的节点,包括业务视图节点和目录节点

...


			String body = "{\r\n" + "\"pid\": \"I8a8a4ca2017a18e018e0a2b3017a19209a7c13a3\",\r\n"

...


					+ "    \"name\": \"SQL查询1\",\r\n" +

...

 "    \"alias\": \"SQL查询1\",\r\n"

...


					+ "    \"sql\": \"select OrderID as a from orders\"\r\n" + "}";

...


			JSONObject json = JSONObject.fromString(body);

...


			// 创建业务视图-SQL查询

...


InvokeResult result = conn.remoteInvoke("AugmentedDataSetForVModule", "createDataModelBizView",

...


					new Object[] { json });

...


			if (result != null && result.isSucceed()) {

...


				JSONObject object = JSONObject.fromObject(result.getResult());

...


				String id = (String) object.optString("id");

...


				System.out.println("SQL查询的id: " + id);

...


			}
		} finally {
			if (conn != null) {
				conn.close();

...


			}
		}
	}
}


```
- <strong>接口调用-方式2(仅支持在已登录的情况下)</strong>

...



http://host:port/smartbi/smartbix/api/dataModel/createBizView

...



- <strong>接口请求类型</strong>

...



POST

...


- <strong>输入</strong>

...



DataModelBizViewCreatedVO

| <strong>属性</strong> | <strong>类型</strong> |

...

 <strong>说明</strong>                    |
| --------------------- | --------------------- | ---------------------------------------- |

...

- <strong>返回值</strong>

CheckResult

...


| pid                    | Stirng                | 业务视图的父节点,必须是数据源中业务视图下的节点,包括业务视图节点和目录节点,如果不是会抛异常
| id             | String                | 业务视图的id,没有指定时自动生成   |
| name          | String                | 业务视图的名称 |
| alias          | String                | 业务视图的别名 |
| sql          | String                | 业务视图的sql, 暂不支持参数 |

- <strong>返回值</strong>

CheckResult

| <strong>属性</strong> | <strong>类型</strong> | <strong>说明</strong>                    |
| --------------------- | --------------------- | ---------------------------------------- |

...

### <strong>简单示例</strong>

![]()

...


| id                    | Stirng                | 业务视图 id                                  |
| errorCode             | String                | 错误码,成功时错误码、错误信息同时为空   |
| errorMessage          | String                | 错误信息,成功时错误码、错误信息同时为空 |
| detail          | String                | 错误详细信息,成功时错误码、错误信息同时为空 |


### <strong>简单示例</strong>

![](https://wiki.smartbi.com.cn/download/attachments/151781673/image.png?version=1&modificationDate=1745396708000&api=v2)

```json
{
    "pid": "I8a8a9fdb019623f123f1661a0196241badee0001",
    "name": "SQL查询1",
    "alias": "SQL查询1",
    "sql": "select OrderID as a from orders"
}
```