|
@@ -781,6 +781,13 @@ module.exports = app => {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增子节点,并排在所有子节点的末尾
|
|
|
+ * @param {Number} tenderId - 标段Id
|
|
|
+ * @param {Number} selectId - 父节点Id
|
|
|
+ * @param {Object} data - 新增节点数据(编号名称等)
|
|
|
+ * @returns {Promise<*>}
|
|
|
+ */
|
|
|
async addChild(tenderId, selectId, data) {
|
|
|
if ((tenderId <= 0) || (selectId <= 0)) {
|
|
|
return [];
|
|
@@ -805,16 +812,39 @@ module.exports = app => {
|
|
|
data.order = children.length + 1;
|
|
|
data.full_path = selectData.full_path + '.' + data.ledger_id;
|
|
|
data.is_leaf = true;
|
|
|
- const result = await this.db.insert(this.tableName, data);
|
|
|
+
|
|
|
+ this.transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ const result = await this.transaction.insert(this.tableName, data);
|
|
|
+ if (children.length === 0) {
|
|
|
+ await this.transaction.update(this.tableName, {is_leaf: false},
|
|
|
+ { where: {tender_id: tenderId, ledger_id: selectData.ledger_id} });
|
|
|
+ }
|
|
|
+ await this.transaction.commit();
|
|
|
+ } catch(err) {
|
|
|
+ console.log(err);
|
|
|
+ this.transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
|
|
|
this.cache.set(cacheKey, maxId + 1, 'EX', this.ctx.app.config.cacheTime);
|
|
|
|
|
|
// 查询应返回的结果
|
|
|
- const createData = await this.getDataByNodeId(tenderId, data.ledger_id);
|
|
|
- return { create: createData };
|
|
|
-
|
|
|
+ const resultData = {};
|
|
|
+ resultData.create = await this.getDataByNodeId(tenderId, data.ledger_id);
|
|
|
+ if (children.length === 0) {
|
|
|
+ resultData.update = await this.getDataByNodeId(tenderId, selectId);
|
|
|
+ }
|
|
|
+ return resultData;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加标准节点,将选择的标准节点,添加为子节点(排序为末尾)
|
|
|
+ * @param {Number} tenderId - 标段Id
|
|
|
+ * @param {Number} selectId - 添加目标节点Id
|
|
|
+ * @param {Object} stdData - 标准节点数据
|
|
|
+ * @returns {Promise<*>}
|
|
|
+ */
|
|
|
async addStdNodeAsChild(tenderId, selectId, stdData) {
|
|
|
const newData = this._filterStdData(stdData);
|
|
|
const result = await this.addChild(tenderId, selectId, newData);
|
|
@@ -1738,8 +1768,8 @@ module.exports = app => {
|
|
|
|
|
|
this.transaction = await this.db.beginTransaction();
|
|
|
const newIds = [];
|
|
|
+ const lastChild = await this.getLastChildData(tenderId, selectId);
|
|
|
try {
|
|
|
- const lastChild = await this.getLastChildData(tenderId, selectId);
|
|
|
// 更新父项isLeaf
|
|
|
if (!lastChild) {
|
|
|
await this.transaction.update(this.tableName, {
|
|
@@ -1789,6 +1819,9 @@ module.exports = app => {
|
|
|
|
|
|
// 查询应返回的结果
|
|
|
result.ledger.create = await this.getDataByIds(newIds);
|
|
|
+ if (!lastChild) {
|
|
|
+ result.ledger.update = await this.getDataByIds([selectData.id]);
|
|
|
+ }
|
|
|
result.pos = await this.ctx.service.pos.getPosData({ lid: newIds });
|
|
|
return result;
|
|
|
}
|