Skip to content

Commit a6d1a60

Browse files
committed
[fix] many GitHub copilot bugs
[optimize] update Upstream packages
1 parent 8b5e690 commit a6d1a60

File tree

12 files changed

+519
-663
lines changed

12 files changed

+519
-663
lines changed

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"dependencies": {
1010
"@arshiash80/strapi-plugin-iconhub": "^1.1.1",
1111
"@ckeditor/strapi-plugin-ckeditor": "^1.1.1",
12-
"@strapi/plugin-cloud": "~5.23.5",
13-
"@strapi/plugin-color-picker": "~5.23.5",
14-
"@strapi/plugin-documentation": "~5.23.5",
15-
"@strapi/plugin-users-permissions": "~5.23.5",
16-
"@strapi/strapi": "~5.23.5",
12+
"@strapi/plugin-cloud": "~5.23.6",
13+
"@strapi/plugin-color-picker": "~5.23.6",
14+
"@strapi/plugin-documentation": "~5.23.6",
15+
"@strapi/plugin-users-permissions": "~5.23.6",
16+
"@strapi/strapi": "~5.23.6",
1717
"better-sqlite3": "^12.2.0",
1818
"cross-env": "^10.0.0",
1919
"mobx-restful-migrator": "^0.1.0",
@@ -34,14 +34,15 @@
3434
"husky": "^9.1.7",
3535
"koajax": "^3.1.2",
3636
"lint-staged": "^16.1.6",
37+
"mobx-restful": "^2.1.3",
3738
"mobx-strapi": "^0.8.1",
3839
"prettier": "^3.6.2",
39-
"swagger-typescript-api": "^13.2.11",
40+
"swagger-typescript-api": "^13.2.13",
4041
"tsx": "^4.20.5",
4142
"typescript": "~5.9.2",
4243
"web-utility": "^4.6.1",
4344
"xlsx": "^0.18.5",
44-
"zx": "^8.8.1"
45+
"zx": "^8.8.2"
4546
},
4647
"pnpm": {
4748
"onlyBuiltDependencies": [

pnpm-lock.yaml

Lines changed: 343 additions & 376 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/import-data.ts

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
* Support import NGO organization data from Excel file to Strapi database
66
*/
77

8-
import * as fs from 'node:fs';
98
import { RestMigrator } from 'mobx-restful-migrator';
109

10+
import { migrationMapping } from './transformers/data-transformer';
11+
import { Config } from './types';
1112
import { ExcelReader } from './utils/excel-reader';
12-
import { Config, SourceOrganization } from './types';
13-
import { TargetOrganizationModel } from './utils/strapi-api';
14-
import { migrationMapping } from './migration/organization-mapping';
1513
import { ImportLogger } from './utils/import-logger';
14+
import { TargetOrganizationModel } from './utils/strapi-api';
1615

1716
// Configuration
1817
const CONFIG: Config = {
@@ -27,27 +26,11 @@ const CONFIG: Config = {
2726
};
2827

2928
// Data source generator function
30-
async function* loadOrganizationData(): AsyncGenerator<SourceOrganization> {
29+
async function* loadOrganizationData() {
3130
console.log(`正在读取 Excel 文件: ${CONFIG.EXCEL_FILE}`);
3231

33-
if (!fs.existsSync(CONFIG.EXCEL_FILE)) {
34-
throw new Error(`Excel 文件不存在: ${CONFIG.EXCEL_FILE}`);
35-
}
36-
3732
// Use existing Excel reader
38-
const rawOrganizations = ExcelReader.readExcelFile(
39-
CONFIG.EXCEL_FILE,
40-
CONFIG.SHEET_NAME,
41-
);
42-
43-
if (CONFIG.MAX_ROWS > 0) {
44-
rawOrganizations.splice(CONFIG.MAX_ROWS);
45-
}
46-
47-
console.log(`从 Excel 读取到 ${rawOrganizations.length} 条记录`);
48-
49-
// Yield each organization from existing reader
50-
yield* rawOrganizations;
33+
yield* ExcelReader.readExcelFile(CONFIG.EXCEL_FILE, CONFIG.SHEET_NAME);
5134
}
5235

5336
// Main function
@@ -100,22 +83,17 @@ async function main(): Promise<void> {
10083

10184
// Print final statistics
10285
logger.printStats();
103-
86+
10487
console.log('\n导入完成!');
10588

10689
// Save logs to files
10790
await logger.saveToFiles();
108-
10991
} catch (error: any) {
11092
console.error('导入失败:', error.message);
111-
if (error.stack) {
112-
console.error('错误堆栈:', error.stack);
113-
}
114-
115-
if (logger) {
116-
await logger.saveToFiles();
117-
}
118-
93+
console.error('错误堆栈:', error.stack);
94+
95+
await logger?.saveToFiles();
96+
11997
process.exit(1);
12098
}
12199
}
@@ -169,8 +147,5 @@ Strapi 数据导入工具
169147
}
170148
}
171149

172-
// Entry point
173-
if (require.main === module) {
174-
parseArgs();
175-
main();
176-
}
150+
parseArgs();
151+
main();

scripts/migration/organization-mapping.ts

Lines changed: 0 additions & 102 deletions
This file was deleted.
Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,74 @@
1-
import { OrganizationData, Organization } from '../types';
1+
import { MigrationSchema, TargetPatch } from 'mobx-restful-migrator';
2+
3+
import { SourceOrganization, TargetOrganization } from '../types';
24
import { AddressTransformer } from './address-transformer';
35
import { DateTransformer } from './date-transformer';
46
import { ServiceTransformer } from './service-transformer';
57
import { QualificationTransformer } from './qualification-transformer';
8+
import { UserTransformer } from './user-transformer';
69
import { DataUtils } from '../utils/data-utils';
10+
import { TargetUserModel } from '../utils/strapi-api';
711

8-
export class DataTransformer {
9-
static transformOrganization = (
10-
organization: Organization,
11-
): OrganizationData => ({
12-
name: organization['常用名称'] || organization.name || '',
13-
code: organization['机构信用代码'] || organization.code || '',
14-
entityType: DataUtils.transformEntityType(
15-
organization['实体类型'] || organization.entityType,
16-
),
17-
registrationCountry: DataUtils.transformRegistrationCountry(
18-
organization['注册国籍'] || organization.registrationCountry,
19-
),
20-
establishedDate: DateTransformer.parseDate(
21-
organization['成立时间'] || organization.establishedDate,
22-
),
23-
coverageArea: ServiceTransformer.extractCoverageFromDescription(
24-
organization['机构/项目简介'] || organization.description,
25-
),
26-
description: DataUtils.cleanDescription(
27-
organization['机构/项目简介'] || organization.description || '',
28-
),
29-
staffCount: DataUtils.parseStaffCount(
30-
organization['机构/项目全职人数'] || organization.staffCount,
31-
),
32-
address: AddressTransformer.transformAddress({
12+
export const migrationMapping: MigrationSchema<
13+
SourceOrganization,
14+
TargetOrganization
15+
> = {
16+
常用名称: ({ 常用名称: value }) => ({ name: { value, unique: true } }),
17+
机构信用代码: 'code',
18+
实体类型: ({ 实体类型: value }) => ({
19+
entityType: { value: DataUtils.transformEntityType(value) },
20+
}),
21+
注册国籍: ({ 注册国籍: value }) => ({
22+
registrationCountry: {
23+
value: DataUtils.transformRegistrationCountry(value),
24+
},
25+
}),
26+
成立时间: ({ 成立时间: value }) => ({
27+
establishedDate: { value: DateTransformer.parseDate(value) },
28+
}),
29+
'机构/项目简介': ({ ['机构/项目简介']: value }) => {
30+
value ||= '';
31+
return {
32+
description: { value: DataUtils.cleanDescription(value) },
33+
coverageArea: {
34+
value: ServiceTransformer.extractCoverageFromDescription(value),
35+
},
36+
};
37+
},
38+
'机构/项目全职人数': ({ ['机构/项目全职人数']: value }) => ({
39+
staffCount: { value: DataUtils.parseStaffCount(value) },
40+
}),
41+
注册地: ({ 注册地, 具体地址 }) => {
42+
const addressData = {
3343
province: AddressTransformer.extractProvinceFromAddress(
34-
organization['注册地'] || organization['具体地址'],
35-
),
36-
city: AddressTransformer.extractCityFromAddress(
37-
organization['注册地'] || organization['具体地址'],
44+
注册地 || 具体地址,
3845
),
46+
city: AddressTransformer.extractCityFromAddress(注册地 || 具体地址),
3947
district: AddressTransformer.extractDistrictFromAddress(
40-
organization['注册地'] || organization['具体地址'],
48+
注册地 || 具体地址,
4149
),
42-
street: organization['具体地址'] || organization.address?.street || '',
43-
}),
44-
services: ServiceTransformer.transformServices(organization),
45-
internetContact: ServiceTransformer.transformContacts(organization),
46-
qualifications:
47-
QualificationTransformer.transformQualifications(organization),
48-
});
49-
}
50+
street: 具体地址 || '',
51+
};
52+
return {
53+
address: { value: AddressTransformer.transformAddress(addressData) },
54+
};
55+
},
56+
机构官网: (row) => ({
57+
services: { value: ServiceTransformer.transformServices(row) },
58+
}),
59+
机构微信公众号: (row) => ({
60+
internetContact: { value: ServiceTransformer.transformContacts(row) },
61+
}),
62+
登记管理机关: (org) => ({
63+
qualifications: {
64+
value: QualificationTransformer.transformQualifications(org),
65+
},
66+
}),
67+
机构联系人联系人姓名: (org) => {
68+
const value = UserTransformer.transformUser(org);
69+
70+
return (
71+
!value ? {} : { contactUser: { value, model: TargetUserModel } }
72+
) as TargetPatch<TargetOrganization>;
73+
},
74+
};

scripts/transformers/qualification-transformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Qualification, Organization } from '../types';
1+
import { Qualification, SourceOrganization } from '../types';
22
import { QUALIFICATION_INDICATORS, QUALIFICATION_TYPES } from '../constants';
33

44
export class QualificationTransformer {
55
static transformQualifications = (
6-
organization: Organization,
6+
organization: SourceOrganization,
77
): Qualification[] => {
88
// Transform qualification indicators using map
99
const qualifications = QUALIFICATION_INDICATORS.filter(

scripts/transformers/service-transformer.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Service, InternetContact, Organization } from '../types';
1+
import { Service, InternetContact, SourceOrganization } from '../types';
22
import {
33
SERVICE_CATEGORY_MAPPING,
44
EDUCATION_FIELDS,
@@ -8,7 +8,7 @@ import {
88
} from '../constants';
99

1010
export class ServiceTransformer {
11-
static transformServices = (organization: Organization): Service[] => {
11+
static transformServices = (organization: SourceOrganization): Service[] => {
1212
const services: Service[] = [];
1313

1414
// extract service information from various education related fields
@@ -61,17 +61,16 @@ export class ServiceTransformer {
6161
return services;
6262
};
6363

64-
static extractTargetGroups = (organization: Organization) =>
64+
static extractTargetGroups = (organization: SourceOrganization) =>
6565
TARGET_GROUP_FIELDS.map((field) => organization[field])
6666
.filter(Boolean)
6767
.join('; ');
6868

69-
static transformContacts(organization: Organization): InternetContact {
69+
static transformContacts(organization: SourceOrganization): InternetContact {
7070
const contact: InternetContact = {};
7171

7272
// 官网
73-
const website =
74-
organization['机构官网'] || organization.internetContact?.website || '';
73+
const website = organization['机构官网'] || '';
7574

7675
if (website) contact.website = website;
7776

0 commit comments

Comments
 (0)