@gingkoo/base-server 0.0.4-alpha.39 → 0.0.4-alpha.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -330,16 +330,29 @@ const excelImport = async (filePath = '') => {
|
|
|
330
330
|
* @param {string[][]} sheetData sheet 数据
|
|
331
331
|
* @param {object} cols 表头信息 e.g { '表名': {name: string | string[], dict: {[key: string]: string}}, dcitMatch: 'include' | 'equal', dictIgnoreCase: boolean }// name 里面是数据库的 字段名,dict 是字典的 key, dcitMatch是匹配规则 include 包含就行 equal 完全匹配, dictIgnoreCase 是否不区分大小写匹配 默认 false 区分
|
|
332
332
|
* @param {number} options.headerMatchCount 匹配上几个是表头 默认 2 个
|
|
333
|
-
* @param {string} options.uniqueKey 唯一 key
|
|
333
|
+
* @param {string | string[]} options.uniqueKey 唯一 key 这些值不能重复,如果是数组,则表示多个字段组合唯一
|
|
334
334
|
* @param {string[]} options.validKeys 有效值 这些值不能为空
|
|
335
335
|
* @param {(text: string)=> void} options.onLogger 记录日志
|
|
336
336
|
*/
|
|
337
337
|
function getSheetData(sheetName, sheetData, cols, options = {}) {
|
|
338
338
|
let headerMatchCount = options?.headerMatchCount || 2;
|
|
339
|
-
let uniqueKey = options?.uniqueKey ||
|
|
339
|
+
let uniqueKey = options?.uniqueKey || [];
|
|
340
340
|
let validKeys = options?.validKeys || [];
|
|
341
|
-
if (uniqueKey
|
|
342
|
-
|
|
341
|
+
if (typeof uniqueKey === 'string') {
|
|
342
|
+
uniqueKey = [uniqueKey];
|
|
343
|
+
}
|
|
344
|
+
if (!Array.isArray(uniqueKey)) {
|
|
345
|
+
uniqueKey = [];
|
|
346
|
+
}
|
|
347
|
+
if (!Array.isArray(validKeys)) {
|
|
348
|
+
validKeys = [];
|
|
349
|
+
}
|
|
350
|
+
if (uniqueKey.length) {
|
|
351
|
+
uniqueKey.forEach((it) => {
|
|
352
|
+
if (!validKeys.includes(it)) {
|
|
353
|
+
validKeys.push(it);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
343
356
|
}
|
|
344
357
|
let onLogger = options?.onLogger || function () {};
|
|
345
358
|
let headerKeys = Object.keys(cols);
|
|
@@ -440,15 +453,24 @@ function getSheetData(sheetName, sheetData, cols, options = {}) {
|
|
|
440
453
|
}
|
|
441
454
|
}
|
|
442
455
|
|
|
443
|
-
if (uniqueKey) {
|
|
456
|
+
if (uniqueKey.length) {
|
|
457
|
+
let key = uniqueKey
|
|
458
|
+
.map((it) => {
|
|
459
|
+
return row[it] ?? '';
|
|
460
|
+
})
|
|
461
|
+
.join('-_-');
|
|
444
462
|
// 存在唯一 key 检查
|
|
445
|
-
if (uniques.includes(
|
|
463
|
+
if (uniques.includes(key)) {
|
|
446
464
|
onLogger(
|
|
447
|
-
`{danger|${sheetName}} sheet 第 ${i + headerIndex + 2} 行 解析失败,原因:{danger|${
|
|
465
|
+
`{danger|${sheetName}} sheet 第 ${i + headerIndex + 2} 行 解析失败,原因:{danger|${uniqueKey
|
|
466
|
+
.map((it) => {
|
|
467
|
+
return sheetColNameMap[it];
|
|
468
|
+
})
|
|
469
|
+
.join('+')}} 列的值重复`,
|
|
448
470
|
);
|
|
449
471
|
return false;
|
|
450
472
|
} else {
|
|
451
|
-
uniques.push(
|
|
473
|
+
uniques.push(key);
|
|
452
474
|
}
|
|
453
475
|
}
|
|
454
476
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gingkoo/base-server",
|
|
3
|
-
"version": "0.0.4-alpha.
|
|
3
|
+
"version": "0.0.4-alpha.40",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"serve": "nodemon serve -p 1000",
|
|
10
10
|
"check": "node scripts/check_publish.js",
|
|
11
11
|
"clean": "rimraf dist",
|
|
12
|
-
"prepublishOnly": "npm run check
|
|
12
|
+
"prepublishOnly": "npm run check "
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|