Browse Source

feat:过滤工单抽取的关联项目为空的记录

dev
zhaobing 12 months ago
parent
commit
e82a6f8567
  1. 110
      api/app/lib/schedule/workOrder.js

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

@ -5,19 +5,19 @@ const request = require('superagent');
let isDev = false let isDev = false
module.exports = function (app, opts,ctx) { module.exports = function (app, opts, ctx) {
const workOrder = app.fs.scheduleInit( const workOrder = app.fs.scheduleInit(
{ {
interval: '0 * * * *',//一小时执行一次 interval: '0 * * * *',//一小时执行一次
immediate: isDev, immediate: isDev,
proRun: !isDev, proRun: !isDev,
}, },
async()=>{ async () => {
try{ try {
//前一次执行时间 //前一次执行时间
console.log('工单数据抽取开始',moment().format('YYYY-MM-DD HH:mm:ss')) console.log('工单数据抽取开始', moment().format('YYYY-MM-DD HH:mm:ss'))
const username = "admin" const username = "admin"
const password = "fs-workflow" const password = "fs-workflow"
let lastExecutionTime = null; let lastExecutionTime = null;
const { parseProcessData } = app.fs.utils const { parseProcessData } = app.fs.utils
const startTime = moment().format('YYYY-MM-DD HH:mm:ss') 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() // 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 // ${rescount ?` WHERE procin.end_time_ is not null
// AND procin.end_time_ > '${lastExecutionTime}' // AND procin.end_time_ > '${lastExecutionTime}'
// AND procin.end_time_ <='${startTime}'` // AND procin.end_time_ <='${startTime}'`
@ -62,54 +62,60 @@ module.exports = function (app, opts,ctx) {
ON procin.id_ = story.procinst_id ON procin.id_ = story.procinst_id
AND procin.state_='COMPLETED'` AND procin.state_='COMPLETED'`
).toPromise() ).toPromise()
const procinstIds = [...new Set(formRes.map(e => e.procinstId))]; const procinstIds = [...new Set(formRes.map(e => e.procinstId))];
// 获取流程实例变量 // 获取流程实例变量
if(formRes && formRes.length > 0){ if (formRes && formRes.length > 0) {
let procinstsVariables = await request.post(encodeURI(opts.camundarest.host+'/'+opts.camundarest.root+`/engine-rest/history/variable-instance`)) let procinstsVariables = await request.post(encodeURI(opts.camundarest.host + '/' + opts.camundarest.root + `/engine-rest/history/variable-instance`))
.auth(username, password) .auth(username, password)
.set('Content-Type', 'application/json') .set('Content-Type', 'application/json')
.send({processInstanceIdIn: procinstIds}) .send({ processInstanceIdIn: procinstIds })
if(procinstsVariables.body&&procinstsVariables.body.length){ if (procinstsVariables.body && procinstsVariables.body.length) {
for (let f of formRes) { for (let f of formRes) {
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 isExsit=await models.FormDataTable.findOne({ if(parseData){
where:{ if(parseData.pomsProjectId.value){
projectId:parseData?parseData.pomsProjectId.value : null, const isExsit = await models.FormDataTable.findOne({
state: f.state||null, where: {
endTime:f.endTime||null, projectId: parseData ? parseData.pomsProjectId.value : null,
startTime:f.createTime||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, if (!isExsit) {
formname:procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName') ? procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName').value : '', await models.FormDataTable.create({
state: f.state||null, projectId: parseData ? parseData.pomsProjectId.value : null,
endTime:f.endTime||null, formname: procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName') ? procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName').value : '',
startTime:f.createTime||null state: f.state || null,
}) endTime: f.endTime || null,
} startTime: f.createTime || null
} })
console.log('工单数据抽取结束') }
}
}
}
console.log('工单数据抽取结束')
}else{ } else {
console.log('未查询到数据') console.log('未查询到数据')
} }
}else{ } else {
console.log('未查询到数据') console.log('未查询到数据')
} }
}catch(error){ } catch (error) {
console.error('失败原因',error) console.error('失败原因', error)
} }
} }
); );
return { return {
workOrder, workOrder,
} }

Loading…
Cancel
Save