完善字段与数据库对应
This commit is contained in:
@@ -442,8 +442,9 @@ export function ExtractionSettings({ onChange }: ExtractionSettingsProps) {
|
|||||||
onChange({
|
onChange({
|
||||||
extractionMethod: currentTab,
|
extractionMethod: currentTab,
|
||||||
promptSettings: {
|
promptSettings: {
|
||||||
...promptType,
|
type: value,
|
||||||
[type]: value
|
template: selectedTemplate[type],
|
||||||
|
content: promptContent[type]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -503,6 +504,17 @@ export function ExtractionSettings({ onChange }: ExtractionSettingsProps) {
|
|||||||
...promptContent,
|
...promptContent,
|
||||||
[type]: ''
|
[type]: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (onChange) {
|
||||||
|
onChange({
|
||||||
|
extractionMethod: currentTab,
|
||||||
|
promptSettings: {
|
||||||
|
type: promptType[type],
|
||||||
|
template: '',
|
||||||
|
content: ''
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+414
-13
@@ -26,10 +26,73 @@ export const handle = {
|
|||||||
breadcrumb: "新增评查点"
|
breadcrumb: "新增评查点"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 定义类型
|
||||||
|
interface RegexField {
|
||||||
|
fieldName: string;
|
||||||
|
regex: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PromptSetting {
|
||||||
|
type: string;
|
||||||
|
template: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ExtactionConfigType {
|
||||||
|
llm_ocr: {
|
||||||
|
fields: string[];
|
||||||
|
prompt_setting: PromptSetting;
|
||||||
|
};
|
||||||
|
llm_vl: {
|
||||||
|
fields: string[];
|
||||||
|
prompt_setting: PromptSetting;
|
||||||
|
};
|
||||||
|
ocr_regex: {
|
||||||
|
fields: RegexField[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RuleConfigType {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Rule {
|
||||||
|
id: string;
|
||||||
|
type: string;
|
||||||
|
config: RuleConfigType;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EvaluationConfigType {
|
||||||
|
logicType: string;
|
||||||
|
customLogic: string;
|
||||||
|
rules: Rule[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormDataType {
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
risk: string;
|
||||||
|
is_enabled: boolean;
|
||||||
|
description: string;
|
||||||
|
references_laws: {
|
||||||
|
name: string;
|
||||||
|
articles: string[];
|
||||||
|
content: string;
|
||||||
|
};
|
||||||
|
evaluation_point_groups_id: number | null;
|
||||||
|
extraction_config: ExtactionConfigType;
|
||||||
|
evaluation_config: EvaluationConfigType;
|
||||||
|
pass_message: string;
|
||||||
|
fail_message: string;
|
||||||
|
suggestion_message: string;
|
||||||
|
suggestion_message_type: string;
|
||||||
|
post_action: string;
|
||||||
|
action_config: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default function RuleNew() {
|
export default function RuleNew() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [extractionFields, setExtractionFields] = useState<string[]>([]);
|
const [extractionFields, setExtractionFields] = useState<string[]>([]);
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState<FormDataType>({
|
||||||
// 基本信息字段
|
// 基本信息字段
|
||||||
name: '',
|
name: '',
|
||||||
code: '',
|
code: '',
|
||||||
@@ -97,23 +160,240 @@ export default function RuleNew() {
|
|||||||
|
|
||||||
// 处理ExtractionSettings组件数据变更
|
// 处理ExtractionSettings组件数据变更
|
||||||
const handleExtractionSettingsChange = (data: Record<string, unknown>) => {
|
const handleExtractionSettingsChange = (data: Record<string, unknown>) => {
|
||||||
setFormData(prevData => ({
|
setFormData(prevData => {
|
||||||
...prevData,
|
// 获取数据
|
||||||
...data
|
const extractionMethod = data.extractionMethod as string;
|
||||||
}));
|
const regexFields = data.regexFields as Array<{ id: string; fieldName: string; regex: string }>;
|
||||||
|
const fields = data.fields as Record<string, string[]>;
|
||||||
|
|
||||||
|
// 根据抽取方法更新对应字段
|
||||||
|
const updatedExtractionConfig = { ...prevData.extraction_config };
|
||||||
|
|
||||||
|
// 更新正则抽取字段
|
||||||
|
if (regexFields) {
|
||||||
|
updatedExtractionConfig.ocr_regex.fields = regexFields
|
||||||
|
.filter(field => field.fieldName && field.regex)
|
||||||
|
.map(field => ({
|
||||||
|
fieldName: field.fieldName,
|
||||||
|
regex: field.regex
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新LLM字段
|
||||||
|
if (fields) {
|
||||||
|
if (fields.llm_ocr) {
|
||||||
|
updatedExtractionConfig.llm_ocr.fields = fields.llm_ocr;
|
||||||
|
}
|
||||||
|
if (fields.llm) {
|
||||||
|
updatedExtractionConfig.llm_vl.fields = fields.llm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新提示词设置
|
||||||
|
if (data.promptSettings) {
|
||||||
|
const promptSettings = data.promptSettings as Record<string, any>;
|
||||||
|
|
||||||
|
// 确定当前是处理哪种类型的提示词
|
||||||
|
if (extractionMethod === 'llm_ocr') {
|
||||||
|
updatedExtractionConfig.llm_ocr.prompt_setting.type = promptSettings.type || 'system';
|
||||||
|
updatedExtractionConfig.llm_ocr.prompt_setting.template = promptSettings.content || '';
|
||||||
|
} else if (extractionMethod === 'llm') {
|
||||||
|
updatedExtractionConfig.llm_vl.prompt_setting.type = promptSettings.type || 'system';
|
||||||
|
updatedExtractionConfig.llm_vl.prompt_setting.template = promptSettings.content || '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 兼容旧的API
|
||||||
|
if (data.promptType) {
|
||||||
|
const promptType = data.promptType as Record<string, string>;
|
||||||
|
if (promptType.llm_ocr) {
|
||||||
|
updatedExtractionConfig.llm_ocr.prompt_setting.type = promptType.llm_ocr;
|
||||||
|
}
|
||||||
|
if (promptType.llm) {
|
||||||
|
updatedExtractionConfig.llm_vl.prompt_setting.type = promptType.llm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.promptContent) {
|
||||||
|
const promptContent = data.promptContent as Record<string, string>;
|
||||||
|
if (promptContent.llm_ocr) {
|
||||||
|
updatedExtractionConfig.llm_ocr.prompt_setting.template = promptContent.llm_ocr;
|
||||||
|
}
|
||||||
|
if (promptContent.llm) {
|
||||||
|
updatedExtractionConfig.llm_vl.prompt_setting.template = promptContent.llm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('更新的抽取设置:', updatedExtractionConfig);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...prevData,
|
||||||
|
extraction_config: updatedExtractionConfig
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理ReviewSettings组件数据变更
|
// 处理ReviewSettings组件数据变更
|
||||||
const handleReviewSettingsChange = (data: Record<string, unknown>) => {
|
const handleReviewSettingsChange = (data: Record<string, unknown>) => {
|
||||||
setFormData(prevData => ({
|
setFormData(prevData => {
|
||||||
...prevData,
|
const updatedData = { ...prevData };
|
||||||
...data
|
|
||||||
}));
|
// 更新规则
|
||||||
|
if (data.rules) {
|
||||||
|
updatedData.evaluation_config.rules = data.rules as Rule[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新组合逻辑
|
||||||
|
if (data.combinationLogic !== undefined) {
|
||||||
|
updatedData.evaluation_config.logicType = data.combinationLogic as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新自定义逻辑
|
||||||
|
if (data.customLogic !== undefined) {
|
||||||
|
updatedData.evaluation_config.customLogic = data.customLogic as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新通过/不通过/建议消息
|
||||||
|
if (data.pass_message !== undefined) {
|
||||||
|
updatedData.pass_message = data.pass_message as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.fail_message !== undefined) {
|
||||||
|
updatedData.fail_message = data.fail_message as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.suggestion_message !== undefined) {
|
||||||
|
updatedData.suggestion_message = data.suggestion_message as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.suggestion_message_type !== undefined) {
|
||||||
|
updatedData.suggestion_message_type = data.suggestion_message_type as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新评查后动作
|
||||||
|
if (data.post_action !== undefined) {
|
||||||
|
updatedData.post_action = data.post_action as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.action_config !== undefined) {
|
||||||
|
updatedData.action_config = data.action_config as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
return updatedData;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 保存评查点
|
// 保存评查点
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
try {
|
try {
|
||||||
|
// 转换提取配置为符合数据库格式的JSON
|
||||||
|
const extractionConfig = {
|
||||||
|
llm: {
|
||||||
|
fields: formData.extraction_config.llm_ocr.fields || [],
|
||||||
|
prompt_setting: {
|
||||||
|
type: formData.extraction_config.llm_ocr.prompt_setting.type || 'system',
|
||||||
|
template: formData.extraction_config.llm_ocr.prompt_setting.template || ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
vlm: {
|
||||||
|
fields: (formData.extraction_config.llm_vl.fields || []).map((field: any) => {
|
||||||
|
// 处理带有类型后缀的字段名 (如 "字段名_类型")
|
||||||
|
if (typeof field === 'string' && field.includes('_')) {
|
||||||
|
const [name, type] = field.split('_');
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
type: type || 'default'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { name: field, type: 'default' };
|
||||||
|
}),
|
||||||
|
prompt_setting: {
|
||||||
|
type: formData.extraction_config.llm_vl.prompt_setting.type || 'system',
|
||||||
|
template: formData.extraction_config.llm_vl.prompt_setting.template || ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
regex: {
|
||||||
|
fields: (formData.extraction_config.ocr_regex.fields || []).map((field: any) => {
|
||||||
|
if (typeof field === 'object') {
|
||||||
|
return {
|
||||||
|
field: field.fieldName || '',
|
||||||
|
pattern: field.regex || ''
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { field: '', pattern: '' };
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('提交的提取配置:', extractionConfig);
|
||||||
|
console.log('原始提取配置:', formData.extraction_config);
|
||||||
|
|
||||||
|
// 转换评查配置为符合数据库格式的JSON
|
||||||
|
const evaluationConfig = {
|
||||||
|
logicType: formData.evaluation_config.logicType || 'and',
|
||||||
|
customLogic: formData.evaluation_config.customLogic || '',
|
||||||
|
rules: (formData.evaluation_config.rules || []).map((rule: any) => {
|
||||||
|
let config = {};
|
||||||
|
|
||||||
|
// 根据不同的规则类型生成对应的配置
|
||||||
|
switch (rule.type) {
|
||||||
|
case 'exists':
|
||||||
|
config = {
|
||||||
|
fields: rule.config?.selectedFields || [],
|
||||||
|
logic: rule.config?.logicRelation || 'and'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'consistency':
|
||||||
|
config = {
|
||||||
|
pairs: rule.config?.pairs || [],
|
||||||
|
logic: rule.config?.logicRelation || 'and'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'format':
|
||||||
|
config = {
|
||||||
|
field: rule.config?.field || '',
|
||||||
|
formatType: rule.config?.formatType || '',
|
||||||
|
parameters: rule.config?.parameters || ''
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'logic':
|
||||||
|
config = {
|
||||||
|
conditions: rule.config?.conditions || [],
|
||||||
|
logic: rule.config?.logicRelation || 'and'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'regex':
|
||||||
|
config = {
|
||||||
|
field: rule.config?.field || '',
|
||||||
|
pattern: rule.config?.pattern || '',
|
||||||
|
matchType: rule.config?.matchType || 'match'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'ai':
|
||||||
|
config = {
|
||||||
|
model: rule.config?.model || 'qwen14b',
|
||||||
|
temperature: rule.config?.temperature || 0.1,
|
||||||
|
prompt: rule.config?.prompt || ''
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'code':
|
||||||
|
config = {
|
||||||
|
language: rule.config?.language || 'javascript',
|
||||||
|
code: rule.config?.code || ''
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
config = rule.config || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: rule.id,
|
||||||
|
type: rule.type,
|
||||||
|
config
|
||||||
|
};
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
// 构建完整的评查点数据
|
// 构建完整的评查点数据
|
||||||
const evaluationPointData = {
|
const evaluationPointData = {
|
||||||
code: formData.code,
|
code: formData.code,
|
||||||
@@ -123,8 +403,8 @@ export default function RuleNew() {
|
|||||||
description: formData.description,
|
description: formData.description,
|
||||||
is_enabled: formData.is_enabled,
|
is_enabled: formData.is_enabled,
|
||||||
references_laws: formData.references_laws,
|
references_laws: formData.references_laws,
|
||||||
extraction_config: formData.extraction_config,
|
extraction_config: extractionConfig,
|
||||||
evaluation_config: formData.evaluation_config,
|
evaluation_config: evaluationConfig,
|
||||||
pass_message: formData.pass_message,
|
pass_message: formData.pass_message,
|
||||||
fail_message: formData.fail_message,
|
fail_message: formData.fail_message,
|
||||||
suggestion_message: formData.suggestion_message,
|
suggestion_message: formData.suggestion_message,
|
||||||
@@ -160,11 +440,132 @@ export default function RuleNew() {
|
|||||||
// 保存为草稿
|
// 保存为草稿
|
||||||
const handleSaveDraft = async () => {
|
const handleSaveDraft = async () => {
|
||||||
try {
|
try {
|
||||||
|
// 转换提取配置为符合数据库格式的JSON
|
||||||
|
const extractionConfig = {
|
||||||
|
llm: {
|
||||||
|
fields: formData.extraction_config.llm_ocr.fields || [],
|
||||||
|
prompt_setting: {
|
||||||
|
type: formData.extraction_config.llm_ocr.prompt_setting.type || 'system',
|
||||||
|
template: formData.extraction_config.llm_ocr.prompt_setting.template || ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
vlm: {
|
||||||
|
fields: (formData.extraction_config.llm_vl.fields || []).map((field: any) => {
|
||||||
|
// 处理带有类型后缀的字段名 (如 "字段名_类型")
|
||||||
|
if (typeof field === 'string' && field.includes('_')) {
|
||||||
|
const [name, type] = field.split('_');
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
type: type || 'default'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { name: field, type: 'default' };
|
||||||
|
}),
|
||||||
|
prompt_setting: {
|
||||||
|
type: formData.extraction_config.llm_vl.prompt_setting.type || 'system',
|
||||||
|
template: formData.extraction_config.llm_vl.prompt_setting.template || ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
regex: {
|
||||||
|
fields: (formData.extraction_config.ocr_regex.fields || []).map((field: any) => {
|
||||||
|
if (typeof field === 'object') {
|
||||||
|
return {
|
||||||
|
field: field.fieldName || '',
|
||||||
|
pattern: field.regex || ''
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { field: '', pattern: '' };
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('草稿提交的提取配置:', extractionConfig);
|
||||||
|
console.log('草稿原始提取配置:', formData.extraction_config);
|
||||||
|
|
||||||
|
// 转换评查配置为符合数据库格式的JSON
|
||||||
|
const evaluationConfig = {
|
||||||
|
logicType: formData.evaluation_config.logicType || 'and',
|
||||||
|
customLogic: formData.evaluation_config.customLogic || '',
|
||||||
|
rules: (formData.evaluation_config.rules || []).map((rule: any) => {
|
||||||
|
let config = {};
|
||||||
|
|
||||||
|
// 根据不同的规则类型生成对应的配置
|
||||||
|
switch (rule.type) {
|
||||||
|
case 'exists':
|
||||||
|
config = {
|
||||||
|
fields: rule.config?.selectedFields || [],
|
||||||
|
logic: rule.config?.logicRelation || 'and'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'consistency':
|
||||||
|
config = {
|
||||||
|
pairs: rule.config?.pairs || [],
|
||||||
|
logic: rule.config?.logicRelation || 'and'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'format':
|
||||||
|
config = {
|
||||||
|
field: rule.config?.field || '',
|
||||||
|
formatType: rule.config?.formatType || '',
|
||||||
|
parameters: rule.config?.parameters || ''
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'logic':
|
||||||
|
config = {
|
||||||
|
conditions: rule.config?.conditions || [],
|
||||||
|
logic: rule.config?.logicRelation || 'and'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'regex':
|
||||||
|
config = {
|
||||||
|
field: rule.config?.field || '',
|
||||||
|
pattern: rule.config?.pattern || '',
|
||||||
|
matchType: rule.config?.matchType || 'match'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'ai':
|
||||||
|
config = {
|
||||||
|
model: rule.config?.model || 'qwen14b',
|
||||||
|
temperature: rule.config?.temperature || 0.1,
|
||||||
|
prompt: rule.config?.prompt || ''
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'code':
|
||||||
|
config = {
|
||||||
|
language: rule.config?.language || 'javascript',
|
||||||
|
code: rule.config?.code || ''
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
config = rule.config || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: rule.id,
|
||||||
|
type: rule.type,
|
||||||
|
config
|
||||||
|
};
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
// 构建带草稿标记的评查点数据
|
// 构建带草稿标记的评查点数据
|
||||||
const draftData = {
|
const draftData = {
|
||||||
...formData,
|
code: formData.code,
|
||||||
|
name: formData.name,
|
||||||
|
evaluation_point_groups_id: formData.evaluation_point_groups_id,
|
||||||
|
risk: formData.risk,
|
||||||
|
description: formData.description,
|
||||||
is_enabled: false, // 草稿默认不启用
|
is_enabled: false, // 草稿默认不启用
|
||||||
is_draft: true // 标记为草稿
|
is_draft: true, // 标记为草稿
|
||||||
|
references_laws: formData.references_laws,
|
||||||
|
extraction_config: extractionConfig,
|
||||||
|
evaluation_config: evaluationConfig,
|
||||||
|
pass_message: formData.pass_message,
|
||||||
|
fail_message: formData.fail_message,
|
||||||
|
suggestion_message: formData.suggestion_message,
|
||||||
|
suggestion_message_type: formData.suggestion_message_type,
|
||||||
|
post_action: formData.post_action,
|
||||||
|
action_config: formData.action_config
|
||||||
};
|
};
|
||||||
|
|
||||||
// 发送数据到API
|
// 发送数据到API
|
||||||
|
|||||||
Reference in New Issue
Block a user