Merge remote-tracking branch 'origin/master'
This commit is contained in:
+2
-5
@@ -747,11 +747,8 @@ public class ComprehensiveQueryController {
|
||||
districtPriceMap.put("city", district.getCity());
|
||||
districtPriceMap.put("district", district.getRegion());
|
||||
districtPriceMap.put("name", district.getName());
|
||||
if (evaluation.getAvgPrice2b() != null && evaluation.getAvgPrice2b() != 0) {
|
||||
districtPriceMap.put("avgPrice", evaluation.getAvgPrice2b());
|
||||
} else {
|
||||
districtPriceMap.put("avgPrice", evaluation.getAvgPrice());
|
||||
}
|
||||
// 估值中已经取过评估2B价格,且经过系数调整,不能在覆盖
|
||||
districtPriceMap.put("avgPrice", evaluation.getAvgPrice());
|
||||
Long totalPrice = new BigDecimal((Integer)districtPriceMap.get("avgPrice")).multiply(new BigDecimal(evaluation.getArea())).longValue();
|
||||
districtPriceMap.put("totalPrice", totalPrice);
|
||||
|
||||
|
||||
+4
-2
@@ -752,7 +752,9 @@ public class PropertyController {
|
||||
districtInfoDto.setDistrict(district.getRegion());
|
||||
districtInfoDto.setName(district.getName());
|
||||
districtInfoDto.setAddress(district.getAddress());
|
||||
int avgPrice = districtStatService.findLatestDistrictAvgPrice(new DistrictKey(district), null);
|
||||
//int avgPrice = districtStatService.findLatestDistrictAvgPrice(new DistrictKey(district), null);
|
||||
// 返回2B价格,小程序用,其他也改为2B
|
||||
int avgPrice = districtStatService.findLatestDistrictAvgPrice2B(new DistrictKey(district), null);
|
||||
if (avgPrice != 0) {
|
||||
districtInfoDto.setAvgPrice(avgPrice);
|
||||
}
|
||||
@@ -2427,7 +2429,7 @@ public class PropertyController {
|
||||
item.put("city", districtStat.getCity());
|
||||
item.put("district", districtStat.getRegion());
|
||||
item.put("name", districtStat.getDistrictName());
|
||||
item.put("avgPrice", districtStat.getAvgPrice());
|
||||
item.put("avgPrice", districtStat.getAvg_price_2b());
|
||||
if ("monthly".equals(model.getPeriodType())) {
|
||||
item.put("date", DateUtil.formatByPattern(districtStat.getWeekend(), "yyyy-MM"));
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -559,7 +559,7 @@ public class DistrictTrendController {
|
||||
DistrictStat ds = districtStatMap.get(key);
|
||||
JSONArray ja = new JSONArray();
|
||||
ja.put(DateUtil.getBeforeDay(ds.getWeekend(), -1).getTime());
|
||||
ja.put(ds.getAvgPrice());
|
||||
ja.put(ds.getAvg_price_2b());
|
||||
districtJa.put(ja);
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ public class DistrictTrendController {
|
||||
DistrictStat ds = villaDistrictStatMap.get(key);
|
||||
JSONArray ja = new JSONArray();
|
||||
ja.put(DateUtil.getBeforeDay(ds.getWeekend(), -1).getTime());
|
||||
ja.put(ds.getAvgPrice());
|
||||
ja.put(ds.getAvg_price_2b());
|
||||
villaJa.put(ja);
|
||||
}
|
||||
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
package com.fangjia.script.dealPrice
|
||||
|
||||
import com.fangjia.core.util.MongoUtils
|
||||
import com.fangjia.script.gj.xiamen.ElasticUtils89
|
||||
import com.fangjia.script.util.ElasticUtils
|
||||
import com.mongodb.AggregationOutput
|
||||
import com.mongodb.BasicDBObject
|
||||
import com.mongodb.DBCollection
|
||||
import com.mongodb.DBObject
|
||||
import org.elasticsearch.action.bulk.BulkRequest
|
||||
import org.elasticsearch.action.bulk.BulkResponse
|
||||
import org.elasticsearch.action.index.IndexRequest
|
||||
import org.elasticsearch.action.support.WriteRequest
|
||||
import org.elasticsearch.client.RequestOptions
|
||||
import org.elasticsearch.common.xcontent.XContentType
|
||||
|
||||
class SynchDealPriceToEs {
|
||||
static DBCollection dealPriceConn = MongoUtils.getCollectionByName("fangjia", "deal_price", "192.168.0.43",28017)
|
||||
|
||||
static main(args) {
|
||||
def task = new SynchDealPriceToEs()
|
||||
task.run()
|
||||
}
|
||||
|
||||
def run(){
|
||||
def batchsize = 2000
|
||||
def citys = getCityCount()
|
||||
citys.each{city,count->
|
||||
def dbcursor = dealPriceConn.find(new BasicDBObject("city", city)).batchSize(batchsize)
|
||||
def ret = []
|
||||
for(def o : dbcursor){
|
||||
ret << o
|
||||
}
|
||||
save(ret)
|
||||
// def index = 0
|
||||
// for(def d : dbcursor){
|
||||
// ret << d
|
||||
// if(ret.size()>=2000){
|
||||
// save(ret)
|
||||
// ret.clear()
|
||||
// index ++
|
||||
// println index
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getCityCount(){
|
||||
|
||||
BasicDBObject match = null;
|
||||
// 定义聚合管道,按 city 字段分组,并计算每个城市的数量
|
||||
DBObject groupFields = new BasicDBObject();
|
||||
|
||||
// match = new BasicDBObject('$match', new BasicDBObject("level", "城市"));
|
||||
groupFields.put("_id", new BasicDBObject("city",'$city'))
|
||||
|
||||
groupFields.put("count", new BasicDBObject('$sum', 1));
|
||||
DBObject group = new BasicDBObject('$group', groupFields);
|
||||
|
||||
// 执行聚合查询
|
||||
AggregationOutput output = dealPriceConn.aggregate(Arrays.asList(group));
|
||||
def map = [:]
|
||||
// 遍历结果
|
||||
for (DBObject result : output.results()) {
|
||||
def obj = (DBObject ) result.get("_id");
|
||||
if(obj.get("city")) {
|
||||
int count = (Integer) result.get("count");
|
||||
map.put(obj.get("city"), count)
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
def save(rows){
|
||||
BulkRequest request = new BulkRequest();
|
||||
int batchSize = 500;
|
||||
int processedCount = 0;
|
||||
def client = ElasticUtils.getClient("192.168.0.206")
|
||||
|
||||
for(def map : rows){
|
||||
// def map = rows.get(key)
|
||||
def data_id = map._id.toString()
|
||||
map.remove("_id")
|
||||
request.add(new IndexRequest("deal_price", "_doc", data_id).source(map, XContentType.JSON));
|
||||
|
||||
// 批量提交数据
|
||||
if (request.numberOfActions() >= batchSize) {
|
||||
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
|
||||
if (bulkResponse.hasFailures()) {
|
||||
// 处理错误
|
||||
print "Bulk request has failures: " + bulkResponse.buildFailureMessage()
|
||||
} else {
|
||||
processedCount += request.numberOfActions();
|
||||
println "Processed " + processedCount + " documents "+new Date().format("yyyy-MM-dd HH:mm:ss")
|
||||
}
|
||||
|
||||
request = new BulkRequest();
|
||||
}
|
||||
}
|
||||
|
||||
if (request.numberOfActions() > 0) {
|
||||
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
|
||||
if (bulkResponse.hasFailures()) {
|
||||
// 处理错误
|
||||
println "Bulk request has failures: " + bulkResponse.buildFailureMessage()
|
||||
} else {
|
||||
processedCount += request.numberOfActions();
|
||||
println "Processed " + processedCount + " documents"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -360,7 +360,7 @@ class NewGaoDePoiBatch extends BaseBatch{
|
||||
def index = 0
|
||||
for(def cityObj : cityList){
|
||||
index ++
|
||||
if(index <140){
|
||||
if(index <291){
|
||||
continue
|
||||
}
|
||||
def fileName = "/home/goojia/gj/poi/old_poi/merge_poi/${cityObj.city}.csv"
|
||||
|
||||
+11
@@ -295,6 +295,17 @@ public interface DistrictStatService {
|
||||
* @return
|
||||
*/
|
||||
public int findLatestDistrictAvgPrice(DistrictKey districtKey,Date weekend);
|
||||
|
||||
/**
|
||||
* 获得指定时间的小区均价2B
|
||||
*
|
||||
* @param districtKey
|
||||
* @param weekend
|
||||
* @return
|
||||
*/
|
||||
int findLatestDistrictAvgPrice2B(DistrictKey districtKey,Date weekend);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+46
@@ -1524,6 +1524,52 @@ public class DistrictStatServiceImpl implements DistrictStatService {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findLatestDistrictAvgPrice2B(DistrictKey districtKey, Date weekend) {
|
||||
if (weekend == null) {
|
||||
weekend = DateUtil.getFirstDayOfWeek(new Date());
|
||||
}
|
||||
String cacheKey = districtKey.getCity() + "_" + districtKey.getRegion() + "_" + districtKey.getName() + "_2B_" + DateUtil.formatToYYMMDD(weekend);
|
||||
Object obj = CacheUtils.getValue(this.getClass(), cacheKey);
|
||||
if (obj != null) {
|
||||
return (Integer)obj;
|
||||
}
|
||||
Integer value = doFindLatestDistrictAvgPrice2B(districtKey, weekend);
|
||||
CacheUtils.putValue(CachePolicyEnum.LONG, this.getClass(), cacheKey, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public Integer doFindLatestDistrictAvgPrice2B(DistrictKey districtKey, Date weekend){
|
||||
|
||||
DistrictStatBo statBo = districtStatService.findDistrictStat(districtKey);
|
||||
if (statBo != null && statBo.getDefaultDistrictStat() != null) {
|
||||
if (statBo.getDefaultDistrictStat().getAvg_price_2b() > 0) {
|
||||
return statBo.getDefaultDistrictStat().getAvg_price_2b();
|
||||
}
|
||||
if (statBo.getDefaultDistrictStat().getAvgPrice() > 0) {
|
||||
return statBo.getDefaultDistrictStat().getAvgPrice();
|
||||
}
|
||||
}
|
||||
|
||||
double r = AveragerUtil.getFloatingRate(districtKey, weekend);
|
||||
if (StringUtils.isNotBlank(districtKey.getCity()) && StringUtils.isNotBlank(districtKey.getRegion())) {
|
||||
RegionStat regionStat = regionStatService.findRegionStat(districtKey.getCity(), districtKey.getRegion(), null);
|
||||
if (regionStat != null) {
|
||||
return (int) (regionStat.getAvgPrice() * r);
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(districtKey.getCity())) {
|
||||
RegionStat regionStat = regionStatService.findRegionStat(districtKey.getCity(), null, null);
|
||||
if (regionStat != null) {
|
||||
return (int) (regionStat.getAvgPrice() * r);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
public Integer doFindLatestDistrictAvgPrice(DistrictKey districtKey, Date weekend){
|
||||
|
||||
DistrictStatBo statBo = districtStatService.findDistrictStat(districtKey);
|
||||
|
||||
Reference in New Issue
Block a user