|
@@ -278,17 +278,12 @@ async function getClassNameMap(compilationID) {
|
|
* 将信息价源数据转换入库
|
|
* 将信息价源数据转换入库
|
|
* @param {String} compilationID - 费用定额ID
|
|
* @param {String} compilationID - 费用定额ID
|
|
* @param {String} period - 期数 eg: 2020年-09月
|
|
* @param {String} period - 期数 eg: 2020年-09月
|
|
- * @param {String} area - 地区 eg: 广州市-广州市
|
|
|
|
|
|
+ * @param {String} areaID - 地区ID
|
|
* @param {Array} sourceData - 造价通源数据
|
|
* @param {Array} sourceData - 造价通源数据
|
|
* @param {Object} classNameMap - 从标准人材机分类树获取的编号-名称映射表
|
|
* @param {Object} classNameMap - 从标准人材机分类树获取的编号-名称映射表
|
|
* @return {Void}
|
|
* @return {Void}
|
|
*/
|
|
*/
|
|
-async function saveData(compilationID, period, area, sourceData, classNameMap) {
|
|
|
|
- let areaItem = await priceInfoAreaModel.findOne({ compilationID, name: area }).lean();
|
|
|
|
- if (!areaItem) {
|
|
|
|
- areaItem = { compilationID, ID: uuidV1(), name: area };
|
|
|
|
- await priceInfoAreaModel.insertMany([areaItem]);
|
|
|
|
- }
|
|
|
|
|
|
+async function saveData(compilationID, period, areaID, sourceData, classNameMap) {
|
|
let lib = await priceInfoLibModel.findOne({ compilationID, period }).lean();
|
|
let lib = await priceInfoLibModel.findOne({ compilationID, period }).lean();
|
|
if (!lib) {
|
|
if (!lib) {
|
|
lib = {
|
|
lib = {
|
|
@@ -300,7 +295,6 @@ async function saveData(compilationID, period, area, sourceData, classNameMap) {
|
|
};
|
|
};
|
|
await priceInfoLibModel.insertMany([lib]);
|
|
await priceInfoLibModel.insertMany([lib]);
|
|
}
|
|
}
|
|
- const areaID = areaItem.ID;
|
|
|
|
const libID = lib.ID;
|
|
const libID = lib.ID;
|
|
// 如果该期数该地区下存在数据,则不处理,防止重复插入数据
|
|
// 如果该期数该地区下存在数据,则不处理,防止重复插入数据
|
|
// 造价通地区数据更新不同步,可能需要多次导入数据补全一期数据,如果已经有数据,说明该地区已经导入成功过了,直接跳过
|
|
// 造价通地区数据更新不同步,可能需要多次导入数据补全一期数据,如果已经有数据,说明该地区已经导入成功过了,直接跳过
|
|
@@ -398,7 +392,19 @@ async function crawlData(from, to, compilationID) {
|
|
const hintInfos = [];
|
|
const hintInfos = [];
|
|
for (const period of periods) {
|
|
for (const period of periods) {
|
|
const sourcePeriod = period.replace(/年|月/g, '');
|
|
const sourcePeriod = period.replace(/年|月/g, '');
|
|
- for (const { city, county } of areas) {
|
|
|
|
|
|
+ for (let i = 0; i < areas.length; i++) {
|
|
|
|
+ // 存入地区
|
|
|
|
+ const { city, county } = areas[i];
|
|
|
|
+ const area = `${city}-${county}`;
|
|
|
|
+ let areaItem = await priceInfoAreaModel.findOne({ compilationID, name: area }).lean();
|
|
|
|
+ const serialNo = i + 1;
|
|
|
|
+ if (!areaItem) {
|
|
|
|
+ areaItem = { compilationID, serialNo, ID: uuidV1(), name: area };
|
|
|
|
+ await priceInfoAreaModel.insertMany([areaItem]);
|
|
|
|
+ } else if (!areaItem.serialNo) { // 需求变更,需要排序,旧数据可能没有排序字段,需要加上
|
|
|
|
+ await priceInfoAreaModel.update({ ID: areaItem.ID }, { $set: { serialNo } });
|
|
|
|
+ }
|
|
|
|
+ // 存入信息价相关数据
|
|
const sourceData = await getPriceInfoSource(token, sourcePeriod, city, county);
|
|
const sourceData = await getPriceInfoSource(token, sourcePeriod, city, county);
|
|
if (typeof sourceData === 'string') {
|
|
if (typeof sourceData === 'string') {
|
|
hintInfos.push(sourceData);
|
|
hintInfos.push(sourceData);
|