Skip to content

Commit

Permalink
优化导入数据
Browse files Browse the repository at this point in the history
  • Loading branch information
adams549659584 committed Aug 20, 2020
1 parent 0f9a798 commit de55372
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

![Instructions.gif](https://s1.ax1x.com/2020/08/19/dQ8R3t.gif)

### v1.4.0

- 优化导入数据

### v1.3.9

- 我的自选基金新增支持s前缀搜索过滤自选基金,如s001071
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "utools-fund",
"version": "v1.3.9",
"version": "v1.4.0",
"description": "自选基金助手",
"main": "main.ts",
"scripts": {
Expand All @@ -25,4 +25,4 @@
"dependencies": {
"axios": "^0.19.2"
}
}
}
14 changes: 12 additions & 2 deletions src/Helper/FundDBHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@ const FUND_DB_PRE_FIX = 'fund_';

export default class FundDBHelper {
static set(data: IFundEnt) {
return utools.db.put({
const db: DBItem<IFundEnt> = {
_id: `${FUND_DB_PRE_FIX}${data.id}`,
data,
});
};
const existDB = FundDBHelper.get(data.id);
if (existDB) {
db._rev = existDB._rev;
}
return utools.db.put(db);
}

static setList(data: IFundEnt[]) {
const existDBList = FundDBHelper.getAll();
const dbList = data.map(x => {
const db: DBItem<IFundEnt> = {
_id: `${FUND_DB_PRE_FIX}${x.id}`,
data: x,
};
const existDB = existDBList.find(d => d.data.id === x.id);
if (existDB) {
db._rev = existDB._rev;
}
return db;
});
return utools.db.bulkDocs(dbList);
Expand Down
2 changes: 1 addition & 1 deletion src/features/fundImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const fundImport: TplFeature = {
enter: async (action, callbackSetList) => {
if (action.type === 'files') {
const jsonFile: FilesPayload = action.payload[0];
if (jsonFile.isFile && jsonFile.name === 'fund_data.json') {
if (jsonFile.isFile && jsonFile.name.includes('fund_data.json')) {
const fundJsonStr = readFileSync(jsonFile.path, { encoding: 'utf-8' });
const fundData: IFundEnt[] = JSON.parse(fundJsonStr);
FundDBHelper.setList(fundData);
Expand Down

0 comments on commit de55372

Please sign in to comment.