|
|
@ -5,19 +5,19 @@ const request = require('superagent'); |
|
|
|
|
|
|
|
let isDev = false |
|
|
|
|
|
|
|
module.exports = function (app, opts,ctx) { |
|
|
|
module.exports = function (app, opts, ctx) { |
|
|
|
const workOrder = app.fs.scheduleInit( |
|
|
|
{ |
|
|
|
interval: '0 * * * *',//一小时执行一次
|
|
|
|
immediate: isDev, |
|
|
|
proRun: !isDev, |
|
|
|
}, |
|
|
|
async()=>{ |
|
|
|
try{ |
|
|
|
async () => { |
|
|
|
try { |
|
|
|
//前一次执行时间
|
|
|
|
console.log('工单数据抽取开始',moment().format('YYYY-MM-DD HH:mm:ss')) |
|
|
|
const username = "admin" |
|
|
|
const password = "fs-workflow" |
|
|
|
console.log('工单数据抽取开始', moment().format('YYYY-MM-DD HH:mm:ss')) |
|
|
|
const username = "admin" |
|
|
|
const password = "fs-workflow" |
|
|
|
let lastExecutionTime = null; |
|
|
|
const { parseProcessData } = app.fs.utils |
|
|
|
const startTime = moment().format('YYYY-MM-DD HH:mm:ss') |
|
|
@ -28,7 +28,7 @@ module.exports = function (app, opts,ctx) { |
|
|
|
// 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}'`
|
|
|
@ -62,54 +62,60 @@ module.exports = function (app, opts,ctx) { |
|
|
|
ON procin.id_ = story.procinst_id |
|
|
|
AND procin.state_='COMPLETED'` |
|
|
|
).toPromise() |
|
|
|
const procinstIds = [...new Set(formRes.map(e => e.procinstId))]; |
|
|
|
// 获取流程实例变量
|
|
|
|
if(formRes && formRes.length > 0){ |
|
|
|
let procinstsVariables = await request.post(encodeURI(opts.camundarest.host+'/'+opts.camundarest.root+`/engine-rest/history/variable-instance`)) |
|
|
|
.auth(username, password) |
|
|
|
.set('Content-Type', 'application/json') |
|
|
|
.send({processInstanceIdIn: procinstIds}) |
|
|
|
if(procinstsVariables.body&&procinstsVariables.body.length){ |
|
|
|
for (let f of formRes) { |
|
|
|
const parseData =f.formSchema&& parseProcessData({ |
|
|
|
formSchema: JSON.parse(f.formSchema), |
|
|
|
formData: JSON.parse(f.formData) |
|
|
|
}) |
|
|
|
//判断结果是否已经存在目标表中
|
|
|
|
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, |
|
|
|
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('工单数据抽取结束') |
|
|
|
const procinstIds = [...new Set(formRes.map(e => e.procinstId))]; |
|
|
|
// 获取流程实例变量
|
|
|
|
if (formRes && formRes.length > 0) { |
|
|
|
let procinstsVariables = await request.post(encodeURI(opts.camundarest.host + '/' + opts.camundarest.root + `/engine-rest/history/variable-instance`)) |
|
|
|
.auth(username, password) |
|
|
|
.set('Content-Type', 'application/json') |
|
|
|
.send({ processInstanceIdIn: procinstIds }) |
|
|
|
if (procinstsVariables.body && procinstsVariables.body.length) { |
|
|
|
for (let f of formRes) { |
|
|
|
const parseData = f.formSchema && parseProcessData({ |
|
|
|
formSchema: JSON.parse(f.formSchema), |
|
|
|
formData: JSON.parse(f.formData) |
|
|
|
}) |
|
|
|
//判断结果是否已经存在目标表中
|
|
|
|
if(parseData){ |
|
|
|
if(parseData.pomsProjectId.value){ |
|
|
|
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, |
|
|
|
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('未查询到数据') |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
console.log('未查询到数据') |
|
|
|
} |
|
|
|
}catch(error){ |
|
|
|
console.error('失败原因',error) |
|
|
|
} else { |
|
|
|
console.log('未查询到数据') |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
console.log('未查询到数据') |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('失败原因', error) |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
return { |
|
|
|
workOrder, |
|
|
|
} |
|
|
|