Bladeren bron

Merge branch 'master' of http://192.168.1.41:3000/SmartCost/ConstructionCost

TonyKang 5 jaren geleden
bovenliggende
commit
9dc2afc94c
28 gewijzigde bestanden met toevoegingen van 691 en 217 verwijderingen
  1. 11 0
      gulpfile.js
  2. 1 1
      modules/all_models/compleGlj_section.js
  3. 1 1
      modules/all_models/compleRation_ration.js
  4. 1 1
      modules/all_models/compleRation_section.js
  5. 1 1
      modules/all_models/stdRation_coe.js
  6. 1 1
      modules/all_models/stdRation_ration.js
  7. 2 3
      modules/all_models/stdRation_section.js
  8. 1 1
      modules/all_models/std_glj.js
  9. 6 6
      modules/complementary_ration_lib/models/searchModel.js
  10. 493 78
      modules/main/facade/ration_facade.js
  11. 73 34
      modules/pm/facade/pm_facade.js
  12. 0 1
      modules/unit_price_file/facade/unit_price_facade.js
  13. 2 2
      public/web/tree_sheet/tree_sheet_controller.js
  14. 2 2
      public/web/tree_sheet/tree_sheet_helper.js
  15. 6 6
      web/building_saas/complementary_glj_lib/html/tools-gongliaoji.html
  16. 5 0
      web/building_saas/complementary_glj_lib/js/glj.js
  17. 2 2
      web/building_saas/complementary_ration_lib/html/dinge.html
  18. 2 2
      web/building_saas/complementary_ration_lib/js/init.js
  19. 2 1
      web/building_saas/main/js/controllers/project_controller.js
  20. 6 3
      web/building_saas/main/js/models/bills.js
  21. 1 1
      web/building_saas/main/js/models/calc_base.js
  22. 1 1
      web/building_saas/main/js/models/calc_program.js
  23. 4 3
      web/building_saas/main/js/models/ration.js
  24. 0 2
      web/building_saas/main/js/models/ration_coe.js
  25. 47 46
      web/building_saas/main/js/views/glj_view.js
  26. 9 7
      web/building_saas/main/js/views/project_view.js
  27. 4 4
      web/building_saas/main/js/views/zmhs_view.js
  28. 7 7
      web/over_write/js/guangdong_2018_export.js

+ 11 - 0
gulpfile.js

@@ -26,6 +26,7 @@ let compleRation_coe_jspaths = config.compleRation_coe_jspaths;
 let compleRation_coe_csspaths = config.compleRation_coe_css;
 let compleRation_inst_csspaths = config.compleRation_inst_css;
 let compleRation_inst_jspaths = config.compleRation_inst_jspaths;
+let unitPrice_jspaths = config.unitPrice_jspaths;
 let version=config.version;
 let cssDest='web/dest/css';
 let scriptsDest='web/dest/scripts';
@@ -171,6 +172,16 @@ let compleRation_instOptions = {
     ]
 }
 
+let unitPriceOptions={
+  version:version,
+  scriptsDest:scriptsDest,
+  jspaths:unitPrice_jspaths,
+  concatName:'unitPrice.all.min',
+  htmlDest:'web/building_saas/unit_price_file',
+  htmlName:'index.html',
+  injectList:['web/dest/scripts/unitPrice.all.min.'+version+'.js']
+}
+
 function minify(options) {
     if(options.jspaths){
         return gulp.src(options.jspaths)

+ 1 - 1
modules/all_models/compleGlj_section.js

@@ -14,7 +14,7 @@ const Schema = mongoose.Schema;
 const compleGljSection = new Schema({
     userId: String,
     compilationId: String,
-    Name: String,
+    Name: {type: String,index: true},
     ID: String,
     ParentID: String,
     NextSiblingID: String,

+ 1 - 1
modules/all_models/compleRation_ration.js

@@ -41,7 +41,7 @@ const compleRationSchema = new Schema({
     userId: String,
     compilationId: String,
     rationRepId: Number,
-    ID:Number,
+    ID:{type: Number,index: true},
     code: String,
     name: String,
     unit: String,

+ 1 - 1
modules/all_models/compleRation_section.js

@@ -17,7 +17,7 @@ const compleRationSectionTreeSchema = new Schema({
     name: String,
     //是否是同层第一个节点
    // isFirst: Boolean,
-    ID: String,
+    ID: {type: String,index: true},
     NextSiblingID: String,
     ParentID: String,
     deleteInfo: deleteSchema,

+ 1 - 1
modules/all_models/stdRation_coe.js

@@ -19,7 +19,7 @@ const coeSchema = new Schema({
 
 const coeListSchema = new Schema({
     libID: Number,                      // 所属定额定ID
-    ID: Number,                         // 系数ID(流水号ID)
+    ID: {type: Number,index: true},                         // 系数ID(流水号ID)
     serialNo: Number,                  //编号
     name: String,                       // 名称
     content: String,                    // 说明

+ 1 - 1
modules/all_models/stdRation_ration.js

@@ -32,7 +32,7 @@ const rationInstSchema = new Schema({
 },{_id: false});
 
 const rationItemSchema = new Schema({
-    ID:Number,
+    ID:{type: Number,index: true},
     code: String,
     name: String,
     unit: String,

+ 2 - 3
modules/all_models/stdRation_section.js

@@ -6,15 +6,14 @@ const mongoose = require('mongoose');
 const Schema = mongoose.Schema;
 const rationChapterTreeSchema = new Schema({//章节树  //生成唯一id改为sectionID  改成string
     rationRepId: Number,
-    ID:Number,
+    ID:{type: Number,index: true},
     ParentID:Number,
     NextSiblingID:Number,
     name: String,
     explanation: String,//说明
     ruleText: String,//计算规则,
     jobContentSituation: String,//工作内容适用情况,ALL适用本项全部定额,PARTIAL适用本项部分定额
-    annotationSituation: String,//附注适用情况,ALL适用本项全部定额,PARTIAL适用本项部分定额
-    isDeleted: Boolean
+    annotationSituation: String//附注适用情况,ALL适用本项全部定额,PARTIAL适用本项部分定额
 });
 
 mongoose.model("std_ration_lib_ration_chapter_trees", rationChapterTreeSchema, 'std_ration_lib_ration_chapter_trees');

+ 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,

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

@@ -27,28 +27,28 @@ class SearchDao{
                 ration = await this.getCompleRation(userId,compilationId,code,ID);
             }else {
                 firstLib = parseInt(firstLib);
-                let firstQuery = {rationRepId: firstLib, code: code, $or: [{isDeleted: null}, {isDeleted: false}]};
+                let firstQuery = {rationRepId: firstLib, code: code};
                 if(ID){
-                    firstQuery = {ID: ID, $or: [{isDeleted: null}, {isDeleted: false}]};
+                    firstQuery = {ID: ID};
                 }
                 ration = await this.getStdRation(firstQuery);
             }
             if(ration == null){//选中的定额库或者默认的定额库中没有找到定额,才走常规的流程查找其它定额库
-                let stdQuery = {rationRepId: {$in: otherLibs}, code: code, $or: [{isDeleted: null}, {isDeleted: false}]};
+                let stdQuery = {rationRepId: {$in: otherLibs}, code: code};
                 if(ID){
-                    stdQuery = {ID: ID, $or: [{isDeleted: null}, {isDeleted: false}]};
+                    stdQuery = {ID: ID};
                 }
                 ration = await this.getStdRation(stdQuery);
                 if(ration == null) ration = await this.getCompleRation(userId,compilationId,code,ID);
             }
             if(isDef(ration)){
                 if (ration.type === 'std') {
-                    let stdChapter = await stdSectionTreeModel.findOne({rationRepId: ration.rationRepId, ID: ration.sectionId, $or: [{isDeleted: null}, {isDeleted: false}]});
+                    let stdChapter = await stdSectionTreeModel.findOne({ID: ration.sectionId});
                     if(isDef(stdChapter)){
                         ration.chapter = stdChapter._doc;
                     }
                 } else {
-                    let compleChapter = await compleRationSectionTreeModel.findOne({ID: ration.sectionId, $or: [{isDeleted: null}, {isDeleted: false}]});
+                    let compleChapter = await compleRationSectionTreeModel.findOne({ID: ration.sectionId});
                     if(isDef(compleChapter)){
                         ration.chapter = compleChapter._doc;
                     }

+ 493 - 78
modules/main/facade/ration_facade.js

@@ -17,6 +17,7 @@ module.exports = {
 
 let mongoose = require('mongoose');
 import SearchDao from '../../complementary_ration_lib/models/searchModel';
+import GLJListModel from "../../glj/models/glj_list_model";
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
 let ration_glj_facade = require("../../ration_glj/facade/ration_glj_facade");
 let glj_calculate_facade = require("../../ration_glj/facade/glj_calculate_facade");
@@ -37,6 +38,13 @@ let complementaryRationModel = mongoose.model('complementary_ration_items');
 
 let coeMolde = mongoose.model('std_ration_lib_coe_list');
 let compleCoeModel = mongoose.model('complementary_ration_coe_list');
+let projectGLJModel = mongoose.model("glj_list");
+let mixRatioModel = mongoose.model("mix_ratio");
+let complementaryGljLibModel = mongoose.model('complementary_glj_lib');
+let counterModel =  mongoose.model('counter');
+let unitPriceModel = mongoose.model('unit_price');
+let chongqingOverWrite = require("../../../web/over_write/js/chongqing_2018.js");
+
 
 let _= require('lodash');
 const projectDao = require('../../pm/models/project_model').project;
@@ -164,8 +172,8 @@ async function insertNewRation(newData,defaultLibID,std,calQuantity) {//插入
     }
     let addRationGLJTime = +new Date();
     console.log("计算消耗量时间-------------------------------"+(addRationGLJTime - startTime));
-    let newRation = await ration_model.model.create(newData);
-    return newRation;
+    await ration_model.model.insertMany(newData);
+    return newData;
     /*ration_model.model.create(newData);
     return newData;*/
 }
@@ -313,34 +321,47 @@ async function addRationTemplate(std,newRation) {
 async function addRationCoe(std,newRation,compilation) {
     let ration_coe_list = [];
     let seq = 0;
+    let stdCoeIDs = [];//与comCoeIDs两者不共存
+    let comCoeIDs = [];
+    let coeMap={};
     if(std.hasOwnProperty('rationCoeList')&&std.rationCoeList.length>0){//添加标准库的工料机
         for(let sub of std.rationCoeList){
-            let libCoe;
-            if (std.type === 'std') {
-                libCoe = await coeMolde.findOne({'libID':std.rationRepId,'ID':sub.ID,"$or": [{"isDeleted": null}, {"isDeleted": false}]});//std.rationRepId;
-            } else {
-                libCoe = await compleCoeModel.findOne({ID: sub.ID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]});
-            }
-            if(libCoe){
-                let newCoe = {};
-                newCoe.ID = uuidV1();
-                newCoe.coeID = sub.ID;
-                newCoe.seq = seq;
-                newCoe.name = libCoe.name;
-                newCoe.content = libCoe.content;
-                newCoe.original_code = libCoe.original_code;
-                newCoe.option_codes = libCoe.option_codes;
-                newCoe.option_list = libCoe.option_list;
-                newCoe.isAdjust=0;
-                newCoe.coes = libCoe.coes;
-                newCoe.rationID = newRation.ID;
-                newCoe.projectID = newRation.projectID;
-                seq++;
-                ration_coe_list.push(newCoe);
-            }
+          std.type === 'std'?stdCoeIDs.push(sub.ID):comCoeIDs.push(sub.ID);  
+        }
+        let libCoeList = [];
+        let seqLibIDs = [];
+        if (std.type === 'std'){
+          libCoeList = await coeMolde.find({'ID':{'$in':stdCoeIDs}}).lean();
+          seqLibIDs = stdCoeIDs;
+        }else{
+          libCoeList = await compleCoeModel.find({'ID':{'$in':comCoeIDs}}).lean();
+          seqLibIDs = comCoeIDs;
+        }
+        for(let lib of libCoeList){
+          coeMap[lib.ID] = lib;
+        }
+        for(let ID of seqLibIDs){
+          let libCoe = coeMap[ID];
+          if(libCoe){
+            let newCoe = {};
+            newCoe.ID = uuidV1();
+            newCoe.coeID = ID;
+            newCoe.seq = seq;
+            newCoe.name = libCoe.name;
+            newCoe.content = libCoe.content;
+            newCoe.original_code = libCoe.original_code;
+            newCoe.option_codes = libCoe.option_codes;
+            newCoe.option_list = libCoe.option_list;
+            newCoe.isAdjust=0;
+            newCoe.coes = libCoe.coes;
+            newCoe.rationID = newRation.ID;
+            newCoe.projectID = newRation.projectID;
+            seq++;
+            ration_coe_list.push(newCoe); 
+          }
         }
     }
-    let lastCoe = await getCustomerCoe(newRation.projectID,newRation.ID,seq,compilation);
+    let lastCoe = await getCustomerCoe(newRation.projectID,newRation.ID,seq,compilation);//这个地方加载overWrite需要一些时间
     ration_coe_list.push(lastCoe);
     await ration_coe.insertMany(ration_coe_list);
     return ration_coe_list;
@@ -376,9 +397,13 @@ async function getCustomerCoe(projectID,rationID,seq,compilation){//取自定义
     try {
     //查看编办中有没有重写路径
      if(compilation.overWriteUrl && compilation.overWriteUrl!=""){
-         let overWrite = require("../../.."+compilation.overWriteUrl);
-         if(overWrite.getCusCoeContent) lastCoe.content = overWrite.getCusCoeContent();
-         if(overWrite.getCustomerCoeData) lastCoe.coes = overWrite.getCustomerCoeData();
+        if(compilation.overWriteUrl.indexOf("chongqing_2018")!= -1){
+          console.log("重庆overwrite");
+          let overWrite = chongqingOverWrite
+          if(overWrite.getCusCoeContent) lastCoe.content = overWrite.getCusCoeContent();
+          if(overWrite.getCustomerCoeData) lastCoe.coes = overWrite.getCustomerCoeData();
+        }
+         
      }
      return lastCoe
    }catch (err){
@@ -400,6 +425,9 @@ async function addRationGLJ(std,newRation,compilation) {
     let newRationGLJList = [];
     let rationGLJShowList = [];
     let projectGLJList = [];
+    let gljKeyMap = {};
+    let mixRatioMap={};
+    let gljCodes=[];
     let unitPriceFileId = 0;
     let property = await projectDao.getProjectProperty(newRation.projectID);
     if(property){
@@ -425,56 +453,66 @@ async function addRationGLJ(std,newRation,compilation) {
         let stdGLJMapTime = +new Date();
         console.log("找到工料机映射表时间-------------------------------"+(stdGLJMapTime - first));
         for(let sub of std.rationGljList){
-            let newGLJ = {};
-            newGLJ.ID = uuidV1();
-            newGLJ.projectID = newRation.projectID;
-            newGLJ.GLJID = sub.gljId;
-            newGLJ.rationID = newRation.ID;
-            newGLJ.billsItemID = newRation.billsItemID;
-            newGLJ.rationItemQuantity = sub.consumeAmt;
-            newGLJ.quantity = sub.consumeAmt;
-            newGLJ.glj_repository_id = std.rationRepId;
-            let std_glj = null;
-            if(sub.type == 'complementary'){//有可能来自标准工料机库或补充工料机库
-                std_glj = cptGLJMap[sub.gljId];
-                newGLJ.from = 'cpt';
-            }else {
-                std_glj = stdGLJMap[sub.gljId];
-                newGLJ.from = 'std';
-            }
-            //多单价情况处理
-            if(ext && ext.priceField && std_glj && std_glj.priceProperty){
-                std_glj.basePrice =  std_glj.priceProperty[ext.priceField];
-            }
-            if(std_glj){
-                newGLJ.name = std_glj.name;
-                newGLJ.code = std_glj.code;
-                newGLJ.original_code = std_glj.code;
-                newGLJ.unit = std_glj.unit;
-                newGLJ.specs = std_glj.specs;
-                newGLJ.model = std_glj.model;
-                newGLJ.basePrice = std_glj.basePrice;
-                newGLJ.marketPrice = std_glj.basePrice;
-                newGLJ.taxRate= std_glj.taxRate;
-                newGLJ.shortName = std_glj.shortName;
-                newGLJ.type = std_glj.gljType;
-                newGLJ.repositoryId = std_glj.repositoryId;
-                newGLJ.adjCoe = std_glj.adjCoe;
-                newGLJ.materialType = std_glj.materialType;
-                newGLJ.materialCoe = std_glj.materialCoe;
-                newGLJ.materialIndexType = std_glj.materialIndexType;
-                newGLJ.materialIndexUnit = std_glj.materialIndexUnit;
-                newGLJ.materialIndexCoe = std_glj.materialIndexCoe;
-                newGLJ.createType = 'normal';
-                let [info,projectGLJ] =  await ration_glj_facade.getInfoFromProjectGLJ(newGLJ,unitPriceFileId,ext);
-                newGLJ = ration_glj_facade.createNewRecord(info);
-                newRationGLJList.push(newGLJ);
-                rationGLJShowList.push(info);
-                projectGLJList.push(projectGLJ)
-            }
+          let newGLJ = {};
+          newGLJ.ID = uuidV1();
+          newGLJ.projectID = newRation.projectID;
+          newGLJ.GLJID = sub.gljId;
+          newGLJ.rationID = newRation.ID;
+          newGLJ.billsItemID = newRation.billsItemID;
+          newGLJ.rationItemQuantity = sub.consumeAmt;
+          newGLJ.quantity = sub.consumeAmt;
+          newGLJ.glj_repository_id = std.rationRepId;
+          let std_glj = null;
+          if(sub.type == 'complementary'){//有可能来自标准工料机库或补充工料机库
+              std_glj = cptGLJMap[sub.gljId];
+              newGLJ.from = 'cpt';
+          }else {
+              std_glj = stdGLJMap[sub.gljId];
+              newGLJ.from = 'std';
+          }
+          //多单价情况处理
+          if(ext && ext.priceField && std_glj && std_glj.priceProperty){
+              std_glj.basePrice =  std_glj.priceProperty[ext.priceField];
+          }
+          if(std_glj){
+            newGLJ.name = std_glj.name;
+            newGLJ.code = std_glj.code;
+            newGLJ.original_code = std_glj.code;
+            newGLJ.unit = std_glj.unit;
+            newGLJ.specs = std_glj.specs;
+            newGLJ.model = std_glj.model;
+            newGLJ.basePrice = std_glj.basePrice;
+            newGLJ.marketPrice = std_glj.basePrice;
+            newGLJ.taxRate= std_glj.taxRate;
+            newGLJ.shortName = std_glj.shortName;
+            newGLJ.type = std_glj.gljType;
+            newGLJ.repositoryId = std_glj.repositoryId;
+            newGLJ.adjCoe = std_glj.adjCoe;
+            newGLJ.materialType = std_glj.materialType;
+            newGLJ.materialCoe = std_glj.materialCoe;
+            newGLJ.materialIndexType = std_glj.materialIndexType;
+            newGLJ.materialIndexUnit = std_glj.materialIndexUnit;
+            newGLJ.materialIndexCoe = std_glj.materialIndexCoe;
+            newGLJ.createType = 'normal';
+
+            let tindex = getIndex(newGLJ);
+            if(std_glj.component && std_glj.component.length > 0) mixRatioMap[tindex] = std_glj.component;
+            let tdata = ration_glj_facade.getGLJSearchInfo(newGLJ);
+            gljKeyMap[tindex] = tdata;
+            gljCodes.push(tdata.code);
+            newRationGLJList.push(newGLJ);
+
+              // let [info,projectGLJ] =  await ration_glj_facade.getInfoFromProjectGLJ(newGLJ,unitPriceFileId,ext);
+              // newGLJ = ration_glj_facade.createNewRecord(info);
+              // newRationGLJList.push(newGLJ);
+              // rationGLJShowList.push(info);
+              // projectGLJList.push(projectGLJ)
+          }
             //let InfoFromProjectGLJ = +new Date();
             //console.log("找到项目工料机时间-------------------------------"+(InfoFromProjectGLJ - std_gljTime));
         }
+        [newRationGLJList, projectGLJList] =  await getProjectGLJinfo(newRation.projectID,newRationGLJList,gljKeyMap,gljCodes,mixRatioMap,unitPriceFileId,ext);
+
     }
     let before = +new Date();
     console.log("总查询时间为-------------------------------"+(before-first));
@@ -484,9 +522,374 @@ async function addRationGLJ(std,newRation,compilation) {
     let after = +new Date();
     console.log("实际插入时间为-------------------------------"+(after-before));
     console.log("总操作时间为-------------------------------"+(after-first));
-    return [rationGLJShowList,projectGLJList]
+    return [newRationGLJList,projectGLJList]
+}
+
+
+async function getProjectGLJinfo(projectID,t_newRationGLJList,gljKeyMap,gljCodes,mixRatioMap,unitPriceFileId,ext){//批量插入或查找项目工料机信息
+  //先根据工料机编号在项目工料机中查找工料机是否存在
+  let projectGLJMap={};
+  let projectGLJList = [];
+  let newProjectGLJList=[];//工料机ID要重新去取
+  let connectKeyList = [];
+  let newRationGLJList = [];
+
+  let gljListModel = new GLJListModel();
+  let t_projectGLJList = await projectGLJModel.find({'project_id':projectID,'code':{'$in':gljCodes}}).lean();
+  for(let pg of t_projectGLJList){
+     let pindex = getIndex(pg);  
+     projectGLJMap[pindex] = pg;
+  }
+  for(let key in gljKeyMap){
+    if(!projectGLJMap[key]){//如果项目工料机不存在,则添加
+      newProjectGLJList.push(gljKeyMap[key]);
+      projectGLJMap[key] = gljKeyMap[key];
+    }
+    //查看组成物
+    if(gljListModel.ownCompositionTypes.indexOf(gljKeyMap[key].type)!=-1){//有组成物的类型
+      connectKeyList.push(key);
+    }
+  }
+
+
+  let [existMixRatioMap,mixRatioInsertData,missCodeList] = await getMixRatioInfo(projectID,projectGLJMap,newProjectGLJList,mixRatioMap,connectKeyList,unitPriceFileId,ext);
+  if(missCodeList.length > 0) gljCodes = gljCodes.concat(missCodeList);
+ 
+ 
+  let [unitPriceMap,newUnitPriceList] = await getUnitPriceData(newProjectGLJList,gljCodes,unitPriceFileId);
+  if(newUnitPriceList.length > 0) await unitPriceModel.insertMany(newUnitPriceList);
+
+
+  if(mixRatioInsertData.length > 0) await mixRatioModel.insertMany(mixRatioInsertData);
+
+  //插入项目工料机
+  if(newProjectGLJList.length > 0){
+    await setIDfromCounter("glj_list",newProjectGLJList);
+    await projectGLJModel.insertMany(newProjectGLJList);
+  }
+
+
+  //组装数据
+  for(let ration_glj of t_newRationGLJList){
+    let rkey = getIndex(ration_glj);
+    let pglj = projectGLJMap[rkey];
+    let subList = [];
+    setUnitPrice(pglj,unitPriceMap);
+    if(existMixRatioMap[rkey]){//如果有组成物
+      for(let m of existMixRatioMap[rkey]){
+         let mpglj = projectGLJMap[getIndex(m)]
+         if(mpglj){
+          let cglj = _.clone(mpglj); 
+          setUnitPrice(cglj,unitPriceMap);
+          cglj.ratio_data = m;
+          subList.push(cglj);
+         }else{
+            throw  `组成物${m.name}对应的项目工料机没有找到`;
+         }
+      }
+      pglj.subList =subList; 
+    }
+    ration_glj.projectGLJID = pglj.id;
+    newRationGLJList.push(ration_glj_facade.createNewRecord(ration_glj));
+    projectGLJList.push(pglj);
+  }
+
+
+
+  return [newRationGLJList, projectGLJList];
+
+
+
+
+  function setUnitPrice(p,unitPriceMap){
+    p.unit_price = unitPriceMap[getIndex(p)];
+  }
+
+}
+
+
+
+async function getUnitPriceData(newProjectGLJList,gljCodes,unitPriceFileId){
+  let unitPriceMap = {};
+  let newUnitPriceList = [];
+  let unitPriceList = await unitPriceModel.find({unit_price_file_id: unitPriceFileId,'code':{'$in':gljCodes}}).lean();
+  for(let u of unitPriceList){
+    unitPriceMap[getIndex(u)]=u;
+  }
+
+  for(let np of newProjectGLJList){
+    let pkey = getIndex(np);
+    if(unitPriceMap[pkey]) continue;
+
+    let insertData = {
+      code: np.code,
+      base_price: np.base_price,
+      market_price: np.market_price,
+      unit_price_file_id: unitPriceFileId,
+      name: np.name,
+      specs:np.specs?np.specs:'',
+      original_code:np.original_code,
+      unit:np.unit?np.unit:'',
+      type: np.type,
+      short_name: np.shortName !== undefined ? np.shortName : '',
+      glj_id: np.glj_id,
+      is_add:0,
+      grossWeightCoe:np.grossWeightCoe,
+      purchaseStorageRate:np.purchaseStorageRate,
+      offSiteTransportLossRate:np.offSiteTransportLossRate,
+      handlingLossRate:np.handlingLossRate
+    };
+    if(np.from=='cpt') insertData.is_add=1;//如果是来自补充工料机,则都添加新增标记
+    if(insertData.code != insertData.original_code) insertData.is_add=1;//添加的时候如果是复制整块来的,可能在源项目中是新增的工料机,这里也要添上(暂时可能还用不到)
+    newUnitPriceList.push(insertData);
+    unitPriceMap[pkey] = insertData;
+  }
+
+
+  if(newUnitPriceList.length > 0) await setIDfromCounter("unit_price",newUnitPriceList);
+
+  return [unitPriceMap,newUnitPriceList];
+
+
 }
 
+
+async function getMixRatioInfo(projectID,projectGLJMap,newProjectGLJList,mixRatioMap,connectKeyList,unitPriceFileId,ext){//取组成物信息,得到缺少的组成物情况
+  let missCodeList = []; //所有组成物信息的编码,用来统一查询对应的项目工料机是否存在
+  let existMixRatioMap ={};
+  let codeMap={};//用来去重
+  let mixRatioInsertData = [];
+
+
+  // 1. 先检查现在的组成物表中,是否有相关信息 - 生成映射记录
+  if(connectKeyList.length > 0){//有组成物的话从数据库中取出组成物信息
+    let mixRatioList = await mixRatioModel.find({'unit_price_file_id': unitPriceFileId,'connect_key': {'$in':connectKeyList}}).lean();
+    for(let m of mixRatioList){
+        //组成物信息分组,查看哪些是已经存在的
+       existMixRatioMap[m.connect_key]?existMixRatioMap[m.connect_key].push(m):existMixRatioMap[m.connect_key]=[m];
+       //查看组成物对应的项目工料机是否存在,如果不存在,要插入项目工料机
+       let mkey = getIndex(m);
+       if(!projectGLJMap[mkey] && !codeMap[m.code]){//如果之前查出来的项目工料机中不包含组成物的信息,要加到missCode里面再查找一次项目工料机看是否存在
+          missCodeList.push(m.code);
+          codeMap[m.code] = true;
+       } 
+    }
+
+    // 2 将第一步得到的映射表 与在标准库查询父工料机得到的映射表对比,得出哪些组物成还需要添加,获得库ID
+    let stdIDs = []; 
+    let comIDs = [];
+    let missMixRatioGroup = [];
+    for(let ck of connectKeyList){//查看项目中组成物信息是否已经存在,如果不存在,则用插定额时获取的组成物信息从数据库中获取
+       if(!existMixRatioMap[ck] && mixRatioMap[ck] && mixRatioMap[ck].length > 0){//组成物信息不存在
+         let pglj = projectGLJMap[ck];//取出父数据 
+         let from =  pglj.from === undefined|| pglj.from ===null || pglj.from === ""?'std' : pglj.from;
+         for(let c of mixRatioMap[ck]){
+            if(from == "std"){//标准的工料机只来自标准的
+                stdIDs.push(c.ID); 
+            }else{
+              c.isStd?stdIDs.push(c.ID):comIDs.push(c.ID);  
+            } 
+         } 
+         missMixRatioGroup.push({'connect_key':ck,'list':mixRatioMap[ck],'from':from});
+       }
+    }
+
+    //3.统一查询所有组成物在标准库中的详细信息
+    let stdMixMap = {};
+    //整理需插入的组成物列表的数据
+    //来自标准工料机
+    if(stdIDs.length > 0){
+      stdIDs = _.uniq(stdIDs);//去重
+      let stdMixList =  await std_glj_lib_gljList_model.find({'ID':{'$in':stdIDs}}).lean();
+      for(let sm of stdMixList){
+        stdMixMap[sm.ID] = sm;
+        let skey = getIndex(sm,['code','name','specs','unit','gljType']);
+        if(!projectGLJMap[skey] && !codeMap[sm.code]){
+          missCodeList.push(sm.code);
+          codeMap[sm.code] = true;
+        }
+      }
+    }
+    //来自组成物工料机
+    let comMixMap = {};
+    if(comIDs.length > 0){
+      comIDs = _.uniq(comIDs);//去重
+      let comMixList = await complementaryGljLibModel.find({'ID':{'$in':comIDs}}).lean();
+      for(let cm of comMixList){
+        comMixMap[cm.ID] = cm;
+        let ckey = getIndex(cm,['code','name','specs','unit','gljType']);
+        if(!projectGLJMap[ckey] && codeMap[cm.code]){
+          missCodeList.push(cm.code);
+          codeMap[cm.code] = true;
+        } 
+      }
+    }
+  
+
+    //4.生成需要插入组成物表的数据
+    for(let mg of missMixRatioGroup){//整理需要插入组成物列表的数据
+        for(let tc of mg.list){
+          let consumpiton = tc.consumeAmt;
+          //只有标准的工料机的组成物才会有多单价、多组成物消耗量的情况
+          if(mg.from == 'std' && ext && ext.quantityField &&( tc.consumeAmtProperty[ext.quantityField]!= undefined && tc.consumeAmtProperty[ext.quantityField]!=null)){
+              consumpiton = tc.consumeAmtProperty[ext.quantityField];
+          }
+          let mfrom = mg.from == 'std' || tc.isStd?'std':'cpt'; 
+          let tmp = mfrom == 'std'?stdMixMap[tc.ID]:comMixMap[tc.ID];//取出之前库中查到的工料机
+          let mixRatioData = {
+              consumption: consumpiton,
+              glj_id: tmp.ID,
+              unit_price_file_id: unitPriceFileId,
+              connect_key: mg.connect_key,
+              type: tmp.gljType,
+              code: tmp.code,
+              specs:tmp.specs?tmp.specs:"",
+              name:tmp.name,
+              unit:tmp.unit?tmp.unit:'',
+              from:mfrom
+            };
+          mixRatioInsertData.push(mixRatioData);
+        }
+    }
+
+
+    if(mixRatioInsertData.length > 0) await setIDfromCounter("mix_ratio",mixRatioInsertData,existMixRatioMap,'connect_key');
+    //await mixRatioModel.insertMany(mixRatioInsertData);  因为没有事务添加组成物数据要放在添加单价文件数据之后
+     
+
+    //5.查询组成物对应的项目工料机是否存在,如果不存在,生成项目工料机信息
+    let projectGLJList = await projectGLJModel.find({'project_id':projectID,'code':{'$in':missCodeList}}).lean();
+    for(let pg of projectGLJList){
+      let pindex = getIndex(pg);  
+      projectGLJMap[pindex] = pg;
+    }
+
+    let lessMix = [];//组成物表存在,项目工料机不存在的数据
+    let lessMixMap = {};//防止重复添加
+    for(let connect_key in existMixRatioMap){
+      let mixRatios = existMixRatioMap[connect_key]; 
+      for(let m of mixRatios){
+        let mk = getIndex(m);
+        if(!projectGLJMap[mk] && !lessMixMap[mk]){//如果组成物对应的项目工料机不存在
+          let nglj = null;
+          if(m.from == 'std'){//这里有值,说明是刚添加到组成物文件中的数据   
+            nglj = stdMixMap[m.glj_id];
+          }else if(m.from == 'cpt'){//这里有值,说明是刚添加到组成物文件中的数据   
+            nglj = comMixMap[m.glj_id];
+          }    
+          if(nglj){
+            nglj.from = m.from;
+            let np = getProjectGLJNewData(nglj,projectID,ext);
+            newProjectGLJList.push(np);
+            projectGLJMap[mk] = np;
+          }else{//这里没找到,说明是组成物文件里有,但是项目工料机没有的数据
+            lessMix.push(m);
+          }
+          lessMixMap[mk] = true;//只要处理过一次,就不用再重新处理了,机械组成物,比如柴油这些,会出现多次
+        }
+      }
+    }
+
+
+   //6. 组成物文件里有,但是项目工料机没有的数据(共用单价文件等情况产生)    
+    let lessIDList=[];
+    let uniqMap ={};//去重
+    let lessStdMix = [];//防止组成物中改了名称等,但是通过glj_id取出来的是还没改前的原始数据
+    if(lessMix.length > 0){
+      for(let lm of lessMix){
+        let parentglj = projectGLJMap[lm.connect_key];
+        if(!parentglj) throw `含有组成物工料机${lm.connect_key},没有找到,添加定额失败`;
+        if((parentglj.from == "std" || lm.from == "std") && lm.code!="80CCS"){//车船税特殊处理
+          if(!uniqMap[lm.glj_id]){
+            lessIDList.push(lm.glj_id);
+            uniqMap[lm.glj_id] = lm;
+          }
+          lessStdMix.push(lm);
+        }else {//来自组成物的直接设置    
+          lm.from = 'cpt';
+          lm.gljType = lm.type;
+          let t_mg = getProjectGLJNewData(lm,projectID);
+          newProjectGLJList.push(t_mg);
+          projectGLJMap[getIndex(lm)] = t_mg;
+        }
+      }
+    }
+
+    if(lessIDList.length > 0){
+      let less_stds =  await std_glj_lib_gljList_model.find({'ID':{'$in':lessIDList}}).lean();
+      let less_stds_map = {};
+      for(let les of  less_stds){
+        less_stds_map[les.ID] = les;
+      }
+      for(let t_l_m of lessStdMix){
+        let t_nglj = less_stds_map[t_l_m.glj_id];
+        t_nglj.from = 'std';
+        //防止组成物中改了名称等,但是通过glj_id取出来的是还没改前的原始数据
+        t_nglj.name = t_l_m.name;
+        t_nglj.code = t_l_m.code;
+        t_nglj.gljType = t_l_m.type;
+        t_nglj.specs = t_l_m.specs;
+        t_nglj.unit = t_l_m.unit;
+        let t_np = getProjectGLJNewData(t_nglj,projectID,ext);
+        newProjectGLJList.push(t_np);
+        projectGLJMap[getIndex(t_l_m)] = t_np;
+      }
+    }
+
+  }
+  return [existMixRatioMap,mixRatioInsertData,missCodeList]
+
+}
+
+
+function getProjectGLJNewData(tmp,projectId,ext){
+  let gljData = {
+      glj_id: tmp.ID,
+      repositoryId:tmp.repositoryId,
+      project_id: projectId,
+      code: tmp.code,
+      name: tmp.name,
+      specs: tmp.specs?tmp.specs:'',
+      unit: tmp.unit === undefined ? '' : tmp.unit,
+      type: tmp.gljType,
+      adjCoe:tmp.adjCoe,
+      original_code:tmp.code,
+      materialType: tmp.materialType,   //三材类别
+      materialCoe: tmp.materialCoe,
+      base_price: tmp.basePrice,
+      market_price: tmp.basePrice,
+      from:tmp.from?tmp.from:"std"
+  };
+  if(gljData.from == 'std' && ext && ext.priceField &&( tmp.priceProperty[ext.priceField]!= undefined && tmp.priceProperty[ext.priceField]!=null)){
+    basePrice = scMathUtil.roundTo(tmp.priceProperty[ext.priceField],-6);
+    gljData.base_price = basePrice;
+    gljData.market_price = basePrice;
+  }
+  return gljData;
+}
+
+async function setIDfromCounter(name,list,map,keyfield){//map,keyfield
+
+  let update = {$inc: {sequence_value: list.length}};
+  let condition = {_id: name};
+  let options = {new: true};
+
+  // 先查找更新
+  let counter = await counterModel.findOneAndUpdate(condition, update, options);
+  let firstID = counter.sequence_value - (list.length - 1);
+  for(let a of list){
+      a.id = firstID;
+      firstID+=1
+      if(map && keyfield){
+        let key = a[keyfield];
+        map[key]?map[key].push(a):map[key]=[a]
+      }
+  }
+
+}
+
+
+
 async function deleRationSubRecode(projectID,rationID,cleanzmhs=false) {//删除挂在定额下的数据,如工程量明细,定额工料机等
     let delete_query={projectID: projectID, rationID: rationID};
     //删除工程量明细
@@ -680,4 +1083,16 @@ function FilterNumberFromUnit (unit) {
     } else {
         return 1;
     }
-};
+};
+
+function getIndex(obj,tpops){
+  let pops = tpops?tpops:['code','name','specs','unit','type'];
+  let t_index = '';
+  let k_arr=[];
+  for(let p of pops){
+      let tmpK = (obj[p]==undefined||obj[p]==null||obj[p]=='')?'null':obj[p];
+      k_arr.push(tmpK);
+  }
+  t_index=k_arr.join("|-|");
+  return t_index;
+}

+ 73 - 34
modules/pm/facade/pm_facade.js

@@ -436,6 +436,7 @@ async function handleCopyProject(key, userID, compilationID, data, newProjectID)
 async function copyProject(userID, compilationID,data,newProjectID = null, delayProjectTask = false) {
     let projectMap = data.projectMap;
     let originalID = projectMap['copy'].document.ID;
+    
     if (!newProjectID) {
         newProjectID = await getCounterID("projects");
     }
@@ -493,6 +494,7 @@ async function copyProject(userID, compilationID,data,newProjectID = null, delay
     ];
     let [billMap,rationMap,projectGLJMap] = await Promise.all(IDtasks);
     //所有复制任务异步处理,提升效率  复制清单,定额,4个文件,项目工料机, 定额工料机,人工系数,工程量明细,定额安装增加费,安装增加费
+
     let copyTasks = [
         copyProjectSetting(originalID,newProjectID),
         copyBills(newProjectID,billMap),
@@ -534,12 +536,12 @@ async function copyProject(userID, compilationID,data,newProjectID = null, delay
 async function createIDsAndReturn(originalID,model) {
     let uuidMaping = {};//做ID映射
     let datas = [];
-    let result = await model.find({"projectID": originalID}, '-_id');
+    let result = await model.find({"projectID": originalID}, '-_id').lean();
     uuidMaping['-1'] = -1;
     //建立uuid-ID映射
     for(let d of result){
         uuidMaping[d.ID] = uuidV1();
-        datas.push(d._doc);
+        datas.push(d);
     }
     return{uuidMaping:uuidMaping,datas:datas};
 }
@@ -547,16 +549,16 @@ async function createIDsAndReturn(originalID,model) {
 async function getProjectGLJIDAndReturn(originalID,newProjectID) {
     let IDMap = {};
     let datas = [];
-    let result = await gljListModel.find({project_id:originalID}, '-_id');
+    let result = await gljListModel.find({project_id:originalID}, '-_id').lean();
     let gljCount = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.glj_list, result.length);
     for(let i = 0; i < result.length; i++){
         let d = result[i];
         let newID = gljCount.sequence_value - (result.length - 1) + i;
         //let newID = await getCounterID("glj_list");
         IDMap[d.id] = newID;
-        d._doc.project_id = newProjectID;
-        d._doc.id = newID;
-        datas.push(d._doc);
+        d.project_id = newProjectID;
+        d.id = newID;
+        datas.push(d);
     }
     return{IDMap:IDMap,datas:datas};
 }
@@ -689,12 +691,15 @@ async function copyUnitPriceFile(newProjectID,rootProjectID,userID,originaluUnit
     }
 
     async function copySubList(srcFID,newFID,model) {
-        let mList = await model.find({unit_price_file_id: srcFID}, '-_id');
+        let mList = await model.find({unit_price_file_id: srcFID}, '-_id').lean();
         let rList = [];
+        let IDcounter = await counter.counterDAO.getIDAfterCountSync(model.modelName, mList.length);
+        let firstID = IDcounter.sequence_value - (mList.length - 1);
         for(let m of mList){
-            m._doc.unit_price_file_id = newFID;
-            m._doc.id = await getCounterID(model.modelName);
-            rList.push(m._doc);
+            m.unit_price_file_id = newFID;
+            m.id = firstID;    
+            firstID+=1
+            rList.push(m);
         }
         await insertMany(rList,model)
     }
@@ -716,26 +721,17 @@ async function copyInstallFee(originalPID,newProjectID) {
 }
 
 async function copyRationSubList(originalPID,newProjectID,billIDMap,rationIDMap,projectGLJIDMap,model) {// 定额工料机,附注条件,工程量明细,定额安装增加费,模板子目
-    let subList = await model.find({projectID:originalPID}, '-_id');
+    let first = +new Date();
+    let subList = await model.find({projectID:originalPID}, '-_id').lean();
     let newList =[];
     for(let s of subList){
-        s._doc = getCopyRationSubData(s._doc,newProjectID,billIDMap,rationIDMap,projectGLJIDMap);
-  /*      s._doc.ID = uuidV1();
-        s._doc.projectID = newProjectID;
-        s._doc.rationID&&rationIDMap[s._doc.rationID]?s._doc.rationID = rationIDMap[s._doc.rationID]:'';
-        s._doc.billID&&billIDMap[s._doc.billID]?s._doc.billID = billIDMap[s._doc.billID]:'';
-        s._doc.billsItemID&&billIDMap[s._doc.billsItemID]?s._doc.billsItemID = billIDMap[s._doc.billsItemID]:'';
-        s._doc.projectGLJID&&projectGLJIDMap[s._doc.projectGLJID]?s._doc.projectGLJID = projectGLJIDMap[s._doc.projectGLJID]:'';
-        if(s._doc.templateList && s._doc.templateList.length > 0 ){
-            for(let t of s._doc.templateList){
-                if(t.billID && billIDMap[t.billID]) t.billID =  billIDMap[t.billID];
-                if(t.fxID && billIDMap[t.fxID]) t.fxID =  billIDMap[t.fxID];
-            }
-        }*/
-        newList.push(s._doc);
+        s = getCopyRationSubData(s,newProjectID,billIDMap,rationIDMap,projectGLJIDMap);
+        newList.push(s);
 
     }
-    await insertMany(newList,model);
+    if(newList.length > 0) await insertMany(newList,model);
+    let last = +new Date();
+    console.log(model.modelName+"-------"+newList.length+"--copyRationSubList - insert时间为-------------------------------"+(last-first));
 }
 
 
@@ -926,10 +922,10 @@ async function getCounterID(collectionName){
 }
 
 async function insertMany(datas,model) {
-    while (datas.length>1000){//因为mongoose限制了批量插入的条数为1000.所以超出限制后需要分批插入
+    /* while (datas.length>1000){//因为mongoose限制了批量插入的条数为1000.所以超出限制后需要分批插入  2020-05-28 测试后发现没有限制,暂时先保留代码
         let newList = datas.splice(0,1000);//一次插入1000条
         await model.insertMany(newList);
-    }
+    } */
     await model.insertMany(datas);
 
 }
@@ -2407,6 +2403,7 @@ async function importProjects(data,req,updateData) {
     let result = {error:0};
     let stringArr = data.split("|----|");
     let datas = [];
+    let first = +new Date();
     for(let s of stringArr){
         datas.push(JSON.parse(cipher.aesDecrypt(s)));
     }
@@ -2431,13 +2428,48 @@ async function importProjects(data,req,updateData) {
             let [constructionProjectID,projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,updateData,req.session.sessionUser.id);
             result.constructionProjectID = constructionProjectID;
             if(datas.length > 1 ){
+                let newProjectSettings=[],bills=[],rations=[],installationFees=[],projectGLJs=[],rationGLJs=[],rationCoes=[],quantityDetails=[],rationInstallations=[],rationTemplates=[],evaluateList=[],bidList=[],contractorList=[],newCalcProgramsFiles=[],newLabourCoes=[]
                 for(let i = 1;i<datas.length;i++){
-                    await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
+                  let [tnewProjectSetting,tbills,trations,tinstallationFees,tprojectGLJs,trationGLJs,trationCoes,tquantityDetails,trationInstallations,trationTemplates,tevaluateList,tbidList,tcontractorList,tnewCalcProgramsFile,tnewLabourCoe] = await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
+                  if(tnewProjectSetting) newProjectSettings.push(tnewProjectSetting);
+                  if(tbills.length > 0) bills = bills.concat(tbills);
+                  if(trations.length > 0) rations = rations.concat(trations);
+                  if(tinstallationFees.length > 0) installationFees = installationFees.concat(tinstallationFees);
+                  if(tprojectGLJs.length > 0) projectGLJs = projectGLJs.concat(tprojectGLJs);
+                  if(trationGLJs.length > 0) rationGLJs = rationGLJs.concat(trationGLJs);
+                  if(trationCoes.length > 0) rationCoes = rationCoes.concat(trationCoes);
+                  if(tquantityDetails.length > 0) quantityDetails = quantityDetails.concat(tquantityDetails);
+                  if(trationInstallations.length > 0) rationInstallations = rationInstallations.concat(trationInstallations);
+                  if(trationTemplates.length > 0) rationTemplates = rationTemplates.concat(trationTemplates);
+                  if(tevaluateList.length > 0) evaluateList = evaluateList.concat(tevaluateList);
+                  if(tbidList.length > 0) bidList = bidList.concat(tbidList);
+                  if(tcontractorList.length > 0)  contractorList = contractorList.concat(tcontractorList);
+                  if(tnewCalcProgramsFile) newCalcProgramsFiles.push(tnewCalcProgramsFile);
+                  if(tnewLabourCoe) newLabourCoes.push(tnewLabourCoe); 
                 }
+
+                if(newProjectSettings.length > 0) await insertMany(newProjectSettings,projectSettingModel)
+                if(bills.length > 0) await insertMany(bills,billsModel);
+                if(rations.length > 0) await insertMany(rations,rationModel);
+                if(installationFees.length > 0) await insertMany(installationFees,installationFeeModel);
+                if(projectGLJs.length > 0) await insertMany(projectGLJs,gljListModel);
+                if(rationGLJs.length > 0) await insertMany(rationGLJs,rationGLJModel);
+                if(rationCoes.length > 0) await insertMany(rationCoes,rationCoeModel);
+                if(quantityDetails.length > 0) await insertMany(quantityDetails,quantityDetailModel);
+                if(rationInstallations.length > 0) await insertMany(rationInstallations,rationInstallationModel);
+                if(rationTemplates.length > 0) await insertMany(rationTemplates,rationTemplateModel);
+                if(evaluateList.length > 0) await insertMany(evaluateList,evaluateListModel);
+                if(bidList.length > 0) await insertMany(bidList,bidListModel);
+                if(contractorList.length > 0) await insertMany(contractorList,contractorListModel);
+                if(newCalcProgramsFiles.length > 0) await insertMany(newCalcProgramsFiles,calcProgramsModel);
+                if(newLabourCoes.length > 0) await insertMany(newLabourCoes,labourCoesModel); 
+
             }
 
         }
     }
+    let finish = +new Date();
+    console.log("导入操作总时间为-------------------------------"+(finish-first));
     return result;
 }
 
@@ -2526,7 +2558,9 @@ async function handleEachProject(data,projectIDMap,labourCoeFileIDMap,calcProgra
         delete newLabourCoe._id;
     }
 
-    if(newProjectSetting) await projectSettingModel.create(newProjectSetting);
+    return [newProjectSetting,bills,rations,installationFees,projectGLJs,rationGLJs,rationCoes,quantityDetails,rationInstallations,rationTemplates,evaluateList,bidList,contractorList,newCalcProgramsFile,newLabourCoe]
+
+ /*    if(newProjectSetting) await projectSettingModel.create(newProjectSetting);
     if(bills.length > 0) await insertMany(bills,billsModel);
     if(rations.length > 0) await insertMany(rations,rationModel);
     if(installationFees.length > 0) await insertMany(installationFees,installationFeeModel);
@@ -2540,8 +2574,8 @@ async function handleEachProject(data,projectIDMap,labourCoeFileIDMap,calcProgra
     if(bidList.length > 0) await insertMany(bidList,bidListModel);
     if(contractorList.length > 0) await insertMany(contractorList,contractorListModel);
     if(newCalcProgramsFile) await calcProgramsModel.create(newCalcProgramsFile);
-    if(newLabourCoe) await labourCoesModel.create(newLabourCoe);
-
+    if(newLabourCoe) await labourCoesModel.create(newLabourCoe); */
+ 
 
 }
 function setMaterialList(datas,newProjectID,projectGLJIDMap){
@@ -2629,6 +2663,8 @@ async function handleMainProjectDatas(mainData,updateData,userID) {
 
 
 async function importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,userID) {
+    
+  
     if(!mainData.files.unitFiles) return;
     let unitFiles = [],unitPrices =[],mixRatios=[],freights=[],originals=[];
     for(let f of mainData.files.unitFiles){
@@ -2650,11 +2686,14 @@ async function importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,use
     if(unitPrices.length > 0) await insertMany(unitPrices,unitPriceModel);
     if(mixRatios.length > 0) await insertMany(mixRatios,mixRatioModel);
 
-    async function setSubList(oList,nList,fileID,model,UUID=false) {
+    async function setSubList(oList,nList,fileID,model) {
+      let IDcounter = await counter.counterDAO.getIDAfterCountSync(model.modelName, oList.length);
+      let firstID = IDcounter.sequence_value - (oList.length - 1);
         for(let o of oList){
             delete o._id;
             o.unit_price_file_id = fileID;
-            UUID == true?o.ID = uuidV1():o.id = await getCounterID(model.modelName);
+            o.id = firstID;
+            firstID+=1
             nList.push(o)
         }
     }

+ 0 - 1
modules/unit_price_file/facade/unit_price_facade.js

@@ -26,7 +26,6 @@ async function setIDfromCounter(name,list,map,keyfield){//map,keyfield
         map[key]?map[key].push(a):map[key]=[a]
       }
   }
-
 }
 
 function getProjectGLJNewData(tmp,projectId,ext){

+ 2 - 2
public/web/tree_sheet/tree_sheet_controller.js

@@ -202,10 +202,10 @@ var TREE_SHEET_CONTROLLER = {
             }
         };
 
-        controller.prototype.refreshTreeNode = function (nodes, recursive) {
+        controller.prototype.refreshTreeNode = function (nodes, recursive,autoFit) {
             var that = this;
             TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
-                TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, nodes, recursive)
+                TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, nodes, recursive,autoFit)
             })
         };
 

+ 2 - 2
public/web/tree_sheet/tree_sheet_helper.js

@@ -109,7 +109,7 @@ var TREE_SHEET_HELPER = {
             }
         })
     },
-    refreshTreeNodeData: function (setting, sheet, nodes, recursive) {
+    refreshTreeNodeData: function (setting, sheet, nodes, recursive,autoFit=true) {
         nodes.forEach(function (node) {
             let iRow = node.serialNo();
             if(setting.emptyRowHeader){
@@ -206,7 +206,7 @@ var TREE_SHEET_HELPER = {
                     cell.locked(typeof projectReadOnly !== 'undefined' && projectReadOnly ? true : false);
                 }
             });
-            if(setting.setAutoFitRow){
+            if(autoFit==true && setting.setAutoFitRow){
                 setting.setAutoFitRow(sheet,node)//自动行高功能比较费时,400行,启用和不启用相差2秒左右
             }
             if (recursive) {

+ 6 - 6
web/building_saas/complementary_glj_lib/html/tools-gongliaoji.html

@@ -74,7 +74,7 @@
                             <!--<input type="radio" class="glj-radio" name="glj" value="allGljs">所有&nbsp;-->&nbsp;
                             <input type="radio" class="glj-radio" name="glj" value="stdGljs">标准&nbsp;&nbsp;
                             <input type="radio" class="glj-radio" name="glj" value="complementaryGljs">补充&nbsp;&nbsp;
-                            <div  class="modal-auto-height" id="componentTreeDiv" style="overflow: hidden">
+                            <div  class="modal-auto-height" id="componentTreeDiv" style="height: 435px; overflow: hidden">
                                 <!--<div class="print-list">-->
                                 <div style="width: 100%; height: 100%; overflow: auto">
                                     <ul id="componentTree" class="ztree"></ul>
@@ -96,7 +96,7 @@
                                         </div>
                                     </div>
                                 </div>
-                                <div class="modal-auto-height col-12" style="overflow: hidden" id="componentSheet">
+                                <div class="modal-auto-height col-12" style="height: 420px; overflow: hidden" id="componentSheet">
                                 </div>
                             </div>
                         </div>
@@ -258,19 +258,19 @@
         };
         $(document).ready(function(){
             //解决spreadjs sheet初始化没高度宽度
-            $('#modalCon').width($(window).width()*0.5);
+            /* $('#modalCon').width($(window).width()*0.5);
             $('#componentTreeDiv').height($(window).height() - 300);
             $("#componentSheet").height($("#componentTreeDiv").height() - 15);
-            $("#componentSheet").width($('#modalCon').width() * 0.63);
+            $("#componentSheet").width($('#modalCon').width() * 0.63); */
             pageOprObj.initPage($("#GLJListSheet")[0], $('#gljComponentSheet')[0], $("#componentSheet")[0]);
         });
         //组成物弹出窗大小设置
-        $(window).resize(function () {
+        /* $(window).resize(function () {
             $('#modalCon').width($(window).width()*0.5);
             $('#componentTreeDiv').height($(window).height() - 300);
             $("#componentSheet").height($("#componentTreeDiv").height()-15);
             $("#componentSheet").width($('#modalCon').width()* 0.63);
-        });
+        }); */
   	</SCRIPT>
 </body>
 <script type="text/javascript">

+ 5 - 0
web/building_saas/complementary_glj_lib/js/glj.js

@@ -3,6 +3,11 @@
  */
 
 $(document).ready(function () {
+    $('#component').on('shown.bs.modal', function () {
+        if (componentOprObj.workBook) {
+            componentOprObj.workBook.refresh();
+        }
+    });
     let moduleName = 'compleGLj';
     SlideResize.loadHorizonWidth(moduleName, [$('#rightResize'), $('#leftResize')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
         refreshALlWorkBook();

+ 2 - 2
web/building_saas/complementary_ration_lib/html/dinge.html

@@ -523,7 +523,7 @@
                     &nbsp;
                     <input type="radio" class="glj-radio" name="glj" value="stdGljs">标准&nbsp;&nbsp;
                     <input type="radio" class="glj-radio" name="glj" value="complementaryGljs">补充&nbsp;&nbsp;
-                    <div  class="modal-auto-height" id="gljSelTreeDiv" style="overflow: hidden">
+                    <div  class="modal-auto-height" id="gljSelTreeDiv" style="height: 435px; overflow: hidden">
                         <div style="width: 100%; height: 100%; overflow: auto">
                             <ul id="selGljTree" class="ztree"></ul>
                         </div>
@@ -543,7 +543,7 @@
                                 </div>
                             </div>
                         </div>
-                        <div class="modal-auto-height col-12" style="overflow: hidden" id="gljSelSheet">
+                        <div class="modal-auto-height col-12" style="height: 420px; overflow: hidden" id="gljSelSheet">
                         </div>
                     </div>
                 </div>

+ 2 - 2
web/building_saas/complementary_ration_lib/js/init.js

@@ -65,7 +65,7 @@ const initialization = (() => {
             $.bootstrapLoading.end();
         });
         //解决spreadjs sheet初始化没高度宽度
-        $('#modalCon').width($(window).width()*0.5);
+        /* $('#modalCon').width($(window).width()*0.5);
         $('#gljSelTreeDiv').height($(window).height() - 300);
         $("#gljSelSheet").height($("#gljSelTreeDiv").height()-21.6);
         $("#gljSelSheet").width($('#modalCon').width() * 0.63);
@@ -74,6 +74,6 @@ const initialization = (() => {
             $('#gljSelTreeDiv').height($(window).height() - 300);
             $("#gljSelSheet").height($("#gljSelTreeDiv").height()-21.6);
             $("#gljSelSheet").width($('#modalCon').width()* 0.63);
-        });
+        }); */
     });
 })();

+ 2 - 1
web/building_saas/main/js/controllers/project_controller.js

@@ -4,7 +4,7 @@
 
 ProjectController = {
     /* sc: tree_sheet_controller */
-    syncDisplayNewNode: function (sc, newNode) {
+    syncDisplayNewNode: function (sc, newNode,callback) {
         TREE_SHEET_HELPER.massOperationSheet(sc.sheet, function () {
             var sels = sc.sheet.getSelections();
             sc.sheet.addRows(newNode.serialNo(), 1);
@@ -14,6 +14,7 @@ ProjectController = {
             //不显示到中间
             //sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
             cbTools.refreshFormulaNodes();
+            if(callback) callback();
         });
     },
     syncDisplayNewNodes: function (sc, newNodes,withOutSelect=false) {//withOutSelect 不需要自动选中,外面自已处理

+ 6 - 3
web/building_saas/main/js/models/bills.js

@@ -854,10 +854,13 @@ var Bills = {
                 me.tree.m_delete(idTreeNodes);
                 $.bootstrapLoading.end();
                 //重新计算
-                project.installation_fee.calcInstallationFee(function (isChange) {
-                    project.calcProgram.calcAllNodesAndSave();
-                    if(!isChange) {
+                project.installation_fee.calcInstallationFee(function (isChange,nodes) {
+                    if(nodes && nodes.length > 0)parentNodes = parentNodes.concat(nodes);
+                    project.calcProgram.calcNodesAndSave(parentNodes);
+                    if(isChange) {
                         project.projectGLJ.loadData();
+                    }else{
+                      project.projectGLJ.calcQuantity();
                     }
                     gljOprObj.refreshView();
                 });

+ 1 - 1
web/building_saas/main/js/models/calc_base.js

@@ -332,7 +332,7 @@ let cbTools = {
     refreshFormulaNodes: function () {
         try {
             let nodes = this.getFormulaNodes();
-            if (nodes.length > 0) projectObj.mainController.refreshTreeNode(nodes);
+            if (nodes.length > 0) projectObj.mainController.refreshTreeNode(nodes,false,false);
         } catch (err) {
             alert('公式引用行号显示刷新失败:' + err.message);
         }

+ 1 - 1
web/building_saas/main/js/models/calc_program.js

@@ -2101,7 +2101,7 @@ class CalcProgram {
             };
 
             for (let node of treeNodes) { delete node.changed };
-            projectObj.mainController.refreshTreeNode(treeNodes);
+            projectObj.mainController.refreshTreeNode(treeNodes,false,false);
 
             // 批量树结点计算后,计算程序早已物是人非,所以这里要重新计算一下。警告:第二个参数千万不能改成3,否则死循环!
             if (activeSubSheetIsCalcProgram())

+ 4 - 3
web/building_saas/main/js/models/ration.js

@@ -673,9 +673,10 @@ var Ration = {
                 newNode.source = newSource;
                 newNode.sourceType = project.Ration.getSourceType();
                 newNode.data = newSource;
-                ProjectController.syncDisplayNewNode(sheetController, newNode);
-                project.ration_glj.addToMainTree(data.ration_gljs);
-                projectObj.mainController.refreshTreeNode([newNode], false);
+                ProjectController.syncDisplayNewNode(sheetController, newNode,function(){
+                  project.ration_glj.addToMainTree(data.ration_gljs);
+                  projectObj.mainController.refreshTreeNode([newNode], false);
+                });
             }
 
 

+ 0 - 2
web/building_saas/main/js/models/ration_coe.js

@@ -98,8 +98,6 @@ var ration_coe = {
                 criteria.ration_coe_list.push(newCoe);
             }
             criteria.updateType = 'ut_create';
-            console.log('enterrrrrrrrrrrrrrrrrrrrrr');
-            console.log(criteria);
             return criteria;
         };
         ration_coe.prototype.getCustomerCoeData = function () {

+ 47 - 46
web/building_saas/main/js/views/glj_view.js

@@ -544,49 +544,54 @@ var gljOprObj = {
         }
     },
     showDataIfRationSelect: function (node,selectedNodeId) {
-        var isShow = false;
-        if(projectReadOnly && this.setting.view.lockColumns){
-            this.setting.view.lockColumns = null;
-        }
-        if(selectedNodeId){
-            this.selectedNodeId = selectedNodeId;
-        }
-        if (node) {
-            if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
-                return;
-            } else {
-                //恢复底色
-                this.sheet.setStyle(this.sheet.getActiveRowIndex(), -1, this.getSelStyle(false,this.setting.style));
-                this.selectedNodeId = node.getID();
-            }
-            if (node.sourceType == "ration") {
-                if(node.data.type==rationType.gljRation){
-                    if($('#linkGLJ').hasClass('active'))  this.showMixRatio(node);
-                }else {
-                    if($('#linkGLJ').hasClass('active')){
-                        this.showRationGLJData(node);
-                        subObj.showGljSubTabData();
-                       // MaterialController.showReplaceDiv(node);
-                    }
-                    if($('#linkAZZJF').hasClass('active')) installationFeeObj.showRationInstallationData(node);
-                    if($('#linkMBZM').hasClass('active')) mbzm_obj.showMBZMData(node);
-                }
-                isShow = true;
-            }
-            if(node.sourceType == ModuleNames.ration_glj){
-                if($('#linkGLJ').hasClass('active')) this.showMixRatio(node);
-                MaterialController.hideReplaceDiv();
-                isShow = true;
-            }
-            if($('#linkGCLMX').hasClass('active')) this.showQuantityDetailData(node);
+      this.sheet.suspendPaint();
+      this.sheet.suspendEvent();
+      var isShow = false;
+      if(projectReadOnly && this.setting.view.lockColumns){
+          this.setting.view.lockColumns = null;
+      }
+      if(selectedNodeId){
+          this.selectedNodeId = selectedNodeId;
+      }
+      if (node) {
+          if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
+              return;
+          } else {
+              //恢复底色
+              this.sheet.setStyle(this.sheet.getActiveRowIndex(), -1, this.getSelStyle(false,this.setting.style));
+              this.selectedNodeId = node.getID();
+          }
+          if (node.sourceType == "ration") {
+              if(node.data.type==rationType.gljRation){
+                  if($('#linkGLJ').hasClass('active'))  this.showMixRatio(node);
+              }else {
+                  if($('#linkGLJ').hasClass('active')){
+                      this.showRationGLJData(node);
+                      subObj.showGljSubTabData();
+                      // MaterialController.showReplaceDiv(node);
+                  }
+                  if($('#linkAZZJF').hasClass('active')) installationFeeObj.showRationInstallationData(node);
+                  if($('#linkMBZM').hasClass('active')) mbzm_obj.showMBZMData(node);
+              }
+              isShow = true;
+          }
+          if(node.sourceType == ModuleNames.ration_glj){
+              if($('#linkGLJ').hasClass('active')) this.showMixRatio(node);
+              MaterialController.hideReplaceDiv();
+              isShow = true;
+          }
+          if($('#linkGCLMX').hasClass('active')) this.showQuantityDetailData(node);
+
+      } else {
+          this.selectedNodeId = null;
+      }
+      if (!isShow) {
+          this.clearSheetData();
+          MaterialController.hideReplaceDiv();
+      }
+      this.sheet.resumeEvent();
+      this.sheet.resumePaint();
 
-        } else {
-            this.selectedNodeId = null;
-        }
-        if (!isShow) {
-            this.clearSheetData();
-            MaterialController.hideReplaceDiv();
-        }
         //子目换算
         //zmhs_obj.showZMHSData(node);
         //   $('#dropdown').hide();
@@ -685,8 +690,6 @@ var gljOprObj = {
         return codeMap;
     },
     initRationTree: function (init,codeMap) {
-        this.sheet.suspendPaint();
-        this.sheet.suspendEvent();
         this.sheet.setRowCount(this.sheetData.length >30?this.sheetData.length:30);
         for (var i = 0; i < this.sheetData.length; i++) {
             let options = this.getCodeOptions(this.sheetData[i],codeMap);
@@ -698,8 +701,6 @@ var gljOprObj = {
                 }
             }
         }
-        this.sheet.resumeEvent();
-        this.sheet.resumePaint();
     },
     getCodeOptions:function (recode,codeMap) {
         let options = [];

+ 9 - 7
web/building_saas/main/js/views/project_view.js

@@ -252,13 +252,15 @@ var projectObj = {
     setActiveCell(field, moveScroll){
         projectObj.mainSpread.focus(true);
         let mainSheet = projectObj.mainSpread.getActiveSheet();
-        let fieldCol = colSettingObj.getColByField(field);
-        if(fieldCol){
-            if(moveScroll){
-                mainSheet.showColumn(fieldCol, GC.Spread.Sheets.HorizontalPosition.center);
-            }
-            mainSheet.setActiveCell(projectObj.project.mainTree.selected.serialNo(), fieldCol);
-        }
+        TREE_SHEET_HELPER.massOperationSheet(mainSheet,function(){
+          let fieldCol = colSettingObj.getColByField(field);
+          if(fieldCol){
+              if(moveScroll){
+                  mainSheet.showColumn(fieldCol, GC.Spread.Sheets.HorizontalPosition.center);
+              }
+              mainSheet.setActiveCell(projectObj.project.mainTree.selected.serialNo(), fieldCol);
+          }
+        });
     },
     //获取粘贴更改的单元格(粘贴时,跳过隐藏行)
     checkSpreadChangedCells: function (info) {

+ 4 - 4
web/building_saas/main/js/views/zmhs_view.js

@@ -119,6 +119,8 @@ let zmhs_obj = {
         let selected = node?node:projectObj.project.mainTree.selected;
         let ration_coe = projectObj.project.ration_coe;
         let coeList = [];
+        this.coeSheet.suspendPaint();
+        this.coeSheet.suspendEvent();
         if(selected&&selected.sourceType == "ration"){
             let ration = selected.data;
             let assList = this.getAssList(node); //2019-01-23 新需求,将辅助定额合并到一个表显示  -- 20191206 辅助定额放前面
@@ -130,8 +132,6 @@ let zmhs_obj = {
         this.coeSheet.setRowCount(0);
         sheetCommonObj.showData(this.coeSheet, this.coeSetting,coeList);
         if (coeList.length > 0) {
-            this.coeSheet.suspendPaint();
-            this.coeSheet.suspendEvent();
             for(let i =0;i<coeList.length;i++ ){
                 if(gljUtil.isDef(coeList[i].option_codes)&&coeList[i].option_codes!=""){
                     this.getComboBoxForCodes(coeList[i],i);//设置可选类型的下拉框
@@ -143,8 +143,6 @@ let zmhs_obj = {
                     this.coeSheet.setCellType(i, 1, sheetCommonObj.getCustomerCoeCellType(this.generateHtmlString,this.bindCusEditorValue,this.updateCusCoeAfterEditor), GC.Spread.Sheets.SheetArea.viewport);
                 }
             }
-            this.coeSheet.resumeEvent();
-            this.coeSheet.resumePaint();
         }
         this.coeSheetData = coeList;
         if(projectReadOnly){
@@ -153,6 +151,8 @@ let zmhs_obj = {
         if(preSelections){//定位光标到之前的位置
             this.coeSheet.setSelection(preSelections[0].row,preSelections[0].col,preSelections[0].rowCount,preSelections[0].colCount);
         }
+        this.coeSheet.resumeEvent();
+        this.coeSheet.resumePaint();
     },
     showCusData:function (node) {
         let selected = node?node:projectObj.project.mainTree.selected;

+ 7 - 7
web/over_write/js/guangdong_2018_export.js

@@ -810,7 +810,7 @@ const XMLStandard = (function () {
                 },
                 // 投标单位编制时间
                 {
-                    name: 'BidCompileDate', mustHasValue: true,
+                    name: 'BidCompileDate', mustHasValue: true, required: true,
                     value: _util.getValueByKey(basicInformation, 'bidCompileDate')
                 },
                 // 投标单位审核人
@@ -1106,7 +1106,7 @@ const XMLStandard = (function () {
                 },
                 // 专业类别
                 {
-                    name: 'Specialty', type: _type.INT,
+                    name: 'Specialty', type: _type.INT, required: true,
                     value: Specialty[tenderData.property.engineeringName]
                 },
                 // 工程用途
@@ -1156,7 +1156,7 @@ const XMLStandard = (function () {
                 },
                 // 导出XML文件名,工程编号+工程名称.xml, 暂时取“名称.xml”,用户设置完工程编号后修改此值
                 {
-                    name: 'FileName',
+                    name: 'FileName', required: true,
                     value: `${tenderData.name}.xml`
                 },
                 // 备注
@@ -1396,7 +1396,7 @@ const XMLStandard = (function () {
                 { name: 'Number', value: bills.code },
                 // 名称
                 {
-                    name: 'Name', dName: '名称', required: true,
+                    name: 'Name', dName: '名称',
                     value: bills.name
                 },
                 // 特征
@@ -1612,7 +1612,7 @@ const XMLStandard = (function () {
                 // 金额
                 { name: 'Total', type: _type.DECIMAL, value: calcItem.unitFee },
                 // 费用代号
-                { name: 'Code', value: CalculationCodeMap[calcItem.name] },
+                { name: 'Code', required: true, value: CalculationCodeMap[calcItem.name] },
                 // 备注
                 { name: 'Remark', value: '' },
             ];
@@ -1958,7 +1958,7 @@ const XMLStandard = (function () {
                 // 金额
                 { name: 'Total', type: _type.DECIMAL, value: _util.getFee(bills.fees, 'common.totalFee') },
                 // 费用代号
-                { name: 'Code', value: getFeeCode(bills) },
+                { name: 'Code', required: true, value: getFeeCode(bills) },
                 // 备注
                 { name: 'Remark', value: bills.remark }
             ];
@@ -2038,7 +2038,7 @@ const XMLStandard = (function () {
                 // 现行价格指数 从承包人主要材料设备-价格指数调整法读取,取不到则输出“0”
                 { name: 'CurrentPrice', type: _type.DECIMAL, value: glj.FI },
                 // 工料机类型
-                { name: 'Kind', type: _type.INT, value: glj.kind },
+                { name: 'Kind', type: _type.INT, required: true, value: glj.kind },
                 // 工料机归属
                 { name: 'Class', value: '' },
                 // 扩展属性