123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 'use strict';
- /**
- *
- *
- * @author EllisRan.
- * @date 2018/4/19
- * @version
- */
- const libConst = require('../const/lib');
- module.exports = app => {
- class QuotaLib extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'quota_lib';
- }
- /**
- * 获取指标源列表
- *
- * @param {Object} status - 指标源状态
- * @return {Array} - 返回列表数据
- */
- async getList(status = 0) {
- this.initSqlBuilder();
- if(status !== 0) {
- this.sqlBuilder.setAndWhere('status', {
- value: status,
- operate: '=',
- });
- }
- this.sqlBuilder.orderBy = [['id', 'desc']];
- const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
- return await this.db.query(sql, sqlParam);
- }
- /**
- * 获取指标源各状态数量
- *
- * @return {Array} - 返回数量列表数据
- */
- async getStatusNum() {
- const pend = await this.db.count(this.tableName, { status: libConst.status.pend });
- const enter = await this.db.count(this.tableName, { status: libConst.status.enter });
- const data = {
- pend,
- enter
- };
- return data;
- }
- /**
- * 新增指标源
- *
- * @param {Object} postData - 文件上传过来的数据
- * @return {Boolean} - 返回新增结果
- */
- async add(postData) {
- const insertData = {
- filename: postData.name,
- status: libConst.status.pend,
- filepath: postData.path,
- create_time: postData.create_time,
- enter_time: ''
- };
- const operate = await this.db.insert(this.tableName, insertData);
- return operate;
- }
- }
- return QuotaLib;
- }
|