فهرست منبع

台账,重新审批后,相关审批流程兼容性代码

MaiXinRong 11 ماه پیش
والد
کامیت
f0b45871bf
2فایلهای تغییر یافته به همراه34 افزوده شده و 17 حذف شده
  1. 26 9
      app/service/ledger_audit.js
  2. 8 8
      app/service/revise_audit.js

+ 26 - 9
app/service/ledger_audit.js

@@ -160,6 +160,23 @@ module.exports = app => {
             return group;
         }
 
+        groupAuditorsUniq(group) {
+            const helper = this.ctx.helper;
+            const uniqGroup = [];
+            for (const g of group) {
+                const curAuditId = g.map(x => { return x.audit_id; });
+                const sameGroup = uniqGroup.find(x => {
+                    if (!x) return false;
+                    if (x[0].audit_type !== g[0].audit_type) return false;
+                    const auditId = x.map(xa => { return xa.audit_id; });
+                    helper._.remove(auditId, function(a) { return curAuditId.indexOf(a) >= 0; });
+                    return auditId.length === 0;
+                });
+                if (!sameGroup) uniqGroup[g[0].audit_order] = g;
+            }
+            return uniqGroup.filter(x => { return !!x });
+        }
+
         async getUniqUserGroup(tenderId, times) {
             const group = await this.getAuditorGroup(tenderId, times);
             const sql =
@@ -171,7 +188,7 @@ module.exports = app => {
             const sqlParam = [times, tenderId, tenderId];
             const user = await this.db.queryOne(sql, sqlParam);
             group.unshift([ user ]);
-            return this.ctx.helper.groupAuditorsUniq(group, 'audit_order');
+            return this.groupAuditorsUniq(group);
         }
 
         async getAuditorHistory(tenderId, times, reverse = false) {
@@ -254,13 +271,13 @@ module.exports = app => {
             tender.nextAuditors = tender.curAuditors.length > 0 ? tender.auditors.filter(x => { return x.audit_order === tender.curAuditors[0].audit_order + 1; }) : [];
             tender.nextAuditorIds = this._.map(tender.nextAuditors, 'audit_id');
             tender.auditorGroups = this.ctx.helper.groupAuditors(tender.auditors, 'audit_order');
-            tender.userGroups = this.ctx.helper.groupAuditorsUniq(tender.auditorGroups);
+            tender.userGroups = this.groupAuditorsUniq(tender.auditorGroups);
             tender.userGroups.unshift([{
-                aid: tender.user.id, order: 0, times: tender.ledger_times, audit_order: 0, audit_type: auditType.key.common,
+                audit_id: tender.user.id, order: 0, times: tender.ledger_times, audit_order: 0, audit_type: auditType.key.common,
                 name: tender.user.name, role: tender.user.role, company: tender.user.company
             }]);
-            tender.finalAuditorIds = tender.userGroups[tender.userGroups.length - 1].map(x => { return x.aid; });
-            tender.relaAuditor = tender.auditors.find(x => { return x.aid === accountId });
+            tender.finalAuditorIds = tender.userGroups[tender.userGroups.length - 1].map(x => { return x.audit_id; });
+            tender.relaAuditor = tender.auditors.find(x => { return x.audit_id === accountId });
 
             tender.assists = [];// await this.service.ledgerAuditAss.getData(tender); // 全部协同人
             tender.assists = tender.assists.filter(x => {
@@ -285,9 +302,9 @@ module.exports = app => {
             if (tender.status === auditConst.status.checkNo && tender.user_id !== this.ctx.session.sessionUser.accountId) {
                 const auditors = await this.getAuditors(tender.id, times); // 全部参与的审批人
                 const auditorGroups = this.ctx.helper.groupAuditors(auditors, 'audit_order');
-                tender.auditors2 = this.ctx.helper.groupAuditorsUniq(auditorGroups, 'audit_order');
+                tender.auditors2 = this.groupAuditorsUniq(auditorGroups);
                 tender.auditors2.unshift([{
-                    aid: tender.user.id, order: 0, times: tender.ledger_times - 1, audit_order: 0, audit_type: auditType.key.common,
+                    audit_id: tender.user.id, order: 0, times: tender.ledger_times - 1, audit_order: 0, audit_type: auditType.key.common,
                     name: tender.user.name, role: tender.user.role, company: tender.user.company
                 }]);
             } else {
@@ -898,8 +915,8 @@ module.exports = app => {
         async updateLastAudit(tender, auditList, lastId) {
             const transaction = await this.db.beginTransaction();
             try {
-                // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
-                const existAudit = auditList.find(x => { return x.aid === lastId });
+                // 先判断auditList里的audit_id是否与lastId相同,相同则删除并重新更新order
+                const existAudit = auditList.find(x => { return x.audit_id === lastId });
                 let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
                 if (existAudit) {
                     await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, audit_id: lastId });

+ 8 - 8
app/service/revise_audit.js

@@ -279,11 +279,11 @@ module.exports = app => {
             revise.auditorGroups = this.ctx.helper.groupAuditors(revise.auditors, 'audit_order');
             revise.userGroups = this.ctx.helper.groupAuditorsUniq(revise.auditorGroups);
             revise.userGroups.unshift([{
-                aid: revise.user.id, order: 0, times: revise.times, audit_order: 0, audit_type: auditType.key.common,
+                audit_id: revise.user.id, order: 0, times: revise.times, audit_order: 0, audit_type: auditType.key.common,
                 name: revise.user.name, role: revise.user.role, company: revise.user.company
             }]);
-            revise.finalAuditorIds = revise.userGroups[revise.userGroups.length - 1].map(x => { return x.aid; });
-            revise.relaAuditor = revise.auditors.find(x => { return x.aid === accountId });
+            revise.finalAuditorIds = revise.userGroups[revise.userGroups.length - 1].map(x => { return x.audit_id; });
+            revise.relaAuditor = revise.auditors.find(x => { return x.audit_id === accountId });
 
             revise.assists = [];// await this.service.ledgerAuditAss.getData(tender); // 全部协同人
             revise.assists = revise.assists.filter(x => {
@@ -310,7 +310,7 @@ module.exports = app => {
                 const auditorGroups = this.ctx.helper.groupAuditors(auditors, 'audit_order');
                 revise.auditors2 = this.ctx.helper.groupAuditorsUniq(auditorGroups, 'audit_order');
                 revise.auditors2.unshift([{
-                    aid: revise.user.id, order: 0, times: revise.times - 1, audit_order: 0, audit_type: auditType.key.common,
+                    audit_id: revise.user.id, order: 0, times: revise.times - 1, audit_order: 0, audit_type: auditType.key.common,
                     name: revise.user.name, role: revise.user.role, company: revise.user.company
                 }]);
             } else {
@@ -723,8 +723,8 @@ module.exports = app => {
                 return {
                     id: x.id,
                     status: x.audit_id === selfAuditor.audit_id ? auditConst.status.checkNo : auditConst.status.checkSkip,
-                    opinion: x.audit_id === selfAuditor.aid ? opinion : '',
-                    end_time: x.audit_id === selfAuditor.aid ? time : null,
+                    opinion: x.audit_id === selfAuditor.audit_id ? opinion : '',
+                    end_time: x.audit_id === selfAuditor.audit_id ? time : null,
                 };
             });
 
@@ -1051,8 +1051,8 @@ module.exports = app => {
         async updateLastAudit(revise, auditList, lastId) {
             const transaction = await this.db.beginTransaction();
             try {
-                // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
-                const existAudit = auditList.find(x => { return x.aid === lastId });
+                // 先判断auditList里的audit_id是否与lastId相同,相同则删除并重新更新order
+                const existAudit = auditList.find(x => { return x.audit_id === lastId });
                 let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
                 if (existAudit) {
                     await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, audit_id: lastId });