| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | 
							- 'use strict';
 
- /**
 
-  * 清单设置 数据模型
 
-  * @author LanJianRong
 
-  * @date 2020/6/30
 
-  * @version
 
-  */
 
- module.exports = app => {
 
-     class MaterialChecklist extends app.BaseService {
 
-         /**
 
-          * 构造函数
 
-          *
 
-          * @param {Object} ctx - egg全局变量
 
-          * @return {void}
 
-          */
 
-         constructor(ctx) {
 
-             super(ctx);
 
-             this.tableName = 'material_checklist';
 
-         }
 
-         async resetData(pushData, removeData, updateData) {
 
-             if (!this.ctx.tender || !this.ctx.material) {
 
-                 throw '数据错误';
 
-             }
 
-             const transaction = await this.db.beginTransaction();
 
-             try {
 
-                 if (pushData.length > 0) {
 
-                     const insertDatas = [];
 
-                     for (const p of pushData) {
 
-                         p.mid = this.ctx.material.id;
 
-                         p.tid = this.ctx.tender.id;
 
-                         insertDatas.push(p);
 
-                     }
 
-                     await transaction.insert(this.tableName, insertDatas);
 
-                 }
 
-                 if (removeData.length > 0) {
 
-                     for (const r of removeData) {
 
-                         await transaction.delete(this.tableName, { id: r });
 
-                     }
 
-                 }
 
-                 if (updateData.length > 0) {
 
-                     await transaction.updateRows(this.tableName, updateData);
 
-                 }
 
-                 await transaction.commit();
 
-                 const materialChecklistData = await this.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
 
-                 const self = this;
 
-                 return await materialChecklistData.sort(function(a, b) {
 
-                     return self.ctx.helper.compareCode(a.b_code, b.b_code);
 
-                 });
 
-             } catch (err) {
 
-                 console.log(err);
 
-                 await transaction.rollback();
 
-                 throw err;
 
-             }
 
-         }
 
-         async updateHadBills(transaction, id, had_bills) {
 
-             if (!this.ctx.tender || !this.ctx.material) {
 
-                 throw '数据错误';
 
-             }
 
-             return await transaction.update(this.tableName, { id, had_bills });
 
-         }
 
-     }
 
-     return MaterialChecklist;
 
- };
 
 
  |