|
@@ -80,6 +80,8 @@ module.exports = app => {
|
|
|
stage.curAuditorIds = this._.map(stage.curAuditors, 'aid');
|
|
|
stage.flowAuditors = stage.curAuditors.length > 0 ? stage.auditors.filter(x => { return x.order === stage.curAuditors[0].order; }) : []; // 当前流程中参与的审批人(包含会签时,审批通过的人)
|
|
|
stage.flowAuditorIds = this._.map(stage.flowAuditors, 'aid');
|
|
|
+ stage.nextAuditors = stage.curAuditors.length > 0 ? stage.auditors.filter(x => { return x.order === stage.curAuditors[0].order + 1; }) : [];
|
|
|
+ stage.nextAuditorIds = this._.map(stage.nextAuditors, 'aid');
|
|
|
stage.auditorGroups = this.ctx.helper.groupAuditors(stage.auditors);
|
|
|
stage.userGroups = this.ctx.helper.groupAuditorsUniq(stage.auditorGroups);
|
|
|
stage.userGroups.unshift([{
|
|
@@ -124,9 +126,23 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async loadPreCheckedStage(stage) {
|
|
|
+ if (stage.order > 1) {
|
|
|
+ const preCheckedStages = await this.ctx.service.stage.getAllDataByCondition({
|
|
|
+ where: { tid: stage.tid, status: auditConst.stage.status.checked },
|
|
|
+ orders: [['order', 'desc']],
|
|
|
+ });
|
|
|
+ stage.preCheckedStage = preCheckedStages[0];
|
|
|
+ } else {
|
|
|
+ stage.preCheckedStage = undefined;
|
|
|
+ }
|
|
|
+ stage.isCheckFirst = stage.order > 1 ? (stage.preCheckedStage ? stage.preCheckedStage.order === stage.order - 1 : false) : true;
|
|
|
+ }
|
|
|
+
|
|
|
async doCheckStage(stage, force = false) {
|
|
|
const status = auditConst.stage.status;
|
|
|
await this.loadStageUser(stage);
|
|
|
+ await this.loadPreCheckedStage(stage);
|
|
|
|
|
|
const accountId = this.ctx.session.sessionUser.accountId, shareIds = [];
|
|
|
const isTenderTourist = await this.service.tenderTourist.getDataByCondition({ tid: stage.tid, user_id: accountId });
|
|
@@ -408,12 +424,17 @@ module.exports = app => {
|
|
|
if (sf && s.readOnly) {
|
|
|
await this.ctx.service.stage.update({ sf_tp: sf.tp, pre_sf_tp: sf.pre_tp }, { id: s.id });
|
|
|
}
|
|
|
- s.sf_tp = sf.tp;
|
|
|
+ s.sf_tp = sf ? sf.tp : 0;
|
|
|
}
|
|
|
}
|
|
|
return stages;
|
|
|
}
|
|
|
|
|
|
+ async getNextStages(tenderId, order) {
|
|
|
+ const sql = 'SELECT * FROM ?? WHERE tid = ? AND `order` > ?';
|
|
|
+ return await this.db.query(sql, [this.tableName, tenderId, order]);
|
|
|
+ }
|
|
|
+
|
|
|
async _getSumTp(condition, ...field) {
|
|
|
const fieldSql = [];
|
|
|
for (const f of field) {
|
|
@@ -434,12 +455,10 @@ module.exports = app => {
|
|
|
async addStage(tenderId, date, period) {
|
|
|
const stages = await this.getAllDataByCondition({
|
|
|
where: { tid: tenderId },
|
|
|
- order: ['order'],
|
|
|
+ order: [['order', 'asc']],
|
|
|
});
|
|
|
const preStage = stages[stages.length - 1];
|
|
|
- if (stages.length > 0 && stages[stages.length - 1].status !== auditConst.stage.status.checked) {
|
|
|
- throw '上一期未审批通过,请等待上一期审批通过后,再新增数据';
|
|
|
- }
|
|
|
+ const preCheckedStage = stages.find(x => { return x.status === auditConst.stage.status.checked; });
|
|
|
const order = stages.length + 1;
|
|
|
const newStage = {
|
|
|
sid: this.uuid.v4(),
|
|
@@ -460,16 +479,18 @@ module.exports = app => {
|
|
|
newStage.im_pre = preStage.im_pre;
|
|
|
newStage.im_gather = preStage.im_gather;
|
|
|
newStage.im_gather_node = preStage.im_gather_node;
|
|
|
- newStage.pre_contract_tp = this.ctx.helper.sum([preStage.pre_contract_tp, preStage.contract_tp, preStage.contract_pc_tp]);
|
|
|
- newStage.pre_qc_tp = this.ctx.helper.sum([preStage.pre_qc_tp, preStage.qc_tp, preStage.qc_pc_tp]);
|
|
|
- newStage.pre_positive_qc_tp = this.ctx.helper.sum([preStage.pre_positive_qc_tp, preStage.positive_qc_tp, preStage.positive_qc_pc_tp]);
|
|
|
- newStage.pre_negative_qc_tp = this.ctx.helper.sum([preStage.pre_negative_qc_tp, preStage.negative_qc_tp, preStage.negative_qc_pc_tp]);
|
|
|
- newStage.pre_yf_tp = this.ctx.helper.add(preStage.pre_yf_tp, preStage.yf_tp);
|
|
|
- if (preStage.order === 1 || preStage.pre_sf_tp) {
|
|
|
- newStage.pre_sf_tp = this.ctx.helper.add(preStage.pre_sf_tp, preStage.sf_tp);
|
|
|
- } else {
|
|
|
- const sumTp = await this._getSumTp({tid: preStage.tid}, 'sf_tp');
|
|
|
- newStage.pre_sf_tp = sumTp.sf_tp || 0;
|
|
|
+ if (preCheckedStage) {
|
|
|
+ newStage.pre_contract_tp = this.ctx.helper.sum([preCheckedStage.pre_contract_tp, preCheckedStage.contract_tp, preCheckedStage.contract_pc_tp]);
|
|
|
+ newStage.pre_qc_tp = this.ctx.helper.sum([preCheckedStage.pre_qc_tp, preStage.qc_tp, preCheckedStage.qc_pc_tp]);
|
|
|
+ newStage.pre_positive_qc_tp = this.ctx.helper.sum([preCheckedStage.pre_positive_qc_tp, preCheckedStage.positive_qc_tp, preCheckedStage.positive_qc_pc_tp]);
|
|
|
+ newStage.pre_negative_qc_tp = this.ctx.helper.sum([preCheckedStage.pre_negative_qc_tp, preCheckedStage.negative_qc_tp, preCheckedStage.negative_qc_pc_tp]);
|
|
|
+ newStage.pre_yf_tp = this.ctx.helper.add(preCheckedStage.pre_yf_tp, preStage.yf_tp);
|
|
|
+ if (preCheckedStage.order === 1 || preCheckedStage.pre_sf_tp) {
|
|
|
+ newStage.pre_sf_tp = this.ctx.helper.add(preCheckedStage.pre_sf_tp, preCheckedStage.sf_tp);
|
|
|
+ } else {
|
|
|
+ const sumTp = await this._getSumTp({tid: preCheckedStage.tid}, 'sf_tp');
|
|
|
+ newStage.pre_sf_tp = sumTp.sf_tp || 0;
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
const projFunRela = await this.ctx.service.project.getFunRela(this.ctx.session.sessionProject.id);
|
|
@@ -498,16 +519,18 @@ module.exports = app => {
|
|
|
}
|
|
|
// 新增期其他台账数据
|
|
|
let pcTp = { contract_pc_tp: 0, qc_pc_tp: 0, pc_tp: 0, positive_qc_pc_tp: 0, negative_qc_pc_tp: 0 };
|
|
|
- if (preStage) {
|
|
|
- const jgclResult = await this.ctx.service.stageJgcl.addInitialStageData(newStage, preStage, transaction);
|
|
|
+ if (preCheckedStage) {
|
|
|
+ const jgclResult = await this.ctx.service.stageJgcl.addInitialStageData(newStage, preCheckedStage, transaction);
|
|
|
if (!jgclResult) throw '初始化甲供材料数据失败';
|
|
|
- const otherResult = await this.ctx.service.stageOther.addInitialStageData(newStage, preStage, transaction);
|
|
|
+ const otherResult = await this.ctx.service.stageOther.addInitialStageData(newStage, preCheckedStage, transaction);
|
|
|
if (!otherResult) throw '初始化其他台账数据失败';
|
|
|
- const safeResult = await this.ctx.service.stageSafeProd.addInitialStageData(newStage, preStage, transaction);
|
|
|
+ const safeResult = await this.ctx.service.stageSafeProd.addInitialStageData(newStage, preCheckedStage, transaction);
|
|
|
if (!safeResult) throw '初始化其他台账数据失败';
|
|
|
- const tempResult = await this.ctx.service.stageTempLand.addInitialStageData(newStage, preStage, transaction);
|
|
|
+ const tempResult = await this.ctx.service.stageTempLand.addInitialStageData(newStage, preCheckedStage, transaction);
|
|
|
if (!tempResult) throw '初始化其他台账数据失败';
|
|
|
+ }
|
|
|
|
|
|
+ if (preStage && preCheckedStage && preStage.order === preCheckedStage.order) {
|
|
|
const priceCalc = new RevisePrice(this.ctx);
|
|
|
pcTp = await priceCalc.newStagePriceChange(newStage, preStage, transaction);
|
|
|
}
|