新增易方达接口以及添加claude技能
This commit is contained in:
@@ -2,12 +2,18 @@ package com.fangjia.core;
|
||||
|
||||
public interface Constants {
|
||||
|
||||
/** 数据库主库*/
|
||||
String FANGJIA_MONGO_URI = "mongodb://developer:G00IDCDEV12385@mongo.db.fangjia.com:28017";
|
||||
String TEST_FANGJIA_MONGO_URI = "mongodb://developer:G00IDCDEV12385@192.168.0.136:28017";
|
||||
String FANGJIA_CRAWL_MONGO_URI = "mongodb://192.168.0.235:27018";
|
||||
/** 日志数据库*/
|
||||
String LOG_MONGO_URI = "mongodb://192.168.0.42:52002";
|
||||
String SEABIRD_MONGO_URI = "mongodb://192.168.0.74:57007";
|
||||
/** 线下归档数据库*/
|
||||
String SEAWATER_MONGO_URI = "mongodb://root:Goojia%40206!!#@192.168.0.206:27020";
|
||||
String MSVC_FANG_JIA_DATA_SERVICE_BASE_PATH ="http://192.168.0.100:38080/FangJiaDataService";
|
||||
/** OpenApi测试账户生成的超级Token*/
|
||||
String SUPER_USER_TOKEN = "F54F52381C49BB9EB4A33EB1B65604AE4B71A28AEE53518A94A2F360408B9056D57553931D15CE6DDE765562DAD286BA38E05A4CDAFC51C3D527A4959BF8E75A3B95DB7108FCEA340DDE61925616DB55118E1851E67D83EAD800460D100D6B667A4ED8EE67C8F7FB";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.fangjia.open.controllers;
|
||||
|
||||
import com.fangjia.open.interceptors.Authority;
|
||||
import com.fangjia.open.interceptors.Role;
|
||||
import com.fangjia.open.model.BasicModel;
|
||||
import com.fangjia.open.model.RestfulModelAndView;
|
||||
import com.fangjia.service.dto.UniversalDto;
|
||||
import com.fangjia.service.efund.EfundMatchService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.sothis.web.mvc.annotation.Param;
|
||||
|
||||
/**
|
||||
* E基金地址匹配接口Controller
|
||||
* @author wenyan
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public class EfundController {
|
||||
|
||||
private EfundMatchService efundMatchService;
|
||||
|
||||
/**
|
||||
* E基金地址匹配接口
|
||||
* 根据地址进行匹配,返回房价信息和地址类型标签
|
||||
*
|
||||
* @param address 地址字符串
|
||||
* @param city 城市名称(可选)
|
||||
* @return 匹配结果JSON
|
||||
*/
|
||||
public RestfulModelAndView matchAction(@Param(name = "address") String address, @Param(name = "city") String city) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
|
||||
// 参数校验
|
||||
if (StringUtils.isBlank(address)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("address参数不能为空"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
// 调用Service进行地址匹配
|
||||
UniversalDto result = efundMatchService.matchAddress(address, city);
|
||||
|
||||
if (result == null || result.isEmpty()) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("地址匹配失败"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
// 返回成功结果
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(result));
|
||||
return mav;
|
||||
}
|
||||
|
||||
public void setEfundMatchService(EfundMatchService efundMatchService) {
|
||||
this.efundMatchService = efundMatchService;
|
||||
}
|
||||
}
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
package com.fangjia.script.opentest
|
||||
|
||||
import com.fangjia.core.Constants
|
||||
import com.fangjia.core.util.HttpRequest
|
||||
import com.fangjia.script.util.ExcelUtils
|
||||
import net.sf.json.JSONObject
|
||||
|
||||
/**
|
||||
* E基金地址匹配接口 - 接口测试脚本
|
||||
* 功能:使用ExcelUtils.multiThreadingModify多线程调用接口,记录结果、耗时和异常信息
|
||||
* @author wenyan
|
||||
*/
|
||||
|
||||
println "========== E基金接口测试 =========="
|
||||
println "开始时间:${new Date()}"
|
||||
|
||||
try {
|
||||
// 1. 定义数据目录和文件路径
|
||||
String scriptDir = new File(getClass().protectionDomain.codeSource.location.path).parent
|
||||
String dataDir = new File(scriptDir, "data").absolutePath
|
||||
String inputFile = "${dataDir}${File.separator}efund_test_data.xlsx"
|
||||
String outputFile = "${dataDir}${File.separator}efund_test_result.xlsx"
|
||||
|
||||
println "测试数据文件:${inputFile}"
|
||||
println "结果输出文件:${outputFile}"
|
||||
|
||||
// 检查测试数据文件是否存在
|
||||
if (!new File(inputFile).exists()) {
|
||||
println "\n错误:测试数据文件不存在!"
|
||||
println "请先运行 EfundTestDataExtractor.groovy 提取测试数据"
|
||||
return
|
||||
}
|
||||
|
||||
// 2. 读取测试数据并准备结果Excel
|
||||
println "\n正在准备测试数据..."
|
||||
List<List<Object>> allData = ExcelUtils.read(inputFile, 0, 0) // 读取所有数据(包括表头)
|
||||
|
||||
if (allData.size() <= 1) {
|
||||
println "警告:测试数据为空!"
|
||||
return
|
||||
}
|
||||
|
||||
println "共 ${allData.size() - 1} 条测试数据"
|
||||
|
||||
// 3. 修改表头,添加结果列
|
||||
allData[0] = ["序号", "城市", "地址", "返回城市", "返回区域", "返回街道","返回道路","返回门牌号",
|
||||
"小区名称", "物业类型", "匹配级别", "匹配置信度",
|
||||
"参考价格", "典型总价", "更新时间", "耗时(ms)", "异常信息"]
|
||||
|
||||
// 4. 为每一行数据添加空的结果列
|
||||
for (int i = 1; i < allData.size(); i++) {
|
||||
List row = allData[i]
|
||||
// 添加12个结果列(从"返回城市"到"异常信息")
|
||||
(3..14).each { row << "" }
|
||||
}
|
||||
|
||||
// 5. 写入初始结果文件
|
||||
println "正在创建结果文件..."
|
||||
ExcelUtils.write(outputFile, allData, "测试结果")
|
||||
println "结果文件创建成功!"
|
||||
|
||||
// 6. 使用 ExcelUtils.multiThreadingModify 多线程调用接口
|
||||
println "\n开始多线程测试接口..."
|
||||
println "接口地址:http://localhost:9180/efund/match"
|
||||
println "线程数:CPU核心数 × 4 = ${Runtime.getRuntime().availableProcessors() * 4}"
|
||||
|
||||
ExcelUtils.multiThreadingModify(outputFile, { List row ->
|
||||
HttpRequest request = new HttpRequest()
|
||||
long startTime = System.currentTimeMillis()
|
||||
|
||||
try {
|
||||
// 提取参数(row[0]=序号, row[1]=城市, row[2]=地址)
|
||||
String city = row[1]?.toString() ?: ""
|
||||
String address = row[2]?.toString() ?: ""
|
||||
|
||||
// 调用接口
|
||||
Map<String, String> params = ["address": address, "token": Constants.SUPER_USER_TOKEN]
|
||||
if (city) {
|
||||
params.put("city", city)
|
||||
}
|
||||
|
||||
String response = request.get("http://localhost:9180/efund/match", params, "UTF-8")
|
||||
long duration = System.currentTimeMillis() - startTime
|
||||
|
||||
// 解析响应
|
||||
JSONObject json = JSONObject.fromObject(response)
|
||||
Integer code = json.optInt("code")
|
||||
JSONObject result = json.optJSONObject("result")
|
||||
|
||||
if (code == 200 && result != null) {
|
||||
// 填充结果列(直接修改row)
|
||||
row[3] = result.optString("city", "")
|
||||
row[4] = result.optString("district", "")
|
||||
row[5] = result.optString("street", "")
|
||||
row[6] = result.optString("road", "")
|
||||
row[7] = result.optString("road_number", "")
|
||||
row[8] = result.optString("community_name", "")
|
||||
row[9] = result.optString("property_type", "")
|
||||
row[10] = result.optString("match_level", "")
|
||||
row[11] = result.opt("match_confidence") ?: ""
|
||||
row[12] = result.opt("reference_price") ?: ""
|
||||
row[13] = result.opt("typical_total_price") ?: ""
|
||||
row[14] = result.optString("update_time", "")
|
||||
row[15] = duration
|
||||
row[16] = "" // 无异常
|
||||
} else {
|
||||
// 接口返回异常
|
||||
row[15] = duration
|
||||
String msg = json.optString("msg", "")
|
||||
row[16] = "接口返回错误(code=${code}): ${msg}"
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
long duration = System.currentTimeMillis() - startTime
|
||||
row[15] = duration
|
||||
row[16] = "异常: ${e.class.simpleName} - ${e.message}"
|
||||
}
|
||||
}, 0, "测试结果")
|
||||
|
||||
// 7. 统计结果
|
||||
println "\n正在统计测试结果..."
|
||||
List<List<Object>> finalData = ExcelUtils.read(outputFile, 0, 0)
|
||||
|
||||
int totalCount = finalData.size() - 1 // 减去表头
|
||||
int successCount = 0
|
||||
int failCount = 0
|
||||
long totalTime = 0
|
||||
|
||||
Map<String, Integer> timeDist = [
|
||||
"<100ms": 0,
|
||||
"100-200ms": 0,
|
||||
"200-500ms": 0,
|
||||
"500-1000ms": 0,
|
||||
">1000ms": 0
|
||||
]
|
||||
|
||||
for (int i = 1; i < finalData.size(); i++) {
|
||||
List row = finalData[i]
|
||||
|
||||
// 统计成功/失败
|
||||
String errorMsg = row[14]?.toString() ?: ""
|
||||
if (errorMsg == "") {
|
||||
successCount++
|
||||
|
||||
// 统计耗时
|
||||
if (row[13] instanceof Number) {
|
||||
int duration = ((Number)row[13]).intValue()
|
||||
totalTime += duration
|
||||
|
||||
// 耗时分布
|
||||
if (duration < 100) timeDist["<100ms"]++
|
||||
else if (duration < 200) timeDist["100-200ms"]++
|
||||
else if (duration < 500) timeDist["200-500ms"]++
|
||||
else if (duration < 1000) timeDist["500-1000ms"]++
|
||||
else timeDist[">1000ms"]++
|
||||
}
|
||||
} else {
|
||||
failCount++
|
||||
}
|
||||
}
|
||||
|
||||
// 8. 保存统计数据到新Sheet
|
||||
println "\n正在保存统计数据到Excel..."
|
||||
List<List<Object>> statsData = []
|
||||
|
||||
// 基本统计
|
||||
statsData << ["统计项", "数值"]
|
||||
statsData << ["测试时间", new Date().format("yyyy-MM-dd HH:mm:ss")]
|
||||
statsData << ["", ""]
|
||||
statsData << ["总测试数", totalCount]
|
||||
statsData << ["成功数", successCount]
|
||||
statsData << ["失败数", failCount]
|
||||
statsData << ["成功率", totalCount > 0 ? String.format('%.2f%%', successCount * 100.0 / totalCount) : '0.00%']
|
||||
|
||||
if (successCount > 0) {
|
||||
int avgTime = (totalTime / successCount).intValue()
|
||||
statsData << ["", ""]
|
||||
statsData << ["平均耗时(ms)", avgTime]
|
||||
|
||||
// 耗时分布
|
||||
statsData << ["", ""]
|
||||
statsData << ["耗时分布", "数量"]
|
||||
timeDist.each { range, count ->
|
||||
statsData << [range, count]
|
||||
}
|
||||
}
|
||||
|
||||
// 添加统计Sheet
|
||||
ExcelUtils.write(outputFile, statsData, "统计数据")
|
||||
|
||||
// 9. 控制台输出统计结果
|
||||
println "\n========== 测试完成 =========="
|
||||
println "总测试数:${totalCount}"
|
||||
println "成功数:${successCount}"
|
||||
println "失败数:${failCount}"
|
||||
println "成功率:${totalCount > 0 ? String.format('%.2f%%', successCount * 100.0 / totalCount) : '0.00%'}"
|
||||
|
||||
if (successCount > 0) {
|
||||
int avgTime = (totalTime / successCount).intValue()
|
||||
println "平均耗时:${avgTime} ms"
|
||||
|
||||
println "\n耗时分布:"
|
||||
timeDist.each { range, count ->
|
||||
if (count > 0) {
|
||||
println " ${range}: ${count} 条"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println "\n结果文件:${outputFile}"
|
||||
println " - Sheet1: 测试结果(详细数据)"
|
||||
println " - Sheet2: 统计数据(汇总信息)"
|
||||
|
||||
} catch (Exception e) {
|
||||
println "\n错误:脚本执行失败!"
|
||||
println "异常类型:${e.class.name}"
|
||||
println "异常信息:${e.message}"
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
println "\n结束时间:${new Date()}"
|
||||
println "========================================"
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package com.fangjia.script.opentest
|
||||
|
||||
import com.fangjia.core.Constants
|
||||
import com.fangjia.core.util.DateUtil
|
||||
import com.fangjia.core.util.Mongo3Utils
|
||||
import com.fangjia.script.util.ExcelUtils
|
||||
import com.mongodb.client.MongoCollection
|
||||
import com.mongodb.client.MongoCursor
|
||||
import org.bson.Document
|
||||
|
||||
/**
|
||||
* E基金地址匹配接口 - 测试数据提取脚本
|
||||
* 功能:从MongoDB 206服务器提取历史测试数据并导出到Excel
|
||||
* @author wenyan
|
||||
*/
|
||||
|
||||
println "========== E基金接口测试数据提取 =========="
|
||||
println "开始时间:${new Date()}"
|
||||
|
||||
try {
|
||||
// 1. 连接MongoDB 206 (使用 Mongo3Utils 和 Constants.SEAWATER_MONGO_URI)
|
||||
println "\n正在连接MongoDB 206服务器..."
|
||||
MongoCollection<Document> coll = Mongo3Utils.getDbCollection(
|
||||
Constants.SEAWATER_MONGO_URI,
|
||||
"business",
|
||||
"open_uri_log"
|
||||
)
|
||||
println "MongoDB连接成功!"
|
||||
|
||||
// 2. 查询条件(使用 Document)
|
||||
println "\n构建查询条件..."
|
||||
Document query = new Document()
|
||||
query.put("user_id", "1007569")
|
||||
query.put("request_uri", "/address/risk")
|
||||
query.put("c_date", new Document().append('$gt', DateUtil.parseDate("2025-07-01", "yyyy-MM-dd")))
|
||||
|
||||
// 先查询总数
|
||||
long totalCount = coll.countDocuments(query)
|
||||
println "符合条件的数据总数:${totalCount}"
|
||||
|
||||
if (totalCount == 0) {
|
||||
println "警告:未找到符合条件的数据!"
|
||||
return
|
||||
}
|
||||
|
||||
println "将提取前 1000 条数据"
|
||||
|
||||
// 3. 查询1000条数据(只查询需要的字段)
|
||||
println "\n开始查询数据..."
|
||||
Document projection = new Document("parameter_map", 1).append("_id", 0)
|
||||
MongoCursor<Document> cursor = coll.find(query)
|
||||
.projection(projection)
|
||||
.limit(1000)
|
||||
.iterator()
|
||||
|
||||
// 4. 提取parameter_map中的city和address
|
||||
List<List<Object>> excelData = []
|
||||
excelData << ["序号", "城市", "地址"]
|
||||
|
||||
int index = 0
|
||||
int validCount = 0
|
||||
int errorCount = 0
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
try {
|
||||
Document doc = cursor.next()
|
||||
index++
|
||||
|
||||
// 提取parameter_map
|
||||
Document paramMap = doc.get("parameter_map", Document.class)
|
||||
|
||||
if (paramMap == null) {
|
||||
println "警告:第 ${index} 条数据没有 parameter_map 字段"
|
||||
errorCount++
|
||||
continue
|
||||
}
|
||||
|
||||
String city = paramMap.getString("city") ?: ""
|
||||
String address = paramMap.getString("address") ?: ""
|
||||
|
||||
excelData << [index, city, address]
|
||||
validCount++
|
||||
|
||||
if (index % 100 == 0) {
|
||||
println "已处理 ${index} 条数据..."
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
errorCount++
|
||||
println "处理第 ${index} 条数据时出错:${e.message}"
|
||||
}
|
||||
}
|
||||
|
||||
cursor.close()
|
||||
|
||||
println "\n数据提取完成!"
|
||||
println "总处理数:${index}"
|
||||
println "有效数据:${validCount}"
|
||||
println "错误数据:${errorCount}"
|
||||
|
||||
// 5. 保存到Excel
|
||||
println "\n正在保存Excel文件..."
|
||||
String scriptDir = new File(getClass().protectionDomain.codeSource.location.path).parent
|
||||
String dataDir = new File(scriptDir, "data").absolutePath
|
||||
new File(dataDir).mkdirs() // 确保目录存在
|
||||
|
||||
String outputFile = "${dataDir}${File.separator}efund_test_data.xlsx"
|
||||
ExcelUtils.write(outputFile, excelData, "测试数据")
|
||||
|
||||
println "Excel文件保存成功!"
|
||||
println "输出文件:${outputFile}"
|
||||
println "数据行数:${excelData.size()} 行(含表头)"
|
||||
|
||||
} catch (Exception e) {
|
||||
println "\n错误:脚本执行失败!"
|
||||
println "异常类型:${e.class.name}"
|
||||
println "异常信息:${e.message}"
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
println "\n结束时间:${new Date()}"
|
||||
println "=========================================="
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.fangjia.script.temp
|
||||
import java.nio.file.*
|
||||
import java.nio.charset.*
|
||||
import java.nio.file.attribute.*
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
// ===== 修改为你的目标目录 =====
|
||||
def rootDir = Paths.get("C:\\Users\\wenyan\\IdeaProjects\\main")
|
||||
// =================================
|
||||
|
||||
def gbkCharset = Charset.forName("GBK")
|
||||
def utf8Charset = StandardCharsets.UTF_8
|
||||
|
||||
Files.walk(rootDir)
|
||||
.filter { Files.isRegularFile(it) }
|
||||
.filter {
|
||||
def name = it.toString().toLowerCase()
|
||||
name.endsWith(".java") || name.endsWith(".groovy")
|
||||
}
|
||||
.forEach { path ->
|
||||
|
||||
byte[] bytes = Files.readAllBytes(path)
|
||||
|
||||
if (isGBK(bytes)) {
|
||||
println "Converting: $path"
|
||||
|
||||
// 用 GBK 解码
|
||||
String content = new String(bytes, gbkCharset)
|
||||
|
||||
// 写回 UTF-8(无 BOM)
|
||||
Files.write(path, content.getBytes(utf8Charset),
|
||||
StandardOpenOption.TRUNCATE_EXISTING)
|
||||
|
||||
} else {
|
||||
println "Skip (not GBK): $path"
|
||||
}
|
||||
}
|
||||
|
||||
println "Done."
|
||||
|
||||
|
||||
// ===== 判断是否为 GBK 编码 =====
|
||||
boolean isGBK(byte[] bytes) {
|
||||
try {
|
||||
def decoder = Charset.forName("UTF-8")
|
||||
.newDecoder()
|
||||
.onMalformedInput(CodingErrorAction.REPORT)
|
||||
.onUnmappableCharacter(CodingErrorAction.REPORT)
|
||||
|
||||
decoder.decode(ByteBuffer.wrap(bytes))
|
||||
return false // 能被 UTF-8 正确解析 → 不是 GBK
|
||||
} catch (Exception e) {
|
||||
return true // UTF-8 解析失败 → 很可能是 GBK
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -599,7 +599,7 @@ public class AddressMatchProxyServiceImpl extends AbstractHttpApiService impleme
|
||||
params.put("city", city);
|
||||
params.put("address", address);
|
||||
try {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/v2/structure", params, "UTF-8");
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/formatNinelevel", params, "UTF-8");
|
||||
if (json != null && json.containsKey("msgCode") && json.getInt("msgCode") == 200) {
|
||||
if (json.containsKey("result")) {
|
||||
return (JSONObject) json.get("result");
|
||||
|
||||
+4
-2
@@ -1096,7 +1096,7 @@ public class DistrictStatServiceImpl implements DistrictStatService {
|
||||
if (StringUtils.isNotBlank(city) && StringUtils.isNotBlank(region) && StringUtils.isNotBlank(name)) {
|
||||
DistrictStatBo districtStatBo = this.districtStatService.findDistrictStat(new DistrictKey(city, region, name));
|
||||
if (districtStatBo.getDefaultDistrictStat() != null) {
|
||||
return districtStatBo.getDefaultDistrictStat().getAvgPrice();
|
||||
return districtStatBo.getDefaultDistrictStat().getAvg_price_2b() != null ? districtStatBo.getDefaultDistrictStat().getAvg_price_2b() : districtStatBo.getDefaultDistrictStat().getAvgPrice();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1861,7 +1861,9 @@ public class DistrictStatServiceImpl implements DistrictStatService {
|
||||
if (null != weekend) {
|
||||
params.add(new QueryParam("weekend", DateUtil.getThisSunday(weekend)));
|
||||
}
|
||||
DistrictStat dss = districtStatDao.findFirstByParams(params);
|
||||
List<SortParam> sortParams = new ArrayList<SortParam>();
|
||||
sortParams.add(new SortParam("weekend", false));
|
||||
DistrictStat dss = districtStatDao.findFirstByParams(params, sortParams);
|
||||
return dss;
|
||||
}
|
||||
});
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.fangjia.service.efund;
|
||||
|
||||
import com.fangjia.service.dto.UniversalDto;
|
||||
|
||||
/**
|
||||
* E基金地址匹配服务
|
||||
* @author wenyan
|
||||
*/
|
||||
public interface EfundMatchService {
|
||||
|
||||
/**
|
||||
* 根据地址进行匹配,返回房价信息和地址类型标签
|
||||
*
|
||||
* @param address 地址字符串
|
||||
* @param city 城市名称(可选)
|
||||
* @return 匹配结果,包含小区信息、房价、地址类型等
|
||||
*/
|
||||
UniversalDto matchAddress(String address, String city);
|
||||
}
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
package com.fangjia.service.efund;
|
||||
|
||||
import com.fangjia.core.ProvinceData;
|
||||
import com.fangjia.core.RegionData;
|
||||
import com.fangjia.core.util.DateUtil;
|
||||
import com.fangjia.core.util.HttpRequest;
|
||||
import com.fangjia.core.util.HttpRequestException;
|
||||
import com.fangjia.dal.common.DistrictKey;
|
||||
import com.fangjia.dal.mongo.model.DistrictStat;
|
||||
import com.fangjia.dal.mongo.model.RegionSellStat;
|
||||
import com.fangjia.dal.mongo.model.bkoff.DealPrice;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.service.api.AddressMatchProxyService;
|
||||
import com.fangjia.service.datastore.DistrictService;
|
||||
import com.fangjia.service.district.DistrictStatService;
|
||||
import com.fangjia.service.dto.UniversalDto;
|
||||
import com.fangjia.service.mongo.fangjia.DealPriceService;
|
||||
import com.fangjia.service.mongo.fangjia.RegionSellStatService;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* E基金地址匹配服务实现
|
||||
* @author wenyan
|
||||
*/
|
||||
public class EfundMatchServiceImpl implements EfundMatchService {
|
||||
|
||||
private AddressMatchProxyService addressMatchProxyService;
|
||||
private DistrictStatService districtStatService;
|
||||
private DealPriceService dealPriceService;
|
||||
private DistrictService districtService;
|
||||
private RegionSellStatService regionSellStatService;
|
||||
|
||||
@Override
|
||||
public UniversalDto matchAddress(String address, String city) {
|
||||
if (StringUtils.isBlank(address)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 调用地址匹配服务
|
||||
JSONObject matchResult = addressMatchProxyService.newMatch(city, address, null, true);
|
||||
|
||||
// 检查是否匹配到POI(有id字段),没有id算匹配失败
|
||||
String id = (matchResult != null) ? matchResult.optString("id") : null;
|
||||
if (StringUtils.isBlank(id)) {
|
||||
// 匹配失败,调用标准化拆分接口
|
||||
return handleAddressStructure(city, address);
|
||||
}
|
||||
// 从匹配结果获取展示用的城市、区域、街道
|
||||
String matchCity = matchResult.optString("city");
|
||||
String matchDistrict = matchResult.optString("district");
|
||||
String matchName = matchResult.optString("name");
|
||||
String street = matchResult.optString("street");
|
||||
String township = matchResult.optString("township");
|
||||
String category = matchResult.optString("category");
|
||||
if(category.contains("写字楼")){
|
||||
category = "写字楼";
|
||||
}
|
||||
Double credit = matchResult.optDouble("credit", 0.0);
|
||||
UniversalDto result = UniversalDto.newDto();
|
||||
// 输出基本信息
|
||||
if(StringUtils.isNotBlank(matchCity)){
|
||||
result.append("city", matchCity);
|
||||
}
|
||||
if(StringUtils.isNotBlank(matchDistrict)){
|
||||
result.append("district", matchDistrict);
|
||||
}
|
||||
if(StringUtils.isNotBlank(township)){
|
||||
result.append("street", township);
|
||||
}
|
||||
if(StringUtils.isNotBlank(township)){
|
||||
result.append("community_name", matchName);
|
||||
}
|
||||
result.append("match_confidence", credit);
|
||||
result.append("property_type", category);
|
||||
result.append("validation", "地址有效");
|
||||
// 有id,匹配到POI,使用id查询权威的小区信息
|
||||
District district = districtService.findById(id);
|
||||
if (district != null && district.getCategory().equals("district")) {
|
||||
// 从District获取权威的城市、区域、名称(用于查询价格和成交数据)
|
||||
String districtCity = district.getCity();
|
||||
String districtRegion = district.getRegion();
|
||||
String districtName = district.getName();
|
||||
// 小区,输出房价
|
||||
result.append("property_type", "住宅");
|
||||
result.append("match_level", "小区级");
|
||||
// 查询小区房价和数据更新时间
|
||||
DistrictStat latestStat = districtStatService.findOneDistrictStatsSort(districtCity, districtRegion, districtName, null);
|
||||
if (latestStat != null) {
|
||||
// 优先使用avg_price_2b,如果为空再使用avgPrice
|
||||
Integer avgPrice = null;
|
||||
if (latestStat.getAvg_price_2b() != null && latestStat.getAvg_price_2b() > 0) {
|
||||
avgPrice = latestStat.getAvg_price_2b();
|
||||
} else if (latestStat.getAvgPrice() > 0) {
|
||||
avgPrice = latestStat.getAvgPrice();
|
||||
}
|
||||
|
||||
if (avgPrice != null && avgPrice > 0) {
|
||||
result.append("reference_price", avgPrice);
|
||||
|
||||
// 数据更新时间
|
||||
if (latestStat.getWeekend() != null) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
result.append("update_time", sdf.format(latestStat.getWeekend()));
|
||||
}
|
||||
|
||||
// 查询典型总价:成交单价最接近参考均价的成交记录的总价
|
||||
DistrictKey districtKey = new DistrictKey(districtCity, districtRegion, districtName);
|
||||
Integer typicalTotalPrice = findTypicalTotalPrice(districtKey, avgPrice);
|
||||
if (typicalTotalPrice != null) {
|
||||
result.append("typical_total_price", typicalTotalPrice);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(district != null && district.getCategory().equals("office")){
|
||||
// 写字楼,不输出房价
|
||||
result.append("property_type", "写字楼");
|
||||
result.append("match_level", "建筑级");
|
||||
}else {
|
||||
result.append("match_level", "建筑级");
|
||||
result.append("property_type", category);
|
||||
if(category.contains("住宅")){
|
||||
result.append("match_level", "小区级");
|
||||
result.append("property_type", "住宅");
|
||||
String location = matchResult.getString("lng") + "," + matchResult.getString("lat");
|
||||
HttpRequest httpRequest = new HttpRequest();
|
||||
JSONObject json = null;
|
||||
Map<String, String> param = new HashMap<String, String>();
|
||||
param.put("location", location);
|
||||
param.put("area", "100");
|
||||
try {
|
||||
json = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8");
|
||||
if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) {
|
||||
result.put("reference_price", json.getInt("unitPrice"));
|
||||
result.append("update_time", DateUtil.formatByPattern(DateUtil.getFirstDayOfWeek(new Date()), "yyyy-MM-dd"));
|
||||
}
|
||||
} catch (HttpRequestException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找典型总价:成交单价最接近参考均价的成交记录的总价
|
||||
* @param districtKey 小区Key
|
||||
* @param referencePrice 参考均价
|
||||
* @return 典型总价(万元)
|
||||
*/
|
||||
private Integer findTypicalTotalPrice(DistrictKey districtKey, Integer referencePrice) {
|
||||
if (referencePrice == null || referencePrice <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 计算半年前的日期和当前日期
|
||||
Date halfYearAgo = new Date(System.currentTimeMillis() - 180L * 24 * 60 * 60 * 1000);
|
||||
Date now = new Date();
|
||||
|
||||
// 查询近半年的成交记录
|
||||
List<DealPrice> dealPrices = dealPriceService.findDealPriceList(
|
||||
districtKey.getCity(),
|
||||
districtKey.getRegion(),
|
||||
districtKey.getName(),
|
||||
halfYearAgo,
|
||||
now
|
||||
);
|
||||
|
||||
if (dealPrices == null || dealPrices.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 找到单价最接近参考均价的成交记录
|
||||
DealPrice closestDeal = null;
|
||||
int minDiff = Integer.MAX_VALUE;
|
||||
|
||||
for (DealPrice deal : dealPrices) {
|
||||
if (deal.getAvgPrice() != null && deal.getTotalPrice() != null) {
|
||||
int diff = Math.abs(deal.getAvgPrice() - referencePrice);
|
||||
if (diff < minDiff) {
|
||||
minDiff = diff;
|
||||
closestDeal = deal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (closestDeal != null && closestDeal.getTotalPrice() != null) {
|
||||
// 检查价格差异是否超过10%
|
||||
double diffPercent = Math.abs(closestDeal.getAvgPrice() - referencePrice) * 1.0 / referencePrice;
|
||||
if (diffPercent > 0.1) {
|
||||
return null;
|
||||
}
|
||||
return closestDeal.getTotalPrice()/10000;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// 查询失败时不影响主流程,仅记录日志
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理地址标准化拆分并返回区域价格
|
||||
* @param city 城市
|
||||
* @param address 地址
|
||||
* @return 包含区域价格的结果
|
||||
*/
|
||||
private UniversalDto handleAddressStructure(String city, String address) {
|
||||
try {
|
||||
// 调用地址标准化拆分
|
||||
JSONObject structureResult = addressMatchProxyService.addressStructure(city, address);
|
||||
if (structureResult == null || structureResult.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UniversalDto result = UniversalDto.newDto();
|
||||
|
||||
// 提取拆分的城市、区域、街道信息
|
||||
String province = structureResult.optString("province", null);
|
||||
String cityField = structureResult.optString("city", null);
|
||||
String structDistrict = structureResult.optString("district", null);
|
||||
String structTownship = structureResult.optString("township", null);
|
||||
String structRoad = structureResult.optString("street", null);
|
||||
String structRoadNumber = structureResult.optString("streetNumber", null);
|
||||
String msg = null;
|
||||
if(structureResult.containsKey("addressAssessment")){
|
||||
JSONObject addressAssessment = structureResult.getJSONObject("addressAssessment");
|
||||
msg = addressAssessment.optString("msg");
|
||||
}
|
||||
// 处理直辖市:如果是直辖市,城市名在province字段中
|
||||
String structCity;
|
||||
if (ProvinceData.isGovernmentCity(province)) {
|
||||
structCity = province;
|
||||
} else {
|
||||
structCity = cityField;
|
||||
}
|
||||
// 输出基本信息
|
||||
result.append("city", structCity);
|
||||
result.append("district", structDistrict);
|
||||
result.append("street", structTownship);
|
||||
result.append("road", structRoad);
|
||||
result.append("road_number", structRoadNumber);
|
||||
result.append("validation", msg);
|
||||
if(StringUtils.isNotBlank(structRoadNumber)){
|
||||
result.append("match_level", "门牌级");
|
||||
}else if(StringUtils.isNotBlank(structRoad)){
|
||||
result.append("match_level", "道路级");
|
||||
}else if(StringUtils.isNotBlank(structTownship)){
|
||||
result.append("match_level", "街道级");
|
||||
}else if(StringUtils.isNotBlank(structDistrict)){
|
||||
result.append("match_level", "区域级");
|
||||
}else if(StringUtils.isNotBlank(structCity)){
|
||||
result.append("match_level", "城市级");
|
||||
}
|
||||
// 格式化城市和区域为简称
|
||||
String formattedCity = RegionData.formatCity(structCity);
|
||||
String formattedRegion = RegionData.formatRegion(formattedCity, structDistrict);
|
||||
|
||||
// 查询区域价格
|
||||
if (StringUtils.isNotBlank(formattedCity) && StringUtils.isNotBlank(formattedRegion)) {
|
||||
RegionSellStat regionSellStat = regionSellStatService.findNewestRegionPrice(formattedCity, formattedRegion);
|
||||
if (regionSellStat != null && regionSellStat.getAvgPrice() != null && regionSellStat.getAvgPrice() > 0) {
|
||||
result.append("reference_price", regionSellStat.getAvgPrice());
|
||||
|
||||
// 数据更新时间
|
||||
if (regionSellStat.getUpdateDate() != null) {
|
||||
result.append("update_time", DateUtil.formatByPattern(DateUtil.parseDate(regionSellStat.getDate().toString(),"yyyyMM"), "yyyy-MM-dd"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
// 处理失败时返回null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAddressMatchProxyService(AddressMatchProxyService addressMatchProxyService) {
|
||||
this.addressMatchProxyService = addressMatchProxyService;
|
||||
}
|
||||
|
||||
public void setDistrictStatService(DistrictStatService districtStatService) {
|
||||
this.districtStatService = districtStatService;
|
||||
}
|
||||
|
||||
public void setDealPriceService(DealPriceService dealPriceService) {
|
||||
this.dealPriceService = dealPriceService;
|
||||
}
|
||||
|
||||
public void setDistrictService(DistrictService districtService) {
|
||||
this.districtService = districtService;
|
||||
}
|
||||
|
||||
public void setRegionSellStatService(RegionSellStatService regionSellStatService) {
|
||||
this.regionSellStatService = regionSellStatService;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<name>fangjia-static</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>GBK</project.build.sourceEncoding>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<build>
|
||||
<finalName>fangjia-static</finalName>
|
||||
@@ -20,7 +20,7 @@
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<encoding>GBK</encoding>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
Reference in New Issue
Block a user