| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 | 'use strict';/** * * * @author Mai * @date * @version */module.exports = app => {    class BudgetStd extends app.BaseService {        /**         * 构造函数         *         * @param {Object} ctx - egg全局变量         * @return {void}         */        constructor(ctx) {            super(ctx);            this.tableName = 'budget_std';        }        async getDataByProjectId(pid) {            const project = await this.ctx.service.project.getDataById(pid);            const sid =  this._.map(project.budget.split(','), this._.toInteger);            return await this.getAllDataByCondition({                where: { id: sid },                columns: ['id', 'name'],            });        }        async getStdList(id, type) {            if (!type) return [[], []];            const gclField = type + '_bills_id', xmjField = type + '_chapter_id';            const std = await this.service.budgetStd.getDataById(id);            const billsId = std[gclField] ? this._.map(std[gclField].split(','), this._.toInteger) : [];            const chaptersId = std[xmjField] ? this._.map(std[xmjField].split(','), this._.toInteger) : [];            const sql = 'SELECT `id`, `name`' +                '  From ?? ' +                '  WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';            const sqlParam = ['zh_std_gcl_list', billsId, billsId];            const billsList = billsId.length > 0 ? await this.db.query(sql, sqlParam) : [];            const sql2 = 'SELECT `id`, `name`' +                '  From ?? ' +                '  WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';            const sqlParam2 = ['zh_std_xmj_list', chaptersId, chaptersId];            const chapterList = chaptersId.length > 0 ? await this.db.query(sql2, sqlParam2) : [];            return [billsList, chapterList];        }        async getTemplateId(id, type) {            if (!id || !type) throw '参数错误';            const budgetStd = await this.getDataById(id);            if (!budgetStd) throw '模板不存在';            return budgetStd[type + '_template_id'];        }    }    return BudgetStd;};
 |