Browse Source

feat: 资料管理 模板导入

caipin 1 ngày trước cách đây
mục cha
commit
ad671db5bb
3 tập tin đã thay đổi với 34 bổ sung14 xóa
  1. 16 3
      app/controller/file_controller.js
  2. 3 5
      app/public/js/filesjs.js
  3. 15 6
      app/service/filing.js

+ 16 - 3
app/controller/file_controller.js

@@ -303,10 +303,22 @@ module.exports = app => {
                 this.checkFilePermission(ctx, 'manage_dir');
                 const data = JSON.parse(ctx.request.body.data);
                 if (!data || !data.init_type) throw '请选择初始化方式';
-                if (data.init_type === 'template') throw '模板库初始化功能暂未开放';
 
                 let sourceData = [];
-                if (data.init_type === 'project') {
+                let templateData = null;
+                if (data.init_type === 'template') {
+                    if (!data.template_id) throw '请选择系统模板库';
+                    templateData = await ctx.service.filingTemplateList.getDataByCondition({
+                        id: data.template_id,
+                        ft_type: ctx.service.filingTemplateList.FtType.org,
+                    });
+                    if (!templateData) throw '选择的系统模板不存在';
+                    sourceData = await ctx.service.filingTemplate.getAllDataByCondition({
+                        where: { temp_id: templateData.id },
+                        orders: [['tree_level', 'asc'], ['tree_order', 'asc']],
+                    });
+                    if (sourceData.length === 0) throw '选择的系统模板没有目录数据';
+                } else if (data.init_type === 'project') {
                     if (!data.source_spid) throw '请选择来源项目';
                     const sourceProjects = await ctx.service.subProject.getManageDirProjects(
                         ctx.session.sessionProject.id,
@@ -324,7 +336,8 @@ module.exports = app => {
                     ctx.subProject.id,
                     data.init_type,
                     sourceData,
-                    ctx.session.sessionUser.accountId
+                    ctx.session.sessionUser.accountId,
+                    templateData
                 );
                 ctx.body = { err: 0, msg: '', data: result };
             } catch (err) {

+ 3 - 5
app/public/js/filesjs.js

@@ -960,16 +960,14 @@ $(document).ready(function() {
         $('#filing-initialization-ok').on('click', function() {
             const button = $(this);
             const initType = $('[name=filing-initialization-type]:checked').val();
+            const data = { init_type: initType };
             if (initType === 'template') {
-                if (!$('#filing-initialization-template').val()) {
+                data.template_id = $('#filing-initialization-template').val();
+                if (!data.template_id) {
                     toastr.warning('请选择系统模板库');
                     return;
                 }
-                toastr.info('模板库初始化功能暂未开放');
-                return;
             }
-
-            const data = { init_type: initType };
             if (initType === 'project') {
                 data.source_spid = $('#filing-initialization-project').val();
                 if (!data.source_spid) {

+ 15 - 6
app/service/filing.js

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