Преглед изворни кода

定额库数据接口 schemas分离等

zhongzewei пре 8 година
родитељ
комит
4fc32b0a13

+ 2 - 24
modules/ration_repository/models/coe.js

@@ -2,30 +2,8 @@
  * Created by CSL on 2017/5/3.
  * 系数表。
  */
-
-var mongoose = require("mongoose");
-var dbm = require("../../../config/db/db_manager");
-var db = dbm.getCfgConnection("scConstruct");
-var counter = require('../../../public/counter/counter');
-
-var coeSchema = mongoose.Schema({
-    coeType: String,                // 系数类型,指作用范围:
-                                    // 单个(如:111量0.001)、人工类、材料类、机械类、全部(如:定额×0.925)。
-    gljCode: String,                  // 要调整的工料机Code(当coeType=0时有效)
-    operator: String,               // 运算符(*、+、-、=)
-    amount: String,                 // 调整的量
-    _id: false
-});
-
-var coeListSchema = mongoose.Schema({
-    libID: Number,                      // 所属定额定ID
-    ID: Number,                         // 系数ID(流水号ID)
-    name: String,                       // 名称
-    content: String,                    // 说明
-    coes: [coeSchema]
-}, {versionKey: false});
-
-var coeListModel = db.model("std_ration_lib_coe_list",coeListSchema, "std_ration_lib_coe_list")
+let counter = require('../../../public/counter/counter');
+import {coeListModel} from './schemas';
 
 var coeListDAO = function(){};
 

+ 0 - 1
modules/ration_repository/models/glj_repository.js

@@ -2,7 +2,6 @@
  * Created by Tony on 2017/5/4.
  * 工料机的总库,根据不同定额库分类,参考原gljList表
  */
-
 var mongoose = require("mongoose");
 var dbm = require("../../../config/db/db_manager");
 var db = dbm.getCfgConnection("scConstruct");

+ 5 - 43
modules/ration_repository/models/ration_item.js

@@ -1,52 +1,14 @@
 /**
  * Created by Tony on 2017/4/28.
  */
-var mongoose = require("mongoose");
-var dbm = require("../../../config/db/db_manager");
-var db = dbm.getCfgConnection("scConstruct");
-var async = require("async");
-var Schema = mongoose.Schema;
 
-var rationGljItemSchema = mongoose.Schema({
-    gljId: Number,
-    consumeAmt: Number,
-    proportion: Number //配合比,暂时无需使用,默认0
-}, { _id: false });
-
-var rationAssItemSchema = mongoose.Schema({
-    name: String,
-    assistID: Number,
-    assistCode: String,
-    stdValue: String,
-    stepValue: String,
-    decimal: Number,
-    carryBit: String,
-    minValue: String,
-    maxValue: String
-}, { _id: false });
-
-var rationItemSchema = mongoose.Schema({
-    ID:Number,
-    code: String,
-    name: String,
-    unit: String,
-    labourPrice: Number,
-    materialPrice: Number,
-    machinePrice: Number,
-    basePrice: Number,
-    sectionId: Number,
-    rationRepId: Number,
-    caption: String,
-    feeType: Number,
-    rationGljList: [rationGljItemSchema],
-    rationCoeList: Array,
-    rationAssList: [rationAssItemSchema]
-});
-var rationItemModel = db.model("std_ration_lib_ration_items",rationItemSchema, "std_ration_lib_ration_items")
-var counter = require('../../../public/counter/counter');
-let gljDao = require('./glj_repository');
+let async = require("async");
 let moment = require('moment');
+let counter = require('../../../public/counter/counter');
+let gljDao = require('./glj_repository');
 let rationRepositoryDao = require('./repository_map');
+import {rationItemModel} from './schemas';
+
 var rationItemDAO = function(){};
 
 rationItemDAO.prototype.getRationItemsBySection = function(sectionId,callback){

+ 4 - 19
modules/ration_repository/models/ration_section_tree.js

@@ -2,26 +2,11 @@
  * Created by Tony on 2017/4/21.
  */
 
-var mongoose = require("mongoose");
-var dbm = require("../../../config/db/db_manager");
-var chapterTreeDb = dbm.getCfgConnection("scConstruct");
-var async = require("async");
-var Schema = mongoose.Schema;
-let rationRepositoryDao = require('./repository_map');
+let async = require('async');
 let moment = require('moment');
-
-var rationChapterTreeSchema = new Schema({//章节树  //生成唯一id改为sectionID  改成string
-    rationRepId: Number,
-    ID:Number,
-    ParentID:Number,
-    NextSiblingID:Number,
-    name: String,
-    explanation: String,//说明
-    ruleText: String,//计算规则
-    isDeleted: Boolean
-});
-var rationChapterTreeModel = chapterTreeDb.model("std_ration_lib_ration_chapter_trees", rationChapterTreeSchema, "std_ration_lib_ration_chapter_trees");
-var counter = require('../../../public/counter/counter');
+let counter = require('../../../public/counter/counter');
+let rationRepositoryDao = require('./repository_map');
+import {rationChapterTreeModel} from './schemas';
 
 var rationChapterTreeDAO = function(){};
 

+ 30 - 36
modules/ration_repository/models/repository_map.js

@@ -2,38 +2,11 @@
  * Created by Tony on 2017/4/24.
  * 重新构造,不适宜生成多个定额库db,还是得统一在一个表
  */
-var mongoose = require('mongoose');
-var dbm = require("../../../config/db/db_manager");
 let async = require("async");
 let moment = require('moment');
+let counter = require('../../../public/counter/counter');
 import gljMapModel from "../../std_glj_lib/models/schemas";
-//var stringUtil = require('../../../public/stringUtil');
-var rationLibdb = dbm.getCfgConnection("scConstruct");
-var Schema = mongoose.Schema;
-
-let oprSchema = new Schema({
-        operateDate: String,
-        operator: String
-    },
-    {_id: false},
-    {versionKey: false});
-
-var RepositoryMapSchema = new Schema({
-    "ID": Number,
-    "dispName" : String,
-    "appType" : String, //如:"建筑" / "公路"
-    "compilationId": String, //编办
-    "compilationName": String,
-    "gljLib": Number,
-    "descr" : String,
-    "creator": String,
-    "createDate": String,
-    "recentOpr" :[oprSchema],
-    "deleted": Boolean
-},  {versionKey: false});
-var counter = require('../../../public/counter/counter');
-
-var rationRepository = rationLibdb.model("std_ration_lib_map", RepositoryMapSchema, "std_ration_lib_map");
+import {rationRepository, rationChapterTreeModel, rationItemModel} from './schemas';
 
 function createNewLibModel(rationLibObj){
     var rst = {};
@@ -232,14 +205,35 @@ rationRepositoryDao.prototype.deleteRationLib = function(oprtor, libId, callback
                            callback(err, '移除工料机库失败!');
                        }
                        else{
-                           //移除工料机库内被引用标记
-                           gljMapModel.update({ID: result[0].gljLib, deleted: false}, {$pull: {rationLibs: {ID: libId}}}, function (err) {
-                               if(err){
-                                   callback(err, '删除引用失败!');
-                               }
-                               else{
-                                   callback(null, '成功!');
+                           async.parallel([
+                               function (cb) {
+                                   //移除工料机库内被引用标记
+                                   gljMapModel.update({ID: result[0].gljLib, deleted: false}, {$pull: {rationLibs: {ID: libId}}}, function (err) {
+                                       if(err){
+                                           cb(err);
+                                       }
+                                       else{
+                                           cb(null);
+                                       }
+                                   });
+                               },
+                               //删除库下定额
+                               function (cb) {
+                                   rationItemModel.update({rationRepId: libId}, {$set: {isDeleted: true}}, {upsert: true, multi: true}, function (err) {
+                                       if(err)cb(err);
+                                       else cb(null);
+                                   });
+                               },
+                               //删除库下章节树
+                               function (cb) {
+                                   rationChapterTreeModel.update({rationRepId: libId}, {$set: {isDeleted: true}}, {upsert: true, multi: true}, function (err) {
+                                       if(err)cb(err);
+                                       else cb(null);
+                                   })
                                }
+                           ], function (err) {
+                               if(err) callback(err, 'fail');
+                               else callback(null, 'sc')
                            });
                        }
                    });

+ 106 - 0
modules/ration_repository/models/schemas.js

@@ -0,0 +1,106 @@
+/**
+ * Created by Zhong on 2017/9/13.
+ */
+import mongoose from "mongoose";
+let dbm = require("../../../config/db/db_manager");
+let db = dbm.getCfgConnection("scConstruct");
+let Schema = mongoose.Schema;
+
+let coeSchema = new Schema({
+    coeType: String,                // 系数类型,指作用范围:
+                                    // 单个(如:111量0.001)、人工类、材料类、机械类、全部(如:定额×0.925)。
+    gljCode: String,                  // 要调整的工料机Code(当coeType=0时有效)
+    operator: String,               // 运算符(*、+、-、=)
+    amount: String,                 // 调整的量
+    _id: false
+});
+
+let coeListSchema = new Schema({
+    libID: Number,                      // 所属定额定ID
+    ID: Number,                         // 系数ID(流水号ID)
+    name: String,                       // 名称
+    content: String,                    // 说明
+    coes: [coeSchema]
+}, {versionKey: false});
+
+
+let oprSchema = new Schema({
+        operateDate: String,
+        operator: String
+    },
+    {_id: false},
+    {versionKey: false});
+
+//定额库
+let RepositoryMapSchema = new Schema({
+    "ID": Number,
+    "dispName" : String,
+    "appType" : String, //如:"建筑" / "公路"
+    "compilationId": String, //编办
+    "compilationName": String,
+    "gljLib": Number,
+    "descr" : String,
+    "creator": String,
+    "createDate": String,
+    "recentOpr" :[oprSchema],
+    "deleted": Boolean
+},  {versionKey: false});
+
+//定额章节树
+let rationChapterTreeSchema = new Schema({
+    rationRepId: Number,
+    ID:Number,
+    ParentID:Number,
+    NextSiblingID:Number,
+    name: String,
+    explanation: String,//说明
+    ruleText: String,//计算规则
+    isDeleted: Boolean
+});
+
+//定额工料机
+let rationGljItemSchema = new Schema({
+    gljId: Number,
+    consumeAmt: Number,
+    proportion: Number //配合比,暂时无需使用,默认0
+}, { _id: false });
+
+//辅助定额调整
+let rationAssItemSchema = new Schema({
+    name: String,
+    assistID: Number,
+    assistCode: String,
+    stdValue: String,
+    stepValue: String,
+    decimal: Number,
+    carryBit: String,
+    minValue: String,
+    maxValue: String
+}, { _id: false });
+
+//定额
+var rationItemSchema = new Schema({
+    ID:Number,
+    code: String,
+    name: String,
+    unit: String,
+    labourPrice: Number,
+    materialPrice: Number,
+    machinePrice: Number,
+    basePrice: Number,
+    sectionId: Number,
+    rationRepId: Number,
+    caption: String,
+    feeType: Number,
+    rationGljList: [rationGljItemSchema],
+    rationCoeList: Array,
+    rationAssList: [rationAssItemSchema],
+    isDeleted: Boolean
+});
+
+let coeListModel = db.model("std_ration_lib_coe_list",coeListSchema, "std_ration_lib_coe_list")
+let rationRepository = db.model("std_ration_lib_map", RepositoryMapSchema, "std_ration_lib_map");
+let rationChapterTreeModel = db.model("std_ration_lib_ration_chapter_trees", rationChapterTreeSchema, "std_ration_lib_ration_chapter_trees");
+let rationItemModel = db.model("std_ration_lib_ration_items",rationItemSchema, "std_ration_lib_ration_items");
+
+export{coeListModel, rationRepository, rationChapterTreeModel, rationItemModel};

+ 42 - 2
modules/std_glj_lib/models/gljMapModel.js

@@ -2,6 +2,7 @@
  * Created by Zhong on 2017/8/11.
  */
 import gljMapModel from "./schemas";
+import {gljModel, gljClassModel} from "./schemas";
 import moment from "moment";
 import counter from "../../../public/counter/counter";
 import async from "async";
@@ -144,14 +145,53 @@ class GljMapDao extends OprDao{
                             callback(null, '此工料机库已被引用!');
                         }
                         else{
-                            gljMapModel.update({ID: libId, deleted: false}, {$set: {deleted: true}}, function (err) {
+                            async.parallel([
+                                function (cb) {
+                                    gljMapModel.update({ID: libId, deleted: false}, {$set: {deleted: true}}, function (err) {
+                                        if(err){
+                                            cb(err);
+                                        }
+                                        else{
+                                            cb(null);
+                                        }
+                                    });
+                                },
+                                function (cb) {
+                                    gljModel.update({repositoryId: libId}, {$set: {deleted: true}}, {upsert: true, multi: true}, function (err) {
+                                        if(err){
+                                            cb(err);
+                                        }
+                                        else{
+                                            cb(null);
+                                        }
+                                    });
+                                },
+                                function (cb) {
+                                    gljClassModel.update({repositoryId: libId}, {$set: {deleted: true}}, {upsert: true, multi: true}, function (err) {
+                                        if(err){
+                                            cb(err);
+                                        }
+                                        else{
+                                            cb(null);
+                                        }
+                                    })
+                                }
+                            ], function (err) {
                                 if(err){
                                     callback(err, '移除工料机库失败!');
                                 }
                                 else{
-                                   callback(null, '删除成功');
+                                    callback(null, '删除成功');
                                 }
                             });
+                           /* gljMapModel.update({ID: libId, deleted: false}, {$set: {deleted: true}}, function (err) {
+                                if(err){
+                                    callback(err, '移除工料机库失败!');
+                                }
+                                else{
+                                   callback(null, '删除成功');
+                                }
+                            });*/
                         }
                     }
                 });

+ 1 - 0
modules/std_glj_lib/models/gljModel.js

@@ -28,6 +28,7 @@ class GljDao  extends OprDao{
                             newClassObj.NextSiblingID = data.NextSiblingID;
                             newClassObj.Name = data.Name;
                             newClassObj.repositoryId = gljLibId;
+                            newClassObj.deleted = false;
                             gljClassModel.create(newClassObj, function(err){
                                 if(err)cb(err);
                                 else{

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

@@ -107,7 +107,7 @@
                                 <!--  <div class="m-2"><a href="javacript:void(0);" data-toggle="modal" data-target="#editTsm" title="编辑">编辑说明</a></div>-->
                                   <div class="main-content m-2">
                                       <h5>说明</h5>
-                                      <textarea id="explanationShow" class="form-control"   rows="7" style="background: white;"></textarea>
+                                      <textarea id="explanationShow" class="form-control" rows="35" style="background: white;"></textarea>
                                   </div>
                               </div>
                           </div>
@@ -117,7 +117,7 @@
                          <!--         <div class="m-2"><a href="javacript:void(0);" data-toggle="modal" data-target="#editTjs" title="编辑">编辑计算规则</a></div>-->
                                   <div class="main-content m-2">
                                       <h5>计算规则</h5>
-                                      <textarea id="ruleTextShow" class="form-control"   rows="7" style="background: white;"></textarea>
+                                      <textarea id="ruleTextShow" class="form-control"   rows="35" style="background: white;"></textarea>
                                   </div>
                               </div>
                           </div>

+ 2 - 2
web/maintain/ration_repository/js/ration.js

@@ -322,7 +322,7 @@ var rationOprObj = {
             if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
                 //addArr.push(rObj);
                 me.addRationItem = rObj;
-                if(rObj.code && rObj.code.trim().length > 0){
+                if(rObj.code && rObj.code.toString().trim().length > 0){
                     if(me.rationsCodes.indexOf(rObj.code) === -1){
                         addArr.push(rObj);
                         me.rationsCodes.push(rObj.code);
@@ -349,7 +349,7 @@ var rationOprObj = {
                         });
                     }*/
                 }
-                else if(rObj.code && rObj.code.trim().length === 0){
+                else if(rObj.code && rObj.code.toString.trim().length === 0){
                     me.workBook.getSheet(0).setValue(args.row, args.col, '');
                 }
             }

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

@@ -12,10 +12,10 @@ var rationGLJOprObj = {
             {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
             {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"},
             {headerName:"规格",headerWidth:120,dataCode:"specs", dataType: "String"},
-            {headerName:"单位",headerWidth:160,dataCode:"unit", dataType: "String"},
+            {headerName:"单位",headerWidth:160,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
             {headerName:"基价单价",headerWidth:160, dataCode:"basePrice", dataType: "Number", formatter:"0.00",  precision: 2},
             {headerName:"定额消耗",headerWidth:160, dataCode:"consumeAmt", dataType: "Number", formatter: "0.000", precision: 3},
-            {headerName:"类型",headerWidth:160,dataCode:"gljType", dataType: "String"}
+            {headerName:"类型",headerWidth:160,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"}
         ],
         view:{
             comboBox:[],
@@ -249,7 +249,7 @@ var rationGLJOprObj = {
                 }
             }
         } else {
-            if(args.editingText && args.editingText.trim().length !== 0){
+            if(args.editingText && args.editingText.toString().trim().length !== 0){
                 let isExist = false;
                 for(let i = 0, len = cacheArr.length; i < len; i++){
                     if(cacheArr[i].code === args.editingText && i !== args.row){
@@ -267,7 +267,7 @@ var rationGLJOprObj = {
                         let rationRepId = storageUtil.getSessionCache("RationGrp","repositoryID");
                         let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
                         let codes = [];
-                        codes.push(args.editingText.trim());
+                        codes.push(args.editingText.toString().trim());
                         me.addGljItems(codes, gljLibID, args);
                     }
                     else if(args.row >= cacheArr.length){//新增
@@ -275,7 +275,7 @@ var rationGLJOprObj = {
                             let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
                             if (gljLibID) {
                                 var codes = [];
-                                codes.push(args.editingText.trim());
+                                codes.push(args.editingText.toString().trim());
                                 me.addGljItems(codes, gljLibID, args);
                             }
                     }