|
@@ -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],
|