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 6b186692a..a1d5b4f9c 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 @@ -8,6 +8,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.gj.district.FangjiaClientUtils import com.fangjia.script.util.DateUtils import com.fangjia.script.util.ElasticUtils import com.fangjia.script.util.MongoUtils @@ -19,6 +20,10 @@ import org.apache.commons.lang.math.RandomUtils import org.elasticsearch.xpack.sql.jdbc.EsDataSource import java.sql.ResultSet +import java.util.concurrent.CountDownLatch +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors +import java.util.concurrent.atomic.AtomicLong @BatchOwner(Watcher.GaoJuan) class ImportIndexStats extends BaseBatch{ @@ -33,6 +38,7 @@ class ImportIndexStats extends BaseBatch{ final DBCollection indices_price_house_newColl = MongoUtils.getCollectionByName("crawl", "indices_price_house_new", "192.168.0.206", 27020) final DBCollection indices_price_house_new_typeColl = MongoUtils.getCollectionByName("crawl", "indices_price_house_new_type", "192.168.0.206", 27020) + public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10) //DSCollection seawater = new DataStore("192.168.0.65", 27777).getCollection("fangjia.seawater") private static def cityList=["北京", "天津", "石家庄", "太原", "呼和浩特", "沈阳", "大连", "长春", "哈尔滨", "上海", "南京", "杭州", "宁波", "合肥", "福州", "厦门", @@ -74,80 +80,112 @@ class ImportIndexStats extends BaseBatch{ def s = "201601" def startDate = null; def stop = false; + def runDates = [] while(!stop){ startDate = DateUtils.parseFromTightYYYYMM(s); def year = startDate.getYear()+1900; def month = startDate.month+1; def date = createDateString(year, month, 0, ""); + + def map = [:] + map.year = year + map.month = month + runDates << map s = DateUtils.addMonth(date, 1, "yyyyMM") - if(year==2024 && month==9){ + if(year==2024 && month==8){ stop = true; } - calculatePriceIndex(year, month); - println "运行......"+date+" 完成" } - - + for(def map : runDates){ + calculatePriceIndex(map.year, map.month); + } } + //计算统计局没有发布的城市的价格指数 def calculatePriceIndex(def year, def month){ def citys =CommonDatautils.findAllCity(); def date = createDateString(year, month, 0, ""); def haveIndexCitys = findPriceIndexCitys(date.toInteger()); - def index = 0; - if(citys){ - for(def city : citys){ - if(haveIndexCitys.contains(city)){ - continue; - } - - def id = findPriceIndex(city, date.toInteger()); - if(id){//已计算 - continue; - } - - def result = [:]; - calculateAvgPriceIndex(city, year, month, result); - calculateAreaPriceInfex(result, city, year, month, 90);//0-90 - calculateAreaPriceInfex(result, city, year, month, 144);//90-144 - calculateAreaPriceInfex(result, city, year, month, 1000);//144-1000 + def totalCount = new AtomicLong() + def addCount = new AtomicLong() + final CountDownLatch latch = new CountDownLatch(citys.size()) - -// checkPriceIndex(result);//涨跌幅控制 - index++; - if(result){ - result.city = city; - result.yearmonth = date.toInteger(); - result.source = 2; - result.remark = "均价计算"; - result.cat = "district"; - result.type = "城市" - savePriceIndex(result); - println "${index}"+ result+" "; - }else{ - println "${index}"+ result+" "+city +" 无数据"; - } + def newCitys = [] + for(def i=0;i def temp = v - 100; if(k == "markup" || k == "areaMarkup90" || k == "areaMarkup144" || k == "areaMarkup1000"){ - if(temp < -2 || temp > 1){ - v = getNewMarkup(temp, -2, 1) + 100; + if(temp < -3 || temp > 3){ + v = getNewMarkup(temp, -3, 3) + 100; detailFlag = 2; } }else if(k == "yearMarkup" || k == "areaYearMarkup90" || k == "areaYearMarkup144" || k == "areaYearMarkup1000"){ - if(temp < -5 || temp > 7){ - v = getNewMarkup(temp, -5, 7) + 100; + if(temp < -20 || temp > 30){ + v = getNewMarkup(temp, -20, 30) + 100; detailFlag = 2; } }else{ - if(temp < -6 || temp > 29){ - v = getNewMarkup(temp, -6, 29) + 100; + if(temp < -50 || temp > 100){ + v = getNewMarkup(temp, -50, 100) + 100; detailFlag = 2; } }