| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 | 
							- 'use strict';
 
- /**
 
-  * 部位明细
 
-  *
 
-  * @author Mai
 
-  * @date
 
-  * @version
 
-  */
 
- module.exports = app => {
 
-     class Pos extends app.BaseService {
 
-         /**
 
-          * 构造函数
 
-          *
 
-          * @param {Object} ctx - egg全局变量
 
-          * @return {void}
 
-          */
 
-         constructor(ctx) {
 
-             super(ctx);
 
-             this.tableName = 'pos';
 
-         }
 
-         async getPosData(condition) {
 
-             return await this.db.select(this.tableName, {
 
-                 where: condition,
 
-                 columns: ['id', 'tid', 'lid', 'name', 'quantity', 'position', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'in_time', 'porder', 'add_stage'],
 
-                 order: [['porder', 'ASC']],
 
-             });
 
-         }
 
-         async getPosDataWithAddStageOrder(condition) {
 
-             const sql = 'SELECT p.id, p.tid, p.lid, p.name, p.quantity, p.position, p.drawing_code, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.porder, p.add_stage, p.add_times, p.add_user, s.order As add_stage_order ' +
 
-                 '  FROM ' + this.tableName + ' p ' +
 
-                 '  LEFT JOIN ' + this.ctx.service.stage.tableName + ' s' +
 
-                 '  ON p.add_stage = s.id'
 
-                 + this.ctx.helper.whereSql(condition, 'p');
 
-             return await this.db.query(sql);
 
-         }
 
-         async getPosDataByIds(ids) {
 
-             if (ids instanceof Array && ids.length > 0) {
 
-                 const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code, sgfh_qty, sjcl_qty, qtcl_qty, add_stage, add_times, add_user' +
 
-                     '  FROM ' + this.tableName +
 
-                     '  WHERE id in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ')';
 
-                 return await this.db.query(sql, []);
 
-             } else {
 
-                 return [];
 
-             }
 
-             // this.initSqlBuilder();
 
-             // this.sqlBuilder.setAndWhere('id', {
 
-             //     operate: 'in',
 
-             //     value: ids
 
-             // });
 
-             // this.sqlBuilder.columns = ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty'];
 
-             // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName)
 
-             // return await this.db.query(sql, sqlParam);
 
-         }
 
-         async getPosDataByUnits(tenderId, units) {
 
-             const sql = 'SELECT p.id, p.lid, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty' +
 
-                 '  FROM ' + this.tableName + ' p' +
 
-                 '  LEFT JOIN ' + this.ctx.service.ledger.tableName + ' b' +
 
-                 '  ON p.lid = b.id ' +
 
-                 '  WHERE p.tid = ? and b.unit IN (?)';
 
-             const sqlParam = [tenderId, units];
 
-             return await this.db.query(sql, sqlParam);
 
-         }
 
-         async _insertPosData(transaction, data, tid) {
 
-             data.id = this.uuid.v4();
 
-             data.tid = tid;
 
-             // todo 新增期
 
-             data.add_stage = 0;
 
-             data.add_times = 0;
 
-             data.in_time = new Date();
 
-             data.add_user = this.ctx.session.sessionUser.accountId;
 
-             if (data.quantity) {
 
-                 const bills = await this.ctx.service.ledger.getDataById(data.lid);
 
-                 const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
 
-                 data.quantity = this.round(data.quantity, precision.value);
 
-             }
 
-             if (transaction) {
 
-                 const addRst = await transaction.insert(this.tableName, data);
 
-             } else {
 
-                 const addRst = await this.db.insert(this.tableName, data);
 
-             }
 
-         }
 
-         async _completeInsertPosData(tid, data) {
 
-             data.id = this.uuid.v4();
 
-             data.tid = tid;
 
-             // todo 新增期
 
-             data.add_stage = 0;
 
-             data.add_times = 0;
 
-             data.in_time = new Date();
 
-             data.add_user = this.ctx.session.sessionUser.accountId;
 
-         }
 
-         async _getUpdateBills(data) {
 
-             const datas = data instanceof Array ? data : [data];
 
-             const bills = await this.ctx.service.ledger.getDataById(datas[0].lid);
 
-             const billsPos = await this.getAllDataByCondition({where: {tid: bills.tender_id, lid: bills.id} });
 
-             const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
 
-             const updateBills = {id: bills.id};
 
-             for (const bp of billsPos) {
 
-                 updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
 
-                 updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
 
-                 updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
 
-                 updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
 
-             }
 
-             for (const d of datas) {
 
-                 if (d.sgfh_qty) {
 
-                     d.sgfh_qty = this.ctx.helper.round(d.sgfh_qty, precision.value);
 
-                     updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
 
-                 }
 
-                 if (d.sjcl_qty) {
 
-                     d.sjcl_qty = this.ctx.helper.round(d.sjcl_qty, precision.value);
 
-                     updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
 
-                 }
 
-                 if (d.qtcl_qty) {
 
-                     d.qtcl_qty = this.ctx.helper.round(d.qtcl_qty, precision.value);
 
-                     updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
 
-                 }
 
-                 d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
 
-                 updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
 
-             }
 
-             const info = this.ctx.tender.info;
 
-             updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
 
-             updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
 
-             updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
 
-             updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
 
-             return updateBills;
 
-         }
 
-         async _addPosData(tid, data) {
 
-             let updateBills = null;
 
-             if (data instanceof Array) {
 
-                 for (const d of data) {
 
-                     this._completeInsertPosData(tid, d);
 
-                 }
 
-                 if (data[0].sgfh_qty !== undefined || data[0].sjcl_qty !== undefined || data[0].qtcl_qty !== undefined) {
 
-                     updateBills = await this._getUpdateBills(data);
 
-                 }
 
-             } else {
 
-                 this._completeInsertPosData(tid, data);
 
-                 if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
 
-                     updateBills = await this._getUpdateBills(data);
 
-                 }
 
-             }
 
-             if (updateBills) {
 
-                 const transaction = await this.db.beginTransaction();
 
-                 try {
 
-                     await transaction.update(this.ctx.service.ledger.tableName, updateBills);
 
-                     updateBills.ledger_id = bills.ledger_id;
 
-                     await transaction.commit();
 
-                 } catch (err) {
 
-                     await transaction.rollback();
 
-                     throw err;
 
-                 }
 
-                 return {
 
-                     ledger: { update: [updateBills] },
 
-                     pos: data,
 
-                 }
 
-             } else {
 
-                 await this.db.insert(this.tableName, data);
 
-                 return { pos: data }
 
-             }
 
-         }
 
-         async _updatePosData(tid, data) {
 
-             if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
 
-                 const op = await this.getDataById(data.id);
 
-                 const bills = await this.ctx.service.ledger.getDataById(op.lid);
 
-                 const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: op.lid} });
 
-                 const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
 
-                 if (data.sgfh_qty !== undefined) {
 
-                     data.sgfh_qty = this.round(data.sgfh_qty, precision.value);
 
-                 } else if (op) {
 
-                     data.sgfh_qty = op.sgfh_qty;
 
-                 }
 
-                 if (data.sjcl_qty !== undefined) {
 
-                     data.sjcl_qty = this.round(data.sjcl_qty, precision.value);
 
-                 } else if (op) {
 
-                     data.sjcl_qty = op.sjcl_qty;
 
-                 }
 
-                 if (data.qtcl_qty !== undefined) {
 
-                     data.qtcl_qty = this.round(data.qtcl_qty, precision.value);
 
-                 } else if (op) {
 
-                     data.qtcl_qty = op.qtcl_qty;
 
-                 }
 
-                 data.quantity = this.ctx.helper.sum([data.sgfh_qty, data.qtcl_qty, data.sjcl_qty]);
 
-                 const updateBills = {id: bills.id};
 
-                 for (const bp of billsPos) {
 
-                     const calcData = bp.id === data.id ? data : bp;
 
-                     updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, calcData.sgfh_qty);
 
-                     updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, calcData.sjcl_qty);
 
-                     updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, calcData.qtcl_qty);
 
-                     updateBills.quantity = this.ctx.helper.add(updateBills.quantity, calcData.quantity);
 
-                 }
 
-                 const info = this.ctx.tender.info;
 
-                 updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
 
-                 updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
 
-                 updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
 
-                 updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
 
-                 const transaction = await this.db.beginTransaction();
 
-                 try {
 
-                     transaction.update(this.tableName, data);
 
-                     transaction.update(this.ctx.service.ledger.tableName, updateBills);
 
-                     await transaction.commit();
 
-                     updateBills.ledger_id = bills.ledger_id;
 
-                     return {
 
-                         ledger: { update: [updateBills] },
 
-                         pos: data,
 
-                     }
 
-                 } catch(err) {
 
-                     await transaction.rollback();
 
-                     throw err;
 
-                 }
 
-             } else {
 
-                 await this.db.update(this.tableName, data);
 
-                 return {pos: data};
 
-             }
 
-         }
 
-         async _updatePosDatas(tid, data) {
 
-             if (data.length === 0) return;
 
-             const op = await this.getDataById(data[0].id);
 
-             const bills = await this.ctx.service.ledger.getDataById(op.lid);
 
-             const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: op.lid} });
 
-             const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
 
-             for (const d of data) {
 
-                 if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined) {
 
-                     if (d.sgfh_qty !== undefined) {
 
-                         d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
 
-                     } else if (op) {
 
-                         d.sgfh_qty = op.sgfh_qty;
 
-                     }
 
-                     if (d.sjcl_qty !== undefined) {
 
-                         d.sjcl_qty = this.round(d.sjcl_qty, precision.value);
 
-                     } else if (op) {
 
-                         d.sjcl_qty = op.sjcl_qty;
 
-                     }
 
-                     if (d.qtcl_qty !== undefined) {
 
-                         d.qtcl_qty = this.round(d.qtcl_qty, precision.value);
 
-                     } else if (op) {
 
-                         d.qtcl_qty = op.qtcl_qty;
 
-                     }
 
-                     d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
 
-                 }
 
-             }
 
-             const updateBills = {id: bills.id};
 
-             for (const bp of billsPos) {
 
-                 const newPos = data.find(function (x) { return x.id === bp.id });
 
-                 const calcData = newPos ? newPos : bp;
 
-                 updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, calcData.sgfh_qty);
 
-                 updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, calcData.sjcl_qty);
 
-                 updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, calcData.qtcl_qty);
 
-                 updateBills.quantity = this.ctx.helper.add(updateBills.quantity, calcData.quantity);
 
-             }
 
-             const info = this.ctx.tender.info;
 
-             updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
 
-             updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
 
-             updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
 
-             updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
 
-             const transaction = await this.db.beginTransaction();
 
-             try {
 
-                 for (const d of data) {
 
-                     transaction.update(this.tableName, d);
 
-                 }
 
-                 await transaction.update(this.ctx.service.ledger.tableName, updateBills);
 
-                 await transaction.commit();
 
-                 updateBills.ledger_id = bills.ledger_id;
 
-                 return {
 
-                     ledger: { update: [updateBills] },
 
-                     pos: data,
 
-                 }
 
-             } catch(err) {
 
-                 await transaction.rollback();
 
-                 throw err;
 
-             }
 
-         }
 
-         async _deletePosData(tid, data) {
 
-             if (!data || data.length === 0) {
 
-                 throw '提交数据错误';
 
-             }
 
-             const pos = await this.getPosData({tid: tid, id: data});
 
-             const bills = await this.ctx.service.ledger.getDataById(pos[0].lid);
 
-             const billsPos = await this.getAllDataByCondition({ where: {tid: tid, lid: bills.id} });
 
-             const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
 
-             for (const bp of billsPos) {
 
-                 if (data.indexOf(bp.id) >= 0) continue;
 
-                 updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
 
-                 updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
 
-                 updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
 
-                 updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
 
-             }
 
-             const info = this.ctx.tender.info;
 
-             updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
 
-             updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
 
-             updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
 
-             updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
 
-             const transaction = await this.db.beginTransaction();
 
-             try {
 
-                 await transaction.delete(this.tableName, {tid: tid, id: data});
 
-                 await transaction.update(this.ctx.service.ledger.tableName, updateBills);
 
-                 await transaction.commit();
 
-                 updateBills.ledger_id = bills.ledger_id;
 
-                 return { ledger: { update: [updateBills] }, pos: data };
 
-             } catch(err) {
 
-                 await transaction.rollback();
 
-                 throw err;
 
-             }
 
-         }
 
-         /**
 
-          * 保存部位明细数据
 
-          * @param data
 
-          * @param {Number} tid - 标段id
 
-          * @returns {Promise<{ledger: {}, pos: null}>}
 
-          */
 
-         async savePosData(data, tid) {
 
-             switch (data.updateType) {
 
-                 case 'add':
 
-                     return await this._addPosData(tid, data.updateData);
 
-                 case 'update':
 
-                     if (data.updateData instanceof Array) {
 
-                         return await this._updatePosDatas(tid, data.updateData);
 
-                     } else {
 
-                         return await this._updatePosData(tid, data.updateData);
 
-                     }
 
-                 case 'delete':
 
-                     return await this._deletePosData(tid, data.updateData);
 
-             }
 
-         }
 
-         /**
 
-          * 复制粘贴 部位明细数据
 
-          * @param {Array} data - 复制粘贴的数据
 
-          * @param {Number} tid - 标段id
 
-          * @returns {Promise<{ledger: {}, pos: null}>}
 
-          */
 
-         async pastePosData(data, tid) {
 
-             if (!(data instanceof Array)) {
 
-                 throw '提交数据错误';
 
-             }
 
-             const transaction = await this.db.beginTransaction();
 
-             const result = { ledger: {}, pos: null };
 
-             const bills = await this.ctx.service.ledger.getDataById(data[0].lid);
 
-             const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
 
-             const updateBills = {id: bills.id};
 
-             const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: bills.id} });
 
-             for (const bp of billsPos) {
 
-                 const d = data.find(function (x) {
 
-                     return bp.id ? x.id === bp.id : false;
 
-                 });
 
-                 if (d) continue;
 
-                 updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
 
-                 updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
 
-                 updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
 
-                 updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
 
-             }
 
-             try {
 
-                 for (const d of data) {
 
-                     const op = d.id ? this._.find(billsPos, {id: d.id}) : null;
 
-                     
 
-                     if (d.sgfh_qty !== undefined) {
 
-                         d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
 
-                     } else if (op) {
 
-                         d.sgfh_qty = op.sgfh_qty;
 
-                     }
 
-                     updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
 
-                     if (d.sjcl_qty !== undefined) {
 
-                         d.sjcl_qty = this.round(d.sjcl_qty, precision.value);
 
-                     } else if (op) {
 
-                         d.sjcl_qty = op.sjcl_qty;
 
-                     }
 
-                     updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
 
-                     if (d.qtcl_qty) {
 
-                         d.qtcl_qty = this.round(d.qtcl_qty, precision.value);
 
-                     } else if (op) {
 
-                         d.qtcl_qty = op.qtcl_qty;
 
-                     }
 
-                     updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
 
-                     d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
 
-                     updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
 
-                     if (d.id) {
 
-                         await transaction.update(this.tableName, d);
 
-                     } else {
 
-                         this._completeInsertPosData(tid, d);
 
-                         transaction.insert(this.tableName, d);
 
-                     }
 
-                 }
 
-                 const info = this.ctx.tender.info;
 
-                 updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
 
-                 updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
 
-                 updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
 
-                 updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
 
-                 await transaction.update(this.ctx.service.ledger.tableName, updateBills);
 
-                 updateBills.ledger_id = bills.ledger_id;
 
-                 await transaction.commit();
 
-             } catch (err) {
 
-                 await transaction.rollback();
 
-                 throw err;
 
-             }
 
-             result.pos = data;
 
-             result.ledger.update = [updateBills];
 
-             return result;
 
-         }
 
-         /**
 
-          * 删除清单下部位明细数据(删除清单时调用)
 
-          *
 
-          * @param transaction - 事务
 
-          * @param tid - 标段id
 
-          * @param lid - 清单id
 
-          * @returns {Promise<void>}
 
-          */
 
-         async deletePosData(transaction, tid, lid) {
 
-             await transaction.delete(this.tableName, {tid: tid, lid: lid});
 
-         }
 
-         /**
 
-          * 复制整块 拷贝部位明细数据
 
-          * @param {Number} orgLid - 拷贝的部位明细所属台账id
 
-          * @param {Number} newLid - 新的台账id
 
-          * @param transaction - 复制整块事务
 
-          * @returns {Promise<void>}
 
-          */
 
-         async copyBillsPosData(orgLid, newLid, transaction) {
 
-             const posData = await this.getAllDataByCondition({ where: { lid: orgLid } });
 
-             if (posData.length > 0) {
 
-                 for (const pd of posData) {
 
-                     pd.id = this.uuid.v4();
 
-                     pd.lid = newLid;
 
-                     pd.tid = this.ctx.tender.id;
 
-                     pd.in_time = new Date();
 
-                 }
 
-                 await transaction.insert(this.tableName, posData);
 
-             }
 
-         }
 
-         /**
 
-          * 批量插入部位数据 - 仅供批量插入清单部位调用
 
-          * @param transaction - 所属事务
 
-          * @param {Number} tid - 标段id
 
-          * @param {Number} lid - 台账id
 
-          * @param {Array} data - 新增数据
 
-          * @returns {Promise<void>}
 
-          */
 
-         async insertLedgerPosData(transaction, tid, bills, data) {
 
-             const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
 
-             const insertDatas = [];
 
-             for (const d of data) {
 
-                 const inD = {
 
-                     id: this.uuid.v4(), tid: tid, lid: bills.id,
 
-                     add_stage: 0, add_times: 0, add_user: this.ctx.session.sessionUser.accountId,
 
-                     in_time: new Date(), porder: data.indexOf(d) + 1,
 
-                     name: d.name, drawing_code: d.drawing_code,
 
-                 };
 
-                 if (d.quantity) {
 
-                     inD.sgfh_qty = this.round(d.quantity, precision.value);
 
-                     inD.quantity = inD.sgfh_qty;
 
-                 }
 
-                 insertDatas.push(inD);
 
-             }
 
-             await transaction.insert(this.tableName, insertDatas);
 
-         }
 
-     }
 
-     return Pos;
 
- };
 
 
  |