@gingkoo/base-server 0.0.4-alpha.31 → 0.0.4-alpha.32

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.
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
  const ExcelJS = require('exceljs');
3
3
  const { sse, bgTaskEnum } = require('../common/sse');
4
+ // const { importlog } = require('../common/logger');
4
5
  const fillHeader = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'ff4576B5' } };
5
6
  const fontHeader = {
6
7
  name: 'Arial Black',
@@ -85,9 +86,10 @@ async function _excelImport(filePath, dataModel, mappingData, mappingRules = 'de
85
86
  var worksheet = workbook.getWorksheet(1);
86
87
  let titleRow = worksheet.getRow(1);
87
88
  titleRow.eachCell((cell, colNumber) => {
88
- if (cell.value in colsMap) {
89
+ let colValue = cellToString(cell.value);
90
+ if (colValue in colsMap) {
89
91
  let colId = cell.address.match(/[a-zA-Z]+/g)[0];
90
- colIndex[colId] = colsMap[cell.value];
92
+ colIndex[colId] = colsMap[colValue];
91
93
  }
92
94
  });
93
95
 
@@ -95,21 +97,23 @@ async function _excelImport(filePath, dataModel, mappingData, mappingRules = 'de
95
97
  let row = worksheet.getRow(i);
96
98
  let rec = {};
97
99
  row.eachCell((cell, colNumber) => {
100
+ let colValue = cellToString(cell.value);
101
+
98
102
  let colId = cell.address.match(/[a-zA-Z]+/g)[0];
99
103
  if (colId in colIndex) {
100
104
  let fieldId = colIndex[colId];
101
105
  if (dataModel[fieldId]['source']) {
102
106
  //数据字典字段
103
107
  let mappingId = dataModel[fieldId]['source']?.split('.')[1];
104
- if (mappingData2?.[mappingId]?.data?.[cell.value]) {
105
- rec[colIndex[colId]] = mappingData2?.[mappingId]?.data?.[cell.value];
108
+ if (mappingData2?.[mappingId]?.data?.[colValue]) {
109
+ rec[colIndex[colId]] = mappingData2?.[mappingId]?.data?.[colValue];
106
110
  } else {
107
111
  //数据字典匹配不到
108
- mappingRules != 'strict' ? (rec[colIndex[colId]] = cell.value) : null;
112
+ mappingRules != 'strict' ? (rec[colIndex[colId]] = colValue) : null;
109
113
  }
110
114
  } else {
111
115
  //非数据字典字段
112
- rec[colIndex[colId]] = cell.value;
116
+ rec[colIndex[colId]] = colValue;
113
117
  }
114
118
  }
115
119
  });
@@ -288,9 +292,10 @@ function handleImportData(mapping, titleRow) {
288
292
  }
289
293
 
290
294
  titleRow.eachCell((cell, colNumber) => {
291
- if (cell.value in colsMap) {
295
+ let colValue = cellToString(cell.value);
296
+ if (colValue in colsMap) {
292
297
  let colId = cell.address.match(/[a-zA-Z]+/g)[0];
293
- colIndex[colId] = colsMap[cell.value];
298
+ colIndex[colId] = colsMap[colValue];
294
299
  }
295
300
  });
296
301
 
@@ -307,7 +312,7 @@ function getSheetData(worksheet, mapping, linkColumn, linkWorksheetMap, linkMapp
307
312
  let rec = {};
308
313
  row.eachCell((cell, colNumber) => {
309
314
  let colId = cell.address.match(/[a-zA-Z]+/g)[0];
310
- let colValue = cell.value;
315
+ let colValue = cellToString(cell.value);
311
316
  if (colId in colIndex) {
312
317
  let fieldId = colIndex[colId];
313
318
 
@@ -402,6 +407,35 @@ function manualVLOOKUP(formula, worksheet, workbook) {
402
407
  return result;
403
408
  }
404
409
 
410
+ const cellToString = (value) => {
411
+ if (typeof value == 'string' || typeof value == 'number') {
412
+ return value + '';
413
+ }
414
+
415
+ if (!value) {
416
+ return '';
417
+ }
418
+
419
+ let _value = '';
420
+ if (value.richText) {
421
+ if (Array.isArray(value.richText)) {
422
+ value.richText.forEach((v) => {
423
+ _value += v?.text || '';
424
+ });
425
+ return _value;
426
+ }
427
+ }
428
+
429
+ if (value.error) {
430
+ _value = '';
431
+ }
432
+
433
+ if (value.result) {
434
+ _value = value.result + '';
435
+ }
436
+ return _value;
437
+ };
438
+
405
439
  /**
406
440
  * 导入多 sheet 他只负责拿数据 给业务那边处理
407
441
  * @param {string} filePath
@@ -422,25 +456,17 @@ const _excelImportMultisheet2 = async (filePath = '') => {
422
456
  worksheet.eachRow((row, rowNumber) => {
423
457
  let rowData = [];
424
458
  row.eachCell((cell, colNumber) => {
425
- let colValue = cell.value;
426
-
427
- if (!colValue && colValue !== 0 && colValue?.result) {
428
- colValue = colValue.result;
429
- }
459
+ let colValue = cellToString(cell.value);
430
460
 
431
461
  if (rowNumber == 1) {
432
462
  sheetInfo.header[colNumber - 1] = colValue;
433
463
  } else {
434
464
  if (cell.formula && cell.formula.includes('VLOOKUP')) {
435
465
  colValue = manualVLOOKUP(cell.formula, worksheet, workbook);
466
+
436
467
  if (colValue === null) {
437
468
  colValue = cell.value?.result ?? cell.value; // 降级使用原始值
438
- if (typeof colValue === 'number') {
439
- colValue = colValue.toString();
440
- }
441
- if (!colValue) {
442
- colValue = '';
443
- }
469
+ colValue = cellToString(colValue);
444
470
  }
445
471
  }
446
472
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/base-server",
3
- "version": "0.0.4-alpha.31",
3
+ "version": "0.0.4-alpha.32",
4
4
  "description": "",
5
5
  "main": "app.js",
6
6
  "scripts": {