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 moment = require('moment')
|
|||
|
|||
// module.exports = function (app, opts) {
|
|||
// const updateAttendance = app.fs.scheduleInit(
|
|||
// {
|
|||
// interval: '34 21 4 * * *',
|
|||
// // interval: '34 */15 * * * *',
|
|||
// immediate: true,
|
|||
// proRun: true,
|
|||
// },
|
|||
// async()=>{
|
|||
// try{
|
|||
// const startTime = moment()
|
|||
// const { models } = app.fs.dc
|
|||
// const { clickHouse } = app.fs
|
|||
// const { database: camWorkflow } = clickHouse.camWorkflow.opts.config
|
|||
// //工单数据
|
|||
// let workOrderNeedData = {
|
|||
// projectName: {
|
|||
// keyWord: ['项目名称'],
|
|||
// require: true,
|
|||
// },
|
|||
// applyTime: {
|
|||
// keyWord: ['申请时间'],
|
|||
// require: true,
|
|||
// },
|
|||
// completionTime: {
|
|||
// keyWord: ['处理完成时间'],
|
|||
// require: true,
|
|||
// },
|
|||
// state:{
|
|||
// keyWord:[''],
|
|||
// require: true,
|
|||
// },
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
// }
|
|||
// const attendanceRes = await clickHouse.pepEmis.query(
|
|||
// `
|
|||
// SELECT
|
|||
// story.id AS historyId,
|
|||
// story.apply_user AS pepUserId,
|
|||
// story.form_data AS formData,
|
|||
// story.submit_form_data AS submitFormData,
|
|||
// fform.form_schema AS formSchema,
|
|||
// fprocess.name AS processName,
|
|||
// procin.state_ AS state,
|
|||
// 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
|
|||
// ON fprocess.id = fform.process_id
|
|||
// INNER JOIN workflow_group AS fgroup
|
|||
// ON fgroup.id = fprocess.group_id
|
|||
// AND fgroup.name = ''
|
|||
// INNER JOIN ${camWorkflow}.act_hi_procinst AS procin
|
|||
// ON procin.id_ = story.procinst_id`
|
|||
// +` ${existOvertimeCount || existVacateCount ?`WHERE story.create_at > '2023-03-16 00:00:00'`: ''}`
|
|||
// ).toPromise()
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
// }catch(error){
|
|||
|
|||
// }
|
|||
// }
|
|||
// );
|
|||
// return {
|
|||
// updateAttendance,
|
|||
// }
|
|||
// }
|
|||
const schedule = require('node-schedule'); |
|||
const moment = require('moment') |
|||
let isDev = false |
|||
|
|||
module.exports = function (app, opts) { |
|||
const workOrder = app.fs.scheduleInit( |
|||
{ |
|||
interval: '0 * * * *',//一小时执行一次
|
|||
immediate: isDev, |
|||
proRun: !isDev, |
|||
}, |
|||
async()=>{ |
|||
try{ |
|||
//前一次执行时间
|
|||
console.log('工单数据抽取开始') |
|||
let lastExecutionTime = null; |
|||
const { parseProcessData } = app.fs.utils |
|||
const startTime = moment() |
|||
const { models } = app.fs.dc |
|||
const { clickHouse } = app.fs |
|||
const { database: camWorkflow } = clickHouse.camWorkflow.opts.config |
|||
//新建表是否有数据
|
|||
const rescount=await models.FormDataTable.count() |
|||
if (lastExecutionTime === null) { |
|||
lastExecutionTime = moment().subtract(1, 'hour'); |
|||
} |
|||
const formRes = await clickHouse.pepEmis.query( |
|||
`SELECT
|
|||
story.id AS historyId, |
|||
story.procinst_id as procinstId, |
|||
story.apply_user AS pepUserId, |
|||
story.form_data AS formData, |
|||
story.submit_form_data AS submitFormData, |
|||
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 |
|||
ON fprocess.id = fform.process_id |
|||
AND fprocess.name = '运维中台售后问题处理工单' |
|||
INNER JOIN workflow_group AS fgroup |
|||
ON fgroup.id = fprocess.group_id |
|||
INNER JOIN ${camWorkflow}.act_hi_procinst AS procin |
|||
ON procin.id_ = story.procinst_id |
|||
${rescount ?` WHERE procin.end_time_ is not null
|
|||
AND procin.end_time_ > '${lastExecutionTime}' |
|||
AND procin.end_time_ <='${startTime}'` |
|||
: ''}` |
|||
).toPromise() |
|||
console.log('formRes1',formRes) |
|||
const procinstIds = [...new Set(formRes.map(e => e.procinstId))]; |
|||
// 获取流程实例变量
|
|||
if(formRes && formRes.length > 0){ |
|||
let procinstsVariables = await ctx.app.camunda.request.post(encodeURI(`/engine-rest/history/variable-instance`), { |
|||
processInstanceIdIn: procinstIds |
|||
}) |
|||
for (let f of formRes) { |
|||
if(f?.formData?.formData && f?.formData?.workflowProcessVersion?.workflowProcessForm?.formSchema) { |
|||
const parseData = parseProcessData({ |
|||
formSchema: JSON.parse(f.formSchema), |
|||
formData: JSON.parse(f.formData) |
|||
}) |
|||
await models.Workorder.create({ |
|||
projectId:parseData.pomsProjectId.value || null, |
|||
formname:procinstsVariables.find(item=>item.id===f.procinstId).name||null, |
|||
state: f.state||null, |
|||
endTime:f.endTime||null, |
|||
startTime:f.createTime||null |
|||
}) |
|||
console.log('工单数据抽取结束') |
|||
} |
|||
} |
|||
|
|||
} |
|||
}catch(error){ |
|||
console.error(error) |
|||
} |
|||
} |
|||
); |
|||
return { |
|||
workOrder, |
|||
} |
|||
} |
Binary file not shown.
Loading…
Reference in new issue