|
@@ -324,22 +324,20 @@ module.exports = app => {
|
|
|
if (!bSameParent) {
|
|
|
throw '复制数据错误:仅可操作同层节点';
|
|
|
}
|
|
|
- const orgParentPath = copyNodes[0].full_path.replace(copyNodes[0].ledger_id, '');
|
|
|
|
|
|
- const newIds = [];
|
|
|
+ const pasteBillsData = [], pastePosData = [];
|
|
|
this.transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 选中节点的所有后兄弟节点,order+粘贴节点个数
|
|
|
await this._updateChildrenOrder(tenderId, selectData.ledger_pid, selectData.order + 1, copyNodes.length);
|
|
|
// 数据库创建新增节点数据
|
|
|
+ const leafBillsId = [];
|
|
|
+ let maxId = await this._getMaxLid(this.ctx.tender.id);
|
|
|
for (let iNode = 0; iNode < copyNodes.length; iNode++) {
|
|
|
const node = copyNodes[iNode];
|
|
|
let datas = await this.getDataByFullPath(paste.tid, node.full_path + '%');
|
|
|
datas = this._.sortBy(datas, 'level');
|
|
|
|
|
|
- const maxId = await this._getMaxLid(this.ctx.tender.id);
|
|
|
-
|
|
|
- const leafBillsId = [];
|
|
|
// 计算粘贴数据中需更新部分
|
|
|
datas.sort(function (x, y) {
|
|
|
return x.level - y.level;
|
|
@@ -372,7 +370,6 @@ module.exports = app => {
|
|
|
if (data.is_leaf) {
|
|
|
leafBillsId.push(idChange);
|
|
|
}
|
|
|
- newIds.push(data.id);
|
|
|
}
|
|
|
for (const data of datas) {
|
|
|
delete data.children;
|
|
@@ -384,13 +381,26 @@ module.exports = app => {
|
|
|
} else {
|
|
|
data.full_path = newParentPath + '' + data.ledger_id;
|
|
|
}
|
|
|
+ pasteBillsData.push(data)
|
|
|
}
|
|
|
- const newData = await this.transaction.insert(this.tableName, datas);
|
|
|
- for (const id of leafBillsId) {
|
|
|
- await this.ctx.service.pos.copyBillsPosData(id.org, id.new, this.transaction);
|
|
|
+ maxId = maxId + datas.length;
|
|
|
+ }
|
|
|
+ const newData = await this.transaction.insert(this.tableName, pasteBillsData);
|
|
|
+ this._cacheMaxLid(tenderId, maxId);
|
|
|
+
|
|
|
+ for (const id of leafBillsId) {
|
|
|
+ const posData = await this.ctx.service.pos.getAllDataByCondition({ where: { tid: paste.tid, lid: id.org } });
|
|
|
+ if (posData.length > 0) {
|
|
|
+ for (const pd of posData) {
|
|
|
+ pd.id = this.uuid.v4();
|
|
|
+ pd.lid = id.new;
|
|
|
+ pd.tid = this.ctx.tender.id;
|
|
|
+ pd.in_time = new Date();
|
|
|
+ pastePosData.push(pd);
|
|
|
+ }
|
|
|
}
|
|
|
- this._cacheMaxLid(tenderId, maxId + datas.length);
|
|
|
}
|
|
|
+ await this.transaction.insert(this.ctx.service.pos.tableName, pastePosData);
|
|
|
await this.transaction.commit();
|
|
|
} catch (err) {
|
|
|
await this.transaction.rollback();
|
|
@@ -402,12 +412,10 @@ module.exports = app => {
|
|
|
for (let i = 1; i <= copyNodes.length; i++) {
|
|
|
order.push(selectData.order + i);
|
|
|
}
|
|
|
- const createData = await this.getDataByIds(newIds);
|
|
|
const updateData = await this.getNextsData(selectData.tender_id, selectData.ledger_pid, selectData.order + copyNodes.length);
|
|
|
- const posData = await this.ctx.service.pos.getPosData({ lid: newIds });
|
|
|
return {
|
|
|
- ledger: { create: createData, update: updateData },
|
|
|
- pos: posData,
|
|
|
+ ledger: { create: pasteBillsData, update: updateData },
|
|
|
+ pos: pastePosData,
|
|
|
};
|
|
|
}
|
|
|
|