|
@@ -85,6 +85,17 @@ module.exports = app => {
|
|
if (data.is_fixed) throw '固定分类,不可编辑';
|
|
if (data.is_fixed) throw '固定分类,不可编辑';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async getNewName(spid, name = '新增文件类别') {
|
|
|
|
+ const data = await this.db.query(`SELECT * FROM ${this.tableName} WHERE spid = '${spid}' AND name LIKE '${name}%'`);
|
|
|
|
+ if (data.length === 0) return name;
|
|
|
|
+
|
|
|
|
+ const _ = this._;
|
|
|
|
+ const names = data.map(x => { return _.toInteger(x.name.replace(name, '')) });
|
|
|
|
+ const filterNames = names.filter(x => { return x > 0 });
|
|
|
|
+ const max = filterNames.reduce((pre, cur) => { return Math.max(pre, cur); }, 0);
|
|
|
|
+ return max >= 0 ? name + (max + 1) : name;
|
|
|
|
+ }
|
|
|
|
+
|
|
async add(data) {
|
|
async add(data) {
|
|
const parent = await this.getDataById(data.tree_pid);
|
|
const parent = await this.getDataById(data.tree_pid);
|
|
if (!parent) throw '添加数据结构错误';
|
|
if (!parent) throw '添加数据结构错误';
|
|
@@ -101,10 +112,11 @@ module.exports = app => {
|
|
const sessionProject = this.ctx.session.sessionProject;
|
|
const sessionProject = this.ctx.session.sessionProject;
|
|
|
|
|
|
const tree_order = preChild ? preChild.tree_order + 1 : (sibling.length > 0 ? sibling[sibling.length - 1].tree_order + 1 : 1);
|
|
const tree_order = preChild ? preChild.tree_order + 1 : (sibling.length > 0 ? sibling[sibling.length - 1].tree_order + 1 : 1);
|
|
|
|
+ const name = await this.getNewName(parent.spid);
|
|
const insertData = {
|
|
const insertData = {
|
|
id: this.uuid.v4(), spid: parent.spid, add_user_id: sessionUser.accountId,
|
|
id: this.uuid.v4(), spid: parent.spid, add_user_id: sessionUser.accountId,
|
|
tree_pid: parent.id, tree_level: parent.tree_level + 1, tree_order,
|
|
tree_pid: parent.id, tree_level: parent.tree_level + 1, tree_order,
|
|
- name: 'xx文件', filing_type: parent.filing_type,
|
|
|
|
|
|
+ name, filing_type: parent.filing_type,
|
|
};
|
|
};
|
|
const operate = await conn.insert(this.tableName, insertData);
|
|
const operate = await conn.insert(this.tableName, insertData);
|
|
if (operate.affectedRows === 0) throw '新增文件夹失败';
|
|
if (operate.affectedRows === 0) throw '新增文件夹失败';
|