宏信相关

This commit is contained in:
2025-12-25 08:53:00 +08:00
parent 469ee5f2ed
commit 5abf2ddaaa
7 changed files with 712 additions and 4 deletions
+6
View File
@@ -602,5 +602,11 @@
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
<!-- <artifactId>jackson-core</artifactId>-->
<!-- <version>2.9.9</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
</dependencies>
</project>
@@ -0,0 +1,62 @@
package com.fangjia.script.gj.test
import com.fangjia.script.commData.CommonDatautils
import com.fangjia.script.util.DateUtils
import com.fangjia.script.util.ExcelUtils
import com.fangjia.script.util.GeoHelper
class JingDongTest {
static main(args) {
// def task = new JingDongTest()
// def path = "D:\\数据\\京东\\京东测试数据.xlsx"
// task.run(path)
// task.addPrice(path)
// 120.12063,30.281452
// 120.120419,30.2767
// 120.116349,30.29144
// 120.137169,30.272963
// 120.108109,30.265553
ExcelUtils.modify("C:\\Users\\gaojuan\\Downloads\\商铺出租信息 (3).xlsx",{d->
if(d['J']){
def arrs = d['J'].split(",")
def distance = GeoHelper.GetDistance(arrs[1].toString().toDouble(), arrs[0].toString().toDouble(), 22.554693, 113.869516)
d['F'] = distance
}
})
}
def run(path){
def cityMap = ["北京":"大兴","厦门":"思明","泉州":"丰泽","安顺":"西秀"]
def rets = []
rets << ["城市","区域","名称","地址","高德经度","高德纬度","均价"]
for(def m : cityMap) {
println m.key +" "+m.value
def districts = CommonDatautils.findAllRegionDistricts(m.key, m.value, "district", ["city", "region", "name", "address", "lng", "lat"]);
for(def d : districts){
if(d.lng){
println d
rets << [d.city, d.region, d.name, d.address, d.lng/10000000000.0, d.lat/10000000000.0]
}
}
}
ExcelUtils.write(path, rets, "数据")
}
def addPrice(path){
ExcelUtils.multiThreadingModify(path,{d->
if(!d['G']){
def dbo = CommonDatautils.findDistrictPrice(d['A'], d['B'], d['C'])
if(dbo){
d['G'] = dbo.avg_price_2b
d['H'] = DateUtils.formatDateByPattern(dbo.weekend,"yyyy-MM-dd")
}
}
})
}
}
@@ -1,22 +1,27 @@
package com.fangjia.script.jiangnanblank
import com.fangjia.core.util.HttpRequest
import com.fangjia.core.util.PriceData
import com.fangjia.core.util.SvgUtils
import com.fangjia.script.ccbevaluation.CcbCommonUtils
import com.fangjia.script.commData.CommonDatautils
import com.fangjia.script.gj.OpenApiUtils
import com.fangjia.script.gj.district.FangjiaClientUtils
import com.fangjia.script.util.ExcelUtils
import com.fangjia.script.util.OpenApiClient
import groovy.json.JsonBuilder
import groovy.sql.Sql
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import groovy.json.JsonOutput
/**
* Created by gaojuan on 2017/12/7.
*/
class TestEvaluation {
def sql = Sql.newInstance(
"jdbc:mysql://192.168.0.92:3306/fangjiatong?useSSL=false&serverTimezone=Asia/Shanghai",
"jdbc:mysql://192.168.0.92:3306/fangjiatong?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai",
"goojia",
"G0ojia123456!@#",
"com.mysql.cj.jdbc.Driver"
@@ -357,7 +362,7 @@ class TestEvaluation {
if(d['B'] == "公寓"){
buildType = 8
}else if(d['B'] == "别墅"){
buildType = 4
buildType = 11
}else if(d['B'] == "商铺"){
buildType = 1
}else if(d['B'] == "办公楼"){
@@ -365,11 +370,13 @@ class TestEvaluation {
}
def lat = dist.lat/10000000000.0
def lng = dist.lng/10000000000.0
def cat = 5
if(buildType==3 || buildType==8 || buildType ==4){
def cat = 6
if(buildType==3 || buildType==8 || buildType ==11){
cat = 1
}else if(buildType == 1){
cat = 4
}else if(buildType == 2){
cat = 6
}
def date = new Date()
rets << [d['E'], dist.city, dist.region, dist.name, dist.address,buildType,d['I'], d['J'].toString().toDouble().toInteger(), lng, lat, d['F'], date, date, cat, d['K'].toString().toDouble().toInteger()]
@@ -394,14 +401,159 @@ class TestEvaluation {
def addEvaluationDetail(){
def rets = []
def detailList = ExcelUtils.read("D:\\数据\\宏信息\\宏信房源台账-基准价-详情.xlsx", 0 , 1)
ExcelUtils.modify("D:\\数据\\宏信息\\宏信项目-最终.xlsx", { d ->
if (d['G']) {
def dist = CommonDatautils.findDistrictById(d['G'])
if (dist) {
def ret = []
ret << d['L'].toString().toDouble().toInteger()
def houses = []
if(["住宅","别墅","公寓"].contains(d["B"])){
def propertyType = 0
if(d["B"] == "别墅"){
propertyType = 1
}
def avgPrice = d['K']
def minPrice = null
def maxPrice = null
if(avgPrice){
minPrice = (int)(avgPrice - avgPrice * 0.1)
maxPrice = (int)(avgPrice + avgPrice * 0.1)
}
houses = OpenApiClient.newHouseAction(dist.city, dist.region, dist.name, propertyType.toString(), minPrice, maxPrice, 5)
}
if(houses){
ret << houses
}else{
ret << []
}
if(d['K']){
ret << createTrend(d['K'].toString().toDouble().toInteger(), d['A'])
}else{
ret << '{"trendSvg":""}'
}
ret << []
ret << "上海宏信建设发展有限公司"
ret << new Date()
ret << new Date()
ret << 1
ret << d['A']
ret << [createAttachment(detailList, d['G'], d['B'], dist)]
rets.add(ret)
def sqlstring = "insert into evaluation_edit_data(evaluation_id, house_samples, market_analysis, custom_properties, company, create_time, update_time, validity_period, subject_name, attachments) values (?,?,?,?,?,?,?,?,?,?)"
sql.withBatch(1, sqlstring){ ps->
for(def r : rets) {
def houseSamplesJson = null
if (r[1]) {
// 修复中文转义
houseSamplesJson = fixUnicodeEscapes(JsonOutput.toJson(r[1]))
}
def marketAnalysisJson = null
if (r[2]) {
// 修复中文转义
marketAnalysisJson = fixUnicodeEscapes(JsonOutput.toJson(r[2]))
}
def customPropertiesJson = r[1] ? JsonOutput.toJson(r[3]) : null
def attachmentsJson = null
if(r[9]){
// 修复中文转义
attachmentsJson = fixUnicodeEscapes(JsonOutput.toJson(r[9]))
}
ps.addBatch(r[0], houseSamplesJson, marketAnalysisJson, customPropertiesJson, r[4], r[5], r[6], r[7], r[8], attachmentsJson)
ps.toString()
}
}
}
}
});
}
def createTrend(price, name){
List<PriceData> data1 = PriceData.getSampleData(price);
List<List<PriceData>> dataSets = new ArrayList<>();
dataSets.add(data1);
List<String> labels = Arrays.asList(name);
def priceTrendMap = [:]
def categories = []
def priceData = []
for(PriceData pd : data1){
categories << pd.yearmonth
priceData << (int)pd.price
}
priceTrendMap.put("categories", categories)
priceTrendMap.put("series", [["name":name,"data":priceData]])
String title = "价格走势图";
String subtitle = categories[0] + " 至 "+categories[categories.size()-1];
// 测试小数位为0(整数等差)
String svgWithoutDecimals = SvgUtils.generatePriceTrendSvg(dataSets, labels, title, subtitle, 0);
return ["avgPrice":price, "priceTrend":priceTrendMap,"trendSvg":svgWithoutDecimals]
}
def createAttachment(detailList, id, type, dist){
def items = []
for(def data : detailList){
if(data["I"]==id && type==data['D']){
def totalPrice = (int)(data['H'] * data['N'])
items << ["city":dist.city, "district":dist.region, "address":data['B'], "area":data['H'], "unitPrice":data['N'].toString().toDouble().toInteger(), "totalPrice":totalPrice]
}
}
def time = new Date().getTime()
def resMap = ["id":"attachment_"+time, "title": "出售资产价格清单","type": 1,"editing": false,"items":items]
return resMap
}
def fixUnicodeEscapes(jsonString){
if (!jsonString){
return jsonString
}
def result = new StringBuilder()
def matcher = jsonString =~ /\\u([0-9a-fA-F]{4})/
def lastIndex = 0
while (matcher.find()) {
// 添加前面的部分
result.append(jsonString.substring(lastIndex, matcher.start()))
// 转换Unicode转义字符
String hex = matcher.group(1)
int codePoint = Integer.parseInt(hex, 16)
// 检查是否是中文字符(常用中文字符范围)
// 中文Unicode范围:0x4E00-0x9FFF,0x3400-0x4DBF,0x20000-0x2A6DF等
if ((codePoint >= 0x4E00 && codePoint <= 0x9FFF) ||
(codePoint >= 0x3400 && codePoint <= 0x4DBF)) {
// 是中文,转换为实际字符
result.append(new String(Character.toChars(codePoint)))
} else {
// 不是中文,保留转义格式
result.append("\\u").append(hex)
}
lastIndex = matcher.end()
}
// 添加剩余部分
result.append(jsonString.substring(lastIndex))
return result.toString()
}
@@ -1607,6 +1607,47 @@ public class OpenApiClient {
public static def newHouseAction(String city, String district, String name, String propertyType, Integer minPrice, Integer maxPrice, Integer pageSize) {
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put("city", city);
params.put("district", district);
params.put("name", name)
params.put("token", TOKEN);
params.put("propertyType", propertyType)
params.put("showSource", "1")
// if(minPrice){
// params.put("minPrice", minPrice)
// }
// if(maxPrice){
// params.put("maxPrice", maxPrice)
// }
// if(pageSize){
// params.put("maxPrice", pageSize)
// }
String content = new HttpRequest().get("http://open.fangjia.com/property/sellCase", params, "utf-8")
JSONObject result = JSONObject.fromObject(content);
while (result == null) {
result = HttpRequestUtil.getJsonContent("http://open.fangjia.com/property/sellCase", params, "utf-8")
println("${city} ${name} 程序调用异常")
Thread.sleep(6000)
}
if (result.getInt("code") == 200) {
return result.get("result");
} else if (result.getInt("code") !=0) {
println("${city} ${name}")
}
} catch (Exception e) {
println("${city} ${name} ${e.getMessage()}")
e.printStackTrace();
}
return null
}
public static def houseAroundBylocationAction(location, size, propertyType, houseType, pageSize) {
def url ="https://open.fangjia.com/house/around?location="+location+"&size="+size+"&pageSize="+pageSize+"&propertyType="+propertyType+"&houseType="+houseType