1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date 2021/7/20
- * @version
- */
- module.exports = app => {
- class SumLoadHistory extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'sum_load_history';
- }
- async getHistroy(tid, lid, type) {
- const his = await this.db.select(this.tableName, {
- where: { tid, lid, type },
- orders: [['load_time', 'desc']],
- limit: 1,
- offset: 0,
- });
- const result = his.length > 0 ? his[0] : null;
- if (result && result.tenders) result.tenders = JSON.parse(result.tenders);
- if (result && result.errors) result.errors = JSON.parse(result.errors);
- return result;
- }
- async getLedgerHistory(tid, lid) {
- return await this.getHistroy(tid, lid, 'ledger');
- }
- async getReviseHistory(tid, lid) {
- return await this.getHistroy(tid, lid, 'revise');
- }
- async getStageHistory(tid, lid) {
- return await this.getHistroy(tid, lid, 'stage');
- }
- async saveLedgerHistory(tid, lid, tenders, errors) {
- const data = {
- tid, lid, type: 'ledger',
- load_time: new Date(), uid: this.ctx.session.sessionUser.accountId,
- tenders: JSON.stringify(tenders), errors: errors ? JSON.stringify(errors) : '',
- };
- await this.db.insert(this.tableName, data);
- }
- async saveReviseHistory(tid, rid, lid, tenders, errors) {
- const data = {
- tid, lid, type: 'revise', rid,
- load_time: new Date(), uid: this.ctx.session.sessionUser.accountId,
- tenders: JSON.stringify(tenders), errors: errors ? JSON.stringify(errors) : '',
- };
- await this.db.insert(this.tableName, data);
- }
- async saveStageHistory(tid, sid, lid, tenders, errors) {
- const data = {
- tid, lid, type: 'revise', sid,
- load_time: new Date(), uid: this.ctx.session.sessionUser.accountId,
- tenders: JSON.stringify(tenders), errors: errors ? JSON.stringify(errors) : '',
- };
- await this.db.insert(this.tableName, data);
- }
- }
- return SumLoadHistory;
- };
|