123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 'use strict';
- /**
- * 中间计量数据模型
- *
- * @author Mai
- * @date 2018/6/27
- * @version
- */
- module.exports = app => {
- class Measure extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'measure';
- }
- /**
- * 新增中间计量
- * @param code - 编号
- * @param date - 年月
- * @param stage - 所属期
- * @returns {Promise<void>}
- */
- async add(tenderId, code, date, stage) {
- const count = await this.ctx.service.measure.count({
- tender_id: tenderId, code: code,
- });
- if (count === 0) {
- const newData = {
- tender_id: tenderId,
- mid: this.uuid.v4(),
- code: code,
- in_time: new Date(),
- };
- const result = await this.ctx.service.measure.db.insert(this.tableName, newData);
- if (result.affectedRow === 0) {
- throw '新增中间计量失败';
- }
- } else {
- throw '您输入的编号已存在';
- }
- }
- }
- return Measure;
- };
|