|
@@ -112,46 +112,8 @@ module.exports = app => {
|
|
async stageTp(ctx) {
|
|
async stageTp(ctx) {
|
|
const tender = ctx.tender;
|
|
const tender = ctx.tender;
|
|
const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
|
|
const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
|
|
- const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
|
|
|
|
- const stageOrderList = await ctx.service.stage.getAllDataByCondition({ columns: ['id', 's_time', 'order'], where: { tid: tender.id } });
|
|
|
|
- const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
|
|
|
|
- let curScheduleStage = scheduleStage.length > 0 ? _.maxBy(scheduleStage, 'order') : null;
|
|
|
|
- let slmList = [];
|
|
|
|
- let nextSlmList = [];
|
|
|
|
- let endSlmList = [];
|
|
|
|
- let yearSlmList = [];
|
|
|
|
- let curYearStageData = [];
|
|
|
|
- if (ctx.params.order && scheduleStage.length > 0) {
|
|
|
|
- curScheduleStage = _.find(scheduleStage, { order: parseInt(ctx.params.order) });
|
|
|
|
- }
|
|
|
|
- if (curScheduleStage) {
|
|
|
|
- // const newSS = _.sortBy(scheduleStage, 'yearmonth');
|
|
|
|
- const newSM = _.sortBy(scheduleMonth, 'yearmonth');
|
|
|
|
- const nowScheduleStage = _.findIndex(newSM, { yearmonth: curScheduleStage.yearmonth });
|
|
|
|
- slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleStage.yearmonth } });
|
|
|
|
- const nextScheduleStage = nowScheduleStage >= 0 && nowScheduleStage + 1 <= newSM.length - 1 ? newSM[nowScheduleStage + 1] : null;
|
|
|
|
- if (nextScheduleStage) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleStage.yearmonth } });
|
|
|
|
- if (nowScheduleStage === 0) {
|
|
|
|
- endSlmList = slmList;
|
|
|
|
- } else if (nowScheduleStage > 0) {
|
|
|
|
- const endYearmonthCollection = _.map(_.take(newSM, nowScheduleStage + 1), 'yearmonth');
|
|
|
|
- endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
|
|
|
|
- }
|
|
|
|
- const yearConllection = _.map(_.filter(newSM, function(item) {
|
|
|
|
- return item.yearmonth.indexOf(curScheduleStage.yearmonth.split('-')[0]) !== -1;
|
|
|
|
- }), 'yearmonth');
|
|
|
|
- yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
|
|
|
|
- // 获取本年完成计量数据
|
|
|
|
- const curStage = _.find(stageOrderList, { order: curScheduleStage.order });
|
|
|
|
- const stageList = _.filter(stageOrderList, function(item) {
|
|
|
|
- return item.s_time.indexOf(curStage.s_time.split('-')[0]) !== -1;
|
|
|
|
- });
|
|
|
|
- const newSS = _.sortBy(scheduleStage, 'yearmonth');
|
|
|
|
- const stageIdList = _.map(_.filter(stageList, function(item) {
|
|
|
|
- return _.find(newSS, { order: item.order });
|
|
|
|
- }), 'id');
|
|
|
|
- curYearStageData = await ctx.service.stageBills.getStagesData(ctx.tender.id, stageIdList.join(','));
|
|
|
|
- }
|
|
|
|
|
|
+ const { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData,
|
|
|
|
+ scheduleMonth, stageOrderList, scheduleStage, curScheduleStage } = await this._getStageAndPlanData(ctx);
|
|
const renderData = {
|
|
const renderData = {
|
|
tender: tender.data,
|
|
tender: tender.data,
|
|
tenderInfo: tender.info,
|
|
tenderInfo: tender.info,
|
|
@@ -202,59 +164,97 @@ module.exports = app => {
|
|
*/
|
|
*/
|
|
async loadTpLedgerData(ctx) {
|
|
async loadTpLedgerData(ctx) {
|
|
try {
|
|
try {
|
|
- const tender = ctx.tender;
|
|
|
|
- // const ledgerData = await ctx.controller.stage._getStageLedgerData(ctx);
|
|
|
|
- // console.log(ledgerData);
|
|
|
|
- const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
|
|
|
|
- const stageOrderList = await ctx.service.stage.getAllDataByCondition({ columns: ['id', 's_time', 'order'], where: { tid: tender.id } });
|
|
|
|
- const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
|
|
|
|
- const curScheduleStage = _.find(scheduleStage, { order: parseInt(ctx.params.order) });
|
|
|
|
- let slmList = [];
|
|
|
|
- let nextSlmList = [];
|
|
|
|
- let endSlmList = [];
|
|
|
|
- let yearSlmList = [];
|
|
|
|
- let curYearStageData = [];
|
|
|
|
- if (curScheduleStage) {
|
|
|
|
- const newSM = _.sortBy(scheduleMonth, 'yearmonth');
|
|
|
|
- const nowScheduleStage = _.findIndex(newSM, { yearmonth: curScheduleStage.yearmonth });
|
|
|
|
- slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleStage.yearmonth } });
|
|
|
|
- const nextScheduleStage = nowScheduleStage >= 0 && nowScheduleStage + 1 <= newSM.length - 1 ? newSM[nowScheduleStage + 1] : null;
|
|
|
|
- if (nextScheduleStage) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleStage.yearmonth } });
|
|
|
|
- if (nowScheduleStage === 0) {
|
|
|
|
- endSlmList = slmList;
|
|
|
|
- } else if (nowScheduleStage > 0) {
|
|
|
|
- const endYearmonthCollection = _.map(_.take(newSM, nowScheduleStage + 1), 'yearmonth');
|
|
|
|
- endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
|
|
|
|
- }
|
|
|
|
- const yearConllection = _.map(_.filter(newSM, function(item) {
|
|
|
|
- return item.yearmonth.indexOf(curScheduleStage.yearmonth.split('-')[0]) !== -1;
|
|
|
|
- }), 'yearmonth');
|
|
|
|
- yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
|
|
|
|
- // 获取本年完成计量数据
|
|
|
|
- const curStage = _.find(stageOrderList, { order: curScheduleStage.order });
|
|
|
|
- const stageList = _.filter(stageOrderList, function(item) {
|
|
|
|
- return item.s_time.indexOf(curStage.s_time.split('-')[0]) !== -1;
|
|
|
|
- });
|
|
|
|
- const newSS = _.sortBy(scheduleStage, 'yearmonth');
|
|
|
|
- const stageIdList = _.map(_.filter(stageList, function(item) {
|
|
|
|
- return _.find(newSS, { order: item.order });
|
|
|
|
- }), 'id');
|
|
|
|
- curYearStageData = await ctx.service.stageBills.getStagesData(tender.id, stageIdList.join(','));
|
|
|
|
|
|
+ const ledgerData = await this._getStageLedgerData(ctx, ctx.params.order);
|
|
|
|
+ const postData = { ledgerData };
|
|
|
|
+ const data = JSON.parse(ctx.request.body.data);
|
|
|
|
+ if (data.filter && data.filter === 'gcl') {
|
|
|
|
+ const { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData } = await this._getStageAndPlanData(ctx);
|
|
|
|
+ _.assignIn(postData, { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData });
|
|
}
|
|
}
|
|
- ctx.body = { err: 0, msg: '', data: {
|
|
|
|
- // ledgerData,
|
|
|
|
- slmList,
|
|
|
|
- nextSlmList,
|
|
|
|
- endSlmList,
|
|
|
|
- yearSlmList,
|
|
|
|
- curYearStageData,
|
|
|
|
- } };
|
|
|
|
|
|
+ ctx.body = { err: 0, msg: '', data: postData };
|
|
} catch (err) {
|
|
} catch (err) {
|
|
this.log(err);
|
|
this.log(err);
|
|
ctx.body = { err: 1, msg: err.toString(), data: [] };
|
|
ctx.body = { err: 1, msg: err.toString(), data: [] };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async _getStageLedgerData(ctx, stageOrder) {
|
|
|
|
+ const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
|
|
|
|
+ const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
|
|
|
|
+ for (const d of dgnData) {
|
|
|
|
+ const l = ctx.app._.find(ledgerData, { id: d.id });
|
|
|
|
+ ctx.app._.assignIn(l, d);
|
|
|
|
+ }
|
|
|
|
+ const stageInfo = await ctx.service.stage.getDataByCondition({
|
|
|
|
+ tid: ctx.tender.id,
|
|
|
|
+ order: stageOrder,
|
|
|
|
+ });
|
|
|
|
+ let preStageData;
|
|
|
|
+ // 当前操作人查看最新数据,其他人查看历史数据
|
|
|
|
+ const curStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, stageInfo.id);
|
|
|
|
+ // 查询截止上期数据
|
|
|
|
+ if (stageInfo.order > 1) {
|
|
|
|
+ preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, stageInfo.order - 1);
|
|
|
|
+ } else {
|
|
|
|
+ preStageData = [];
|
|
|
|
+ }
|
|
|
|
+ this.ctx.helper.assignRelaData(ledgerData, [
|
|
|
|
+ { data: curStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid' },
|
|
|
|
+ { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_', relaId: 'lid' },
|
|
|
|
+ ]);
|
|
|
|
+ return ledgerData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取本期下台账计量和计划数据(Ajax)
|
|
|
|
+ *
|
|
|
|
+ * @param ctx
|
|
|
|
+ * @return {Promise<void>}
|
|
|
|
+ */
|
|
|
|
+ async _getStageAndPlanData(ctx) {
|
|
|
|
+ const tender = ctx.tender;
|
|
|
|
+ const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
|
|
|
|
+ const stageOrderList = await ctx.service.stage.getAllDataByCondition({ columns: ['id', 's_time', 'order'], where: { tid: tender.id } });
|
|
|
|
+ const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
|
|
|
|
+ let curScheduleStage = scheduleStage.length > 0 ? _.maxBy(scheduleStage, 'order') : null;
|
|
|
|
+ if (ctx.params.order && scheduleStage.length > 0) {
|
|
|
|
+ curScheduleStage = _.find(scheduleStage, { order: parseInt(ctx.params.order) });
|
|
|
|
+ }
|
|
|
|
+ let slmList = [];
|
|
|
|
+ let nextSlmList = [];
|
|
|
|
+ let endSlmList = [];
|
|
|
|
+ let yearSlmList = [];
|
|
|
|
+ let curYearStageData = [];
|
|
|
|
+ if (curScheduleStage) {
|
|
|
|
+ const newSM = _.sortBy(scheduleMonth, 'yearmonth');
|
|
|
|
+ const nowScheduleStage = _.findIndex(newSM, { yearmonth: curScheduleStage.yearmonth });
|
|
|
|
+ slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleStage.yearmonth } });
|
|
|
|
+ const nextScheduleStage = nowScheduleStage >= 0 && nowScheduleStage + 1 <= newSM.length - 1 ? newSM[nowScheduleStage + 1] : null;
|
|
|
|
+ if (nextScheduleStage) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleStage.yearmonth } });
|
|
|
|
+ if (nowScheduleStage === 0) {
|
|
|
|
+ endSlmList = slmList;
|
|
|
|
+ } else if (nowScheduleStage > 0) {
|
|
|
|
+ const endYearmonthCollection = _.map(_.take(newSM, nowScheduleStage + 1), 'yearmonth');
|
|
|
|
+ endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
|
|
|
|
+ }
|
|
|
|
+ const yearConllection = _.map(_.filter(newSM, function(item) {
|
|
|
|
+ return item.yearmonth.indexOf(curScheduleStage.yearmonth.split('-')[0]) !== -1;
|
|
|
|
+ }), 'yearmonth');
|
|
|
|
+ yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
|
|
|
|
+ // 获取本年完成计量数据
|
|
|
|
+ const curStage = _.find(stageOrderList, { order: curScheduleStage.order });
|
|
|
|
+ const stageList = _.filter(stageOrderList, function(item) {
|
|
|
|
+ return item.s_time.indexOf(curStage.s_time.split('-')[0]) !== -1;
|
|
|
|
+ });
|
|
|
|
+ const newSS = _.sortBy(scheduleStage, 'yearmonth');
|
|
|
|
+ const stageIdList = _.map(_.filter(stageList, function(item) {
|
|
|
|
+ return _.find(newSS, { order: item.order });
|
|
|
|
+ }), 'id');
|
|
|
|
+ curYearStageData = await ctx.service.stageBills.getStagesData(tender.id, stageIdList.join(','));
|
|
|
|
+ }
|
|
|
|
+ return { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData, scheduleMonth, stageOrderList, scheduleStage, curScheduleStage };
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取台账数据(Ajax)
|
|
* 获取台账数据(Ajax)
|
|
*
|
|
*
|