fix审批流转逻辑

This commit is contained in:
ChenXinXin committed 2024-05-09 16:04:07 +08:00
1 parent e31835cc13
commit fb714c0ea8
2 files changed
+47 -19

No files matched your search

+43 -16
View File
@@ -56,6 +56,7 @@ class TaskService extends Service {
})
}
// TODO:逻辑待优化
async buildNext({ taskData, type }) {
const { userId, username } = this.ctx.userInfo;
const { taskId, taskWorkflow, taskConfigId, taskEditUserList, taskEditedUserList } = taskData;
@@ -66,6 +67,8 @@ class TaskService extends Service {
var curNode = taskWorkflow.nodeList.find(node => node.id == taskConfigId)
var taskStatus = "running"
taskData.createHistoryBy = userId
// 1、更新task状态
if (type == '同意') {
var approvalType = curNode.properties.approvalType
@@ -73,14 +76,13 @@ class TaskService extends Service {
var editedUserList = taskEditedUserList && taskEditedUserList.split(',') || []
// 判断该节点是否已完成
if ((approvalType == "会签" || approvalType == "依次审批") && editUserList.length > 1) {
if (curNode.id.startsWith('approvalTask') && (approvalType == "会签" || approvalType == "依次审批") && editUserList.length > 1) {
// 未完成
editedUserList.push(userId)
updateTaskData = {
taskEditUserList: editUserList.filter(u => u != userId).join(','),
taskEditedUserList: editedUserList.join(','),
}
historyInsertData.push(await this.createTaskHistory({ taskData, taskStatus, type }))
} else {// 流转搭配下一节点
@@ -102,6 +104,19 @@ class TaskService extends Service {
}
// 下一个节点是抄送节点
if (nextNode.properties.type === "noticeTask") {
historyInsertData.push(await this.createTaskHistory({ taskData, taskStatus, type }))
taskData = {
...taskData,
taskConfigId: nextNode.id,
taskEditUserList: nextNode.properties.userIdList.join(','),
taskEditedUserList: null,
taskComment: null,
taskExplain: '抄送节点',
taskHandleDesc: '抄送',
taskLineTypeList: '抄送',
operationAt: dayjs().format("YYYY-MM-DD HH:mm:ss")
}
noticeInsertData.push({
noticeId: await idGenerateUtil.uuid(),
@@ -112,19 +127,25 @@ class TaskService extends Service {
pushAt: dayjs().format("YYYY-MM-DD HH:mm:ss")
})
historyInsertData.push(await this.createTaskHistory({ taskData, taskStatus, type }))
nextNode = await this.getNextNode(taskWorkflow, curNode)
var noticeUser = nextNode.properties.userIdList
for (let index = 0; index < noticeUser.length; index++) {
const element = noticeUser[index];
taskData.createHistoryBy = element
historyInsertData.push(await this.createTaskHistory({ taskData, taskStatus, type }))
}
taskData = {
...taskData,
taskConfigId: nextNode.id,
taskEditUserList: nextNode.properties.userIdList.join(','),
taskEditUserList: null,
taskEditedUserList: null,
taskComment: null,
taskExplain: null,
taskHandleDesc: null,
taskLineTypeList: null,
operationAt: dayjs().format("YYYY-MM-DD HH:mm:ss")
}
const result = await this.buildNext({ taskData, type })
const result = await this.buildNext({ taskData, type: 'end' })
updateTaskData = result.updateTaskData
historyInsertData.push(...result.historyInsertData)
noticeInsertData.push(...result.noticeInsertData)
@@ -184,7 +205,8 @@ class TaskService extends Service {
// 解构 taskData 对象以简化访问
const { taskId, taskFormInput, taskConfigId, taskNextConfigList,
taskLineType, taskEditUserList, taskViewUserList,
taskComment, taskWorkflow, operationAt } = taskData;
taskComment, taskWorkflow, operationAt, createHistoryBy,
taskHandleDesc, taskExplain, taskLineTypeList } = taskData;
// 计算任务持续时间
const taskCostDuration = Math.round(dayjs().diff(dayjs(operationAt)) / 1000);
@@ -195,15 +217,15 @@ class TaskService extends Service {
taskFormInput: JSON.stringify(taskFormInput),
taskConfigId,
taskNextConfigList,
taskLineTypeList: taskLineType,
taskLineTypeList: taskLineTypeList || type,
taskEditUserList,
taskViewUserList,
taskComment,
taskWorkflow: JSON.stringify(taskWorkflow),
taskExplain: type,
taskHandleDesc: type,
taskExplain: taskExplain || type,
taskHandleDesc: taskHandleDesc || type,
taskCostDuration,
createHistoryBy: taskEditUserList,
createHistoryBy: createHistoryBy,
createHistoryAt: dayjs().format('YYYY-MM-DD HH:mm:ss')
}
}
@@ -251,12 +273,17 @@ class TaskService extends Service {
})
var nodeStatus = '审批中'
if (approvalType == "或签") {
nodeStatus = _.some(userConfig, ['handleDesc', '拒绝']) ? '已拒绝' : _.some(userConfig, ['handleDesc', '同意']) ? '已同意' : '审批中'
} else {
var nodeStatus = _.some(userConfig, ['handleDesc', '拒绝']) ? '已拒绝' : _.every(userConfig, ['handleDesc', '同意']) ? '已同意' : '审批中'
if (id.startsWith('approvalTask')) {
if (approvalType == "或签") {
nodeStatus = _.some(userConfig, ['handleDesc', '拒绝']) ? '已拒绝' : _.some(userConfig, ['handleDesc', '同意']) ? '已同意' : '审批中'
} else {
var nodeStatus = _.some(userConfig, ['handleDesc', '拒绝']) ? '已拒绝' : _.every(userConfig, ['handleDesc', '同意']) ? '已同意' : '审批中'
}
} else if (id.startsWith('noticeTask')) {
nodeStatus = _.every(userConfig, u => u.createHistoryAt) ? '已抄送' : '抄送中'
}
return {
id,
label,