|
@@ -230,7 +230,7 @@ class TreeService extends Service {
|
|
/**
|
|
/**
|
|
* 新增数据(新增为selectData的后项,该方法不可单独使用)
|
|
* 新增数据(新增为selectData的后项,该方法不可单独使用)
|
|
*
|
|
*
|
|
- * @param {Number} mid - 台账id
|
|
|
|
|
|
+ * @param {Number} mid - master-id
|
|
* @param {Object} select - 选中节点的数据
|
|
* @param {Object} select - 选中节点的数据
|
|
* @param {Object} data - 新增节点的初始数据
|
|
* @param {Object} data - 新增节点的初始数据
|
|
* @return {Object} - 新增结果
|
|
* @return {Object} - 新增结果
|
|
@@ -259,7 +259,7 @@ class TreeService extends Service {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 新增节点
|
|
* 新增节点
|
|
- * @param {Number} mid - 台账id
|
|
|
|
|
|
+ * @param {Number} mid - master id
|
|
* @param {Number} kid - 清单节点id
|
|
* @param {Number} kid - 清单节点id
|
|
* @returns {Promise<void>}
|
|
* @returns {Promise<void>}
|
|
*/
|
|
*/
|
|
@@ -292,8 +292,8 @@ class TreeService extends Service {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 删除节点
|
|
* 删除节点
|
|
- * @param {Number} tenderId - 标段id
|
|
|
|
- * @param {Object} deleteData - 删除节点数据
|
|
|
|
|
|
+ * @param {Number} mid - master id
|
|
|
|
+ * @param {Object} deleteNode - 删除节点数据
|
|
* @return {Promise<*>}
|
|
* @return {Promise<*>}
|
|
* @private
|
|
* @private
|
|
*/
|
|
*/
|
|
@@ -314,10 +314,10 @@ class TreeService extends Service {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * tenderId标段中, 删除选中节点及其子节点
|
|
|
|
|
|
+ * 删除选中节点及其子节点
|
|
*
|
|
*
|
|
- * @param {Number} tenderId - 标段id
|
|
|
|
- * @param {Number} selectId - 选中节点id
|
|
|
|
|
|
+ * @param {Number} mid - master id
|
|
|
|
+ * @param {Number} kid - 选中节点id
|
|
* @return {Array} - 被删除的数据
|
|
* @return {Array} - 被删除的数据
|
|
*/
|
|
*/
|
|
async deleteNode(mid, kid) {
|
|
async deleteNode(mid, kid) {
|
|
@@ -521,8 +521,8 @@ class TreeService extends Service {
|
|
/**
|
|
/**
|
|
* 升级节点
|
|
* 升级节点
|
|
*
|
|
*
|
|
- * @param {Number} tenderId - 标段id
|
|
|
|
- * @param {Number} selectId - 选中节点id
|
|
|
|
|
|
+ * @param {Number} mid - master id
|
|
|
|
+ * @param {Number} kid - 选中节点id
|
|
* @return {Array} - 发生改变的数据
|
|
* @return {Array} - 发生改变的数据
|
|
*/
|
|
*/
|
|
async upLevelNode(mid, kid) {
|
|
async upLevelNode(mid, kid) {
|
|
@@ -612,8 +612,8 @@ class TreeService extends Service {
|
|
/**
|
|
/**
|
|
* 降级节点
|
|
* 降级节点
|
|
*
|
|
*
|
|
- * @param {Number} tenderId - 标段id
|
|
|
|
- * @param {Number} selectId - 选中节点id
|
|
|
|
|
|
+ * @param {Number} mid - master id
|
|
|
|
+ * @param {Number} kid - 选中节点id
|
|
* @return {Array} - 发生改变的数据
|
|
* @return {Array} - 发生改变的数据
|
|
*/
|
|
*/
|
|
async downLevelNode(mid, kid) {
|
|
async downLevelNode(mid, kid) {
|
|
@@ -682,7 +682,7 @@ class TreeService extends Service {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 提交多条数据 - 不影响计算等未提交项
|
|
* 提交多条数据 - 不影响计算等未提交项
|
|
- * @param {Number} tenderId - 标段id
|
|
|
|
|
|
+ * @param {Number} mid - master id
|
|
* @param {Array} datas - 提交数据
|
|
* @param {Array} datas - 提交数据
|
|
* @return {Array} - 提交后的数据
|
|
* @return {Array} - 提交后的数据
|
|
*/
|
|
*/
|
|
@@ -711,110 +711,6 @@ class TreeService extends Service {
|
|
const resultData = await this.getDataById(this._.map(datas, 'id'));
|
|
const resultData = await this.getDataById(this._.map(datas, 'id'));
|
|
return resultData;
|
|
return resultData;
|
|
}
|
|
}
|
|
-
|
|
|
|
- async pasteBlockRelaData(relaData) {
|
|
|
|
- if (!this.transaction) throw '更新数据错误';
|
|
|
|
- // for (const id of relaData) {
|
|
|
|
- // await this.ctx.service.pos.copyBillsPosData(id.org, id.new, this.transaction);
|
|
|
|
- // }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- async getPasteBlockResult(select, copyNodes) {
|
|
|
|
- const createData = await this.getDataByIds(newIds);
|
|
|
|
- const updateData = await this.getNextsData(selectData[this.setting.mid], selectData[this.setting.pid], selectData[this.setting.order] + copyNodes.length);
|
|
|
|
- //const posData = await this.ctx.service.pos.getPosData({ lid: newIds });
|
|
|
|
- return {
|
|
|
|
- ledger: { create: createData, update: updateData },
|
|
|
|
- //pos: posData,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 复制粘贴整块
|
|
|
|
- * @param {Number} tenderId - 标段Id
|
|
|
|
- * @param {Number} selectId - 选中几点Id
|
|
|
|
- * @param {Array} block - 复制节点Id
|
|
|
|
- * @return {Object} - 提价后的数据(其中新增粘贴数据,只返回第一层)
|
|
|
|
- */
|
|
|
|
- async pasteBlock(mid, kid, block) {
|
|
|
|
- if ((mid <= 0) || (kid <= 0)) return [];
|
|
|
|
-
|
|
|
|
- const selectData = await this.getDataByNodeId(mid, kid);
|
|
|
|
- if (!selectData) throw '数据错误';
|
|
|
|
-
|
|
|
|
- const copyNodes = await this.getDataByNodeIds(mid, block);
|
|
|
|
- if (!copyNodes || copyNodes.length <= 0) throw '复制数据错误';
|
|
|
|
- for (const node of copyNodes) {
|
|
|
|
- if (node[this.setting.pid] !== copyNodes[0][this.setting.pid]) throw '复制数据错误:仅可操作同层节点';
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const newParentPath = selectData[this.setting.fullPath].replace(selectData[this.setting.kid], '');
|
|
|
|
- const orgParentPath = copyNodes[0][this.setting.fullPath].replace(copyNodes[0][this.setting.kid], '');
|
|
|
|
- const newIds = [];
|
|
|
|
- this.transaction = await this.db.beginTransaction();
|
|
|
|
- try {
|
|
|
|
- // 选中节点的所有后兄弟节点,order+粘贴节点个数
|
|
|
|
- await this._updateSelectNextsOrder(selectData, copyNodes.length);
|
|
|
|
- for (let iNode = 0; iNode < copyNodes.length; iNode++) {
|
|
|
|
- const node = copyNodes[iNode];
|
|
|
|
- let datas = await this.getDataByFullPath(mid, node[this.setting.fullPath] + '%');
|
|
|
|
- datas = this._.sortBy(datas, 'level');
|
|
|
|
-
|
|
|
|
- const maxId = await this._getMaxLid(mid);
|
|
|
|
- this._cacheMaxLid(mid, maxId + datas.length);
|
|
|
|
-
|
|
|
|
- const billsId = [];
|
|
|
|
- // 计算粘贴数据中需更新部分
|
|
|
|
- for (let index = 0; index < datas.length; index++) {
|
|
|
|
- const data = datas[index];
|
|
|
|
- const newId = maxId + index + 1;
|
|
|
|
- const idChange = {
|
|
|
|
- org: data.id,
|
|
|
|
- };
|
|
|
|
- data.id = this.uuid.v4();
|
|
|
|
- idChange.new = data.id;
|
|
|
|
- data[this.setting.mid] = mid;
|
|
|
|
- if (!data[this.setting.isLeaf]) {
|
|
|
|
- for (const children of datas) {
|
|
|
|
- children[this.setting.fullPath] = children[this.setting.fullPath].replace('.' + data[this.setting.kid], '.' + newId);
|
|
|
|
- if (children[this.setting.pid] === data[this.setting.kid]) {
|
|
|
|
- children[this.setting.pid] = newId;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- data[this.setting.fullPath] = data[this.setting.fullPath].replace('.' + data[this.setting.kid], '.' + newId);
|
|
|
|
- }
|
|
|
|
- data[this.setting.kid] = newId;
|
|
|
|
- data[this.setting.fullPath] = data[this.setting.fullPath].replace(orgParentPath, newParentPath);
|
|
|
|
- if (data[this.setting.pid] === node[this.setting.pid]) {
|
|
|
|
- data[this.setting.pid] = selectData[this.setting.pid];
|
|
|
|
- data[this.setting.order] = selectData[this.setting.order] + iNode + 1;
|
|
|
|
- }
|
|
|
|
- data[this.setting.level] = data[this.setting.level] + selectData[this.setting.level] - copyNodes[0][this.setting.level];
|
|
|
|
- idChange.isLeaf = data[this.setting.isLeaf];
|
|
|
|
- billsId.push(idChange);
|
|
|
|
- newIds.push(data.id);
|
|
|
|
- }
|
|
|
|
- const newData = await this.transaction.insert(this.tableName, datas);
|
|
|
|
- await this.pasteBlockRelaData(billsId);
|
|
|
|
- }
|
|
|
|
- // 数据库创建新增节点数据
|
|
|
|
- await this.transaction.commit();
|
|
|
|
- } catch (err) {
|
|
|
|
- await this.transaction.rollback();
|
|
|
|
- throw err;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 查询应返回的结果
|
|
|
|
- const createData = await this.getDataByIds(newIds);
|
|
|
|
- const updateData = await this.getNextsData(selectData[this.setting.mid], selectData[this.setting.pid], selectData[this.setting.order] + copyNodes.length);
|
|
|
|
- //const posData = await this.ctx.service.pos.getPosData({ lid: newIds });
|
|
|
|
- return {
|
|
|
|
- ledger: { create: createData, update: updateData },
|
|
|
|
- //pos: posData,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = TreeService;
|
|
module.exports = TreeService;
|