From 877ee4f977fcc60133384292ce1644c3fa9ff395 Mon Sep 17 00:00:00 2001 From: majintao Date: Thu, 15 Aug 2024 17:20:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B9=B3=E7=B1=B3=E7=A7=9F?= =?UTF-8?q?=E9=87=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fangjia/dal/mongo/model/SqmetreRent.java | 16 +- .../open/controllers/PropertyController.java | 11286 ++++++++-------- .../open/controllers/RentController.java | 2 +- .../open/model/AvgPriceQueryModel.java | 9 + .../datastore/EvaluationServiceImpl.java | 2 +- .../district/HouseReportServiceImpl.java | 6 +- .../district/SqmetreRentServiceImpl.java | 7 + 7 files changed, 5699 insertions(+), 5629 deletions(-) diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/SqmetreRent.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/SqmetreRent.java index 839d829bc..284449824 100644 --- a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/SqmetreRent.java +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/SqmetreRent.java @@ -15,15 +15,15 @@ import com.fangjia.dal.MongoEntity; public class SqmetreRent implements MongoEntity { /** - * + * */ private static final long serialVersionUID = -5525712882803653336L; private String id; private String city; private String region; private String districtName; - private Integer avgPrice; - private Integer calcAvgPrice; + private Number avgPrice; + private Number calcAvgPrice; private Double markup; private Date weekend; private String cat; @@ -74,20 +74,20 @@ public class SqmetreRent implements MongoEntity { } @Column(name = "avg_price") - public Integer getAvgPrice() { + public Number getAvgPrice() { return avgPrice; } - public void setAvgPrice(Integer avgPrice) { + public void setAvgPrice(Number avgPrice) { this.avgPrice = avgPrice; } @Column(name = "calc_avg_price") - public Integer getCalcAvgPrice() { + public Number getCalcAvgPrice() { return calcAvgPrice; } - public void setCalcAvgPrice(Integer calcAvgPrice) { + public void setCalcAvgPrice(Number calcAvgPrice) { this.calcAvgPrice = calcAvgPrice; } @@ -163,7 +163,5 @@ public class SqmetreRent implements MongoEntity { public void setCat(String cat) { this.cat = cat; } - - } 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 b5efca725..10e92ff24 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 @@ -14,6 +14,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.persistence.Id; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; @@ -130,5323 +131,5378 @@ import com.mongodb.DBObject; @Authority(role = Role.USER) public class PropertyController { - private static final Logger LOGGER = LoggerFactory.getLogger(PropertyController.class); - private DistrictService districtService; - private AddressParser addressParser; - private DistrictStatService districtStatService; - private DealPriceService dealPriceService; - private HouseService houseService; - private ApiUserService apiUserService; - private NoHouseDistrictService noHouseDistrictService; - private UserService userService; - private HouseLoudongService houseLoudongService; - private LoudongService loudongService; - private EvaluationService evaluationService; - private FjtEvaluationService fjtEvaluationService; - private FieldFilterService fieldFilterService; - private OpenLogService openLogService; - private DistrictStatRentService districtStatRentService; - private BatchEvaluateService batchEvaluateService; - private DistrictAttentionRankService districtAttentionRankService; - private DistrictHotService districtHotService; - private CityHotService cityHotService; - private BizShopService bizShopService; - private BusStationService busStationService; - private BaiduApiService baiduApiService; - private DistrictHouseResourceStatService districtHouseResourceStatService; - private DistrictSellStatService districtSellStatService; - private DistrictAnalyDataService districtAnalyDataService; - private AddressMatchProxyService addressMatchProxyService; - private AddressParserService addressParserService; - private ApiUserAuthorityService apiUserAuthorityService; - private AverageStatisticsService averageStatisticsService; - private NetworkPriceService networkPriceService; - private AverageAnalyService averageAnalyService; - private ServerAreaService serverAreaService; - private HouseAuctionService houseAuctionService; - private ApiUserCfgService apiUserCfgService; - private OpenApiLogService openApiLogService; - private FangjiaOfficialAreaService fangjiaOfficialAreaService; - private RegionAnaDataService regionAnaDataService; - private SeawaterDao seawaterDao; - private SeawaterService seawaterService; - private SqmetreRentService sqmetreRentService; - private CommunityPoiService communityPoiService; - private CommunityBasePriceService communityBasePriceService; - private EvaluateFactorService evaluateFactorService; + private static final Logger LOGGER = LoggerFactory.getLogger(PropertyController.class); + private DistrictService districtService; + private AddressParser addressParser; + private DistrictStatService districtStatService; + private DealPriceService dealPriceService; + private HouseService houseService; + private ApiUserService apiUserService; + private NoHouseDistrictService noHouseDistrictService; + private UserService userService; + private HouseLoudongService houseLoudongService; + private LoudongService loudongService; + private EvaluationService evaluationService; + private FjtEvaluationService fjtEvaluationService; + private FieldFilterService fieldFilterService; + private OpenLogService openLogService; + private DistrictStatRentService districtStatRentService; + private BatchEvaluateService batchEvaluateService; + private DistrictAttentionRankService districtAttentionRankService; + private DistrictHotService districtHotService; + private CityHotService cityHotService; + private BizShopService bizShopService; + private BusStationService busStationService; + private BaiduApiService baiduApiService; + private DistrictHouseResourceStatService districtHouseResourceStatService; + private DistrictSellStatService districtSellStatService; + private DistrictAnalyDataService districtAnalyDataService; + private AddressMatchProxyService addressMatchProxyService; + private AddressParserService addressParserService; + private ApiUserAuthorityService apiUserAuthorityService; + private AverageStatisticsService averageStatisticsService; + private NetworkPriceService networkPriceService; + private AverageAnalyService averageAnalyService; + private ServerAreaService serverAreaService; + private HouseAuctionService houseAuctionService; + private ApiUserCfgService apiUserCfgService; + private OpenApiLogService openApiLogService; + private FangjiaOfficialAreaService fangjiaOfficialAreaService; + private RegionAnaDataService regionAnaDataService; + private SeawaterDao seawaterDao; + private SeawaterService seawaterService; + private SqmetreRentService sqmetreRentService; + private CommunityPoiService communityPoiService; + private CommunityBasePriceService communityBasePriceService; + private EvaluateFactorService evaluateFactorService; - private FileDao fileDao = FileDao.getInstance(); - private static final int DEFAULT_PAGE_SIZE = 20; - private static final String[] PROPERTY_SEARCH_API_FIELDS = { "address", "city", "region", "name", "lat2", "lng2","lat", "lng", "block", "estateType2", "addrAlias", "alias" }; - static final int BAI_DU_GEO = 1;// 百度系坐标 - static final int GAO_DE_GEO = 2;// 高德系坐标 + private FileDao fileDao = FileDao.getInstance(); + private static final int DEFAULT_PAGE_SIZE = 20; + private static final String[] PROPERTY_SEARCH_API_FIELDS = {"address", "city", "region", "name", "lat2", "lng2", "lat", "lng", "block", "estateType2", "addrAlias", "alias"}; + static final int BAI_DU_GEO = 1;// 百度系坐标 + static final int GAO_DE_GEO = 2;// 高德系坐标 - private AutoCompleteService autoCompleteService; + private AutoCompleteService autoCompleteService; - private DistrictRoomSqmetreRentService districtRoomSqmetreRentService; - private RentDealPriceService rentDealPriceService; - private EvaluateRatioService evaluateRatioService; - private AliasFangService aliasFangService; + private DistrictRoomSqmetreRentService districtRoomSqmetreRentService; + private RentDealPriceService rentDealPriceService; + private EvaluateRatioService evaluateRatioService; + private AliasFangService aliasFangService; - private static final int EVALUATE_SHOW_DETAIL = 1; - private static final Map PROPERTY_TYPES = new HashMap() { - { - put(null, "普通住宅"); - put("0", "普通住宅"); - put("1", "别墅"); - put("2", "商住"); - } - }; + private static final int EVALUATE_SHOW_DETAIL = 1; + private static final Map PROPERTY_TYPES = new HashMap() { + { + put(null, "普通住宅"); + put("0", "普通住宅"); + put("1", "别墅"); + put("2", "商住"); + } + }; - private static final Map DIRECTION = new HashMap() { - { - put(null, "南"); - put("1", "西南"); - put("2", "东南"); - put("3", "南"); - put("4", "西北"); - put("5", "东北"); - put("6", "东"); - put("7", "西"); - put("8", "北"); - put("9", "东西"); - put("10", "南北"); - } - }; + private static final Map DIRECTION = new HashMap() { + { + put(null, "南"); + put("1", "西南"); + put("2", "东南"); + put("3", "南"); + put("4", "西北"); + put("5", "东北"); + put("6", "东"); + put("7", "西"); + put("8", "北"); + put("9", "东西"); + put("10", "南北"); + } + }; - private static final Map FITMENT = new HashMap() { - { - put(null, "简装"); - put("1", "毛坯"); - put("2", "简装"); - put("3", "精装"); - put("4", "豪装"); - } - }; + private static final Map FITMENT = new HashMap() { + { + put(null, "简装"); + put("1", "毛坯"); + put("2", "简装"); + put("3", "精装"); + put("4", "豪装"); + } + }; - private static final Map EVALUATION_MODEL_FITMENT = new HashMap() { - { - put(null, "简单装修"); - put("简装", "简单装修"); - put("毛坯", "毛坯"); - put("精装", "精装修"); - put("豪装", "豪华装修"); - } - }; + private static final Map EVALUATION_MODEL_FITMENT = new HashMap() { + { + put(null, "简单装修"); + put("简装", "简单装修"); + put("毛坯", "毛坯"); + put("精装", "精装修"); + put("豪装", "豪华装修"); + } + }; - private static final Map FITMENT_MAP = new HashMap() { - { - put("1", "毛坯"); - put("2", "简装"); - put("3", "精装"); - put("4", "豪装"); - } - }; + private static final Map FITMENT_MAP = new HashMap() { + { + put("1", "毛坯"); + put("2", "简装"); + put("3", "精装"); + put("4", "豪装"); + } + }; - private static final Map SIGHT = new HashMap() { - { - put(null, "一般"); - put("1", "景观房"); - put("2", "侧景观房"); - put("3", "一般"); - put("4", "差"); - } - }; + private static final Map SIGHT = new HashMap() { + { + put(null, "一般"); + put("1", "景观房"); + put("2", "侧景观房"); + put("3", "一般"); + put("4", "差"); + } + }; - private static final Map NOISE = new HashMap() { - { - put(null, "无噪音"); - put("0", "无噪音"); - put("1", "噪音较小"); - put("2", "噪音大"); - } - }; + private static final Map NOISE = new HashMap() { + { + put(null, "无噪音"); + put("0", "无噪音"); + put("1", "噪音较小"); + put("2", "噪音大"); + } + }; - private static final Map WORRY_FACTOR = new HashMap() { - { - put("0", "变电站"); - put("1", "垃圾场"); - put("2", "高架噪音"); - put("3", "轨交噪音"); - put("4", "发射塔"); - } - }; + private static final Map WORRY_FACTOR = new HashMap() { + { + put("0", "变电站"); + put("1", "垃圾场"); + put("2", "高架噪音"); + put("3", "轨交噪音"); + put("4", "发射塔"); + } + }; - private static final Map FACILITIES = new HashMap() { - { - put("0", "健身房"); - put("1", "游泳池"); - put("2", "会所"); - put("3", "网球场"); - put("4", "球场"); - put("5", "棋牌室"); - put("6", "停车场"); - put("7", "图书馆"); - put("8", "活动中心"); - } - }; + private static final Map FACILITIES = new HashMap() { + { + put("0", "健身房"); + put("1", "游泳池"); + put("2", "会所"); + put("3", "网球场"); + put("4", "球场"); + put("5", "棋牌室"); + put("6", "停车场"); + put("7", "图书馆"); + put("8", "活动中心"); + } + }; - private static final Map FJT_DIRECTION = new HashMap() { - { - put("1", "西南"); - put("2", "东南"); - put("3", "南"); - put("4", "西北"); - put("5", "东北"); - put("6", "东"); - put("7", "西"); - put("8", "北"); - put("9", "东西"); - put("10", "南北"); - } - }; - private static final Map FJT_FITMENT = new HashMap() { - { - put("0", "毛坯"); - put("1", "毛坯"); - put("2", "简装"); - put("4", "精装"); - put("5", "豪华装修"); - } - }; - private static final Map NEGATIVE_FACTOR = new HashMap() { - { - put(null, "无"); - put("1", "很近"); - put("2", "较近"); - put("3", "无"); - } - }; - private static final Map AROUND_KEYWORD_FACTOR = new HashMap() { - { - put("KTV", "KTV"); - put("医院", "hospital"); - put("学校", "school"); - put("银行", "bank"); - put("ATM", "ATM"); - put("写字楼", "office"); - put("超市", "superMarket"); - put("公园", "park"); - put("停车场", "parking"); - put("机场", "airport"); - put("网吧", "netbar"); - put("电影院", "cinema"); - put("美容院", "beautySalon"); - put("健身中心", "fitnessCenter"); - put("商场", "shoppingMall"); - put("星级酒店", "hotel"); - put("高尔夫球场", "golf"); - put("咖啡厅", "cafe"); - } - }; + private static final Map FJT_DIRECTION = new HashMap() { + { + put("1", "西南"); + put("2", "东南"); + put("3", "南"); + put("4", "西北"); + put("5", "东北"); + put("6", "东"); + put("7", "西"); + put("8", "北"); + put("9", "东西"); + put("10", "南北"); + } + }; + private static final Map FJT_FITMENT = new HashMap() { + { + put("0", "毛坯"); + put("1", "毛坯"); + put("2", "简装"); + put("4", "精装"); + put("5", "豪华装修"); + } + }; + private static final Map NEGATIVE_FACTOR = new HashMap() { + { + put(null, "无"); + put("1", "很近"); + put("2", "较近"); + put("3", "无"); + } + }; + private static final Map AROUND_KEYWORD_FACTOR = new HashMap() { + { + put("KTV", "KTV"); + put("医院", "hospital"); + put("学校", "school"); + put("银行", "bank"); + put("ATM", "ATM"); + put("写字楼", "office"); + put("超市", "superMarket"); + put("公园", "park"); + put("停车场", "parking"); + put("机场", "airport"); + put("网吧", "netbar"); + put("电影院", "cinema"); + put("美容院", "beautySalon"); + put("健身中心", "fitnessCenter"); + put("商场", "shoppingMall"); + put("星级酒店", "hotel"); + put("高尔夫球场", "golf"); + put("咖啡厅", "cafe"); + } + }; - private static final Map AROUND_KEYWORD_FACTOR_NEW = new HashMap() { - { - put("学校", "school"); - put("医院", "hospital"); - put("银行", "bank"); - put("超市", "supermarket"); - put("商场", "market"); - put("美容院", "beautySalon"); - put("健身中心", "gym"); - put("公园/绿地", "park"); - put("地铁", "metro"); - put("公交", "bus"); - put("码头", "dock"); - put("机场", "airport"); - put("火车站", "trainStation"); - put("餐馆", "restaurant"); - put("酒店", "hotel"); - } - }; + private static final Map AROUND_KEYWORD_FACTOR_NEW = new HashMap() { + { + put("学校", "school"); + put("医院", "hospital"); + put("银行", "bank"); + put("超市", "supermarket"); + put("商场", "market"); + put("美容院", "beautySalon"); + put("健身中心", "gym"); + put("公园/绿地", "park"); + put("地铁", "metro"); + put("公交", "bus"); + put("码头", "dock"); + put("机场", "airport"); + put("火车站", "trainStation"); + put("餐馆", "restaurant"); + put("酒店", "hotel"); + } + }; - Map listKeyMap = new HashMap() { - { - put("school", "schools"); - put("hospital", "hospitals"); - put("bank", "banks"); - put("supermarket", "supermarkets"); - put("market", "markets"); - put("beautySalon", "beautySalons"); - put("gym", "gyms"); - put("park", "parks"); - put("bus", "buses"); - put("metro", "metros"); - put("dock", "docks"); - put("airport", "airports"); - put("trainStation", "trainStations"); - put("restaurant", "restaurants"); - put("hotel", "hotels"); - } - }; + Map listKeyMap = new HashMap() { + { + put("school", "schools"); + put("hospital", "hospitals"); + put("bank", "banks"); + put("supermarket", "supermarkets"); + put("market", "markets"); + put("beautySalon", "beautySalons"); + put("gym", "gyms"); + put("park", "parks"); + put("bus", "buses"); + put("metro", "metros"); + put("dock", "docks"); + put("airport", "airports"); + put("trainStation", "trainStations"); + put("restaurant", "restaurants"); + put("hotel", "hotels"); + } + }; - private static final Map CITYLEVEL_MAP = new HashMap() { - { - put("1000", "one");// 一线 - put("1500", "newOne");// 新一线 - put("2000", "two");// 二线 - put("3000", "three");// 三线 - put("4000", "four");// 四线 - put("5000", "five");// 五线 - } - }; - /** - * 第三方均价映射 - */ - private static final Map OTHER_PRICE_MAP = new HashMap() { - { - put("zhuge_price", "诸葛找房"); - put("anjuke_price", "安居客"); - put("fang_price", "房天下"); - put("lianjia_price", "链家"); - put("cityhouse_price", "禧泰数据"); - put("maitian_price", "麦田"); - put("ke_price", "贝壳"); - put("taofang_price", "淘房365"); - put("zhongyuan_price", "中原"); - put("tbs_price", "兔博士"); - put("qfang_price", "Q房"); - put("fangtan_price", "房探"); - put("fangduoduo_price", "房多多"); - put("wiwj_price", "我爱我家"); - } - }; + private static final Map CITYLEVEL_MAP = new HashMap() { + { + put("1000", "one");// 一线 + put("1500", "newOne");// 新一线 + put("2000", "two");// 二线 + put("3000", "three");// 三线 + put("4000", "four");// 四线 + put("5000", "five");// 五线 + } + }; + /** + * 第三方均价映射 + */ + private static final Map OTHER_PRICE_MAP = new HashMap() { + { + put("zhuge_price", "诸葛找房"); + put("anjuke_price", "安居客"); + put("fang_price", "房天下"); + put("lianjia_price", "链家"); + put("cityhouse_price", "禧泰数据"); + put("maitian_price", "麦田"); + put("ke_price", "贝壳"); + put("taofang_price", "淘房365"); + put("zhongyuan_price", "中原"); + put("tbs_price", "兔博士"); + put("qfang_price", "Q房"); + put("fangtan_price", "房探"); + put("fangduoduo_price", "房多多"); + put("wiwj_price", "我爱我家"); + } + }; - /** - * 利用百度API把GPS转换成Google经纬度 - * - * @param lng - * @param lat - * @return - */ - private CoordPoint convertWGSToGoogleByAPI(double lng, double lat) { - Map lnglatMap = null; - try { - lnglatMap = LatitudeAndLongitudeUtil.geoGpsToBaidu(lng, lat); - } catch (Exception e) { - return null; - } + /** + * 利用百度API把GPS转换成Google经纬度 + * + * @param lng + * @param lat + * @return + */ + private CoordPoint convertWGSToGoogleByAPI(double lng, double lat) { + Map lnglatMap = null; + try { + lnglatMap = LatitudeAndLongitudeUtil.geoGpsToBaidu(lng, lat); + } catch (Exception e) { + return null; + } - if (lnglatMap != null) { - lnglatMap = GeocodeUtils.geoconvBaiduToGoogle(lnglatMap.get("lng"), lnglatMap.get("lat")); - return new CoordPoint(lnglatMap.get("lng"), lnglatMap.get("lat")); - } - return null; - } + if (lnglatMap != null) { + lnglatMap = GeocodeUtils.geoconvBaiduToGoogle(lnglatMap.get("lng"), lnglatMap.get("lat")); + return new CoordPoint(lnglatMap.get("lng"), lnglatMap.get("lat")); + } + return null; + } - /** - * 利用算法模板把GPS转换成Google经纬度 - * - * @param lng - * @param lat - * @return - */ - private CoordPoint convertWGSToGoogleByMode(double lng, double lat) { - return CoordinateConversion.wgs_gcj_encrypts(lat, lng); - } + /** + * 利用算法模板把GPS转换成Google经纬度 + * + * @param lng + * @param lat + * @return + */ + private CoordPoint convertWGSToGoogleByMode(double lng, double lat) { + return CoordinateConversion.wgs_gcj_encrypts(lat, lng); + } - public Object searchAction(PropertySearchModel model) { + public Object searchAction(PropertySearchModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity())) { - mav.setModel(BasicModel.buildBadRequestModel("城市(city)不能为空")); - return mav; - } - if (!RegionData.isCity(model.getCity())) { - String city = RegionData.formatCity(model.getCity()); - if (null == city) { - mav.setModel(BasicModel.buildBadRequestModel("非法城市:" + model.getCity())); - return mav; - } else { - model.setCity(city); - } - } - if (StringUtils.isNotBlank(model.getDistrict())) { - model.setDistrict(RegionData.formatRegion(model.getCity(), model.getDistrict())); - } + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("城市(city)不能为空")); + return mav; + } + if (!RegionData.isCity(model.getCity())) { + String city = RegionData.formatCity(model.getCity()); + if (null == city) { + mav.setModel(BasicModel.buildBadRequestModel("非法城市:" + model.getCity())); + return mav; + } else { + model.setCity(city); + } + } + if (StringUtils.isNotBlank(model.getDistrict())) { + model.setDistrict(RegionData.formatRegion(model.getCity(), model.getDistrict())); + } - /** 设置默认坐标系 */ - if (model.getFrom() == 0) { - model.setFrom(BAI_DU_GEO); - } - if (StringUtils.isBlank(model.getKeyword()) && !isRadiusSearch(model)) { - ServerArea cityData = ServerAreaData.getServerAreaByCity(model.getCity()); - if (cityData == null) { - mav.setModel(BasicModel.buildBadRequestModel("城市:" + model.getCity() + "暂不支持")); - return mav; - } - if (cityData.getLng2() <= 0 || cityData.getLat2() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("关键字(keyword)和经纬度信息(lat,lng,radius)不能同时为空")); - return mav; - } - if (model.getFrom() == BAI_DU_GEO) { - model.setLat(DataUtil.roundDouble(cityData.getLat2(), 6)); - model.setLng(DataUtil.roundDouble(cityData.getLng2(), 6)); - } else if (model.getFrom() == GAO_DE_GEO) { - model.setLat(DataUtil.roundDouble(cityData.getLat(), 6)); - model.setLng(DataUtil.roundDouble(cityData.getLng(), 6)); - } - } - if (isRadiusSearch(model)) { - if (model.getRadius() == null || model.getRadius() <= 0 || model.getRadius() >= 5000) { - model.setRadius(1000); - } - if (model.getFrom() == 0) { - model.setFrom(BAI_DU_GEO); - } - } + /** 设置默认坐标系 */ + if (model.getFrom() == 0) { + model.setFrom(BAI_DU_GEO); + } + if (StringUtils.isBlank(model.getKeyword()) && !isRadiusSearch(model)) { + ServerArea cityData = ServerAreaData.getServerAreaByCity(model.getCity()); + if (cityData == null) { + mav.setModel(BasicModel.buildBadRequestModel("城市:" + model.getCity() + "暂不支持")); + return mav; + } + if (cityData.getLng2() <= 0 || cityData.getLat2() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("关键字(keyword)和经纬度信息(lat,lng,radius)不能同时为空")); + return mav; + } + if (model.getFrom() == BAI_DU_GEO) { + model.setLat(DataUtil.roundDouble(cityData.getLat2(), 6)); + model.setLng(DataUtil.roundDouble(cityData.getLng2(), 6)); + } else if (model.getFrom() == GAO_DE_GEO) { + model.setLat(DataUtil.roundDouble(cityData.getLat(), 6)); + model.setLng(DataUtil.roundDouble(cityData.getLng(), 6)); + } + } + if (isRadiusSearch(model)) { + if (model.getRadius() == null || model.getRadius() <= 0 || model.getRadius() >= 5000) { + model.setRadius(1000); + } + if (model.getFrom() == 0) { + model.setFrom(BAI_DU_GEO); + } + } - if (model.getMax() == null) { - model.setMax(DEFAULT_PAGE_SIZE); - } else if (model.getMax().intValue() > 100) { - model.setMax(100); - } else if (model.getMax().intValue() < 1) { - model.setMax(DEFAULT_PAGE_SIZE); - } + if (model.getMax() == null) { + model.setMax(DEFAULT_PAGE_SIZE); + } else if (model.getMax().intValue() > 100) { + model.setMax(100); + } else if (model.getMax().intValue() < 1) { + model.setMax(DEFAULT_PAGE_SIZE); + } - SdQuery sdQuery = null; - CoordPoint point = null; + SdQuery sdQuery = null; + CoordPoint point = null; - if (isRadiusSearch(model)) { - if (model.getLat() < 0 || model.getLat() > 90) { - mav.setModel(BasicModel.buildBadRequestModel("lat(维度)的取值范围是0~90")); - return mav; - } - if (model.getLng() < 0 || model.getLng() > 180) { - mav.setModel(BasicModel.buildBadRequestModel("lng(经度)的取值范围是0~180")); - return mav; - } - // from=0为默认值,表示输入值为GPS的经纬度 - // from>0,表示为输入的是baidu经纬度 - if (model.getFrom() == BAI_DU_GEO) { - Map geo = GeocodeUtils.geoconvBaiduToGoogle(model.getLng(), model.getLat()); - point = new CoordPoint(geo.get("lng"), geo.get("lat")); + if (isRadiusSearch(model)) { + if (model.getLat() < 0 || model.getLat() > 90) { + mav.setModel(BasicModel.buildBadRequestModel("lat(维度)的取值范围是0~90")); + return mav; + } + if (model.getLng() < 0 || model.getLng() > 180) { + mav.setModel(BasicModel.buildBadRequestModel("lng(经度)的取值范围是0~180")); + return mav; + } + // from=0为默认值,表示输入值为GPS的经纬度 + // from>0,表示为输入的是baidu经纬度 + if (model.getFrom() == BAI_DU_GEO) { + Map geo = GeocodeUtils.geoconvBaiduToGoogle(model.getLng(), model.getLat()); + point = new CoordPoint(geo.get("lng"), geo.get("lat")); - } else if (model.getFrom() == GAO_DE_GEO) { - point = new CoordPoint(model.getLng(), model.getLat()); - } - if (point != null) { - sdQuery = new SdQuery(); - sdQuery.setPoint(point.getLat() + "," + point.getLng()); - sdQuery.setField("lat_lng"); - sdQuery.setDistance(String.valueOf(model.getRadius() / 1000.0)); - } - } + } else if (model.getFrom() == GAO_DE_GEO) { + point = new CoordPoint(model.getLng(), model.getLat()); + } + if (point != null) { + sdQuery = new SdQuery(); + sdQuery.setPoint(point.getLat() + "," + point.getLng()); + sdQuery.setField("lat_lng"); + sdQuery.setDistance(String.valueOf(model.getRadius() / 1000.0)); + } + } - List result = districtService.searchByKeyword(model.getCity(), model.getDistrict(), - model.getKeyword(), "district", sdQuery, PROPERTY_SEARCH_API_FIELDS, model.getMax()); - if (result.isEmpty() && StringUtils.isNotBlank(model.getKeyword())) { - District matchDistrict = matchDistrict(model.getCity(), model.getKeyword(), model.getDistrict(), null); - if (matchDistrict != null) { - if (isRadiusSearch(model)) {// 如果搜索中包涵经纬度信息,计算匹配出来的小区是否在指定半径内 - double distance; - if (hasGeoPoint(matchDistrict)) { - distance = GeoUtils.calculateDistance(point.getLng(), point.getLat(), - matchDistrict.getLng() / 10000000000d, matchDistrict.getLat() / 10000000000d); - if (distance < model.getRadius()) { - result.add(matchDistrict); - } - } + List result = districtService.searchByKeyword(model.getCity(), model.getDistrict(), + model.getKeyword(), "district", sdQuery, PROPERTY_SEARCH_API_FIELDS, model.getMax()); + if (result.isEmpty() && StringUtils.isNotBlank(model.getKeyword())) { + District matchDistrict = matchDistrict(model.getCity(), model.getKeyword(), model.getDistrict(), null); + if (matchDistrict != null) { + if (isRadiusSearch(model)) {// 如果搜索中包涵经纬度信息,计算匹配出来的小区是否在指定半径内 + double distance; + if (hasGeoPoint(matchDistrict)) { + distance = GeoUtils.calculateDistance(point.getLng(), point.getLat(), + matchDistrict.getLng() / 10000000000d, matchDistrict.getLat() / 10000000000d); + if (distance < model.getRadius()) { + result.add(matchDistrict); + } + } - } else { - result.add(matchDistrict); - } - } - } - String inputAddress = null; - if (StringUtils.isNotBlank(model.getKeyword())) { - com.fangjia.service.address.mode.Address address = addressParserService.standardize(model.getCity(), - model.getKeyword()); - if (StringUtils.isNotBlank(address.getStreet())) { - inputAddress = address.getStreet(); - } - if (StringUtils.isNotBlank(address.getStreetNumber())) { - inputAddress = inputAddress + address.getStreetNumber(); - } - } + } else { + result.add(matchDistrict); + } + } + } + String inputAddress = null; + if (StringUtils.isNotBlank(model.getKeyword())) { + com.fangjia.service.address.mode.Address address = addressParserService.standardize(model.getCity(), + model.getKeyword()); + if (StringUtils.isNotBlank(address.getStreet())) { + inputAddress = address.getStreet(); + } + if (StringUtils.isNotBlank(address.getStreetNumber())) { + inputAddress = inputAddress + address.getStreetNumber(); + } + } - List list = new ArrayList(); - for (District district : result) { - PropertyDto dto = new PropertyDto(); - dto.setId(district.getId()); - if (inputAddress == null) { - dto.setAddress(district.getAddress()); - } else { - dto.setAddress(findMostSimilarAddress(inputAddress, district)); - } - dto.setCity(district.getCity()); - dto.setDistrict(district.getRegion()); - if (model.getFrom() == BAI_DU_GEO) { - if (district.getLat2() != null && district.getLng2() != null) { - dto.setLat(Double.toString(district.getLat2() / 10000000000D)); - dto.setLng(Double.toString(district.getLng2() / 10000000000D)); - } - } else if (model.getFrom() == GAO_DE_GEO) { - if (district.getLat() != null && district.getLng() != null) { - dto.setLat(Double.toString(district.getLat() / 10000000000D)); - dto.setLng(Double.toString(district.getLng() / 10000000000D)); - } - } - if (isRadiusSearch(model) && district.getLng() != null && district.getLat() != null && point != null) { - dto.setDistance(String.valueOf((long) GeoUtils.calculateDistance(district.getLng() / 10000000000D, - district.getLat() / 10000000000D, point.getLng(), point.getLat()))); - } + List list = new ArrayList(); + for (District district : result) { + PropertyDto dto = new PropertyDto(); + dto.setId(district.getId()); + if (inputAddress == null) { + dto.setAddress(district.getAddress()); + } else { + dto.setAddress(findMostSimilarAddress(inputAddress, district)); + } + dto.setCity(district.getCity()); + dto.setDistrict(district.getRegion()); + if (model.getFrom() == BAI_DU_GEO) { + if (district.getLat2() != null && district.getLng2() != null) { + dto.setLat(Double.toString(district.getLat2() / 10000000000D)); + dto.setLng(Double.toString(district.getLng2() / 10000000000D)); + } + } else if (model.getFrom() == GAO_DE_GEO) { + if (district.getLat() != null && district.getLng() != null) { + dto.setLat(Double.toString(district.getLat() / 10000000000D)); + dto.setLng(Double.toString(district.getLng() / 10000000000D)); + } + } + if (isRadiusSearch(model) && district.getLng() != null && district.getLat() != null && point != null) { + dto.setDistance(String.valueOf((long) GeoUtils.calculateDistance(district.getLng() / 10000000000D, + district.getLat() / 10000000000D, point.getLng(), point.getLat()))); + } - dto.setName(district.getName()); - if (district.getBlock() == null) { - dto.setBlock(""); - } else { - dto.setBlock(district.getBlock()); - } - dto.setPropertyType(district.getEstateType2()); - if (CollectionUtils.isNotEmpty(district.getAlias())) { - // 将最相近的别名输出给用户 - String alias = null; - double similarity = 0; - if (StringUtils.isNotBlank(model.getKeyword())) { - for (String mappingAlias : district.getAlias()) { - double curr = AddressParserUtil.getSimilarityRatio(mappingAlias, model.getKeyword()); - if (curr > similarity ) { - similarity = curr; - alias = mappingAlias; - } - } - } - if (StringUtils.isNotBlank(alias)) { - dto.setAlias(alias); - } else { - dto.setAlias(district.getAlias().get(0)); - } - } - list.add(dto); - } + dto.setName(district.getName()); + if (district.getBlock() == null) { + dto.setBlock(""); + } else { + dto.setBlock(district.getBlock()); + } + dto.setPropertyType(district.getEstateType2()); + if (CollectionUtils.isNotEmpty(district.getAlias())) { + // 将最相近的别名输出给用户 + String alias = null; + double similarity = 0; + if (StringUtils.isNotBlank(model.getKeyword())) { + for (String mappingAlias : district.getAlias()) { + double curr = AddressParserUtil.getSimilarityRatio(mappingAlias, model.getKeyword()); + if (curr > similarity) { + similarity = curr; + alias = mappingAlias; + } + } + } + if (StringUtils.isNotBlank(alias)) { + dto.setAlias(alias); + } else { + dto.setAlias(district.getAlias().get(0)); + } + } + list.add(dto); + } - mav.setModel(BasicModel.buildOKModel().setResult(list)); - return mav; - } + mav.setModel(BasicModel.buildOKModel().setResult(list)); + return mav; + } - private String findMostSimilarAddress(String inputAddress, District district) { + private String findMostSimilarAddress(String inputAddress, District district) { - if (StringUtils.isBlank(inputAddress)) { - return district.getAddress(); - } - if (StringUtils.isNotBlank(district.getKeyword()) && district.getAddress().contains(inputAddress)) { - return district.getAddress(); - } - if (district.getAddrAlias() == null) { - return district.getAddress(); - } - for (String addr : district.getAddrAlias()) { - if (addr.contains(inputAddress)) { - return addr; - } - } - return district.getAddress(); - } + if (StringUtils.isBlank(inputAddress)) { + return district.getAddress(); + } + if (StringUtils.isNotBlank(district.getKeyword()) && district.getAddress().contains(inputAddress)) { + return district.getAddress(); + } + if (district.getAddrAlias() == null) { + return district.getAddress(); + } + for (String addr : district.getAddrAlias()) { + if (addr.contains(inputAddress)) { + return addr; + } + } + return district.getAddress(); + } - /** - * 判断小区是否有经纬度 - * - * @param district - * @return - */ - private boolean hasGeoPoint(District district) { - return district.getLat() != null && district.getLng() != null && district.getLat() != 0 - && district.getLng() != 0; - } + /** + * 判断小区是否有经纬度 + * + * @param district + * @return + */ + private boolean hasGeoPoint(District district) { + return district.getLat() != null && district.getLng() != null && district.getLat() != 0 + && district.getLng() != 0; + } - /** - * 调用匹配接口匹配小区 - * - * @param city - * @param address - * @param region - * @param name - * @return - */ - private District matchDistrict(String city, String address, String region, String name) { + /** + * 调用匹配接口匹配小区 + * + * @param city + * @param address + * @param region + * @param name + * @return + */ + private District matchDistrict(String city, String address, String region, String name) { - Map params = new HashMap(); - params.put("city", city); - params.put("token", APIConstant.SUPER_USER_TOKEN); - params.put("address", address); - params.put("category", "property"); - if (StringUtils.isNotBlank(region)) { - params.put("suggestDistrict", region); - } - if(StringUtils.isNotBlank(name)){ - params.put("suggestName", name); - } - String content = addressMatchProxyService.parser(params); - if (StringUtils.isBlank(content)) { - return null; - } - JSONObject json = JSONObject.fromObject(content); - if (json.getInt("code") != 200) { - return null; - } - JSONObject result = json.getJSONObject("result"); - if (result.getDouble("credit") > 0.5) { - return districtService.findById(result.getString("id")); - } - return null; - } + Map params = new HashMap(); + params.put("city", city); + params.put("token", APIConstant.SUPER_USER_TOKEN); + params.put("address", address); + params.put("category", "property"); + if (StringUtils.isNotBlank(region)) { + params.put("suggestDistrict", region); + } + if (StringUtils.isNotBlank(name)) { + params.put("suggestName", name); + } + String content = addressMatchProxyService.parser(params); + if (StringUtils.isBlank(content)) { + return null; + } + JSONObject json = JSONObject.fromObject(content); + if (json.getInt("code") != 200) { + return null; + } + JSONObject result = json.getJSONObject("result"); + if (result.getDouble("credit") > 0.5) { + return districtService.findById(result.getString("id")); + } + return null; + } - public Object detailAction(PropertySearchModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getId()) - && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) - || StringUtils.isBlank(model.getName())) - && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) - || StringUtils.isBlank(model.getAddress()))) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:请输入正确的参数组合")); - return mav; - } - String userId = FangjiaApiUtil.parseUserId(model.getToken()); + public Object detailAction(PropertySearchModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getId()) + && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) + || StringUtils.isBlank(model.getName())) + && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) + || StringUtils.isBlank(model.getAddress()))) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:请输入正确的参数组合")); + return mav; + } + String userId = FangjiaApiUtil.parseUserId(model.getToken()); - District district = null; - if (StringUtils.isNotBlank(model.getId())){ - if(ObjectId.isValid(model.getId())){ - district = districtService.findById(model.getId()); - }else{ - mav.setModel(BasicModel.buildBadRequestModel("非法的住宅ID")); - return mav; - } - } + District district = null; + if (StringUtils.isNotBlank(model.getId())) { + if (ObjectId.isValid(model.getId())) { + district = districtService.findById(model.getId()); + } else { + mav.setModel(BasicModel.buildBadRequestModel("非法的住宅ID")); + return mav; + } + } - if (district == null && StringUtils.isNotBlank(model.getCity()) && StringUtils.isNotBlank(model.getDistrict()) - && StringUtils.isNotBlank(model.getName())) { - district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district != null) { - district = districtService.findById(district.getId()); - } - } + if (district == null && StringUtils.isNotBlank(model.getCity()) && StringUtils.isNotBlank(model.getDistrict()) + && StringUtils.isNotBlank(model.getName())) { + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district != null) { + district = districtService.findById(district.getId()); + } + } - if (district == null && StringUtils.isNotBlank(model.getCity()) && StringUtils.isNotBlank(model.getDistrict()) - && StringUtils.isNotBlank(model.getAddress())) { - Map result = addressParser.parse2(model.getCity(), model.getAddress(), "district", false); - saveAddressMatchLog(result, model.getAddress(), model.getCity(), model.getToken()); - Integer status = (Integer) result.get("status"); - Integer precise = (Integer) result.get("precise"); - if (status != null && status == 0 && precise == 0) { - String id = (String) result.get("id"); - district = districtService.findById(id); - } - } + if (district == null && StringUtils.isNotBlank(model.getCity()) && StringUtils.isNotBlank(model.getDistrict()) + && StringUtils.isNotBlank(model.getAddress())) { + Map result = addressParser.parse2(model.getCity(), model.getAddress(), "district", false); + saveAddressMatchLog(result, model.getAddress(), model.getCity(), model.getToken()); + Integer status = (Integer) result.get("status"); + Integer precise = (Integer) result.get("precise"); + if (status != null && status == 0 && precise == 0) { + String id = (String) result.get("id"); + district = districtService.findById(id); + } + } - if (district != null) { - fieldFilterService.filterWithProcessNUll(district); - DistrictInfoDto districtInfoDto = new DistrictInfoDto(); - if (model.getDetailLevel() == null || model.getDetailLevel() >= 0) { - districtInfoDto.setId(district.getId()); - districtInfoDto.setCity(district.getCity()); - districtInfoDto.setDistrict(district.getRegion()); - districtInfoDto.setName(district.getName()); - districtInfoDto.setAddress(district.getAddress()); - int avgPrice = districtStatService.findLatestDistrictAvgPrice(new DistrictKey(district), null); - if (avgPrice != 0) { - districtInfoDto.setAvgPrice(avgPrice); - } - districtInfoDto.setPropertyType(district.getEstateType2()); - if (district.getLat2() != null && district.getLat2() != 0 && district.getLng2() != null - && district.getLng2() != 0) { - districtInfoDto.setLat(district.getLat2() / 10000000000D); - districtInfoDto.setLng(district.getLng2() / 10000000000D); - } - } + if (district != null) { + fieldFilterService.filterWithProcessNUll(district); + DistrictInfoDto districtInfoDto = new DistrictInfoDto(); + if (model.getDetailLevel() == null || model.getDetailLevel() >= 0) { + districtInfoDto.setId(district.getId()); + districtInfoDto.setCity(district.getCity()); + districtInfoDto.setDistrict(district.getRegion()); + districtInfoDto.setName(district.getName()); + districtInfoDto.setAddress(district.getAddress()); + int avgPrice = districtStatService.findLatestDistrictAvgPrice(new DistrictKey(district), null); + if (avgPrice != 0) { + districtInfoDto.setAvgPrice(avgPrice); + } + districtInfoDto.setPropertyType(district.getEstateType2()); + if (district.getLat2() != null && district.getLat2() != 0 && district.getLng2() != null + && district.getLng2() != 0) { + districtInfoDto.setLat(district.getLat2() / 10000000000D); + districtInfoDto.setLng(district.getLng2() / 10000000000D); + } + } - districtInfoDto.setBlock(district.getBlock()); - districtInfoDto.setLoopLine(district.getLoopLineInfo()); - if (HouseValidator.validateBuildingType(district.getBuildType())) { - districtInfoDto.setBuildingType(district.getBuildType()); - } else { - districtInfoDto.setBuildingType(""); - } - districtInfoDto.setAlias(district.getMappingAlias()); - districtInfoDto.setAddressAlias(district.getAddrAlias()); - districtInfoDto.setCommunity(district.getStreetCommunity()); - districtInfoDto.setCommercialArea(district.getBusinessQuarter()); - if (district.getHouseholdCount() != null) { - districtInfoDto.setTotalUnitCount(SeaweedUtils.formatHouseholdCount(district.getHouseholdCount().toString())); - } else { - districtInfoDto.setTotalUnitCount(""); - } - districtInfoDto.setManagementFee(district.getEstateCharge()); - if (district.getCarSiteCount() != null) { - districtInfoDto.setParking(SeaweedUtils.formatCarSiteCount(district.getCarSiteCount().toString())); - } else { - districtInfoDto.setParking(""); - } - districtInfoDto.setParkingDescription(district.getCarSite()); - districtInfoDto.setOwnershipPeriod(district.getPropertyLife()); - districtInfoDto.setOwnershipType(district.getHouseProperty()); - districtInfoDto.setStartBuildTime(district.getStartBuildingDate()); - if (district.getOpenDate() != null) { - Date minDate = DateUtil.parseDate("1900-01-01", "yyyy-MM-dd"); - Date maxDate = DateUtil.parseDate("2025-01-01", "yyyy-MM-dd"); - if (district.getOpenDate().after(minDate) && district.getOpenDate().before(maxDate)) { - districtInfoDto - .setStartSellingTime(DateUtil.formatByPattern(district.getOpenDate(), "yyyy-MM-dd")); - } - } else { - districtInfoDto.setStartSellingTime(""); - } + districtInfoDto.setBlock(district.getBlock()); + districtInfoDto.setLoopLine(district.getLoopLineInfo()); + if (HouseValidator.validateBuildingType(district.getBuildType())) { + districtInfoDto.setBuildingType(district.getBuildType()); + } else { + districtInfoDto.setBuildingType(""); + } + districtInfoDto.setAlias(district.getMappingAlias()); + districtInfoDto.setAddressAlias(district.getAddrAlias()); + districtInfoDto.setCommunity(district.getStreetCommunity()); + districtInfoDto.setCommercialArea(district.getBusinessQuarter()); + if (district.getHouseholdCount() != null) { + districtInfoDto.setTotalUnitCount(SeaweedUtils.formatHouseholdCount(district.getHouseholdCount().toString())); + } else { + districtInfoDto.setTotalUnitCount(""); + } + districtInfoDto.setManagementFee(district.getEstateCharge()); + if (district.getCarSiteCount() != null) { + districtInfoDto.setParking(SeaweedUtils.formatCarSiteCount(district.getCarSiteCount().toString())); + } else { + districtInfoDto.setParking(""); + } + districtInfoDto.setParkingDescription(district.getCarSite()); + districtInfoDto.setOwnershipPeriod(district.getPropertyLife()); + districtInfoDto.setOwnershipType(district.getHouseProperty()); + districtInfoDto.setStartBuildTime(district.getStartBuildingDate()); + if (district.getOpenDate() != null) { + Date minDate = DateUtil.parseDate("1900-01-01", "yyyy-MM-dd"); + Date maxDate = DateUtil.parseDate("2025-01-01", "yyyy-MM-dd"); + if (district.getOpenDate().after(minDate) && district.getOpenDate().before(maxDate)) { + districtInfoDto + .setStartSellingTime(DateUtil.formatByPattern(district.getOpenDate(), "yyyy-MM-dd")); + } + } else { + districtInfoDto.setStartSellingTime(""); + } - districtInfoDto.setFinishBuildTime(district.getFinishBuildingDate()); - districtInfoDto.setMoveinTime(district.getLiveDate()); - districtInfoDto.setFloorSpace(SeaweedUtils.formatAllArea(district.getAllArea())); - districtInfoDto.setConstructionSpace(district.getBuildArea()); - districtInfoDto.setPlotRatio(SeaweedUtils.formatCubagePercent(district.getCubagePercent())); - districtInfoDto.setGreenPercentage(SeaweedUtils.formatVirescencePercent(district.getVirescencePercent())); - districtInfoDto.setPreSalePermit(district.getLicence()); - districtInfoDto.setDeveloper(district.getDeveloper()); - districtInfoDto.setDiscount(district.getDiscount()); - districtInfoDto.setPropertyManagement(district.getEstateCompany()); - if (HouseValidator.fetchFitmentInfo(district.getFitment()) == null) { - districtInfoDto.setDecorationStandard(""); - } else { - districtInfoDto.setDecorationStandard(HouseValidator.fetchFitmentInfo(district.getFitment())); - } - districtInfoDto.setBuildingStructure(district.getBuildStructure()); - districtInfoDto.setSupportingFacilities(district.getFacilities()); - districtInfoDto.setTransportation(district.getTraffic()); - districtInfoDto.setRelatedInfo(district.getRelateInfo()); - districtInfoDto.setDescription(district.getDescription()); - districtInfoDto.setSalesOfficeAdd(district.getSellAddress()); - districtInfoDto.setSalesPhoneNumber(district.getMobile()); - districtInfoDto.setTownship(district.getTownship()); - if (district.getLoudongCount() != null && district.getLoudongCount() > 0) { - districtInfoDto.setBuildingCount(district.getLoudongCount()); - } + districtInfoDto.setFinishBuildTime(district.getFinishBuildingDate()); + districtInfoDto.setMoveinTime(district.getLiveDate()); + districtInfoDto.setFloorSpace(SeaweedUtils.formatAllArea(district.getAllArea())); + districtInfoDto.setConstructionSpace(district.getBuildArea()); + districtInfoDto.setPlotRatio(SeaweedUtils.formatCubagePercent(district.getCubagePercent())); + districtInfoDto.setGreenPercentage(SeaweedUtils.formatVirescencePercent(district.getVirescencePercent())); + districtInfoDto.setPreSalePermit(district.getLicence()); + districtInfoDto.setDeveloper(district.getDeveloper()); + districtInfoDto.setDiscount(district.getDiscount()); + districtInfoDto.setPropertyManagement(district.getEstateCompany()); + if (HouseValidator.fetchFitmentInfo(district.getFitment()) == null) { + districtInfoDto.setDecorationStandard(""); + } else { + districtInfoDto.setDecorationStandard(HouseValidator.fetchFitmentInfo(district.getFitment())); + } + districtInfoDto.setBuildingStructure(district.getBuildStructure()); + districtInfoDto.setSupportingFacilities(district.getFacilities()); + districtInfoDto.setTransportation(district.getTraffic()); + districtInfoDto.setRelatedInfo(district.getRelateInfo()); + districtInfoDto.setDescription(district.getDescription()); + districtInfoDto.setSalesOfficeAdd(district.getSellAddress()); + districtInfoDto.setSalesPhoneNumber(district.getMobile()); + districtInfoDto.setTownship(district.getTownship()); + if (district.getLoudongCount() != null && district.getLoudongCount() > 0) { + districtInfoDto.setBuildingCount(district.getLoudongCount()); + } // Integer finishYear = districtService.getBuildYear(district); - Integer finishYear = districtService.getCreateYear(district); - if (finishYear != null) { - districtInfoDto.setFinishYear(finishYear); - } - - mav.setModel(BasicModel.buildOKModel().setResult(districtInfoDto)); - return mav; - } - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - - - public Object detail2Action(PropertySearchModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getId()) - && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) - || StringUtils.isBlank(model.getName())) - && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) - || StringUtils.isBlank(model.getAddress()))) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:请输入正确的参数组合")); - return mav; - } - - District district = null; - if (StringUtils.isNotBlank(model.getId())){ - if(ObjectId.isValid(model.getId())){ - district = districtService.findById(model.getId()); - }else{ - mav.setModel(BasicModel.buildBadRequestModel("非法的住宅ID")); - return mav; - } - } - - if (district == null && StringUtils.isNotBlank(model.getCity()) && StringUtils.isNotBlank(model.getDistrict()) - && StringUtils.isNotBlank(model.getName())) { - district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district != null) { - district = districtService.findById(district.getId()); - } - } - - if (district == null && StringUtils.isNotBlank(model.getCity()) && StringUtils.isNotBlank(model.getDistrict()) - && StringUtils.isNotBlank(model.getAddress())) { - Map result = addressParser.parse2(model.getCity(), model.getAddress(), "district", false); - saveAddressMatchLog(result, model.getAddress(), model.getCity(), model.getToken()); - Integer status = (Integer) result.get("status"); - Integer precise = (Integer) result.get("precise"); - if (status != null && status == 0 && precise == 0) { - String id = (String) result.get("id"); - district = districtService.findById(id); - } - } - - if (district != null) { - fieldFilterService.filterWithProcessNUll(district); - DistrictInfoDto districtInfoDto = new DistrictInfoDto(); - districtInfoDto.setId(district.getId()); - districtInfoDto.setCity(district.getCity()); - districtInfoDto.setDistrict(district.getRegion()); - districtInfoDto.setName(district.getName()); - districtInfoDto.setAlias(district.getMappingAlias()); - districtInfoDto.setAddress(district.getAddress()); - districtInfoDto.setAddressAlias(district.getAddrAlias()); - if (district.getLat2() != null && district.getLat2() != 0 && district.getLng2() != null - && district.getLng2() != 0) { - districtInfoDto.setLat2(district.getLat2() / 10000000000D); - districtInfoDto.setLng2(district.getLng2() / 10000000000D); - } - if (district.getLat() != null && district.getLat() != 0 && district.getLng() != null - && district.getLng() != 0) { - districtInfoDto.setLat(district.getLat() / 10000000000D); - districtInfoDto.setLng(district.getLng() / 10000000000D); - } - districtInfoDto.setPropertyType(district.getEstateType2()); - if (HouseValidator.validateBuildingType(district.getBuildType())) { - districtInfoDto.setBuildingType(district.getBuildType()); - } else { - districtInfoDto.setBuildingType(""); - } - districtInfoDto.setBlock(district.getBlock()); - districtInfoDto.setTownship(district.getTownship()); - if (district.getLoudongCount() != null && district.getLoudongCount() > 0) { - districtInfoDto.setBuildingCount(district.getLoudongCount()); - } - - if (district.getHouseholdCount() != null) { - districtInfoDto.setTotalUnitCount(SeaweedUtils.formatHouseholdCount(district.getHouseholdCount().toString())); - } else { - districtInfoDto.setTotalUnitCount(""); - } - districtInfoDto.setManagementFee(district.getEstateCharge()); - if (district.getCarSiteCount() != null) { - districtInfoDto.setParking(SeaweedUtils.formatCarSiteCount(district.getCarSiteCount().toString())); - } else { - districtInfoDto.setParking(""); - } - districtInfoDto.setOwnershipPeriod(district.getPropertyLife()); - districtInfoDto.setOwnershipType(district.getHouseProperty()); - districtInfoDto.setBuildingStructure(district.getBuildStructure()); - districtInfoDto.setLandProperty(district.getLandProperty()); - districtInfoDto.setFloorSpace(SeaweedUtils.formatAllArea(district.getAllArea())); - districtInfoDto.setConstructionSpace(district.getBuildArea()); - districtInfoDto.setPlotRatio(SeaweedUtils.formatCubagePercent(district.getCubagePercent())); - districtInfoDto.setGreenPercentage(SeaweedUtils.formatVirescencePercent(district.getVirescencePercent())); - districtInfoDto.setDeveloper(district.getDeveloper()); - districtInfoDto.setPropertyManagement(district.getEstateCompany()); - - Integer finishYear = districtService.getCreateYear(district); - if (finishYear != null) { - districtInfoDto.setFinishYear(finishYear); - } - - mav.setModel(BasicModel.buildOKModel().setResult(districtInfoDto)); - return mav; - } - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - - private void saveAddressMatchLog(Map resMap, String keywords, String city, String token) { - Map tokenMap = FangjiaApiUtil.parseToken(token); - String userName = null; - // token验证后,拿取出的字段再去数据库验证一遍 - if (tokenMap != null && StringUtils.isNotBlank(tokenMap.get("userid")) - && !"null".equals(tokenMap.get("userid"))) { - User user = userService.findById(Long.parseLong(tokenMap.get("userid"))); - if (user != null) { - userName = user.getUserName(); - } - } - // 记录用户搜索词open匹配结果 - HttpServletRequest request = ActionContext.getContext().getRequest(); - AddressMatchLog addressMatchLog = new AddressMatchLog(); - addressMatchLog.setCity(city); - addressMatchLog.setInput(keywords); - addressMatchLog.setIp(AnalyticsUtil.getIpAddress(request)); - addressMatchLog.setSource("API"); - addressMatchLog.setUserName(userName); - addressMatchLog.setCreationDate(new Date()); - addressMatchLog.setModificationDate(new Date()); - if (MapUtils.isNotEmpty(resMap)) { - if (resMap.containsKey("status") && (Integer) resMap.get("status") == 0) { - List> result = new ArrayList>(); - Map map = new HashMap(); - map.put("city", (String) resMap.get("city")); - map.put("region", (String) resMap.get("region")); - map.put("name", (String) resMap.get("name")); - result.add(map); - addressMatchLog.setResult(result); - } else { - addressMatchLog.setStatus(1); - } - } else { - addressMatchLog.setStatus(1); - } - addressMatchLogService.addAddressMatchLog(addressMatchLog); - } - - @Authority(role = Role.NONE) - public Object sampleEvaluateAction(PropertyEvaluationModel model, HttpServletRequest request) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); - return mav; - } - if (model.getCity().endsWith("市")) { - model.setCity(model.getCity().replaceAll("市$", "")); - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - model.setName(district.getName()); - - if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { - mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); - return mav; - } - if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); - return mav; - } - - if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); - return mav; - } - if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { - mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); - return mav; - } - - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - EvaluationBo evaluationBo = evaluationService.doApply(buildEvaluation(model, request), true, false, true); - if (evaluationBo != null && evaluationBo.getSampleModeValue() > 0) { - UniversalDto dto = UniversalDto.newDto(); - dto.put("city", district.getCity()); - dto.put("district", district.getRegion()); - dto.put("name", district.getName()); - dto.put("totalPrice", evaluationBo.getSampleModeValue()); - dto.put("avgPrice", evaluationBo.getSampleModeValue() / model.getSize()); - mav.setModel(BasicModel.buildOKModel().setResult(dto)); - return mav; - } - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); - return mav; - } - - public Object evaluateAction(PropertyEvaluationModel model, HttpServletRequest request) - throws NumberFormatException, IllegalAccessException { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); - return mav; - } - if (model.getCity().endsWith("市")) { - model.setCity(model.getCity().replaceAll("市$", "")); - } - if (StringUtils.isNotBlank(request.getParameter("calDate"))) { - Date calDate = null; - try { - calDate = DateUtils.parseDate(request.getParameter("calDate"), new String[] { "yyyy-MM-dd" }); - } catch (ParseException e) { - - } - if (calDate == null) { - mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); - return mav; - } else { - model.setCalDate(calDate); - } - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - if(model.getDistrict().contains("市辖区") || model.getDistrict().contains(model.getCity())){ - district = districtService.findByNameAndAlias(model.getCity(), null, model.getName(), "district"); - } - if(district == null){ - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - } - model.setName(district.getName()); - - if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { - mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); - return mav; - } - if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); - return mav; - } - - if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); - return mav; - } - if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { - mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); - return mav; - } - - if(model.getFloor() == null){ - JSONObject structureOb = addressMatchProxyService.addressStructure(district.getCity(), model.getAddress()); - if(structureOb != null){ - if(structureOb.containsKey("buildingNumber")){ - model.setBuildingNumber(structureOb.getString("buildingNumber")); - } - - if(structureOb.containsKey("roomNumber")){ - String roomNumber = structureOb.getString("roomNumber"); - model.setFloor(getFloor(roomNumber)); - } - - } - } - - if(model.getMaxFloor() == null && model.getFloor() != null &&StringUtils.isNotBlank(model.getBuildingNumber())){ - Loudong loudong = loudongService.findForEvaluate(district.getId(), model.getBuildingNumber(), model.getUnitNumber()); - if(loudong != null && loudong.getFloors() >= model.getFloor()){ - model.setMaxFloor(loudong.getFloors()); - } - } - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - - if (model.getCalDate() != null) { - if (new Date().before(model.getCalDate())) { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); - } - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } - - - Evaluation evaluation = evaluationService.evaluate(district, buildEvaluation(model, request), - model.getCalDate()); - Double cityPriceCredit = null; - if (StringUtils.isNotBlank(evaluation.getFromUserId())) { - try { - ApiUserAuthority apiUserAuthority = apiUserAuthorityService - .findByUserId(Long.valueOf(evaluation.getFromUserId())); - if (apiUserAuthority.getCityCreditMap() != null - && apiUserAuthority.getCityCreditMap().containsKey(evaluation.getCity())) { - cityPriceCredit = apiUserAuthority.getCityCreditMap().get(evaluation.getCity()); - if (cityPriceCredit > 1 || cityPriceCredit < 0) { - cityPriceCredit = null; - } - } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - - this.adjustPriceByRatio(district, evaluation); - } - - // 调整面积不同面积价格 - try { - DistrictStatBo districtStatBo = districtStatService.findDistrictStat(new DistrictKey(district)); - int orgAvgPrice = 0; - if (districtStatBo != null) { - if (StringUtils.isNotBlank(district.getEstateType2()) && district.getEstateType2().contains("别墅") && districtStatBo.getVillaDistrictStat() != null) { - orgAvgPrice = districtStatBo.getVillaDistrictStat().getAvgPrice(); - } else if (districtStatBo.getDistrictStat() != null) { - orgAvgPrice = districtStatBo.getDistrictStat().getAvgPrice(); - } - } - if (evaluation != null && evaluation.getAvgPrice() != null && evaluation.getAvgPrice() > 0) { - int factorPrice = evaluation.getAvgPrice(); - int avgPrice = evaluateFactorService.recompose(district.getCity(), district.getRegion(), evaluation.getArea(), factorPrice, orgAvgPrice); - Integer minPrice = (int)(evaluation.getAvgPrice() * 0.95); - Integer maxPrice = (int)(evaluation.getAvgPrice() * 1.05); - // 偏离度超过5%不进行调整 - if (minPrice <= avgPrice && avgPrice <= maxPrice) { - evaluation.setAvgPrice(avgPrice); - evaluation.setBigTotalPrice((long) (avgPrice * evaluation.getArea())); - } - } - } catch (Exception ex) { - LOGGER.error("调整面积不同面积价格异常{}", ex.getMessage()); - } - - if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0 - && (cityPriceCredit == null || evaluation.getCredit() >= cityPriceCredit)) { - Map districtPriceMap = new HashMap(); - districtPriceMap.put("city", district.getCity()); - districtPriceMap.put("district", district.getRegion()); - districtPriceMap.put("name", district.getName()); - districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); - districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); - - // 根据城市等 级设置D级可信度 - ApiUserAuthority apiUserAuthority = apiUserAuthorityService - .findByUserId(Long.valueOf(evaluation.getFromUserId())); - if (apiUserAuthority != null && null != apiUserAuthority.getCreditLevelStatus() - && apiUserAuthority.getCreditLevelStatus() == 1) { - double dCredit = 0.61; - if (null != apiUserAuthority.getPriceRatingMap()) { - ServerArea serverArea = serverAreaService.findByDisplay(evaluation.getCity()); - Map rateMap = apiUserAuthority.getPriceRatingMap(); - if (null != rateMap) { - dCredit = rateMap.get(CITYLEVEL_MAP.get(serverArea.getNewCityGrade().toString())); - } - } - Map rMap = getLastEvaluationPrice(district, evaluation, dCredit); - - if (model.getScope() == EVALUATE_SHOW_DETAIL) { - if (null != rMap) { - if (rMap.containsKey("level")) { - districtPriceMap.put("level", rMap.get("level")); - } - if (rMap.containsKey("other_price")) { - districtPriceMap.put("other_price", rMap.get("other_price")); - } - } - } - - Long lastPrice = (Long) rMap.get("lastPrice"); - - if (null != lastPrice) { - districtPriceMap.put("totalPrice", lastPrice); - if (lastPrice > 0 && lastPrice != evaluation.getBigTotalPrice()) { - districtPriceMap.put("avgPrice", (int) (lastPrice / evaluation.getArea())); - } - } else { - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); - return mav; - } - - } else { - districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); - } - - if (model.getScope() == EVALUATE_SHOW_DETAIL) { - districtPriceMap.put("evaluateWay", evaluation.getEvaluateWay()); - districtPriceMap.put("credit", evaluation.getCredit()); - districtPriceMap.put("id", evaluation.getId()); - } - mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); - try{ - if(StringUtils.isNotBlank(evaluation.getFromUserId()) && !evaluation.getFromUserId().equals("1007497")){ - openApiLogService.saveLog(CommonUtils.convertToMap(model), districtPriceMap, evaluation, "/property/evaluate"); - } - - }catch(Exception e){ - e.printStackTrace(); - } - - return mav; - } else { - evaluationService.remove(evaluation.getId()); - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); - return mav; - } - } - - /** - * 系数下调 - * - * @param district - * @param evaluation - */ - private void adjustPriceByRatio(District district, Evaluation evaluation) { - - try { - ApiUserCfg apiUserCfg_pt = apiUserCfgService.findByUserId(Long.valueOf(evaluation.getFromUserId()), ApiUserCfg.ApiUserCfgKey.PRICE_TYPE); - if (apiUserCfg_pt != null && apiUserCfg_pt.getCfgValue() != null) { - String priceType = apiUserCfg_pt.getCfgValue().toString(); - // 评估价则系数调整 - if (StringUtils.isNotBlank(priceType) && "evaluate".equals(priceType)) { - EvaluateRatio evaluateRatio = null; - if (StringUtils.isNotBlank(district.getRegion())) { - evaluateRatio = evaluateRatioService.findByCityAndRegion(district.getCity(), district.getRegion()); - } - if (evaluateRatio == null) { - evaluateRatio = evaluateRatioService.findByCity(district.getCity()); - } - if (evaluateRatio != null) { - // 系数添加 - long totalPrice = evaluation.getBigTotalPrice(); - totalPrice = (long) (totalPrice * (1 + evaluateRatio.getRatio())); - evaluation.setBigTotalPrice(totalPrice); - evaluation.setAvgPrice((int) (totalPrice / evaluation.getArea())); - } - } - } - } catch (Exception ex) { - LOGGER.error("系数下调异常{}", ex.getMessage()); - } - } - - static final Map CITY_CORRECTION_FACTOR = new HashMap(); - static { - CITY_CORRECTION_FACTOR.put("上海", 0.02); - CITY_CORRECTION_FACTOR.put("杭州", 0.1); - CITY_CORRECTION_FACTOR.put("大连", 0.09); - CITY_CORRECTION_FACTOR.put("广州", 0.09); - CITY_CORRECTION_FACTOR.put("深圳", 0.02); - CITY_CORRECTION_FACTOR.put("重庆", 0.1); - CITY_CORRECTION_FACTOR.put("苏州", 0.08); - CITY_CORRECTION_FACTOR.put("成都", 0.07); - CITY_CORRECTION_FACTOR.put("北京", 0.04); - CITY_CORRECTION_FACTOR.put("厦门", 0.1); - } - - public Object evaluateForTestAction(PropertyEvaluationModel model, HttpServletRequest request) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity())) { - mav.setModel(BasicModel.buildBadRequestModel("城市为必填项")); - return mav; - } - if (model.getSize() <= 0){ - mav.setModel(BasicModel.buildBadRequestModel("面积为必填项")); - return mav; - } - if(StringUtils.isBlank(model.getAddress()) && StringUtils.isBlank(model.getName())){ - mav.setModel(BasicModel.buildBadRequestModel("地址和小区名至少填一个")); - return mav; - } - if(StringUtils.isNotBlank(model.getName()) && StringUtils.isBlank(model.getAddress())){ - model.setAddress(model.getName()); - } - if (StringUtils.isNotBlank(request.getParameter("calDate"))) { - Date calDate = DateUtil.parseDate(request.getParameter("calDate"), "yyyy-MM-dd"); - model.setCalDate(calDate); - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findDistrict(new DistrictKey(model.getCity(), model.getDistrict(), model.getName()), "district");//matchDistrict(model.getCity(), model.getAddress(), model.getDistrict(), model.getName()); - if(district == null){ - //防止地址模糊,名称详细的情况 - district = matchDistrict(model.getCity(), model.getName(), model.getDistrict(), model.getAddress()); - if(district == null){ - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - } - model.setName(district.getName()); - if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { - mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); - return mav; - } - if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); - return mav; - } - - if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); - return mav; - } - if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { - mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); - return mav; - } - - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - - if (model.getCalDate() != null) { - if (new Date().before(model.getCalDate())) { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); - } - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } - Evaluation evaluation = evaluationService.evaluate(district, buildEvaluation(model, request), model.getCalDate()); - if(!"self".equalsIgnoreCase(evaluation.getEvaluateWay())){ - evaluationService.remove(evaluation.getId()); - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); - return mav; - } - - this.adjustPriceByRatio(district, evaluation); - - // 调整面积不同面积价格 - try { - DistrictStatBo districtStatBo = districtStatService.findDistrictStat(new DistrictKey(district)); - int orgAvgPrice = 0; - if (districtStatBo != null) { - if (StringUtils.isNotBlank(district.getEstateType2()) && district.getEstateType2().contains("别墅") && districtStatBo.getVillaDistrictStat() != null) { - orgAvgPrice = districtStatBo.getVillaDistrictStat().getAvgPrice(); - } else if (districtStatBo.getDistrictStat() != null) { - orgAvgPrice = districtStatBo.getDistrictStat().getAvgPrice(); - } - } - if (evaluation != null && evaluation.getAvgPrice() != null && evaluation.getAvgPrice() > 0) { - int factorPrice = evaluation.getAvgPrice(); - int avgPrice = evaluateFactorService.recompose(district.getCity(), district.getRegion(), evaluation.getArea(), factorPrice, orgAvgPrice); - Integer minPrice = (int)(evaluation.getAvgPrice() * 0.95); - Integer maxPrice = (int)(evaluation.getAvgPrice() * 1.05); - // 偏离度超过5%不进行调整 - if (minPrice <= avgPrice && avgPrice <= maxPrice) { - evaluation.setAvgPrice(avgPrice); - evaluation.setBigTotalPrice((long) (avgPrice * evaluation.getArea())); - } - } - } catch (Exception ex) { - - } - Map districtPriceMap = new LinkedHashMap(); - districtPriceMap.put("city", district.getCity()); - districtPriceMap.put("district", district.getRegion()); - districtPriceMap.put("name", district.getName()); - - districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); - districtPriceMap.put("unitPrice", evaluation.getAvgPrice()); - // 新增置信度 - CommunityBasePrice communityBasePrice = communityBasePriceService.getById(district.getId()); - if (communityBasePrice != null) { - districtPriceMap.put("credit", communityBasePrice.getCredit()); - } else { - districtPriceMap.put("credit", evaluation.getCredit()); - } - List names = new ArrayList(); - names.add(district.getName()); - if(district.getAlias() != null){ - for(String alia : district.getAlias()){ - if(StringUtils.isNotBlank(alia) && !names.contains(alia)){ - names.add(alia); - } - } - } - Integer minPrice = (int)(evaluation.getAvgPrice() * 0.8); - Integer maxPrice = (int)(evaluation.getAvgPrice() * 1.2); - Integer min10Price = (int)(evaluation.getAvgPrice() * 0.9); - Integer max10Price = (int)(evaluation.getAvgPrice() * 1.1); - // 新增第三方均价 - try { - double dCredit = 0.61; - Map rMap = getLastEvaluationPrice(district, evaluation, dCredit); - if (null != rMap) { - if (rMap.containsKey("other_price")) { - Map otherPriceMap = (Map) rMap.get("other_price"); - Map priceResultMap = new HashMap(); - for (String key : otherPriceMap.keySet()) { - Integer price = otherPriceMap.get(key); - // 剔除偏差大于10的 - if (min10Price <= price && max10Price >= price) { - if (OTHER_PRICE_MAP.containsKey(key)) { - priceResultMap.put(OTHER_PRICE_MAP.get(key), price); - } - } - } - districtPriceMap.put("otherPrice", priceResultMap); - } - } - } catch (Exception ex) { - - } - List houses = seawaterDao.findHouses(district.getCity(), district.getRegion(), names,minPrice, maxPrice, 20); - if(houses.size() > 3){ - districtPriceMap.put("calcType", 1); - List houseDtos = new ArrayList(); - for(Seawater seawater: houses){ - UniversalDto houseDto = new UniversalDto(); - houseDto.append("city", seawater.getCity()); - houseDto.append("district", seawater.getRegion()); - houseDto.append("name", seawater.getDistrictName()); - houseDto.append("title", seawater.getName()); - houseDto.append("size", seawater.getArea()); - houseDto.append("unitPrice", seawater.getAvgPrice()); - houseDto.append("totalPrice", seawater.getTotalPrice()); - houseDto.append("room", seawater.getRoom()); - houseDto.append("hall", seawater.getHall()); - houseDto.append("toilet", seawater.getToilet()); - houseDto.append("direction", HouseValidator.fetchDirectionInfo(seawater.getDirection())); - houseDto.append("decoration", HouseValidator.fetchFitmentInfo(seawater.getFitment())); - houseDto.append("publishDate", seawater.getpDate()); - if(seawater.getHeight() != null && seawater.getHeight() > 0){ - houseDto.append("maxFloor", seawater.getHeight()); - } - houseDtos.add(houseDto); - } - districtPriceMap.put("houses", houseDtos); - }else if(district.getLng() != null && district.getLng() > 0){ - double lng = DataUtil.roundDouble(district.getLng() / 10000000000.0,6); - double lat = DataUtil.roundDouble(district.getLat() / 10000000000.0, 6); - List districts = districtService.findNearestDistrict(district.getEstateType2(), lng, lat, 1000 * 3 , 6, null); - if(districts.size() < 2){ - evaluationService.remove(evaluation.getId()); - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); - return mav; - } - UniversalDto modelFeaturesFto = UniversalDto.newDto(); - districtPriceMap.put("calcType", 2); - modelFeaturesFto.append("propertyType", district.getEstateType2()); - modelFeaturesFto.append("lng", lng); - modelFeaturesFto.append("lat", lat); - DistrictAnalyData districtAnalyData = districtAnalyDataService.findByDistrictKey(new DistrictKey(district)); - if(districtAnalyData != null && districtAnalyData.getHalfYearMarkup() != null){ - modelFeaturesFto.append("halfYearMarkup", DataUtil.roundDouble(districtAnalyData.getHalfYearMarkup() * 100 ,2)); - } - RegionAnaData regionAnaData = regionAnaDataService.findRegionAnaData(district.getCity(), district.getRegion()); - if(regionAnaData != null){ - modelFeaturesFto.append("region20PercentPrice", regionAnaData.getRegion20PercentPrice()); - modelFeaturesFto.append("region80PercentPrice", regionAnaData.getRegion80PercentPrice()); - } - List nearCommunityDtos = new ArrayList(); - for(District d : districts){ - if(d.getId().equals(district.getId())){ - continue; - } - UniversalDto districtDto = UniversalDto.newDto(); - districtDto.append("city", d.getCity()); - districtDto.append("region", d.getRegion()); - districtDto.append("name", d.getName()); - districtDto.append("lng", DataUtil.roundDouble(d.getLng()/10000000000.0 ,6)); - districtDto.append("lat", DataUtil.roundDouble(d.getLat()/10000000000.0, 6)); - districtDto.append("distance", GeoUtils.calculateDistance(lng, lat, d.getLng()/10000000000.0, d.getLat()/10000000000.0)); - districtDto.append("propertyType", d.getEstateType2()); - Integer buildYear = districtService.getBuildYear(d); - if(buildYear != null){ - districtDto.append("buildYear", String.valueOf(buildYear)); - } - districtAnalyData = districtAnalyDataService.findByDistrictKey(new DistrictKey(d)); - if(districtAnalyData != null){ - if (districtAnalyData.getHalfYearMarkup() != null) { - districtDto.append("halfYearMarkup", DataUtil.roundDouble(districtAnalyData.getHalfYearMarkup() * 100, 2)); - } - if (districtAnalyData.getAvgPrice() != null && minPrice <= districtAnalyData.getAvgPrice() && maxPrice >= districtAnalyData.getAvgPrice()) { - districtDto.append("avgPrice", districtAnalyData.getAvgPrice()); - } - } - - nearCommunityDtos.add(districtDto); - } - Integer buildYear = districtService.getBuildYear(district); - if(buildYear != null){ - modelFeaturesFto.put("buildYear", String.valueOf(buildYear)); - } - modelFeaturesFto.append("nearCommunity", nearCommunityDtos); - - // 模型特征新增周边数量 - CommunityPoi communityPoi = communityPoiService.getById(district.getId()); - if (communityPoi != null) { - modelFeaturesFto.put("subway", communityPoi.getSubway()); - modelFeaturesFto.put("traffic", communityPoi.getTraffic()); - modelFeaturesFto.put("bank", communityPoi.getBank()); - modelFeaturesFto.put("primary", communityPoi.getPrimary()); - modelFeaturesFto.put("hospital", communityPoi.getHospital()); - modelFeaturesFto.put("junior", communityPoi.getJunior()); - modelFeaturesFto.put("funeral", communityPoi.getFuneral()); - } - districtPriceMap.put("modelFeatures", modelFeaturesFto); - } - mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); - return mav; - } - /** - * 地址估值 - * @param model 参数 - * @param request - * @return - */ - public Object addressEvaluateAction(PropertyEvaluationModel model, HttpServletRequest request) throws IllegalAccessException { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getAddress()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,地址,面积(size)为必填项")); - return mav; - } - if(model.getDistrict()!=null){ - //区域编码转房价网区域 - FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertOfficialCodeToFangjia(model.getDistrict()); - if(fangjiaOfficialAreaMap != null){ - model.setDistrict(fangjiaOfficialAreaMap.getFangjiaDistrict()); - } - } - - boolean villaFlag = DataUtil.isVilla(model.getSize(), model.getName(), model.getHeight(), model.getRoom()); - - District district = null; - Map params = new HashMap(); - params.put("city", model.getCity()); - if(StringUtils.isNotBlank(model.getDistrict())){ - params.put("suggestDistrict", model.getDistrict()); - } - params.put("address", model.getAddress()); - if(StringUtils.isNotBlank(model.getName())){ - params.put("suggestName", model.getName()); - } - params.put("category", "district"); - String result = addressMatchProxyService.parser(params); - if (result != null) { - JSONObject json = JSONObject.fromObject(result); - if(json.getInt("code")==200){ - Map map = (Map) json.get("result"); - if((Integer)map.get("precise")>=0){ - String propertyType = (String) map.get("propertyType"); - if(villaFlag && StringUtils.isNotBlank(propertyType) && !propertyType.equals("别墅")){ - district = districtService.findByNameAndAlias((String) map.get("city"), (String) map.get("district"), (String) map.get("name")+"别墅", "district"); - } - if(null == district){ - district = districtService.findByNameAndAlias((String) map.get("city"), (String) map.get("district"), (String) map.get("name"), "district"); - } - - } - } - } - - if(district == null){ - mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!")); - return mav; - } - model.setDistrict(district.getRegion()); - model.setName(district.getName()); - return this.evaluateAction(model,request); - } - - public Object evaluate2Action(PropertyEvaluationModel model, HttpServletRequest request) - throws NumberFormatException, IllegalAccessException { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); - return mav; - } - if (model.getCity().endsWith("市")) { - model.setCity(model.getCity().replaceAll("市$", "")); - } - if (StringUtils.isNotBlank(request.getParameter("calDate"))) { - Date calDate = null; - try { - calDate = DateUtils.parseDate(request.getParameter("calDate"), new String[] { "yyyy-MM-dd" }); - } catch (ParseException e) { - - } - if (calDate == null) { - mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); - return mav; - } else { - model.setCalDate(calDate); - } - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - model.setName(district.getName()); - - if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { - mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); - return mav; - } - if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); - return mav; - } - - if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); - return mav; - } - if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { - mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); - return mav; - } - - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - - if (model.getCalDate() != null) { - if (new Date().before(model.getCalDate())) { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); - } - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } - Evaluation evaluation = evaluationService.evaluate(district, buildEvaluation(model, request), model.getCalDate()); - Double cityPriceCredit = null; - if (StringUtils.isNotBlank(evaluation.getFromUserId())) { - try { - ApiUserAuthority apiUserAuthority = apiUserAuthorityService - .findByUserId(Long.valueOf(evaluation.getFromUserId())); - if (apiUserAuthority.getCityCreditMap() != null - && apiUserAuthority.getCityCreditMap().containsKey(evaluation.getCity())) { - cityPriceCredit = apiUserAuthority.getCityCreditMap().get(evaluation.getCity()); - if (cityPriceCredit > 1 || cityPriceCredit < 0) { - cityPriceCredit = null; - } - } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0 - && (cityPriceCredit == null || evaluation.getCredit() >= cityPriceCredit)) { - - Map districtPriceMap = new HashMap(); - districtPriceMap.put("city", district.getCity()); - districtPriceMap.put("district", district.getRegion()); - districtPriceMap.put("name", district.getName()); - districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); - - // 根据城市等 级设置D级可信度 - ApiUserAuthority apiUserAuthority = apiUserAuthorityService - .findByUserId(Long.valueOf(evaluation.getFromUserId())); - if (apiUserAuthority != null && null != apiUserAuthority.getCreditLevelStatus() - && apiUserAuthority.getCreditLevelStatus() == 1) { - double dCredit = 0.61; - if (null != apiUserAuthority.getPriceRatingMap()) { - ServerArea serverArea = serverAreaService.findByDisplay(evaluation.getCity()); - Map rateMap = apiUserAuthority.getPriceRatingMap(); - if (null != rateMap) { - dCredit = rateMap.get(CITYLEVEL_MAP.get(serverArea.getNewCityGrade().toString())); - } - } - Map rMap = getLastEvaluationPrice(district, evaluation, dCredit); - - if (model.getScope() == EVALUATE_SHOW_DETAIL) { - if (null != rMap) { - if (rMap.containsKey("level")) { - districtPriceMap.put("level", rMap.get("level")); - } - if (rMap.containsKey("other_price")) { - districtPriceMap.put("other_price", rMap.get("other_price")); - } - } - } - - Long lastPrice = (Long) rMap.get("lastPrice"); - if (null != lastPrice) { - districtPriceMap.put("totalPrice", lastPrice); - if (lastPrice > 0 && lastPrice != evaluation.getBigTotalPrice()) { - districtPriceMap.put("avgPrice", (int) (lastPrice / evaluation.getArea())); - } - } else { - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); - return mav; - } - - } else { - districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); - } - - if (model.getScope() == EVALUATE_SHOW_DETAIL) { - districtPriceMap.put("evaluateWay", evaluation.getEvaluateWay()); - districtPriceMap.put("credit", evaluation.getCredit()); - districtPriceMap.put("id", evaluation.getId()); - } - mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); - return mav; - } else { - evaluationService.remove(evaluation.getId()); - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); - return mav; - } - } - - /** - * 四川锦程 定制接口 多建筑年代 - * @param model - * @param request - * @return - * @throws NumberFormatException - * @throws IllegalAccessException - */ - public Object evaluate3Action(PropertyEvaluationModel model, HttpServletRequest request) - throws NumberFormatException, IllegalAccessException { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); - return mav; - } - if (model.getCity().endsWith("市")) { - model.setCity(model.getCity().replaceAll("市$", "")); - } - if (StringUtils.isNotBlank(request.getParameter("calDate"))) { - Date calDate = null; - try { - calDate = DateUtils.parseDate(request.getParameter("calDate"), new String[] { "yyyy-MM-dd" }); - } catch (ParseException e) { - - } - if (calDate == null) { - mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); - return mav; - } else { - model.setCalDate(calDate); - } - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - model.setName(district.getName()); - - if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { - mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); - return mav; - } - if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); - return mav; - } - - if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); - return mav; - } - if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { - mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); - return mav; - } - - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - - if (model.getCalDate() != null) { - if (new Date().before(model.getCalDate())) { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); - } - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } - Evaluation evaluation = evaluationService.evaluate(district, buildEvaluation(model, request), model.getCalDate()); - Double cityPriceCredit = null; - if (StringUtils.isNotBlank(evaluation.getFromUserId())) { - try { - ApiUserAuthority apiUserAuthority = apiUserAuthorityService - .findByUserId(Long.valueOf(evaluation.getFromUserId())); - if (apiUserAuthority.getCityCreditMap() != null - && apiUserAuthority.getCityCreditMap().containsKey(evaluation.getCity())) { - cityPriceCredit = apiUserAuthority.getCityCreditMap().get(evaluation.getCity()); - if (cityPriceCredit > 1 || cityPriceCredit < 0) { - cityPriceCredit = null; - } - } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0 - && (cityPriceCredit == null || evaluation.getCredit() >= cityPriceCredit)) { - - Map districtPriceMap = new HashMap(); - districtPriceMap.put("city", district.getCity()); - districtPriceMap.put("district", district.getRegion()); - districtPriceMap.put("name", district.getName()); - districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); - if(StringUtils.isNotBlank(district.getFinishBuildingDate())){ - Pattern pat3 = Pattern.compile("\\d{4}"); - Matcher matcher3 = pat3.matcher(district.getFinishBuildingDate()); - if (matcher3.find()) { - districtPriceMap.put("buildYear", matcher3.group()); - } - } - - - // 根据城市等 级设置D级可信度 - ApiUserAuthority apiUserAuthority = apiUserAuthorityService - .findByUserId(Long.valueOf(evaluation.getFromUserId())); - if (apiUserAuthority != null && null != apiUserAuthority.getCreditLevelStatus() - && apiUserAuthority.getCreditLevelStatus() == 1) { - double dCredit = 0.61; - if (null != apiUserAuthority.getPriceRatingMap()) { - ServerArea serverArea = serverAreaService.findByDisplay(evaluation.getCity()); - Map rateMap = apiUserAuthority.getPriceRatingMap(); - if (null != rateMap) { - dCredit = rateMap.get(CITYLEVEL_MAP.get(serverArea.getNewCityGrade().toString())); - } - } - Map rMap = getLastEvaluationPrice(district, evaluation, dCredit); - - if (model.getScope() == EVALUATE_SHOW_DETAIL) { - if (null != rMap) { - if (rMap.containsKey("level")) { - districtPriceMap.put("level", rMap.get("level")); - } - if (rMap.containsKey("other_price")) { - districtPriceMap.put("other_price", rMap.get("other_price")); - } - } - } - - Long lastPrice = (Long) rMap.get("lastPrice"); - if (null != lastPrice) { - districtPriceMap.put("totalPrice", lastPrice); - if (lastPrice > 0 && lastPrice != evaluation.getBigTotalPrice()) { - districtPriceMap.put("avgPrice", (int) (lastPrice / evaluation.getArea())); - } - } else { - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); - return mav; - } - - } else { - districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); - } - - if (model.getScope() == EVALUATE_SHOW_DETAIL) { - districtPriceMap.put("evaluateWay", evaluation.getEvaluateWay()); - districtPriceMap.put("credit", evaluation.getCredit()); - districtPriceMap.put("id", evaluation.getId()); - } - mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); - return mav; - } else { - evaluationService.remove(evaluation.getId()); - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); - return mav; - } - } - - @Authority(role = Role.USER) - public Object addBatchEvaluateTaskAction(BatchEvaluateModel model) throws IOException { - - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (model.getFile() == null || model.getFile().isEmpty()) { - mav.setModel(BasicModel.buildBadRequestModel("请上传包含待评估数据的数据文件")); - return mav; - } - MultipartFile file = model.getFile(); - - if (StringUtils.isNotBlank(model.getCharset()) && Charset.isSupported(model.getCharset())) { - mav.setModel(BasicModel.buildBadRequestModel("字符编码不支持")); - return mav; - } else { - model.setCharset("GBK"); - } - Map tokenMap = FangjiaApiUtil.parseToken(model.getToken()); - String userId = tokenMap.get("userid"); - DBObject dbFile = fileDao.save(file.getBytes(), file.getContentType()); - String fileId = (String) dbFile.get("_id"); - BatchEvaluateTask task = new BatchEvaluateTask(); - task.setDateCreated(new Date()); - task.setStatus(BatchEvaluateTask.StatusEnum.INIT.getStatus()); - task.setDataFileId(fileId); - task.setUserId(userId); - task.setFileName(file.getOriginalFilename()); - task.setCharset(model.getCharset()); - batchEvaluateService.saveBatchEvaluateTask(task); - Map data = new HashMap(); - data.put("taskId", task.getId()); - mav.setModel(BasicModel.buildOKModel().setResult(data)); - return mav; - } - - @Authority(role = Role.USER) - public Object batchEvaluateTaskStatusAction(BatchEvaluateModel model) { - - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())) { - mav.setModel(BasicModel.buildBadRequestModel("任务id非法")); - return mav; - } - Map tokenMap = FangjiaApiUtil.parseToken(model.getToken()); - String userId = tokenMap.get("userid"); - BatchEvaluateTask task = batchEvaluateService.findBatchEvaluateTaskById(model.getId()); - if (task == null || !task.getUserId().equals(userId)) { - mav.setModel(BasicModel.buildBadRequestModel("任务不存在")); - return mav; - } - Map data = new HashMap(); - data.put("status", task.getStatus()); - if (BatchEvaluateTask.StatusEnum.INIT.getStatus() == task.getStatus()) { - data.put("msg", "待处理"); - } else if (BatchEvaluateTask.StatusEnum.DOING.getStatus() == task.getStatus()) { - data.put("msg", "处理中"); - } else if (BatchEvaluateTask.StatusEnum.SUC.getStatus() == task.getStatus()) { - data.put("msg", "已完成"); - data.put("downLink", "http://open.fangjia.com/property/downEvaluateResult?id=" + task.getId() + "&token=" - + model.getToken()); - } else if (BatchEvaluateTask.StatusEnum.ERROR.getStatus() == task.getStatus()) { - data.put("msg", "处理失败"); - data.put("subMsg", task.getMsg()); - } - mav.setModel(BasicModel.buildOKModel().setResult(data)); - return mav; - } - - @Authority(role = Role.USER) - public Object downEvaluateResultAction(BatchEvaluateModel model, HttpServletResponse response) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())) { - mav.setModel(BasicModel.buildBadRequestModel("任务id非法")); - return mav; - } - Map tokenMap = FangjiaApiUtil.parseToken(model.getToken()); - - String userId = tokenMap.get("userid"); - BatchEvaluateTask task = batchEvaluateService.findBatchEvaluateTaskById(model.getId()); - if (task == null || !task.getUserId().equals(userId)) { - mav.setModel(BasicModel.buildBadRequestModel("任务不存在")); - return mav; - } - - DBObject file = fileDao.findById(task.getDataFileId()); - byte[] data = (byte[]) file.get("data"); - OutputStream os = null; - try { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application/x-gzip"); - String fileName = DateUtil.formatToYYYYMMDDhhmmss(new Date()) + ".csv.gz"; - response.setHeader("Content-Disposition", "attachment;filename=" + fileName); - os = response.getOutputStream();// 取得输出流 - os.write(data); - os.flush(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (os != null) { - os.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - ModelAndViewSupport mv = new ModelAndViewSupport(); - mv.setViewType("stream"); - return mv; - } - - @Authority(role = Role.NONE) - public Object batchEvaluateTemplateAction(BatchEvaluateModel model, HttpServletResponse response, - HttpServletRequest request) { - OutputStream os = null; - FileInputStream fis = null; - try { - response.setCharacterEncoding("UTF-8"); - response.setContentType("text/csv"); - response.setHeader("Content-Disposition", "attachment;filename=batchEvaluateTemplate.csv"); - os = response.getOutputStream();// 取得输出流 - String path = request.getSession().getServletContext().getRealPath("") + File.separator + "WEB-INF" - + File.separator + "classes" + File.separator + "batchEvaluateTemplate.csv"; - File template = new File(path); - fis = new FileInputStream(template); - byte[] data = new byte[fis.available()]; - fis.read(data); - os.write(data); - os.flush(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (os != null) { - os.close(); - } - if (fis != null) { - fis.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - ModelAndViewSupport mv = new ModelAndViewSupport(); - mv.setViewType("stream"); - return mv; - } - - public Object evaluateShopAction(PropertyEvaluationModel model, HttpServletRequest request) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); - return mav; - } - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "shop"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - model.setName(district.getName()); - if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { - mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); - return mav; - } - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - if (model.getCalDate() != null) { - model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } - Evaluation evaluation = evaluationService.evaluateWithPadding(buildEvaluation(model, request), - model.getCalDate()); - if (null != evaluation && evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0) { - Map districtPriceMap = new HashMap(); - districtPriceMap.put("city", district.getCity()); - districtPriceMap.put("district", district.getRegion()); - districtPriceMap.put("name", district.getName()); - districtPriceMap.put("totalPrice", evaluation.getTotalPrice()); - districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); - mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); - return mav; - } else { - evaluationService.remove(evaluation.getId()); - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价")); - return mav; - } - } - - public Object filterAction(PropertySearchModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - District district = districtService.findById(model.getId()); - fieldFilterService.refresh(); - fieldFilterService.filterWithProcessNUll(district); - mav.setModel(BasicModel.buildOKModel().setResult(district)); - return mav; - } - - public Object houseRentAction(PropertyEvaluationModel model, HttpServletRequest request) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getHouseType() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,房型(houseType)为必填项")); - return mav; - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - model.setName(district.getName()); - if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { - mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); - return mav; - } - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - List evaluations = evaluationService.histroyRent(district, buildEvaluation(model, request), 1, - model.getHouseType()); - if (evaluations.isEmpty()) { - mav.setModel(BasicModel.buildOKModel().setMsg("暂无租金")); - } else { - Evaluation evaluation = evaluations.get(0); - JSONObject item = new JSONObject(); - item.put("city", district.getCity()); - item.put("district", district.getRegion()); - item.put("name", district.getName()); - item.put("rent", evaluation.getAvgPrice()); - item.put("changePercent", evaluation.getMarkup() / 100d); - mav.setModel(BasicModel.buildOKModel().setResult(item)); - } - return mav; - } - - public Object historyRentAction(PropertyEvaluationModel model, HttpServletRequest request) { - - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getHouseType() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,房型(houseType)为必填项")); - return mav; - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - model.setName(district.getName()); - if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { - mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); - return mav; - } - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - if (model.getPeriodCount() == null) { - model.setPeriodCount(1); - } - if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) { - mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]")); - return mav; - } - - List evaluations = evaluationService.histroyRent(district, buildEvaluation(model, request), - model.getPeriodCount(), model.getHouseType()); - List historyEvaluations = new ArrayList(); - for (Evaluation evaluation : evaluations) { - if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0) { - JSONObject item = new JSONObject(); - item.put("city", district.getCity()); - item.put("district", district.getRegion()); - item.put("name", district.getName()); - item.put("rent", evaluation.getAvgPrice()); - item.put("changePercent", evaluation.getMarkup() / 100d); - item.put("date", DateUtil.formatByPattern(evaluation.getCreationDate(), "yyyy-MM")); - historyEvaluations.add(item); - } - } - if (historyEvaluations.size() > model.getPeriodCount()) { - historyEvaluations = historyEvaluations.subList(historyEvaluations.size() - model.getPeriodCount(), - historyEvaluations.size()); - } - mav.setModel(BasicModel.buildOKModel().setResult(historyEvaluations)); - return mav; - - } - - public Object historyEvaluateAction(PropertyEvaluationModel model, HttpServletRequest request) { - - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); - return mav; - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - model.setName(district.getName()); - - if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { - mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); - return mav; - } - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - if (model.getPeriodCount() == null) { - model.setPeriodCount(1); - } - if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) { - mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]")); - return mav; - } - if (StringUtils.isBlank(model.getPeriodType())) { - model.setPeriodType("weekly"); - } else { - if (!"weekly".equals(model.getPeriodType()) && !"monthly".equals(model.getPeriodType())) { - mav.setModel(BasicModel.buildBadRequestModel("periodModel值非法,合法值为:weekly,monthly")); - return mav; - } - } - Calendar calendar = Calendar.getInstance(); - if ("weekly".equals(model.getPeriodType())) { - calendar.add(Calendar.DATE, -model.getPeriodCount().intValue() * 7); - } else { - calendar.add(Calendar.MONTH, -model.getPeriodCount().intValue()); - - } - List evaluations = evaluationService.histroyEvaluate(district, buildEvaluation(model, request), - calendar.getTime(), model.getPeriodType()); - List historyEvaluations = new ArrayList(); - for (Evaluation evaluation : evaluations) { - if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0) { - JSONObject item = new JSONObject(); - item.put("city", district.getCity()); - item.put("district", district.getRegion()); - item.put("name", district.getName()); - item.put("totalPrice", evaluation.getBigTotalPrice()); - item.put("avgPrice", evaluation.getAvgPrice()); - item.put("changePercent", evaluation.getMarkup() / 100d); - if ("weekly".equals(model.getPeriodType())) { - item.put("date", DateUtil.formatByPattern(evaluation.getCreationDate(), "yyyy-MM-dd")); - } else { - item.put("date", DateUtil.formatByPattern(evaluation.getCreationDate(), "yyyy-MM")); - } - historyEvaluations.add(item); - } - } - if (historyEvaluations.size() > model.getPeriodCount()) { - historyEvaluations = historyEvaluations.subList(historyEvaluations.size() - model.getPeriodCount(), - historyEvaluations.size()); - } - mav.setModel(BasicModel.buildOKModel().setResult(historyEvaluations)); - return mav; - } - - public Object avgPriceAction(AvgPriceQueryModel model) { - - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); - return mav; - } - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (null == district) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - if (model.getPeriodCount() == null) { - model.setPeriodCount(1); - } - if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) { - mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]")); - return mav; - } - if (StringUtils.isBlank(model.getPeriodType())) { - model.setPeriodType("weekly"); - } else { - if (!"weekly".equals(model.getPeriodType()) && !"monthly".equals(model.getPeriodType())) { - mav.setModel(BasicModel.buildBadRequestModel("periodModel值非法,合法值为:weekly,monthly")); - return mav; - } - } - Calendar calendar = Calendar.getInstance(); - if ("weekly".equals(model.getPeriodType())) { - calendar.add(Calendar.DATE, -model.getPeriodCount().intValue() * 7); - } else { - calendar.add(Calendar.MONTH, -model.getPeriodCount().intValue()); - } - - List districtStats = districtStatService.findAllDistrictStatByNameWithPadding(district.getCity(), - district.getRegion(), district.getName(), district.getEstateType2(), calendar.getTime(), new Date(), - model.getPeriodType()); - if (districtStats.size() > model.getPeriodCount()) { - districtStats = districtStats.subList(districtStats.size() - model.getPeriodCount(), districtStats.size()); - } - List> result = new ArrayList>(model.getPeriodCount()); - for (DistrictStat districtStat : districtStats) { - Map item = new LinkedHashMap(); - item.put("city", districtStat.getCity()); - item.put("district", districtStat.getRegion()); - item.put("name", districtStat.getDistrictName()); - item.put("avgPrice", districtStat.getAvgPrice()); - if ("monthly".equals(model.getPeriodType())) { - item.put("date", DateUtil.formatByPattern(districtStat.getWeekend(), "yyyy-MM")); - } else { - item.put("date", DateUtil.formatByPattern(districtStat.getWeekend(), "yyyy-MM-dd")); - } - item.put("changePercent", districtStat.getMarkup() / 100d); - result.add(item); - } - mav.setModel(BasicModel.buildOKModel().setResult(result)); - return mav; - } - - /** - * 小区租金查询接口 - * - * @param model - * @return - */ - public Object rentAction(AvgPriceQueryModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); - return mav; - } - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (null == district) { - mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); - return mav; - } - if (model.getPeriodCount() == null) { - model.setPeriodCount(1); - } - if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) { - mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]")); - return mav; - } - if (model.getHouseType() == null || model.getHouseType() < 1) { - mav.setModel(BasicModel.buildBadRequestModel("房屋类型不合法")); - return mav; - } - String estateType2 = "小区"; - if (district.getEstateType2().contains("别墅")) { - estateType2 = "别墅"; - } - List rents = districtStatRentService.findAllByDistrictKeyAndHouseType( - new DistrictKey(district), model.getHouseType(), estateType2, model.getPeriodCount()); - if (rents.isEmpty() && estateType2.equals("别墅")) { - estateType2 = "小区"; - rents = districtStatRentService.findAllByDistrictKeyAndHouseType(new DistrictKey(district), - model.getHouseType(), estateType2, model.getPeriodCount()); - } - List> result = new ArrayList>(model.getPeriodCount()); - for (DistrictStatRent districtStat : rents) { - Map item = new LinkedHashMap(); - item.put("city", districtStat.getCity()); - item.put("district", districtStat.getRegion()); - item.put("name", districtStat.getDistrictName()); - item.put("rent", districtStat.getAvgPrice()); - item.put("date", DateUtil.formatByPattern(districtStat.getEndMonthDate(), "yyyy-MM")); - item.put("houseType", districtStat.getHouseType()); - item.put("changePercent", districtStat.getMarkup() / 100d); - result.add(item); - } - mav.setModel(BasicModel.buildOKModel().setResult(result)); - return mav; - } - - public Object rankAction(final DealPriceModel model) { - - RestfulModelAndView mav = new RestfulModelAndView(); - model.setCity(RegionData.formatCity(model.getCity())); - if (StringUtils.isBlank(model.getCity())) { - mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); - return mav; - } - model.setDistrict(RegionData.formatRegion(model.getCity(), model.getDistrict())); - if (StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getName())) { - mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); - return mav; - } - DistrictAnalyData districtAnalyData = districtAnalyDataService - .findByDistrictKey(new DistrictKey(model.getCity(), model.getDistrict(), model.getName())); - if (null != districtAnalyData && StringUtils.isNotBlank(districtAnalyData.getRank())) { - String[] rankDesc = districtAnalyData.getRank().split("/"); - int rank = Integer.valueOf(rankDesc[0]); - int total = Integer.valueOf(rankDesc[1]); - UniversalDto dto = new UniversalDto(); - dto.append("relativeRank", DataUtil.roundDouble(((total - rank) / (double) total) * 100, 2)); - - if(null != districtAnalyData.getRegionRank()){ - dto.append("regionRelativeRank", DataUtil.roundDouble(((districtAnalyData.getRegionRankTotal() - districtAnalyData.getRegionRank()) / (double) districtAnalyData.getRegionRankTotal()) * 100, 2)); - } - mav.setModel(BasicModel.buildOKModel().setResult(dto)); - } else { - mav.setModel(BasicModel.buildOKModel().setMsg("暂无该小区排名信息")); - } - return mav; - - } - - - - /** - * 小区成交记录查询 - * - * @param model - * @return - */ - public Object dealAction(final DealPriceModel model) { - - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity())) { - mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getName())) { - mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); - return mav; - } - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - - if (model.getMax() == null || model.getMax() < 1) { - model.setMax(DEFAULT_PAGE_SIZE); - } else if (model.getMax() > 100) { - model.setMax(100); - } - - Set districtNames = new HashSet(); - if (null == district) { - districtNames.add(model.getName()); - } else { - districtNames.add(district.getName()); - if (district.getAlias() != null) { - districtNames.addAll(district.getAlias()); - } - final String masterDistrictName = district.getMasterDistrictName(); - if (StringUtils.isNotBlank(masterDistrictName)) { - List districts; - if ("master".equals(masterDistrictName)) { - // 所有的分期数据 - districts = districtService.findSlaves(model.getCity(), model.getDistrict(), model.getName()); - } else { - // 根据主小区名查询所有名称 - districts = districtService.findSlaves(model.getCity(), model.getDistrict(), masterDistrictName); - } - if (CollectionUtils.isNotEmpty(districts)) { - for (District districtTemp : districts) { - districtNames.add(districtTemp.getName()); - } - } - - // districtNames 不包含 主小区名,加进去 - if (!districtNames.contains(masterDistrictName)){ - districtNames.add(masterDistrictName); - } - - } - } - // 将搜房中的别名与名称加入查询集合 - try { - List aliasFangs = aliasFangService.findFangByNameAndAlias(model.getCity(), model.getDistrict(), districtNames); - Set aliasSet = new HashSet(); - for (AliasFang aliasFang : aliasFangs) { - if (StringUtils.isNotBlank(aliasFang.getName())) { - aliasSet.add(aliasFang.getName()); - } - if (StringUtils.isNotBlank(aliasFang.getAlias())) { - aliasSet.add(aliasFang.getAlias()); - } - } - districtNames.addAll(aliasSet); - } catch (Exception ex) { - ex.printStackTrace(); - } + Integer finishYear = districtService.getCreateYear(district); + if (finishYear != null) { + districtInfoDto.setFinishYear(finishYear); + } + + mav.setModel(BasicModel.buildOKModel().setResult(districtInfoDto)); + return mav; + } + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + + + public Object detail2Action(PropertySearchModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getId()) + && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) + || StringUtils.isBlank(model.getName())) + && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) + || StringUtils.isBlank(model.getAddress()))) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:请输入正确的参数组合")); + return mav; + } + + District district = null; + if (StringUtils.isNotBlank(model.getId())) { + if (ObjectId.isValid(model.getId())) { + district = districtService.findById(model.getId()); + } else { + mav.setModel(BasicModel.buildBadRequestModel("非法的住宅ID")); + return mav; + } + } + + if (district == null && StringUtils.isNotBlank(model.getCity()) && StringUtils.isNotBlank(model.getDistrict()) + && StringUtils.isNotBlank(model.getName())) { + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district != null) { + district = districtService.findById(district.getId()); + } + } + + if (district == null && StringUtils.isNotBlank(model.getCity()) && StringUtils.isNotBlank(model.getDistrict()) + && StringUtils.isNotBlank(model.getAddress())) { + Map result = addressParser.parse2(model.getCity(), model.getAddress(), "district", false); + saveAddressMatchLog(result, model.getAddress(), model.getCity(), model.getToken()); + Integer status = (Integer) result.get("status"); + Integer precise = (Integer) result.get("precise"); + if (status != null && status == 0 && precise == 0) { + String id = (String) result.get("id"); + district = districtService.findById(id); + } + } + + if (district != null) { + fieldFilterService.filterWithProcessNUll(district); + DistrictInfoDto districtInfoDto = new DistrictInfoDto(); + districtInfoDto.setId(district.getId()); + districtInfoDto.setCity(district.getCity()); + districtInfoDto.setDistrict(district.getRegion()); + districtInfoDto.setName(district.getName()); + districtInfoDto.setAlias(district.getMappingAlias()); + districtInfoDto.setAddress(district.getAddress()); + districtInfoDto.setAddressAlias(district.getAddrAlias()); + if (district.getLat2() != null && district.getLat2() != 0 && district.getLng2() != null + && district.getLng2() != 0) { + districtInfoDto.setLat2(district.getLat2() / 10000000000D); + districtInfoDto.setLng2(district.getLng2() / 10000000000D); + } + if (district.getLat() != null && district.getLat() != 0 && district.getLng() != null + && district.getLng() != 0) { + districtInfoDto.setLat(district.getLat() / 10000000000D); + districtInfoDto.setLng(district.getLng() / 10000000000D); + } + districtInfoDto.setPropertyType(district.getEstateType2()); + if (HouseValidator.validateBuildingType(district.getBuildType())) { + districtInfoDto.setBuildingType(district.getBuildType()); + } else { + districtInfoDto.setBuildingType(""); + } + districtInfoDto.setBlock(district.getBlock()); + districtInfoDto.setTownship(district.getTownship()); + if (district.getLoudongCount() != null && district.getLoudongCount() > 0) { + districtInfoDto.setBuildingCount(district.getLoudongCount()); + } + + if (district.getHouseholdCount() != null) { + districtInfoDto.setTotalUnitCount(SeaweedUtils.formatHouseholdCount(district.getHouseholdCount().toString())); + } else { + districtInfoDto.setTotalUnitCount(""); + } + districtInfoDto.setManagementFee(district.getEstateCharge()); + if (district.getCarSiteCount() != null) { + districtInfoDto.setParking(SeaweedUtils.formatCarSiteCount(district.getCarSiteCount().toString())); + } else { + districtInfoDto.setParking(""); + } + districtInfoDto.setOwnershipPeriod(district.getPropertyLife()); + districtInfoDto.setOwnershipType(district.getHouseProperty()); + districtInfoDto.setBuildingStructure(district.getBuildStructure()); + districtInfoDto.setLandProperty(district.getLandProperty()); + districtInfoDto.setFloorSpace(SeaweedUtils.formatAllArea(district.getAllArea())); + districtInfoDto.setConstructionSpace(district.getBuildArea()); + districtInfoDto.setPlotRatio(SeaweedUtils.formatCubagePercent(district.getCubagePercent())); + districtInfoDto.setGreenPercentage(SeaweedUtils.formatVirescencePercent(district.getVirescencePercent())); + districtInfoDto.setDeveloper(district.getDeveloper()); + districtInfoDto.setPropertyManagement(district.getEstateCompany()); + + Integer finishYear = districtService.getCreateYear(district); + if (finishYear != null) { + districtInfoDto.setFinishYear(finishYear); + } + + mav.setModel(BasicModel.buildOKModel().setResult(districtInfoDto)); + return mav; + } + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + + private void saveAddressMatchLog(Map resMap, String keywords, String city, String token) { + Map tokenMap = FangjiaApiUtil.parseToken(token); + String userName = null; + // token验证后,拿取出的字段再去数据库验证一遍 + if (tokenMap != null && StringUtils.isNotBlank(tokenMap.get("userid")) + && !"null".equals(tokenMap.get("userid"))) { + User user = userService.findById(Long.parseLong(tokenMap.get("userid"))); + if (user != null) { + userName = user.getUserName(); + } + } + // 记录用户搜索词open匹配结果 + HttpServletRequest request = ActionContext.getContext().getRequest(); + AddressMatchLog addressMatchLog = new AddressMatchLog(); + addressMatchLog.setCity(city); + addressMatchLog.setInput(keywords); + addressMatchLog.setIp(AnalyticsUtil.getIpAddress(request)); + addressMatchLog.setSource("API"); + addressMatchLog.setUserName(userName); + addressMatchLog.setCreationDate(new Date()); + addressMatchLog.setModificationDate(new Date()); + if (MapUtils.isNotEmpty(resMap)) { + if (resMap.containsKey("status") && (Integer) resMap.get("status") == 0) { + List> result = new ArrayList>(); + Map map = new HashMap(); + map.put("city", (String) resMap.get("city")); + map.put("region", (String) resMap.get("region")); + map.put("name", (String) resMap.get("name")); + result.add(map); + addressMatchLog.setResult(result); + } else { + addressMatchLog.setStatus(1); + } + } else { + addressMatchLog.setStatus(1); + } + addressMatchLogService.addAddressMatchLog(addressMatchLog); + } + + @Authority(role = Role.NONE) + public Object sampleEvaluateAction(PropertyEvaluationModel model, HttpServletRequest request) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); + return mav; + } + if (model.getCity().endsWith("市")) { + model.setCity(model.getCity().replaceAll("市$", "")); + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + model.setName(district.getName()); + + if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { + mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); + return mav; + } + if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); + return mav; + } + + if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); + return mav; + } + if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { + mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); + return mav; + } + + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + EvaluationBo evaluationBo = evaluationService.doApply(buildEvaluation(model, request), true, false, true); + if (evaluationBo != null && evaluationBo.getSampleModeValue() > 0) { + UniversalDto dto = UniversalDto.newDto(); + dto.put("city", district.getCity()); + dto.put("district", district.getRegion()); + dto.put("name", district.getName()); + dto.put("totalPrice", evaluationBo.getSampleModeValue()); + dto.put("avgPrice", evaluationBo.getSampleModeValue() / model.getSize()); + mav.setModel(BasicModel.buildOKModel().setResult(dto)); + return mav; + } + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); + return mav; + } + + public Object evaluateAction(PropertyEvaluationModel model, HttpServletRequest request) + throws NumberFormatException, IllegalAccessException { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); + return mav; + } + if (model.getCity().endsWith("市")) { + model.setCity(model.getCity().replaceAll("市$", "")); + } + if (StringUtils.isNotBlank(request.getParameter("calDate"))) { + Date calDate = null; + try { + calDate = DateUtils.parseDate(request.getParameter("calDate"), new String[]{"yyyy-MM-dd"}); + } catch (ParseException e) { + + } + if (calDate == null) { + mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); + return mav; + } else { + model.setCalDate(calDate); + } + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + if (model.getDistrict().contains("市辖区") || model.getDistrict().contains(model.getCity())) { + district = districtService.findByNameAndAlias(model.getCity(), null, model.getName(), "district"); + } + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + } + model.setName(district.getName()); + + if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { + mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); + return mav; + } + if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); + return mav; + } + + if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); + return mav; + } + if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { + mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); + return mav; + } + + if (model.getFloor() == null) { + JSONObject structureOb = addressMatchProxyService.addressStructure(district.getCity(), model.getAddress()); + if (structureOb != null) { + if (structureOb.containsKey("buildingNumber")) { + model.setBuildingNumber(structureOb.getString("buildingNumber")); + } + + if (structureOb.containsKey("roomNumber")) { + String roomNumber = structureOb.getString("roomNumber"); + model.setFloor(getFloor(roomNumber)); + } + + } + } + + if (model.getMaxFloor() == null && model.getFloor() != null && StringUtils.isNotBlank(model.getBuildingNumber())) { + Loudong loudong = loudongService.findForEvaluate(district.getId(), model.getBuildingNumber(), model.getUnitNumber()); + if (loudong != null && loudong.getFloors() >= model.getFloor()) { + model.setMaxFloor(loudong.getFloors()); + } + } + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + + if (model.getCalDate() != null) { + if (new Date().before(model.getCalDate())) { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); + } + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } + + + Evaluation evaluation = evaluationService.evaluate(district, buildEvaluation(model, request), + model.getCalDate()); + Double cityPriceCredit = null; + if (StringUtils.isNotBlank(evaluation.getFromUserId())) { + try { + ApiUserAuthority apiUserAuthority = apiUserAuthorityService + .findByUserId(Long.valueOf(evaluation.getFromUserId())); + if (apiUserAuthority.getCityCreditMap() != null + && apiUserAuthority.getCityCreditMap().containsKey(evaluation.getCity())) { + cityPriceCredit = apiUserAuthority.getCityCreditMap().get(evaluation.getCity()); + if (cityPriceCredit > 1 || cityPriceCredit < 0) { + cityPriceCredit = null; + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + this.adjustPriceByRatio(district, evaluation); + } + + // 调整面积不同面积价格 + try { + DistrictStatBo districtStatBo = districtStatService.findDistrictStat(new DistrictKey(district)); + int orgAvgPrice = 0; + if (districtStatBo != null) { + if (StringUtils.isNotBlank(district.getEstateType2()) && district.getEstateType2().contains("别墅") && districtStatBo.getVillaDistrictStat() != null) { + orgAvgPrice = districtStatBo.getVillaDistrictStat().getAvgPrice(); + } else if (districtStatBo.getDistrictStat() != null) { + orgAvgPrice = districtStatBo.getDistrictStat().getAvgPrice(); + } + } + if (evaluation != null && evaluation.getAvgPrice() != null && evaluation.getAvgPrice() > 0) { + int factorPrice = evaluation.getAvgPrice(); + int avgPrice = evaluateFactorService.recompose(district.getCity(), district.getRegion(), evaluation.getArea(), factorPrice, orgAvgPrice); + Integer minPrice = (int) (evaluation.getAvgPrice() * 0.95); + Integer maxPrice = (int) (evaluation.getAvgPrice() * 1.05); + // 偏离度超过5%不进行调整 + if (minPrice <= avgPrice && avgPrice <= maxPrice) { + evaluation.setAvgPrice(avgPrice); + evaluation.setBigTotalPrice((long) (avgPrice * evaluation.getArea())); + } + } + } catch (Exception ex) { + LOGGER.error("调整面积不同面积价格异常{}", ex.getMessage()); + } + + if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0 + && (cityPriceCredit == null || evaluation.getCredit() >= cityPriceCredit)) { + Map districtPriceMap = new HashMap(); + districtPriceMap.put("city", district.getCity()); + districtPriceMap.put("district", district.getRegion()); + districtPriceMap.put("name", district.getName()); + districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); + districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); + + // 根据城市等 级设置D级可信度 + ApiUserAuthority apiUserAuthority = apiUserAuthorityService + .findByUserId(Long.valueOf(evaluation.getFromUserId())); + if (apiUserAuthority != null && null != apiUserAuthority.getCreditLevelStatus() + && apiUserAuthority.getCreditLevelStatus() == 1) { + double dCredit = 0.61; + if (null != apiUserAuthority.getPriceRatingMap()) { + ServerArea serverArea = serverAreaService.findByDisplay(evaluation.getCity()); + Map rateMap = apiUserAuthority.getPriceRatingMap(); + if (null != rateMap) { + dCredit = rateMap.get(CITYLEVEL_MAP.get(serverArea.getNewCityGrade().toString())); + } + } + Map rMap = getLastEvaluationPrice(district, evaluation, dCredit); + + if (model.getScope() == EVALUATE_SHOW_DETAIL) { + if (null != rMap) { + if (rMap.containsKey("level")) { + districtPriceMap.put("level", rMap.get("level")); + } + if (rMap.containsKey("other_price")) { + districtPriceMap.put("other_price", rMap.get("other_price")); + } + } + } + + Long lastPrice = (Long) rMap.get("lastPrice"); + + if (null != lastPrice) { + districtPriceMap.put("totalPrice", lastPrice); + if (lastPrice > 0 && lastPrice != evaluation.getBigTotalPrice()) { + districtPriceMap.put("avgPrice", (int) (lastPrice / evaluation.getArea())); + } + } else { + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); + return mav; + } + + } else { + districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); + } + + if (model.getScope() == EVALUATE_SHOW_DETAIL) { + districtPriceMap.put("evaluateWay", evaluation.getEvaluateWay()); + districtPriceMap.put("credit", evaluation.getCredit()); + districtPriceMap.put("id", evaluation.getId()); + } + mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); + try { + if (StringUtils.isNotBlank(evaluation.getFromUserId()) && !evaluation.getFromUserId().equals("1007497")) { + openApiLogService.saveLog(CommonUtils.convertToMap(model), districtPriceMap, evaluation, "/property/evaluate"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return mav; + } else { + evaluationService.remove(evaluation.getId()); + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); + return mav; + } + } + + /** + * 系数下调 + * + * @param district + * @param evaluation + */ + private void adjustPriceByRatio(District district, Evaluation evaluation) { + + try { + ApiUserCfg apiUserCfg_pt = apiUserCfgService.findByUserId(Long.valueOf(evaluation.getFromUserId()), ApiUserCfg.ApiUserCfgKey.PRICE_TYPE); + if (apiUserCfg_pt != null && apiUserCfg_pt.getCfgValue() != null) { + String priceType = apiUserCfg_pt.getCfgValue().toString(); + // 评估价则系数调整 + if (StringUtils.isNotBlank(priceType) && "evaluate".equals(priceType)) { + EvaluateRatio evaluateRatio = null; + if (StringUtils.isNotBlank(district.getRegion())) { + evaluateRatio = evaluateRatioService.findByCityAndRegion(district.getCity(), district.getRegion()); + } + if (evaluateRatio == null) { + evaluateRatio = evaluateRatioService.findByCity(district.getCity()); + } + if (evaluateRatio != null) { + // 系数添加 + long totalPrice = evaluation.getBigTotalPrice(); + totalPrice = (long) (totalPrice * (1 + evaluateRatio.getRatio())); + evaluation.setBigTotalPrice(totalPrice); + evaluation.setAvgPrice((int) (totalPrice / evaluation.getArea())); + } + } + } + } catch (Exception ex) { + LOGGER.error("系数下调异常{}", ex.getMessage()); + } + } + + static final Map CITY_CORRECTION_FACTOR = new HashMap(); + + static { + CITY_CORRECTION_FACTOR.put("上海", 0.02); + CITY_CORRECTION_FACTOR.put("杭州", 0.1); + CITY_CORRECTION_FACTOR.put("大连", 0.09); + CITY_CORRECTION_FACTOR.put("广州", 0.09); + CITY_CORRECTION_FACTOR.put("深圳", 0.02); + CITY_CORRECTION_FACTOR.put("重庆", 0.1); + CITY_CORRECTION_FACTOR.put("苏州", 0.08); + CITY_CORRECTION_FACTOR.put("成都", 0.07); + CITY_CORRECTION_FACTOR.put("北京", 0.04); + CITY_CORRECTION_FACTOR.put("厦门", 0.1); + } + + public Object evaluateForTestAction(PropertyEvaluationModel model, HttpServletRequest request) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("城市为必填项")); + return mav; + } + if (model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("面积为必填项")); + return mav; + } + if (StringUtils.isBlank(model.getAddress()) && StringUtils.isBlank(model.getName())) { + mav.setModel(BasicModel.buildBadRequestModel("地址和小区名至少填一个")); + return mav; + } + if (StringUtils.isNotBlank(model.getName()) && StringUtils.isBlank(model.getAddress())) { + model.setAddress(model.getName()); + } + if (StringUtils.isNotBlank(request.getParameter("calDate"))) { + Date calDate = DateUtil.parseDate(request.getParameter("calDate"), "yyyy-MM-dd"); + model.setCalDate(calDate); + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findDistrict(new DistrictKey(model.getCity(), model.getDistrict(), model.getName()), "district");//matchDistrict(model.getCity(), model.getAddress(), model.getDistrict(), model.getName()); + if (district == null) { + //防止地址模糊,名称详细的情况 + district = matchDistrict(model.getCity(), model.getName(), model.getDistrict(), model.getAddress()); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + } + model.setName(district.getName()); + if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { + mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); + return mav; + } + if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); + return mav; + } + + if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); + return mav; + } + if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { + mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); + return mav; + } + + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + + if (model.getCalDate() != null) { + if (new Date().before(model.getCalDate())) { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); + } + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } + Evaluation evaluation = evaluationService.evaluate(district, buildEvaluation(model, request), model.getCalDate()); + if (!"self".equalsIgnoreCase(evaluation.getEvaluateWay())) { + evaluationService.remove(evaluation.getId()); + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); + return mav; + } + + this.adjustPriceByRatio(district, evaluation); + + // 调整面积不同面积价格 + try { + DistrictStatBo districtStatBo = districtStatService.findDistrictStat(new DistrictKey(district)); + int orgAvgPrice = 0; + if (districtStatBo != null) { + if (StringUtils.isNotBlank(district.getEstateType2()) && district.getEstateType2().contains("别墅") && districtStatBo.getVillaDistrictStat() != null) { + orgAvgPrice = districtStatBo.getVillaDistrictStat().getAvgPrice(); + } else if (districtStatBo.getDistrictStat() != null) { + orgAvgPrice = districtStatBo.getDistrictStat().getAvgPrice(); + } + } + if (evaluation != null && evaluation.getAvgPrice() != null && evaluation.getAvgPrice() > 0) { + int factorPrice = evaluation.getAvgPrice(); + int avgPrice = evaluateFactorService.recompose(district.getCity(), district.getRegion(), evaluation.getArea(), factorPrice, orgAvgPrice); + Integer minPrice = (int) (evaluation.getAvgPrice() * 0.95); + Integer maxPrice = (int) (evaluation.getAvgPrice() * 1.05); + // 偏离度超过5%不进行调整 + if (minPrice <= avgPrice && avgPrice <= maxPrice) { + evaluation.setAvgPrice(avgPrice); + evaluation.setBigTotalPrice((long) (avgPrice * evaluation.getArea())); + } + } + } catch (Exception ex) { + + } + Map districtPriceMap = new LinkedHashMap(); + districtPriceMap.put("city", district.getCity()); + districtPriceMap.put("district", district.getRegion()); + districtPriceMap.put("name", district.getName()); + + districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); + districtPriceMap.put("unitPrice", evaluation.getAvgPrice()); + // 新增置信度 + CommunityBasePrice communityBasePrice = communityBasePriceService.getById(district.getId()); + if (communityBasePrice != null) { + districtPriceMap.put("credit", communityBasePrice.getCredit()); + } else { + districtPriceMap.put("credit", evaluation.getCredit()); + } + List names = new ArrayList(); + names.add(district.getName()); + if (district.getAlias() != null) { + for (String alia : district.getAlias()) { + if (StringUtils.isNotBlank(alia) && !names.contains(alia)) { + names.add(alia); + } + } + } + Integer minPrice = (int) (evaluation.getAvgPrice() * 0.8); + Integer maxPrice = (int) (evaluation.getAvgPrice() * 1.2); + Integer min10Price = (int) (evaluation.getAvgPrice() * 0.9); + Integer max10Price = (int) (evaluation.getAvgPrice() * 1.1); + // 新增第三方均价 + try { + double dCredit = 0.61; + Map rMap = getLastEvaluationPrice(district, evaluation, dCredit); + if (null != rMap) { + if (rMap.containsKey("other_price")) { + Map otherPriceMap = (Map) rMap.get("other_price"); + Map priceResultMap = new HashMap(); + for (String key : otherPriceMap.keySet()) { + Integer price = otherPriceMap.get(key); + // 剔除偏差大于10的 + if (min10Price <= price && max10Price >= price) { + if (OTHER_PRICE_MAP.containsKey(key)) { + priceResultMap.put(OTHER_PRICE_MAP.get(key), price); + } + } + } + districtPriceMap.put("otherPrice", priceResultMap); + } + } + } catch (Exception ex) { + + } + List houses = seawaterDao.findHouses(district.getCity(), district.getRegion(), names, minPrice, maxPrice, 20); + if (houses.size() > 3) { + districtPriceMap.put("calcType", 1); + List houseDtos = new ArrayList(); + for (Seawater seawater : houses) { + UniversalDto houseDto = new UniversalDto(); + houseDto.append("city", seawater.getCity()); + houseDto.append("district", seawater.getRegion()); + houseDto.append("name", seawater.getDistrictName()); + houseDto.append("title", seawater.getName()); + houseDto.append("size", seawater.getArea()); + houseDto.append("unitPrice", seawater.getAvgPrice()); + houseDto.append("totalPrice", seawater.getTotalPrice()); + houseDto.append("room", seawater.getRoom()); + houseDto.append("hall", seawater.getHall()); + houseDto.append("toilet", seawater.getToilet()); + houseDto.append("direction", HouseValidator.fetchDirectionInfo(seawater.getDirection())); + houseDto.append("decoration", HouseValidator.fetchFitmentInfo(seawater.getFitment())); + houseDto.append("publishDate", seawater.getpDate()); + if (seawater.getHeight() != null && seawater.getHeight() > 0) { + houseDto.append("maxFloor", seawater.getHeight()); + } + houseDtos.add(houseDto); + } + districtPriceMap.put("houses", houseDtos); + } else if (district.getLng() != null && district.getLng() > 0) { + double lng = DataUtil.roundDouble(district.getLng() / 10000000000.0, 6); + double lat = DataUtil.roundDouble(district.getLat() / 10000000000.0, 6); + List districts = districtService.findNearestDistrict(district.getEstateType2(), lng, lat, 1000 * 3, 6, null); + if (districts.size() < 2) { + evaluationService.remove(evaluation.getId()); + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); + return mav; + } + UniversalDto modelFeaturesFto = UniversalDto.newDto(); + districtPriceMap.put("calcType", 2); + modelFeaturesFto.append("propertyType", district.getEstateType2()); + modelFeaturesFto.append("lng", lng); + modelFeaturesFto.append("lat", lat); + DistrictAnalyData districtAnalyData = districtAnalyDataService.findByDistrictKey(new DistrictKey(district)); + if (districtAnalyData != null && districtAnalyData.getHalfYearMarkup() != null) { + modelFeaturesFto.append("halfYearMarkup", DataUtil.roundDouble(districtAnalyData.getHalfYearMarkup() * 100, 2)); + } + RegionAnaData regionAnaData = regionAnaDataService.findRegionAnaData(district.getCity(), district.getRegion()); + if (regionAnaData != null) { + modelFeaturesFto.append("region20PercentPrice", regionAnaData.getRegion20PercentPrice()); + modelFeaturesFto.append("region80PercentPrice", regionAnaData.getRegion80PercentPrice()); + } + List nearCommunityDtos = new ArrayList(); + for (District d : districts) { + if (d.getId().equals(district.getId())) { + continue; + } + UniversalDto districtDto = UniversalDto.newDto(); + districtDto.append("city", d.getCity()); + districtDto.append("region", d.getRegion()); + districtDto.append("name", d.getName()); + districtDto.append("lng", DataUtil.roundDouble(d.getLng() / 10000000000.0, 6)); + districtDto.append("lat", DataUtil.roundDouble(d.getLat() / 10000000000.0, 6)); + districtDto.append("distance", GeoUtils.calculateDistance(lng, lat, d.getLng() / 10000000000.0, d.getLat() / 10000000000.0)); + districtDto.append("propertyType", d.getEstateType2()); + Integer buildYear = districtService.getBuildYear(d); + if (buildYear != null) { + districtDto.append("buildYear", String.valueOf(buildYear)); + } + districtAnalyData = districtAnalyDataService.findByDistrictKey(new DistrictKey(d)); + if (districtAnalyData != null) { + if (districtAnalyData.getHalfYearMarkup() != null) { + districtDto.append("halfYearMarkup", DataUtil.roundDouble(districtAnalyData.getHalfYearMarkup() * 100, 2)); + } + if (districtAnalyData.getAvgPrice() != null && minPrice <= districtAnalyData.getAvgPrice() && maxPrice >= districtAnalyData.getAvgPrice()) { + districtDto.append("avgPrice", districtAnalyData.getAvgPrice()); + } + } + + nearCommunityDtos.add(districtDto); + } + Integer buildYear = districtService.getBuildYear(district); + if (buildYear != null) { + modelFeaturesFto.put("buildYear", String.valueOf(buildYear)); + } + modelFeaturesFto.append("nearCommunity", nearCommunityDtos); + + // 模型特征新增周边数量 + CommunityPoi communityPoi = communityPoiService.getById(district.getId()); + if (communityPoi != null) { + modelFeaturesFto.put("subway", communityPoi.getSubway()); + modelFeaturesFto.put("traffic", communityPoi.getTraffic()); + modelFeaturesFto.put("bank", communityPoi.getBank()); + modelFeaturesFto.put("primary", communityPoi.getPrimary()); + modelFeaturesFto.put("hospital", communityPoi.getHospital()); + modelFeaturesFto.put("junior", communityPoi.getJunior()); + modelFeaturesFto.put("funeral", communityPoi.getFuneral()); + } + districtPriceMap.put("modelFeatures", modelFeaturesFto); + } + mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); + return mav; + } + + /** + * 地址估值 + * + * @param model 参数 + * @param request + * @return + */ + public Object addressEvaluateAction(PropertyEvaluationModel model, HttpServletRequest request) throws IllegalAccessException { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getAddress()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,地址,面积(size)为必填项")); + return mav; + } + if (model.getDistrict() != null) { + //区域编码转房价网区域 + FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertOfficialCodeToFangjia(model.getDistrict()); + if (fangjiaOfficialAreaMap != null) { + model.setDistrict(fangjiaOfficialAreaMap.getFangjiaDistrict()); + } + } + + boolean villaFlag = DataUtil.isVilla(model.getSize(), model.getName(), model.getHeight(), model.getRoom()); + + District district = null; + Map params = new HashMap(); + params.put("city", model.getCity()); + if (StringUtils.isNotBlank(model.getDistrict())) { + params.put("suggestDistrict", model.getDistrict()); + } + params.put("address", model.getAddress()); + if (StringUtils.isNotBlank(model.getName())) { + params.put("suggestName", model.getName()); + } + params.put("category", "district"); + String result = addressMatchProxyService.parser(params); + if (result != null) { + JSONObject json = JSONObject.fromObject(result); + if (json.getInt("code") == 200) { + Map map = (Map) json.get("result"); + if ((Integer) map.get("precise") >= 0) { + String propertyType = (String) map.get("propertyType"); + if (villaFlag && StringUtils.isNotBlank(propertyType) && !propertyType.equals("别墅")) { + district = districtService.findByNameAndAlias((String) map.get("city"), (String) map.get("district"), (String) map.get("name") + "别墅", "district"); + } + if (null == district) { + district = districtService.findByNameAndAlias((String) map.get("city"), (String) map.get("district"), (String) map.get("name"), "district"); + } + + } + } + } + + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!")); + return mav; + } + model.setDistrict(district.getRegion()); + model.setName(district.getName()); + return this.evaluateAction(model, request); + } + + public Object evaluate2Action(PropertyEvaluationModel model, HttpServletRequest request) + throws NumberFormatException, IllegalAccessException { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); + return mav; + } + if (model.getCity().endsWith("市")) { + model.setCity(model.getCity().replaceAll("市$", "")); + } + if (StringUtils.isNotBlank(request.getParameter("calDate"))) { + Date calDate = null; + try { + calDate = DateUtils.parseDate(request.getParameter("calDate"), new String[]{"yyyy-MM-dd"}); + } catch (ParseException e) { + + } + if (calDate == null) { + mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); + return mav; + } else { + model.setCalDate(calDate); + } + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + model.setName(district.getName()); + + if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { + mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); + return mav; + } + if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); + return mav; + } + + if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); + return mav; + } + if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { + mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); + return mav; + } + + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + + if (model.getCalDate() != null) { + if (new Date().before(model.getCalDate())) { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); + } + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } + Evaluation evaluation = evaluationService.evaluate(district, buildEvaluation(model, request), model.getCalDate()); + Double cityPriceCredit = null; + if (StringUtils.isNotBlank(evaluation.getFromUserId())) { + try { + ApiUserAuthority apiUserAuthority = apiUserAuthorityService + .findByUserId(Long.valueOf(evaluation.getFromUserId())); + if (apiUserAuthority.getCityCreditMap() != null + && apiUserAuthority.getCityCreditMap().containsKey(evaluation.getCity())) { + cityPriceCredit = apiUserAuthority.getCityCreditMap().get(evaluation.getCity()); + if (cityPriceCredit > 1 || cityPriceCredit < 0) { + cityPriceCredit = null; + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0 + && (cityPriceCredit == null || evaluation.getCredit() >= cityPriceCredit)) { + + Map districtPriceMap = new HashMap(); + districtPriceMap.put("city", district.getCity()); + districtPriceMap.put("district", district.getRegion()); + districtPriceMap.put("name", district.getName()); + districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); + + // 根据城市等 级设置D级可信度 + ApiUserAuthority apiUserAuthority = apiUserAuthorityService + .findByUserId(Long.valueOf(evaluation.getFromUserId())); + if (apiUserAuthority != null && null != apiUserAuthority.getCreditLevelStatus() + && apiUserAuthority.getCreditLevelStatus() == 1) { + double dCredit = 0.61; + if (null != apiUserAuthority.getPriceRatingMap()) { + ServerArea serverArea = serverAreaService.findByDisplay(evaluation.getCity()); + Map rateMap = apiUserAuthority.getPriceRatingMap(); + if (null != rateMap) { + dCredit = rateMap.get(CITYLEVEL_MAP.get(serverArea.getNewCityGrade().toString())); + } + } + Map rMap = getLastEvaluationPrice(district, evaluation, dCredit); + + if (model.getScope() == EVALUATE_SHOW_DETAIL) { + if (null != rMap) { + if (rMap.containsKey("level")) { + districtPriceMap.put("level", rMap.get("level")); + } + if (rMap.containsKey("other_price")) { + districtPriceMap.put("other_price", rMap.get("other_price")); + } + } + } + + Long lastPrice = (Long) rMap.get("lastPrice"); + if (null != lastPrice) { + districtPriceMap.put("totalPrice", lastPrice); + if (lastPrice > 0 && lastPrice != evaluation.getBigTotalPrice()) { + districtPriceMap.put("avgPrice", (int) (lastPrice / evaluation.getArea())); + } + } else { + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); + return mav; + } + + } else { + districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); + } + + if (model.getScope() == EVALUATE_SHOW_DETAIL) { + districtPriceMap.put("evaluateWay", evaluation.getEvaluateWay()); + districtPriceMap.put("credit", evaluation.getCredit()); + districtPriceMap.put("id", evaluation.getId()); + } + mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); + return mav; + } else { + evaluationService.remove(evaluation.getId()); + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); + return mav; + } + } + + /** + * 四川锦程 定制接口 多建筑年代 + * + * @param model + * @param request + * @return + * @throws NumberFormatException + * @throws IllegalAccessException + */ + public Object evaluate3Action(PropertyEvaluationModel model, HttpServletRequest request) + throws NumberFormatException, IllegalAccessException { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); + return mav; + } + if (model.getCity().endsWith("市")) { + model.setCity(model.getCity().replaceAll("市$", "")); + } + if (StringUtils.isNotBlank(request.getParameter("calDate"))) { + Date calDate = null; + try { + calDate = DateUtils.parseDate(request.getParameter("calDate"), new String[]{"yyyy-MM-dd"}); + } catch (ParseException e) { + + } + if (calDate == null) { + mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); + return mav; + } else { + model.setCalDate(calDate); + } + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + model.setName(district.getName()); + + if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { + mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); + return mav; + } + if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); + return mav; + } + + if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); + return mav; + } + if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { + mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); + return mav; + } + + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + + if (model.getCalDate() != null) { + if (new Date().before(model.getCalDate())) { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); + } + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } + Evaluation evaluation = evaluationService.evaluate(district, buildEvaluation(model, request), model.getCalDate()); + Double cityPriceCredit = null; + if (StringUtils.isNotBlank(evaluation.getFromUserId())) { + try { + ApiUserAuthority apiUserAuthority = apiUserAuthorityService + .findByUserId(Long.valueOf(evaluation.getFromUserId())); + if (apiUserAuthority.getCityCreditMap() != null + && apiUserAuthority.getCityCreditMap().containsKey(evaluation.getCity())) { + cityPriceCredit = apiUserAuthority.getCityCreditMap().get(evaluation.getCity()); + if (cityPriceCredit > 1 || cityPriceCredit < 0) { + cityPriceCredit = null; + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0 + && (cityPriceCredit == null || evaluation.getCredit() >= cityPriceCredit)) { + + Map districtPriceMap = new HashMap(); + districtPriceMap.put("city", district.getCity()); + districtPriceMap.put("district", district.getRegion()); + districtPriceMap.put("name", district.getName()); + districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); + if (StringUtils.isNotBlank(district.getFinishBuildingDate())) { + Pattern pat3 = Pattern.compile("\\d{4}"); + Matcher matcher3 = pat3.matcher(district.getFinishBuildingDate()); + if (matcher3.find()) { + districtPriceMap.put("buildYear", matcher3.group()); + } + } + + + // 根据城市等 级设置D级可信度 + ApiUserAuthority apiUserAuthority = apiUserAuthorityService + .findByUserId(Long.valueOf(evaluation.getFromUserId())); + if (apiUserAuthority != null && null != apiUserAuthority.getCreditLevelStatus() + && apiUserAuthority.getCreditLevelStatus() == 1) { + double dCredit = 0.61; + if (null != apiUserAuthority.getPriceRatingMap()) { + ServerArea serverArea = serverAreaService.findByDisplay(evaluation.getCity()); + Map rateMap = apiUserAuthority.getPriceRatingMap(); + if (null != rateMap) { + dCredit = rateMap.get(CITYLEVEL_MAP.get(serverArea.getNewCityGrade().toString())); + } + } + Map rMap = getLastEvaluationPrice(district, evaluation, dCredit); + + if (model.getScope() == EVALUATE_SHOW_DETAIL) { + if (null != rMap) { + if (rMap.containsKey("level")) { + districtPriceMap.put("level", rMap.get("level")); + } + if (rMap.containsKey("other_price")) { + districtPriceMap.put("other_price", rMap.get("other_price")); + } + } + } + + Long lastPrice = (Long) rMap.get("lastPrice"); + if (null != lastPrice) { + districtPriceMap.put("totalPrice", lastPrice); + if (lastPrice > 0 && lastPrice != evaluation.getBigTotalPrice()) { + districtPriceMap.put("avgPrice", (int) (lastPrice / evaluation.getArea())); + } + } else { + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); + return mav; + } + + } else { + districtPriceMap.put("totalPrice", evaluation.getBigTotalPrice()); + } + + if (model.getScope() == EVALUATE_SHOW_DETAIL) { + districtPriceMap.put("evaluateWay", evaluation.getEvaluateWay()); + districtPriceMap.put("credit", evaluation.getCredit()); + districtPriceMap.put("id", evaluation.getId()); + } + mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); + return mav; + } else { + evaluationService.remove(evaluation.getId()); + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价").markNoData()); + return mav; + } + } + + @Authority(role = Role.USER) + public Object addBatchEvaluateTaskAction(BatchEvaluateModel model) throws IOException { + + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (model.getFile() == null || model.getFile().isEmpty()) { + mav.setModel(BasicModel.buildBadRequestModel("请上传包含待评估数据的数据文件")); + return mav; + } + MultipartFile file = model.getFile(); + + if (StringUtils.isNotBlank(model.getCharset()) && Charset.isSupported(model.getCharset())) { + mav.setModel(BasicModel.buildBadRequestModel("字符编码不支持")); + return mav; + } else { + model.setCharset("GBK"); + } + Map tokenMap = FangjiaApiUtil.parseToken(model.getToken()); + String userId = tokenMap.get("userid"); + DBObject dbFile = fileDao.save(file.getBytes(), file.getContentType()); + String fileId = (String) dbFile.get("_id"); + BatchEvaluateTask task = new BatchEvaluateTask(); + task.setDateCreated(new Date()); + task.setStatus(BatchEvaluateTask.StatusEnum.INIT.getStatus()); + task.setDataFileId(fileId); + task.setUserId(userId); + task.setFileName(file.getOriginalFilename()); + task.setCharset(model.getCharset()); + batchEvaluateService.saveBatchEvaluateTask(task); + Map data = new HashMap(); + data.put("taskId", task.getId()); + mav.setModel(BasicModel.buildOKModel().setResult(data)); + return mav; + } + + @Authority(role = Role.USER) + public Object batchEvaluateTaskStatusAction(BatchEvaluateModel model) { + + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())) { + mav.setModel(BasicModel.buildBadRequestModel("任务id非法")); + return mav; + } + Map tokenMap = FangjiaApiUtil.parseToken(model.getToken()); + String userId = tokenMap.get("userid"); + BatchEvaluateTask task = batchEvaluateService.findBatchEvaluateTaskById(model.getId()); + if (task == null || !task.getUserId().equals(userId)) { + mav.setModel(BasicModel.buildBadRequestModel("任务不存在")); + return mav; + } + Map data = new HashMap(); + data.put("status", task.getStatus()); + if (BatchEvaluateTask.StatusEnum.INIT.getStatus() == task.getStatus()) { + data.put("msg", "待处理"); + } else if (BatchEvaluateTask.StatusEnum.DOING.getStatus() == task.getStatus()) { + data.put("msg", "处理中"); + } else if (BatchEvaluateTask.StatusEnum.SUC.getStatus() == task.getStatus()) { + data.put("msg", "已完成"); + data.put("downLink", "http://open.fangjia.com/property/downEvaluateResult?id=" + task.getId() + "&token=" + + model.getToken()); + } else if (BatchEvaluateTask.StatusEnum.ERROR.getStatus() == task.getStatus()) { + data.put("msg", "处理失败"); + data.put("subMsg", task.getMsg()); + } + mav.setModel(BasicModel.buildOKModel().setResult(data)); + return mav; + } + + @Authority(role = Role.USER) + public Object downEvaluateResultAction(BatchEvaluateModel model, HttpServletResponse response) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())) { + mav.setModel(BasicModel.buildBadRequestModel("任务id非法")); + return mav; + } + Map tokenMap = FangjiaApiUtil.parseToken(model.getToken()); + + String userId = tokenMap.get("userid"); + BatchEvaluateTask task = batchEvaluateService.findBatchEvaluateTaskById(model.getId()); + if (task == null || !task.getUserId().equals(userId)) { + mav.setModel(BasicModel.buildBadRequestModel("任务不存在")); + return mav; + } + + DBObject file = fileDao.findById(task.getDataFileId()); + byte[] data = (byte[]) file.get("data"); + OutputStream os = null; + try { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/x-gzip"); + String fileName = DateUtil.formatToYYYYMMDDhhmmss(new Date()) + ".csv.gz"; + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + os = response.getOutputStream();// 取得输出流 + os.write(data); + os.flush(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (os != null) { + os.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + ModelAndViewSupport mv = new ModelAndViewSupport(); + mv.setViewType("stream"); + return mv; + } + + @Authority(role = Role.NONE) + public Object batchEvaluateTemplateAction(BatchEvaluateModel model, HttpServletResponse response, + HttpServletRequest request) { + OutputStream os = null; + FileInputStream fis = null; + try { + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/csv"); + response.setHeader("Content-Disposition", "attachment;filename=batchEvaluateTemplate.csv"); + os = response.getOutputStream();// 取得输出流 + String path = request.getSession().getServletContext().getRealPath("") + File.separator + "WEB-INF" + + File.separator + "classes" + File.separator + "batchEvaluateTemplate.csv"; + File template = new File(path); + fis = new FileInputStream(template); + byte[] data = new byte[fis.available()]; + fis.read(data); + os.write(data); + os.flush(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (os != null) { + os.close(); + } + if (fis != null) { + fis.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + ModelAndViewSupport mv = new ModelAndViewSupport(); + mv.setViewType("stream"); + return mv; + } + + public Object evaluateShopAction(PropertyEvaluationModel model, HttpServletRequest request) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); + return mav; + } + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "shop"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + model.setName(district.getName()); + if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { + mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); + return mav; + } + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + if (model.getCalDate() != null) { + model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } + Evaluation evaluation = evaluationService.evaluateWithPadding(buildEvaluation(model, request), + model.getCalDate()); + if (null != evaluation && evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0) { + Map districtPriceMap = new HashMap(); + districtPriceMap.put("city", district.getCity()); + districtPriceMap.put("district", district.getRegion()); + districtPriceMap.put("name", district.getName()); + districtPriceMap.put("totalPrice", evaluation.getTotalPrice()); + districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); + mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); + return mav; + } else { + evaluationService.remove(evaluation.getId()); + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的估价")); + return mav; + } + } + + public Object filterAction(PropertySearchModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + District district = districtService.findById(model.getId()); + fieldFilterService.refresh(); + fieldFilterService.filterWithProcessNUll(district); + mav.setModel(BasicModel.buildOKModel().setResult(district)); + return mav; + } + + public Object houseRentAction(PropertyEvaluationModel model, HttpServletRequest request) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getHouseType() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,房型(houseType)为必填项")); + return mav; + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + model.setName(district.getName()); + if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { + mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); + return mav; + } + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + List evaluations = evaluationService.histroyRent(district, buildEvaluation(model, request), 1, + model.getHouseType()); + if (evaluations.isEmpty()) { + mav.setModel(BasicModel.buildOKModel().setMsg("暂无租金")); + } else { + Evaluation evaluation = evaluations.get(0); + JSONObject item = new JSONObject(); + item.put("city", district.getCity()); + item.put("district", district.getRegion()); + item.put("name", district.getName()); + item.put("rent", evaluation.getAvgPrice()); + item.put("changePercent", evaluation.getMarkup() / 100d); + mav.setModel(BasicModel.buildOKModel().setResult(item)); + } + return mav; + } + + public Object historyRentAction(PropertyEvaluationModel model, HttpServletRequest request) { + + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getHouseType() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,房型(houseType)为必填项")); + return mav; + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + model.setName(district.getName()); + if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { + mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); + return mav; + } + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + if (model.getPeriodCount() == null) { + model.setPeriodCount(1); + } + if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) { + mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]")); + return mav; + } + + List evaluations = evaluationService.histroyRent(district, buildEvaluation(model, request), + model.getPeriodCount(), model.getHouseType()); + List historyEvaluations = new ArrayList(); + for (Evaluation evaluation : evaluations) { + if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0) { + JSONObject item = new JSONObject(); + item.put("city", district.getCity()); + item.put("district", district.getRegion()); + item.put("name", district.getName()); + item.put("rent", evaluation.getAvgPrice()); + item.put("changePercent", evaluation.getMarkup() / 100d); + item.put("date", DateUtil.formatByPattern(evaluation.getCreationDate(), "yyyy-MM")); + historyEvaluations.add(item); + } + } + if (historyEvaluations.size() > model.getPeriodCount()) { + historyEvaluations = historyEvaluations.subList(historyEvaluations.size() - model.getPeriodCount(), + historyEvaluations.size()); + } + mav.setModel(BasicModel.buildOKModel().setResult(historyEvaluations)); + return mav; + + } + + public Object historyEvaluateAction(PropertyEvaluationModel model, HttpServletRequest request) { + + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); + return mav; + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + model.setName(district.getName()); + + if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) { + mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法")); + return mav; + } + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + if (model.getPeriodCount() == null) { + model.setPeriodCount(1); + } + if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) { + mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]")); + return mav; + } + if (StringUtils.isBlank(model.getPeriodType())) { + model.setPeriodType("weekly"); + } else { + if (!"weekly".equals(model.getPeriodType()) && !"monthly".equals(model.getPeriodType())) { + mav.setModel(BasicModel.buildBadRequestModel("periodModel值非法,合法值为:weekly,monthly")); + return mav; + } + } + Calendar calendar = Calendar.getInstance(); + if ("weekly".equals(model.getPeriodType())) { + calendar.add(Calendar.DATE, -model.getPeriodCount().intValue() * 7); + } else { + calendar.add(Calendar.MONTH, -model.getPeriodCount().intValue()); + + } + List evaluations = evaluationService.histroyEvaluate(district, buildEvaluation(model, request), + calendar.getTime(), model.getPeriodType()); + List historyEvaluations = new ArrayList(); + for (Evaluation evaluation : evaluations) { + if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 0) { + JSONObject item = new JSONObject(); + item.put("city", district.getCity()); + item.put("district", district.getRegion()); + item.put("name", district.getName()); + item.put("totalPrice", evaluation.getBigTotalPrice()); + item.put("avgPrice", evaluation.getAvgPrice()); + item.put("changePercent", evaluation.getMarkup() / 100d); + if ("weekly".equals(model.getPeriodType())) { + item.put("date", DateUtil.formatByPattern(evaluation.getCreationDate(), "yyyy-MM-dd")); + } else { + item.put("date", DateUtil.formatByPattern(evaluation.getCreationDate(), "yyyy-MM")); + } + historyEvaluations.add(item); + } + } + if (historyEvaluations.size() > model.getPeriodCount()) { + historyEvaluations = historyEvaluations.subList(historyEvaluations.size() - model.getPeriodCount(), + historyEvaluations.size()); + } + mav.setModel(BasicModel.buildOKModel().setResult(historyEvaluations)); + return mav; + } + + public Object avgPriceAction(AvgPriceQueryModel model) { + + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); + return mav; + } + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (null == district) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + if (model.getPeriodCount() == null) { + model.setPeriodCount(1); + } + if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) { + mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]")); + return mav; + } + if (StringUtils.isBlank(model.getPeriodType())) { + model.setPeriodType("weekly"); + } else { + if (!"weekly".equals(model.getPeriodType()) && !"monthly".equals(model.getPeriodType())) { + mav.setModel(BasicModel.buildBadRequestModel("periodModel值非法,合法值为:weekly,monthly")); + return mav; + } + } + Calendar calendar = Calendar.getInstance(); + if ("weekly".equals(model.getPeriodType())) { + calendar.add(Calendar.DATE, -model.getPeriodCount().intValue() * 7); + } else { + calendar.add(Calendar.MONTH, -model.getPeriodCount().intValue()); + } + + List districtStats = districtStatService.findAllDistrictStatByNameWithPadding(district.getCity(), + district.getRegion(), district.getName(), district.getEstateType2(), calendar.getTime(), new Date(), + model.getPeriodType()); + if (districtStats.size() > model.getPeriodCount()) { + districtStats = districtStats.subList(districtStats.size() - model.getPeriodCount(), districtStats.size()); + } + List> result = new ArrayList>(model.getPeriodCount()); + for (DistrictStat districtStat : districtStats) { + Map item = new LinkedHashMap(); + item.put("city", districtStat.getCity()); + item.put("district", districtStat.getRegion()); + item.put("name", districtStat.getDistrictName()); + item.put("avgPrice", districtStat.getAvgPrice()); + if ("monthly".equals(model.getPeriodType())) { + item.put("date", DateUtil.formatByPattern(districtStat.getWeekend(), "yyyy-MM")); + } else { + item.put("date", DateUtil.formatByPattern(districtStat.getWeekend(), "yyyy-MM-dd")); + } + item.put("changePercent", districtStat.getMarkup() / 100d); + result.add(item); + } + mav.setModel(BasicModel.buildOKModel().setResult(result)); + return mav; + } + + /** + * 小区租金查询接口 + * + * @param model + * @return + */ + public Object rentAction(AvgPriceQueryModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); + return mav; + } + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (null == district) { + mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); + return mav; + } + if (model.getPeriodCount() == null) { + model.setPeriodCount(1); + } + if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) { + mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]")); + return mav; + } + if (model.getHouseType() == null || model.getHouseType() < 1) { + mav.setModel(BasicModel.buildBadRequestModel("房屋类型不合法")); + return mav; + } + String estateType2 = "小区"; + if (district.getEstateType2().contains("别墅")) { + estateType2 = "别墅"; + } + List rents = districtStatRentService.findAllByDistrictKeyAndHouseType( + new DistrictKey(district), model.getHouseType(), estateType2, model.getPeriodCount()); + if (rents.isEmpty() && estateType2.equals("别墅")) { + estateType2 = "小区"; + rents = districtStatRentService.findAllByDistrictKeyAndHouseType(new DistrictKey(district), + model.getHouseType(), estateType2, model.getPeriodCount()); + } + List> result = new ArrayList>(model.getPeriodCount()); + for (DistrictStatRent districtStat : rents) { + Map item = new LinkedHashMap(); + item.put("city", districtStat.getCity()); + item.put("district", districtStat.getRegion()); + item.put("name", districtStat.getDistrictName()); + item.put("rent", districtStat.getAvgPrice()); + item.put("date", DateUtil.formatByPattern(districtStat.getEndMonthDate(), "yyyy-MM")); + item.put("houseType", districtStat.getHouseType()); + item.put("changePercent", districtStat.getMarkup() / 100d); + result.add(item); + } + mav.setModel(BasicModel.buildOKModel().setResult(result)); + return mav; + } + + /** + * 平米租金 + * cat 表示租金类型 + * city:城市 , region : 区域 ,district :小区 + * + * @param model + * @return + */ + + public Object sqmeterRentAction(AvgPriceQueryModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCat())) { + mav.setModel(BasicModel.buildBadRequestModel("参数缺失:cat(租金类型)是必须参数")); + return mav; + } + if ("city".equals(model.getCity()) && StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("城市平米租金,city(城市)是必须参数")); + return mav; + } + if ("region".equals(model.getCity()) && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()))) { + mav.setModel(BasicModel.buildBadRequestModel("区域平米租金,city(城市),district(区域)是必须参数")); + return mav; + } + if ("district".equals(model.getCity()) && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) || StringUtils.isBlank(model.getName()))) { + mav.setModel(BasicModel.buildBadRequestModel("小区平米租金,city(城市),district(区域),name(小区名)是必须参数")); + return mav; + } + if ("district".equals(model.getCat())) { + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (null == district) { + mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); + return mav; + } + } + if (model.getPeriodCount() == null) { + model.setPeriodCount(1); + } + if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) { + mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]")); + return mav; + } + Date startDate = DateUtil.add(new Date(), Calendar.MONTH, -model.getPeriodCount()); + + List sqmetreRents = sqmetreRentService.findSqmetreRents(model.getCity(), model.getDistrict(), model.getName(), model.getCat(), startDate, null); + List> result = new ArrayList>(model.getPeriodCount()); + + for (SqmetreRent sqmetreRent : sqmetreRents) { + Map item = new LinkedHashMap(); + item.put("city", sqmetreRent.getCity()); + item.put("district", sqmetreRent.getRegion()); + item.put("name", sqmetreRent.getDistrictName()); + item.put("rent", sqmetreRent.getAvgPrice().intValue()); + item.put("date", DateUtil.formatByPattern(sqmetreRent.getWeekend(), "yyyy-MM")); + result.add(item); + } + mav.setModel(BasicModel.buildOKModel().setResult(result)); + return mav; + } + + public Object rankAction(final DealPriceModel model) { + + RestfulModelAndView mav = new RestfulModelAndView(); + model.setCity(RegionData.formatCity(model.getCity())); + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); + return mav; + } + model.setDistrict(RegionData.formatRegion(model.getCity(), model.getDistrict())); + if (StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getName())) { + mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); + return mav; + } + DistrictAnalyData districtAnalyData = districtAnalyDataService + .findByDistrictKey(new DistrictKey(model.getCity(), model.getDistrict(), model.getName())); + if (null != districtAnalyData && StringUtils.isNotBlank(districtAnalyData.getRank())) { + String[] rankDesc = districtAnalyData.getRank().split("/"); + int rank = Integer.valueOf(rankDesc[0]); + int total = Integer.valueOf(rankDesc[1]); + UniversalDto dto = new UniversalDto(); + dto.append("relativeRank", DataUtil.roundDouble(((total - rank) / (double) total) * 100, 2)); + + if (null != districtAnalyData.getRegionRank()) { + dto.append("regionRelativeRank", DataUtil.roundDouble(((districtAnalyData.getRegionRankTotal() - districtAnalyData.getRegionRank()) / (double) districtAnalyData.getRegionRankTotal()) * 100, 2)); + } + mav.setModel(BasicModel.buildOKModel().setResult(dto)); + } else { + mav.setModel(BasicModel.buildOKModel().setMsg("暂无该小区排名信息")); + } + return mav; + + } + + + /** + * 小区成交记录查询 + * + * @param model + * @return + */ + public Object dealAction(final DealPriceModel model) { + + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getName())) { + mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); + return mav; + } + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + + if (model.getMax() == null || model.getMax() < 1) { + model.setMax(DEFAULT_PAGE_SIZE); + } else if (model.getMax() > 100) { + model.setMax(100); + } + + Set districtNames = new HashSet(); + if (null == district) { + districtNames.add(model.getName()); + } else { + districtNames.add(district.getName()); + if (district.getAlias() != null) { + districtNames.addAll(district.getAlias()); + } + final String masterDistrictName = district.getMasterDistrictName(); + if (StringUtils.isNotBlank(masterDistrictName)) { + List districts; + if ("master".equals(masterDistrictName)) { + // 所有的分期数据 + districts = districtService.findSlaves(model.getCity(), model.getDistrict(), model.getName()); + } else { + // 根据主小区名查询所有名称 + districts = districtService.findSlaves(model.getCity(), model.getDistrict(), masterDistrictName); + } + if (CollectionUtils.isNotEmpty(districts)) { + for (District districtTemp : districts) { + districtNames.add(districtTemp.getName()); + } + } + + // districtNames 不包含 主小区名,加进去 + if (!districtNames.contains(masterDistrictName)) { + districtNames.add(masterDistrictName); + } + + } + } + // 将搜房中的别名与名称加入查询集合 + try { + List aliasFangs = aliasFangService.findFangByNameAndAlias(model.getCity(), model.getDistrict(), districtNames); + Set aliasSet = new HashSet(); + for (AliasFang aliasFang : aliasFangs) { + if (StringUtils.isNotBlank(aliasFang.getName())) { + aliasSet.add(aliasFang.getName()); + } + if (StringUtils.isNotBlank(aliasFang.getAlias())) { + aliasSet.add(aliasFang.getAlias()); + } + } + districtNames.addAll(aliasSet); + } catch (Exception ex) { + ex.printStackTrace(); + } // List dealPrices = new ArrayList(); - // 将主名与映射别名查得成交加入 存在不能查出最新成交问题 + // 将主名与映射别名查得成交加入 存在不能查出最新成交问题 // for (String name : districtNames) { // List dealPricesTempList = findDealPricesByName(model.getCity(), model.getDistrict(), name, model.getMax() * 5, model); // if (CollectionUtils.isNotEmpty(dealPricesTempList)) { // dealPrices.addAll(dealPricesTempList); // } // } - List dealPrices = findDealPricesByNames(model.getCity(), model.getDistrict(), new ArrayList(districtNames), model.getMax() * 5, model); - if (model.getSize() != null) { - Collections.sort(dealPrices, new Comparator() { - @Override - public int compare(DealPrice o1, DealPrice o2) { - Double a1 = Math.abs(model.getSize() - o1.getArea()); - Double a2 = Math.abs(model.getSize() - o2.getArea()); - if (a1.compareTo(a2) == 0) { - return -o1.getTradeDate().compareTo(o2.getTradeDate()); - } - return a1.compareTo(a2); - } - }); - } else if (StringUtils.isNotBlank(model.getFloor())) { - final int floor = Integer.valueOf(model.getFloor()); - Collections.sort(dealPrices, new Comparator() { - @Override - public int compare(DealPrice o1, DealPrice o2) { - if (o1.getFloor() == null) { - return 1; - } - if (o1.getFloor() == o2.getFloor() && o1.getFloor() == null) { - return 0; - } - if (o2.getFloor() == null) { - return -1; - } + List dealPrices = findDealPricesByNames(model.getCity(), model.getDistrict(), new ArrayList(districtNames), model.getMax() * 5, model); + if (model.getSize() != null) { + Collections.sort(dealPrices, new Comparator() { + @Override + public int compare(DealPrice o1, DealPrice o2) { + Double a1 = Math.abs(model.getSize() - o1.getArea()); + Double a2 = Math.abs(model.getSize() - o2.getArea()); + if (a1.compareTo(a2) == 0) { + return -o1.getTradeDate().compareTo(o2.getTradeDate()); + } + return a1.compareTo(a2); + } + }); + } else if (StringUtils.isNotBlank(model.getFloor())) { + final int floor = Integer.valueOf(model.getFloor()); + Collections.sort(dealPrices, new Comparator() { + @Override + public int compare(DealPrice o1, DealPrice o2) { + if (o1.getFloor() == null) { + return 1; + } + if (o1.getFloor() == o2.getFloor() && o1.getFloor() == null) { + return 0; + } + if (o2.getFloor() == null) { + return -1; + } - Integer a1 = Math.abs(floor - o1.getFloor()); - Integer a2 = Math.abs(floor - o2.getFloor()); - if (a1.compareTo(a2) == 0) { - return -o1.getTradeDate().compareTo(o2.getTradeDate()); - } - return a1.compareTo(a2); - } - }); - } - if (dealPrices.size() > model.getMax()) { - dealPrices = dealPrices.subList(0, model.getMax()); - } + Integer a1 = Math.abs(floor - o1.getFloor()); + Integer a2 = Math.abs(floor - o2.getFloor()); + if (a1.compareTo(a2) == 0) { + return -o1.getTradeDate().compareTo(o2.getTradeDate()); + } + return a1.compareTo(a2); + } + }); + } + if (dealPrices.size() > model.getMax()) { + dealPrices = dealPrices.subList(0, model.getMax()); + } - List> formateDealPrices = new ArrayList>(); - Map deal; - for (DealPrice dealPrice : dealPrices) { - if (model.isConvert()) { - fieldFilterService.filterWithProcessNUll(dealPrice); - } - deal = new LinkedHashMap(); - dealPrice.setId(null); - deal.put("city", dealPrice.getCity()); - deal.put("district", dealPrice.getRegion()); - deal.put("name", dealPrice.getDistrictName()); - if (dealPrice.getArea() == null) { - deal.put("size", ""); - } else { - deal.put("size", dealPrice.getArea()); - } - deal.put("avgPrice", dealPrice.getAvgPrice()); - deal.put("totalPrice", dealPrice.getTotalPrice()); - deal.put("tradeDate", DateUtil.formatByPattern(dealPrice.getTradeDate(), "yyyy-MM-dd")); - if (dealPrice.getFloor() == null || dealPrice.getFloor() < 1) { - deal.put("floor", ""); - } else { - deal.put("floor", dealPrice.getFloor().toString()); - } - if (dealPrice.getHeight() == null || dealPrice.getHeight() < 1) { - deal.put("maxFloor", ""); - } else { - deal.put("maxFloor", dealPrice.getHeight().toString()); - } + List> formateDealPrices = new ArrayList>(); + Map deal; + for (DealPrice dealPrice : dealPrices) { + if (model.isConvert()) { + fieldFilterService.filterWithProcessNUll(dealPrice); + } + deal = new LinkedHashMap(); + dealPrice.setId(null); + deal.put("city", dealPrice.getCity()); + deal.put("district", dealPrice.getRegion()); + deal.put("name", dealPrice.getDistrictName()); + if (dealPrice.getArea() == null) { + deal.put("size", ""); + } else { + deal.put("size", dealPrice.getArea()); + } + deal.put("avgPrice", dealPrice.getAvgPrice()); + deal.put("totalPrice", dealPrice.getTotalPrice()); + deal.put("tradeDate", DateUtil.formatByPattern(dealPrice.getTradeDate(), "yyyy-MM-dd")); + if (dealPrice.getFloor() == null || dealPrice.getFloor() < 1) { + deal.put("floor", ""); + } else { + deal.put("floor", dealPrice.getFloor().toString()); + } + if (dealPrice.getHeight() == null || dealPrice.getHeight() < 1) { + deal.put("maxFloor", ""); + } else { + deal.put("maxFloor", dealPrice.getHeight().toString()); + } - if (dealPrice.getRoom() == null || dealPrice.getRoom() < 1) { - deal.put("room", ""); - } else { - deal.put("room", dealPrice.getRoom().toString()); - } - if (dealPrice.getHall() == null || dealPrice.getHall() < 1) { - deal.put("hall", ""); - } else { - deal.put("hall", dealPrice.getHall().toString()); - } - if (dealPrice.getToilet() == null || dealPrice.getToilet() < 1) { - deal.put("toilet", ""); - } else { - deal.put("toilet", dealPrice.getToilet().toString()); - } - String fitment = HouseValidator.fetchFitmentInfo(dealPrice.getFitment()); - if (fitment == null) { - deal.put("decoration", ""); - } else { - deal.put("decoration", fitment); - } - String direction = HouseValidator.fetchDirectionInfo(dealPrice.getDirection()); - if (direction == null) { - deal.put("direction", ""); - } else { - deal.put("direction", direction); - } - formateDealPrices.add(deal); - } - mav.setModel(BasicModel.buildOKModel().setResult(formateDealPrices)); - return mav; - } + if (dealPrice.getRoom() == null || dealPrice.getRoom() < 1) { + deal.put("room", ""); + } else { + deal.put("room", dealPrice.getRoom().toString()); + } + if (dealPrice.getHall() == null || dealPrice.getHall() < 1) { + deal.put("hall", ""); + } else { + deal.put("hall", dealPrice.getHall().toString()); + } + if (dealPrice.getToilet() == null || dealPrice.getToilet() < 1) { + deal.put("toilet", ""); + } else { + deal.put("toilet", dealPrice.getToilet().toString()); + } + String fitment = HouseValidator.fetchFitmentInfo(dealPrice.getFitment()); + if (fitment == null) { + deal.put("decoration", ""); + } else { + deal.put("decoration", fitment); + } + String direction = HouseValidator.fetchDirectionInfo(dealPrice.getDirection()); + if (direction == null) { + deal.put("direction", ""); + } else { + deal.put("direction", direction); + } + formateDealPrices.add(deal); + } + mav.setModel(BasicModel.buildOKModel().setResult(formateDealPrices)); + return mav; + } - public Object houseAction(DealPriceModel model) { + public Object houseAction(DealPriceModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity())) { - mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getName())) { - mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); - return mav; - } - if (null == model.getSize()) { - mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能为空")); - return mav; - } - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName().replace(" ",""), - "district"); - if (null == district) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - if (model.getMax() == null || model.getMax() < 1) { - model.setMax(DEFAULT_PAGE_SIZE); - } else if (model.getMax() > 100) { - model.setMax(100); - } - FacetQueryResult houseList = findDistrictHouses(district, model.getMax() * 5); - if (houseList == null || houseList.isEmpty()) {// 通知API没有找到房源 - String cat = "sell"; - String source = ""; - ApiUser apiUser = checkNewAuthorized(model.getToken()); - if (apiUser != null) { - User user = userService.findById(apiUser.getId()); - if (user != null) { - source = user.getUserName(); - } + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getName())) { + mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); + return mav; + } + if (null == model.getSize()) { + mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能为空")); + return mav; + } + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName().replace(" ", ""), + "district"); + if (null == district) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + if (model.getMax() == null || model.getMax() < 1) { + model.setMax(DEFAULT_PAGE_SIZE); + } else if (model.getMax() > 100) { + model.setMax(100); + } + FacetQueryResult houseList = findDistrictHouses(district, model.getMax() * 5); + if (houseList == null || houseList.isEmpty()) {// 通知API没有找到房源 + String cat = "sell"; + String source = ""; + ApiUser apiUser = checkNewAuthorized(model.getToken()); + if (apiUser != null) { + User user = userService.findById(apiUser.getId()); + if (user != null) { + source = user.getUserName(); + } - } else { - source = "api调用"; - } + } else { + source = "api调用"; + } - NoHouseDistrict noHouseDistrict = noHouseDistrictService.findNoHouseDistrictByParams(district.getCity(), - district.getRegion(), district.getName(), cat, source); - if (noHouseDistrict == null) { - noHouseDistrict = new NoHouseDistrict(); - noHouseDistrict.setCity(district.getCity()); - noHouseDistrict.setRegion(district.getRegion()); - noHouseDistrict.setName(district.getName()); - noHouseDistrict.setCategory(cat); - noHouseDistrict.setCreationDate(new Date()); - noHouseDistrict.setModificationDate(new Date()); - noHouseDistrict.setLevel(10); - noHouseDistrict.setCrawlCount(0); - noHouseDistrict.setSource(source); - noHouseDistrictService.save(noHouseDistrict); - } - } - List houseBoList = fillDistrictInfoForHouse(houseList, district, model.isConvert()); - orderHouseList(houseBoList, model); - if (houseBoList.size() > model.getMax()) { - houseBoList = new FacetQueryResult(houseBoList.subList(0, model.getMax())); - } - mav.setModel(BasicModel.buildOKModel().setResult(houseBoList)); - return mav; + NoHouseDistrict noHouseDistrict = noHouseDistrictService.findNoHouseDistrictByParams(district.getCity(), + district.getRegion(), district.getName(), cat, source); + if (noHouseDistrict == null) { + noHouseDistrict = new NoHouseDistrict(); + noHouseDistrict.setCity(district.getCity()); + noHouseDistrict.setRegion(district.getRegion()); + noHouseDistrict.setName(district.getName()); + noHouseDistrict.setCategory(cat); + noHouseDistrict.setCreationDate(new Date()); + noHouseDistrict.setModificationDate(new Date()); + noHouseDistrict.setLevel(10); + noHouseDistrict.setCrawlCount(0); + noHouseDistrict.setSource(source); + noHouseDistrictService.save(noHouseDistrict); + } + } + List houseBoList = fillDistrictInfoForHouse(houseList, district, model.isConvert()); + orderHouseList(houseBoList, model); + if (houseBoList.size() > model.getMax()) { + houseBoList = new FacetQueryResult(houseBoList.subList(0, model.getMax())); + } + mav.setModel(BasicModel.buildOKModel().setResult(houseBoList)); + return mav; - } + } - private boolean isRadiusSearch(PropertySearchModel model) { - return model.getLat() != null && model.getLng() != null && model.getLat() != 0 && model.getLng() != 0; - } + private boolean isRadiusSearch(PropertySearchModel model) { + return model.getLat() != null && model.getLng() != null && model.getLat() != 0 && model.getLng() != 0; + } - private String transformPicsToFangJia(String url) { + private String transformPicsToFangJia(String url) { - return "http://static.fangjia.com/stc/fs/" + encodePicUrl(url, "o", "district"); + return "http://static.fangjia.com/stc/fs/" + encodePicUrl(url, "o", "district"); - } + } - public String encodePicUrl(String u, String s, String t) { - try { - return SecurityUtil.encode("u=" + URLEncoder.encode(u, "UTF-8") + "&s=" + s + "&t=" + t); - } catch (Exception e) { - return SecurityUtil.encode("u=" + u + "&s=" + s + "&t=" + t); - } + public String encodePicUrl(String u, String s, String t) { + try { + return SecurityUtil.encode("u=" + URLEncoder.encode(u, "UTF-8") + "&s=" + s + "&t=" + t); + } catch (Exception e) { + return SecurityUtil.encode("u=" + u + "&s=" + s + "&t=" + t); + } - } + } - /** - * 通过EvaluationModel组装Evaluation实体 - * - * @param model - * @param request - * @return - */ - private Evaluation buildEvaluation(PropertyEvaluationModel model, HttpServletRequest request) { - Evaluation evaluation = new Evaluation(); - evaluation.setCity(model.getCity()); - evaluation.setRegion(model.getRegion()); - evaluation.setDistrictName(model.getName()); - evaluation.setDirection(DIRECTION.get(model.getDirection())); - evaluation.setFitment(EVALUATION_MODEL_FITMENT.get(FITMENT.get(StringUtils.isNotBlank(model.getDecoration()) ? - model.getDecoration() : model.getFitment()))); - evaluation.setNoise(NOISE.get(model.getNoise())); - evaluation.setEstateType(PROPERTY_TYPES.get(model.getPropertyType())); - evaluation.setSight(SIGHT.get(model.getView())); - evaluation.setAtticArea(model.getAtticSize()); - evaluation.setTerraceArea(model.getOuterSize()); - evaluation.setBasementArea(model.getBasementSize()); - evaluation.setGardenArea(model.getGardenSize()); - String worryFacility = model.getNegativeFactor(); - evaluation.setWorryFacility(NEGATIVE_FACTOR.get(worryFacility)); - evaluation.setCreationDate(new Date()); - evaluation.setModificationDate(new Date()); - evaluation.setClientNo(model.getClientNo()); - if (0 != model.getAge()) { - evaluation.setAge(model.getAge()); - } - evaluation.setArea(model.getSize()); - if (ArrayUtils.isNotEmpty(model.getBuildQuality())) { - evaluation.setBuildQuality(convertToString(model.getBuildQuality())); - } - if (StringUtils.isNotBlank(model.getBuildType())) { - evaluation.setBuildType(model.getBuildType()); - } - if (StringUtils.isNotBlank(model.getCarport())) { - evaluation.setCarport(model.getCarport()); - } - if (model.getDecorationAge() >= 1 && model.getDecorationAge() <= 5) { - evaluation.setFitmentAge(model.getDecorationAge()); - } - evaluation.setCarportPrice(model.getCarportPrice()); - evaluation.setCity(model.getCity()); - evaluation.setDistrictName(model.getName()); - if (model.getDecorationCost() != null && model.getDecorationCost() > 0) { - evaluation.setFitmentCharge(model.getDecorationCost()); - } - if (0 != model.getHall()) { - evaluation.setHall(model.getHall()); - } - if (null != model.getFloor()) { - evaluation.setFloor(model.getFloor()); - } - if (model.getMaxFloor() != null && 0 != model.getMaxFloor()) { - evaluation.setHeight(model.getMaxFloor()); - } - if (StringUtils.isNotBlank(model.getBuildingNumber())) { - evaluation.setHouseNum(model.getBuildingNumber()); - } - if (StringUtils.isNotBlank(model.getHouseProperty())) { - evaluation.setHouseProperty(model.getHouseProperty()); - } - if (StringUtils.isNotBlank(model.getInsidepos())) { - evaluation.setInsidepos(model.getInsidepos()); - } - if (StringUtils.isNotBlank(model.getLightingVentilation())) { - evaluation.setLightingVentilation(model.getLightingVentilation()); - } + /** + * 通过EvaluationModel组装Evaluation实体 + * + * @param model + * @param request + * @return + */ + private Evaluation buildEvaluation(PropertyEvaluationModel model, HttpServletRequest request) { + Evaluation evaluation = new Evaluation(); + evaluation.setCity(model.getCity()); + evaluation.setRegion(model.getRegion()); + evaluation.setDistrictName(model.getName()); + evaluation.setDirection(DIRECTION.get(model.getDirection())); + evaluation.setFitment(EVALUATION_MODEL_FITMENT.get(FITMENT.get(StringUtils.isNotBlank(model.getDecoration()) ? + model.getDecoration() : model.getFitment()))); + evaluation.setNoise(NOISE.get(model.getNoise())); + evaluation.setEstateType(PROPERTY_TYPES.get(model.getPropertyType())); + evaluation.setSight(SIGHT.get(model.getView())); + evaluation.setAtticArea(model.getAtticSize()); + evaluation.setTerraceArea(model.getOuterSize()); + evaluation.setBasementArea(model.getBasementSize()); + evaluation.setGardenArea(model.getGardenSize()); + String worryFacility = model.getNegativeFactor(); + evaluation.setWorryFacility(NEGATIVE_FACTOR.get(worryFacility)); + evaluation.setCreationDate(new Date()); + evaluation.setModificationDate(new Date()); + evaluation.setClientNo(model.getClientNo()); + if (0 != model.getAge()) { + evaluation.setAge(model.getAge()); + } + evaluation.setArea(model.getSize()); + if (ArrayUtils.isNotEmpty(model.getBuildQuality())) { + evaluation.setBuildQuality(convertToString(model.getBuildQuality())); + } + if (StringUtils.isNotBlank(model.getBuildType())) { + evaluation.setBuildType(model.getBuildType()); + } + if (StringUtils.isNotBlank(model.getCarport())) { + evaluation.setCarport(model.getCarport()); + } + if (model.getDecorationAge() >= 1 && model.getDecorationAge() <= 5) { + evaluation.setFitmentAge(model.getDecorationAge()); + } + evaluation.setCarportPrice(model.getCarportPrice()); + evaluation.setCity(model.getCity()); + evaluation.setDistrictName(model.getName()); + if (model.getDecorationCost() != null && model.getDecorationCost() > 0) { + evaluation.setFitmentCharge(model.getDecorationCost()); + } + if (0 != model.getHall()) { + evaluation.setHall(model.getHall()); + } + if (null != model.getFloor()) { + evaluation.setFloor(model.getFloor()); + } + if (model.getMaxFloor() != null && 0 != model.getMaxFloor()) { + evaluation.setHeight(model.getMaxFloor()); + } + if (StringUtils.isNotBlank(model.getBuildingNumber())) { + evaluation.setHouseNum(model.getBuildingNumber()); + } + if (StringUtils.isNotBlank(model.getHouseProperty())) { + evaluation.setHouseProperty(model.getHouseProperty()); + } + if (StringUtils.isNotBlank(model.getInsidepos())) { + evaluation.setInsidepos(model.getInsidepos()); + } + if (StringUtils.isNotBlank(model.getLightingVentilation())) { + evaluation.setLightingVentilation(model.getLightingVentilation()); + } - if (StringUtils.isNotBlank(model.getOtherFactor())) { - evaluation.setOtherFactor(model.getOtherFactor()); - } - evaluation.setRegion(model.getDistrict()); - if (null != model.getRoom()) { - evaluation.setRoom(model.getRoom()); - } - if (StringUtils.isNotBlank(model.getRoomNumber())) { - evaluation.setRoomNum(model.getRoomNumber()); - } - if (StringUtils.isNotBlank(model.getSideset())) { - evaluation.setSideset(model.getSideset()); - } - if (0 != model.getToilet()) { - evaluation.setToilet(model.getToilet()); - } - if (model.getFacilities() != null) { - String facilities = model.getFacilities(); - String[] fs = facilities.split(","); - for (int i = 0; i < fs.length; i++) { - fs[i] = FACILITIES.get(fs[i]); - } - evaluation.setFacilities(convertToString(fs)); - } + if (StringUtils.isNotBlank(model.getOtherFactor())) { + evaluation.setOtherFactor(model.getOtherFactor()); + } + evaluation.setRegion(model.getDistrict()); + if (null != model.getRoom()) { + evaluation.setRoom(model.getRoom()); + } + if (StringUtils.isNotBlank(model.getRoomNumber())) { + evaluation.setRoomNum(model.getRoomNumber()); + } + if (StringUtils.isNotBlank(model.getSideset())) { + evaluation.setSideset(model.getSideset()); + } + if (0 != model.getToilet()) { + evaluation.setToilet(model.getToilet()); + } + if (model.getFacilities() != null) { + String facilities = model.getFacilities(); + String[] fs = facilities.split(","); + for (int i = 0; i < fs.length; i++) { + fs[i] = FACILITIES.get(fs[i]); + } + evaluation.setFacilities(convertToString(fs)); + } - if (StringUtils.isNotBlank(model.getFacade())) { - evaluation.setFacade(model.getFacade()); - } - if (StringUtils.isNotBlank(model.getTraffice())) { - evaluation.setTraffice(model.getTraffice()); - } - if (StringUtils.isNotBlank(model.getShape())) { - evaluation.setShape(model.getShape()); - } - if (StringUtils.isNotBlank(model.getObstacle())) { - evaluation.setObstacle(model.getObstacle()); - } - if (StringUtils.isNotBlank(model.getIndustry())) { - evaluation.setIndustry(model.getIndustry()); - } - if (StringUtils.isNotBlank(model.getSupportDevice())) { - evaluation.setSupportDevice(model.getSupportDevice()); - } - if (StringUtils.isNotBlank(model.getLeftPosition())) { - evaluation.setLeftPosition(model.getLeftPosition()); - } - if (StringUtils.isNotBlank(model.getShopType())) { - evaluation.setShopType(model.getShopType()); - } - if (StringUtils.isNotBlank(model.getShopUnique())) { - evaluation.setShopUnique(model.getShopUnique()); - } - if (StringUtils.isNotBlank(model.getLocation())) { - evaluation.setLocation(model.getLocation()); - } - if (model.isNewDistrict()) { - evaluation.setNewDistrict(model.isNewDistrict()); - } - String ip = AnalyticsUtil.getIpAddress(ActionContext.getContext().getRequest()); - evaluation.setIp(ip); - AuthenticationBean authenticationBean = (AuthenticationBean) request - .getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN); - if (authenticationBean != null && authenticationBean.apiUser != null) { - evaluation.setFromUserId(String.valueOf(authenticationBean.apiUser.getId())); - } - evaluation.setSource("api_property_evaluation"); - return evaluation; - } + if (StringUtils.isNotBlank(model.getFacade())) { + evaluation.setFacade(model.getFacade()); + } + if (StringUtils.isNotBlank(model.getTraffice())) { + evaluation.setTraffice(model.getTraffice()); + } + if (StringUtils.isNotBlank(model.getShape())) { + evaluation.setShape(model.getShape()); + } + if (StringUtils.isNotBlank(model.getObstacle())) { + evaluation.setObstacle(model.getObstacle()); + } + if (StringUtils.isNotBlank(model.getIndustry())) { + evaluation.setIndustry(model.getIndustry()); + } + if (StringUtils.isNotBlank(model.getSupportDevice())) { + evaluation.setSupportDevice(model.getSupportDevice()); + } + if (StringUtils.isNotBlank(model.getLeftPosition())) { + evaluation.setLeftPosition(model.getLeftPosition()); + } + if (StringUtils.isNotBlank(model.getShopType())) { + evaluation.setShopType(model.getShopType()); + } + if (StringUtils.isNotBlank(model.getShopUnique())) { + evaluation.setShopUnique(model.getShopUnique()); + } + if (StringUtils.isNotBlank(model.getLocation())) { + evaluation.setLocation(model.getLocation()); + } + if (model.isNewDistrict()) { + evaluation.setNewDistrict(model.isNewDistrict()); + } + String ip = AnalyticsUtil.getIpAddress(ActionContext.getContext().getRequest()); + evaluation.setIp(ip); + AuthenticationBean authenticationBean = (AuthenticationBean) request + .getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN); + if (authenticationBean != null && authenticationBean.apiUser != null) { + evaluation.setFromUserId(String.valueOf(authenticationBean.apiUser.getId())); + } + evaluation.setSource("api_property_evaluation"); + return evaluation; + } - /** - * 批量获取小区的均价,均价走势数据 - * - * @param request - * @return - */ - public Object priceAction(HttpServletRequest request) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); + /** + * 批量获取小区的均价,均价走势数据 + * + * @param request + * @return + */ + public Object priceAction(HttpServletRequest request) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); - JSONObject jo = getJsonParam(request); - if (jo == null || !jo.containsKey("property") || jo.getJSONArray("property").size() == 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数格式错误")); - return mav; - } - JSONArray ja = jo.getJSONArray("property"); - if (ja.size() > 12) { - mav.setModel(BasicModel.buildBadRequestModel("批量查询小区数超过上限")); - return mav; - } + JSONObject jo = getJsonParam(request); + if (jo == null || !jo.containsKey("property") || jo.getJSONArray("property").size() == 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数格式错误")); + return mav; + } + JSONArray ja = jo.getJSONArray("property"); + if (ja.size() > 12) { + mav.setModel(BasicModel.buildBadRequestModel("批量查询小区数超过上限")); + return mav; + } - JSONArray jsonArray = new JSONArray();// 结果集 - boolean hasData = false; - for (Object o : ja) { - JSONObject subJo = (JSONObject) o; - String id = subJo.containsKey("id") ? subJo.getString("id") : null; - String city = subJo.containsKey("city") ? subJo.getString("city") : null; - String region = subJo.containsKey("district") ? subJo.getString("district") : null; - String name = subJo.containsKey("name") ? subJo.getString("name") : null; - Date updatedDate = DateUtil.getLastWeekendOfLastMonth(new Date()); + JSONArray jsonArray = new JSONArray();// 结果集 + boolean hasData = false; + for (Object o : ja) { + JSONObject subJo = (JSONObject) o; + String id = subJo.containsKey("id") ? subJo.getString("id") : null; + String city = subJo.containsKey("city") ? subJo.getString("city") : null; + String region = subJo.containsKey("district") ? subJo.getString("district") : null; + String name = subJo.containsKey("name") ? subJo.getString("name") : null; + Date updatedDate = DateUtil.getLastWeekendOfLastMonth(new Date()); - JSONObject resultJo = new JSONObject(); - District district; - if (StringUtils.isNotBlank(id)) { - district = districtService.findById(id); - } else { - if (StringUtils.isBlank(city) || StringUtils.isBlank(region) || StringUtils.isBlank(name)) { - mav.setModel(BasicModel.buildBadRequestModel("参数格式错误")); - return mav; - } - district = districtService.findByNameAndAlias(city, region, name, "district"); - } - if (district == null) { - jsonArray.add(resultJo); - continue; - } - hasData = true; - resultJo.put("id", district.getId()); - resultJo.put("city", district.getCity()); - resultJo.put("district", district.getRegion()); - resultJo.put("name", district.getName()); + JSONObject resultJo = new JSONObject(); + District district; + if (StringUtils.isNotBlank(id)) { + district = districtService.findById(id); + } else { + if (StringUtils.isBlank(city) || StringUtils.isBlank(region) || StringUtils.isBlank(name)) { + mav.setModel(BasicModel.buildBadRequestModel("参数格式错误")); + return mav; + } + district = districtService.findByNameAndAlias(city, region, name, "district"); + } + if (district == null) { + jsonArray.add(resultJo); + continue; + } + hasData = true; + resultJo.put("id", district.getId()); + resultJo.put("city", district.getCity()); + resultJo.put("district", district.getRegion()); + resultJo.put("name", district.getName()); - int monthCountOfYear = 12;// 一年12个月 - List districtSellStats = districtSellStatService.getAllWithMonths(district.getCity(), - district.getRegion(), district.getName(), monthCountOfYear); - if (CollectionUtils.isNotEmpty(districtSellStats)) { - DistrictSellStat districtSellStat = districtSellStats.get(0); + int monthCountOfYear = 12;// 一年12个月 + List districtSellStats = districtSellStatService.getAllWithMonths(district.getCity(), + district.getRegion(), district.getName(), monthCountOfYear); + if (CollectionUtils.isNotEmpty(districtSellStats)) { + DistrictSellStat districtSellStat = districtSellStats.get(0); - Integer avgPrice = districtSellStat.getAvgPrice(); - Double mom = districtSellStat.getMom(); - Double yoy = districtSellStat.getYoy(); - Integer riseOnMonth = null; - Integer riseOnYear = null; - if (districtSellStats.size() > 1) { - if (districtSellStats.get(1).getDate() + 1 == districtSellStat.getDate()) { - riseOnMonth = avgPrice - districtSellStats.get(1).getAvgPrice(); - } - if (districtSellStats.size() == monthCountOfYear) { - riseOnYear = avgPrice - districtSellStats.get(monthCountOfYear - 1).getAvgPrice(); - } - } + Integer avgPrice = districtSellStat.getAvgPrice(); + Double mom = districtSellStat.getMom(); + Double yoy = districtSellStat.getYoy(); + Integer riseOnMonth = null; + Integer riseOnYear = null; + if (districtSellStats.size() > 1) { + if (districtSellStats.get(1).getDate() + 1 == districtSellStat.getDate()) { + riseOnMonth = avgPrice - districtSellStats.get(1).getAvgPrice(); + } + if (districtSellStats.size() == monthCountOfYear) { + riseOnYear = avgPrice - districtSellStats.get(monthCountOfYear - 1).getAvgPrice(); + } + } - JSONArray trendJa = new JSONArray(); - for (DistrictSellStat jsa : districtSellStats) { - String date = new StringBuffer(jsa.getDate() + "").insert(4, "-").toString(); + JSONArray trendJa = new JSONArray(); + for (DistrictSellStat jsa : districtSellStats) { + String date = new StringBuffer(jsa.getDate() + "").insert(4, "-").toString(); - JSONObject trendJo = new JSONObject(); - trendJo.put("avgPrice", jsa.getAvgPrice()); - trendJo.put("mom", jsa.getMom()); - trendJo.put("date", date); - trendJa.add(trendJo); - } - resultJo.put("avgPrice", avgPrice); - resultJo.put("riseOnMonth", riseOnMonth); - resultJo.put("mom", mom); - resultJo.put("riseOnYear", riseOnYear); - resultJo.put("yoy", yoy); - resultJo.put("updatedDate", sdf.format(updatedDate)); - resultJo.put("avgPriceTrend", trendJa); - } - jsonArray.add(resultJo); - } - if (!hasData) { - BasicModel.markNoDataRequest(); - } - mav.setModel(BasicModel.buildOKModel().setResult(jsonArray)); - return mav; - } + JSONObject trendJo = new JSONObject(); + trendJo.put("avgPrice", jsa.getAvgPrice()); + trendJo.put("mom", jsa.getMom()); + trendJo.put("date", date); + trendJa.add(trendJo); + } + resultJo.put("avgPrice", avgPrice); + resultJo.put("riseOnMonth", riseOnMonth); + resultJo.put("mom", mom); + resultJo.put("riseOnYear", riseOnYear); + resultJo.put("yoy", yoy); + resultJo.put("updatedDate", sdf.format(updatedDate)); + resultJo.put("avgPriceTrend", trendJa); + } + jsonArray.add(resultJo); + } + if (!hasData) { + BasicModel.markNoDataRequest(); + } + mav.setModel(BasicModel.buildOKModel().setResult(jsonArray)); + return mav; + } - public Object floorPlanAction(@Valid FloorPlanModel model) { + public Object floorPlanAction(@Valid FloorPlanModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - District district = districtService.findById(model.getId()); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("未找到该小区")); - return mav; - } - List srcFloorPlanPics = district.getSrcFloorplanPics(); - List floorPlanDtos = new ArrayList(); - for (Object obj : srcFloorPlanPics) { - if (obj != null && obj instanceof Map) { - Map src = (Map) obj; - if (src.containsKey("url") && src.containsKey("main_type") && src.containsKey("main_type_area")) { - FloorPlanDto dto = new FloorPlanDto(); - dto.setUrl(src.get("url")); - dto.setMainHouseType(src.get("main_type")); - dto.setMainHouseTypeArea(src.get("main_type_area")); - dto.setTitle(src.get("description")); - floorPlanDtos.add(dto); - } - } - } - if (floorPlanDtos.isEmpty()) { - for (Object obj : srcFloorPlanPics) { - if (obj != null && obj instanceof Map) { - Map src = (Map) obj; - if (src.containsKey("url") && src.containsKey("description")) { - FloorPlanDto dto = new FloorPlanDto(); - dto.setUrl(src.get("url")); - dto.setTitle(src.get("description")); - floorPlanDtos.add(dto); - } - } - } - } + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + District district = districtService.findById(model.getId()); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("未找到该小区")); + return mav; + } + List srcFloorPlanPics = district.getSrcFloorplanPics(); + List floorPlanDtos = new ArrayList(); + for (Object obj : srcFloorPlanPics) { + if (obj != null && obj instanceof Map) { + Map src = (Map) obj; + if (src.containsKey("url") && src.containsKey("main_type") && src.containsKey("main_type_area")) { + FloorPlanDto dto = new FloorPlanDto(); + dto.setUrl(src.get("url")); + dto.setMainHouseType(src.get("main_type")); + dto.setMainHouseTypeArea(src.get("main_type_area")); + dto.setTitle(src.get("description")); + floorPlanDtos.add(dto); + } + } + } + if (floorPlanDtos.isEmpty()) { + for (Object obj : srcFloorPlanPics) { + if (obj != null && obj instanceof Map) { + Map src = (Map) obj; + if (src.containsKey("url") && src.containsKey("description")) { + FloorPlanDto dto = new FloorPlanDto(); + dto.setUrl(src.get("url")); + dto.setTitle(src.get("description")); + floorPlanDtos.add(dto); + } + } + } + } - mav.setModel(BasicModel.buildOKModel().setResult(floorPlanDtos)); - return mav; - } + mav.setModel(BasicModel.buildOKModel().setResult(floorPlanDtos)); + return mav; + } - /** - * 批量获取小区的配套数据,最多12个小区 - * - * @param request - * @return - */ - public Object facilitiesAction(HttpServletRequest request) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); + /** + * 批量获取小区的配套数据,最多12个小区 + * + * @param request + * @return + */ + public Object facilitiesAction(HttpServletRequest request) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); - JSONObject jo = getJsonParam(request); - if (jo == null || !jo.containsKey("property") || jo.getJSONArray("property").size() == 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数格式错误")); - return mav; - } - // 查询半径 ,默认1000米,最大5000米 - Double radius = getRadius(jo); - if (radius == null) { - mav.setModel(BasicModel.buildBadRequestModel("查询半径(radius)非法")); - return mav; - } - Integer maxNum = getNum(jo); - if (maxNum == null) { - mav.setModel(BasicModel.buildBadRequestModel("最大记录数(num)非法")); - return mav; - } - JSONArray ja = jo.getJSONArray("property"); - if (ja.size() > 12) { - mav.setModel(BasicModel.buildBadRequestModel("批量查询小区数超过上限")); - return mav; - } + JSONObject jo = getJsonParam(request); + if (jo == null || !jo.containsKey("property") || jo.getJSONArray("property").size() == 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数格式错误")); + return mav; + } + // 查询半径 ,默认1000米,最大5000米 + Double radius = getRadius(jo); + if (radius == null) { + mav.setModel(BasicModel.buildBadRequestModel("查询半径(radius)非法")); + return mav; + } + Integer maxNum = getNum(jo); + if (maxNum == null) { + mav.setModel(BasicModel.buildBadRequestModel("最大记录数(num)非法")); + return mav; + } + JSONArray ja = jo.getJSONArray("property"); + if (ja.size() > 12) { + mav.setModel(BasicModel.buildBadRequestModel("批量查询小区数超过上限")); + return mav; + } - JSONArray jsonArray = new JSONArray();// 结果集 - boolean hasData = false; - for (Object o : ja) { - JSONObject subJo = (JSONObject) o; - String id = subJo.containsKey("id") ? subJo.getString("id") : null; - String city = subJo.containsKey("city") ? subJo.getString("city") : null; - String region = subJo.containsKey("district") ? subJo.getString("district") : null; - String name = subJo.containsKey("name") ? subJo.getString("name") : null; + JSONArray jsonArray = new JSONArray();// 结果集 + boolean hasData = false; + for (Object o : ja) { + JSONObject subJo = (JSONObject) o; + String id = subJo.containsKey("id") ? subJo.getString("id") : null; + String city = subJo.containsKey("city") ? subJo.getString("city") : null; + String region = subJo.containsKey("district") ? subJo.getString("district") : null; + String name = subJo.containsKey("name") ? subJo.getString("name") : null; - District district = null; - if (StringUtils.isNotBlank(id)) { - district = districtService.findById(id); - } else { - if (StringUtils.isBlank(city) || StringUtils.isBlank(region) || StringUtils.isBlank(name)) { - mav.setModel(BasicModel.buildBadRequestModel("参数格式错误")); - return mav; - } - district = districtService.findByNameAndAlias(city, region, name, "district"); - } - JSONObject aroundJo = new JSONObject(); - if (null == district || district.getLat2() == null || district.getLat2() == 0) { - jsonArray.add(aroundJo); - continue; - } - hasData = true; - aroundJo.put("id", district.getId()); - aroundJo.put("city", district.getCity()); - aroundJo.put("district", district.getRegion()); - aroundJo.put("name", district.getName()); + District district = null; + if (StringUtils.isNotBlank(id)) { + district = districtService.findById(id); + } else { + if (StringUtils.isBlank(city) || StringUtils.isBlank(region) || StringUtils.isBlank(name)) { + mav.setModel(BasicModel.buildBadRequestModel("参数格式错误")); + return mav; + } + district = districtService.findByNameAndAlias(city, region, name, "district"); + } + JSONObject aroundJo = new JSONObject(); + if (null == district || district.getLat2() == null || district.getLat2() == 0) { + jsonArray.add(aroundJo); + continue; + } + hasData = true; + aroundJo.put("id", district.getId()); + aroundJo.put("city", district.getCity()); + aroundJo.put("district", district.getRegion()); + aroundJo.put("name", district.getName()); - double lat = district.getLat2() / 10000000000d; - double lng = district.getLng2() / 10000000000d; + double lat = district.getLat2() / 10000000000d; + double lng = district.getLng2() / 10000000000d; - // 查询小区周边(所有类型) - List arrs = baiduApiService.searchNearbyLocalDatabase(district, radius); - Map> districtAroundMap = Maps.newHashMap(); - Map districtAroundCountMap = Maps.newHashMap(); + // 查询小区周边(所有类型) + List arrs = baiduApiService.searchNearbyLocalDatabase(district, radius); + Map> districtAroundMap = Maps.newHashMap(); + Map districtAroundCountMap = Maps.newHashMap(); - for (String key : AROUND_KEYWORD_FACTOR_NEW.keySet()) { - districtAroundMap.put(AROUND_KEYWORD_FACTOR_NEW.get(key), new ArrayList());// 把key的英文put到map并把value设置为一个List引用 - } - for (int i = 0; i < arrs.size(); i++) { - BaiduPlacePoi poiObj = arrs.get(i); - String _name = poiObj.getName(); - String keyword = poiObj.getKeyword(); - double latjs = poiObj.getLat(); - double lngjs = poiObj.getLng(); - String key = AROUND_KEYWORD_FACTOR_NEW.get(keyword); - if (StringUtils.isBlank(key)) { - continue; - } + for (String key : AROUND_KEYWORD_FACTOR_NEW.keySet()) { + districtAroundMap.put(AROUND_KEYWORD_FACTOR_NEW.get(key), new ArrayList());// 把key的英文put到map并把value设置为一个List引用 + } + for (int i = 0; i < arrs.size(); i++) { + BaiduPlacePoi poiObj = arrs.get(i); + String _name = poiObj.getName(); + String keyword = poiObj.getKeyword(); + double latjs = poiObj.getLat(); + double lngjs = poiObj.getLng(); + String key = AROUND_KEYWORD_FACTOR_NEW.get(keyword); + if (StringUtils.isBlank(key)) { + continue; + } - AroundDto dto = new AroundDto(); - dto.setName(_name); - dto.setLat(latjs); - dto.setLng(lngjs); - dto.setDistance((int) GeoUtils.calculateDistance(lng, lat, lngjs, latjs)); - if (districtAroundMap.get(key) != null) { - districtAroundMap.get(key).add(dto);// 按key值取出list add 周边名称已经经纬度 - } - } + AroundDto dto = new AroundDto(); + dto.setName(_name); + dto.setLat(latjs); + dto.setLng(lngjs); + dto.setDistance((int) GeoUtils.calculateDistance(lng, lat, lngjs, latjs)); + if (districtAroundMap.get(key) != null) { + districtAroundMap.get(key).add(dto);// 按key值取出list add 周边名称已经经纬度 + } + } - // 周边公交、地铁 - Map> stationMap = busStationService.getNearByStations(district.getCity(), lat, lng, - radius); - addToDistrictAroundMap(districtAroundMap, stationMap, district, "公交"); - addToDistrictAroundMap(districtAroundMap, stationMap, district, "地铁"); + // 周边公交、地铁 + Map> stationMap = busStationService.getNearByStations(district.getCity(), lat, lng, + radius); + addToDistrictAroundMap(districtAroundMap, stationMap, district, "公交"); + addToDistrictAroundMap(districtAroundMap, stationMap, district, "地铁"); - // 根据maxNum参数过滤返回值数量,并由近及远排序 - filterAndSortResult(districtAroundMap, districtAroundCountMap, maxNum); + // 根据maxNum参数过滤返回值数量,并由近及远排序 + filterAndSortResult(districtAroundMap, districtAroundCountMap, maxNum); - // 封装成需要的返回格式 - for (Map.Entry> entry : districtAroundMap.entrySet()) { - String key = entry.getKey(); - List listVal = entry.getValue(); - if (CollectionUtils.isEmpty(listVal)) { - continue; - } - JSONObject jsonObject = new JSONObject(); - jsonObject.put("count", districtAroundCountMap.get(key)); - jsonObject.put(listKeyMap.get(key), listVal); - aroundJo.put(key, jsonObject); - } + // 封装成需要的返回格式 + for (Map.Entry> entry : districtAroundMap.entrySet()) { + String key = entry.getKey(); + List listVal = entry.getValue(); + if (CollectionUtils.isEmpty(listVal)) { + continue; + } + JSONObject jsonObject = new JSONObject(); + jsonObject.put("count", districtAroundCountMap.get(key)); + jsonObject.put(listKeyMap.get(key), listVal); + aroundJo.put(key, jsonObject); + } - jsonArray.add(aroundJo); - } - if (!hasData) { - BasicModel.markNoDataRequest(); - } - mav.setModel(BasicModel.buildOKModel().setResult(jsonArray)); - return mav; - } + jsonArray.add(aroundJo); + } + if (!hasData) { + BasicModel.markNoDataRequest(); + } + mav.setModel(BasicModel.buildOKModel().setResult(jsonArray)); + return mav; + } - private void filterAndSortResult(Map> districtAroundMap, - Map districtAroundCountMap, int maxNum) { - for (Map.Entry> entry : districtAroundMap.entrySet()) { - List dtos = entry.getValue(); - districtAroundCountMap.put(entry.getKey(), CollectionUtils.isEmpty(dtos) ? 0 : dtos.size()); - if (dtos != null && dtos.size() > 1) { - Collections.sort(dtos, new Comparator() { - @Override - public int compare(AroundDto o1, AroundDto o2) { - return o1.getDistance() - o2.getDistance(); - } - }); - } - if (maxNum < Integer.MAX_VALUE) { - dtos = dtos.subList(0, Math.min(dtos.size(), maxNum)); - } - districtAroundMap.put(entry.getKey(), dtos); - } - } + private void filterAndSortResult(Map> districtAroundMap, + Map districtAroundCountMap, int maxNum) { + for (Map.Entry> entry : districtAroundMap.entrySet()) { + List dtos = entry.getValue(); + districtAroundCountMap.put(entry.getKey(), CollectionUtils.isEmpty(dtos) ? 0 : dtos.size()); + if (dtos != null && dtos.size() > 1) { + Collections.sort(dtos, new Comparator() { + @Override + public int compare(AroundDto o1, AroundDto o2) { + return o1.getDistance() - o2.getDistance(); + } + }); + } + if (maxNum < Integer.MAX_VALUE) { + dtos = dtos.subList(0, Math.min(dtos.size(), maxNum)); + } + districtAroundMap.put(entry.getKey(), dtos); + } + } - /** - * 获取JSON参数中的num参数值 - * - * @param jo - * @return - */ - private Integer getNum(JSONObject jo) { - Integer num = Integer.MAX_VALUE; - if (jo.containsKey("num")) { - try { - if (!jo.getString("num").matches("\\d+")) { - num = null; - } else { - num = jo.getInt("num"); - if (num <= 0) { - num = null; - } - } - } catch (Exception e) { - num = null; - } - } - return num; - } + /** + * 获取JSON参数中的num参数值 + * + * @param jo + * @return + */ + private Integer getNum(JSONObject jo) { + Integer num = Integer.MAX_VALUE; + if (jo.containsKey("num")) { + try { + if (!jo.getString("num").matches("\\d+")) { + num = null; + } else { + num = jo.getInt("num"); + if (num <= 0) { + num = null; + } + } + } catch (Exception e) { + num = null; + } + } + return num; + } - /** - * 获取JSON参数中的radius值 - * - * @param jo - * @return - */ - private Double getRadius(JSONObject jo) { - Double radius = 1000d; - if (jo.containsKey("radius")) { - try { - radius = jo.getDouble("radius"); - if (radius <= 0 || radius > 5000) { - radius = null; - } - } catch (Exception e) { - radius = null; - } - } - return radius; - } + /** + * 获取JSON参数中的radius值 + * + * @param jo + * @return + */ + private Double getRadius(JSONObject jo) { + Double radius = 1000d; + if (jo.containsKey("radius")) { + try { + radius = jo.getDouble("radius"); + if (radius <= 0 || radius > 5000) { + radius = null; + } + } catch (Exception e) { + radius = null; + } + } + return radius; + } - private void addToDistrictAroundMap(Map> districtAroundMap, - Map> stationMap, District district, String type) { - List busList = stationMap.get(type); - Set stationCache = Sets.newHashSet();// 记录是否有重复站点 - List aroundDtos = Lists.newArrayList(); - double lat = district.getLat2() / 10000000000d; - double lng = district.getLng2() / 10000000000d; - if (CollectionUtils.isNotEmpty(busList)) { - for (BusStation bs : busList) { - if (stationCache.add(bs.getStation())) { - AroundDto aroundDto = new AroundDto(); - aroundDto.setLat(bs.getLat()); - aroundDto.setLng(bs.getLng()); - aroundDto.setName(bs.getStation()); - aroundDto.setDistance((int) GeoUtils.calculateDistance(lng, lat, bs.getLng(), bs.getLat())); - aroundDtos.add(aroundDto); - } - } - String key = AROUND_KEYWORD_FACTOR_NEW.get(type); - districtAroundMap.put(key, aroundDtos); - } - } + private void addToDistrictAroundMap(Map> districtAroundMap, + Map> stationMap, District district, String type) { + List busList = stationMap.get(type); + Set stationCache = Sets.newHashSet();// 记录是否有重复站点 + List aroundDtos = Lists.newArrayList(); + double lat = district.getLat2() / 10000000000d; + double lng = district.getLng2() / 10000000000d; + if (CollectionUtils.isNotEmpty(busList)) { + for (BusStation bs : busList) { + if (stationCache.add(bs.getStation())) { + AroundDto aroundDto = new AroundDto(); + aroundDto.setLat(bs.getLat()); + aroundDto.setLng(bs.getLng()); + aroundDto.setName(bs.getStation()); + aroundDto.setDistance((int) GeoUtils.calculateDistance(lng, lat, bs.getLng(), bs.getLat())); + aroundDtos.add(aroundDto); + } + } + String key = AROUND_KEYWORD_FACTOR_NEW.get(type); + districtAroundMap.put(key, aroundDtos); + } + } - public Object searchRoomAction(PropertyEvaluationModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity())) { - mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getKeyword())) { - mav.setModel(BasicModel.buildBadRequestModel("keyword(关键词)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getUnitNumber())) { - mav.setModel(BasicModel.buildBadRequestModel("unitNumber(室号)不能为空")); - return mav; - } + public Object searchRoomAction(PropertyEvaluationModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getKeyword())) { + mav.setModel(BasicModel.buildBadRequestModel("keyword(关键词)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getUnitNumber())) { + mav.setModel(BasicModel.buildBadRequestModel("unitNumber(室号)不能为空")); + return mav; + } - District district = null; - // if(StringUtils.isNotBlank(model.getDistrict())){ - district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getKeyword(), - "district"); - // } - if (district == null) { - Map result = addressParser.parse2(model.getCity(), model.getKeyword(), "district", false); - saveAddressMatchLog(result, model.getKeyword(), model.getCity(), model.getToken()); - Integer status = (Integer) result.get("status"); - Integer precise = (Integer) result.get("precise"); - if (status != null && status == 0 && precise == 0) { - String id = (String) result.get("id"); - District matchDistrict = districtService.findById(id); - if (StringUtils.isBlank(model.getDistrict()) || model.getDistrict().equals(matchDistrict.getRegion())) { - district = matchDistrict; - } - } else { - saveAddressMatchLog(result, model.getKeyword(), model.getCity(), model.getToken()); - } - } - if (district == null) { - mav.setModel(BasicModel.buildOKModel()); - return mav; - } - HouseLoudong loudong = houseLoudongService.findHouseLoudong(district.getCity(), district.getRegion(), - district.getName(), model.getBuildingNumber(), "1", model.getUnitNumber()); - if (loudong != null) { - mav.setModel(BasicModel.buildOKModel().setResult(convertToRoomInfo(loudong, district, model.isConvert()))); - return mav; - } - FjtEvaluation fjtEvaluation = fjtEvaluationService.findFjtEvaluationByConditions(district.getCity(), - district.getRegion(), district.getName(), model.getBuildingNumber(), model.getUnitNumber()); - if (fjtEvaluation != null) { - mav.setModel(BasicModel.buildOKModel().setResult(convertToRoomInfo(fjtEvaluation, district, model.isConvert()))); - return mav; - } + District district = null; + // if(StringUtils.isNotBlank(model.getDistrict())){ + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getKeyword(), + "district"); + // } + if (district == null) { + Map result = addressParser.parse2(model.getCity(), model.getKeyword(), "district", false); + saveAddressMatchLog(result, model.getKeyword(), model.getCity(), model.getToken()); + Integer status = (Integer) result.get("status"); + Integer precise = (Integer) result.get("precise"); + if (status != null && status == 0 && precise == 0) { + String id = (String) result.get("id"); + District matchDistrict = districtService.findById(id); + if (StringUtils.isBlank(model.getDistrict()) || model.getDistrict().equals(matchDistrict.getRegion())) { + district = matchDistrict; + } + } else { + saveAddressMatchLog(result, model.getKeyword(), model.getCity(), model.getToken()); + } + } + if (district == null) { + mav.setModel(BasicModel.buildOKModel()); + return mav; + } + HouseLoudong loudong = houseLoudongService.findHouseLoudong(district.getCity(), district.getRegion(), + district.getName(), model.getBuildingNumber(), "1", model.getUnitNumber()); + if (loudong != null) { + mav.setModel(BasicModel.buildOKModel().setResult(convertToRoomInfo(loudong, district, model.isConvert()))); + return mav; + } + FjtEvaluation fjtEvaluation = fjtEvaluationService.findFjtEvaluationByConditions(district.getCity(), + district.getRegion(), district.getName(), model.getBuildingNumber(), model.getUnitNumber()); + if (fjtEvaluation != null) { + mav.setModel(BasicModel.buildOKModel().setResult(convertToRoomInfo(fjtEvaluation, district, model.isConvert()))); + return mav; + } - Evaluation evaluation = evaluationService.findEvaluationByNum(district.getCity(), district.getRegion(), - district.getName(), model.getBuildingNumber(), model.getUnitNumber()); - if (evaluation != null) { - mav.setModel(BasicModel.buildOKModel().setResult(convertToRoomInfo(evaluation, district, model.isConvert()))); - return mav; - } - mav.setModel(BasicModel.buildOKModel()); - return mav; + Evaluation evaluation = evaluationService.findEvaluationByNum(district.getCity(), district.getRegion(), + district.getName(), model.getBuildingNumber(), model.getUnitNumber()); + if (evaluation != null) { + mav.setModel(BasicModel.buildOKModel().setResult(convertToRoomInfo(evaluation, district, model.isConvert()))); + return mav; + } + mav.setModel(BasicModel.buildOKModel()); + return mav; - } + } - /** - * 把房价通估价,房价网估价以及房子信息转成房子信息 - * - * @param in - * @param district - * @param convert - * @return - */ - private Map convertToRoomInfo(Object in, District district, boolean convert) { - LinkedHashMap result = new LinkedHashMap(); - if (in instanceof HouseLoudong) { - HouseLoudong loudong = (HouseLoudong) in; - result.put("city", district.getCity()); - result.put("district", district.getRegion()); - result.put("name", district.getName()); - result.put("address", district.getAddress()); - result.put("propertyType", district.getEstateType2()); - if (loudong.getHouseNum() == null) { - result.put("buildingNumber", ""); - } else { - result.put("buildingNumber", loudong.getHouseNum()); - } - if (null == loudong.getRoomNum()) { - result.put("unitNumber", ""); - } else { - result.put("unitNumber", loudong.getRoomNum()); - } - if (loudong.getHouseArea() > 0) { - result.put("size", DataUtil.roundDouble(loudong.getHouseArea(), 2) + ""); - } else { - result.put("size", ""); - } + /** + * 把房价通估价,房价网估价以及房子信息转成房子信息 + * + * @param in + * @param district + * @param convert + * @return + */ + private Map convertToRoomInfo(Object in, District district, boolean convert) { + LinkedHashMap result = new LinkedHashMap(); + if (in instanceof HouseLoudong) { + HouseLoudong loudong = (HouseLoudong) in; + result.put("city", district.getCity()); + result.put("district", district.getRegion()); + result.put("name", district.getName()); + result.put("address", district.getAddress()); + result.put("propertyType", district.getEstateType2()); + if (loudong.getHouseNum() == null) { + result.put("buildingNumber", ""); + } else { + result.put("buildingNumber", loudong.getHouseNum()); + } + if (null == loudong.getRoomNum()) { + result.put("unitNumber", ""); + } else { + result.put("unitNumber", loudong.getRoomNum()); + } + if (loudong.getHouseArea() > 0) { + result.put("size", DataUtil.roundDouble(loudong.getHouseArea(), 2) + ""); + } else { + result.put("size", ""); + } - if (loudong.getHouseFloor() > 0) { - result.put("floor", loudong.getHouseFloor() + ""); - } else { - result.put("floor", ""); - } - if (loudong.getHouseHeight() > 0) { - result.put("maxFloor", loudong.getHouseHeight() + ""); - } else { - result.put("maxFloor", ""); - } - if (loudong.getRoom() > 0) { - result.put("room", loudong.getRoom() + ""); - } else { - result.put("room", ""); - } - if (loudong.getHall() > 0) { - result.put("hall", loudong.getHall() + ""); - } else { - result.put("hall", ""); - } - if (loudong.getToilet() > 0) { - result.put("toilet", loudong.getToilet() + ""); - } else { - result.put("toilet", ""); - } - if (null == loudong.getDirection()) { - result.put("direction", ""); - } else { - result.put("direction", loudong.getDirection()); - } - if (null == loudong.getFitmentRank()) { - result.put("decoration", ""); - } else { - result.put("decoration", HouseValidator.fetchFitmentInfo(loudong.getFitmentRank())); - } - } else if (in instanceof FjtEvaluation) { - FjtEvaluation fjtEvaluation = (FjtEvaluation) in; - result.put("city", district.getCity()); - result.put("district", district.getRegion()); - result.put("name", district.getName()); - result.put("address", district.getAddress()); - result.put("propertyType", district.getEstateType2()); - if (null == fjtEvaluation.getHouseNum()) { - result.put("buildingNumber", ""); - } else { - result.put("buildingNumber", fjtEvaluation.getHouseNum()); - } - if (null == fjtEvaluation.getHouseNum()) { - result.put("unitNumber", ""); - } else { - result.put("unitNumber", fjtEvaluation.getRoomNum()); - } + if (loudong.getHouseFloor() > 0) { + result.put("floor", loudong.getHouseFloor() + ""); + } else { + result.put("floor", ""); + } + if (loudong.getHouseHeight() > 0) { + result.put("maxFloor", loudong.getHouseHeight() + ""); + } else { + result.put("maxFloor", ""); + } + if (loudong.getRoom() > 0) { + result.put("room", loudong.getRoom() + ""); + } else { + result.put("room", ""); + } + if (loudong.getHall() > 0) { + result.put("hall", loudong.getHall() + ""); + } else { + result.put("hall", ""); + } + if (loudong.getToilet() > 0) { + result.put("toilet", loudong.getToilet() + ""); + } else { + result.put("toilet", ""); + } + if (null == loudong.getDirection()) { + result.put("direction", ""); + } else { + result.put("direction", loudong.getDirection()); + } + if (null == loudong.getFitmentRank()) { + result.put("decoration", ""); + } else { + result.put("decoration", HouseValidator.fetchFitmentInfo(loudong.getFitmentRank())); + } + } else if (in instanceof FjtEvaluation) { + FjtEvaluation fjtEvaluation = (FjtEvaluation) in; + result.put("city", district.getCity()); + result.put("district", district.getRegion()); + result.put("name", district.getName()); + result.put("address", district.getAddress()); + result.put("propertyType", district.getEstateType2()); + if (null == fjtEvaluation.getHouseNum()) { + result.put("buildingNumber", ""); + } else { + result.put("buildingNumber", fjtEvaluation.getHouseNum()); + } + if (null == fjtEvaluation.getHouseNum()) { + result.put("unitNumber", ""); + } else { + result.put("unitNumber", fjtEvaluation.getRoomNum()); + } - if (fjtEvaluation.getHouseArea() > 0) { - result.put("size", DataUtil.roundDouble(fjtEvaluation.getHouseArea(), 2) + ""); - } else { - result.put("size", ""); - } - if (fjtEvaluation.getHouseFloor() > 0) { - result.put("floor", fjtEvaluation.getHouseFloor() + ""); - } else { - result.put("floor", ""); - } - if (fjtEvaluation.getHouseHight() > 0) { - result.put("maxFloor", fjtEvaluation.getHouseHight() + ""); - } else { - result.put("maxFloor", ""); - } - if (fjtEvaluation.getHouseRoom() != null) { - result.put("room", fjtEvaluation.getHouseRoom().toString()); - } else { - result.put("room", ""); - } - if (fjtEvaluation.getHouseHall() != null) { - result.put("hall", fjtEvaluation.getHouseHall().toString()); - } else { - result.put("room", ""); - } - if (FJT_DIRECTION.get(fjtEvaluation.getDirection() + "") == null) { - result.put("direction", ""); - } else { - result.put("direction", FJT_DIRECTION.get(fjtEvaluation.getDirection() + "")); - } - if (FJT_FITMENT.get(fjtEvaluation.getFitment() + "") == null) { - result.put("decoration", ""); - } else { - result.put("decoration", - HouseValidator.fetchFitmentInfo(FJT_FITMENT.get(fjtEvaluation.getFitment() + ""))); - } - } else if (in instanceof Evaluation) { - Evaluation evaluation = (Evaluation) in; - result.put("city", district.getCity()); - result.put("district", district.getRegion()); - result.put("name", district.getName()); - result.put("address", district.getAddress()); - result.put("propertyType", district.getEstateType2()); - if (null == evaluation.getHouseNum()) { - result.put("buildingNumber", ""); - } else { - result.put("buildingNumber", evaluation.getHouseNum()); - } - if (null == evaluation.getRoomNum()) { - result.put("unitNumber", ""); - } else { - result.put("unitNumber", evaluation.getRoomNum()); - } - if (null == evaluation.getArea() || evaluation.getArea() < 0) { - result.put("size", ""); - } else { - result.put("size", DataUtil.roundDouble(evaluation.getArea(), 2) + ""); - } - if (null == evaluation.getFloor() || evaluation.getFloor() < 0) { - result.put("floor", ""); - } else { - result.put("floor", evaluation.getFloor().toString()); - } - if (null == evaluation.getHeight() || evaluation.getHeight() < 0) { - result.put("maxFloor", ""); - } else { - result.put("maxFloor", evaluation.getHeight().toString()); - } - if (evaluation.getRoom() != null && evaluation.getRoom() > 0) { - result.put("room", evaluation.getRoom().toString()); - } else { - result.put("room", 0); - } - if (evaluation.getHall() != null && evaluation.getHall() > 0) { - result.put("hall", evaluation.getHall().toString()); - } else { - result.put("hall", ""); - } - if (evaluation.getToilet() != null && evaluation.getToilet() > 0) { - result.put("toilet", evaluation.getToilet().toString()); - } else { - result.put("toilet", ""); - } - if (evaluation.getDirection() == null) { - result.put("direction", ""); - } else { - result.put("direction", evaluation.getDirection()); - } - if (evaluation.getFitment() == null) { - result.put("decoration", ""); - } else { - result.put("decoration", HouseValidator.fetchFitmentInfo(evaluation.getFitment())); - } - } + if (fjtEvaluation.getHouseArea() > 0) { + result.put("size", DataUtil.roundDouble(fjtEvaluation.getHouseArea(), 2) + ""); + } else { + result.put("size", ""); + } + if (fjtEvaluation.getHouseFloor() > 0) { + result.put("floor", fjtEvaluation.getHouseFloor() + ""); + } else { + result.put("floor", ""); + } + if (fjtEvaluation.getHouseHight() > 0) { + result.put("maxFloor", fjtEvaluation.getHouseHight() + ""); + } else { + result.put("maxFloor", ""); + } + if (fjtEvaluation.getHouseRoom() != null) { + result.put("room", fjtEvaluation.getHouseRoom().toString()); + } else { + result.put("room", ""); + } + if (fjtEvaluation.getHouseHall() != null) { + result.put("hall", fjtEvaluation.getHouseHall().toString()); + } else { + result.put("room", ""); + } + if (FJT_DIRECTION.get(fjtEvaluation.getDirection() + "") == null) { + result.put("direction", ""); + } else { + result.put("direction", FJT_DIRECTION.get(fjtEvaluation.getDirection() + "")); + } + if (FJT_FITMENT.get(fjtEvaluation.getFitment() + "") == null) { + result.put("decoration", ""); + } else { + result.put("decoration", + HouseValidator.fetchFitmentInfo(FJT_FITMENT.get(fjtEvaluation.getFitment() + ""))); + } + } else if (in instanceof Evaluation) { + Evaluation evaluation = (Evaluation) in; + result.put("city", district.getCity()); + result.put("district", district.getRegion()); + result.put("name", district.getName()); + result.put("address", district.getAddress()); + result.put("propertyType", district.getEstateType2()); + if (null == evaluation.getHouseNum()) { + result.put("buildingNumber", ""); + } else { + result.put("buildingNumber", evaluation.getHouseNum()); + } + if (null == evaluation.getRoomNum()) { + result.put("unitNumber", ""); + } else { + result.put("unitNumber", evaluation.getRoomNum()); + } + if (null == evaluation.getArea() || evaluation.getArea() < 0) { + result.put("size", ""); + } else { + result.put("size", DataUtil.roundDouble(evaluation.getArea(), 2) + ""); + } + if (null == evaluation.getFloor() || evaluation.getFloor() < 0) { + result.put("floor", ""); + } else { + result.put("floor", evaluation.getFloor().toString()); + } + if (null == evaluation.getHeight() || evaluation.getHeight() < 0) { + result.put("maxFloor", ""); + } else { + result.put("maxFloor", evaluation.getHeight().toString()); + } + if (evaluation.getRoom() != null && evaluation.getRoom() > 0) { + result.put("room", evaluation.getRoom().toString()); + } else { + result.put("room", 0); + } + if (evaluation.getHall() != null && evaluation.getHall() > 0) { + result.put("hall", evaluation.getHall().toString()); + } else { + result.put("hall", ""); + } + if (evaluation.getToilet() != null && evaluation.getToilet() > 0) { + result.put("toilet", evaluation.getToilet().toString()); + } else { + result.put("toilet", ""); + } + if (evaluation.getDirection() == null) { + result.put("direction", ""); + } else { + result.put("direction", evaluation.getDirection()); + } + if (evaluation.getFitment() == null) { + result.put("decoration", ""); + } else { + result.put("decoration", HouseValidator.fetchFitmentInfo(evaluation.getFitment())); + } + } - return result; + return result; - } + } - public AddressParser getAddressParser() { - return addressParser; - } + public AddressParser getAddressParser() { + return addressParser; + } - public void setAddressParser(AddressParser addressParser) { - this.addressParser = addressParser; - } + public void setAddressParser(AddressParser addressParser) { + this.addressParser = addressParser; + } - private String convertToString(String[] strs) { - if (ArrayUtils.isNotEmpty(strs)) { - StringBuffer ret = new StringBuffer(); - for (String str : strs) { - if (StringUtils.isEmpty(ret.toString())) { - ret.append(str); - } else { - ret.append(",").append(str); - } - } - return ret.toString(); - } - return null; - } + private String convertToString(String[] strs) { + if (ArrayUtils.isNotEmpty(strs)) { + StringBuffer ret = new StringBuffer(); + for (String str : strs) { + if (StringUtils.isEmpty(ret.toString())) { + ret.append(str); + } else { + ret.append(",").append(str); + } + } + return ret.toString(); + } + return null; + } - private List findDealPricesByNames(String city, String region, List names, int max, - DealPriceModel model) { - List params = new ArrayList(); - params.add(new QueryParam("city", city)); - params.add(new QueryParam("region", region)); - params.add(new QueryParam("districtName", QueryParam.IN_OPERATOR, names)); - if (model.getRoom() != null) { - params.add(new QueryParam("room", model.getRoom())); - } - if (model.getHall() != null) { - params.add(new QueryParam("hall", model.getHall())); - } - // 18年之后抓住的数据没有score字段 + private List findDealPricesByNames(String city, String region, List names, int max, + DealPriceModel model) { + List params = new ArrayList(); + params.add(new QueryParam("city", city)); + params.add(new QueryParam("region", region)); + params.add(new QueryParam("districtName", QueryParam.IN_OPERATOR, names)); + if (model.getRoom() != null) { + params.add(new QueryParam("room", model.getRoom())); + } + if (model.getHall() != null) { + params.add(new QueryParam("hall", model.getHall())); + } + // 18年之后抓住的数据没有score字段 // params.add(new QueryParam("score", QueryParam.GREATER_THAN_OPERATOR, 200000000000l)); - List dealPrices = dealPriceService.findDealPrices(params, max); - List distinctDealPrices = new ArrayList(); - for (DealPrice dealPrice : dealPrices) { - if (dealPrice.getAvgPrice() == null) { - dealPrice.setAvgPrice((int) (dealPrice.getTotalPrice() / dealPrice.getArea())); - } - if (!checkExists(distinctDealPrices, dealPrice)) { - distinctDealPrices.add(dealPrice); - } - } - return distinctDealPrices; - } + List dealPrices = dealPriceService.findDealPrices(params, max); + List distinctDealPrices = new ArrayList(); + for (DealPrice dealPrice : dealPrices) { + if (dealPrice.getAvgPrice() == null) { + dealPrice.setAvgPrice((int) (dealPrice.getTotalPrice() / dealPrice.getArea())); + } + if (!checkExists(distinctDealPrices, dealPrice)) { + distinctDealPrices.add(dealPrice); + } + } + return distinctDealPrices; + } - private List findDealPricesByName(String city, String region, String name, int max, - DealPriceModel model) { - List params = new ArrayList(); - params.add(new QueryParam("city", city)); - params.add(new QueryParam("region", region)); - params.add(new QueryParam("districtName", name)); - if (model.getRoom() != null) { - params.add(new QueryParam("room", model.getRoom())); - } - if (model.getHall() != null) { - params.add(new QueryParam("hall", model.getHall())); - } - // 18年之后抓住的数据没有score字段 + private List findDealPricesByName(String city, String region, String name, int max, + DealPriceModel model) { + List params = new ArrayList(); + params.add(new QueryParam("city", city)); + params.add(new QueryParam("region", region)); + params.add(new QueryParam("districtName", name)); + if (model.getRoom() != null) { + params.add(new QueryParam("room", model.getRoom())); + } + if (model.getHall() != null) { + params.add(new QueryParam("hall", model.getHall())); + } + // 18年之后抓住的数据没有score字段 // params.add(new QueryParam("score", QueryParam.GREATER_THAN_OPERATOR, 200000000000l)); - List dealPrices = dealPriceService.findDealPrices(params, max); - List distinctDealPrices = new ArrayList(); - for (DealPrice dealPrice : dealPrices) { - if (dealPrice.getAvgPrice() == null) { - dealPrice.setAvgPrice((int) (dealPrice.getTotalPrice() / dealPrice.getArea())); - } - if (!checkExists(distinctDealPrices, dealPrice)) { - distinctDealPrices.add(dealPrice); - } - } - return distinctDealPrices; - } + List dealPrices = dealPriceService.findDealPrices(params, max); + List distinctDealPrices = new ArrayList(); + for (DealPrice dealPrice : dealPrices) { + if (dealPrice.getAvgPrice() == null) { + dealPrice.setAvgPrice((int) (dealPrice.getTotalPrice() / dealPrice.getArea())); + } + if (!checkExists(distinctDealPrices, dealPrice)) { + distinctDealPrices.add(dealPrice); + } + } + return distinctDealPrices; + } - private boolean checkExists(List dealPrices, DealPrice dealPrice) { - for (DealPrice bo : dealPrices) { - if (bo.getArea().equals(dealPrice.getArea()) && bo.getAvgPrice().equals(dealPrice.getAvgPrice()) - && bo.getTradeDate().equals(dealPrice.getTradeDate())) { - return true; - } - } - return false; - } + private boolean checkExists(List dealPrices, DealPrice dealPrice) { + for (DealPrice bo : dealPrices) { + if (bo.getArea().equals(dealPrice.getArea()) && bo.getAvgPrice().equals(dealPrice.getAvgPrice()) + && bo.getTradeDate().equals(dealPrice.getTradeDate())) { + return true; + } + } + return false; + } - private void orderHouseList(List houseBoList, final DealPriceModel model) { + private void orderHouseList(List houseBoList, final DealPriceModel model) { - Integer floor = null; - final Double size = model.getSize(); + Integer floor = null; + final Double size = model.getSize(); - try { - floor = Integer.valueOf(model.getFloor()); - } catch (Exception e) { + try { + floor = Integer.valueOf(model.getFloor()); + } catch (Exception e) { - } - final Integer fFloor = floor; + } + final Integer fFloor = floor; - Collections.sort(houseBoList, new Comparator() { - @Override - public int compare(NewHousePojo o1, NewHousePojo o2) { - Double score1 = computeScore(o1); - Double score2 = computeScore(o2); - return score2.compareTo(score1); - } + Collections.sort(houseBoList, new Comparator() { + @Override + public int compare(NewHousePojo o1, NewHousePojo o2) { + Double score1 = computeScore(o1); + Double score2 = computeScore(o2); + return score2.compareTo(score1); + } - private double computeScore(NewHousePojo bo) { - double score = 0; - if (StringUtils.isNotBlank(bo.getFloor()) && fFloor != null) { - double _floor = Double.valueOf(bo.getFloor()); - score += computeAreaScore(_floor, fFloor) * 0.02; - } - if (StringUtils.isNotBlank(bo.getSize()) && size != null) { - double _size = Double.valueOf(bo.getSize()); - score += computeAreaScore(_size, size) * 0.98; - } - return score; - } + private double computeScore(NewHousePojo bo) { + double score = 0; + if (StringUtils.isNotBlank(bo.getFloor()) && fFloor != null) { + double _floor = Double.valueOf(bo.getFloor()); + score += computeAreaScore(_floor, fFloor) * 0.02; + } + if (StringUtils.isNotBlank(bo.getSize()) && size != null) { + double _size = Double.valueOf(bo.getSize()); + score += computeAreaScore(_size, size) * 0.98; + } + return score; + } - private double computeAreaScore(double a1, double a2) { - return 2 / (1 + Math.exp(Math.abs(1 - a1 / a2))); - } + private double computeAreaScore(double a1, double a2) { + return 2 / (1 + Math.exp(Math.abs(1 - a1 / a2))); + } - }); - } + }); + } - /** - * ????С????? - * - * @param district - * @return - */ - private FacetQueryResult findDistrictHouses(District district, int max) { - return houseService.findHouses(district, null, 0, max); - } + /** + * ????С????? + * + * @param district + * @return + */ + private FacetQueryResult findDistrictHouses(District district, int max) { + return houseService.findHouses(district, null, 0, max); + } - /** - * 新版token验证 - * - * @param token - * @return - */ - private ApiUser checkNewAuthorized(String token) { - Map tokenMap = FangjiaApiUtil.parseToken(token); - if (tokenMap == null) { - return null; - } - // token验证后,拿取出的字段再去数据库验证一遍 - if (StringUtils.isNotBlank(tokenMap.get("userid")) && !"null".equals(tokenMap.get("userid"))) { - List params = new ArrayList(); - params.add(new QueryParam("ID", tokenMap.get("userid"))); - ApiUser apiUser = apiUserService.findApiUserById(Long.parseLong(tokenMap.get("userid"))); - if (apiUser != null) { - if (tokenMap.get("appKey").equals(apiUser.getAppKey())) { - return apiUser; - } - } - } - return null; - } + /** + * 新版token验证 + * + * @param token + * @return + */ + private ApiUser checkNewAuthorized(String token) { + Map tokenMap = FangjiaApiUtil.parseToken(token); + if (tokenMap == null) { + return null; + } + // token验证后,拿取出的字段再去数据库验证一遍 + if (StringUtils.isNotBlank(tokenMap.get("userid")) && !"null".equals(tokenMap.get("userid"))) { + List params = new ArrayList(); + params.add(new QueryParam("ID", tokenMap.get("userid"))); + ApiUser apiUser = apiUserService.findApiUserById(Long.parseLong(tokenMap.get("userid"))); + if (apiUser != null) { + if (tokenMap.get("appKey").equals(apiUser.getAppKey())) { + return apiUser; + } + } + } + return null; + } - private JSONObject getJsonParam(HttpServletRequest request) { - JSONObject jo = null; - StringBuffer sb = new StringBuffer(); - try { - BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8")); - String line; - while ((line = br.readLine()) != null) { - sb.append(line); - } - try { - jo = JSONObject.fromObject(sb.toString()); - } catch (Exception e) { - LOGGER.error("getJsonParam:" + sb.toString()); - } - } catch (Exception e) { - jo = null; - } + private JSONObject getJsonParam(HttpServletRequest request) { + JSONObject jo = null; + StringBuffer sb = new StringBuffer(); + try { + BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8")); + String line; + while ((line = br.readLine()) != null) { + sb.append(line); + } + try { + jo = JSONObject.fromObject(sb.toString()); + } catch (Exception e) { + LOGGER.error("getJsonParam:" + sb.toString()); + } + } catch (Exception e) { + jo = null; + } - return jo; - } + return jo; + } - private List fillDistrictInfoForHouse(FacetQueryResult houseList, - District district, boolean convert) { - FacetQueryResult list = new FacetQueryResult(); - for (com.fangjia.service.bo.HouseBo bo : houseList) { - House house = bo.getHouse(); - NewHousePojo b = new NewHousePojo(); - b.setCity(house.getCity()); - b.setDistrict(district.getRegion()); - if (null == district.getBlock()) { - b.setBlock(""); - } else { - b.setBlock(district.getBlock()); - } - b.setName(district.getName()); - b.setAddress(bo.getAddress() == null ? district.getAddress() : bo.getAddress()); - if (house.getArea() != null) { - b.setSize(house.getArea().toString()); - } else { - b.setSize(""); - } - if (house.getTotalPrice() != null) { - b.setListingPrice(house.getTotalPrice().toString()); - } else { - b.setListingPrice(""); - } - if (b.getSize() != null && b.getListingPrice() != null && house.getArea() != 0) { - b.setAvgPrice((int) (house.getTotalPrice() / house.getArea())); - if (b.getAvgPrice() > 300000 || b.getAvgPrice() < 1000) { - continue; - } - } + private List fillDistrictInfoForHouse(FacetQueryResult houseList, + District district, boolean convert) { + FacetQueryResult list = new FacetQueryResult(); + for (com.fangjia.service.bo.HouseBo bo : houseList) { + House house = bo.getHouse(); + NewHousePojo b = new NewHousePojo(); + b.setCity(house.getCity()); + b.setDistrict(district.getRegion()); + if (null == district.getBlock()) { + b.setBlock(""); + } else { + b.setBlock(district.getBlock()); + } + b.setName(district.getName()); + b.setAddress(bo.getAddress() == null ? district.getAddress() : bo.getAddress()); + if (house.getArea() != null) { + b.setSize(house.getArea().toString()); + } else { + b.setSize(""); + } + if (house.getTotalPrice() != null) { + b.setListingPrice(house.getTotalPrice().toString()); + } else { + b.setListingPrice(""); + } + if (b.getSize() != null && b.getListingPrice() != null && house.getArea() != 0) { + b.setAvgPrice((int) (house.getTotalPrice() / house.getArea())); + if (b.getAvgPrice() > 300000 || b.getAvgPrice() < 1000) { + continue; + } + } - if (house.getFloor() != null && house.getFloor() > 0) { - b.setFloor(house.getFloor().toString()); - } else { - b.setFloor(""); - } - if (house.getHeight() != null && house.getHeight() > 0) { - b.setMaxFloor(house.getHeight().toString()); - } else { - b.setMaxFloor(""); - } - if (null != house.getRoom() && house.getRoom() > 0) { - b.setRoom(house.getRoom().toString()); - } else { - b.setRoom(""); - } - if (null != house.getHall() && house.getHall() > 0) { - b.setHall(house.getHall().toString()); - } else { - b.setHall(""); - } - if (null != house.getToilet() && house.getToilet() > 0) { - b.setToilet(house.getToilet().toString()); - } else { - b.setToilet(""); - } - String fitment = HouseValidator.fetchFitmentInfo(house.getFitment()); - if (null != fitment) { - b.setDecoration(fitment); - } else { - b.setDecoration(""); - } - String direction = HouseValidator.fetchDirectionInfo(house.getDirection()); - if (null != direction) { - b.setDirection(direction); - } else { - b.setDirection(""); - } + if (house.getFloor() != null && house.getFloor() > 0) { + b.setFloor(house.getFloor().toString()); + } else { + b.setFloor(""); + } + if (house.getHeight() != null && house.getHeight() > 0) { + b.setMaxFloor(house.getHeight().toString()); + } else { + b.setMaxFloor(""); + } + if (null != house.getRoom() && house.getRoom() > 0) { + b.setRoom(house.getRoom().toString()); + } else { + b.setRoom(""); + } + if (null != house.getHall() && house.getHall() > 0) { + b.setHall(house.getHall().toString()); + } else { + b.setHall(""); + } + if (null != house.getToilet() && house.getToilet() > 0) { + b.setToilet(house.getToilet().toString()); + } else { + b.setToilet(""); + } + String fitment = HouseValidator.fetchFitmentInfo(house.getFitment()); + if (null != fitment) { + b.setDecoration(fitment); + } else { + b.setDecoration(""); + } + String direction = HouseValidator.fetchDirectionInfo(house.getDirection()); + if (null != direction) { + b.setDirection(direction); + } else { + b.setDirection(""); + } // if (house.getPics() != null && !house.getPics().isEmpty()) { // b.setPic(transformPicsToFangJia(house.getPics().get(house.getPics().size() / 2))); // } else { // b.setPic(""); // } - if (house.getPublishDate() != null) { - if (new Date().before(house.getPublishDate())) { - house.setPublishDate(house.getModificationDate()); - } else { - house.setPublishDate(house.getPublishDate()); - } - } - if (house.getPublishDate() == null) { - b.setPublishDate("");// 发布时间 - } else { - b.setPublishDate(DateUtil.formatByPattern(house.getPublishDate(), "yyyy-MM-dd"));// 发布时间 - } - b.setSource(getDomainName(house.getUrl())); - if (HouseValidator.validateBuildingType(house.getBuildType())) { - b.setBuildingType(house.getBuildType()); - } - if (HouseValidator.validateArea(house.getArea()) && !checkExists(list, b)) { - list.add(b); - } - - } - return list; - } - - // 200~900ms - public Object similarAction(PropertyEvaluationModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity())) { - mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getName())) { - mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); - return mav; - } - if (0 >= model.getSize()) { - mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能为空")); - return mav; - } - // 在库中找到对应的小区 - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - // 查找均价 - List districtStats = districtStatService.findAllDistrictStatsSort(district.getCity(), - district.getRegion(), district.getName(), model.getCalDate()); - Integer districtAvg = 0; - if (districtStats != null && !districtStats.isEmpty()) { - DistrictStat districtStat = districtStats.get(0); - districtAvg = districtStat.getAvgPrice(); - } - Integer avgPrice = 0; - Integer tatalPrice = 0; - int count = 0; - List listHouse = similarCommMethod(model, "similar", district); - for (House house : listHouse) { - long temp = Math.round(house.getTotalPrice() / house.getArea()); - // 均价范围在0.8~1.2 - if (temp > districtAvg * 1.3 || temp < districtAvg * 0.7) { - continue; - } - avgPrice = (int) temp + avgPrice; - count++; - } - - if (count == 0) { - mav.setModel(BasicModel.buildOKModel().setMsg("该小区无均价")); - return mav; - } - avgPrice = avgPrice / count; - tatalPrice = (int)Math.round(avgPrice * model.getSize()); - Map districtPriceMap = new HashMap(); - districtPriceMap.put("city", district.getCity()); - districtPriceMap.put("district", district.getRegion()); - districtPriceMap.put("name", district.getName()); - districtPriceMap.put("totalPrice", tatalPrice); - districtPriceMap.put("avgPrice", avgPrice); - mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); - return mav; - } - - // 寻找相似房源 - public List similarCommMethod(PropertyEvaluationModel model, String kind, District district) { - model.setName(district.getName()); - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (model.getCalDate() != null) { - model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } - List listHouse = new ArrayList(); - FacetQueryResult houseBos = houseService.findSeabirdHouses(district, 0, 1000); - if ("similarSort".equals(kind)) { - listHouse = houseService.findSimilarDistrictParam(houseBos, FJT_DIRECTION.get(model.getDirection()), - FITMENT_MAP.get(model.getFitment()), PROPERTY_TYPES.get(model.getEstateType()), model.getFloor(), - model.getRoom(), model.getHall(), model.getSize(), 1); - } else if ("similar".equals(kind)) { - for (int param = 1; param <= 5; param++) { - listHouse.addAll(houseService.findSimilarDistrict(houseBos, FJT_DIRECTION.get(model.getDirection()), - FITMENT_MAP.get(model.getFitment()), PROPERTY_TYPES.get(model.getEstateType()), - model.getFloor(), model.getRoom(), model.getHall(), model.getSize(), param)); - if (listHouse.size() > 50) { - break; - } - } - } - if (listHouse == null || listHouse.size() < 5) { - List districts = houseService.findAroundDistrict(district); - for (District around : districts) { - FacetQueryResult aroundBos = houseService.findSeabirdHouses(around, 0, 1000); - if (listHouse == null || listHouse.isEmpty()) { - listHouse = houseService.findSimilarDistrict(aroundBos, FJT_DIRECTION.get(model.getDirection()), - FITMENT_MAP.get(model.getFitment()), PROPERTY_TYPES.get(model.getEstateType()), - model.getFloor(), model.getRoom(), model.getHall(), model.getSize(), 3); - } else { - listHouse - .addAll(houseService.findSimilarDistrict(aroundBos, FJT_DIRECTION.get(model.getDirection()), - FITMENT_MAP.get(model.getFitment()), PROPERTY_TYPES.get(model.getEstateType()), - model.getFloor(), model.getRoom(), model.getHall(), model.getSize(), 3)); - } - if (listHouse.size() > 10) { - break; - } - } - } - return listHouse; - } - - public static final String[] DFIELDS = { "city", "region", "name", "address" }; - - public Object autoCompleteAction(PropertySearchModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity())) { - mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); - return mav; - } - if (!"全国".equals(model.getCity())) { - if (!RegionData.isCity(model.getCity())) { - String city = RegionData.formatCity(model.getCity()); - if (null == city) { - mav.setModel(BasicModel.buildBadRequestModel("非法城市:" + model.getCity())); - return mav; - } else { - model.setCity(city); - } - } - } - - if (StringUtils.isNotBlank(model.getDistrict())) { - model.setDistrict(RegionData.formatRegion(model.getCity(), model.getDistrict())); - } - - if (StringUtils.isBlank(model.getKeyword())) { - mav.setModel(BasicModel.buildBadRequestModel("keyword(关键字)不能为空")); - return mav; - } - - String type = "name"; - if (StringUtils.isNotBlank(model.getFilter())) { - type = model.getFilter(); - } - //强行启用小区库 - if ("true".equals(model.getUseSeaweed())) { - if (model.getMax() == null || model.getMax() < 1 || model.getMax() > 100) { - model.setMax(10); - } - List params = new ArrayList(); - if (!"全国".equals(model.getCity())) { - params.add(new QueryParam("city", model.getCity())); - } - if (StringUtils.isNotBlank(model.getDistrict())) { - params.add(new QueryParam("region", model.getDistrict())); - } - params.add(new QueryParam("category", "district")); - params.add(new QueryParam("visible", 0)); - // BooleanQuery srQuery1 = new BooleanQuery(); - // BooleanQuery nameQuery = new BooleanQuery(); - // nameQuery.add(new TermQuery(new Term("district_name", model.getKeyword())), - // BooleanClause.Occur.SHOULD); - // nameQuery.add(new PrefixQuery(new Term("name", - // QueryParser.escape(model.getKeyword()).toLowerCase())), - // BooleanClause.Occur.SHOULD); - // nameQuery.add(new TermQuery(new Term("alias_std", model.getKeyword())), - // BooleanClause.Occur.SHOULD); - // nameQuery.add(new TermQuery(new Term("address", model.getKeyword())), - // BooleanClause.Occur.SHOULD); - // nameQuery.add(new TermQuery(new Term("addr_alias_std", model.getKeyword())), - // BooleanClause.Occur.SHOULD); - - if (StringUtils.isNotBlank(model.getKeyword())) { - BooleanQuery query = new BooleanQuery(); - if (model.getUseOrQuery()) { - params.add(new QueryParam("$fangjiawang_query_type", "or")); - } - // 2017-11-02新增, 指定查询字段,以:分割为多个字段查询,处理pds搜索问题,不指定默认用keyword查询 - String queryFields = model.getQueryField(); - if (StringUtils.isNotBlank(queryFields) && queryFields.contains(":")) { - String[] fs = queryFields.split(":"); - for (String f : fs) { - Query q1 = new TermQuery(new Term(f, QueryParser.escape(model.getKeyword()).toLowerCase())); - q1.setBoost(0.99f); - query.add(q1, BooleanClause.Occur.SHOULD); - } - } else { - Query q1 = new TermQuery( - new Term(model.getQueryField(), QueryParser.escape(model.getKeyword()).toLowerCase())); - q1.setBoost(0.99f); - query.add(q1, BooleanClause.Occur.SHOULD); - } - - /* - * Query q2 = new TermQuery(new Term("keyword_cjk", - * QueryParser.escape(model.getKeyword()).toLowerCase())); q2.setBoost(0.01f); - * query.add(q2, BooleanClause.Occur.SHOULD); - */ - - /* - * String districtName = tokenDistrictName(model.getKeyword()); - * if(StringUtils.isNotBlank(districtName)){ Query q3 = new TermQuery(new - * Term("keyword_cjk", districtName)); q3.setBoost(0.99f); query.add(q3, - * BooleanClause.Occur.SHOULD); } - */ - // Query query = - // boostQueryDistrictNewPolicy.create(ServiceUtil.removeAndGetKeyword(params)); - params.add(new QueryParam("$sr", new SrQuery(query))); - // params.add(new QueryParam("keyword", - // QueryParser.escape(model.getKeyword()).toLowerCase())); - - } - List districts = districtService.findAllByParams(params, 0, model.getMax(), new String[] { "city", - "region", "name", "alias", "address", "addrAlias", "lat2", "lng2", "householdCount" }); - - List result = new ArrayList(); - if (districts != null) { - for (District district : districts) { - BasicDBObject item = new BasicDBObject(); - item.append("city", district.getCity()); - item.append("district", district.getRegion()); - item.append("name", district.getName()); - item.append("address", district.getAddress()); - item.append("latBaidu", district.getLat2()); - item.append("lngBaidu", district.getLng2()); - item.append("houseHoldCount", district.getHouseholdCount()); - if (district.getAlias() != null && district.getAlias().size() > 0) { - item.append("alias", district.getAlias()); - } - if (CollectionUtils.isNotEmpty(district.getAddrAlias())) { - item.append("address_alias", district.getAddrAlias()); - } - result.add(item); - } - } - mav.setModel(BasicModel.buildOKModel().setResult(result)); - } else { - if (model.getMax() == null || model.getMax() < 1 || model.getMax() > 20) { - model.setMax(10); - } - List autoCompleteBos = autoCompleteService.suggest("district", type, model.getCity(), - model.getKeyword(), model.getMax()); - List result = new ArrayList(); - if (autoCompleteBos != null) { - for (AutoCompleteBo bo : autoCompleteBos) { - BasicDBObject item = new BasicDBObject(); - item.append("city", model.getCity()); - item.append("district", bo.getRegion()); - item.append("name", bo.getVal()); - item.append("address", bo.getDesc()); - result.add(item); - } - } - mav.setModel(BasicModel.buildOKModel().setResult(result)); - } - - return mav; - } - - /** - * 解析出关键字中的小区名 - * - * @param keyword - * @return - */ - private String tokenDistrictName(String keyword) { - List tokens = CnTokenizer.tokenizer(keyword); - Token token = getTokenByType(tokens, KeywordEnum.district); - if (token != null && "district".equals(token.getKeywordTypes())) { - return token.getName(); - } - return null; - } - - private Token getTokenByType(List tokens, KeywordEnum type) { - for (Token token : tokens) { - if (token.containsType(type)) { - return token; - } - } - return null; - } - - public Object similarSortAction(PropertyEvaluationModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity())) { - mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); - return mav; - } - if (StringUtils.isBlank(model.getName())) { - mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); - return mav; - } - if (0 >= model.getSize()) { - mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能为空")); - return mav; - } - // 在库中找到对应的小区 - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),"district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - - Integer avgPrice = 0; - Integer tatalPrice = 0; - int count = 0; - List listHouse = similarCommMethod(model, "similarSort", district); - - // 查找均价 - List districtStats = districtStatService.findAllDistrictStatsSort(district.getCity(), - district.getRegion(), district.getName(), model.getCalDate()); - Integer districtAvg = 0; - if (districtStats != null && !districtStats.isEmpty()) { - DistrictStat districtStat = districtStats.get(0); - districtAvg = districtStat.getAvgPrice(); - } - for (House house : listHouse) { - long temp = Math.round(house.getTotalPrice() / house.getArea()); - if (temp > districtAvg * 1.3 || temp < districtAvg * 0.7) { - continue; - } - avgPrice = (int) temp + avgPrice; - count++; - } - if (count == 0) { - mav.setModel(BasicModel.buildOKModel().setMsg("该小区无均价")); - return mav; - } - avgPrice = avgPrice / count; - tatalPrice = (int)Math.round(avgPrice * model.getSize()); - Map districtPriceMap = new HashMap(); - districtPriceMap.put("city", district.getCity()); - districtPriceMap.put("district", district.getRegion()); - districtPriceMap.put("name", district.getName()); - districtPriceMap.put("totalPrice", tatalPrice); - districtPriceMap.put("avgPrice", avgPrice); - mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); - return mav; - } - - public String getDomainName(String url) { - if (StringUtils.isNotBlank(url)) { - Pattern p = Pattern.compile("[^//]*?\\.(com|cn|net|org|biz|info|cc|tv)", Pattern.CASE_INSENSITIVE); - Matcher matcher = p.matcher(url); - if (matcher.find()) { - return matcher.group(); - } - } - return "fangjia.com"; - } - - private Integer getFloor(String roomNumber){ - if(StringUtils.isNotBlank(roomNumber) && DataUtil.isNumber(roomNumber)){ - if(roomNumber.length() == 3){ - return Integer.valueOf(roomNumber.substring(0,1)); - }else if(roomNumber.length() == 4){ - return Integer.valueOf(roomNumber.substring(0,2)); - }else{ - return null; - } - } - return null; - } - - private boolean checkExists(FacetQueryResult houseBoList, NewHousePojo house) { - for (NewHousePojo bo : houseBoList) { - boolean sameName = bo.getName().equals(house.getName()); - boolean sameAddress = bo.getAddress() != null ? bo.getAddress().equals(house.getAddress()) - : house.getAddress() == null; - boolean sameTotalPrice = bo.getListingPrice() != null ? bo.getListingPrice().equals(house.getListingPrice()) - : house.getListingPrice() == null; - boolean samePublishDate = bo.getPublishDate() != null ? bo.getPublishDate().equals(house.getPublishDate()) - : house.getPublishDate() == null; - boolean sameArea = bo.getSize() != null ? bo.getSize().equals(house.getSize()) : house.getSize() == null; - boolean sameFloor = bo.getFloor() != null ? bo.getFloor().equals(house.getFloor()) - : house.getFloor() == null; - if (sameName && sameAddress && sameFloor && sameTotalPrice && samePublishDate && sameArea) { - return true; - } - } - return false; - } - - /** - * 小区统计分析接口 - * - * @param model - * @return - */ - public Object analysisAction(DistrictQueryModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); - return mav; - } - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (null == district) { - mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); - return mav; - } - if (district.getLat2() == null || district.getLng2() == null) { - - mav.setModel(BasicModel.buildOKModel()); - return mav; - } - - DistrictKey districtKey = new DistrictKey(district.getCity(), district.getRegion(), district.getName()); - DistrictAttentionRank attention = districtAttentionRankService.findByDistrictKey(districtKey);// 小区关注度信息 - CityHot cityHot = cityHotService.findByCity(district.getCity()); - DistrictHot districtHot = districtHotService.findDistrictHotByDistrictKey(districtKey); - if (null != districtHot) { - if (null != districtHot.getHouseLastMonth() && districtHot.getHouseLastMonth() > 0) { - int lastMonthHouses = districtHot.getHouseLastMonth();// 上月挂牌量 - - if (null != cityHot && null != cityHot.getSellMarkupMonth()) { - districtHot.setHouseHalfYear( - (int) (lastMonthHouses * 6 * (1 + cityHot.getSellMarkupMonth() / 10000.0))); - } else { - districtHot.setHouseHalfYear((int) (lastMonthHouses * 6 * 0.9625)); - } - } - } - - double lat = district.getLat2() / 10000000000d; - double lng = district.getLng2() / 10000000000d; - double radius = 1000d; - double aroundAvgConsumption = bizShopService.findAroundAvgConsumption(lat, lng, radius, "餐厅");// 周边消费人均 - - int regionClickRank = 0; - int cityClickRank = 0; - int houseLastMonth = 0; - int houseHalfYear = 0; - - if (attention != null) { - if (attention.getRegionClickRank() != null) { - regionClickRank = attention.getRegionClickRank(); - } - if (attention.getCityClickRank() != null) { - cityClickRank = attention.getCityClickRank(); - } - } - - if (districtHot != null) { - if (districtHot.getHouseHalfYear() != null) { - houseHalfYear = districtHot.getHouseHalfYear(); - } - if (districtHot.getHouseLastMonth() != null) { - houseLastMonth = districtHot.getHouseLastMonth(); - } - } - - DistrictAnalysisDto districtAnalysisDto = new DistrictAnalysisDto(); - districtAnalysisDto.setCity(district.getCity());// 城市 - districtAnalysisDto.setDistrict(district.getRegion());// 区域 - districtAnalysisDto.setName(district.getName());// 小区名 - districtAnalysisDto.setAvgPriceAround((int) aroundAvgConsumption);// 周边餐饮平均消费 - districtAnalysisDto.setDistrictClickRank(regionClickRank);// 区域关注度排名 - districtAnalysisDto.setCityClickRank(cityClickRank);// 全市关注度排名 - districtAnalysisDto.setHouseHalfYear(houseHalfYear);// 近半年小区挂牌量 - districtAnalysisDto.setHouseLastMonth(houseLastMonth);// 上月小区挂牌量 - - mav.setModel(BasicModel.buildOKModel().setResult(districtAnalysisDto)); - return mav; - } - - /** - * 小区交通接口 - * - * @param model - * @return - */ - public Object trafficAction(DistrictQueryModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); - return mav; - } - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (null == district) { - mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); - return mav; - } - if (district.getLat2() == null || district.getLng2() == null) { - - mav.setModel(BasicModel.buildOKModel()); - return mav; - } - - double lat = district.getLat2() / 10000000000d; - double lng = district.getLng2() / 10000000000d; - double radius = 1000d; - - Map> stationMap = busStationService.getNearByStations(district.getCity(), lat, lng, - radius);// 查询交通信息(公交,地铁) bus_station,bus_line - List MetroStations = stationMap.get("地铁"); - List BusStation = stationMap.get("公交"); - - List StationDtos = new ArrayList(); - if (MetroStations != null) { - for (BusStation station : MetroStations) { - StationDto stationDto = new StationDto(); - stationDto.setName(station.getStation()); - stationDto.setLineName(station.getLineId()); - StationDtos.add(stationDto); - } - } - - if (BusStation != null) { - for (BusStation station : BusStation) { - StationDto stationDto = new StationDto(); - stationDto.setName(station.getStation()); - stationDto.setLineName(station.getLineId()); - StationDtos.add(stationDto); - } - } - - mav.setModel(BasicModel.buildOKModel().setResult(StationDtos)); - return mav; - } - - /** - * 小区周边接口 - * - * @param model - * @return - */ - public Object aroundAction(DistrictQueryModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict())) { - mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); - return mav; - } - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (null == district) { - mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); - return mav; - } - if (district.getLat2() == null || district.getLng2() == null) { - - mav.setModel(BasicModel.buildOKModel()); - return mav; - } - - double radius = 1000d;// 查周围半径为1公里距离的信息 - - List arrs = baiduApiService.searchNearbyLocalDatabase(district, radius);// 查询小区周边(所有类型) - Map> districtAroundMap = new HashMap>(); - - for (String key : AROUND_KEYWORD_FACTOR.keySet()) { - - List aroundNames = new ArrayList(); - districtAroundMap.put(AROUND_KEYWORD_FACTOR.get(key), aroundNames);// 把key的英文put到map并把value设置为一个List引用 - - } - for (int i = 0; i < arrs.size(); i++) { - BaiduPlacePoi poiObj = arrs.get(i); - String name = poiObj.getName(); - String keyword = poiObj.getKeyword(); - double latjs = poiObj.getLat(); - double lngjs = poiObj.getLng(); - String key = AROUND_KEYWORD_FACTOR.get(keyword); - - AroundDto dto = new AroundDto(); - dto.setName(name); - dto.setLat(latjs); - dto.setLng(lngjs); - if (districtAroundMap.get(key) != null) { - districtAroundMap.get(key).add(dto);// 按key值取出list add 周边名称已经经纬度 - } - - } - mav.setModel(BasicModel.buildOKModel().setResult(districtAroundMap)); - return mav; - } - - /** - * 相同小区相似户型房源挂牌量接口
- * 获取该小区的满足指定相似条件的挂牌房源量 条件说明: 1.输入面积-5<=房源面积<=输入面积+5 2.上个月发布的房源 - * - * @author yinjihuan - * @date 2016年9月1日 - * @param city - * 城市 - * @param district - * 区域 - * @param name - * 小区名 - * @param size - * 面积 - * @return - */ - public Object similarHouseAmoutAction(@Param(name = "city") String city, @Param(name = "district") String district, - @Param(name = "name") String name, @Param(name = "size") Double size) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(city) || StringUtils.isBlank(name) || StringUtils.isBlank(district) || size == null) { - mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名),size(面积)是必须参数")); - return mav; - } - if (size <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能小于0")); - return mav; - } - District districtInfo = districtService.findByNameAndAlias(city, district, name, "district"); - if (null == districtInfo) { - mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); - return mav; - } - long result = districtHouseResourceStatService.findSimilarHouseAmoutCount(districtInfo.getId(), size); - BasicModel model = new BasicModel(200, "ok"); - model.setResult(result); - mav.setModel(model); - return mav; - } - - /** - * 周边小区相似户型挂牌量接口
- * 获取该小区的满足指定相似条件的挂牌房源量 条件说明: 1.输入面积-5<=房源面积<=输入面积+5 2.上个月发布的房源 - * - * @author yinjihuan - * @date 2016年9月1日 - * @param city - * 城市 - * @param district - * 区域 - * @param name - * 小区名 - * @param size - * 面积 - * @param radius - * 周边小区最大半径(单位:米,默认2000) - * @return - */ - public Object nearbySimilarHouseAmoutAction(@Param(name = "city") String city, - @Param(name = "district") String district, @Param(name = "name") String name, - @Param(name = "size") Double size, @Param(name = "radius") Integer radius) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(city) || StringUtils.isBlank(name) || StringUtils.isBlank(district) || size == null) { - mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名),size(面积)是必须参数")); - return mav; - } - if (size <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能小于0")); - return mav; - } - District districtInfo = districtService.findByNameAndAlias(city, district, name, "district"); - if (null == districtInfo) { - mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); - return mav; - } - if (radius == null) { - radius = 2000; - } - // 找出小区周边范围类的小区 - List districts = districtService.findNearestDistrict(districtInfo, radius, 500); - List districtIds = new ArrayList(); - for (District dis : districts) { - districtIds.add(dis.getId()); - } - districtIds.add(districtInfo.getId()); - BasicModel model = new BasicModel(200, "ok"); - model.setResult(districtHouseResourceStatService.findNearbySimilarHouseAmoutCount(size, districtIds)); - mav.setModel(model); - return mav; - } - - /** - * 小区周边一公里均价 - * - * @author wenyan - * @param model - * @return - */ - public Object aroundAverageAction(@Valid AroundAverageModel model) { - - RestfulModelAndView mav = new RestfulModelAndView(); - DistrictKey key = new DistrictKey(model.getCity(), model.getDistrict(), model.getName()); - DistrictAnalyData districtAnalyData = districtAnalyDataService.findByDistrictKey(key); - BasicModel dataModel = BasicModel.buildOKModel(); - if (districtAnalyData != null && districtAnalyData.getAroundDistrictAvgPrice() != null) { - UniversalDto dto = UniversalDto.newDto(); - dto.append("averagePrice", districtAnalyData.getAroundDistrictAvgPrice()); - dataModel.setResult(dto); - } - mav.setModel(dataModel); - return mav; - - } - - /** - * 相同小区相似户型租金范围查询接口 - * - * @param model - * @return - */ - public Object similarHouseRentRangeAction(@Valid RentModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (null == district) { - mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); - return mav; - } - - // List houseBos = - // houseService.findDistrictHouseByCat(district.getCity(), district.getRegion(), - // district.getName(), 100, null, model.getSize()-5, model.getSize()+5); - Integer room = houseService.getDistrictRoomType(model.getSize()); - if (null == room) { - mav.setModel(BasicModel.buildBadRequestModel("根据size(面积)没有找到相应的室")); - return mav; - } - - List districtStatRents = districtStatRentService.findLatestDistrictStatRent(district, 1, - (int) room); - if (null == districtStatRents || districtStatRents.size() == 0) { - mav.setModel(BasicModel.buildOKModel()); - } else { - DistrictStatRent districtStatRent = districtStatRents.get(0); - Map rentRangeMap = new HashMap(); - if (districtStatRent.getAvgPrice() > 0) { - Integer avgPrice = districtStatRent.getAvgPrice(); - rentRangeMap.put("min", (int) (avgPrice - avgPrice * 0.08)); - rentRangeMap.put("max", (int) (avgPrice + avgPrice * 0.08)); - } - mav.setModel(BasicModel.buildOKModel().setResult(rentRangeMap)); - } - return mav; - } - - /** - * 周边小区相似户型租金范围查询接口 - * - * @param model - * @return - */ - public Object nearlySimilarHouseRentRangeAction(@Valid RentModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (null == district) { - mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); - return mav; - } - if (null == model.getRadius()) {// 设置默认值 - model.setRadius(2000); - } - - List districts = districtService.findNearestDistrict(district, model.getRadius(), 500); - if (null != districts) { - // List houseBos = new ArrayList(); - // for(District dist : districts){ - // List bos = houseService.findDistrictHouseByCat(dist.getCity(), - // dist.getRegion(), dist.getName(), 100, null, model.getSize()-5, - // model.getSize()+5); - // houseBos.addAll(bos); - // } - Integer room = houseService.getDistrictRoomType(model.getSize()); - if (null == room) { - mav.setModel(BasicModel.buildBadRequestModel("根据size(面积)没有找到相应的室")); - return mav; - } - - List prices = new ArrayList(); - for (District dist : districts) { - List districtStatRents = districtStatRentService.findLatestDistrictStatRent(dist, 1, - room); - if (null != districtStatRents && districtStatRents.size() > 0) { - DistrictStatRent districtStatRent = districtStatRents.get(0); - if (districtStatRent.getAvgPrice() > 0) { - Integer avgPrice = districtStatRent.getAvgPrice(); - prices.add(avgPrice); - } - } - } - - Map rentRangeMap = new HashMap(); - if (prices.size() > 0) { - Collections.sort(prices); - rentRangeMap.put("min", prices.get(0)); - rentRangeMap.put("max", prices.get(prices.size() - 1)); - mav.setModel(BasicModel.buildOKModel().setResult(rentRangeMap)); - } else { - mav.setModel(BasicModel.buildOKModel()); - } - } else { - mav.setModel(BasicModel.buildBadRequestModel("没找到周边小区")); - } - - return mav; - } - - /** - * 室号查询接口 - * - * @param model - * @return - */ - public Object roomAction(@Valid RoomModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - - List queryParams = new ArrayList(); - queryParams.add(new QueryParam("city", model.getCity())); - queryParams.add(new QueryParam("region", model.getDistrict())); - queryParams.add(new QueryParam("name", model.getProjectName())); - queryParams.add(new QueryParam("houseNum", model.getBuildingNumber())); - queryParams.add(new QueryParam("houseNumUnit", model.getUnitNumber())); - if (model.getFloor() != null) { - queryParams.add(new QueryParam("houseFloor", model.getFloor())); - } - List sortParams = new ArrayList(); - sortParams.add(new SortParam("houseFloor", true)); - List houseLoudongs = houseLoudongService.findAll(queryParams, new Pager(Integer.MAX_VALUE)); - List rooms = new ArrayList(); - for (HouseLoudong houseLoudong : houseLoudongs) { - if ("--".equals(houseLoudong.getRoomNum())) { - continue; - } - RoomDto dto = new RoomDto(); - dto.setDisplay(houseLoudong.getRoomNum() + "室"); - dto.setUnitNumber(houseLoudong.getHouseNumUnit()); - dto.setRoom(houseLoudong.getRoomNum()); - rooms.add(dto); - } - mav.setModel(BasicModel.buildOKModel().setResult(rooms)); - return mav; - } - - /** - * 楼栋楼层信息查询接口 - * - * @param model - * @return - */ - public Object floorsAction(@Valid FloorsModel model) { - - RestfulModelAndView mav = new RestfulModelAndView(); - List loudongs = loudongService.findAll(model.getCity(), model.getDistrict(), model.getProjectName(), - model.getBuildingNumber(), model.getUnitNumber(), Integer.MAX_VALUE); - if (null == loudongs || loudongs.isEmpty()) { - mav.setModel(BasicModel.buildBadRequestModel("楼栋不存在")); - return mav; - } - List floors = new ArrayList(); - if (loudongs.get(0).getFloors() > 0) { - for (int i = 1; i <= loudongs.get(0).getFloors(); i++) { - floors.add(i); - } - } - mav.setModel(BasicModel.buildOKModel().setResult(floors)); - return mav; - } - - /** - * 楼栋查询接口 - * - * @param model - * @return - */ - public Object buildingAction(@Valid BuildingModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - - List loudongs = loudongService.findAll(model.getCity(), model.getDistrict(), model.getProjectName(), - null, null, Integer.MAX_VALUE); - List dtos = new ArrayList(); - List keys = new ArrayList(); - for (Loudong loudong : loudongs) { - if (keys.contains(loudong.getHouseNumber()) || "--".equals(loudong.getHouseNumber())) { - continue; - } - BuildingDto dto = new BuildingDto(); - dto.setId(loudong.getId()); - dto.setBuildingNumber(loudong.getHouseNumber()); - dto.setLabel(loudong.getHouseNumber()); - dtos.add(dto); - keys.add(loudong.getHouseNumber()); - } - - Collections.sort(dtos, new Comparator() { - @Override - public int compare(BuildingDto o1, BuildingDto o2) { - if (StringUtils.isNumeric(o1.getBuildingNumber()) && StringUtils.isNumeric(o2.getBuildingNumber())) { - return new Double(o1.getBuildingNumber()).compareTo(new Double(o2.getBuildingNumber())); - } else if (StringUtils.isNumeric(o1.getBuildingNumber())) { - return -1; - } else if (StringUtils.isNumeric(o2.getBuildingNumber())) { - return 1; - } else { - return o1.getBuildingNumber().compareTo(o2.getBuildingNumber()); - } - - } - }); - - mav.setModel(BasicModel.buildOKModel().setResult(dtos)); - return mav; - } - - /** - * 楼栋查询接口 - * - * @param model - * @return - */ - public Object unitNumberAction(@Valid UnitNumberModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - - List loudongs = loudongService.findAll(model.getCity(), model.getDistrict(), model.getProjectName(), - model.getBuildingNumber(), null, Integer.MAX_VALUE); - - List dtos = new ArrayList(); - List keys = new ArrayList(); - for (Loudong loudong : loudongs) { - if (keys.contains(loudong.getUnitNumber()) || "--".equals(loudong.getUnitNumber())) { - continue; - } - UnitNumberDto dto = new UnitNumberDto(); - dto.setId(loudong.getId()); - dto.setBuildingNumber(loudong.getHouseNumber()); - dto.setUnitNumber(loudong.getUnitNumber()); - dto.setLabel(loudong.getUnitNumber()); - dtos.add(dto); - keys.add(loudong.getUnitNumber()); - } - Collections.sort(dtos, new Comparator() { - @Override - public int compare(UnitNumberDto o1, UnitNumberDto o2) { - if (StringUtils.isNumeric(o1.getUnitNumber()) && StringUtils.isNumeric(o2.getUnitNumber())) { - return new Double(o1.getUnitNumber()).compareTo(new Double(o2.getUnitNumber())); - } else if (StringUtils.isNumeric(o1.getUnitNumber())) { - return -1; - } else if (StringUtils.isNumeric(o2.getUnitNumber())) { - return 1; - } else { - return o1.getUnitNumber().compareTo(o2.getUnitNumber()); - } - - } - }); - - mav.setModel(BasicModel.buildOKModel().setResult(dtos)); - return mav; - } - - public Object avgPrice2Action(@Param(name = "city") String city, @Param(name = "district") String district, - @Param(name = "name") String name) { - - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(city) || StringUtils.isBlank(district) || StringUtils.isBlank(name)) { - mav.setModel(BasicModel.buildBadRequestModel("小区所在城市,所在区域,小区名为必填项")); - return mav; - } - - District districtBo = districtService.findByNameAndAlias(city, district, name, "district"); - if (null == districtBo) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - - DistrictStatBo districtStatBo = districtStatService - .findDistrictStat(new DistrictKey(districtBo.getCity(), districtBo.getRegion(), districtBo.getName())); - if (null == districtStatBo || (districtStatBo != null && districtStatBo.getDistrictStat() == null - && districtStatBo.getVillaDistrictStat() == null)) { - mav.setModel(BasicModel.buildOKModel()); - return mav; - } - Integer lastAvgPrice = averageAnalyService.getLastAvgPrice(districtBo, districtStatBo); - Map map = new HashMap(); - map.put("city", districtBo.getCity()); - map.put("district", districtBo.getRegion()); - map.put("name", districtBo.getName()); - map.put("avgPrice", lastAvgPrice); - if (districtStatBo.getDistrictStat() != null) { - map.put("date", DateUtil.formatByPattern(districtStatBo.getDistrictStat().getWeekend(), "yyyy-MM-dd")); - } else if (districtStatBo.getVillaDistrictStat() == null) { - map.put("date", DateUtil.formatByPattern(districtStatBo.getVillaDistrictStat().getWeekend(), "yyyy-MM-dd")); - } - - mav.setModel(BasicModel.buildOKModel().setResult(map)); - return mav; - } - - private Map getLastEvaluationPrice(District district, Evaluation evaluation, double dCredit) - throws NumberFormatException, IllegalAccessException { - Date startDate = DateUtil.parseDate(DateUtil.addMonth(new Date(), -6), "yyyy-MM-dd"); - // 第三方价格 - Map otherPriceRets = averageStatisticsService.findFirstAverageStatictics(district.getCity(), - district.getRegion(), district.getName(), district.getCategory(), startDate); - if (null == otherPriceRets) { - otherPriceRets = new HashMap(); - } - - otherPriceRets.put("fjw_price", evaluation.getAvgPrice()); - Map levelMap = getPriceLevel(otherPriceRets, evaluation.getCredit()); - Long lastPrice = getLastPrice(levelMap, otherPriceRets, evaluation, dCredit); - - Map rMap = new HashMap(); - rMap.put("lastPrice", lastPrice); - if (null != levelMap && levelMap.containsKey("level")) { - String priceLevel = (String) levelMap.get("level"); - rMap.put("level", priceLevel); - } - rMap.put("other_price", otherPriceRets); - return rMap; - } - - private Long getLastPrice(Map retMap, Map otherPriceRets, Evaluation evaluation, double dCredit) { - Long lastPrice = null; - if (null != retMap) { - String priceLevel = (String) retMap.get("level"); - - if (priceLevel.equals("D")) { - - lastPrice = inputResultByWebsite(otherPriceRets, evaluation, dCredit); - - } else if (priceLevel.equals("E")) { - if (evaluation.getCredit() >= 0.65) { - lastPrice = evaluation.getBigTotalPrice(); - } else { - List prices = (List) retMap.get("prices"); - int avgPrice = 0; - if (prices != null) { - avgPrice = findNewPrice(prices, evaluation.getAvgPrice()); - } - // 在 dCredit与0.65之间 - if (evaluation.getCredit() >= dCredit && dCredit < 0.65) { - if (avgPrice > 0) { - Double newTotalPrice = avgPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else { - if (null != otherPriceRets.get("lianjia_price")) { - Integer lianjiaPrice = (Integer) otherPriceRets.get("lianjia_price"); - Double newTotalPrice = lianjiaPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else if (null != otherPriceRets.get("zhugezhaofang_price")) { - Integer zhugezhaofangPrice = (Integer) otherPriceRets.get("zhugezhaofang_price"); - Double newTotalPrice = zhugezhaofangPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else if (null != otherPriceRets.get("yungujia_price")) { - Integer yungujiaPrice = (Integer) otherPriceRets.get("yungujia_price"); - Double newTotalPrice = yungujiaPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else if (null != otherPriceRets.get("fanggugu_price")) { - Integer fangguguPrice = (Integer) otherPriceRets.get("fanggugu_price"); - Double newTotalPrice = fangguguPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else { - lastPrice = evaluation.getBigTotalPrice(); - } - } - } else if (evaluation.getCredit() < dCredit) {// 在dCredit以下 - if (avgPrice > 0) { - Double newTotalPrice = avgPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else { - if (null != otherPriceRets.get("lianjia_price")) { - Integer lianjiaPrice = (Integer) otherPriceRets.get("lianjia_price"); - Double newTotalPrice = lianjiaPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else if (null != otherPriceRets.get("zhugezhaofang_price")) { - Integer zhugezhaofangPrice = (Integer) otherPriceRets.get("zhugezhaofang_price"); - Double newTotalPrice = zhugezhaofangPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else if (null != otherPriceRets.get("yungujia_price")) { - Integer yungujiaPrice = (Integer) otherPriceRets.get("yungujia_price"); - Double newTotalPrice = yungujiaPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else if (null != otherPriceRets.get("fanggugu_price")) { - Integer fangguguPrice = (Integer) otherPriceRets.get("fanggugu_price"); - Double newTotalPrice = fangguguPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } - } - } - } - - } else if (priceLevel.equals("C")) { - List smallPrices = (List) retMap.get("small_prices"); - if (smallPrices != null) { - smallPrices.add(evaluation.getAvgPrice()); - int avgPrice = sum(smallPrices) / smallPrices.size(); - Double newTotalPrice = avgPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } - } else { - lastPrice = evaluation.getBigTotalPrice(); - } - } - return lastPrice; - } - - private Long inputResultByWebsite(Map otherPriceRets, Evaluation evaluation, double dCredit) { - Long lastPrice = null; - if (evaluation.getCredit() >= dCredit) { - lastPrice = evaluation.getBigTotalPrice(); - } else { - if (evaluation.getCredit() < dCredit) { - if (null != otherPriceRets.get("lianjia_price")) { - Integer lianjiaPrice = (Integer) otherPriceRets.get("lianjia_price"); - Double newTotalPrice = lianjiaPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else if (null != otherPriceRets.get("zhugezhaofang_price")) { - Integer zhugezhaofangPrice = (Integer) otherPriceRets.get("zhugezhaofang_price"); - Double newTotalPrice = zhugezhaofangPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else if (null != otherPriceRets.get("yungujia_price")) { - Integer yungujiaPrice = (Integer) otherPriceRets.get("yungujia_price"); - Double newTotalPrice = yungujiaPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else if (null != otherPriceRets.get("fanggugu_price")) { - Integer fangguguPrice = (Integer) otherPriceRets.get("fanggugu_price"); - Double newTotalPrice = fangguguPrice * evaluation.getArea(); - lastPrice = newTotalPrice.longValue(); - } else { - lastPrice = evaluation.getBigTotalPrice(); - } - } else { - lastPrice = evaluation.getBigTotalPrice(); - } - } - return lastPrice; - } - - private Integer findNewPrice(List prices, int avgPrice) { - int minValue1 = Integer.MAX_VALUE; - List> values = new ArrayList>(); - int fjw_price = avgPrice; - - // 找出最小差 - for (int i = 0; i < prices.size() - 1; i++) { - int a = prices.get(i); - for (int j = i + 1; j < prices.size(); j++) { - int b = prices.get(j); - int mod = Math.abs(a - b); - if (mod < minValue1) { - minValue1 = mod; - } - } - } - - // 根据最小差找出结果 - for (int i = 0; i < prices.size() - 1; i++) { - int a = prices.get(i); - for (int j = i + 1; j < prices.size(); j++) { - int b = prices.get(j); - int mod = Math.abs(a - b); - if (mod == minValue1) { - values.add(Arrays.asList(a, b)); - } - } - } - - int minValue2 = Integer.MAX_VALUE; - int lastValue = 0; - if (values.size() >= 1) { - for (List value : values) { - int newPrice = (value.get(0) + value.get(1)) / 2; - int mod = Math.abs(fjw_price - newPrice); - if (mod < minValue2) { - minValue2 = mod; - lastValue = newPrice; - } - } - } - - if (lastValue > 0) { - double temp = DataUtil.getDoubleRound(2, minValue1 * 100 / lastValue); - temp = Math.abs(temp); - if (temp > 15) { - lastValue = 0; - } - } - return lastValue; - } - - private Integer sum(List smallPrices) { - int sum = 0; - for (int price : smallPrices) { - sum += price; - } - return sum; - } - - private Map getPriceLevel(Map otherPriceRets, double credit) { - - Integer avgPrice = (Integer) otherPriceRets.get("fjw_price"); - - int keyCount = 0; - int commonCount = 0; - int isExistCount = 0; - - List prices = new ArrayList(); - List smallPrices = new ArrayList(); - - if (null != otherPriceRets.get("fanggugu_price")) { - Integer fangguguPrice = (Integer) otherPriceRets.get("fanggugu_price"); - int mod = avgPrice - fangguguPrice; - double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); - temp = Math.abs(temp); - if (temp <= 15) { - keyCount++; - } else { - prices.add(fangguguPrice); - } - isExistCount++; - } - if (null != otherPriceRets.get("yungujia_price")) { - Integer yungujiaPrice = (Integer) otherPriceRets.get("yungujia_price"); - int mod = avgPrice - yungujiaPrice; - double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); - temp = Math.abs(temp); - if (temp <= 15) { - keyCount++; - } else { - prices.add(yungujiaPrice); - } - - isExistCount++; - } - - if (null != otherPriceRets.get("zhugezhaofang_price")) { - Integer zhugezhaofangPrice = (Integer) otherPriceRets.get("zhugezhaofang_price"); - int mod = avgPrice - zhugezhaofangPrice; - double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); - temp = Math.abs(temp); - if (temp <= 15) { - keyCount++; - } else { - prices.add(zhugezhaofangPrice); - } - - isExistCount++; - } - - if (null != otherPriceRets.get("lianjia_price")) { - Integer lianjiaPrice = (Integer) otherPriceRets.get("lianjia_price"); - int mod = avgPrice - lianjiaPrice; - double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); - temp = Math.abs(temp); - if (temp <= 15) { - keyCount++; - } else { - prices.add(lianjiaPrice); - } - isExistCount++; - } - if (null != otherPriceRets.get("anjuke_price")) { - Integer anjukePrice = (Integer) otherPriceRets.get("anjuke_price"); - int mod = avgPrice - anjukePrice; - double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); - temp = Math.abs(temp); - if (temp <= 15) { - commonCount++; - smallPrices.add(anjukePrice); - } else { - prices.add(anjukePrice); - } - - isExistCount++; - } - if (null != otherPriceRets.get("ganji_price")) { - Integer ganjiPrice = (Integer) otherPriceRets.get("ganji_price"); - int mod = avgPrice - ganjiPrice; - double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); - temp = Math.abs(temp); - if (temp <= 15) { - commonCount++; - smallPrices.add(ganjiPrice); - } else { - prices.add(ganjiPrice); - } - - isExistCount++; - } - if (null != otherPriceRets.get("soufan_price")) { - Integer soufan_price = (Integer) otherPriceRets.get("soufan_price"); - int mod = avgPrice - soufan_price; - double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); - temp = Math.abs(temp); - if (temp <= 15) { - commonCount++; - smallPrices.add(soufan_price); - } else { - prices.add(soufan_price); - } - - isExistCount++; - } - if (null != otherPriceRets.get("tobushi_price")) { - Integer tobushi = (Integer) otherPriceRets.get("tobushi_price"); - int mod = avgPrice - tobushi; - double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); - temp = Math.abs(temp); - if (temp <= 15) { - commonCount++; - smallPrices.add(tobushi); - } else { - prices.add(tobushi); - } - - isExistCount++; - } - - if (null != otherPriceRets.get("zhongyuan_price")) { - Integer zhongyuanPrice = (Integer) otherPriceRets.get("zhongyuan_price"); - int mod = avgPrice - zhongyuanPrice; - double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); - temp = Math.abs(temp); - if (temp <= 15) { - commonCount++; - smallPrices.add(zhongyuanPrice); - } else { - prices.add(zhongyuanPrice); - } - - isExistCount++; - } - - Map retMap = new HashMap(); - String level = null; - if (keyCount >= 2) { - level = "A"; - } else if (keyCount >= 1 && commonCount >= 1) { - level = "A"; - } else if (keyCount >= 1 || commonCount >= 2) { - level = "B"; - } else if (commonCount >= 1) { - level = "C"; - } else if (isExistCount == 0) { - level = "D"; - } else if (isExistCount >= 1) { - if (isExistCount == 1) { - level = "D"; - } else { - level = "E"; - } - } - - if (credit == 0) { - level = "E"; - } - - if (StringUtils.isNotBlank(level)) { - retMap.put("level", level); - retMap.put("prices", prices); - retMap.put("small_prices", smallPrices); - } - return retMap; - } - - /** - * 房产交易记录查询 - * - * @param model - * @return - */ - public Object transactionRecordAction(PropertySearchModel model) { - // 输入(model中拿取) city+district+name+houseNum(楼栋号)+roomNum(室号) trade_date倒序 - // max查询条数 - // 输出 - // {"result":{"districtCnt":"小区1年内成交数量","transactionList":[{"time":"yyyy-MM-dd","price":"xxx万"}]}} - // time是每笔的成交时间,price是每笔的成交金额,注意看数据格式 - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - String city = model.getCity(); - String district = model.getDistrict(); - String name = model.getName(); - String houseNum = model.getHouseNum(); - String roomNum = model.getRoomNum(); - int max = model.getMax() == null ? 10 : model.getMax(); - if (StringUtils.isBlank(city)) { - mav.setModel(BasicModel.buildBadRequestModel("城市(city)不能为空")); - return mav; - } - if (StringUtils.isBlank(district)) { - mav.setModel(BasicModel.buildBadRequestModel("区域(district)不能为空")); - return mav; - } - if (StringUtils.isBlank(name)) { - mav.setModel(BasicModel.buildBadRequestModel("小区名(name)不能为空")); - return mav; - } - if (StringUtils.isBlank(houseNum)) { - mav.setModel(BasicModel.buildBadRequestModel("楼栋号(houseNum)不能为空")); - return mav; - } - if (StringUtils.isBlank(roomNum)) { - mav.setModel(BasicModel.buildBadRequestModel("室号(roomNum)不能为空")); - return mav; - } - Date curDate = new Date(); - // 小区1年内成交数量 - long count = dealPriceService.findTradeCount(city, district, name, DateUtil.getDateOfLastMonth(curDate, -12), - curDate); - List list = dealPriceService.findMaxTrade(city, district, name, houseNum, roomNum, max); - List transactionList = new ArrayList(); - for (DealPrice dealPrice : list) { - HouseDealPriceDetailDto detail = new HouseDealPriceDetailDto(); - detail.setPrice(dealPrice.getTotalPrice()); - detail.setPriceStr(DataUtil.roundDouble((dealPrice.getTotalPrice() / 10000d), 2) + "万"); - detail.setTime(DateUtil.formatByPattern(dealPrice.getTradeDate(), "yyyy-MM-dd")); - transactionList.add(detail); - } - HouseDealPriceDto dto = new HouseDealPriceDto(); - dto.setDistrictCnt(count); - dto.setTransactionList(transactionList); - mav.setModel(BasicModel.buildOKModel().setResult(dto)); - return mav; - } - - /** - * 房产拍卖记录 - * - * @param model - * @return - */ - public Object auctionRecordAction(PropertySearchModel model) { - // 拍卖记录表是fangjia_crawl.house_auction HouseAuction - // 输入(model中拿取) city+district+name+houseNum(楼栋号)+roomNum(室号) announcement_date倒序 - // max查询条数 - // 输入对应的表查询字段 cityMatch+regionMatch+nameMatch+buildingNumber+roomNumber - // 输出 - // {"result":{"districtCnt":"小区1年内拍卖数量","transactionList":[{"time":"yyyy-MM-dd","name":"xxx拍卖行"}]}} - // time是每笔的成交时间,name是每笔的拍卖机构,注意看数据格式 - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - String city = model.getCity(); - String district = model.getDistrict(); - String name = model.getName(); - String houseNum = model.getHouseNum(); - String roomNum = model.getRoomNum(); - int max = model.getMax() == null ? 10 : model.getMax(); - if (StringUtils.isBlank(city)) { - mav.setModel(BasicModel.buildBadRequestModel("城市(city)不能为空")); - return mav; - } - if (StringUtils.isBlank(district)) { - mav.setModel(BasicModel.buildBadRequestModel("区域(district)不能为空")); - return mav; - } - if (StringUtils.isBlank(name)) { - mav.setModel(BasicModel.buildBadRequestModel("小区名(name)不能为空")); - return mav; - } - if (StringUtils.isBlank(houseNum)) { - mav.setModel(BasicModel.buildBadRequestModel("楼栋号(houseNum)不能为空")); - return mav; - } - if (StringUtils.isBlank(roomNum)) { - mav.setModel(BasicModel.buildBadRequestModel("室号(roomNum)不能为空")); - return mav; - } - Date curDate = new Date(); - // 小区1年内成交数量 - long count = houseAuctionService.findHouseAuctionCount(city, district, name, - DateUtil.getDateOfLastMonth(curDate, -12), curDate); - List list = houseAuctionService.findMaxHouseAuction(city, district, name, houseNum, roomNum, max); - List transactionList = new ArrayList(); - for (HouseAuction houseAuction : list) { - HouseAuctionDetailDto detail = new HouseAuctionDetailDto(); - detail.setName(houseAuction.getCourt()); - detail.setTime(DateUtil.formatByPattern(houseAuction.getAuctionTime(), "yyyy-MM-dd")); - transactionList.add(detail); - } - HouseAuctionDto dto = new HouseAuctionDto(); - dto.setDistrictCnt(count); - dto.setTransactionList(transactionList); - mav.setModel(BasicModel.buildOKModel().setResult(dto)); - return mav; - } - - /** - * 房产近期评估次数 - * - * @param model - * @return - */ - public Object evaluateNumAction(PropertySearchModel model) { - // 输入(model中拿取) city+district+name+houseNum(楼栋号)+roomNum(室号) - // 输出 {"result":{"oneMonth":"房屋最近30天的评估次数","threeMonth":"房屋最近90天的评估次数"}} - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - String city = model.getCity(); - String district = model.getDistrict(); - String name = model.getName(); - String houseNum = model.getHouseNum(); - String roomNum = model.getRoomNum(); - if (StringUtils.isBlank(city)) { - mav.setModel(BasicModel.buildBadRequestModel("城市(city)不能为空")); - return mav; - } - if (StringUtils.isBlank(district)) { - mav.setModel(BasicModel.buildBadRequestModel("区域(district)不能为空")); - return mav; - } - if (StringUtils.isBlank(name)) { - mav.setModel(BasicModel.buildBadRequestModel("小区名(name)不能为空")); - return mav; - } - if (StringUtils.isBlank(houseNum)) { - mav.setModel(BasicModel.buildBadRequestModel("楼栋号(houseNum)不能为空")); - return mav; - } - if (StringUtils.isBlank(roomNum)) { - mav.setModel(BasicModel.buildBadRequestModel("室号(roomNum)不能为空")); - return mav; - } - Date curDate = new Date(); - long oneMonth = evaluationService.countByHouse(city, district, name, houseNum, roomNum, - DateUtil.getDateOfLastMonth(curDate, -1), curDate); - long threeMonth = evaluationService.countByHouse(city, district, name, houseNum, roomNum, - DateUtil.getDateOfLastMonth(curDate, -3), curDate); - mav.setModel(BasicModel.buildOKModel().setResult(new HouseEvaluateNumDto(oneMonth, threeMonth))); - return mav; - } - - /*** - * 小区租金估值报告(上半部分) - * @param model - * @param request - * @return - * @throws NumberFormatException - * @throws IllegalAccessException - */ - @Authority(role = Role.NONE) - public Object rentReportAction(PropertyEvaluationModel model, HttpServletRequest request)throws NumberFormatException, IllegalAccessException { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); - return mav; - } - if (model.getCity().endsWith("市")) { - model.setCity(model.getCity().replaceAll("市$", "")); - } - if (StringUtils.isNotBlank(request.getParameter("calDate"))) { - Date calDate = null; - try { - calDate = org.apache.commons.lang.time.DateUtils.parseDate(request.getParameter("calDate"), new String[] { "yyyy-MM-dd" }); - } catch (ParseException e) { - - } - if (calDate == null) { - mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); - return mav; - } else { - model.setCalDate(calDate); - } - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - model.setName(district.getName()); - - - if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); - return mav; - } - - if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); - return mav; - } - if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { - mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); - return mav; - } - - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - - if (model.getCalDate() != null) { - if (new Date().before(model.getCalDate())) { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); - } - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } - - 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(); - districtPriceMap.put("city", district.getCity()); - districtPriceMap.put("district", district.getRegion()); - districtPriceMap.put("name", district.getName()); - districtPriceMap.put("address", district.getAddress()); - districtPriceMap.put("totalPrice", evaluation.getTotalPrice()); - districtPriceMap.put("totalPriceUpper", CurrencyConverter.toChinese(String.valueOf(evaluation.getTotalPrice()))); - districtPriceMap.put("cal_date", DateUtil.formatByPattern(new Date(), "yyyy/MM/dd")); - districtPriceMap.put("direction", evaluation.getDirection()); - districtPriceMap.put("size", evaluation.getArea()); - districtPriceMap.put("floor", model.getFloor()); - districtPriceMap.put("height", model.getHeight()); - districtPriceMap.put("fitment", evaluation.getFitment()); - districtPriceMap.put("buildYear",district.getFinishBuildingDate()); - - Integer startPrice = (int)(evaluation.getTotalPrice() - evaluation.getTotalPrice()*0.2); - Integer endPrice = (int)(evaluation.getTotalPrice() + evaluation.getTotalPrice()*0.2); - - //周边相似小区 + if (house.getPublishDate() != null) { + if (new Date().before(house.getPublishDate())) { + house.setPublishDate(house.getModificationDate()); + } else { + house.setPublishDate(house.getPublishDate()); + } + } + if (house.getPublishDate() == null) { + b.setPublishDate("");// 发布时间 + } else { + b.setPublishDate(DateUtil.formatByPattern(house.getPublishDate(), "yyyy-MM-dd"));// 发布时间 + } + b.setSource(getDomainName(house.getUrl())); + if (HouseValidator.validateBuildingType(house.getBuildType())) { + b.setBuildingType(house.getBuildType()); + } + if (HouseValidator.validateArea(house.getArea()) && !checkExists(list, b)) { + list.add(b); + } + + } + return list; + } + + // 200~900ms + public Object similarAction(PropertyEvaluationModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getName())) { + mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); + return mav; + } + if (0 >= model.getSize()) { + mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能为空")); + return mav; + } + // 在库中找到对应的小区 + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + // 查找均价 + List districtStats = districtStatService.findAllDistrictStatsSort(district.getCity(), + district.getRegion(), district.getName(), model.getCalDate()); + Integer districtAvg = 0; + if (districtStats != null && !districtStats.isEmpty()) { + DistrictStat districtStat = districtStats.get(0); + districtAvg = districtStat.getAvgPrice(); + } + Integer avgPrice = 0; + Integer tatalPrice = 0; + int count = 0; + List listHouse = similarCommMethod(model, "similar", district); + for (House house : listHouse) { + long temp = Math.round(house.getTotalPrice() / house.getArea()); + // 均价范围在0.8~1.2 + if (temp > districtAvg * 1.3 || temp < districtAvg * 0.7) { + continue; + } + avgPrice = (int) temp + avgPrice; + count++; + } + + if (count == 0) { + mav.setModel(BasicModel.buildOKModel().setMsg("该小区无均价")); + return mav; + } + avgPrice = avgPrice / count; + tatalPrice = (int) Math.round(avgPrice * model.getSize()); + Map districtPriceMap = new HashMap(); + districtPriceMap.put("city", district.getCity()); + districtPriceMap.put("district", district.getRegion()); + districtPriceMap.put("name", district.getName()); + districtPriceMap.put("totalPrice", tatalPrice); + districtPriceMap.put("avgPrice", avgPrice); + mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); + return mav; + } + + // 寻找相似房源 + public List similarCommMethod(PropertyEvaluationModel model, String kind, District district) { + model.setName(district.getName()); + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (model.getCalDate() != null) { + model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } + List listHouse = new ArrayList(); + FacetQueryResult houseBos = houseService.findSeabirdHouses(district, 0, 1000); + if ("similarSort".equals(kind)) { + listHouse = houseService.findSimilarDistrictParam(houseBos, FJT_DIRECTION.get(model.getDirection()), + FITMENT_MAP.get(model.getFitment()), PROPERTY_TYPES.get(model.getEstateType()), model.getFloor(), + model.getRoom(), model.getHall(), model.getSize(), 1); + } else if ("similar".equals(kind)) { + for (int param = 1; param <= 5; param++) { + listHouse.addAll(houseService.findSimilarDistrict(houseBos, FJT_DIRECTION.get(model.getDirection()), + FITMENT_MAP.get(model.getFitment()), PROPERTY_TYPES.get(model.getEstateType()), + model.getFloor(), model.getRoom(), model.getHall(), model.getSize(), param)); + if (listHouse.size() > 50) { + break; + } + } + } + if (listHouse == null || listHouse.size() < 5) { + List districts = houseService.findAroundDistrict(district); + for (District around : districts) { + FacetQueryResult aroundBos = houseService.findSeabirdHouses(around, 0, 1000); + if (listHouse == null || listHouse.isEmpty()) { + listHouse = houseService.findSimilarDistrict(aroundBos, FJT_DIRECTION.get(model.getDirection()), + FITMENT_MAP.get(model.getFitment()), PROPERTY_TYPES.get(model.getEstateType()), + model.getFloor(), model.getRoom(), model.getHall(), model.getSize(), 3); + } else { + listHouse + .addAll(houseService.findSimilarDistrict(aroundBos, FJT_DIRECTION.get(model.getDirection()), + FITMENT_MAP.get(model.getFitment()), PROPERTY_TYPES.get(model.getEstateType()), + model.getFloor(), model.getRoom(), model.getHall(), model.getSize(), 3)); + } + if (listHouse.size() > 10) { + break; + } + } + } + return listHouse; + } + + public static final String[] DFIELDS = {"city", "region", "name", "address"}; + + public Object autoCompleteAction(PropertySearchModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); + return mav; + } + if (!"全国".equals(model.getCity())) { + if (!RegionData.isCity(model.getCity())) { + String city = RegionData.formatCity(model.getCity()); + if (null == city) { + mav.setModel(BasicModel.buildBadRequestModel("非法城市:" + model.getCity())); + return mav; + } else { + model.setCity(city); + } + } + } + + if (StringUtils.isNotBlank(model.getDistrict())) { + model.setDistrict(RegionData.formatRegion(model.getCity(), model.getDistrict())); + } + + if (StringUtils.isBlank(model.getKeyword())) { + mav.setModel(BasicModel.buildBadRequestModel("keyword(关键字)不能为空")); + return mav; + } + + String type = "name"; + if (StringUtils.isNotBlank(model.getFilter())) { + type = model.getFilter(); + } + //强行启用小区库 + if ("true".equals(model.getUseSeaweed())) { + if (model.getMax() == null || model.getMax() < 1 || model.getMax() > 100) { + model.setMax(10); + } + List params = new ArrayList(); + if (!"全国".equals(model.getCity())) { + params.add(new QueryParam("city", model.getCity())); + } + if (StringUtils.isNotBlank(model.getDistrict())) { + params.add(new QueryParam("region", model.getDistrict())); + } + params.add(new QueryParam("category", "district")); + params.add(new QueryParam("visible", 0)); + // BooleanQuery srQuery1 = new BooleanQuery(); + // BooleanQuery nameQuery = new BooleanQuery(); + // nameQuery.add(new TermQuery(new Term("district_name", model.getKeyword())), + // BooleanClause.Occur.SHOULD); + // nameQuery.add(new PrefixQuery(new Term("name", + // QueryParser.escape(model.getKeyword()).toLowerCase())), + // BooleanClause.Occur.SHOULD); + // nameQuery.add(new TermQuery(new Term("alias_std", model.getKeyword())), + // BooleanClause.Occur.SHOULD); + // nameQuery.add(new TermQuery(new Term("address", model.getKeyword())), + // BooleanClause.Occur.SHOULD); + // nameQuery.add(new TermQuery(new Term("addr_alias_std", model.getKeyword())), + // BooleanClause.Occur.SHOULD); + + if (StringUtils.isNotBlank(model.getKeyword())) { + BooleanQuery query = new BooleanQuery(); + if (model.getUseOrQuery()) { + params.add(new QueryParam("$fangjiawang_query_type", "or")); + } + // 2017-11-02新增, 指定查询字段,以:分割为多个字段查询,处理pds搜索问题,不指定默认用keyword查询 + String queryFields = model.getQueryField(); + if (StringUtils.isNotBlank(queryFields) && queryFields.contains(":")) { + String[] fs = queryFields.split(":"); + for (String f : fs) { + Query q1 = new TermQuery(new Term(f, QueryParser.escape(model.getKeyword()).toLowerCase())); + q1.setBoost(0.99f); + query.add(q1, BooleanClause.Occur.SHOULD); + } + } else { + Query q1 = new TermQuery( + new Term(model.getQueryField(), QueryParser.escape(model.getKeyword()).toLowerCase())); + q1.setBoost(0.99f); + query.add(q1, BooleanClause.Occur.SHOULD); + } + + /* + * Query q2 = new TermQuery(new Term("keyword_cjk", + * QueryParser.escape(model.getKeyword()).toLowerCase())); q2.setBoost(0.01f); + * query.add(q2, BooleanClause.Occur.SHOULD); + */ + + /* + * String districtName = tokenDistrictName(model.getKeyword()); + * if(StringUtils.isNotBlank(districtName)){ Query q3 = new TermQuery(new + * Term("keyword_cjk", districtName)); q3.setBoost(0.99f); query.add(q3, + * BooleanClause.Occur.SHOULD); } + */ + // Query query = + // boostQueryDistrictNewPolicy.create(ServiceUtil.removeAndGetKeyword(params)); + params.add(new QueryParam("$sr", new SrQuery(query))); + // params.add(new QueryParam("keyword", + // QueryParser.escape(model.getKeyword()).toLowerCase())); + + } + List districts = districtService.findAllByParams(params, 0, model.getMax(), new String[]{"city", + "region", "name", "alias", "address", "addrAlias", "lat2", "lng2", "householdCount"}); + + List result = new ArrayList(); + if (districts != null) { + for (District district : districts) { + BasicDBObject item = new BasicDBObject(); + item.append("city", district.getCity()); + item.append("district", district.getRegion()); + item.append("name", district.getName()); + item.append("address", district.getAddress()); + item.append("latBaidu", district.getLat2()); + item.append("lngBaidu", district.getLng2()); + item.append("houseHoldCount", district.getHouseholdCount()); + if (district.getAlias() != null && district.getAlias().size() > 0) { + item.append("alias", district.getAlias()); + } + if (CollectionUtils.isNotEmpty(district.getAddrAlias())) { + item.append("address_alias", district.getAddrAlias()); + } + result.add(item); + } + } + mav.setModel(BasicModel.buildOKModel().setResult(result)); + } else { + if (model.getMax() == null || model.getMax() < 1 || model.getMax() > 20) { + model.setMax(10); + } + List autoCompleteBos = autoCompleteService.suggest("district", type, model.getCity(), + model.getKeyword(), model.getMax()); + List result = new ArrayList(); + if (autoCompleteBos != null) { + for (AutoCompleteBo bo : autoCompleteBos) { + BasicDBObject item = new BasicDBObject(); + item.append("city", model.getCity()); + item.append("district", bo.getRegion()); + item.append("name", bo.getVal()); + item.append("address", bo.getDesc()); + result.add(item); + } + } + mav.setModel(BasicModel.buildOKModel().setResult(result)); + } + + return mav; + } + + /** + * 解析出关键字中的小区名 + * + * @param keyword + * @return + */ + private String tokenDistrictName(String keyword) { + List tokens = CnTokenizer.tokenizer(keyword); + Token token = getTokenByType(tokens, KeywordEnum.district); + if (token != null && "district".equals(token.getKeywordTypes())) { + return token.getName(); + } + return null; + } + + private Token getTokenByType(List tokens, KeywordEnum type) { + for (Token token : tokens) { + if (token.containsType(type)) { + return token; + } + } + return null; + } + + public Object similarSortAction(PropertyEvaluationModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("city(城市)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("district(区域)不能为空")); + return mav; + } + if (StringUtils.isBlank(model.getName())) { + mav.setModel(BasicModel.buildBadRequestModel("name(小区名)不能为空")); + return mav; + } + if (0 >= model.getSize()) { + mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能为空")); + return mav; + } + // 在库中找到对应的小区 + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + + Integer avgPrice = 0; + Integer tatalPrice = 0; + int count = 0; + List listHouse = similarCommMethod(model, "similarSort", district); + + // 查找均价 + List districtStats = districtStatService.findAllDistrictStatsSort(district.getCity(), + district.getRegion(), district.getName(), model.getCalDate()); + Integer districtAvg = 0; + if (districtStats != null && !districtStats.isEmpty()) { + DistrictStat districtStat = districtStats.get(0); + districtAvg = districtStat.getAvgPrice(); + } + for (House house : listHouse) { + long temp = Math.round(house.getTotalPrice() / house.getArea()); + if (temp > districtAvg * 1.3 || temp < districtAvg * 0.7) { + continue; + } + avgPrice = (int) temp + avgPrice; + count++; + } + if (count == 0) { + mav.setModel(BasicModel.buildOKModel().setMsg("该小区无均价")); + return mav; + } + avgPrice = avgPrice / count; + tatalPrice = (int) Math.round(avgPrice * model.getSize()); + Map districtPriceMap = new HashMap(); + districtPriceMap.put("city", district.getCity()); + districtPriceMap.put("district", district.getRegion()); + districtPriceMap.put("name", district.getName()); + districtPriceMap.put("totalPrice", tatalPrice); + districtPriceMap.put("avgPrice", avgPrice); + mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); + return mav; + } + + public String getDomainName(String url) { + if (StringUtils.isNotBlank(url)) { + Pattern p = Pattern.compile("[^//]*?\\.(com|cn|net|org|biz|info|cc|tv)", Pattern.CASE_INSENSITIVE); + Matcher matcher = p.matcher(url); + if (matcher.find()) { + return matcher.group(); + } + } + return "fangjia.com"; + } + + private Integer getFloor(String roomNumber) { + if (StringUtils.isNotBlank(roomNumber) && DataUtil.isNumber(roomNumber)) { + if (roomNumber.length() == 3) { + return Integer.valueOf(roomNumber.substring(0, 1)); + } else if (roomNumber.length() == 4) { + return Integer.valueOf(roomNumber.substring(0, 2)); + } else { + return null; + } + } + return null; + } + + private boolean checkExists(FacetQueryResult houseBoList, NewHousePojo house) { + for (NewHousePojo bo : houseBoList) { + boolean sameName = bo.getName().equals(house.getName()); + boolean sameAddress = bo.getAddress() != null ? bo.getAddress().equals(house.getAddress()) + : house.getAddress() == null; + boolean sameTotalPrice = bo.getListingPrice() != null ? bo.getListingPrice().equals(house.getListingPrice()) + : house.getListingPrice() == null; + boolean samePublishDate = bo.getPublishDate() != null ? bo.getPublishDate().equals(house.getPublishDate()) + : house.getPublishDate() == null; + boolean sameArea = bo.getSize() != null ? bo.getSize().equals(house.getSize()) : house.getSize() == null; + boolean sameFloor = bo.getFloor() != null ? bo.getFloor().equals(house.getFloor()) + : house.getFloor() == null; + if (sameName && sameAddress && sameFloor && sameTotalPrice && samePublishDate && sameArea) { + return true; + } + } + return false; + } + + /** + * 小区统计分析接口 + * + * @param model + * @return + */ + public Object analysisAction(DistrictQueryModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); + return mav; + } + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (null == district) { + mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); + return mav; + } + if (district.getLat2() == null || district.getLng2() == null) { + + mav.setModel(BasicModel.buildOKModel()); + return mav; + } + + DistrictKey districtKey = new DistrictKey(district.getCity(), district.getRegion(), district.getName()); + DistrictAttentionRank attention = districtAttentionRankService.findByDistrictKey(districtKey);// 小区关注度信息 + CityHot cityHot = cityHotService.findByCity(district.getCity()); + DistrictHot districtHot = districtHotService.findDistrictHotByDistrictKey(districtKey); + if (null != districtHot) { + if (null != districtHot.getHouseLastMonth() && districtHot.getHouseLastMonth() > 0) { + int lastMonthHouses = districtHot.getHouseLastMonth();// 上月挂牌量 + + if (null != cityHot && null != cityHot.getSellMarkupMonth()) { + districtHot.setHouseHalfYear( + (int) (lastMonthHouses * 6 * (1 + cityHot.getSellMarkupMonth() / 10000.0))); + } else { + districtHot.setHouseHalfYear((int) (lastMonthHouses * 6 * 0.9625)); + } + } + } + + double lat = district.getLat2() / 10000000000d; + double lng = district.getLng2() / 10000000000d; + double radius = 1000d; + double aroundAvgConsumption = bizShopService.findAroundAvgConsumption(lat, lng, radius, "餐厅");// 周边消费人均 + + int regionClickRank = 0; + int cityClickRank = 0; + int houseLastMonth = 0; + int houseHalfYear = 0; + + if (attention != null) { + if (attention.getRegionClickRank() != null) { + regionClickRank = attention.getRegionClickRank(); + } + if (attention.getCityClickRank() != null) { + cityClickRank = attention.getCityClickRank(); + } + } + + if (districtHot != null) { + if (districtHot.getHouseHalfYear() != null) { + houseHalfYear = districtHot.getHouseHalfYear(); + } + if (districtHot.getHouseLastMonth() != null) { + houseLastMonth = districtHot.getHouseLastMonth(); + } + } + + DistrictAnalysisDto districtAnalysisDto = new DistrictAnalysisDto(); + districtAnalysisDto.setCity(district.getCity());// 城市 + districtAnalysisDto.setDistrict(district.getRegion());// 区域 + districtAnalysisDto.setName(district.getName());// 小区名 + districtAnalysisDto.setAvgPriceAround((int) aroundAvgConsumption);// 周边餐饮平均消费 + districtAnalysisDto.setDistrictClickRank(regionClickRank);// 区域关注度排名 + districtAnalysisDto.setCityClickRank(cityClickRank);// 全市关注度排名 + districtAnalysisDto.setHouseHalfYear(houseHalfYear);// 近半年小区挂牌量 + districtAnalysisDto.setHouseLastMonth(houseLastMonth);// 上月小区挂牌量 + + mav.setModel(BasicModel.buildOKModel().setResult(districtAnalysisDto)); + return mav; + } + + /** + * 小区交通接口 + * + * @param model + * @return + */ + public Object trafficAction(DistrictQueryModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); + return mav; + } + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (null == district) { + mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); + return mav; + } + if (district.getLat2() == null || district.getLng2() == null) { + + mav.setModel(BasicModel.buildOKModel()); + return mav; + } + + double lat = district.getLat2() / 10000000000d; + double lng = district.getLng2() / 10000000000d; + double radius = 1000d; + + Map> stationMap = busStationService.getNearByStations(district.getCity(), lat, lng, + radius);// 查询交通信息(公交,地铁) bus_station,bus_line + List MetroStations = stationMap.get("地铁"); + List BusStation = stationMap.get("公交"); + + List StationDtos = new ArrayList(); + if (MetroStations != null) { + for (BusStation station : MetroStations) { + StationDto stationDto = new StationDto(); + stationDto.setName(station.getStation()); + stationDto.setLineName(station.getLineId()); + StationDtos.add(stationDto); + } + } + + if (BusStation != null) { + for (BusStation station : BusStation) { + StationDto stationDto = new StationDto(); + stationDto.setName(station.getStation()); + stationDto.setLineName(station.getLineId()); + StationDtos.add(stationDto); + } + } + + mav.setModel(BasicModel.buildOKModel().setResult(StationDtos)); + return mav; + } + + /** + * 小区周边接口 + * + * @param model + * @return + */ + public Object aroundAction(DistrictQueryModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict())) { + mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名)是必须参数")); + return mav; + } + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (null == district) { + mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); + return mav; + } + if (district.getLat2() == null || district.getLng2() == null) { + + mav.setModel(BasicModel.buildOKModel()); + return mav; + } + + double radius = 1000d;// 查周围半径为1公里距离的信息 + + List arrs = baiduApiService.searchNearbyLocalDatabase(district, radius);// 查询小区周边(所有类型) + Map> districtAroundMap = new HashMap>(); + + for (String key : AROUND_KEYWORD_FACTOR.keySet()) { + + List aroundNames = new ArrayList(); + districtAroundMap.put(AROUND_KEYWORD_FACTOR.get(key), aroundNames);// 把key的英文put到map并把value设置为一个List引用 + + } + for (int i = 0; i < arrs.size(); i++) { + BaiduPlacePoi poiObj = arrs.get(i); + String name = poiObj.getName(); + String keyword = poiObj.getKeyword(); + double latjs = poiObj.getLat(); + double lngjs = poiObj.getLng(); + String key = AROUND_KEYWORD_FACTOR.get(keyword); + + AroundDto dto = new AroundDto(); + dto.setName(name); + dto.setLat(latjs); + dto.setLng(lngjs); + if (districtAroundMap.get(key) != null) { + districtAroundMap.get(key).add(dto);// 按key值取出list add 周边名称已经经纬度 + } + + } + mav.setModel(BasicModel.buildOKModel().setResult(districtAroundMap)); + return mav; + } + + /** + * 相同小区相似户型房源挂牌量接口
+ * 获取该小区的满足指定相似条件的挂牌房源量 条件说明: 1.输入面积-5<=房源面积<=输入面积+5 2.上个月发布的房源 + * + * @param city 城市 + * @param district 区域 + * @param name 小区名 + * @param size 面积 + * @return + * @author yinjihuan + * @date 2016年9月1日 + */ + public Object similarHouseAmoutAction(@Param(name = "city") String city, @Param(name = "district") String district, + @Param(name = "name") String name, @Param(name = "size") Double size) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(city) || StringUtils.isBlank(name) || StringUtils.isBlank(district) || size == null) { + mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名),size(面积)是必须参数")); + return mav; + } + if (size <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能小于0")); + return mav; + } + District districtInfo = districtService.findByNameAndAlias(city, district, name, "district"); + if (null == districtInfo) { + mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); + return mav; + } + long result = districtHouseResourceStatService.findSimilarHouseAmoutCount(districtInfo.getId(), size); + BasicModel model = new BasicModel(200, "ok"); + model.setResult(result); + mav.setModel(model); + return mav; + } + + /** + * 周边小区相似户型挂牌量接口
+ * 获取该小区的满足指定相似条件的挂牌房源量 条件说明: 1.输入面积-5<=房源面积<=输入面积+5 2.上个月发布的房源 + * + * @param city 城市 + * @param district 区域 + * @param name 小区名 + * @param size 面积 + * @param radius 周边小区最大半径(单位:米,默认2000) + * @return + * @author yinjihuan + * @date 2016年9月1日 + */ + public Object nearbySimilarHouseAmoutAction(@Param(name = "city") String city, + @Param(name = "district") String district, @Param(name = "name") String name, + @Param(name = "size") Double size, @Param(name = "radius") Integer radius) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(city) || StringUtils.isBlank(name) || StringUtils.isBlank(district) || size == null) { + mav.setModel(BasicModel.buildBadRequestModel("参数缺失:city(城市),district(区域),name(小区名),size(面积)是必须参数")); + return mav; + } + if (size <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("size(面积)不能小于0")); + return mav; + } + District districtInfo = districtService.findByNameAndAlias(city, district, name, "district"); + if (null == districtInfo) { + mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); + return mav; + } + if (radius == null) { + radius = 2000; + } + // 找出小区周边范围类的小区 + List districts = districtService.findNearestDistrict(districtInfo, radius, 500); + List districtIds = new ArrayList(); + for (District dis : districts) { + districtIds.add(dis.getId()); + } + districtIds.add(districtInfo.getId()); + BasicModel model = new BasicModel(200, "ok"); + model.setResult(districtHouseResourceStatService.findNearbySimilarHouseAmoutCount(size, districtIds)); + mav.setModel(model); + return mav; + } + + /** + * 小区周边一公里均价 + * + * @param model + * @return + * @author wenyan + */ + public Object aroundAverageAction(@Valid AroundAverageModel model) { + + RestfulModelAndView mav = new RestfulModelAndView(); + DistrictKey key = new DistrictKey(model.getCity(), model.getDistrict(), model.getName()); + DistrictAnalyData districtAnalyData = districtAnalyDataService.findByDistrictKey(key); + BasicModel dataModel = BasicModel.buildOKModel(); + if (districtAnalyData != null && districtAnalyData.getAroundDistrictAvgPrice() != null) { + UniversalDto dto = UniversalDto.newDto(); + dto.append("averagePrice", districtAnalyData.getAroundDistrictAvgPrice()); + dataModel.setResult(dto); + } + mav.setModel(dataModel); + return mav; + + } + + /** + * 相同小区相似户型租金范围查询接口 + * + * @param model + * @return + */ + public Object similarHouseRentRangeAction(@Valid RentModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (null == district) { + mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); + return mav; + } + + // List houseBos = + // houseService.findDistrictHouseByCat(district.getCity(), district.getRegion(), + // district.getName(), 100, null, model.getSize()-5, model.getSize()+5); + Integer room = houseService.getDistrictRoomType(model.getSize()); + if (null == room) { + mav.setModel(BasicModel.buildBadRequestModel("根据size(面积)没有找到相应的室")); + return mav; + } + + List districtStatRents = districtStatRentService.findLatestDistrictStatRent(district, 1, + (int) room); + if (null == districtStatRents || districtStatRents.size() == 0) { + mav.setModel(BasicModel.buildOKModel()); + } else { + DistrictStatRent districtStatRent = districtStatRents.get(0); + Map rentRangeMap = new HashMap(); + if (districtStatRent.getAvgPrice() > 0) { + Integer avgPrice = districtStatRent.getAvgPrice(); + rentRangeMap.put("min", (int) (avgPrice - avgPrice * 0.08)); + rentRangeMap.put("max", (int) (avgPrice + avgPrice * 0.08)); + } + mav.setModel(BasicModel.buildOKModel().setResult(rentRangeMap)); + } + return mav; + } + + /** + * 周边小区相似户型租金范围查询接口 + * + * @param model + * @return + */ + public Object nearlySimilarHouseRentRangeAction(@Valid RentModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (null == district) { + mav.setModel(BasicModel.buildBadRequestModel("小区不存在")); + return mav; + } + if (null == model.getRadius()) {// 设置默认值 + model.setRadius(2000); + } + + List districts = districtService.findNearestDistrict(district, model.getRadius(), 500); + if (null != districts) { + // List houseBos = new ArrayList(); + // for(District dist : districts){ + // List bos = houseService.findDistrictHouseByCat(dist.getCity(), + // dist.getRegion(), dist.getName(), 100, null, model.getSize()-5, + // model.getSize()+5); + // houseBos.addAll(bos); + // } + Integer room = houseService.getDistrictRoomType(model.getSize()); + if (null == room) { + mav.setModel(BasicModel.buildBadRequestModel("根据size(面积)没有找到相应的室")); + return mav; + } + + List prices = new ArrayList(); + for (District dist : districts) { + List districtStatRents = districtStatRentService.findLatestDistrictStatRent(dist, 1, + room); + if (null != districtStatRents && districtStatRents.size() > 0) { + DistrictStatRent districtStatRent = districtStatRents.get(0); + if (districtStatRent.getAvgPrice() > 0) { + Integer avgPrice = districtStatRent.getAvgPrice(); + prices.add(avgPrice); + } + } + } + + Map rentRangeMap = new HashMap(); + if (prices.size() > 0) { + Collections.sort(prices); + rentRangeMap.put("min", prices.get(0)); + rentRangeMap.put("max", prices.get(prices.size() - 1)); + mav.setModel(BasicModel.buildOKModel().setResult(rentRangeMap)); + } else { + mav.setModel(BasicModel.buildOKModel()); + } + } else { + mav.setModel(BasicModel.buildBadRequestModel("没找到周边小区")); + } + + return mav; + } + + /** + * 室号查询接口 + * + * @param model + * @return + */ + public Object roomAction(@Valid RoomModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + + List queryParams = new ArrayList(); + queryParams.add(new QueryParam("city", model.getCity())); + queryParams.add(new QueryParam("region", model.getDistrict())); + queryParams.add(new QueryParam("name", model.getProjectName())); + queryParams.add(new QueryParam("houseNum", model.getBuildingNumber())); + queryParams.add(new QueryParam("houseNumUnit", model.getUnitNumber())); + if (model.getFloor() != null) { + queryParams.add(new QueryParam("houseFloor", model.getFloor())); + } + List sortParams = new ArrayList(); + sortParams.add(new SortParam("houseFloor", true)); + List houseLoudongs = houseLoudongService.findAll(queryParams, new Pager(Integer.MAX_VALUE)); + List rooms = new ArrayList(); + for (HouseLoudong houseLoudong : houseLoudongs) { + if ("--".equals(houseLoudong.getRoomNum())) { + continue; + } + RoomDto dto = new RoomDto(); + dto.setDisplay(houseLoudong.getRoomNum() + "室"); + dto.setUnitNumber(houseLoudong.getHouseNumUnit()); + dto.setRoom(houseLoudong.getRoomNum()); + rooms.add(dto); + } + mav.setModel(BasicModel.buildOKModel().setResult(rooms)); + return mav; + } + + /** + * 楼栋楼层信息查询接口 + * + * @param model + * @return + */ + public Object floorsAction(@Valid FloorsModel model) { + + RestfulModelAndView mav = new RestfulModelAndView(); + List loudongs = loudongService.findAll(model.getCity(), model.getDistrict(), model.getProjectName(), + model.getBuildingNumber(), model.getUnitNumber(), Integer.MAX_VALUE); + if (null == loudongs || loudongs.isEmpty()) { + mav.setModel(BasicModel.buildBadRequestModel("楼栋不存在")); + return mav; + } + List floors = new ArrayList(); + if (loudongs.get(0).getFloors() > 0) { + for (int i = 1; i <= loudongs.get(0).getFloors(); i++) { + floors.add(i); + } + } + mav.setModel(BasicModel.buildOKModel().setResult(floors)); + return mav; + } + + /** + * 楼栋查询接口 + * + * @param model + * @return + */ + public Object buildingAction(@Valid BuildingModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + + List loudongs = loudongService.findAll(model.getCity(), model.getDistrict(), model.getProjectName(), + null, null, Integer.MAX_VALUE); + List dtos = new ArrayList(); + List keys = new ArrayList(); + for (Loudong loudong : loudongs) { + if (keys.contains(loudong.getHouseNumber()) || "--".equals(loudong.getHouseNumber())) { + continue; + } + BuildingDto dto = new BuildingDto(); + dto.setId(loudong.getId()); + dto.setBuildingNumber(loudong.getHouseNumber()); + dto.setLabel(loudong.getHouseNumber()); + dtos.add(dto); + keys.add(loudong.getHouseNumber()); + } + + Collections.sort(dtos, new Comparator() { + @Override + public int compare(BuildingDto o1, BuildingDto o2) { + if (StringUtils.isNumeric(o1.getBuildingNumber()) && StringUtils.isNumeric(o2.getBuildingNumber())) { + return new Double(o1.getBuildingNumber()).compareTo(new Double(o2.getBuildingNumber())); + } else if (StringUtils.isNumeric(o1.getBuildingNumber())) { + return -1; + } else if (StringUtils.isNumeric(o2.getBuildingNumber())) { + return 1; + } else { + return o1.getBuildingNumber().compareTo(o2.getBuildingNumber()); + } + + } + }); + + mav.setModel(BasicModel.buildOKModel().setResult(dtos)); + return mav; + } + + /** + * 楼栋查询接口 + * + * @param model + * @return + */ + public Object unitNumberAction(@Valid UnitNumberModel model) { + RestfulModelAndView mav = new RestfulModelAndView(); + + List loudongs = loudongService.findAll(model.getCity(), model.getDistrict(), model.getProjectName(), + model.getBuildingNumber(), null, Integer.MAX_VALUE); + + List dtos = new ArrayList(); + List keys = new ArrayList(); + for (Loudong loudong : loudongs) { + if (keys.contains(loudong.getUnitNumber()) || "--".equals(loudong.getUnitNumber())) { + continue; + } + UnitNumberDto dto = new UnitNumberDto(); + dto.setId(loudong.getId()); + dto.setBuildingNumber(loudong.getHouseNumber()); + dto.setUnitNumber(loudong.getUnitNumber()); + dto.setLabel(loudong.getUnitNumber()); + dtos.add(dto); + keys.add(loudong.getUnitNumber()); + } + Collections.sort(dtos, new Comparator() { + @Override + public int compare(UnitNumberDto o1, UnitNumberDto o2) { + if (StringUtils.isNumeric(o1.getUnitNumber()) && StringUtils.isNumeric(o2.getUnitNumber())) { + return new Double(o1.getUnitNumber()).compareTo(new Double(o2.getUnitNumber())); + } else if (StringUtils.isNumeric(o1.getUnitNumber())) { + return -1; + } else if (StringUtils.isNumeric(o2.getUnitNumber())) { + return 1; + } else { + return o1.getUnitNumber().compareTo(o2.getUnitNumber()); + } + + } + }); + + mav.setModel(BasicModel.buildOKModel().setResult(dtos)); + return mav; + } + + public Object avgPrice2Action(@Param(name = "city") String city, @Param(name = "district") String district, + @Param(name = "name") String name) { + + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(city) || StringUtils.isBlank(district) || StringUtils.isBlank(name)) { + mav.setModel(BasicModel.buildBadRequestModel("小区所在城市,所在区域,小区名为必填项")); + return mav; + } + + District districtBo = districtService.findByNameAndAlias(city, district, name, "district"); + if (null == districtBo) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + + DistrictStatBo districtStatBo = districtStatService + .findDistrictStat(new DistrictKey(districtBo.getCity(), districtBo.getRegion(), districtBo.getName())); + if (null == districtStatBo || (districtStatBo != null && districtStatBo.getDistrictStat() == null + && districtStatBo.getVillaDistrictStat() == null)) { + mav.setModel(BasicModel.buildOKModel()); + return mav; + } + Integer lastAvgPrice = averageAnalyService.getLastAvgPrice(districtBo, districtStatBo); + Map map = new HashMap(); + map.put("city", districtBo.getCity()); + map.put("district", districtBo.getRegion()); + map.put("name", districtBo.getName()); + map.put("avgPrice", lastAvgPrice); + if (districtStatBo.getDistrictStat() != null) { + map.put("date", DateUtil.formatByPattern(districtStatBo.getDistrictStat().getWeekend(), "yyyy-MM-dd")); + } else if (districtStatBo.getVillaDistrictStat() == null) { + map.put("date", DateUtil.formatByPattern(districtStatBo.getVillaDistrictStat().getWeekend(), "yyyy-MM-dd")); + } + + mav.setModel(BasicModel.buildOKModel().setResult(map)); + return mav; + } + + private Map getLastEvaluationPrice(District district, Evaluation evaluation, double dCredit) + throws NumberFormatException, IllegalAccessException { + Date startDate = DateUtil.parseDate(DateUtil.addMonth(new Date(), -6), "yyyy-MM-dd"); + // 第三方价格 + Map otherPriceRets = averageStatisticsService.findFirstAverageStatictics(district.getCity(), + district.getRegion(), district.getName(), district.getCategory(), startDate); + if (null == otherPriceRets) { + otherPriceRets = new HashMap(); + } + + otherPriceRets.put("fjw_price", evaluation.getAvgPrice()); + Map levelMap = getPriceLevel(otherPriceRets, evaluation.getCredit()); + Long lastPrice = getLastPrice(levelMap, otherPriceRets, evaluation, dCredit); + + Map rMap = new HashMap(); + rMap.put("lastPrice", lastPrice); + if (null != levelMap && levelMap.containsKey("level")) { + String priceLevel = (String) levelMap.get("level"); + rMap.put("level", priceLevel); + } + rMap.put("other_price", otherPriceRets); + return rMap; + } + + private Long getLastPrice(Map retMap, Map otherPriceRets, Evaluation evaluation, double dCredit) { + Long lastPrice = null; + if (null != retMap) { + String priceLevel = (String) retMap.get("level"); + + if (priceLevel.equals("D")) { + + lastPrice = inputResultByWebsite(otherPriceRets, evaluation, dCredit); + + } else if (priceLevel.equals("E")) { + if (evaluation.getCredit() >= 0.65) { + lastPrice = evaluation.getBigTotalPrice(); + } else { + List prices = (List) retMap.get("prices"); + int avgPrice = 0; + if (prices != null) { + avgPrice = findNewPrice(prices, evaluation.getAvgPrice()); + } + // 在 dCredit与0.65之间 + if (evaluation.getCredit() >= dCredit && dCredit < 0.65) { + if (avgPrice > 0) { + Double newTotalPrice = avgPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else { + if (null != otherPriceRets.get("lianjia_price")) { + Integer lianjiaPrice = (Integer) otherPriceRets.get("lianjia_price"); + Double newTotalPrice = lianjiaPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else if (null != otherPriceRets.get("zhugezhaofang_price")) { + Integer zhugezhaofangPrice = (Integer) otherPriceRets.get("zhugezhaofang_price"); + Double newTotalPrice = zhugezhaofangPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else if (null != otherPriceRets.get("yungujia_price")) { + Integer yungujiaPrice = (Integer) otherPriceRets.get("yungujia_price"); + Double newTotalPrice = yungujiaPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else if (null != otherPriceRets.get("fanggugu_price")) { + Integer fangguguPrice = (Integer) otherPriceRets.get("fanggugu_price"); + Double newTotalPrice = fangguguPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else { + lastPrice = evaluation.getBigTotalPrice(); + } + } + } else if (evaluation.getCredit() < dCredit) {// 在dCredit以下 + if (avgPrice > 0) { + Double newTotalPrice = avgPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else { + if (null != otherPriceRets.get("lianjia_price")) { + Integer lianjiaPrice = (Integer) otherPriceRets.get("lianjia_price"); + Double newTotalPrice = lianjiaPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else if (null != otherPriceRets.get("zhugezhaofang_price")) { + Integer zhugezhaofangPrice = (Integer) otherPriceRets.get("zhugezhaofang_price"); + Double newTotalPrice = zhugezhaofangPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else if (null != otherPriceRets.get("yungujia_price")) { + Integer yungujiaPrice = (Integer) otherPriceRets.get("yungujia_price"); + Double newTotalPrice = yungujiaPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else if (null != otherPriceRets.get("fanggugu_price")) { + Integer fangguguPrice = (Integer) otherPriceRets.get("fanggugu_price"); + Double newTotalPrice = fangguguPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } + } + } + } + + } else if (priceLevel.equals("C")) { + List smallPrices = (List) retMap.get("small_prices"); + if (smallPrices != null) { + smallPrices.add(evaluation.getAvgPrice()); + int avgPrice = sum(smallPrices) / smallPrices.size(); + Double newTotalPrice = avgPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } + } else { + lastPrice = evaluation.getBigTotalPrice(); + } + } + return lastPrice; + } + + private Long inputResultByWebsite(Map otherPriceRets, Evaluation evaluation, double dCredit) { + Long lastPrice = null; + if (evaluation.getCredit() >= dCredit) { + lastPrice = evaluation.getBigTotalPrice(); + } else { + if (evaluation.getCredit() < dCredit) { + if (null != otherPriceRets.get("lianjia_price")) { + Integer lianjiaPrice = (Integer) otherPriceRets.get("lianjia_price"); + Double newTotalPrice = lianjiaPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else if (null != otherPriceRets.get("zhugezhaofang_price")) { + Integer zhugezhaofangPrice = (Integer) otherPriceRets.get("zhugezhaofang_price"); + Double newTotalPrice = zhugezhaofangPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else if (null != otherPriceRets.get("yungujia_price")) { + Integer yungujiaPrice = (Integer) otherPriceRets.get("yungujia_price"); + Double newTotalPrice = yungujiaPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else if (null != otherPriceRets.get("fanggugu_price")) { + Integer fangguguPrice = (Integer) otherPriceRets.get("fanggugu_price"); + Double newTotalPrice = fangguguPrice * evaluation.getArea(); + lastPrice = newTotalPrice.longValue(); + } else { + lastPrice = evaluation.getBigTotalPrice(); + } + } else { + lastPrice = evaluation.getBigTotalPrice(); + } + } + return lastPrice; + } + + private Integer findNewPrice(List prices, int avgPrice) { + int minValue1 = Integer.MAX_VALUE; + List> values = new ArrayList>(); + int fjw_price = avgPrice; + + // 找出最小差 + for (int i = 0; i < prices.size() - 1; i++) { + int a = prices.get(i); + for (int j = i + 1; j < prices.size(); j++) { + int b = prices.get(j); + int mod = Math.abs(a - b); + if (mod < minValue1) { + minValue1 = mod; + } + } + } + + // 根据最小差找出结果 + for (int i = 0; i < prices.size() - 1; i++) { + int a = prices.get(i); + for (int j = i + 1; j < prices.size(); j++) { + int b = prices.get(j); + int mod = Math.abs(a - b); + if (mod == minValue1) { + values.add(Arrays.asList(a, b)); + } + } + } + + int minValue2 = Integer.MAX_VALUE; + int lastValue = 0; + if (values.size() >= 1) { + for (List value : values) { + int newPrice = (value.get(0) + value.get(1)) / 2; + int mod = Math.abs(fjw_price - newPrice); + if (mod < minValue2) { + minValue2 = mod; + lastValue = newPrice; + } + } + } + + if (lastValue > 0) { + double temp = DataUtil.getDoubleRound(2, minValue1 * 100 / lastValue); + temp = Math.abs(temp); + if (temp > 15) { + lastValue = 0; + } + } + return lastValue; + } + + private Integer sum(List smallPrices) { + int sum = 0; + for (int price : smallPrices) { + sum += price; + } + return sum; + } + + private Map getPriceLevel(Map otherPriceRets, double credit) { + + Integer avgPrice = (Integer) otherPriceRets.get("fjw_price"); + + int keyCount = 0; + int commonCount = 0; + int isExistCount = 0; + + List prices = new ArrayList(); + List smallPrices = new ArrayList(); + + if (null != otherPriceRets.get("fanggugu_price")) { + Integer fangguguPrice = (Integer) otherPriceRets.get("fanggugu_price"); + int mod = avgPrice - fangguguPrice; + double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); + temp = Math.abs(temp); + if (temp <= 15) { + keyCount++; + } else { + prices.add(fangguguPrice); + } + isExistCount++; + } + if (null != otherPriceRets.get("yungujia_price")) { + Integer yungujiaPrice = (Integer) otherPriceRets.get("yungujia_price"); + int mod = avgPrice - yungujiaPrice; + double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); + temp = Math.abs(temp); + if (temp <= 15) { + keyCount++; + } else { + prices.add(yungujiaPrice); + } + + isExistCount++; + } + + if (null != otherPriceRets.get("zhugezhaofang_price")) { + Integer zhugezhaofangPrice = (Integer) otherPriceRets.get("zhugezhaofang_price"); + int mod = avgPrice - zhugezhaofangPrice; + double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); + temp = Math.abs(temp); + if (temp <= 15) { + keyCount++; + } else { + prices.add(zhugezhaofangPrice); + } + + isExistCount++; + } + + if (null != otherPriceRets.get("lianjia_price")) { + Integer lianjiaPrice = (Integer) otherPriceRets.get("lianjia_price"); + int mod = avgPrice - lianjiaPrice; + double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); + temp = Math.abs(temp); + if (temp <= 15) { + keyCount++; + } else { + prices.add(lianjiaPrice); + } + isExistCount++; + } + if (null != otherPriceRets.get("anjuke_price")) { + Integer anjukePrice = (Integer) otherPriceRets.get("anjuke_price"); + int mod = avgPrice - anjukePrice; + double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); + temp = Math.abs(temp); + if (temp <= 15) { + commonCount++; + smallPrices.add(anjukePrice); + } else { + prices.add(anjukePrice); + } + + isExistCount++; + } + if (null != otherPriceRets.get("ganji_price")) { + Integer ganjiPrice = (Integer) otherPriceRets.get("ganji_price"); + int mod = avgPrice - ganjiPrice; + double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); + temp = Math.abs(temp); + if (temp <= 15) { + commonCount++; + smallPrices.add(ganjiPrice); + } else { + prices.add(ganjiPrice); + } + + isExistCount++; + } + if (null != otherPriceRets.get("soufan_price")) { + Integer soufan_price = (Integer) otherPriceRets.get("soufan_price"); + int mod = avgPrice - soufan_price; + double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); + temp = Math.abs(temp); + if (temp <= 15) { + commonCount++; + smallPrices.add(soufan_price); + } else { + prices.add(soufan_price); + } + + isExistCount++; + } + if (null != otherPriceRets.get("tobushi_price")) { + Integer tobushi = (Integer) otherPriceRets.get("tobushi_price"); + int mod = avgPrice - tobushi; + double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); + temp = Math.abs(temp); + if (temp <= 15) { + commonCount++; + smallPrices.add(tobushi); + } else { + prices.add(tobushi); + } + + isExistCount++; + } + + if (null != otherPriceRets.get("zhongyuan_price")) { + Integer zhongyuanPrice = (Integer) otherPriceRets.get("zhongyuan_price"); + int mod = avgPrice - zhongyuanPrice; + double temp = DataUtil.getDoubleRound(2, mod * 100 / avgPrice); + temp = Math.abs(temp); + if (temp <= 15) { + commonCount++; + smallPrices.add(zhongyuanPrice); + } else { + prices.add(zhongyuanPrice); + } + + isExistCount++; + } + + Map retMap = new HashMap(); + String level = null; + if (keyCount >= 2) { + level = "A"; + } else if (keyCount >= 1 && commonCount >= 1) { + level = "A"; + } else if (keyCount >= 1 || commonCount >= 2) { + level = "B"; + } else if (commonCount >= 1) { + level = "C"; + } else if (isExistCount == 0) { + level = "D"; + } else if (isExistCount >= 1) { + if (isExistCount == 1) { + level = "D"; + } else { + level = "E"; + } + } + + if (credit == 0) { + level = "E"; + } + + if (StringUtils.isNotBlank(level)) { + retMap.put("level", level); + retMap.put("prices", prices); + retMap.put("small_prices", smallPrices); + } + return retMap; + } + + /** + * 房产交易记录查询 + * + * @param model + * @return + */ + public Object transactionRecordAction(PropertySearchModel model) { + // 输入(model中拿取) city+district+name+houseNum(楼栋号)+roomNum(室号) trade_date倒序 + // max查询条数 + // 输出 + // {"result":{"districtCnt":"小区1年内成交数量","transactionList":[{"time":"yyyy-MM-dd","price":"xxx万"}]}} + // time是每笔的成交时间,price是每笔的成交金额,注意看数据格式 + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + String city = model.getCity(); + String district = model.getDistrict(); + String name = model.getName(); + String houseNum = model.getHouseNum(); + String roomNum = model.getRoomNum(); + int max = model.getMax() == null ? 10 : model.getMax(); + if (StringUtils.isBlank(city)) { + mav.setModel(BasicModel.buildBadRequestModel("城市(city)不能为空")); + return mav; + } + if (StringUtils.isBlank(district)) { + mav.setModel(BasicModel.buildBadRequestModel("区域(district)不能为空")); + return mav; + } + if (StringUtils.isBlank(name)) { + mav.setModel(BasicModel.buildBadRequestModel("小区名(name)不能为空")); + return mav; + } + if (StringUtils.isBlank(houseNum)) { + mav.setModel(BasicModel.buildBadRequestModel("楼栋号(houseNum)不能为空")); + return mav; + } + if (StringUtils.isBlank(roomNum)) { + mav.setModel(BasicModel.buildBadRequestModel("室号(roomNum)不能为空")); + return mav; + } + Date curDate = new Date(); + // 小区1年内成交数量 + long count = dealPriceService.findTradeCount(city, district, name, DateUtil.getDateOfLastMonth(curDate, -12), + curDate); + List list = dealPriceService.findMaxTrade(city, district, name, houseNum, roomNum, max); + List transactionList = new ArrayList(); + for (DealPrice dealPrice : list) { + HouseDealPriceDetailDto detail = new HouseDealPriceDetailDto(); + detail.setPrice(dealPrice.getTotalPrice()); + detail.setPriceStr(DataUtil.roundDouble((dealPrice.getTotalPrice() / 10000d), 2) + "万"); + detail.setTime(DateUtil.formatByPattern(dealPrice.getTradeDate(), "yyyy-MM-dd")); + transactionList.add(detail); + } + HouseDealPriceDto dto = new HouseDealPriceDto(); + dto.setDistrictCnt(count); + dto.setTransactionList(transactionList); + mav.setModel(BasicModel.buildOKModel().setResult(dto)); + return mav; + } + + /** + * 房产拍卖记录 + * + * @param model + * @return + */ + public Object auctionRecordAction(PropertySearchModel model) { + // 拍卖记录表是fangjia_crawl.house_auction HouseAuction + // 输入(model中拿取) city+district+name+houseNum(楼栋号)+roomNum(室号) announcement_date倒序 + // max查询条数 + // 输入对应的表查询字段 cityMatch+regionMatch+nameMatch+buildingNumber+roomNumber + // 输出 + // {"result":{"districtCnt":"小区1年内拍卖数量","transactionList":[{"time":"yyyy-MM-dd","name":"xxx拍卖行"}]}} + // time是每笔的成交时间,name是每笔的拍卖机构,注意看数据格式 + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + String city = model.getCity(); + String district = model.getDistrict(); + String name = model.getName(); + String houseNum = model.getHouseNum(); + String roomNum = model.getRoomNum(); + int max = model.getMax() == null ? 10 : model.getMax(); + if (StringUtils.isBlank(city)) { + mav.setModel(BasicModel.buildBadRequestModel("城市(city)不能为空")); + return mav; + } + if (StringUtils.isBlank(district)) { + mav.setModel(BasicModel.buildBadRequestModel("区域(district)不能为空")); + return mav; + } + if (StringUtils.isBlank(name)) { + mav.setModel(BasicModel.buildBadRequestModel("小区名(name)不能为空")); + return mav; + } + if (StringUtils.isBlank(houseNum)) { + mav.setModel(BasicModel.buildBadRequestModel("楼栋号(houseNum)不能为空")); + return mav; + } + if (StringUtils.isBlank(roomNum)) { + mav.setModel(BasicModel.buildBadRequestModel("室号(roomNum)不能为空")); + return mav; + } + Date curDate = new Date(); + // 小区1年内成交数量 + long count = houseAuctionService.findHouseAuctionCount(city, district, name, + DateUtil.getDateOfLastMonth(curDate, -12), curDate); + List list = houseAuctionService.findMaxHouseAuction(city, district, name, houseNum, roomNum, max); + List transactionList = new ArrayList(); + for (HouseAuction houseAuction : list) { + HouseAuctionDetailDto detail = new HouseAuctionDetailDto(); + detail.setName(houseAuction.getCourt()); + detail.setTime(DateUtil.formatByPattern(houseAuction.getAuctionTime(), "yyyy-MM-dd")); + transactionList.add(detail); + } + HouseAuctionDto dto = new HouseAuctionDto(); + dto.setDistrictCnt(count); + dto.setTransactionList(transactionList); + mav.setModel(BasicModel.buildOKModel().setResult(dto)); + return mav; + } + + /** + * 房产近期评估次数 + * + * @param model + * @return + */ + public Object evaluateNumAction(PropertySearchModel model) { + // 输入(model中拿取) city+district+name+houseNum(楼栋号)+roomNum(室号) + // 输出 {"result":{"oneMonth":"房屋最近30天的评估次数","threeMonth":"房屋最近90天的评估次数"}} + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + String city = model.getCity(); + String district = model.getDistrict(); + String name = model.getName(); + String houseNum = model.getHouseNum(); + String roomNum = model.getRoomNum(); + if (StringUtils.isBlank(city)) { + mav.setModel(BasicModel.buildBadRequestModel("城市(city)不能为空")); + return mav; + } + if (StringUtils.isBlank(district)) { + mav.setModel(BasicModel.buildBadRequestModel("区域(district)不能为空")); + return mav; + } + if (StringUtils.isBlank(name)) { + mav.setModel(BasicModel.buildBadRequestModel("小区名(name)不能为空")); + return mav; + } + if (StringUtils.isBlank(houseNum)) { + mav.setModel(BasicModel.buildBadRequestModel("楼栋号(houseNum)不能为空")); + return mav; + } + if (StringUtils.isBlank(roomNum)) { + mav.setModel(BasicModel.buildBadRequestModel("室号(roomNum)不能为空")); + return mav; + } + Date curDate = new Date(); + long oneMonth = evaluationService.countByHouse(city, district, name, houseNum, roomNum, + DateUtil.getDateOfLastMonth(curDate, -1), curDate); + long threeMonth = evaluationService.countByHouse(city, district, name, houseNum, roomNum, + DateUtil.getDateOfLastMonth(curDate, -3), curDate); + mav.setModel(BasicModel.buildOKModel().setResult(new HouseEvaluateNumDto(oneMonth, threeMonth))); + return mav; + } + + /*** + * 小区租金估值报告(上半部分) + * @param model + * @param request + * @return + * @throws NumberFormatException + * @throws IllegalAccessException + */ + @Authority(role = Role.NONE) + public Object rentReportAction(PropertyEvaluationModel model, HttpServletRequest request) throws NumberFormatException, IllegalAccessException { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); + return mav; + } + if (model.getCity().endsWith("市")) { + model.setCity(model.getCity().replaceAll("市$", "")); + } + if (StringUtils.isNotBlank(request.getParameter("calDate"))) { + Date calDate = null; + try { + calDate = org.apache.commons.lang.time.DateUtils.parseDate(request.getParameter("calDate"), new String[]{"yyyy-MM-dd"}); + } catch (ParseException e) { + + } + if (calDate == null) { + mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); + return mav; + } else { + model.setCalDate(calDate); + } + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + model.setName(district.getName()); + + + if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); + return mav; + } + + if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); + return mav; + } + if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { + mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); + return mav; + } + + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + + if (model.getCalDate() != null) { + if (new Date().before(model.getCalDate())) { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); + } + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } + + 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(); + districtPriceMap.put("city", district.getCity()); + districtPriceMap.put("district", district.getRegion()); + districtPriceMap.put("name", district.getName()); + districtPriceMap.put("address", district.getAddress()); + districtPriceMap.put("totalPrice", evaluation.getTotalPrice()); + districtPriceMap.put("totalPriceUpper", CurrencyConverter.toChinese(String.valueOf(evaluation.getTotalPrice()))); + districtPriceMap.put("cal_date", DateUtil.formatByPattern(new Date(), "yyyy/MM/dd")); + districtPriceMap.put("direction", evaluation.getDirection()); + districtPriceMap.put("size", evaluation.getArea()); + districtPriceMap.put("floor", model.getFloor()); + districtPriceMap.put("height", model.getHeight()); + districtPriceMap.put("fitment", evaluation.getFitment()); + districtPriceMap.put("buildYear", district.getFinishBuildingDate()); + + 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); // } @@ -5472,7 +5528,7 @@ public class PropertyController { // } // } - //相似房源 + //相似房源 // 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")); @@ -5553,488 +5609,488 @@ public class PropertyController { // 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().setResult(districtPriceMap)); + return mav; + } else { - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的租金估价").markNoData()); - return mav; - } - } + 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()); + /*** + * 小区租金估值报告(下半部分) + * @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 (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); - } - 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); - } - } - } - } - } + //周边相似小区 + 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); + //相似房源 + 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()!=null && 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) { + //周边相似小区租金 + Integer room = null; + if (model.getRoom() != null && 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 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) { + ///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); + 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; - } - } - - - public Object evaluateRentAction(PropertyEvaluationModel model, HttpServletRequest request)throws NumberFormatException, IllegalAccessException { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) - || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); - return mav; - } - if (model.getCity().endsWith("市")) { - model.setCity(model.getCity().replaceAll("市$", "")); - } - if (StringUtils.isNotBlank(request.getParameter("calDate"))) { - Date calDate = null; - try { - calDate = org.apache.commons.lang.time.DateUtils.parseDate(request.getParameter("calDate"), new String[] { "yyyy-MM-dd" }); - } catch (ParseException e) { - - } - if (calDate == null) { - mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); - return mav; - } else { - model.setCalDate(calDate); - } - } - /* 先到CPDB库中查找小区 */ - District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - if (district == null) { - mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); - return mav; - } - model.setName(district.getName()); - - - if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); - return mav; - } - - if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { - mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); - return mav; - } - if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { - mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); - return mav; - } - - model.setRegion(district.getRegion()); - model.setDistrictName(district.getName()); - if (StringUtils.isBlank(model.getPropertyType())) { - if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { - model.setPropertyType("1"); - } - } - - if (model.getCalDate() != null) { - if (new Date().before(model.getCalDate())) { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); - } - } else { - model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); - } - - 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) { - Map districtPriceMap = new HashMap(); - districtPriceMap.put("city", district.getCity()); - districtPriceMap.put("district", district.getRegion()); - districtPriceMap.put("name", district.getName()); - districtPriceMap.put("address", district.getAddress()); - districtPriceMap.put("totalPrice", evaluation.getTotalPrice()); - districtPriceMap.put("cal_date", model.getCalDate()); - mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); - return mav; - } else { - - mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的租金估价").markNoData()); - return mav; - } - } - - public Object searchHouseLoudongAction(PropertyEvaluationModel model, HttpServletRequest request)throws NumberFormatException, IllegalAccessException { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - - if (StringUtils.isBlank(model.getId()) || StringUtils.isBlank(model.getHouseNumber()) || StringUtils.isBlank(model.getRoomNumber())){ - mav.setModel(BasicModel.buildBadRequestModel("参数非法:楼盘编号,楼栋号,室为必填项")); - return mav; - } - - List houseLoudongs = houseLoudongService.findAll(model.getId(), model.getHouseNumber(), model.getUnitNumber(), model.getRoomNumber()); - mav.setModel(BasicModel.buildOKModel().setResult(houseLoudongs)); - return mav; - } - - - public Object searchLoudongAction(PropertyEvaluationModel model, HttpServletRequest request)throws NumberFormatException, IllegalAccessException { - RestfulModelAndView mav = new RestfulModelAndView(); - mav.setViewType("rest"); - - if (StringUtils.isBlank(model.getId()) || StringUtils.isBlank(model.getHouseNumber())){ - mav.setModel(BasicModel.buildBadRequestModel("参数非法:楼盘编号,楼栋号为必填项")); - return mav; - } - - - List loudongs = loudongService.findAll(model.getId(), model.getHouseNumber(), model.getUnitNumber()); - mav.setModel(BasicModel.buildOKModel().setResult(loudongs)); - return mav; - } - - - public void setHouseLoudongService(HouseLoudongService houseLoudongService) { - this.houseLoudongService = houseLoudongService; - } - - public void setFieldFilterService(FieldFilterService fieldFilterService) { - this.fieldFilterService = fieldFilterService; - } - - public void setApiUserService(ApiUserService apiUserService) { - this.apiUserService = apiUserService; - } - - public void setEvaluationService(EvaluationService evaluationService) { - this.evaluationService = evaluationService; - } - - public void setDistrictService(DistrictService districtService) { - this.districtService = districtService; - } - - public void setNoHouseDistrictService(NoHouseDistrictService noHouseDistrictService) { - this.noHouseDistrictService = noHouseDistrictService; - } - - public void setUserService(UserService userService) { - this.userService = userService; - } - - public void setHouseService(HouseService houseService) { - this.houseService = houseService; - } - - public void setAddressService(AddressService addressService) { - } - - public void setDistrictStatService(DistrictStatService districtStatService) { - this.districtStatService = districtStatService; - } - - public void setDealPriceService(DealPriceService dealPriceService) { - this.dealPriceService = dealPriceService; - } + 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; + } + } + + + public Object evaluateRentAction(PropertyEvaluationModel model, HttpServletRequest request) throws NumberFormatException, IllegalAccessException { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName()) + || StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项")); + return mav; + } + if (model.getCity().endsWith("市")) { + model.setCity(model.getCity().replaceAll("市$", "")); + } + if (StringUtils.isNotBlank(request.getParameter("calDate"))) { + Date calDate = null; + try { + calDate = org.apache.commons.lang.time.DateUtils.parseDate(request.getParameter("calDate"), new String[]{"yyyy-MM-dd"}); + } catch (ParseException e) { + + } + if (calDate == null) { + mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法")); + return mav; + } else { + model.setCalDate(calDate); + } + } + /* 先到CPDB库中查找小区 */ + District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), + "district"); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该小区不存在")); + return mav; + } + model.setName(district.getName()); + + + if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)")); + return mav; + } + + if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) { + mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)")); + return mav; + } + if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) { + mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); + return mav; + } + + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + if (StringUtils.isBlank(model.getPropertyType())) { + if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) { + model.setPropertyType("1"); + } + } + + if (model.getCalDate() != null) { + if (new Date().before(model.getCalDate())) { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate())); + } + } else { + model.setCalDate(DateUtil.getFirstDayOfWeek(new Date())); + } + + 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) { + Map districtPriceMap = new HashMap(); + districtPriceMap.put("city", district.getCity()); + districtPriceMap.put("district", district.getRegion()); + districtPriceMap.put("name", district.getName()); + districtPriceMap.put("address", district.getAddress()); + districtPriceMap.put("totalPrice", evaluation.getTotalPrice()); + districtPriceMap.put("cal_date", model.getCalDate()); + mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap)); + return mav; + } else { + + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的租金估价").markNoData()); + return mav; + } + } + + public Object searchHouseLoudongAction(PropertyEvaluationModel model, HttpServletRequest request) throws NumberFormatException, IllegalAccessException { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + + if (StringUtils.isBlank(model.getId()) || StringUtils.isBlank(model.getHouseNumber()) || StringUtils.isBlank(model.getRoomNumber())) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:楼盘编号,楼栋号,室为必填项")); + return mav; + } + + List houseLoudongs = houseLoudongService.findAll(model.getId(), model.getHouseNumber(), model.getUnitNumber(), model.getRoomNumber()); + mav.setModel(BasicModel.buildOKModel().setResult(houseLoudongs)); + return mav; + } + + + public Object searchLoudongAction(PropertyEvaluationModel model, HttpServletRequest request) throws NumberFormatException, IllegalAccessException { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + + if (StringUtils.isBlank(model.getId()) || StringUtils.isBlank(model.getHouseNumber())) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:楼盘编号,楼栋号为必填项")); + return mav; + } + + + List loudongs = loudongService.findAll(model.getId(), model.getHouseNumber(), model.getUnitNumber()); + mav.setModel(BasicModel.buildOKModel().setResult(loudongs)); + return mav; + } + + + public void setHouseLoudongService(HouseLoudongService houseLoudongService) { + this.houseLoudongService = houseLoudongService; + } + + public void setFieldFilterService(FieldFilterService fieldFilterService) { + this.fieldFilterService = fieldFilterService; + } + + public void setApiUserService(ApiUserService apiUserService) { + this.apiUserService = apiUserService; + } + + public void setEvaluationService(EvaluationService evaluationService) { + this.evaluationService = evaluationService; + } + + public void setDistrictService(DistrictService districtService) { + this.districtService = districtService; + } + + public void setNoHouseDistrictService(NoHouseDistrictService noHouseDistrictService) { + this.noHouseDistrictService = noHouseDistrictService; + } + + public void setUserService(UserService userService) { + this.userService = userService; + } + + public void setHouseService(HouseService houseService) { + this.houseService = houseService; + } + + public void setAddressService(AddressService addressService) { + } + + public void setDistrictStatService(DistrictStatService districtStatService) { + this.districtStatService = districtStatService; + } + + public void setDealPriceService(DealPriceService dealPriceService) { + this.dealPriceService = dealPriceService; + } - protected AddressMatchLogService addressMatchLogService; + protected AddressMatchLogService addressMatchLogService; - public AddressMatchLogService getAddressMatchLogService() { - return addressMatchLogService; - } + public AddressMatchLogService getAddressMatchLogService() { + return addressMatchLogService; + } - public void setAddressMatchLogService(AddressMatchLogService addressMatchLogService) { - this.addressMatchLogService = addressMatchLogService; - } + public void setAddressMatchLogService(AddressMatchLogService addressMatchLogService) { + this.addressMatchLogService = addressMatchLogService; + } - public OpenLogService getOpenLogService() { - return openLogService; - } + public OpenLogService getOpenLogService() { + return openLogService; + } - public void setOpenLogService(OpenLogService openLogService) { - this.openLogService = openLogService; - } + public void setOpenLogService(OpenLogService openLogService) { + this.openLogService = openLogService; + } - public void setAutoCompleteService(AutoCompleteService autoCompleteService) { - this.autoCompleteService = autoCompleteService; - } + public void setAutoCompleteService(AutoCompleteService autoCompleteService) { + this.autoCompleteService = autoCompleteService; + } - public void setDistrictStatRentService(DistrictStatRentService districtStatRentService) { - this.districtStatRentService = districtStatRentService; - } + public void setDistrictStatRentService(DistrictStatRentService districtStatRentService) { + this.districtStatRentService = districtStatRentService; + } - public BatchEvaluateService getBatchEvaluateService() { - return batchEvaluateService; - } + public BatchEvaluateService getBatchEvaluateService() { + return batchEvaluateService; + } - public void setBatchEvaluateService(BatchEvaluateService batchEvaluateService) { - this.batchEvaluateService = batchEvaluateService; - } + public void setBatchEvaluateService(BatchEvaluateService batchEvaluateService) { + this.batchEvaluateService = batchEvaluateService; + } - public void setDistrictAttentionRankService(DistrictAttentionRankService districtAttentionRankService) { - this.districtAttentionRankService = districtAttentionRankService; - } + public void setDistrictAttentionRankService(DistrictAttentionRankService districtAttentionRankService) { + this.districtAttentionRankService = districtAttentionRankService; + } - public void setDistrictHotService(DistrictHotService districtHotService) { - this.districtHotService = districtHotService; - } + public void setDistrictHotService(DistrictHotService districtHotService) { + this.districtHotService = districtHotService; + } - public void setCityHotService(CityHotService cityHotService) { - this.cityHotService = cityHotService; - } + public void setCityHotService(CityHotService cityHotService) { + this.cityHotService = cityHotService; + } - public void setBizShopService(BizShopService bizShopService) { - this.bizShopService = bizShopService; - } + public void setBizShopService(BizShopService bizShopService) { + this.bizShopService = bizShopService; + } - public void setBusStationService(BusStationService busStationService) { - this.busStationService = busStationService; - } + public void setBusStationService(BusStationService busStationService) { + this.busStationService = busStationService; + } - public void setBaiduApiService(BaiduApiService baiduApiService) { - this.baiduApiService = baiduApiService; - } + public void setBaiduApiService(BaiduApiService baiduApiService) { + this.baiduApiService = baiduApiService; + } - public void setDistrictHouseResourceStatService(DistrictHouseResourceStatService districtHouseResourceStatService) { - this.districtHouseResourceStatService = districtHouseResourceStatService; - } + public void setDistrictHouseResourceStatService(DistrictHouseResourceStatService districtHouseResourceStatService) { + this.districtHouseResourceStatService = districtHouseResourceStatService; + } - public void setDistrictSellStatService(DistrictSellStatService districtSellStatService) { - this.districtSellStatService = districtSellStatService; - } + public void setDistrictSellStatService(DistrictSellStatService districtSellStatService) { + this.districtSellStatService = districtSellStatService; + } - public void setDistrictAnalyDataService(DistrictAnalyDataService districtAnalyDataService) { - this.districtAnalyDataService = districtAnalyDataService; - } + public void setDistrictAnalyDataService(DistrictAnalyDataService districtAnalyDataService) { + this.districtAnalyDataService = districtAnalyDataService; + } - public void setAddressMatchProxyService(AddressMatchProxyService addressMatchProxyService) { - this.addressMatchProxyService = addressMatchProxyService; - } + public void setAddressMatchProxyService(AddressMatchProxyService addressMatchProxyService) { + this.addressMatchProxyService = addressMatchProxyService; + } - public void setLoudongService(LoudongService loudongService) { - this.loudongService = loudongService; - } + public void setLoudongService(LoudongService loudongService) { + this.loudongService = loudongService; + } - public void setAddressParserService(AddressParserService addressParserService) { - this.addressParserService = addressParserService; - } + public void setAddressParserService(AddressParserService addressParserService) { + this.addressParserService = addressParserService; + } - public void setApiUserAuthorityService(ApiUserAuthorityService apiUserAuthorityService) { - this.apiUserAuthorityService = apiUserAuthorityService; - } + public void setApiUserAuthorityService(ApiUserAuthorityService apiUserAuthorityService) { + this.apiUserAuthorityService = apiUserAuthorityService; + } - public void setAverageStatisticsService(AverageStatisticsService averageStatisticsService) { - this.averageStatisticsService = averageStatisticsService; - } + public void setAverageStatisticsService(AverageStatisticsService averageStatisticsService) { + this.averageStatisticsService = averageStatisticsService; + } - public void setNetworkPriceService(NetworkPriceService networkPriceService) { - this.networkPriceService = networkPriceService; - } + public void setNetworkPriceService(NetworkPriceService networkPriceService) { + this.networkPriceService = networkPriceService; + } - public void setAverageAnalyService(AverageAnalyService averageAnalyService) { - this.averageAnalyService = averageAnalyService; - } + public void setAverageAnalyService(AverageAnalyService averageAnalyService) { + this.averageAnalyService = averageAnalyService; + } - public void setServerAreaService(ServerAreaService serverAreaService) { - this.serverAreaService = serverAreaService; - } + public void setServerAreaService(ServerAreaService serverAreaService) { + this.serverAreaService = serverAreaService; + } - public void setHouseAuctionService(HouseAuctionService houseAuctionService) { - this.houseAuctionService = houseAuctionService; - } + public void setHouseAuctionService(HouseAuctionService houseAuctionService) { + this.houseAuctionService = houseAuctionService; + } - public void setFjtEvaluationService(FjtEvaluationService fjtEvaluationService) { - this.fjtEvaluationService = fjtEvaluationService; - } + public void setFjtEvaluationService(FjtEvaluationService fjtEvaluationService) { + this.fjtEvaluationService = fjtEvaluationService; + } - public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) { - this.apiUserCfgService = apiUserCfgService; - } + public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) { + this.apiUserCfgService = apiUserCfgService; + } - public void setOpenApiLogService(OpenApiLogService openApiLogService) { - this.openApiLogService = openApiLogService; - } + public void setOpenApiLogService(OpenApiLogService openApiLogService) { + this.openApiLogService = openApiLogService; + } - public void setFangjiaOfficialAreaService(FangjiaOfficialAreaService fangjiaOfficialAreaService) { - this.fangjiaOfficialAreaService = fangjiaOfficialAreaService; - } + public void setFangjiaOfficialAreaService(FangjiaOfficialAreaService fangjiaOfficialAreaService) { + this.fangjiaOfficialAreaService = fangjiaOfficialAreaService; + } - public void setSeawaterDao(SeawaterDao seawaterDao) { - this.seawaterDao = seawaterDao; - } + public void setSeawaterDao(SeawaterDao seawaterDao) { + this.seawaterDao = seawaterDao; + } - public void setRegionAnaDataService(RegionAnaDataService regionAnaDataService) { - this.regionAnaDataService = regionAnaDataService; - } + public void setRegionAnaDataService(RegionAnaDataService regionAnaDataService) { + this.regionAnaDataService = regionAnaDataService; + } - public void setSeawaterService(SeawaterService seawaterService) { - this.seawaterService = seawaterService; - } + public void setSeawaterService(SeawaterService seawaterService) { + this.seawaterService = seawaterService; + } - public void setSqmetreRentService(SqmetreRentService sqmetreRentService) { - this.sqmetreRentService = sqmetreRentService; - } + public void setSqmetreRentService(SqmetreRentService sqmetreRentService) { + this.sqmetreRentService = sqmetreRentService; + } - public void setDistrictRoomSqmetreRentService(DistrictRoomSqmetreRentService districtRoomSqmetreRentService) { - this.districtRoomSqmetreRentService = districtRoomSqmetreRentService; - } + public void setDistrictRoomSqmetreRentService(DistrictRoomSqmetreRentService districtRoomSqmetreRentService) { + this.districtRoomSqmetreRentService = districtRoomSqmetreRentService; + } - public void setRentDealPriceService(RentDealPriceService rentDealPriceService) { - this.rentDealPriceService = rentDealPriceService; - } + public void setRentDealPriceService(RentDealPriceService rentDealPriceService) { + this.rentDealPriceService = rentDealPriceService; + } - public void setEvaluateRatioService(EvaluateRatioService evaluateRatioService) { - this.evaluateRatioService = evaluateRatioService; - } + public void setEvaluateRatioService(EvaluateRatioService evaluateRatioService) { + this.evaluateRatioService = evaluateRatioService; + } - public void setCommunityPoiService(CommunityPoiService communityPoiService) { - this.communityPoiService = communityPoiService; - } + public void setCommunityPoiService(CommunityPoiService communityPoiService) { + this.communityPoiService = communityPoiService; + } - public void setEvaluateFactorService(EvaluateFactorService evaluateFactorService) { - this.evaluateFactorService = evaluateFactorService; - } + public void setEvaluateFactorService(EvaluateFactorService evaluateFactorService) { + this.evaluateFactorService = evaluateFactorService; + } - public void setCommunityBasePriceService(CommunityBasePriceService communityBasePriceService) { - this.communityBasePriceService = communityBasePriceService; - } + public void setCommunityBasePriceService(CommunityBasePriceService communityBasePriceService) { + this.communityBasePriceService = communityBasePriceService; + } - public void setAliasFangService(AliasFangService aliasFangService) { - this.aliasFangService = aliasFangService; - } + public void setAliasFangService(AliasFangService aliasFangService) { + this.aliasFangService = aliasFangService; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/RentController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/RentController.java index d745b80dc..0c5f5004f 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/RentController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/RentController.java @@ -203,7 +203,7 @@ public class RentController { private Double getSqmetreRent(District district){ SqmetreRent sqmetreRent = sqmetreRentService.findNearestSqmetreRent(district.getCity(), district.getRegion(), district.getName(), null, "district"); if(null != sqmetreRent){ - return Double.valueOf(sqmetreRent.getAvgPrice()); + return Double.valueOf(sqmetreRent.getAvgPrice().intValue()); } return null; } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/model/AvgPriceQueryModel.java b/projects/fangjia-open/src/main/java/com/fangjia/open/model/AvgPriceQueryModel.java index 8095e9091..ef8e44a85 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/model/AvgPriceQueryModel.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/model/AvgPriceQueryModel.java @@ -27,6 +27,15 @@ public class AvgPriceQueryModel { Integer periodCount; String periodType; Integer houseType; + String cat; + + public String getCat() { + return cat; + } + + public void setCat(String cat) { + this.cat = cat; + } public Integer getPeriodCount() { return periodCount; diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/EvaluationServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/EvaluationServiceImpl.java index 817db88d3..ac396fe4b 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/EvaluationServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/EvaluationServiceImpl.java @@ -1038,7 +1038,7 @@ public class EvaluationServiceImpl implements EvaluationService { SqmetreRent sqmetreRent = sqmetreRentService.findNearestSqmetreRent(district.getCity(), district.getRegion(), district.getName(), DateUtil.formatToYYYYMMDD(weekend), "district"); if(sqmetreRent!=null){ - long totalPrice = evaluationRateService.evaluationRent(sqmetreRent.getAvgPrice(), evaluation); + long totalPrice = evaluationRateService.evaluationRent(sqmetreRent.getAvgPrice().intValue(), evaluation); evaluation.setTotalPrice(((Number) (totalPrice)).intValue()); diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/district/HouseReportServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/district/HouseReportServiceImpl.java index 03adaa106..36c8859d4 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/district/HouseReportServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/district/HouseReportServiceImpl.java @@ -194,7 +194,7 @@ public class HouseReportServiceImpl implements HouseReportService{ SqmetreRent citySqmetreRent = sqmetreRentService.findNearestSqmetreRent(city, null, null, "city"); RegionStat cityRegionStat = regionStatService.findByCity(city); if(null != citySqmetreRent && null != cityRegionStat){ - Double rate = DataUtil.getDoubleRound(2, citySqmetreRent.getAvgPrice()*12*100/cityRegionStat.getAvgPrice()); + Double rate = DataUtil.getDoubleRound(2, citySqmetreRent.getAvgPrice().intValue()*12*100/cityRegionStat.getAvgPrice()); return rate; } return null; @@ -205,7 +205,7 @@ public class HouseReportServiceImpl implements HouseReportService{ SqmetreRent regionSqmetreRent = sqmetreRentService.findNearestSqmetreRent(city, region, null, "region"); RegionStat regionStat = regionStatService.findRegionStat(city, region); if(null != regionSqmetreRent && null != regionStat){ - Double rate = DataUtil.getDoubleRound(2, regionSqmetreRent.getAvgPrice()*12*100/regionStat.getAvgPrice()); + Double rate = DataUtil.getDoubleRound(2, regionSqmetreRent.getAvgPrice().intValue()*12*100/regionStat.getAvgPrice()); return rate; } return null; @@ -224,7 +224,7 @@ public class HouseReportServiceImpl implements HouseReportService{ distAvgPrice = statBo.getVillaDistrictStat().getAvgPrice(); } if(distAvgPrice > 0){ - Double rate = DataUtil.getDoubleRound(2, distSqmetreRent.getAvgPrice()*12*100/distAvgPrice); + Double rate = DataUtil.getDoubleRound(2, distSqmetreRent.getAvgPrice().intValue()*12*100/distAvgPrice); return rate; } } diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/district/SqmetreRentServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/district/SqmetreRentServiceImpl.java index 56630bc77..0a681b403 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/district/SqmetreRentServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/district/SqmetreRentServiceImpl.java @@ -126,6 +126,13 @@ public class SqmetreRentServiceImpl implements SqmetreRentService{ if(StringUtils.isNotBlank(cat)){ params.add(new QueryParam("cat", cat)); } + if(null != startDate){ + params.add(new QueryParam("weekend",QueryParam.GREATER_THAN_EQUAL_OPERATOR, startDate)); + } + + if(null != endDate){ + params.add(new QueryParam("weekend",QueryParam.LESS_THAN_EQUAL_OPERATOR, endDate)); + } List sortParams = new ArrayList(); sortParams.add(new SortParam("weekend", true));