API接口添加每次调用费用;涉农接口添加涉农标识计费
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.fangjia.dal.mongo.tool.model;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@@ -73,6 +74,7 @@ public class OpenUriLog implements MongoEntity {
|
||||
private Map<String, Object> resMap;
|
||||
private String parameterMaps;
|
||||
private String tid;
|
||||
private Double cost;
|
||||
|
||||
public String getParameterMaps() {
|
||||
return this.parameterMaps;
|
||||
@@ -238,6 +240,14 @@ public class OpenUriLog implements MongoEntity {
|
||||
this.tid = tid;
|
||||
}
|
||||
|
||||
@Column(name = "cost")
|
||||
public Double getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
public void setCost(Double cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -34,6 +34,7 @@ public class APIConstant {
|
||||
public static final long SUPER_USER_ID = 1007497l;
|
||||
|
||||
public static final String IS_RETURN_DATA = "IS_RETURN_DATA";
|
||||
public static final String API_COST_KEY = "api_cost_key";
|
||||
|
||||
static { // 初始化变量
|
||||
|
||||
|
||||
+16
-184
@@ -1,14 +1,11 @@
|
||||
package com.fangjia.open.controllers;
|
||||
|
||||
import com.fangjia.core.util.DataUtil;
|
||||
import com.fangjia.core.util.HttpRequest;
|
||||
import com.fangjia.dal.mongo.model.DistrictAnalyData;
|
||||
import com.fangjia.dal.mongo.model.Township;
|
||||
import com.fangjia.dal.mongo.model.VillageIdentify;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.open.APIConstant;
|
||||
import com.fangjia.open.FangjiaApiUtil;
|
||||
import com.fangjia.open.dto.UniversalDto;
|
||||
import com.fangjia.open.dto.addressGovernance.DistrictDto;
|
||||
import com.fangjia.open.dto.addressGovernance.DistrictIdentifyDto;
|
||||
import com.fangjia.open.dto.addressGovernance.MatchedBuildingDto;
|
||||
@@ -237,53 +234,6 @@ public class AddrSvcController {
|
||||
return mav;
|
||||
}
|
||||
|
||||
public Object valueRateAction(AddesssMatchModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
if (StringUtils.isBlank(model.getAddress())) {
|
||||
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("address", model.getAddress());
|
||||
params.put("category", "property");
|
||||
params.put("useMap", "false");
|
||||
params.put("district", model.getSuggestDistrict());
|
||||
try {
|
||||
//新匹配接口
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaNlpService/match", params, "UTF-8");
|
||||
UniversalDto dto = null;
|
||||
if (json != null && json.size() > 0 && json.containsKey("id")) {
|
||||
String commId = json.getString("id");
|
||||
if (StringUtils.isNotBlank(commId)) {
|
||||
DistrictAnalyData districtAnalyData = districtAnalyDataService.findByDistrictId(commId);
|
||||
if (districtAnalyData != null) {
|
||||
District district = districtService.findById(commId);
|
||||
dto = new UniversalDto();
|
||||
dto.append("city", districtAnalyData.getCity());
|
||||
dto.append("district", districtAnalyData.getRegion());
|
||||
dto.append("name", districtAnalyData.getDistrictName());
|
||||
dto.append("lng", DataUtil.roundDouble(district.getLng()/10000000000d, 6));
|
||||
dto.append("lat", DataUtil.roundDouble(district.getLat()/10000000000d, 6));
|
||||
dto.append("valueRate", districtAnalyData.getValueRate());
|
||||
dto.append("avgPrice", districtAnalyData.getAvgPrice());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dto == null) {
|
||||
mav.setModel(BasicModel.buildOKModel().markNoData());
|
||||
}else{
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(dto));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中..."));
|
||||
}
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 地址匹配
|
||||
*/
|
||||
@@ -564,18 +514,12 @@ public class AddrSvcController {
|
||||
//我们的结果
|
||||
JSONObject result = json.getJSONObject("result");
|
||||
//我们省级及以上有开发区,直接用我们的结果
|
||||
if (result.containsKey("devDistrictName") && StringUtils.isNotBlank(result.get("devDistrictName").toString())) {
|
||||
// basicModel.setResult(result);
|
||||
if(result.containsKey("countyGov") && StringUtils.isNotBlank(result.get("countyGov").toString())){
|
||||
result.put("countyGov","");
|
||||
}
|
||||
}
|
||||
basicModel.setResult(result);
|
||||
//齐梁现在无法调用
|
||||
/*else if (!"2".equals(type)) { // 对私的不用齐梁
|
||||
if (result.containsKey("devDistrictName")) {
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
else {
|
||||
|
||||
} else if (!"2".equals(type)) { // 对私的不用齐梁
|
||||
basicModel.setResult(result);
|
||||
} else {
|
||||
try {
|
||||
//如果是江苏省或者浙江省 调用齐梁的结果
|
||||
if (result.containsKey("province") && ("中国".equals(result.getString("province")))) {
|
||||
@@ -625,7 +569,7 @@ public class AddrSvcController {
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
mav.setModel(basicModel);
|
||||
@@ -982,6 +926,7 @@ public class AddrSvcController {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (json != null) {
|
||||
int code = json.getInt("msgCode");
|
||||
String msg = json.getString("msg");
|
||||
@@ -1021,6 +966,9 @@ public class AddrSvcController {
|
||||
}
|
||||
}
|
||||
basicModel.setResult(result);
|
||||
if (!result.containsKey("verifyFlag") || StringUtils.isBlank(result.getString("verifyFlag"))) {
|
||||
basicModel.markNoData();
|
||||
}
|
||||
}
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
@@ -1090,7 +1038,6 @@ public class AddrSvcController {
|
||||
basicModel.setResult(resultMap);
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
// params.put("showTestValue", "2");
|
||||
Integer radius = model.getRadius();
|
||||
params.put("radius", (radius != null && radius != 0) ? radius.toString() : null);
|
||||
try {
|
||||
@@ -1102,8 +1049,6 @@ public class AddrSvcController {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (json != null) {
|
||||
int code = json.getInt("msgCode");
|
||||
String msg = json.getString("msg");
|
||||
@@ -1111,66 +1056,10 @@ public class AddrSvcController {
|
||||
if (json.containsKey("result")) {
|
||||
//我们的结果
|
||||
JSONObject result = json.getJSONObject("result");
|
||||
//我们省级及以上有开发区,直接用我们的结果
|
||||
if (result.containsKey("devDistrictName")) {
|
||||
basicModel.setResult(result);
|
||||
} else if (!"2".equals(type)) { // 对私的不用齐梁
|
||||
basicModel.setResult(result);
|
||||
} else {
|
||||
try {
|
||||
//如果是江苏省或者浙江省 调用齐梁的结果
|
||||
// if ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province"))) {
|
||||
// 齐梁不可用,屏蔽
|
||||
if (result.containsKey("province") && ("中国".equals(result.getString("province")))) {
|
||||
|
||||
//结果比较,如果涉农结果不一致
|
||||
//调用齐梁 type :1 对公 0 对私
|
||||
//我们 type :1 对私 2 对共
|
||||
String qltype = "2".equals(type) ? "1" : "0";
|
||||
Map<String, String> map = senRequest(address, qltype);
|
||||
// 涉农结果不一样
|
||||
if (!map.get("verifyFlag").equals(result.get("verifyFlag"))) {
|
||||
// 齐梁县政府但是涉农为农,取我们的结果 扬中市三茅街道中华村永固河路1号
|
||||
if ("是".equals(map.get("countyGov")) && "农".equals(map.get("verifyFlag"))) {
|
||||
basicModel.setResult(result);
|
||||
mav.setModel(basicModel);
|
||||
return mav;
|
||||
}
|
||||
//有市辖建制镇, 或者城市不一样 用我们
|
||||
if (result.containsKey("city")) {
|
||||
if ("是".equals(result.get("administrativeTowns")) || (!result.get("city").equals(map.get("city")) && StringUtils.isNotBlank(result.getString("city")))) {
|
||||
basicModel.setResult(result);
|
||||
} else {
|
||||
map.put("addrVerify", "地址有效");
|
||||
map.put("addrArea", addrArea(map, type));
|
||||
map.put("countyLevelCity", countyLevelCity(map));
|
||||
map.put("typeName", areaMap.get(map.get("typeCode")));
|
||||
basicModel.setResult(map);
|
||||
}
|
||||
} else {
|
||||
map.put("addrVerify", "地址有效");
|
||||
map.put("addrArea", addrArea(map, type));
|
||||
map.put("countyLevelCity", countyLevelCity(map));
|
||||
map.put("typeName", areaMap.get(map.get("typeCode")));
|
||||
basicModel.setResult(map);
|
||||
}
|
||||
|
||||
} else {
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
|
||||
} else {
|
||||
basicModel.setResult(result);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
|
||||
if (!result.containsKey("verifyFlag") || StringUtils.isBlank(result.getString("verifyFlag"))) {
|
||||
basicModel.markNoData();
|
||||
}
|
||||
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
@@ -1249,8 +1138,6 @@ public class AddrSvcController {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (json != null) {
|
||||
int code = json.getInt("msgCode");
|
||||
String msg = json.getString("msg");
|
||||
@@ -1258,65 +1145,10 @@ public class AddrSvcController {
|
||||
if (json.containsKey("result")) {
|
||||
//我们的结果
|
||||
JSONObject result = json.getJSONObject("result");
|
||||
//我们省级及以上有开发区,直接用我们的结果
|
||||
if (result.containsKey("devDistrictName")) {
|
||||
basicModel.setResult(result);
|
||||
} else if (!"2".equals(type)) { // 对私的不用齐梁
|
||||
basicModel.setResult(result);
|
||||
} else {
|
||||
try {
|
||||
//如果是江苏省或者浙江省 调用齐梁的结果
|
||||
// if ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province"))) {
|
||||
if (result.containsKey("province") && ("中国".equals(result.getString("province")))) {
|
||||
|
||||
//结果比较,如果涉农结果不一致
|
||||
//调用齐梁 type :1 对公 0 对私
|
||||
//我们 type :1 对私 2 对共
|
||||
String qltype = "2".equals(type) ? "1" : "0";
|
||||
Map<String, String> map = senRequest(address, qltype);
|
||||
// 涉农结果不一样
|
||||
if (!map.get("verifyFlag").equals(result.get("verifyFlag"))) {
|
||||
// 齐梁县政府但是涉农为农,取我们的结果 扬中市三茅街道中华村永固河路1号
|
||||
if ("是".equals(map.get("countyGov")) && "农".equals(map.get("verifyFlag"))) {
|
||||
basicModel.setResult(result);
|
||||
mav.setModel(basicModel);
|
||||
return mav;
|
||||
}
|
||||
//有市辖建制镇, 或者城市不一样 用我们
|
||||
if (result.containsKey("city")) {
|
||||
if ("是".equals(result.get("administrativeTowns")) || (!result.get("city").equals(map.get("city")) && StringUtils.isNotBlank(result.getString("city")))) {
|
||||
basicModel.setResult(result);
|
||||
} else {
|
||||
map.put("addrVerify", "地址有效");
|
||||
map.put("addrArea", addrArea(map, type));
|
||||
map.put("countyLevelCity", countyLevelCity(map));
|
||||
map.put("typeName", areaMap.get(map.get("typeCode")));
|
||||
basicModel.setResult(map);
|
||||
}
|
||||
} else {
|
||||
map.put("addrVerify", "地址有效");
|
||||
map.put("addrArea", addrArea(map, type));
|
||||
map.put("countyLevelCity", countyLevelCity(map));
|
||||
map.put("typeName", areaMap.get(map.get("typeCode")));
|
||||
basicModel.setResult(map);
|
||||
}
|
||||
|
||||
} else {
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
|
||||
} else {
|
||||
basicModel.setResult(result);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
|
||||
if (!result.containsKey("verifyFlag") || StringUtils.isBlank(result.getString("verifyFlag"))) {
|
||||
basicModel.markNoData();
|
||||
}
|
||||
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
|
||||
+3
-187
@@ -6,28 +6,9 @@ import com.fangjia.open.interceptors.Role;
|
||||
import com.fangjia.open.model.AddressModel;
|
||||
import com.fangjia.open.model.BasicModel;
|
||||
import com.fangjia.open.model.RestfulModelAndView;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Authenticator;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.Proxy;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -101,17 +82,12 @@ public class GdBankController {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("地址不能为空"));
|
||||
return mav;
|
||||
}
|
||||
String type = StringUtils.isNotBlank(model.getType()) ? model.getType() : null;
|
||||
String address = model.getAddress();
|
||||
|
||||
HttpRequest request = new HttpRequest();
|
||||
JSONObject json = null;
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : null);
|
||||
//params.put("type", type);
|
||||
//params.put("redis", (model.getRadius() != null && model.getRadius() != 0) ? model.getRadius().toString() : null);
|
||||
params.put("address", model.getAddress());
|
||||
//params.put("showFullValue", "2");
|
||||
try {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/cebEnterpriseVillageIdentify", params, "UTF-8");
|
||||
} catch (Exception e) {
|
||||
@@ -126,69 +102,11 @@ public class GdBankController {
|
||||
String msg = json.getString("msg");
|
||||
BasicModel basicModel = new BasicModel(code, msg);
|
||||
if (json.containsKey("result")) {
|
||||
//我们的结果
|
||||
JSONObject result = json.getJSONObject("result");
|
||||
//我们省级及以上有开发区,直接用我们的结果
|
||||
if (!result.containsKey("verifyFlag") || StringUtils.isBlank(result.getString("verifyFlag"))) {
|
||||
basicModel.markNoData();
|
||||
}
|
||||
basicModel.setResult(result);
|
||||
// if (result.containsKey("devDistrictName")) {
|
||||
// } else {
|
||||
// try {
|
||||
// // 我们是县政府,且涉农结果为农,取我们结果,因为光大部分逻辑调整
|
||||
// if ("是".equals(result.get("countyGov")) && "农".equals(result.get("verifyFlag"))) {
|
||||
// basicModel.setResult(result);
|
||||
// mav.setModel(basicModel);
|
||||
// return mav;
|
||||
// }
|
||||
// //如果是江苏省或者浙江省 调用齐梁的结果
|
||||
// if ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province"))) {
|
||||
// //结果比较,如果涉农结果不一致
|
||||
// //调用齐梁 type :1 对公 0 对私
|
||||
// //我们 type :1 对私 2 对共
|
||||
// String qltype = "2".equals(type) ? "1" : "0";
|
||||
// Map<String, String> map = senRequest(address, qltype);
|
||||
// // 涉农结果不一样
|
||||
// if (!map.get("verifyFlag").equals(result.get("verifyFlag"))) {
|
||||
// // 齐梁县政府但是涉农为农,取我们的结果 扬中市三茅街道中华村永固河路1号
|
||||
// if ("是".equals(map.get("countyGov")) && "农".equals(map.get("verifyFlag"))) {
|
||||
// basicModel.setResult(result);
|
||||
// mav.setModel(basicModel);
|
||||
// return mav;
|
||||
// }
|
||||
// //城市不一样 用我们
|
||||
// if (result.containsKey("city")) {
|
||||
// if ((!result.get("city").equals(map.get("city")) && StringUtils.isNotBlank(result.getString("city")))) {
|
||||
// basicModel.setResult(result);
|
||||
// } else {
|
||||
// map.put("addrVerify", "地址有效");
|
||||
// map.put("typeName", areaMap.get(map.get("typeCode")));
|
||||
// map.put("addrArea", addrArea(map, type));
|
||||
// map.put("countyLevelCity", countyLevelCity(map));
|
||||
// basicModel.setResult(map);
|
||||
// }
|
||||
// } else {
|
||||
// map.put("addrVerify", "地址有效");
|
||||
// map.put("typeName", areaMap.get(map.get("typeCode")));
|
||||
// map.put("addrArea", addrArea(map, type));
|
||||
// map.put("countyLevelCity", countyLevelCity(map));
|
||||
// basicModel.setResult(map);
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// basicModel.setResult(result);
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// basicModel.setResult(result);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// basicModel.setResult(result);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
@@ -197,106 +115,4 @@ public class GdBankController {
|
||||
return mav;
|
||||
}
|
||||
|
||||
private static Map<String, String> senRequest(String address, String type) throws IOException {
|
||||
String targetURL = "http://146.56.217.44:9010/uams/farmer/all/v3/sign";
|
||||
String proxyHost = "tunnel2.qg.net";
|
||||
int proxyPort = 14186;
|
||||
final String proxyUsername = "113BBC06";
|
||||
final String proxyPassword = "3B2FBD05B0AF";
|
||||
String jsonData = "{\"address\":\"" + address + "\",\"type\":\"" + type + "\"}";
|
||||
String authKey = proxyUsername;
|
||||
String password = proxyPassword;
|
||||
String auth = authKey + ":" + password;
|
||||
String authHeader = "Basic " + new BASE64Encoder().encode(auth.getBytes(Charset.forName("UTF-8")));
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(targetURL);
|
||||
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(proxyUsername, proxyPassword.toCharArray());
|
||||
}
|
||||
});
|
||||
httpPost.setHeader("Content-Type", "application/json");
|
||||
httpPost.setHeader("Accept", "*/*");
|
||||
httpPost.setHeader("Host", "146.56.217.44:9010");
|
||||
httpPost.setHeader("Proxy-Authorization", authHeader);
|
||||
StringEntity stringEntity = new StringEntity(jsonData, ContentType.APPLICATION_JSON);
|
||||
httpPost.setEntity(stringEntity);
|
||||
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
int retryCount = 2; // 设置重试次数
|
||||
int retryDelay = 10; // 设置重试延迟时间(毫秒)
|
||||
boolean success = false;
|
||||
for (int i = 0; i < retryCount; i++) {
|
||||
try {
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
success = true;
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
System.err.println("代理请求失败,进行重试...");
|
||||
try {
|
||||
Thread.sleep(retryDelay);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
HttpEntity responseEntity = httpResponse.getEntity();
|
||||
String responseString = EntityUtils.toString(responseEntity);
|
||||
|
||||
// 使用 Gson 解析 JSON 字符串
|
||||
Gson gson = new Gson();
|
||||
JsonObject jsonObject = gson.fromJson(responseString, JsonObject.class);
|
||||
|
||||
|
||||
// 创建 Map 存储各个值
|
||||
Map<String, String> dataMap = new HashMap<String, String>();
|
||||
|
||||
// 获取各个值并放入 Map
|
||||
// dataMap.put("code", jsonObject.get("code").getAsString());
|
||||
// dataMap.put("msg", jsonObject.get("msg").getAsString());
|
||||
JsonElement dataElement = jsonObject.get("data");
|
||||
if (dataElement != null && !dataElement.isJsonNull() && dataElement.isJsonObject()) {
|
||||
JsonObject data = dataElement.getAsJsonObject();
|
||||
// 在这里继续处理 data 对象
|
||||
|
||||
if (data != null && !data.isJsonNull()) {
|
||||
|
||||
// dataMap.put("version", data.get("version").getAsString());
|
||||
dataMap.put("province", data.get("province").getAsString());
|
||||
dataMap.put("city", data.get("city").getAsString());
|
||||
dataMap.put("district", data.get("district").getAsString());
|
||||
dataMap.put("town", data.get("town").getAsString());
|
||||
dataMap.put("committee", data.get("village").getAsString());
|
||||
dataMap.put("provinceCode", data.get("provinceCode").getAsString());
|
||||
dataMap.put("cityCode", data.get("cityCode").getAsString());
|
||||
dataMap.put("districtCode", data.get("districtCode").getAsString());
|
||||
dataMap.put("townCode", data.get("townCode").getAsString());
|
||||
dataMap.put("committeeCode", data.get("villageCode").getAsString());
|
||||
dataMap.put("typeCode", data.get("areaCode").getAsString());
|
||||
dataMap.put("verifyFlag", "0".equals(data.get("farmer").getAsString()) ? "非农" : "农");
|
||||
dataMap.put("countyGov", "0".equals(data.get("isGovt").getAsString()) ? "否" : "是");
|
||||
// dataMap.put("govtAddr", data.get("govtAddr").isJsonNull() ? null : data.get("govtAddr").getAsString()); // 对于可能为 null 的值,需要判断是否为空
|
||||
JsonArray indusParkList = data.get("indusParkList").isJsonNull() ? null : data.get("indusParkList").getAsJsonArray();
|
||||
|
||||
if (indusParkList != null) {
|
||||
JsonObject jsonObject1 = gson.fromJson(indusParkList.get(0), JsonObject.class);
|
||||
dataMap.put("devDistrictName", jsonObject1.get("indusParkName").getAsString());
|
||||
dataMap.put("devDistrict", "是");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
httpResponse.close();
|
||||
return dataMap;
|
||||
} else {
|
||||
System.err.println("重试次数已用完,请求失败。");
|
||||
}
|
||||
|
||||
httpClient.close();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+46
-10
@@ -5,6 +5,7 @@ import com.fangjia.open.*;
|
||||
import com.fangjia.open.model.BasicModel;
|
||||
import com.fangjia.open.model.RestfulModelAndView;
|
||||
import com.fangjia.service.open.ApiVisitCountService;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.sothis.web.mvc.ActionContext;
|
||||
import org.sothis.web.mvc.ActionInvocation;
|
||||
@@ -12,10 +13,8 @@ import org.sothis.web.mvc.ActionInvocationException;
|
||||
import org.sothis.web.mvc.Interceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* API访问计费Interceptor
|
||||
@@ -61,6 +60,7 @@ public class ApiVisitCountInterceptor implements Interceptor {
|
||||
List<String> serviceCodes = getServiceCode(request);
|
||||
if(serviceCodes.isEmpty()){
|
||||
if(isNeedCharge(authBean, result, uri)){
|
||||
ActionContext.getContext().set(APIConstant.API_COST_KEY, 1d);
|
||||
apiVisitCountService.increaseApiVisitCount(authBean.apiUser.getId(), uri, null, new Date());
|
||||
}
|
||||
}else{
|
||||
@@ -101,25 +101,29 @@ public class ApiVisitCountInterceptor implements Interceptor {
|
||||
}
|
||||
RestfulModelAndView mv = (RestfulModelAndView) result;
|
||||
Object object = mv.model();
|
||||
if (object != null && object instanceof BasicModel) {
|
||||
boolean isReturnData = Boolean.FALSE;
|
||||
if (object instanceof BasicModel) {
|
||||
BasicModel model = (BasicModel) object;
|
||||
if(HttpStatusCodeEnum.OK.getCode() != model.getCode()){
|
||||
return false;
|
||||
}
|
||||
} else if (object != null && object instanceof HttpCode) {
|
||||
isReturnData = isReturnData(model.getResult());
|
||||
} else if (object instanceof HttpCode) {
|
||||
HttpCode httpCode = (HttpCode) object;
|
||||
if(OpenHttpCodeEnum.OK.getCode() != httpCode.getCode()){
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
isReturnData = isReturnData(object);
|
||||
}
|
||||
Boolean isReturnData = (Boolean)ActionContext.getContext().get(APIConstant.IS_RETURN_DATA);
|
||||
if(null != isReturnData && isReturnData){
|
||||
ActionContext.getContext().set(APIConstant.IS_RETURN_DATA, isReturnData);
|
||||
if(isReturnData){
|
||||
return true;
|
||||
}
|
||||
if(null == auth.getOpenResourseUrisMap()){
|
||||
if(null == auth.getOpenResourseUrisMap() || auth.getOpenResourseUrisMap().get(uri) == null){
|
||||
return true;
|
||||
}
|
||||
return auth.getOpenResourseUrisMap().get(uri) == null || auth.getOpenResourseUrisMap().get(uri) != PRICING_MODEL_BY_DATA_RESULT;
|
||||
return auth.getOpenResourseUrisMap().get(uri) != PRICING_MODEL_BY_DATA_RESULT;
|
||||
}
|
||||
/**
|
||||
* 判断是否是超级用户
|
||||
@@ -148,4 +152,36 @@ public class ApiVisitCountInterceptor implements Interceptor {
|
||||
this.apiVisitCountService = apiVisitCountService;
|
||||
}
|
||||
|
||||
private boolean isReturnData(Object result) {
|
||||
|
||||
Boolean isReturnData = (Boolean) ActionContext.getContext().get(APIConstant.IS_RETURN_DATA);
|
||||
if(isReturnData != null){
|
||||
return isReturnData;
|
||||
}
|
||||
if (result == null) {
|
||||
return false;
|
||||
}
|
||||
if (result instanceof Map) {
|
||||
Map map = (Map) result;
|
||||
if (map.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} else if (result instanceof Collection) {
|
||||
Collection coll = (Collection) result;
|
||||
if (coll.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
JSONObject json = JSONObject.fromObject(result);
|
||||
if (json.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-49
@@ -24,6 +24,7 @@ import org.sothis.web.mvc.ActionInvocationException;
|
||||
import org.sothis.web.mvc.Interceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
@@ -56,12 +57,12 @@ public class AuditInterceptor implements Interceptor {
|
||||
|
||||
ActionContext context = invocation.getActionContext();
|
||||
long startMills = System.currentTimeMillis();
|
||||
int status;
|
||||
boolean isReturnData;
|
||||
String msg;
|
||||
Object result = invocation.invoke();
|
||||
HttpServletRequest request = context.getRequest();
|
||||
if (result != null && result instanceof RestfulModelAndView) {
|
||||
if (result instanceof RestfulModelAndView) {
|
||||
HttpServletRequest request = context.getRequest();
|
||||
int status;
|
||||
boolean isReturnData;
|
||||
String msg;
|
||||
AuthenticationBean instance = (AuthenticationBean) request.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
|
||||
ApiUser apiUser = null;
|
||||
User user = null;
|
||||
@@ -72,13 +73,12 @@ public class AuditInterceptor implements Interceptor {
|
||||
}
|
||||
RestfulModelAndView restfulModelAndView = (RestfulModelAndView) result;
|
||||
Object object = restfulModelAndView.model();
|
||||
if (object != null && object instanceof BasicModel) {
|
||||
if (object instanceof BasicModel) {
|
||||
BasicModel model = (BasicModel) object;
|
||||
status = model.getCode();
|
||||
msg = model.getMsg();
|
||||
model.setTid(request.getParameter("tid"));
|
||||
isReturnData = isReturnData(model.getResult());
|
||||
} else if (object != null && object instanceof HttpCode) {
|
||||
} else if (object instanceof HttpCode) {
|
||||
HttpCode httpCode = (HttpCode) object;
|
||||
status = httpCode.getCode();
|
||||
msg = httpCode.getMessage();
|
||||
@@ -92,51 +92,13 @@ public class AuditInterceptor implements Interceptor {
|
||||
} else {
|
||||
status = 200;
|
||||
msg = "返回成功(不规范API)";
|
||||
isReturnData = isReturnData(object);
|
||||
|
||||
}
|
||||
if (isReturnData) {
|
||||
ActionContext.getContext().set(APIConstant.IS_RETURN_DATA, Boolean.TRUE);
|
||||
} else if (isReturnData) {
|
||||
ActionContext.getContext().set(APIConstant.IS_RETURN_DATA, Boolean.FALSE);
|
||||
}
|
||||
openUriLogAction(request, apiUser, user, object, status, isReturnData, msg, startMills);
|
||||
openUriLogAction(request, apiUser, user, object, status, msg, startMills);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isReturnData(Object result) {
|
||||
|
||||
Boolean isReturnData = (Boolean) ActionContext.getContext().get(APIConstant.IS_RETURN_DATA);
|
||||
if(isReturnData != null){
|
||||
return isReturnData;
|
||||
}
|
||||
if (result == null) {
|
||||
return false;
|
||||
}
|
||||
if (result instanceof Map) {
|
||||
Map map = (Map) result;
|
||||
if (map.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} else if (result instanceof Collection) {
|
||||
Collection coll = (Collection) result;
|
||||
if (coll.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
JSONObject json = JSONObject.fromObject(result);
|
||||
if (json.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setOpenUriLogService(OpenUriLogService openUriLogService) {
|
||||
this.openUriLogService = openUriLogService;
|
||||
}
|
||||
@@ -159,11 +121,10 @@ public class AuditInterceptor implements Interceptor {
|
||||
* @param request
|
||||
* @param apiUser
|
||||
* @param status
|
||||
* @param isReturnData
|
||||
* @param msg
|
||||
* @param startMills
|
||||
*/
|
||||
private void openUriLogAction(HttpServletRequest request, ApiUser apiUser, User user, Object result, int status, boolean isReturnData, String msg, long startMills) {
|
||||
private void openUriLogAction(HttpServletRequest request, ApiUser apiUser, User user, Object result, int status, String msg, long startMills) {
|
||||
|
||||
|
||||
/**1:无token或者token错误的不记录日志 2:OpenApi测试账户:仅供房价网内部使用,正常访问的情况下不记录日志*/
|
||||
@@ -191,6 +152,7 @@ public class AuditInterceptor implements Interceptor {
|
||||
openUriLog.setTime(System.currentTimeMillis() - startMills);
|
||||
openUriLog.setCode(status);
|
||||
openUriLog.setMsg(msg);
|
||||
Boolean isReturnData = (Boolean) ActionContext.getContext().get(APIConstant.IS_RETURN_DATA);
|
||||
openUriLog.setDataStatus(isReturnData?1:0);
|
||||
String tid = request.getParameter("tid");
|
||||
openUriLog.setTid(tid);
|
||||
@@ -203,6 +165,12 @@ public class AuditInterceptor implements Interceptor {
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("", e);
|
||||
}
|
||||
Double cost = (Double) ActionContext.getContext().get(APIConstant.API_COST_KEY);
|
||||
if(cost != null){
|
||||
openUriLog.setCost(cost);
|
||||
}else{
|
||||
openUriLog.setCost(0d);
|
||||
}
|
||||
queue.put(openUriLog);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -12,7 +12,7 @@ sothis.interceptors.valid.class=com.fangjia.open.interceptors.ValidatorIntercept
|
||||
sothis.interceptors.viewConfig.class=com.fangjia.open.interceptors.JsonViewInterceptor
|
||||
sothis.interceptors.apiVisit.class=com.fangjia.open.interceptors.ApiVisitCountInterceptor
|
||||
sothis.interceptors.decrypt.class=com.fangjia.open.interceptors.DecryptInterceptor
|
||||
sothis.interceptors.stack.default=apiVisit,audit,upload,auth,decrypt,params,valid,viewConfig
|
||||
sothis.interceptors.stack.default=audit,apiVisit,upload,auth,decrypt,params,valid,viewConfig
|
||||
|
||||
sothis.views.ftl.class=org.sothis.web.mvc.views.freemarker.FreemarkerView
|
||||
sothis.views.rest.class=com.fangjia.open.views.RestView
|
||||
|
||||
Reference in New Issue
Block a user