Browse Source

feat:修改工单抽取逻辑

dev
zhaobing 1 year ago
parent
commit
146d2a88ad
  1. 26
      api/app/lib/schedule/workOrder.js

26
api/app/lib/schedule/workOrder.js

@ -25,10 +25,13 @@ module.exports = function (app, opts,ctx) {
const { clickHouse } = app.fs const { clickHouse } = app.fs
const { database: camWorkflow } = clickHouse.camWorkflow.opts.config const { database: camWorkflow } = clickHouse.camWorkflow.opts.config
//新建表是否有数据 //新建表是否有数据
const rescount=await models.FormDataTable.count() // const rescount=await models.FormDataTable.count()
if (lastExecutionTime === null) { if (lastExecutionTime === null) {
lastExecutionTime = moment().subtract(1, 'hour').format('YYYY-MM-DD HH:mm:ss') 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( const formRes = await clickHouse.pepEmis.query(
`SELECT `SELECT
story.id AS historyId, story.id AS historyId,
@ -58,9 +61,7 @@ module.exports = function (app, opts,ctx) {
INNER JOIN ${camWorkflow}.act_hi_procinst AS procin INNER JOIN ${camWorkflow}.act_hi_procinst AS procin
ON procin.id_ = story.procinst_id ON procin.id_ = story.procinst_id
AND procin.state_='COMPLETED' AND procin.state_='COMPLETED'
${rescount ?` WHERE procin.end_time_ is not null
AND procin.end_time_ > '${lastExecutionTime}'
AND procin.end_time_ <='${startTime}'`
: ''}` : ''}`
).toPromise() ).toPromise()
const procinstIds = [...new Set(formRes.map(e => e.procinstId))]; const procinstIds = [...new Set(formRes.map(e => e.procinstId))];
@ -76,17 +77,28 @@ module.exports = function (app, opts,ctx) {
formSchema: JSON.parse(f.formSchema), formSchema: JSON.parse(f.formSchema),
formData: JSON.parse(f.formData) formData: JSON.parse(f.formData)
}) })
const res=await models.FormDataTable.create({ //判断结果是否已经存在目标表中
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
}
})
//如果不存在则插入
if(!isExsit){
await models.FormDataTable.create({
projectId:parseData?parseData.pomsProjectId.value : null, projectId:parseData?parseData.pomsProjectId.value : null,
formname:procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName') ? procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName').value : '', formname:procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName') ? procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName').value : '',
state: f.state||null, state: f.state||null,
endTime:f.endTime||null, endTime:f.endTime||null,
startTime:f.createTime||null startTime:f.createTime||null
}) })
console.log('formRes3',res) }
}
console.log('工单数据抽取结束') console.log('工单数据抽取结束')
}
}else{ }else{
console.log('未查询到数据') console.log('未查询到数据')
} }

Loading…
Cancel
Save