revise_pos.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class RevisePos extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'revise_pos';
  20. }
  21. /**
  22. * 获取 修订 清单数据
  23. * @param {Number}tid - 标段id
  24. * @param {uuid}rid - 修订id
  25. * @returns {Promise<void>}
  26. */
  27. async getData(tid) {
  28. return await this.db.select(this.tableName, {
  29. where: {tid: tid}
  30. });
  31. }
  32. async getDataByLid(tid, lid) {
  33. return await this.db.select(this.tableName, {
  34. where: {tid: tid, lid: lid}
  35. });
  36. }
  37. async insertLedgerPosData(transaction, tid, rid, bills, data) {
  38. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  39. const insertDatas = [];
  40. for (const d of data) {
  41. const inD = {
  42. id: this.uuid.v4(), tid: tid, lid: bills.id, crid: rid,
  43. add_stage: 0, add_times: 0, add_user: this.ctx.session.sessionUser.accountId,
  44. name: d.name, drawing_code: d.drawing_code,
  45. };
  46. if (d.quantity) {
  47. inD.sgfh_qty = this.round(d.quantity, precision.value);
  48. inD.quantity = inD.sgfh_qty;
  49. }
  50. insertDatas.push(inD);
  51. }
  52. await transaction.insert(this.tableName, insertDatas);
  53. }
  54. }
  55. return RevisePos;
  56. };