|
|
@@ -328,7 +328,7 @@ module.exports = app => {
|
|
|
try {
|
|
|
const ledgerTp = await this._updateTender(transaction);
|
|
|
const begin_time = new Date();
|
|
|
- const updateData = audits.map(x => { return { id: x.id, status: auditConst.status.checking, begin_time } });
|
|
|
+ const updateData = audits.map(x => { return { id: x.id, status: auditConst.status.checking, begin_time, audit_locked: 0 } });
|
|
|
await transaction.updateRows(this.tableName, updateData);
|
|
|
// 计算原报最终数据
|
|
|
const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
@@ -513,7 +513,12 @@ module.exports = app => {
|
|
|
await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
|
|
|
await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
|
|
|
// 流程至下一审批人
|
|
|
- const updateData = nextAudits.map(x => { return { id: x.id, status: auditConst.status.checking, begin_time: time }; });
|
|
|
+ const updateData = nextAudits.map(x => {
|
|
|
+ return {
|
|
|
+ id: x.id, status: x.audit_locked ? auditConst.status.checking : x.status,
|
|
|
+ begin_time: x.audit_locked ? x.begin_time : time, audit_locked: 0,
|
|
|
+ };
|
|
|
+ });
|
|
|
await transaction.updateRows(this.tableName, updateData);
|
|
|
// 同步 期信息
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
@@ -658,15 +663,18 @@ module.exports = app => {
|
|
|
const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
const auditors = await this.getUniqAuditor(stageId, times); // 全部参与的审批人
|
|
|
const newAuditors = auditors.map(x => {
|
|
|
- return {
|
|
|
- aid: x.aid, tid: selfAudit.tid, sid: selfAudit.sid,
|
|
|
- times: times + 1, order: x.audit_order, status: auditConst.status.uncheck,
|
|
|
- audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
- audit_group: x.audit_group, audit_group_order: x.audit_group_order,
|
|
|
- audit_group_limit: x.audit_group_limit, audit_checkno_valid: x.audit_checkno_valid,
|
|
|
- audit_group_need: x.audit_group_need,
|
|
|
- audit_ledger_id: x.audit_ledger_id,
|
|
|
- }
|
|
|
+ const locked = x.audit_locked || (x.audit_type === auditType.key.union && x.status === auditConst.status.checked && x.audit_order === selfAudit.audit_order) ? 1 : 0;
|
|
|
+ return {
|
|
|
+ aid: x.aid, tid: selfAudit.tid, sid: selfAudit.sid,
|
|
|
+ times: times + 1, order: x.audit_order, status: locked ? x.status : auditConst.status.uncheck,
|
|
|
+ begin_time: locked ? x.begin_time : null, end_time: locked ? x.end_time: null,
|
|
|
+ audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
+ audit_group: x.audit_group, audit_group_order: x.audit_group_order,
|
|
|
+ audit_group_limit: x.audit_group_limit, audit_checkno_valid: x.audit_checkno_valid,
|
|
|
+ audit_group_need: x.audit_group_need,
|
|
|
+ audit_ledger_id: x.audit_ledger_id,
|
|
|
+ audit_locked: locked,
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
@@ -890,15 +898,18 @@ module.exports = app => {
|
|
|
}
|
|
|
const newFlowAuditors = [];
|
|
|
flowAudits.forEach(x => {
|
|
|
+ const locked = x.audit_type === auditType.key.union && x.status === auditConst.status.checked ? 1 : 0;
|
|
|
newFlowAuditors.push({
|
|
|
tid: this.ctx.stage.tid, sid: this.ctx.stage.id, aid: x.aid,
|
|
|
times: x.times, order: selfAudit.order + 2,
|
|
|
- status: auditConst.status.uncheck,
|
|
|
+ status: locked ? auditConst.status.checked : auditConst.status.uncheck,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
audit_group: x.audit_group, audit_group_order: x.audit_group_order,
|
|
|
audit_group_limit: x.audit_group_limit, audit_checkno_valid: x.audit_checkno_valid,
|
|
|
audit_group_need: x.audit_group_need,
|
|
|
audit_ledger_id: x.audit_ledger_id,
|
|
|
+ audit_locked: locked,
|
|
|
+ begin_time: locked ? x.begin_time : null, end_time: locked ? x.end_time : null,
|
|
|
});
|
|
|
});
|
|
|
await transaction.insert(this.tableName, newFlowAuditors);
|
|
|
@@ -2368,96 +2379,12 @@ module.exports = app => {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- async lockConfirm4CheckNoPre(stage, uid, pre_uid, transaction) {
|
|
|
- if (!transaction) throw '缺少参数';
|
|
|
-
|
|
|
- const locked = await this.getAllDataByCondition({ where: { sid: stage.id, locked: 1, times: stage.curTimes } });
|
|
|
- locked.forEach(x => {
|
|
|
- x.locked_ledger_id = x.ass_ledger_id.split(',');
|
|
|
- });
|
|
|
- // 审批人数据锁定
|
|
|
- const locking = await this.getAllDataByCondition({ where: { sid: stage.id, times: stage.curTimes, user_id: uid, confirm: 1 } });
|
|
|
- locking.forEach(x => {
|
|
|
- x.locked_ledger_id = x.ass_ledger_id.split(',');
|
|
|
- });
|
|
|
- if (locking.length > 0) {
|
|
|
- const updateLock = locking.map(x => { return { id: x.id, locked: 1 }; });
|
|
|
- await transaction.updateRows(this.tableName, updateLock);
|
|
|
- }
|
|
|
- const preConfirm = await this.getAllDataByCondition({ where: { sid: stage.id, times: stage.curTimes, user_id: pre_uid, confirm: 1 } });
|
|
|
- // 前审批人数据,与被锁定数据相关数据确认状态保留
|
|
|
- locked.push(...locking);
|
|
|
- if (preConfirm.length > 0) {
|
|
|
- const delConfirm = [];
|
|
|
- for (const pc of preConfirm) {
|
|
|
- const bills = await this.ctx.service.ledger.getDataByCondition({ tender_id: stage.tid, ledger_id: pc.ledger_id });
|
|
|
- const billsOwner = bills ? bills.full_path.split('-') : [];
|
|
|
- const exist = locked.find(x => {
|
|
|
- for (const id of x.locked_ledger_id) {
|
|
|
- if (billsOwner.indexOf(id) >= 0) return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- });
|
|
|
- if (!exist) delConfirm.push(pc.id);
|
|
|
- }
|
|
|
- if (delConfirm.length > 0) await transaction.delete(this.tableName, { id: delConfirm });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- async lockConfirm4CheckNo(stage, uid, auditors, transaction) {
|
|
|
- if (!transaction) throw '缺少参数';
|
|
|
- // 审批人数据锁定
|
|
|
- const lockConfirm = await this.getAllDataByCondition({ where: { sid: stage.id, times: stage.curTimes, o: uid, confirm: 1 } });
|
|
|
- if (lockConfirm.length === 0) return;
|
|
|
-
|
|
|
- const insertData = [];
|
|
|
- lockConfirm.forEach(x => {
|
|
|
- delete x.id;
|
|
|
- x.locked = 1;
|
|
|
- x.times = x.times + 1;
|
|
|
- insertData.push(x);
|
|
|
- });
|
|
|
- // 审批人前所有角色,与锁定数据相关确认状态保留
|
|
|
- const keepUid = [ stage.user_id ];
|
|
|
- for (const a of auditors) {
|
|
|
- if (a.aid === uid) break;
|
|
|
- keepUid.push(a.aid);
|
|
|
- }
|
|
|
- const keepConfirm = await this.getAllDataByCondition({ where: { sid: stage.id, times: stage.curTimes, user_id: keepUid, confirm: 1 } });
|
|
|
- for (const kc of keepConfirm) {
|
|
|
- const bills = await this.ctx.service.ledger.getDataByCondition({ tender_id: stage.tid, ledger_id: kc.ledger_id });
|
|
|
- const billsOwner = bills ? bills.full_path.split('-') : [];
|
|
|
- const exist = lockConfirm.find(x => {
|
|
|
- const lid = x.ass_ledger_id.split(',');
|
|
|
- for (const id of lid) {
|
|
|
- if (billsOwner.indexOf(id) >= 0) return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- });
|
|
|
- if (exist) {
|
|
|
- delete kc.id;
|
|
|
- kc.locked = 0;
|
|
|
- kc.times = kc.times + 1;
|
|
|
- insertData.push(kc);
|
|
|
- }
|
|
|
- }
|
|
|
- if (insertData.length > 0) await transaction.insert(this.tableName, insertData);
|
|
|
- }
|
|
|
-
|
|
|
- async cancelLock(stage, uid, transaction) {
|
|
|
- if (transaction) {
|
|
|
- await transaction.update(this.tableName, { locked: 0 }, { where: { sid: stage.id, times: stage.times, aid: uid } });
|
|
|
- } else {
|
|
|
- await this.db.update(this.tableName, { locked: 0 }, { where: { sid: stage.id, times: stage.times, aid: uid } });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- async getLockedId(stage) {
|
|
|
+ async getUnionLockedId(stage) {
|
|
|
return await this.getAllDataByCondition({ where: { sid: stage.id, times: stage.times, audit_locked: 1 } });
|
|
|
}
|
|
|
|
|
|
- async getComfirmLockedId(stage) {
|
|
|
- return await this.getAllDataByCondition({ where: { sid: stage.id, times: stage.times, order: stage.curOrder, status: auditConst.status.checked } });
|
|
|
+ async getAuditLockedId(stage) {
|
|
|
+ return await this.db.query(`SELECT * FROM ${this.tableName} where sid = ? and times = ? and audit_locked_lid <> ''`, [stage.id, stage.times]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -2502,6 +2429,43 @@ module.exports = app => {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ async checkAuditSkip(sid) {
|
|
|
+ const stage = await this.ctx.service.stage.getDataById(sid);
|
|
|
+ if (stage.status === auditConst.status.checked) return;
|
|
|
+ if (stage.status === auditConst.status.uncheck || stage.status === auditConst.status.checkNo) return;
|
|
|
+
|
|
|
+ await this.service.stage.doCheckStage(stage, true);
|
|
|
+ if (!stage.curAuditors || stage.curAuditors[0].audit_type !== auditType.key.union) return;
|
|
|
+
|
|
|
+ const ledgerData = await this.ctx.service.ledger.getData(stage.tid);
|
|
|
+ const curStageData = await this.ctx.service.stageBills.getLastestStageData2(stage.tid, stage.id);
|
|
|
+ const checkCalcFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty'];
|
|
|
+ this.ctx.helper.assignRelaData(ledgerData, [
|
|
|
+ { data: curStageData, fields: checkCalcFields, prefix: '', relaId: 'lid' },
|
|
|
+ ]);
|
|
|
+ const Ledger = require('../lib/ledger');
|
|
|
+ const billsTree = new Ledger.billsTree(this.ctx, {
|
|
|
+ id: 'ledger_id',
|
|
|
+ pid: 'ledger_pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ calcFields: []
|
|
|
+ });
|
|
|
+ billsTree.loadDatas(ledgerData);
|
|
|
+
|
|
|
+ const curTime = new Date();
|
|
|
+ const skipAudit = [];
|
|
|
+ for (const audit of stage.curAuditors) {
|
|
|
+ const auditNodes = audit.audit_ledger_id.split(',').map(x => { return billsTree.getItems(parseInt(x))});
|
|
|
+ if (billsTree.checkNodesUsed(auditNodes, checkCalcFields)) {
|
|
|
+ skipAudit.push({ id: audit.id, status: auditConst.status.checkSkip, opinion: '协同节点未计量', end_time: curTime });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (skipAudit.length === stage.curAuditors.length) skipAudit.pop();
|
|
|
+ if (skipAudit.length > 0) await this.db.updateRows(this.tableName, skipAudit);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return StageAudit;
|