diff --git a/deliverables/auto/pom.xml b/deliverables/auto/pom.xml index 292ddf9d6..831bfe4c9 100644 --- a/deliverables/auto/pom.xml +++ b/deliverables/auto/pom.xml @@ -18,6 +18,6 @@ goojia-auto - ../../projects/goojia-auto + diff --git a/projects/fangjia-bkoff/src/main/webapp/style/address/main.css.baiduyun.uploading.cfg b/projects/fangjia-bkoff/src/main/webapp/style/address/main.css.baiduyun.uploading.cfg new file mode 100644 index 000000000..74aacef5a Binary files /dev/null and b/projects/fangjia-bkoff/src/main/webapp/style/address/main.css.baiduyun.uploading.cfg differ diff --git a/projects/fangjia-bkoff/src/main/webapp/style/audit/list.css.baiduyun.uploading.cfg b/projects/fangjia-bkoff/src/main/webapp/style/audit/list.css.baiduyun.uploading.cfg new file mode 100644 index 000000000..f612f71b5 Binary files /dev/null and b/projects/fangjia-bkoff/src/main/webapp/style/audit/list.css.baiduyun.uploading.cfg differ diff --git a/projects/fangjia-bkoff/src/main/webapp/style/theme.css.baiduyun.uploading.cfg b/projects/fangjia-bkoff/src/main/webapp/style/theme.css.baiduyun.uploading.cfg new file mode 100644 index 000000000..0c2959a18 Binary files /dev/null and b/projects/fangjia-bkoff/src/main/webapp/style/theme.css.baiduyun.uploading.cfg differ diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AaController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AaController.java index d83085e01..ce11d95e3 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AaController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AaController.java @@ -22,16 +22,16 @@ public class AaController { private AddressModeParserChain addressModeParserChain; public Object pickAction() throws Exception { - File file = new File("C:\\Users\\yk\\Desktop\\yongjia\\test\\上海-0730.txt"); - File file2 = new File("C:\\Users\\yk\\Desktop\\yongjia\\test\\上海-0730_picker.txt"); + File file = new File("C:\\Users\\yk\\Desktop\\yongjia\\test\\涓婃捣-0730.txt"); + File file2 = new File("C:\\Users\\yk\\Desktop\\yongjia\\test\\涓婃捣-0730_picker.txt"); if (file2.exists()) { file2.delete(); } - BufferedWriter fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2, true), "GBK")); // 指定编码格式,以免读取时中文字符异常 + BufferedWriter fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2, true), "GBK")); // 鎸囧畾缂栫爜鏍煎紡锛屼互鍏嶈鍙栨椂涓枃瀛楃寮傚父 - // 全部写入缓存中的内容 + // 鍏ㄩ儴鍐欏叆缂撳瓨涓殑鍐呭 - InputStreamReader read = new InputStreamReader(new FileInputStream(file), "utf-8");// 考虑到编码格式 + InputStreamReader read = new InputStreamReader(new FileInputStream(file), "utf-8");// 鑰冭檻鍒扮紪鐮佹牸寮� BufferedReader bufferedReader = new BufferedReader(read); String lineTxt = null; while ((lineTxt = bufferedReader.readLine()) != null) { @@ -42,7 +42,7 @@ public class AaController { List tokens = CnAddressTokenizer.tokenizer(lineTxt); addressPickerChain.doPick(tokens, ret); - // parserChain.doParse("上海", lineTxt, ret); + // parserChain.doParse("涓婃捣", lineTxt, ret); ret.remove(AddressAnalyseResultKeyEnum.orgAddress.name()); // ret.remove(AddressAnalyseResultKeyEnum.shortAddress.name()); @@ -64,16 +64,16 @@ public class AaController { } public Object parseAction() throws Exception { - File file = new File("C:\\Users\\yk\\Desktop\\yongjia\\test\\上海-0730.txt"); - File file2 = new File("C:\\Users\\yk\\Desktop\\yongjia\\test\\上海-0730_parser.txt"); + File file = new File("C:\\Users\\yk\\Desktop\\yongjia\\test\\涓婃捣-0730.txt"); + File file2 = new File("C:\\Users\\yk\\Desktop\\yongjia\\test\\涓婃捣-0730_parser.txt"); if (file2.exists()) { file2.delete(); } - BufferedWriter fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2, true), "GBK")); // 指定编码格式,以免读取时中文字符异常 + BufferedWriter fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2, true), "GBK")); // 鎸囧畾缂栫爜鏍煎紡锛屼互鍏嶈鍙栨椂涓枃瀛楃寮傚父 - // 全部写入缓存中的内容 + // 鍏ㄩ儴鍐欏叆缂撳瓨涓殑鍐呭 - InputStreamReader read = new InputStreamReader(new FileInputStream(file), "utf-8");// 考虑到编码格式 + InputStreamReader read = new InputStreamReader(new FileInputStream(file), "utf-8");// 鑰冭檻鍒扮紪鐮佹牸寮� BufferedReader bufferedReader = new BufferedReader(read); String lineTxt = null; while ((lineTxt = bufferedReader.readLine()) != null) { @@ -81,7 +81,7 @@ public class AaController { ret.put(AddressAnalyseResultKeyEnum.orgAddress.name(), lineTxt); System.out.println(lineTxt); - addressModeParserChain.doParse("上海", lineTxt, ret); + addressModeParserChain.doParse("涓婃捣", lineTxt, ret); ret.remove(AddressAnalyseResultKeyEnum.orgAddress.name()); ret.remove(AddressAnalyseResultKeyEnum.shortAddress.name()); diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/ComprehensiveQueryController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/ComprehensiveQueryController.java new file mode 100644 index 000000000..710ced096 --- /dev/null +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/ComprehensiveQueryController.java @@ -0,0 +1,1316 @@ +package com.fangjia.open.controllers; + +import com.fangjia.core.util.*; +import com.fangjia.dal.common.DistrictKey; +import com.fangjia.dal.mongo.fangjia.model.ServerArea; +import com.fangjia.dal.mongo.model.ApiUserCfg; +import com.fangjia.dal.mongo.model.DistrictFacilitys; +import com.fangjia.dal.mongo.model.Evaluation; +import com.fangjia.dal.mongo.model.FangjiaOfficialAreaMap; +import com.fangjia.dal.mongo.model.bkoff.Loudong; +import com.fangjia.dal.mongo.open.model.ApiUserAuthority; +import com.fangjia.dal.mongo.open.model.EvaluateRatio; +import com.fangjia.dal.seaweed.model.District; +import com.fangjia.open.HttpCode; +import com.fangjia.open.OpenHttpCodeEnum; +import com.fangjia.open.dto.HouseValueInformationDto; +import com.fangjia.open.dto.UniversalDto; +import com.fangjia.open.dto.addressGovernance.MatchedBuildingDto; +import com.fangjia.open.interceptors.AuthenticationBean; +import com.fangjia.open.interceptors.Authority; +import com.fangjia.open.interceptors.Role; +import com.fangjia.open.model.*; +import com.fangjia.open.util.CommonDtoUtils; +import com.fangjia.open.util.CommonUtils; +import com.fangjia.open.ws.query.SampleQuery; +import com.fangjia.service.api.AddressMatchProxyService; +import com.fangjia.service.api.ApiUserCfgService; +import com.fangjia.service.bo.Collateral; +import com.fangjia.service.bo.DistrictStatBo; +import com.fangjia.service.bo.Sample; +import com.fangjia.service.datastore.*; +import com.fangjia.service.datastore.bean.CollateralSampleQueryBean; +import com.fangjia.service.district.*; +import com.fangjia.service.mongo.bkoff.HouseLoudongService; +import com.fangjia.service.mongo.bkoff.LoudongService; +import com.fangjia.service.mongo.fangjia.*; +import com.fangjia.service.open.*; +import com.fangjia.service.tool.OpenLogService; +import com.fangjia.service.web.AddressService; +import net.sf.json.JSONObject; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.DateUtils; +import org.slf4j.Logger; +import org.sothis.web.mvc.ActionContext; + +import javax.servlet.http.HttpServletRequest; +import java.text.ParseException; +import java.util.*; + +import static com.poseidon.util.TypeConverter.convertToString; + +/** + * @author 13607 + * @since 2023/12/12 10:29 + */ +@Authority(role = Role.USER) +public class ComprehensiveQueryController { + private DistrictService districtService; + + private DistrictStatService districtStatService; + + private FangjiaOfficialAreaService fangjiaOfficialAreaService; + private AddressMatchProxyService addressMatchProxyService; + + private static final Logger LOGGER = LoggerFactory.getLogger(PropertyController.class); + private HouseLoudongService houseLoudongService; + private LoudongService loudongService; + private EvaluationService evaluationService; + private BatchEvaluateService batchEvaluateService; + private ApiUserAuthorityService apiUserAuthorityService; + private AverageStatisticsService averageStatisticsService; + private ServerAreaService serverAreaService; + private ApiUserCfgService apiUserCfgService; + private OpenApiLogService openApiLogService; + private EvaluateFactorService evaluateFactorService; + + private CzbankSampleService czbankSampleService; + + private DistrictFacilitysService districtFacilitysService; + + 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"}; + static final int BAI_DU_GEO = 1;// 百度系坐标 + static final int GAO_DE_GEO = 2;// 高德系坐标 + + + + private EvaluateRatioService evaluateRatioService; + + 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 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 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 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 NEGATIVE_FACTOR = new HashMap() { + { + put(null, "无"); + put("1", "很近"); + put("2", "较近"); + put("3", "无"); + } + }; + + + 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");// 五线 + } + }; + + public Object houseValueInformationAction(HouseInfomationModel model, HttpServletRequest httpServletRequest) { + + // 原小区均价 + HouseValueInformationDto houseValueInformation = new HouseValueInformationDto(); + RestfulModelAndView mav = new RestfulModelAndView(); + + if (StringUtils.isBlank(model.getAddress()) || StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(String.valueOf(model.getSize()))) { + mav.setModel(BasicModel.buildBadRequestModel("城市(city),地址(address),面积(size)为必填字段")); + return mav; + } + + HttpRequest httpRequest = new HttpRequest(); + JSONObject json = null; + Map communityAvgPriceParams = new HashMap(); + communityAvgPriceParams.put("city", model.getCity()); + communityAvgPriceParams.put("address", model.getAddress()); + communityAvgPriceParams.put("category", model.getCategory()); + communityAvgPriceParams.put("useMap", String.valueOf(model.isUseMap())); + JSONObject matchResponse = null; + try { + matchResponse = httpRequest.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/v2/match", communityAvgPriceParams, "UTF-8"); + } catch (HttpRequestException e) { + + } + if(matchResponse == null || !matchResponse.containsKey("result") || !matchResponse.getJSONObject("result").containsKey("id")) { + mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!")); + return mav; + } + String id = matchResponse.getJSONObject("result").getString("id"); + District district = districtService.findById(id); + if (district == null) { + mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!")); + return mav; + } + + MatchedBuildingDto dto = CommonDtoUtils.transformV(MatchedBuildingDto.class, matchResponse.getJSONObject("result")); + DistrictStatBo statBo = districtStatService.findCurrentDistrictStat(new DistrictKey(district)); + if (null != statBo) { + if (statBo.getDistrictStat() != null) { + dto.setAvgPrice(statBo.getDistrictStat().getAvgPrice()); + } else if (statBo.getVillaDistrictStat() != null) { + dto.setAvgPrice(statBo.getVillaDistrictStat().getAvgPrice()); + } + + } + // 保存小区均价的返回结果 + houseValueInformation.setCommunityAvgPrice(dto); + + //原房屋价值评估 + //根据model给PropertyEvaluationModel赋值 + PropertyEvaluationModel propertyEvaluationModel = createPropertyEvaluationModelFromHouseInfomationModel(model); + boolean villaFlag = DataUtil.isVilla(propertyEvaluationModel.getSize(), propertyEvaluationModel.getName(), propertyEvaluationModel.getHeight(), propertyEvaluationModel.getRoom()); + String propertyType = district.getEstateType2(); + if (villaFlag && StringUtils.isNotBlank(propertyType) && !propertyType.equals("别墅")) { + District bieShuDistrict = districtService.findByNameAndAlias(district.getCity(), district.getRegion(), district.getName() + "别墅", "district"); + if (bieShuDistrict != null) { + district = bieShuDistrict; + } + } + propertyEvaluationModel.setDistrict(district.getRegion()); + propertyEvaluationModel.setName(district.getName()); + try { + evaluateAction(propertyEvaluationModel, httpServletRequest, houseValueInformation, mav); + } catch (IllegalAccessException e) { + + } +// houseValueInformation.setAddressValue(modelAndView); + + //房源样本 + + //构造sampleQuery对象 + SampleQuery sampleQuery = new SampleQuery(); + sampleQuery.setCity(model.getCity()); + sampleQuery.setStrctureArea(model.getSize()); + sampleQuery.setAddress(model.getAddress()); + +// RestfulModelAndView houseCaseMav = new RestfulModelAndView(); + List querys = null; + try { + querys = convertSampileQueryToBean(district,sampleQuery); + } catch (Exception e) { + mav.setModel(BasicModel.buildBadRequestModel(e.getMessage())); + return mav; + } + if (null == sampleQuery.getMax()) { + sampleQuery.setMax(10); + } + // 此处慢 + long start = System.currentTimeMillis(); + List collaterals = czbankSampleService.findSample2(querys, sampleQuery.getMax()); + long end = System.currentTimeMillis(); + System.out.println("用时:"+(end-start)); + Collateral collateral = collaterals.get(0); + List samples = collateral.getSample(); + UniversalDto houseCaseDto = UniversalDto.newDto(); + if (null != collateral.getMaxPrice()) { + houseCaseDto.append("maxUnitPrice", collateral.getMaxPrice()); + } + if (null != collateral.getMinPrice()) { + houseCaseDto.append("minUnitPrice", collateral.getMinPrice()); + } + houseCaseDto.append("datas", samples); +// if(samples!= null && samples.size()>=2){ +// Sample minSample = samples.get(samples.size()-2); +// Sample maxSample = samples.get(samples.size()-1); +// dto.append("minUnitPrice", minSample.getUnitPrice()); +// dto.append("maxUnitPrice", maxSample.getUnitPrice()); +// } +// if(samples.size()>2){ +// dto.append("datas", samples.subList(0, samples.size()-2)); +// }else{ +// dto.append("datas", samples); +// } + +// houseCaseMav.setModel(BasicModel.buildOKModel().setResult(dto)); +// return houseCaseMav; + + //将房源数据放到结果集 + houseValueInformation.setHouseCase(houseCaseDto); + + // 原周边POI + DistrictFacilitys facilitys = districtFacilitysService.findByDistrict(district); + // 将周边POI数据放到结果集 + houseValueInformation.setSurroundingPoi(facilitys); + mav.setModel(BasicModel.buildOKModel().setResult(houseValueInformation)); + return mav; + } + + private PropertyEvaluationModel createPropertyEvaluationModelFromHouseInfomationModel(HouseInfomationModel model) { + PropertyEvaluationModel propertyModel = new PropertyEvaluationModel(); + propertyModel.setCity(model.getCity()); + propertyModel.setAddress(model.getAddress()); + propertyModel.setSize(model.getSize()); + + if (StringUtils.isNotBlank(model.getDistrict())) { + propertyModel.setDistrict(model.getDistrict()); + } + if (StringUtils.isNotBlank(model.getName())) { + propertyModel.setName(model.getName()); + } + if (StringUtils.isNotBlank(model.getBuildingNumber())) { + propertyModel.setBuildingNumber(model.getBuildingNumber()); + } + if (StringUtils.isNotBlank(model.getUnitNumber())) { + propertyModel.setUnitNumber(model.getUnitNumber()); + } + if (model.getFloor() != null && model.getFloor() != 0) { + propertyModel.setFloor(model.getFloor()); + } + if (model.getMaxFloor() != null && model.getMaxFloor() != 0) { + propertyModel.setMaxFloor(model.getMaxFloor()); + } + if (model.getRoom() != null && model.getRoom() != 0) { + propertyModel.setRoom(model.getRoom()); + } + if (model.getHall() != 0) { + propertyModel.setHall(model.getHall()); + } + if (model.getToilet() != 0) { + propertyModel.setToilet(model.getToilet()); + } + if (model.getCalDate() != null) { + propertyModel.setCalDate(model.getCalDate()); + } + if (model.getPropertyType() != null) { + propertyModel.setPropertyType(model.getPropertyType()); + } + if (StringUtils.isNotBlank(model.getDirection())) { + propertyModel.setDirection(model.getDirection()); + } + if (StringUtils.isNotBlank(model.getDecoration())) { + propertyModel.setDecoration(model.getDecoration()); + } + + if (model.getDecorationCost() != null && model.getDecorationCost() != 0) { + propertyModel.setDecorationCost(model.getDecorationCost()); + } + + if (model.getDecorationAge() != 0) { + propertyModel.setDecorationAge(model.getDecorationAge()); + } + if (StringUtils.isNotBlank(model.getView())) { + propertyModel.setView(model.getView()); + } + if (StringUtils.isNotBlank(model.getNoise())) { + propertyModel.setNoise(model.getNoise()); + } + if (model.getGardenSize() != null && model.getGardenSize() != 0) { + propertyModel.setGardenSize(model.getGardenSize()); + } + if (model.getBasementSize() != null && model.getBasementSize() != 0) { + propertyModel.setBasementSize(model.getBasementSize()); + } + if (model.getOuterSize() != null && model.getOuterSize() != 0) { + propertyModel.setOuterSize(model.getOuterSize()); + } + if (model.getAtticSize() != null && model.getAtticSize() != 0) { + propertyModel.setAtticSize(model.getAtticSize()); + } + if (StringUtils.isNotBlank(model.getNegativeFactor())) { + propertyModel.setNegativeFactor(model.getNegativeFactor()); + } + if (model.getAge() != 0) { + propertyModel.setAge(model.getAge()); + } + if (model.getCarportPrice() != null && model.getCarportPrice() != 0) { + propertyModel.setCarportPrice(model.getCarportPrice()); + } + + if (StringUtils.isNotBlank(model.getFacilities())) { + propertyModel.setFacilities(model.getFacilities()); + } + if (StringUtils.isNotBlank(model.getInsidePosition())) { + propertyModel.setInsidePosition(model.getInsidePosition()); + } + return propertyModel; + } + + private List convertSampileQueryToBean(District district,SampleQuery... queries) throws Exception { + + List queryBeans = new ArrayList(queries.length); + for (SampleQuery q : queries) { + + CollateralSampleQueryBean queryBean = new CollateralSampleQueryBean(); + BeanUtils.copyProperties(q, queryBean); + queryBean.setProperty(district); + String estateType = queryBean.getProperty().getEstateType2(); + queryBean.setPropertyTypeCode("01"); + if (StringUtils.isNotBlank(estateType)) { + if (estateType.equals("普通住宅")) { + queryBean.setPropertyTypeCode("01"); + } else if (estateType.equals("别墅")) { + queryBean.setPropertyTypeCode("02"); + } else if (estateType.equals("商住")) { + queryBean.setPropertyTypeCode("03"); + } + } + + Integer decrCondCode = queryBean.getDecrCondCode(); + if (decrCondCode == null) { + decrCondCode = 2; + } + if (decrCondCode > 5 || decrCondCode < 1) { + throw new Exception("decrCondCode取值非法"); + } + Integer towardDirectCode = queryBean.getTowardDirectCode(); + if (towardDirectCode == null) { + towardDirectCode = 3; + } + if (towardDirectCode > 10 || towardDirectCode < 1) { + throw new Exception("towardDirectCode取值非法"); + } + queryBeans.add(queryBean); + } + return queryBeans; + } + + 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()); + } + } + + public Object evaluateAction(PropertyEvaluationModel model, HttpServletRequest request, HouseValueInformationDto houseValueInformation, RestfulModelAndView mav) + 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()); + } + // 将评估价放到结果集 + houseValueInformation.setAddressValue(districtPriceMap); +// 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; + } + } + + 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 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.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; + } + + 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 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; + } + + 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 Integer sum(List smallPrices) { + int sum = 0; + for (int price : smallPrices) { + sum += price; + } + return sum; + } + + 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; + } + + + + + public void setEvaluationService(EvaluationService evaluationService) { + this.evaluationService = evaluationService; + } + + public void setDistrictService(DistrictService districtService) { + this.districtService = districtService; + } + + public void setAddressService(AddressService addressService) { + } + + public void setDistrictStatService(DistrictStatService districtStatService) { + this.districtStatService = districtStatService; + } + + protected AddressMatchLogService addressMatchLogService; + + public void setAddressMatchLogService(AddressMatchLogService addressMatchLogService) { + this.addressMatchLogService = addressMatchLogService; + } + + + + public BatchEvaluateService getBatchEvaluateService() { + return batchEvaluateService; + } + + public void setBatchEvaluateService(BatchEvaluateService batchEvaluateService) { + this.batchEvaluateService = batchEvaluateService; + } + + public void setAddressMatchProxyService(AddressMatchProxyService addressMatchProxyService) { + this.addressMatchProxyService = addressMatchProxyService; + } + + public void setLoudongService(LoudongService loudongService) { + this.loudongService = loudongService; + } + + public void setApiUserAuthorityService(ApiUserAuthorityService apiUserAuthorityService) { + this.apiUserAuthorityService = apiUserAuthorityService; + } + + public void setAverageStatisticsService(AverageStatisticsService averageStatisticsService) { + this.averageStatisticsService = averageStatisticsService; + } + + public void setServerAreaService(ServerAreaService serverAreaService) { + this.serverAreaService = serverAreaService; + } + + public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) { + this.apiUserCfgService = apiUserCfgService; + } + + public void setOpenApiLogService(OpenApiLogService openApiLogService) { + this.openApiLogService = openApiLogService; + } + + public void setFangjiaOfficialAreaService(FangjiaOfficialAreaService fangjiaOfficialAreaService) { + this.fangjiaOfficialAreaService = fangjiaOfficialAreaService; + } + + + public void setEvaluateRatioService(EvaluateRatioService evaluateRatioService) { + this.evaluateRatioService = evaluateRatioService; + } + + + public void setEvaluateFactorService(EvaluateFactorService evaluateFactorService) { + this.evaluateFactorService = evaluateFactorService; + } + + public void setCzbankSampleService(CzbankSampleService czbankSampleService) { + this.czbankSampleService = czbankSampleService; + } + + public void setDistrictFacilitysService(DistrictFacilitysService districtFacilitysService) { + this.districtFacilitysService = districtFacilitysService; + } + +} + diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/HouseController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/HouseController.java index 083ae48f0..f3548c9cc 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/HouseController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/HouseController.java @@ -903,7 +903,10 @@ public class HouseController { if(null == sampleQuery.getMax()){ sampleQuery.setMax(10); } + long start = System.currentTimeMillis(); List collaterals = czbankSampleService.findSample2(querys, sampleQuery.getMax()); + long end = System.currentTimeMillis(); + System.out.println("用时:"+(end-start)); Collateral collateral = collaterals.get(0); List samples = collateral.getSample(); UniversalDto dto = UniversalDto.newDto(); @@ -913,7 +916,8 @@ public class HouseController { if(null != collateral.getMinPrice()){ dto.append("minUnitPrice", collateral.getMinPrice()); } - dto.append("datas", samples); + + dto.append("datas", samples); // if(samples!= null && samples.size()>=2){ // Sample minSample = samples.get(samples.size()-2); // Sample maxSample = samples.get(samples.size()-1); diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/TestController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/TestController.java new file mode 100644 index 000000000..07fbed914 --- /dev/null +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/TestController.java @@ -0,0 +1,1608 @@ +/* +package com.fangjia.open.controllers; + +import com.fangjia.core.util.*; +import com.fangjia.dal.common.DistrictKey; +import com.fangjia.dal.mongo.fangjia.model.ServerArea; +import com.fangjia.dal.mongo.model.ApiUserCfg; +import com.fangjia.dal.mongo.model.DistrictFacilitys; +import com.fangjia.dal.mongo.model.Evaluation; +import com.fangjia.dal.mongo.model.FangjiaOfficialAreaMap; +import com.fangjia.dal.mongo.model.bkoff.Loudong; +import com.fangjia.dal.mongo.open.model.ApiUserAuthority; +import com.fangjia.dal.mongo.open.model.EvaluateRatio; +import com.fangjia.dal.seaweed.model.District; +import com.fangjia.open.HttpCode; +import com.fangjia.open.OpenHttpCodeEnum; +import com.fangjia.open.dto.HouseValueInformationDto; +import com.fangjia.open.dto.UniversalDto; +import com.fangjia.open.dto.addressGovernance.MatchedBuildingDto; +import com.fangjia.open.interceptors.AuthenticationBean; +import com.fangjia.open.model.*; +import com.fangjia.open.util.CommonDtoUtils; +import com.fangjia.open.util.CommonUtils; +import com.fangjia.open.ws.query.SampleQuery; +import com.fangjia.service.api.AddressMatchProxyService; +import com.fangjia.service.api.ApiUserCfgService; +import com.fangjia.service.bo.Collateral; +import com.fangjia.service.bo.DistrictStatBo; +import com.fangjia.service.bo.Sample; +import com.fangjia.service.datastore.*; +import com.fangjia.service.datastore.bean.CollateralSampleQueryBean; +import com.fangjia.service.district.*; +import com.fangjia.service.mongo.bkoff.HouseLoudongService; +import com.fangjia.service.mongo.bkoff.LoudongService; +import com.fangjia.service.mongo.fangjia.*; +import com.fangjia.service.open.*; +import com.fangjia.service.tool.OpenLogService; +import com.fangjia.service.web.AddressService; +import net.sf.json.JSONObject; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.DateUtils; +import org.slf4j.Logger; +import org.sothis.web.mvc.ActionContext; +import org.sothis.web.mvc.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import java.text.ParseException; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import static com.poseidon.util.TypeConverter.convertToString; + +*/ +/** + * @author 13607 + * @since 2023/12/12 10:29 + *//* + + + +public class TestController { + private DistrictService districtService; + + private DistrictStatService districtStatService; + + private FangjiaOfficialAreaService fangjiaOfficialAreaService; + private AddressMatchProxyService addressMatchProxyService; + + private static final Logger LOGGER = LoggerFactory.getLogger(PropertyController.class); + private HouseLoudongService houseLoudongService; + private LoudongService loudongService; + private EvaluationService evaluationService; + private BatchEvaluateService batchEvaluateService; + private ApiUserAuthorityService apiUserAuthorityService; + private AverageStatisticsService averageStatisticsService; + private ServerAreaService serverAreaService; + private ApiUserCfgService apiUserCfgService; + private OpenApiLogService openApiLogService; + private EvaluateFactorService evaluateFactorService; + + private CzbankSampleService czbankSampleService; + + private DistrictFacilitysService districtFacilitysService; + + 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"}; + static final int BAI_DU_GEO = 1;// 百度系坐标 + static final int GAO_DE_GEO = 2;// 高德系坐标 + + + private EvaluateRatioService evaluateRatioService; + + 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 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 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 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 NEGATIVE_FACTOR = new HashMap() { + { + put(null, "无"); + put("1", "很近"); + put("2", "较近"); + put("3", "无"); + } + }; + + + 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");// 五线 + } + }; + + + //全局json + private JSONObject globalJson = null; + + + public Object houseValueInformationAction(HouseInfomationModel model, HttpServletRequest httpServletRequest) throws IllegalAccessException, HttpRequestException { + + HouseValueInformationDto houseValueInformation = new HouseValueInformationDto(); + RestfulModelAndView mav = new RestfulModelAndView(); + + if (StringUtils.isBlank(model.getAddress()) || StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(String.valueOf(model.getSize()))) { + mav.setModel(BasicModel.buildBadRequestModel("城市(city),地址(address),面积(size)为必填字段")); + return mav; + } + + HttpRequest httpRequest = new HttpRequest(); + + Map communityAvgPriceParams = new HashMap(); + communityAvgPriceParams.put("city", model.getCity()); + communityAvgPriceParams.put("address", model.getAddress()); + communityAvgPriceParams.put("category", model.getCategory()); + communityAvgPriceParams.put("useMap", String.valueOf(model.isUseMap())); + globalJson = httpRequest.getJsonContent("http://192.168.0.100:32080/FangJiaNlpService/match", communityAvgPriceParams, "UTF-8"); + + // 创建线程池 + ExecutorService executorService = Executors.newFixedThreadPool(5); + + Future avgPriceFuture = executorService.submit(new UpdateCommunityAvgPriceCallable(globalJson, mav)); + Future> future2 = executorService.submit(new UpdateAddressValueCallable( globalJson, model, mav, httpServletRequest)); + Future future3 = executorService.submit(new UpdateHouseCaseCallable(houseValueInformation, globalJson, model, mav)); + Future future4 = executorService.submit(new UpdateSurroundingPoiCallable(houseValueInformation, globalJson, model, mav)); + + try { + // 获取线程任务的返回结果 + MatchedBuildingDto avgPrice = avgPriceFuture.get(); + if (avgPrice!=null){ + houseValueInformation.setCommunityAvgPrice(avgPrice); + }else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + Map result2 = future2.get(); + UniversalDto result3 = future3.get(); + DistrictFacilitys result4 = future4.get(); + + // 根据需要处理返回结果 + // ... + } catch (Exception e) { + // 处理异常 + e.printStackTrace(); + } + + + // 关闭线程池 + executorService.shutdown(); + return mav; + + + } + + private class UpdateCommunityAvgPriceCallable implements Callable { + private JSONObject globalJson; + private ModelAndView mav; + + public UpdateCommunityAvgPriceCallable( JSONObject globalJson, ModelAndView mav) { + this.globalJson = globalJson; + this.mav = mav; + } + + @Override + public MatchedBuildingDto call() throws Exception { + synchronized (globalJson) { + + try { + //新匹配接口 + JSONObject json = globalJson; + BasicModel basicModel = new BasicModel(200, "ok"); + if (json != null && json.size() > 0) { + MatchedBuildingDto dto = CommonDtoUtils.transformV(MatchedBuildingDto.class, json); + + District district = districtService.findByNameAndAlias(dto.getCity(), dto.getDistrict(), dto.getName(), "district"); + if (null != district) { + DistrictStatBo statBo = districtStatService.findCurrentDistrictStat(new DistrictKey(dto.getCity(), dto.getDistrict(), dto.getName())); + if (null != statBo) { + if (statBo.getDistrictStat() != null) { + dto.setAvgPrice(statBo.getDistrictStat().getAvgPrice()); + } else if (statBo.getVillaDistrictStat() != null) { + dto.setAvgPrice(statBo.getVillaDistrictStat().getAvgPrice()); + } + + } + } +// basicModel.setResult(dto); + // 保存小区均价的返回结果 + return dto; + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return null; + } + } + } + + private class UpdateAddressValueCallable implements Callable { + private JSONObject globalJson; + + private HouseInfomationModel model; + + private RestfulModelAndView mav; + private HttpServletRequest httpServletRequest; + + public UpdateAddressValueCallable(JSONObject globalJson, HouseInfomationModel model, RestfulModelAndView mav, HttpServletRequest httpServletRequest) { + this.globalJson = globalJson; + this.model = model; + this.mav = mav; + this.httpServletRequest = httpServletRequest; + } + + @Override + public MatchedBuildingDto call() throws Exception { + //根据model给PropertyEvaluationModel赋值 + PropertyEvaluationModel propertyEvaluationModel = createPropertyEvaluationModelFromHouseInfomationModel(model); + +// RestfulModelAndView propertyEvaluationMav = new RestfulModelAndView(); +// mav.setViewType("rest"); +// if (StringUtils.isBlank(propertyEvaluationModel.getCity()) || StringUtils.isBlank(propertyEvaluationModel.getAddress()) || propertyEvaluationModel.getSize() <= 0) { +// mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,地址,面积(size)为必填项")); +// return mav; +// } + if (propertyEvaluationModel.getDistrict() != null) { + //区域编码转房价网区域 + FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertOfficialCodeToFangjia(propertyEvaluationModel.getDistrict()); + if (fangjiaOfficialAreaMap != null) { + propertyEvaluationModel.setDistrict(fangjiaOfficialAreaMap.getFangjiaDistrict()); + } + } + + boolean villaFlag = DataUtil.isVilla(propertyEvaluationModel.getSize(), propertyEvaluationModel.getName(), propertyEvaluationModel.getHeight(), propertyEvaluationModel.getRoom()); + + District district = null; + Map params = new HashMap(); + params.put("city", propertyEvaluationModel.getCity()); + if (StringUtils.isNotBlank(propertyEvaluationModel.getDistrict())) { + params.put("suggestDistrict", propertyEvaluationModel.getDistrict()); + } + params.put("address", propertyEvaluationModel.getAddress()); + if (StringUtils.isNotBlank(propertyEvaluationModel.getName())) { + params.put("suggestName", propertyEvaluationModel.getName()); + } + params.put("category", "district"); + String result = addressMatchProxyService.parser(params); + if (result != null) { + JSONObject json = globalJson; + 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; + } + propertyEvaluationModel.setDistrict(district.getRegion()); + propertyEvaluationModel.setName(district.getName()); + try { + evaluateAction(propertyEvaluationModel, httpServletRequest, mav); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + private class UpdateAddressValueRunnable implements Runnable { + private HouseValueInformationDto houseValueInformation; + + private JSONObject globalJson; + + private HouseInfomationModel model; + + private RestfulModelAndView mav; + private HttpServletRequest httpServletRequest; + + public UpdateAddressValueRunnable(HouseValueInformationDto houseValueInformation, JSONObject globalJson, HouseInfomationModel model, RestfulModelAndView mav, HttpServletRequest httpServletRequest) { + this.houseValueInformation = houseValueInformation; + this.globalJson = globalJson; + this.model = model; + this.mav = mav; + this.httpServletRequest = httpServletRequest; + } + + @Override + public void run() { + //根据model给PropertyEvaluationModel赋值 + PropertyEvaluationModel propertyEvaluationModel = createPropertyEvaluationModelFromHouseInfomationModel(model); + +// RestfulModelAndView propertyEvaluationMav = new RestfulModelAndView(); +// mav.setViewType("rest"); +// if (StringUtils.isBlank(propertyEvaluationModel.getCity()) || StringUtils.isBlank(propertyEvaluationModel.getAddress()) || propertyEvaluationModel.getSize() <= 0) { +// mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,地址,面积(size)为必填项")); +// return mav; +// } + if (propertyEvaluationModel.getDistrict() != null) { + //区域编码转房价网区域 + FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertOfficialCodeToFangjia(propertyEvaluationModel.getDistrict()); + if (fangjiaOfficialAreaMap != null) { + propertyEvaluationModel.setDistrict(fangjiaOfficialAreaMap.getFangjiaDistrict()); + } + } + + boolean villaFlag = DataUtil.isVilla(propertyEvaluationModel.getSize(), propertyEvaluationModel.getName(), propertyEvaluationModel.getHeight(), propertyEvaluationModel.getRoom()); + + District district = null; + Map params = new HashMap(); + params.put("city", propertyEvaluationModel.getCity()); + if (StringUtils.isNotBlank(propertyEvaluationModel.getDistrict())) { + params.put("suggestDistrict", propertyEvaluationModel.getDistrict()); + } + params.put("address", propertyEvaluationModel.getAddress()); + if (StringUtils.isNotBlank(propertyEvaluationModel.getName())) { + params.put("suggestName", propertyEvaluationModel.getName()); + } + params.put("category", "district"); + String result = addressMatchProxyService.parser(params); + if (result != null) { + JSONObject json = globalJson; + 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; + } + propertyEvaluationModel.setDistrict(district.getRegion()); + propertyEvaluationModel.setName(district.getName()); + try { + evaluateAction(propertyEvaluationModel, httpServletRequest, houseValueInformation, mav); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + private class UpdateHouseCaseRunnable implements Runnable { + private HouseValueInformationDto houseValueInformation; + + private JSONObject globalJson; + + private HouseInfomationModel model; + private RestfulModelAndView mav; + + public UpdateHouseCaseRunnable(HouseValueInformationDto houseValueInformation, JSONObject globalJson, HouseInfomationModel model, RestfulModelAndView mav) { + this.houseValueInformation = houseValueInformation; + this.globalJson = globalJson; + this.model = model; + this.mav = mav; + } + + @Override + public void run() { + //房源样本 + + //构造sampleQuery对象 + SampleQuery sampleQuery = new SampleQuery(); + sampleQuery.setCity(model.getCity()); + sampleQuery.setStrctureArea(model.getSize()); + sampleQuery.setAddress(model.getAddress()); + +// RestfulModelAndView houseCaseMav = new RestfulModelAndView(); + List querys = null; + try { + querys = convertSampileQueryToBean(sampleQuery); + } catch (Exception e) { + mav.setModel(BasicModel.buildBadRequestModel(e.getMessage())); + } + if (null == sampleQuery.getMax()) { + sampleQuery.setMax(10); + } + // 此处慢 + long start = System.currentTimeMillis(); + List collaterals = czbankSampleService.findSample2(querys, sampleQuery.getMax()); + long end = System.currentTimeMillis(); + System.out.println("用时:" + (end - start)); + Collateral collateral = collaterals.get(0); + List samples = collateral.getSample(); + UniversalDto dto = UniversalDto.newDto(); + if (null != collateral.getMaxPrice()) { + dto.append("maxUnitPrice", collateral.getMaxPrice()); + } + if (null != collateral.getMinPrice()) { + dto.append("minUnitPrice", collateral.getMinPrice()); + } + dto.append("datas", samples); + houseValueInformation.setHouseCase(dto); + + } + } + + private class UpdateSurroundingPoiRunnable implements Runnable { + private HouseValueInformationDto houseValueInformation; + + private JSONObject globalJson; + + private HouseInfomationModel model; + private RestfulModelAndView mav; + + public UpdateSurroundingPoiRunnable(HouseValueInformationDto houseValueInformation, JSONObject globalJson, HouseInfomationModel model, RestfulModelAndView mav) { + this.houseValueInformation = houseValueInformation; + this.globalJson = globalJson; + this.model = model; + this.mav = mav; + } + + @Override + public void run() { + //周边POI + +// RestfulModelAndView mav = new RestfulModelAndView(); +// mav.setViewType("rest"); + if (StringUtils.isBlank(model.getAddress())) { + mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "地址必须输入")); +// return mav; + } else { + String cat = "district"; + + HttpRequest request = new HttpRequest(); +// json = null; +// Map poiParams = new HashMap(); +// poiParams.put("city", model.getCity()); +// poiParams.put("address", model.getAddress()); +// poiParams.put("category", "property"); + //新匹配接口 +// json = request.getJsonContent("http://192.168.0.100:32080/FangJiaNlpService/match", poiParams, "UTF-8"); + JSONObject json = globalJson; + District property = null; + if (json != null && json.size() > 0) { + MatchedBuildingDto matchedBuildingDto = CommonDtoUtils.transformV(MatchedBuildingDto.class, json); + property = districtService.findByNameAndAlias(matchedBuildingDto.getCity(), matchedBuildingDto.getDistrict(), matchedBuildingDto.getName(), cat); + if (null == property) { + mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "小区数据不存在")); +// return mav; + } + DistrictFacilitys facilitys = districtFacilitysService.findByDistrict(property); +// mav.setModel(BasicModel.buildOKModel().setResult(facilitys)); + // 将周边POI数据放到结果集 + houseValueInformation.setSurroundingPoi(facilitys); + } else { + mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "小区数据不存在")); + } + } +// return mav; +// houseValueInformation.setSurroundingPoi(mav); + + mav.setModel(BasicModel.buildOKModel().setResult(houseValueInformation)); +// return mav; + } + } + + private PropertyEvaluationModel createPropertyEvaluationModelFromHouseInfomationModel(HouseInfomationModel model) { + PropertyEvaluationModel propertyModel = new PropertyEvaluationModel(); + propertyModel.setCity(model.getCity()); + propertyModel.setAddress(model.getAddress()); + propertyModel.setSize(model.getSize()); + + if (StringUtils.isNotBlank(model.getDistrict())) { + propertyModel.setDistrict(model.getDistrict()); + } + if (StringUtils.isNotBlank(model.getName())) { + propertyModel.setName(model.getName()); + } + if (StringUtils.isNotBlank(model.getBuildingNumber())) { + propertyModel.setBuildingNumber(model.getBuildingNumber()); + } + if (StringUtils.isNotBlank(model.getUnitNumber())) { + propertyModel.setUnitNumber(model.getUnitNumber()); + } + if (model.getFloor() != null && model.getFloor() != 0) { + propertyModel.setFloor(model.getFloor()); + } + if (model.getMaxFloor() != null && model.getMaxFloor() != 0) { + propertyModel.setMaxFloor(model.getMaxFloor()); + } + if (model.getRoom() != null && model.getRoom() != 0) { + propertyModel.setRoom(model.getRoom()); + } + if (model.getHall() != 0) { + propertyModel.setHall(model.getHall()); + } + if (model.getToilet() != 0) { + propertyModel.setToilet(model.getToilet()); + } + if (model.getCalDate() != null) { + propertyModel.setCalDate(model.getCalDate()); + } + if (model.getPropertyType() != null) { + propertyModel.setPropertyType(model.getPropertyType()); + } + if (StringUtils.isNotBlank(model.getDirection())) { + propertyModel.setDirection(model.getDirection()); + } + if (StringUtils.isNotBlank(model.getDecoration())) { + propertyModel.setDecoration(model.getDecoration()); + } + + if (model.getDecorationCost() != null && model.getDecorationCost() != 0) { + propertyModel.setDecorationCost(model.getDecorationCost()); + } + + if (model.getDecorationAge() != 0) { + propertyModel.setDecorationAge(model.getDecorationAge()); + } + if (StringUtils.isNotBlank(model.getView())) { + propertyModel.setView(model.getView()); + } + if (StringUtils.isNotBlank(model.getNoise())) { + propertyModel.setNoise(model.getNoise()); + } + if (model.getGardenSize() != null && model.getGardenSize() != 0) { + propertyModel.setGardenSize(model.getGardenSize()); + } + if (model.getBasementSize() != null && model.getBasementSize() != 0) { + propertyModel.setBasementSize(model.getBasementSize()); + } + if (model.getOuterSize() != null && model.getOuterSize() != 0) { + propertyModel.setOuterSize(model.getOuterSize()); + } + if (model.getAtticSize() != null && model.getAtticSize() != 0) { + propertyModel.setAtticSize(model.getAtticSize()); + } + if (StringUtils.isNotBlank(model.getNegativeFactor())) { + propertyModel.setNegativeFactor(model.getNegativeFactor()); + } + if (model.getAge() != 0) { + propertyModel.setAge(model.getAge()); + } + if (model.getCarportPrice() != null && model.getCarportPrice() != 0) { + propertyModel.setCarportPrice(model.getCarportPrice()); + } + + if (StringUtils.isNotBlank(model.getFacilities())) { + propertyModel.setFacilities(model.getFacilities()); + } + if (StringUtils.isNotBlank(model.getInsidePosition())) { + propertyModel.setInsidePosition(model.getInsidePosition()); + } + return propertyModel; + } + + private List convertSampileQueryToBean(SampleQuery... queries) throws Exception { + + List queryBeans = new ArrayList(queries.length); + for (SampleQuery q : queries) { + + CollateralSampleQueryBean queryBean = new CollateralSampleQueryBean(); + BeanUtils.copyProperties(q, queryBean); +// String propertyTypeCode = queryBean.getPropertyTypeCode(); +// if(!Arrays.asList("01", "02", "03").contains(propertyTypeCode)){ +// throw new Exception("propertyTypeCode取值非法"); +// } + String cat = "district"; + + if (StringUtils.isNotBlank(queryBean.getCity()) && StringUtils.isNotBlank(queryBean.getDistrict()) && StringUtils.isNotBlank(queryBean.getBuildingName())) { + District property = districtService.findByNameAndAlias(queryBean.getCity(), queryBean.getDistrict(), queryBean.getBuildingName(), cat); + if (property == null) { + throw new Exception("未找到该小区"); + } + queryBean.setProperty(property); + } else if (StringUtils.isNotBlank(queryBean.getAddress())) { + HttpRequest request = new HttpRequest(); + JSONObject json = null; + String address = queryBean.getAddress().replace(" ", "").replace("%", ""); +// Map params = new HashMap(); +// params.put("city", queryBean.getCity()); +// params.put("address", address); +// params.put("category", "property"); + //新匹配接口 +// json = request.getJsonContent("http://192.168.0.100:32080/FangJiaNlpService/match", params, "UTF-8"); + json = globalJson; + if (json != null && json.size() > 0) { + MatchedBuildingDto dto = CommonDtoUtils.transformV(MatchedBuildingDto.class, json); + District property = districtService.findByNameAndAlias(dto.getCity(), dto.getDistrict(), dto.getName(), cat); + if (property == null) { + throw new Exception("未找到该小区"); + } + queryBean.setProperty(property); + } else { + throw new Exception("未找到该小区"); + } + } + String estateType = queryBean.getProperty().getEstateType2(); + queryBean.setPropertyTypeCode("01"); + if (StringUtils.isNotBlank(estateType)) { + if (estateType.equals("普通住宅")) { + queryBean.setPropertyTypeCode("01"); + } else if (estateType.equals("别墅")) { + queryBean.setPropertyTypeCode("02"); + } else if (estateType.equals("商住")) { + queryBean.setPropertyTypeCode("03"); + } + } + + Integer decrCondCode = queryBean.getDecrCondCode(); + if (decrCondCode == null) { + decrCondCode = 2; + } + if (decrCondCode > 5 || decrCondCode < 1) { + throw new Exception("decrCondCode取值非法"); + } + Integer towardDirectCode = queryBean.getTowardDirectCode(); + if (towardDirectCode == null) { + towardDirectCode = 3; + } + if (towardDirectCode > 10 || towardDirectCode < 1) { + throw new Exception("towardDirectCode取值非法"); + } + queryBeans.add(queryBean); + } + return queryBeans; + } + + 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()); + } + } + + public Object evaluateAction(PropertyEvaluationModel model, HttpServletRequest request, HouseValueInformationDto houseValueInformation, RestfulModelAndView mav) + 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()); + } + // 将评估价放到结果集 + houseValueInformation.setAddressValue(districtPriceMap); +// 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; + } + } + + 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 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.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; + } + + 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 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; + } + + 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 Integer sum(List smallPrices) { + int sum = 0; + for (int price : smallPrices) { + sum += price; + } + return sum; + } + + 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; + } + + + public void setEvaluationService(EvaluationService evaluationService) { + this.evaluationService = evaluationService; + } + + public void setDistrictService(DistrictService districtService) { + this.districtService = districtService; + } + + public void setAddressService(AddressService addressService) { + } + + public void setDistrictStatService(DistrictStatService districtStatService) { + this.districtStatService = districtStatService; + } + + protected AddressMatchLogService addressMatchLogService; + + public void setAddressMatchLogService(AddressMatchLogService addressMatchLogService) { + this.addressMatchLogService = addressMatchLogService; + } + + + public BatchEvaluateService getBatchEvaluateService() { + return batchEvaluateService; + } + + public void setBatchEvaluateService(BatchEvaluateService batchEvaluateService) { + this.batchEvaluateService = batchEvaluateService; + } + + public void setAddressMatchProxyService(AddressMatchProxyService addressMatchProxyService) { + this.addressMatchProxyService = addressMatchProxyService; + } + + public void setLoudongService(LoudongService loudongService) { + this.loudongService = loudongService; + } + + public void setApiUserAuthorityService(ApiUserAuthorityService apiUserAuthorityService) { + this.apiUserAuthorityService = apiUserAuthorityService; + } + + public void setAverageStatisticsService(AverageStatisticsService averageStatisticsService) { + this.averageStatisticsService = averageStatisticsService; + } + + public void setServerAreaService(ServerAreaService serverAreaService) { + this.serverAreaService = serverAreaService; + } + + public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) { + this.apiUserCfgService = apiUserCfgService; + } + + public void setOpenApiLogService(OpenApiLogService openApiLogService) { + this.openApiLogService = openApiLogService; + } + + public void setFangjiaOfficialAreaService(FangjiaOfficialAreaService fangjiaOfficialAreaService) { + this.fangjiaOfficialAreaService = fangjiaOfficialAreaService; + } + + + public void setEvaluateRatioService(EvaluateRatioService evaluateRatioService) { + this.evaluateRatioService = evaluateRatioService; + } + + + public void setEvaluateFactorService(EvaluateFactorService evaluateFactorService) { + this.evaluateFactorService = evaluateFactorService; + } + + public void setCzbankSampleService(CzbankSampleService czbankSampleService) { + this.czbankSampleService = czbankSampleService; + } + + public void setDistrictFacilitysService(DistrictFacilitysService districtFacilitysService) { + this.districtFacilitysService = districtFacilitysService; + } + +} + +*/ diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/dto/CityNewPriceDto.java b/projects/fangjia-open/src/main/java/com/fangjia/open/dto/CityNewPriceDto.java index 438808ffc..4b09649d3 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/dto/CityNewPriceDto.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/dto/CityNewPriceDto.java @@ -7,7 +7,8 @@ import com.fangjia.dal.mongo.model.CityNewPrice; import com.fangjia.dal.mongo.model.RegionSellStat; @SuppressWarnings("serial") -public class CityNewPriceDto implements Serializable{ +public class +CityNewPriceDto implements Serializable{ /** * diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/dto/HouseValueInformationDto.java b/projects/fangjia-open/src/main/java/com/fangjia/open/dto/HouseValueInformationDto.java new file mode 100644 index 000000000..a10089a40 --- /dev/null +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/dto/HouseValueInformationDto.java @@ -0,0 +1,57 @@ +package com.fangjia.open.dto; + +import com.fangjia.dal.mongo.model.DistrictFacilitys; +import com.fangjia.open.dto.addressGovernance.MatchedBuildingDto; +import com.fangjia.open.model.RestfulModelAndView; + +import java.util.Map; + +/** + * @author 13607 + * @since 2023/12/12 10:47 + */ +public class HouseValueInformationDto { + // 鍘熷皬鍖哄潎浠疯繑鍥炲�� + private MatchedBuildingDto communityAvgPrice; + // 鍘熸埧灞嬩环鍊艰瘎浼拌繑鍥炲�� + private Map addressValue; + + //鍘熸埧婧愭牱鏈繑鍥炲�� + private UniversalDto houseCase; + + //鍘熷懆杈筆OI杩斿洖鍊� + private DistrictFacilitys surroundingPoi; + + public MatchedBuildingDto getCommunityAvgPrice() { + return communityAvgPrice; + } + + public void setCommunityAvgPrice(MatchedBuildingDto communityAvgPrice) { + this.communityAvgPrice = communityAvgPrice; + } + + public Map getAddressValue() { + return addressValue; + } + + public void setAddressValue(Map addressValue) { + this.addressValue = addressValue; + } + + public UniversalDto getHouseCase() { + return houseCase; + } + + public void setHouseCase(UniversalDto houseCase) { + this.houseCase = houseCase; + } + + public DistrictFacilitys getSurroundingPoi() { + return surroundingPoi; + } + + public void setSurroundingPoi(DistrictFacilitys surroundingPoi) { + this.surroundingPoi = surroundingPoi; + } +} + diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/model/HouseInfomationModel.java b/projects/fangjia-open/src/main/java/com/fangjia/open/model/HouseInfomationModel.java new file mode 100644 index 000000000..52cbca930 --- /dev/null +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/model/HouseInfomationModel.java @@ -0,0 +1,941 @@ +package com.fangjia.open.model; + +import java.util.Date; + +/** + * @author 13607 + * @since 2023/12/12 14:27 + */ +public class HouseInfomationModel extends FangjiaApiModel { + private String city; + private String address; + private String category; + private boolean useMap; + + /** + * 判断是不是有房估价 + */ + private boolean isYouFang; + + /** + * 判断是不是友达 + */ + private boolean isYouDa; + + /** + * 区域 + */ + private String region; + + /** + * 区域(新版本估价) + **/ + private String district; + + /** + * 小区名 + */ + private String districtName; + /** + * 小区名(新版本) + */ + private String name; + /** + * 楼号 + */ + private String unitNumber; + /** + * 新楼号 + */ + private String houseNumber; + + private String id; + /** + * 室号 + */ + private String roomNumber; + + /** + * 面积 + */ + private double size; + + /** + * 所在楼层 + */ + private Integer floor; + + /** + * 总楼层 + */ + private Integer height; + + /** + * 室数 + */ + private Integer room; + + /** + * 厅数 + */ + private int hall; + + /** + * 卫数 + */ + private int toilet; + + /** + * 估价时间 + */ + private Date calDate; + + private String propertyType; + + + /** + * 建筑类型 + */ + private String buildType; + + /** + * 朝向 + */ + private String direction; + + /** + * 装修情况 + */ + private String fitment; + + /** + * 装修价格 + */ + private int fitmentCharge; + + /** + * 景观情况 + */ + private String view; + + /** + * 噪音情况 + */ + private String noise; + + /** + * 花园面积 + */ + private Double gardenArea; + + /** + * 地下室面积 + */ + private Double basementArea; + + /** + * 厌恶因素 + */ + private String[] worryFactor; + + /** + * 房龄 + */ + private int age; + + /** + * 自有车位 + */ + private String carport; + + /** + * 小区配套 + */ + private String facilities; + + /** + * 小区位置 + */ + private String insidepos; + + /** + * 装修年限 + */ + private int fitmentAge; + + /** + * 采光通风 + */ + private String lightingVentilation; + + /** + * 边套装置 + */ + private String sideset; + + /** + * 建筑质量 + */ + private String[] buildQuality; + + /** + * 厌恶设施 + */ + private String worryFacility; + + /** + * 产权属性 + */ + private String houseProperty; + + /** + * 其他因素 + */ + private String otherFactor; + + /** + * 门面开间 + */ + private String facade; + + /** + * 公共交通 + */ + private String traffice; + + /** + * 形状 + */ + private String shape; + + /** + * 障碍物 + */ + private String obstacle; + + /** + * 经营性质 + */ + private String industry; + + /** + * 配套设备 + */ + private String supportDevice; + + /** + * 距离扶梯位置 + */ + private String leftPosition; + + /** + * 商铺类型 + */ + private String shopType; + + /** + * 商铺唯一性 + */ + private String shopUnique; + + /** + * 商铺位置 + */ + private String location; + + private String kind; + + private boolean isNewDistrict; + + private Integer carportPrice; + + private String keyword; + + private String buildingNumber; + + private Integer maxFloor; + + private String decoration; + + private Integer decorationCost; + + private Double gardenSize; + private Double basementSize; + private Double outerSize; + private Double atticSize; + private String negativeFactor; + private String insidePosition; + private int decorationAge; + + private boolean convert; + + private String estateType; + private String periodType; + private Integer periodCount; + + + private Integer houseType; + private String clientNo; + private int scope; + + private Integer maxPrice; + private Integer minPrice; + + private Integer radius; + private Integer limit; + private String app; + + private String user; + + private Integer avgPrice; + + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public boolean isUseMap() { + return useMap; + } + + public void setUseMap(boolean useMap) { + this.useMap = useMap; + } + + public boolean isYouFang() { + return isYouFang; + } + + public void setYouFang(boolean youFang) { + isYouFang = youFang; + } + + public boolean isYouDa() { + return isYouDa; + } + + public void setYouDa(boolean youDa) { + isYouDa = youDa; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public String getDistrict() { + return district; + } + + public void setDistrict(String district) { + this.district = district; + } + + public String getDistrictName() { + return districtName; + } + + public void setDistrictName(String districtName) { + this.districtName = districtName; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUnitNumber() { + return unitNumber; + } + + public void setUnitNumber(String unitNumber) { + this.unitNumber = unitNumber; + } + + public String getHouseNumber() { + return houseNumber; + } + + public void setHouseNumber(String houseNumber) { + this.houseNumber = houseNumber; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getRoomNumber() { + return roomNumber; + } + + public void setRoomNumber(String roomNumber) { + this.roomNumber = roomNumber; + } + + public double getSize() { + return size; + } + + public void setSize(double size) { + this.size = size; + } + + public Integer getFloor() { + return floor; + } + + public void setFloor(Integer floor) { + this.floor = floor; + } + + public Integer getHeight() { + return height; + } + + public void setHeight(Integer height) { + this.height = height; + } + + public Integer getRoom() { + return room; + } + + public void setRoom(Integer room) { + this.room = room; + } + + public int getHall() { + return hall; + } + + public void setHall(int hall) { + this.hall = hall; + } + + public int getToilet() { + return toilet; + } + + public void setToilet(int toilet) { + this.toilet = toilet; + } + + public Date getCalDate() { + return calDate; + } + + public void setCalDate(Date calDate) { + this.calDate = calDate; + } + + public String getPropertyType() { + return propertyType; + } + + public void setPropertyType(String propertyType) { + this.propertyType = propertyType; + } + + public String getBuildType() { + return buildType; + } + + public void setBuildType(String buildType) { + this.buildType = buildType; + } + + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + public String getFitment() { + return fitment; + } + + public void setFitment(String fitment) { + this.fitment = fitment; + } + + public int getFitmentCharge() { + return fitmentCharge; + } + + public void setFitmentCharge(int fitmentCharge) { + this.fitmentCharge = fitmentCharge; + } + + public String getView() { + return view; + } + + public void setView(String view) { + this.view = view; + } + + public String getNoise() { + return noise; + } + + public void setNoise(String noise) { + this.noise = noise; + } + + public Double getGardenArea() { + return gardenArea; + } + + public void setGardenArea(Double gardenArea) { + this.gardenArea = gardenArea; + } + + public Double getBasementArea() { + return basementArea; + } + + public void setBasementArea(Double basementArea) { + this.basementArea = basementArea; + } + + public String[] getWorryFactor() { + return worryFactor; + } + + public void setWorryFactor(String[] worryFactor) { + this.worryFactor = worryFactor; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getCarport() { + return carport; + } + + public void setCarport(String carport) { + this.carport = carport; + } + + public String getFacilities() { + return facilities; + } + + public void setFacilities(String facilities) { + this.facilities = facilities; + } + + public String getInsidepos() { + return insidepos; + } + + public void setInsidepos(String insidepos) { + this.insidepos = insidepos; + } + + public int getFitmentAge() { + return fitmentAge; + } + + public void setFitmentAge(int fitmentAge) { + this.fitmentAge = fitmentAge; + } + + public String getLightingVentilation() { + return lightingVentilation; + } + + public void setLightingVentilation(String lightingVentilation) { + this.lightingVentilation = lightingVentilation; + } + + public String getSideset() { + return sideset; + } + + public void setSideset(String sideset) { + this.sideset = sideset; + } + + public String[] getBuildQuality() { + return buildQuality; + } + + public void setBuildQuality(String[] buildQuality) { + this.buildQuality = buildQuality; + } + + public String getWorryFacility() { + return worryFacility; + } + + public void setWorryFacility(String worryFacility) { + this.worryFacility = worryFacility; + } + + public String getHouseProperty() { + return houseProperty; + } + + public void setHouseProperty(String houseProperty) { + this.houseProperty = houseProperty; + } + + public String getOtherFactor() { + return otherFactor; + } + + public void setOtherFactor(String otherFactor) { + this.otherFactor = otherFactor; + } + + public String getFacade() { + return facade; + } + + public void setFacade(String facade) { + this.facade = facade; + } + + public String getTraffice() { + return traffice; + } + + public void setTraffice(String traffice) { + this.traffice = traffice; + } + + public String getShape() { + return shape; + } + + public void setShape(String shape) { + this.shape = shape; + } + + public String getObstacle() { + return obstacle; + } + + public void setObstacle(String obstacle) { + this.obstacle = obstacle; + } + + public String getIndustry() { + return industry; + } + + public void setIndustry(String industry) { + this.industry = industry; + } + + public String getSupportDevice() { + return supportDevice; + } + + public void setSupportDevice(String supportDevice) { + this.supportDevice = supportDevice; + } + + public String getLeftPosition() { + return leftPosition; + } + + public void setLeftPosition(String leftPosition) { + this.leftPosition = leftPosition; + } + + public String getShopType() { + return shopType; + } + + public void setShopType(String shopType) { + this.shopType = shopType; + } + + public String getShopUnique() { + return shopUnique; + } + + public void setShopUnique(String shopUnique) { + this.shopUnique = shopUnique; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + + public boolean isNewDistrict() { + return isNewDistrict; + } + + public void setNewDistrict(boolean newDistrict) { + isNewDistrict = newDistrict; + } + + public Integer getCarportPrice() { + return carportPrice; + } + + public void setCarportPrice(Integer carportPrice) { + this.carportPrice = carportPrice; + } + + public String getKeyword() { + return keyword; + } + + public void setKeyword(String keyword) { + this.keyword = keyword; + } + + public String getBuildingNumber() { + return buildingNumber; + } + + public void setBuildingNumber(String buildingNumber) { + this.buildingNumber = buildingNumber; + } + + public Integer getMaxFloor() { + return maxFloor; + } + + public void setMaxFloor(Integer maxFloor) { + this.maxFloor = maxFloor; + } + + public String getDecoration() { + return decoration; + } + + public void setDecoration(String decoration) { + this.decoration = decoration; + } + + public Integer getDecorationCost() { + return decorationCost; + } + + public void setDecorationCost(Integer decorationCost) { + this.decorationCost = decorationCost; + } + + public Double getGardenSize() { + return gardenSize; + } + + public void setGardenSize(Double gardenSize) { + this.gardenSize = gardenSize; + } + + public Double getBasementSize() { + return basementSize; + } + + public void setBasementSize(Double basementSize) { + this.basementSize = basementSize; + } + + public Double getOuterSize() { + return outerSize; + } + + public void setOuterSize(Double outerSize) { + this.outerSize = outerSize; + } + + public Double getAtticSize() { + return atticSize; + } + + public void setAtticSize(Double atticSize) { + this.atticSize = atticSize; + } + + public String getNegativeFactor() { + return negativeFactor; + } + + public void setNegativeFactor(String negativeFactor) { + this.negativeFactor = negativeFactor; + } + + public String getInsidePosition() { + return insidePosition; + } + + public void setInsidePosition(String insidePosition) { + this.insidePosition = insidePosition; + } + + public int getDecorationAge() { + return decorationAge; + } + + public void setDecorationAge(int decorationAge) { + this.decorationAge = decorationAge; + } + + public boolean isConvert() { + return convert; + } + + public void setConvert(boolean convert) { + this.convert = convert; + } + + public String getEstateType() { + return estateType; + } + + public void setEstateType(String estateType) { + this.estateType = estateType; + } + + public String getPeriodType() { + return periodType; + } + + public void setPeriodType(String periodType) { + this.periodType = periodType; + } + + public Integer getPeriodCount() { + return periodCount; + } + + public void setPeriodCount(Integer periodCount) { + this.periodCount = periodCount; + } + + public Integer getHouseType() { + return houseType; + } + + public void setHouseType(Integer houseType) { + this.houseType = houseType; + } + + public String getClientNo() { + return clientNo; + } + + public void setClientNo(String clientNo) { + this.clientNo = clientNo; + } + + public int getScope() { + return scope; + } + + public void setScope(int scope) { + this.scope = scope; + } + + public Integer getMaxPrice() { + return maxPrice; + } + + public void setMaxPrice(Integer maxPrice) { + this.maxPrice = maxPrice; + } + + public Integer getMinPrice() { + return minPrice; + } + + public void setMinPrice(Integer minPrice) { + this.minPrice = minPrice; + } + + public Integer getRadius() { + return radius; + } + + public void setRadius(Integer radius) { + this.radius = radius; + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public Integer getAvgPrice() { + return avgPrice; + } + + public void setAvgPrice(Integer avgPrice) { + this.avgPrice = avgPrice; + } +} + diff --git a/projects/fangjia-open/~$缃戝紑鏀炬帴鍙f枃妗1.0.doc b/projects/fangjia-open/~$缃戝紑鏀炬帴鍙f枃妗1.0.doc deleted file mode 100644 index cf2f05482..000000000 Binary files a/projects/fangjia-open/~$缃戝紑鏀炬帴鍙f枃妗1.0.doc and /dev/null differ diff --git a/projects/fangjia-pds/src/main/webapp/static/v1.2/js/skin/whyGreen/datepicker.css.baiduyun.uploading.cfg b/projects/fangjia-pds/src/main/webapp/static/v1.2/js/skin/whyGreen/datepicker.css.baiduyun.uploading.cfg new file mode 100644 index 000000000..898a600ea Binary files /dev/null and b/projects/fangjia-pds/src/main/webapp/static/v1.2/js/skin/whyGreen/datepicker.css.baiduyun.uploading.cfg differ diff --git a/projects/fangjia-pds/src/main/webapp/static/v1.2/js/skin/whyGreen/img.gif.baiduyun.uploading.cfg b/projects/fangjia-pds/src/main/webapp/static/v1.2/js/skin/whyGreen/img.gif.baiduyun.uploading.cfg new file mode 100644 index 000000000..8a5c576b8 Binary files /dev/null and b/projects/fangjia-pds/src/main/webapp/static/v1.2/js/skin/whyGreen/img.gif.baiduyun.uploading.cfg differ diff --git a/projects/fangjia-pds/src/main/webapp/static/v1.2/style/common.css.baiduyun.uploading.cfg b/projects/fangjia-pds/src/main/webapp/static/v1.2/style/common.css.baiduyun.uploading.cfg new file mode 100644 index 000000000..1a676aa72 Binary files /dev/null and b/projects/fangjia-pds/src/main/webapp/static/v1.2/style/common.css.baiduyun.uploading.cfg differ diff --git a/projects/fangjia-pds/src/main/webapp/static/v1.2/style/datepicker.css.baiduyun.uploading.cfg b/projects/fangjia-pds/src/main/webapp/static/v1.2/style/datepicker.css.baiduyun.uploading.cfg new file mode 100644 index 000000000..20cd31e15 Binary files /dev/null and b/projects/fangjia-pds/src/main/webapp/static/v1.2/style/datepicker.css.baiduyun.uploading.cfg differ diff --git a/projects/fangjia-pds/src/main/webapp/static/v1.2/style/dialogBox.css.baiduyun.uploading.cfg b/projects/fangjia-pds/src/main/webapp/static/v1.2/style/dialogBox.css.baiduyun.uploading.cfg new file mode 100644 index 000000000..e271d60c6 Binary files /dev/null and b/projects/fangjia-pds/src/main/webapp/static/v1.2/style/dialogBox.css.baiduyun.uploading.cfg differ diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/majintao/sdklog/sdkclient_CommunicateLog_info b/projects/fangjia-script/src/main/groovy/com/fangjia/script/majintao/sdklog/sdkclient_CommunicateLog_info new file mode 100644 index 000000000..e69de29bb diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/majintao/sdklog/sdkclient_EMAYSDK_info b/projects/fangjia-script/src/main/groovy/com/fangjia/script/majintao/sdklog/sdkclient_EMAYSDK_info new file mode 100644 index 000000000..e69de29bb diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/majintao/test.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/majintao/test.groovy new file mode 100644 index 000000000..e6b861ff6 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/majintao/test.groovy @@ -0,0 +1,71 @@ +package com.fangjia.script.majintao + +import com.fangjia.core.util.HttpRequest +import com.fangjia.script.util.ExcelUtils +import net.sf.json.JSONObject + + +ExcelUtils.removeEmptyRow("F:\\估家\\文件\\北交所\\testcopy.xlsx") +ExcelUtils.singleThreadingModify("F:\\估家\\文件\\北交所\\testcopy.xlsx", { List items -> + String excelFilePath = "F:\\估家\\文件\\北交所\\testcopy.xlsx"; + String comprehensiveUrl = "http://192.168.10.15:9180/comprehensiveQuery/houseValueInformation"; + String communityUrl = "http://192.168.10.15:9180/addrSvc/avgPrice"; + String valueUrl = "http://192.168.10.15:9180/property/addressEvaluate"; + String caseUrl = "http://192.168.10.15:9180/house/case"; + String poiUrl = "http://192.168.10.15:9180/district/addrFacilitys"; + + HttpRequest httpRequest = new HttpRequest(); + map = new HashMap() + + String city = items['A'] + String address = items['B'] + double size = items['C'] + + System.out.println(city + "---" + address + "----" + size); + + map.put("city", city) + map.put("address", address) + map.put("size", size.toString()) + map.put("strctureArea", size.toString()) + map.put("token", "F54F52381C49BB9EB4A33EB1B65604AE4B71A28AEE53518A94A2F360408B9056D57553931D15CE6DDE765562DAD286BA38E05A4CDAFC51C3D527A4959BF8E75A3B95DB7108FCEA340DDE61925616DB55118E1851E67D83EAD800460D100D6B667A4ED8EE67C8F7FB") + + if (!address.contains("%")) { + // 发送HTTP请求 + long start + long end + +// start = System.currentTimeMillis(); +// httpRequest.getJsonContent(communityUrl, map, "UTF-8") +// +// +// end = System.currentTimeMillis(); +// items['D'] = String.valueOf(end - start); +// +// start = System.currentTimeMillis(); +// httpRequest.getJsonContent(valueUrl, map, "UTF-8") +// end = System.currentTimeMillis(); +// items['E'] = String.valueOf(end - start); +// +// start = System.currentTimeMillis(); +// httpRequest.getJsonContent(caseUrl, map, "UTF-8") +// end = System.currentTimeMillis(); +// items['F'] = String.valueOf(end - start); +// +// start = System.currentTimeMillis(); +// httpRequest.getJsonContent(poiUrl, map, "UTF-8") +// end = System.currentTimeMillis(); +// items['G'] = String.valueOf(end - start); + + start = System.currentTimeMillis(); + def content = httpRequest.getJsonContent(comprehensiveUrl, map, "UTF-8") + end = System.currentTimeMillis(); + items['H'] = String.valueOf(end - start); + println content.get("msg") + if(content.get("msg").contains("该地址不支持估价!")) { + items['I'] = "该地址不支持估价!" + } + } + + +}) + diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/ExcelUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/ExcelUtils.groovy index 4d263c58e..87c14b741 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/ExcelUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/ExcelUtils.groovy @@ -443,6 +443,45 @@ public class ExcelUtils{ } + public static singleThreadingModify(String fileName, Closure closure, Integer srcSheetIndex = 0, String destSheetName = null){ + if(!destSheetName){ + def inp = new FileInputStream(fileName); + Workbook workbook = WorkbookFactory.create(inp) + workbook.setForceFormulaRecalculation(true) + Sheet sheet = workbook.getSheetAt(srcSheetIndex); + destSheetName = sheet.getSheetName(); + } + + def data = ExcelUtils.read(fileName, srcSheetIndex, 0) + def body = data.subList(1, data.size()) + def nThread = Runtime.getRuntime().availableProcessors() * 3 + println nThread + ExecutorService executorService = Executors.newFixedThreadPool(3) + final AtomicInteger counter = new AtomicInteger(0) + final double total = body.size() + for(int i = 0 ; i < body.size(); i++){ + final row = body[i] + executorService.submit(new Runnable() { + @Override + void run() { + try{ + closure.call(row) + int count = counter.incrementAndGet() + if(count % 1000 == 0){ + println(DateUtils.formatDateByPattern(new Date(), "yyyy-MM-dd HH:mm:ss")+"执行进度:${com.fangjia.core.util.DataUtil.roundDouble((count * 100)/total, 2)}%") + } + }catch (Exception e){ + println(row) + e.printStackTrace() + } + } + }) + } + executorService.shutdown() + executorService.awaitTermination(30, TimeUnit.DAYS) + ExcelUtils.write(fileName, data, destSheetName) + } + public static Object getCellValue(Cell cell){ diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/CzbankSampleServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/CzbankSampleServiceImpl.java index 31ac175fe..d066c60a4 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/CzbankSampleServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/CzbankSampleServiceImpl.java @@ -37,18 +37,19 @@ import java.util.regex.Pattern; /** * 浙商银行风险缓释样本数据接口实现类 + * * @author wenyan */ -public class CzbankSampleServiceImpl implements CzbankSampleService{ +public class CzbankSampleServiceImpl implements CzbankSampleService { private static String[] DEAL_PRICE_FIELDS = new String[]{"city", "region", "districtName", "houseNumber", "totalPrice", "avgPrice", "area", "roomNumber", "fitment", "direction", "floor", "height", "tradeDate", "address"}; private static String[] HOUSE_FIELDS = new String[]{"city", "region", "districtName", "totalPrice", "avgPrice", - "area", "fitment", "direction", "floor", "height", "publishDate", "address", "estateType","url"}; + "area", "fitment", "direction", "floor", "height", "publishDate", "address", "estateType", "url"}; - public static String[] TAGS =new String[]{"独栋", "联排", "叠加", "双拼", "花园面积", "泳池", "别墅", "带花园", "洋房", "叠拼", "独院", "联体", "微墅", "大平墅"}; + public static String[] TAGS = new String[]{"独栋", "联排", "叠加", "双拼", "花园面积", "泳池", "别墅", "带花园", "洋房", "叠拼", "独院", "联体", "微墅", "大平墅"}; private DealPriceDao dealPriceDao; private HouseDao houseDao; @@ -63,10 +64,10 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ public List findSample(List queryBeans, int max) { List collateralList = new ArrayList(); - for(CollateralSampleQueryBean queryBean : queryBeans){ + for (CollateralSampleQueryBean queryBean : queryBeans) { Collateral collateral = new Collateral(); collateral.setCltNo(queryBean.getCltNo()); - if(queryBean.getProperty() != null){ + if (queryBean.getProperty() != null) { collateral.setSample(findSampleByQuery(queryBean, max)); } collateralList.add(collateral); @@ -78,10 +79,10 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ public List findSample2(List queryBeans, int max) { List collateralList = new ArrayList(); - for(CollateralSampleQueryBean queryBean : queryBeans){ - if(queryBean.getProperty() != null){ - Collateral collateral = findSampleByQuery2(queryBean, max); - if(null != collateral){ + for (CollateralSampleQueryBean queryBean : queryBeans) { + if (queryBean.getProperty() != null) { + Collateral collateral = findSampleByQuery2(queryBean, max); + if (null != collateral) { collateralList.add(collateral); } } @@ -95,34 +96,34 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ SampleWrapper target = convertQueryBean2Sample(queryBean); District district = queryBean.getProperty(); - List querySamples= new ArrayList(); + List querySamples = new ArrayList(); List samples = findShopSampleByDistrict(district.getCity(), district.getRegion(), district.getName(), district.getAlias()); scoreForSample(samples, target); - for(SampleWrapper sample : samples){ + for (SampleWrapper sample : samples) { sample.setProperty(queryBean.getProperty()); } querySamples.addAll(samples); - if(querySamples.size() < max){ + if (querySamples.size() < max) { district = districtService.findOneByKey(new DistrictKey(queryBean.getFangjiaCity(), queryBean.getFangjiaDistrict(), queryBean.getBuildingName()), "shop"); List districts = districtService.findNearestDistrict(district, 1000, 5); - for(District d : districts){ + for (District d : districts) { d = districtService.findById(d.getId()); List nearlySample = findShopSampleByDistrict(d.getCity(), d.getRegion(), d.getName(), district.getAlias()); - for(SampleWrapper sample : nearlySample){ + for (SampleWrapper sample : nearlySample) { sample.setProperty(d); } scoreForSample(nearlySample, target); querySamples.addAll(nearlySample); - if(querySamples.size() > max){ + if (querySamples.size() > max) { break; } } } List selectedSample = new ArrayList(max); Set priceUniqueKeys = new HashSet(); - for(int i = 0; i < querySamples.size() && selectedSample.size() < max;i++){ + for (int i = 0; i < querySamples.size() && selectedSample.size() < max; i++) { SampleWrapper wrapper = querySamples.get(i); - if(priceUniqueKeys.contains(wrapper.getUnitPrice())){ + if (priceUniqueKeys.contains(wrapper.getUnitPrice())) { continue; } priceUniqueKeys.add(wrapper.getUnitPrice()); @@ -131,7 +132,7 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ fillOthersInfo(selectedSample); List sampleList = new ArrayList(selectedSample.size()); - for(SampleWrapper sampleWrapper : selectedSample){ + for (SampleWrapper sampleWrapper : selectedSample) { ShopSample sample = new ShopSample(); BeanUtils.copyProperties(sampleWrapper, sample); sample.setProjectId(sampleWrapper.getProperty().getId()); @@ -141,14 +142,13 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ } - - private List findShopSampleByDistrict(String city, String region, String name, List alias){ + private List findShopSampleByDistrict(String city, String region, String name, List alias) { List names = new ArrayList(); names.add(name); - if(alias != null){ - for(String alia : alias){ - if(StringUtils.isNotBlank(alia) && alia.length() > 2 && !names.contains(alia)){ + if (alias != null) { + for (String alia : alias) { + if (StringUtils.isNotBlank(alia) && alia.length() > 2 && !names.contains(alia)) { names.add(alia); } } @@ -157,8 +157,8 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ List samples = new ArrayList(); List houseQuery = new ArrayList(); - houseQuery.add(new QueryParam("city", city )); - houseQuery.add(new QueryParam("region", region )); + houseQuery.add(new QueryParam("city", city)); + houseQuery.add(new QueryParam("region", region)); BooleanQuery nameQuery = new BooleanQuery(); int c = 0; for (String n : names) { @@ -183,9 +183,9 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ houseQuery.add(new QueryParam("category", "shop_sell")); List houses = houseDao.findAllByParams(houseQuery, houseSortParams, 0, 500, HOUSE_FIELDS); FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertFangjiaToOfficial(city, region); - for(House house : houses){ + for (House house : houses) { SampleWrapper sampleWrapper = convertHouse2Sample(house); - if(fangjiaOfficialAreaMap != null){ + if (fangjiaOfficialAreaMap != null) { sampleWrapper.setProvince(fangjiaOfficialAreaMap.getProvinceCode()); sampleWrapper.setCity(fangjiaOfficialAreaMap.getCityCode()); sampleWrapper.setDistrict(fangjiaOfficialAreaMap.getDistrictCode()); @@ -195,55 +195,55 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ return samples; } - private List findSampleByQuery(CollateralSampleQueryBean queryBean, int max){ + private List findSampleByQuery(CollateralSampleQueryBean queryBean, int max) { SampleWrapper target = convertQueryBean2Sample(queryBean); District district = queryBean.getProperty(); DistrictStat districtStat = districtStatService.findOneDistrictStatsSort(district.getCity(), district.getRegion(), district.getName(), new Date()); - if(districtStat == null){ - districtStat = districtStatService.findOneDistrictStatsSort(district.getCity(), district.getRegion(), district.getName(), DateUtil.add( new Date(), -7)); + if (districtStat == null) { + districtStat = districtStatService.findOneDistrictStatsSort(district.getCity(), district.getRegion(), district.getName(), DateUtil.add(new Date(), -7)); } - List querySamples= new ArrayList(); + List querySamples = new ArrayList(); // List samples = findSampleByDistrict(district.getCity(), district.getRegion(), district.getName(), district.getAlias(), district.getMasterDistrictNname(), district.getEstateType2(),queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat); - List samples = findJnbankSampleByDistrict(district.getCity(), district.getRegion(), district.getName(), district.getAlias(), district.getMasterDistrictNname(), district.getEstateType2(),queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat); + List samples = findJnbankSampleByDistrict(district.getCity(), district.getRegion(), district.getName(), district.getAlias(), district.getMasterDistrictNname(), district.getEstateType2(), queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat); // scoreForSample(samples, target); sortForSample(samples, target); - for(SampleWrapper sample : samples){ + for (SampleWrapper sample : samples) { sample.setProperty(queryBean.getProperty()); } querySamples.addAll(samples); - if(querySamples.size() < max){ + if (querySamples.size() < max) { district = districtService.findOneByKey(new DistrictKey(district.getCity(), district.getRegion(), district.getName()), "district"); List districts = districtService.findNearestDistrict(district, 1000, 5); - for(District d : districts){ + for (District d : districts) { d = districtService.findById(d.getId()); //List nearlySample = findSampleByDistrict(d.getCity(), d.getRegion(), d.getName(), district.getAlias(), district.getMasterDistrictNname(), district.getEstateType2(),queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat); - List nearlySample = findJnbankSampleByDistrict(d.getCity(), d.getRegion(), d.getName(), district.getAlias(), district.getMasterDistrictNname(), district.getEstateType2(),queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat); + List nearlySample = findJnbankSampleByDistrict(d.getCity(), d.getRegion(), d.getName(), district.getAlias(), district.getMasterDistrictNname(), district.getEstateType2(), queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat); - for(SampleWrapper sample : nearlySample){ + for (SampleWrapper sample : nearlySample) { sample.setProperty(d); } // scoreForSample(nearlySample, target); sortForSample(nearlySample, target); querySamples.addAll(nearlySample); - if(querySamples.size() > max){ + if (querySamples.size() > max) { break; } } } - if(querySamples.isEmpty()){ + if (querySamples.isEmpty()) { SampleWrapper standardSample = createStandardSample(queryBean); - if(standardSample != null){ + if (standardSample != null) { standardSample.setProperty(queryBean.getProperty()); querySamples.add(standardSample); } } List selectedSample = new ArrayList(max); Set priceUniqueKeys = new HashSet(); - for(int i = 0; i < querySamples.size() && selectedSample.size() < max;i++){ + for (int i = 0; i < querySamples.size() && selectedSample.size() < max; i++) { SampleWrapper wrapper = querySamples.get(i); - if(priceUniqueKeys.contains(wrapper.getUnitPrice())){ + if (priceUniqueKeys.contains(wrapper.getUnitPrice())) { continue; } priceUniqueKeys.add(wrapper.getUnitPrice()); @@ -252,7 +252,7 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ fillOthersInfo(selectedSample); List sampleList = new ArrayList(selectedSample.size()); - for(SampleWrapper sampleWrapper : selectedSample){ + for (SampleWrapper sampleWrapper : selectedSample) { Sample sample = new Sample(); BeanUtils.copyProperties(sampleWrapper, sample); sampleList.add(sample); @@ -262,87 +262,88 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ /** * 添加样本的其他信息 + * * @param samples */ - private void fillOthersInfo(List samples){ - for(SampleWrapper sample : samples){ + private void fillOthersInfo(List samples) { + for (SampleWrapper sample : samples) { District district = sample.getProperty(); Date finishBuildingDate = DateUtil.parseStringToDate(district.getFinishBuildingDate()); - if(finishBuildingDate != null){ - sample.setCompleteDate(DateUtil.formatByPattern(finishBuildingDate,"yyyy-MM-dd")); + if (finishBuildingDate != null) { + sample.setCompleteDate(DateUtil.formatByPattern(finishBuildingDate, "yyyy-MM-dd")); } - if(district.getLat2() != null && district.getLat2() > 0){ + if (district.getLat2() != null && district.getLat2() > 0) { sample.setLatitude(district.getLat2() / 10000000000d); - sample.setLongitude(district.getLng2()/ 10000000000d); + sample.setLongitude(district.getLng2() / 10000000000d); } - if(StringUtils.isNotBlank(district.getAddress()) && district.getAddress().length() < 80){ + if (StringUtils.isNotBlank(district.getAddress()) && district.getAddress().length() < 80) { sample.setBuildingAddr(district.getAddress()); } - if("钢结构".equals(district.getBuildStructure())){ + if ("钢结构".equals(district.getBuildStructure())) { sample.setBuildStructureCode(10); - }else if("钢筋混凝土结构".equals(district.getBuildStructure()) - || "钢、钢筋混凝土结构".equals(district.getBuildStructure())){ + } else if ("钢筋混凝土结构".equals(district.getBuildStructure()) + || "钢、钢筋混凝土结构".equals(district.getBuildStructure())) { sample.setBuildStructureCode(20); - }else if("混合结构".equals(district.getBuildStructure())){ + } else if ("混合结构".equals(district.getBuildStructure())) { sample.setBuildStructureCode(30); - }else if("砖木结构".equals(district.getBuildStructure())){ + } else if ("砖木结构".equals(district.getBuildStructure())) { sample.setBuildStructureCode(40); } String propertyLife; - if(district.getCategory().equals("shop")){//商铺总是用年限设置为40年 + if (district.getCategory().equals("shop")) {//商铺总是用年限设置为40年 propertyLife = "40"; - }else{ - if(sample.getBuildStructureCode() != null){ - if("10".equals(sample.getBuildStructureCode())){ + } else { + if (sample.getBuildStructureCode() != null) { + if ("10".equals(sample.getBuildStructureCode())) { propertyLife = "70"; - }else if("20".equals(sample.getBuildStructureCode())){ + } else if ("20".equals(sample.getBuildStructureCode())) { propertyLife = "60"; - }else if("40".equals(sample.getBuildStructureCode())){ + } else if ("40".equals(sample.getBuildStructureCode())) { propertyLife = "40"; - }else if("30".equals(sample.getBuildStructureCode())){ + } else if ("30".equals(sample.getBuildStructureCode())) { propertyLife = "50"; - }else{ + } else { propertyLife = "60"; } - }else{ + } else { propertyLife = "60"; } } sample.setHouseUseLimit(Integer.valueOf(propertyLife)); sample.setBuildingRemainLife(getRemainUseYear(district, propertyLife)); - if(sample.getBuildingRemainLife() != null){ + if (sample.getBuildingRemainLife() != null) { sample.setHouseHadUsed(sample.getHouseUseLimit() - sample.getBuildingRemainLife()); } //之前是房源名称加“商住”,这块是将房源名称用小区名称填充 - if(StringUtils.isNotBlank(sample.getBuildingName()) && sample.getBuildingName().contains("(商住)")){ - if(!district.getName().contains("商住") && !district.getName().contains("商业")){ + if (StringUtils.isNotBlank(sample.getBuildingName()) && sample.getBuildingName().contains("(商住)")) { + if (!district.getName().contains("商住") && !district.getName().contains("商业")) { sample.setBuildingName(district.getName() + "(商住)"); } } - if("district".equals(district.getCategory())){ - if(sample.getAboveFloorAmount() != null && sample.getAboveFloorAmount() > 6){ + if ("district".equals(district.getCategory())) { + if (sample.getAboveFloorAmount() != null && sample.getAboveFloorAmount() > 6) { sample.setIsElevator(1); - }else{ + } else { sample.setIsElevator(0); } - if("别墅".equals(district.getEstateType2())){ + if ("别墅".equals(district.getEstateType2())) { sample.setPropertyTypeCode("02"); - }else{ + } else { sample.setPropertyTypeCode("01"); } String yearMonth = DateUtil.formatByPattern(sample.getSampleDate(), "yyyyMM"); DistrictSellStat districtSellStat = districtSellStatService.findByYearMonth(district.getCity(), district.getRegion(), district.getName(), Integer.valueOf(yearMonth)); - if(districtSellStat != null){ + if (districtSellStat != null) { sample.setDealDayPriceIndex(new Double(String.valueOf(districtSellStat.getAvgPrice()))); } DistrictStat districtStat = districtStatService.findOneDistrictStatsSort(district.getCity(), district.getRegion(), district.getName(), new Date()); - if(districtStat != null && districtStat.getAvgPrice() > 0){ + if (districtStat != null && districtStat.getAvgPrice() > 0) { sample.setCurrentPriceIndex(new Double(String.valueOf(districtStat.getAvgPrice()))); - if(sample.getDealDayPriceIndex() == null && DateUtil.getThisSunday(sample.getSampleDate()).equals(DateUtil.getThisSunday(new Date()))){ + if (sample.getDealDayPriceIndex() == null && DateUtil.getThisSunday(sample.getSampleDate()).equals(DateUtil.getThisSunday(new Date()))) { sample.setDealDayPriceIndex(sample.getCurrentPriceIndex()); } } @@ -353,37 +354,38 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ /** * 添加样本的其他信息 + * * @param samples */ - private void fillOthersSimpleInfo(List samples){ - for(SampleWrapper sample : samples){ + private void fillOthersSimpleInfo(List samples) { + for (SampleWrapper sample : samples) { District district = sample.getProperty(); Date finishBuildingDate = DateUtil.parseStringToDate(district.getFinishBuildingDate()); - if(finishBuildingDate != null){ - sample.setCompleteDate(DateUtil.formatByPattern(finishBuildingDate,"yyyy-MM-dd")); + if (finishBuildingDate != null) { + sample.setCompleteDate(DateUtil.formatByPattern(finishBuildingDate, "yyyy-MM-dd")); } - if(district.getLat2() != null && district.getLat2() > 0){ + if (district.getLat2() != null && district.getLat2() > 0) { sample.setLatitude(district.getLat2() / 10000000000d); - sample.setLongitude(district.getLng2()/ 10000000000d); + sample.setLongitude(district.getLng2() / 10000000000d); } - if(StringUtils.isNotBlank(district.getAddress()) && district.getAddress().length() < 80){ + if (StringUtils.isNotBlank(district.getAddress()) && district.getAddress().length() < 80) { sample.setBuildingAddr(district.getAddress()); } - if("钢结构".equals(district.getBuildStructure())){ + if ("钢结构".equals(district.getBuildStructure())) { sample.setBuildStructureCode(10); - }else if("钢筋混凝土结构".equals(district.getBuildStructure()) - || "钢、钢筋混凝土结构".equals(district.getBuildStructure())){ + } else if ("钢筋混凝土结构".equals(district.getBuildStructure()) + || "钢、钢筋混凝土结构".equals(district.getBuildStructure())) { sample.setBuildStructureCode(20); - }else if("混合结构".equals(district.getBuildStructure())){ + } else if ("混合结构".equals(district.getBuildStructure())) { sample.setBuildStructureCode(30); - }else if("砖木结构".equals(district.getBuildStructure())){ + } else if ("砖木结构".equals(district.getBuildStructure())) { sample.setBuildStructureCode(40); } //之前是房源名称加“商住”,这块是将房源名称用小区名称填充 - if(StringUtils.isNotBlank(sample.getBuildingName()) && sample.getBuildingName().contains("(商住)")){ - if(!district.getName().contains("商住") && !district.getName().contains("商业")){ + if (StringUtils.isNotBlank(sample.getBuildingName()) && sample.getBuildingName().contains("(商住)")) { + if (!district.getName().contains("商住") && !district.getName().contains("商业")) { sample.setBuildingName(district.getName() + "(商住)"); } } @@ -391,91 +393,126 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ } - - - private Collateral findSampleByQuery2(CollateralSampleQueryBean queryBean, int max){ + private Collateral findSampleByQuery2(CollateralSampleQueryBean queryBean, int max) { SampleWrapper target = convertQueryBean2Sample(queryBean); District district = queryBean.getProperty(); DistrictStat districtStat = districtStatService.findOneDistrictStatsSort(district.getCity(), district.getRegion(), district.getName(), new Date()); - if(districtStat == null){ - districtStat = districtStatService.findOneDistrictStatsSort(district.getCity(), district.getRegion(), district.getName(), DateUtil.add( new Date(), -7)); + if (districtStat == null) { + districtStat = districtStatService.findOneDistrictStatsSort(district.getCity(), district.getRegion(), district.getName(), DateUtil.add(new Date(), -7)); } - List querySamples= new ArrayList(); - List samples = findBeijiaoShouSampleByDistrict(district.getCity(), district.getRegion(), district.getName(), district.getAlias(), district.getMasterDistrictNname(), district.getEstateType2(),queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat, target.getStrctureArea(), 500); + List keys = new ArrayList(); + List querySamples = new ArrayList(); + String key = district.getName() + "_" + district.getRegion() + "_" + district.getCity(); + // 修改 + keys.add(key); + if (district.getAlias() != null) { + for (String alia : district.getAlias()) { + if (StringUtils.isNotBlank(alia)) { + key = alia + "_" + district.getRegion() + "_" + district.getCity(); + if (!keys.contains(key)) { + keys.add(key); + } + } + } + } + List samples = findBeijiaoShouSampleByDistrict(keys, district.getEstateType2(), queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat, target.getStrctureArea(), 20); + keys.clear(); sortForSample(samples, target); SampleWrapper maxSample = null; SampleWrapper minSample = null; - for(SampleWrapper sample : samples){ + + querySamples.addAll(samples); + if (querySamples.size() < max) { + district = districtService.findOneByKey(new DistrictKey(district.getCity(), district.getRegion(), district.getName()), "district"); + List districts = districtService.doFindNearestHasHouseDistrict(district, 3000, 50); + for (District d : districts) { + key = d.getName() + "_" + d.getRegion() + "_" + d.getCity(); + if (!keys.contains(key)) { + keys.add(key); + } + if (d.getAlias() != null) { + for (String alia : d.getAlias()) { + if (StringUtils.isNotBlank(alia)) { + key = alia + "_" + d.getRegion() + "_" + d.getCity(); + if (!keys.contains(key)) { + keys.add(key); + } + } + } + } + if (keys.size() > 10) { + if (querySamples.size() > max) { + break; + } else { + List nearlySample = findBeijiaoShouSampleByDistrict(keys, district.getEstateType2(), queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat, target.getStrctureArea(), 200); + + + for (SampleWrapper sample : nearlySample) { + sample.setProperty(d); + } + sortForSample(nearlySample, target); + HashMap> map = new HashMap>(); + //将样本按小区名分组 + for (SampleWrapper sample : nearlySample) { + String districtName = sample.getBuildingName(); + if (!map.containsKey(districtName)) { + List sampleWrappers = new ArrayList(); + sampleWrappers.add(sample); + map.put(districtName,sampleWrappers); + }else { + map.get(districtName).add(sample); + } + } + //将数据放入样本仓库 + for (Map.Entry> entry : map.entrySet()) { + //超过两个,只取两个 + // 取三个 + if (entry.getValue().size()>=3){ + querySamples.addAll(entry.getValue().subList(0,2)); + }else { + // 不超过两个,全部放入 + querySamples.addAll(entry.getValue()); + } + } +// if(nearlySample.size()>=2){ +// querySamples.addAll(nearlySample.subList(0,2)); +// }else{ +// querySamples.addAll(nearlySample); +// } + + } + keys.clear(); + } + + } + } + for (SampleWrapper sample : querySamples) { sample.setProperty(queryBean.getProperty()); - if(maxSample==null){ - maxSample = new SampleWrapper(); + if (maxSample == null) { +// maxSample = new SampleWrapper(); maxSample = sample; - }else{ - if(sample.getUnitPrice()>maxSample.getUnitPrice()){ + } else { + if (sample.getUnitPrice() > maxSample.getUnitPrice()) { maxSample = sample; } } - if(minSample==null){ - minSample = new SampleWrapper(); + if (minSample == null) { +// minSample = new SampleWrapper(); minSample = sample; - }else{ - if(sample.getUnitPrice() districts = districtService.findNearestDistrict(district, 3000, 50); - for(District d : districts){ - d = districtService.findById(d.getId()); - List nearlySample = findBeijiaoShouSampleByDistrict(d.getCity(), d.getRegion(), d.getName(), district.getAlias(), district.getMasterDistrictNname(), district.getEstateType2(),queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat, target.getStrctureArea(), 20); - - for(SampleWrapper sample : nearlySample){ - sample.setProperty(d); - } - sortForSample(nearlySample, target); -// for(SampleWrapper sample : nearlySample){ -// if(maxSample==null){ -// maxSample = new SampleWrapper(); -// maxSample = sample; -// }else{ -// if(sample.getUnitPrice()>maxSample.getUnitPrice()){ -// maxSample = sample; -// } -// } -// -// if(minSample==null){ -// minSample = new SampleWrapper(); -// minSample = sample; -// }else{ -// if(sample.getUnitPrice() max){ - break; - }else{ - if(nearlySample.size()>=2){ - querySamples.addAll(nearlySample.subList(0,2)); - }else{ - querySamples.addAll(nearlySample); - } - - } - } - } List selectedSample = new ArrayList(max); Set priceUniqueKeys = new HashSet(); - for(int i = 0; i < querySamples.size() && selectedSample.size() < max;i++){ + for (int i = 0; i < querySamples.size() && selectedSample.size() < max; i++) { SampleWrapper wrapper = querySamples.get(i); - if(priceUniqueKeys.contains(wrapper.getUnitPrice())){ + if (priceUniqueKeys.contains(wrapper.getUnitPrice())) { continue; } priceUniqueKeys.add(wrapper.getUnitPrice()); @@ -484,7 +521,7 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ fillOthersSimpleInfo(selectedSample); List sampleList = new ArrayList(selectedSample.size()); - for(SampleWrapper sampleWrapper : selectedSample){ + for (SampleWrapper sampleWrapper : selectedSample) { Sample sample = new Sample(); BeanUtils.copyProperties(sampleWrapper, sample); sampleList.add(sample); @@ -495,14 +532,14 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ collateral.setCltNo(queryBean.getCltNo()); collateral.setSample(sampleList); - if(minSample!=null){ + if (minSample != null) { // Sample sample = new Sample(); // BeanUtils.copyProperties(minSample, sample); // sampleList.add(sample); collateral.setMinPrice(minSample.getUnitPrice()); } - if(maxSample!=null){ + if (maxSample != null) { // Sample sample = new Sample(); // BeanUtils.copyProperties(maxSample, sample); // sampleList.add(sample); @@ -513,14 +550,13 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ } - - /** * 创建一个标准样本 + * * @param queryBean * @return */ - private SampleWrapper createStandardSample(CollateralSampleQueryBean queryBean){ + private SampleWrapper createStandardSample(CollateralSampleQueryBean queryBean) { SampleWrapper sample = new SampleWrapper(); sample.setCity(queryBean.getCity()); @@ -535,24 +571,24 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ sample.setSampleId(queryBean.getProperty().getId()); sample.setSampleDate(DateUtil.getThisSunday(new Date())); int avgPrice = districtStatService.findLatestDistrictAvgPrice(queryBean.getProperty().getCity(), queryBean.getProperty().getRegion(), queryBean.getProperty().getBlock(), queryBean.getProperty().getName()); - if(avgPrice != 0){ + if (avgPrice != 0) { sample.setUnitPrice(avgPrice); - }else{ + } else { return null; } return sample; } - /** * 样本特征正规化 + * * @param samples * @return */ - private List scoreForSample(List samples, SampleWrapper targetSample){ + private List scoreForSample(List samples, SampleWrapper targetSample) { - if(samples.isEmpty()){ + if (samples.isEmpty()) { return samples; } MaxMinModel areaMaxMin = new MaxMinModel(); @@ -562,78 +598,78 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ samples.add(0, targetSample); long now = System.currentTimeMillis(); - for(SampleWrapper sample : samples){ - if(sample.getStrctureArea() > areaMaxMin.max){ + for (SampleWrapper sample : samples) { + if (sample.getStrctureArea() > areaMaxMin.max) { areaMaxMin.max = sample.getStrctureArea(); } - if(sample.getStrctureArea() < areaMaxMin.min){ + if (sample.getStrctureArea() < areaMaxMin.min) { areaMaxMin.min = sample.getStrctureArea(); } - if(sample.getFloorNumber() != null && sample.getFloorNumber() > floorMaxMin.max){ - floorMaxMin.max = (double)sample.getFloorNumber(); + if (sample.getFloorNumber() != null && sample.getFloorNumber() > floorMaxMin.max) { + floorMaxMin.max = (double) sample.getFloorNumber(); } - if(sample.getFloorNumber() != null && sample.getFloorNumber() < floorMaxMin.min){ - floorMaxMin.min = (double)sample.getFloorNumber(); + if (sample.getFloorNumber() != null && sample.getFloorNumber() < floorMaxMin.min) { + floorMaxMin.min = (double) sample.getFloorNumber(); } - long freshness = (now - sample.getSampleDate().getTime())/(1000 * 60 * 60 * 24); - if(freshness > freshnessMaxMin.max){ + long freshness = (now - sample.getSampleDate().getTime()) / (1000 * 60 * 60 * 24); + if (freshness > freshnessMaxMin.max) { freshnessMaxMin.max = (double) freshness; } - if(freshness < freshnessMaxMin.min){ - freshnessMaxMin.min = (double)freshness; + if (freshness < freshnessMaxMin.min) { + freshnessMaxMin.min = (double) freshness; } - if(sample.getUnitPrice() != null){ - if(sample.getUnitPrice() > avgPriceMaxMin.max){ - avgPriceMaxMin.max = (double)sample.getUnitPrice(); + if (sample.getUnitPrice() != null) { + if (sample.getUnitPrice() > avgPriceMaxMin.max) { + avgPriceMaxMin.max = (double) sample.getUnitPrice(); } - if(sample.getUnitPrice() < avgPriceMaxMin.min){ - avgPriceMaxMin.min = (double)sample.getUnitPrice(); + if (sample.getUnitPrice() < avgPriceMaxMin.min) { + avgPriceMaxMin.min = (double) sample.getUnitPrice(); } } } - for(SampleWrapper sample : samples){ - Double areaScore,floorScore,freshnessScore,fitmentScore,directionScore,caseTypeScore,avgPriceScore; - if(areaMaxMin.max == areaMaxMin.min){ + for (SampleWrapper sample : samples) { + Double areaScore, floorScore, freshnessScore, fitmentScore, directionScore, caseTypeScore, avgPriceScore; + if (areaMaxMin.max == areaMaxMin.min) { areaScore = 1d; - }else{ - areaScore = (sample.getStrctureArea() - areaMaxMin.min) /(areaMaxMin.max - areaMaxMin.min); + } else { + areaScore = (sample.getStrctureArea() - areaMaxMin.min) / (areaMaxMin.max - areaMaxMin.min); } - if(floorMaxMin.min == floorMaxMin.max){ + if (floorMaxMin.min == floorMaxMin.max) { floorScore = 1.0; - }else if(sample.getFloorNumber() != null){ - floorScore = (sample.getFloorNumber() - floorMaxMin.min)/(floorMaxMin.max - floorMaxMin.min); - }else{ + } else if (sample.getFloorNumber() != null) { + floorScore = (sample.getFloorNumber() - floorMaxMin.min) / (floorMaxMin.max - floorMaxMin.min); + } else { floorScore = 0.0; } - if(freshnessMaxMin.max == freshnessMaxMin.min){ + if (freshnessMaxMin.max == freshnessMaxMin.min) { freshnessScore = 1.0; - }else{ - freshnessScore = ((now - sample.getSampleDate().getTime())/(1000 * 60 * 60 * 24 * 7) - freshnessMaxMin.min)/(freshnessMaxMin.max - freshnessMaxMin.min); + } else { + freshnessScore = ((now - sample.getSampleDate().getTime()) / (1000 * 60 * 60 * 24 * 7) - freshnessMaxMin.min) / (freshnessMaxMin.max - freshnessMaxMin.min); } - if(null != sample.getDecrCondCode() && sample.getDecrCondCode().equals(targetSample.getDecrCondCode())){ + if (null != sample.getDecrCondCode() && sample.getDecrCondCode().equals(targetSample.getDecrCondCode())) { fitmentScore = 1.0; - }else{ + } else { fitmentScore = 0.0; } - if(null !=sample.getTowardDirectCode() && sample.getTowardDirectCode().equals(targetSample.getTowardDirectCode())){ + if (null != sample.getTowardDirectCode() && sample.getTowardDirectCode().equals(targetSample.getTowardDirectCode())) { directionScore = 1.0; - }else{ + } else { directionScore = 0.0; } - if(sample.getCaseTypeCode() == null){ + if (sample.getCaseTypeCode() == null) { caseTypeScore = 1.0; - }else if("02".equals(sample.getCaseTypeCode())){ + } else if ("02".equals(sample.getCaseTypeCode())) { caseTypeScore = 0.8; - }else if("03".equals(sample.getCaseTypeCode())){ + } else if ("03".equals(sample.getCaseTypeCode())) { caseTypeScore = 0.3; - }else{ + } else { caseTypeScore = 0.0; } - if(targetSample.getUnitPrice() == null){ + if (targetSample.getUnitPrice() == null) { avgPriceScore = 1.0; - }else{ - avgPriceScore = (sample.getUnitPrice() - avgPriceMaxMin.min)/(avgPriceMaxMin.max - avgPriceMaxMin.min); + } else { + avgPriceScore = (sample.getUnitPrice() - avgPriceMaxMin.min) / (avgPriceMaxMin.max - avgPriceMaxMin.min); } sample.getNormalizedFactor().put("areaScore", areaScore); sample.getNormalizedFactor().put("floorScore", floorScore); @@ -644,19 +680,19 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ sample.getNormalizedFactor().put("avgPriceScore", avgPriceScore); } - for(SampleWrapper sample : samples){ + for (SampleWrapper sample : samples) { double score = 0.0; - score += ( Math.abs(targetSample.getNormalizedFactor().get("areaScore") - sample.getNormalizedFactor().get("areaScore")) ) * 5; - score += ( Math.abs(targetSample.getNormalizedFactor().get("floorScore") - sample.getNormalizedFactor().get("floorScore")) ) * 3; - score += ( Math.abs(targetSample.getNormalizedFactor().get("freshnessScore") - sample.getNormalizedFactor().get("freshnessScore")) ) * 20; - score += ( Math.abs(targetSample.getNormalizedFactor().get("fitmentScore") - sample.getNormalizedFactor().get("fitmentScore")) ) * 2; - score += ( Math.abs(targetSample.getNormalizedFactor().get("directionScore") - sample.getNormalizedFactor().get("directionScore")) ) * 2; - score += ( Math.abs(targetSample.getNormalizedFactor().get("caseTypeScore") - sample.getNormalizedFactor().get("caseTypeScore")) ) * 1; - score += ( Math.abs(targetSample.getNormalizedFactor().get("avgPriceScore") - sample.getNormalizedFactor().get("avgPriceScore")) ) * 70; - try{ - sample.setSampleLevel(DataUtil.roundDouble(score, 5)); - }catch(Exception e){ - e.printStackTrace(); + score += (Math.abs(targetSample.getNormalizedFactor().get("areaScore") - sample.getNormalizedFactor().get("areaScore"))) * 5; + score += (Math.abs(targetSample.getNormalizedFactor().get("floorScore") - sample.getNormalizedFactor().get("floorScore"))) * 3; + score += (Math.abs(targetSample.getNormalizedFactor().get("freshnessScore") - sample.getNormalizedFactor().get("freshnessScore"))) * 20; + score += (Math.abs(targetSample.getNormalizedFactor().get("fitmentScore") - sample.getNormalizedFactor().get("fitmentScore"))) * 2; + score += (Math.abs(targetSample.getNormalizedFactor().get("directionScore") - sample.getNormalizedFactor().get("directionScore"))) * 2; + score += (Math.abs(targetSample.getNormalizedFactor().get("caseTypeScore") - sample.getNormalizedFactor().get("caseTypeScore"))) * 1; + score += (Math.abs(targetSample.getNormalizedFactor().get("avgPriceScore") - sample.getNormalizedFactor().get("avgPriceScore"))) * 70; + try { + sample.setSampleLevel(DataUtil.roundDouble(score, 5)); + } catch (Exception e) { + e.printStackTrace(); } } Collections.sort(samples); @@ -665,12 +701,12 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ } - private List sortForSample(List samples, final SampleWrapper targetSample){ + private List sortForSample(List samples, final SampleWrapper targetSample) { - if(samples.isEmpty()){ + if (samples.isEmpty()) { return samples; } - if(null == targetSample.getStrctureArea()){ + if (null == targetSample.getStrctureArea()) { return samples; } // if(samples!=null && samples.size() < max){ @@ -685,15 +721,15 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ }); List prices = new ArrayList(); - for(SampleWrapper sample : samples){ - if(!prices.contains(sample.getUnitPrice())){ + for (SampleWrapper sample : samples) { + if (!prices.contains(sample.getUnitPrice())) { prices.add(sample.getUnitPrice()); - if(prices.size()>=10){ + if (prices.size() >= 10) { break; } } } - final Integer midPrice = (int)median(prices); + final Integer midPrice = (int) median(prices); Collections.sort(samples, new Comparator() { public int compare(SampleWrapper o1, SampleWrapper o2) { Integer d1 = Math.abs(o1.getUnitPrice() - midPrice); @@ -708,49 +744,50 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ double j = 0; Collections.sort(total); int size = total.size(); - if(size % 2 == 1){ - j = total.get((size-1)/2); - }else { - j = (total.get(size/2-1) + total.get(size/2) + 0.0)/2; + if (size % 2 == 1) { + j = total.get((size - 1) / 2); + } else { + j = (total.get(size / 2 - 1) + total.get(size / 2) + 0.0) / 2; } return j; } /** * 查找小区样本 + * * @param city * @param region * @param name * @param alias - * @param estateType 用户查询物业类型 + * @param estateType 用户查询物业类型 * @param startDate * @param distEstateType 小区物业类型 * @return */ - private List findSampleByDistrict(String city, String region, String name, List alias, String masterName, String distEstateType, String estateType, Date startDate, DistrictStat districtStat){ + private List findSampleByDistrict(String city, String region, String name, List alias, String masterName, String distEstateType, String estateType, Date startDate, DistrictStat districtStat) { List names = new ArrayList(); names.add(ClientUtils.escapeQueryChars(name)); - if(alias != null){ - for(String alia : alias){ - if(StringUtils.isNotBlank(alia) && alia.length() >= 2 && !names.contains(alia)){ + if (alias != null) { + for (String alia : alias) { + if (StringUtils.isNotBlank(alia) && alia.length() >= 2 && !names.contains(alia)) { names.add(ClientUtils.escapeQueryChars(alia)); } } } - if(StringUtils.isNotBlank(masterName)){ - names.add(ClientUtils.escapeQueryChars(masterName)); + if (StringUtils.isNotBlank(masterName)) { + names.add(ClientUtils.escapeQueryChars(masterName)); } List samples = new ArrayList(); List houseQuery = new ArrayList(); - houseQuery.add(new QueryParam("city", city )); - houseQuery.add(new QueryParam("region", region )); - if(districtStat != null && districtStat.getAvgPrice() > 0){ + houseQuery.add(new QueryParam("city", city)); + houseQuery.add(new QueryParam("region", region)); + if (districtStat != null && districtStat.getAvgPrice() > 0) { int avgPrice = districtStat.getAvgPrice(); - houseQuery.add(new QueryParam("avgPrice", QueryParam.GREATER_THAN_EQUAL_OPERATOR, (int)(avgPrice * 0.5 )));//0.85 - houseQuery.add(new QueryParam("avgPrice", QueryParam.LESS_THAN_EQUAL_OPERATOR, (int)(avgPrice * 1.5 )));//1.15 + houseQuery.add(new QueryParam("avgPrice", QueryParam.GREATER_THAN_EQUAL_OPERATOR, (int) (avgPrice * 0.5)));//0.85 + houseQuery.add(new QueryParam("avgPrice", QueryParam.LESS_THAN_EQUAL_OPERATOR, (int) (avgPrice * 1.5)));//1.15 } BooleanQuery nameQuery = new BooleanQuery(); int c = 0; @@ -758,21 +795,21 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ if (StringUtils.isNotBlank(name)) { if (name.indexOf("(") > -1 || name.indexOf(")") > -1 || name.indexOf("(") > -1 || name.indexOf(")") > -1 | name.indexOf("[") > -1 || name.indexOf("]") > -1 || name.indexOf("-") > -1 || name.indexOf("{") > -1 - || name.indexOf("}") > -1 || name.indexOf("{") > -1 || name.indexOf("}") > -1 || name.indexOf(":") > -1|| name.indexOf("\\") > -1) { + || name.indexOf("}") > -1 || name.indexOf("{") > -1 || name.indexOf("}") > -1 || name.indexOf(":") > -1 || name.indexOf("\\") > -1) { continue; } c++; nameQuery.add(new TermQuery(new Term("district_name", n)), BooleanClause.Occur.SHOULD); } } - - if(nameQuery.clauses().size()==0){ - return samples; + + if (nameQuery.clauses().size() == 0) { + return samples; } BooleanQuery srQuery = new BooleanQuery(); srQuery.add(nameQuery, BooleanClause.Occur.MUST); houseQuery.add(new QueryParam("$sr", new SrQuery(srQuery))); - if(startDate != null){ + if (startDate != null) { houseQuery.add(new QueryParam("publishDate", QueryParam.GREATER_THAN_OPERATOR, startDate)); } @@ -782,89 +819,89 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ int height = 0; int maxFloor = 0; boolean allSampleHasHeight = true; - for(House house : houses){ - if(StringUtils.isNotBlank(estateType) && estateType.equals("01")){//01:普通住宅 02:别墅 - if(StringUtils.isNotBlank(house.getEstateType()) && house.getEstateType().contains("别墅")){ + for (House house : houses) { + if (StringUtils.isNotBlank(estateType) && estateType.equals("01")) {//01:普通住宅 02:别墅 + if (StringUtils.isNotBlank(house.getEstateType()) && house.getEstateType().contains("别墅")) { continue; } - if(isVilla(house.getArea(), house.getName(), house.getHeight(), house.getRoom())){ + if (isVilla(house.getArea(), house.getName(), house.getHeight(), house.getRoom())) { continue; } - }else if(StringUtils.isNotBlank(estateType) && estateType.equals("02")){ - if(house.getHeight()!=null && house.getHeight()>=10){ + } else if (StringUtils.isNotBlank(estateType) && estateType.equals("02")) { + if (house.getHeight() != null && house.getHeight() >= 10) { continue; } - if(house.getFloor()!=null && house.getFloor()>=10){ + if (house.getFloor() != null && house.getFloor() >= 10) { continue; } } SampleWrapper sample = convertHouse2Sample(house); - if(isAvailableSample(sample)){ + if (isAvailableSample(sample)) { samples.add(sample); } - if(sample.getAboveFloorAmount() == null){ + if (sample.getAboveFloorAmount() == null) { allSampleHasHeight = false; - }else if(sample.getAboveFloorAmount() > 0 && sample.getAboveFloorAmount() > height && sample.getAboveFloorAmount() < 100){ - height = sample.getAboveFloorAmount() ; + } else if (sample.getAboveFloorAmount() > 0 && sample.getAboveFloorAmount() > height && sample.getAboveFloorAmount() < 100) { + height = sample.getAboveFloorAmount(); } - if(sample.getFloorNumber() != null && sample.getFloorNumber() > maxFloor){ + if (sample.getFloorNumber() != null && sample.getFloorNumber() > maxFloor) { maxFloor = sample.getFloorNumber(); } //浙商测试特意添加 - if(house.getDistrictName().equals("新泾三村") && house.getArea()>=35 && house.getArea()<=55){ + if (house.getDistrictName().equals("新泾三村") && house.getArea() >= 35 && house.getArea() <= 55) { sample.setDoorNo("502"); sample.setBuildingNoName("56"); } - if(StringUtils.isNotBlank(house.getEstateType())){ - if(house.getEstateType().contains("商业") || house.getEstateType().contains("商住") || house.getEstateType().contains("办公")){ - sample.setBuildingName(house.getDistrictName() +"(商住)"); + if (StringUtils.isNotBlank(house.getEstateType())) { + if (house.getEstateType().contains("商业") || house.getEstateType().contains("商住") || house.getEstateType().contains("办公")) { + sample.setBuildingName(house.getDistrictName() + "(商住)"); } - }else{ - if(StringUtils.isNotBlank(distEstateType) && (distEstateType.contains("商住") && (!name.contains("商住") || !name.contains("商业")) )){ + } else { + if (StringUtils.isNotBlank(distEstateType) && (distEstateType.contains("商住") && (!name.contains("商住") || !name.contains("商业")))) { sample.setBuildingName(house.getDistrictName() + "(商住)"); } } } List dealPriceQuery = new ArrayList(); - dealPriceQuery.add(new QueryParam("city", city )); - dealPriceQuery.add(new QueryParam("region", region )); + dealPriceQuery.add(new QueryParam("city", city)); + dealPriceQuery.add(new QueryParam("region", region)); dealPriceQuery.add(new QueryParam("districtName", QueryParam.IN_OPERATOR, names)); - if(startDate != null){ - dealPriceQuery.add(new QueryParam("tradeDate", QueryParam.GREATER_THAN_OPERATOR, startDate )); - }else{ - dealPriceQuery.add(new QueryParam("tradeDate", QueryParam.GREATER_THAN_OPERATOR, DateUtil.add(new Date(), Calendar.MONTH, -3) )); + if (startDate != null) { + dealPriceQuery.add(new QueryParam("tradeDate", QueryParam.GREATER_THAN_OPERATOR, startDate)); + } else { + dealPriceQuery.add(new QueryParam("tradeDate", QueryParam.GREATER_THAN_OPERATOR, DateUtil.add(new Date(), Calendar.MONTH, -3))); } - List dealPriceSortParams = new ArrayList(); + List dealPriceSortParams = new ArrayList(); dealPriceSortParams.add(new SortParam("tradeDate", false)); List dealPrices = dealPriceDao.findAllByParams(dealPriceQuery, dealPriceSortParams, 0, 100, DEAL_PRICE_FIELDS); - for(DealPrice dealPrice : dealPrices){ + for (DealPrice dealPrice : dealPrices) { SampleWrapper sample = convertDealPrice2Sample(dealPrice); - if(isAvailableSample(sample)){ + if (isAvailableSample(sample)) { samples.add(sample); } - if(sample.getAboveFloorAmount() == null){ + if (sample.getAboveFloorAmount() == null) { allSampleHasHeight = false; - }else if(sample.getAboveFloorAmount() > 0 && sample.getAboveFloorAmount() > height && sample.getAboveFloorAmount() < 100){ - height = sample.getAboveFloorAmount() ; + } else if (sample.getAboveFloorAmount() > 0 && sample.getAboveFloorAmount() > height && sample.getAboveFloorAmount() < 100) { + height = sample.getAboveFloorAmount(); } - if(sample.getFloorNumber() != null && sample.getFloorNumber() > maxFloor){ + if (sample.getFloorNumber() != null && sample.getFloorNumber() > maxFloor) { maxFloor = sample.getFloorNumber(); } } - if(!allSampleHasHeight){ - if(height == 0){//如果没有楼高到楼栋库里寻找最高的楼高 + if (!allSampleHasHeight) { + if (height == 0) {//如果没有楼高到楼栋库里寻找最高的楼高 height = findHeight(city, region, name); } - if(height == 0){//如果楼栋库没有使用房源中的最大楼层 + if (height == 0) {//如果楼栋库没有使用房源中的最大楼层 height = maxFloor; } - if(height == 0){//没有楼高信息使用默认的楼高 - if(estateType == "01"){//住宅默认6楼 + if (height == 0) {//没有楼高信息使用默认的楼高 + if (estateType == "01") {//住宅默认6楼 height = 6; - }else{//别墅默认三村 + } else {//别墅默认三村 height = 3; } } @@ -872,18 +909,18 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertFangjiaToOfficial(city, region); - for(SampleWrapper sample : samples){ - if(sample.getAboveFloorAmount() == null){ + for (SampleWrapper sample : samples) { + if (sample.getAboveFloorAmount() == null) { sample.setAboveFloorAmount(height); } - if(sample.getFloorNumber() == null){ - if("01".equals(estateType)){ - sample.setFloorNumber((sample.getAboveFloorAmount()/2)); - }else{ + if (sample.getFloorNumber() == null) { + if ("01".equals(estateType)) { + sample.setFloorNumber((sample.getAboveFloorAmount() / 2)); + } else { sample.setFloorNumber(1); } } - if(fangjiaOfficialAreaMap != null){ + if (fangjiaOfficialAreaMap != null) { sample.setProvince(fangjiaOfficialAreaMap.getProvinceCode()); sample.setCity(fangjiaOfficialAreaMap.getCityCode()); sample.setDistrict(fangjiaOfficialAreaMap.getDistrictCode()); @@ -896,27 +933,28 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ /** * 江南行查找小区样本(优先使用贝壳链家) + * * @param city * @param region * @param name * @param alias - * @param estateType 用户查询物业类型 + * @param estateType 用户查询物业类型 * @param startDate * @param distEstateType 小区物业类型 * @return */ - private List findJnbankSampleByDistrict(String city, String region, String name, List alias, String masterName, String distEstateType, String estateType, Date startDate, DistrictStat districtStat){ + private List findJnbankSampleByDistrict(String city, String region, String name, List alias, String masterName, String distEstateType, String estateType, Date startDate, DistrictStat districtStat) { List names = new ArrayList(); names.add(ClientUtils.escapeQueryChars(name)); - if(alias != null){ - for(String alia : alias){ - if(StringUtils.isNotBlank(alia) && alia.length() >= 2 && !names.contains(alia)){ + if (alias != null) { + for (String alia : alias) { + if (StringUtils.isNotBlank(alia) && alia.length() >= 2 && !names.contains(alia)) { names.add(ClientUtils.escapeQueryChars(alia)); } } } - if(StringUtils.isNotBlank(masterName)){ + if (StringUtils.isNotBlank(masterName)) { names.add(ClientUtils.escapeQueryChars(masterName)); } @@ -924,12 +962,12 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ List nolianjiaSamples = new ArrayList(); List houseQuery = new ArrayList(); - houseQuery.add(new QueryParam("city", city )); - houseQuery.add(new QueryParam("region", region )); - if(districtStat != null && districtStat.getAvgPrice() > 0){ + houseQuery.add(new QueryParam("city", city)); + houseQuery.add(new QueryParam("region", region)); + if (districtStat != null && districtStat.getAvgPrice() > 0) { int avgPrice = districtStat.getAvgPrice(); - houseQuery.add(new QueryParam("avgPrice", QueryParam.GREATER_THAN_EQUAL_OPERATOR, (int)(avgPrice * 0.5 )));//0.85 - houseQuery.add(new QueryParam("avgPrice", QueryParam.LESS_THAN_EQUAL_OPERATOR, (int)(avgPrice * 1.5 )));//1.15 + houseQuery.add(new QueryParam("avgPrice", QueryParam.GREATER_THAN_EQUAL_OPERATOR, (int) (avgPrice * 0.5)));//0.85 + houseQuery.add(new QueryParam("avgPrice", QueryParam.LESS_THAN_EQUAL_OPERATOR, (int) (avgPrice * 1.5)));//1.15 } BooleanQuery nameQuery = new BooleanQuery(); int c = 0; @@ -937,7 +975,7 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ if (StringUtils.isNotBlank(name)) { if (name.indexOf("(") > -1 || name.indexOf(")") > -1 || name.indexOf("(") > -1 || name.indexOf(")") > -1 | name.indexOf("[") > -1 || name.indexOf("]") > -1 || name.indexOf("-") > -1 || name.indexOf("{") > -1 - || name.indexOf("}") > -1 || name.indexOf("{") > -1 || name.indexOf("}") > -1 || name.indexOf(":") > -1|| name.indexOf("\\") > -1) { + || name.indexOf("}") > -1 || name.indexOf("{") > -1 || name.indexOf("}") > -1 || name.indexOf(":") > -1 || name.indexOf("\\") > -1) { continue; } c++; @@ -945,13 +983,13 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ } } - if(nameQuery.clauses().size()==0){ + if (nameQuery.clauses().size() == 0) { return samples; } BooleanQuery srQuery = new BooleanQuery(); srQuery.add(nameQuery, BooleanClause.Occur.MUST); houseQuery.add(new QueryParam("$sr", new SrQuery(srQuery))); - if(startDate != null){ + if (startDate != null) { houseQuery.add(new QueryParam("publishDate", QueryParam.GREATER_THAN_OPERATOR, startDate)); } @@ -961,93 +999,93 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ int height = 0; int maxFloor = 0; boolean allSampleHasHeight = true; - for(House house : houses){ - if(StringUtils.isNotBlank(estateType) && estateType.equals("01")){//01:普通住宅 02:别墅 - if(StringUtils.isNotBlank(house.getEstateType()) && house.getEstateType().contains("别墅")){ + for (House house : houses) { + if (StringUtils.isNotBlank(estateType) && estateType.equals("01")) {//01:普通住宅 02:别墅 + if (StringUtils.isNotBlank(house.getEstateType()) && house.getEstateType().contains("别墅")) { continue; } - if(isVilla(house.getArea(), house.getName(), house.getHeight(), house.getRoom())){ + if (isVilla(house.getArea(), house.getName(), house.getHeight(), house.getRoom())) { continue; } - }else if(StringUtils.isNotBlank(estateType) && estateType.equals("02")){ - if(house.getHeight()!=null && house.getHeight()>=10){ + } else if (StringUtils.isNotBlank(estateType) && estateType.equals("02")) { + if (house.getHeight() != null && house.getHeight() >= 10) { continue; } - if(house.getFloor()!=null && house.getFloor()>=10){ + if (house.getFloor() != null && house.getFloor() >= 10) { continue; } } SampleWrapper sample = convertHouse2Sample(house); - if(isAvailableSample(sample)){ - if(house.getUrl().contains("lianjia.com") || house.getUrl().contains("ke.com")){ + if (isAvailableSample(sample)) { + if (house.getUrl().contains("lianjia.com") || house.getUrl().contains("ke.com")) { samples.add(sample); - }else{ + } else { nolianjiaSamples.add(sample); } } - if(sample.getAboveFloorAmount() == null){ + if (sample.getAboveFloorAmount() == null) { allSampleHasHeight = false; - }else if(sample.getAboveFloorAmount() > 0 && sample.getAboveFloorAmount() > height && sample.getAboveFloorAmount() < 100){ - height = sample.getAboveFloorAmount() ; + } else if (sample.getAboveFloorAmount() > 0 && sample.getAboveFloorAmount() > height && sample.getAboveFloorAmount() < 100) { + height = sample.getAboveFloorAmount(); } - if(sample.getFloorNumber() != null && sample.getFloorNumber() > maxFloor){ + if (sample.getFloorNumber() != null && sample.getFloorNumber() > maxFloor) { maxFloor = sample.getFloorNumber(); } //浙商测试特意添加 - if(house.getDistrictName().equals("新泾三村") && house.getArea()>=35 && house.getArea()<=55){ + if (house.getDistrictName().equals("新泾三村") && house.getArea() >= 35 && house.getArea() <= 55) { sample.setDoorNo("502"); sample.setBuildingNoName("56"); } - if(StringUtils.isNotBlank(house.getEstateType())){ - if(house.getEstateType().contains("商业") || house.getEstateType().contains("商住") || house.getEstateType().contains("办公")){ - sample.setBuildingName(house.getDistrictName() +"(商住)"); + if (StringUtils.isNotBlank(house.getEstateType())) { + if (house.getEstateType().contains("商业") || house.getEstateType().contains("商住") || house.getEstateType().contains("办公")) { + sample.setBuildingName(house.getDistrictName() + "(商住)"); } - }else{ - if(StringUtils.isNotBlank(distEstateType) && (distEstateType.contains("商住") && (!name.contains("商住") || !name.contains("商业")) )){ + } else { + if (StringUtils.isNotBlank(distEstateType) && (distEstateType.contains("商住") && (!name.contains("商住") || !name.contains("商业")))) { sample.setBuildingName(house.getDistrictName() + "(商住)"); } } } List dealPriceQuery = new ArrayList(); - dealPriceQuery.add(new QueryParam("city", city )); - dealPriceQuery.add(new QueryParam("region", region )); + dealPriceQuery.add(new QueryParam("city", city)); + dealPriceQuery.add(new QueryParam("region", region)); dealPriceQuery.add(new QueryParam("districtName", QueryParam.IN_OPERATOR, names)); - if(startDate != null){ - dealPriceQuery.add(new QueryParam("tradeDate", QueryParam.GREATER_THAN_OPERATOR, startDate )); - }else{ - dealPriceQuery.add(new QueryParam("tradeDate", QueryParam.GREATER_THAN_OPERATOR, DateUtil.add(new Date(), Calendar.MONTH, -3) )); + if (startDate != null) { + dealPriceQuery.add(new QueryParam("tradeDate", QueryParam.GREATER_THAN_OPERATOR, startDate)); + } else { + dealPriceQuery.add(new QueryParam("tradeDate", QueryParam.GREATER_THAN_OPERATOR, DateUtil.add(new Date(), Calendar.MONTH, -3))); } - List dealPriceSortParams = new ArrayList(); + List dealPriceSortParams = new ArrayList(); dealPriceSortParams.add(new SortParam("tradeDate", false)); List dealPrices = dealPriceDao.findAllByParams(dealPriceQuery, dealPriceSortParams, 0, 100, DEAL_PRICE_FIELDS); - for(DealPrice dealPrice : dealPrices){ + for (DealPrice dealPrice : dealPrices) { SampleWrapper sample = convertDealPrice2Sample(dealPrice); - if(isAvailableSample(sample)){ + if (isAvailableSample(sample)) { samples.add(sample); } - if(sample.getAboveFloorAmount() == null){ + if (sample.getAboveFloorAmount() == null) { allSampleHasHeight = false; - }else if(sample.getAboveFloorAmount() > 0 && sample.getAboveFloorAmount() > height && sample.getAboveFloorAmount() < 100){ - height = sample.getAboveFloorAmount() ; + } else if (sample.getAboveFloorAmount() > 0 && sample.getAboveFloorAmount() > height && sample.getAboveFloorAmount() < 100) { + height = sample.getAboveFloorAmount(); } - if(sample.getFloorNumber() != null && sample.getFloorNumber() > maxFloor){ + if (sample.getFloorNumber() != null && sample.getFloorNumber() > maxFloor) { maxFloor = sample.getFloorNumber(); } } - if(!allSampleHasHeight){ - if(height == 0){//如果没有楼高到楼栋库里寻找最高的楼高 + if (!allSampleHasHeight) { + if (height == 0) {//如果没有楼高到楼栋库里寻找最高的楼高 height = findHeight(city, region, name); } - if(height == 0){//如果楼栋库没有使用房源中的最大楼层 + if (height == 0) {//如果楼栋库没有使用房源中的最大楼层 height = maxFloor; } - if(height == 0){//没有楼高信息使用默认的楼高 - if(estateType == "01"){//住宅默认6楼 + if (height == 0) {//没有楼高信息使用默认的楼高 + if (estateType == "01") {//住宅默认6楼 height = 6; - }else{//别墅默认三村 + } else {//别墅默认三村 height = 3; } } @@ -1055,22 +1093,22 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertFangjiaToOfficial(city, region); - if(samples.size()<10){ + if (samples.size() < 10) { samples.addAll(nolianjiaSamples); } - for(SampleWrapper sample : samples){ - if(sample.getAboveFloorAmount() == null){ + for (SampleWrapper sample : samples) { + if (sample.getAboveFloorAmount() == null) { sample.setAboveFloorAmount(height); } - if(sample.getFloorNumber() == null){ - if("01".equals(estateType)){ - sample.setFloorNumber((sample.getAboveFloorAmount()/2)); - }else{ + if (sample.getFloorNumber() == null) { + if ("01".equals(estateType)) { + sample.setFloorNumber((sample.getAboveFloorAmount() / 2)); + } else { sample.setFloorNumber(1); } } - if(fangjiaOfficialAreaMap != null){ + if (fangjiaOfficialAreaMap != null) { sample.setProvince(fangjiaOfficialAreaMap.getProvinceCode()); sample.setCity(fangjiaOfficialAreaMap.getCityCode()); sample.setDistrict(fangjiaOfficialAreaMap.getDistrictCode()); @@ -1082,120 +1120,104 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ } - - private List findBeijiaoShouSampleByDistrict(String city, String region, String name, List alias, String masterName, String distEstateType, String estateType, Date startDate, DistrictStat districtStat, Double area, Integer maxResultCount){ - - List names = new ArrayList(); - names.add(ClientUtils.escapeQueryChars(name)); - if(alias != null){ - for(String alia : alias){ - if(StringUtils.isNotBlank(alia) && alia.length() >= 2 && !names.contains(alia)){ - names.add(ClientUtils.escapeQueryChars(alia)); - } - } - } - if(StringUtils.isNotBlank(masterName)){ - names.add(ClientUtils.escapeQueryChars(masterName)); - } - + private List findBeijiaoShouSampleByDistrict(List districtNameKeys, String distEstateType, String estateType, Date startDate, DistrictStat districtStat, Double area, Integer maxResultCount) { List samples = new ArrayList(); List nolianjiaSamples = new ArrayList(); List houseQuery = new ArrayList(); - houseQuery.add(new QueryParam("city", city )); - houseQuery.add(new QueryParam("region", region )); - Integer minPrice = null; Integer maxPrice = null; - if(districtStat != null && districtStat.getAvgPrice() > 0){ + if (districtStat != null && districtStat.getAvgPrice() > 0) { int avgPrice = districtStat.getAvgPrice(); - minPrice = (int)(avgPrice * 0.8 ); - maxPrice = (int)(avgPrice * 1.2 ); + minPrice = (int) (avgPrice * 0.8); + maxPrice = (int) (avgPrice * 1.2); houseQuery.add(new QueryParam("avgPrice", QueryParam.GREATER_THAN_EQUAL_OPERATOR, minPrice));//0.85 houseQuery.add(new QueryParam("avgPrice", QueryParam.LESS_THAN_EQUAL_OPERATOR, maxPrice));//1.15 } - if(area != null && area > 0){ - double stepArea = DataUtil.getDoubleRound(2,area*0.2); - if(stepArea<15){ + if (area != null && area > 0) { + double stepArea = DataUtil.getDoubleRound(2, area * 0.2); + if (stepArea < 15) { stepArea = 15; } - houseQuery.add(new QueryParam("area", QueryParam.GREATER_THAN_EQUAL_OPERATOR, area - stepArea)); - houseQuery.add(new QueryParam("area", QueryParam.LESS_THAN_EQUAL_OPERATOR, area + stepArea)); + double paramValue = DataUtil.getDoubleRound(2, area - stepArea); + houseQuery.add(new QueryParam("area", QueryParam.GREATER_THAN_EQUAL_OPERATOR, paramValue)); + double paramValue1 = DataUtil.getDoubleRound(2, area + stepArea); + houseQuery.add(new QueryParam("area", QueryParam.LESS_THAN_EQUAL_OPERATOR, paramValue1)); } BooleanQuery nameQuery = new BooleanQuery(); int c = 0; - for (String n : names) { + for (String name : districtNameKeys) { if (StringUtils.isNotBlank(name)) { - if (name.indexOf("(") > -1 || name.indexOf(")") > -1 || name.indexOf("(") > -1 || name.indexOf(")") > -1 - | name.indexOf("[") > -1 || name.indexOf("]") > -1 || name.indexOf("-") > -1 || name.indexOf("{") > -1 - || name.indexOf("}") > -1 || name.indexOf("{") > -1 || name.indexOf("}") > -1 || name.indexOf(":") > -1|| name.indexOf("\\") > -1) { - continue; - } + name = ClientUtils.escapeQueryChars(name); c++; - nameQuery.add(new TermQuery(new Term("district_name", n)), BooleanClause.Occur.SHOULD); + nameQuery.add(new TermQuery(new Term("districtname_key", name)), BooleanClause.Occur.SHOULD); } } - - if(nameQuery.clauses().size()==0){ + if (nameQuery.clauses().size() == 0) { return samples; } BooleanQuery srQuery = new BooleanQuery(); srQuery.add(nameQuery, BooleanClause.Occur.MUST); + houseQuery.add(new QueryParam("$sr", new SrQuery(srQuery))); - if(startDate != null){ + if (startDate != null) { houseQuery.add(new QueryParam("publishDate", QueryParam.GREATER_THAN_OPERATOR, startDate)); } + //限制返回文档数 + // 在此处设置返回结果的数量限制 +// houseQuery.add(new QueryParam("$limit", 5)); + List houseSortParams = new ArrayList(); houseSortParams.add(new SortParam("publishDate", false)); List houses = houseDao.findAllByParams(houseQuery, houseSortParams, 0, maxResultCount, HOUSE_FIELDS); int height = 0; int maxFloor = 0; boolean allSampleHasHeight = true; - for(House house : houses){ - if(StringUtils.isNotBlank(estateType) && estateType.equals("01")){//01:普通住宅 02:别墅 - if(StringUtils.isNotBlank(house.getEstateType()) && house.getEstateType().contains("别墅")){ + for (House house : houses) { + if (StringUtils.isNotBlank(estateType) && estateType.equals("01")) {//01:普通住宅 02:别墅 + if (StringUtils.isNotBlank(house.getEstateType()) && house.getEstateType().contains("别墅")) { continue; } - if(isVilla(house.getArea(), house.getName(), house.getHeight(), house.getRoom())){ + if (isVilla(house.getArea(), house.getName(), house.getHeight(), house.getRoom())) { continue; } - }else if(StringUtils.isNotBlank(estateType) && estateType.equals("02")){ - if(house.getHeight()!=null && house.getHeight()>=10){ + } else if (StringUtils.isNotBlank(estateType) && estateType.equals("02")) { + if (house.getHeight() != null && house.getHeight() >= 10) { continue; } - if(house.getFloor()!=null && house.getFloor()>=10){ + if (house.getFloor() != null && house.getFloor() >= 10) { continue; } } - Integer avgPrice = (int)(house.getTotalPrice()/house.getArea()); - if(minPrice !=null && (avgPricemaxPrice)){ + Integer avgPrice = (int) (house.getTotalPrice() / house.getArea()); + if (minPrice != null && (avgPrice < minPrice || avgPrice > maxPrice)) { continue; } house.setAvgPrice(avgPrice); SampleWrapper sample = convertHouse2Sample(house); - if(isAvailableSample(sample)){ - if(house.getUrl().contains("lianjia.com") || house.getUrl().contains("ke.com")){ + if (isAvailableSample(sample)) { + if (house.getUrl().contains("lianjia.com") || house.getUrl().contains("ke.com")) { samples.add(sample); - }else{ + } else { nolianjiaSamples.add(sample); } } //浙商测试特意添加 - if(house.getDistrictName().equals("新泾三村") && house.getArea()>=35 && house.getArea()<=55){ + if (house.getDistrictName().equals("新泾三村") && house.getArea() >= 35 && house.getArea() <= 55) { sample.setDoorNo("502"); sample.setBuildingNoName("56"); } - if(StringUtils.isNotBlank(house.getEstateType())){ - if(house.getEstateType().contains("商业") || house.getEstateType().contains("商住") || house.getEstateType().contains("办公")){ - sample.setBuildingName(house.getDistrictName() +"(商住)"); + if (StringUtils.isNotBlank(house.getEstateType())) { + if (house.getEstateType().contains("商业") || house.getEstateType().contains("商住") || house.getEstateType().contains("办公")) { + sample.setBuildingName(house.getDistrictName() + "(商住)"); } - }else{ - if(StringUtils.isNotBlank(distEstateType) && (distEstateType.contains("商住") && (!name.contains("商住") || !name.contains("商业")) )){ + } else { + if (StringUtils.isNotBlank(distEstateType) && (distEstateType.contains("商住") && (!house.getDistrictName().contains("商住") || !house.getDistrictName().contains("商业")))) { sample.setBuildingName(house.getDistrictName() + "(商住)"); } } @@ -1204,21 +1226,21 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ // FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertFangjiaToOfficial(city, region); - if(samples.size()<10){ + if (samples.size() < 10) { samples.addAll(nolianjiaSamples); } - for(SampleWrapper sample : samples){ + for (SampleWrapper sample : samples) { // if(sample.getAboveFloorAmount() == null){ // sample.setAboveFloorAmount(height); // } - if(sample.getFloorNumber() == null){ - if("01".equals(estateType)){ + if (sample.getFloorNumber() == null) { + if ("01".equals(estateType)) { // System.out.println(sample.getAboveFloorAmount()); - if(sample.getAboveFloorAmount()!=null){ - sample.setFloorNumber((sample.getAboveFloorAmount()/2)); + if (sample.getAboveFloorAmount() != null) { + sample.setFloorNumber((sample.getAboveFloorAmount() / 2)); } - }else{ + } else { sample.setFloorNumber(1); } } @@ -1234,12 +1256,13 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ /** * 根据小区名在楼栋库中查询最大的楼高 + * * @param city * @param region * @param name * @return */ - private int findHeight(String city, String region, String name){ + private int findHeight(String city, String region, String name) { List query = new ArrayList(); query.add(new QueryParam("city", city)); @@ -1249,7 +1272,7 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ List sortParams = new ArrayList(); sortParams.add(new SortParam("floors", false)); Loudong loudong = loudongDao.findFirstByParams(query, sortParams); - if(loudong == null){ + if (loudong == null) { return 0; } return loudong.getFloors(); @@ -1260,7 +1283,7 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ * @param dealPrice * @return */ - private SampleWrapper convertDealPrice2Sample(DealPrice dealPrice){ + private SampleWrapper convertDealPrice2Sample(DealPrice dealPrice) { SampleWrapper sample = new SampleWrapper(); sample.setSampleId(dealPrice.getId()); @@ -1278,14 +1301,14 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ sample.setDetailAddress(dealPrice.getAddress()); sample.setDoorNo(dealPrice.getRoomNumber()); sample.setBuildingNoName(dealPrice.getHouseNumber()); - if(sample.getUnitPrice() == null && dealPrice.getTotalPrice() != null && dealPrice.getArea() != null && dealPrice.getArea() != 0){ - sample.setUnitPrice((int)(dealPrice.getTotalPrice() / dealPrice.getArea())); + if (sample.getUnitPrice() == null && dealPrice.getTotalPrice() != null && dealPrice.getArea() != null && dealPrice.getArea() != 0) { + sample.setUnitPrice((int) (dealPrice.getTotalPrice() / dealPrice.getArea())); } return sample; } - private SampleWrapper convertQueryBean2Sample(CollateralSampleQueryBean queryBean){ + private SampleWrapper convertQueryBean2Sample(CollateralSampleQueryBean queryBean) { SampleWrapper sample = new SampleWrapper(); sample.setCity(queryBean.getFangjiaCity()); sample.setDistrict(queryBean.getFangjiaDistrict()); @@ -1296,13 +1319,13 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ sample.setTowardDirectCode(queryBean.getTowardDirectCode()); sample.setSampleDate(new Date()); Integer avgPrice = districtStatService.findLatestDistrictAvgPrice(sample.getCity(), sample.getDistrict(), null, sample.getBuildingName()); - if(avgPrice != 0){ + if (avgPrice != 0) { sample.setUnitPrice(avgPrice); } return sample; } - private SampleWrapper convertQueryBean2Sample(ShopCollateralSampleQueryBean queryBean){ + private SampleWrapper convertQueryBean2Sample(ShopCollateralSampleQueryBean queryBean) { SampleWrapper sample = new SampleWrapper(); sample.setCity(queryBean.getFangjiaCity()); sample.setDistrict(queryBean.getFangjiaDistrict()); @@ -1315,10 +1338,11 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ /** * 把挂牌房源转换成样本数据 + * * @param house * @return */ - private SampleWrapper convertHouse2Sample(House house){ + private SampleWrapper convertHouse2Sample(House house) { SampleWrapper sample = new SampleWrapper(); sample.setSampleId(house.getId()); sample.setCity(house.getCity()); @@ -1333,19 +1357,20 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ sample.setTowardDirectCode(HouseValidator.formatDirectionToCode(house.getDirection())); sample.setSampleDate(house.getPublishDate()); sample.setDetailAddress(house.getAddress()); - if(sample.getUnitPrice() == null && house.getTotalPrice() != null && house.getArea() != null){ - sample.setUnitPrice((int)(house.getTotalPrice()/house.getArea())); + if (sample.getUnitPrice() == null && house.getTotalPrice() != null && house.getArea() != null) { + sample.setUnitPrice((int) (house.getTotalPrice() / house.getArea())); } return sample; } /** * 判断样本是否可用 + * * @param sample * @return */ - private boolean isAvailableSample(SampleWrapper sample){ - if(sample.getStrctureArea() > 500 || sample.getStrctureArea() < 10){ + private boolean isAvailableSample(SampleWrapper sample) { + if (sample.getStrctureArea() > 500 || sample.getStrctureArea() < 10) { return false; } @@ -1363,14 +1388,14 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ return null; } - private Integer getBuildYear(String finishDate, String liveDate, String buildDate ,Date openDate) { + private Integer getBuildYear(String finishDate, String liveDate, String buildDate, Date openDate) { Integer finishYear = getYearFormDate(finishDate); Integer liveYear = getYearFormDate(liveDate); Integer buildYear = getYearFormDate(buildDate); Integer openYear = null; - if(openDate != null){ - openYear = Integer.valueOf(DateUtil.formatByPattern(openDate,"yyyy")); + if (openDate != null) { + openYear = Integer.valueOf(DateUtil.formatByPattern(openDate, "yyyy")); } int minYear = Integer.MAX_VALUE; if (finishYear != null && finishYear < minYear) { @@ -1382,42 +1407,42 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ if (buildYear != null && buildYear < minYear) { minYear = buildYear; } - if(openYear != null && openYear < minYear){ + if (openYear != null && openYear < minYear) { minYear = openYear; } - if(minYear == Integer.MAX_VALUE){ + if (minYear == Integer.MAX_VALUE) { return null; } return minYear; } - public String getOpenDate(District district){ - if(district.getOpenDate()!=null){ + public String getOpenDate(District district) { + if (district.getOpenDate() != null) { return DateUtil.formatToYYYYMMDD(district.getOpenDate()); } - if(StringUtils.isNotBlank(district.getLiveDate())){ + if (StringUtils.isNotBlank(district.getLiveDate())) { return DateUtil.formatToYYYYMMDD(DateUtil.parseStringToDate(district.getLiveDate())); } - if(StringUtils.isNotBlank(district.getFinishBuildingDate())){ + if (StringUtils.isNotBlank(district.getFinishBuildingDate())) { return DateUtil.formatToYYYYMMDD(DateUtil.parseStringToDate(district.getFinishBuildingDate())); } return null; } - private Integer getHouseUseYear(Integer minYear, String s){ + private Integer getHouseUseYear(Integer minYear, String s) { - if(StringUtils.isBlank(s)){ + if (StringUtils.isBlank(s)) { return null; } - if(minYear != null && minYear > 0){ + if (minYear != null && minYear > 0) { int curYear = new Date().getYear() + 1900; int shengYuYear = curYear - minYear; - if( shengYuYear > 0 && shengYuYear <= 70){ - Integer year = extractYear(s); - if(year !=null && year > 0 && year <= 70){ + if (shengYuYear > 0 && shengYuYear <= 70) { + Integer year = extractYear(s); + if (year != null && year > 0 && year <= 70) { int useYear = year - shengYuYear; - if(year > 0 && year <= 70){ + if (year > 0 && year <= 70) { return useYear; } @@ -1427,19 +1452,19 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ return null; } - private Integer extractYear(String s){ + private Integer extractYear(String s) { Pattern p = Pattern.compile("(\\d+)"); Matcher m = p.matcher(s); - if(m.find()){ + if (m.find()) { return Integer.parseInt(m.group(1)); } return null; } - private Integer getYearFormDate(String dateStr){ - if(dateStr != null && StringUtils.isNotBlank(dateStr)){ + private Integer getYearFormDate(String dateStr) { + if (dateStr != null && StringUtils.isNotBlank(dateStr)) { Date date = DateUtil.parseStringToDate(dateStr); - if(date != null){ + if (date != null) { int year = date.getYear() + 1900; return year; } @@ -1449,6 +1474,7 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ /** * 是否是别墅 + * * @return */ public boolean isVilla(Double area, String name, Integer height, Integer room) { @@ -1503,7 +1529,8 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ public void setDistrictSellStatService(DistrictSellStatService districtSellStatService) { this.districtSellStatService = districtSellStatService; } - class MaxMinModel{ + + class MaxMinModel { Double min = Double.MAX_VALUE; Double max = 0d; diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/DistrictService.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/DistrictService.java index 5c48fa0b4..d1f56da79 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/DistrictService.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/DistrictService.java @@ -522,6 +522,7 @@ public interface DistrictService extends ModeService { public District findOneByKey(DistrictKey districtKey, String cat); List findNearestDistrict(District district, int radiusMeters, int limit); + List doFindNearestHasHouseDistrict(District district, int radiusMeters, int limit) ; List findNearestDistrict(District district, int radiusMeters, String[] fields, int limit); diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/DistrictServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/DistrictServiceImpl.java index 4f9dc8686..c5f8d917c 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/DistrictServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/DistrictServiceImpl.java @@ -2297,6 +2297,22 @@ public class DistrictServiceImpl implements DistrictService { return list; } + @SuppressWarnings("unchecked") + public List findNearestHasHouseDistrict(District district, int radiusMeters, int limit) { + String cacheKey = district.getCity() + "#" + district.getRegion() + "#" + district.getName() + "#" + radiusMeters + "#_if_sell_1" + limit; + Object obj = CacheUtils.getValue(this.getClass(), cacheKey); + if (obj != null) { + return (List) obj; + } + ArrayList list = new ArrayList(); + List nlist = doFindNearestHasHouseDistrict(district, radiusMeters, limit); + if (nlist.size() > 0) { + list = (ArrayList) nlist; + } + CacheUtils.putValue(CachePolicyEnum.LONG, this.getClass(), cacheKey, list); + return list; + } + public List findNearestDistrict(District district, int radiusMeters, String[] fields, int limit) { String cacheKey = district.getCity() + "#" + district.getRegion() + "#" + district.getName() + "#" + radiusMeters + "#" + limit; @@ -2437,6 +2453,48 @@ public class DistrictServiceImpl implements DistrictService { return new ArrayList(ret); } + public List doFindNearestHasHouseDistrict(District district, int radiusMeters, int limit) { + if (district == null || district.getLat() == null || district.getLng() == null || district.getLat() <= 0 + || district.getLng() <= 0) { + return Collections.EMPTY_LIST; + } + + List params = new ArrayList(); + params.add(new QueryParam("category", "district")); + params.add(new QueryParam("city", district.getCity())); + params.add(new QueryParam("visible", 0)); + params.add(new QueryParam("ifSell", 1)); + SdQuery sdQuery = new SdQuery(); + sdQuery.setPoint((double) district.getLat() / 10000000000.0 + "," + (double) district.getLng() / 10000000000.0); + sdQuery.setField("lat_lng"); + sdQuery.setDistance(String.valueOf((double) radiusMeters / 1000.0)); + params.add(new QueryParam(QueryParam.SD_PARAM_NAME, sdQuery)); + List list = districtDao.findAllByParams(params, null, 0, limit * 2, + new String[] { "city", "region", "name", "estateType2", "id" }); + if (list.isEmpty()) { + return list; + } + + List ret = new ArrayList(); + for (District d : list) { + if (district.getName().equals(d.getName()) && district.getRegion().equals(d.getRegion()) + && district.getCity().equals(d.getCity())) { + continue; + } + if (d.getEstateType2() != null) { + if (d.getEstateType2().indexOf(district.getEstateType2()) > -1) { + ret.add(d); + } + } + } + + if (ret.size() > limit) { + ret = ret.subList(0, limit); + } + + return new ArrayList(ret); + } + public List doFindNearestDistrict(District district, int radiusMeters, String[] fields, int limit) { if (district == null || district.getLat() == null || district.getLng() == null || district.getLat() <= 0