zhangweicheng 6 vuotta sitten
vanhempi
commit
e4baa333d9

+ 1 - 1
modules/all_models/stdRation_ration.js

@@ -37,7 +37,7 @@ const rationItemSchema = new Schema({
     name: String,
     unit: String,
     basePrice: Number,
-    sectionId: Number,
+    sectionId: {type: Number,index: true},
     rationRepId: Number,
     caption: String,
     feeType: Number,

+ 1 - 1
modules/all_models/std_glj.js

@@ -21,7 +21,7 @@ const std_gljComponent = new Schema(
 const std_glj = new Schema({
     deleted: Boolean,
     repositoryId: {type: Number,index: true},
-    ID: Number,
+    ID: {type: Number,index: true},
     code: String,
     name: String,
     specs: String,

+ 11 - 2
modules/complementary_ration_lib/controllers/compleRationController.js

@@ -9,6 +9,8 @@ let compleRationDao = new CompleRationDao();
 let coeListDAO = require('../../ration_repository/models/coe');
 const coeFacade = require('../facades/compleCoeFacade');
 const installFacade = require('../facades/compleInstallFacade');
+let gljUtil = require('../../../public/gljUtil');
+
 let callback = function (req, res, err, msg, data) {
     res.json({error: err, message: msg, data: data})
 };
@@ -89,10 +91,17 @@ class CompleRationController extends BaseController{
         let data = JSON.parse(req.body.data),
             rations = [];
         try {
+            let compilation = req.session.sessionCompilation;
+            let util = gljUtil;
+            //查看编办中有没有重写路径
+            if(compilation.overWriteUrl && compilation.overWriteUrl!=""){
+                let overWrite = require("../../.."+compilation.overWriteUrl);
+                if(overWrite.sortRationGLJ) util = overWrite;
+            }
             if (data.type === libType.complementary) {
-                rations = await compleRationDao.getCompleRationBySection(req.session.sessionUser.id, data.sectionId);
+                rations = await compleRationDao.getCompleRationBySection(req.session.sessionUser.id, data.sectionId,util);
             }  else {
-                rations = await compleRationDao.getRationGljItemsBySection(data.sectionId);
+                rations = await compleRationDao.getRationGljItemsBySection(data.sectionId,util);
             }
             callback(req, res, 0, 'success', rations);
         } catch (err) {

+ 7 - 24
modules/complementary_ration_lib/models/compleRationModel.js

@@ -12,6 +12,7 @@ import async from 'async';
 let stdRationModel = require ('../../ration_repository/models/ration_item').Model;
 let counter = require('../../../public/counter/counter');
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
+let gljUtil = require('../../../public/gljUtil');
 
 class CompleRatoinDao {
     async updateRation(userID, compilationId, updateData, callback){
@@ -131,7 +132,7 @@ class CompleRatoinDao {
     }
 
     //根据章节树获取补充定额
-    async getCompleRationBySection(userId, sectionId) {
+    async getCompleRationBySection(userId, sectionId,gUtil) {
         const deleteQuery = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
         let compleRations = await compleRationModel.find({sectionId: sectionId, $or: deleteQuery});
         for(let ration of compleRations){
@@ -157,17 +158,8 @@ class CompleRatoinDao {
             if(comGljIds.length > 0) {
                 comGljs = await complementaryGljModel.find({userId: userId, ID: {$in: comGljIds}});
             }
-            let gljDatas = stdGljs.concat(comGljs);
-            gljDatas.sort(function (a, b) {
-                let aV = a.gljType + a.code,
-                    bV = b.gljType + b.code;
-                if(aV > bV) {
-                    return 1;
-                } else if (aV < bV) {
-                    return -1;
-                }
-                return 0;
-            });
+            if(!gUtil) gUtil = gljUtil;
+            let gljDatas = gUtil.sortRationGLJ(stdGljs.concat(comGljs));
             for(let glj of gljDatas){
                 hintsArr.push(` ${glj.code} ${glj.name}${glj.specs ? '&nbsp;&nbsp;&nbsp;' + glj.specs : ''}&nbsp;&nbsp&nbsp;${glj.unit}&nbsp;&nbsp;&nbsp;${gljAmtMapping[glj.ID]}`)
             }
@@ -186,7 +178,7 @@ class CompleRatoinDao {
     }
 
     //造价书定额库 根据章节树过去标准定额
-    async getRationGljItemsBySection(sectionId, callback){
+    async getRationGljItemsBySection(sectionId,gUtil){
         let stdRations = await stdRationModel.find({sectionId: sectionId});
         for(let ration of stdRations){
             ration._doc.type = 'std';
@@ -243,17 +235,8 @@ class CompleRatoinDao {
             if(stdGljIds.length > 0) {
                 stdGljs = await stdGljModel.find({ID: {$in: stdGljIds}});
             }
-            let gljDatas = stdGljs;
-            gljDatas.sort(function (a, b) {
-                let aV = a.gljType + a.code,
-                    bV = b.gljType + b.code;
-                if(aV > bV) {
-                    return 1;
-                } else if (aV < bV) {
-                    return -1;
-                }
-                return 0;
-            });
+            if(!gUtil) gUtil = gljUtil;
+            let gljDatas =  gUtil.sortRationGLJ(stdGljs);
             for(let glj of gljDatas){
                 hintsArr.push(` ${glj.code} ${glj.name}${glj.specs ? '&nbsp;&nbsp;&nbsp;' + glj.specs : ''}&nbsp;&nbsp&nbsp;${glj.unit}&nbsp;&nbsp;&nbsp;${gljAmtMapping[glj.ID]}`)
             }

+ 7 - 7
modules/complementary_ration_lib/models/searchModel.js

@@ -14,13 +14,13 @@ const compleRationLib = 'compleRationLib';
 class SearchDao{
     async getRationItem(userId, compilationId, rationRepIds, code, ID, callback){
         let ration = null;
+        let otherLibs=[];
         try{
-            let firstLib = rationRepIds.shift();//优先取第一个
-            if(rationRepIds.includes(firstLib)) {//去掉重复的库ID
-                rationRepIds.splice(rationRepIds.indexOf(firstLib), 1);
-            }
-            if(rationRepIds.includes(compleRationLib)) {
-                rationRepIds.splice(rationRepIds.indexOf(compleRationLib), 1);
+            let firstLib = rationRepIds[0];//优先取第一个
+            for (let l of rationRepIds){
+                if(l != firstLib && l != compleRationLib){
+                    otherLibs.push(l);
+                }
             }
             if(firstLib == compleRationLib){//说明选中的是补充定额库
                 ration = await this.getCompleRation(userId,compilationId,code,ID);
@@ -33,7 +33,7 @@ class SearchDao{
                 ration = await this.getStdRation(firstQuery);
             }
             if(ration == null){//选中的定额库或者默认的定额库中没有找到定额,才走常规的流程查找其它定额库
-                let stdQuery = {rationRepId: {$in: rationRepIds}, code: code, $or: [{isDeleted: null}, {isDeleted: false}]};
+                let stdQuery = {rationRepId: {$in: otherLibs}, code: code, $or: [{isDeleted: null}, {isDeleted: false}]};
                 if(ID){
                     stdQuery = {ID: ID, $or: [{isDeleted: null}, {isDeleted: false}]};
                 }

+ 5 - 2
public/web/gljUtil.js

@@ -331,7 +331,7 @@ let gljUtil = {
     sortRationGLJ:function (list) {
         list = _.sortByAll(list, [function (item) {
             return gljUtil.getMainType(item.type);
-        }, "code"]);
+        }, gljUtil.getCodeSortMath()]);
         return list;
     },
     sortMixRatio:function (list) {
@@ -344,9 +344,12 @@ let gljUtil = {
         list = lo.sortByAll(list, [function (item) {
             if(specialMap[item.unit_price.type] != undefined) return specialMap[item.unit_price.type];
             return gljUtil.getMainType(item.unit_price.type);
-        }, "code"]);
+        }, gljUtil.getCodeSortMath()]);
         return list;
     },
+    getCodeSortMath:function () {
+      return "code"
+    },
     isConcreteType:function (type) {
         let concreteType = [gljUtil.gljType.CONCRETE,gljUtil.gljType.MORTAR,gljUtil.gljType.MIX_RATIO];//混凝土大类:混凝土、砂浆,配合比
         return concreteType.indexOf(type)!=-1

+ 26 - 0
web/over_write/js/zhejiang_2005.js

@@ -39,10 +39,36 @@ function overwriteRationCalcBases (taxType){
     ];
 })();
 
+if(typeof gljUtil !== 'undefined'){
+    gljUtil.getCodeSortMath = getCodeSortMath
+}
 
 
 
 
+if(typeof module !== 'undefined'){
+    let _= require('lodash');
 
+    module.exports = {
+        sortRationGLJ: function(list){
+            list = _.sortByAll(list, [function (item) {
+                return getMainType(item.gljType?item.gljType:item.type);
+            }, getCodeSortMath()]);
+            return list;
+
+            function getMainType(type) {
+                let str = type + "";
+                return parseInt(str.substr(0,1));
+            }
+         }
+    };
+}
+
+function getCodeSortMath() {
+    return function (item) {
+        let arr = item.code.split('-');
+        return parseInt(arr[0])
+    }
+}