|
@@ -160,6 +160,23 @@ module.exports = app => {
|
|
return group;
|
|
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) {
|
|
async getUniqUserGroup(tenderId, times) {
|
|
const group = await this.getAuditorGroup(tenderId, times);
|
|
const group = await this.getAuditorGroup(tenderId, times);
|
|
const sql =
|
|
const sql =
|
|
@@ -171,7 +188,7 @@ module.exports = app => {
|
|
const sqlParam = [times, tenderId, tenderId];
|
|
const sqlParam = [times, tenderId, tenderId];
|
|
const user = await this.db.queryOne(sql, sqlParam);
|
|
const user = await this.db.queryOne(sql, sqlParam);
|
|
group.unshift([ user ]);
|
|
group.unshift([ user ]);
|
|
- return this.ctx.helper.groupAuditorsUniq(group, 'audit_order');
|
|
|
|
|
|
+ return this.groupAuditorsUniq(group);
|
|
}
|
|
}
|
|
|
|
|
|
async getAuditorHistory(tenderId, times, reverse = false) {
|
|
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.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.nextAuditorIds = this._.map(tender.nextAuditors, 'audit_id');
|
|
tender.auditorGroups = this.ctx.helper.groupAuditors(tender.auditors, 'audit_order');
|
|
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([{
|
|
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
|
|
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 = [];// await this.service.ledgerAuditAss.getData(tender); // 全部协同人
|
|
tender.assists = tender.assists.filter(x => {
|
|
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) {
|
|
if (tender.status === auditConst.status.checkNo && tender.user_id !== this.ctx.session.sessionUser.accountId) {
|
|
const auditors = await this.getAuditors(tender.id, times); // 全部参与的审批人
|
|
const auditors = await this.getAuditors(tender.id, times); // 全部参与的审批人
|
|
const auditorGroups = this.ctx.helper.groupAuditors(auditors, 'audit_order');
|
|
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([{
|
|
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
|
|
name: tender.user.name, role: tender.user.role, company: tender.user.company
|
|
}]);
|
|
}]);
|
|
} else {
|
|
} else {
|
|
@@ -898,8 +915,8 @@ module.exports = app => {
|
|
async updateLastAudit(tender, auditList, lastId) {
|
|
async updateLastAudit(tender, auditList, lastId) {
|
|
const transaction = await this.db.beginTransaction();
|
|
const transaction = await this.db.beginTransaction();
|
|
try {
|
|
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
|
|
let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
|
|
if (existAudit) {
|
|
if (existAudit) {
|
|
await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, audit_id: lastId });
|
|
await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, audit_id: lastId });
|