فهرست منبع

导出章节树

zeweizhong 6 سال پیش
والد
کامیت
6364750b3f

+ 16 - 65
modules/ration_repository/controllers/ration_repository_controller.js

@@ -17,6 +17,7 @@ const fs = require("fs");
 // excel解析
 const excel = require("node-xlsx");
 const rationItem = require("../models/ration_item");
+const rationSectionTree = require('../models/ration_section_tree');
 const rationLibModel = mongoose.model('std_ration_lib_map');
 const rationItemModel = mongoose.model('std_ration_lib_ration_items');
 import STDGLJListModel from '../../std_glj_lib/models/gljModel';
@@ -195,9 +196,21 @@ class RationRepositoryController extends baseController {
                 if (sheet[0] === undefined || sheet[0].data === undefined) {
                     throw 'excel没有对应数据';
                 }
-                const failGLJList = type === 'source_file' ?
-                    await rationItem.batchAddFromExcel(rationRepId, sheet[0].data) :
-                    await rationItem.batchUpdateSectionIdFromExcel(sheet[0].data);
+                let failGLJList;
+                switch (type) {
+                    // 导入原始数据
+                    case 'source_file':
+                        failGLJList = await rationItem.batchAddFromExcel(rationRepId, sheet[0].data);
+                        break;
+                    // 导入内部数据
+                    case 'import_data':
+                        failGLJList = await rationItem.batchUpdateSectionIdFromExcel(sheet[0].data);
+                        break;
+                    // 导入章节数据(一列文本,生成兄弟节点树)
+                    case 'section_file':
+                        await rationSectionTree.importSection(rationRepId, sheet[0].data);
+                        break;
+                }
                 if (Array.isArray(failGLJList) && failGLJList.length > 0) {
                     responseData.msg = failGLJList.join("<br/>");
                 }
@@ -301,65 +314,3 @@ class RationRepositoryController extends baseController {
 }
 
 export default RationRepositoryController;
-/*
-module.exports = {
-    addRationRepository:function(req,res){
-        var rationObj = JSON.parse(req.body.rationRepObj);
-        rationRepository.addRationRepository(rationObj,function(err,data){
-            if (data) {
-                callback(req, res, err, "has data", data);
-            } else {
-                callback(req, res, err, "no data", null);
-            }
-        })
-    },
-    getDisPlayRationLibs: function(req, res){
-        rationRepository.getDisplayRationLibs(function(err, data){
-            if (data) {
-                callback(req, res, err, "has data",data);
-            } else {
-                callback(req, res, err, "no data", null);
-            }
-        });
-    },
-    getRealLibName:function(req,res){
-        var libName = req.body.rationName;
-        rationRepository.getRealLibName(libName,function(err,data){
-            if (data) {
-                callback(req, res, err, "has data", data);
-            } else {
-                callback(req, res, err, "no data", null);
-            }
-        })
-    },
-    getLibIDByName:function(req,res){
-        rationRepository.getLibIDByName(req.body.libName, function(err,data){
-            if (data) {
-                callback(req, res, err, "has ID", data);
-            } else {
-                callback(req, res, err, "no ID", null);
-            }
-        })
-    },
-    deleteRationLib:function(req,res){
-        var rationName = req.body.rationName;
-        rationRepository.deleteRationLib(rationName,function(err,data){
-            if (data) {
-                callback(req, res, err, "has data", data);
-            } else {
-                callback(req, res, err, "no data", null);
-            }
-        })
-    },
-    updateRationRepositoryName: function(req, res) {
-        var orgName = req.body.rationName;
-        var newName = req.body.newName;
-        rationRepository.updateName(orgName, newName, function(err, data){
-            if (data) {
-                callback(req, res, err, "has data", data);
-            } else {
-                callback(req, res, err, "no data", null);
-            }
-        });
-    }
-}*/

+ 21 - 0
modules/ration_repository/models/ration_section_tree.js

@@ -11,6 +11,27 @@ const rationModel = mongoose.model('std_ration_lib_ration_items');
 const compleRationSectionTemp = mongoose.model('complementary_ration_section_templates');
 var rationChapterTreeDAO = function(){};
 
+rationChapterTreeDAO.prototype.importSection = async function (rationRepId, sheetData) {
+    const counterRst = await counter.counterDAO.getIDAfterCount(counter.moduleName.rationTree, sheetData.length);
+    const insertData = [];
+    const beginID = counterRst.sequence_value - (sheetData.length - 1);
+    for (let i = 0; i < sheetData.length; i++) {
+        const curData = sheetData[i];
+        const nextData = sheetData[i + 1];
+        const curID = beginID + i;
+        const nextID = nextData ? curID + 1 : -1;
+        const name = curData[0];
+        insertData.push({
+            rationRepId,
+            name,
+            ID: curID,
+            NextSiblingID: nextID,
+            ParentID: -1
+        });
+    }
+    await rationChapterTreeModel.insertMany(insertData);
+};
+
 rationChapterTreeDAO.prototype.sectionTemplateCount = async function (compilationId) {
     return await compleRationSectionTemp.find({compilationId}).count();
 };

+ 66 - 1
web/maintain/ration_repository/js/main.js

@@ -154,6 +154,15 @@ $(function () {
         rationRepId = id;
         $("#import2").modal("show");
     });
+    // 导入章节数据
+    $('#showArea').on('click', '.import-section', function () {
+        let id = $(this).data('id');
+        id = parseInt(id);
+        if (isNaN(id) || id <= 0) {
+            return false;
+        }
+        rationRepId = id;
+    });
 
     // 导入原始数据确认
     $("#source-import,#data-import").click(function() {
@@ -213,7 +222,63 @@ $(function () {
             alert(error);
         }
     });
-
+    // 导入章节数据确认
+    $('#import-section-confirm').click(function() {
+        $.bootstrapLoading.start();
+        const self = $(this);
+        const dialog = $('#section');
+        try {
+            const formData = new FormData();
+            const file = $('input[name=section_file]')[0];
+            if (file.files.length <= 0) {
+                throw '请选择文件!';
+            }
+            formData.append('file', file.files[0]);
+            formData.append('type', 'section_file');
+            // 获取定额库id
+            if (rationRepId <= 0) {
+                return false;
+            }
+            formData.append('rationRepId', rationRepId);
+            $.ajax({
+                url: '/rationRepository/api/upload',
+                type: 'POST',
+                data: formData,
+                cache: false,
+                contentType: false,
+                processData: false,
+                beforeSend: function() {
+                    self.attr('disabled', 'disabled');
+                    self.text('上传中...');
+                },
+                success: function(response){
+                    self.removeAttr('disabled');
+                    self.text('确定导入');
+                    if (response.err === 0) {
+                        $.bootstrapLoading.end();
+                        const message = response.msg !== undefined ? response.msg : '';
+                        if (message !== '') {
+                            alert(message);
+                        }
+                        // 成功则关闭窗体
+                        dialog.modal("hide");
+                    } else {
+                        $.bootstrapLoading.end();
+                        const message = response.msg !== undefined ? response.msg : '上传失败!';
+                        alert(message);
+                    }
+                },
+                error: function(){
+                    $.bootstrapLoading.end();
+                    alert("与服务器通信发生错误");
+                    self.removeAttr('disabled');
+                    self.text('确定导入');
+                }
+            });
+        } catch(error) {
+            alert(error);
+        }
+    });
     // 导出数据
     $("#showArea").on("click", ".export", function () {
         let id = $(this).data("id");

+ 44 - 1
web/maintain/ration_repository/main.html

@@ -49,7 +49,19 @@
                   <div class="col-md-8">
                     <div class="warp-p2 mt-3">
                       <table class="table table-hover table-bordered">
-                        <thead><tr><th>定额库名称</th><th>定额库编码</th><th width="160">费用定额</th><th width="160">添加时间</th><th width="90">操作</th><th width="90">原始数据</th><th width="150">内部数据</th><th width="90">补充模板</th></tr></thead>
+                        <thead>
+                            <tr>
+                                <th>定额库名称</th>
+                                <th>定额库编码</th>
+                                <th width="160">费用定额</th>
+                                <th width="160">添加时间</th>
+                                <th width="90">操作</th>
+                                <th width="90">原始数据</th>
+                                <th width="150">内部数据</th>
+                                <th width="90">章节数据</th>
+                                <th width="90">补充模板</th>
+                            </tr>
+                        </thead>
                         <tbody id="showArea">
                         <% for(let lib of rationLibs){ %>
                         <tr id="<%= lib.ID %>">
@@ -70,6 +82,9 @@
                                 <a class="btn btn-secondary btn-sm import-data" href="javacript:void(0);" data-id="<%= lib.ID %>" title="导入内部数据"><i class="fa fa-sign-in fa-rotate-90"></i>导入</a>
                             </td>
                             <td>
+                                <a class="btn btn-secondary btn-sm import-section" data-toggle="modal" data-target="#section" href="javacript:void(0);" data-id="<%= lib.ID %>" title="导入章节树"><i class="fa fa-sign-in fa-rotate-90"></i>导入</a>
+                            </td>
+                            <td>
                                 <a class="btn btn-secondary btn-sm set-comple" href="javacript:void(0);" data-id="<%= lib.ID %>" title="将章节树设为补充模板数据"><i class="fa fa-sign-in fa-rotate-90"></i>设置</a>
                             </td>
                         </tr>
@@ -274,6 +289,34 @@
             </div>
         </div>
     </div>
+    <!--导入章节树-->
+    <div class="modal fade" id="section" data-backdrop="static" style="display: none;" aria-hidden="true">
+        <div class="modal-dialog" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title">导入章节数据</h5>
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                        <span aria-hidden="true">×</span>
+                    </button>
+                </div>
+                <div class="modal-body">
+                    <div class="alert alert-warning" role="alert">
+                        导入操作会覆盖数据,请谨慎操作!!
+                    </div>
+                    <form>
+                        <div class="form-group">
+                            <label>请选择Excel格式文件</label>
+                            <input class="form-control-file" type="file" name="section_file" accept=".xlsx,.xls">
+                        </div>
+                    </form>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-primary" id="import-section-confirm">确定导入</button>
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                </div>
+            </div>
+        </div>
+    </div>
     <!--弹出设置模板-->
     <div class="modal fade" id="template" data-backdrop="static" style="display: none;" aria-hidden="true">
         <div class="modal-dialog" role="document">