|
@@ -202,132 +202,87 @@ module.exports = app => {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 审批
|
|
|
- * @param {Number} stageId - 标段id
|
|
|
- * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
|
|
|
- * @param {Number} times - 第几次审批
|
|
|
- * @returns {Promise<void>}
|
|
|
- */
|
|
|
- async check(stageId, checkData, times = 1) {
|
|
|
- if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.checkNoPre) {
|
|
|
- throw '提交数据错误';
|
|
|
+ async _checked(stageId, checkData, times) {
|
|
|
+ const time = new Date();
|
|
|
+ // 整理当前流程审核人状态更新
|
|
|
+ const audit = await this.getDataByCondition({sid: stageId, times: times, status: auditConst.status.checking});
|
|
|
+ if (!audit) {
|
|
|
+ throw '审核数据错误';
|
|
|
}
|
|
|
+ const nextAudit = await this.getDataByCondition({sid: stageId, times: times, order: audit.order + 1});
|
|
|
+ const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- // 整理当前流程审核人状态更新
|
|
|
- const time = new Date();
|
|
|
- const audit = await this.getDataByCondition({sid: stageId, times: times, status: auditConst.status.checking});
|
|
|
- if (!audit) {
|
|
|
- throw '审核数据错误';
|
|
|
- }
|
|
|
- // 更新当前审核流程
|
|
|
await transaction.update(this.tableName, {id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time});
|
|
|
- if (checkData.checkType === auditConst.status.checked) { // 审批通过
|
|
|
- const nextAudit = await this.getDataByCondition({sid: stageId, times: times, order: audit.order + 1});
|
|
|
- // 无下一审核人表示,审核结束
|
|
|
- if (nextAudit) {
|
|
|
- // 计算该审批人最终数据
|
|
|
- await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
- // 复制一份下一审核人数据
|
|
|
- await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, nextAudit.order, transaction);
|
|
|
- // 流程至下一审批人
|
|
|
- await transaction.update(this.tableName, {id: nextAudit.id, status: auditConst.status.checking, begin_time: time});
|
|
|
- // 同步 期信息
|
|
|
- const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
- await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: stageId, status: auditConst.status.checking,
|
|
|
- contract_tp: tpData.contract_tp,
|
|
|
- qc_tp: tpData.qc_tp,
|
|
|
- });
|
|
|
- } else {
|
|
|
- // 本期结束
|
|
|
- // 生成截止本期数据 final数据
|
|
|
- await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
- await this.ctx.service.stagePosFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
- // 计算并合同支付最终数据
|
|
|
- await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
- // 同步 期信息
|
|
|
- const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
- await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: stageId, status: checkData.checkType,
|
|
|
- contract_tp: tpData.contract_tp,
|
|
|
- qc_tp: tpData.qc_tp,
|
|
|
- });
|
|
|
- }
|
|
|
- } else if (checkData.checkType === auditConst.status.checkNo) { // 审批退回 原报, times+1
|
|
|
+ // 计算并合同支付最终数据
|
|
|
+ await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // 无下一审核人表示,审核结束
|
|
|
+ if (nextAudit) {
|
|
|
+ // 复制一份下一审核人数据
|
|
|
+ await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, nextAudit.order, transaction);
|
|
|
+ // 流程至下一审批人
|
|
|
+ await transaction.update(this.tableName, {id: nextAudit.id, status: auditConst.status.checking, begin_time: time});
|
|
|
// 同步 期信息
|
|
|
- const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: stageId, status: checkData.checkType,
|
|
|
+ id: stageId, status: auditConst.status.checking,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
- times: times + 1,
|
|
|
});
|
|
|
- // 拷贝新一次审核流程列表
|
|
|
- // const auditors = await this.getAllDataByCondition({
|
|
|
- // where: {sid: stageId, times: times},
|
|
|
- // columns: ['tid', 'sid', 'aid', 'order']
|
|
|
- // });
|
|
|
- const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid`';
|
|
|
- const sqlParam = [this.tableName, stageId, times];
|
|
|
- const auditors = await this.db.query(sql, sqlParam);
|
|
|
- let order = 1;
|
|
|
- for (const a of auditors) {
|
|
|
- a.times = times + 1;
|
|
|
- a.order = order;
|
|
|
- a.status = auditConst.status.uncheck;
|
|
|
- order++;
|
|
|
- }
|
|
|
- await transaction.insert(this.tableName, auditors);
|
|
|
- // 计算该审批人最终数据
|
|
|
- await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
- // 复制一份最新数据给原报
|
|
|
- await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times + 1, 0, transaction);
|
|
|
- } else if (checkData.checkType === auditConst.status.checkNoPre) { // 审批退回 上一审批人
|
|
|
+ } else {
|
|
|
+ // 本期结束
|
|
|
+ // 生成截止本期数据 final数据
|
|
|
+ await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
+ await this.ctx.service.stagePosFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
// 同步 期信息
|
|
|
- const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
id: stageId, status: checkData.checkType,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
});
|
|
|
- // 将当前审批人 与 上一审批人再次添加至流程,顺移其后审批人流程顺序
|
|
|
- if (audit.order > 1) {
|
|
|
- // 顺移气候审核人流程顺序
|
|
|
- this.initSqlBuilder();
|
|
|
- this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=', });
|
|
|
- this.sqlBuilder.setAndWhere('order', { value: audit.order, operate: '>', });
|
|
|
- this.sqlBuilder.setUpdateData('order', { value: 2, selfOperate: '+', });
|
|
|
- const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
- const data = await transaction.query(sql, sqlParam);
|
|
|
-
|
|
|
- // 上一审批人,当前审批人 再次添加至流程
|
|
|
- const preAuditor = await this.getDataByCondition({sid: stageId, times: times, order: audit.order - 1});
|
|
|
- const newAuditors = [];
|
|
|
- newAuditors.push({
|
|
|
- tid: preAuditor.tid, sid: preAuditor.sid, aid: preAuditor.aid,
|
|
|
- times: preAuditor.times, order: preAuditor.order + 2, status: auditConst.status.checking,
|
|
|
- begin_time: time,
|
|
|
- });
|
|
|
- newAuditors.push({
|
|
|
- tid: audit.tid, sid: audit.sid, aid: audit.aid,
|
|
|
- times: audit.times, order: audit.order + 2, status: auditConst.status.uncheck
|
|
|
- });
|
|
|
- await transaction.insert(this.tableName, newAuditors);
|
|
|
-
|
|
|
- // 计算该审批人最终数据
|
|
|
- await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
- // 复制一份最新数据给上一人
|
|
|
- await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction);
|
|
|
- } else {
|
|
|
- throw '审核数据错误';
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw '无效审批操作';
|
|
|
}
|
|
|
+ await transaction.commit();
|
|
|
+ } catch (err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async _checkNo(stageId, checkData, times) {
|
|
|
+ const time = new Date();
|
|
|
+ // 整理当前流程审核人状态更新
|
|
|
+ const audit = await this.getDataByCondition({sid: stageId, times: times, status: auditConst.status.checking});
|
|
|
+ if (!audit) {
|
|
|
+ throw '审核数据错误';
|
|
|
+ }
|
|
|
+ const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid`';
|
|
|
+ const sqlParam = [this.tableName, stageId, times];
|
|
|
+ const auditors = await this.db.query(sql, sqlParam);
|
|
|
+ let order = 1;
|
|
|
+ for (const a of auditors) {
|
|
|
+ a.times = times + 1;
|
|
|
+ a.order = order;
|
|
|
+ a.status = auditConst.status.uncheck;
|
|
|
+ order++;
|
|
|
+ }
|
|
|
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ await transaction.update(this.tableName, {id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time});
|
|
|
+ // 同步 期信息
|
|
|
+ await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
+ id: stageId, status: checkData.checkType,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
+ times: times + 1,
|
|
|
+ });
|
|
|
+ // 拷贝新一次审核流程列表
|
|
|
+ await transaction.insert(this.tableName, auditors);
|
|
|
+ // 计算该审批人最终数据
|
|
|
+ await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // 复制一份最新数据给原报
|
|
|
+ await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times + 1, 0, transaction);
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
@@ -335,6 +290,195 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async _checkNoPre(stageId, checkData, times) {
|
|
|
+ const time = new Date();
|
|
|
+ // 整理当前流程审核人状态更新
|
|
|
+ const audit = await this.getDataByCondition({sid: stageId, times: times, status: auditConst.status.checking});
|
|
|
+ if (!audit || audit.order <= 1) {
|
|
|
+ throw '审核数据错误';
|
|
|
+ }
|
|
|
+ const preAuditor = await this.getDataByCondition({sid: stageId, times: times, order: audit.order - 1});
|
|
|
+
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ await transaction.update(this.tableName, {id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time});
|
|
|
+ // 顺移气候审核人流程顺序
|
|
|
+ this.initSqlBuilder();
|
|
|
+ this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=', });
|
|
|
+ this.sqlBuilder.setAndWhere('order', { value: audit.order, operate: '>', });
|
|
|
+ this.sqlBuilder.setUpdateData('order', { value: 2, selfOperate: '+', });
|
|
|
+ const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
+ const data = await transaction.query(sql, sqlParam);
|
|
|
+ // 上一审批人,当前审批人 再次添加至流程
|
|
|
+ const newAuditors = [];
|
|
|
+ newAuditors.push({
|
|
|
+ tid: preAuditor.tid, sid: preAuditor.sid, aid: preAuditor.aid,
|
|
|
+ times: preAuditor.times, order: preAuditor.order + 2, status: auditConst.status.checking,
|
|
|
+ begin_time: time,
|
|
|
+ });
|
|
|
+ newAuditors.push({
|
|
|
+ tid: audit.tid, sid: audit.sid, aid: audit.aid,
|
|
|
+ times: audit.times, order: audit.order + 2, status: auditConst.status.uncheck
|
|
|
+ });
|
|
|
+ await transaction.insert(this.tableName, newAuditors);
|
|
|
+ // 计算该审批人最终数据
|
|
|
+ await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // 复制一份最新数据给下一人
|
|
|
+ await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction);
|
|
|
+ await transaction.commit();
|
|
|
+ } catch(err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批
|
|
|
+ * @param {Number} stageId - 标段id
|
|
|
+ * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
|
|
|
+ * @param {Number} times - 第几次审批
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
+ async check(stageId, checkData, times = 1) {
|
|
|
+ if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.checkNoPre) {
|
|
|
+ throw '提交数据错误';
|
|
|
+ }
|
|
|
+ // // 整理当前流程审核人状态更新
|
|
|
+ // const audit = await this.getDataByCondition({sid: stageId, times: times, status: auditConst.status.checking});
|
|
|
+ // if (!audit) {
|
|
|
+ // throw '审核数据错误';
|
|
|
+ // }
|
|
|
+ //const time = new Date();
|
|
|
+
|
|
|
+ switch (checkData.checkType) {
|
|
|
+ case auditConst.status.checked:
|
|
|
+ await this._checked(stageId, checkData, times);
|
|
|
+ break;
|
|
|
+ case auditConst.status.checkNo:
|
|
|
+ await this._checkNo(stageId, checkData, times);
|
|
|
+ break;
|
|
|
+ case auditConst.status.checkNoPre:
|
|
|
+ await this._checkNoPre(stageId, checkData, times);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw '无效审批操作';
|
|
|
+ }
|
|
|
+
|
|
|
+ // const transaction = await this.db.beginTransaction();
|
|
|
+ // try {
|
|
|
+ // // 更新当前审核流程
|
|
|
+ // await transaction.update(this.tableName, {id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time});
|
|
|
+ // if (checkData.checkType === auditConst.status.checked) { // 审批通过
|
|
|
+ // const nextAudit = await this.getDataByCondition({sid: stageId, times: times, order: audit.order + 1});
|
|
|
+ // // 无下一审核人表示,审核结束
|
|
|
+ // if (nextAudit) {
|
|
|
+ // // 计算该审批人最终数据
|
|
|
+ // await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // // 复制一份下一审核人数据
|
|
|
+ // await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, nextAudit.order, transaction);
|
|
|
+ // // 流程至下一审批人
|
|
|
+ // await transaction.update(this.tableName, {id: nextAudit.id, status: auditConst.status.checking, begin_time: time});
|
|
|
+ // // 同步 期信息
|
|
|
+ // const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ // await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
+ // id: stageId, status: auditConst.status.checking,
|
|
|
+ // contract_tp: tpData.contract_tp,
|
|
|
+ // qc_tp: tpData.qc_tp,
|
|
|
+ // });
|
|
|
+ // } else {
|
|
|
+ // // 本期结束
|
|
|
+ // // 生成截止本期数据 final数据
|
|
|
+ // await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
+ // await this.ctx.service.stagePosFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
+ // // 计算并合同支付最终数据
|
|
|
+ // await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // // 同步 期信息
|
|
|
+ // const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ // await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
+ // id: stageId, status: checkData.checkType,
|
|
|
+ // contract_tp: tpData.contract_tp,
|
|
|
+ // qc_tp: tpData.qc_tp,
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // } else if (checkData.checkType === auditConst.status.checkNo) { // 审批退回 原报, times+1
|
|
|
+ // // 同步 期信息
|
|
|
+ // const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ // await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
+ // id: stageId, status: checkData.checkType,
|
|
|
+ // contract_tp: tpData.contract_tp,
|
|
|
+ // qc_tp: tpData.qc_tp,
|
|
|
+ // times: times + 1,
|
|
|
+ // });
|
|
|
+ // // 拷贝新一次审核流程列表
|
|
|
+ // // const auditors = await this.getAllDataByCondition({
|
|
|
+ // // where: {sid: stageId, times: times},
|
|
|
+ // // columns: ['tid', 'sid', 'aid', 'order']
|
|
|
+ // // });
|
|
|
+ // const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid`';
|
|
|
+ // const sqlParam = [this.tableName, stageId, times];
|
|
|
+ // const auditors = await this.db.query(sql, sqlParam);
|
|
|
+ // let order = 1;
|
|
|
+ // for (const a of auditors) {
|
|
|
+ // a.times = times + 1;
|
|
|
+ // a.order = order;
|
|
|
+ // a.status = auditConst.status.uncheck;
|
|
|
+ // order++;
|
|
|
+ // }
|
|
|
+ // await transaction.insert(this.tableName, auditors);
|
|
|
+ // // 计算该审批人最终数据
|
|
|
+ // await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // // 复制一份最新数据给原报
|
|
|
+ // await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times + 1, 0, transaction);
|
|
|
+ // } else if (checkData.checkType === auditConst.status.checkNoPre) { // 审批退回 上一审批人
|
|
|
+ // // 同步 期信息
|
|
|
+ // const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ // await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
+ // id: stageId, status: checkData.checkType,
|
|
|
+ // contract_tp: tpData.contract_tp,
|
|
|
+ // qc_tp: tpData.qc_tp,
|
|
|
+ // });
|
|
|
+ // // 将当前审批人 与 上一审批人再次添加至流程,顺移其后审批人流程顺序
|
|
|
+ // if (audit.order > 1) {
|
|
|
+ // // 顺移气候审核人流程顺序
|
|
|
+ // this.initSqlBuilder();
|
|
|
+ // this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=', });
|
|
|
+ // this.sqlBuilder.setAndWhere('order', { value: audit.order, operate: '>', });
|
|
|
+ // this.sqlBuilder.setUpdateData('order', { value: 2, selfOperate: '+', });
|
|
|
+ // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
+ // const data = await transaction.query(sql, sqlParam);
|
|
|
+ //
|
|
|
+ // // 上一审批人,当前审批人 再次添加至流程
|
|
|
+ // const preAuditor = await this.getDataByCondition({sid: stageId, times: times, order: audit.order - 1});
|
|
|
+ // const newAuditors = [];
|
|
|
+ // newAuditors.push({
|
|
|
+ // tid: preAuditor.tid, sid: preAuditor.sid, aid: preAuditor.aid,
|
|
|
+ // times: preAuditor.times, order: preAuditor.order + 2, status: auditConst.status.checking,
|
|
|
+ // begin_time: time,
|
|
|
+ // });
|
|
|
+ // newAuditors.push({
|
|
|
+ // tid: audit.tid, sid: audit.sid, aid: audit.aid,
|
|
|
+ // times: audit.times, order: audit.order + 2, status: auditConst.status.uncheck
|
|
|
+ // });
|
|
|
+ // await transaction.insert(this.tableName, newAuditors);
|
|
|
+ //
|
|
|
+ // // 计算该审批人最终数据
|
|
|
+ // await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // // 复制一份最新数据给上一人
|
|
|
+ // await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction);
|
|
|
+ // } else {
|
|
|
+ // throw '审核数据错误';
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // throw '无效审批操作';
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // await transaction.commit();
|
|
|
+ // } catch (err) {
|
|
|
+ // await transaction.rollback();
|
|
|
+ // throw err;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取审核人需要审核的期列表
|
|
|
*
|