12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 'use strict';
- module.exports = app => {
- class ScheduleStage extends app.BaseService {
- constructor(ctx) {
- super(ctx);
- this.tableName = 'schedule_stage';
- }
- async getLastPlanMonth() {
- const sql = 'SELECT `yearmonth` FROM ?? WHERE `tid` = ? ORDER BY `yearmonth` DESC Limit 0,1';
- const sqlParam = [this.tableName, this.ctx.tender.id];
- return await this.db.query(sql, sqlParam);
- }
- async add(data) {
- const transaction = await this.db.beginTransaction();
- try {
- const insertData = {
- tid: this.ctx.tender.id,
- yearmonth: data.yearmonth,
- order: data.order,
- };
- // 更新schedule_month stage_tp_used为1
- const updateData = {
- stage_tp_used: 1,
- };
- const option = {
- where: {
- tid: this.ctx.tender.id,
- yearmonth: data.yearmonth,
- },
- };
- await transaction.update(this.ctx.service.scheduleMonth.tableName, updateData, option);
- await transaction.insert(this.tableName, insertData);
- await transaction.commit();
- return true;
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- async del(data) {
- const transaction = await this.db.beginTransaction();
- try {
- const info = await this.getDataById(data.id);
- await transaction.delete(this.tableName, { id: data.id });
- // 更新schedule_month stage_tp_used为0
- const updateData = {
- stage_tp_used: 0,
- };
- const option = {
- where: {
- tid: this.ctx.tender.id,
- yearmonth: info.yearmonth,
- },
- };
- await transaction.update(this.ctx.service.scheduleMonth.tableName, updateData, option);
- await transaction.commit();
- return true;
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- async changeOrder(data) {
- const transaction = await this.db.beginTransaction();
- try {
- const updateData = {
- id: data.id,
- order: data.order,
- };
- await transaction.update(this.tableName, updateData);
- await transaction.commit();
- return true;
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- }
- return ScheduleStage;
- };
|