162 lines
4.3 KiB
JavaScript
162 lines
4.3 KiB
JavaScript
import http from 'http';
|
|
import { Buffer } from 'buffer';
|
|
|
|
// 测试评查点列表接口
|
|
function testGetEvaluationPoints() {
|
|
const options = {
|
|
hostname: '127.0.0.1',
|
|
port: 9000,
|
|
path: '/admin/evaluation_points',
|
|
method: 'GET',
|
|
headers: {
|
|
'Accept': 'application/json'
|
|
}
|
|
};
|
|
|
|
const req = http.request(options, (res) => {
|
|
console.log(`状态码: ${res.statusCode}`);
|
|
console.log(`响应头: ${JSON.stringify(res.headers)}`);
|
|
|
|
let data = '';
|
|
|
|
res.on('data', (chunk) => {
|
|
data += chunk;
|
|
});
|
|
|
|
res.on('end', () => {
|
|
console.log('获取评查点列表成功!');
|
|
try {
|
|
const jsonData = JSON.parse(data);
|
|
console.log(`共获取 ${jsonData.length} 条评查点数据`);
|
|
console.log('第一条数据:', JSON.stringify(jsonData[0], null, 2).substring(0, 200) + '...');
|
|
} catch (e) {
|
|
console.error('解析JSON数据失败:', e.message);
|
|
console.log('原始数据:', data);
|
|
}
|
|
});
|
|
});
|
|
|
|
req.on('error', (e) => {
|
|
console.error(`获取评查点列表请求失败: ${e.message}`);
|
|
});
|
|
|
|
req.end();
|
|
}
|
|
|
|
// 测试创建评查点接口
|
|
function testCreateEvaluationPoint() {
|
|
const testData = {
|
|
name: '测试评查点',
|
|
code: 'TEST_RULE_001',
|
|
risk: 'medium',
|
|
is_enabled: true,
|
|
description: '这是一个用于测试接口的评查点',
|
|
type: 'content',
|
|
references_laws: {
|
|
name: '《中华人民共和国民法典》',
|
|
articles: ['第五百八十五条', '第五百八十六条'],
|
|
content: '当事人应当按照约定全面履行自己的义务。'
|
|
},
|
|
evaluation_point_groups_id: 1,
|
|
extraction_config: {
|
|
llm: {
|
|
fields: ['合同名称', '合同编号', '签订日期'],
|
|
prompt_setting: {
|
|
type: 'system',
|
|
template: '请从文档中提取以下字段信息:合同名称、合同编号、签订日期'
|
|
}
|
|
},
|
|
vlm: {
|
|
fields: [
|
|
{ name: '公章', type: 'seal' },
|
|
{ name: '签名', type: 'handwriting' }
|
|
],
|
|
prompt_setting: {
|
|
type: 'system',
|
|
template: '请识别文档中的公章和签名'
|
|
}
|
|
},
|
|
regex: {
|
|
fields: [
|
|
{ field: '合同编号', pattern: 'HT-\\d{4}-\\d{6}' }
|
|
]
|
|
}
|
|
},
|
|
evaluation_config: {
|
|
logicType: 'and',
|
|
customLogic: '',
|
|
rules: [
|
|
{
|
|
id: '1',
|
|
type: 'exists',
|
|
config: {
|
|
fields: ['合同名称', '合同编号', '签订日期'],
|
|
logic: 'and'
|
|
}
|
|
}
|
|
]
|
|
},
|
|
pass_message: '文档检查通过,符合规范要求。',
|
|
fail_message: '文档存在以下问题,请修改后重新提交。',
|
|
suggestion_message: '',
|
|
suggestion_message_type: 'warning',
|
|
post_action: 'none',
|
|
action_config: ''
|
|
};
|
|
|
|
const postData = JSON.stringify(testData);
|
|
|
|
const options = {
|
|
hostname: '127.0.0.1',
|
|
port: 9000,
|
|
path: '/admin/evaluation_points',
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Content-Length': Buffer.byteLength(postData),
|
|
'Accept': 'application/json',
|
|
'Prefer': 'return=representation'
|
|
}
|
|
};
|
|
|
|
const req = http.request(options, (res) => {
|
|
console.log(`状态码: ${res.statusCode}`);
|
|
console.log(`响应头: ${JSON.stringify(res.headers)}`);
|
|
|
|
let data = '';
|
|
|
|
res.on('data', (chunk) => {
|
|
data += chunk;
|
|
});
|
|
|
|
res.on('end', () => {
|
|
console.log('创建评查点成功!');
|
|
try {
|
|
const jsonData = JSON.parse(data);
|
|
console.log('创建的评查点ID:', jsonData.id);
|
|
console.log('创建的评查点数据:', JSON.stringify(jsonData, null, 2).substring(0, 200) + '...');
|
|
} catch (e) {
|
|
console.error('解析JSON数据失败:', e.message);
|
|
console.log('原始数据:', data);
|
|
}
|
|
});
|
|
});
|
|
|
|
req.on('error', (e) => {
|
|
console.error(`创建评查点请求失败: ${e.message}`);
|
|
});
|
|
|
|
req.write(postData);
|
|
req.end();
|
|
}
|
|
|
|
// 运行测试
|
|
console.log('开始测试评查点API...');
|
|
console.log('1. 测试获取评查点列表...');
|
|
testGetEvaluationPoints();
|
|
|
|
// 等待3秒后测试创建评查点
|
|
setTimeout(() => {
|
|
console.log('\n2. 测试创建评查点...');
|
|
testCreateEvaluationPoint();
|
|
}, 3000);
|