|
@@ -29,6 +29,21 @@ module.exports = app => {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ async _insertPosData(transaction, data, tid) {
|
|
|
+ data.tid = tid;
|
|
|
+ // todo 新增期
|
|
|
+ data.add_stage = 0;
|
|
|
+ data.add_times = 0;
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ const addRst = await transaction.insert(this.tableName, data);
|
|
|
+ data.id = addRst.insertId;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存部位明细数据
|
|
|
* @param data
|
|
@@ -41,18 +56,13 @@ module.exports = app => {
|
|
|
const result = { ledger: {}, pos: null };
|
|
|
if (data.updateType === 'add') {
|
|
|
const tender = await this.ctx.service.tender.getTender(tid);
|
|
|
- data.updateData.tid = tid;
|
|
|
- // todo 新增期
|
|
|
- data.updateData.add_stage = 0;
|
|
|
- data.updateData.add_times = 0;
|
|
|
- data.updateData.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 (data.updateData instanceof Array) {
|
|
|
+ for (const d of data.updateData) {
|
|
|
+ this._insertPosData(transaction, d, tid);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this._insertPosData(transaction, data.updateData, tid);
|
|
|
}
|
|
|
- const addRst = await transaction.insert(this.tableName, data.updateData);
|
|
|
- data.updateData.id = addRst.insertId;
|
|
|
} else if (data.updateType === 'update') {
|
|
|
const datas = data.updateData instanceof Array ? data.updateData : [data.updateData];
|
|
|
result.ledger.update = [];
|
|
@@ -97,6 +107,52 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 复制粘贴 部位明细数据
|
|
|
+ * @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 }, updateLid = [];
|
|
|
+ try {
|
|
|
+ for (const d of data) {
|
|
|
+ if (d.quantity) {
|
|
|
+ const bills = await this.ctx.service.ledger.getDataById(d.lid);
|
|
|
+ const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
|
|
|
+ d.quantity = this._.round(d.quantity, precision.value);
|
|
|
+ console.log(updateLid);
|
|
|
+ if (updateLid.indexOf(d.lid) === -1) {
|
|
|
+ updateLid.push(d.lid);
|
|
|
+ }
|
|
|
+ console.log(updateLid);
|
|
|
+ }
|
|
|
+ if (d.id) {
|
|
|
+ await transaction.update(this.tableName, d);
|
|
|
+ } else {
|
|
|
+ this._insertPosData(transaction, d, tid);
|
|
|
+ }
|
|
|
+ for (const lid of updateLid) {
|
|
|
+ await this.ctx.service.ledger.calc(tid, lid, transaction);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await transaction.commit();
|
|
|
+ } catch (err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ result.pos = data;
|
|
|
+ if (updateLid.length > 0) {
|
|
|
+ result.ledger.update = await this.ctx.service.ledger.getDataByIds(updateLid);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 删除清单下部位明细数据(删除清单时调用)
|
|
|
*
|
|
|
* @param transaction - 事务
|