From 5abf2ddaaaead79e383399b8ef35cfa3b0c725da Mon Sep 17 00:00:00 2001 From: gaojuan1 Date: Thu, 25 Dec 2025 08:53:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8F=E4=BF=A1=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fangjia/core/util/PriceData.java | 82 +++++ .../java/com/fangjia/core/util/PriceDto.java | 49 +++ .../java/com/fangjia/core/util/SvgUtils.java | 316 ++++++++++++++++++ projects/fangjia-script/pom.xml | 6 + .../script/gj/test/JingDongTest.groovy | 62 ++++ .../jiangnanblank/TestEvaluation.groovy | 160 ++++++++- .../fangjia/script/util/OpenApiClient.groovy | 41 +++ 7 files changed, 712 insertions(+), 4 deletions(-) create mode 100644 projects/fangjia-core/src/main/java/com/fangjia/core/util/PriceData.java create mode 100644 projects/fangjia-core/src/main/java/com/fangjia/core/util/PriceDto.java create mode 100644 projects/fangjia-core/src/main/java/com/fangjia/core/util/SvgUtils.java create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/test/JingDongTest.groovy diff --git a/projects/fangjia-core/src/main/java/com/fangjia/core/util/PriceData.java b/projects/fangjia-core/src/main/java/com/fangjia/core/util/PriceData.java new file mode 100644 index 000000000..7c3d7e4f8 --- /dev/null +++ b/projects/fangjia-core/src/main/java/com/fangjia/core/util/PriceData.java @@ -0,0 +1,82 @@ +package com.fangjia.core.util; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +@Data +public class PriceData { + private String yearmonth; + private Double price; + private Double volume; // 新增æˆ�交é‡�字段 + + public PriceData() {} + + public PriceData(String yearmonth, Double price) { + this.yearmonth = yearmonth; + this.price = price; + } + + public PriceData(String yearmonth, Double price, Double volume) { + this.yearmonth = yearmonth; + this.price = price; + this.volume = volume; + } + + public static List getSampleData() { + List data = new ArrayList<>(); + double basePrice = 22000; + double minPrice = basePrice * (1 - 0.04); + double maxPrice = basePrice * (1 + 0.04); + Random random = new Random(); + + for (int i = 0; i < 2; i++) { + int year = 2024; + int month = i + 4; + if (month > 12) { + year++; + month -= 12; + } + String date = String.format("%d-%02d", year, month); + double price = minPrice + random.nextDouble() * (maxPrice - minPrice); + double volume = 100 + random.nextInt(100); + data.add(new PriceData(date, price, volume)); + System.out.println(data.get(i)); + } + return data; + } + + public static List getSampleData(double basePrice) { + List data = new ArrayList<>(); + double minPrice = basePrice * (1 - 0.02); + double maxPrice = basePrice * (1 + 0.02); + Random random = new Random(); + + for (int i = 0; i < 12; i++) { + int year = 2025; + int month = i + 1; + if (month > 12) { + year++; + month -= 12; + } + String date = String.format("%d-%02d", year, month); + double price = minPrice + random.nextDouble() * (maxPrice - minPrice); + double volume = 100 + random.nextInt(200); + data.add(new PriceData(date, price, volume)); + System.out.println(data.get(i)); + } + return data; + } + + public static List getSampleData2() { + List data = new ArrayList<>(); + data.add(new PriceData("2025-01", 11110.0, 90.0)); + data.add(new PriceData("2025-02", 11115.0, 110.0)); + data.add(new PriceData("2025-03", 11112.0, 95.0)); + data.add(new PriceData("2025-04", 11120.0, 150.0)); + data.add(new PriceData("2025-05", 11118.0, 140.0)); + return data; + } +} diff --git a/projects/fangjia-core/src/main/java/com/fangjia/core/util/PriceDto.java b/projects/fangjia-core/src/main/java/com/fangjia/core/util/PriceDto.java new file mode 100644 index 000000000..899c1832f --- /dev/null +++ b/projects/fangjia-core/src/main/java/com/fangjia/core/util/PriceDto.java @@ -0,0 +1,49 @@ +package com.fangjia.core.util; + +import lombok.Builder; +import lombok.Data; + +import java.util.List; + +/** + * @author shenjian + * @since 2024/12/17 + */ +@Data +public class PriceDto { + private Integer id; + + private Integer avgPrice;//本周å�‡ä»· + + private PriceTrend priceTrend; //å�‡ä»·èµ°åŠ¿ + + private List rentPrices;//本月租金 + + private PriceTrend rentTrend;//租金走势 + + @Data + @Builder + public static class RentPrice { + private String name; + private Integer price; + } + + @Data + public static class PriceTrend { + private List categories; + private List series; + private List doubleSeries; + } + + @Data + public static class Series { + private String name; + private List data; + } + + @Data + public static class DoubleSeries { + private String name; + private List data; + } +} diff --git a/projects/fangjia-core/src/main/java/com/fangjia/core/util/SvgUtils.java b/projects/fangjia-core/src/main/java/com/fangjia/core/util/SvgUtils.java new file mode 100644 index 000000000..ce45c16da --- /dev/null +++ b/projects/fangjia-core/src/main/java/com/fangjia/core/util/SvgUtils.java @@ -0,0 +1,316 @@ +package com.fangjia.core.util; + + + +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + + +/** + * SVG工具类,用于生æˆ�价格趋势的SVG图表 + */ + +public class SvgUtils { + + // SVG画布尺寸 + private static final int WIDTH = 800; + private static final int HEIGHT = 500; + private static final int PADDING = 60; + + // 生æˆ�SVG折线图(支æŒ�多æ�¡çº¿ï¼‰ï¼Œæ–°å¢ždecimalPlaceså�‚数控制Yè½´å°�æ•°ä½� + public static String generatePriceTrendSvg(List> dataSets, List labels, String title, String subtitle, int decimalPlaces) { + if (dataSets.isEmpty() || dataSets.get(0).isEmpty()) { + return ""; + } + // 过滤为空的数æ�® + dataSets = dataSets.stream() + .map(innerList -> innerList.stream() + .filter(priceData -> priceData != null && priceData.getPrice() != null) + .collect(Collectors.toList())) + .collect(Collectors.toList()); + + // 计算价格和时间的范围 + double minPrice = dataSets.stream() + .flatMap(List::stream) + .filter((p) -> p != null && p.getPrice() != null) + .mapToDouble(PriceData::getPrice) + .min() + .orElse(0) * 0.8; + double maxPrice = dataSets.stream() + .flatMap(List::stream) + .filter((p) -> p != null && p.getPrice() != null) + .mapToDouble(PriceData::getPrice) + .max() + .orElse(1) * 1.2; + double buffer = 0.1; + minPrice = minPrice * (1 - buffer); + maxPrice = maxPrice * (1 + buffer); + + // 如果decimalPlaces为0,调整minPriceå’ŒmaxPrice为整数等差 +// if (decimalPlaces == 0) { +// long step = calculateStep((long) Math.ceil(maxPrice) - (long) Math.floor(minPrice)); +// minPrice = Math.floor(minPrice / step) * step; +// maxPrice = Math.ceil(maxPrice / step) * step; +// } + + // è§£æž�最å°�和最大日期 + String minYearMonth = dataSets.stream() + .flatMap(List::stream) + .map(PriceData::getYearmonth) + .min(String::compareTo) + .orElse("2024-08"); + String maxYearMonth = dataSets.stream() + .flatMap(List::stream) + .map(PriceData::getYearmonth) + .max(String::compareTo) + .orElse("2025-01"); + + // 构建SVG内容 + StringBuilder svg = new StringBuilder(); + svg.append(String.format("", WIDTH, HEIGHT)); + svg.append(String.format("", WIDTH, HEIGHT)); + + // 添加标题和副标题 + svg.append(String.format("%s", + WIDTH / 2, 30, title)); + svg.append(String.format("%s", + WIDTH / 2, 50, subtitle)); + + // 画虚线网格线和å��标轴 + svg.append(drawGrid(minYearMonth, maxYearMonth, minPrice, maxPrice, decimalPlaces)); + svg.append(drawAxis(minYearMonth, maxYearMonth, minPrice, maxPrice, decimalPlaces)); + + // 画多æ�¡æŠ˜çº¿å’Œå›¾ä¾‹ + String[] colors = {"#66B3FF", "#FF6666", "#FFA500", "#8A2BE2"}; + for (int i = 0; i < dataSets.size(); i++) { + svg.append(drawSmoothLine(dataSets.get(i), minYearMonth, maxYearMonth, minPrice, maxPrice, colors[i % colors.length], decimalPlaces)); + svg.append(String.format("", 650, 60 + i * 20, colors[i % colors.length])); + svg.append(String.format("%s", 670, 70 + i * 20, labels.get(i))); + } + + svg.append(""); + return svg.toString(); + } + + // 绘制平滑折线 + private static String drawSmoothLine(List data, String minYearMonth, String maxYearMonth, double minPrice, double maxPrice, String color, int decimalPlaces) { +// if (data.size() < 2) return ""; + StringBuilder path = new StringBuilder("", x, y, color)); + pointsAndLabels.append(String.format("%." + decimalPlaces + "f", + x + 5, y - 5, color, point.getPrice())); + + path.append("M").append(x).append(",").append(y); + } else if (data.size() > 1) { + for (int i = 0; i < data.size() - 1; i++) { + PriceData point1 = data.get(i); + PriceData point2 = data.get(i + 1); + int monthIndex1 = Math.max(0, Math.min(totalMonths - 1, getMonthIndex(point1.getYearmonth()) - getMonthIndex(minYearMonth))); + int monthIndex2 = Math.max(0, Math.min(totalMonths - 1, getMonthIndex(point2.getYearmonth()) - getMonthIndex(minYearMonth))); + + int x1 = PADDING + (monthIndex1 * (WIDTH - 2 * PADDING) / (totalMonths - 1)); + int y1 = HEIGHT - PADDING - (int) ((point1.getPrice() - minPrice) * (HEIGHT - 2 * PADDING) / (maxPrice - minPrice)); + int x2 = PADDING + (monthIndex2 * (WIDTH - 2 * PADDING) / (totalMonths - 1)); + int y2 = HEIGHT - PADDING - (int) ((point2.getPrice() - minPrice) * (HEIGHT - 2 * PADDING) / (maxPrice - minPrice)); + + int controlX1 = x1 + (x2 - x1) / 3; + int controlY1 = y1; + int controlX2 = x2 - (x2 - x1) / 3; + int controlY2 = y2; + + if (i == 0) path.append(x1).append(",").append(y1); + path.append(" C").append(controlX1).append(",").append(controlY1).append(" ").append(controlX2).append(",").append(controlY2).append(" ").append(x2).append(",").append(y2); + + pointsAndLabels.append(String.format("", x1, y1, color)); + pointsAndLabels.append(String.format("%." + decimalPlaces + "f", + x1 + 5, y1 - 5, color, point1.getPrice())); + } + + PriceData lastPoint = data.get(data.size() - 1); + int lastMonthIndex = Math.max(0, Math.min(totalMonths - 1, getMonthIndex(lastPoint.getYearmonth()) - getMonthIndex(minYearMonth))); + int lastX = PADDING + (lastMonthIndex * (WIDTH - 2 * PADDING) / (totalMonths - 1)); + int lastY = HEIGHT - PADDING - (int) ((lastPoint.getPrice() - minPrice) * (HEIGHT - 2 * PADDING) / (maxPrice - minPrice)); + pointsAndLabels.append(String.format("", lastX, lastY, color)); + pointsAndLabels.append(String.format("%." + decimalPlaces + "f", + lastX + 5, lastY - 5, color, lastPoint.getPrice())); + } + path.append("' fill='none' stroke='").append(color).append("' stroke-width='2'/>"); + path.append(pointsAndLabels); + return path.toString(); + } + + // 绘制网格线 + private static String drawGrid(String minYearMonth, String maxYearMonth, double minPrice, double maxPrice, int decimalPlaces) { + StringBuilder grid = new StringBuilder(); + double step = calculateYStep(minPrice, maxPrice, decimalPlaces); + int numSteps = (int) ((maxPrice - minPrice) / step) + 1; + + for (int i = 0; i < numSteps; i++) { + double price = minPrice + i * step; + if (price > maxPrice) break; + int y = HEIGHT - PADDING - (int) ((price - minPrice) * (HEIGHT - 2 * PADDING) / (maxPrice - minPrice)); + grid.append(String.format("", + PADDING, y, WIDTH - PADDING, y)); + } + return grid.toString(); + } + + // 绘制å��标轴 + private static String drawAxis(String minYearMonth, String maxYearMonth, double minPrice, double maxPrice, int decimalPlaces) { + StringBuilder axis = new StringBuilder(); + + // Xè½´ + axis.append(String.format("", + PADDING, HEIGHT - PADDING, WIDTH - PADDING, HEIGHT - PADDING)); + axis.append(String.format("", + PADDING, PADDING, PADDING, HEIGHT - PADDING)); + + // X轴刻度 + int totalMonths = getMonthIndex(maxYearMonth) - getMonthIndex(minYearMonth) + 1; + for (int i = 0; i < totalMonths; i++) { + int x; + if (totalMonths == 1) { + // 当å�ªæœ‰ä¸€ä¸ªæœˆæ—¶ï¼Œå°†åˆ»åº¦æ”¾åœ¨ä¸­é—´ä½�ç½® + x = PADDING + (WIDTH - 2 * PADDING) / 2; + } else { + x = PADDING + i * (WIDTH - 2 * PADDING) / (totalMonths - 1); + } + String monthLabel = getMonthLabel(minYearMonth, i); + axis.append(String.format("", + x, HEIGHT - PADDING + 5, x, HEIGHT - PADDING)); + axis.append(String.format("%s", + x, HEIGHT - PADDING + 20, monthLabel)); + } + + // Y轴刻度 + double step = calculateYStep(minPrice, maxPrice, decimalPlaces); + int numSteps = (int) ((maxPrice - minPrice) / step) + 1; + for (int i = 0; i < numSteps; i++) { + double price = minPrice + i * step; + int y = HEIGHT - PADDING - (int) ((price - minPrice) * (HEIGHT - 2 * PADDING) / (maxPrice - minPrice)); + axis.append(String.format("", + PADDING - 5, y, PADDING, y)); + axis.append(String.format("%." + decimalPlaces + "f", + PADDING - 10, y + 5, price)); + } + + return axis.toString(); + } + + // 计算Y轴步长 + private static double calculateYStep(double minPrice, double maxPrice, int decimalPlaces) { + double range = maxPrice - minPrice; + if (decimalPlaces == 0) { + return calculateStep((long) range); + } + double step = range / 10.0; // 默认10个间隔 + double scale = Math.pow(10, decimalPlaces); + return Math.round(step * scale) / scale; + } + + // 计算整数步长 + private static long calculateStep(long range) { + long step = (long) Math.pow(10, Math.floor(Math.log10(range))); + if (range / step < 4) step /= 2; + else if (range / step > 8) step *= 2; + return step; + } + + // 获å�–月份标签和索引(ä¿�æŒ�ä¸�å�˜ï¼‰ + private static String getMonthLabel(String minYearMonth, int offset) { + int totalMonths = getMonthIndex(minYearMonth); + int targetMonthIndex = totalMonths + offset; + int year = 2024 + targetMonthIndex / 12; + int month = targetMonthIndex % 12 + 1; + return String.format("%d-%02d", year, month); + } + + private static int getMonthIndex(String yearMonth) { + int year = Integer.parseInt(yearMonth.substring(0, 4)); + int month = Integer.parseInt(yearMonth.substring(5)); + return (year - 2024) * 12 + (month - 1); + } + + + public static void generateSvg(String svgContent, String outputPath) { + try (FileWriter writer = new FileWriter(outputPath)) { + writer.write(svgContent); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 对é½�已有系列数æ�®ä¸Žæ–°çš„æ—¶é—´è½´ + */ + public static void alignSeriesData(List newCategories, List series, PriceDto.PriceTrend rentTrend) { + for (PriceDto.DoubleSeries s : series) { + List originalData = s.getData(); + List originalCategories = new ArrayList<>(rentTrend.getCategories()); // å�‡è®¾åŽŸå§‹æ—¶é—´è½´å�¯ä»Žåˆ«å¤„获å�– + List alignedData = new ArrayList<>(); + + // æ ¹æ�®æ–°çš„æ—¶é—´è½´å¯¹é½�æ•°æ�® + for (String date : newCategories) { + int index = originalCategories.indexOf(date); + if (index >= 0 && index < originalData.size()) { + alignedData.add(originalData.get(index)); + } else { + alignedData.add(null); // 日期ä¸�存在时补 null + } + } + s.setData(alignedData); + } + } + + // 测试方法 + public static void main(String[] args) { + List data1 = PriceData.getSampleData(5200); + List> dataSets = new ArrayList<>(); + dataSets.add(data1); + String name = "新世纪大厦"; + List labels = Arrays.asList(name); + + String title = "价格走势图"; + String subtitle = "2024-12 至 2025-11"; + +// // 测试å°�æ•°ä½�为2 +// String svgWithoutDecimals = generatePriceTrendSvg(dataSets, labels, title, subtitle, 2); +// System.out.println("With 2 decimal places:"); +// System.out.println(svgWithoutDecimals); + + // 测试å°�æ•°ä½�为0(整数等差) + String svgWithoutDecimals = generatePriceTrendSvg(dataSets, labels, title, subtitle, 0); + System.out.println("With 0 decimal places (integer steps):"); + System.out.println(svgWithoutDecimals); + + try { + generateSvg(svgWithoutDecimals, name + ".svg"); + System.out.println("PNG image generated successfully at: price_trend.png"); + } catch (Exception e) { + e.printStackTrace(); + } + +// String locationStr = "114.407048,30.481859"; +// String[] location = locationStr.split(","); +// Double lng = Double.parseDouble(location[0]); +// Double lat = Double.parseDouble(location[1]); +// String mapUrl = "https://restapi.amap.com/v3/staticmap?location=" + lng + "," + lat +// + "&zoom=14&size=780*300&markers=mid,,A:" + lng + "," + lat +// + "&key=ee95e52bf08006f63fd29bcfbcf21df0"; +// System.out.println(mapUrl); + } +} \ No newline at end of file diff --git a/projects/fangjia-script/pom.xml b/projects/fangjia-script/pom.xml index 698a360f2..17e32cbde 100644 --- a/projects/fangjia-script/pom.xml +++ b/projects/fangjia-script/pom.xml @@ -602,5 +602,11 @@ mysql-connector-java 8.0.33 + + + + + + diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/test/JingDongTest.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/test/JingDongTest.groovy new file mode 100644 index 000000000..8acc1ff69 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/test/JingDongTest.groovy @@ -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") + } + } + }) + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/jiangnanblank/TestEvaluation.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/jiangnanblank/TestEvaluation.groovy index c395ff47d..8a70933ab 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/jiangnanblank/TestEvaluation.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/jiangnanblank/TestEvaluation.groovy @@ -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 data1 = PriceData.getSampleData(price); + List> dataSets = new ArrayList<>(); + dataSets.add(data1); + List 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() } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/OpenApiClient.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/OpenApiClient.groovy index 4636489d1..7b8012be3 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/OpenApiClient.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/OpenApiClient.groovy @@ -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 params = new HashMap(); + 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