优化报告折线图
This commit is contained in:
@@ -159,6 +159,11 @@
|
|||||||
<artifactId>jfreechart</artifactId>
|
<artifactId>jfreechart</artifactId>
|
||||||
<version>1.5.3</version>
|
<version>1.5.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.xmlgraphics</groupId>
|
||||||
|
<artifactId>batik-codec</artifactId>
|
||||||
|
<version>1.12</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.sothis</groupId>
|
<groupId>org.sothis</groupId>
|
||||||
<artifactId>sothis-core</artifactId>
|
<artifactId>sothis-core</artifactId>
|
||||||
|
|||||||
+46
-8
@@ -26,11 +26,18 @@ import com.fangjia.service.mongo.fangjia.FileService;
|
|||||||
import com.fangjia.service.mongo.fangjia.SeawaterService;
|
import com.fangjia.service.mongo.fangjia.SeawaterService;
|
||||||
import com.fangjia.service.util.DistrictScoreUtil;
|
import com.fangjia.service.util.DistrictScoreUtil;
|
||||||
import com.lowagie.text.pdf.BaseFont;
|
import com.lowagie.text.pdf.BaseFont;
|
||||||
|
import org.apache.batik.transcoder.Transcoder;
|
||||||
|
import org.apache.batik.transcoder.TranscoderException;
|
||||||
|
import org.apache.batik.transcoder.TranscoderInput;
|
||||||
|
import org.apache.batik.transcoder.TranscoderOutput;
|
||||||
|
import org.apache.batik.transcoder.image.JPEGTranscoder;
|
||||||
|
import org.apache.batik.transcoder.image.PNGTranscoder;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.search.BooleanClause;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.sothis.core.util.CollectionUtils;
|
import org.sothis.core.util.CollectionUtils;
|
||||||
@@ -39,11 +46,10 @@ import org.sothis.web.mvc.annotation.Param;
|
|||||||
import org.xhtmlrenderer.pdf.ITextFontResolver;
|
import org.xhtmlrenderer.pdf.ITextFontResolver;
|
||||||
import org.xhtmlrenderer.pdf.ITextRenderer;
|
import org.xhtmlrenderer.pdf.ITextRenderer;
|
||||||
|
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -84,7 +90,7 @@ public class CcbRentController {
|
|||||||
public Object downloadPageAction(PropertyEvaluationModel result, HttpServletRequest request, @Param(name = "city") String city, @Param(name = "district") String districtStr,
|
public Object downloadPageAction(PropertyEvaluationModel result, HttpServletRequest request, @Param(name = "city") String city, @Param(name = "district") String districtStr,
|
||||||
@Param(name = "name") String name, @Param(name = "address") String address,
|
@Param(name = "name") String name, @Param(name = "address") String address,
|
||||||
@Param(name = "size") Double size, @Param(name = "floor") Integer floor, @Param(name = "height") Integer height, @Param(name = "room") Integer room,
|
@Param(name = "size") Double size, @Param(name = "floor") Integer floor, @Param(name = "height") Integer height, @Param(name = "room") Integer room,
|
||||||
@Param(name = "hall") Integer hall, @Param(name = "toilet") Integer toilet, @Param(name = "direction") String direction, @Param(name = "fitment") String fitment) {
|
@Param(name = "hall") Integer hall, @Param(name = "toilet") Integer toilet, @Param(name = "direction") String direction, @Param(name = "fitment") String fitment, @Param(name = "chartImgUrl") String chartImgUrl) {
|
||||||
com.fangjia.open.model.PropertyEvaluationModel model = new com.fangjia.open.model.PropertyEvaluationModel();
|
com.fangjia.open.model.PropertyEvaluationModel model = new com.fangjia.open.model.PropertyEvaluationModel();
|
||||||
model.setCity(city);
|
model.setCity(city);
|
||||||
model.setDistrict(districtStr);
|
model.setDistrict(districtStr);
|
||||||
@@ -261,7 +267,8 @@ public class CcbRentController {
|
|||||||
districtPriceMap.put("trends", trendsMap);
|
districtPriceMap.put("trends", trendsMap);
|
||||||
|
|
||||||
// 生成走势图图片,一遍转pdf
|
// 生成走势图图片,一遍转pdf
|
||||||
String tradesImgUrl = buildTrendImage(trendsMap, room);
|
//String tradesImgUrl = buildTrendImage(trendsMap, room);
|
||||||
|
String tradesImgUrl = chartImgUrl;
|
||||||
|
|
||||||
//成交的租房房源
|
//成交的租房房源
|
||||||
List<RentDealPrice> rentTrades = rentDealPriceService.getRentDealPrices(district.getCity(), district.getRegion(), district.getName(), 5);
|
List<RentDealPrice> rentTrades = rentDealPriceService.getRentDealPrices(district.getCity(), district.getRegion(), district.getName(), 5);
|
||||||
@@ -426,23 +433,54 @@ public class CcbRentController {
|
|||||||
return evaluation;
|
return evaluation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object saveHighChartAsImageAction(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
String svg = request.getParameter("svg");
|
||||||
|
ByteArrayOutputStream out = null;
|
||||||
|
String url = null;
|
||||||
|
try {
|
||||||
|
svg = svg.replaceAll(":rect", "rect");
|
||||||
|
Transcoder t = new PNGTranscoder();
|
||||||
|
out = new ByteArrayOutputStream();
|
||||||
|
TranscoderInput input = new TranscoderInput(new StringReader(svg));
|
||||||
|
TranscoderOutput output = new TranscoderOutput(out);
|
||||||
|
t.transcode(input, output);
|
||||||
|
byte[] data = out.toByteArray();
|
||||||
|
String id = new ObjectId().toString();
|
||||||
|
fileService.save(id,"o", data, "image/png", "o");
|
||||||
|
url = "http://img0.fangjia.com/stc/fs/" + DataUtil.encodePicUrl(id, "o", "house");
|
||||||
|
} catch (TranscoderException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JsonModel model = new JsonModel();
|
||||||
|
AutoCompleteBo bo = new AutoCompleteBo();
|
||||||
|
bo.setAddress(url);
|
||||||
|
model.setJsonModel(bo);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
public void downloadAction(HttpServletResponse response, HttpServletRequest request, @Param(name = "city") String city, @Param(name = "district") String district,
|
public void downloadAction(HttpServletResponse response, HttpServletRequest request, @Param(name = "city") String city, @Param(name = "district") String district,
|
||||||
@Param(name = "name") String name, @Param(name = "address") String address,
|
@Param(name = "name") String name, @Param(name = "address") String address,
|
||||||
@Param(name = "size") Double size, @Param(name = "floor") Integer floor, @Param(name = "height") Integer height, @Param(name = "room") Integer room,
|
@Param(name = "size") Double size, @Param(name = "floor") Integer floor, @Param(name = "height") Integer height, @Param(name = "room") Integer room,
|
||||||
@Param(name = "hall") Integer hall, @Param(name = "toilet") Integer toilet, @Param(name = "direction") String direction, @Param(name = "fitment") String fitment) throws IOException {
|
@Param(name = "hall") Integer hall, @Param(name = "toilet") Integer toilet, @Param(name = "direction") String direction, @Param(name = "fitment") String fitment, @Param(name = "chartImgUrl") String chartImgUrl) throws IOException {
|
||||||
response.setHeader("Content-disposition", "attachment; filename=report.pdf");
|
response.setHeader("Content-disposition", "attachment; filename=report.pdf");
|
||||||
response.setContentType("application/pdf;charset=UTF-8");
|
response.setContentType("application/pdf;charset=UTF-8");
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
OutputStream os = null;
|
OutputStream os = null;
|
||||||
try {
|
try {
|
||||||
os = response.getOutputStream();
|
os = response.getOutputStream();
|
||||||
ITextRenderer renderer = new ITextRenderer(35, 21);
|
ITextRenderer renderer = new ITextRenderer(35, 24);
|
||||||
ITextFontResolver fontResolver = renderer.getFontResolver();
|
ITextFontResolver fontResolver = renderer.getFontResolver();
|
||||||
String fontUrl = ActionContext.getContext().getServletContext().getRealPath("/") + "fonts" + File.separator + "simsun.ttc";
|
String fontUrl = ActionContext.getContext().getServletContext().getRealPath("/") + "fonts" + File.separator + "simsun.ttc";
|
||||||
fontResolver.addFont(fontUrl, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
fontResolver.addFont(fontUrl, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
||||||
final String path = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
|
final String path = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
|
||||||
String url = path + "/ccbRent/downloadPage?city=" + DataUtil.urlEncode(city) + "&district="+DataUtil.urlEncode(district)+"&name="+DataUtil.urlEncode(name);
|
String url = path + "/ccbRent/downloadPage?city=" + DataUtil.urlEncode(city) + "&district="+DataUtil.urlEncode(district)+"&name="+DataUtil.urlEncode(name);
|
||||||
url += "&address=" + DataUtil.urlEncode(address) +"&size="+size+"&floor="+floor+"&height="+height+"&room="+room+"&hall="+hall+"&toilet="+toilet+"&direction="+direction+"&fitment="+fitment;
|
url += "&address=" + DataUtil.urlEncode(address) +"&size="+size+"&floor="+floor+"&height="+height+"&room="+room+"&hall="+hall+"&toilet="+toilet+"&direction="+direction+"&fitment="+fitment+"&chartImgUrl="+chartImgUrl;
|
||||||
renderer.setDocument(url);
|
renderer.setDocument(url);
|
||||||
renderer.layout();
|
renderer.layout();
|
||||||
renderer.createPDF(os, true);
|
renderer.createPDF(os, true);
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ package com.fangjia.open.util;
|
|||||||
|
|
||||||
import com.fangjia.core.util.DataUtil;
|
import com.fangjia.core.util.DataUtil;
|
||||||
import com.fangjia.service.mongo.fangjia.FileService;
|
import com.fangjia.service.mongo.fangjia.FileService;
|
||||||
|
import org.apache.batik.transcoder.Transcoder;
|
||||||
|
import org.apache.batik.transcoder.TranscoderException;
|
||||||
|
import org.apache.batik.transcoder.TranscoderInput;
|
||||||
|
import org.apache.batik.transcoder.TranscoderOutput;
|
||||||
|
import org.apache.batik.transcoder.image.JPEGTranscoder;
|
||||||
|
import org.apache.batik.transcoder.image.PNGTranscoder;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
import org.jfree.chart.ChartFactory;
|
import org.jfree.chart.ChartFactory;
|
||||||
import org.jfree.chart.ChartPanel;
|
import org.jfree.chart.ChartPanel;
|
||||||
@@ -16,9 +22,7 @@ import org.jfree.data.category.DefaultCategoryDataset;
|
|||||||
import org.jfree.ui.RefineryUtilities;
|
import org.jfree.ui.RefineryUtilities;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -99,6 +103,42 @@ public class LineChartsUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void svg2ImgTest() {
|
||||||
|
String svg = "<svg height=\"200\" xmlns=\"http://www.w3.org/2000/svg\"><polygon points=\"10,10 75,150 150,60\" style=\"fill:#63BCF7;stroke:black;stroke-width:3\"/></svg>";
|
||||||
|
String type="image/png";
|
||||||
|
String filename="svg";
|
||||||
|
if (null != type && null != svg) {
|
||||||
|
svg = svg.replaceAll(":rect", "rect");
|
||||||
|
String ext = "";
|
||||||
|
Transcoder t = null;
|
||||||
|
if (type.equals("image/png")) {
|
||||||
|
ext = "png";
|
||||||
|
t = new PNGTranscoder();
|
||||||
|
}
|
||||||
|
else if (type.equals("image/jpeg")) {
|
||||||
|
ext = "jpg";
|
||||||
|
t = new JPEGTranscoder();
|
||||||
|
}
|
||||||
|
if (null != t) {
|
||||||
|
OutputStream out = null;
|
||||||
|
try {
|
||||||
|
out = new FileOutputStream("D:\\"+filename+"."+ext);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
TranscoderInput input = new TranscoderInput(new StringReader(svg));
|
||||||
|
TranscoderOutput output = new TranscoderOutput(out);
|
||||||
|
try{
|
||||||
|
t.transcode(input, output);
|
||||||
|
System.out.println("out");
|
||||||
|
}
|
||||||
|
catch (TranscoderException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定义图表对象
|
* 定义图表对象
|
||||||
* @param rowKey 曲线名,如一居室
|
* @param rowKey 曲线名,如一居室
|
||||||
|
|||||||
@@ -18,11 +18,11 @@
|
|||||||
body {
|
body {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
background: #f8f8f8;
|
background: white;
|
||||||
}
|
}
|
||||||
.main {
|
.main {
|
||||||
margin: 4px 8px 4px 8px;
|
margin: 4px 8px 4px 8px;
|
||||||
background: #f8f8f8;
|
background: white;
|
||||||
}
|
}
|
||||||
.title {
|
.title {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -107,6 +107,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="title1">5 历史租金</div>
|
<div class="title1">5 历史租金</div>
|
||||||
<div class="charts" id="districtRentTrendsChart"></div>
|
<div class="charts" id="districtRentTrendsChart"></div>
|
||||||
|
<input type="hidden" id="chartImgUrl"/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="title1">6 已租房源</div>
|
<div class="title1">6 已租房源</div>
|
||||||
@@ -181,7 +182,8 @@
|
|||||||
<script type='text/javascript' src='http://g.alicdn.com/sj/lib/zepto/zepto.js' charset='utf-8'></script>
|
<script type='text/javascript' src='http://g.alicdn.com/sj/lib/zepto/zepto.js' charset='utf-8'></script>
|
||||||
<script type='text/javascript' src='http://g.alicdn.com/msui/sm/0.6.2/js/sm.js' charset='utf-8'></script>
|
<script type='text/javascript' src='http://g.alicdn.com/msui/sm/0.6.2/js/sm.js' charset='utf-8'></script>
|
||||||
<!-- 暂时注释 -->
|
<!-- 暂时注释 -->
|
||||||
<script type="text/javascript" src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script>
|
<script type="text/javascript" src="http://cdn.highcharts.com.cn/highcharts/9.0.1/highcharts.js"></script>
|
||||||
|
<script type="text/javascript" src="https://code.highcharts.com.cn/highcharts/modules/exporting.js"></script>
|
||||||
<script type='text/javascript' src='../static/js/wx.js' charset='utf-8'></script>
|
<script type='text/javascript' src='../static/js/wx.js' charset='utf-8'></script>
|
||||||
<script type="text/javascript" src="../static/js/trend-charts.js"></script>
|
<script type="text/javascript" src="../static/js/trend-charts.js"></script>
|
||||||
<script src="https://html2canvas.hertzen.com/dist/html2canvas.js"></script>
|
<script src="https://html2canvas.hertzen.com/dist/html2canvas.js"></script>
|
||||||
@@ -220,9 +222,11 @@
|
|||||||
// jspdf.addFont('SourceHanSans-Normal.ttf', 'SourceHanSans-Normal', 'normal');
|
// jspdf.addFont('SourceHanSans-Normal.ttf', 'SourceHanSans-Normal', 'normal');
|
||||||
// jspdf.setFont('SourceHanSans-Light');
|
// jspdf.setFont('SourceHanSans-Light');
|
||||||
//console.log(jspdf.getFontList());
|
//console.log(jspdf.getFontList());
|
||||||
|
var chart;
|
||||||
$("#download").bind('click', function(){
|
$("#download").bind('click', function(){
|
||||||
|
var chartImgUrl = $('#chartImgUrl').val();
|
||||||
window.location.href = "download?city="+params.city+"&district="+params.district+"&name="+params.name+"&address="+params.address+"&size="+params.size+"&floor="+params.floor
|
window.location.href = "download?city="+params.city+"&district="+params.district+"&name="+params.name+"&address="+params.address+"&size="+params.size+"&floor="+params.floor
|
||||||
+"&height="+params.height+"&room="+params.room+"&hall="+params.hall+"&toilet="+params.toilet+"&direction="+params.direction+"&fitment="+params.fitment;
|
+"&height="+params.height+"&room="+params.room+"&hall="+params.hall+"&toilet="+params.toilet+"&direction="+params.direction+"&fitment="+params.fitment+"&chartImgUrl=" + chartImgUrl;
|
||||||
// jspdf.html(document.body, {
|
// jspdf.html(document.body, {
|
||||||
// callback: function (doc) {
|
// callback: function (doc) {
|
||||||
// doc.save("租金报告.pdf");
|
// doc.save("租金报告.pdf");
|
||||||
@@ -428,8 +432,9 @@
|
|||||||
var config = {yaxis : yaxis};
|
var config = {yaxis : yaxis};
|
||||||
createHighChartNow(renderId, data, config);
|
createHighChartNow(renderId, data, config);
|
||||||
};
|
};
|
||||||
|
|
||||||
function createHighChartNow(renderId, data, config) {
|
function createHighChartNow(renderId, data, config) {
|
||||||
var chart = new Highcharts.Chart({
|
chart = new Highcharts.Chart({
|
||||||
credits:{
|
credits:{
|
||||||
enabled:true,
|
enabled:true,
|
||||||
text: '',
|
text: '',
|
||||||
@@ -448,6 +453,9 @@
|
|||||||
renderTo: renderId,
|
renderTo: renderId,
|
||||||
type: 'spline'
|
type: 'spline'
|
||||||
},
|
},
|
||||||
|
exporting: {
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
title: {
|
title: {
|
||||||
text: data.title,
|
text: data.title,
|
||||||
floating: false,
|
floating: false,
|
||||||
@@ -481,7 +489,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
saveHighChartImg();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function saveHighChartImg() {
|
||||||
|
var svg = chart.getSVG();
|
||||||
|
$.ajax({
|
||||||
|
// 注意需要加..
|
||||||
|
url: "saveHighChartAsImage",
|
||||||
|
data: {
|
||||||
|
svg:svg
|
||||||
|
},
|
||||||
|
dataType: "json",
|
||||||
|
type: "post",
|
||||||
|
success: function (ret) {
|
||||||
|
if (ret.address != null) {
|
||||||
|
$('#chartImgUrl').val(ret.address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
$(function () {
|
$(function () {
|
||||||
init();
|
init();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,26 +18,26 @@
|
|||||||
body {
|
body {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
background: #f8f8f8;
|
background: white;
|
||||||
/** 特别注意,否则中文不生效 **/
|
/** 特别注意,否则中文不生效 **/
|
||||||
font-family: SimSun;
|
font-family: SimSun;
|
||||||
}
|
}
|
||||||
.main {
|
.main {
|
||||||
margin: 4px 8px 4px 8px;
|
margin: 4px 8px 4px 8px;
|
||||||
background: #f8f8f8;
|
background: white;
|
||||||
}
|
}
|
||||||
.title {
|
.title {
|
||||||
position: relative;
|
position: relative;
|
||||||
color: #1E90FF;
|
color: #1E90FF;
|
||||||
}
|
}
|
||||||
.title1 {
|
.title1 {
|
||||||
font-size: 15px;
|
font-size: 19px;
|
||||||
color: #1E90FF;
|
color: #1E90FF;
|
||||||
margin-top: 2px;
|
margin-top: 3px;
|
||||||
margin-bottom: 2px;
|
margin-bottom: 3px;
|
||||||
}
|
}
|
||||||
.p {
|
.p {
|
||||||
font-size: 13px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
.table {
|
.table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<#if result.tradesImgUrl??>
|
<#if result.tradesImgUrl??>
|
||||||
<#-- <img width="800px" height="300px" src="../static/images/test.png"></img>-->
|
<#-- <img width="800px" height="300px" src="../static/images/test.png"></img>-->
|
||||||
<img width="800px" height="300px" src="${result.tradesImgUrl}"></img>
|
<img width="600px" height="300px" src="${result.tradesImgUrl}"></img>
|
||||||
<#else>
|
<#else>
|
||||||
<div class="p table">
|
<div class="p table">
|
||||||
<table class="inline">
|
<table class="inline">
|
||||||
|
|||||||
Reference in New Issue
Block a user