代码优化

This commit is contained in:
ChenXinXin committed 2024-05-16 17:21:05 +08:00
1 parent 12bbc3dade
commit 991cae5f15
1 file changed
+16 -10
+16 -10
View File
@@ -361,7 +361,7 @@ class TaskService extends Service {
editUserList.splice(i + 1, 0, abnormalUser); editUserList.splice(i + 1, 0, abnormalUser);
} }
} }
var abnormalUserName = userList.find(u => u.userId == abnormalUser)?.username || abnormalUser var abnormalUserName = userList.find(u => u.userId == abnormalUser)?.username || abnormalUser + "(账号被禁用)"
// 插入禁用账号的历史记录 // 插入禁用账号的历史记录
_.assign(taskData, { _.assign(taskData, {
taskComment: "账号禁用,系统自动转交" + abnormalUserName, taskComment: "账号禁用,系统自动转交" + abnormalUserName,
@@ -390,7 +390,11 @@ class TaskService extends Service {
foundNode.properties.userIdList = newUserIdList; foundNode.properties.userIdList = newUserIdList;
} }
updateTaskData.taskWorkflow = JSON.stringify(_.cloneDeep(taskWorkflow)) updateTaskData.taskWorkflow = JSON.stringify(_.cloneDeep(taskWorkflow))
updateTaskData.taskViewUserList = taskViewUserList.push(abnormalUser) if (taskViewUserList) {
updateTaskData.taskViewUserList = taskViewUserList.split(',').concat(abnormalUser).join(',')
} else {
updateTaskData.taskViewUserList = abnormalUser
}
} else { } else {
// 自动同意 // 自动同意
editUserList = editUserList.filter(editUser => !bannedUser.includes(editUser)) editUserList = editUserList.filter(editUser => !bannedUser.includes(editUser))
@@ -489,17 +493,19 @@ class TaskService extends Service {
async getTaskWorkflow() { async getTaskWorkflow() {
const { jianghuKnex } = this.app; const { jianghuKnex } = this.app;
const { userId } = this.ctx.userInfo;
const { taskId } = this.ctx.request.body.appData.actionData; const { taskId } = this.ctx.request.body.appData.actionData;
// 获取当前审批 // 获取当前审批
const task = await jianghuKnex('task').where({ taskId }).first(); const task = await jianghuKnex('task').where({ taskId }).select('taskWorkflow', 'taskConfigId', 'taskViewUserList').first();
const { taskWorkflow, taskConfigId } = task const { taskWorkflow, taskViewUserList } = task
// 获取审批流历史 // 获取审批流历史
const taskHistory = await jianghuKnex('task_history').where({ taskId }).select(); const taskHistory = await jianghuKnex('task_history').where({ taskId })
.select('taskConfigId', 'createHistoryBy', 'taskComment', 'taskHandleDesc', 'createHistoryAt', 'taskStatus');
// 获取人员 // 获取人员
const userList = await jianghuKnex('enterprise_user').select() const userList = await jianghuKnex('enterprise_user').whereIn('userId', taskViewUserList.split(',')).select('userId', 'username')
if (!task) throw new Error('Task not found');
var workflowHistory = JSON.parse(taskWorkflow).nodeList.filter(n => !['start', 'end', 'conditionTask'].includes(n.properties.type)) var workflowHistory = JSON.parse(taskWorkflow).nodeList.filter(n => !['start', 'end', 'conditionTask'].includes(n.properties.type))
.map(node => { .map(node => {
@@ -509,12 +515,13 @@ class TaskService extends Service {
var username = userList.find(u => u.userId == appUserId)?.username, var username = userList.find(u => u.userId == appUserId)?.username,
historyRecord = taskHistory.find(h => h.taskConfigId == node.id && h.createHistoryBy == appUserId); historyRecord = taskHistory.find(h => h.taskConfigId == node.id && h.createHistoryBy == appUserId);
username = username ? username : appUserId + '(账号被禁用)'
if (historyRecord) { if (historyRecord) {
const { taskComment, taskHandleDesc, createHistoryAt, taskStatus } = historyRecord const { taskComment, taskHandleDesc, createHistoryAt, taskStatus } = historyRecord
return { return {
userId: appUserId, userId: appUserId,
username: username || appUserId + '(账号被禁用)', username: username,
comment: taskComment, comment: taskComment,
handleDesc: taskHandleDesc, handleDesc: taskHandleDesc,
createHistoryAt: dayjs(createHistoryAt || '').format('YYYY-MM-DD HH:mm:ss'), createHistoryAt: dayjs(createHistoryAt || '').format('YYYY-MM-DD HH:mm:ss'),
@@ -523,7 +530,7 @@ class TaskService extends Service {
} else { } else {
return { return {
userId: appUserId, userId: appUserId,
username: username || appUserId + '(账号被禁用)', username: username,
} }
} }
}) })
@@ -550,7 +557,6 @@ class TaskService extends Service {
}) })
return workflowHistory return workflowHistory
} }
async getTaskList() { async getTaskList() {