|
@@ -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 {
|
|
@@ -425,6 +442,7 @@ module.exports = app => {
|
|
|
if (!auditor) {
|
|
|
throw '该审核人不存在';
|
|
|
}
|
|
|
+ await transaction.delete(this.tableName, { tid: tenderId, audit_order: auditor.audit_order, times});
|
|
|
await this._syncOrderByDelete(transaction, tenderId, auditor.audit_order, times);
|
|
|
await transaction.delete(this.tableName, condition);
|
|
|
await transaction.commit();
|
|
@@ -696,28 +714,37 @@ module.exports = app => {
|
|
|
*/
|
|
|
async checkAgain(tenderId, times = 1) {
|
|
|
const time = new Date();
|
|
|
+ const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
// 整理当前流程审核人状态更新
|
|
|
const auditors = await this.getAllDataByCondition({
|
|
|
where: { tender_id: tenderId, times },
|
|
|
orders: [['audit_order', 'desc']],
|
|
|
});
|
|
|
if (auditors.length <= 0) throw '台账审核数据错误';
|
|
|
- const selfAudit = auditors[0];
|
|
|
- if (selfAudit.audit_id !== this.ctx.session.sessionUser.accountId) throw '当前台账您无权重审';
|
|
|
+ const flowAuditors = auditors.filter(x => { return x.audit_order === auditors[0].audit_order; });
|
|
|
+ const selfAudit = flowAuditors.find(x => { return x.audit_id === accountId; });
|
|
|
+ if (!selfAudit) throw '当前台账您无权重审';
|
|
|
const tender = this.ctx.service.tender.getDataById(tenderId);
|
|
|
if (!tender) throw '标段数据错误';
|
|
|
|
|
|
let otherAuditIds = [tender.user_id, ...auditors.map(x => { return x.audit_id })];
|
|
|
otherAuditIds = this._.uniq(otherAuditIds).filter(x => { return x !== selfAudit.audit_id; });
|
|
|
|
|
|
- const checkAgainAuditor = {
|
|
|
- tender_id: tenderId, times, audit_order: selfAudit.audit_order + 1, audit_id: selfAudit.audit_id,
|
|
|
- begin_time: time, end_time: time, opinion: '', status: auditConst.status.checkAgain,
|
|
|
- };
|
|
|
- const checkingAuditor = {
|
|
|
- tender_id: tenderId, times, audit_order: selfAudit.audit_order + 2, audit_id: selfAudit.audit_id,
|
|
|
- begin_time: time, end_time: null, opinion: '', status: auditConst.status.checking,
|
|
|
- };
|
|
|
+ const checkAgainAuditor = flowAuditors.map(x => {
|
|
|
+ return {
|
|
|
+ tender_id: tenderId, times, audit_order: x.audit_order + 1, audit_id: x.audit_id,
|
|
|
+ audit_type: x.audit_type, audit_ledger_id: x.audit_ledger_id,
|
|
|
+ begin_time: time, end_time: time, opinion: '',
|
|
|
+ status: x.audit_id === accountId ? auditConst.status.checkAgain : auditConst.status.checkSkip,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const checkingAuditor = flowAuditors.map(x => {
|
|
|
+ return {
|
|
|
+ tender_id: tenderId, times, audit_order: x.audit_order + 2, audit_id: x.audit_id,
|
|
|
+ audit_type: x.audit_type, audit_ledger_id: x.audit_ledger_id,
|
|
|
+ begin_time: time, end_time: null, opinion: '', status: auditConst.status.checking,
|
|
|
+ };
|
|
|
+ });
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 当前审批人2次添加至流程中
|
|
@@ -898,8 +925,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 });
|