1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 'use strict';
- /**
- * 清单设置 数据模型
- * @author LanJianRong
- * @date 2020/6/30
- * @version
- */
- module.exports = app => {
- class MaterialListGcl extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'material_list_gcl';
- }
- async setData(mid, data) {
- if (!this.ctx.tender) {
- throw '数据错误';
- }
- const transaction = await this.db.beginTransaction();
- try {
- const insertArray = [];
- for (const d of data) {
- insertArray.push({
- tid: this.ctx.tender.id,
- mid,
- order: d.order,
- gcl_id: d.gcl_id,
- mb_id: d.mb_id,
- quantity: d.quantity,
- expr: d.expr,
- });
- }
- if (insertArray.length > 0) await transaction.insert(this.tableName, insertArray);
- await transaction.update(this.ctx.service.material.tableName, { id: mid, is_new: 1 });
- await transaction.commit();
- return true;
- } catch (err) {
- console.log(err);
- await transaction.rollback();
- throw err;
- }
- }
- async insertOrDelGcl(transaction, insertGclList, removeGclList, mid) {
- if (insertGclList.length > 0) {
- for (const gcl of insertGclList) {
- gcl.tid = this.ctx.tender.id;
- gcl.mid = mid;
- }
- await transaction.insert(this.tableName, insertGclList);
- }
- if (removeGclList.length > 0) {
- for (const gcl of removeGclList) {
- await transaction.delete(this.tableName, { id: gcl.id });
- }
- }
- }
- }
- return MaterialListGcl;
- };
|