Parcourir la source

feat: 改版后的重庆信息价爬取

vian il y a 4 ans
Parent
commit
cd42be00c8

+ 84 - 9
modules/ration_repository/models/ration_item.js

@@ -9,6 +9,7 @@ let gljDao = require('./glj_repository');
 let rationRepositoryDao = require('./repository_map');
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
 const rationItemModel = mongoose.model('std_ration_lib_ration_items');
+const _rationItemModelBackup = mongoose.model('std_ration_lib_ration_items_backup');
 const stdRationLibModel = mongoose.model('std_ration_lib_map');
 const stdRationSectionModel = mongoose.model('std_ration_lib_ration_chapter_trees');
 const compleRationModel = mongoose.model('complementary_ration_items');
@@ -21,14 +22,85 @@ import stdgljutil  from "../../../public/cache/std_glj_type_util";
 const stdGLJItemModel = mongoose.model('std_glj_lib_gljList');
 var rationItemDAO = function(){};
 
+rationItemDAO.prototype.overwriteRationGLJList = async function (sourceLibID, targetLibID) {
+    const rations = await _rationItemModelBackup.find({ rationRepId: sourceLibID }, 'ID code rationGljList').lean();
+    const bulks = [];
+    rations.forEach(ration => {
+        if (ration.rationGljList && ration.rationGljList.length) {
+            ration.rationGljList.forEach(rGLJ => {
+                delete rGLJ.gljCode;
+            });
+            bulks.push({
+                updateOne: {
+                    filter: { rationRepId: targetLibID, code: ration.code },
+                    update: { $set: { rationGljList: ration.rationGljList } }
+                }
+            })
+        }
+    });
+    if (bulks) {
+        await rationItemModel.bulkWrite(bulks);
+    }
+}
+
+rationItemDAO.prototype.handleGLJCode = async function (rationLibID, gljLibID) {
+    const rations = await _rationItemModelBackup.find({ rationRepId: rationLibID }, 'ID rationGljList').lean();
+    const gljs = await stdGLJItemModel.find({ repositoryId: gljLibID }, 'ID code').lean();
+    const gljMap = {};
+    gljs.forEach(glj => gljMap[glj.ID] = glj.code);
+    const bulks = [];
+    rations.forEach(ration => {
+        if (ration.rationGljList && ration.rationGljList.length) {
+            ration.rationGljList.forEach(rGLJ => {
+                rGLJ.gljCode = gljMap[rGLJ.gljId];
+            });
+            bulks.push({
+                updateOne: {
+                    filter: { ID: ration.ID },
+                    update: { $set: { rationGljList: ration.rationGljList } }
+                }
+            })
+        }
+    });
+    if (bulks.length) {
+        await _rationItemModelBackup.bulkWrite(bulks);
+    }
+}
+
+rationItemDAO.prototype.handleGLJCodeID = async function (rationLibID, gljLibID) {
+    const rations = await _rationItemModelBackup.find({ rationRepId: rationLibID }, 'ID rationGljList').lean();
+    const gljs = await stdGLJItemModel.find({ repositoryId: gljLibID }, 'ID code').lean();
+    const gljMap = {};
+    gljs.forEach(glj => gljMap[glj.code] = glj.ID);
+    const bulks = [];
+    rations.forEach(ration => {
+        if (ration.rationGljList && ration.rationGljList.length) {
+            ration.rationGljList.forEach(rGLJ => {
+                rGLJ.gljId = gljMap[rGLJ.gljCode];
+            });
+            bulks.push({
+                updateOne: {
+                    filter: { ID: ration.ID },
+                    update: { $set: { rationGljList: ration.rationGljList } }
+                }
+            })
+        }
+    });
+    if (bulks.length) {
+        await _rationItemModelBackup.bulkWrite(bulks);
+    }
+}
+
+
 // 处理部颁数据
 rationItemDAO.prototype.handleBBData = async function (rationLibID, gljLibID) {
     const rations = await rationItemModel.find({ rationRepId: rationLibID }, '-_id code ID rationGljList').lean();
-    const gljs = await stdGLJItemModel.find({ repositoryId: gljLibID, 'component.0': {$exists: true} }, '-_id ID component').lean();
+    const types = [202, 203]
+    const gljs = await stdGLJItemModel.find({ repositoryId: gljLibID, gljType: {$in: types}, 'component.0': {$exists: true} }, '-_id ID component').lean();
     const gljIDMap = {};
     gljs.forEach(glj => gljIDMap[glj.ID] = glj);
     const updateData = [];
-    const errorRange = 0.004;
+    const errorRange = 0.04;
     for (const ration of rations) {
         if (!ration.rationGljList) {
             continue;
@@ -52,16 +124,19 @@ rationItemDAO.prototype.handleBBData = async function (rationLibID, gljLibID) {
         let isChanged = false;
         for (let i = 0; i < ration.rationGljList.length; i++) {
             const rGLJ = ration.rationGljList[i];
+            if (rGLJ) {
+                
+            }
             if (componentAmtMap[rGLJ.gljId]) {
                 isChanged = true;
                 const diff = scMathUtil.roundTo(rGLJ.consumeAmt - componentAmtMap[rGLJ.gljId], -3);
-                if (diff > errorRange || diff < -errorRange) {
+                if (diff < 0) {
+                    console.log(`ration.code`);
+                    console.log(ration.code);
+                }
+                if (diff > errorRange) {
                     // 扣减
                     rGLJ.consumeAmt = diff;
-                    if (diff < 0) {
-                        console.log(`ration.code`);
-                        console.log(ration.code);
-                    }
                     newRationGljList.push(rGLJ);    
                 }
             } else {
@@ -82,7 +157,7 @@ rationItemDAO.prototype.handleBBData = async function (rationLibID, gljLibID) {
     }
 };
 
-/* rationItemDAO.prototype.copyLib = async function (sourceLibID, targetLibID) {
+rationItemDAO.prototype.copyLib = async function (sourceLibID, targetLibID) {
     // coe-list
     const coeIDMap = {};
     const newCoeData = [];
@@ -157,7 +232,7 @@ rationItemDAO.prototype.handleBBData = async function (rationLibID, gljLibID) {
     await rationItemModel.insertMany(newRationData);
 
 };
- */
+
 // 由于导入excel时,excel数据存在负的工程量,所以导入后一些定额人材机的消耗量可能为负,需要处理
 rationItemDAO.prototype.handleMinusQuantity = async function() {
     const updateTask = [];

Fichier diff supprimé car celui-ci est trop grand
+ 485 - 957
web/over_write/crawler/chongqing_2018_price_crawler.js


+ 1 - 1
web/over_write/crawler/guangdong_2018_price_crawler.js

@@ -115,7 +115,7 @@ const TIME_OUT = 120000;
 
 // 创建axios实例
 const axiosConfig = {
-  baseURL: 'https://api.zjtcn.com/user',
+  baseURL: 'http://api.zjtcn.com/user',
   timeout: TIME_OUT,
   /* proxy: {
     host: "127.0.0.1", port: "8888" // Fiddler抓包,需要打开Fiddler否则会报connect error

+ 30 - 0
web/over_write/js/jiangxi_2017.js

@@ -1,5 +1,35 @@
 'use strict';
 
+//允许使用的工料机类型:人工、普通材料、其他材料费、混凝土、砂浆、配合比、商品混凝土、商品砂浆
+//机械台班、机上人工、机械组成物、主材、设备
+if(typeof allowGljType !== 'undefined'){
+    allowGljType = [1, 201, 202, 203, 204, 205, 206, 207, 301, 302, 303, 4, 5];
+}
+if(typeof allowComponent !== 'undefined'){
+    //允许含有组成物的工料机类型:混凝土、砂浆、配合比、机械台班、主材
+    allowComponent = [202, 203, 204, 301, 4];
+}
+if(typeof componentType !== 'undefined'){
+    //可以作为组成物的工料机类型:普通材料、机械组成物、机上人工、主材
+    componentType = [201, 302, 303, 4];
+}
+if(typeof machineAllowComponent !== 'undefined'){
+    //允许含有组成物的机械工料机类型:机械台班器仪表
+    machineAllowComponent = [301];
+}
+if(typeof machineComponent !== 'undefined'){
+    //可以作为机械工料机组成物的工料机类型:机械组成物、机上人工
+    machineComponent = [302, 303];
+}
+if(typeof materialAllowComponent !== 'undefined'){
+    //允许含有组成物的材料工料机类型:混凝土、砂浆、配合比
+    materialAllowComponent = [202, 203, 204];
+}
+if(typeof materialComponent !== 'undefined'){
+    //可以作为材料工料机组成物的工料机类型:普通材料
+    materialComponent = [201];
+}
+
 /**
  *
  *