valuation.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 billsList = await this.db.select('zh_std_gcl_list', {
  38. where: {id: billsId},
  39. columns: ['id', 'name'],
  40. });
  41. billsList.sort(function (a, b) {
  42. return billsId.indexOf(a.id) - billsList.indexOf(b.id);
  43. });
  44. const chapterList = await this.db.select('zh_std_xmj_list', {
  45. where: {id: chaptersId},
  46. columns: ['id', 'name'],
  47. });
  48. chapterList.sort(function (a, b) {
  49. return chaptersId.indexOf(a.id) - chapterList.indexOf(b.id);
  50. });
  51. return [billsList, chapterList];
  52. }
  53. }
  54. return Valuation;
  55. };