You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.6 KiB
92 lines
3.6 KiB
import { DATA_BASE_TYPES, DATA_BASE_TYPES_OTHER, DESIGN_DRIVER_TYPE, OTHER_JDBC } from '@constants/constant'; |
|
import { DatabaseType } from './app.typings'; |
|
import { Connection } from './crud/crud.typings'; |
|
export function getAllDatabaseTypes():DatabaseType[] { |
|
return [ |
|
...DATA_BASE_TYPES, |
|
...BI.Providers.getProvider('dec.connection.provider.datebase').customDatabaseType.map(item => { |
|
return { |
|
...item, |
|
internal: false, |
|
commonly: false, |
|
}; |
|
}), |
|
]; |
|
} |
|
function getPlugin(type: string) { |
|
return BI.Providers.getProvider('dec.connection.provider.datebase').customDatabaseType.find(item => item.databaseType === type); |
|
} |
|
export function getPluginWidgetShow(plugin: string) { |
|
return BI.get(getPlugin(plugin), 'show'); |
|
} |
|
|
|
export function getPluginWidgetEdit(plugin: string) { |
|
return BI.get(getPlugin(plugin), 'edit'); |
|
} |
|
|
|
// 由于database可能为空,所以为了兼容平台和设计器,需要根据driver来判断数据库类型 |
|
export function getJdbcDatabaseType(database: string, driver: string): DatabaseType { |
|
if (!database && !driver) { |
|
return DATA_BASE_TYPES_OTHER; |
|
} |
|
let databaseType = null; |
|
// 从全部数据库类型中获取jdbc类型的 |
|
// 兼容之前的逻辑,otherJdbc要单独处理一下 |
|
const jdbcDatabases = getAllDatabaseTypes().filter(v => v.type === 'jdbc' || v.type === OTHER_JDBC); |
|
// KERNEL-1655 兼容旧版 由于旧版设计器创建的数据连接database都为other,所以要根据driver来判断数据类型 |
|
if (database && database !== 'other' && jdbcDatabases.some(item => item.databaseType === database)) { |
|
databaseType = jdbcDatabases.find(item => item.databaseType === database); |
|
} else { |
|
const designDatabase = DESIGN_DRIVER_TYPE.find(item => item.driver === driver); |
|
const decisionDatabase = jdbcDatabases.find(item => item.driver === driver); |
|
const type = designDatabase ? BI.get(designDatabase, 'type') : BI.get(decisionDatabase, 'databaseType'); |
|
databaseType = jdbcDatabases.find(item => item.databaseType === type); |
|
} |
|
if (!databaseType) { |
|
return DATA_BASE_TYPES_OTHER; |
|
} |
|
|
|
return databaseType; |
|
} |
|
|
|
export function resolveUrlInfo (url: string, database?: string) { |
|
if (BI.isNull(url)) return {}; |
|
|
|
return BI.Providers.getProvider('dec.connection.provider.datebase').getJdbcResolveByType(database)(url) || { |
|
host: '', |
|
port: '', |
|
databaseName: '', |
|
urlInfo: '', |
|
}; |
|
} |
|
|
|
// 拼接url |
|
export function splitUrl(host: string, port: string, database: string, baseUrl: string) { |
|
if (baseUrl.startsWith('jdbc:sqlserver')) { |
|
return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '') |
|
.replace('=database', `=${database}`); |
|
} |
|
|
|
return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '') |
|
.replace('database', database) |
|
.replace('dbname', database); |
|
} |
|
|
|
export function connectionCanEdit(connection: Connection) { |
|
if (connection && connection.privilegeDetailBeanList) { |
|
// privilegeType === 4 代表编辑权限,privilegeValue === 2 代表有权限 |
|
return connection.privilegeDetailBeanList.some(item => item.privilegeType === 4 && item.privilegeValue === 2); |
|
} |
|
|
|
return true; |
|
} |
|
|
|
export function getTextByDatabaseType(databaseType: string) { |
|
const database = getAllDatabaseTypes().find(item => item.databaseType === databaseType); |
|
|
|
return database ? database.text : ''; |
|
} |
|
|
|
export function getChartLength(str: string) { |
|
return str.replace(/[^\x00-\xff]/g, '01').length; |
|
}
|
|
|