valuation.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 sql = 'SELECT `id`, `name`' +
  44. ' From ?? ' +
  45. ' WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';
  46. const sqlParam = ['zh_std_gcl_list', billsId, billsId];
  47. const billsList = await this.db.query(sql, sqlParam);
  48. const chaptersId = valuation[valuationField.std_xmj]
  49. ? this._.map(valuation[valuationField.std_xmj].split(','), this._.toInteger)
  50. : [-1];
  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. const gljId = valuation[valuationField.glj_lib]
  57. ? this._.map(valuation[valuationField.glj_lib].split(','), this._.toInteger)
  58. : [-1];
  59. const sql3 = 'SELECT `id`, `name`' +
  60. ' From ?? ' +
  61. ' WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';
  62. const sqlParam3 = ['zh_glj_lib_list', gljId, gljId];
  63. const gljList = await this.db.query(sql3, sqlParam3);
  64. return [billsList, chapterList, gljList];
  65. }
  66. }
  67. return Valuation;
  68. };