Browse Source

从固定审批流变成固定终审时,审批流程调整问题

MaiXinRong 1 year ago
parent
commit
1e614863cc
2 changed files with 16 additions and 13 deletions
  1. 1 1
      app/middleware/stage_check.js
  2. 15 12
      app/service/stage_audit.js

+ 1 - 1
app/middleware/stage_check.js

@@ -154,7 +154,7 @@ module.exports = options => {
                     const shenpiInfo = yield this.service.shenpiAudit.getDataByCondition({ tid: stage.tid, sp_type: shenpiConst.sp_type.stage, sp_status: shenpi_status });
                     // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
                     const lastAuditors = auditList.filter(x => { x.order === auditList.order; });
-                    if (shenpiInfo && (lastAuditors.length > 1 || shenpiInfo.audit_id !== lastAuditors[0].aid)) {
+                    if (shenpiInfo && (lastAuditors.length === 0 || (lastAuditors.length > 1 || shenpiInfo.audit_id !== lastAuditors[0].aid))) {
                         yield this.service.stageAudit.updateLastAudit(stage, auditList, shenpiInfo.audit_id);
                     } else if (!shenpiInfo) {
                         // 不存在终审人的状态下这里恢复为授权审批人

+ 15 - 12
app/service/stage_audit.js

@@ -1848,25 +1848,28 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
-                const idList = this._.map(auditList, 'aid');
-                let order = idList.length + 1;
-                if (idList.indexOf(lastId) !== -1) {
+                const existAudit = auditList.find(x => { return x.aid === lastId });
+                let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.order)}, 0) + 1 : 1; // 最大值 + 1
+                if (existAudit) {
                     await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, aid: lastId });
-                    await transaction.delete(this.ctx.service.stageAuditAss.tableName, { sid: stage.id, times: stage.times, user_id: lastId });
-
-                    const audit = this._.find(auditList, { 'aid': lastId });
-                    const orgAuditors = auditList.filter(x => { return x.order === audit.order; });
-                    if (orgAuditors.length === 1) {
-                        // 顺移之后审核人流程顺序
-                        await this._syncOrderByDelete(transaction, stage.id, audit.order, stage.times);
-                        order = order - 1;
+                    const sameOrder = auditList.find(x => { return x.order === existAudit.order });
+                    if (!sameOrder) {
+                        const updateData = [];
+                        auditList.forEach(x => {
+                            if (x.order <= existAudit.order) return;
+                            updateData.push({id: x.id, order: x.order - 1, audit_order: x.audit_order - 1});
+                        });
+                        if (updateData.length > 0) {
+                            await transaction.updateRows(updateData);
+                            order = order - 1;
+                        }
                     }
                 }
-
                 // 添加终审
                 const newAuditor = {
                     tid: stage.tid, sid: stage.id, aid: lastId,
                     times: stage.times, order, status: auditConst.status.uncheck,
+                    audit_type: auditType.key.common, audit_order: order,
                 };
                 await transaction.insert(this.tableName, newAuditor);
                 await transaction.commit();