住宅指数

This commit is contained in:
2024-09-27 16:20:59 +08:00
parent c236962d2e
commit 3c8b595944
@@ -9,6 +9,7 @@ import com.fangjia.script.BatchOwner
import com.fangjia.script.Watcher import com.fangjia.script.Watcher
import com.fangjia.script.commData.CommonDatautils import com.fangjia.script.commData.CommonDatautils
import com.fangjia.script.util.DateUtils import com.fangjia.script.util.DateUtils
import com.fangjia.script.util.ElasticUtils
import com.fangjia.script.util.MongoUtils import com.fangjia.script.util.MongoUtils
import com.mongodb.BasicDBObject import com.mongodb.BasicDBObject
import com.mongodb.DBCollection import com.mongodb.DBCollection
@@ -23,8 +24,15 @@ import java.sql.ResultSet
class ImportIndexStats extends BaseBatch{ class ImportIndexStats extends BaseBatch{
//public final static DBCollection under_line = new Mongo("192.168.0.136", 27017).getDB('fangjia').getCollection('stats_index'); //public final static DBCollection under_line = new Mongo("192.168.0.136", 27017).getDB('fangjia').getCollection('stats_index');
public static final DBCollection on_line = MongoUtils.getCollectionByName("fangjia", "stats_index", "mongo.db.fangjia.com") public static final DBCollection on_line = MongoUtils.getCollectionByName("fangjia", "stats_index", "mongo.db.fangjia.com")
public static final DBCollection STATS_INDEX_COLL = MongoUtils.getCollectionByName("fangjia_stat", "stats_index", "mongo.db.fangjia.com")
public static final DBCollection REGION_STAT_COLL = MongoUtils.getCollectionByName("fangjia", "region_stat", "mongo.db.fangjia.com") public static final DBCollection REGION_STAT_COLL = MongoUtils.getCollectionByName("fangjia", "region_stat", "mongo.db.fangjia.com")
//public static final DSCollection SEAWATER_COLL = new DataStore("192.168.0.65", 27777).getCollection("fangjia.seawater")
final DBCollection indices_price_house_sellColl = MongoUtils.getCollectionByName("crawl", "indices_price_house_sell", "192.168.0.206", 27020)
final DBCollection indices_price_house_sell_typeColl = MongoUtils.getCollectionByName("crawl", "indices_price_house_sell_type", "192.168.0.206", 27020)
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)
//DSCollection seawater = new DataStore("192.168.0.65", 27777).getCollection("fangjia.seawater") //DSCollection seawater = new DataStore("192.168.0.65", 27777).getCollection("fangjia.seawater")
private static def cityList=["北京", "天津", "石家庄", "太原", "呼和浩特", "沈阳", "大连", "长春", "哈尔滨", "上海", "南京", "杭州", "宁波", "合肥", "福州", "厦门", private static def cityList=["北京", "天津", "石家庄", "太原", "呼和浩特", "沈阳", "大连", "长春", "哈尔滨", "上海", "南京", "杭州", "宁波", "合肥", "福州", "厦门",
@@ -32,7 +40,9 @@ class ImportIndexStats extends BaseBatch{
"秦皇岛", "包头", "丹东", "锦州", "吉林", "牡丹江", "无锡", "扬州", "徐州", "温州", "金华", "蚌埠", "安庆", "泉州", "九江", "赣州", "烟台", "济宁", "洛阳", "平顶山", "秦皇岛", "包头", "丹东", "锦州", "吉林", "牡丹江", "无锡", "扬州", "徐州", "温州", "金华", "蚌埠", "安庆", "泉州", "九江", "赣州", "烟台", "济宁", "洛阳", "平顶山",
"宜昌", "襄阳", "岳阳", "常德", "惠州", "湛江", "韶关", "桂林", "北海", "三亚", "泸州", "南充", "遵义", "大理"]; "宜昌", "襄阳", "岳阳", "常德", "惠州", "湛江", "韶关", "桂林", "北海", "三亚", "泸州", "南充", "遵义", "大理"];
public static final def dingjiYear = 2016;
public static final def dingjiYear = 2015;
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 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() private static final EsDataSource dataSource = new EsDataSource()
@@ -51,13 +61,17 @@ class ImportIndexStats extends BaseBatch{
@Override @Override
public void process(Object args) { public void process(Object args) {
Calendar calendar=Calendar.getInstance(); // updateDataType()
def month= calendar.get(Calendar.MONTH)+1; // synch()
def year= calendar.get(Calendar.YEAR); // synchTjjIndex()//同步统计局抓取过来的指数
def date = createDateString(year, month, 0, "");
calculatePriceIndex(year, month);
/*def s = "201601" // Calendar calendar=Calendar.getInstance();
// def month= calendar.get(Calendar.MONTH)+1;
// def year= calendar.get(Calendar.YEAR);
// def date = createDateString(year, month, 0, "");
// calculatePriceIndex(year, month);
def s = "201601"
def startDate = null; def startDate = null;
def stop = false; def stop = false;
while(!stop){ while(!stop){
@@ -67,12 +81,12 @@ class ImportIndexStats extends BaseBatch{
def date = createDateString(year, month, 0, ""); def date = createDateString(year, month, 0, "");
s = DateUtils.addMonth(date, 1, "yyyyMM") s = DateUtils.addMonth(date, 1, "yyyyMM")
if(year==2017 && month==7){ if(year==2024 && month==8){
stop = true; stop = true;
} }
calculatePriceIndex(year, month); calculatePriceIndex(year, month);
println "运行......"+date println "运行......"+date
}*/ }
} }
@@ -96,27 +110,20 @@ class ImportIndexStats extends BaseBatch{
def result = [:]; def result = [:];
calculateAvgPriceIndex(city, year, month, result); calculateAvgPriceIndex(city, year, month, result);
def curMonthPriceMap = findHouse2(city, createDateString(year, month, 1, "-"), createDateString(year, month + 1, 1, "-")); calculateAreaPriceInfex(result, city, year, month, 90);//0-90
def lastMonthPriceMap = findHouse2(city, createDateString(year, month-1, 1, "-"), createDateString(year, month , 1, "-")); calculateAreaPriceInfex(result, city, year, month, 144);//90-144
def lastYearPriceMap = findHouse2(city, createDateString(year-1, month, 1, "-"), createDateString(year-1, month + 1, 1, "-")); calculateAreaPriceInfex(result, city, year, month, 1000);//144-1000
def fixPriceMap = findHouse2(city, createDateString(dingjiYear, month, 1, "-"), createDateString(dingjiYear, month+1 , 1, "-"));
calculateAreaPriceInfex(result, 90, curMonthPriceMap.get("0_90"),lastMonthPriceMap.get("0_90"),lastYearPriceMap.get("0_90"), fixPriceMap.get("0_90"));//0-90
calculateAreaPriceInfex(result, 144, curMonthPriceMap.get("90-144"),lastMonthPriceMap.get("90-144"),lastYearPriceMap.get("90-144"), fixPriceMap.get("90-144"));//90-144
calculateAreaPriceInfex(result, 1000, curMonthPriceMap.get("144_500"),lastMonthPriceMap.get("144_500"),lastYearPriceMap.get("144_500"), fixPriceMap.get("144_500"));//144-1000
// calculateAreaPriceInfex(city, year, month, result, 0, 90);//0-90 // checkPriceIndex(result);//涨跌幅控制
// calculateAreaPriceInfex(city, year, month, result, 90, 144);//90-144
// calculateAreaPriceInfex(city, year, month, result, 144, 1000);//144-1000
checkPriceIndex(result);
index++; index++;
if(result){ if(result){
result.city = city; result.city = city;
result.yearmonth = date; result.yearmonth = date.toInteger();
result.source = 2; result.source = 2;
result.remark = "均价计算"; result.remark = "均价计算";
result.cat = "district"; result.cat = "district";
result.type = "城市"
savePriceIndex(result); savePriceIndex(result);
} }
println "${index}"+ result; println "${index}"+ result;
@@ -124,39 +131,55 @@ class ImportIndexStats extends BaseBatch{
} }
} }
//计算新建住房的价格指数 //计算住房的价格指数
def calculateAvgPriceIndex(def city, def year, def month, def result){ def calculateAvgPriceIndex(def city, def year, def month, def result){
def curMonthPrice = findCityByDates(city, createDateString(year, month, 1, "-"), createDateString(year, month + 1, 1, "-")); // def curMonthPrice = findCityByDates(city, createDateString(year, month, 1, "-"), createDateString(year, month + 1, 1, "-"));
def startDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(DateUtils.parseFromTightYYYYMM(year.toString()+month.toString())),"yyyyMMdd")
def endDate = DateUtils.formatDateByPattern(DateUtils.getLastDayOfMonth(DateUtils.parseFromTightYYYYMM(year.toString()+(month.toString()))),"yyyyMMdd")
def curMonthPrice = findHouse3(city, startDate.toInteger(), endDate.toInteger(), null)
float markup = 0f; float markup = 0f;
float yearMarkup = 0f; float yearMarkup = 0f;
float dingJiMarkup = 0f; float dingJiMarkup = 0f;
//环比涨跌幅 //环比涨跌幅
def lastMonthPrice = findCityByDates(city, createDateString(year, month - 1, 1, "-"), createDateString(year, month, 1, "-"));
// def lastMonthPrice = findCityByDates(city, createDateString(year, month - 1, 1, "-"), createDateString(year, month, 1, "-"));
startDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(DateUtils.parseFromTightYYYYMM(year.toString()+month.toString()),-1),"yyyyMMdd")
endDate = DateUtils.formatDateByPattern(DateUtils.getLastDayOfMonth(DateUtils.parseFromTightYYYYMM(year.toString()+month.toString()),-1),"yyyyMMdd")
def lastMonthPrice = findHouse3(city, startDate.toInteger(), endDate.toInteger(), null)
if(lastMonthPrice){ if(lastMonthPrice){
markup = curMonthPrice *100/lastMonthPrice markup = curMonthPrice *100/lastMonthPrice
markup = DataUtil.getDoubleRound(1,markup); markup = DataUtil.getDoubleRound(1,markup);
}else{
def v = random(-3, 3) + 100;
markup = v;
} }
// else{
// def v = random(-3, 3) + 100;
// markup = v;
// }
//同比涨跌幅 //同比涨跌幅
def lastYearPrice = findCityByDates(city, createDateString(year-1, month, 1, "-"), createDateString(year-1, month+1 , 1, "-")); // def lastYearPrice = findCityByDates(city, createDateString(year-1, month, 1, "-"), createDateString(year-1, month+1 , 1, "-"));
startDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(DateUtils.parseFromTightYYYYMM((year-1).toString()+month.toString())),"yyyyMMdd")
endDate = DateUtils.formatDateByPattern(DateUtils.getLastDayOfMonth(DateUtils.parseFromTightYYYYMM((year-1).toString()+(month.toString()))),"yyyyMMdd")
def lastYearPrice = findHouse3(city, startDate.toInteger(), endDate.toInteger(), null)
if(lastYearPrice){ if(lastYearPrice){
yearMarkup = curMonthPrice * 100/lastYearPrice; yearMarkup = curMonthPrice * 100/lastYearPrice;
yearMarkup = DataUtil.getRound(1,yearMarkup); yearMarkup = DataUtil.getRound(1,yearMarkup);
}else{
def v = random(-5, 5) + 100;
yearMarkup = v;
} }
// else{
// def v = random(-5, 5) + 100;
// yearMarkup = v;
// }
//定基涨跌幅 //定基涨跌幅
def dingJiPrice = findCityByDates(city, createDateString(dingjiYear, month, 1, "-"), createDateString(dingjiYear, month+1 , 1, "-")); // def dingJiPrice = findCityByDates(city, createDateString(dingjiYear, month, 1, "-"), createDateString(dingjiYear, month+1 , 1, "-"));
startDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(DateUtils.parseFromTightYYYYMMDD2(dingjiYear.toString()+"0101")),"yyyyMMdd")
endDate = DateUtils.formatDateByPattern(DateUtils.getLastDayOfMonth(DateUtils.parseFromTightYYYYMMDD2(dingjiYear.toInteger()+"1231")),"yyyyMMdd")
def dingJiPrice = findHouse3(city, startDate, endDate, null)
if(dingJiPrice){ if(dingJiPrice){
dingJiMarkup = curMonthPrice*100/dingJiPrice; dingJiMarkup = curMonthPrice*100/dingJiPrice;
dingJiMarkup = DataUtil.getRound(1,dingJiMarkup); dingJiMarkup = DataUtil.getRound(1,dingJiMarkup);
}else{
def v = random(-8, 8) + 100;
dingJiMarkup = v;
} }
// else{
// def v = random(-8, 8) + 100;
// dingJiMarkup = v;
// }
if(markup){ if(markup){
result.markup = markup; result.markup = markup;
@@ -174,44 +197,52 @@ class ImportIndexStats extends BaseBatch{
} }
//计算住宅按平米分类的价格指数 //计算住宅按平米分类的价格指数
def calculateAreaPriceInfex(def result, def endArea, def curHousePrices1, def lastMonthHousePrices1, def lastYearHousePrice2, def dingjiHousePrices3){ def calculateAreaPriceInfex(def result, def city, def year, def month, def endArea){
//def curHousePrices1 = findHouse(city, startArea, endArea, createDateString(year, month, 1, "-"), createDateString(year, month + 1, 1, "-")); def startDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(DateUtils.parseFromTightYYYYMM(year.toString()+month.toString())),"yyyyMMdd")
def cur_price = getAvgPrice(curHousePrices1); def endDate = DateUtils.formatDateByPattern(DateUtils.getLastDayOfMonth(DateUtils.parseFromTightYYYYMM(year.toString()+(month.toString()))),"yyyyMMdd")
def cur_price = findHouse3(city, startDate, endDate, endArea);
def areaMarkup = 0; def areaMarkup = 0;
def areaYearMarkup = 0; def areaYearMarkup = 0;
def areaDingJiMarkup = 0; def areaDingJiMarkup = 0;
//环比涨跌幅 //环比涨跌幅
//def lastMonthHousePrices1 = findHouse(city, startArea, endArea, createDateString(year, month-1, 1, "-"), createDateString(year, month , 1, "-")); startDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(DateUtils.parseFromTightYYYYMM(year.toString()+month.toString()),-1),"yyyyMMdd")
def lastMonthlt90_price = getAvgPrice(lastMonthHousePrices1); endDate = DateUtils.formatDateByPattern(DateUtils.getLastDayOfMonth(DateUtils.parseFromTightYYYYMM(year.toString()+month.toString()),-1),"yyyyMMdd")
def lastMonthlt90_price = findHouse3(city, startDate, endDate, endArea);
if(cur_price && lastMonthlt90_price){ if(cur_price && lastMonthlt90_price){
areaMarkup = cur_price*100/lastMonthlt90_price areaMarkup = cur_price*100/lastMonthlt90_price
areaMarkup = DataUtil.getRound(1,areaMarkup); areaMarkup = DataUtil.getRound(1,areaMarkup);
}else{
def v = random(-3, 3) + 100;
areaMarkup = v;
} }
// else{
// def v = random(-3, 3) + 100;
// areaMarkup = v;
// }
//def lastYearHousePrice2 = findHouse(city, startArea, endArea, createDateString(year-1, month, 1, "-"), createDateString(year-1, month + 1, 1, "-")); startDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(DateUtils.parseFromTightYYYYMM((year-1).toString()+month.toString())),"yyyyMMdd")
def lastYearprice = getAvgPrice(lastYearHousePrice2); endDate = DateUtils.formatDateByPattern(DateUtils.getLastDayOfMonth(DateUtils.parseFromTightYYYYMM((year-1).toString()+(month.toString()))),"yyyyMMdd")
def lastYearprice = findHouse3(city, startDate, endDate, endArea);
//同比涨跌幅 //同比涨跌幅
if(cur_price && lastYearprice){ if(cur_price && lastYearprice){
areaYearMarkup = cur_price *100/lastYearprice areaYearMarkup = cur_price *100/lastYearprice
areaYearMarkup = DataUtil.getRound(1,areaYearMarkup); areaYearMarkup = DataUtil.getRound(1,areaYearMarkup);
}else{
def v = random(-5, 5) + 100;
areaYearMarkup = v;
} }
// else{
// def v = random(-5, 5) + 100;
// areaYearMarkup = v;
// }
//定基涨跌幅 //定基涨跌幅
//def dingjiHousePrices3 = findHouse(city, startArea, endArea, createDateString(2010, month, 1, "-"), createDateString(2010, month+1 , 1, "-")); startDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(DateUtils.parseFromTightYYYYMMDD2(dingjiYear.toString()+"0101")),"yyyyMMdd")
def dingJiPrice = getAvgPrice(dingjiHousePrices3); endDate = DateUtils.formatDateByPattern(DateUtils.getLastDayOfMonth(DateUtils.parseFromTightYYYYMMDD2(dingjiYear.toInteger()+"1231")),"yyyyMMdd")
def dingJiPrice = findHouse3(city, startDate, endDate, endArea);
if(cur_price && dingJiPrice){ if(cur_price && dingJiPrice){
areaDingJiMarkup = cur_price *100/dingJiPrice areaDingJiMarkup = cur_price *100/dingJiPrice
areaDingJiMarkup = DataUtil.getRound(1,areaDingJiMarkup); areaDingJiMarkup = DataUtil.getRound(1,areaDingJiMarkup);
}else{
def v = random(-8, 8) + 100;
areaDingJiMarkup = v;
} }
// else{
// def v = random(-8, 8) + 100;
// areaDingJiMarkup = v;
// }
if(areaMarkup){ if(areaMarkup){
@@ -320,29 +351,58 @@ class ImportIndexStats extends BaseBatch{
// def dbCursor = seawater.find(q, keys).batchSize(5000); // def dbCursor = seawater.find(q, keys).batchSize(5000);
// Iterator<BasicDBObject> it = dbCursor.iterator() // Iterator<BasicDBObject> it = dbCursor.iterator()
ResultSet rs = dataSource.connection.createStatement().executeQuery(sqlBuffer.toString())
println city +" : "+startDate+" "+endDate +" "+startArea+"-"+endArea println city +" : "+startDate+" "+endDate +" "+startArea+"-"+endArea
def prices = []; def prices = [];
while (rs.next()) { ElasticUtils.executeSqlQuery(sqlBuffer.toString(),{ rs->
def area = (Double) rs.getObject("area") def area = (Double) rs.getObject("area")
def totalPrice = (Integer) rs.getObject("total_price") def totalPrice = (Integer) rs.getObject("total_price")
if(!totalPrice){
continue;
}
if(area <= 25 && area>=500){
continue;
}
def price = totalPrice.toInteger()/area.toDouble(); def price = totalPrice.toInteger()/area.toDouble();
if(price > 1000 && price < 200000){ if(price > 1000 && price < 200000){
prices << price.toInteger() prices << price.toInteger()
} }
} })
return prices; return prices;
} }
def findHouse3(def city,def startDate, def endDate, def endArea){
final StringBuffer sqlBuffer = new StringBuffer()
sqlBuffer.append("SELECT avg(avg_price) as avg_price FROM \"seawater-20*\" WHERE 1=1")
sqlBuffer.append(" and city = '").append(city).append("'")
sqlBuffer.append(" and cat = 'sell'")
sqlBuffer.append(" and p_date >="+startDate).append(" and p_date <="+endDate);
sqlBuffer.append(" and avg_price < 300000")
if(endArea){
if(endArea ==90){
sqlBuffer.append(" and area>=25 and area<90 and total_price>0")
}else if (endArea == 144){
sqlBuffer.append(" and area>=90 and area<144 and total_price>0 ")
}else if (endArea > 144){
sqlBuffer.append(" and area>=144 and total_price>0 ")
}
}
def avg_price = null;
try{
ElasticUtils.executeSqlQuery(sqlBuffer.toString(),{ rs->
avg_price = rs.avg_price
})
}catch(Exception e){
avg_price = findHouse3(city,startDate, endDate, endArea);
println e.getMessage()
}
if(avg_price){
return (int)avg_price;
}
return null
}
def findHouse2(def city,def startDate, def endDate){ def findHouse2(def city,def startDate, def endDate){
@@ -367,20 +427,13 @@ class ImportIndexStats extends BaseBatch{
} }
sqlBuffer.append(" and cat = 'sell'") sqlBuffer.append(" and cat = 'sell'")
sqlBuffer.append(" and p_date >="+startDate).append(" and p_date <="+endDate); sqlBuffer.append(" and p_date >="+startDate).append(" and p_date <="+endDate);
sqlBuffer.append(" ORDER BY p_date desc limit 5000") sqlBuffer.append(" and area>=25 and area<=500 and total_price>0 ORDER BY p_date desc limit 5000")
def priceMap = [:]; def priceMap = [:];
try{ try{
ResultSet rs = dataSource.connection.createStatement().executeQuery(sqlBuffer.toString()) ElasticUtils.executeSqlQuery(sqlBuffer.toString(),{ rs->
while (rs.next()) { def area = rs.area
def area = (Double) rs.getObject("area") def totalPrice = rs.total_price
def totalPrice = (Integer) rs.getObject("total_price")
if(!totalPrice){
continue;
}
if(area <= 25 && area>=500){
continue;
}
def areaKey = ""; def areaKey = "";
if(area>0 && area<90){ if(area>0 && area<90){
@@ -403,7 +456,7 @@ class ImportIndexStats extends BaseBatch{
prices << price.toInteger() prices << price.toInteger()
} }
} })
}catch(Exception e){ }catch(Exception e){
findHouse2(city,startDate, endDate); findHouse2(city,startDate, endDate);
} }
@@ -470,11 +523,12 @@ class ImportIndexStats extends BaseBatch{
} }
def findPriceIndexCitys(def date){ def findPriceIndexCitys(def date){
DBObject q = new BasicDBObject(); DBObject q = new BasicDBObject();
q.put("yearmonth", date); q.put("yearmonth", date.toInteger());
q.put("cat", "district")
DBObject keys = new BasicDBObject(); DBObject keys = new BasicDBObject();
keys.put("city", 1) keys.put("city", 1)
def cursor = on_line.find(q, keys); def cursor = STATS_INDEX_COLL.find(q, keys);
def citys = []; def citys = [];
for(def dbo : cursor){ for(def dbo : cursor){
if(!citys.contains(dbo.city)){ if(!citys.contains(dbo.city)){
@@ -492,8 +546,7 @@ class ImportIndexStats extends BaseBatch{
DBObject keys = new BasicDBObject(); DBObject keys = new BasicDBObject();
keys.put("city", 1) keys.put("city", 1)
def cursor = on_line.find(q, keys); def cursor = STATS_INDEX_COLL.find(q, keys);
def citys = [];
for(def dbo : cursor){ for(def dbo : cursor){
def id = dbo.get("_id"); def id = dbo.get("_id");
return id; return id;
@@ -510,13 +563,13 @@ class ImportIndexStats extends BaseBatch{
dbo.put("cat",result.cat); dbo.put("cat",result.cat);
dbo.put("c_date",new Date()); dbo.put("c_date",new Date());
if(result.markup){ if(result.markup){
dbo.put("new_chain", result.markup.toDouble()); dbo.put("chain", result.markup.toDouble());
} }
if(result.yearMarkup){ if(result.yearMarkup){
dbo.put("new_yeartoyear", result.yearMarkup.toDouble()); dbo.put("yeartoyear", result.yearMarkup.toDouble());
} }
if(result.dingJiMarkup){ if(result.dingJiMarkup){
dbo.put("new_fixedbase", result.dingJiMarkup.toDouble()); dbo.put("fixedbase", result.dingJiMarkup.toDouble());
} }
if(result.areaMarkup90){ if(result.areaMarkup90){
@@ -560,12 +613,151 @@ class ImportIndexStats extends BaseBatch{
if(id){ if(id){
DBObject q = new BasicDBObject() DBObject q = new BasicDBObject()
q.put("_id", id) q.put("_id", id)
on_line.update(q, new BasicDBObject('$set', dbo)); STATS_INDEX_COLL.update(q, new BasicDBObject('$set', dbo));
}else{ }else{
on_line.save(dbo); STATS_INDEX_COLL.save(dbo);
} }
}
def updateDataType(){
def cursor = on_line.find(new BasicDBObject()).batchSize(5000)
def index = 0
for(def d : cursor){
index++
def udata = new BasicDBObject()
udata.put("yearmonth", d.yearmonth.toInteger())
on_line.update(new BasicDBObject("_id", d._id), new BasicDBObject('$set', udata))
println index
}
}
def synch(){
def cursor = on_line.find(new BasicDBObject()).batchSize(5000)
for(def d : cursor){
STATS_INDEX_COLL.save(d)
}
}
def synchTjjIndex(){
def s = "202401"
def startDate = null;
def stop = false;
while(!stop){
startDate = DateUtils.parseFromTightYYYYMM(s);
def year = startDate.getYear()+1900;
def month = startDate.month+1;
def date = createDateString(year, month, 0, "");
createTjjData(date)
println "运行......"+date+".......保存完成"
s = DateUtils.addMonth(date, 1, "yyyyMM")
if(year==2024 && month==8){
stop = true;
}
}
}
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 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 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 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 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
}
STATS_INDEX_COLL.insert(rets)
}
def findTjjIndex(coll, queryStartDate, queryEndDate){
def q = new BasicDBObject()
q.put("date", new BasicDBObject('$gte',queryStartDate).append('$lte', queryEndDate))
def dbcursor = coll.find(q)
def map = [:]
for(def d : dbcursor){
def o = map.get(d.city)
if(!o){
map.put(d.city,d)
}
}
return map;
}
def findTjjAreaIndex(coll,queryStartDate, queryEndDate){
def q = new BasicDBObject()
q.put("date", new BasicDBObject('$gte',queryStartDate).append('$lte', queryEndDate))
def dbcursor = coll.find(q)
def map = [:]
for(def d : dbcursor){
def areaMap = map.get(d.city)
if(!areaMap){
areaMap = [:]
map.put(d.city, areaMap)
}
def o = areaMap.get(d.area)
if(!o){
areaMap.put(d.area, d)
}
}
return map;
} }
} }