新增写字楼接口
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
package com.fangjia.dal.mongo.dao.office;
|
||||
|
||||
import com.fangjia.dal.MongoDao;
|
||||
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||
import com.fangjia.dal.mongo.model.RegionStat;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface OfficeRentStatDao extends MongoDao<OfficeRentStat> {
|
||||
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.fangjia.dal.mongo.dao.office;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fangjia.dal.mongo.dao.RegionStatDao;
|
||||
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.fangjia.core.util.DateUtil;
|
||||
import com.fangjia.dal.MongoDaoImpl;
|
||||
import com.fangjia.dal.QueryParam;
|
||||
import com.fangjia.dal.SortParam;
|
||||
import com.fangjia.dal.mongo.model.RegionStat;
|
||||
|
||||
public class OfficeRentStatDaoImpl extends MongoDaoImpl<OfficeRentStat> implements OfficeRentStatDao {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.fangjia.dal.mongo.model;
|
||||
|
||||
import com.fangjia.dal.MongoEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Table(name = "fangjia_stat.office_rent_stat")
|
||||
public class OfficeRentStat implements MongoEntity {
|
||||
private static final long serialVersionUID = 4425229045088250573L;
|
||||
|
||||
private String id;
|
||||
private String cat;
|
||||
private String city;
|
||||
private String district;
|
||||
private Integer date;
|
||||
private Double avgPrice;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "_id", unique = true, nullable = false)
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "cat")
|
||||
public String getCat() {
|
||||
return cat;
|
||||
}
|
||||
|
||||
public void setCat(String cat) {
|
||||
this.cat = cat;
|
||||
}
|
||||
|
||||
@Column(name = "city")
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
@Column(name = "district")
|
||||
public String getDistrict() {
|
||||
return district;
|
||||
}
|
||||
|
||||
public void setDistrict(String district) {
|
||||
this.district = district;
|
||||
}
|
||||
|
||||
@Column(name = "date")
|
||||
public Integer getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Integer date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
@Column(name = "avg_price")
|
||||
public Double getAvgPrice() {
|
||||
return avgPrice;
|
||||
}
|
||||
|
||||
public void setAvgPrice(Double avgPrice) {
|
||||
this.avgPrice = avgPrice;
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package com.fangjia.open.controllers;
|
||||
|
||||
import com.fangjia.core.RegionData;
|
||||
import com.fangjia.core.util.LoggerFactory;
|
||||
import com.fangjia.dal.common.ServerAreaData;
|
||||
import com.fangjia.dal.mongo.fangjia.model.ServerArea;
|
||||
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||
import com.fangjia.open.HttpCode;
|
||||
import com.fangjia.open.OpenHttpCodeEnum;
|
||||
import com.fangjia.open.interceptors.Authority;
|
||||
import com.fangjia.open.interceptors.Role;
|
||||
import com.fangjia.open.model.BasicModel;
|
||||
import com.fangjia.open.model.RestfulModelAndView;
|
||||
import com.fangjia.service.datastore.OfficeService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.sothis.web.mvc.annotation.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author shenjian
|
||||
* @since 2025/1/21
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public class OfficeController {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PropertyController.class);
|
||||
|
||||
private OfficeService officeService;
|
||||
|
||||
/**
|
||||
* 城市出租均价
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object cityRentAction(@Param(name = "city") String city, @Param(name = "startDate") Integer startDate, @Param(name = "endDate") Integer endDate) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(city)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city不能为null"));
|
||||
return mav;
|
||||
}
|
||||
if (!RegionData.isCity(city)) {
|
||||
String formatCity = RegionData.formatCity(city);
|
||||
if (StringUtils.isNotBlank(formatCity)) {
|
||||
city = formatCity;
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city非法"));
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
ServerArea serverArea = ServerAreaData.getServerAreaByCity(city);
|
||||
if (null == serverArea) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city非法"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
if (startDate == null || endDate == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("startDate或endDate不能为null"));
|
||||
return mav;
|
||||
}
|
||||
if (startDate > endDate) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("startDate不能大于endDate"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
List<OfficeRentStat> regionStats = officeService.findOfficeRentStat(city, null, startDate, endDate);
|
||||
|
||||
if (CollectionUtils.isEmpty(regionStats)) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "该城市没有均价数据"));
|
||||
return mav;
|
||||
}
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(regionStats));
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 区域出租均价
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object districtRentAction(@Param(name = "city") String city, @Param(name = "district") String district,
|
||||
@Param(name = "startDate") Integer startDate, @Param(name = "endDate") Integer endDate) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(city)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city不能为null"));
|
||||
return mav;
|
||||
}
|
||||
if (!RegionData.isCity(city)) {
|
||||
String formatCity = RegionData.formatCity(city);
|
||||
if (StringUtils.isNotBlank(formatCity)) {
|
||||
city = formatCity;
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city非法"));
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
ServerArea serverArea = ServerAreaData.getServerAreaByCity(city);
|
||||
if (null == serverArea) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city非法"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
if (startDate == null || endDate == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("startDate或endDate不能为null"));
|
||||
return mav;
|
||||
}
|
||||
if (startDate > endDate) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("startDate不能大于endDate"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
List<OfficeRentStat> regionStats = officeService.findOfficeRentStat(city, district, startDate, endDate);
|
||||
|
||||
if (CollectionUtils.isEmpty(regionStats)) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "该城市没有均价数据"));
|
||||
return mav;
|
||||
}
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(regionStats));
|
||||
return mav;
|
||||
}
|
||||
|
||||
public void setOfficeService(OfficeService officeService) {
|
||||
this.officeService = officeService;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.fangjia.service.datastore;
|
||||
|
||||
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author shenjian
|
||||
* @since 2025/1/21
|
||||
*/
|
||||
public interface OfficeService {
|
||||
|
||||
|
||||
/**
|
||||
* @param city
|
||||
* @param region
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
List<OfficeRentStat> findOfficeRentStat(final String city, final String region, final Integer startDate, final Integer endDate);
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.fangjia.service.datastore;
|
||||
|
||||
import com.fangjia.core.util.CacheUtils;
|
||||
import com.fangjia.dal.QueryParam;
|
||||
import com.fangjia.dal.SortParam;
|
||||
import com.fangjia.dal.mongo.dao.office.OfficeRentStatDao;
|
||||
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||
import org.sothis.core.util.Closure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author shenjian
|
||||
* @since 2025/1/21
|
||||
*/
|
||||
public class OfficeServiceImpl implements OfficeService {
|
||||
|
||||
private OfficeRentStatDao officeRentStatDao;
|
||||
|
||||
public List<OfficeRentStat> findOfficeRentStat(final String city, final String region, final Integer startDate, final Integer endDate) {
|
||||
return CacheUtils.getValue(this.getClass(), "findOfficeRentStat", city + region + startDate + endDate,
|
||||
CacheUtils.CachePolicyEnum.MIDDLE, new Closure<List<OfficeRentStat>, String>() {
|
||||
public List<OfficeRentStat> execute(String input) {
|
||||
return doFindRegionBlockStat(city, region, startDate, endDate);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<OfficeRentStat> doFindRegionBlockStat(final String city, final String region, Integer startDate, Integer endDate) {
|
||||
if (startDate == null) {
|
||||
throw new IllegalArgumentException("开始日期不能为空");
|
||||
}
|
||||
if (endDate == null) {
|
||||
throw new IllegalArgumentException("结束日期不能为空");
|
||||
}
|
||||
|
||||
List<QueryParam> params = new ArrayList<QueryParam>();
|
||||
params.add(new QueryParam("city", city));
|
||||
params.add(new QueryParam("district", region));
|
||||
|
||||
if (startDate != null) {
|
||||
params.add(new QueryParam("date", QueryParam.GREATER_THAN_EQUAL_OPERATOR, startDate));
|
||||
}
|
||||
if (endDate != null) {
|
||||
params.add(new QueryParam("date", QueryParam.LESS_THAN_EQUAL_OPERATOR, endDate));
|
||||
}
|
||||
List<SortParam> sortParams = new ArrayList<SortParam>();
|
||||
sortParams.add(new SortParam("date", true));
|
||||
List<OfficeRentStat> regionStats = officeRentStatDao.findAllByParams(params, sortParams);
|
||||
return regionStats;
|
||||
}
|
||||
|
||||
public void setOfficeRentStatDao(OfficeRentStatDao officeRentStatDao) {
|
||||
this.officeRentStatDao = officeRentStatDao;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user