| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 | 
							- '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);
 
-             data.tenders = tenders;
 
-             data.errors = errors;
 
-             return 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);
 
-             data.tenders = tenders;
 
-             data.errors = errors;
 
-             return data;
 
-         }
 
-         async saveStageHistory(tid, sid, lid, tenders, errors, cover) {
 
-             const data = {
 
-                 tid, lid, type: 'stage', sid,
 
-                 load_time: new Date(), uid: this.ctx.session.sessionUser.accountId,
 
-                 tenders: JSON.stringify(tenders), errors: errors ? JSON.stringify(errors) : '',
 
-                 cover: cover,
 
-             };
 
-             await this.db.insert(this.tableName, data);
 
-             data.tenders = tenders;
 
-             data.errors = errors;
 
-             return data;
 
-         }
 
-         async getReviseLastestData(rid) {
 
-             const sql = 'SELECT * FROM ' + this.tableName +
 
-                 '  WHERE id in ( SELECT top 1 id FROM ' + this.tableName + ' WHERE rid = ? order by load_time desc)';
 
-             const data = await this.db.query(sql, [rid]);
 
-             if (data.tenders) data.tenders = JSON.parse(data.tenders);
 
-             if (data.errors) data.errors = JSON.parse(data.errors);
 
-             return data;
 
-         }
 
-         async getStageLastestData(sid) {
 
-             const sql = 'SELECT * FROM ' + this.tableName +
 
-                 '  WHERE id in ( SELECT top 1 id FROM ' + this.tableName + ' WHERE sid = ? order by load_time desc)';
 
-             const data = await this.db.query(sql, [sid]);
 
-             if (data.tenders) data.tenders = JSON.parse(data.tenders);
 
-             if (data.errors) data.errors = JSON.parse(data.errors);
 
-             return data;
 
-         }
 
-     }
 
-     return SumLoadHistory;
 
- };
 
 
  |