封装/poi/search到open
This commit is contained in:
+101
-46
@@ -1,6 +1,7 @@
|
||||
package com.fangjia.open.controllers;
|
||||
|
||||
import com.fangjia.core.RegionData;
|
||||
import com.fangjia.core.util.HttpRequest;
|
||||
import com.fangjia.dal.mongo.model.AmapPoi;
|
||||
import com.fangjia.dal.mongo.model.CbmRegion;
|
||||
import com.fangjia.dal.mongo.model.elastic.CbmAmapPoi;
|
||||
@@ -8,10 +9,7 @@ import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.open.dto.UniversalDto;
|
||||
import com.fangjia.open.interceptors.Authority;
|
||||
import com.fangjia.open.interceptors.Role;
|
||||
import com.fangjia.open.model.AntiFraudQuestionModel;
|
||||
import com.fangjia.open.model.BasicModel;
|
||||
import com.fangjia.open.model.PoiSuggestModel;
|
||||
import com.fangjia.open.model.RestfulModelAndView;
|
||||
import com.fangjia.open.model.*;
|
||||
import com.fangjia.service.address.AddressParserService;
|
||||
import com.fangjia.service.address.AddressParserUtil;
|
||||
import com.fangjia.service.address.mode.Address;
|
||||
@@ -19,6 +17,7 @@ import com.fangjia.service.api.AmapPoiService;
|
||||
import com.fangjia.service.bo.Point;
|
||||
import com.fangjia.service.datastore.DistrictService;
|
||||
import com.fangjia.service.mongo.fangjia.CbmRegionService;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.validation.Valid;
|
||||
@@ -33,14 +32,14 @@ public class PoiController {
|
||||
private DistrictService districtService;
|
||||
private static final String[] PROPERTY_SEARCH_API_FIELDS = {"address", "city", "region", "name", "addrAlias"};
|
||||
|
||||
public Object getAntiFraudQuestionAction(@Valid AntiFraudQuestionModel model){
|
||||
public Object getAntiFraudQuestionAction(@Valid AntiFraudQuestionModel model) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
Point point = amapPoiService.geocode(model.getCity(), model.getAddress());
|
||||
if(point != null){
|
||||
if (point != null) {
|
||||
List<AmapPoi> poiList = amapPoiService.findAntiFraudPoisAction(point, model.getActualPoiSelectRadius(),
|
||||
model.getFraudPoiSelectMinRadius(), model.getActualCount(), model.getFraudCount());
|
||||
List<UniversalDto> pois = new ArrayList<UniversalDto>();
|
||||
for(AmapPoi poi : poiList){
|
||||
for (AmapPoi poi : poiList) {
|
||||
UniversalDto dto = UniversalDto.newDto();
|
||||
dto.append("id", poi.getId());
|
||||
dto.append("city", poi.getCityname());
|
||||
@@ -54,22 +53,22 @@ public class PoiController {
|
||||
pois.add(dto);
|
||||
}
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(pois));
|
||||
}else{
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(Collections.emptyList()));
|
||||
}
|
||||
return mav;
|
||||
|
||||
}
|
||||
|
||||
public Object cmbTipsAction(@Valid PoiSuggestModel poiSuggestModel){
|
||||
public Object cmbTipsAction(@Valid PoiSuggestModel poiSuggestModel) {
|
||||
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
String city = RegionData.formatCity(poiSuggestModel.getCity());
|
||||
if(city != null){
|
||||
if (city != null) {
|
||||
String region = RegionData.formatRegion(city, poiSuggestModel.getRegion());
|
||||
if(!RegionData.isRegion(city, region) && RegionData.getRegionByCity(city) != null){
|
||||
for(String r : RegionData.getRegionByCity(city)){
|
||||
if(region.startsWith(r)){
|
||||
if (!RegionData.isRegion(city, region) && RegionData.getRegionByCity(city) != null) {
|
||||
for (String r : RegionData.getRegionByCity(city)) {
|
||||
if (region.startsWith(r)) {
|
||||
region = r;
|
||||
break;
|
||||
}
|
||||
@@ -78,71 +77,71 @@ public class PoiController {
|
||||
poiSuggestModel.setCity(city);
|
||||
poiSuggestModel.setRegion(region);
|
||||
}
|
||||
if(!RegionData.isRegion(poiSuggestModel.getCity(), poiSuggestModel.getRegion()) || !RegionData.isCity(poiSuggestModel.getCity())){
|
||||
if (!RegionData.isRegion(poiSuggestModel.getCity(), poiSuggestModel.getRegion()) || !RegionData.isCity(poiSuggestModel.getCity())) {
|
||||
CbmRegion cbmRegion = cbmRegionService.findCbmRegion(poiSuggestModel.getCity(), poiSuggestModel.getRegion());
|
||||
if(cbmRegion != null){
|
||||
if (cbmRegion != null) {
|
||||
poiSuggestModel.setCity(cbmRegion.getCity());
|
||||
poiSuggestModel.setRegion(cbmRegion.getRegion());
|
||||
}
|
||||
}
|
||||
if(city == null){
|
||||
if (city == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city非法"));
|
||||
return mav;
|
||||
}
|
||||
Address address = addressParserService.standardizeForSearch(poiSuggestModel.getCity(), poiSuggestModel.getKeywords());
|
||||
String keywords = poiSuggestModel.getKeywords();
|
||||
if(StringUtils.isNotBlank(address.getEffectiveAddress())){
|
||||
if (StringUtils.isNotBlank(address.getEffectiveAddress())) {
|
||||
poiSuggestModel.setKeywords(address.getEffectiveAddress());
|
||||
poiSuggestModel.setCity(address.getCity());
|
||||
if(StringUtils.isNotBlank(address.getDistrict())){
|
||||
if (StringUtils.isNotBlank(address.getDistrict())) {
|
||||
poiSuggestModel.setRegion(address.getDistrict());
|
||||
}
|
||||
}
|
||||
List<District> districts = districtService.cmbSearch(poiSuggestModel.getCity(), poiSuggestModel.getRegion(), poiSuggestModel.getKeywords(), PROPERTY_SEARCH_API_FIELDS, poiSuggestModel.getLimit());
|
||||
List<UniversalDto> dtos = new ArrayList<UniversalDto>();
|
||||
Set<String> keys = new HashSet<String>();
|
||||
for(District district : districts){
|
||||
for (District district : districts) {
|
||||
UniversalDto dto = new UniversalDto();
|
||||
dto.append("city", district.getCity());
|
||||
dto.append("region", district.getRegion());
|
||||
if(district.getName().contains(poiSuggestModel.getKeywords()) || district.getAlias() == null){
|
||||
if (district.getName().contains(poiSuggestModel.getKeywords()) || district.getAlias() == null) {
|
||||
dto.append("name", district.getName());
|
||||
keys.add(district.getName());
|
||||
dto.append("address", district.getAddress());
|
||||
}else{
|
||||
} else {
|
||||
dto.append("name", getLookLikeString(poiSuggestModel.getKeywords(), district.getAlias(), district.getName()));
|
||||
keys.add((String)dto.get("name"));
|
||||
if(district.getAddress() == null || district.getAddress().contains(poiSuggestModel.getKeywords()) || district.getAddrAlias() == null){
|
||||
keys.add((String) dto.get("name"));
|
||||
if (district.getAddress() == null || district.getAddress().contains(poiSuggestModel.getKeywords()) || district.getAddrAlias() == null) {
|
||||
dto.append("address", district.getAddress());
|
||||
}else{
|
||||
} else {
|
||||
dto.append("address", getLookLikeString(poiSuggestModel.getKeywords(), district.getAddrAlias(), district.getAddress()));
|
||||
}
|
||||
}
|
||||
dtos.add(dto);
|
||||
}
|
||||
if(dtos.size() == poiSuggestModel.getLimit()){
|
||||
if (dtos.size() == poiSuggestModel.getLimit()) {
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(dtos));
|
||||
return mav;
|
||||
}
|
||||
List<AmapPoi> amapPois = amapPoiService.inputtips(poiSuggestModel.getCity(), poiSuggestModel.getRegion(), keywords, poiSuggestModel.getLimit(), false);
|
||||
for(AmapPoi amapPoi : amapPois){
|
||||
if(!keys.contains(amapPoi.getName())){
|
||||
for (AmapPoi amapPoi : amapPois) {
|
||||
if (!keys.contains(amapPoi.getName())) {
|
||||
UniversalDto dto = new UniversalDto();
|
||||
if(amapPoi.getCity() == null){
|
||||
if (amapPoi.getCity() == null) {
|
||||
dto.append("city", poiSuggestModel.getCity());
|
||||
}else{
|
||||
} else {
|
||||
dto.append("city", amapPoi.getCity());
|
||||
}
|
||||
if(amapPoi.getRegion() == null){
|
||||
if (amapPoi.getRegion() == null) {
|
||||
dto.append("region", poiSuggestModel.getRegion());
|
||||
}else{
|
||||
} else {
|
||||
dto.append("region", amapPoi.getRegion());
|
||||
}
|
||||
dto.append("name", amapPoi.getName());
|
||||
dto.append("address", amapPoi.getAddress());
|
||||
dtos.add(dto);
|
||||
}
|
||||
if(dtos.size() >= poiSuggestModel.getLimit()){
|
||||
if (dtos.size() >= poiSuggestModel.getLimit()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -150,16 +149,16 @@ public class PoiController {
|
||||
return mav;
|
||||
}
|
||||
|
||||
String getLookLikeString(String orgStr, List<String> list, String extend){
|
||||
if(list == null){
|
||||
String getLookLikeString(String orgStr, List<String> list, String extend) {
|
||||
if (list == null) {
|
||||
list = new ArrayList<String>();
|
||||
}
|
||||
list.add(extend);
|
||||
String targetStr = extend;
|
||||
double similar = 0;
|
||||
for(String item : list){
|
||||
for (String item : list) {
|
||||
double s = AddressParserUtil.getSimilarityRatio(orgStr, item);
|
||||
if(s > similar){
|
||||
if (s > similar) {
|
||||
targetStr = item;
|
||||
similar = s;
|
||||
}
|
||||
@@ -167,14 +166,14 @@ public class PoiController {
|
||||
return targetStr;
|
||||
}
|
||||
|
||||
public Object cmbTips2Action(@Valid PoiSuggestModel poiSuggestModel){
|
||||
public Object cmbTips2Action(@Valid PoiSuggestModel poiSuggestModel) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
String city = RegionData.formatCity(poiSuggestModel.getCity());
|
||||
if(city != null){
|
||||
if (city != null) {
|
||||
String region = RegionData.formatRegion(city, poiSuggestModel.getRegion());
|
||||
if(!RegionData.isRegion(city, region) && RegionData.getRegionByCity(city) != null){
|
||||
for(String r : RegionData.getRegionByCity(city)){
|
||||
if(region.startsWith(r)){
|
||||
if (!RegionData.isRegion(city, region) && RegionData.getRegionByCity(city) != null) {
|
||||
for (String r : RegionData.getRegionByCity(city)) {
|
||||
if (region.startsWith(r)) {
|
||||
region = r;
|
||||
break;
|
||||
}
|
||||
@@ -183,28 +182,28 @@ public class PoiController {
|
||||
poiSuggestModel.setCity(city);
|
||||
poiSuggestModel.setRegion(region);
|
||||
}
|
||||
if(!RegionData.isRegion(poiSuggestModel.getCity(), poiSuggestModel.getRegion()) || !RegionData.isCity(poiSuggestModel.getCity())){
|
||||
if (!RegionData.isRegion(poiSuggestModel.getCity(), poiSuggestModel.getRegion()) || !RegionData.isCity(poiSuggestModel.getCity())) {
|
||||
CbmRegion cbmRegion = cbmRegionService.findCbmRegion(poiSuggestModel.getCity(), poiSuggestModel.getRegion());
|
||||
poiSuggestModel.setCity(cbmRegion.getCity());
|
||||
poiSuggestModel.setRegion(cbmRegion.getRegion());
|
||||
}
|
||||
Address address = addressParserService.standardizeForSearch(poiSuggestModel.getCity(), poiSuggestModel.getKeywords());
|
||||
if(StringUtils.isNotBlank(address.getEffectiveAddress())){
|
||||
if (StringUtils.isNotBlank(address.getEffectiveAddress())) {
|
||||
poiSuggestModel.setKeywords(address.getEffectiveAddress());
|
||||
poiSuggestModel.setCity(address.getCity());
|
||||
poiSuggestModel.setRegion(address.getDistrict());
|
||||
}
|
||||
List<CbmAmapPoi> amapPois = amapPoiService.cmbTips(poiSuggestModel.getCity(), poiSuggestModel.getRegion(), poiSuggestModel.getKeywords());
|
||||
List<UniversalDto> dtos = new ArrayList<UniversalDto>();
|
||||
for(CbmAmapPoi poi : amapPois){
|
||||
for (CbmAmapPoi poi : amapPois) {
|
||||
UniversalDto dto = UniversalDto.newDto();
|
||||
dto.append("city", poi.getCityname());
|
||||
dto.append("region", poi.getAdname());
|
||||
dto.append("name", poi.getName());
|
||||
dto.append("address", poi.getAddress());
|
||||
if(!poi.getName().startsWith(poiSuggestModel.getKeywords()) && poi.getAlias() != null && poi.getAlias().contains(poi.getText())){
|
||||
if (!poi.getName().startsWith(poiSuggestModel.getKeywords()) && poi.getAlias() != null && poi.getAlias().contains(poi.getText())) {
|
||||
dto.append("name", poi.getText());
|
||||
}else if((poi.getAddress() != null && !poi.getAddress().startsWith(poiSuggestModel.getKeywords())) && poi.getAddrAlias() != null && poi.getAddrAlias().contains(poi.getText())){
|
||||
} else if ((poi.getAddress() != null && !poi.getAddress().startsWith(poiSuggestModel.getKeywords())) && poi.getAddrAlias() != null && poi.getAddrAlias().contains(poi.getText())) {
|
||||
dto.append("address", poi.getText());
|
||||
}
|
||||
dtos.add(dto);
|
||||
@@ -213,6 +212,62 @@ public class PoiController {
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* POI搜索服务
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
public Object searchAction(AddressModel model) {
|
||||
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
if (StringUtils.isBlank(model.getLocation()) || StringUtils.isBlank(model.getCity())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("城市和经纬度为必填项"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
HttpRequest request = new HttpRequest();
|
||||
JSONObject json = null;
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("city", model.getCity());
|
||||
params.put("location", model.getLocation());
|
||||
params.put("types", StringUtils.isNotBlank(model.getTypes()) ? model.getTypes() : null);
|
||||
Integer radius = model.getRadius();
|
||||
if (radius != null && radius > 0) {
|
||||
params.put("radius", radius.toString());
|
||||
}
|
||||
Integer offset = model.getOffset();
|
||||
if (offset != null && offset > 0) {
|
||||
params.put("offset", offset.toString());
|
||||
}
|
||||
Integer page = model.getPage();
|
||||
if (page != null && page > 0) {
|
||||
params.put("page", page.toString());
|
||||
}
|
||||
try {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/poi/search", params, "UTF-8");
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/poi/search", params, "UTF-8");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (json != null) {
|
||||
int code = json.getInt("msgCode");
|
||||
String msg = json.getString("msg");
|
||||
BasicModel basicModel = new BasicModel(code, msg);
|
||||
if (json.containsKey("result")) {
|
||||
basicModel.setResult(json.get("result"));
|
||||
}
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中..."));
|
||||
}
|
||||
return mav;
|
||||
}
|
||||
|
||||
public void setAmapPoiService(AmapPoiService amapPoiService) {
|
||||
this.amapPoiService = amapPoiService;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,10 @@ public class AddressModel extends FangjiaApiModel {
|
||||
private Integer radius;
|
||||
// 查询数量
|
||||
private Integer number;
|
||||
private Integer offset;
|
||||
// 查询页码
|
||||
private Integer pageNo;
|
||||
private Integer page;
|
||||
// 是否用于检查
|
||||
private String dataLevel;
|
||||
|
||||
@@ -49,6 +51,9 @@ public class AddressModel extends FangjiaApiModel {
|
||||
|
||||
private String lat;
|
||||
private String lng;
|
||||
|
||||
private String location;
|
||||
private String types;
|
||||
public boolean isContainsLocation() {
|
||||
return containsLocation;
|
||||
}
|
||||
@@ -297,4 +302,36 @@ public class AddressModel extends FangjiaApiModel {
|
||||
public void setLng(String lng) {
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(String types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public Integer getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(Integer offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public Integer getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Integer page) {
|
||||
this.page = page;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user