schedule_month.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. module.exports = app => {
  3. class ScheduleMonth extends app.BaseService {
  4. constructor(ctx) {
  5. super(ctx);
  6. this.tableName = 'schedule_month';
  7. }
  8. async getLastPlanMonth() {
  9. const sql = 'SELECT `yearmonth` FROM ?? WHERE `tid` = ? ORDER BY `yearmonth` DESC Limit 0,1';
  10. const sqlParam = [this.tableName, this.ctx.tender.id];
  11. return await this.db.query(sql, sqlParam);
  12. }
  13. async add(data) {
  14. const transaction = await this.db.beginTransaction();
  15. try {
  16. const insertData = [];
  17. for (const m of data) {
  18. insertData.push({ tid: this.ctx.tender.id, yearmonth: m });
  19. }
  20. if (insertData.length > 0) await transaction.insert(this.tableName, insertData);
  21. await transaction.commit();
  22. return true;
  23. } catch (err) {
  24. await transaction.rollback();
  25. throw err;
  26. }
  27. }
  28. async del(data) {
  29. const transaction = await this.db.beginTransaction();
  30. try {
  31. for (const m of data) {
  32. const delData = { tid: this.ctx.tender.id, yearmonth: m };
  33. await transaction.delete(this.tableName, delData);
  34. await transaction.delete(this.ctx.service.scheduleLedgerMonth.tableName, delData);
  35. }
  36. await transaction.commit();
  37. return true;
  38. } catch (err) {
  39. await transaction.rollback();
  40. throw err;
  41. }
  42. }
  43. }
  44. return ScheduleMonth;
  45. };