refactor: use dot notation for table name config (schema.table instead of schema_table)
Replace underscore-based table name splitting with dot-based splitting to match the standard schema.tablename format, removing MySQL compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -40,7 +40,7 @@ export function getDbConfig() {
|
||||
const configManager = ConfigManager.getInstance()
|
||||
const config = configManager.getConfig()
|
||||
return {
|
||||
TABLE_NAME: config.orderResolution.tableName || 'productionContractData_26 年压力表合同数据',
|
||||
TABLE_NAME: config.orderResolution.tableName || 'ERPAuto.vw_productionContractData',
|
||||
FIELD_PRODUCTION_ID: config.orderResolution.productionIdField || '总排号',
|
||||
FIELD_ORDER_NUMBER: config.orderResolution.orderNumberField || '生产订单号'
|
||||
}
|
||||
@@ -58,35 +58,28 @@ export class OrderNumberResolver {
|
||||
|
||||
/**
|
||||
* Get table name based on database type
|
||||
* Converts schema_tablename format to database-specific quoting:
|
||||
* Converts schema.tablename format to database-specific quoting:
|
||||
* - SQL Server: [schema].[tablename]
|
||||
* - PostgreSQL: "schema"."tablename"
|
||||
* - MySQL: schema_tablename (as-is)
|
||||
* e.g., productionContractData_26年压力表合同数据 ->
|
||||
* SQL Server: [productionContractData].[26年压力表合同数据]
|
||||
* PostgreSQL: "productionContractData"."26年压力表合同数据"
|
||||
* MySQL: productionContractData_26年压力表合同数据
|
||||
* e.g., ERPAuto.vw_productionContractData ->
|
||||
* SQL Server: [ERPAuto].[vw_productionContractData]
|
||||
* PostgreSQL: "ERPAuto"."vw_productionContractData"
|
||||
*/
|
||||
private getTableName(tableName: string): string {
|
||||
if (this.dbService.type === 'sqlserver' || this.dbService.type === 'postgresql') {
|
||||
// Find the FIRST underscore to split schema and table name
|
||||
// This handles patterns like: schema_tablename
|
||||
const firstUnderscoreIndex = tableName.indexOf('_')
|
||||
if (firstUnderscoreIndex > 0) {
|
||||
const schema = tableName.substring(0, firstUnderscoreIndex)
|
||||
const actualTableName = tableName.substring(firstUnderscoreIndex + 1)
|
||||
if (this.dbService.type === 'sqlserver') {
|
||||
return `[${schema}].[${actualTableName}]`
|
||||
}
|
||||
return `"${schema}"."${actualTableName}"`
|
||||
}
|
||||
// If no underscore found, default schema
|
||||
const dotIndex = tableName.indexOf('.')
|
||||
if (dotIndex > 0) {
|
||||
const schema = tableName.substring(0, dotIndex)
|
||||
const actualTableName = tableName.substring(dotIndex + 1)
|
||||
if (this.dbService.type === 'sqlserver') {
|
||||
return `[dbo].[${tableName}]`
|
||||
return `[${schema}].[${actualTableName}]`
|
||||
}
|
||||
return `"public"."${tableName}"`
|
||||
return `"${schema}"."${actualTableName}"`
|
||||
}
|
||||
return tableName
|
||||
// No dot found — use default schema
|
||||
if (this.dbService.type === 'sqlserver') {
|
||||
return `[dbo].[${tableName}]`
|
||||
}
|
||||
return `"public"."${tableName}"`
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,7 +41,7 @@ export async function getSourceNumbersFromInputs(
|
||||
}
|
||||
|
||||
if (productionIds.length > 0) {
|
||||
const contractTableName = getValidationTableName('productionContractData_26年压力表合同数据')
|
||||
const contractTableName = getValidationTableName('ERPAuto.vw_productionContractData')
|
||||
const batchSize = 2000
|
||||
|
||||
if (dbType === 'sqlserver') {
|
||||
|
||||
@@ -325,7 +325,7 @@ export class ValidationApplicationService {
|
||||
}
|
||||
|
||||
private async loadTypeKeywords(dbService: ValidationDatabaseService): Promise<TypeKeyword[]> {
|
||||
const typeKeywordTableName = getValidationTableName('dbo_MaterialsTypeToBeDeleted')
|
||||
const typeKeywordTableName = getValidationTableName('dbo.MaterialsTypeToBeDeleted')
|
||||
const sql = `
|
||||
SELECT MaterialName, ManagerName
|
||||
FROM ${typeKeywordTableName}
|
||||
@@ -341,7 +341,7 @@ export class ValidationApplicationService {
|
||||
private async loadMarkedCodes(
|
||||
dbService: ValidationDatabaseService
|
||||
): Promise<Map<string, string>> {
|
||||
const markedTableName = getValidationTableName('dbo_MaterialsToBeDeleted')
|
||||
const markedTableName = getValidationTableName('dbo.MaterialsToBeDeleted')
|
||||
const sql = `
|
||||
SELECT MaterialCode, ManagerName
|
||||
FROM ${markedTableName}
|
||||
@@ -416,7 +416,7 @@ export class ValidationApplicationService {
|
||||
|
||||
try {
|
||||
dbService = await createValidationDatabaseService()
|
||||
const detailTableName = getValidationTableName('dbo_DiscreteMaterialPlanData')
|
||||
const detailTableName = getValidationTableName('dbo.DiscreteMaterialPlanData')
|
||||
const enrichedMaterials: MaterialRecordSummary[] = []
|
||||
|
||||
log.info(`Enriching ${materials.length} materials with details`)
|
||||
@@ -501,7 +501,7 @@ export class ValidationApplicationService {
|
||||
selectedManagers: string[],
|
||||
orderNumbers: string[]
|
||||
): Promise<string[]> {
|
||||
const markedTableName = getValidationTableName('dbo_MaterialsToBeDeleted')
|
||||
const markedTableName = getValidationTableName('dbo.MaterialsToBeDeleted')
|
||||
|
||||
// Admin with selected managers: filter MaterialsToBeDeleted by ManagerName IN (selectedManagers)
|
||||
if (isAdmin && selectedManagers && selectedManagers.length > 0) {
|
||||
|
||||
@@ -52,25 +52,22 @@ export async function createValidationDatabaseService(): Promise<ValidationDatab
|
||||
return mysqlService
|
||||
}
|
||||
|
||||
export function getValidationTableName(mysqlTableName: string): string {
|
||||
export function getValidationTableName(dottedTableName: string): string {
|
||||
const configManager = ConfigManager.getInstance()
|
||||
const dbType = configManager.getDatabaseType()
|
||||
|
||||
if (dbType === 'sqlserver' || dbType === 'postgresql') {
|
||||
const firstUnderscoreIndex = mysqlTableName.indexOf('_')
|
||||
if (firstUnderscoreIndex > 0) {
|
||||
const schema = mysqlTableName.substring(0, firstUnderscoreIndex)
|
||||
const tableName = mysqlTableName.substring(firstUnderscoreIndex + 1)
|
||||
if (dbType === 'sqlserver') {
|
||||
return `[${schema}].[${tableName}]`
|
||||
}
|
||||
return `"${schema}"."${tableName}"`
|
||||
}
|
||||
const dotIndex = dottedTableName.indexOf('.')
|
||||
if (dotIndex > 0) {
|
||||
const schema = dottedTableName.substring(0, dotIndex)
|
||||
const tableName = dottedTableName.substring(dotIndex + 1)
|
||||
if (dbType === 'sqlserver') {
|
||||
return `[dbo].[${mysqlTableName}]`
|
||||
return `[${schema}].[${tableName}]`
|
||||
}
|
||||
return `"public"."${mysqlTableName}"`
|
||||
return `"${schema}"."${tableName}"`
|
||||
}
|
||||
|
||||
return mysqlTableName
|
||||
// No dot found — use default schema
|
||||
if (dbType === 'sqlserver') {
|
||||
return `[dbo].[${dottedTableName}]`
|
||||
}
|
||||
return `"public"."${dottedTableName}"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user