设置指导价修改时间

This commit is contained in:
2024-03-01 10:25:53 +08:00
parent 1b8ef57322
commit e993a2d0bc
@@ -1,7 +1,16 @@
import com.fangjia.core.RegionData
import com.fangjia.core.util.GeoUtils
import com.fangjia.core.util.HttpRequest
import com.fangjia.core.util.Mongo3Utils
import com.fangjia.core.util.MongoUtils
import com.fangjia.script.util.CommonUtils
import com.fangjia.script.util.DbUtils
import com.fangjia.script.util.ExcelUtils
import com.mongodb.BasicDBObject
import com.mongodb.client.MongoCollection
import net.sf.json.JSONObject
import org.bson.Document
import org.bson.types.ObjectId
import org.elasticsearch.xpack.sql.jdbc.EsDataSource
import java.sql.Connection
@@ -11,67 +20,43 @@ import java.util.function.Consumer
import static com.mongodb.client.model.Filters.and
import static com.mongodb.client.model.Filters.eq
//REGION_CONN = MongoUtils.getCollectionByName("fangjia", "region_block", MongoUtils.MongoDB_Domain_mongo, MongoUtils.MongoDB_Port_28017);
//TOWNSHIP_CONN = MongoUtils.getCollectionByName("fangjia", "township", MongoUtils.MongoDB_Domain_mongo, MongoUtils.MongoDB_Port_28017);
//TOWNSHIP_CONN.find().each {BasicDBObject township->
// township.area_station = township.central
// township.removeField("central")
// TOWNSHIP_CONN.save(township)
//
//}
//REGION_CONN.find(new BasicDBObject("category", "region")).each {BasicDBObject regionBlock->
// def lng = regionBlock.lng/10000000000l
// def lat = regionBlock.lat/10000000000l
// HttpRequest request = new HttpRequest()
// JSONObject resp = request.getJsonContent("http://localhost:8080/FangJiaAddressService/geocode/township", ['location':"$lng,$lat".toString()], "UTF-8")
// if(resp.result){
// TOWNSHIP_CONN.update(new BasicDBObject("_id", new ObjectId(resp.result.id)), new BasicDBObject('$set', new BasicDBObject('central', 1)))
// println(resp.result)
// }
//}
def cityList = ["上海", "广州", "北京", "深圳", "成都", "杭州", "重庆", "武汉", "西安", "天津"]
def roots = ["lianjia.com", "zhuge.com", "fang.com", "anjuke.com", "58.com", "soufy.cn"]
MongoCollection<Document> DISTRICT_STAT = Mongo3Utils.getDbCollection("fangjia", "district_stat_rent")
MongoCollection<Document> DEAL_PRICE = Mongo3Utils.getDbCollection("fangjia", "deal_price")
def data = [["城市", "区域", "小区名", "版块", "装修", "朝向", "室", "厅", "卫", '标题', '总价', '面积', '单价', '发布时间', '来源']]
cityList.each { def city ->
def statMap = [:]
DISTRICT_STAT.find(and(eq("city", city), eq("end_month_date", Date.parse("yyyyMMdd", "20190228")))).forEach(new Consumer<Document>() {
@Override
void accept(Document t) {
def key = "${t.city}_${t.region}_${t.district_name}_${t.house_type}".toString()
statMap[key] = t.avg_price
}
})
roots.each { def root ->
EsDataSource dataSource = new EsDataSource();
String address = "jdbc:es://http://192.168.0.206:9200/timezone=UTC&page.size=250&connect.timeout=120s&network.timeout=120s&page.timeout=120s"
dataSource.setUrl(address)
Properties connectionProperties = new Properties()
connectionProperties.put("user", "developer")
connectionProperties.put("password", "5e8edd851d2fdfbd7415232c67367cc3")
dataSource.setProperties(connectionProperties)
Connection connection = dataSource.getConnection()
Statement statement = connection.createStatement()
ResultSet rs = statement.executeQuery("""select * from "seawater-2019" where city='${city}' and cat = 'rent' order by p_date""")
int count = 0
while (rs.next()) {
String region = rs.getString("region")
String district_name = rs.getString("district_name")
int room = rs.getInt("room")
def key = "${city}_${region}_${district_name}_${room}".toString()
if (!statMap.containsKey(key)) {
continue
}
int total_price = rs.getInt("total_price")
double area = rs.getDouble("area")
int avg_price = (int) (total_price / area)
if (total_price * 1.3 || total_price < statMap[key] * 0.7) {
continue
}
String block = rs.getString("block")
String name = rs.getString("name")
String fitment = rs.getString("fitment")
String direction = rs.getString("direction")
int hall = rs.getInt("hall")
int toilet = rs.getInt("toilet")
int p_date = rs.getInt("p_date")
if (!block || !name || !fitment || !direction || room == 0 || hall == 0 || toilet == 0) {
continue
}
println(rs.getString('url'))
def item = [city, region, district_name, block, fitment, direction, room, hall, toilet, name, total_price, area, avg_price, p_date, root]
println(item)
data << item
count++
if(count > 10){
break
}
}
}
}
ExcelUtils.write("D:\\建设银行\\租金样本.xlsx", data, "结果")
//CommonUtils.findAllCity().each {def city->
// DbUtils.multiThreadingExecuteQueryOnSeaweed(DbUtils.buildSeaweedQuery(city, null, null, "district"),{BasicDBObject office->
// if(!office.township){
// def lng = office.lng/10000000000l
// def lat = office.lat/10000000000l
// HttpRequest request = new HttpRequest()
// JSONObject resp = request.getJsonContent("http://localhost:8080/FangJiaAddressService/geocode/township", ['location':"$lng,$lat".toString()], "UTF-8")
// if(resp.result){
// println(office._id.toString() + "\t" + office.township + "\t-->\t" + resp.result.streetName)
// DbUtils.seaweed.update(new BasicDBObject("_id", office._id), new BasicDBObject('$set', new BasicDBObject('township', resp.result.streetName)))
// }
// }
// })
//}
ExcelUtils.multiThreadingModify("C:\\Users\\goojia\\Desktop\\地图查询数据导出-添加经纬度-兴趣点.xlsx",{List item->
def lng = item["AB"].toString().split(",")[0].toDouble()
def lat = item["AB"].toString().split(",")[1].toDouble()
item["AD"] = GeoUtils.calculateDistance(121.526672,31.142637,lng, lat)
println(item)
})