diff --git a/app/constant/constant.js b/app/constant/constant.js index fd1774f..63619a0 100644 --- a/app/constant/constant.js +++ b/app/constant/constant.js @@ -1,32 +1,5 @@ 'use strict'; -module.exports.tableEnum = Object.freeze({ - // ========================江湖表============================ - _cache: "_cache", - _constant: "_constant", - _constant_ui: "_constant_ui", - _file: "_file", - _group: "_group", - _page: "_page", - _record_history: "_record_history", - _resource: "_resource", - _resource_request_log: "_resource_request_log", - _role: "_role", - _user: "_user", - _user_group_role: "_user_group_role", - _user_group_role_page: "_user_group_role_page", - _user_group_role_resource: "_user_group_role_resource", - _user_session: "_user_session", - _constant_ui: "_constant_ui", - // ========================基础表============================ - workflow: 'workflow', - task: 'task', - task_history: 'task_history', - // ========================基础View============================ - // ========================View============================ - _view01_user: "_view01_user", -}); - module.exports.genderEnum = Object.freeze({ male: 'male', female: 'female' diff --git a/app/service/task.js b/app/service/task.js index c4d382f..ae894ea 100644 --- a/app/service/task.js +++ b/app/service/task.js @@ -1,8 +1,6 @@ 'use strict'; const Service = require('egg').Service; -const { tableEnum, articlePublishStatusEnum } = require("../constant/constant"); const _ = require("lodash"); -const path = require("path"); // TODO: 封装一下 const dayjs = require("dayjs"); @@ -12,24 +10,7 @@ dayjs.extend(utc) dayjs.extend(timezone) const idGenerateUtil = require("@jianghujs/jianghu/app/common/idGenerateUtil"); -const validateUtil = require("@jianghujs/jianghu/app/common/validateUtil"); const { BizError, errorInfoEnum } = require("../constant/error"); -const fs = require("fs"), - fsPromises = require("fs").promises, - unlink = fsPromises.unlink, - rename = fsPromises.rename, - util = require("util"), - exists = util.promisify(fs.exists); -const actionDataScheme = Object.freeze({ - deletedArticle: { - type: "object", - additionalProperties: true, - required: ["articleId"], - properties: { - articleId: { anyOf: [{ type: "string" }, { type: "number" }] }, - }, - }, -}); class TaskService extends Service { async upcomingToUserId() { @@ -62,7 +43,7 @@ class TaskService extends Service { const { workflowId, taskTitle, workflowForm, workflowFormData, workflowConfigCustom } = actionData; const { userId, username } = this.ctx.userInfo; const taskId = await idGenerateUtil.uuid(); - const workflow = await jianghuKnex(tableEnum.workflow, this.ctx).where({workflowId}).first(); + const workflow = await jianghuKnex('workflow', this.ctx).where({workflowId}).first(); if (!workflow) { throw new BizError(errorInfoEnum.workflow_not_found) return @@ -106,7 +87,7 @@ class TaskService extends Service { workflowConfig: JSON.stringify(workflowConfig) } await jianghuKnex.transaction(async trx => { - const [id] = await trx(tableEnum.task, this.ctx).insert(startData); + const [id] = await trx('task', this.ctx).insert(startData); // 并行模式下,生成所有的userTask if (mode == 'parallel') { await this.generateAllUserTask(id, trx); @@ -125,7 +106,7 @@ class TaskService extends Service { */ async getGroupUserList(groupId) { const { jianghuKnex, config } = this.app; - const userList = await jianghuKnex(tableEnum._user_group_role).where({groupId}).select('userId'); + const userList = await jianghuKnex('_user_group_role').where({groupId}).select('userId'); return userList.map(e => { return e.userId }); @@ -147,7 +128,7 @@ class TaskService extends Service { const { jianghuKnex, config } = this.app; const { userId: careUser, taskId } = actionData; const { userId } = this.ctx.userInfo; - const taskInfo = await jianghuKnex(tableEnum.task).where({taskId}).first(); + const taskInfo = await jianghuKnex('task').where({taskId}).first(); // 转交写入历史 const history = { taskId: taskId, @@ -157,10 +138,10 @@ class TaskService extends Service { historyChooseName: line.label, historyCostDuration: 0 } - await jianghuKnex(tableEnum.task_history).insert(history); + await jianghuKnex('task_history').insert(history); // 修改task处理人 const taskProcessorList = taskInfo.taskProcessorList.replace(userId, careUser); - await jianghuKnex(tableEnum.task).where({taskId}).update({taskProcessorList}); + await jianghuKnex('task').where({taskId}).update({taskProcessorList}); } /** * 工单历史信息 @@ -171,14 +152,14 @@ class TaskService extends Service { const { jianghuKnex, config } = this.app; const { id } = actionData; const { userId } = this.ctx.userInfo; - const taskInfo = await jianghuKnex(tableEnum.task).where({id}).first(); + const taskInfo = await jianghuKnex('task').where({id}).first(); // 获取process 流程、根据节点线路组建步骤条 if (!taskInfo) { throw new BizError(errorInfoEnum.task_not_found); } - const taskHistoryList = await jianghuKnex(tableEnum.task_history).where({taskId: taskInfo.taskId}).orderBy('id', 'asc').select(); + const taskHistoryList = await jianghuKnex('task_history').where({taskId: taskInfo.taskId}).orderBy('id', 'asc').select(); const taskStepperList = this.makeStepper(taskInfo.workflowConfig, taskHistoryList, taskInfo); - const userList = await jianghuKnex(tableEnum._view01_user).whereIn('userId', taskInfo.taskViewUserList.split(',')).select(); + const userList = await jianghuKnex('_view01_user').whereIn('userId', taskInfo.taskViewUserList.split(',')).select(); taskInfo.workflowConfig = JSON.parse(taskInfo.workflowConfig); const taskHistoryConfigList = this.getTaskHistoryConfigList(taskInfo.workflowConfig, taskHistoryList, userList); @@ -310,14 +291,14 @@ class TaskService extends Service { return nodeAllList.filter(e => lineList.some(s => s.to === e.id) && !existIdList.includes(e.id)); } async generateAllUserTask(id, trx) { - const taskInfo = await trx(tableEnum.task).where({id}).first(); + const taskInfo = await trx('task').where({id}).first(); delete taskInfo.id; const {nodeList = [], lineList = []} = JSON.parse(taskInfo.workflowConfig || '{}'); const userNode = nodeList.filter(e => e.id.includes('userTask') || e.id.includes('receiveTask') ); for (const node of userNode) { let taskEditUserList = await this.getProcessUserList([node]); const nextLineList = lineList.filter(e => e.from === node.id); - await trx(tableEnum.task).insert({ + await trx('task').insert({ ...taskInfo, taskNextConfigList: JSON.stringify(nextLineList), taskLineTypeList: node.lineTypeList, @@ -339,7 +320,7 @@ class TaskService extends Service { const { userId } = this.ctx.userInfo; // 准备任务数据 - const taskInfo = await trx(tableEnum.task).where({id}).first(); + const taskInfo = await trx('task').where({id}).first(); delete taskInfo.id; const {mode = 'serial', nodeList = [], lineList = []} = JSON.parse(taskInfo.workflowConfig || '{}'); const userNode = nodeList.filter(e => e.id.includes('userTask') || e.id.includes('receiveTask') ); @@ -350,7 +331,7 @@ class TaskService extends Service { const currentNode = nodeList.find(e => e.id === taskInfo.taskConfigId); // 写入exec历史 - const taskHistory = await trx(tableEnum.task_history, this.ctx).where({taskId: taskInfo.taskId}).orderBy('operationAt', 'desc').select(); + const taskHistory = await trx('task_history', this.ctx).where({taskId: taskInfo.taskId}).orderBy('operationAt', 'desc').select(); const [prevHistory] = taskHistory; // let taskFormInput = JSON.parse(taskInfo.taskFormInput); // taskFormInput.input = taskTpl.input; @@ -372,7 +353,7 @@ class TaskService extends Service { taskComment } delete history.taskEditedUserList; - await trx(tableEnum.task_history, this.ctx).insert(history); + await trx('task_history', this.ctx).insert(history); // 未配置连线时,默认添加拒绝连线到end节点 if (endNode && !lines.length) { @@ -393,13 +374,13 @@ class TaskService extends Service { // 当前节点如果需要所有人审批并且不是拒绝连线时,检查是否所有人都审批过了 if (currentNode.isNeedAllApproval && !line.toInterruptEnd) { let taskEditedUserList = taskInfo.taskEditedUserList? `${taskInfo.taskEditedUserList},${userId}`: userId; - await trx(tableEnum.task, this.ctx).where({id}).update({taskEditedUserList}); + await trx('task', this.ctx).where({id}).update({taskEditedUserList}); if (_.xor(taskEditedUserList.split(','), taskInfo.taskEditUserList.split(',')).length != 0) { return } } - await trx(tableEnum.task, this.ctx).where({id}).delete(); + await trx('task', this.ctx).where({id}).delete(); // 结束流程 // 条件: @@ -423,8 +404,8 @@ class TaskService extends Service { taskLineLabel: line.type + '-' + line.label, taskCostDuration: 0 } - await trx(tableEnum.task_history, this.ctx).insert(endHistory); - await trx(tableEnum.task).insert({ + await trx('task_history', this.ctx).insert(endHistory); + await trx('task').insert({ ...taskInfo, taskId: taskInfo.taskId, taskFormInput: taskInfo.taskFormInput, @@ -436,7 +417,7 @@ class TaskService extends Service { }); // 默认拒绝节点,删除全部任务,执行interruptHook if (line.toInterruptEnd) { - await trx(tableEnum.task, this.ctx).where({taskId: taskInfo.taskId, taskStatus: 'running'}).delete(); + await trx('task', this.ctx).where({taskId: taskInfo.taskId, taskStatus: 'running'}).delete(); await this.executeHook(endNode.interruptHook); } else { await this.executeHook(endNode.finishHook); @@ -457,7 +438,7 @@ class TaskService extends Service { // 串行审核,生成下一个task if (mode == 'serial') { - await trx(tableEnum.task, this.ctx).insert({ + await trx('task', this.ctx).insert({ ...taskInfo, taskId: taskInfo.taskId, taskFormInput, diff --git a/app/service/workflow.js b/app/service/workflow.js index 4439450..e93ef09 100644 --- a/app/service/workflow.js +++ b/app/service/workflow.js @@ -1,8 +1,5 @@ 'use strict'; const Service = require('egg').Service; -const { tableEnum, articlePublishStatusEnum } = require("../constant/constant"); -const _ = require("lodash"); -const path = require("path"); // TODO: 封装一下 const dayjs = require("dayjs"); @@ -12,24 +9,7 @@ dayjs.extend(utc) dayjs.extend(timezone) const idGenerateUtil = require("@jianghujs/jianghu/app/common/idGenerateUtil"); -const validateUtil = require("@jianghujs/jianghu/app/common/validateUtil"); const { BizError, errorInfoEnum } = require("../constant/error"); -const fs = require("fs"), - fsPromises = require("fs").promises, - unlink = fsPromises.unlink, - rename = fsPromises.rename, - util = require("util"), - exists = util.promisify(fs.exists); -const actionDataScheme = Object.freeze({ - deletedArticle: { - type: "object", - additionalProperties: true, - required: ["articleId"], - properties: { - articleId: { anyOf: [{ type: "string" }, { type: "number" }] }, - }, - }, -}); class WorkflowService extends Service { @@ -39,7 +19,7 @@ class WorkflowService extends Service { actionData.formId = await idGenerateUtil.idPlus({ knex: jianghuKnex, startValue: 1000, - tableName: tableEnum.form, + tableName: 'form', columnName: "formId" }); } @@ -49,7 +29,7 @@ class WorkflowService extends Service { actionData.workflowId = await idGenerateUtil.idPlus({ knex: jianghuKnex, startValue: 1000, - tableName: tableEnum.workflow, + tableName: 'workflow', columnName: "workflowId" }); } @@ -60,7 +40,7 @@ class WorkflowService extends Service { let { tplId } = actionData; const tplIds = tplId ? tplId.split(',') : []; if (tplIds.length) { - const tplList = await jianghuKnex(tableEnum.form).whereIn('formId', tplIds).select(); + const tplList = await jianghuKnex('form').whereIn('formId', tplIds).select(); let formList = []; const formData = {}; for( const item of tplList) { @@ -88,7 +68,7 @@ class WorkflowService extends Service { const { jianghuKnex } = this.app; const { formItemList, workflowConfigCustom, workflowId } = actionData; - let workflow = await jianghuKnex(tableEnum.workflow, this.ctx).where({workflowId}).first(); + let workflow = await jianghuKnex('workflow', this.ctx).where({workflowId}).first(); if(!workflow) { throw new BizError(errorInfoEnum.workflow_not_found); } @@ -112,9 +92,9 @@ class WorkflowService extends Service { const { taskId } = this.ctx.request.body.appData.actionData; const { jianghuKnex } = this.app; - const taskInfo = await jianghuKnex(tableEnum.task, this.ctx).where({taskId}).first(); - const taskHistoryList = await jianghuKnex(tableEnum.task_history).where({taskId: taskInfo.taskId}).orderBy('id', 'asc').select(); - // const userList = await jianghuKnex(tableEnum._view01_user).whereIn('userId', taskInfo.taskViewUserList.split(',')).select(); + const taskInfo = await jianghuKnex('task', this.ctx).where({taskId}).first(); + const taskHistoryList = await jianghuKnex('task_history').where({taskId: taskInfo.taskId}).orderBy('id', 'asc').select(); + // const userList = await jianghuKnex('_view01_user').whereIn('userId', taskInfo.taskViewUserList.split(',')).select(); // taskInfo.workflowConfig = JSON.parse(taskInfo.workflowConfig); // return this.ctx.service.task.getTaskHistoryConfigList(taskInfo.workflowConfig, taskHistoryList, userList); const lineTypeList = taskInfo.taskLineTypeList; @@ -127,7 +107,7 @@ class WorkflowService extends Service { async appendUsername() { const rows = this.ctx.body.appData.resultData.rows; const { jianghuKnex } = this.app; - const userList = await jianghuKnex(tableEnum._view01_user).whereIn('userId', rows.map(item => item.taskInitUser)).select(); + const userList = await jianghuKnex('_view01_user').whereIn('userId', rows.map(item => item.taskInitUser)).select(); rows.forEach(item => { const user = userList.find(it => it.userId === item.taskInitUser); item.taskInitUsername = user.username;