|
@@ -1369,6 +1369,50 @@ module.exports = app => {
|
|
|
throw err;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ async batchSetAudits(tid, cids, from_cid) {
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ const changes = await this.ctx.service.change.getAllDataByCondition({ where: { tid, cid: cids } });
|
|
|
+ const from_change = await this.ctx.service.change.getDataByCondition({ tid, cid: from_cid });
|
|
|
+ const new_audits = await transaction.select(this.tableName, { where: { cid: from_cid, times: from_change.times }, orders: [['audit_order', 'asc']] });
|
|
|
+ new_audits.shift();
|
|
|
+ const insertAudits = [];
|
|
|
+ const updateChanges = [];
|
|
|
+ for (const c of changes) {
|
|
|
+ if (from_change.sp_group !== c.sp_group) {
|
|
|
+ updateChanges.push({
|
|
|
+ row: { sp_group: from_change.sp_group },
|
|
|
+ where: { tid, cid: c.cid }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const newAudits = new_audits.map(x => {
|
|
|
+ return {
|
|
|
+ tid, cid: c.cid, uid: x.uid, name: x.name,
|
|
|
+ company: x.company, jobs: x.role,
|
|
|
+ usort: x.usort, usite: x.usite,
|
|
|
+ audit_order: x.audit_order, audit_type: x.audit_type,
|
|
|
+ times: c.times, status: auditConst.status.uncheck,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ // 先删除旧的审批流(除了原报),再添加新的
|
|
|
+ const sql = 'DELETE FROM ?? WHERE `cid`= ? AND `times` = ? AND `usite` != 0';
|
|
|
+ const sqlParam = [this.tableName, c.cid, c.times];
|
|
|
+ await transaction.query(sql, sqlParam);
|
|
|
+ // await transaction.delete(this.tableName, { tid, cid: c.cid, times: c.times });
|
|
|
+ insertAudits.push(...newAudits);
|
|
|
+ }
|
|
|
+ if (updateChanges.length > 0) await transaction.updateRows(this.ctx.service.change.tableName, updateChanges);
|
|
|
+ if (insertAudits.length > 0) await transaction.insert(this.tableName, insertAudits);
|
|
|
+ // 更新到审批流程方法
|
|
|
+ await transaction.commit();
|
|
|
+ return true;
|
|
|
+ } catch (err) {
|
|
|
+ console.log(err);
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return ChangeAudit;
|