fix(dc/tool-c): Fix special character handling and improve UX
Major fixes: - Fix pivot transformation with special characters in column names - Fix compute column validation for Chinese punctuation - Fix recode dialog to fetch unique values from full dataset via new API - Add column mapping mechanism to handle special characters Database migration: - Add column_mapping field to dc_tool_c_sessions table - Migration file: 20251208_add_column_mapping UX improvements: - Darken table grid lines for better visibility - Reduce column width by 40% with tooltip support - Insert new columns next to source columns - Preserve original row order after operations - Add notice about 50-row preview limit Modified files: - Backend: SessionService, SessionController, QuickActionService, routes - Python: pivot.py, compute.py, recode.py, binning.py, conditional.py - Frontend: DataGrid, RecodeDialog, index.tsx, ag-grid-custom.css - Database: schema.prisma, migration SQL Status: Code complete, database migrated, ready for testing
This commit is contained in:
@@ -25,6 +25,10 @@ interface SessionIdParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface GetUniqueValuesQuery {
|
||||
column: string;
|
||||
}
|
||||
|
||||
// ==================== 控制器 ====================
|
||||
|
||||
export class SessionController {
|
||||
@@ -362,6 +366,69 @@ export class SessionController {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ✨ 获取列的唯一值(用于数值映射)
|
||||
*
|
||||
* GET /api/v1/dc/tool-c/sessions/:id/unique-values?column=xxx
|
||||
*/
|
||||
async getUniqueValues(
|
||||
request: FastifyRequest<{ Params: SessionIdParams; Querystring: GetUniqueValuesQuery }>,
|
||||
reply: FastifyReply
|
||||
) {
|
||||
try {
|
||||
const { id } = request.params;
|
||||
const { column } = request.query;
|
||||
|
||||
if (!column) {
|
||||
return reply.code(400).send({
|
||||
success: false,
|
||||
error: '缺少column参数',
|
||||
});
|
||||
}
|
||||
|
||||
logger.info(`[SessionController] 获取唯一值: session=${id}, column=${column}`);
|
||||
|
||||
// 1. 获取完整数据
|
||||
const data = await sessionService.getFullData(id);
|
||||
|
||||
// 2. 提取唯一值(去除空值和首尾空格)
|
||||
const values = data.map((row) => row[column]);
|
||||
const cleanedValues = values.map((val) => {
|
||||
if (val === null || val === undefined || val === '') return null;
|
||||
// 如果是字符串,去除首尾空格
|
||||
return typeof val === 'string' ? val.trim() : val;
|
||||
});
|
||||
|
||||
// 3. 去重
|
||||
const uniqueValues = Array.from(new Set(cleanedValues))
|
||||
.filter((v) => v !== null && v !== '' && v !== '(空白)')
|
||||
.sort(); // 排序,方便查看
|
||||
|
||||
logger.info(`[SessionController] 唯一值数量: ${uniqueValues.length}`);
|
||||
|
||||
// 4. 返回结果
|
||||
return reply.send({
|
||||
success: true,
|
||||
data: {
|
||||
column,
|
||||
uniqueValues,
|
||||
count: uniqueValues.length,
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
logger.error(`[SessionController] 获取唯一值失败: ${error.message}`);
|
||||
|
||||
const statusCode = error.message.includes('不存在') || error.message.includes('过期')
|
||||
? 404
|
||||
: 500;
|
||||
|
||||
return reply.code(statusCode).send({
|
||||
success: false,
|
||||
error: error.message || '获取唯一值失败',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 导出单例实例 ====================
|
||||
|
||||
@@ -226,3 +226,4 @@ export class StreamAIController {
|
||||
export const streamAIController = new StreamAIController();
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user