fix: 人员数据治理迁移8

This commit is contained in:
2026-11-11 17:29:54 +08:00
parent 6aabaf7e52
commit acac267b11
6 changed files with 193 additions and 54 deletions
+20 -10
View File
@@ -10,14 +10,17 @@
* Access_Token 路径:data->access_token
* Expires_in 路径:data->expires_in,单位:SECONDS
* 数据地址:http://127.0.0.1:18080/api/persons,GET 或 POST
* 机构地址:http://127.0.0.1:18080/api/units,GET 或 POST
* 返回码路径:code,成功返回值:0,消息路径:msg
* 人员数组路径:data->list,总数路径:data->total
* 数据数组路径:data->list,总数路径:data->total
* 数据字段按人员接口字段表生成,全部为字符串;码值为模拟值。
* 字段映射示例:gh→loginname、xm→username、xb→sex、sjhm→mobile、yx→email、lxrq→arrivalAtSchoolDate。
* gh、grbsm 均为唯一标识,可按实际目标中间表字段配置。
* 机构配置:dwdm→id(唯一标识)、dwmc→name、bmflmc→unitType。
* 人员配置:bmmz→unitId,值与机构接口的 dwdm 相同。
* 分页 Query 参数:pageNumber=${页码}、pageSize=${数量},例如起始页码 1、数量 20。
* POST JSON 也可使用 {"pageNumber":"${页码}","pageSize":"${数量}"}。
* 不配置分页参数时一次返回全部 100 条数据。
* 也支持 page 和 pagesize。不配置分页参数时返回全部 100 条人员或 5 条机构。
* 默认不要求认证;MOCK_REQUIRE_TOKEN=1 时,数据接口要求以下任意一种凭证:
* Header Authorization: Bearer ${Access_Token}
* Query 或 JSON 参数 access_token: ${Access_Token}
@@ -32,12 +35,18 @@ const REQUIRE_TOKEN = process.env.MOCK_REQUIRE_TOKEN === '1';
const TOKEN = 'person-governance-mock-token';
const MAX_BODY_BYTES = 1024 * 1024;
const units = [
{ dwdm: 'MOCK-D1', dwmc: '计算机学院', bmflmc: '教学单位' },
{ dwdm: 'MOCK-D2', dwmc: '机械工程学院', bmflmc: '教学单位' },
{ dwdm: 'MOCK-D3', dwmc: '经济管理学院', bmflmc: '教学单位' },
{ dwdm: 'MOCK-D4', dwmc: '外国语学院', bmflmc: '教学单位' },
{ dwdm: 'MOCK-D5', dwmc: '教务处', bmflmc: '行政单位' }
];
const persons = Array.from({ length: 100 }, (_, index) => {
const number = index + 1;
const suffix = String(number).padStart(3, '0');
const department = index % 5;
const departmentCode = `MOCK-D${department + 1}`;
const departmentName = ['计算机学院', '机械工程学院', '经济管理学院', '外国语学院', '教务处'][department];
const { dwdm: departmentCode, dwmc: departmentName } = units[index % units.length];
const female = number % 2 === 0;
const retired = number % 10 === 0;
const birthYear = retired ? 1960 + index % 5 : 1980 + index % 15;
@@ -175,7 +184,7 @@ function positiveInteger(value, fallback, name) {
const server = http.createServer(async (request, response) => {
try {
const url = new URL(request.url, 'http://localhost');
if (!['/api/token', '/api/persons'].includes(url.pathname)) {
if (!['/api/token', '/api/persons', '/api/units'].includes(url.pathname)) {
request.resume();
return reply(response, 404, 404, '接口不存在');
}
@@ -196,14 +205,15 @@ const server = http.createServer(async (request, response) => {
return reply(response, 401, 401, 'Token 无效或未提供');
}
const pageNumber = positiveInteger(params.pageNumber ?? params.page, 1, 'pageNumber');
const pageSize = positiveInteger(params.pageSize, 100, 'pageSize');
const pageSize = positiveInteger(params.pageSize ?? params.pagesize, 100, 'pageSize');
if (pageSize > 1000) {
return reply(response, 400, 400, 'pageSize 不能超过 1000');
}
const start = (pageNumber - 1) * pageSize;
const records = url.pathname === '/api/units' ? units : persons;
return reply(response, 200, 0, '成功', {
list: persons.slice(start, start + pageSize),
total: persons.length,
list: records.slice(start, start + pageSize),
total: records.length,
pageNumber,
pageSize
});
@@ -220,5 +230,5 @@ server.on('error', error => {
server.listen(PORT, HOST, () => {
console.log(`人员治理测试服务:http://${HOST}:${PORT},已预填充 ${persons.length} 条模拟数据`);
console.log('Token 接口:/api/token;人员接口:/api/persons');
console.log('Token 接口:/api/token;人员接口:/api/persons;机构接口:/api/units');
});