|
@@ -124,6 +124,7 @@ module.exports = app => {
|
|
|
level: 'level',
|
|
|
rootId: -1
|
|
|
});
|
|
|
+ this.resultTenderInfo = [];
|
|
|
}
|
|
|
|
|
|
_checkSpecialTender(tender, special) {
|
|
@@ -135,6 +136,9 @@ module.exports = app => {
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 台账数据
|
|
|
+ */
|
|
|
async _gatherStageData(index, tender, stage, hasPre) {
|
|
|
const helper = this.ctx.helper;
|
|
|
const billsTree = new Ledger.billsTree(this.ctx, {
|
|
@@ -308,7 +312,7 @@ module.exports = app => {
|
|
|
await this._gatherStageData(index, tender, stages[0], hasPre);
|
|
|
}
|
|
|
|
|
|
- async _gatherLegerData(sTender, index) {
|
|
|
+ async _gatherLedgerData(sTender, index) {
|
|
|
const helper = this.ctx.helper;
|
|
|
const billsTree = new Ledger.billsTree(this.ctx, {
|
|
|
id: 'ledger_id',
|
|
@@ -318,7 +322,7 @@ module.exports = app => {
|
|
|
rootId: -1,
|
|
|
keys: ['id', 'tender_id', 'ledger_id'],
|
|
|
stageId: 'id',
|
|
|
- calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
|
|
|
+ calcFields: ['deal_tp', 'total_price'],
|
|
|
});
|
|
|
const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
|
|
|
const billsData = await this.ctx.service.ledger.getData(tender.id);
|
|
@@ -339,7 +343,7 @@ module.exports = app => {
|
|
|
rootId: -1,
|
|
|
keys: ['id', 'tender_id', 'ledger_id'],
|
|
|
stageId: 'id',
|
|
|
- calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
|
|
|
+ calcFields: ['deal_tp', 'total_price'],
|
|
|
});
|
|
|
const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
|
|
|
const billsData = await this.ctx.service.ledger.getData(tender.id);
|
|
@@ -373,7 +377,7 @@ module.exports = app => {
|
|
|
await this._gatherCheckedFinalData(tender, commonIndex, gsSetting.hasPre);
|
|
|
break;
|
|
|
case 'ledger':
|
|
|
- await this._gatherLegerData(tender, commonIndex);
|
|
|
+ await this._gatherLedgerData(tender, commonIndex);
|
|
|
break;
|
|
|
}
|
|
|
commonIndex++;
|
|
@@ -386,6 +390,189 @@ module.exports = app => {
|
|
|
return this.resultTree.getDefaultDatas();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 标段信息
|
|
|
+ */
|
|
|
+ async _getBaseTenderInfo(tender) {
|
|
|
+ const info = {
|
|
|
+ id: tender.id,
|
|
|
+ name: tender.name,
|
|
|
+
|
|
|
+ deal_tp: tender.deal_tp,
|
|
|
+ tp: tender.total_price
|
|
|
+ };
|
|
|
+ if (tender.ledger_status === auditConst.ledger.status.uncheck || tender.ledger_status === auditConst.ledger.status.checkNo) {
|
|
|
+ const sum = await this.ctx.service.ledger.addUp({tender_id: tender.id/*, is_leaf: true*/});
|
|
|
+ info.tp = sum.total_price;
|
|
|
+ info.deal_tp = sum.deal_tp;
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+ async _getStageTenderInfo(stage, info) {
|
|
|
+ if (stage) {
|
|
|
+ const helper = this.ctx.helper;
|
|
|
+ await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+ await this.ctx.service.stage.checkStageGatherData(stage);
|
|
|
+
|
|
|
+ info.pre_contract_tp = stage.pre_contract_tp;
|
|
|
+ info.pre_qc_tp = stage.pre_qc_tp;
|
|
|
+ info.pre_gather_tp = helper.add(info.pre_contract_tp, info.pre_qc_tp);
|
|
|
+
|
|
|
+ info.contract_tp = stage.contract_tp;
|
|
|
+ info.qc_tp = stage.qc_tp;
|
|
|
+ info.gather_tp = helper.add(info.contract_tp, info.qc_tp);
|
|
|
+
|
|
|
+ info.end_contract_tp = helper.add(info.pre_contract_tp, info.contract_tp);
|
|
|
+ info.end_qc_tp = helper.add(info.pre_qc_tp, info.qc_tp);
|
|
|
+ info.end_gather_tp = helper.add(info.pre_gather_tp, info.gather_tp);
|
|
|
+
|
|
|
+ info.yf = stage.yf;
|
|
|
+ info.pre_yf = stage.pre_yf;
|
|
|
+ info.end_yf = helper.add(stage.yf, stage.pre_yf);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async _gatherMonthTenderInfo(sTender, index, month, hasPre) {
|
|
|
+ const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
|
|
|
+ const info = this._getBaseTenderInfo(tender);
|
|
|
+ const stage = await this.ctx.service.stage.getDataByCondition({tid: tender.id, s_time: month});
|
|
|
+ this._getStageTenderInfo(stage, info);
|
|
|
+ this.resultTenderInfo.push(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ async _gatherZoneTenderInfo(sTender, index, zone) {
|
|
|
+ const helper = this.ctx.helper;
|
|
|
+ /**
|
|
|
+ * 汇总并合并 相关数据
|
|
|
+ * @param {Array} index - 主数据
|
|
|
+ * @param {Array[]}rela - 相关数据 {data, fields, prefix, relaId}
|
|
|
+ */
|
|
|
+ const sumAssignRelaData = function (index, rela) {
|
|
|
+ const loadFields = function (datas, fields, prefix, relaId) {
|
|
|
+ for (const d of datas) {
|
|
|
+ const key = indexPre + d[relaId];
|
|
|
+ const m = index[key];
|
|
|
+ if (m) {
|
|
|
+ for (const f of fields) {
|
|
|
+ if (d[f] !== undefined) {
|
|
|
+ m[prefix + f] = helper.add(m[prefix + f], d[f]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ for (const r of rela) {
|
|
|
+ loadFields(r.data, r.fields, r.prefix, r.relaId);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
|
|
|
+ const info = this._getBaseTenderInfo(tender);
|
|
|
+
|
|
|
+ const times = zone.split(' - ');
|
|
|
+ if (times.length !== 2) throw '选择的汇总周期无效';
|
|
|
+ const beginTime = moment(times[0], 'YYYY-MM').date();
|
|
|
+ const endTime = moment(times[1], 'YYYY-MM').date();
|
|
|
+
|
|
|
+ const stages = await this.ctx.service.stage.getAllDataByCondition({ where: { tid: tender.id } });
|
|
|
+ for (const stage of stages) {
|
|
|
+ const sTime = moment(stage.s_time, 'YYYY-MM').date();
|
|
|
+ if (sTime >= beginTime && sTime <= endTime) {
|
|
|
+ await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+ await this.ctx.service.stage.checkStageGatherData(stage);
|
|
|
+
|
|
|
+ info.contract_tp = helper.add(info.contract_tp, stage.contract_tp);
|
|
|
+ info.qc_tp = helper.add(info.qc_tp, stage.qc_tp);
|
|
|
+
|
|
|
+ info.yf = helper.add(info.yf, stage.yf);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ info.gather_tp = helper.add(info.contract_tp, info.qc_tp);
|
|
|
+
|
|
|
+ this.resultTenderInfo.push(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ async _gatherFinalTenderInfo(sTender, index, hasPre) {
|
|
|
+ const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
|
|
|
+ const info = this._getBaseTenderInfo(tender);
|
|
|
+ const stages = await this.db.select(this.ctx.service.stage.tableName, {
|
|
|
+ where: { tid: tender.id },
|
|
|
+ orders: [['order', 'desc']],
|
|
|
+ });
|
|
|
+ if (stages.length !== 0) {
|
|
|
+ const lastStage = stages[0];
|
|
|
+ if (lastStage.status === auditConst.stage.status.uncheck && lastStage.user_id !== this.ctx.session.sessionUser.accountId) {
|
|
|
+ stages.splice(0, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await this._getStageTenderInfo(stages[0], info);
|
|
|
+ this.resultTenderInfo.push(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ async _gatherCheckedFinalTenderInfo(sTender, index, hasPre) {
|
|
|
+ const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
|
|
|
+ const info = this._getBaseTenderInfo(tender);
|
|
|
+ const stages = await this.db.select(this.ctx.service.stage.tableName, {
|
|
|
+ where: { tid: tender.id },
|
|
|
+ orders: [['order', 'desc']],
|
|
|
+ });
|
|
|
+ if (stages.length !== 0) {
|
|
|
+ const lastStage = stages[0];
|
|
|
+ if (lastStage.status !== auditConst.stage.status.checked) {
|
|
|
+ stages.splice(0, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await this._getStageTenderInfo(stages[0], info);
|
|
|
+ this.resultTenderInfo.push(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ async _gatherLedgerTenderInfo(sTender, index) {
|
|
|
+ const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
|
|
|
+ const info = this._getBaseTenderInfo(tender);
|
|
|
+ this.resultTenderInfo.push(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ async _gatherSpecialTenderInfo(sTender, sKey) {
|
|
|
+ const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
|
|
|
+
|
|
|
+ const info = this._getBaseTenderInfo(tender);
|
|
|
+ info.spec = sKey;
|
|
|
+ this.resultTenderInfo.push(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getGatherTenderInfo(memFieldKeys, gsDefine, gsCustom) {
|
|
|
+ if (!gsDefine || !gsDefine.enable) return [];
|
|
|
+ if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
|
|
|
+
|
|
|
+ this.resultTenderInfo = [];
|
|
|
+ const gsSetting = JSON.parse(gsDefine.setting);
|
|
|
+ let commonIndex = 0;
|
|
|
+ for (const tender of gsCustom.tenders) {
|
|
|
+ const specialKey = this._checkSpecialTender(tender, gsSetting.special);
|
|
|
+ if (specialKey === '') {
|
|
|
+ switch (gsSetting.type) {
|
|
|
+ case 'month':
|
|
|
+ await this._gatherMonthTenderInfo(tender, commonIndex, gsCustom.month, gsSetting.hasPre);
|
|
|
+ break;
|
|
|
+ case 'zone':
|
|
|
+ await this._gatherZoneTenderInfo(tender, commonIndex, gsCustom.zone);
|
|
|
+ break;
|
|
|
+ case 'final':
|
|
|
+ await this._gatherFinalTenderInfo(tender, commonIndex, gsSetting.hasPre);
|
|
|
+ break;
|
|
|
+ case 'checked-final':
|
|
|
+ await this._gatherCheckedFinalTenderInfo(tender, commonIndex, gsSetting.hasPre);
|
|
|
+ break;
|
|
|
+ case 'ledger':
|
|
|
+ await this._gatherLedgerTenderInfo(tender, commonIndex);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ commonIndex++;
|
|
|
+ } else {
|
|
|
+ await this._gatherSpecialTenderInfo(tender, specialKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return RptGatherMemory;
|