|
@@ -152,16 +152,17 @@ module.exports = app => {
|
|
|
/**
|
|
/**
|
|
|
* 首次初始化项目资料目录。
|
|
* 首次初始化项目资料目录。
|
|
|
*
|
|
*
|
|
|
- * 空白模式创建一个可继续编辑的根目录;项目模式只复制目录字段,
|
|
|
|
|
|
|
+ * 空白模式创建一个可继续编辑的根目录;模板和项目模式只复制目录字段,
|
|
|
* 不复制文件与目录授权用户配置。
|
|
* 不复制文件与目录授权用户配置。
|
|
|
*
|
|
*
|
|
|
* @param {String} spid 目标子项目ID
|
|
* @param {String} spid 目标子项目ID
|
|
|
- * @param {String} initType 初始化方式(blank/project)
|
|
|
|
|
- * @param {Array} sourceData 来源项目有效目录
|
|
|
|
|
|
|
+ * @param {String} initType 初始化方式(blank/template/project)
|
|
|
|
|
+ * @param {Array} sourceData 来源模板或项目的有效目录
|
|
|
* @param {Number} operatorUid 初始化用户ID
|
|
* @param {Number} operatorUid 初始化用户ID
|
|
|
|
|
+ * @param {Object|null} templateData 选用的系统模板
|
|
|
* @return {Object} 初始化结果
|
|
* @return {Object} 初始化结果
|
|
|
*/
|
|
*/
|
|
|
- async initializeDirectory(spid, initType, sourceData, operatorUid) {
|
|
|
|
|
|
|
+ async initializeDirectory(spid, initType, sourceData, operatorUid, templateData = null) {
|
|
|
let directorySource = sourceData || [];
|
|
let directorySource = sourceData || [];
|
|
|
if (initType === 'blank') {
|
|
if (initType === 'blank') {
|
|
|
directorySource = [{
|
|
directorySource = [{
|
|
@@ -169,10 +170,11 @@ module.exports = app => {
|
|
|
name: '新建文件夹', filing_type: maxFilingType + 1, is_fixed: 1,
|
|
name: '新建文件夹', filing_type: maxFilingType + 1, is_fixed: 1,
|
|
|
tips: '', upload_tips: '', file_company: '', is_rela: 0,
|
|
tips: '', upload_tips: '', file_company: '', is_rela: 0,
|
|
|
}];
|
|
}];
|
|
|
- } else if (initType !== 'project') {
|
|
|
|
|
|
|
+ } else if (initType !== 'project' && initType !== 'template') {
|
|
|
throw '初始化方式错误';
|
|
throw '初始化方式错误';
|
|
|
}
|
|
}
|
|
|
- if (directorySource.length === 0) throw '来源项目没有可复制的资料目录';
|
|
|
|
|
|
|
+ if (initType === 'template' && (!templateData || !templateData.id)) throw '系统模板数据错误';
|
|
|
|
|
+ if (directorySource.length === 0) throw '来源数据没有可复制的资料目录';
|
|
|
const insertData = this._buildInitializedFiling(spid, directorySource, operatorUid);
|
|
const insertData = this._buildInitializedFiling(spid, directorySource, operatorUid);
|
|
|
|
|
|
|
|
const conn = await this.db.beginTransaction();
|
|
const conn = await this.db.beginTransaction();
|
|
@@ -183,6 +185,13 @@ module.exports = app => {
|
|
|
const activeCount = await conn.count(this.tableName, { spid, is_deleted: 0 });
|
|
const activeCount = await conn.count(this.tableName, { spid, is_deleted: 0 });
|
|
|
if (activeCount > 0) throw '当前项目已经存在资料目录,无需重复初始化';
|
|
if (activeCount > 0) throw '当前项目已经存在资料目录,无需重复初始化';
|
|
|
await conn.insert(this.tableName, insertData);
|
|
await conn.insert(this.tableName, insertData);
|
|
|
|
|
+ if (initType === 'template') {
|
|
|
|
|
+ await conn.update(this.ctx.service.subProject.tableName, {
|
|
|
|
|
+ id: spid,
|
|
|
|
|
+ filing_template_id: templateData.id,
|
|
|
|
|
+ filing_template_name: templateData.name,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
await conn.commit();
|
|
await conn.commit();
|
|
|
return { count: insertData.length };
|
|
return { count: insertData.length };
|
|
|
} catch (err) {
|
|
} catch (err) {
|