valuation.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class Valuation extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'valuation_list';
  20. }
  21. async getProjectValidValuation(pid) {
  22. const project = await this.ctx.service.project.getDataById(pid);
  23. const vid = this._.map(project.valuation.split(','), this._.toInteger);
  24. return await this.db.select(this.tableName, {
  25. where: {id: vid},
  26. columns: ['id', 'name'],
  27. });
  28. }
  29. async getValuationTemplate(id) {
  30. const valuation = await this.getDataById(id);
  31. return parseInt(valuation.template_id);
  32. }
  33. async getValuationStdList(id) {
  34. const valuation = await this.getDataById(id);
  35. const billsId = this._.map(valuation.bill_id.split(','), this._.toInteger);
  36. const chaptersId = this._.map(valuation.chapter_id.split(','), this._.toInteger);
  37. const sql = 'SELECT `id`, `name`' +
  38. ' From ?? ' +
  39. ' WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';
  40. const sqlParam = ['zh_std_gcl_list', billsId, billsId];
  41. const billsList = await this.db.query(sql, sqlParam);
  42. const sql2 = 'SELECT `id`, `name`' +
  43. ' From ?? ' +
  44. ' WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';
  45. const sqlParam2 = ['zh_std_xmj_list', chaptersId, chaptersId];
  46. const chapterList = await this.db.query(sql2, sqlParam2);
  47. return [billsList, chapterList];
  48. }
  49. }
  50. return Valuation;
  51. };