|
@@ -8,6 +8,8 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
+const _ = require('lodash');
|
|
|
+
|
|
|
const StageIm = require('../lib/stage_im');
|
|
|
const imType = require('../const/tender').imType;
|
|
|
const audit = require('../const/audit');
|
|
@@ -21,6 +23,15 @@ const stageImVersion = '1.0';
|
|
|
|
|
|
const Ledger = require('../lib/ledger');
|
|
|
|
|
|
+const curFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil'];
|
|
|
+const preFields = ['pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp'];
|
|
|
+const endFields = ['end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp'];
|
|
|
+const finalFields = ['final_tp', 'final_ratio'];
|
|
|
+
|
|
|
+const stageFields = curFields.concat(preFields, endFields, finalFields);
|
|
|
+const stageEndFields = preFields.concat(endFields, finalFields);
|
|
|
+const bglFields = ['qc_bgl_code'];
|
|
|
+
|
|
|
module.exports = app => {
|
|
|
class ReportMemory extends app.BaseService {
|
|
|
|
|
@@ -78,6 +89,13 @@ module.exports = app => {
|
|
|
this.stageImData = null;
|
|
|
}
|
|
|
|
|
|
+ _checkFieldsExist(source, check) {
|
|
|
+ for (const s of source) {
|
|
|
+ if (check.indexOf(s)) return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
// build-time: 162-384ms, redis-cache: 0-41ms, mysql + IO: 116-146ms
|
|
|
// 一定程度上算是大Value缓存,数据多了以后:
|
|
|
// 1. 达到redis内存阈值时,数据会swap到磁盘,此时将消耗IO时间
|
|
@@ -280,31 +298,58 @@ module.exports = app => {
|
|
|
return monthProgress;
|
|
|
}
|
|
|
|
|
|
+ async _calcBillsBgl() {
|
|
|
+ const helper = this.ctx.helper;
|
|
|
+ const tender = this.ctx.tender;
|
|
|
+ const stage = this.ctx.stage;
|
|
|
+ const bglData = this.ctx.stage.readOnly
|
|
|
+ ? await this.ctx.service.stageChange.getAuditorAllStageData(tender.id, stage.id, stage.curTimes, stage.curOrder)
|
|
|
+ : await this.ctx.service.stageChange.getLastestAllStageData(tender.id, stage.id);
|
|
|
+
|
|
|
+ for (const node of this.billsTree.nodes) {
|
|
|
+ node.qc_bgl_code = '';
|
|
|
+ if (node.children && node.children.length > 0) continue;
|
|
|
+
|
|
|
+ const nodeBgl = helper._.pullAllBy(bglData, [{lid: node.id}], 'lid');
|
|
|
+ const validBgl = helper._.filter(nodeBgl, function (x) {
|
|
|
+ return !helper.checkZero(x.qty);
|
|
|
+ });
|
|
|
+ node.qc_bgl_code = helper._.uniq(helper._.map(validBgl, 'c_code')).join(';');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async getStageBillsData(tid, sid, fields) {
|
|
|
await this.ctx.service.tender.checkTender(tid);
|
|
|
await this.ctx.service.stage.checkStage(sid);
|
|
|
|
|
|
const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
|
|
|
- if (this.ctx.stage.readOnly) {
|
|
|
- const curStage = await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id,
|
|
|
- this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
|
|
|
- this.ctx.helper.assignRelaData(billsData, [
|
|
|
- {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
|
|
|
- ]);
|
|
|
- } else {
|
|
|
- const curStage = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
|
|
|
+ if (this._checkFieldsExist(fields, stageFields)) {
|
|
|
+ if (this.ctx.stage.readOnly) {
|
|
|
+ const curStage = await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id,
|
|
|
+ this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
|
|
|
+ this.ctx.helper.assignRelaData(billsData, [
|
|
|
+ {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ const curStage = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
|
|
|
+ this.ctx.helper.assignRelaData(billsData, [
|
|
|
+ {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (this._checkFieldsExist(fields, preFields)) {
|
|
|
+ const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
|
|
|
this.ctx.helper.assignRelaData(billsData, [
|
|
|
- {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
|
|
|
+ {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
|
|
|
]);
|
|
|
}
|
|
|
- const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
|
|
|
-
|
|
|
- this.ctx.helper.assignRelaData(billsData, [
|
|
|
- {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
|
|
|
- ]);
|
|
|
this.billsTree.loadDatas(billsData);
|
|
|
this.billsTree.calculateAll();
|
|
|
|
|
|
+ if (this._checkFieldsExist(fields, bglFields)) {
|
|
|
+ await this._calcBillsBgl();
|
|
|
+ }
|
|
|
+
|
|
|
return this.billsTree.getDatas([
|
|
|
'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
|
|
|
'code', 'b_code', 'name', 'unit', 'unit_price',
|
|
@@ -316,6 +361,7 @@ module.exports = app => {
|
|
|
'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
|
|
|
'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
|
|
|
'final_tp', 'final_ratio',
|
|
|
+ 'qc_bgl_code',
|
|
|
]);
|
|
|
}
|
|
|
|