|
|
@@ -8,10 +8,17 @@ const installSectionModel = mongoose.model("std_ration_lib_installationSection")
|
|
|
const installFeeItemModel = mongoose.model("std_ration_lib_installation");
|
|
|
const complementaryGljModel = mongoose.model('complementary_glj_lib');
|
|
|
const stdGljModel = mongoose.model('std_glj_lib_gljList');
|
|
|
+const stdgljutil = require('../../../public/cache/std_glj_type_util');
|
|
|
+const installFacade = require('../facades/compleInstallFacade');
|
|
|
import async from 'async';
|
|
|
let stdRationModel = require ('../../ration_repository/models/ration_item').Model;
|
|
|
+import SectionTreeDao from '../models/sectionTreeModel';
|
|
|
+const sectionTreeDao = new SectionTreeDao();
|
|
|
+import GljDao from "../../complementary_glj_lib/models/gljModel";
|
|
|
+const gljDao = new GljDao();
|
|
|
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 +138,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 +164,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 ? ' ' + glj.specs : ''}   ${glj.unit} ${gljAmtMapping[glj.ID]}`)
|
|
|
}
|
|
|
@@ -186,7 +184,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 +241,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 ? ' ' + glj.specs : ''}   ${glj.unit} ${gljAmtMapping[glj.ID]}`)
|
|
|
}
|
|
|
@@ -475,23 +464,27 @@ class CompleRatoinDao {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- async getInstallation(rationRepId, callback){
|
|
|
- try {
|
|
|
- let feeItems = await installFeeItemModel.find({rationRepId: rationRepId, $or: [{deleted: false}, {deleted: null}]});
|
|
|
- for(let feeItem of feeItems){
|
|
|
- let sids = [];
|
|
|
- for(let sec of feeItem.section){
|
|
|
- sids.push(sec.ID);
|
|
|
- }
|
|
|
- if(sids.length > 0){
|
|
|
- let sections = await installSectionModel.find({ID: {$in: sids}, $or: [{deleted: false}, {deleted: null}]});
|
|
|
- feeItem._doc.section = sections;
|
|
|
- }
|
|
|
- }
|
|
|
- callback(0, feeItems);
|
|
|
- }
|
|
|
- catch(err){
|
|
|
- callback(err, null);
|
|
|
+ async getCodes (userId, compilationId) {
|
|
|
+ const compleRations = await compleRationModel.find({userId, compilationId}, '-_id code').lean();
|
|
|
+ const codes = [];
|
|
|
+ compleRations.forEach(item => codes.push(item.code));
|
|
|
+ return codes;
|
|
|
+ }
|
|
|
+
|
|
|
+ async prepareInitData (userId, compilationId, gljLibId) {
|
|
|
+ const rationsCodes = await this.getCodes(userId, compilationId);
|
|
|
+ const gljDistTypeCache = stdgljutil.getStdGljTypeCacheObj().toArray();
|
|
|
+ const installationData = await installFacade.getInstallation(userId, compilationId);
|
|
|
+ const rationTreeData = await sectionTreeDao.getComplementaryTree(userId, compilationId);
|
|
|
+ const mixedTreeData = await gljDao.getMixedTree(gljLibId, userId, compilationId);
|
|
|
+ const mixedGLJData = await gljDao.getGLJDataSync(gljLibId, userId, compilationId);
|
|
|
+ return {
|
|
|
+ rationsCodes,
|
|
|
+ gljDistTypeCache,
|
|
|
+ installationData,
|
|
|
+ rationTreeData,
|
|
|
+ mixedTreeData,
|
|
|
+ mixedGLJData
|
|
|
}
|
|
|
}
|
|
|
}
|