sum_load_history.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2021/7/20
  7. * @version
  8. */
  9. module.exports = app => {
  10. class SumLoadHistory extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'sum_load_history';
  20. }
  21. async getHistroy(tid, lid, type) {
  22. const his = await this.db.select(this.tableName, {
  23. where: { tid, lid, type },
  24. orders: [['load_time', 'desc']],
  25. limit: 1,
  26. offset: 0,
  27. });
  28. const result = his.length > 0 ? his[0] : null;
  29. if (result && result.tenders) result.tenders = JSON.parse(result.tenders);
  30. if (result && result.errors) result.errors = JSON.parse(result.errors);
  31. return result;
  32. }
  33. async getLedgerHistory(tid, lid) {
  34. return await this.getHistroy(tid, lid, 'ledger');
  35. }
  36. async getReviseHistory(tid, lid) {
  37. return await this.getHistroy(tid, lid, 'revise');
  38. }
  39. async getStageHistory(tid, lid) {
  40. return await this.getHistroy(tid, lid, 'stage');
  41. }
  42. async saveLedgerHistory(tid, lid, tenders, errors) {
  43. const data = {
  44. tid, lid, type: 'ledger',
  45. load_time: new Date(), uid: this.ctx.session.sessionUser.accountId,
  46. tenders: JSON.stringify(tenders), errors: errors ? JSON.stringify(errors) : '',
  47. };
  48. await this.db.insert(this.tableName, data);
  49. }
  50. async saveReviseHistory(tid, rid, lid, tenders, errors) {
  51. const data = {
  52. tid, lid, type: 'revise', rid,
  53. load_time: new Date(), uid: this.ctx.session.sessionUser.accountId,
  54. tenders: JSON.stringify(tenders), errors: errors ? JSON.stringify(errors) : '',
  55. };
  56. await this.db.insert(this.tableName, data);
  57. }
  58. async saveStageHistory(tid, sid, lid, tenders, errors) {
  59. const data = {
  60. tid, lid, type: 'revise', sid,
  61. load_time: new Date(), uid: this.ctx.session.sessionUser.accountId,
  62. tenders: JSON.stringify(tenders), errors: errors ? JSON.stringify(errors) : '',
  63. };
  64. await this.db.insert(this.tableName, data);
  65. }
  66. }
  67. return SumLoadHistory;
  68. };