measure.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. /**
  3. * 中间计量数据模型
  4. *
  5. * @author Mai
  6. * @date 2018/6/27
  7. * @version
  8. */
  9. module.exports = app => {
  10. class Measure extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'measure';
  20. }
  21. /**
  22. * 新增中间计量
  23. * @param code - 编号
  24. * @param date - 年月
  25. * @param stage - 所属期
  26. * @returns {Promise<void>}
  27. */
  28. async add(tenderId, code, date, stage) {
  29. const count = await this.ctx.service.measure.count({
  30. tender_id: tenderId, code: code,
  31. });
  32. if (count === 0) {
  33. const newData = {
  34. tender_id: tenderId,
  35. mid: this.uuid.v4(),
  36. code: code,
  37. in_time: new Date(),
  38. };
  39. const result = await this.ctx.service.measure.db.insert(this.tableName, newData);
  40. if (result.affectedRow === 0) {
  41. throw '新增中间计量失败';
  42. }
  43. } else {
  44. throw '您输入的编号已存在';
  45. }
  46. }
  47. }
  48. return Measure;
  49. };