1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- '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, userId, 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(),
- userId: userId,
- };
- const result = await this.ctx.service.measure.db.insert(this.tableName, newData);
- if (result.affectedRow === 0) {
- throw '新增中间计量失败';
- }
- } else {
- throw '您输入的编号已存在';
- }
- }
- async joinMeasure(tenderId, audit_id) {
- const sql = 'SELECT M.* FROM ?? As M, ?? As MA ' +
- ' WHERE M.`tender_id` = ? and MA.`audit_id` = ? and M.times = MA.times and MA.`order` > 0';
- const sqlParam = [this.tableName, this.ctx.service.measureAudit.tableName, tenderId, audit_id];
- return await this.db.query(sql, sqlParam);
- }
- }
- return Measure;
- };
|