

通过数据源工具类执行自定义sql示例demo， 其中工具方法如build(), encode()等可自行替换调整

// 注意通过自定义sql方式无法记录标准日志， 非特定场景需求建议走标准 [数据操作接口](https://weapp.eteams.cn/build/techdoc/wdoc/index.html#/public/doc/c98b2645-ea0a-465e-a00c-19b36aa50c4b)

```java
@Autowired
private DataSetService dataSetService;

// 数据源类型
private final static SourceType sourceType = com.weaver.ebuilder.datasource.api.enums.SourceType.LOGIC;
// eb表单对应标识
private final static String groupId = "weaver-ebuilder-form-service";

/**
 * 执行自定义sql
 * @param customSql 外部传入自定义sql
 * @return 查询结果集
 */
public List<Map<String, Object>> executeSql(String customSql) {
	ExecuteSqlEntity executeSqlEntity = build(customSql, groupId, sourceType);
	final Map<String, Object> resultMap = dataSetService.executeSql(executeSqlEntity);
	final String status = (String) resultMap.get("status");
	final String msg = (String) resultMap.get("message");
	if(Util.equals(status,"OK")) {
		List<Map<String, Object>> dataList = (List<Map<String, Object>>) resultMap.get("records");
		return dataList;
	}
	return null;
}

public static ExecuteSqlEntity build(String sql, String groupId, SourceType sourceType) {
	ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
	executeSqlEntity.setSql(encode(sql));
	executeSqlEntity.setGroupId(groupId);
	executeSqlEntity.setSourceType(sourceType);
	return executeSqlEntity;
}

public static String encode(String text) {
	byte[] textByte;
	try {
		textByte = text.getBytes("UTF-8");
	} catch (UnsupportedEncodingException var3) {
		throw new RuntimeException(var3);
	}
	return Base64.getEncoder().encodeToString(textByte);
}
```
