|
@@ -138,25 +138,35 @@ module.exports = app => {
|
|
* @private
|
|
* @private
|
|
*/
|
|
*/
|
|
async _getMaxLid(mid) {
|
|
async _getMaxLid(mid) {
|
|
- // const cacheKey = this.setting.keyPre + mid;
|
|
|
|
- // let maxId = parseInt(await this.cache.get(cacheKey));
|
|
|
|
- // if (!maxId) {
|
|
|
|
- const sql = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
|
|
|
|
- const sqlParam = [this.setting.kid, this.ctx.service.ledger.tableName, mid];
|
|
|
|
- const queryResult = await this.db.queryOne(sql, sqlParam);
|
|
|
|
- let maxId = queryResult.max_id || 0;
|
|
|
|
- if (this.newBills) {
|
|
|
|
- const sql2 = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
|
|
|
|
- const sqlParam2 = [this.setting.kid, this.tableName, mid];
|
|
|
|
- const queryResult2 = await this.db.queryOne(sql2, sqlParam2);
|
|
|
|
- if (maxId < queryResult2.max_id || 0) {
|
|
|
|
- maxId = queryResult2.max_id || 0;
|
|
|
|
|
|
+ const cacheKey = this.setting.keyPre + mid;
|
|
|
|
+ let maxId = parseInt(await this.cache.get(cacheKey));
|
|
|
|
+ if (!maxId) {
|
|
|
|
+ const sql = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
|
|
|
|
+ const sqlParam = [this.setting.kid, this.ctx.service.ledger.tableName, mid];
|
|
|
|
+ const queryResult = await this.db.queryOne(sql, sqlParam);
|
|
|
|
+ maxId = queryResult.max_id || 0;
|
|
|
|
+ if (this.newBills) {
|
|
|
|
+ const sql2 = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
|
|
|
|
+ const sqlParam2 = [this.setting.kid, this.tableName, mid];
|
|
|
|
+ const queryResult2 = await this.db.queryOne(sql2, sqlParam2);
|
|
|
|
+ if (maxId < queryResult2.max_id || 0) {
|
|
|
|
+ maxId = queryResult2.max_id || 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ this.cache.set(cacheKey, maxId, 'EX', this.ctx.app.config.cacheTime);
|
|
}
|
|
}
|
|
- // this.cache.set(cacheKey, maxId, 'EX', this.ctx.app.config.cacheTime);
|
|
|
|
- // }
|
|
|
|
return maxId;
|
|
return maxId;
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 移除最大节点id(修订时使用)
|
|
|
|
+ *
|
|
|
|
+ * @param {Number} mid - master id
|
|
|
|
+ * @return {Number}
|
|
|
|
+ * @private
|
|
|
|
+ */
|
|
|
|
+ async _removeCacheMaxLid(mid) {
|
|
|
|
+ return await this.cache.del(this.setting.keyPre + mid);
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 根据 父节点id 和 节点排序order 获取数据
|
|
* 根据 父节点id 和 节点排序order 获取数据
|
|
@@ -287,7 +297,7 @@ module.exports = app => {
|
|
data[this.setting.isLeaf] = true;
|
|
data[this.setting.isLeaf] = true;
|
|
const result = await this.transaction.insert(this.tableName, data);
|
|
const result = await this.transaction.insert(this.tableName, data);
|
|
|
|
|
|
- // this._cacheMaxLid(mid, maxId + 1);
|
|
|
|
|
|
+ this._cacheMaxLid(mid, maxId + 1);
|
|
|
|
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -364,7 +374,7 @@ module.exports = app => {
|
|
newDatas.push(newData);
|
|
newDatas.push(newData);
|
|
}
|
|
}
|
|
const insertResult = await this.transaction.insert(this.tableName, newDatas);
|
|
const insertResult = await this.transaction.insert(this.tableName, newDatas);
|
|
- // this._cacheMaxLid(mid, maxId + count);
|
|
|
|
|
|
+ this._cacheMaxLid(mid, maxId + count);
|
|
|
|
|
|
if (insertResult.affectedRows !== count) throw '新增节点数据错误';
|
|
if (insertResult.affectedRows !== count) throw '新增节点数据错误';
|
|
await this.transaction.commit();
|
|
await this.transaction.commit();
|
|
@@ -725,7 +735,7 @@ module.exports = app => {
|
|
await this.calcNode(qd, this.transaction);
|
|
await this.calcNode(qd, this.transaction);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // this._cacheMaxLid(tenderId, maxId + data.length);
|
|
|
|
|
|
+ this._cacheMaxLid(tenderId, maxId + data.length);
|
|
await this.transaction.commit();
|
|
await this.transaction.commit();
|
|
} catch (err) {
|
|
} catch (err) {
|
|
await this.transaction.rollback();
|
|
await this.transaction.rollback();
|
|
@@ -794,7 +804,7 @@ module.exports = app => {
|
|
await this.calcNode(qd, this.transaction);
|
|
await this.calcNode(qd, this.transaction);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // this._cacheMaxLid(tenderId, maxId + data.length);
|
|
|
|
|
|
+ this._cacheMaxLid(tenderId, maxId + data.length);
|
|
await this.transaction.commit();
|
|
await this.transaction.commit();
|
|
} catch (err) {
|
|
} catch (err) {
|
|
await this.transaction.rollback();
|
|
await this.transaction.rollback();
|
|
@@ -1277,7 +1287,7 @@ module.exports = app => {
|
|
if (pasteBillsData.length > 0) {
|
|
if (pasteBillsData.length > 0) {
|
|
const newData = await this.transaction.insert(this.tableName, pasteBillsData);
|
|
const newData = await this.transaction.insert(this.tableName, pasteBillsData);
|
|
}
|
|
}
|
|
- // this._cacheMaxLid(tid, maxId);
|
|
|
|
|
|
+ this._cacheMaxLid(tid, maxId);
|
|
if (pastePosData.length > 0) {
|
|
if (pastePosData.length > 0) {
|
|
await this.transaction.insert(this.ctx.service.changePos.tableName, pastePosData);
|
|
await this.transaction.insert(this.ctx.service.changePos.tableName, pastePosData);
|
|
}
|
|
}
|
|
@@ -1367,7 +1377,7 @@ module.exports = app => {
|
|
throw err;
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
|
|
- // this._cacheMaxLid(tenderId, maxId + 1);
|
|
|
|
|
|
+ this._cacheMaxLid(tenderId, maxId + 1);
|
|
|
|
|
|
// 查询应返回的结果
|
|
// 查询应返回的结果
|
|
const resultData = {};
|
|
const resultData = {};
|
|
@@ -1555,7 +1565,7 @@ module.exports = app => {
|
|
if (changeId) data.ccid = changeId;
|
|
if (changeId) data.ccid = changeId;
|
|
const result = await this.transaction.insert(this.tableName, data);
|
|
const result = await this.transaction.insert(this.tableName, data);
|
|
|
|
|
|
- // this._cacheMaxLid(tenderId, maxId + 1);
|
|
|
|
|
|
+ this._cacheMaxLid(tenderId, maxId + 1);
|
|
|
|
|
|
return [result, data];
|
|
return [result, data];
|
|
}
|
|
}
|