|  | @@ -30,6 +30,70 @@ function debugConsole(str, type = 'log') {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +const areas = [
 | 
	
		
			
				|  |  | +    '主城区',
 | 
	
		
			
				|  |  | +    '渝中区',
 | 
	
		
			
				|  |  | +    '江北区',
 | 
	
		
			
				|  |  | +    '沙坪坝区',
 | 
	
		
			
				|  |  | +    '南岸区',
 | 
	
		
			
				|  |  | +    '九龙坡区',
 | 
	
		
			
				|  |  | +    '大渡口区',
 | 
	
		
			
				|  |  | +    '北碚区',
 | 
	
		
			
				|  |  | +    '渝北区',
 | 
	
		
			
				|  |  | +    '巴南区',
 | 
	
		
			
				|  |  | +    '万州区',
 | 
	
		
			
				|  |  | +    '涪陵区',
 | 
	
		
			
				|  |  | +    '万盛区',
 | 
	
		
			
				|  |  | +    '双桥区',
 | 
	
		
			
				|  |  | +    '黔江区',
 | 
	
		
			
				|  |  | +    '长寿区',
 | 
	
		
			
				|  |  | +    '江津区',
 | 
	
		
			
				|  |  | +    '合川区',
 | 
	
		
			
				|  |  | +    '永川区',
 | 
	
		
			
				|  |  | +    '南川区',
 | 
	
		
			
				|  |  | +    '綦江县',
 | 
	
		
			
				|  |  | +    '潼南县',
 | 
	
		
			
				|  |  | +    '铜梁县',
 | 
	
		
			
				|  |  | +    '大足县',
 | 
	
		
			
				|  |  | +    '荣昌县',
 | 
	
		
			
				|  |  | +    '璧山县',
 | 
	
		
			
				|  |  | +    '梁平区',
 | 
	
		
			
				|  |  | +    '城口县',
 | 
	
		
			
				|  |  | +    '丰都县',
 | 
	
		
			
				|  |  | +    '垫江县',
 | 
	
		
			
				|  |  | +    '忠县',
 | 
	
		
			
				|  |  | +    '开州区',
 | 
	
		
			
				|  |  | +    '云阳县',
 | 
	
		
			
				|  |  | +    '奉节县',
 | 
	
		
			
				|  |  | +    '巫山县',
 | 
	
		
			
				|  |  | +    '巫溪县',
 | 
	
		
			
				|  |  | +    '石柱县',
 | 
	
		
			
				|  |  | +    '秀山县',
 | 
	
		
			
				|  |  | +    '酉阳县',
 | 
	
		
			
				|  |  | +    '彭水县',
 | 
	
		
			
				|  |  | +    '大足区',
 | 
	
		
			
				|  |  | +    '綦江区',
 | 
	
		
			
				|  |  | +    '万盛经开区',
 | 
	
		
			
				|  |  | +    '双桥经开区',
 | 
	
		
			
				|  |  | +    '铜梁区',
 | 
	
		
			
				|  |  | +    '璧山区',
 | 
	
		
			
				|  |  | +    '荣昌县1',
 | 
	
		
			
				|  |  | +    '荣昌县2',
 | 
	
		
			
				|  |  | +    '彭水县1',
 | 
	
		
			
				|  |  | +    '彭水县2',
 | 
	
		
			
				|  |  | +    '彭水县3',
 | 
	
		
			
				|  |  | +    '潼南区',
 | 
	
		
			
				|  |  | +    '荣昌区1',
 | 
	
		
			
				|  |  | +    '荣昌区2',
 | 
	
		
			
				|  |  | +    '武隆区',
 | 
	
		
			
				|  |  | +    '武隆区1',
 | 
	
		
			
				|  |  | +    '武隆区2',
 | 
	
		
			
				|  |  | +    '武隆区3',
 | 
	
		
			
				|  |  | +    '武隆区4',
 | 
	
		
			
				|  |  | +    '武隆区5',
 | 
	
		
			
				|  |  | +    '武隆区6',
 | 
	
		
			
				|  |  | +];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  // 页面类型
 | 
	
		
			
				|  |  |  const PageType = {
 | 
	
		
			
				|  |  |      GENERAL: '/Index.aspx',
 | 
	
	
		
			
				|  | @@ -710,6 +774,10 @@ async function transfromGeneralData(period, compilationID, generalData) {
 | 
	
		
			
				|  |  |      const area = '通用';
 | 
	
		
			
				|  |  |      // 爬取数据的时候,地区数据先匹配名称,如果费用定额已有此地区,不新增
 | 
	
		
			
				|  |  |      const matchedArea = await priceInfoAreaModel.findOne({ compilationID, name: area }).lean();
 | 
	
		
			
				|  |  | +    // 地区需要serialNo字段,打补丁
 | 
	
		
			
				|  |  | +    if (matchedArea && !matchedArea.serialNo) {
 | 
	
		
			
				|  |  | +        await priceInfoAreaModel.update({ ID: matchedArea.ID }, { $set: { serialNo: 1 } });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |      const areaID = matchedArea && matchedArea.ID || uuidV1();
 | 
	
		
			
				|  |  |      const compilationAreas = [];
 | 
	
		
			
				|  |  |      const libData = {
 | 
	
	
		
			
				|  | @@ -831,9 +899,14 @@ async function transformAreaData(period, compilationID, libData, areaData, mixed
 | 
	
		
			
				|  |  |      const priceData = [];
 | 
	
		
			
				|  |  |      for (const { area, subData } of data) {
 | 
	
		
			
				|  |  |          const matchedArea = await priceInfoAreaModel.findOne({ compilationID, name: area }).lean();
 | 
	
		
			
				|  |  | +        // 地区需要serialNo字段,打补丁
 | 
	
		
			
				|  |  | +        const serialNo = areas.indexOf(area) + 1;
 | 
	
		
			
				|  |  | +        if (matchedArea && !matchedArea.serialNo) {
 | 
	
		
			
				|  |  | +            await priceInfoAreaModel.update({ ID: matchedArea.ID }, { $set: { serialNo } });
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          const areaID = matchedArea && matchedArea.ID || uuidV1();
 | 
	
		
			
				|  |  |          if (!matchedArea) {
 | 
	
		
			
				|  |  | -            compilationAreas.push({ compilationID, ID: areaID, name: area });
 | 
	
		
			
				|  |  | +            compilationAreas.push({ compilationID, serialNo, ID: areaID, name: area });
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          let preClass;
 | 
	
		
			
				|  |  |          subData.forEach(subItem => {
 | 
	
	
		
			
				|  | @@ -914,9 +987,10 @@ async function save(period, generalData, areaData, mixedData) {
 | 
	
		
			
				|  |  |   * 爬取数据
 | 
	
		
			
				|  |  |   * @param {String} from - 从哪一期开始 eg: 2020-01
 | 
	
		
			
				|  |  |   * @param {String} to - 从哪一期结束 eg: 2020-05
 | 
	
		
			
				|  |  | + * @param {String} compilationID - 费用定额ID
 | 
	
		
			
				|  |  |   * @return {Object}
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  | -async function crawlData(from, to) {
 | 
	
		
			
				|  |  | +async function crawlData(from, to, compilationID) {
 | 
	
		
			
				|  |  |      let curPeriod;
 | 
	
		
			
				|  |  |      try {
 | 
	
		
			
				|  |  |          const $index = await loadPage(PageType.GENERAL);
 | 
	
	
		
			
				|  | @@ -924,6 +998,21 @@ async function crawlData(from, to) {
 | 
	
		
			
				|  |  |          if (!periodData) {
 | 
	
		
			
				|  |  |              throw '无效的期数区间。';
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        // 地区补丁
 | 
	
		
			
				|  |  | +        const areaData = await priceInfoAreaModel.find({ compilationID, serialNo: null }).lean();
 | 
	
		
			
				|  |  | +        const bulks = [];
 | 
	
		
			
				|  |  | +        areaData.forEach(areaItem => {
 | 
	
		
			
				|  |  | +            const serialNo = areas.indexOf(areaItem.name) + 1;
 | 
	
		
			
				|  |  | +            bulks.push({
 | 
	
		
			
				|  |  | +                updateOne: {
 | 
	
		
			
				|  |  | +                    filter: { ID: areaItem.ID },
 | 
	
		
			
				|  |  | +                    update: { serialNo }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        if (bulks.length) {
 | 
	
		
			
				|  |  | +            await priceInfoAreaModel.bulkWrite(bulks);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          // 一期一期爬取数据
 | 
	
		
			
				|  |  |          debugConsole('allTime', 'time');
 | 
	
		
			
				|  |  |          for (const periodItem of periodData) {
 |