1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 'use strict';
- module.exports = app => {
- class Schedule extends app.BaseService {
- constructor(ctx) {
- super(ctx);
- this.tableName = 'schedule';
- }
- async saveMode(data) {
- const transaction = await this.db.beginTransaction();
- try {
- const options = {
- where: {
- tid: this.ctx.tender.id,
- },
- };
- const updateData = {
- mode: data.mode,
- };
- await transaction.update(this.tableName, updateData, options);
- if (data.update_under_ledger.length > 0) {
- const month_list = [];
- const update_options = [];
- for (const un of data.update_under_ledger) {
- const option = {
- row: {
- plan_tp: un.plan_tp,
- plan_gcl: un.plan_gcl,
- },
- where: {
- tid: this.ctx.tender.id,
- lid: un.lid,
- yearmonth: un.yearmonth,
- },
- };
- update_options.push(option);
- if (!this._.find(month_list, un.yearmonth)) {
- month_list.push(un.yearmonth);
- }
- }
- if (update_options.length > 0) {
- await transaction.updateRows(this.ctx.service.scheduleLedgerMonth.tableName, update_options);
- for (const m of month_list) {
- await this.ctx.service.scheduleLedgerMonth.calcMonthPlan(transaction, this.ctx.tender.id, m);
- }
- await this.ctx.service.scheduleMonth.calcPlan(transaction, this.ctx.tender.id);
- }
- }
- await transaction.commit();
- return true;
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- }
- return Schedule;
- };
|