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 index 07fbed914..c7e315645 100644 --- 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 @@ -1,1608 +1,59 @@ -/* package com.fangjia.open.controllers; -import com.fangjia.core.util.*; -import com.fangjia.dal.common.DistrictKey; +import com.fangjia.open.model.BasicModel; +import org.apache.commons.lang.StringUtils; +import org.sothis.web.mvc.ActionContext; +import org.sothis.web.mvc.annotation.Param; + +import com.fangjia.dal.common.ServerAreaData; 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.dal.mongo.mobile.model.SearchKeyword; 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 com.fangjia.open.dto.SearchKeywordResultDto; +import com.fangjia.open.interceptors.Authority; +import com.fangjia.open.interceptors.Role; +import com.fangjia.open.model.RestfulModelAndView; +import com.fangjia.service.api.AutoCompleteService; +import com.fangjia.service.api.CategoryEnum; +import com.fangjia.service.datastore.DistrictService; +import com.fangjia.service.datastore.HouseService; +import com.fangjia.service.datastore.RentHouseService; +import com.fangjia.service.datastore.bean.DistrictQueryBean; +import com.fangjia.service.datastore.bean.HouseQueryBean; +import com.fangjia.service.datastore.bean.RentHouseQueryBean; +import com.fangjia.service.mongo.mobile.SearchKeywordService; 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 - *//* - - - + * 站内搜索controller + * + * @author liupei + */ 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(); + public Object testIpAction(@Param(name = "city") String city, @Param(name = "keyword") String keyword) { RestfulModelAndView mav = new RestfulModelAndView(); + ActionContext context = ActionContext.getContext(); + HttpServletRequest request = context.getRequest(); - 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(); + String ip = getVisitorIp(request); + mav.setModel(BasicModel.buildOKModel().setResult(ip)); 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; + private String getVisitorIp(HttpServletRequest request) { + String ip = request.getHeader("X-Forwarded-For"); + if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); } - - @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; - } + if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); } - } - - 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; + if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); } - - @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; + return ip.split(",")[0]; // 处理多个 IP 的情况 } } - -*/ diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/exceptionhander/FangjiaOpenExceptionHandler.java b/projects/fangjia-open/src/main/java/com/fangjia/open/exceptionhander/FangjiaOpenExceptionHandler.java index e07724665..0cb790a78 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/exceptionhander/FangjiaOpenExceptionHandler.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/exceptionhander/FangjiaOpenExceptionHandler.java @@ -5,6 +5,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; import com.fangjia.core.util.DingDingMessageUtil; import org.slf4j.Logger; @@ -19,23 +20,29 @@ public class FangjiaOpenExceptionHandler implements ExceptionHandler { if (LOGGER.isErrorEnabled()) { LOGGER.error("", e); } - String ip = getServerIp(); + ActionContext context = ActionContext.getContext(); + HttpServletRequest request = context.getRequest(); + + String ip = getVisitorIp(request); String token = "2307d2fec8314b3e8b4b83dd1d42da2e2051638e3e668f21e77ca01258bf682c"; DingDingMessageUtil.sendTextMessage(token, "[OpenApi] "+ip+"服务器内部错误,请及时关注!"); - ActionContext context = ActionContext.getContext(); context.getResponse().setStatus(500); context.getResponse().setCharacterEncoding("UTF-8"); context.getResponse().setContentType("application/json;charset=UTF-8"); context.getResponse().getWriter().println("{\"code\":500, \"msg\":\"服务器内部错误\"}"); } - private String getServerIp() { - try { - InetAddress inetAddress = InetAddress.getLocalHost(); - return inetAddress.getHostAddress(); - } catch (UnknownHostException e) { - LOGGER.error("Unable to get server IP address", e); - return "Unknown IP"; + private String getVisitorIp(HttpServletRequest request) { + String ip = request.getHeader("X-Forwarded-For"); + if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); } + if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + return ip.split(",")[0]; // 处理多个 IP 的情况 } }