compare_controller.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (!data.keyword || data.keyword === '') {
  36. throw '请输入查询关键字';
  37. }
  38. for (const tender of tenders) {
  39. if (!tender.lib_id) {
  40. throw '查询的标段有误或不存在';
  41. }
  42. tender.data = await ctx.service.tenderNode.search(tender.lib_id, data.keyword);
  43. for (const n of tender.data) {
  44. const condition = {
  45. lib_id: tender.lib_id,
  46. node_id: n.node_id,
  47. }
  48. n.children = await ctx.service.tenderIndex.getAllDataByCondition({where: condition});
  49. }
  50. }
  51. responseData.data = tenders;
  52. } catch (err) {
  53. responseData.err = 1;
  54. responseData.msg = err.toString();
  55. console.log(err);
  56. }
  57. //console.log('end' + new Date());
  58. ctx.body = responseData;
  59. }
  60. }
  61. return CompareController;
  62. }