tender_node.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. /**
  3. * 标段 -- 指标节点业务类
  4. *
  5. * @author Mai
  6. * @date 2018/4/25
  7. * @version
  8. */
  9. module.exports = app => {
  10. class TenderNode extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局context
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'tender_node';
  20. }
  21. async search (tenderId, keyword) {
  22. const searchKey = '%' + keyword + '%';
  23. const sql = 'Select * From ??' +
  24. ' where `lib_id` = ' + tenderId + ' and (`name` like ? or code like ?)';
  25. const sqlParam = [this.tableName, searchKey, searchKey];
  26. return await this.db.query(sql, sqlParam);
  27. }
  28. async searchClass (tenderId, indexClass, className) {
  29. if (indexClass === this.app.nodeConst.indexClass.dy) {
  30. const sql = 'Select * From ' + this.tableName +
  31. ' Where `lib_id` = ? and `index_class` = ? and `class_name` = ?';
  32. const sqlParam = [tenderId, indexClass, className];
  33. return await this.db.query(sql, sqlParam);
  34. } else {
  35. const sql = 'Select * From ' + this.tableName +
  36. ' Where `lib_id` = ? and `index_class` = ?';
  37. const sqlParam = [tenderId, indexClass];
  38. return await this.db.query(sql, sqlParam);
  39. }
  40. }
  41. async searchParent(tenderId, className) {
  42. const sql = 'SELECT tn.bills_xid, qb.code, qb.name, qb.units, qb.dgn_quantity1, qb.dgn_quantity2, qb.dgn_price, qb.total_price' +
  43. ' FROM ' + this.tableName + ' As tn' +
  44. ' LEFT JOIN ' + this.ctx.service.bills.tableName + ' As qb ON tn.bills_xid = qb.n_id and tn.lib_id = qb.lib_id' +
  45. ' WHERE tn.`lib_id` = ? and tn.class_name = ?' +
  46. ' GROUP By tn.bills_xid' +
  47. ' ORDER By qb.code ASC';
  48. const param = [tenderId, className];
  49. return await this.db.query(sql, param);
  50. }
  51. };
  52. return TenderNode;
  53. };