Browse Source

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

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

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

@ -5,17 +5,17 @@ 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;
@ -64,49 +64,55 @@ module.exports = function (app, opts,ctx) {
).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){ if (!isExsit) {
await models.FormDataTable.create({ 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('工单数据抽取结束') console.log('工单数据抽取结束')
}else{ } else {
console.log('未查询到数据') console.log('未查询到数据')
} }
}else{ } else {
console.log('未查询到数据') console.log('未查询到数据')
} }
}catch(error){ } catch (error) {
console.error('失败原因',error) console.error('失败原因', error)
} }
} }
); );

Loading…
Cancel
Save