Merge branch 'script_gj' into 'master'
Script gj See merge request !1215
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.fangjia</groupId>
|
||||
<artifactId>fangjia-core</artifactId>
|
||||
@@ -17,8 +17,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
<encoding>GBK</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
@@ -105,15 +105,15 @@
|
||||
<version>3.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pinyin4j</groupId>
|
||||
<artifactId>pinyin4j</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<groupId>net.sourceforge.pinyin4j</groupId>
|
||||
<artifactId>pinyin4j</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ibm.icu</groupId>
|
||||
<artifactId>icu4j</artifactId>
|
||||
<version>3.4.4</version>
|
||||
</dependency>
|
||||
<groupId>com.ibm.icu</groupId>
|
||||
<artifactId>icu4j</artifactId>
|
||||
<version>3.4.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.json-lib</groupId>
|
||||
<artifactId>json-lib</artifactId>
|
||||
@@ -124,7 +124,7 @@
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.8.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
@@ -155,11 +155,11 @@
|
||||
<artifactId>hanlp</artifactId>
|
||||
<version>portable-1.6.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-mapper-asl</artifactId>
|
||||
<version>1.9.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-mapper-asl</artifactId>
|
||||
<version>1.9.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
@@ -170,5 +170,11 @@
|
||||
<artifactId>json</artifactId>
|
||||
<version>RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.20</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -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<PriceData> getSampleData() {
|
||||
List<PriceData> 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<PriceData> getSampleData(double basePrice) {
|
||||
List<PriceData> 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<PriceData> getSampleData2() {
|
||||
List<PriceData> 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;
|
||||
}
|
||||
}
|
||||
@@ -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<RentPrice> rentPrices;//本月租金
|
||||
|
||||
private PriceTrend rentTrend;//租金走势
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public static class RentPrice {
|
||||
private String name;
|
||||
private Integer price;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PriceTrend {
|
||||
private List<String> categories;
|
||||
private List<Series> series;
|
||||
private List<DoubleSeries> doubleSeries;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Series {
|
||||
private String name;
|
||||
private List<Integer> data;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DoubleSeries {
|
||||
private String name;
|
||||
private List<Double> data;
|
||||
}
|
||||
}
|
||||
@@ -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<List<PriceData>> dataSets, List<String> labels, String title, String subtitle, int decimalPlaces) {
|
||||
if (dataSets.isEmpty() || dataSets.get(0).isEmpty()) {
|
||||
return "<svg xmlns='http://www.w3.org/2000/svg' width='" + WIDTH + "' height='" + HEIGHT + "'></svg>";
|
||||
}
|
||||
// 过滤为空的数据
|
||||
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("<svg xmlns='http://www.w3.org/2000/svg' width='%d' height='%d'>", WIDTH, HEIGHT));
|
||||
svg.append(String.format("<rect width='%d' height='%d' fill='#ffffff'/>", WIDTH, HEIGHT));
|
||||
|
||||
// 添加标题和副标题
|
||||
svg.append(String.format("<text x='%d' y='%d' font-size='20' font-family='Arial' fill='#333333' font-weight='bold' text-anchor='middle'>%s</text>",
|
||||
WIDTH / 2, 30, title));
|
||||
svg.append(String.format("<text x='%d' y='%d' font-size='14' font-family='Arial' fill='#666666' text-anchor='middle'>%s</text>",
|
||||
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("<rect x='%d' y='%d' width='10' height='10' fill='%s'/>", 650, 60 + i * 20, colors[i % colors.length]));
|
||||
svg.append(String.format("<text x='%d' y='%d' font-size='12' fill='#333333'>%s</text>", 670, 70 + i * 20, labels.get(i)));
|
||||
}
|
||||
|
||||
svg.append("</svg>");
|
||||
return svg.toString();
|
||||
}
|
||||
|
||||
// 绘制平滑折线
|
||||
private static String drawSmoothLine(List<PriceData> data, String minYearMonth, String maxYearMonth, double minPrice, double maxPrice, String color, int decimalPlaces) {
|
||||
// if (data.size() < 2) return "";
|
||||
StringBuilder path = new StringBuilder("<path d='M");
|
||||
StringBuilder pointsAndLabels = new StringBuilder();
|
||||
int totalMonths = getMonthIndex(maxYearMonth) - getMonthIndex(minYearMonth) + 1;
|
||||
if (data.size() == 1) {
|
||||
// 处理只有一个数据点的情况
|
||||
PriceData point = data.get(0);
|
||||
int monthIndex = Math.max(0, Math.min(totalMonths - 1, getMonthIndex(point.getYearmonth()) - getMonthIndex(minYearMonth)));
|
||||
int x = WIDTH / 2;
|
||||
int y = HEIGHT - PADDING - (HEIGHT - 2 * PADDING) / 2;
|
||||
// int y = HEIGHT - PADDING - (int) ((point.getPrice() - minPrice) * (HEIGHT - 2 * PADDING) / (maxPrice - minPrice));
|
||||
|
||||
pointsAndLabels.append(String.format("<circle cx='%d' cy='%d' r='3' fill='%s'/>", x, y, color));
|
||||
pointsAndLabels.append(String.format("<text x='%d' y='%d' font-size='10' fill='%s'>%." + decimalPlaces + "f</text>",
|
||||
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("<circle cx='%d' cy='%d' r='3' fill='%s'/>", x1, y1, color));
|
||||
pointsAndLabels.append(String.format("<text x='%d' y='%d' font-size='10' fill='%s'>%." + decimalPlaces + "f</text>",
|
||||
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("<circle cx='%d' cy='%d' r='3' fill='%s'/>", lastX, lastY, color));
|
||||
pointsAndLabels.append(String.format("<text x='%d' y='%d' font-size='10' fill='%s'>%." + decimalPlaces + "f</text>",
|
||||
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("<line x1='%d' y1='%d' x2='%d' y2='%d' stroke='#e0e0e0' stroke-dasharray='5,5'/>",
|
||||
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("<line x1='%d' y1='%d' x2='%d' y2='%d' stroke='#333333' stroke-width='2'/>",
|
||||
PADDING, HEIGHT - PADDING, WIDTH - PADDING, HEIGHT - PADDING));
|
||||
axis.append(String.format("<line x1='%d' y1='%d' x2='%d' y2='%d' stroke='#333333' stroke-width='2'/>",
|
||||
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("<line x1='%d' y1='%d' x2='%d' y2='%d' stroke='#333333' stroke-width='1'/>",
|
||||
x, HEIGHT - PADDING + 5, x, HEIGHT - PADDING));
|
||||
axis.append(String.format("<text x='%d' y='%d' font-size='12' fill='#333333' text-anchor='middle'>%s</text>",
|
||||
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("<line x1='%d' y1='%d' x2='%d' y2='%d' stroke='#333333' stroke-width='1'/>",
|
||||
PADDING - 5, y, PADDING, y));
|
||||
axis.append(String.format("<text x='%d' y='%d' font-size='12' fill='#333333' text-anchor='end'>%." + decimalPlaces + "f</text>",
|
||||
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<String> newCategories, List<PriceDto.DoubleSeries> series, PriceDto.PriceTrend rentTrend) {
|
||||
for (PriceDto.DoubleSeries s : series) {
|
||||
List<Double> originalData = s.getData();
|
||||
List<String> originalCategories = new ArrayList<>(rentTrend.getCategories()); // 假设原始时间轴可从别处获取
|
||||
List<Double> 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<PriceData> data1 = PriceData.getSampleData(5200);
|
||||
List<List<PriceData>> dataSets = new ArrayList<>();
|
||||
dataSets.add(data1);
|
||||
String name = "新世纪大厦";
|
||||
List<String> 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);
|
||||
}
|
||||
}
|
||||
@@ -602,5 +602,6 @@
|
||||
<!-- <artifactId>mysql-connector-java</artifactId>-->
|
||||
<!-- <version>8.0.33</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
+18
-11
@@ -1,22 +1,19 @@
|
||||
package com.fangjia.script.gj.district
|
||||
|
||||
import com.fangjia.core.util.GeoUtils
|
||||
import com.fangjia.script.commData.CommonDatautils
|
||||
import com.fangjia.script.util.ExcelUtils
|
||||
import com.fangjia.script.util.MongoUtils
|
||||
import com.fangjia.script.yinjihaun.amap.GaoDeApiUtils
|
||||
import com.mongodb.BasicDBList
|
||||
import com.mongodb.BasicDBObject
|
||||
import com.mongodb.DBCollection
|
||||
|
||||
import net.sf.json.JSONNull
|
||||
import org.bson.types.ObjectId
|
||||
|
||||
|
||||
class DistrictLocationGeo {
|
||||
|
||||
final DBCollection JD_SEAWEED_COLL = MongoUtils.getCollectionByName("business", "jingdong_community", "192.168.0.206",27020)
|
||||
final DBCollection JD_GEO_COLL = MongoUtils.getCollectionByName("business", "jingdong_geo", "192.168.0.206",27020)
|
||||
|
||||
final DBCollection JD_review_GEO_COLL = MongoUtils.getCollectionByName("business", "jingdong_review_geo", "192.168.0.206",27020)
|
||||
static main(args) {
|
||||
def task = new DistrictLocationGeo()
|
||||
task.run()//通过经纬度,调用高德逆解析,并保存数据
|
||||
@@ -25,14 +22,23 @@ class DistrictLocationGeo {
|
||||
|
||||
}
|
||||
def run(){
|
||||
ExcelUtils.multiThreadingModify("D:\\数据\\京东\\京东新增数据5.6万.xlsx",{ d->
|
||||
ExcelUtils.multiThreadingModify("D:\\数据\\京东\\房价网重复小区数据5-1217【机密】(1).xlsx",{ d->
|
||||
if(d['A']){
|
||||
def dbo = JD_SEAWEED_COLL.findOne(new BasicDBObject("_id", new ObjectId(d['A'])))
|
||||
if(dbo && dbo.longitude){
|
||||
def jsonObject = GaoDeApiUtils.geocode(dbo.longitude+","+dbo.latitude)
|
||||
// def dbo = JD_SEAWEED_COLL.findOne(new BasicDBObject("_id", new ObjectId(d['A'])))
|
||||
def obj = CommonDatautils.findDistrictById(d['A'])
|
||||
if(obj && obj.lat){
|
||||
def lat = obj.lat/10000000000.0;
|
||||
def lng = obj.lng/10000000000.0;
|
||||
def jsonObject = GaoDeApiUtils.geocode(lng+","+lat)
|
||||
if(jsonObject){
|
||||
d["F"] = "高德"
|
||||
// def dbo = new BasicDBObject()
|
||||
def dbo = new BasicDBObject()
|
||||
dbo.put("city", obj.city)
|
||||
dbo.put("district", obj.region)
|
||||
dbo.put("name", obj.name)
|
||||
dbo.put("comm_id", d['A'])
|
||||
dbo.put("lng", lng)
|
||||
dbo.put("lat", lat)
|
||||
dbo.put("formatted_address", jsonObject.regeocode.formatted_address)
|
||||
def addrComp = jsonObject.regeocode.addressComponent
|
||||
dbo.put("addressComponent", addrComp)
|
||||
@@ -42,13 +48,14 @@ class DistrictLocationGeo {
|
||||
dbo.put("aois", jsonObject.regeocode.aois)
|
||||
dbo = cleanGeoData(dbo)
|
||||
dbo = convertToDBObject(dbo)
|
||||
JD_GEO_COLL.save(dbo)
|
||||
JD_review_GEO_COLL.save(dbo)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static BasicDBObject convertToDBObject(Map map) {
|
||||
|
||||
+62
@@ -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
-1
@@ -11,7 +11,7 @@ class NanjiangVillage {
|
||||
}
|
||||
|
||||
def run(){
|
||||
ExcelUtils.multiThreadingModify("D:\\数据\\南京银行\\县城清洗-结果.xlsx",{d->
|
||||
ExcelUtils.multiThreadingModify("D:\\数据\\南京银行\\新地址核实(县城).xlsx",{d->
|
||||
|
||||
if(!d['F']){
|
||||
def dto = OpenApiUtils.addrVerifyNanjing(null, d['A'], 2)
|
||||
|
||||
+2
-2
@@ -10,10 +10,10 @@ class XiamenVillage {
|
||||
}
|
||||
|
||||
def run(){
|
||||
ExcelUtils.multiThreadingModify("D:\\数据\\厦门\\涉农组织类型判定(to估家,2025-10-31)-以此为准.xlsx",{ d->
|
||||
ExcelUtils.multiThreadingModify("D:\\数据\\厦门\\工业园区与涉农组织类型矛盾.xlsx",{ d->
|
||||
|
||||
if(!d['R']){
|
||||
def dto = OpenApiUtils.addrVerifyXiameng(null, d['B'], 2)
|
||||
def dto = OpenApiUtils.addrVerifyXiameng(null, d['A'], 2)
|
||||
if(dto){
|
||||
// def dto = jsonObj.result
|
||||
d['F'] = dto.province
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ import com.mongodb.DBCollection
|
||||
*/
|
||||
|
||||
|
||||
//@BatchOwner(Watcher.GaoJuan)
|
||||
@BatchOwner(Watcher.GaoJuan)
|
||||
class RelatedTaiWanBatch extends BaseBatch{
|
||||
|
||||
|
||||
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package com.fangjia.script.gj.xiamen
|
||||
|
||||
import com.fangjia.script.BaseBatch
|
||||
import com.fangjia.script.gj.OpenApiUtils
|
||||
import com.fangjia.script.util.DateUtil
|
||||
import com.fangjia.script.util.ExcelUtils
|
||||
|
||||
/**
|
||||
* 厦门每月月初自动跑涉农数据
|
||||
*/
|
||||
class XiaMenVillageBatch extends BaseBatch{
|
||||
|
||||
|
||||
static main(args) {
|
||||
runBatch(new XiaMenVillageBatch(), args);
|
||||
}
|
||||
|
||||
@Override
|
||||
void process(Object args) {
|
||||
def monthStr = DateUtil.formatByPattern(new Date(), "yyyy-MM");
|
||||
def outFileName = "xmbank_"+monthStr+"_result.xlsx"
|
||||
def inFileName = "xmbank_"+monthStr+".xlsx"
|
||||
def exists = checkFileExists(outFileName)
|
||||
if(!exists){
|
||||
def rows = []
|
||||
rows << ["序号","地址","判定后涉农组织类型(城市企业[不含县城企业]、农村企业、县城企业)","所属工业园区或经济开发区"]
|
||||
def rets = XmBankVillageFtpUtils.readExcelFile(inFileName)
|
||||
if(rets){
|
||||
for(def row : rets){
|
||||
if(row[1]){
|
||||
def dto = OpenApiUtils.addrVerifyXiameng(null, row[1], 2)
|
||||
if(dto){
|
||||
row[2] = dto.addrArea //所属区域 农村区域 城市区域 县城城区(对公)
|
||||
if(dto.devDistrictName){
|
||||
row[3] = dto.devDistrictName//开发区
|
||||
}else{
|
||||
row[3] = ""
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
rows << row
|
||||
}
|
||||
}
|
||||
uploadExcel(rows, outFileName)
|
||||
|
||||
}else{
|
||||
println "已存在 "+ DateUtil.formatByPattern(new Date(), "yyyy-MM-dd HH:mm:ss")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static boolean uploadExcel(def data, String fileName, String sheetName = "Sheet1") {
|
||||
if (data == null || data.isEmpty()) {
|
||||
println "数据为空,无法生成Excel"
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. 生成Excel内容
|
||||
byte[] excelBytes = ExcelUtils.createExcelBytes(data, sheetName)
|
||||
|
||||
// 2. 上传到服务器
|
||||
return XmBankVillageFtpUtils.uploadExcelBytes(excelBytes, fileName)
|
||||
|
||||
} catch (Exception e) {
|
||||
println "生成并上传Excel失败: ${e.message}"
|
||||
e.printStackTrace()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
def checkFileExists(def fileName){
|
||||
def files = XmBankVillageFtpUtils.listOutFileNames()
|
||||
def existsFlag = false
|
||||
if(files){
|
||||
for(def file : files){
|
||||
if(file.filename == fileName){
|
||||
existsFlag = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return existsFlag
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package com.fangjia.script.gj.xiamen
|
||||
|
||||
import com.fangjia.script.jiangnanblank.SFTP
|
||||
import com.fangjia.script.util.ExcelUtils
|
||||
import com.jcraft.jsch.ChannelSftp
|
||||
import org.apache.poi.ss.usermodel.Cell
|
||||
import org.apache.poi.ss.usermodel.Row
|
||||
import org.apache.poi.ss.usermodel.Sheet
|
||||
import org.apache.poi.ss.usermodel.Workbook
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory
|
||||
|
||||
import java.nio.charset.Charset
|
||||
|
||||
class XmBankVillageFtpUtils {
|
||||
static def ftpServer = "192.168.0.86"
|
||||
static def ftpPort = 17495
|
||||
static def ftpUser = "xmbank"
|
||||
static def ftpPassword = "Xmbank123!@#"
|
||||
static def ftpPath = "/output/village_data"
|
||||
static def ftpInPath = "/input/village"
|
||||
|
||||
|
||||
|
||||
static SFTP sftp = new SFTP();
|
||||
static ChannelSftp sftpChannel = sftp.connect(ftpServer, ftpPort, ftpUser, ftpPassword);
|
||||
|
||||
|
||||
static def ftpUpload(outputPath_dist, month){
|
||||
//上传到ftp
|
||||
sftpChannel = reConnect();
|
||||
sftp.upload(ftpPath, outputPath_dist, sftpChannel);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static def reConnect(){
|
||||
if(sftpChannel == null){
|
||||
println "sftpChannel 为空,需重连....."
|
||||
if(sftp == null){
|
||||
sftp = new SFTP();
|
||||
}
|
||||
sftpChannel = sftp.connect(ftpServer, ftpPort, ftpUser, ftpPassword);
|
||||
}else{
|
||||
println "sftpChannel 正常....."
|
||||
}
|
||||
return sftpChannel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static def listOutFileNames(){
|
||||
//上传到ftp
|
||||
sftpChannel = reConnect();
|
||||
Vector files = sftp.listFiles(ftpPath+"/", sftpChannel);
|
||||
return files
|
||||
}
|
||||
|
||||
static def listInFileNames(){
|
||||
//上传到ftp
|
||||
sftpChannel = reConnect();
|
||||
Vector files = sftp.listFiles(ftpInPath+"/", sftpChannel);
|
||||
return files
|
||||
}
|
||||
|
||||
static def getFileLength(String path, String month){
|
||||
sftpChannel = reConnect();
|
||||
def size = sftp.getFileSize(ftpPath+ month+"/"+path, sftpChannel)
|
||||
return size
|
||||
}
|
||||
|
||||
static def readExcelFile(String fileName) {
|
||||
sftpChannel = reConnect()
|
||||
try {
|
||||
// 构建完整的远程路径
|
||||
String fullRemotePath = ftpInPath + "/"+fileName
|
||||
println "开始读取Excel文件: ${fullRemotePath}"
|
||||
// 从SFTP服务器获取文件流
|
||||
InputStream inputStream = sftpChannel.get(fullRemotePath)
|
||||
def excelData = ExcelUtils.readFromStream(inputStream, 0, 1)
|
||||
println "Excel共有 ${excelData.size()} 行数据"
|
||||
inputStream.close()
|
||||
return excelData
|
||||
} catch (Exception e) {
|
||||
println "读取Excel文件失败: ${e.message}"
|
||||
e.printStackTrace()
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传Excel字节数组到服务器
|
||||
* @param excelBytes Excel字节数组
|
||||
* @param fileName 文件名
|
||||
* @return 上传是否成功
|
||||
*/
|
||||
private static boolean uploadExcelBytes(byte[] excelBytes, String fileName) {
|
||||
sftpChannel = reConnect()
|
||||
|
||||
try {
|
||||
// 构建完整的远程路径
|
||||
String remoteFilePath = "${ftpPath}/${fileName}"
|
||||
|
||||
println "开始上传Excel文件到: ${remoteFilePath}"
|
||||
println "文件大小: ${excelBytes.length} 字节"
|
||||
|
||||
// 将字节数组转换为输入流
|
||||
InputStream inputStream = new ByteArrayInputStream(excelBytes)
|
||||
|
||||
// 上传文件
|
||||
sftpChannel.put(inputStream, remoteFilePath)
|
||||
|
||||
// 关闭流
|
||||
inputStream.close()
|
||||
|
||||
println "Excel文件上传成功: ${remoteFilePath}"
|
||||
|
||||
return true
|
||||
|
||||
} catch (Exception e) {
|
||||
println "上传Excel文件失败: ${e.message}"
|
||||
e.printStackTrace()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+217
-12
@@ -1,24 +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.MongoUtils
|
||||
import com.fangjia.script.util.OpenApiClient
|
||||
import com.mongodb.DBCollection
|
||||
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"
|
||||
@@ -36,11 +39,13 @@ class TestEvaluation {
|
||||
// task.newAndOldMatch()
|
||||
|
||||
// task.addFjwToBprice("D:\\数据\\宏信息\\宏信房源台账-价格.xlsx")
|
||||
// task.addAreaFactor()
|
||||
task.addAreaFactor()
|
||||
|
||||
// task.addOptName()
|
||||
// task.addDistId()
|
||||
task.addEvaluationToDB()
|
||||
// task.addEvaluationToDB()
|
||||
|
||||
// task.addEvaluationDetail()
|
||||
}
|
||||
|
||||
def houseSimilar(){
|
||||
@@ -293,7 +298,7 @@ class TestEvaluation {
|
||||
|
||||
|
||||
def addAreaFactor(){
|
||||
ExcelUtils.multiThreadingModify("D:\\数据\\宏信息\\宏信房源台账-基准价(含ID).xlsx",{d->
|
||||
ExcelUtils.multiThreadingModify("D:\\数据\\宏信息\\(红色)宏信估值详情-最新0106.xlsx",{d->
|
||||
if(d['I'] && d['J'] && d['K']){
|
||||
def dist = CommonDatautils.findDistrictById(d['I'])
|
||||
if(dist){
|
||||
@@ -309,6 +314,11 @@ class TestEvaluation {
|
||||
// }
|
||||
// d['L']=(int)(d['J']*d['K'])
|
||||
// d['N'] = (int)(d['L'] + d['L']*d['M'])
|
||||
def obj = CommonDatautils.queryDistrictPriceData(dist.city, dist.region, dist.name)
|
||||
if(obj && obj.avg_price_2b){
|
||||
d['M'] = obj.avg_price_2b
|
||||
d['L'] = (int)(obj.avg_price_2b * d['K'])
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -357,7 +367,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,14 +375,16 @@ 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()]
|
||||
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(), 2]
|
||||
}
|
||||
}
|
||||
},1)
|
||||
@@ -381,15 +393,208 @@ class TestEvaluation {
|
||||
}
|
||||
|
||||
def addDataToDB(rows){
|
||||
def sqlstring = "insert into evaluation(user_id, city, region, district_name, address, build_type, house_area, total_price, lng, lat, org_code, create_time, update_time, cat, unit_price ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||
def sqlstring = "insert into evaluation(user_id, city, region, district_name, address, build_type, house_area, total_price, lng, lat, org_code, create_time, update_time, cat, unit_price,report_type,average_price ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||
|
||||
sql.withBatch(1, sqlstring){ ps->
|
||||
for(def r : rows) {
|
||||
ps.addBatch(r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14])
|
||||
ps.addBatch(r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15],r[14])
|
||||
ps.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def addEvaluationDetail(){
|
||||
def rets = []
|
||||
|
||||
def detailList = ExcelUtils.read("D:\\数据\\宏信息\\宏信房源台账-基准价-详情.xlsx", 0 , 1)
|
||||
ExcelUtils.modify("D:\\数据\\宏信息\\宏信项目-最终.xlsx", { d ->
|
||||
if (d['G'] && d['L'] && d['L'].toString().toDouble().toInteger()>=3472507) {
|
||||
def rows = findEvaluationIdExists(d['L'].toString().toDouble().toInteger())
|
||||
if(!rows){
|
||||
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 = avgPrice
|
||||
maxPrice = (int)(avgPrice + avgPrice * 0.1)
|
||||
}
|
||||
houses = OpenApiClient.newHouseAction(dist.city, dist.region, dist.name, propertyType.toString(), minPrice, maxPrice, 5)
|
||||
|
||||
if(houses.size()<5){
|
||||
if(avgPrice){
|
||||
minPrice = avgPrice
|
||||
maxPrice = (int)(avgPrice + avgPrice * 0.2)
|
||||
}
|
||||
houses = OpenApiClient.newHouseAction(dist.city, dist.region, dist.name, propertyType.toString(), minPrice, maxPrice, 15)
|
||||
}
|
||||
}
|
||||
if(houses){
|
||||
ret << createHouse(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)
|
||||
saveEvaluationEditData(ret)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
def saveEvaluationEditData(r){
|
||||
|
||||
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->
|
||||
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 findEvaluationIdExists(evaluationId){
|
||||
def query = "SELECT * FROM evaluation_edit_data WHERE evaluation_id = ? LIMIT 1"
|
||||
return sql.firstRow(query, [evaluationId])
|
||||
}
|
||||
|
||||
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 = 0
|
||||
if (data['H'] && data['N']){
|
||||
totalPrice = (int)(data['H'] * data['N'])
|
||||
}
|
||||
def unitPrice = 0
|
||||
if(data['N']){
|
||||
unitPrice = data['N'].toString().toDouble().toInteger()
|
||||
}
|
||||
items << ["city":dist.city, "district":dist.region, "address":data['B'], "area":data['H'], "unitPrice":unitPrice, "totalPrice":totalPrice]
|
||||
}
|
||||
}
|
||||
|
||||
if(items.size()>1){
|
||||
def time = new Date().getTime()
|
||||
def resMap = ["id":"attachment_"+time, "title": "出售资产价格清单","type": 1,"editing": false,"items":items]
|
||||
return [resMap]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
def createHouse(houses){
|
||||
def rets = []
|
||||
def i = 0
|
||||
def time = new Date().getTime()
|
||||
for(def h : houses){
|
||||
def pdate = h.caseDate.replace("-","").substring(0,6)
|
||||
rets << ["city":h.city, "district":h.district, "name":h.name, "publishDate":pdate, "unitPrice":h.unitPrice, "_uid":"sample_"+time+"_"+i,"source":h.source, "area":h.size, "distance":h.distance, "totalPrice":h.totalPrice]
|
||||
i++
|
||||
}
|
||||
return rets;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.apache.poi.ss.usermodel.*
|
||||
import org.apache.poi.ss.util.CellRangeAddress
|
||||
import org.apache.poi.ss.util.RegionUtil
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook
|
||||
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
@@ -103,6 +104,50 @@ public class ExcelUtils{
|
||||
}
|
||||
|
||||
|
||||
public static List<List<Object>> readFromStream(def inp,int sheetIndex = 0,int skipRow = 1){
|
||||
List<ExcelRow<Object>> ret = new ArrayList<ExcelRow<Object>>();
|
||||
try {
|
||||
Workbook workbook = WorkbookFactory.create(inp)
|
||||
workbook.setForceFormulaRecalculation(true)
|
||||
Sheet sheet = workbook.getSheetAt(sheetIndex);
|
||||
//行号
|
||||
int rowIndex = 0;
|
||||
for(Row row : sheet){
|
||||
rowIndex ++
|
||||
if(rowIndex <= skipRow){
|
||||
continue;
|
||||
}
|
||||
short minColIx = 0;
|
||||
short maxColIx = row.getLastCellNum();
|
||||
List<Object> rowData = new ExcelRow<Object>();
|
||||
for(short colIx=minColIx; colIx<maxColIx; colIx++) {
|
||||
Cell cell = row.getCell(colIx);
|
||||
if(cell == null) {
|
||||
rowData.add(colIx, null);
|
||||
}else{
|
||||
rowData.add(getCellValue(cell))
|
||||
}
|
||||
}
|
||||
ret.add(rowData);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
if (inp != null){
|
||||
try {
|
||||
inp.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static String getSheetName(String fileName, Integer srcSheetIndex = 0){
|
||||
def inp = new FileInputStream(fileName);
|
||||
Workbook workbook = WorkbookFactory.create(inp)
|
||||
@@ -297,7 +342,7 @@ public class ExcelUtils{
|
||||
row = mainSheet.createRow(rowIndex);
|
||||
row.setHeightInPoints(30)
|
||||
List<Object> rowDataList = data.get(rowIndex);
|
||||
if(rowDataList == null) continue
|
||||
if(rowDataList == null) continue
|
||||
try{
|
||||
for(int cellIndex = 0 ; cellIndex < rowDataList.size();cellIndex++){
|
||||
Cell cell = row.createCell(cellIndex);
|
||||
@@ -499,9 +544,9 @@ public class ExcelUtils{
|
||||
try{
|
||||
return cell.getStringCellValue()
|
||||
}catch (Exception ex){
|
||||
println cell.getColumnIndex()
|
||||
println cell.getRowIndex()
|
||||
return cell.getRichStringCellValue().getString()
|
||||
println cell.getColumnIndex()
|
||||
println cell.getRowIndex()
|
||||
return cell.getRichStringCellValue().getString()
|
||||
}
|
||||
}
|
||||
case Cell.CELL_TYPE_NUMERIC:
|
||||
@@ -515,4 +560,220 @@ public class ExcelUtils{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Excel字节数组
|
||||
* @param data Excel数据
|
||||
* @param sheetName Sheet名称
|
||||
* @return Excel文件的字节数组
|
||||
*/
|
||||
private static byte[] createExcelBytes(List<List<String>> data, String sheetName) {
|
||||
Workbook workbook = null
|
||||
ByteArrayOutputStream outputStream = null
|
||||
|
||||
try {
|
||||
// 创建新的工作簿(使用.xlsx格式)
|
||||
workbook = new XSSFWorkbook()
|
||||
|
||||
// 创建样式(可选)
|
||||
CellStyle headerStyle = createHeaderStyle(workbook)
|
||||
CellStyle dataStyle = createDataStyle(workbook)
|
||||
|
||||
// 创建Sheet
|
||||
Sheet sheet = workbook.createSheet(sheetName)
|
||||
sheet.setColumnWidth(0, 5 * 256)
|
||||
sheet.setColumnWidth(1, 100 * 256)
|
||||
sheet.setColumnWidth(2, 20 * 256)
|
||||
sheet.setColumnWidth(3, 50 * 256)
|
||||
|
||||
// 写入数据
|
||||
writeDataToSheet(sheet, data, headerStyle, dataStyle)
|
||||
|
||||
// 自动调整列宽(可选)
|
||||
// autoSizeColumns(sheet, data)
|
||||
|
||||
// 将工作簿写入字节数组
|
||||
outputStream = new ByteArrayOutputStream()
|
||||
workbook.write(outputStream)
|
||||
|
||||
return outputStream.toByteArray()
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("创建Excel失败: ${e.message}", e)
|
||||
} finally {
|
||||
// 关闭资源
|
||||
try {
|
||||
if (outputStream != null) {
|
||||
outputStream.close()
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建表头样式
|
||||
*/
|
||||
private static CellStyle createHeaderStyle(Workbook workbook) {
|
||||
CellStyle style = workbook.createCellStyle()
|
||||
|
||||
// 设置字体
|
||||
Font font = workbook.createFont()
|
||||
// font.setBoldweight(7)
|
||||
font.setBoldweight(Font.BOLDWEIGHT_BOLD)
|
||||
font.setFontHeightInPoints((short) 12)
|
||||
font.setColor(IndexedColors.BLACK.getIndex())
|
||||
style.setFont(font)
|
||||
|
||||
// 设置背景色
|
||||
style.setFillForegroundColor(IndexedColors.TURQUOISE.getIndex())
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND)
|
||||
|
||||
// 设置边框
|
||||
// style.setBorderBottom(BorderStyle.THIN)
|
||||
// style.setBorderTop(BorderStyle.THIN)
|
||||
// style.setBorderRight(BorderStyle.THIN)
|
||||
// style.setBorderLeft(BorderStyle.THIN)
|
||||
|
||||
// 居中
|
||||
style.setAlignment(HorizontalAlignment.CENTER)
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER)
|
||||
|
||||
return style
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据样式
|
||||
*/
|
||||
private static CellStyle createDataStyle(Workbook workbook) {
|
||||
CellStyle style = workbook.createCellStyle()
|
||||
|
||||
// 设置边框
|
||||
// style.setBorderBottom(BorderStyle.THIN)
|
||||
// style.setBorderTop(BorderStyle.THIN)
|
||||
// style.setBorderRight(BorderStyle.THIN)
|
||||
// style.setBorderLeft(BorderStyle.THIN)
|
||||
|
||||
// 自动换行
|
||||
style.setWrapText(true)
|
||||
|
||||
return style
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动调整列宽
|
||||
*/
|
||||
private static void autoSizeColumns(Sheet sheet, List<List<String>> data) {
|
||||
if (data.isEmpty()) return
|
||||
|
||||
int maxColumns = data.max { it.size() }?.size() ?: 0
|
||||
|
||||
for (int i = 0; i < maxColumns; i++) {
|
||||
sheet.autoSizeColumn(i)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入数据到Sheet
|
||||
*/
|
||||
private static void writeDataToSheet(Sheet sheet, List<List<String>> data,
|
||||
CellStyle headerStyle, CellStyle dataStyle) {
|
||||
// 判断是否有表头(第一行是否为表头)
|
||||
boolean hasHeader = data.size() > 0
|
||||
|
||||
for (int rowIndex = 0; rowIndex < data.size(); rowIndex++) {
|
||||
List<String> rowData = data[rowIndex]
|
||||
Row row = sheet.createRow(rowIndex)
|
||||
|
||||
if(rowIndex == 0){
|
||||
row.setHeightInPoints(35.0)
|
||||
}
|
||||
for (int colIndex = 0; colIndex < rowData.size(); colIndex++) {
|
||||
Cell cell = row.createCell(colIndex)
|
||||
String cellValue = rowData[colIndex] ?: ""
|
||||
|
||||
// 设置单元格值
|
||||
setCellValue(cell, cellValue)
|
||||
|
||||
// 应用样式
|
||||
if (rowIndex == 0 && hasHeader && headerStyle != null) {
|
||||
cell.setCellStyle(headerStyle)
|
||||
} else if (dataStyle != null) {
|
||||
cell.setCellStyle(dataStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置单元格值(智能识别类型)
|
||||
*/
|
||||
private static void setCellValue(Cell cell, String value) {
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
cell.setCellValue("")
|
||||
return
|
||||
}
|
||||
|
||||
// 尝试判断是否为数字
|
||||
if (isNumeric(value)) {
|
||||
try {
|
||||
if (value.contains(".")) {
|
||||
cell.setCellValue(Double.parseDouble(value))
|
||||
} else {
|
||||
cell.setCellValue(Long.parseLong(value))
|
||||
}
|
||||
return
|
||||
} catch (Exception e) {
|
||||
// 如果不是数字,继续
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试判断是否为日期
|
||||
if (isDate(value)) {
|
||||
try {
|
||||
// 这里可以添加日期格式转换逻辑
|
||||
// 暂时按字符串处理
|
||||
cell.setCellValue(value)
|
||||
} catch (Exception e) {
|
||||
cell.setCellValue(value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 默认为字符串
|
||||
cell.setCellValue(value)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查字符串是否为数字
|
||||
*/
|
||||
private static boolean isNumeric(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return false
|
||||
}
|
||||
// 允许小数点、负号
|
||||
return str.matches("-?\\d+(\\.\\d+)?")
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查字符串是否为日期(简单判断)
|
||||
*/
|
||||
private static boolean isDate(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return false
|
||||
}
|
||||
// 常见的日期格式模式
|
||||
def datePatterns = [
|
||||
/^\d{4}-\d{2}-\d{2}$/,
|
||||
/^\d{4}\/\d{2}\/\d{2}$/,
|
||||
/^\d{4}年\d{2}月\d{2}日$/,
|
||||
/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/
|
||||
]
|
||||
|
||||
return datePatterns.any { pattern -> str =~ pattern }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.toString())
|
||||
}
|
||||
if(maxPrice){
|
||||
params.put("maxPrice", maxPrice.toString())
|
||||
}
|
||||
if(pageSize){
|
||||
params.put("pageSize", pageSize.toString())
|
||||
}
|
||||
|
||||
String content = new HttpRequest().get("http://localhost:8080/property/sellCase", params, "utf-8")
|
||||
JSONObject result = JSONObject.fromObject(content);
|
||||
while (result == null) {
|
||||
result = HttpRequestUtil.getJsonContent("http://localhost:8080/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
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.zip.GZIPInputStream
|
||||
|
||||
class GaoDeApiUtils {
|
||||
//67423021cae3b58e5c2ac595a389b036 :临时买的key
|
||||
def static GAO_DE_AK = "67423021cae3b58e5c2ac595a389b036" //宝剑:c6fcd4bfbc40d73ee762b8115dca3390
|
||||
def static GAO_DE_AK = "d22fcd4274e037fdd1e9357d91152504" //宝剑:c6fcd4bfbc40d73ee762b8115dca3390
|
||||
//15021384995:dfc2245bac8a7b2d5b62e060e59d4eca
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user