zhaobing’
1 year ago
9 changed files with 221 additions and 4 deletions
@ -0,0 +1,113 @@ |
|||||
|
'use strict'; |
||||
|
// const moment = require('moment');
|
||||
|
// const CamundaApi = require('../../utils/camunda-api');
|
||||
|
|
||||
|
//运维相关的待办事项
|
||||
|
async function getUnfinished (ctx) { |
||||
|
const { models } = ctx.fs.dc |
||||
|
const { clickHouse } = ctx.app.fs |
||||
|
const userInfo = ctx.fs.api.userInfo; |
||||
|
// const { camundaUserId } =ctx.fs.api
|
||||
|
const assignee='fsUser'+userInfo.pepUserId |
||||
|
const BeforeAssignUser='fsBeforeAssignUser'+userInfo.pepUserId |
||||
|
const AfterAssignUser='fsAfterAssignUser'+userInfo.pepUserId |
||||
|
|
||||
|
try{ |
||||
|
let all=await clickHouse.camWorkflow.query(` |
||||
|
SELECT DISTINCT * |
||||
|
FROM ( |
||||
|
SELECT * |
||||
|
FROM ( |
||||
|
SELECT DISTINCT RES.* |
||||
|
FROM act_hi_taskinst RES, act_hi_procinst PRO |
||||
|
WHERE 1 = 1 |
||||
|
AND RES.end_time_ IS NULL |
||||
|
AND 1 = 1 |
||||
|
AND RES.assignee_ = '${assignee}' |
||||
|
AND RES.proc_inst_id_ = PRO.proc_inst_id_ |
||||
|
AND PRO.business_key_ in ('160','159') |
||||
|
) RES |
||||
|
UNION ALL |
||||
|
SELECT * |
||||
|
FROM ( |
||||
|
SELECT DISTINCT RES.* |
||||
|
FROM act_hi_taskinst RES |
||||
|
WHERE 1 = 1 |
||||
|
AND RES.end_time_ IS NULL |
||||
|
AND 1 = 1 |
||||
|
AND RES.id_ IN ( |
||||
|
SELECT id_ |
||||
|
FROM act_hi_varinst VAR |
||||
|
WHERE name_ IN ('${BeforeAssignUser}','${AfterAssignUser}') |
||||
|
AND var_type_ IS NOT NULL |
||||
|
AND var_type_ = 'string' |
||||
|
AND text_ IS NOT NULL |
||||
|
AND text_ = 'pending' |
||||
|
) |
||||
|
) RES |
||||
|
) AS res; |
||||
|
`).toPromise()
|
||||
|
const procinstIds = [...new Set(all.map(e => e.proc_inst_id_))]; |
||||
|
// 获取流程实例变量
|
||||
|
if(all && all.length > 0){ |
||||
|
let procinstsVariables = await ctx.app.camunda.request.post(encodeURI(`/engine-rest/history/variable-instance`), { |
||||
|
processInstanceIdIn: procinstIds |
||||
|
}) |
||||
|
let data = { list: all, procinstsVariables: procinstsVariables, keywords: null, userInfo: userInfo, userId: userInfo.pepUserId }; |
||||
|
ctx.body = { count: countFilters(data) } |
||||
|
}else { |
||||
|
ctx.body = { count: 0 }; |
||||
|
} |
||||
|
ctx.status = 200 |
||||
|
}catch(error){ |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
message: typeof error == 'string' ? error : undefined |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function countFilters(data) { |
||||
|
let totalCount = 0; |
||||
|
// let searchKeywords = data.keywords ? data.keywords.toLowerCase() : null;
|
||||
|
let keywordsFlag = false; |
||||
|
data.list.map(e => { |
||||
|
let curVariables = data.procinstsVariables.body && data.procinstsVariables.body.filter(item => item.processInstanceId === e.processInstanceId); |
||||
|
keywordsFlag = false; |
||||
|
const isAssignee = e.assignee === `fsUser${data.userId}`; |
||||
|
if (isAssignee) { |
||||
|
//当前节点任务的办理人是自己才会过滤是否有前后加签
|
||||
|
const fsAfterAssignUnNum = curVariables.find(v => (v.name == 'fsAfterAssignUnNum' && e.id == v.taskId)) ? true : false; |
||||
|
const fsBeforeAssignUnNum = curVariables.find(v => (v.name == 'fsBeforeAssignUnNum' && e.id == v.taskId)) ? curVariables.find(v => (v.name == 'fsBeforeAssignUnNum' && e.id == v.taskId)) : false; |
||||
|
//需要过滤一下前后加签,如果是当前用户的任务但是操作过前后加签不显示代办任务里
|
||||
|
if (fsBeforeAssignUnNum) { |
||||
|
//存在前加签判断是否前加签的人员已经处理完了
|
||||
|
if (fsBeforeAssignUnNum.value === 0) { keywordsFlag = true; }; |
||||
|
} else { |
||||
|
//判断是否存在后加签,有后加签就不显示当前用户的待办任务
|
||||
|
if (!fsAfterAssignUnNum) { keywordsFlag = true; } |
||||
|
} |
||||
|
} else { |
||||
|
keywordsFlag = true; |
||||
|
} |
||||
|
if (keywordsFlag) { |
||||
|
//暂未用到关键词传参
|
||||
|
// if (searchKeywords) {
|
||||
|
// const fsFormItemName = curVariables.find(t => t.name == 'fsFormItemName') ? curVariables.find(t => t.name == 'fsFormItemName').value : '';
|
||||
|
// const fsEmisApplyUserName = curVariables.find(t => t.name == 'fsEmisApplyUserName') ? curVariables.find(t => t.name == 'fsEmisApplyUserName').value : '';
|
||||
|
// if (!((fsFormItemName && fsFormItemName.toLowerCase().includes(searchKeywords)) || (fsEmisApplyUserName.includes(searchKeywords))
|
||||
|
// )) {
|
||||
|
// totalCount++;
|
||||
|
// }
|
||||
|
// } else {
|
||||
|
totalCount++; |
||||
|
// }
|
||||
|
} |
||||
|
}); |
||||
|
return totalCount; |
||||
|
} |
||||
|
|
||||
|
module.exports = { |
||||
|
getUnfinished |
||||
|
}; |
@ -0,0 +1,71 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const request = require('superagent'); |
||||
|
|
||||
|
function factory(app, router, opts) { |
||||
|
return async function (ctx, next) { |
||||
|
const apiRoot = `${opts.host}/${opts.root}`; |
||||
|
|
||||
|
const username = ctx.fs.api.camundaUserId ? ctx.fs.api.camundaUserId : "admin"; |
||||
|
const password = ctx.fs.api.password ? ctx.fs.api.password : "fs-workflow"; |
||||
|
|
||||
|
// console.log('[camunda-rest] ctx.fs.api:', JSON.stringify(ctx.fs.api))
|
||||
|
console.log('[camunda-rest] ctx.fs.api.camundaUserId:', ctx.fs.api.camundaUserId) |
||||
|
const req = { |
||||
|
get: (url, query) => { |
||||
|
return request |
||||
|
.get(`${apiRoot}${url}`) |
||||
|
.query(query) |
||||
|
.auth(username, password); |
||||
|
}, |
||||
|
post: (url, data, query, userId) => { |
||||
|
if(url.indexOf('engine-rest/task') != -1 && url.indexOf('variables') != -1) { |
||||
|
console.log(` |
||||
|
\n批量转办\n |
||||
|
url ${apiRoot}${url}\n |
||||
|
query ${query}\n |
||||
|
auth |
||||
|
username ${userId && `fsUser${userId}` || username}\n |
||||
|
pwd ${userId && `workflow-${userId}` || password}\n |
||||
|
data ${JSON.stringify(data)} |
||||
|
`)
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
return request |
||||
|
.post(`${apiRoot}${url}`) |
||||
|
.query(query) |
||||
|
.auth(userId && `fsUser${userId}` || username, |
||||
|
userId && `workflow-${userId}` || password) |
||||
|
.set('Content-Type', 'application/json') |
||||
|
.send(data); |
||||
|
}, |
||||
|
|
||||
|
put: (url, data, userId) => { |
||||
|
return request |
||||
|
.put(`${apiRoot}${url}`) |
||||
|
.auth(userId && `fsUser${userId}` || username, |
||||
|
userId && `workflow-${userId}` || password) |
||||
|
.set('Content-Type', 'application/json') |
||||
|
.send(data); |
||||
|
}, |
||||
|
|
||||
|
delete: (url, userId) => { |
||||
|
return request |
||||
|
.del(`${apiRoot}${url}`) |
||||
|
.auth(userId && `fsUser${userId}` || username, |
||||
|
userId && `workflow-${userId}` || password); |
||||
|
}, |
||||
|
deploy: (url, file) => { |
||||
|
return request.post(`${apiRoot}${url}`).auth(username, password).attach('file', file); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
app.camunda = app.camunda || {}; |
||||
|
app.camunda.request = req; |
||||
|
|
||||
|
await next(); |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
module.exports = factory; |
@ -0,0 +1,10 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
|
||||
|
const form = require('../../controllers/form'); |
||||
|
|
||||
|
module.exports = function (app, router, opts) { |
||||
|
app.fs.api.logAttr['GET/unfinished'] = { content: '表单待办事项', visible: true }; |
||||
|
router.get('/unfinished', form.getUnfinished); |
||||
|
|
||||
|
}; |
Loading…
Reference in new issue