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('未查询到数据') }