12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 'use strict';
- /**
- * 不参与调差-清单关联表 数据模型
- *
- * @author Mai
- * @date 2018/8/13
- * @version
- */
- module.exports = app => {
- class MaterialListNotJoin extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'material_list_notjoin';
- }
- /**
- * 添加不参与调差的清单
- * @return {void}
- */
- async add(data) {
- if (!this.ctx.tender || !this.ctx.material) {
- throw '数据错误';
- }
- const newListNotJoin = {
- tid: this.ctx.tender.id,
- mid: this.ctx.material.id,
- gcl_id: data.gcl_id,
- xmj_id: data.id,
- mx_id: data.mx_id !== undefined ? data.mx_id : '',
- in_time: new Date(),
- };
- // 新增不参与调差清单
- const result = await this.db.insert(this.tableName, newListNotJoin);
- if (result.affectedRows === 0) {
- throw '新增不参与调差清单数据失败';
- }
- return await this.getDataById(result.insertId);
- }
- /**
- * 删除不参与调差的清单
- * @param {int} id 工料id
- * @return {void}
- */
- async del(id) {
- if (!this.ctx.tender || !this.ctx.material) {
- throw '数据错误';
- }
- // 判断是否可删
- return await this.deleteById(id);
- }
- /**
- * 复制上一期不参与调差的清单到下一期中
- * @param {Object} transaction - 新增一期的事务
- * @param {Object} list 上期清单
- * @param {int} mid 工料id
- * @return {void}
- */
- async copyNewStageNotJoinList(transaction, list, mid) {
- if (!this.ctx.tender) {
- throw '数据错误';
- }
- const notJoinlist = [];
- for (const mb of list) {
- const newLists = {
- tid: mb.tid,
- mid,
- gcl_id: mb.gcl_id,
- xmj_id: mb.xmj_id,
- mx_id: mb.mx_id,
- in_time: new Date(),
- };
- notJoinlist.push(newLists);
- }
- // 复制上一期不参与调差的清单
- return await transaction.insert(this.tableName, notJoinlist);
- }
- }
- return MaterialListNotJoin;
- };
|