移除房价网钉钉消息
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
package com.fangjia.script.util
|
||||
|
||||
/**
|
||||
* POI查询结果数据类
|
||||
*/
|
||||
class PoiSearchResult {
|
||||
// 总数量
|
||||
long totalCount
|
||||
|
||||
// 最近距离(米)
|
||||
Double minDistanceMeters
|
||||
|
||||
// 最近的N个POI列表
|
||||
List<PoiInfo> nearestPois = []
|
||||
|
||||
// 类型分布统计
|
||||
Map<String, Long> typeDistribution = [:]
|
||||
|
||||
// 主类型分布统计
|
||||
Map<Integer, Long> mainTypeDistribution = [:]
|
||||
|
||||
// 区域分布统计
|
||||
Map<String, Long> districtDistribution = [:]
|
||||
|
||||
@Override
|
||||
String toString() {
|
||||
return super.toString()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package com.fangjia.script.util
|
||||
|
||||
import org.apache.http.HttpHost
|
||||
import org.apache.http.auth.AuthScope
|
||||
import org.apache.http.auth.UsernamePasswordCredentials
|
||||
import org.apache.http.client.CredentialsProvider
|
||||
import org.apache.http.client.config.RequestConfig
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
|
||||
import org.elasticsearch.action.search.SearchRequest
|
||||
import org.elasticsearch.action.search.SearchResponse
|
||||
import org.elasticsearch.client.RequestOptions
|
||||
import org.elasticsearch.client.RestClient
|
||||
import org.elasticsearch.client.RestClientBuilder
|
||||
import org.elasticsearch.client.RestHighLevelClient
|
||||
import org.elasticsearch.common.unit.DistanceUnit
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder
|
||||
import org.elasticsearch.index.query.QueryBuilders
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder
|
||||
import org.elasticsearch.search.sort.SortBuilders
|
||||
import org.elasticsearch.search.sort.SortOrder
|
||||
import org.elasticsearch.xpack.sql.jdbc.EsDataSource
|
||||
|
||||
public class PoiUtils {
|
||||
|
||||
static RestHighLevelClient client = getClient()
|
||||
|
||||
static RestHighLevelClient getClient() {
|
||||
RestClientBuilder builder = RestClient.builder(new HttpHost("192.168.0.89", 9200, "http"));
|
||||
builder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
|
||||
@Override
|
||||
RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
|
||||
requestConfigBuilder.setConnectionRequestTimeout(1000 * 60);
|
||||
requestConfigBuilder.setSocketTimeout(1000 * 180);
|
||||
return requestConfigBuilder;
|
||||
}
|
||||
})
|
||||
builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
|
||||
@Override
|
||||
HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {
|
||||
httpAsyncClientBuilder.disableAuthCaching();
|
||||
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "elasticsearch"));
|
||||
httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
|
||||
return httpAsyncClientBuilder;
|
||||
}
|
||||
})
|
||||
return new RestHighLevelClient(builder)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度搜索POI
|
||||
* @param city
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @param tags
|
||||
* @param distance
|
||||
* @param maxResults
|
||||
* @return
|
||||
*/
|
||||
public static PoiSearchResult searchPoi(String city, Double lng, Double lat, List<String> tags =[],String distance = "1km", int maxResults = 20) {
|
||||
PoiSearchResult poiSearchResult = null
|
||||
SearchResponse response = null
|
||||
try {
|
||||
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder()
|
||||
// 构建查询条件
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
|
||||
|
||||
// 地理位置查询
|
||||
boolQuery.must(QueryBuilders.geoDistanceQuery("location")
|
||||
.point(lat, lng)
|
||||
.distance(distance))
|
||||
|
||||
boolQuery.must(QueryBuilders.termQuery("city", city))
|
||||
if(!tags.isEmpty()){
|
||||
boolQuery.must(QueryBuilders.termsQuery("small_type", tags))
|
||||
}
|
||||
sourceBuilder.trackTotalHits(true) // 强制追踪总数
|
||||
// boolQuery.must(QueryBuilders.termQuery("status", "0"))
|
||||
sourceBuilder.query(boolQuery)
|
||||
sourceBuilder.sort(SortBuilders.geoDistanceSort("location", lat, lng)
|
||||
.order(SortOrder.ASC)
|
||||
.unit(DistanceUnit.METERS))
|
||||
sourceBuilder.size(maxResults)
|
||||
SearchRequest searchRequest = new SearchRequest("didata_map_poi_shards")
|
||||
searchRequest.source(sourceBuilder)
|
||||
response = client.search(searchRequest, RequestOptions.DEFAULT)
|
||||
poiSearchResult = parseSearchResponse(response)
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("根据名称搜索POI失败: ${e.message}", e)
|
||||
}finally {
|
||||
|
||||
}
|
||||
return poiSearchResult
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析搜索响应
|
||||
*/
|
||||
private static PoiSearchResult parseSearchResponse(SearchResponse response) {
|
||||
PoiSearchResult result = new PoiSearchResult()
|
||||
// 总数量
|
||||
result.totalCount = response.hits.totalHits.value
|
||||
// 最近的POI列表
|
||||
result.nearestPois = parsePoiInfos(response, true)
|
||||
if(result.nearestPois.size() > 0){
|
||||
result.minDistanceMeters = result.nearestPois[0].distanceMeters
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析POI信息列表
|
||||
*/
|
||||
private static List<PoiInfo> parsePoiInfos(SearchResponse response, boolean includeDistance = true) {
|
||||
List<PoiInfo> pois = []
|
||||
response.hits.hits.each { hit ->
|
||||
def source = hit.sourceAsMap
|
||||
PoiInfo poi = new PoiInfo(
|
||||
id: source.id,
|
||||
name: source.name,
|
||||
type: source.type,
|
||||
cat: source.cat,
|
||||
mainType: source.main_type as Integer,
|
||||
secondaryType: source.secondary_type,
|
||||
smallType: source.small_type,
|
||||
address: source.address,
|
||||
city: source.city,
|
||||
district: source.district,
|
||||
province: source.province,
|
||||
location: source.location as Map,
|
||||
dataSource: source.data_source,
|
||||
status: source.status
|
||||
)
|
||||
// 添加距离信息
|
||||
if (includeDistance && hit.sortValues && hit.sortValues.length > 0) {
|
||||
// 距离通常是最后一个排序字段
|
||||
def distanceValue = hit.sortValues[hit.sortValues.length - 1]
|
||||
if (distanceValue instanceof Number) {
|
||||
poi.distanceMeters = (int)distanceValue.doubleValue()
|
||||
}
|
||||
}
|
||||
pois.add(poi)
|
||||
}
|
||||
return pois
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void main(String[] args) {
|
||||
PoiSearchResult result = PoiUtils.searchPoi("上海市", 121.19563,31.296209, ["便民商店/便利店","7-ELEVEn便利店","OK便利店"])
|
||||
println(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PoiInfo {
|
||||
String id
|
||||
String name
|
||||
String type
|
||||
String cat
|
||||
Integer mainType
|
||||
String secondaryType
|
||||
String smallType
|
||||
String address
|
||||
String city
|
||||
String district
|
||||
String province
|
||||
Map<String, Object> location
|
||||
Integer distanceMeters
|
||||
String dataSource
|
||||
String status
|
||||
}
|
||||
|
||||
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package com.fangjia.script.wenyan.temp
|
||||
|
||||
import com.fangjia.core.util.DataUtil
|
||||
import com.fangjia.script.util.ExcelUtils
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
|
||||
|
||||
public static Double normalize(Double orgValue, double min, double max) {
|
||||
if (min > max) {
|
||||
throw new IllegalArgumentException("min should be less than or equal to max");
|
||||
}
|
||||
if(orgValue == null){
|
||||
return null;
|
||||
}
|
||||
double value = orgValue;
|
||||
// 大于 max:不断除以 2,直到 ≤ max
|
||||
while (value > max) {
|
||||
value /= 2.0;
|
||||
}
|
||||
|
||||
// 小于 min:不断乘以 2,直到 ≥ min
|
||||
while (value < min) {
|
||||
if(value < 0){
|
||||
value /= 2.0;
|
||||
}else{
|
||||
value *= 2.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return DataUtil.roundDouble(value, 2);
|
||||
}
|
||||
//def map1 =[:]
|
||||
//ExcelUtils.read("C:\\Users\\goojia\\Desktop\\楼盘评级\\楼盘数据2.xlsx").each {
|
||||
// map1[it[0]] = it[1]
|
||||
//}
|
||||
//ExcelUtils.multiThreadingModify("C:\\Users\\goojia\\Desktop\\楼盘评级\\估家科技楼盘评级数据测试反馈.xlsx",{List item->
|
||||
// item["X"] = map1.getOrDefault(item["A"],null)
|
||||
// if(item["X"]){
|
||||
// DataUtil.roundDouble(item["X"],2)
|
||||
// }
|
||||
//}, 1)
|
||||
//
|
||||
//ExcelUtils.multiThreadingModify("C:\\Users\\goojia\\Desktop\\楼盘评级\\估家科技楼盘评级数据测试反馈.xlsx",{List item->
|
||||
// item["X"] = map1.getOrDefault(item["A"],null)
|
||||
// if(item["X"]){
|
||||
// DataUtil.roundDouble(item["X"],2)
|
||||
// }
|
||||
//}, 3)
|
||||
|
||||
//ExcelUtils.multiThreadingModify("C:\\Users\\goojia\\Desktop\\楼盘评级\\估家科技楼盘评级数据测试反馈.xlsx",{List item->
|
||||
// def row = "l"
|
||||
// if(!(item[row] instanceof Double) && StringUtils.isBlank(item[row])){
|
||||
// item[ row] = null
|
||||
// }
|
||||
// if(item[row] && item[row] instanceof String){
|
||||
// println("---" + item)
|
||||
// }
|
||||
// item[row] = normalize(item[row], -30, 20);
|
||||
//
|
||||
//},0)
|
||||
//ExcelUtils.multiThreadingModify("C:\\Users\\goojia\\Desktop\\楼盘评级\\估家科技楼盘评级数据测试反馈.xlsx",{List item->
|
||||
// def row = "l"
|
||||
// if(!(item[row] instanceof Double) && StringUtils.isBlank(item[row])){
|
||||
// item[ row] = null
|
||||
// }
|
||||
// if(item[row] && item[row] instanceof String){
|
||||
// println("---" + item)
|
||||
// }
|
||||
// item[row] = normalize(item[row], -30, 20);
|
||||
//},1)
|
||||
ExcelUtils.multiThreadingModify("C:\\Users\\goojia\\Desktop\\楼盘评级\\估家科技楼盘评级数据测试反馈V3.xlsx",{List item->
|
||||
def row = "l"
|
||||
if(!(item[row] instanceof Double) && StringUtils.isBlank(item[row])){
|
||||
item[ row] = null
|
||||
}
|
||||
if(item[row] && item[row] instanceof String){
|
||||
println("---" + item)
|
||||
}
|
||||
item[row] = normalize(item[row], -30, 13);
|
||||
},2)
|
||||
ExcelUtils.multiThreadingModify("C:\\Users\\goojia\\Desktop\\楼盘评级\\估家科技楼盘评级数据测试反馈V3.xlsx",{List item->
|
||||
def row = "l"
|
||||
if(!(item[row] instanceof Double) && StringUtils.isBlank(item[row])){
|
||||
item[ row] = null
|
||||
}
|
||||
if(item[row] && item[row] instanceof String){
|
||||
println("---" + item)
|
||||
}
|
||||
item[row] = normalize(item[row], -30, 13);
|
||||
},3)
|
||||
Reference in New Issue
Block a user