This commit is contained in:
Xu Chang 2023-01-17 11:40:12 +08:00
commit 60bc45a388
3 changed files with 33 additions and 4 deletions

View File

@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.getImportationTemplate = exports.exportEntity = exports.importEntity = exports.clearPorts = exports.registerPorts = void 0;
const tslib_1 = require("tslib");
const assert_1 = tslib_1.__importDefault(require("assert"));
const xlsx_1 = require("xlsx");
const Importations = {};
const Exportations = {};
function registerPorts(importations, exportations) {
@ -41,12 +42,24 @@ async function importEntity(params, context) {
const entity = params.get('entity');
const file = params.get('file');
const id = params.get('id');
<<<<<<< HEAD
const option = params.get('option');
throw new Error('not implement yet');
=======
const arrayBuffer = await file.arrayBuffer();
const workbook = (0, xlsx_1.read)(arrayBuffer);
const { SheetNames, Sheets } = workbook;
for (const sheetName of SheetNames) {
const sheet = Sheets[sheetName];
const dataList = xlsx_1.utils.sheet_to_json(sheet, {});
console.log(dataList);
}
// throw new Error('not implement yet');
>>>>>>> 8533a93fe25ac6bd0406d879dd47c6c17248957c
}
exports.importEntity = importEntity;
async function exportEntity(params, context) {
throw new Error('not implement yet');
throw new Error('export not implement yet');
}
exports.exportEntity = exportEntity;
async function getImportationTemplate(params, context) {

View File

@ -17,7 +17,8 @@
"dependencies": {
"lodash": "^4.17.21",
"oak-domain": "file:../oak-domain",
"oak-external-sdk": "file:../oak-external-sdk"
"oak-external-sdk": "file:../oak-external-sdk",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@types/node": "^18.0.0",

View File

@ -2,7 +2,7 @@ import assert from 'assert';
import { EntityDict, SelectOption } from 'oak-domain/lib/types/Entity';
import { Importation, Exportation } from 'oak-domain/lib/types/Port';
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
import { read, utils } from 'xlsx';
const Importations: Record<string, any> = {};
const Exportations: Record<string, any> = {};
@ -48,9 +48,24 @@ export async function importEntity<
const entity = params.get('entity') as keyof ED;
const file = params.get('file') as File;
const id = params.get('id') as string;
<<<<<<< HEAD
const option = params.get('option') as Object;
throw new Error('not implement yet');
=======
const arrayBuffer = await file.arrayBuffer();
const workbook = read(arrayBuffer);
const { SheetNames, Sheets } = workbook;
for (const sheetName of SheetNames) {
const sheet = Sheets[sheetName];
const dataList = utils.sheet_to_json(
sheet
);
console.log(dataList);
}
// throw new Error('not implement yet');
>>>>>>> 8533a93fe25ac6bd0406d879dd47c6c17248957c
}
export async function exportEntity<
@ -62,7 +77,7 @@ export async function exportEntity<
id: string;
filter?: ED[T]['Selection']['filter'];
}, context: Cxt): Promise<NodeJS.ReadableStream> {
throw new Error('not implement yet');
throw new Error('export not implement yet');
}
export async function getImportationTemplate<