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 f31580327..e75123689 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 @@ -4960,7 +4960,7 @@ public class PropertyController { } /*** - * 小区租金估值报告 + * 小区租金估值报告(上半部分) * @param model * @param request * @return @@ -5060,6 +5060,153 @@ public class PropertyController { Integer startPrice = (int)(evaluation.getTotalPrice() - evaluation.getTotalPrice()*0.2); Integer endPrice = (int)(evaluation.getTotalPrice() + evaluation.getTotalPrice()*0.2); + //周边相似小区 +// if (null == model.getRadius()) {// 设置默认值 +// model.setRadius(1000); +// } +// String[] fields = { "city", "region", "name", "estateType2", "id","finishBuildingDate"}; +// List allDistricts = districtService.findNearestDistrict(district, model.getRadius(), fields, Integer.MAX_VALUE); +// //按条件过滤相似小区 +// Integer buildYear = null; +// List districts = new ArrayList(); +// if(StringUtils.isNotBlank(district.getFinishBuildingDate())){ +// buildYear = DistrictScoreUtil.parseStringToDate(district.getFinishBuildingDate()); +// if(buildYear!=null){ +// districts = new ArrayList(); +// int startYear = buildYear -7; +// int endYear = buildYear + 7; +// for(District dist : allDistricts){ +// if(StringUtils.isNotBlank(dist.getFinishBuildingDate())){ +// int simlarDistYear = DistrictScoreUtil.parseStringToDate(district.getFinishBuildingDate()); +// if(simlarDistYear>=startYear && simlarDistYear<=endYear && StringUtils.isNotBlank(district.getEstateType2()) && StringUtils.isNotBlank(dist.getEstateType2()) && district.getEstateType2().equals(dist.getEstateType2())){ +// districts.add(dist); +// } +// } +// } +// } +// } + + //相似房源 +// Double startArea = model.getSize() - model.getSize()*0.1; +// Double endArea = model.getSize() + model.getSize()*0.1; +// Integer startDate = Integer.parseInt(org.apache.tools.ant.util.DateUtils.format(DateUtil.addMonthToDate(new Date(), -12), "yyyyMMdd")); +// List houses = seawaterService.findSeawatersFromEs2("rent", district.getCity(), district.getRegion(), district.getName(), null, null, startDate, null, +// startArea, endArea, startPrice, endPrice, null, null, "p_date", false, 1, 5 , null,"seawater-20*/_doc"); +// //无评估小区房源用周边相似小区的房源 +// if(null == houses || houses.size()==0){ +// for (District dist : districts) { +// houses = seawaterService.findSeawatersFromEs2("rent", dist.getCity(), dist.getRegion(), dist.getName(), null, null, startDate, null, +// startArea, endArea, startPrice, endPrice, null, null, "p_date", false, 1, 5 , null,"seawater-20*/_doc"); +// if(houses!=null && houses.size()>0){ +// break; +// } +// } +// } +// districtPriceMap.put("houses", houses); + +// //周边相似小区租金 +// Integer room = null; +// if(model.getRoom()!=0){ +// room = model.getRoom(); +// }else{ +// room = houseService.getDistrictRoomType((float)model.getSize()); +// } +// if (null != districts) { +// if (null != room) { +// List dtos = new ArrayList(); +// Date weekend = DateUtil.getFirstDayOfWeek(new Date()); +// for (District dist : districts) { +// +// List districtRoomSqmetreRents = districtRoomSqmetreRentService.findDistrictRoomSqmetreRents(dist, 1, room); +// +// ///List districtStatRents = districtStatRentService.findLatestDistrictStatRent(dist, 1, room); +// if (null != districtRoomSqmetreRents && districtRoomSqmetreRents.size() > 0) { +// DistrictRoomSqmetreRent districtRoomSqmetreRent = districtRoomSqmetreRents.get(0); +// if (districtRoomSqmetreRent.getAvgPrice() > 0) { +// +// int startSqPrice = (int)(evaluation.getAvgPrice() - evaluation.getAvgPrice()*0.1); +// int endSqPrice = (int)(evaluation.getAvgPrice() + evaluation.getAvgPrice()*0.1); +//// SqmetreRent sqmetreRent = sqmetreRentService.findNearestSqmetreRent(dist.getCity(), dist.getRegion(), dist.getName(), DateUtil.formatToYYYYMMDD(weekend), "district"); +// if(districtRoomSqmetreRent.getAvgPrice()>=startSqPrice && districtRoomSqmetreRent.getAvgPrice()<=endSqPrice){ +// DistrictHouseDtao dto = new DistrictHouseDtao(); +// dto.setCity(dist.getCity()); +// dto.setRegion(dist.getRegion()); +// dto.setDistrictName(dist.getName()); +// dto.setSqAvgPrice(districtRoomSqmetreRent.getAvgPrice()); +// dto.setRoom(room); +// dtos.add(dto); +// if(dtos.size()>=5){ +// break; +// } +// } +// } +// } +// } +// districtPriceMap.put("districts", dtos); +// } +// } +// +// +// //近一年户型租金走势 +// Map trendsMap = districtRoomSqmetreRentService.getRentTrends(district.getCity(), district.getRegion(), district.getName(), room, -12); +//// Map trendsMap = districtStatRentService.getRentTrend(district.getCity(), district.getRegion(), district.getDistrictName(), -12); +// if (MapUtils.isNotEmpty(trendsMap)) { +// Map distMap = (Map) trendsMap.get("distMap"); +// Map trendMap = (Map) distMap.get(String.valueOf(trendsMap.get("room"))); +// if (MapUtils.isNotEmpty(trendMap)) { +// for (String key : trendMap.keySet()) { +// Double totalPrice = (trendMap.get(key) * evaluation.getArea()); +// trendMap.put(key, totalPrice.intValue()); +// } +// } +// } +// districtPriceMap.put("trends", trendsMap); +// +// +// //成交的租房房源 +// List rentTrades = rentDealPriceService.getRentDealPrices(district.getCity(), district.getRegion(), district.getName(), 5); +// districtPriceMap.put("trades", rentTrades); + + mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); + return mav; + } else { + + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的租金估价").markNoData()); + return mav; + } + } + + /*** + * 小区租金估值报告(下半部分) + * @param model + * @param request + * @return + * @throws NumberFormatException + * @throws IllegalAccessException + */ + @Authority(role = Role.NONE) + public Object rentReport2Action(PropertyEvaluationModel model, HttpServletRequest request)throws NumberFormatException, IllegalAccessException { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),"district"); + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + Evaluation evaluation = buildEvaluation(model, request); + evaluation.setSource("api_property_evaluate_rent"); + evaluation = evaluationService.evaluateRent(district, evaluation, model.getCalDate()); + + if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0) { + evaluation.setAvgPrice((int)(evaluation.getTotalPrice()/evaluation.getArea())); + Map districtPriceMap = new HashMap(); + Integer startPrice = (int)(evaluation.getTotalPrice() - evaluation.getTotalPrice()*0.2); + Integer endPrice = (int)(evaluation.getTotalPrice() + evaluation.getTotalPrice()*0.2); + //周边相似小区 if (null == model.getRadius()) {// 设置默认值 model.setRadius(1000); @@ -5170,7 +5317,6 @@ public class PropertyController { mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); return mav; } else { - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的租金估价").markNoData()); return mav; } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/WeiXinEvaluationController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/WeiXinEvaluationController.java index 33009b27b..7507185f8 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/WeiXinEvaluationController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/WeiXinEvaluationController.java @@ -8,6 +8,7 @@ import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; +import com.fangjia.open.util.InsidePolygon2; import com.fangjia.service.mongo.fangjia.PriceBorderService; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @@ -808,10 +809,13 @@ public class WeiXinEvaluationController { Point point = new Point(Double.valueOf(ll[0]), Double.valueOf(ll[1])); points.add(point); } - Point point = new Point(district.getLng2()/10000000000.0, district.getLat2()/10000000000.0); - boolean flag = InsidePolygon.aboutZone(point, points); + Point point = new Point(district.getLng()/10000000000.0, district.getLat()/10000000000.0); + //boolean flag = InsidePolygon.aboutZone(point, points); + //boolean flag = InsidePolygon.isPtInPoly(point.getLon(), point.getLat(), points); + boolean flag = InsidePolygon2.checkIsInPolygon(point, points); if(flag){ pbObj = pb; + System.out.println(district.getRegion()+" "+district.getName()+" "+pb.getName()); break; } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/util/InsidePolygon.java b/projects/fangjia-open/src/main/java/com/fangjia/open/util/InsidePolygon.java index 096e1ae99..55706d5b4 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/util/InsidePolygon.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/util/InsidePolygon.java @@ -143,5 +143,44 @@ public class InsidePolygon { if ( ( (odd >> 1) << 1) == odd) return false; return true; - } + } + + + public static boolean isPtInPoly (double ALon , double ALat , List ps) { + int iSum, iCount, iIndex; + double dLon1 = 0, dLon2 = 0, dLat1 = 0, dLat2 = 0, dLon; + if (ps.size() < 3) { + return false; + } + iSum = 0; + iCount = ps.size(); + for (iIndex = 0; iIndex= dLat1) && (ALat < dLat2)) || ((ALat >= dLat2) && (ALat < dLat1))) { + if (Math.abs(dLat1 - dLat2) > 0) { + //得到 A点向左射线与边的交点的x坐标: + dLon = dLon1 - ((dLon1 - dLon2) * (dLat1 - ALat) ) / (dLat1 - dLat2); + // 如果交点在A点左侧(说明是做射线与 边的交点),则射线与边的全部交点数加一: + if (dLon < ALon) { + iSum++; + } + } + } + } + if ((iSum % 2) != 0) { + return true; + } + return false; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/util/InsidePolygon2.java b/projects/fangjia-open/src/main/java/com/fangjia/open/util/InsidePolygon2.java new file mode 100644 index 000000000..2ecdb60fe --- /dev/null +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/util/InsidePolygon2.java @@ -0,0 +1,116 @@ +package com.fangjia.open.util; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +public class InsidePolygon2 { + /** + * 判断当前位置是否在多边形区域内 + * + * @param checkPoint 当前经纬度 + * @param areaAround 围栏范围 + * @return + */ + public static boolean checkIsInPolygon(Point checkPoint, List areaAround) { + Point2D.Double point = new Point2D.Double(checkPoint.getLat(), checkPoint.getLon()); + List pointList = new ArrayList(); + for (Point everyPoint : areaAround) { + Point2D.Double polygonPoint = new Point2D.Double(everyPoint.getLat(), everyPoint.getLon()); + pointList.add(polygonPoint); + } + return checkIsPtInPoly(point, pointList); + } + + /** + * 判断点是否在多边形内,如果点位于多边形的顶点或边上,也算做点在多边形内,直接返回true + * + * @param point 检测点 + * @param pts 多边形的顶点 + * @return 点在多边形内返回true, 否则返回false + */ + public static boolean checkIsPtInPoly(Point2D.Double point, List pts) { + int N = pts.size(); + //如果点位于多边形的顶点或边上,也算做点在多边形内,直接返回true + boolean boundOrVertex = true; + //cross points count of x + int intersectCount = 0; + //浮点类型计算时候与0比较时候的容差 + double precision = 2e-10; + //neighbour bound vertices + Point2D.Double p1, p2; + //当前点 + Point2D.Double p = point; + //left vertex + p1 = pts.get(0); + //check all rays + for (int i = 1; i <= N; ++i) { + if (p.equals(p1)) { + //p is an vertex + return boundOrVertex; + } + //right vertex + p2 = pts.get(i % N); + //ray is outside of our interests + if (p.x < Math.min(p1.x, p2.x) || p.x > Math.max(p1.x, p2.x)) { + p1 = p2; + //next ray left point + continue; + } + //ray is crossing over by the algorithm (common part of) + if (p.x > Math.min(p1.x, p2.x) && p.x < Math.max(p1.x, p2.x)) { + //x is before of ray + if (p.y <= Math.max(p1.y, p2.y)) { + //overlies on a horizontal ray + if (p1.x == p2.x && p.y >= Math.min(p1.y, p2.y)) { + return boundOrVertex; + } + //ray is vertical + if (p1.y == p2.y) { + //overlies on a vertical ray + if (p1.y == p.y) { + return boundOrVertex; + //before ray + } else { + ++intersectCount; + } + } else { + //cross point on the left side + //cross point of y + double xinters = (p.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y; + //overlies on a ray + if (Math.abs(p.y - xinters) < precision) { + return boundOrVertex; + } + //before ray + if (p.y < xinters) { + ++intersectCount; + } + } + } + } else { + //special case when ray is crossing through the vertex + //p crossing over p2 + if (p.x == p2.x && p.y <= p2.y) { + //next vertex + Point2D.Double p3 = pts.get((i + 1) % N); + //p.x lies between p1.x & p3.x + if (p.x >= Math.min(p1.x, p3.x) && p.x <= Math.max(p1.x, p3.x)) { + ++intersectCount; + } else { + intersectCount += 2; + } + } + } + //next ray left point + p1 = p2; + } + //偶数在多边形外 + if (intersectCount % 2 == 0) { + return false; + } else { + //奇数在多边形内 + return true; + } + } +} diff --git a/projects/fangjia-open/src/main/webapp/ccbRent/detail.ftl b/projects/fangjia-open/src/main/webapp/ccbRent/detail.ftl index 29bff8e79..a3d233ead 100644 --- a/projects/fangjia-open/src/main/webapp/ccbRent/detail.ftl +++ b/projects/fangjia-open/src/main/webapp/ccbRent/detail.ftl @@ -201,6 +201,7 @@