Browse Source

feat:修改工单抽取逻辑

dev
zhaobing 12 months ago
parent
commit
146d2a88ad
  1. 40
      api/app/lib/schedule/workOrder.js

40
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))];
@ -75,18 +76,29 @@ module.exports = function (app, opts,ctx) {
const parseData =f.formSchema&& parseProcessData({ const parseData =f.formSchema&& parseProcessData({
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({ //判断结果是否已经存在目标表中
projectId:parseData?parseData.pomsProjectId.value : null, const isExsit=await models.FormDataTable.findOne({
formname:procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName') ? procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName').value : '', where:{
state: f.state||null, projectId:parseData?parseData.pomsProjectId.value : null,
endTime:f.endTime||null, state: f.state||null,
startTime:f.createTime||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{ }else{
console.log('未查询到数据') console.log('未查询到数据')
} }

Loading…
Cancel
Save