-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
115 changed files
with
1,137 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ | |
], | ||
"useWorkspaces": true, | ||
"npmClient": "yarn", | ||
"version": "2.5.17-beta.8" | ||
"version": "2.5.17-beta.9" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ | |
"@steedos/service-package-loader": "^2.5" | ||
}, | ||
"devDependencies": { | ||
"moleculer-repl": "^0.7.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,105 @@ | ||
<!-- | ||
* @Author: [email protected] | ||
* @Date: 2021-10-21 09:57:01 | ||
* @LastEditors: sunhaolin@hotoa.com | ||
* @LastEditTime: 2022-07-15 14:18:13 | ||
* @LastEditors: 孙浩林 sunhaolin@steedos.com | ||
* @LastEditTime: 2023-10-27 12:55:47 | ||
* @Description: | ||
--> | ||
## 功能说明 | ||
- 此包是系统设置中的数据导入功能,可通过excel导入对象数据 | ||
|
||
### 提供importData函数支持导入.data.json、.data.csv、.flow.json数据 | ||
### 提供importData action 支持导入{objectname}.data.json、{objectname}.data.csv、{flowApiname}.flow.data.json数据 | ||
|
||
- 比如在自定义的软件包package.service.js中监听系统初始化事件或者服务启动时调用importData导入软件包中的数据: | ||
- 比如在自定义的软件包package.service.js中监听系统初始化事件调用importData导入软件包中的数据: | ||
|
||
```js | ||
const { importData } = require('@steedos/data-import') | ||
const path = require('path') | ||
|
||
module.exports = { | ||
/** | ||
* Events | ||
*/ | ||
events: { | ||
// 系统初始化成功 | ||
'service-cloud-init.succeeded': async function (ctx) { | ||
await importData(path.join(__dirname, 'main', 'default', 'data')); | ||
await this.broker.call("~packages-@steedos/data-import.importData", { | ||
data: { | ||
"csv": csvData, | ||
"json": jsonData, | ||
"flow": flowData, | ||
}, | ||
spaceId, | ||
onlyInsert: true, | ||
}) | ||
} | ||
}, | ||
/** | ||
* Service started lifecycle event handler | ||
*/ | ||
async started() { | ||
await importData(path.join(__dirname, 'main', 'default', 'data')); | ||
}, | ||
}; | ||
``` | ||
|
||
- importData 函数参数说明 | ||
- importData action 参数说明 | ||
```js | ||
/** | ||
* | ||
* @param {*} filePath 要导入数据的文件夹路径 | ||
* @param {*} onlyInsert 仅导入,在导入数据之前先检查,如果存在任意一条记录,则不执行导入,默认true,如果是false, 则如果存在则执行更新操作。 | ||
*/ | ||
export async function importData(filePath: string, onlyInsert: boolean = true) { | ||
// 函数体 | ||
* 参数示例: | ||
{ | ||
data: { | ||
"csv": [{ objectName: 'warehouse', records: [ [Object] ]], | ||
"json": [{ objectName: 'house', records: [ [Object] ]], | ||
"flow": { flowApiName1: {}, flowApiName2: {} }, | ||
}, | ||
spaceId, | ||
onlyInsert: true, | ||
} | ||
*/ | ||
"importData": { | ||
params: { | ||
data: { | ||
type: "object", | ||
props: { | ||
csv: { | ||
type: "array", | ||
items: { | ||
type: "object", | ||
props: { | ||
objectName: { type: "string" }, | ||
records: { type: "array", items: "object" }, | ||
} | ||
}, | ||
optional: true, | ||
}, | ||
json: { | ||
type: "array", | ||
items: { | ||
type: "object", | ||
props: { | ||
objectName: { type: "string" }, | ||
records: { type: "array", items: "object" }, | ||
} | ||
}, | ||
optional: true, | ||
}, | ||
flow: { | ||
type: "object", | ||
optional: true, | ||
}, | ||
} | ||
}, | ||
spaceId: { type: "string" }, | ||
onlyInsert: { type: "boolean", optional: true, default: true }, // 仅新增,在导入数据之前先检查,如果存在任意一条记录,则不执行导入,默认true,如果是false, 则如果存在则执行更新操作。 | ||
}, | ||
async handler(ctx) { | ||
|
||
} | ||
} | ||
``` | ||
``` | ||
## 使用mongodb cli 导出演示数据 | ||
- json: 使用命令导出。例如: `mongoexport --uri="mongodb://192.168.3.31:27017/steedos-apps" --jsonArray --collection=contract_types --out=contract_types.data.json` | ||
- csv: 使用命令导出。例如: `mongoexport --uri="mongodb://192.168.3.31:27017/steedos-apps" --collection=contract_types --type=csv --fields=name,code --out=contract_types.data.csv` | ||
|
||
## 编码要求 | ||
json、csv中文件请使用`utf-8`编码 | ||
|
||
## 示例,导出合同模块数据, 进入`main\default\data`文件夹后执行以下命令 | ||
``` | ||
mongoexport --uri="mongodb://192.168.3.31:27017/steedos-apps" --collection=contract_types --type=csv --fields=name,code --out=contract_types.data.csv | ||
mongoexport --uri="mongodb://192.168.3.31:27017/steedos-apps" --jsonArray --collection=contracts --out=contracts.data.json | ||
``` |
Oops, something went wrong.