|
@@ -787,6 +787,39 @@ class BaseBillsSerivce extends TreeService {
|
|
|
ledgerBills.is_tp = ledgerExtra ? ledgerExtra.is_tp : 0;
|
|
|
return ledgerBills
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取最大节点id
|
|
|
+ *
|
|
|
+ * @param {Number} mid - master id
|
|
|
+ * @return {Number}
|
|
|
+ * @private
|
|
|
+ */
|
|
|
+ async _getMaxLid(mid) {
|
|
|
+ const cacheKey = this.setting.keyPre + mid;
|
|
|
+ let maxId = this.setting.cacheKey ? parseInt(await this.cache.get(cacheKey)) : undefined;
|
|
|
+ if (this.setting.cacheKey) {
|
|
|
+ // 判断是否存在变更新增部位maxId,有则取两者最大值
|
|
|
+ const changeReviseCacheKey = 'change_ledger_maxLid2:' + mid;
|
|
|
+ const changeReviseMaxId = await this.cache.get(changeReviseCacheKey);
|
|
|
+ if (changeReviseMaxId) {
|
|
|
+ maxId = !maxId ? parseInt(changeReviseMaxId) : Math.max(maxId, parseInt(changeReviseMaxId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!maxId) {
|
|
|
+ const sql = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
|
|
|
+ const sqlParam = [this.setting.kid, this.tableName, mid];
|
|
|
+ const queryResult = await this.db.queryOne(sql, sqlParam);
|
|
|
+ maxId = queryResult.max_id || 0;
|
|
|
+ const sql1 = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
|
|
|
+ const sqlParam1 = [this.setting.kid, this.ctx.service.changeLedger.tableName, mid];
|
|
|
+ const queryResult1 = await this.db.queryOne(sql1, sqlParam1);
|
|
|
+ const maxId1 = queryResult1.max_id || 0;
|
|
|
+ maxId = Math.max(maxId, maxId1);
|
|
|
+ if (this.setting.cacheKey) this.cache.set(cacheKey, maxId, 'EX', this.ctx.app.config.cacheTime);
|
|
|
+ }
|
|
|
+ return maxId;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = BaseBillsSerivce;
|