From 146d2a88adbc9b46255f7ab4151a5db6d087a854 Mon Sep 17 00:00:00 2001 From: zhaobing Date: Thu, 25 Jan 2024 16:06:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E6=94=B9=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E6=8A=BD=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/schedule/workOrder.js | 40 ++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/api/app/lib/schedule/workOrder.js b/api/app/lib/schedule/workOrder.js index a308fec..01e020c 100644 --- a/api/app/lib/schedule/workOrder.js +++ b/api/app/lib/schedule/workOrder.js @@ -25,10 +25,13 @@ module.exports = function (app, opts,ctx) { const { clickHouse } = app.fs const { database: camWorkflow } = clickHouse.camWorkflow.opts.config //新建表是否有数据 - const rescount=await models.FormDataTable.count() + // const rescount=await models.FormDataTable.count() if (lastExecutionTime === null) { lastExecutionTime = moment().subtract(1, 'hour').format('YYYY-MM-DD HH:mm:ss') } + // ${rescount ?` WHERE procin.end_time_ is not null + // AND procin.end_time_ > '${lastExecutionTime}' + // AND procin.end_time_ <='${startTime}'` const formRes = await clickHouse.pepEmis.query( `SELECT story.id AS historyId, @@ -58,9 +61,7 @@ module.exports = function (app, opts,ctx) { INNER JOIN ${camWorkflow}.act_hi_procinst AS procin ON procin.id_ = story.procinst_id AND procin.state_='COMPLETED' - ${rescount ?` WHERE procin.end_time_ is not null - AND procin.end_time_ > '${lastExecutionTime}' - AND procin.end_time_ <='${startTime}'` + : ''}` ).toPromise() const procinstIds = [...new Set(formRes.map(e => e.procinstId))]; @@ -75,18 +76,29 @@ module.exports = function (app, opts,ctx) { const parseData =f.formSchema&& parseProcessData({ formSchema: JSON.parse(f.formSchema), formData: JSON.parse(f.formData) - }) - const res=await models.FormDataTable.create({ - projectId:parseData?parseData.pomsProjectId.value : null, - formname:procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName') ? procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName').value : '', - state: f.state||null, - endTime:f.endTime||null, - startTime:f.createTime||null + }) + //判断结果是否已经存在目标表中 + const isExsit=await models.FormDataTable.findOne({ + where:{ + projectId:parseData?parseData.pomsProjectId.value : null, + state: f.state||null, + endTime:f.endTime||null, + startTime:f.createTime||null + } }) - console.log('formRes3',res) - console.log('工单数据抽取结束') - + //如果不存在则插入 + if(!isExsit){ + await models.FormDataTable.create({ + projectId:parseData?parseData.pomsProjectId.value : null, + formname:procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName') ? procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName').value : '', + state: f.state||null, + endTime:f.endTime||null, + startTime:f.createTime||null + }) + } } + console.log('工单数据抽取结束') + }else{ console.log('未查询到数据') }