diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/trade/ImportIndexStats.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/trade/ImportIndexStats.groovy index 4009417a7..c51b3f825 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/trade/ImportIndexStats.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/trade/ImportIndexStats.groovy @@ -1,6 +1,7 @@ package com.fangjia.script.trade import com.fangjia.core.util.DataUtil +import com.fangjia.core.util.DateUtil import com.fangjia.script.BaseBatch ///导入价格指数 @@ -8,6 +9,7 @@ import com.fangjia.script.BaseBatch import com.fangjia.script.BatchOwner import com.fangjia.script.Watcher import com.fangjia.script.commData.CommonDatautils +import com.fangjia.script.common.DataHandleUtils import com.fangjia.script.gj.district.FangjiaClientUtils import com.fangjia.script.util.DateUtils import com.fangjia.script.util.ElasticUtils @@ -17,6 +19,7 @@ import com.mongodb.DBCollection import com.mongodb.DBObject import org.apache.commons.lang.StringUtils import org.apache.commons.lang.math.RandomUtils +import org.bson.types.ObjectId import org.elasticsearch.xpack.sql.jdbc.EsDataSource import java.sql.ResultSet @@ -50,7 +53,7 @@ class ImportIndexStats extends BaseBatch{ - public static final def dingjiYear = 2015; + public static final def dingjiYear = 2020; private static final String address = "jdbc:es://http://seawater.es.db.fangjia.com:9200/timezone=UTC&page.size=250&connect.timeout=120s&network.timeout=120s&page.timeout=120s" private static final EsDataSource dataSource = new EsDataSource() @@ -74,12 +77,84 @@ class ImportIndexStats extends BaseBatch{ // synchTjjIndex()//同步统计局抓取过来的指数 // Calendar calendar=Calendar.getInstance(); -// def month= calendar.get(Calendar.MONTH)+1; +// def month= calendar.get(Calendar.MONTH); // def year= calendar.get(Calendar.YEAR); // def date = createDateString(year, month, 0, ""); -// calculatePriceIndex(year, month); - - def s = "201601" +// calculatePriceIndex(year, month, date); + +// addLostIndex() + + addHistoryIndex() + } + + def addLostIndex(){ + def citys = CommonDatautils.findAllCity(); + for(def city : citys){ + if(cityList.contains(city)){ + println city +" 数据来源于统计局" + continue; + } + def start = findStartOrEndIndex(city, 1) + def end = findStartOrEndIndex(city, -1) + if(start && end){ + def startYearmonth = 201601 + if(start.yearmonth>201601){ + startYearmonth = start.yearmonth + } + def months = DateUtils.getBetweenMonth(startYearmonth.toString(), end.yearmonth.toString()) + for(def i=0;i0){ + def dbo = findCityIndexByMonth(city, months[i].toInteger()) + if(dbo && (!dbo.chain || !dbo.yeartoyear || !dbo.fixedbase)){ + def lastMonthObj = findCityIndexByMonth(city, months[i-1]) + def nextObj = findCityIndexByMonth(city, months[i+1]) + def udata = new BasicDBObject() + if(!dbo.chain){ + def indexs = [] + if(lastMonthObj && lastMonthObj.chain){ + indexs << lastMonthObj.chain + } + if(nextObj && nextObj.chain){ + indexs << nextObj.chain + } + udata.put("chain",DataHandleUtils.getDoubleRound(1, indexs.sum()/indexs.size())) + udata.put("remark","推导") + + STATS_INDEX_COLL.update(new BasicDBObject("_id", dbo._id), new BasicDBObject('$set', udata),false, true); + } +// if(!dbo.yeartoyear){ +// +// } +// if(!dbo.fixedbase){ +// +// } + + } + } + } + } + + } + } + + def findStartOrEndIndex(city , sort){ + def q = new BasicDBObject("city", city) + def curosr = STATS_INDEX_COLL.find(q).sort(new BasicDBObject("yearmonth", sort)).limit(1) + def obj = null + for(def d : curosr){ + obj = d + } + return obj; + } + + + def findCityIndexByMonth(city , month){ + def q = new BasicDBObject("city", city).append("yearmonth", month) + return STATS_INDEX_COLL.findOne(q) + } + + def addHistoryIndex(){ + def s = "202101" def startDate = null; def stop = false; def runDates = [] @@ -95,8 +170,8 @@ class ImportIndexStats extends BaseBatch{ map.date = date runDates << map s = DateUtils.addMonth(date, 1, "yyyyMM") - - if(year==2024 && month==8){ + + if(year==2024 && month==9){ stop = true; } } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/DateUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/DateUtils.groovy index f6399a2dd..1f18053bf 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/DateUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/DateUtils.groovy @@ -988,6 +988,28 @@ class DateUtils { return null; } + public static List getBetweenMonth(start, end){ + def stop = false; + def months = [] + while(!stop){ + start = com.fangjia.script.util.DateUtils.parseFromTightYYYYMM(start); + def year = start.getYear()+1900; + def month = start.month+1; + if(month <10){ + start = year.toString()+"0"+month.toString() + }else{ + start = year.toString()+month.toString() + } + months << start + start = DateUtils.addMonth(start, 1, "yyyyMM") + + if(start > end){ + stop = true; + } + } + return months; + } + public static long random(long begin, long end) { long rtn = begin + (long) (Math.random() * (end - begin)); // 如果返回的是开始时间和结束时间,则递归调用本函数查找随机值