zhaobing’
1 year ago
14 changed files with 341 additions and 136 deletions
@ -0,0 +1,70 @@ |
|||||
|
/* eslint-disable*/ |
||||
|
|
||||
|
'use strict'; |
||||
|
|
||||
|
module.exports = dc => { |
||||
|
const DataTypes = dc.ORM; |
||||
|
const sequelize = dc.orm; |
||||
|
const FormDataTable = sequelize.define("formDataTable", { |
||||
|
id: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
defaultValue: "nextval(\"formDataTable_id_seq\"::regclass)", |
||||
|
comment: "id", |
||||
|
primaryKey: true, |
||||
|
field: "id", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
projectId: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "项目id", |
||||
|
primaryKey: false, |
||||
|
field: "project_id", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
formname: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "工单名称", |
||||
|
primaryKey: false, |
||||
|
field: "formname", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
startTime: { |
||||
|
type: DataTypes.DATE, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "开始时间", |
||||
|
primaryKey: false, |
||||
|
field: "start_time", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
endTime: { |
||||
|
type: DataTypes.DATE, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "结束时间", |
||||
|
primaryKey: false, |
||||
|
field: "end_time", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
state: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "state", |
||||
|
autoIncrement: false |
||||
|
} |
||||
|
}, { |
||||
|
tableName: "form_data_table", |
||||
|
comment: "", |
||||
|
indexes: [] |
||||
|
}); |
||||
|
dc.models.FormDataTable = FormDataTable; |
||||
|
return FormDataTable; |
||||
|
}; |
@ -1,116 +1,94 @@ |
|||||
|
|
||||
// const schedule = require('node-schedule');
|
const schedule = require('node-schedule'); |
||||
// const moment = require('moment')
|
const moment = require('moment') |
||||
|
let isDev = false |
||||
// module.exports = function (app, opts) {
|
|
||||
// const updateAttendance = app.fs.scheduleInit(
|
module.exports = function (app, opts) { |
||||
// {
|
const workOrder = app.fs.scheduleInit( |
||||
// interval: '34 21 4 * * *',
|
{ |
||||
// // interval: '34 */15 * * * *',
|
interval: '0 * * * *',//一小时执行一次
|
||||
// immediate: true,
|
immediate: isDev, |
||||
// proRun: true,
|
proRun: !isDev, |
||||
// },
|
}, |
||||
// async()=>{
|
async()=>{ |
||||
// try{
|
try{ |
||||
// const startTime = moment()
|
//前一次执行时间
|
||||
// const { models } = app.fs.dc
|
console.log('工单数据抽取开始') |
||||
// const { clickHouse } = app.fs
|
let lastExecutionTime = null; |
||||
// const { database: camWorkflow } = clickHouse.camWorkflow.opts.config
|
const { parseProcessData } = app.fs.utils |
||||
// //工单数据
|
const startTime = moment() |
||||
// let workOrderNeedData = {
|
const { models } = app.fs.dc |
||||
// projectName: {
|
const { clickHouse } = app.fs |
||||
// keyWord: ['项目名称'],
|
const { database: camWorkflow } = clickHouse.camWorkflow.opts.config |
||||
// require: true,
|
//新建表是否有数据
|
||||
// },
|
const rescount=await models.FormDataTable.count() |
||||
// applyTime: {
|
if (lastExecutionTime === null) { |
||||
// keyWord: ['申请时间'],
|
lastExecutionTime = moment().subtract(1, 'hour'); |
||||
// require: true,
|
} |
||||
// },
|
const formRes = await clickHouse.pepEmis.query( |
||||
// completionTime: {
|
`SELECT
|
||||
// keyWord: ['处理完成时间'],
|
story.id AS historyId, |
||||
// require: true,
|
story.procinst_id as procinstId, |
||||
// },
|
story.apply_user AS pepUserId, |
||||
// state:{
|
story.form_data AS formData, |
||||
// keyWord:[''],
|
story.submit_form_data AS submitFormData, |
||||
// require: true,
|
story.create_at as createTime, |
||||
// },
|
fform.form_schema AS formSchema, |
||||
|
fprocess.name AS processName, |
||||
|
procin.state_ AS state, |
||||
|
procin.end_time_ as endTime, |
||||
|
fform.id AS formId, |
||||
|
fversion.id AS versionId, |
||||
|
fgroup.name AS groupName |
||||
|
FROM |
||||
|
workflow_process_history AS story |
||||
|
INNER JOIN workflow_process_version AS fversion |
||||
|
ON fversion.id = story.version_id |
||||
|
INNER JOIN workflow_process_form AS fform |
||||
|
ON fform.id = fversion.form_id |
||||
// }
|
INNER JOIN workflow_process AS fprocess |
||||
// const attendanceRes = await clickHouse.pepEmis.query(
|
ON fprocess.id = fform.process_id |
||||
// `
|
AND fprocess.name = '运维中台售后问题处理工单' |
||||
// SELECT
|
INNER JOIN workflow_group AS fgroup |
||||
// story.id AS historyId,
|
ON fgroup.id = fprocess.group_id |
||||
// story.apply_user AS pepUserId,
|
INNER JOIN ${camWorkflow}.act_hi_procinst AS procin |
||||
// story.form_data AS formData,
|
ON procin.id_ = story.procinst_id |
||||
// story.submit_form_data AS submitFormData,
|
${rescount ?` WHERE procin.end_time_ is not null
|
||||
// fform.form_schema AS formSchema,
|
AND procin.end_time_ > '${lastExecutionTime}' |
||||
// fprocess.name AS processName,
|
AND procin.end_time_ <='${startTime}'` |
||||
// procin.state_ AS state,
|
: ''}` |
||||
// fform.id AS formId,
|
).toPromise() |
||||
// fversion.id AS versionId,
|
console.log('formRes1',formRes) |
||||
// fgroup.name AS groupName
|
const procinstIds = [...new Set(formRes.map(e => e.procinstId))]; |
||||
// FROM
|
// 获取流程实例变量
|
||||
// workflow_process_history AS story
|
if(formRes && formRes.length > 0){ |
||||
// INNER JOIN workflow_process_version AS fversion
|
let procinstsVariables = await ctx.app.camunda.request.post(encodeURI(`/engine-rest/history/variable-instance`), { |
||||
// ON fversion.id = story.version_id
|
processInstanceIdIn: procinstIds |
||||
// INNER JOIN workflow_process_form AS fform
|
}) |
||||
// ON fform.id = fversion.form_id
|
for (let f of formRes) { |
||||
// INNER JOIN workflow_process AS fprocess
|
if(f?.formData?.formData && f?.formData?.workflowProcessVersion?.workflowProcessForm?.formSchema) { |
||||
// ON fprocess.id = fform.process_id
|
const parseData = parseProcessData({ |
||||
// INNER JOIN workflow_group AS fgroup
|
formSchema: JSON.parse(f.formSchema), |
||||
// ON fgroup.id = fprocess.group_id
|
formData: JSON.parse(f.formData) |
||||
// AND fgroup.name = ''
|
}) |
||||
// INNER JOIN ${camWorkflow}.act_hi_procinst AS procin
|
await models.Workorder.create({ |
||||
// ON procin.id_ = story.procinst_id`
|
projectId:parseData.pomsProjectId.value || null, |
||||
// +` ${existOvertimeCount || existVacateCount ?`WHERE story.create_at > '2023-03-16 00:00:00'`: ''}`
|
formname:procinstsVariables.find(item=>item.id===f.procinstId).name||null, |
||||
// ).toPromise()
|
state: f.state||null, |
||||
|
endTime:f.endTime||null, |
||||
|
startTime:f.createTime||null |
||||
|
}) |
||||
|
console.log('工单数据抽取结束') |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
}catch(error){ |
||||
|
console.error(error) |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
return { |
||||
|
workOrder, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
// }catch(error){
|
|
||||
|
|
||||
// }
|
|
||||
// }
|
|
||||
// );
|
|
||||
// return {
|
|
||||
// updateAttendance,
|
|
||||
// }
|
|
||||
// }
|
|
Binary file not shown.
Loading…
Reference in new issue