审批处理样式处理
This commit is contained in:
1 parent
e751661fc9
commit
5f7e5a038f
3 files changed
+262
-127
No files matched your search
+94
-24
@@ -57,15 +57,13 @@ class TaskService extends Service {
|
||||
}
|
||||
|
||||
async buildNext({ taskData, type }) {
|
||||
|
||||
const { userId, username } = this.ctx.userInfo;
|
||||
|
||||
const { taskId, workflowConfig, taskConfigId, taskEditUserList, taskEditedUserList } = taskData;
|
||||
const { taskId, taskWorkflow, taskConfigId, taskEditUserList, taskEditedUserList } = taskData;
|
||||
|
||||
var updateTaskData = null
|
||||
var historyInsertData = []
|
||||
var noticeInsertData = []
|
||||
var curNode = workflowConfig.nodeList.find(node => node.id == taskConfigId)
|
||||
var curNode = taskWorkflow.nodeList.find(node => node.id == taskConfigId)
|
||||
var taskStatus = "running"
|
||||
|
||||
// 1、更新task状态
|
||||
@@ -87,8 +85,8 @@ class TaskService extends Service {
|
||||
} else {// 流转搭配下一节点
|
||||
|
||||
// 找下一个节点
|
||||
var nextNode = await this.getNextNode(workflowConfig, curNode)
|
||||
var nextLine = workflowConfig.lineList.find(line => line.sourceNodeId == nextNode.id)
|
||||
var nextNode = await this.getNextNode(taskWorkflow, curNode)
|
||||
var nextLine = taskWorkflow.lineList.find(line => line.sourceNodeId == nextNode.id)
|
||||
|
||||
// 下一个节点是审批节点
|
||||
if (nextNode.properties.type === "approvalTask") {
|
||||
@@ -106,17 +104,17 @@ class TaskService extends Service {
|
||||
noticeInsertData.push({
|
||||
noticeId: await idGenerateUtil.uuid(),
|
||||
noticeName: "通知-审批-" + taskId,
|
||||
noticeContent: '{}',
|
||||
noticeContent: nextNode.properties.userIdList.join(','),
|
||||
pushContent: '{}',
|
||||
pushStatus: "success",
|
||||
pushAt: dayjs().format("YYYY-MM-DD HH:mm:ss")
|
||||
})
|
||||
historyInsertData.push(await this.createTaskHistory({ taskData, taskStatus, type }))
|
||||
nextNode = await this.getNextNode(workflowConfig, curNode)
|
||||
nextNode = await this.getNextNode(taskWorkflow, curNode)
|
||||
taskData = {
|
||||
...taskData,
|
||||
taskConfigId: nextNode.id,
|
||||
taskEditUserList: null,
|
||||
// taskEditUserList: nextNode.properties.userIdList.join(','),
|
||||
taskEditedUserList: null,
|
||||
taskComment: null,
|
||||
operationAt: dayjs().format("YYYY-MM-DD HH:mm:ss")
|
||||
@@ -165,8 +163,9 @@ class TaskService extends Service {
|
||||
}
|
||||
|
||||
async getNextNode(workflow, curNode) {
|
||||
var line = workflow.lineList.find(l => l.sourceNodeId == curNode.id)
|
||||
var nextNode = workflow.nodeList.find(n => n.id == line.targetNodeId)
|
||||
const { lineList, nodeList } = workflow
|
||||
var line = lineList.find(l => l.sourceNodeId == curNode.id),
|
||||
nextNode = nodeList.find(n => n.id == line.targetNodeId);
|
||||
|
||||
if (nextNode.properties.type === "conditionTask") {
|
||||
nextNode = this.getNextNode(workflow, nextNode)
|
||||
@@ -176,25 +175,96 @@ class TaskService extends Service {
|
||||
}
|
||||
|
||||
async createTaskHistory({ taskData, taskStatus, type }) {
|
||||
const { userId, username } = this.ctx.userInfo;
|
||||
|
||||
// 解构 taskData 对象以简化访问
|
||||
const { taskId, taskFormInput, taskConfigId, taskNextConfigList,
|
||||
taskLineType, taskEditUserList, taskViewUserList,
|
||||
taskComment, taskWorkflow, operationAt } = taskData;
|
||||
|
||||
// 计算任务持续时间
|
||||
const taskCostDuration = Math.round(dayjs().diff(dayjs(operationAt)) / 1000);
|
||||
|
||||
return {
|
||||
taskId: taskData.taskId,
|
||||
taskStatus: taskStatus,
|
||||
taskTitle: taskData.taskTitle,
|
||||
taskFormInput: JSON.stringify(taskData.taskFormInput),
|
||||
taskConfigId: taskData.taskConfigId,
|
||||
taskNextConfigList: taskData.taskNextConfigList,
|
||||
taskLineTypeList: taskData.taskLineType,
|
||||
taskInitUser: taskData.taskInitUser,
|
||||
taskEditUserList: taskData.taskEditUserList,
|
||||
taskViewUserList: taskData.taskViewUserList,
|
||||
taskComment: taskData.taskComment,
|
||||
workflowConfig: JSON.stringify(taskData.taskWorkflow),
|
||||
taskId,
|
||||
taskStatus,
|
||||
taskFormInput: JSON.stringify(taskFormInput),
|
||||
taskConfigId,
|
||||
taskNextConfigList,
|
||||
taskLineTypeList: taskLineType,
|
||||
taskEditUserList,
|
||||
taskViewUserList,
|
||||
taskComment,
|
||||
taskWorkflow: JSON.stringify(taskWorkflow),
|
||||
taskExplain: type,
|
||||
taskHandleDesc: type,
|
||||
taskCostDuration: Math.round(dayjs().diff(dayjs(taskData.operationAt)) / 1000)
|
||||
taskCostDuration,
|
||||
createHistoryBy: userId,
|
||||
createHistoryAt: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async getTaskWorkflow() {
|
||||
const { jianghuKnex } = this.app;
|
||||
const { userId } = this.ctx.userInfo;
|
||||
const { taskId } = this.ctx.request.body.appData.actionData;
|
||||
|
||||
// 获取当前审批
|
||||
const task = await jianghuKnex('task').where({ taskId }).first();
|
||||
const { taskWorkflow, taskConfigId } = task
|
||||
|
||||
// 获取审批流历史
|
||||
const taskHistory = await jianghuKnex('task_history').where({ taskId }).select();
|
||||
// 获取人员
|
||||
const userList = await jianghuKnex('enterprise_user').select()
|
||||
|
||||
var workflowHistory = JSON.parse(taskWorkflow).nodeList.filter(n => !['start', 'end', 'conditionTask'].includes(n.properties.type))
|
||||
.map(node => {
|
||||
const { id, label, userIdList, approvalType } = node.properties
|
||||
|
||||
const userConfig = userIdList?.map(appUserId => {
|
||||
var username = userList.find(u => u.userId == appUserId)?.username,
|
||||
historyRecord = taskHistory.find(h => h.taskConfigId == node.id && h.createHistoryBy == appUserId);
|
||||
|
||||
if (historyRecord) {
|
||||
const { taskComment, taskHandleDesc, createHistoryAt, taskStatus } = historyRecord
|
||||
|
||||
return {
|
||||
userId: userId,
|
||||
username: username,
|
||||
comment: taskComment,
|
||||
handleDesc: taskHandleDesc,
|
||||
createHistoryAt: dayjs(createHistoryAt || '').format('YYYY-MM-DD HH:mm:ss'),
|
||||
taskStatus: taskStatus,
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
userId: userId,
|
||||
username: username,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
var nodeStatus = '审批中'
|
||||
if (approvalType == "或签") {
|
||||
nodeStatus = _.some(userConfig, ['handleDesc', '拒绝']) ? '已拒绝' : _.some(userConfig, ['handleDesc', '同意']) ? '已同意' : '审批中'
|
||||
} else {
|
||||
var nodeStatus = _.some(userConfig, ['handleDesc', '拒绝']) ? '已拒绝' : _.every(userConfig, ['handleDesc', '同意']) ? '已同意' : '审批中'
|
||||
}
|
||||
|
||||
return {
|
||||
id,
|
||||
label,
|
||||
approvalType: approvalType, // 是审批节点就取审批形式
|
||||
userList: userConfig,
|
||||
nodeStatus: nodeStatus
|
||||
}
|
||||
})
|
||||
|
||||
return workflowHistory
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TaskService;
|
||||
Reference in new issue
Block a user