'use strict'; /** * * * @author Mai * @date * @version */ const tenderConst = require('../const/tender'); module.exports = app => { class Valuation extends app.BaseService { /** * 构造函数 * * @param {Object} ctx - egg全局变量 * @return {void} */ constructor(ctx) { super(ctx); this.tableName = 'valuation_list'; } async getProjectValidValuation(pid) { const project = await this.ctx.service.project.getDataById(pid); const vid = this._.map(project.valuation.split(','), this._.toInteger); return await this.db.select(this.tableName, { where: {id: vid}, columns: ['id', 'name'], }); } async getValuationTemplate(id, measureType) { const valuationField = tenderConst.valuationField(measureType); if (!valuationField) return -1; const valuation = await this.getDataById(id); return parseInt(valuation[valuationField.template]); } async getValuationStdList(id, measureType) { const valuationField = tenderConst.valuationField(measureType); if (!valuationField) return [[], []]; const valuation = await this.getDataById(id); const billsId = valuation[valuationField.std_bills] ? this._.map(valuation[valuationField.std_bills].split(','), this._.toInteger) : [-1]; const sql = 'SELECT `id`, `name`' + ' From ?? ' + ' WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)'; const sqlParam = ['zh_std_gcl_list', billsId, billsId]; const billsList = await this.db.query(sql, sqlParam); const chaptersId = valuation[valuationField.std_xmj] ? this._.map(valuation[valuationField.std_xmj].split(','), this._.toInteger) : [-1]; const sql2 = 'SELECT `id`, `name`' + ' From ?? ' + ' WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)'; const sqlParam2 = ['zh_std_xmj_list', chaptersId, chaptersId]; const chapterList = await this.db.query(sql2, sqlParam2); const gljId = valuation[valuationField.glj_lib] ? this._.map(valuation[valuationField.glj_lib].split(','), this._.toInteger) : [-1]; const sql3 = 'SELECT `id`, `name`' + ' From ?? ' + ' WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)'; const sqlParam3 = ['zh_glj_lib_list', gljId, gljId]; const gljList = await this.db.query(sql3, sqlParam3); return [billsList, chapterList, gljList]; } } return Valuation; };