package cn.autoform.web.service.datasource;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import cn.autoform.db.entity.DBConnectionManagerEntity;
|
import cn.autoform.db.entity.FieldPropertyEntity;
|
import cn.autoform.db.entity.FormFieldEntity;
|
import cn.autoform.db.entity.FormdatsourceEntity;
|
import cn.autoform.fw.service.DatabaseMetaDateService;
|
import cn.autoform.web.mapper.datasource.DatasourceMapper;
|
|
/**
|
* 数据源管理Service
|
* @author liumy
|
*
|
*/
|
@Service
|
public class DatasourceService {
|
|
@Autowired
|
private DatasourceMapper datasourceMapper = null;
|
|
@Autowired
|
private DatabaseMetaDateService databaseMetaDateService = null;
|
|
/**
|
* 从表单数据源表中取出数据
|
* @param tenantID
|
* @param formid
|
* @return
|
*/
|
public List<FormdatsourceEntity> getFormdatsourceList(String tenantID, String formid){
|
return datasourceMapper.getFormdatsourceList(tenantID, formid);
|
}
|
|
/**
|
* 新增一条数据源
|
* @param tenantID
|
* @param formID
|
* @param dataSourceName
|
* @param databaseName
|
* @param datasource
|
* @param createUser
|
* @return
|
*/
|
public int createFormdatsource(FormdatsourceEntity formdatsource) {
|
|
return datasourceMapper.createFormdatsource(formdatsource);
|
}
|
|
/**
|
* 新增一条数据连接
|
* @param tenantID
|
* @param dataConnectionName
|
* @param dBconnectionString
|
* @param dBUserID
|
* @param dBPassword
|
* @param dBType
|
* @param createUser
|
* @return
|
*/
|
public int createDBconnection(DBConnectionManagerEntity dBConnectionManagerEntity) {
|
|
return datasourceMapper.createDBconnection(dBConnectionManagerEntity);
|
}
|
|
/**
|
* 删除一条数据源
|
* @param tenantID
|
* @param formID
|
* @param dataSourceName
|
* @return
|
*/
|
public int deleteFormdatsource(String tenantID,String formID, String dataSourceName) {
|
return datasourceMapper.deleteFormdatsource(formID, tenantID, dataSourceName);
|
}
|
|
/**
|
* 数据连接名取得
|
* @param tenantID
|
* @return
|
*/
|
public List<String> getDataConnectionName(String tenantID) {
|
return datasourceMapper.getDataConnectionName(tenantID);
|
}
|
|
/**
|
* 外部数据连接取得
|
* @param tenantID
|
* @param dataConnectionName
|
* @return
|
*/
|
public DBConnectionManagerEntity getDBconnectionList(String tenantID,String dataConnectionName) {
|
return datasourceMapper.getDBconnectionList(tenantID, dataConnectionName);
|
}
|
|
/**
|
* 详细数据源取得
|
* @param tenantID
|
* @param formID
|
* @param dataSourceName
|
* @return
|
*/
|
public List<FormdatsourceEntity> getDatasource(String tenantID,String formID, String dataSourceName) {
|
return datasourceMapper.getDatasource(formID, tenantID, dataSourceName);
|
}
|
|
/**
|
* 获取设定数据源的相关字段信息
|
* @param tenantID
|
* @param formID
|
* @return
|
*/
|
public List<FieldPropertyEntity> getFieldPropertyList(String tenantID,String formID,int columnOrderNum,String property) {
|
return datasourceMapper.getFieldPropertyList(tenantID, formID, columnOrderNum, property);
|
}
|
|
/**
|
* 获取字段信息
|
* @param tenantID
|
* @param formID
|
* @param columnOrderNum
|
* @return
|
*/
|
public List<FormFieldEntity> getFieldkeyList(String tenantID,String formID, int columnOrderNum) {
|
return datasourceMapper.getFieldkeyList(tenantID, formID, columnOrderNum);
|
}
|
|
/**
|
* 获取字段顺番
|
* @param tenantID
|
* @param formID
|
* @return
|
*/
|
public List<FieldPropertyEntity> getColumnNum(String tenantID,String formID) {
|
return datasourceMapper.getColumnNum(tenantID, formID);
|
}
|
|
/**
|
* 列值取得
|
* @param tenantID
|
* @param formID
|
* @param dataSourceName
|
* @param columnNames
|
* @return
|
* @throws Exception
|
*/
|
public Map<String,List<String>> getColumnsValues(String tenantID, String formID, String dataSourceName, String columnNames){
|
|
List<FormdatsourceEntity> listDataSource = this.getDatasource(tenantID, formID, dataSourceName);
|
|
Map<String,List<String>> mpColumnInfo = new HashMap<String,List<String>>();
|
|
FormdatsourceEntity formdatsource = listDataSource.get(0);
|
|
String databaseName = formdatsource.getDatabaseName();
|
|
String datasource = formdatsource.getDatasource();
|
|
String[] arrColumns = columnNames.split(",");
|
|
for(String column : arrColumns) {
|
|
List<String> listColumnValue = databaseMetaDateService.getColumnsInfo(tenantID, databaseName, datasource, column);
|
|
mpColumnInfo.put(column, listColumnValue);
|
}
|
return mpColumnInfo;
|
}
|
|
}
|