unit_price_model.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * 单价文件业务模型
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/6/30
  6. * @version
  7. */
  8. import BaseModel from "../../common/base/base_model";
  9. import UnitPriceSchema from "./schemas/unit_price";
  10. class UnitPriceModel extends BaseModel {
  11. /**
  12. * 构造函数
  13. *
  14. * @return {void}
  15. */
  16. constructor() {
  17. let parent = super();
  18. parent.model = UnitPriceSchema;
  19. parent.init();
  20. }
  21. /**
  22. * 根据标段获取对应单价数据
  23. *
  24. * @param {Number} tenderId
  25. * @return {Promise}
  26. */
  27. async getDataByTenderId(tenderId) {
  28. tenderId = parseInt(tenderId);
  29. if (isNaN(tenderId) || tenderId <= 0) {
  30. return null;
  31. }
  32. let unitPriceList = await this.db.model.find({tender_id: tenderId});
  33. if (unitPriceList.length <= 0) {
  34. return null;
  35. }
  36. // 整理数据
  37. let result = {};
  38. for(let tmp of unitPriceList) {
  39. result[tmp.code] = tmp;
  40. }
  41. return result;
  42. }
  43. }
  44. export default UnitPriceModel;