diff --git a/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java b/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java index 0248a92da..93218b265 100644 --- a/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java +++ b/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java @@ -312,25 +312,6 @@ public class DataUtil { return ret; } - /** - * 加密图片url - * - * @param u - * @param s - * @param t - * @return - */ - public static String encodePicUrl(String u, String s, String t) { - if (StringUtils.isBlank(u)) { - return StringUtils.EMPTY; - } - try { - return SecurityUtil.encode("u=" + URLEncoder.encode(u, "UTF-8") + "&s=" + s + "&t=" + t); - } catch (UnsupportedEncodingException e) { - return SecurityUtil.encode("u=" + u + "&s=" + s + "&t=" + t); - } - } - /** * 把字符串以16进制数值显示出来 * @@ -1805,6 +1786,25 @@ public class DataUtil { return b2.toString(); } + /** + * 加密图片url + * + * @param u + * @param s + * @param t + * @return + */ + public static String encodePicUrl(String u, String s, String t) { + if (StringUtils.isBlank(u)) { + return StringUtils.EMPTY; + } + try { + return SecurityUtil.encode("u=" + URLEncoder.encode(u, "UTF-8") + "&s=" + s + "&t=" + t); + } catch (UnsupportedEncodingException e) { + return SecurityUtil.encode("u=" + u + "&s=" + s + "&t=" + t); + } + } + public static void main(String[] args) { System.out.println(getFirstChar("文裕花园")); System.out.println(getFirstChar("文怡花园")); diff --git a/projects/fangjia-open/pom.xml b/projects/fangjia-open/pom.xml index 7581188b2..3d34afcdd 100644 --- a/projects/fangjia-open/pom.xml +++ b/projects/fangjia-open/pom.xml @@ -147,11 +147,18 @@ 1.0.0 jdk18 + org.xhtmlrenderer core-renderer R8 + + + org.jfree + jfreechart + 1.5.3 + org.sothis sothis-core diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java index f7b2eef7e..5f3343578 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java @@ -5103,8 +5103,8 @@ public class PropertyController { //周边相似小区租金 Integer room = null; - if(model.getHouseType()!=null){ - room = model.getHouseType(); + if(model.getRoom()!=0){ + room = model.getRoom(); }else{ room = houseService.getDistrictRoomType((float)model.getSize()); } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/CcbRentController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/CcbRentController.java index fc28c6302..18ce0551a 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/CcbRentController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/CcbRentController.java @@ -1,7 +1,5 @@ package com.fangjia.open.controllers.weixin; -import com.alibaba.fastjson.JSON; -import com.alibaba.nacos.client.identify.Base64; import com.fangjia.core.util.*; import com.fangjia.dal.QueryParam; import com.fangjia.dal.SdQuery; @@ -15,27 +13,29 @@ import com.fangjia.open.compatible.model.JsonModel; import com.fangjia.open.dto.DistrictHouseDtao; import com.fangjia.open.interceptors.AuthenticationBean; import com.fangjia.open.model.BaseModel; -import com.fangjia.open.model.BasicModel; import com.fangjia.open.model.weixin.EvaluationModel; import com.fangjia.open.model.weixin.PropertyEvaluationModel; +import com.fangjia.open.util.LineChartsUtils; import com.fangjia.service.api.AutoCompleteBo; import com.fangjia.service.datastore.DistrictService; import com.fangjia.service.datastore.EvaluationService; import com.fangjia.service.datastore.HouseService; import com.fangjia.service.district.DistrictRoomSqmetreRentService; import com.fangjia.service.district.RentDealPriceService; +import com.fangjia.service.mongo.fangjia.FileService; import com.fangjia.service.mongo.fangjia.SeawaterService; import com.fangjia.service.util.DistrictScoreUtil; import com.lowagie.text.pdf.BaseFont; -import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.TermQuery; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sothis.core.util.CollectionUtils; import org.sothis.web.mvc.ActionContext; import org.sothis.web.mvc.annotation.Param; -import org.springframework.beans.factory.annotation.Autowired; import org.xhtmlrenderer.pdf.ITextFontResolver; import org.xhtmlrenderer.pdf.ITextRenderer; @@ -55,12 +55,15 @@ import java.util.*; */ public class CcbRentController { + private static final Logger logger = LoggerFactory.getLogger(CcbRentController.class); + private DistrictService districtService; private SeawaterService seawaterService; private DistrictRoomSqmetreRentService districtRoomSqmetreRentService; private EvaluationService evaluationService; private HouseService houseService; private RentDealPriceService rentDealPriceService; + private FileService fileService; public Object indexAction(BaseModel result) { return result; @@ -203,11 +206,18 @@ public class CcbRentController { } } } + if (CollectionUtils.isNotEmpty(houses)) { + for (Seawater seawater: houses) { + if (seawater.getpDate() != null) { + seawater.setRoot(DateUtil.formatByPattern(DateUtil.parseDate(String.valueOf(seawater.getpDate()), "yyyyMMdd"), "yyyy-MM-dd")); + } + } + } districtPriceMap.put("houses", houses); //周边相似小区租金 - if(model.getHouseType()!=null){ - room = model.getHouseType(); + if(model.getRoom() != 0){ + room = model.getRoom(); }else{ room = houseService.getDistrictRoomType((float)model.getSize()); } @@ -250,16 +260,48 @@ public class CcbRentController { Map trendsMap = districtRoomSqmetreRentService.getRentTrends(district.getCity(), district.getRegion(), district.getName(), room, -12); districtPriceMap.put("trends", trendsMap); + // 生成走势图图片,一遍转pdf + String tradesImgUrl = buildTrendImage(trendsMap, room); + //成交的租房房源 List rentTrades = rentDealPriceService.getRentDealPrices(district.getCity(), district.getRegion(), district.getName(), 5); + if (CollectionUtils.isNotEmpty(rentTrades)) { + for (RentDealPrice price : rentTrades) { + // 返回成交日期到前端,直接取日期转pdf报错!!!!!!!!!!!!!!!!! + if (price.getTradeDate() != null) { + price.setSource(DateUtil.formatByPattern(price.getTradeDate(), "yyyy-MM-dd")); + } + } + } districtPriceMap.put("trades", rentTrades); + districtPriceMap.put("tradesImgUrl", tradesImgUrl); result.setResult(districtPriceMap); } -// result.setResult(new HashMap()); return result; } + private String buildTrendImage(Map trendsMap, Integer room) { + List times = (List) trendsMap.get("times"); + Map distMap = (Map) ((Map) trendsMap.get("distMap")).get(String.valueOf(room)); + if (distMap != null) { + List values = new ArrayList(); + for (int i = 0; i < times.size(); i++) { + if (distMap.get(times.get(i)) != null) { + values.add((Integer) distMap.get(times.get(i))); + } else { + values.add(null); + } + } + // 保存到本地测试 + //String url = LineChartsUtils.createChartAndSave2Png("d://test.png",room + "居室", times, values); + String url = LineChartsUtils.createChartAndUpload(fileService,room + "居室", times, values); + logger.info("租金估值图片上传至服务器:{}", url); + return url; + } + return null; + } + /** * 通过EvaluationModel组装Evaluation实体 * @@ -534,4 +576,8 @@ public class CcbRentController { public void setRentDealPriceService(RentDealPriceService rentDealPriceService) { this.rentDealPriceService = rentDealPriceService; } + + public void setFileService(FileService fileService) { + this.fileService = fileService; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/util/LineChartsUtils.java b/projects/fangjia-open/src/main/java/com/fangjia/open/util/LineChartsUtils.java new file mode 100644 index 000000000..1ce0f9126 --- /dev/null +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/util/LineChartsUtils.java @@ -0,0 +1,137 @@ +package com.fangjia.open.util; + +import com.fangjia.core.util.DataUtil; +import com.fangjia.service.mongo.fangjia.FileService; +import org.bson.types.ObjectId; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.LineAndShapeRenderer; +import org.jfree.chart.ui.ApplicationFrame; +import org.jfree.data.category.DefaultCategoryDataset; +import org.jfree.ui.RefineryUtilities; + +import java.awt.*; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * 折线图绘图工具类 + * + * @author shenjian + * @since 2021/4/9 + */ +public class LineChartsUtils { + + + public static void main(String[] args) throws IOException { + File file = new File("d://test.png"); + List columns = new ArrayList(); + columns.add("2020-02"); + columns.add("2020-03"); + columns.add("2020-04"); + columns.add("2020-05"); + columns.add("2020-06"); + columns.add("2020-07"); + columns.add("2020-08"); + columns.add("2020-09"); + columns.add("2020-10"); + columns.add("2020-11"); + columns.add("2020-12"); + columns.add("2021-01"); + + List values = new ArrayList(); + values.add(1000); + values.add(2000); + values.add(2000); + values.add(2000); + values.add(2000); + values.add(2000); + values.add(2000); + values.add(3000); + values.add(3000); + values.add(3000); + values.add(3000); + values.add(3000); + + createChartAndSave2Png("d://test.png", "1居室", columns, values); + } + + public static String createChartAndSave2Png(String path, String rowKey, List columns, List values) { + File file = new File(path); + try { + ChartUtilities.saveChartAsPNG(file, createChart(rowKey, columns, values),800,300); + } catch (IOException e) { + e.printStackTrace(); + } + return path; + } + + public static String createChartAndUpload(FileService fileService, String rowKey, List columns, List values) { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try { + ChartUtilities.writeChartAsPNG(os, createChart(rowKey, columns, values),800,300); + byte[] data = os.toByteArray(); + String id = new ObjectId().toString(); + fileService.save(id,"o", data, "image/png", "o"); + String url = "http://img0.fangjia.com/stc/fs/" + DataUtil.encodePicUrl(id, "o", "house"); + + return url; + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return null; + } + + /** + * 定义图表对象 + * @param rowKey 曲线名,如一居室 + * @param columns 横坐标名 + * @param values 纵坐标值 + */ + public static JFreeChart createChart(String rowKey, List columns, List values) { + createDataset(rowKey, columns, values); + // 折线图名称, 横坐标名称, 纵坐标名称 数据水平竖直 PlotOrientation.HORIZONTAL, 水平显示图像 true, 水平显示图像 true, include legend true, tooltips false, urls + JFreeChart chart = ChartFactory.createLineChart("", "", "", createDataset(rowKey, columns, values), PlotOrientation.VERTICAL, true, true, false); + CategoryPlot plot = chart.getCategoryPlot(); + plot.setRangeGridlinesVisible(false); // 是否显示格子线 + plot.setBackgroundAlpha(0.3f); // 设置背景透明度 + LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); + renderer.setSeriesPaint(0, Color.BLUE); + NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); + rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); + rangeAxis.setAutoRangeIncludesZero(true); + rangeAxis.setUpperMargin(0.20); + rangeAxis.setLabelAngle(Math.PI / 2.0); + return chart; + } + + private static DefaultCategoryDataset createDataset(String rowKey, List columns, List values) { + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + for (int i = 0; i < columns.size(); i++) { + String column = columns.get(i); + if (values.get(i) != null) { + dataset.addValue(Double.valueOf(values.get(i)), rowKey, column); + } else { + dataset.addValue(null, rowKey, column); + } + } + return dataset; + } +} diff --git a/projects/fangjia-open/src/main/webapp/ccbRent/downloadPage.ftl b/projects/fangjia-open/src/main/webapp/ccbRent/downloadPage.ftl index d22216559..615fef4c5 100644 --- a/projects/fangjia-open/src/main/webapp/ccbRent/downloadPage.ftl +++ b/projects/fangjia-open/src/main/webapp/ccbRent/downloadPage.ftl @@ -106,7 +106,18 @@
5 鍘嗗彶绉熼噾
-
+
+ <#if result.tradesImgUrl??> +<#-- --> + + <#else> +
+ + +
鏆傛棤鏁版嵁
+
+ +
6 宸茬鎴挎簮
@@ -137,7 +148,7 @@ <#if bo.room??>${bo.room} <#if bo.hall??>${bo.hall} <#if bo.fitment??>${bo.fitment} - <#if bo.tradeDate??>${bo.tradeDate} + <#if bo.source??>${bo.source} <#else> @@ -176,7 +187,7 @@ <#if bo.room??>${bo.room} <#if bo.hall??>${bo.hall} <#if bo.fitment??>${bo.fitment} - <#if bo.pDate??>${bo.pDate} + <#if bo.root??>${bo.root} <#else> @@ -201,9 +212,20 @@ - - 鏆傛棤鏁版嵁 - + <#if (result.districts??&&result.districts?size>0)> + <#list result.districts as bo> + + <#if bo.city??>${bo.city} + <#if bo.region??>${bo.region} + <#if bo.districtName??>${bo.districtName} + <#if bo.totalPrice??>${bo.totalPrice} + <#if bo.room??>${bo.room} + <#if bo.hall??>${bo.hall} + + + <#else> + 鏆傛棤鏁版嵁 +
diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictRoomSqmetreRentServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictRoomSqmetreRentServiceImpl.java index 16828ac76..c1d4eafa8 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictRoomSqmetreRentServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictRoomSqmetreRentServiceImpl.java @@ -47,7 +47,7 @@ public class DistrictRoomSqmetreRentServiceImpl implements DistrictRoomSqmetreRe rooms = new ArrayList(); for(DistrictRoomSqmetreRent rent : districtRents){ - Map priceMap = distMap.get(room); + Map priceMap = distMap.get(String.valueOf(room)); if(null == priceMap){ priceMap = new HashMap(); distMap.put(String.valueOf(room), priceMap);