valuation.js 2.3 KB

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