ソースを参照

修复新增部位maxLid值获取bug

laiguoran 3 年 前
コミット
b5f4d2732d
2 ファイル変更35 行追加22 行削除
  1. 32 22
      app/service/change_ledger.js
  2. 3 0
      app/service/revise_audit.js

+ 32 - 22
app/service/change_ledger.js

@@ -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];
         }
         }

+ 3 - 0
app/service/revise_audit.js

@@ -427,6 +427,7 @@ module.exports = app => {
                         await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, {
                         await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, {
                             status: SmsAliConst.status.success,
                             status: SmsAliConst.status.success,
                         });
                         });
+
                         // 微信模板通知
                         // 微信模板通知
                         // const wechatData2 = {
                         // const wechatData2 = {
                         //     status: wxConst.status.success,
                         //     status: wxConst.status.success,
@@ -462,6 +463,8 @@ module.exports = app => {
                             total_price: sum.total_price,
                             total_price: sum.total_price,
                             deal_tp: sum.deal_tp,
                             deal_tp: sum.deal_tp,
                         });
                         });
+                        // 清除变更新增部位maxLid缓存,防止树结构混乱
+                        await this.ctx.service.changeLedger._removeCacheMaxLid(audit.tender_id);
                         // 短信通知-审批通过提醒功能
                         // 短信通知-审批通过提醒功能
                         // 下一人
                         // 下一人
                         // const msg = '台账修订审批通过,请登录系统处理。';
                         // const msg = '台账修订审批通过,请登录系统处理。';