/house/around接口

This commit is contained in:
majintao
2024-11-27 18:12:50 +08:00
parent 592e2671f1
commit 1c35420bf7
7 changed files with 1811 additions and 1453 deletions
@@ -6,6 +6,7 @@ import javax.persistence.*;
import com.fangjia.dal.DatastoreCategory;
import com.fangjia.dal.SeawaterEntity;
import com.fasterxml.jackson.annotation.JsonInclude;
@Entity
@Table(name = "fangjia.seawater")
@@ -35,9 +36,11 @@ public class Seawater implements SeawaterEntity {
private String id;
private String category;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
private int status;
private String city;
private String region;
private String district;
private String districtName;
private String address;
private Date modificationDate;
@@ -46,8 +49,10 @@ public class Seawater implements SeawaterEntity {
private String block;
private Integer totalPrice;
private Double area;
private Double size;
private Integer height;
private Integer floor;
private Integer maxFloor;
private String floorInfo;
private String fitment;
private Integer room;
@@ -55,10 +60,13 @@ public class Seawater implements SeawaterEntity {
private Integer toilet;
private String mobile;
private Integer pDate;
private String publishDate;
private Integer userId;
private String url;
private String root;
private Integer avgPrice;
private Integer unitPrice;
private String purpose;
private String estateType;
private String buildType;
@@ -70,6 +78,8 @@ public class Seawater implements SeawaterEntity {
private String housingAge; //房屋年限 满二年
private String elevator; //配备电梯 有/无
private String decoration;
@Id
@Column(name = "_id")
public String getId() {
@@ -395,4 +405,52 @@ public class Seawater implements SeawaterEntity {
public void setElevator(String elevator) {
this.elevator = elevator;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public Double getSize() {
return size;
}
public void setSize(Double size) {
this.size = size;
}
public Integer getMaxFloor() {
return maxFloor;
}
public void setMaxFloor(Integer maxFloor) {
this.maxFloor = maxFloor;
}
public Integer getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(Integer unitPrice) {
this.unitPrice = unitPrice;
}
public String getPublishDate() {
return publishDate;
}
public void setPublishDate(String publishDate) {
this.publishDate = publishDate;
}
public String getDecoration() {
return decoration;
}
public void setDecoration(String decoration) {
this.decoration = decoration;
}
}
@@ -24,6 +24,8 @@ public class Seaweed implements SeaweedEntity {
private List<String> alias;
private List<String> addrAlias;
private double score;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "_id")
@@ -134,4 +136,13 @@ public class Seaweed implements SeaweedEntity {
public void setEstateType2(String estateType2) {
this.estateType2 = estateType2;
}
@Transient
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}
@@ -14,6 +14,7 @@ import com.fangjia.dal.mongo.model.StatsIndex;
import com.fangjia.dal.seawater.dao.SeawaterDao;
import com.fangjia.dal.seawater.model.Seawater;
import com.fangjia.dal.seaweed.model.District;
import com.fangjia.dal.seaweed.model.Seaweed;
import com.fangjia.dal.sql.model.ApiUser;
import com.fangjia.datastore.driver.FacetResult;
import com.fangjia.open.FangjiaApiUtil;
@@ -38,10 +39,7 @@ import com.fangjia.service.bo.Collateral;
import com.fangjia.service.bo.DistrictStatBo;
import com.fangjia.service.bo.Sample;
import com.fangjia.service.bo.ShopSample;
import com.fangjia.service.datastore.CzbankSampleService;
import com.fangjia.service.datastore.DistrictService;
import com.fangjia.service.datastore.HouseService;
import com.fangjia.service.datastore.NoHouseDistrictService;
import com.fangjia.service.datastore.*;
import com.fangjia.service.datastore.bean.CollateralSampleQueryBean;
import com.fangjia.service.datastore.bean.ShopCollateralSampleQueryBean;
import com.fangjia.service.district.DistrictFacilitysService;
@@ -70,6 +68,7 @@ import java.io.IOException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Authority(role = Role.USER)
public class HouseController {
@@ -98,6 +97,8 @@ public class HouseController {
private SeawaterService seawaterService;
private SeawaterDao seawaterDao;
private SeaweedService seaweedService;
private List<String> PROPERTY_TYPE_CODE_LIST = Arrays.asList("01", "02");
@@ -137,10 +138,10 @@ public class HouseController {
}
public static final String[] INCLUDE_DISTRICT_FIELDS = {
"id", "city", "region", "name", "address","estateType2", "alias",
"id", "city", "region", "name", "address", "estateType2", "alias",
"estateCharge", "virescencePercent", "cubagePercent",
"houseProperty","buildType","lat","lng","lat2","lng2",
"buildDate","finishBuildingDate","liveDate","propertyLife","block","openDate"
"houseProperty", "buildType", "lat", "lng", "lat2", "lng2",
"buildDate", "finishBuildingDate", "liveDate", "propertyLife", "block", "openDate"
};
private static final String[] INCLUDE_HOUSE_FIELDS = {
@@ -149,20 +150,18 @@ public class HouseController {
"address", "publishDate", "url"};
public Object publishAction(@Valid HousePublishModel model){
public Object publishAction(@Valid HousePublishModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
if(model.getImage() == null || model.getImage().length == 0){
if (model.getImage() == null || model.getImage().length == 0) {
mav.setModel(BasicModel.buildBadRequestModel("图片不能为空"));
return mav;
}
MultipartFile[] images = model.getImage();
for (int i = 0; i < images.length; i++) {
MultipartFile img = images[i];
if(img.getSize() > MAX_PIC_SIZE){
if (img.getSize() > MAX_PIC_SIZE) {
mav.setModel(BasicModel.buildBadRequestModel("图片过大"));
return mav;
}
@@ -170,25 +169,25 @@ public class HouseController {
Map<String, String> tokenMap = FangjiaApiUtil.parseToken(model.getToken());
String userId = tokenMap.get("userid");
House house = createHouse(model,Integer.valueOf(userId));
if(StringUtils.isNotBlank(house.getId())){
if(StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())){
House house = createHouse(model, Integer.valueOf(userId));
if (StringUtils.isNotBlank(house.getId())) {
if (StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())) {
mav.setModel(BasicModel.buildBadRequestModel("房源id不合法"));
return mav;
}
House dbHouse = houseService.findHouseById(model.getId());
if(dbHouse == null){
if (dbHouse == null) {
mav.setModel(BasicModel.buildBadRequestModel("房源不存在"));
return mav;
}
if(!userId.equals(dbHouse.getUserId().toString())){
if (!userId.equals(dbHouse.getUserId().toString())) {
mav.setModel(BasicModel.buildUnAuthorizedModel().setMsg("你没有权限修改该房源"));
return mav;
}
for(String pic : dbHouse.getPics()){//删除过时的房源图片
fileDao.delete(pic,"user_house","o");
fileDao.delete(pic,"user_house","s");
fileDao.delete(pic,"user_house","m");
for (String pic : dbHouse.getPics()) {//删除过时的房源图片
fileDao.delete(pic, "user_house", "o");
fileDao.delete(pic, "user_house", "s");
fileDao.delete(pic, "user_house", "m");
}
}
houseService.saveHouse(house);
@@ -197,10 +196,10 @@ public class HouseController {
MultipartFile img = images[i];
try {
String url = userId + "/" + house.getId() + "/api/" + img.getOriginalFilename();
url = getPicUrl(url,urls);
fileDao.save(url, "user_house", "o" ,img.getBytes(),img.getContentType());
fileDao.save(url, "user_house", "s" ,img.getBytes(),img.getContentType());
fileDao.save(url, "user_house", "m" ,img.getBytes(),img.getContentType());
url = getPicUrl(url, urls);
fileDao.save(url, "user_house", "o", img.getBytes(), img.getContentType());
fileDao.save(url, "user_house", "s", img.getBytes(), img.getContentType());
fileDao.save(url, "user_house", "m", img.getBytes(), img.getContentType());
} catch (IOException e) {
e.printStackTrace();
}
@@ -213,38 +212,38 @@ public class HouseController {
}
@Authority(role = Role.USER)
public Object similarAction(@Valid CollateralSampleQuery collateralSampleQuery){
public Object similarAction(@Valid CollateralSampleQuery collateralSampleQuery) {
RestfulModelAndView mav = new RestfulModelAndView();
List<CollateralSampleQueryBean> querys = null;
try{
try {
querys = convertQueryToBean(collateralSampleQuery);
}catch (Exception e){
} catch (Exception e) {
mav.setModel(BasicModel.buildBadRequestModel(e.getMessage()));
return mav;
}
if(null == collateralSampleQuery.getMax()){
if (null == collateralSampleQuery.getMax()) {
collateralSampleQuery.setMax(3);
}
List<Collateral> collaterals = czbankSampleService.findSample(querys, collateralSampleQuery.getMax());
Collateral collateral = collaterals.get(0);
for(Sample sample : collateral.getSample()){
if(querys.size() > 0 && querys.get(0).getProperty() != null){
for (Sample sample : collateral.getSample()) {
if (querys.size() > 0 && querys.get(0).getProperty() != null) {
District district = querys.get(0).getProperty();
if(district != null){
if (district != null) {
sample.setHouseUseLimit(DataUtil.extractPrice(district.getPropertyLife()));
if(sample.getHouseUseLimit() == null && !Arrays.asList("成都", "重庆").contains(district.getCity())){
if(district.getEstateType2() != null && district.getEstateType2().contains("商住")){
if (sample.getHouseUseLimit() == null && !Arrays.asList("成都", "重庆").contains(district.getCity())) {
if (district.getEstateType2() != null && district.getEstateType2().contains("商住")) {
sample.setHouseUseLimit(50);
}else{
} else {
sample.setHouseUseLimit(70);
}
}
if(sample.getHouseUseLimit() != null && sample.getCompleteDate() != null){
if (sample.getHouseUseLimit() != null && sample.getCompleteDate() != null) {
Integer houseHadUsed = DateUtil.getYear(new Date()) - Integer.valueOf(sample.getCompleteDate().substring(0, 4));
sample.setHouseHadUsed(houseHadUsed);
sample.setBuildingRemainLife(sample.getHouseUseLimit() - sample.getHouseHadUsed());
}else {
} else {
sample.setHouseHadUsed(null);
sample.setBuildingRemainLife(null);
}
@@ -256,14 +255,16 @@ public class HouseController {
}
/**商铺相似房源接口*/
/**
* 商铺相似房源接口
*/
@Authority(role = Role.USER)
public Object shopSimilarAction(@Valid ShopCollateralSampleQuery query){
public Object shopSimilarAction(@Valid ShopCollateralSampleQuery query) {
RestfulModelAndView mav = new RestfulModelAndView();
ShopCollateralSampleQueryBean queryBean = new ShopCollateralSampleQueryBean();
BeanUtils.copyProperties(query, queryBean);
FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertOfficialCodeToFangjia(queryBean.getDistrict());
if(fangjiaOfficialAreaMap == null){
if (fangjiaOfficialAreaMap == null) {
String msg = "地区信息无法映射到房价网的地区信息->(province:" + queryBean.getProvince() + " ,city: " + queryBean.getCity() + " ,district: " + queryBean.getDistrict() + ")";
mav.setModel(BasicModel.buildBadRequestModel(msg));
return mav;
@@ -271,7 +272,7 @@ public class HouseController {
queryBean.setFangjiaCity(fangjiaOfficialAreaMap.getFangjiaCity());
queryBean.setFangjiaDistrict(fangjiaOfficialAreaMap.getFangjiaDistrict());
District property = districtService.findByNameAndAlias(queryBean.getFangjiaCity(), queryBean.getFangjiaDistrict(), queryBean.getBuildingName(), "shop");
if(property == null){
if (property == null) {
mav.setModel(BasicModel.buildBadRequestModel("未找到该商铺"));
return mav;
}
@@ -282,43 +283,43 @@ public class HouseController {
}
private List<CollateralSampleQueryBean> convertQueryToBean(CollateralSampleQuery... queries) throws Exception{
private List<CollateralSampleQueryBean> convertQueryToBean(CollateralSampleQuery... queries) throws Exception {
List<CollateralSampleQueryBean> queryBeans = new ArrayList<CollateralSampleQueryBean>(queries.length);
for(CollateralSampleQuery q : queries){
for (CollateralSampleQuery q : queries) {
CollateralSampleQueryBean queryBean = new CollateralSampleQueryBean();
BeanUtils.copyProperties(q, queryBean);
String city = queryBean.getCity();
FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertOfficialCodeToFangjia(q.getDistrict());
if(fangjiaOfficialAreaMap == null){
if (fangjiaOfficialAreaMap == null) {
throw new Exception("地区信息无法映射到房价网的地区信息->(province:" + q.getProvince() + " ,city: " + q.getCity() + " ,district: " + q.getDistrict() + ")");
}
queryBean.setFangjiaCity(fangjiaOfficialAreaMap.getFangjiaCity());
queryBean.setFangjiaDistrict(fangjiaOfficialAreaMap.getFangjiaDistrict());
String propertyTypeCode = queryBean.getPropertyTypeCode();
if(!PROPERTY_TYPE_CODE_LIST.contains(propertyTypeCode)){
if (!PROPERTY_TYPE_CODE_LIST.contains(propertyTypeCode)) {
throw new Exception("propertyTypeCode取值非法");
}
String cat = "district";
District property = districtService.findByNameAndAlias(queryBean.getFangjiaCity(), queryBean.getFangjiaDistrict(), queryBean.getBuildingName(), cat);
if(property == null){
if (property == null) {
throw new Exception("未找到该小区");
}
queryBean.setProperty(property);
Integer decrCondCode = queryBean.getDecrCondCode();
if(decrCondCode == null){
if (decrCondCode == null) {
decrCondCode = 2;
}
if(decrCondCode > 5 || decrCondCode < 1){
if (decrCondCode > 5 || decrCondCode < 1) {
throw new Exception("decrCondCode取值非法");
}
Integer towardDirectCode = queryBean.getTowardDirectCode();
if(towardDirectCode == null){
if (towardDirectCode == null) {
towardDirectCode = 3;
}
if(towardDirectCode > 10 || towardDirectCode < 1){
if (towardDirectCode > 10 || towardDirectCode < 1) {
throw new Exception("towardDirectCode取值非法");
}
queryBeans.add(queryBean);
@@ -327,10 +328,10 @@ public class HouseController {
}
private List<CollateralSampleQueryBean> convertSampileQueryToBean(SampleQuery... queries) throws Exception{
private List<CollateralSampleQueryBean> convertSampileQueryToBean(SampleQuery... queries) throws Exception {
List<CollateralSampleQueryBean> queryBeans = new ArrayList<CollateralSampleQueryBean>(queries.length);
for(SampleQuery q : queries){
for (SampleQuery q : queries) {
CollateralSampleQueryBean queryBean = new CollateralSampleQueryBean();
BeanUtils.copyProperties(q, queryBean);
@@ -340,57 +341,57 @@ public class HouseController {
// }
String cat = "district";
if(StringUtils.isNotBlank(queryBean.getCity()) && StringUtils.isNotBlank(queryBean.getDistrict()) && StringUtils.isNotBlank(queryBean.getBuildingName())){
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){
if (property == null) {
throw new Exception("未找到该小区");
}
queryBean.setProperty(property);
}else if(StringUtils.isNotBlank(queryBean.getAddress())){
} else if (StringUtils.isNotBlank(queryBean.getAddress())) {
HttpRequest request = new HttpRequest();
JSONObject json = null;
String address = queryBean.getAddress().replace(" ","").replace("%","");
String address = queryBean.getAddress().replace(" ", "").replace("%", "");
Map<String, String> params = new HashMap<String, String>();
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");
if (json != null && json.size()>0) {
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){
if (property == null) {
throw new Exception("未找到该小区");
}
queryBean.setProperty(property);
}else{
} else {
throw new Exception("未找到该小区");
}
}
String estateType = queryBean.getProperty().getEstateType2();
queryBean.setPropertyTypeCode("01");
if(StringUtils.isNotBlank(estateType)){
if(estateType.equals("普通住宅")){
if (StringUtils.isNotBlank(estateType)) {
if (estateType.equals("普通住宅")) {
queryBean.setPropertyTypeCode("01");
}else if(estateType.equals("别墅")){
} else if (estateType.equals("别墅")) {
queryBean.setPropertyTypeCode("02");
}else if(estateType.equals("商住")){
} else if (estateType.equals("商住")) {
queryBean.setPropertyTypeCode("03");
}
}
Integer decrCondCode = queryBean.getDecrCondCode();
if(decrCondCode == null){
if (decrCondCode == null) {
decrCondCode = 2;
}
if(decrCondCode > 5 || decrCondCode < 1){
if (decrCondCode > 5 || decrCondCode < 1) {
throw new Exception("decrCondCode取值非法");
}
Integer towardDirectCode = queryBean.getTowardDirectCode();
if(towardDirectCode == null){
if (towardDirectCode == null) {
towardDirectCode = 3;
}
if(towardDirectCode > 10 || towardDirectCode < 1){
if (towardDirectCode > 10 || towardDirectCode < 1) {
throw new Exception("towardDirectCode取值非法");
}
queryBeans.add(queryBean);
@@ -437,25 +438,25 @@ public class HouseController {
// return queryBeans;
// }
public Object detailAction(HousePublishModel model){
public Object detailAction(HousePublishModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
if(StringUtils.isBlank(model.getId())){
if (StringUtils.isBlank(model.getId())) {
mav.setModel(BasicModel.buildBadRequestModel("房源id不能为空"));
return mav;
}
if(StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())){
if (StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())) {
mav.setModel(BasicModel.buildBadRequestModel("房源id不合法"));
return mav;
}
House dbHouse = houseService.findHouseById(model.getId());
if(dbHouse == null || dbHouse.getStatus() == HOUSE_DELETE_STATUS){
if (dbHouse == null || dbHouse.getStatus() == HOUSE_DELETE_STATUS) {
mav.setModel(BasicModel.buildBadRequestModel("房源不存在"));
return mav;
}
Map<String, String> tokenMap = FangjiaApiUtil.parseToken(model.getToken());
String userId = tokenMap.get("userid");
if(dbHouse.getUserId() == null || !userId.equals(dbHouse.getUserId().toString())){
if (dbHouse.getUserId() == null || !userId.equals(dbHouse.getUserId().toString())) {
mav.setModel(BasicModel.buildUnAuthorizedModel().setMsg("你没有权限访问该房源"));
return mav;
}
@@ -463,25 +464,25 @@ public class HouseController {
return mav;
}
public Object deleteAction(HousePublishModel model){
public Object deleteAction(HousePublishModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
if(StringUtils.isBlank(model.getId())){
if (StringUtils.isBlank(model.getId())) {
mav.setModel(BasicModel.buildBadRequestModel("房源id不能为空"));
return mav;
}
if(StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())){
if (StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())) {
mav.setModel(BasicModel.buildBadRequestModel("房源id不合法"));
return mav;
}
House dbHouse = houseService.findHouseById(model.getId());
if(dbHouse == null || dbHouse.getStatus() == HOUSE_DELETE_STATUS){
if (dbHouse == null || dbHouse.getStatus() == HOUSE_DELETE_STATUS) {
mav.setModel(BasicModel.buildBadRequestModel("房源不存在"));
return mav;
}
Map<String, String> tokenMap = FangjiaApiUtil.parseToken(model.getToken());
String userId = tokenMap.get("userid");
if(dbHouse.getUserId() == null || !userId.equals(dbHouse.getUserId().toString())){
if (dbHouse.getUserId() == null || !userId.equals(dbHouse.getUserId().toString())) {
mav.setModel(BasicModel.buildUnAuthorizedModel().setMsg("你没有权限删除该房源"));
return mav;
}
@@ -490,33 +491,33 @@ public class HouseController {
return mav;
}
public Object refreshAction(HousePublishModel model){
public Object refreshAction(HousePublishModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
if(StringUtils.isBlank(model.getId())){
if (StringUtils.isBlank(model.getId())) {
mav.setModel(BasicModel.buildBadRequestModel("房源id不能为空"));
return mav;
}
if(StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())){
if (StringUtils.isBlank(model.getId()) || !ObjectId.isValid(model.getId())) {
mav.setModel(BasicModel.buildBadRequestModel("房源id不合法"));
return mav;
}
House dbHouse = houseService.findHouseById(model.getId());
if(dbHouse == null || dbHouse.getStatus() == HOUSE_DELETE_STATUS){
if (dbHouse == null || dbHouse.getStatus() == HOUSE_DELETE_STATUS) {
mav.setModel(BasicModel.buildBadRequestModel("房源不存在"));
return mav;
}
Map<String, String> tokenMap = FangjiaApiUtil.parseToken(model.getToken());
String userId = tokenMap.get("userid");
if(dbHouse.getUserId() == null || !userId.equals(dbHouse.getUserId().toString())){
if (dbHouse.getUserId() == null || !userId.equals(dbHouse.getUserId().toString())) {
mav.setModel(BasicModel.buildUnAuthorizedModel().setMsg("你没有权限删除该房源"));
return mav;
}
boolean refresh = houseService.refreshHouse(dbHouse.getId(), Integer.valueOf(userId), "api");
if(!refresh){
if (!refresh) {
mav.setModel(BasicModel.buildOKModel().setMsg("每天只能刷新一次房源"));
return mav;
}else{
} else {
mav.setModel(BasicModel.buildOKModel().setMsg("刷新成功"));
return mav;
}
@@ -531,44 +532,43 @@ public class HouseController {
}
District district = null;
DistrictKey districtKey = null;
if(StringUtils.isNotBlank(model.getName())){
if (StringUtils.isNotBlank(model.getName())) {
districtKey = new DistrictKey(model.getCity(), model.getRegion(), model.getName());
district = districtService.findDistrict(districtKey, "district");
}else{
} else {
district = districtService.findDistrictById(model.getId());
if(district!=null){
if (district != null) {
districtKey = new DistrictKey(district.getCity(), district.getRegion(), district.getName());
}
}
if(district == null){
if (district == null) {
mav.setModel(BasicModel.buildBadRequestModel("该小区不存在"));
return mav;
}
DistrictStatBo bo = districtStatService.findCurrentDistrictStat(districtKey);
Integer minPrice = null;
Integer maxPrice = null;
if(bo.getDistrictStat()!=null){
minPrice = (int)(bo.getDistrictStat().getAvgPrice() * 0.8);
maxPrice = (int)(bo.getDistrictStat().getAvgPrice() * 1.2);
if (bo.getDistrictStat() != null) {
minPrice = (int) (bo.getDistrictStat().getAvgPrice() * 0.8);
maxPrice = (int) (bo.getDistrictStat().getAvgPrice() * 1.2);
}
List<String> names = new ArrayList<String>();
names.add(district.getName());
if(district.getAlias() != null){
for(String alia : district.getAlias()){
if(StringUtils.isNotBlank(alia) && !names.contains(alia)){
if (district.getAlias() != null) {
for (String alia : district.getAlias()) {
if (StringUtils.isNotBlank(alia) && !names.contains(alia)) {
names.add(alia);
}
}
}
List<Seawater> houses = seawaterDao.findSeawatersFromEs("sell", district.getCity(), district.getRegion(), district.getName(), district.getAlias(), null, model.getStartTime(), model.getEndTime(),null,null,minPrice, maxPrice,null,null,"p_date", false,0, model.getPageSize(),"latest_seawater");
List<Seawater> houses = seawaterDao.findSeawatersFromEs("sell", district.getCity(), district.getRegion(), district.getName(), district.getAlias(), null, model.getStartTime(), model.getEndTime(), null, null, minPrice, maxPrice, null, null, "p_date", false, 0, model.getPageSize(), "latest_seawater");
//List<Seawater> houses1 = seawaterDao.findHouses(district.getCity(), district.getRegion(), names, minPrice, maxPrice, model.getPageSize());
mav.setModel(BasicModel.buildOKModel().setResult(houses));
return mav;
}
public Object arroundlistAction(final HouseSearchModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
@@ -578,17 +578,17 @@ public class HouseController {
}
District district = null;
DistrictKey districtKey = null;
if(StringUtils.isNotBlank(model.getName())){
if (StringUtils.isNotBlank(model.getName())) {
districtKey = new DistrictKey(model.getCity(), model.getRegion(), model.getName());
district = districtService.findDistrict(districtKey, "district");
}else{
} else {
district = districtService.findDistrictById(model.getId());
if(district!=null){
if (district != null) {
districtKey = new DistrictKey(district.getCity(), district.getRegion(), district.getName());
}
}
if(district == null){
if (district == null) {
mav.setModel(BasicModel.buildBadRequestModel("该小区不存在"));
return mav;
}
@@ -596,26 +596,26 @@ public class HouseController {
//周边小区,默认10
List<District> districts = districtService.findNearestDistrict(district, 1000, model.getDistCount());
List<Seawater> houses = new ArrayList<Seawater>();
for(District dist : districts){
for (District dist : districts) {
districtKey = new DistrictKey(dist.getCity(), dist.getRegion(), dist.getName());
DistrictStatBo bo = districtStatService.findCurrentDistrictStat(districtKey);
Integer minPrice = null;
Integer maxPrice = null;
if(bo.getDistrictStat()!=null){
minPrice = (int)(bo.getDistrictStat().getAvgPrice() * 0.9);
maxPrice = (int)(bo.getDistrictStat().getAvgPrice() * 1.1);
if (bo.getDistrictStat() != null) {
minPrice = (int) (bo.getDistrictStat().getAvgPrice() * 0.9);
maxPrice = (int) (bo.getDistrictStat().getAvgPrice() * 1.1);
}
List<String> names = new ArrayList<String>();
names.add(district.getName());
if(district.getAlias() != null){
for(String alia : district.getAlias()){
if(StringUtils.isNotBlank(alia) && !names.contains(alia)){
if (district.getAlias() != null) {
for (String alia : district.getAlias()) {
if (StringUtils.isNotBlank(alia) && !names.contains(alia)) {
names.add(alia);
}
}
}
List<Seawater> arroundhouses = seawaterDao.findSeawatersFromEs("sell", dist.getCity(), dist.getRegion(), dist.getName(), dist.getAlias(), null, model.getStartTime(), model.getEndTime(),null,null,minPrice, maxPrice,null,null,"p_date", false,0, model.getPageSize(),"latest_seawater");
if(arroundhouses!=null && arroundhouses.size()>0){
List<Seawater> arroundhouses = seawaterDao.findSeawatersFromEs("sell", dist.getCity(), dist.getRegion(), dist.getName(), dist.getAlias(), null, model.getStartTime(), model.getEndTime(), null, null, minPrice, maxPrice, null, null, "p_date", false, 0, model.getPageSize(), "latest_seawater");
if (arroundhouses != null && arroundhouses.size() > 0) {
houses.addAll(arroundhouses);
}
}
@@ -628,7 +628,7 @@ public class HouseController {
urls.add(url);
return url;
}
for (int i = 0;; i++) {
for (int i = 0; ; i++) {
String newName = url + "_" + i;
if (!urls.contains(newName)) {
return url;
@@ -636,7 +636,7 @@ public class HouseController {
}
}
private House createHouse(HousePublishModel model, Integer userId){
private House createHouse(HousePublishModel model, Integer userId) {
House house = new House();
house.setSource("api");
house.setUserId(userId);
@@ -656,7 +656,7 @@ public class HouseController {
house.setHeight(model.getMaxFloor());
house.setFitment(model.getFitment());
house.setDirection(model.getDirection());
house.setTotalPrice((int)(model.getTotalPrice() * 10000));
house.setTotalPrice((int) (model.getTotalPrice() * 10000));
house.setArea(model.getSize());
house.setRoom(model.getRoom());
house.setHall(model.getHall());
@@ -677,10 +677,10 @@ public class HouseController {
mav.setViewType("rest");
Map<String, Object> resMap = new LinkedHashMap<String, Object>();
if(StringUtils.isBlank(model.getCity()) || model.getTotalPrice() == null) {
if (StringUtils.isBlank(model.getCity()) || model.getTotalPrice() == null) {
mav.setModel(BasicModel.buildBadRequestModel("必填参数错误"));
return mav;
}else {
} else {
double[] compArrs = compareTotalPrice(model.getCity(), model.getTotalPrice());
if (compArrs == null) {
resMap.put("rank", 0);
@@ -696,8 +696,9 @@ public class HouseController {
public static final int VALUE_SKIP = 100;
private double[] compareTotalPrice(String city, int totalPrice) {
if(StringUtils.isBlank(city) || totalPrice <= 1000) {
if (StringUtils.isBlank(city) || totalPrice <= 1000) {
return null;
}
@@ -718,10 +719,10 @@ public class HouseController {
int totalCount = 0;
Map<String, Integer> rangeMap = new HashMap<String, Integer>();
for(FacetResult ft : facetQueryResult) {
if("total_price_range".equals(ft.getName()) && ft.getValues() != null) {
for(FacetResult.Count c : ft.getValues()) {
rangeMap.put(c.getName(), (int)c.getCount());
for (FacetResult ft : facetQueryResult) {
if ("total_price_range".equals(ft.getName()) && ft.getValues() != null) {
for (FacetResult.Count c : ft.getValues()) {
rangeMap.put(c.getName(), (int) c.getCount());
totalCount += c.getCount();
}
}
@@ -733,12 +734,12 @@ public class HouseController {
//房源的最大最小值
Integer[] extrmeValue = houseService.findExtremeTotalPrice(city, null);
if(extrmeValue == null) {
if (extrmeValue == null) {
return null;
}
List<Item> items = menuService.getItems(ServerAreaData.getServerAreaByDisplay(city), MenuCategoryEnum.ershoufang, "totalPriceRange");
for(Item item : items) {
for (Item item : items) {
String[] vals = item.getValue().split("_");
if (vals == null || vals.length == 0) {
continue;
@@ -755,7 +756,7 @@ public class HouseController {
itemValue = new Value(Integer.parseInt(vals[0]), Integer.parseInt(vals[1]), item.getValue());
}
}
if(itemValue.getMin() == 0 && extrmeValue[0] < itemValue.getMax()) {
if (itemValue.getMin() == 0 && extrmeValue[0] < itemValue.getMax()) {
itemValue.setMin(extrmeValue[0]);
}
@@ -764,11 +765,11 @@ public class HouseController {
inthisValue.setName(item.getName());
}
if(itemValue.getMax() < totalPrice) {
if (itemValue.getMax() < totalPrice) {
baseLessThan += (rangeMap.containsKey(item.getName()) ? rangeMap.get(item.getName()) : 0);
}
if(itemValue.getMin() > totalPrice) {
if (itemValue.getMin() > totalPrice) {
baseGreaterThan += (rangeMap.containsKey(item.getName()) ? rangeMap.get(item.getName()) : 0);
}
} catch (Exception e) {
@@ -776,15 +777,15 @@ public class HouseController {
}
}
if(inthisValue != null) {
double p = ((totalPrice - inthisValue.getMin()) / (double)VALUE_SKIP) / ((inthisValue.getMax() - inthisValue.getMin()) / (double)VALUE_SKIP);
if(rangeMap.containsKey(inthisValue.getName())) {
if (inthisValue != null) {
double p = ((totalPrice - inthisValue.getMin()) / (double) VALUE_SKIP) / ((inthisValue.getMax() - inthisValue.getMin()) / (double) VALUE_SKIP);
if (rangeMap.containsKey(inthisValue.getName())) {
baseLessThan += p * rangeMap.get(inthisValue.getName());
baseGreaterThan += ((1.0 - p) * rangeMap.get(inthisValue.getName()));
}
}
return new double[]{(int)((double)baseLessThan / (double)totalCount * 10000) / 100.0, (int)((double)baseGreaterThan / (double)totalCount * 10000) / 100.0};
return new double[]{(int) ((double) baseLessThan / (double) totalCount * 10000) / 100.0, (int) ((double) baseGreaterThan / (double) totalCount * 10000) / 100.0};
}
@Authority(role = Role.USER)
@@ -860,7 +861,7 @@ public class HouseController {
}
List<District> districts = districtService.findSimilarityDistrict(district, 1000, 3);// 查找一公里以内相似的小区
for (District d : districts) {
d = districtService.findById(d.getId() , INCLUDE_DISTRICT_FIELDS);
d = districtService.findById(d.getId(), INCLUDE_DISTRICT_FIELDS);
if (getRemainUseYear(district) == null) {
continue;
}
@@ -879,7 +880,7 @@ public class HouseController {
if (houseBoList.size() > 5) {
houseBoList = new FacetQueryResult<HousePojo>(houseBoList.subList(0, 5));
}
if(houseBoList.isEmpty()){
if (houseBoList.isEmpty()) {
BasicModel.markNoDataRequest();
}
resMap.put("totalCount", houseBoList.size());
@@ -889,31 +890,143 @@ public class HouseController {
return mav;
}
@Authority(role = Role.USER)
public Object aroundAction(final HouseSearchModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
if (StringUtils.isBlank(model.getLocation())) {
mav.setModel(BasicModel.buildBadRequestModel("location(经纬度)不能为空"));
return mav;
}
model.setLocation(model.getLocation().replace(",", ","));
if (StringUtils.isBlank(model.getLocation()) || !model.getLocation().contains(",")) {
mav.setModel(BasicModel.buildBadRequestModel("location(经纬度)不能为空或格式错误"));
return mav;
}
String[] locationStr = model.getLocation().split(",");
Double lng = Double.valueOf(locationStr[0]);
Double lat = Double.valueOf(locationStr[1]);
if ("2".equals(model.getLocationType())) {
Map<String, Double> gcj02Location = GeoUtils.bd09ToGcj02(lat, lng);
lng = gcj02Location.get("lng");
lat = gcj02Location.get("lat");
}
if (lng < 70 || lng > 140 || lat < 0 || lat > 55) {
mav.setModel(BasicModel.buildBadRequestModel("非中国经纬度"));
return mav;
}
String category = "district";
if ("1".equals(model.getPropertyType())) {
category = "office";
} else if ("2".equals(model.getPropertyType())) {
category = "shop";
}
public Object caseAction(@Valid SampleQuery sampleQuery){
List<Seaweed> seaweedList = seaweedService.findSeaweedByLocation(lat, lng, 3000, category);
if (seaweedList == null || seaweedList.isEmpty()) {
mav.setModel(BasicModel.buildBadRequestModel("没有找到相关的楼盘"));
return mav;
}
String cat = "sell";
if ("1".equals(model.getHouseType())) {
if ("0".equals(model.getPropertyType())) {
cat = "rent";
}
if ("1".equals(model.getPropertyType())) {
cat = "office_rent";
}
if ("2".equals(model.getPropertyType())) {
cat = "shop_rent";
}
} else {
if ("1".equals(model.getPropertyType())) {
cat = "office_sell";
}
if ("2".equals(model.getPropertyType())) {
cat = "shop_sell";
}
}
List<Seawater> houses;
List<Seawater> houseList = new ArrayList<Seawater>();
for (Seaweed seaweed : seaweedList) {
if (model.getSize() != null && model.getSize() != 0) {
Double size = model.getSize();
houses = seawaterDao.findSeawatersFromEs(cat, seaweed.getCity(), seaweed.getRegion(), seaweed.getName(), seaweed.getAlias(), null,
model.getStartTime(), model.getEndTime(), 0.9 * size, 1.1 * size, null, null, null, null,
"p_date", false, 0, 5, "latest_seawater");
} else {
houses = seawaterDao.findSeawatersFromEs(cat, seaweed.getCity(), seaweed.getRegion(), seaweed.getName(), seaweed.getAlias(), null,
model.getStartTime(), model.getEndTime(), null, null, null, null, null, null,
"p_date", false, 0, 5, "latest_seawater");
}
for (Seawater house : houses) {
Seawater seawater = new Seawater();
seawater.setCity(house.getCity());
seawater.setDistrict(house.getRegion());
seawater.setAddress(house.getAddress());
seawater.setName(house.getDistrictName());
seawater.setSize(house.getArea());
seawater.setUnitPrice(house.getAvgPrice());
seawater.setTotalPrice(house.getTotalPrice());
seawater.setDirection(house.getDirection());
seawater.setFloor(house.getFloor());
seawater.setMaxFloor(house.getHeight());
seawater.setRoom(house.getRoom());
seawater.setHall(house.getHall());
seawater.setToilet(house.getToilet());
seawater.setDecoration(house.getFitment());
if (house.getpDate() != null && house.getpDate() > 10000000) {
String numberStr = String.valueOf(house.getpDate());
// 拆分字符串并格式化
String year = numberStr.substring(0, 4); // 前四位是年份
String month = numberStr.substring(4, 6); // 中间两位是月份
String day = numberStr.substring(6, 8); // 最后两位是日期
String formattedDate = year + "-" + month + "-" + day;
seawater.setPublishDate(formattedDate);
}
if (houseList.size() > 4) {
break;
}
houseList.add(seawater);
}
if (houseList.size() > 4) {
break;
}
}
BasicModel basicModel = new BasicModel(200, "ok");
// 组装数据
basicModel.setResult(houseList);
mav.setModel(basicModel);
mav.setViewType("rest");
return mav;
}
public Object caseAction(@Valid SampleQuery sampleQuery) {
RestfulModelAndView mav = new RestfulModelAndView();
List<CollateralSampleQueryBean> querys = null;
try{
try {
querys = convertSampileQueryToBean(sampleQuery);
}catch (Exception e){
} catch (Exception e) {
mav.setModel(BasicModel.buildBadRequestModel(e.getMessage()));
return mav;
}
if(null == sampleQuery.getMax()){
if (null == sampleQuery.getMax()) {
sampleQuery.setMax(10);
}
long start = System.currentTimeMillis();
List<Collateral> collaterals = czbankSampleService.findSample2(querys, sampleQuery.getMax());
long end = System.currentTimeMillis();
System.out.println("用时:"+(end-start));
System.out.println("用时:" + (end - start));
Collateral collateral = collaterals.get(0);
List<Sample> samples = collateral.getSample();
UniversalDto dto = UniversalDto.newDto();
if(null != collateral.getMaxPrice()){
if (null != collateral.getMaxPrice()) {
dto.append("maxUnitPrice", collateral.getMaxPrice());
}
if(null != collateral.getMinPrice()){
if (null != collateral.getMinPrice()) {
dto.append("minUnitPrice", collateral.getMinPrice());
}
@@ -935,8 +1048,6 @@ public class HouseController {
}
private List<HousePojo> fillDistrictInfoForHouse(FacetQueryResult<com.fangjia.service.bo.HouseBo> houseList, Date endDate,
District district, boolean showDetail, boolean matchModel) {
FacetQueryResult<HousePojo> list = new FacetQueryResult<HousePojo>();
@@ -977,7 +1088,7 @@ public class HouseController {
}
String buildDate = null, remainUseYear = null;
if (district.getBuildDate() != null || district.getFinishBuildingDate() != null || district.getLiveDate() != null || district.getOpenDate() != null) {
Integer minYear = getBuildYear(district.getFinishBuildingDate(), district.getLiveDate(), district.getBuildDate(),district.getOpenDate());
Integer minYear = getBuildYear(district.getFinishBuildingDate(), district.getLiveDate(), district.getBuildDate(), district.getOpenDate());
if (minYear != null && minYear > 0) {
buildDate = minYear + "年";
if (getHouseUseYear(minYear, district.getPropertyLife()) != null) {
@@ -1094,13 +1205,13 @@ public class HouseController {
List<Date> months = DateUtil.getMonthList(new Date(), 6);
Date endMonthStartDate = DateUtil.getFirstDayOfMonth(months.get(0));
long diffDay = (publishDate.getTime() - endMonthStartDate.getTime()) / (long)(24 * 3600 * 1000);
long diffDay = (publishDate.getTime() - endMonthStartDate.getTime()) / (long) (24 * 3600 * 1000);
int df = (int) ((173 - diffDay) * 0.5);
if(df <= 0) {
if (df <= 0) {
df = 1;
}
Date ret = DateUtil.getBeforeDay(endDate, (int)df);
Date ret = DateUtil.getBeforeDay(endDate, (int) df);
return ret;
}
@@ -1498,14 +1609,14 @@ public class HouseController {
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) {
@@ -1517,28 +1628,28 @@ public class HouseController {
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;
}
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){
if (shengYuYear > 0 && shengYuYear <= 70) {
Integer year = extractYear(s);
if(year !=null && year > 0 && year <= 70){
if (year != null && year > 0 && year <= 70) {
int useYear = year - shengYuYear;
if(year > 0 && year <= 70){
if (year > 0 && year <= 70) {
return useYear;
}
@@ -1676,10 +1787,10 @@ public class HouseController {
}
private Integer getRemainUseYear(District district) {
if("苏州".equals(district.getCity())){
if("商住".equals(district.getEstateType2())){
if ("苏州".equals(district.getCity())) {
if ("商住".equals(district.getEstateType2())) {
district.setPropertyLife("47");
}else{
} else {
district.setPropertyLife("67");
}
}
@@ -1701,4 +1812,7 @@ public class HouseController {
this.fangjiaOfficialAreaService = fangjiaOfficialAreaService;
}
public void setSeaweedService(SeaweedService seaweedService) {
this.seaweedService = seaweedService;
}
}
@@ -13,6 +13,16 @@ public class HouseSearchModel extends SearchModel {
private String unitNo;
private Double size;
private Boolean showDetail;
private String city;
private String location;
private String locationType;
private String propertyType;
private String houseType;
@Override
public QueryBean getQueryBean() {
HouseQueryBean queryBean = new HouseQueryBean();
@@ -125,4 +135,46 @@ public class HouseSearchModel extends SearchModel {
public void setId(String id) {
this.id = id;
}
@Override
public String getCity() {
return city;
}
@Override
public void setCity(String city) {
this.city = city;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getLocationType() {
return locationType;
}
public void setLocationType(String locationType) {
this.locationType = locationType;
}
public String getPropertyType() {
return propertyType;
}
public void setPropertyType(String propertyType) {
this.propertyType = propertyType;
}
public String getHouseType() {
return houseType;
}
public void setHouseType(String houseType) {
this.houseType = houseType;
}
}
@@ -1535,15 +1535,23 @@ public class DistrictServiceImpl implements DistrictService {
List<District> ret = new ArrayList<District>();
for (District d : districts) {
if (null == d.getLat2() || null == d.getLng2()) {
if (d.getLat2() == null || d.getLng2() == null) {
continue;
}
double dis = GeoUtils.calculateDistance(lng, lat, d.getLng() / 10000000000.0, d.getLat() / 10000000000.0);
if (dis <= radius) {
d.setScore(dis); // Assuming District has a `distance` field to store the calculated distance.
ret.add(d);
}
}
Collections.sort(ret, new Comparator<District>() {
@Override
public int compare(District d1, District d2) {
return Double.compare(d1.getScore(), d2.getScore());
}
});
return ret;
}
@@ -0,0 +1,13 @@
package com.fangjia.service.datastore;
import com.fangjia.dal.QueryParam;
import com.fangjia.dal.common.DistrictKey;
import com.fangjia.dal.seaweed.model.Seaweed;
import com.fangjia.dal.seaweed.model.Shop;
import java.util.List;
public interface SeaweedService {
List<Seaweed> findSeaweedByLocation(double lat, double lng, double radius,String cat,int limit);
List<Seaweed> findSeaweedByLocation(double lat, double lng, double radius,String cat);
}
@@ -0,0 +1,102 @@
package com.fangjia.service.datastore;
import com.fangjia.core.util.CacheUtils;
import com.fangjia.core.util.CacheUtils.CachePolicyEnum;
import com.fangjia.core.util.GeoUtils;
import com.fangjia.dal.QueryParam;
import com.fangjia.dal.common.DistrictKey;
import com.fangjia.dal.seaweed.dao.SeaweedDao;
import com.fangjia.dal.seaweed.dao.ShopDao;
import com.fangjia.dal.seaweed.model.District;
import com.fangjia.dal.seaweed.model.Seaweed;
import com.fangjia.dal.seaweed.model.Shop;
import com.fangjia.service.index.BoostQueryPolicy;
import org.apache.commons.lang.StringUtils;
import org.sothis.core.util.Closure;
import org.sothis.core.util.CollectionUtils;
import java.util.*;
public class SeaweedServiceImpl implements SeaweedService {
private SeaweedDao seaweedDao;
@Override
public List<Seaweed> findSeaweedByLocation(double lat, double lng, double radius,String cat,int limit) {
double[] latlngs = GeoUtils.getAround(lat, lng, radius);
List<QueryParam> params = new ArrayList<QueryParam>();
params.add(new QueryParam("category", cat));
params.add(new QueryParam("status", 0));
params.add(new QueryParam("lat", QueryParam.GREATER_THAN_EQUAL_OPERATOR, latlngs[0] * 10000000000d));
params.add(new QueryParam("lat", QueryParam.LESS_THAN_EQUAL_OPERATOR, latlngs[1] * 10000000000d));
params.add(new QueryParam("lng", QueryParam.GREATER_THAN_EQUAL_OPERATOR, latlngs[2] * 10000000000d));
params.add(new QueryParam("lng", QueryParam.LESS_THAN_EQUAL_OPERATOR, latlngs[3] * 10000000000d));
List<Seaweed> seaweeds = seaweedDao.findAllByParams(params,limit);
if (CollectionUtils.isEmpty(seaweeds)) {
return Collections.emptyList();
}
List<Seaweed> ret = new ArrayList<Seaweed>();
for (Seaweed d : seaweeds) {
if (d.getLat() == null || d.getLng() == null) {
continue;
}
double dis = GeoUtils.calculateDistance(lng, lat, d.getLng() / 10000000000.0, d.getLat() / 10000000000.0);
if (dis <= radius) {
d.setScore(dis); // Assuming District has a `distance` field to store the calculated distance.
ret.add(d);
}
}
Collections.sort(ret, new Comparator<Seaweed>() {
@Override
public int compare(Seaweed d1, Seaweed d2) {
return Double.compare(d1.getScore(), d2.getScore());
}
});
return ret;
}
@Override
public List<Seaweed> findSeaweedByLocation(double lat, double lng, double radius, String cat) {
double[] latlngs = GeoUtils.getAround(lat, lng, radius);
List<QueryParam> params = new ArrayList<QueryParam>();
params.add(new QueryParam("category", cat));
params.add(new QueryParam("status", 0));
params.add(new QueryParam("lat", QueryParam.GREATER_THAN_EQUAL_OPERATOR, latlngs[0] * 10000000000d));
params.add(new QueryParam("lat", QueryParam.LESS_THAN_EQUAL_OPERATOR, latlngs[1] * 10000000000d));
params.add(new QueryParam("lng", QueryParam.GREATER_THAN_EQUAL_OPERATOR, latlngs[2] * 10000000000d));
params.add(new QueryParam("lng", QueryParam.LESS_THAN_EQUAL_OPERATOR, latlngs[3] * 10000000000d));
List<Seaweed> seaweeds = seaweedDao.findAllByParams(params);
if (CollectionUtils.isEmpty(seaweeds)) {
return Collections.emptyList();
}
List<Seaweed> ret = new ArrayList<Seaweed>();
for (Seaweed d : seaweeds) {
if (d.getLat() == null || d.getLng() == null) {
continue;
}
double dis = GeoUtils.calculateDistance(lng, lat, d.getLng() / 10000000000.0, d.getLat() / 10000000000.0);
if (dis <= radius) {
d.setScore(dis); // Assuming District has a `distance` field to store the calculated distance.
ret.add(d);
}
}
Collections.sort(ret, new Comparator<Seaweed>() {
@Override
public int compare(Seaweed d1, Seaweed d2) {
return Double.compare(d1.getScore(), d2.getScore());
}
});
return ret;
}
public void setSeaweedDao(SeaweedDao seaweedDao) {
this.seaweedDao = seaweedDao;
}
}