接口优化
This commit is contained in:
@@ -0,0 +1,202 @@
|
|||||||
|
package com.fangjia.core.util;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class SeaweedUtils {
|
||||||
|
public static void main(String[] args){
|
||||||
|
System.out.println(formatVirescencePercent("1"));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 标准化输出绿化率
|
||||||
|
*/
|
||||||
|
public static String formatVirescencePercent(String virescence_percent) {
|
||||||
|
// 绿化率
|
||||||
|
if (StringUtils.isNotBlank(virescence_percent) && checkValue(virescence_percent)!=null) {
|
||||||
|
double val = Double.valueOf(virescence_percent);
|
||||||
|
if (val < 1) {
|
||||||
|
return String.valueOf(val * 100);
|
||||||
|
}
|
||||||
|
if (val == 1) {
|
||||||
|
return String.valueOf(val * 10);
|
||||||
|
}
|
||||||
|
if (val >= 70) {
|
||||||
|
return "65";
|
||||||
|
}
|
||||||
|
return String.valueOf(val);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准化容积率输出
|
||||||
|
*/
|
||||||
|
public static String formatCubagePercent(String cubage_percent) {
|
||||||
|
if (StringUtils.isNotBlank(cubage_percent) && checkValue(cubage_percent)!=null) {
|
||||||
|
double val = Double.valueOf(cubage_percent);
|
||||||
|
if (val >= 7 && val < 8) {
|
||||||
|
return "6.2";
|
||||||
|
}
|
||||||
|
if (val >= 8 && val < 9) {
|
||||||
|
return "6.3";
|
||||||
|
}
|
||||||
|
if (val >= 9 && val < 10) {
|
||||||
|
return "6.5";
|
||||||
|
}
|
||||||
|
if (val >= 10) {
|
||||||
|
return "6.7";
|
||||||
|
}
|
||||||
|
return String.valueOf(val);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准化车位输出
|
||||||
|
*/
|
||||||
|
public static String formatCarSiteCount(String car_site_count) {
|
||||||
|
if (StringUtils.isNotBlank(car_site_count) && checkValue(car_site_count)!=null) {
|
||||||
|
long val = Long.valueOf(car_site_count);
|
||||||
|
if (val > 2500 || val < 100) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return String.valueOf(val);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准化户数输出
|
||||||
|
*/
|
||||||
|
public static String formatHouseholdCount(String household_count) {
|
||||||
|
if (StringUtils.isNotBlank(household_count) && checkValue(household_count)!=null ) {
|
||||||
|
if (Integer.valueOf(household_count) < 50) {
|
||||||
|
return null; // 户数
|
||||||
|
}
|
||||||
|
return household_count;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准化总占地面积输出
|
||||||
|
*/
|
||||||
|
public static String formatAllArea(String all_area) {
|
||||||
|
if (StringUtils.isNotBlank(all_area)) {
|
||||||
|
Double formattedVal = 0.0;
|
||||||
|
if (all_area.toString().indexOf("公顷") != -1) {
|
||||||
|
String val = all_area.toString();
|
||||||
|
formattedVal = (Double.valueOf(val.substring(0, val.indexOf("公顷"))) * 10000);
|
||||||
|
} else if(checkValue(all_area)!=null) {
|
||||||
|
formattedVal = Double.valueOf(all_area);
|
||||||
|
}
|
||||||
|
if (formattedVal > 100000 || formattedVal == 0.0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return String.valueOf(formattedVal);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取浮点数与整数
|
||||||
|
*/
|
||||||
|
static String getNumber(String input) {
|
||||||
|
Pattern pattern = Pattern.compile("\\d+(\\.\\d+)?");
|
||||||
|
Matcher matcher = pattern.matcher(input);
|
||||||
|
List<String> list = new ArrayList();
|
||||||
|
while (matcher.find()) {
|
||||||
|
list.add(matcher.group());
|
||||||
|
}
|
||||||
|
if(list.size()>0){
|
||||||
|
return list.get(0);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static Float checkValue(String value){
|
||||||
|
if(StringUtils.isNotBlank(value)){
|
||||||
|
value = getNumber(value);
|
||||||
|
if(StringUtils.isNotBlank(value)){
|
||||||
|
value = subZeroAndDot(value);
|
||||||
|
if(isNumber(value)){
|
||||||
|
Float v = Float.parseFloat(value);
|
||||||
|
if(v>0){
|
||||||
|
return v;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}else if(isFloat(value)){
|
||||||
|
Float v = Float.parseFloat(value);
|
||||||
|
if(v>0){
|
||||||
|
return v;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isNumber(String str){
|
||||||
|
try {
|
||||||
|
Integer.parseInt(str);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isFloat(String str){
|
||||||
|
try {
|
||||||
|
Float.parseFloat(str);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正则表达式去掉多余的.与0
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static String subZeroAndDot(String v){
|
||||||
|
|
||||||
|
if(StringUtils.isNotBlank(v)){
|
||||||
|
if(v.indexOf(".")!=-1){
|
||||||
|
Double myNum2 = Double.valueOf(v);
|
||||||
|
BigDecimal b = new java.math.BigDecimal(myNum2);
|
||||||
|
Double myNum3 = b.setScale(2, java.math.BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||||
|
v = myNum3.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(v.indexOf(".")>-1){
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
if(v.endsWith("0")){
|
||||||
|
v = v.substring(0,v.length()-1);
|
||||||
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(v.endsWith(".")){
|
||||||
|
v=v.substring(0,v.length()-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -99,6 +99,9 @@ public class PaiMai implements MongoEntity {
|
|||||||
private Integer marketAvgPrice;
|
private Integer marketAvgPrice;
|
||||||
/**物业类型*/
|
/**物业类型*/
|
||||||
private String matchEstateType;
|
private String matchEstateType;
|
||||||
|
private String houseNum;
|
||||||
|
private String unitNum;
|
||||||
|
private String roomNum;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
@@ -488,4 +491,28 @@ public class PaiMai implements MongoEntity {
|
|||||||
public void setMatchEstateType(String matchEstateType) {
|
public void setMatchEstateType(String matchEstateType) {
|
||||||
this.matchEstateType = matchEstateType;
|
this.matchEstateType = matchEstateType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHouseNum() {
|
||||||
|
return houseNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHouseNum(String houseNum) {
|
||||||
|
this.houseNum = houseNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUnitNum() {
|
||||||
|
return unitNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnitNum(String unitNum) {
|
||||||
|
this.unitNum = unitNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoomNum() {
|
||||||
|
return roomNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoomNum(String roomNum) {
|
||||||
|
this.roomNum = roomNum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+39
@@ -1,6 +1,7 @@
|
|||||||
package com.fangjia.open.controllers;
|
package com.fangjia.open.controllers;
|
||||||
|
|
||||||
import com.fangjia.core.util.DateUtil;
|
import com.fangjia.core.util.DateUtil;
|
||||||
|
import com.fangjia.core.util.HttpRequest;
|
||||||
import com.fangjia.dal.QueryParam;
|
import com.fangjia.dal.QueryParam;
|
||||||
import com.fangjia.dal.SortParam;
|
import com.fangjia.dal.SortParam;
|
||||||
import com.fangjia.dal.common.DistrictKey;
|
import com.fangjia.dal.common.DistrictKey;
|
||||||
@@ -14,6 +15,7 @@ import com.fangjia.open.model.BasicModel;
|
|||||||
import com.fangjia.open.model.RestfulModelAndView;
|
import com.fangjia.open.model.RestfulModelAndView;
|
||||||
import com.fangjia.service.fsh.DistrictNewPriceService;
|
import com.fangjia.service.fsh.DistrictNewPriceService;
|
||||||
import com.fangjia.service.open.PaiMaiService;
|
import com.fangjia.service.open.PaiMaiService;
|
||||||
|
import net.sf.json.JSONObject;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
@@ -204,10 +206,47 @@ public class AuctionController {
|
|||||||
List<SortParam> sortParams = new ArrayList<SortParam>();
|
List<SortParam> sortParams = new ArrayList<SortParam>();
|
||||||
sortParams.add(new SortParam("startDate", false));
|
sortParams.add(new SortParam("startDate", false));
|
||||||
List<PaiMai> paimais = paiMaiService.findAll(params, sortParams, model.getLimit(), SEARCH_FIELDS);
|
List<PaiMai> paimais = paiMaiService.findAll(params, sortParams, model.getLimit(), SEARCH_FIELDS);
|
||||||
|
if(paimais!=null && paimais.size()>0){
|
||||||
|
for(PaiMai paiMai : paimais){
|
||||||
|
Map<String, Object> map = standard(paiMai.getCity(), paiMai.getAddress());
|
||||||
|
if(map!=null){
|
||||||
|
paiMai.setHouseNum((String) map.get("buildingNumber"));
|
||||||
|
paiMai.setUnitNum((String) map.get("unitNumber"));
|
||||||
|
paiMai.setRoomNum((String) map.get("roomNumber"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
mav.setModel(BasicModel.buildOKModel().setResult(paimais));
|
mav.setModel(BasicModel.buildOKModel().setResult(paimais));
|
||||||
return mav;
|
return mav;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Map standard(String city, String address){
|
||||||
|
HttpRequest request = new HttpRequest();
|
||||||
|
JSONObject json = null;
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("city", city);
|
||||||
|
params.put("address", address);
|
||||||
|
try{
|
||||||
|
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/structure", params, "UTF-8");
|
||||||
|
} catch(Exception e){
|
||||||
|
try {
|
||||||
|
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/structure", params, "UTF-8");
|
||||||
|
} catch(Exception ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json != null) {
|
||||||
|
int code = json.getInt("status");
|
||||||
|
String msg = json.getString("msg");
|
||||||
|
if(json.containsKey("result")){
|
||||||
|
return (Map)json.get("result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void setPaiMaiService(PaiMaiService paiMaiService) {
|
public void setPaiMaiService(PaiMaiService paiMaiService) {
|
||||||
this.paiMaiService = paiMaiService;
|
this.paiMaiService = paiMaiService;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -734,13 +734,13 @@ public class PropertyController {
|
|||||||
districtInfoDto.setCommunity(district.getStreetCommunity());
|
districtInfoDto.setCommunity(district.getStreetCommunity());
|
||||||
districtInfoDto.setCommercialArea(district.getBusinessQuarter());
|
districtInfoDto.setCommercialArea(district.getBusinessQuarter());
|
||||||
if (district.getHouseholdCount() != null) {
|
if (district.getHouseholdCount() != null) {
|
||||||
districtInfoDto.setTotalUnitCount(district.getHouseholdCount().toString());
|
districtInfoDto.setTotalUnitCount(SeaweedUtils.formatHouseholdCount(district.getHouseholdCount().toString()));
|
||||||
} else {
|
} else {
|
||||||
districtInfoDto.setTotalUnitCount("");
|
districtInfoDto.setTotalUnitCount("");
|
||||||
}
|
}
|
||||||
districtInfoDto.setManagementFee(district.getEstateCharge());
|
districtInfoDto.setManagementFee(district.getEstateCharge());
|
||||||
if (district.getCarSiteCount() != null) {
|
if (district.getCarSiteCount() != null) {
|
||||||
districtInfoDto.setParking(district.getCarSiteCount().toString());
|
districtInfoDto.setParking(SeaweedUtils.formatCarSiteCount(district.getCarSiteCount().toString()));
|
||||||
} else {
|
} else {
|
||||||
districtInfoDto.setParking("");
|
districtInfoDto.setParking("");
|
||||||
}
|
}
|
||||||
@@ -761,10 +761,10 @@ public class PropertyController {
|
|||||||
|
|
||||||
districtInfoDto.setFinishBuildTime(district.getFinishBuildingDate());
|
districtInfoDto.setFinishBuildTime(district.getFinishBuildingDate());
|
||||||
districtInfoDto.setMoveinTime(district.getLiveDate());
|
districtInfoDto.setMoveinTime(district.getLiveDate());
|
||||||
districtInfoDto.setFloorSpace(district.getAllArea());
|
districtInfoDto.setFloorSpace(SeaweedUtils.formatAllArea(district.getAllArea()));
|
||||||
districtInfoDto.setConstructionSpace(district.getBuildArea());
|
districtInfoDto.setConstructionSpace(district.getBuildArea());
|
||||||
districtInfoDto.setPlotRatio(district.getCubagePercent());
|
districtInfoDto.setPlotRatio(SeaweedUtils.formatCubagePercent(district.getCubagePercent()));
|
||||||
districtInfoDto.setGreenPercentage(district.getVirescencePercent());
|
districtInfoDto.setGreenPercentage(SeaweedUtils.formatVirescencePercent(district.getVirescencePercent()));
|
||||||
districtInfoDto.setPreSalePermit(district.getLicence());
|
districtInfoDto.setPreSalePermit(district.getLicence());
|
||||||
districtInfoDto.setDeveloper(district.getDeveloper());
|
districtInfoDto.setDeveloper(district.getDeveloper());
|
||||||
districtInfoDto.setDiscount(district.getDiscount());
|
districtInfoDto.setDiscount(district.getDiscount());
|
||||||
|
|||||||
Reference in New Issue
Block a user