Browse Source

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

dev
zhaobing 1 year 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
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'))
console.log('工单数据抽取开始', moment().format('YYYY-MM-DD HH:mm:ss'))
const username = "admin"
const password = "fs-workflow"
let lastExecutionTime = null;
@ -64,49 +64,55 @@ module.exports = function (app, opts,ctx) {
).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`))
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){
.send({ processInstanceIdIn: procinstIds })
if (procinstsVariables.body && procinstsVariables.body.length) {
for (let f of formRes) {
const parseData =f.formSchema&& parseProcessData({
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(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){
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
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('未查询到数据')
}
}else{
} else {
console.log('未查询到数据')
}
}catch(error){
console.error('失败原因',error)
} catch (error) {
console.error('失败原因', error)
}
}
);

Loading…
Cancel
Save