Просмотр исходного кода

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionOperation

TonyKang 7 лет назад
Родитель
Сommit
a32bd4a59c

+ 160 - 58
modules/ration_repository/controllers/ration_repository_controller.js

@@ -9,59 +9,66 @@ import async from "async";
 var callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
 };
+// 上传控件
+const multiparty = require("multiparty");
+const fs = require("fs");
+// excel解析
+const excel = require("node-xlsx");
+const rationItem = require("../models/ration_item");
 
-class RationRepositoryController extends baseController{
-   async getCompilationList(req, res){
-       try{
-           let compilationModel = new CompilationModel(), rst = [];
-           let compilationList = await compilationModel.getCompilationList();
-           if(compilationList.length <= 0){
-               throw '没有数据';
-           }
-           else{
-
-               compilationList.forEach(function (compilation) {
-                   rst.push({_id: compilation._id, name: compilation.name});
-               });
-               //获得相关编办下的工料机库
-               let parallelFucs = [];
-               for(let i = 0; i < rst.length; i++){
-                   parallelFucs.push((function (obj) {
-                       return function (cb) {
-                           gljMapModel.find({compilationId: obj._id, deleted: false}, function (err, result) {
-                               if(err){
-                                   cb(err);
-                               }
-                               else{
-                                   cb(null, result);
-                               }
-                           })
-                       }
-                   })(rst[i]));
-               }
-               async.parallel(parallelFucs, function (err, result) {
-                   if(err){
-                       callback(req, res, err, '没有数据', null);
-                   }
-                   else{
-                       let gljLibsRst = [];
-                       for(let i = 0; i < result.length; i++){
-                           for(let j = 0; j < result[i].length; j++){
-                               gljLibsRst.push(result[i][j]);
-                           }
-                       }
-                       callback(req, res, false, '', {compilation: rst, gljLibs: gljLibsRst});
-                   }
-               })
-           }
-       }
-        catch(err) {
+class RationRepositoryController extends baseController {
+    async getCompilationList(req, res) {
+        try {
+            let compilationModel = new CompilationModel(), rst = [];
+            let compilationList = await compilationModel.getCompilationList();
+            if (compilationList.length <= 0) {
+                throw '没有数据';
+            }
+            else {
+
+                compilationList.forEach(function (compilation) {
+                    rst.push({_id: compilation._id, name: compilation.name});
+                });
+                //获得相关编办下的工料机库
+                let parallelFucs = [];
+                for (let i = 0; i < rst.length; i++) {
+                    parallelFucs.push((function (obj) {
+                        return function (cb) {
+                            gljMapModel.find({compilationId: obj._id, deleted: false}, function (err, result) {
+                                if (err) {
+                                    cb(err);
+                                }
+                                else {
+                                    cb(null, result);
+                                }
+                            })
+                        }
+                    })(rst[i]));
+                }
+                async.parallel(parallelFucs, function (err, result) {
+                    if (err) {
+                        callback(req, res, err, '没有数据', null);
+                    }
+                    else {
+                        let gljLibsRst = [];
+                        for (let i = 0; i < result.length; i++) {
+                            for (let j = 0; j < result[i].length; j++) {
+                                gljLibsRst.push(result[i][j]);
+                            }
+                        }
+                        callback(req, res, false, '', {compilation: rst, gljLibs: gljLibsRst});
+                    }
+                })
+            }
+        }
+        catch (err) {
             callback(req, res, err, '没有数据', null);
         }
     }
-    addRationRepository(req,res){
+
+    addRationRepository(req, res) {
         var rationObj = JSON.parse(req.body.rationRepObj);
-        rationRepository.addRationRepository(rationObj,function(err,data){
+        rationRepository.addRationRepository(rationObj, function (err, data) {
             if (data) {
                 callback(req, res, err, "has data", data);
             } else {
@@ -70,27 +77,30 @@ class RationRepositoryController extends baseController{
         })
     }
     getRationLib(req, res){
-        let libId = req.body.libId;
+        let data = JSON.parse(req.body.data);
+        let libId = data.libId;
         rationRepository.getRationLib(libId, function(err, data){
             if (data) {
-                callback(req, res, err, "has data",data);
+                callback(req, res, err, "has data", data);
             } else {
                 callback(req, res, err, "no data", null);
             }
         });
     }
-    getDisPlayRationLibs(req, res){
-        rationRepository.getDisplayRationLibs(function(err, data){
+
+    getDisPlayRationLibs(req, res) {
+        rationRepository.getDisplayRationLibs(function (err, data) {
             if (data) {
-                callback(req, res, err, "has data",data);
+                callback(req, res, err, "has data", data);
             } else {
                 callback(req, res, err, "no data", null);
             }
         });
     }
-    getRealLibName(req,res){
+
+    getRealLibName(req, res) {
         var libName = req.body.rationName;
-        rationRepository.getRealLibName(libName,function(err,data){
+        rationRepository.getRealLibName(libName, function (err, data) {
             if (data) {
                 callback(req, res, err, "has data", data);
             } else {
@@ -98,8 +108,9 @@ class RationRepositoryController extends baseController{
             }
         })
     }
-    getLibIDByName(req,res){
-        rationRepository.getLibIDByName(req.body.libName, function(err,data){
+
+    getLibIDByName(req, res) {
+        rationRepository.getLibIDByName(req.body.libName, function (err, data) {
             if (data) {
                 callback(req, res, err, "has ID", data);
             } else {
@@ -108,7 +119,7 @@ class RationRepositoryController extends baseController{
         })
     }
 
-    deleteRationLib(req,res){
+    deleteRationLib(req, res) {
         let oprtor = req.body.oprtor,
             libId = req.body.libId;
         rationRepository.deleteRationLib(oprtor, libId, function (err, message) {
@@ -123,6 +134,97 @@ class RationRepositoryController extends baseController{
             callback(req, res, err, message, null);
         })
     }
+
+    /**
+     * 上传定额库原始数据
+     *
+     * @param {Object} request
+     * @param {Object} response
+     * @return {void}
+     */
+    async uploadSourceData(request, response) {
+        let responseData = {
+            err: 0,
+            msg: ''
+        };
+        const allowHeader = ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
+        try {
+            const uploadOption = {
+                uploadDir: './public/tmp'
+            };
+            const form = new multiparty.Form(uploadOption);
+            form.parse(request, async function(err, fields, files) {
+                const rationRepId = fields.rationRepId !== undefined && fields.rationRepId.length > 0 ?
+                    fields.rationRepId[0] : 0;
+                if (rationRepId <= 0) {
+                    throw '参数错误';
+                }
+                const file = files.file !== undefined ? files.file[0] : null;
+                if (err || file === null) {
+                    throw '上传失败';
+                }
+                // 判断类型
+                if (file.headers['content-type'] === undefined || allowHeader.indexOf(file.headers['content-type']) < 0) {
+                    throw '不支持该类型';
+                }
+                // 重命名文件名
+                const uploadFullName = uploadOption.uploadDir + '/' + file.originalFilename;
+                fs.renameSync(file.path, uploadFullName);
+
+                const sheet = excel.parse(uploadFullName);
+                if (sheet[0] === undefined || sheet[0].data === undefined) {
+                    throw 'excel没有对应数据';
+                }
+
+                const result = await rationItem.batchAddFromExcel(rationRepId, sheet[0].data);
+                // 删除文件
+                if (result) {
+                    fs.unlink(uploadFullName, null);
+                }
+                response.json(responseData);
+            });
+        } catch (error) {
+            responseData.err = 1;
+            responseData.msg = error;
+            response.json(responseData);
+        }
+
+        return;
+    }
+
+    /**
+     * 导出内容数据
+     *
+     * @param {Object} request
+     * @param {Object} response
+     * @return {void}
+     */
+    async exportRationData(request, response) {
+        let rationRepId = request.query.rationRepId;
+        rationRepId = parseInt(rationRepId);
+        try {
+            if (isNaN(rationRepId) || rationRepId <= 0) {
+                throw '参数错误';
+            }
+            const excelData = await rationItem.exportExcelData(rationRepId);
+            const buffer = excel.build([{name: "sheet", data: excelData}]);
+            const filePath = './public/tmp/export.xlsx';
+            fs.writeFileSync(filePath, buffer, 'binary');
+            const stats = fs.statSync(filePath);
+            // 下载相关header
+            response.set({
+                'Content-Type': 'application/octet-stream',
+                'Content-Disposition': 'attachment; filename=ration.xlsx',
+                'Content-Length': stats.size
+            });
+            fs.createReadStream(filePath).pipe(response);
+            fs.unlink(filePath);
+        } catch (error) {
+            response.end(error);
+        }
+
+    }
+
 }
 
 export default RationRepositoryController;

+ 6 - 0
modules/ration_repository/controllers/ration_section_tree_controller.js

@@ -23,6 +23,12 @@ class RationChapterTreeController extends BaseController{
             })
         }
     }
+    getNewRationTreeID(req, res){
+        rationChapterTreeData.getNewRationTreeID(function (err, data) {
+            callback(req, res, err, '', data);
+        });
+
+    }
     createNewNode(req, res){
         var libId = req.body.rationLibId;
         var lastNodeId = req.body.lastNodeId;

+ 140 - 3
modules/ration_repository/models/ration_item.js

@@ -333,7 +333,7 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                 }
                                 updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
                             }
-                            updatePrc.basePrice = updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice;
+                            updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice, -2);
                             //updateDataBase
                             rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
                                     machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
@@ -457,7 +457,144 @@ rationItemDAO.prototype.updateAnnotation = function (lastOpr, repId, updateArr,
             }
         });
     });
-}
+};
+
+/**
+ * 根据条件获取定额数据
+ *
+ * @param {Object} condition
+ * @param {Object} fields
+ * @param {String} indexBy
+ * @return {Promise|Array}
+ */
+rationItemDAO.prototype.getRationItemByCondition = async function (condition, fields = null, indexBy = null) {
+    let result = [];
+    if (Object.keys(condition).length <= 0) {
+        return result;
+    }
+    result = await rationItemModel.find(condition, fields);
+    if (indexBy !== null && result.length > 0) {
+        let tmpResult = {};
+        for(let tmp of result) {
+            tmpResult[tmp[indexBy]] = tmp;
+        }
+        result = tmpResult;
+    }
+    return result;
+};
+
+/**
+ * 从excel中批量新增数据
+ *
+ * @param {Number} rationRepId
+ * @param {Array} data
+ * @return {bool}
+ */
+rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) {
+    if (data.length <= 0) {
+        return false;
+    }
+    let lastData = {};
+    const rationData = [];
+    // 编码列表,用于查找库中是否有对应数据
+    let rationCodeList = [];
+    let gljCodeList = [];
+    for (const tmp of data) {
+        if (tmp.length <= 0) {
+            continue;
+        }
+        // 如果第一个字段为null则是工料机数据,放入上一个数据的工料机字段
+        if (tmp[0] === undefined && Object.keys(lastData).length > 0) {
+            const tmpRationGlj = {
+                gljId: 1,
+                consumeAmt: tmp[4],
+                proportion: 0,
+            };
+            lastData.rationGljList.push(tmpRationGlj);
+            if (gljCodeList.indexOf(tmp[1]) < 0) {
+                gljCodeList.push(tmp[1]);
+            }
+            continue;
+        }
+
+        if (tmp[0] === '定额' && Object.keys(lastData).length > 0) {
+            rationData.push(lastData);
+        }
+
+        // 组装数据
+        lastData = {
+            code: tmp[1],
+            name: tmp[2],
+            unit: tmp[3],
+            caption: tmp[2],
+            rationRepId: rationRepId,
+            rationGljList: []
+        };
+        // 防止重复加入
+        if (rationCodeList.indexOf(tmp[1]) < 0) {
+            rationCodeList.push(tmp[1]);
+        }
+    }
+    // 最后一个入数组
+    rationData.push(lastData);
+
+    // 查找数据库中是否已存在待插入数据
+    const condition = {
+        rationRepId: rationRepId,
+        code: { $in: rationCodeList }
+    };
+    const existCodeList = await this.getRationItemByCondition(condition, ['code'], 'code');
+    // 过滤插入数据
+    let insertData = [];
+    for (const ration of rationData) {
+        if (existCodeList[ration.code] !== undefined) {
+            continue;
+        }
+        insertData.push(ration);
+    }
+    // 如果都已经存在,直接返回
+    if (insertData.length <= 0) {
+        return true;
+    }
+
+    // 组织id
+    const counterInfo = await counter.counterDAO.getIDAfterCount(counter.moduleName.rations, insertData.length);
+    let maxId = counterInfo.value.sequence_value;
+    maxId = parseInt(maxId);
+
+    let count = 0;
+    for (const index in insertData) {
+        insertData[index].ID = maxId - (insertData.length - 1) + count;
+        count++;
+    }
+    // 插入数据库
+    const result = await rationItemModel.create(insertData);
+    return result.length > 0;
+};
+
+/**
+ * 导出到excel的数据
+ *
+ * @param {Number} rationRepId
+ * @return {Array}
+ */
+rationItemDAO.prototype.exportExcelData = async function(rationRepId) {
+    const condition = {
+        rationRepId: rationRepId
+    };
+    // @todo 限制导出的数量以防内存溢出
+    const rationDataList = await this.getRationItemByCondition(condition, ['name', 'code']);
+    // 整理数据
+    let rationData = [];
+    for (const tmp of rationDataList) {
+        const ration = [null, tmp.code, tmp.name];
+        rationData.push(ration);
+    }
+    const excelData = [['树ID', '定额名', '定额编码']];
+    excelData.push.apply(excelData, rationData);
+
+    return excelData;
+};
 
-module.exports = new rationItemDAO()
+module.exports = new rationItemDAO();
 

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

@@ -18,6 +18,17 @@ rationChapterTreeDAO.prototype.getRationChapterTree = function(rationLibId,callb
     })
 }
 
+rationChapterTreeDAO.prototype.getNewRationTreeID = function (callback) {
+    counter.counterDAO.getIDAfterCount(counter.moduleName.rationTree, 1, function(err, result){
+        if(err){
+            callback(err, null);
+        }
+        else{
+            callback(0, result.value.sequence_value);
+        }
+    });
+};
+
 rationChapterTreeDAO.prototype.getRationChapterTreeByRepId = function(repId,callback){
     rationChapterTreeModel.find({"rationRepId": repId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
         if(data.length) callback(0,data);

+ 1 - 1
modules/ration_repository/models/repository_map.js

@@ -156,7 +156,7 @@ rationRepositoryDao.prototype.getRationLib = function(libId, callback) {
         if (err) {
             callback( 'Error', null);
         } else {
-            callback( false, data);
+            callback(0, data);
         }
     });
 };

+ 5 - 0
modules/ration_repository/routes/ration_rep_routes.js

@@ -38,6 +38,7 @@ module.exports =  function (app) {
     apiRouter.post("/getLibIDByName",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getLibIDByName);
 
     apiRouter.post("/getRationTree",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.getRationChapterTree);
+    apiRouter.post("/getNewRationTreeID",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.getNewRationTreeID);
     apiRouter.post("/createNewNode",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.createNewNode);
     apiRouter.post("/updateNodes",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateNodes);
     apiRouter.post("/deleteNodes",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.deleteNodes);
@@ -72,5 +73,9 @@ module.exports =  function (app) {
     apiRouter.post('/getRationItem',searchController.auth, searchController.init, searchController.getRationItem);
     apiRouter.post('/findRation', searchController.auth, searchController.init, searchController.findRation);
 
+    // 导入导出定额库相关
+    apiRouter.post('/upload', rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.uploadSourceData);
+    apiRouter.get('/export', rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.exportRationData);
+
     app.use("/rationRepository/api",apiRouter);
 }

+ 2 - 0
package.json

@@ -25,6 +25,8 @@
     "bluebird": "^3.5.0",
     "jszip": "^3.1.3",
     "log4js": "~2.3.3",
+    "multiparty": "^4.1.3",
+    "node-xlsx": "^0.11.2",
     "pdfkit": "^0.8.2",
     "ueditor": "^1.2.3"
   },

+ 6 - 2
public/counter/counter.js

@@ -45,14 +45,18 @@ var counterDAO = function(){};
  *     result.value.sequence_value Ϊ�޸ĺ��id
  * }
  */
-counterDAO.prototype.getIDAfterCount = function(moduleName, stepCount, callback) {
+counterDAO.prototype.getIDAfterCount = async function(moduleName, stepCount, callback = null) {
     var sc = stepCount;
     if (isNaN(stepCount) || (stepCount < 0)) {
         sc = 1;
     } else if (!(/^-?\d+$/.test(stepCount))) {
         sc = Math.round(stepCount + 0.5);
     }
-    counterModel.findAndModify({_id: moduleName}, [], { $inc: { sequence_value: sc } }, {'new':true}, callback);
+    if (callback === null) {
+        return await counterModel.findAndModify({_id: moduleName}, [], { $inc: { sequence_value: sc } }, {'new':true});
+    } else {
+        counterModel.findAndModify({_id: moduleName}, [], { $inc: { sequence_value: sc } }, {'new':true}, callback);
+    }
 }
 
 counterDAO.prototype.getCurrentID = function(moduleName, callback) {

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

@@ -76,6 +76,76 @@ $(function () {
 
     });
     getCompilationList();
+
+    // 导入原始数据按钮
+    let rationRepId = 0;
+    $("#showArea").on("click", ".import-source", function () {
+        let id = $(this).data("id");
+        id = parseInt(id);
+        if (isNaN(id) || id <= 0) {
+            return false;
+        }
+        rationRepId = id;
+        $("#import").modal("show");
+    });
+
+    // 导入原始数据确认
+    $("#source-import").click(function() {
+        const self = $(this);
+        try {
+            let formData = new FormData();
+            let file = $("input[name='source_file']")[0];
+            if (file.files.length <= 0) {
+                throw '请选择文件!';
+            }
+            formData.append('file', file.files[0]);
+            // 获取定额库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) {
+                        // 成功则关闭窗体
+                        $("#import").modal("hide");
+                    } else {
+                        const message = response.msg !== undefined ? response.msg : '上传失败!';
+                        alert(message);
+                    }
+                },
+                error: function(){
+                    alert("与服务器通信发生错误");
+                    self.removeAttr('disabled');
+                    self.text('确定导入');
+                }
+            });
+        } catch(error) {
+            alert(error);
+        }
+    });
+
+    // 导出数据
+    $("#showArea").on("click", ".export", function () {
+        let id = $(this).data("id");
+        id = parseInt(id);
+        if (isNaN(id) || id <= 0) {
+            return false;
+        }
+        window.location.href = '/rationRepository/api/export?rationRepId=' + id;
+    });
 });
 
 function getAllRationLib(callback){
@@ -103,7 +173,11 @@ function getAllRationLib(callback){
                         "<td>"+createDate+" </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>");
+                        "<i class='fa fa-remove'></i></a></td>" +
+                        "<td><a class='btn btn-secondary btn-sm import-source' href='javacript:void(0);' data-id='"+ id +"' title='导入原始数据'><i class='fa fa-sign-in fa-rotate-90'></i>导入</a></td>" +
+                        "<td><a class='btn btn-success btn-sm export' href='javacript:void(0);' data-toggle='modal' data-id='"+ id +"' data-target='#emport' title='导出内部数据'><i class='fa fa-sign-out fa-rotate-270'></i>导出</a> " +
+                        "<a class='btn btn-secondary btn-sm' href='javacript:void(0);' data-toggle='modal' data-target='#import2' title='导入内部数据'><i class='fa fa-sign-in fa-rotate-90'></i>导入</a></td>" +
+                        "</tr>");
                     var newHref = "/rationRepository/ration?repository="+id;
                     $("#tempId td:first a").attr("href", newHref);
                     $("#tempId").attr("id", id);

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

@@ -47,11 +47,6 @@ let rationOprObj = {
     buildSheet: function(container) {
         let rationRepId = getQueryString("repository");
         let me = rationOprObj;
-        let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
-        if(!gljLibID || typeof gljLibID === 'undefined' || gljLibID == -1){
-            alert("没有引用工料机库!");
-            window.location.href = "/rationRepository/main";
-        }
         me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
         me.getRationsCodes(rationRepId);
         me.rationDelOpr();

+ 3 - 3
web/maintain/ration_repository/js/ration_glj.js

@@ -449,7 +449,7 @@ var rationGLJOprObj = {
                 });
                 let roundPrice = scMathUtil.roundTo(labourPrice, -2);
                 rst.labourPrice = roundPrice;
-                rationBasePrc += roundPrice;
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
             }
             if(price.gljType2.length > 0){
                 let materialPrice = 0;
@@ -458,7 +458,7 @@ var rationGLJOprObj = {
                 });
                 let roundPrice = scMathUtil.roundTo(materialPrice, -2);
                 rst.materialPrice = roundPrice;
-                rationBasePrc += roundPrice;
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
             }
             if(price.gljType3.length > 0){
                 let machinePrice = 0;
@@ -467,7 +467,7 @@ var rationGLJOprObj = {
                 });
                 let roundPrice = scMathUtil.roundTo(machinePrice, -2);
                 rst.machinePrice = roundPrice;
-                rationBasePrc += roundPrice;
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
             }
             rst.rationBasePrc = rationBasePrc;
         }

+ 57 - 40
web/maintain/ration_repository/js/section_tree.js

@@ -4,27 +4,39 @@
 let pageOprObj = {
     rationLibName : null,
     rationLibId : null,
+    gljLibId: null,
     initPage : function() {
-        var me = this, rationLibId = getQueryString("repository"),//获取定额库参数
-            rationLibName = storageUtil.getSessionCache("RationGrp","repositoryID_" + rationLibId);
-        if (rationLibName) {
-            var html = $("#rationname")[0].outerHTML;
-            html = html.replace("XXX定额库", rationLibName);
-            $("#rationname")[0].outerHTML = html;
-            me.rationLibName = rationLibName;
-            me.rationLibId = rationLibId;
-            sectionTreeObj.getSectionTree(rationLibId);
-            //job
-            jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
-            $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
-            $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
-            jobContentOprObj.bindAllEvents($('#txtareaAll'));
-            //fz
-            annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
-            $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
-            $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
-            annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
-        }
+        let me = this, rationLibId = getQueryString("repository");
+        me.getRationLibInfo(rationLibId, function (rstData) {
+            if(rstData.length > 0){
+                me.rationLibName = rstData[0].dispName;
+                me.gljLibId = rstData[0].gljLib;
+                if(!me.gljLibId || typeof me.gljLibId === 'undefined' || me.gljLibId == -1){
+                    alert("没有引用工料机库!");
+                    window.location.href = "/rationRepository/main";
+                }
+                if (me.rationLibName) {
+                    var html = $("#rationname")[0].outerHTML;
+                    html = html.replace("XXX定额库", me.rationLibName);
+                    $("#rationname")[0].outerHTML = html;
+                    me.rationLibId = rationLibId;
+                    sectionTreeObj.getSectionTree(rationLibId);
+                    //job
+                    jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
+                    $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
+                    $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
+                    jobContentOprObj.bindAllEvents($('#txtareaAll'));
+                    //fz
+                    annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
+                    $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
+                    $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
+                    annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
+                }
+            }
+        });
+    },
+    getRationLibInfo: function (rationLibId, callback) {
+        CommonAjax.post('api/getRationLib', {libId: rationLibId}, callback);
     }
 }
 
@@ -277,27 +289,32 @@ let sectionTreeObj = {
         let me = this;
         me.insertBtn.addClass('disabled');
         let postData = [];
-        let newID = me.tree.newNodeID();
-        let selected = me.tree.selected;
-        let insertObj = me.getUpdateObj(me.updateType.new, newID, -1, -1, '', null);
-        if(me.isDef(selected)) {
-            let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), newID, null, null, null);
-            postData.push(updateObj);
-            insertObj.updateData.ParentID = selected.getParentID();
-            if(me.isDef(selected.nextSibling)){
-                insertObj.updateData.NextSiblingID = selected.getNextSiblingID();
+        CommonAjax.post('api/getNewRationTreeID', {}, function (newID) {
+            if(!me.isDef(newID)){
+                return;
             }
-        }
-        postData.push(insertObj);
-        if(postData.length > 0){
-            //ajax
-            me.sectionTreeAjax(postData, function (rstData) {
-                me.controller.insert();
-                me.refreshBtn(me.tree.selected);
-                //fresh tools
-                me.initTools(me.tree.selected);
-            });
-        }
+            me.tree.maxNodeID(newID - 1);
+            let selected = me.tree.selected;
+            let insertObj = me.getUpdateObj(me.updateType.new, newID, -1, -1, '', null);
+            if(me.isDef(selected)) {
+                let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), newID, null, null, null);
+                postData.push(updateObj);
+                insertObj.updateData.ParentID = selected.getParentID();
+                if(me.isDef(selected.nextSibling)){
+                    insertObj.updateData.NextSiblingID = selected.getNextSiblingID();
+                }
+            }
+            postData.push(insertObj);
+            if(postData.length > 0){
+                //ajax
+                me.sectionTreeAjax(postData, function (rstData) {
+                    me.controller.insert();
+                    me.refreshBtn(me.tree.selected);
+                    //fresh tools
+                    me.initTools(me.tree.selected);
+                });
+            }
+        });
     },
     remove: function (selected) {
         let me = this;

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

@@ -35,7 +35,7 @@
                   <div class="col-md-8">
                     <div class="warp-p2 mt-3">
                       <table class="table table-hover table-bordered">
-                        <thead><tr><th>定额库名称</th><th width="160">编办</th><th width="160">添加时间</th><th width="90">操作</th></tr></thead>
+                        <thead><tr><th>定额库名称</th><th width="160">编办</th><th width="160">添加时间</th><th width="90">操作</th><th width="90">原始数据</th><th width="150">内部数据</th></tr></thead>
                         <tbody id="showArea">
                         </tbody>
                       </table>
@@ -153,6 +153,67 @@
             </div>
         </div>
     </div>
+    <!--弹出导入原始数据-->
+    <div class="modal fade" id="import" data-backdrop="static" style="display: none;" aria-hidden="true">
+        <form action="/rationRepository/api/upload" enctype="multipart/form-data" method="post">
+            <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="source_file">
+                            </div>
+                        </form>
+                    </div>
+                    <div class="modal-footer">
+                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                        <input type="hidden" name="rationRepId" value="0"/>
+                        <button type="button" class="btn btn-primary" id="source-import">确定导入</button>
+                    </div>
+                </div>
+            </div>
+        </form>
+    </div>
+
+    <!--弹出导入内部数据-->
+    <div class="modal fade" id="import2" 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">
+                        </div>
+                    </form>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                    <input type="hidden" name="rationRepId" value="0"/>
+                    <a href="" class="btn btn-primary">确定导入</a>
+                </div>
+            </div>
+        </div>
+    </div>
     <!-- JS. -->
     <script src="/lib/jquery/jquery.min.js"></script>
     <script src="/lib/tether/tether.min.js"></script>