Browse Source

修复升降级bug

ellisran 9 tháng trước cách đây
mục cha
commit
7b79eed0b2
2 tập tin đã thay đổi với 39 bổ sung5 xóa
  1. 7 1
      app/public/js/contract_detail.js
  2. 32 4
      app/service/contract_tree.js

+ 7 - 1
app/public/js/contract_detail.js

@@ -203,6 +203,12 @@ $(document).ready(function() {
             //         break;
             //     }
             // }
+            const nextNodes = _.filter(tree.getChildren(tree.getParent(first)), function (item){ return item.order > first.order });
+            let nextHadContract = false;
+            for (const next of nextNodes) {
+                if (nextHadContract) continue;
+                nextHadContract = this.checkContract(next);
+            }
             const valid = !sheet.zh_setting.readOnly;
 
             setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1);
@@ -211,7 +217,7 @@ $(document).ready(function() {
             setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
             setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
             setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first)
-                && first.level > 2 && tree.isLastSibling(last) && upPower && !hadContract);
+                && first.level > 2 && (!nextHadContract || tree.isLastSibling(last)) && upPower && !hadContract);
             setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
                 && first.level > 1 && preNode && (preNode.children.length > 0 || preNode.children.length === 0) && !hadContract && preNode.c_code === undefined);
             // setObjEnable($('#cut'), valid);

+ 32 - 4
app/service/contract_tree.js

@@ -590,6 +590,11 @@ module.exports = app => {
             const selects = await this.getDataByKidAndCount(options, kid, count);
 
             if (selects.length !== count) throw '升级节点数据错误';
+            if (this._.findIndex(selects, function (item) {
+                return item.c_code;
+            }) !== -1) {
+                throw '存在合同节点不可升级';
+            }
             const first = selects[0], last = selects[count - 1];
             const parent = await this.getDataByKid(options, first[this.setting.pid]);
             if (!parent) throw '升级节点数据错误';
@@ -651,6 +656,11 @@ module.exports = app => {
             if (!count) count = 1;
             const selects = await this.getDataByKidAndCount(options, kid, count);
             if (!selects) throw '降级节点数据错误';
+            if (this._.findIndex(selects, function (item) {
+                return item.c_code;
+            }) !== -1) {
+                throw '存在合同节点不可降级';
+            }
             const first = selects[0], last = selects[count - 1];
             const pre = await this.getDataByParentAndOrder(options, first[this.setting.pid], first[this.setting.order] - 1);
             if (!pre) throw '节点不可降级';
@@ -879,6 +889,11 @@ module.exports = app => {
             // 查询selectData的lastChild
             const lastChild = await this.getLastChildData(options, select[this.setting.kid]);
             const nexts = await this.getNextsData(options, select[this.setting.pid], select[this.setting.order]);
+            if (this._.findIndex(nexts, function (item) {
+                return item.c_code;
+            }) !== -1) {
+                throw '存在合同节点不可升级';
+            }
             if (nexts && nexts.length > 0) {
                 // 修改nextsData pid, 排序
                 // this.initSqlBuilder();
@@ -904,8 +919,8 @@ module.exports = app => {
                 // });
                 // const [sql1, sqlParam1] = this.sqlBuilder.build(this.tableName, 'update');
                 const orderInc = lastChild ? lastChild[this.setting.order] - select[this.setting.order] : - select[this.setting.order];
-                const sql1 = 'UPDATE ?? SET `' + this.setting.order + '` = ' + (orderInc > 0 ? '+' : '-') + Math.abs(orderInc) + ' WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.pid + ' = ? AND `' + this.setting.order + '` > ?';
-                const sqlParam1 = [this.tableName, select[this.setting.kid], select[this.setting.pid], select[this.setting.order]];
+                const sql1 = 'UPDATE ?? SET `'+ this.setting.pid + '` = '+ select[this.setting.kid] +' , `' + this.setting.order + '` = `'+ this.setting.order + '`' + (orderInc > 0 ? '+' : '-') + Math.abs(orderInc) + ' WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.pid + ' = ? AND `' + this.setting.order + '` > ?';
+                const sqlParam1 = [this.tableName, select[this.setting.pid], select[this.setting.order]];
                 transaction ? await transaction.query(sql1, sqlParam1) : await this.db.query(sql1, sqlParam1);
 
                 // 选中节点 isLeaf应为false
@@ -919,8 +934,8 @@ module.exports = app => {
                 const oldSubStr = this.db.escape(select[this.setting.pid] + '-');
                 const newSubStr = this.db.escape(select[this.setting.kid] + '-');
                 const sqlArr = [];
-                sqlArr.push('Update ?? SET `' + this.setting.fullPath + '` = Replace(`' + this.setting.fullPath + '`,' + oldSubStr + ',' + newSubStr + ') Where');
-                sqlArr.push('(`' + this.ctx.helper._getOptionsSql(options) + ')');
+                sqlArr.push('Update ?? SET `' + this.setting.fullPath + '` = Replace(`' + this.setting.fullPath + '`,' + oldSubStr + ',' + newSubStr + ') Where ');
+                sqlArr.push(this.ctx.helper._getOptionsSql(options));
                 sqlArr.push(' And (');
                 for (const data of nexts) {
                     sqlArr.push('`' + this.setting.fullPath + '` Like ' + this.db.escape(data[this.setting.fullPath] + '%'));
@@ -931,6 +946,7 @@ module.exports = app => {
                 sqlArr.push(')');
                 const sql = sqlArr.join('');
                 const resultData = transaction ? await transaction.query(sql, [this.tableName]) : await this.db.query(sql, [this.tableName]);
+                transaction ? await transaction.query(sql, [this.ctx.service.contract.tableName]) : await this.db.query(sql, [this.ctx.service.contract.tableName]);
                 return resultData;
             }
         }
@@ -942,6 +958,12 @@ module.exports = app => {
          * @private
          */
         async _syncUplevelChildren(options, select, transaction = null) {
+            const children = await this.getDataByFullPath(options, select[this.setting.fullPath] + '-%');
+            if (this._.findIndex(children, function (item) {
+                return item.c_code;
+            }) !== -1) {
+                throw '存在合同节点不可升级';
+            }
             // this.initSqlBuilder();
             // this.sqlBuilder.setAndWhere(this.setting.mid, {
             //     value: select[this.setting.mid],
@@ -977,6 +999,12 @@ module.exports = app => {
          * @private
          */
         async _syncDownlevelChildren(options, select, newFullPath, transaction = null) {
+            const children = await this.getDataByFullPath(options, select[this.setting.fullPath] + '-%');
+            if (this._.findIndex(children, function (item) {
+                return item.c_code;
+            }) !== -1) {
+                throw '存在合同节点不可降级';
+            }
             // this.initSqlBuilder();
             // this.sqlBuilder.setAndWhere(this.setting.mid, {
             //     value: select[this.setting.mid],