ledger_extra.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. /**
  3. * 部位明细
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class LedgerExtra extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.depart = ctx.app.config.table_depart.heavy;
  20. this.tableName = 'ledger_extra';
  21. }
  22. async getData(tid, columns) {
  23. if (!columns || columns.length === 0) return [];
  24. return await this.db.select(this.departTableName(tid), {
  25. where: { tid },
  26. columns: ['id', ...columns],
  27. });
  28. }
  29. async getCalcTemplateData(tid) {
  30. const sql = `SELECT id, calc_template FROM ${this.departTableName(tid)} WHERE tid = ? and calc_template <> ''`;
  31. return await this.db.query(sql, [tid]);
  32. }
  33. async getUsedCalcTemplate(tid) {
  34. const sql = `SELECT calc_template, count(id) as count FROM ${this.departTableName(tid)} WHERE tid = ? and calc_template <> '' GROUP BY calc_template`;
  35. const result = await this.db.query(sql, [tid]);
  36. return result;
  37. // return result.map(x => { return x.calc_template; });
  38. }
  39. async updateMultiLimit(id, multi_limit) {
  40. const exist = await this.getDataById(id);
  41. if (exist) {
  42. await this.defaultUpdate({ id, multi_limit });
  43. } else {
  44. await this.db.insert(this.tableName, { id, tid: this.ctx.tender.id, multi_limit });
  45. }
  46. }
  47. }
  48. return LedgerExtra;
  49. };