Przeglądaj źródła

清单指引库定额结构修改、定额导入内部数据debug

zhongzewei 6 lat temu
rodzic
commit
dccb36b8b7

+ 1 - 0
modules/all_models/std_billsGuidance_lib.js

@@ -12,6 +12,7 @@ const mongoose = require('mongoose');
 const Schema = mongoose.Schema;
 
 const stdBillsGuidanceLib = new Schema({
+    type: Number, //1:清单指引 2:清单精灵
     ID: String, //uuid
     compilationId: String,
     compilationName: String,

+ 20 - 17
modules/ration_repository/controllers/ration_repository_controller.js

@@ -159,12 +159,13 @@ class RationRepositoryController extends baseController {
             msg: ''
         };
         const allowHeader = ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
-        try {
-            const uploadOption = {
-                uploadDir: './public'
-            };
-            const form = new multiparty.Form(uploadOption);
-            form.parse(request, async function(err, fields, files) {
+        const uploadOption = {
+            uploadDir: './public'
+        };
+        const form = new multiparty.Form(uploadOption);
+        let uploadFullName
+        form.parse(request, async function(err, fields, files) {
+            try{
                 const rationRepId = fields.rationRepId !== undefined && fields.rationRepId.length > 0 ?
                     fields.rationRepId[0] : 0;
                 const type = fields.type !== undefined && fields.type.length > 0 ?
@@ -181,7 +182,7 @@ class RationRepositoryController extends baseController {
                     throw '不支持该类型';
                 }
                 // 重命名文件名
-                const uploadFullName = uploadOption.uploadDir + '/' + file.originalFilename;
+                uploadFullName = uploadOption.uploadDir + '/' + file.originalFilename;
                 fs.renameSync(file.path, uploadFullName);
 
                 const sheet = excel.parse(uploadFullName);
@@ -191,22 +192,24 @@ class RationRepositoryController extends baseController {
                 const result = type === 'source_file' ?
                     await rationItem.batchAddFromExcel(rationRepId, sheet[0].data) :
                     await rationItem.batchUpdateSectionIdFromExcel(sheet[0].data);
-
-                if (rationItem.failGLJList.length > 0) {
+                if (rationItem.failGLJList && rationItem.failGLJList.length > 0) {
                     responseData.msg = rationItem.failGLJList.join("\r\n");
                 }
                 // 删除文件
-                if (result) {
+                if(uploadFullName && fs.existsSync(uploadFullName)){
                     fs.unlink(uploadFullName);
                 }
                 response.json(responseData);
-            });
-        } catch (error) {
-            responseData.err = 1;
-            responseData.msg = error;
-            response.json(responseData);
-        }
-
+            }
+            catch (error){
+                if(uploadFullName && fs.existsSync(uploadFullName)){
+                    fs.unlink(uploadFullName);
+                }
+                responseData.err = 1;
+                responseData.msg = error;
+                response.json(responseData);
+            }
+        });
         return;
     }
 

+ 8 - 6
modules/ration_repository/models/ration_item.js

@@ -778,7 +778,7 @@ rationItemDAO.prototype.batchUpdateSectionIdFromExcel = async function(data) {
         return false;
     }
     // 批量执行update
-    const bulk = rationItemModel.collection.initializeOrderedBulkOp();
+    let bulkOprs = [];
     for (const tmp of data) {
         let rationId = parseInt(tmp[2]);
         rationId = isNaN(rationId) || rationId <= 0 ? 0 : rationId;
@@ -787,15 +787,17 @@ rationItemDAO.prototype.batchUpdateSectionIdFromExcel = async function(data) {
         // 取费专业
         let feeType = parseInt(tmp[1]);
         feeType = isNaN(feeType) || feeType <= 0 ? 0 : feeType;
+        let name = tmp[4];
+        name = name ? name : '';
         if (sectionId <= 0 || rationId <= 0 || feeType <= 0) {
             continue;
         }
-
-        bulk.find({"ID": rationId}).update({$set: { sectionId: sectionId, feeType: feeType }});
+        bulkOprs.push({updateOne: {filter: {ID: rationId}, update: {$set: {sectionId: sectionId, feeType: feeType, name: name}}}});
     }
-
-    const result = await bulk.execute();
-    return result.isOk();
+    if(bulkOprs.length <= 0){
+        throw '无有效数据(树ID、取费专业、定额ID不为空、且为数值)';
+    }
+    await rationItemModel.bulkWrite(bulkOprs);
 };
 
 module.exports = new rationItemDAO();

+ 17 - 0
web/maintain/billsGuidance_lib/css/main.css

@@ -283,3 +283,20 @@ body {
     opacity: .65;
     color:#666
 }
+.top-content, .fluid-content {
+    overflow: auto;
+    border-bottom: 1px solid #ccc;
+    width: 100%
+}
+.top-content .main-data-top{
+    height: 370px;
+    overflow: auto;
+}
+/*.bottom-content .main-data-bottom{
+    height: 370px;
+    overflow: auto;
+}*/
+.side-search-box{
+    background:#fff;
+    border-bottom:1px solid #ddd
+}

+ 16 - 1
web/maintain/billsGuidance_lib/html/main.html

@@ -31,7 +31,7 @@
                   <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>清单规则</th><th width="160">添加时间</th><th width="90">操作</th></tr></thead>
+                        <thead><tr><th>清单指引名称</th><th>编办</th><th>清单规则</th><th>类型</th><th width="160">添加时间</th><th width="90">操作</th></tr></thead>
                         <tbody>
                         </tbody>
                       </table>
@@ -65,6 +65,21 @@
                       <label>清单规则</label>
                       <select id="billsLibSels" class="form-control"><option>重庆清单规则-2013</option></select>
                     </div>
+                      <div class="form-group">
+                          <label>类型</label>
+                          <div>
+                              <div class="form-check form-check-inline">
+                                  <label class="form-check-label">
+                                      <input class="form-check-input" type="radio" checked name="inlineRadioOptions" id="inlineRadio1" value="1"> 清单指引
+                                  </label>
+                              </div>
+                              <div class="form-check form-check-inline">
+                                  <label class="form-check-label">
+                                      <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="2"> 清单精灵
+                                  </label>
+                              </div>
+                          </div>
+                      </div>
                   </form>
                 </div>
                 <div class="modal-footer">

+ 13 - 1
web/maintain/billsGuidance_lib/html/zhiyin.html

@@ -63,8 +63,20 @@
                                     <button id="insertRation" class="btn btn-primary btn-sm" type="button">插入定额</button>
                                 </div>
                             </div>
+                            <!--搜索结果窗体-->
+                            <div class="side-search-box col-12 p-0" id="rationSearchResult" style="display: none;">
+                                <div class="d-flex justify-content-between">
+                                    <span id="searchCount">搜索结果:153</span><a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="top-content" style="overflow: hidden">
+                            <div class="main-data-top" id="sectionSpread">
+                            </div>
+                        </div>
+                        <div class="bottom-content">
+                            <div class="main-data-bottom" id="rationSpread"></div>
                         </div>
-                        <div id="rationSpread" class="main-data-side-q">
                     </div>
                   </div>
                 </div>

+ 117 - 17
web/maintain/billsGuidance_lib/js/billsGuidance.js

@@ -124,11 +124,53 @@ const billsGuidance = (function () {
             }
         }
     };
+    //定额章节树
+    const section = {
+        dom: $('#sectionSpread'),
+        workBook: null,
+        cache: [],
+        tree: null,
+        controller: null,
+        treeSetting: {
+            treeCol: 0,
+            emptyRows: 0,
+            headRows: 1,
+            headRowHeight: [40],
+            defaultRowHeight: 21,
+            cols: [{
+                width: 400,
+                readOnly: true,
+                head: {
+                    titleNames: ["名称"],
+                    spanCols: [1],
+                    spanRows: [1],
+                    vAlign: [1],
+                    hAlign: [1],
+                    font: ["Arial"]
+                },
+                data: {
+                    field: "name",
+                    vAlign: 1,
+                    hAlign: 0,
+                    font: "Arial"
+                }
+            }]
+        },
+        headers: [
+            {name: '名称', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
+        ],
+        events: {
+            SelectionChanged: function (sender, info) {
+                sectionInitSel(info.newSelections[0].row)
+            }
+        }
+    };
+
     const ration = {
         dom: $('#rationSpread'),
         workBook: null,
-        datas: [],
-        cache: [],
+        datas: [],//所有的数据,搜索定额时,从所有数据中筛选
+        cache: [],//显示在表格上的数据,添加定额可以有效根据行识别定额
         headers: [
             {name: '选择', dataCode: 'select', width: 50, vAlign: 'center', hAlign: 'center'},
             {name: '编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
@@ -247,7 +289,7 @@ const billsGuidance = (function () {
     function cleanData(sheet, headers, rowCount){
         renderSheetFunc(sheet, function () {
             sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
-            if (rowCount > 0) {
+            if (rowCount >= 0) {
                 sheet.setRowCount(rowCount);
             }
         });
@@ -391,24 +433,58 @@ const billsGuidance = (function () {
         };
         renderSheetFunc(sheet, fuc);
     }
+    //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
+    //@param {Number}sectionId {Array}rations @return {Array}
+    function getRationsBySectionId(sectionId, rations) {
+        if(!sectionId || !rations){
+            return [];
+        }
+        return _.filter(rations, {sectionId});
+    }
+    //定额章节树焦点控制
+    //@param {Number}row @return {void}
+    function sectionInitSel(row) {
+        let rationSheet = ration.workBook.getActiveSheet();
+        let sectionNode = section.tree ? section.tree.items[row] : null;
+        if(sectionNode && sectionNode.children.length === 0){
+            let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
+            ration.cache = sectionRations;
+            showData(rationSheet, ration.headers, sectionRations);
+        }
+        else {
+            cleanData(rationSheet, ration.headers, 0);
+        }
+    }
     //初始化定额条目
     //@param {Number}rationLibId @return {void}
     function initRationItems(rationLibId){
         $.bootstrapLoading.start();
-        CommonAjax.post('/rationRepository/api/getRationItemsByLib', {rationLibId: rationLibId}, function (rstData) {
-            rstData.sort(function (a, b) {
-                let rst = 0;
-                if(a.code > b.code){
-                    rst = 1;
-                }
-                else if(a.code < b.code){
-                    rst = -1;
-                }
-                return rst;
+        //获取定额章节树
+        let sectionSheet = section.workBook.getActiveSheet();
+        CommonAjax.post('/rationRepository/api/getRationTree', {rationLibId: rationLibId}, function (sectionDatas) {
+            //获取所有定额数据
+            CommonAjax.post('/rationRepository/api/getRationItemsByLib', {rationLibId: rationLibId}, function (rstData) {
+                section.cache = sectionDatas;
+                initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
+                //初始焦点在第一行(切换库)
+                sectionSheet.setActiveCell(0, 0);
+                rstData.sort(function (a, b) {
+                    let rst = 0;
+                    if(a.code > b.code){
+                        rst = 1;
+                    }
+                    else if(a.code < b.code){
+                        rst = -1;
+                    }
+                    return rst;
+                });
+                ration.datas = rstData;
+                sectionInitSel(0);
+                $.bootstrapLoading.end();
+            }, function () {
+                $.bootstrapLoading.end();
             });
-            ration.datas = rstData;
-            ration.cache = rstData;
-            showData(ration.workBook.getActiveSheet(), ration.headers, rstData);
+        }, function () {
             $.bootstrapLoading.end();
         });
     }
@@ -775,16 +851,40 @@ const billsGuidance = (function () {
                     return data.code.includes(searchStr);
                 });
             }
+            $('.top-content').hide();
+            $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
+            $('#rationSearchResult').show();
+            autoFlashHeight();
+            ration.workBook.refresh();
             let rationSheet = ration.workBook.getActiveSheet();
             renderSheetFunc(rationSheet, function () {
+                clearCheckedRation(getCheckedRationRows());
                 showData(rationSheet, ration.headers, ration.cache);
             })
         });
+        //关闭搜索
+        $('#rationSearchResult a').click(function () {
+            $('.top-content').show();
+            $('#rationSearchResult').hide();
+            autoFlashHeight();
+            renderSheetFunc(ration.workBook.getActiveSheet(), function () {
+                clearCheckedRation(getCheckedRationRows());
+            });
+            section.workBook.refresh();
+            ration.workBook.refresh();
+            $('#searchText').val('');
+            //恢复章节树下的定额
+            sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
+        });
+        //执行搜索
+        $('#searchText').keyup(function (e) {
+            $('#searchBtn').click();
+        });
     }
     //初始化视图
     //@param {void} @return {void}
     function initViews(){
-        let modules = [bills, guideItem, ration];
+        let modules = [bills, guideItem, section, ration];
         initWorkBooks(modules);
         getLibWithBills(libID);
         initBtn();

+ 5 - 5
web/maintain/billsGuidance_lib/js/global.js

@@ -1,19 +1,19 @@
 /*全局自适应高度*/
 function autoFlashHeight(){
     var headerHeight = $(".header").height();
-    var bottomContentHeight = $(".bottom-content").height();
+    var topContentHeight = $('#rationSearchResult').is(':visible') ? 0 : 370;
     var toolsBar = $(".toolsbar").height();
     var toolsBarHeightQ = $(".tools-bar-height-q").height();
     $(".content").height($(window).height()-headerHeight);
     $(".main-side").height($(window).height()-headerHeight-2);
     $(".fluid-content").height($(window).height()-headerHeight-1);
-    $(".side-content").height($(window).height()-headerHeight );
+    $(".side-content").height($(window).height()-headerHeight);
     $(".poj-list").height($(window).height()-headerHeight);
-    $(".form-list").height($(window).height()-headerHeight-50 );
-    $(".main-data-top").height($(window).height()-headerHeight-toolsBar-bottomContentHeight-2);
+    $(".form-list").height($(window).height()-headerHeight-50);
     $(".main-data").height($(window).height()-headerHeight-toolsBar);
     $(".main-data-full").height($(window).height()-headerHeight);
-    $(".main-data-side-q").height($(window).height()-headerHeight-toolsBarHeightQ-2);
+    $(".main-data-bottom").height($(window).height()-headerHeight-toolsBarHeightQ-topContentHeight-$('#rationSearchResult').height() + 30);
+    $('.bottom-content').height($('.main-data-bottom').height());
 
 };
 $(window).resize(autoFlashHeight);

+ 11 - 2
web/maintain/billsGuidance_lib/js/main.js

@@ -10,6 +10,7 @@
 
 const billsGuidanceMain = (function () {
     const updateType = {create: 'create', update: 'update', delete: 'delete'};
+    const typeString = {1: '清单指引', 2: '清单精灵'};
     let guidanceLibs = [];
     let curLib = null;
     //上一个选择的库(三次确认删除同一库时用)
@@ -53,9 +54,12 @@ const billsGuidanceMain = (function () {
     //html新增库
     //@param {Object}tbody {Object}lib @return {void}
     function addLibToView(tbody, lib){
+        let type = lib.type && typeString[lib.type] ? typeString[lib.type] : ''
         let tr = `<tr id="${lib.ID}">
             <td><a href="/billsGuidance/guidance/?libID=${lib.ID}">${lib.name}</a>
-            <td>${lib.compilationName}</td><td>${lib.billsLibName}</td>
+            <td>${lib.compilationName}</td>
+            <td>${lib.billsLibName}</td>
+            <td>${type}</td>
             <td>${lib.createDate.split(' ')[0]}</td>
             <td><a href="javascript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a>
             <a href="javascript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td></tr>`;
@@ -108,7 +112,12 @@ const billsGuidanceMain = (function () {
                 }
                 //新建
                 $.bootstrapLoading.start();
-                let createData = {ID: uuid.v1(), name: cName, compilationId: compilationId, compilationName: compilationName, billsLibId: parseInt(billsLibId), billsLibName:billsLibName};
+                //库类型
+                let addType = $('#add').find('input:checked');
+                if(!addType){
+                    throw '请选择库类型';
+                }
+                let createData = {type: parseInt(addType.val()), ID: uuid.v1(), name: cName, compilationId: compilationId, compilationName: compilationName, billsLibId: parseInt(billsLibId), billsLibName:billsLibName};
                 let updateData = {updateType: updateType.create, updateData: createData};
                 CommonAjax.post('/billsGuidance/api/updateBillsGuideLib', updateData, function (rstData) {
                     guidanceLibs.push(rstData);

+ 4 - 0
web/maintain/ration_repository/js/main.js

@@ -130,6 +130,7 @@ $(function () {
 
     // 导入原始数据确认
     $("#source-import,#data-import").click(function() {
+        $.bootstrapLoading.start();
         const self = $(this);
         const type = self.is("#source-import") ? 'source_file' : 'import_data';
         const dialog = type === 'source_file' ? $("#import") : $("#import2");
@@ -161,6 +162,7 @@ $(function () {
                     self.removeAttr('disabled');
                     self.text('确定导入');
                     if (response.err === 0) {
+                        $.bootstrapLoading.end();
                         const message = response.msg !== undefined ? response.msg : '';
                         if (message !== '') {
                             alert(message);
@@ -168,11 +170,13 @@ $(function () {
                         // 成功则关闭窗体
                         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('确定导入');

+ 1 - 0
web/maintain/ration_repository/js/ration.js

@@ -568,6 +568,7 @@ let rationOprObj = {
                     me.mixDel = 0;
                 }
                 if(callback) callback();
+                me.workBook.focus(true);
             },
             error:function(){
             }

+ 2 - 2
web/maintain/ration_repository/main.html

@@ -168,7 +168,7 @@
                     <form>
                         <div class="form-group">
                             <label>请选择Excel格式文件</label>
-                            <input class="form-control-file" type="file" name="source_file">
+                            <input class="form-control-file" type="file" name="source_file" accept=".xlsx,.xls">
                         </div>
                     </form>
                 </div>
@@ -197,7 +197,7 @@
                     <form>
                         <div class="form-group">
                             <label>请选择Excel格式文件</label>
-                            <input class="form-control-file" type="file" name="import_data"/>
+                            <input class="form-control-file" type="file" accept=".xlsx,.xls" name="import_data"/>
                         </div>
                     </form>
                 </div>