From fac47d1faf38fa6af157ee8bca4a810cb10b8290 Mon Sep 17 00:00:00 2001 From: gaojuan Date: Fri, 1 Nov 2024 14:37:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E6=95=B0=E8=84=9A=E6=9C=AC=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../script/trade/ImportIndexStats.groovy | 146 ++++++++++-------- 1 file changed, 78 insertions(+), 68 deletions(-) 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 b5de80cae..7e5d2151c 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,16 +1,14 @@ package com.fangjia.script.trade import com.fangjia.core.util.DataUtil -import com.fangjia.core.util.DateUtil import com.fangjia.script.BaseBatch +import com.fangjia.script.BatchOwner +import com.fangjia.script.Watcher ///导入价格指数 -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 import com.fangjia.script.util.MongoUtils @@ -19,10 +17,8 @@ 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 import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService import java.util.concurrent.Executors @@ -74,13 +70,19 @@ class ImportIndexStats extends BaseBatch{ // updateDataType() // synch() -// synchTjjIndex()//同步统计局抓取过来的指数 +// synchTjjIndex()//批量同步统计局抓取过来的指数 Calendar calendar=Calendar.getInstance(); def month= calendar.get(Calendar.MONTH); def year= calendar.get(Calendar.YEAR); def date = createDateString(year, month, 0, ""); - calculatePriceIndex(year, month, date); + + def day = calendar.get(Calendar.DATE) + if(day == 5){ + calculatePriceIndex(year, month, date); + } + + createTjjData(date)//同步单期统计局数据 // addLostIndex() // addHistoryIndex() @@ -199,7 +201,7 @@ class ImportIndexStats extends BaseBatch{ runDates << map s = DateUtils.addMonth(date, 1, "yyyyMM") - if(year==2024 && month==8){ + if(year==2024 && month==10){ stop = true; } } @@ -210,7 +212,7 @@ class ImportIndexStats extends BaseBatch{ //计算统计局没有发布的城市的价格指数 def calculatePriceIndex(def year, def month, def date){ -// def citys = ["五指山","琼海","儋州","文昌","万宁","东方","定安","屯昌","澄迈","临高","白沙","昌江","乐东","陵水","保亭","琼中"]// +// def citys = ["定安","五指山","琼海","儋州","文昌","万宁","东方","屯昌","澄迈","临高","白沙","昌江","乐东","陵水","保亭","琼中"]// def citys = CommonDatautils.findAllCity(); // def date = createDateString(year, month, 0, ""); def haveIndexCitys = findPriceIndexCitys(date.toInteger()); @@ -233,14 +235,14 @@ class ImportIndexStats extends BaseBatch{ if(id){//已计算 continue; } - if(date.toInteger()>=201601){ - dingjiYear = 2015 - }else if(date.toInteger()>=202101){ - dingjiYear = 2020 + if(date.toInteger()>=203101){ + dingjiYear = 2030 }else if(date.toInteger()>=202601){ dingjiYear = 2025 - }else if(date.toInteger()>=203101){ - dingjiYear = 2030 + }else if(date.toInteger()>=202101){ + dingjiYear = 2020 + }else if(date.toInteger()>=201601){ + dingjiYear = 2015 } fixedThreadPool.execute(new Runnable() { void run() { @@ -259,6 +261,7 @@ class ImportIndexStats extends BaseBatch{ }); } latch.await(1, TimeUnit.MINUTES); +// latch.await(1, TimeUnit.MINUTES); } def calculating(city, year, month, date){ @@ -826,69 +829,76 @@ class ImportIndexStats extends BaseBatch{ } def createTjjData(date){ - def queryStartDate = DateUtils.parseFromTightByPattern(date+"01", "yyyyMMdd") - def queryEndDate = DateUtils.parseFromTightByPattern(date+"05", "yyyyMMdd") - def sellIndexMap = findTjjIndex(indices_price_house_sellColl, queryStartDate, queryEndDate) - def sellIndexAreaMap = findTjjAreaIndex(indices_price_house_sell_typeColl, queryStartDate, queryEndDate) - def newIndexMap = findTjjIndex(indices_price_house_newColl, queryStartDate, queryEndDate) - def newAreaIndexAreaMap = findTjjAreaIndex(indices_price_house_new_typeColl, queryStartDate, queryEndDate) - def rets = [] - sellIndexMap.each{city, d-> - def dbo = new BasicDBObject() - dbo.put("city",d.city) - dbo.put("yearmonth",date.toInteger()) - dbo.put("source" ,1) - dbo.put("remark" , "统计局数据导入") - dbo.put("cat" , "district") - dbo.put("c_date" , new Date()) - dbo.put("m_date" , new Date()) - dbo.put("type" , "城市") - dbo.put("chain" ,d.mom) - dbo.put("yeartoyear" , d.yoy) - dbo.put("fixedbase" , d.fixedbase) + def count = STATS_INDEX_COLL.count(new BasicDBObject("type","城市").append("source", 1).append("yearmonth", date.toInteger())) + if(count == 0){ + def queryStartDate = DateUtils.parseFromTightByPattern(date+"01", "yyyyMMdd") + def queryEndDate = DateUtils.parseFromTightByPattern(date+"05", "yyyyMMdd") + def sellIndexMap = findTjjIndex(indices_price_house_sellColl, queryStartDate, queryEndDate) + def sellIndexAreaMap = findTjjAreaIndex(indices_price_house_sell_typeColl, queryStartDate, queryEndDate) + + def newIndexMap = findTjjIndex(indices_price_house_newColl, queryStartDate, queryEndDate) + def newAreaIndexAreaMap = findTjjAreaIndex(indices_price_house_new_typeColl, queryStartDate, queryEndDate) + def rets = [] + sellIndexMap.each{city, d-> + def dbo = new BasicDBObject() + dbo.put("city",d.city) + dbo.put("yearmonth",date.toInteger()) + dbo.put("source" ,1) + dbo.put("remark" , "统计局数据导入") + dbo.put("cat" , "district") + dbo.put("c_date" , new Date()) + dbo.put("m_date" , new Date()) + dbo.put("type" , "城市") + dbo.put("chain" ,d.mom) + dbo.put("yeartoyear" , d.yoy) + dbo.put("fixedbase" , d.fixedbase) - def areaMap = sellIndexAreaMap.get(d.city) - def areaObj1 = areaMap.get("90") - dbo.put("below_chain" , areaObj1.mom) - dbo.put("below_yeartoyear" , areaObj1.yoy) - dbo.put("below_fixedbase" , areaObj1.fixedbase) + def areaMap = sellIndexAreaMap.get(d.city) + def areaObj1 = areaMap.get("90") + dbo.put("below_chain" , areaObj1.mom) + dbo.put("below_yeartoyear" , areaObj1.yoy) + dbo.put("below_fixedbase" , areaObj1.fixedbase) - def areaObj2 = areaMap.get("90-144") - dbo.put("among_chain" , areaObj2.mom) - dbo.put("among_yeartoyear" , areaObj2.yoy) - dbo.put("among_fixedbase" , areaObj2.fixedbase) + def areaObj2 = areaMap.get("90-144") + dbo.put("among_chain" , areaObj2.mom) + dbo.put("among_yeartoyear" , areaObj2.yoy) + dbo.put("among_fixedbase" , areaObj2.fixedbase) - def areaObj3 = areaMap.get("144") - dbo.put("above_chain" , areaObj3.mom) - dbo.put("above_yeartoyear" , areaObj3.yoy) - dbo.put("above_fixedbase" , areaObj3.fixedbase) + def areaObj3 = areaMap.get("144") + dbo.put("above_chain" , areaObj3.mom) + dbo.put("above_yeartoyear" , areaObj3.yoy) + dbo.put("above_fixedbase" , areaObj3.fixedbase) - def newObj = newIndexMap.get(d.city) - dbo.put("new_chain" , newObj.mom) - dbo.put("new_yeartoyear" , newObj.yoy) - dbo.put("new_fixedbase" , newObj.fixedbase) + def newObj = newIndexMap.get(d.city) + dbo.put("new_chain" , newObj.mom) + dbo.put("new_yeartoyear" , newObj.yoy) + dbo.put("new_fixedbase" , newObj.fixedbase) - def newAreaMap = newAreaIndexAreaMap.get(d.city) - def areaNewObj1 = newAreaMap.get("90") - dbo.put("new_below_chain" , areaNewObj1.mom) - dbo.put("new_below_yeartoyear" , areaNewObj1.yoy) - dbo.put("new_below_fixedbase" , areaNewObj1.fixedbase) + def newAreaMap = newAreaIndexAreaMap.get(d.city) + def areaNewObj1 = newAreaMap.get("90") + dbo.put("new_below_chain" , areaNewObj1.mom) + dbo.put("new_below_yeartoyear" , areaNewObj1.yoy) + dbo.put("new_below_fixedbase" , areaNewObj1.fixedbase) - def areaNewObj2 = newAreaMap.get("90-144") - dbo.put("new_among_chain" , areaNewObj2.mom) - dbo.put("new_among_yeartoyear" , areaNewObj2.yoy) - dbo.put("new_among_fixedbase" , areaNewObj2.fixedbase) + def areaNewObj2 = newAreaMap.get("90-144") + dbo.put("new_among_chain" , areaNewObj2.mom) + dbo.put("new_among_yeartoyear" , areaNewObj2.yoy) + dbo.put("new_among_fixedbase" , areaNewObj2.fixedbase) - def areaNewObj3 = newAreaMap.get("144") - dbo.put("new_above_chain" , areaNewObj3.mom) - dbo.put("new_above_yeartoyear" , areaNewObj3.yoy) - dbo.put("new_above_fixedbase" , areaNewObj3.fixedbase) + def areaNewObj3 = newAreaMap.get("144") + dbo.put("new_above_chain" , areaNewObj3.mom) + dbo.put("new_above_yeartoyear" , areaNewObj3.yoy) + dbo.put("new_above_fixedbase" , areaNewObj3.fixedbase) + + rets << dbo + } + if(rets){ + STATS_INDEX_COLL.insert(rets) + } - rets << dbo } - STATS_INDEX_COLL.insert(rets) } def findTjjIndex(coll, queryStartDate, queryEndDate){