package cn.autoform.web.controller.datasource;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import cn.autoform.db.entity.DBConnectionManagerEntity;
|
import cn.autoform.db.entity.FieldPropertyEntity;
|
import cn.autoform.db.entity.FormdatsourceEntity;
|
import cn.autoform.fw.exception.RestResult;
|
import cn.autoform.fw.service.DatabaseMetaDateService;
|
import cn.autoform.fw.utility.RestResultGenerator;
|
import cn.autoform.web.service.datasource.DatasourceService;
|
|
/**
|
* 数据源信息管理
|
* @author liumy
|
*
|
* @param <T>
|
*/
|
@RestController
|
public class DatasourceController<T> {
|
|
@Autowired
|
private DatasourceService datasourceService = null;
|
|
@Autowired
|
private DatabaseMetaDateService databaseMetaDateService = null;
|
|
/**
|
* 初期化
|
*
|
* @param tenantID
|
* 租户ID
|
* @param formid
|
* 表单ID
|
* @return 表单数据源
|
*/
|
@RequestMapping(value = "${requset.datasource01}", method = RequestMethod.GET)
|
public RestResult<List<FormdatsourceEntity>> getFormdatsourceListService(String tenantID, String formID) {
|
|
List<FormdatsourceEntity> rsList = datasourceService.getFormdatsourceList(tenantID, formID);
|
return RestResultGenerator.genSuccessResult(rsList);
|
}
|
|
/**
|
* 新增一条数据源
|
*
|
* @param tenantID
|
* @param formID
|
* @param dataSourceName
|
* @param databaseName
|
* @param datasource
|
* @param createUser
|
* @return
|
*/
|
@RequestMapping(value = "${requset.datasource02}", method = RequestMethod.POST)
|
public RestResult<String> createFormdatsourceService(@RequestBody FormdatsourceEntity formdatsource) {
|
|
int nRs = datasourceService.createFormdatsource(formdatsource);
|
return RestResultGenerator.genSuccessResult(String.valueOf(nRs));
|
}
|
|
/**
|
* 删除一条数据源
|
*
|
* @param tenantID
|
* @param formID
|
* @param dataSourceName
|
* @return
|
*/
|
@RequestMapping(value = "${requset.datasource03}", method = RequestMethod.GET)
|
public RestResult<String> deleteFormdatsourceService(String tenantID, String formID, String dataSourceName) {
|
int nRs = datasourceService.deleteFormdatsource(tenantID, formID, dataSourceName);
|
return RestResultGenerator.genSuccessResult(String.valueOf(nRs));
|
}
|
|
/**
|
* 数据连接名取得
|
*
|
* @param tenantID
|
* @return
|
*/
|
@RequestMapping(value = "${requset.datasource04}", method = RequestMethod.GET)
|
public RestResult<List<String>> getDataConnectionNameService(String tenantID) {
|
List<String> rsList = datasourceService.getDataConnectionName(tenantID);
|
return RestResultGenerator.genSuccessResult(rsList);
|
}
|
|
/**
|
* 数据源详细取得
|
*
|
* @param tenantID
|
* @param dataConnectionName
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datasource05}", method = RequestMethod.GET)
|
public RestResult<List<String>> getDatasourceListService(String tenantID, String dataConnectionName) {
|
System.out.println(tenantID);
|
List<String> rsList = databaseMetaDateService.getDatabaseTableName(tenantID, dataConnectionName);
|
|
return RestResultGenerator.genSuccessResult(rsList);
|
}
|
|
/**
|
* 数据库詳細JSON取得(表单设计用)
|
*
|
* @param datasource
|
* @param tenantID
|
* @param dataConnectionName
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datasource06}", method = RequestMethod.GET)
|
public RestResult<List<Map<String,List<String>>>> getDatasourceColumnsNameService(String formID, String tenantID) {
|
|
List<Map<String,List<String>>> rsList = new ArrayList<Map<String,List<String>>>();
|
// 当前表单下所有数据源取得
|
List<FormdatsourceEntity> listDataSource = datasourceService.getFormdatsourceList(tenantID, formID);
|
for(FormdatsourceEntity formdatsource : listDataSource) {
|
// 数据源名
|
String datasourceName = formdatsource.getDataSourceName();
|
// 数据库名
|
String databaseName = formdatsource.getDatabaseName();
|
// 已选择的数据表名
|
String tableName = formdatsource.getDatasource();
|
// 获取所有列名List
|
List<String> listColumns = databaseMetaDateService.getDatabaseColumnsName(tenantID, databaseName, tableName);
|
|
Map<String,List<String>> mpTableMap = new HashMap<String,List<String>>();
|
|
mpTableMap.put(datasourceName, listColumns);
|
|
rsList.add(mpTableMap);
|
|
}
|
|
return RestResultGenerator.genSuccessResult(rsList);
|
|
}
|
|
/**
|
* 新增一条数据连接
|
*
|
* @param dBConnectionManagerEntity
|
* @return
|
*/
|
@RequestMapping(value = "${requset.datasource07}", method = RequestMethod.POST)
|
public RestResult<String> createDBconnectionService(
|
@RequestBody DBConnectionManagerEntity dBConnectionManagerEntity) {
|
int nRs = datasourceService.createDBconnection(dBConnectionManagerEntity);
|
|
return RestResultGenerator.genSuccessResult(String.valueOf(nRs));
|
}
|
|
// @RequestMapping(value = "${requset.datasource08}", method = RequestMethod.GET)
|
// public RestResult<Map<String,List<String>>> getDatasourceColumnsValueService1(String tenantID, String formID, String dataSourceName, String columnNames) {
|
//
|
// List<FormdatsourceEntity> listDataSource = datasourceService.getDatasource(tenantID, formID, dataSourceName);
|
// Map<String,List<String>> mpColumnInfo = new HashMap<String,List<String>>();
|
//
|
// FormdatsourceEntity formdatsource = listDataSource.get(0);
|
//
|
// String[] arrColumns = columnNames.split(",");
|
//
|
// for(String column : arrColumns) {
|
////
|
//// List<String> listColumnValue = databaseMetaDateService.getColumnsInfo(formdatsource, column);
|
//// mpColumnInfo.put(column, listColumnValue);
|
//
|
// }
|
//
|
// return RestResultGenerator.genSuccessResult(mpColumnInfo);
|
// }
|
|
/**
|
* 获取列详细值
|
* @param tenantID 租户
|
* @param databaseName 数据连接名
|
* @param datasource 表名
|
* @param columnNames 列名
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datasource08}", method = RequestMethod.GET)
|
public RestResult<Map<String,List<String>>> getDatasourceColumnsValueService(String tenantID, String databaseName, String datasource, String columnNames) {
|
|
String[] arrColumns = columnNames.split(",");
|
Map<String,List<String>> mpColumnInfo = new HashMap<String,List<String>>();
|
|
for(String column : arrColumns) {
|
|
List<String> listColumnValue = databaseMetaDateService.getColumnsInfo(tenantID,databaseName, datasource,column);
|
mpColumnInfo.put(column, listColumnValue);
|
|
}
|
|
return RestResultGenerator.genSuccessResult(mpColumnInfo);
|
}
|
|
/**
|
* 获取当前表单数据源详细信息
|
* @param tenantID
|
* @param formID
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datasource09}", method = RequestMethod.GET)
|
public RestResult<List<Map<String, List<Map<String,List<Map<String,List<String>>>>>>>> getDatasourceInfoService(String tenantID, String formID){
|
// 当前表单下所有数据源取得
|
List<FormdatsourceEntity> listDataSource = datasourceService.getFormdatsourceList(tenantID, formID);
|
|
List<Map<String, List<Map<String,List<Map<String,List<String>>>>>>> rsList = new ArrayList<Map<String, List<Map<String,List<Map<String,List<String>>>>>>>();
|
|
for(FormdatsourceEntity formdatsource : listDataSource) {
|
// 数据源名
|
String datasourceName = formdatsource.getDataSourceName();
|
// 数据库名
|
String databaseName = formdatsource.getDatabaseName();
|
// 已选择的数据表名
|
String tableName = formdatsource.getDatasource();
|
|
Map<String,List<String>> mpColumn = databaseMetaDateService.getDatabaseColumnsInfo(tenantID, databaseName, tableName);
|
|
List<Map<String,List<String>>> listColumnInfo = new ArrayList<Map<String,List<String>>>();
|
|
listColumnInfo.add(mpColumn);
|
|
Map<String,List<Map<String,List<String>>>> mpTable = new HashMap<String,List<Map<String,List<String>>>>();
|
|
mpTable.put(tableName, listColumnInfo);
|
|
List<Map<String,List<Map<String,List<String>>>>> listTables = new ArrayList<Map<String,List<Map<String,List<String>>>>>();
|
|
listTables.add(mpTable);
|
|
Map<String, List<Map<String,List<Map<String,List<String>>>>>> mpDatabase = new HashMap<String, List<Map<String,List<Map<String,List<String>>>>>>();
|
|
mpDatabase.put(datasourceName, listTables);
|
rsList.add(mpDatabase);
|
}
|
|
|
return RestResultGenerator.genSuccessResult(rsList);
|
}
|
|
/**
|
* 字段数据源取得服务(发布用)
|
* @param tenantID
|
* @param formID
|
* @return
|
*/
|
@RequestMapping(value = "${requset.datasource10}", method = RequestMethod.GET)
|
public RestResult<List<Map<String,Map<String,String>>>> getFieldDatasourceInfoService(String tenantID, String formID ) {
|
|
List<Map<String,Map<String,String>>> rsList = new ArrayList<Map<String,Map<String,String>>>();
|
// 取得当前表单字段属性datasourcetype为dataSource的所有字段信息 datasource textcolumn valuecolumn namecolumn
|
// 设定数据源的字段column取得
|
List<FieldPropertyEntity> listFieldProper = datasourceService.getColumnNum(tenantID, formID);
|
for(FieldPropertyEntity fieldProperty : listFieldProper) {
|
|
//
|
int columnOrderNum = fieldProperty.getColumnOrderNum();
|
|
// 别名取得
|
String fieldKey = datasourceService.getFieldkeyList(tenantID, formID, columnOrderNum).get(0).getFieldKey();
|
|
// 数据源名
|
String datasource = datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "datasource").get(0).getValue();
|
// 列1名
|
String textcolumn = datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "textcolumn").get(0).getValue();
|
// 列2名
|
String valuecolumn = datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "valuecolumn").get(0).getValue();
|
// 列3
|
String namecolumn = "";
|
if(!datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "namecolumn").isEmpty()) {
|
namecolumn = datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "namecolumn").get(0).getValue();
|
}
|
|
Map<String,String> mpFieldInfo = new HashMap<String,String>();
|
|
mpFieldInfo.put("datasource", datasource);
|
|
mpFieldInfo.put("textcolumn", textcolumn);
|
|
mpFieldInfo.put("valuecolumn", valuecolumn);
|
|
mpFieldInfo.put("namecolumn", namecolumn);
|
|
Map<String,Map<String,String>> mpField = new HashMap<String,Map<String,String>>();
|
|
mpField.put(fieldKey, mpFieldInfo);
|
|
rsList.add(mpField);
|
}
|
|
return RestResultGenerator.genSuccessResult(rsList);
|
}
|
}
|