compare_controller.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. /**
  3. * 指标对比控制器
  4. *
  5. * @author Mai
  6. * @data 2018/4/19
  7. * @version
  8. */
  9. const libConst = require('../const/lib');
  10. module.exports = app => {
  11. class CompareController extends app.BaseController {
  12. /**
  13. * 指标对比页面
  14. *
  15. * @param {object} ctx - egg全局context
  16. * @return {void}
  17. */
  18. async index (ctx) {
  19. const libList = await ctx.service.quotaLib.getList(libConst.status.enter);
  20. const renderData = {
  21. libList
  22. };
  23. await this.layout('compare/index.ejs', renderData, 'compare/modal.ejs');
  24. }
  25. async search (ctx) {
  26. //console.log('start' + new Date());
  27. const responseData = {
  28. err: 0,
  29. msg: '',
  30. data: [],
  31. };
  32. try {
  33. const data = JSON.parse(ctx.request.body.data);
  34. const tenders = data.tenders;
  35. for (const tender of tenders) {
  36. if (!tender.lib_id) {
  37. throw '查询的标段有误或不存在';
  38. }
  39. tender.data = await ctx.service.tenderNode.search(tender.lib_id, data.keyword);
  40. for (const n of tender.data) {
  41. const condition = {
  42. lib_id: tender.lib_id,
  43. node_id: n.node_id,
  44. }
  45. n.children = await ctx.service.tenderIndex.getAllDataByCondition({where: condition});
  46. }
  47. }
  48. responseData.data = tenders;
  49. } catch (err) {
  50. responseData.err = 1;
  51. responseData.msg = err.toString();
  52. }
  53. //console.log('end' + new Date());
  54. ctx.body = responseData;
  55. }
  56. }
  57. return CompareController;
  58. }