|
@@ -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();
|