|
@@ -40,6 +40,29 @@ module.exports = app => {
|
|
this.tableName = 'ledger';
|
|
this.tableName = 'ledger';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async innerAdd(data, tenderId, transaction) {
|
|
|
|
+ const datas = data instanceof Array ? data : [data];
|
|
|
|
+ if (tenderId <= 0) {
|
|
|
|
+ throw '标段id错误';
|
|
|
|
+ }
|
|
|
|
+ // 数组则为批量插入
|
|
|
|
+ if (datas.length <= 0) {
|
|
|
|
+ throw '插入数据为空';
|
|
|
|
+ }
|
|
|
|
+ // 整理数据
|
|
|
|
+ const insertData = [];
|
|
|
|
+ for (const tmp of datas) {
|
|
|
|
+ tmp.ledger_id = tmp.id;
|
|
|
|
+ tmp.ledger_pid = tmp.pid;
|
|
|
|
+ tmp.tender_id = tenderId;
|
|
|
|
+ delete tmp.id;
|
|
|
|
+ delete tmp.pid;
|
|
|
|
+ insertData.push(tmp);
|
|
|
|
+ }
|
|
|
|
+ const operate = await transaction.insert(this.tableName, insertData);
|
|
|
|
+ return operate.affectedRows === datas.length;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 新增数据
|
|
* 新增数据
|
|
*
|
|
*
|
|
@@ -51,31 +74,13 @@ module.exports = app => {
|
|
this.transaction = await this.db.beginTransaction();
|
|
this.transaction = await this.db.beginTransaction();
|
|
let result = false;
|
|
let result = false;
|
|
try {
|
|
try {
|
|
- if (tenderId <= 0) {
|
|
|
|
- throw '标段id错误';
|
|
|
|
- }
|
|
|
|
- if (data instanceof Array) {
|
|
|
|
- // 数组则为批量插入
|
|
|
|
- if (data.length <= 0) {
|
|
|
|
- throw '插入数据为空';
|
|
|
|
- }
|
|
|
|
- // 整理数据
|
|
|
|
- const insertData = [];
|
|
|
|
- for (const tmp of data) {
|
|
|
|
- tmp.ledger_id = tmp.id;
|
|
|
|
- tmp.ledger_pid = tmp.pid;
|
|
|
|
- tmp.tender_id = tenderId;
|
|
|
|
- delete tmp.id;
|
|
|
|
- delete tmp.pid;
|
|
|
|
- insertData.push(tmp);
|
|
|
|
- }
|
|
|
|
- const operate = await this.transaction.insert(this.tableName, insertData);
|
|
|
|
- this.transaction.commit();
|
|
|
|
- result = operate.affectedRows > 0;
|
|
|
|
- } else {
|
|
|
|
- // 对象则单个插入
|
|
|
|
|
|
+ result = await this.innerAdd(data, tenderId, this.transaction);
|
|
|
|
+ if (!result) {
|
|
|
|
+ throw '新增数据错误';
|
|
}
|
|
}
|
|
|
|
+ this.transaction.commit();
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
+ this.transaction.rollback();
|
|
result = false;
|
|
result = false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -550,7 +555,7 @@ module.exports = app => {
|
|
// 选中节点--全部后节点 order--
|
|
// 选中节点--全部后节点 order--
|
|
await this._updateSelectNextsOrder(selectData, -1);
|
|
await this._updateSelectNextsOrder(selectData, -1);
|
|
// 更新父项金额
|
|
// 更新父项金额
|
|
- if (selectData.total_price && Math.abs(selectData.total_price) > zeroRange) {
|
|
|
|
|
|
+ if (this.ctx.helper.checkZero(selectData.total_price)) {
|
|
const parentFullPath = selectData.full_path.replace('.' + selectData.ledger_id, '');
|
|
const parentFullPath = selectData.full_path.replace('.' + selectData.ledger_id, '');
|
|
const updateMap = {};
|
|
const updateMap = {};
|
|
updateMap[parentFullPath] = -selectData.total_price;
|
|
updateMap[parentFullPath] = -selectData.total_price;
|
|
@@ -568,7 +573,7 @@ module.exports = app => {
|
|
updateData = await this.getNextsData(tenderId, selectData.ledger_pid, selectData.order - 1);
|
|
updateData = await this.getNextsData(tenderId, selectData.ledger_pid, selectData.order - 1);
|
|
updateData = updateData ? updateData : [];
|
|
updateData = updateData ? updateData : [];
|
|
const updateData1 = await this.getDataByNodeId(tenderId, selectData.ledger_pid);
|
|
const updateData1 = await this.getDataByNodeId(tenderId, selectData.ledger_pid);
|
|
- if (selectData.total_price && Math.abs(selectData.total_price) > zeroRange) {
|
|
|
|
|
|
+ if (this.ctx.helper.checkZero(selectData.total_price)) {
|
|
const updateData2 = await this.getFullLevelDataByFullPath(tenderId, updateData1.full_path);
|
|
const updateData2 = await this.getFullLevelDataByFullPath(tenderId, updateData1.full_path);
|
|
updateData = updateData.concat(updateData2);
|
|
updateData = updateData.concat(updateData2);
|
|
} else if (updateData1.is_leaf !== parentData.is_leaf) {
|
|
} else if (updateData1.is_leaf !== parentData.is_leaf) {
|
|
@@ -1108,7 +1113,7 @@ module.exports = app => {
|
|
await this.transaction.insert(this.tableName, datas);
|
|
await this.transaction.insert(this.tableName, datas);
|
|
}
|
|
}
|
|
// 更新父节点金额
|
|
// 更新父节点金额
|
|
- if (Math.abs(incre) > zeroRange) {
|
|
|
|
|
|
+ if (this.ctx.helper.checkZero(incre)) {
|
|
const updateMap = {};
|
|
const updateMap = {};
|
|
updateMap[newParentPath] = incre;
|
|
updateMap[newParentPath] = incre;
|
|
await this._increCalcParent(tenderId, updateMap);
|
|
await this._increCalcParent(tenderId, updateMap);
|
|
@@ -1126,7 +1131,7 @@ module.exports = app => {
|
|
}
|
|
}
|
|
const createData = await this.getDataByParentAndOrder(selectData.tender_id, selectData.ledger_pid, order);
|
|
const createData = await this.getDataByParentAndOrder(selectData.tender_id, selectData.ledger_pid, order);
|
|
const updateData = await this.getNextsData(selectData.tender_id, selectData.ledger_pid, selectData.order + copyNodes.length);
|
|
const updateData = await this.getNextsData(selectData.tender_id, selectData.ledger_pid, selectData.order + copyNodes.length);
|
|
- if (Math.abs(incre) > zeroRange) {
|
|
|
|
|
|
+ if (this.ctx.helper.checkZero(incre)) {
|
|
const updateData1 = await this.getFullLevelDataByFullPath(selectData.tender_id, newParentPath);
|
|
const updateData1 = await this.getFullLevelDataByFullPath(selectData.tender_id, newParentPath);
|
|
return { create: createData, update: updateData.concat(updateData1) };
|
|
return { create: createData, update: updateData.concat(updateData1) };
|
|
} else {
|
|
} else {
|
|
@@ -1204,7 +1209,7 @@ module.exports = app => {
|
|
if (updateNode.is_leaf) {
|
|
if (updateNode.is_leaf) {
|
|
calcData.total_price = calcData.quantity * calcData.unit_price;
|
|
calcData.total_price = calcData.quantity * calcData.unit_price;
|
|
}
|
|
}
|
|
- if (updateNode.total_price === undefined || Math.abs(calcData.total_price - updateNode.total_price) > zeroRange) {
|
|
|
|
|
|
+ if (updateNode.total_price === undefined || this.ctx.helper.checkZero(calcData.total_price - updateNode.total_price)) {
|
|
const pfp = updateNode.full_path.replace('.' + updateNode.ledger_id, '');
|
|
const pfp = updateNode.full_path.replace('.' + updateNode.ledger_id, '');
|
|
if (updateMap[pfp]) {
|
|
if (updateMap[pfp]) {
|
|
updateMap[pfp] = updateMap[pfp] + calcData.total_price - updateNode.total_price;
|
|
updateMap[pfp] = updateMap[pfp] + calcData.total_price - updateNode.total_price;
|