valuation.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 sql = 'SELECT `id`, `name`' +
  45. ' From ?? ' +
  46. ' WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';
  47. const sqlParam = ['zh_std_gcl_list', billsId, billsId];
  48. const billsList = await this.db.query(sql, sqlParam);
  49. // const chapterList = await this.db.select('zh_std_xmj_list', {
  50. // where: {id: chaptersId},
  51. // columns: ['id', 'name'],
  52. // });
  53. // chapterList.sort(function (a, b) {
  54. // return chaptersId.indexOf(a.id) - chapterList.indexOf(b.id);
  55. // });
  56. const sql2 = 'SELECT `id`, `name`' +
  57. ' From ?? ' +
  58. ' WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';
  59. const sqlParam2 = ['zh_std_xmj_list', chaptersId, chaptersId];
  60. const chapterList = await this.db.query(sql2, sqlParam2);
  61. return [billsList, chapterList];
  62. }
  63. }
  64. return Valuation;
  65. };