From de5537260b8013d195a5fe82be4d1613493bfb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E5=90=9B?= <13760614423@163.com> Date: Thu, 20 Aug 2020 22:41:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AF=BC=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++++ package.json | 4 ++-- src/Helper/FundDBHelper.ts | 14 ++++++++++++-- src/features/fundImport.ts | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8d358d3..feabbbb 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ ![Instructions.gif](https://s1.ax1x.com/2020/08/19/dQ8R3t.gif) +### v1.4.0 + +- 优化导入数据 + ### v1.3.9 - 我的自选基金新增支持s前缀搜索过滤自选基金,如s001071 diff --git a/package.json b/package.json index 3d02d96..74eb249 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "utools-fund", - "version": "v1.3.9", + "version": "v1.4.0", "description": "自选基金助手", "main": "main.ts", "scripts": { @@ -25,4 +25,4 @@ "dependencies": { "axios": "^0.19.2" } -} +} \ No newline at end of file diff --git a/src/Helper/FundDBHelper.ts b/src/Helper/FundDBHelper.ts index c5c7e0b..361553e 100644 --- a/src/Helper/FundDBHelper.ts +++ b/src/Helper/FundDBHelper.ts @@ -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 = { _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 = { _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); diff --git a/src/features/fundImport.ts b/src/features/fundImport.ts index 8b7062c..3b88c8a 100644 --- a/src/features/fundImport.ts +++ b/src/features/fundImport.ts @@ -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);