Merge remote-tracking branch 'origin/master'
This commit is contained in:
+38
-25
@@ -1,10 +1,13 @@
|
||||
package com.fangjia.open.controllers;
|
||||
|
||||
import com.fangjia.core.util.HttpRequest;
|
||||
import com.fangjia.dal.common.DistrictKey;
|
||||
import com.fangjia.dal.mongo.model.VillageIdentify;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.open.dto.addressGovernance.*;
|
||||
import com.fangjia.open.APIConstant;
|
||||
import com.fangjia.open.dto.addressGovernance.DistrictDto;
|
||||
import com.fangjia.open.dto.addressGovernance.DistrictIdentifyDto;
|
||||
import com.fangjia.open.dto.addressGovernance.MatchedBuildingDto;
|
||||
import com.fangjia.open.dto.addressGovernance.StructureAndCompleteDto;
|
||||
import com.fangjia.open.interceptors.Authority;
|
||||
import com.fangjia.open.interceptors.Role;
|
||||
import com.fangjia.open.model.AddesssMatchModel;
|
||||
@@ -12,7 +15,7 @@ import com.fangjia.open.model.AddressModel;
|
||||
import com.fangjia.open.model.BasicModel;
|
||||
import com.fangjia.open.model.RestfulModelAndView;
|
||||
import com.fangjia.open.util.CommonDtoUtils;
|
||||
import com.fangjia.service.bo.DistrictStatBo;
|
||||
import com.fangjia.service.bo.DistrictAvgBo;
|
||||
import com.fangjia.service.datastore.DistrictService;
|
||||
import com.fangjia.service.district.DistrictStatService;
|
||||
import com.fangjia.service.mongo.fangjia.VillageIdentifyService;
|
||||
@@ -39,9 +42,7 @@ 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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -253,6 +254,10 @@ public class AddrSvcController {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaNlpService/match", params, "UTF-8");
|
||||
BasicModel basicModel = new BasicModel(200, "ok");
|
||||
if (json != null && json.size() > 0) {
|
||||
// 非超级用户不返回置信度
|
||||
if (json.containsKey("credit") && !APIConstant.SUPER_USER_TOKEN.equals(model.getToken())) {
|
||||
json.remove("credit");
|
||||
}
|
||||
basicModel.setResult(CommonDtoUtils.transformV(MatchedBuildingDto.class, json));
|
||||
}
|
||||
mav.setModel(basicModel);
|
||||
@@ -372,18 +377,26 @@ public class AddrSvcController {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaNlpService/match", params, "UTF-8");
|
||||
BasicModel basicModel = new BasicModel(200, "ok");
|
||||
if (json != null && json.size() > 0) {
|
||||
MatchedBuildingDto dto = CommonDtoUtils.transformV(MatchedBuildingDto.class, json);
|
||||
MatchedBuildingDto dto = new MatchedBuildingDto();
|
||||
if (json.containsKey("id")) {
|
||||
dto.setId(json.getString("id"));
|
||||
}
|
||||
if (json.containsKey("city")) {
|
||||
dto.setCity(json.getString("city"));
|
||||
}
|
||||
if (json.containsKey("district")) {
|
||||
dto.setDistrict(json.getString("district"));
|
||||
}
|
||||
if (json.containsKey("name")) {
|
||||
dto.setName(json.getString("name"));
|
||||
}
|
||||
|
||||
District district = districtService.findByNameAndAlias(dto.getCity(), dto.getDistrict(), dto.getName(), "district");
|
||||
if (null != district) {
|
||||
DistrictStatBo statBo = districtStatService.findCurrentDistrictStat(new DistrictKey(dto.getCity(), dto.getDistrict(), dto.getName()));
|
||||
//DistrictStatBo statBo = districtStatService.findCurrentDistrictStat(new DistrictKey(dto.getCity(), dto.getDistrict(), dto.getName()));
|
||||
DistrictAvgBo statBo = districtStatService.findDistrictStat(district, "district", null);
|
||||
if (null != statBo) {
|
||||
if (statBo.getDistrictStat() != null) {
|
||||
dto.setAvgPrice(statBo.getDistrictStat().getAvgPrice());
|
||||
} else if (statBo.getVillaDistrictStat() != null) {
|
||||
dto.setAvgPrice(statBo.getVillaDistrictStat().getAvgPrice());
|
||||
}
|
||||
|
||||
dto.setAvgPrice(statBo.getAvgPrice());
|
||||
}
|
||||
}
|
||||
basicModel.setResult(dto);
|
||||
@@ -506,7 +519,7 @@ public class AddrSvcController {
|
||||
} else {
|
||||
try {
|
||||
//如果是江苏省或者浙江省 调用齐梁的结果
|
||||
if ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province"))) {
|
||||
if (result.containsKey("province") && ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province")))) {
|
||||
//结果比较,如果涉农结果不一致
|
||||
//调用齐梁 type :1 对公 0 对私
|
||||
//我们 type :1 对私 2 对共
|
||||
@@ -1094,13 +1107,13 @@ public class AddrSvcController {
|
||||
if (result.containsKey("province")) {
|
||||
map.put("province", result.getString("province"));
|
||||
}
|
||||
if (result.containsKey("provinceCode")) {
|
||||
if (result.containsKey("tjjProvinceCode")) {
|
||||
map.put("provinceCode", result.getString("tjjProvinceCode"));
|
||||
}
|
||||
if (result.containsKey("city")) {
|
||||
map.put("city", result.getString("city"));
|
||||
}
|
||||
if (result.containsKey("cityCode")) {
|
||||
if (result.containsKey("tjjCityCode")) {
|
||||
map.put("cityCode", result.getString("tjjCityCode"));
|
||||
}
|
||||
list.add(map);
|
||||
@@ -1152,8 +1165,8 @@ public class AddrSvcController {
|
||||
if (result.containsKey("province")) {
|
||||
map.put("province", result.getString("province"));
|
||||
}
|
||||
if (result.containsKey("provinceCode")) {
|
||||
map.put("provinceCode", result.getString("mzbProvinceCode"));
|
||||
if (result.containsKey("tjjProvinceCode")) {
|
||||
map.put("provinceCode", result.getString("tjjProvinceCode"));
|
||||
}
|
||||
list.add(map);
|
||||
}
|
||||
@@ -1207,19 +1220,19 @@ public class AddrSvcController {
|
||||
if (result.containsKey("province")) {
|
||||
map.put("province", result.getString("province"));
|
||||
}
|
||||
if (result.containsKey("provinceCode")) {
|
||||
if (result.containsKey("tjjProvinceCode")) {
|
||||
map.put("provinceCode", result.getString("tjjProvinceCode"));
|
||||
}
|
||||
if (result.containsKey("city")) {
|
||||
map.put("city", result.getString("city"));
|
||||
}
|
||||
if (result.containsKey("cityCode")) {
|
||||
if (result.containsKey("tjjCityCode")) {
|
||||
map.put("cityCode", result.getString("tjjCityCode"));
|
||||
}
|
||||
if (result.containsKey("district")) {
|
||||
map.put("district", result.getString("district"));
|
||||
}
|
||||
if (result.containsKey("districtCode")) {
|
||||
if (result.containsKey("tjjDistrictCode")) {
|
||||
map.put("districtCode", result.getString("tjjDistrictCode"));
|
||||
}
|
||||
list.add(map);
|
||||
@@ -1269,25 +1282,25 @@ public class AddrSvcController {
|
||||
if (result.containsKey("province")) {
|
||||
map.put("province", result.getString("province"));
|
||||
}
|
||||
if (result.containsKey("provinceCode")) {
|
||||
if (result.containsKey("tjjProvinceCode")) {
|
||||
map.put("provinceCode", result.getString("tjjProvinceCode"));
|
||||
}
|
||||
if (result.containsKey("city")) {
|
||||
map.put("city", result.getString("city"));
|
||||
}
|
||||
if (result.containsKey("cityCode")) {
|
||||
if (result.containsKey("tjjCityCode")) {
|
||||
map.put("cityCode", result.getString("tjjCityCode"));
|
||||
}
|
||||
if (result.containsKey("district")) {
|
||||
map.put("district", result.getString("district"));
|
||||
}
|
||||
if (result.containsKey("districtCode")) {
|
||||
if (result.containsKey("tjjDistrictCode")) {
|
||||
map.put("districtCode", result.getString("tjjDistrictCode"));
|
||||
}
|
||||
if (result.containsKey("street")) {
|
||||
map.put("street", result.getString("street"));
|
||||
}
|
||||
if (result.containsKey("streetCode")) {
|
||||
if (result.containsKey("tjjStreetCode")) {
|
||||
map.put("streetCode", result.getString("tjjStreetCode"));
|
||||
}
|
||||
list.add(map);
|
||||
|
||||
+5
-3
@@ -2247,8 +2247,8 @@ public class AddressController {
|
||||
public Object financialRatingAction(CommunitySummaryRequestDto model) {
|
||||
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
if (StringUtils.isBlank(model.getAddress()) || "null".equals(model.getAddress())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("地址不能为空"));
|
||||
if ((StringUtils.isBlank(model.getAddress()) || "null".equals(model.getAddress())) && StringUtils.isBlank(model.getId())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("地址和id不能同时为空"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
@@ -2260,11 +2260,13 @@ public class AddressController {
|
||||
|
||||
JSONObject reqBody = new JSONObject();
|
||||
reqBody.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : CONFIG.getDefaultCity());
|
||||
reqBody.put("address", model.getAddress());
|
||||
reqBody.put("address", StringUtils.isNotBlank(model.getAddress()) ? model.getAddress() : "");
|
||||
reqBody.put("seaweedId", StringUtils.isNotBlank(model.getId()) ? model.getId() : "");
|
||||
reqBody.put("area", model.getArea());
|
||||
reqBody.put("maxFloor", model.getMaxFloor());
|
||||
reqBody.put("housePurpose", model.getHousePurpose());
|
||||
reqBody.put("memo", model.getMemo());
|
||||
reqBody.put("showOther", false);
|
||||
String result = request.postWithBody("http://192.168.0.100:32080/FangJiaAddressService/financialRating", reqBody, headers, "UTF-8");
|
||||
if (result != null) {
|
||||
try {
|
||||
|
||||
+55
-6
@@ -42,6 +42,7 @@ import org.slf4j.Logger;
|
||||
import org.sothis.web.mvc.ActionContext;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
@@ -78,6 +79,9 @@ public class ComprehensiveQueryController {
|
||||
|
||||
private static final int DEFAULT_PAGE_SIZE = 20;
|
||||
private static final String[] PROPERTY_SEARCH_API_FIELDS = {"address", "city", "region", "name", "lat2", "lng2", "lat", "lng", "block", "estateType2", "addrAlias"};
|
||||
|
||||
private static final List<String> GAODE_LEVEL = Arrays.asList("兴趣点", "门牌号", "单元号", "楼层", "房间", "门址", "住宅区");
|
||||
|
||||
static final int BAI_DU_GEO = 1;// 百度系坐标
|
||||
static final int GAO_DE_GEO = 2;// 高德系坐标
|
||||
|
||||
@@ -215,6 +219,11 @@ public class ComprehensiveQueryController {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("地址(address),面积(size)为必填字段"));
|
||||
return mav;
|
||||
}
|
||||
// 不支持车位等估价
|
||||
if (model.getAddress().contains("车位")) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("非住宅无法估值"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
String cityStr = model.getCity();
|
||||
if (StringUtils.isNotBlank(cityStr) && cityStr.matches("\\d+")) {
|
||||
@@ -244,10 +253,36 @@ public class ComprehensiveQueryController {
|
||||
} catch (HttpRequestException e) {
|
||||
|
||||
}
|
||||
if (matchResponse == null || !matchResponse.containsKey("result") || !matchResponse.getJSONObject("result").containsKey("id")) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||
return mav;
|
||||
}
|
||||
// 去掉经纬度解析
|
||||
// if (matchResponse == null || !matchResponse.containsKey("result") || !matchResponse.getJSONObject("result").containsKey("id")) {
|
||||
// //加上高德获取经纬度 和 根据经纬度估值
|
||||
// Map<String, String> map = GeoUtils.parserByGaode(model.getCity(), model.getAddress());
|
||||
// if (map.containsKey("level") && GAODE_LEVEL.contains(map.get("level"))
|
||||
// && map.containsKey("lng") && map.containsKey("lat")) {
|
||||
// String location = map.get("lng") + "," + map.get("lat");
|
||||
// JSONObject jsonResult = null;
|
||||
// Map<String, String> param = new HashMap<String, String>();
|
||||
// param.put("location", location);
|
||||
// param.put("area", String.valueOf(model.getSize()));
|
||||
// try {
|
||||
// jsonResult = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8");
|
||||
// if (jsonResult.containsKey("msg") && "成功".equals(jsonResult.getString("msg"))) {
|
||||
// HashMap<String, Object> resultMap = new HashMap<String, Object>();
|
||||
// resultMap.put("avgPrice", jsonResult.getString("unitPrice"));
|
||||
// resultMap.put("totalPrice", jsonResult.getString("totalPrice"));
|
||||
// houseValueInformation.setAddressValue(resultMap);
|
||||
// mav.setModel(BasicModel.buildOKModel().setResult(houseValueInformation));
|
||||
// } else {
|
||||
// mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||
// }
|
||||
// } catch (HttpRequestException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// } else {
|
||||
// mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||
// }
|
||||
// return mav;
|
||||
// }
|
||||
String id = matchResponse.getJSONObject("result").getString("id");
|
||||
District district = districtService.findById(id);
|
||||
if (district == null) {
|
||||
@@ -277,6 +312,13 @@ public class ComprehensiveQueryController {
|
||||
}
|
||||
|
||||
}
|
||||
// 价格下调10%
|
||||
if (dto.getAvgPrice() != null) {
|
||||
int avgPrice = new BigDecimal(dto.getAvgPrice()).multiply(new BigDecimal(0.9)).intValue();
|
||||
dto.setAvgPrice(avgPrice);
|
||||
}
|
||||
// 非住宅无法估值
|
||||
|
||||
// 保存小区均价的返回结果
|
||||
houseValueInformation.setCommunityAvgPrice(dto);
|
||||
|
||||
@@ -300,6 +342,13 @@ public class ComprehensiveQueryController {
|
||||
} catch (IllegalAccessException e) {
|
||||
|
||||
}
|
||||
// 价格下调10%
|
||||
Map<String, Object> addressValue = houseValueInformation.getAddressValue();
|
||||
if (addressValue != null && addressValue.get("totalPrice") != null && addressValue.get("avgPrice") != null) {
|
||||
int evaluatePrice = new BigDecimal((Integer) addressValue.get("avgPrice")).multiply(new BigDecimal(0.9)).intValue();
|
||||
addressValue.put("avgPrice", evaluatePrice);
|
||||
addressValue.put("totalPrice", new BigDecimal(evaluatePrice * model.getSize()).intValue());
|
||||
}
|
||||
// houseValueInformation.setAddressValue(modelAndView);
|
||||
|
||||
//房源样本
|
||||
@@ -909,9 +958,9 @@ public class ComprehensiveQueryController {
|
||||
otherPriceRets = new HashMap();
|
||||
}
|
||||
|
||||
if (evaluation.getAvgPrice2b()!=null&&evaluation.getAvgPrice2b() > 0){
|
||||
if (evaluation.getAvgPrice2b() != null && evaluation.getAvgPrice2b() > 0) {
|
||||
otherPriceRets.put("fjw_price", evaluation.getAvgPrice2b());
|
||||
}else {
|
||||
} else {
|
||||
otherPriceRets.put("fjw_price", evaluation.getAvgPrice());
|
||||
}
|
||||
Map<String, Object> levelMap = getPriceLevel(otherPriceRets, evaluation.getCredit());
|
||||
|
||||
@@ -1925,8 +1925,12 @@ public class FshController {
|
||||
evaluation.setFitmentCharge(model.getDecorationCost());
|
||||
}
|
||||
evaluation.setGardenArea(model.getGardenArea());
|
||||
if (0 != model.getHall()) {
|
||||
evaluation.setHall(model.getHall());
|
||||
try {
|
||||
if (0 != model.getHall()) {
|
||||
evaluation.setHall(model.getHall());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
if (null != model.getFloor()) {
|
||||
evaluation.setFloor(model.getFloor());
|
||||
@@ -1951,7 +1955,7 @@ public class FshController {
|
||||
evaluation.setOtherFactor(model.getOtherFactor());
|
||||
}
|
||||
evaluation.setRegion(model.getDistrict());
|
||||
if (0 != model.getRoom()) {
|
||||
if (model.getRoom() != null && 0 != model.getRoom()) {
|
||||
evaluation.setRoom(model.getRoom());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getRoomNumber())) {
|
||||
|
||||
+1
-1
@@ -1170,7 +1170,7 @@ public class HouseController {
|
||||
|| statsIndex.getBelowFixedbase() == null) {
|
||||
return null;
|
||||
}
|
||||
Date endDate = DateUtil.parseDate(statsIndex.getYearmonth(), "yyyyMM");
|
||||
Date endDate = DateUtil.parseDate(statsIndex.getYearmonth().toString(), "yyyyMM");
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(endDate);
|
||||
c.add(Calendar.MONTH, -1);
|
||||
|
||||
+33
-4
@@ -178,7 +178,10 @@ public class PropertyController {
|
||||
|
||||
private FileDao fileDao = FileDao.getInstance();
|
||||
private static final int DEFAULT_PAGE_SIZE = 20;
|
||||
private static final int DEFAULT_HOUSE_COUNT = 5;
|
||||
private static final String[] PROPERTY_SEARCH_API_FIELDS = {"address", "city", "region", "name", "lat2", "lng2", "lat", "lng", "block", "estateType2", "addrAlias", "alias"};
|
||||
|
||||
private static final List<String> GAODE_LEVEL = Arrays.asList("兴趣点", "门牌号", "单元号", "楼层", "房间", "门址", "住宅区");
|
||||
static final int BAI_DU_GEO = 1;// 百度系坐标
|
||||
static final int GAO_DE_GEO = 2;// 高德系坐标
|
||||
|
||||
@@ -1051,7 +1054,8 @@ public class PropertyController {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName())
|
||||
|| StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) {
|
||||
|| StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0 || model.getCity().contains("全国")
|
||||
|| model.getDistrict().contains("全国")) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项"));
|
||||
return mav;
|
||||
}
|
||||
@@ -1621,7 +1625,32 @@ public class PropertyController {
|
||||
}
|
||||
|
||||
if (district == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||
//加上高德获取经纬度 和 根据经纬度估值
|
||||
Map<String, String> map = GeoUtils.parserByGaode(model.getCity(), model.getAddress());
|
||||
if (map.containsKey("level") && GAODE_LEVEL.contains(map.get("level"))
|
||||
&& map.containsKey("lng") && map.containsKey("lat")) {
|
||||
String location = map.get("lng") + "," + map.get("lat");
|
||||
HttpRequest httpRequest = new HttpRequest();
|
||||
JSONObject json = null;
|
||||
Map<String, String> param = new HashMap<String, String>();
|
||||
param.put("location", location);
|
||||
param.put("area", String.valueOf(model.getSize()));
|
||||
try {
|
||||
json = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8");
|
||||
if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) {
|
||||
HashMap<String, String> resultMap = new HashMap<String, String>();
|
||||
resultMap.put("avgPrice",json.getString("unitPrice"));
|
||||
resultMap.put("totalPrice",json.getString("totalPrice"));
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(resultMap));
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||
}
|
||||
} catch (HttpRequestException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||
}
|
||||
return mav;
|
||||
}
|
||||
model.setDistrict(district.getRegion());
|
||||
@@ -2507,7 +2536,7 @@ public class PropertyController {
|
||||
}
|
||||
Date startDate = DateUtil.add(new Date(), Calendar.MONTH, -model.getPeriodCount());
|
||||
|
||||
List<SqmetreRent> sqmetreRents = sqmetreRentService.findSqmetreRents(RegionData.formatCity(model.getCity()), RegionData.formatRegion(model.getCity(),model.getDistrict()), model.getName(), model.getCat(), startDate, null);
|
||||
List<SqmetreRent> sqmetreRents = sqmetreRentService.findSqmetreRents(RegionData.formatCity(model.getCity()), RegionData.formatRegion(model.getCity(), model.getDistrict()), model.getName(), model.getCat(), startDate, null);
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(model.getPeriodCount());
|
||||
|
||||
for (SqmetreRent sqmetreRent : sqmetreRents) {
|
||||
@@ -2780,7 +2809,7 @@ public class PropertyController {
|
||||
return mav;
|
||||
}
|
||||
if (model.getMax() == null || model.getMax() < 1) {
|
||||
model.setMax(DEFAULT_PAGE_SIZE);
|
||||
model.setMax(DEFAULT_HOUSE_COUNT);
|
||||
} else if (model.getMax() > 100) {
|
||||
model.setMax(100);
|
||||
}
|
||||
|
||||
+449
-370
@@ -5,7 +5,13 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fangjia.dal.mongo.model.FangjiaOfficialAreaMap;
|
||||
import com.fangjia.dal.mongo.model.PropertyStatsIndex;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.open.model.BasicModel;
|
||||
import com.fangjia.service.datastore.DistrictService;
|
||||
import com.fangjia.service.mongo.fangjia.PropertyStatsIndexService;
|
||||
import com.fangjia.service.open.FangjiaOfficialAreaService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.fangjia.core.util.DistrictCodeUtils;
|
||||
@@ -22,380 +28,453 @@ import com.fangjia.service.bo.IndexBo;
|
||||
import com.fangjia.service.bo.LandPriceIndexBo;
|
||||
import com.fangjia.service.mongo.fangjia.LandPriceIndexService;
|
||||
import com.fangjia.service.mongo.fangjia.StatsIndexService;
|
||||
import org.sothis.core.util.CollectionUtils;
|
||||
|
||||
public class StatsIndexController {
|
||||
private StatsIndexService statsIndexService;
|
||||
private LandPriceIndexService landPriceIndexService;
|
||||
private StatsIndexService statsIndexService;
|
||||
private LandPriceIndexService landPriceIndexService;
|
||||
|
||||
/**
|
||||
*查询
|
||||
* param y:city : ,yearmonth: yyyyMM cat:商铺,写字楼,住宅
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if(StringUtils.isBlank(model.getCity())){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "请输入城市编码"));
|
||||
return mav;
|
||||
}
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if(cityName == null){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
if (StringUtils.isBlank(model.getYearmonth())) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "请输入要查询的年月"));
|
||||
return mav;
|
||||
}
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
List<StatsIndex> statsIndexs=statsIndexService.findAllStats(model.getCity(), model.getYearmonth(), true,model.getCat());
|
||||
List<StatsIndex> statsIndexList=new ArrayList<StatsIndex>();
|
||||
if("商铺".equalsIgnoreCase(model.getCat()) || "写字楼".equalsIgnoreCase(model.getCat())){
|
||||
for(StatsIndex statsIndex:statsIndexs){
|
||||
StatsIndex newStatsIndex=new StatsIndex();
|
||||
newStatsIndex.setFangChain(statsIndex.getFangChain());
|
||||
newStatsIndex.setFangIndex(statsIndex.getFangIndex());
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(statsIndex.getYearmonth());
|
||||
if(StringUtils.isNotBlank(newStatsIndex.getCity())){
|
||||
statsIndexList.add(newStatsIndex);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for(StatsIndex statsIndex:statsIndexs){
|
||||
StatsIndex newStatsIndex=new StatsIndex();
|
||||
newStatsIndex.setNewChain(statsIndex.getNewChain());
|
||||
newStatsIndex.setNewYeartoyear(statsIndex.getNewYeartoyear());
|
||||
newStatsIndex.setNewFixedbase(statsIndex.getNewFixedbase());
|
||||
|
||||
newStatsIndex.setBelowChain(statsIndex.getBelowChain());
|
||||
newStatsIndex.setBelowYeartoyear(statsIndex.getBelowYeartoyear());
|
||||
newStatsIndex.setBelowFixedbase(statsIndex.getBelowFixedbase());
|
||||
|
||||
newStatsIndex.setAmongChain(statsIndex.getAmongChain());
|
||||
newStatsIndex.setAmongYeartoyear(statsIndex.getAmongYeartoyear());
|
||||
newStatsIndex.setAmongFixedbase(statsIndex.getAmongFixedbase());
|
||||
|
||||
newStatsIndex.setAboveChain(statsIndex.getAboveChain());
|
||||
newStatsIndex.setAboveYeartoyear(statsIndex.getAboveYeartoyear());
|
||||
newStatsIndex.setAboveFixedbase(statsIndex.getAboveFixedbase());
|
||||
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(String.valueOf(statsIndex.getSource()));
|
||||
if(StringUtils.isNotBlank(newStatsIndex.getCity())){
|
||||
statsIndexList.add(newStatsIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(statsIndexList.isEmpty()){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "请检查输入的城市或者年月"));
|
||||
return mav;
|
||||
}
|
||||
resMap.put("results",statsIndexList.get(0));
|
||||
if(statsIndexList.size()>0){
|
||||
resMap.put("count", statsIndexList.size());
|
||||
if("商铺".equals(model.getCat())){
|
||||
resMap.put("type", "商铺");
|
||||
}else if("写字楼".equals(model.getCat())){
|
||||
resMap.put("type", "写字楼");
|
||||
}else{
|
||||
resMap.put("type", "住宅");
|
||||
}
|
||||
}
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
private FangjiaOfficialAreaService fangjiaOfficialAreaService;
|
||||
private DistrictService districtService;
|
||||
|
||||
/**
|
||||
*查询新房指数
|
||||
* param yearmonth: yyyyMM
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchNewDistrictIndexAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if(StringUtils.isNotBlank(model.getCity())){
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if(cityName == null){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if(StringUtils.isBlank(model.getYearmonth())){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年月必须输入,格式:yyyyMM"));
|
||||
return mav;
|
||||
}
|
||||
List<StatsIndex> statsIndexs = statsIndexService.findAllStats(model.getCity(), model.getYearmonth(), false, "住宅");
|
||||
List<IndexBo> statsIndexList = new ArrayList<IndexBo>();
|
||||
|
||||
if(statsIndexs != null && statsIndexs.size() > 0){
|
||||
for(StatsIndex statsIndex : statsIndexs){
|
||||
IndexBo newStatsIndex = new IndexBo();
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(statsIndex.getYearmonth());
|
||||
newStatsIndex.setMOM(statsIndex.getNewChain());
|
||||
newStatsIndex.setYOY(statsIndex.getNewYeartoyear());
|
||||
newStatsIndex.setFixedBase(statsIndex.getNewFixedbase());
|
||||
newStatsIndex.setSource(String.valueOf(statsIndex.getSource()));
|
||||
if(StringUtils.isNotBlank(newStatsIndex.getCity())){
|
||||
statsIndexList.add(newStatsIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(statsIndexList.isEmpty()){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results",statsIndexList);
|
||||
resMap.put("count", statsIndexList.size());
|
||||
resMap.put("type", "新建商品房");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
*查询二手房指数
|
||||
* param yearmonth: yyyyMM
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchDistrictIndexAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if(StringUtils.isNotBlank(model.getCity())){
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if(cityName == null){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if(StringUtils.isBlank(model.getYearmonth())){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年月必须输入,格式:yyyyMM"));
|
||||
return mav;
|
||||
}
|
||||
List<StatsIndex> statsIndexs = statsIndexService.findAllStats(model.getCity(), model.getYearmonth(), false, "住宅");
|
||||
List<IndexBo> statsIndexList = new ArrayList<IndexBo>();
|
||||
|
||||
if(statsIndexs != null && statsIndexs.size() > 0){
|
||||
for(StatsIndex statsIndex:statsIndexs){
|
||||
IndexBo newStatsIndex = new IndexBo();
|
||||
newStatsIndex.setSmallMOM(statsIndex.getBelowChain());
|
||||
newStatsIndex.setSmallYOY(statsIndex.getBelowYeartoyear());
|
||||
newStatsIndex.setSmallFixedBase(statsIndex.getBelowFixedbase());
|
||||
|
||||
newStatsIndex.setMediumMOM(statsIndex.getAmongChain());
|
||||
newStatsIndex.setMediumYOY(statsIndex.getAmongYeartoyear());
|
||||
newStatsIndex.setMediumFixedBase(statsIndex.getAmongFixedbase());
|
||||
|
||||
newStatsIndex.setLargeMOM(statsIndex.getAboveChain());
|
||||
newStatsIndex.setLargeYOY(statsIndex.getAboveYeartoyear());
|
||||
newStatsIndex.setLargeFixedBase(statsIndex.getAboveFixedbase());
|
||||
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(statsIndex.getYearmonth());
|
||||
newStatsIndex.setSource(String.valueOf(statsIndex.getSource()));
|
||||
if(StringUtils.isNotBlank(newStatsIndex.getCity())){
|
||||
statsIndexList.add(newStatsIndex);
|
||||
}else{
|
||||
System.out.println(statsIndex.getCity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(statsIndexList.isEmpty()){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results",statsIndexList);
|
||||
resMap.put("count", statsIndexList.size());
|
||||
resMap.put("type", "二手住宅");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
*查询商铺指数
|
||||
* param yearmonth: yyyyMM
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchShopIndexAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if(StringUtils.isNotBlank(model.getCity())){
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if(cityName == null){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if(StringUtils.isBlank(model.getYearmonth())){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年月必须输入,格式:yyyyMM"));
|
||||
return mav;
|
||||
}
|
||||
List<StatsIndex> statsIndexs = statsIndexService.findAllStats(model.getCity(), model.getYearmonth(), true, "商铺");
|
||||
List<IndexBo> statsIndexList = new ArrayList<IndexBo>();
|
||||
|
||||
if(statsIndexs != null && statsIndexs.size() > 0){
|
||||
for(StatsIndex statsIndex:statsIndexs){
|
||||
IndexBo newStatsIndex = new IndexBo();
|
||||
newStatsIndex.setMOM(statsIndex.getFangChain());
|
||||
newStatsIndex.setIndex(statsIndex.getFangIndex());
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(statsIndex.getYearmonth());
|
||||
newStatsIndex.setSource(String.valueOf(statsIndex.getSource()));
|
||||
if(StringUtils.isNotBlank(newStatsIndex.getCity())){
|
||||
statsIndexList.add(newStatsIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(statsIndexList.isEmpty()){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results",statsIndexList);
|
||||
resMap.put("count", statsIndexList.size());
|
||||
resMap.put("type", "商铺");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
*查询写字楼指数
|
||||
* yearmonth: yyyyMM
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchOfficeIndexAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if(StringUtils.isNotBlank(model.getCity())){
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if(cityName == null){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if(StringUtils.isBlank(model.getYearmonth())){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年月必须输入,格式:yyyyMM"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
List<StatsIndex> statsIndexs=statsIndexService.findAllStats(model.getCity(), model.getYearmonth(), true, "写字楼");
|
||||
List<IndexBo> statsIndexList = new ArrayList<IndexBo>();
|
||||
|
||||
if(statsIndexs != null && statsIndexs.size() > 0){
|
||||
for(StatsIndex statsIndex:statsIndexs){
|
||||
IndexBo newStatsIndex = new IndexBo();
|
||||
newStatsIndex.setMOM(statsIndex.getFangChain());
|
||||
newStatsIndex.setIndex(statsIndex.getFangIndex());
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(statsIndex.getYearmonth());
|
||||
newStatsIndex.setSource(String.valueOf(statsIndex.getSource()));
|
||||
if(StringUtils.isNotBlank(newStatsIndex.getCity())){
|
||||
statsIndexList.add(newStatsIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(statsIndexList.isEmpty()){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results",statsIndexList);
|
||||
resMap.put("count", statsIndexList.size());
|
||||
resMap.put("type", "写字楼");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
*查询
|
||||
* param city:城市 , year:年份
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchLandIndexAction(LandPriceIndexModel model) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if(StringUtils.isNotBlank(model.getCity())) {
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if(cityName == null){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if(model.getYear() <= 0){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年份必须输入,格式:yyyy"));
|
||||
return mav;
|
||||
}
|
||||
List<LandPriceIndex> landPriceIndexList = new ArrayList<LandPriceIndex>();
|
||||
if(StringUtils.isNotBlank(model.getCity())) {
|
||||
landPriceIndexList = landPriceIndexService.findByCityAndYear(model.getCity(), model.getYear());
|
||||
} else {
|
||||
landPriceIndexList = landPriceIndexService.findAllByYear(model.getYear());
|
||||
}
|
||||
List<LandPriceIndexBo> landPriceIndexBoList = new ArrayList<LandPriceIndexBo>();
|
||||
|
||||
if(landPriceIndexList != null && landPriceIndexList.size() > 0){
|
||||
for(LandPriceIndex landPriceIndex:landPriceIndexList){
|
||||
LandPriceIndexBo landPriceIndexBo = new LandPriceIndexBo();
|
||||
|
||||
landPriceIndexBo.setCity(DistrictCodeUtils.getCityCode(landPriceIndex.getCity()));
|
||||
landPriceIndexBo.setYear(landPriceIndex.getYear());
|
||||
landPriceIndexBo.setCompositeIndex(landPriceIndex.getComprehensiveIndex());
|
||||
landPriceIndexBo.setCommercialIndex(landPriceIndex.getCommercialIndex());
|
||||
landPriceIndexBo.setResidentialIndex(landPriceIndex.getDistrictIndex());
|
||||
landPriceIndexBo.setIndustrialIndex(landPriceIndex.getIndustryIndex());
|
||||
|
||||
if(StringUtils.isNotBlank(landPriceIndexBo.getCity())){
|
||||
landPriceIndexBoList.add(landPriceIndexBo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(landPriceIndexBoList.isEmpty()){
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results",landPriceIndexBoList);
|
||||
resMap.put("count", landPriceIndexBoList.size());
|
||||
resMap.put("type", "土地");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
private String getSourceString(int source){
|
||||
if(source == 1){
|
||||
return "统计局";
|
||||
}else if(source == 2){
|
||||
return "房价网";
|
||||
}else if(source == 3){
|
||||
return "手工输入";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setStatsIndexService(StatsIndexService statsIndexService) {
|
||||
this.statsIndexService = statsIndexService;
|
||||
}
|
||||
private PropertyStatsIndexService propertyStatsIndexService;
|
||||
|
||||
public void setLandPriceIndexService(LandPriceIndexService landPriceIndexService) {
|
||||
this.landPriceIndexService = landPriceIndexService;
|
||||
}
|
||||
/**
|
||||
* 查询城市级别价格指数
|
||||
* param y:city : ,yearmonth: yyyyMM cat:商铺,写字楼,住宅
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object cityAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(model.getCity())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("请输入城市编码"));
|
||||
return mav;
|
||||
}
|
||||
if (null == model.getYearmonth()) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("请输入要查询的年月"));
|
||||
return mav;
|
||||
}
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if (cityName == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
StatsIndex statsIndex = statsIndexService.findStatsIndex(cityName, "", "城市", "", model.getYearmonth(), model.getCat());
|
||||
if (statsIndex != null) {
|
||||
StatsIndex newStatsIndex = new StatsIndex();
|
||||
newStatsIndex.setChain(statsIndex.getChain());
|
||||
newStatsIndex.setYeartoyear(statsIndex.getYeartoyear());
|
||||
newStatsIndex.setFixedbase(statsIndex.getFixedbase());
|
||||
|
||||
newStatsIndex.setBelowChain(statsIndex.getBelowChain());
|
||||
newStatsIndex.setBelowYeartoyear(statsIndex.getBelowYeartoyear());
|
||||
newStatsIndex.setBelowFixedbase(statsIndex.getBelowFixedbase());
|
||||
|
||||
newStatsIndex.setAmongChain(statsIndex.getAmongChain());
|
||||
newStatsIndex.setAmongYeartoyear(statsIndex.getAmongYeartoyear());
|
||||
newStatsIndex.setAmongFixedbase(statsIndex.getAmongFixedbase());
|
||||
|
||||
newStatsIndex.setAboveChain(statsIndex.getAboveChain());
|
||||
newStatsIndex.setAboveYeartoyear(statsIndex.getAboveYeartoyear());
|
||||
newStatsIndex.setAboveFixedbase(statsIndex.getAboveFixedbase());
|
||||
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(model.getYearmonth());
|
||||
resMap.put("results", newStatsIndex);
|
||||
}
|
||||
resMap.put("status", "200");
|
||||
resMap.put("msg", "ok");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询区域级别价格指数
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
@Authority(role = Role.USER)
|
||||
public Object districtAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(model.getDistrict())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("请输入区域编码"));
|
||||
return mav;
|
||||
}
|
||||
if (null == model.getYearmonth()) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("请输入要查询的年月"));
|
||||
return mav;
|
||||
}
|
||||
FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertOfficialCodeToFangjia(model.getDistrict());
|
||||
if (fangjiaOfficialAreaMap == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("无法匹配到该区域编码"));
|
||||
return mav;
|
||||
}
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
StatsIndex statsIndex = statsIndexService.findStatsIndex(fangjiaOfficialAreaMap.getFangjiaCity(), fangjiaOfficialAreaMap.getFangjiaDistrict(), "区域", "", model.getYearmonth(), model.getCat());
|
||||
if (statsIndex != null) {
|
||||
StatsIndex newStatsIndex = new StatsIndex();
|
||||
newStatsIndex.setChain(statsIndex.getChain());
|
||||
newStatsIndex.setYeartoyear(statsIndex.getYeartoyear());
|
||||
newStatsIndex.setFixedbase(statsIndex.getFixedbase());
|
||||
newStatsIndex.setDistrict(model.getDistrict());
|
||||
newStatsIndex.setYearmonth(model.getYearmonth());
|
||||
resMap.put("results", newStatsIndex);
|
||||
}
|
||||
resMap.put("status", "200");
|
||||
resMap.put("msg", "ok");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小区价格指数
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object propertyAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(model.getId())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("请输入小区id"));
|
||||
return mav;
|
||||
}
|
||||
if (null == model.getYearmonth()) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("请输入要查询的年月"));
|
||||
return mav;
|
||||
}
|
||||
District district = districtService.findById(model.getId());
|
||||
if (district == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("无法匹配到小区"));
|
||||
return mav;
|
||||
}
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
PropertyStatsIndex statsIndex = propertyStatsIndexService.findStatsIndex(district.getCity(), district.getRegion(), district.getName(), model.getYearmonth());
|
||||
if (statsIndex != null) {
|
||||
PropertyStatsIndex newStatsIndex = new PropertyStatsIndex();
|
||||
newStatsIndex.setChain(statsIndex.getChain());
|
||||
newStatsIndex.setYeartoyear(statsIndex.getYeartoyear());
|
||||
newStatsIndex.setFixedbase(statsIndex.getFixedbase());
|
||||
newStatsIndex.setDistrict(model.getDistrict());
|
||||
newStatsIndex.setYearmonth(model.getYearmonth());
|
||||
newStatsIndex.setId(model.getId());
|
||||
resMap.put("results", newStatsIndex);
|
||||
}
|
||||
|
||||
resMap.put("status", "200");
|
||||
resMap.put("msg", "ok");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询新房指数
|
||||
* param yearmonth: yyyyMM
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchNewDistrictIndexAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isNotBlank(model.getCity())) {
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if (cityName == null) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if (null == model.getYearmonth()) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年月必须输入,格式:yyyyMM"));
|
||||
return mav;
|
||||
}
|
||||
List<StatsIndex> statsIndexs = statsIndexService.findAllStats(model.getCity(), model.getYearmonth(), false, "住宅");
|
||||
List<IndexBo> statsIndexList = new ArrayList<IndexBo>();
|
||||
|
||||
if (statsIndexs != null && statsIndexs.size() > 0) {
|
||||
for (StatsIndex statsIndex : statsIndexs) {
|
||||
IndexBo newStatsIndex = new IndexBo();
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(statsIndex.getYearmonth().toString());
|
||||
newStatsIndex.setMOM(statsIndex.getChain());
|
||||
newStatsIndex.setYOY(statsIndex.getYeartoyear());
|
||||
newStatsIndex.setFixedBase(statsIndex.getFixedbase());
|
||||
newStatsIndex.setSource(String.valueOf(statsIndex.getSource()));
|
||||
if (StringUtils.isNotBlank(newStatsIndex.getCity())) {
|
||||
statsIndexList.add(newStatsIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (statsIndexList.isEmpty()) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results", statsIndexList);
|
||||
resMap.put("count", statsIndexList.size());
|
||||
resMap.put("type", "新建商品房");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询二手房指数
|
||||
* param yearmonth: yyyyMM
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchDistrictIndexAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isNotBlank(model.getCity())) {
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if (cityName == null) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if (null == model.getYearmonth()) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年月必须输入,格式:yyyyMM"));
|
||||
return mav;
|
||||
}
|
||||
List<StatsIndex> statsIndexs = statsIndexService.findAllStats(model.getCity(), model.getYearmonth(), false, "住宅");
|
||||
List<IndexBo> statsIndexList = new ArrayList<IndexBo>();
|
||||
|
||||
if (statsIndexs != null && statsIndexs.size() > 0) {
|
||||
for (StatsIndex statsIndex : statsIndexs) {
|
||||
IndexBo newStatsIndex = new IndexBo();
|
||||
newStatsIndex.setSmallMOM(statsIndex.getBelowChain());
|
||||
newStatsIndex.setSmallYOY(statsIndex.getBelowYeartoyear());
|
||||
newStatsIndex.setSmallFixedBase(statsIndex.getBelowFixedbase());
|
||||
|
||||
newStatsIndex.setMediumMOM(statsIndex.getAmongChain());
|
||||
newStatsIndex.setMediumYOY(statsIndex.getAmongYeartoyear());
|
||||
newStatsIndex.setMediumFixedBase(statsIndex.getAmongFixedbase());
|
||||
|
||||
newStatsIndex.setLargeMOM(statsIndex.getAboveChain());
|
||||
newStatsIndex.setLargeYOY(statsIndex.getAboveYeartoyear());
|
||||
newStatsIndex.setLargeFixedBase(statsIndex.getAboveFixedbase());
|
||||
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(statsIndex.getYearmonth().toString());
|
||||
newStatsIndex.setSource(String.valueOf(statsIndex.getSource()));
|
||||
if (StringUtils.isNotBlank(newStatsIndex.getCity())) {
|
||||
statsIndexList.add(newStatsIndex);
|
||||
} else {
|
||||
System.out.println(statsIndex.getCity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (statsIndexList.isEmpty()) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results", statsIndexList);
|
||||
resMap.put("count", statsIndexList.size());
|
||||
resMap.put("type", "二手住宅");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商铺指数
|
||||
* param yearmonth: yyyyMM
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchShopIndexAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isNotBlank(model.getCity())) {
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if (cityName == null) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if (null == model.getYearmonth()) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年月必须输入,格式:yyyyMM"));
|
||||
return mav;
|
||||
}
|
||||
List<StatsIndex> statsIndexs = statsIndexService.findAllStats(model.getCity(), model.getYearmonth(), true, "商铺");
|
||||
List<IndexBo> statsIndexList = new ArrayList<IndexBo>();
|
||||
|
||||
if (statsIndexs != null && statsIndexs.size() > 0) {
|
||||
for (StatsIndex statsIndex : statsIndexs) {
|
||||
IndexBo newStatsIndex = new IndexBo();
|
||||
newStatsIndex.setMOM(statsIndex.getFangChain());
|
||||
newStatsIndex.setIndex(statsIndex.getFangIndex());
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(statsIndex.getYearmonth().toString());
|
||||
newStatsIndex.setSource(String.valueOf(statsIndex.getSource()));
|
||||
if (StringUtils.isNotBlank(newStatsIndex.getCity())) {
|
||||
statsIndexList.add(newStatsIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (statsIndexList.isEmpty()) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results", statsIndexList);
|
||||
resMap.put("count", statsIndexList.size());
|
||||
resMap.put("type", "商铺");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询写字楼指数
|
||||
* yearmonth: yyyyMM
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchOfficeIndexAction(StatsIndexModel model) throws Exception {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isNotBlank(model.getCity())) {
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if (cityName == null) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if (null == model.getYearmonth()) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年月必须输入,格式:yyyyMM"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
List<StatsIndex> statsIndexs = statsIndexService.findAllStats(model.getCity(), model.getYearmonth(), true, "写字楼");
|
||||
List<IndexBo> statsIndexList = new ArrayList<IndexBo>();
|
||||
|
||||
if (statsIndexs != null && statsIndexs.size() > 0) {
|
||||
for (StatsIndex statsIndex : statsIndexs) {
|
||||
IndexBo newStatsIndex = new IndexBo();
|
||||
newStatsIndex.setMOM(statsIndex.getFangChain());
|
||||
newStatsIndex.setIndex(statsIndex.getFangIndex());
|
||||
newStatsIndex.setCity(DistrictCodeUtils.getCityCode(statsIndex.getCity()));
|
||||
newStatsIndex.setYearmonth(statsIndex.getYearmonth().toString());
|
||||
newStatsIndex.setSource(String.valueOf(statsIndex.getSource()));
|
||||
if (StringUtils.isNotBlank(newStatsIndex.getCity())) {
|
||||
statsIndexList.add(newStatsIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (statsIndexList.isEmpty()) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results", statsIndexList);
|
||||
resMap.put("count", statsIndexList.size());
|
||||
resMap.put("type", "写字楼");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
* param city:城市 , year:年份
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public Object searchLandIndexAction(LandPriceIndexModel model) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isNotBlank(model.getCity())) {
|
||||
String cityName = DistrictCodeUtils.getCityName(model.getCity());
|
||||
if (cityName == null) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "无法匹配到该城市编码"));
|
||||
return mav;
|
||||
}
|
||||
model.setCity(cityName);
|
||||
}
|
||||
if (model.getYear() <= 0) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.ARGUMENT_LOSE, "年份必须输入,格式:yyyy"));
|
||||
return mav;
|
||||
}
|
||||
List<LandPriceIndex> landPriceIndexList = new ArrayList<LandPriceIndex>();
|
||||
if (StringUtils.isNotBlank(model.getCity())) {
|
||||
landPriceIndexList = landPriceIndexService.findByCityAndYear(model.getCity(), model.getYear());
|
||||
} else {
|
||||
landPriceIndexList = landPriceIndexService.findAllByYear(model.getYear());
|
||||
}
|
||||
List<LandPriceIndexBo> landPriceIndexBoList = new ArrayList<LandPriceIndexBo>();
|
||||
|
||||
if (landPriceIndexList != null && landPriceIndexList.size() > 0) {
|
||||
for (LandPriceIndex landPriceIndex : landPriceIndexList) {
|
||||
LandPriceIndexBo landPriceIndexBo = new LandPriceIndexBo();
|
||||
|
||||
landPriceIndexBo.setCity(DistrictCodeUtils.getCityCode(landPriceIndex.getCity()));
|
||||
landPriceIndexBo.setYear(landPriceIndex.getYear());
|
||||
landPriceIndexBo.setCompositeIndex(landPriceIndex.getComprehensiveIndex());
|
||||
landPriceIndexBo.setCommercialIndex(landPriceIndex.getCommercialIndex());
|
||||
landPriceIndexBo.setResidentialIndex(landPriceIndex.getDistrictIndex());
|
||||
landPriceIndexBo.setIndustrialIndex(landPriceIndex.getIndustryIndex());
|
||||
|
||||
if (StringUtils.isNotBlank(landPriceIndexBo.getCity())) {
|
||||
landPriceIndexBoList.add(landPriceIndexBo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (landPriceIndexBoList.isEmpty()) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "目标数据不存在"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("results", landPriceIndexBoList);
|
||||
resMap.put("count", landPriceIndexBoList.size());
|
||||
resMap.put("type", "土地");
|
||||
mav.setModel(resMap);
|
||||
return mav;
|
||||
}
|
||||
|
||||
private String getSourceString(int source) {
|
||||
if (source == 1) {
|
||||
return "统计局";
|
||||
} else if (source == 2) {
|
||||
return "房价网";
|
||||
} else if (source == 3) {
|
||||
return "手工输入";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setStatsIndexService(StatsIndexService statsIndexService) {
|
||||
this.statsIndexService = statsIndexService;
|
||||
}
|
||||
|
||||
public void setLandPriceIndexService(LandPriceIndexService landPriceIndexService) {
|
||||
this.landPriceIndexService = landPriceIndexService;
|
||||
}
|
||||
|
||||
public void setFangjiaOfficialAreaService(FangjiaOfficialAreaService fangjiaOfficialAreaService) {
|
||||
this.fangjiaOfficialAreaService = fangjiaOfficialAreaService;
|
||||
}
|
||||
|
||||
public void setDistrictService(DistrictService districtService) {
|
||||
this.districtService = districtService;
|
||||
}
|
||||
|
||||
public void setPropertyStatsIndexService(PropertyStatsIndexService propertyStatsIndexService) {
|
||||
this.propertyStatsIndexService = propertyStatsIndexService;
|
||||
}
|
||||
}
|
||||
|
||||
+35
-1593
File diff suppressed because it is too large
Load Diff
+302
-38
@@ -4,22 +4,29 @@ import java.util.*;
|
||||
|
||||
import com.fangjia.core.util.AnalyticsUtil;
|
||||
import com.fangjia.core.util.BeanUtils;
|
||||
import com.fangjia.core.util.DataUtil;
|
||||
import com.fangjia.core.util.DateUtil;
|
||||
import com.fangjia.dal.QueryParam;
|
||||
import com.fangjia.dal.mongo.model.ApiInvokeStatistical;
|
||||
import com.fangjia.dal.mongo.model.SendSmsLog;
|
||||
import com.fangjia.dal.mongo.open.model.ApiUserAuthority;
|
||||
import com.fangjia.dal.mongo.open.model.OpenResource;
|
||||
import com.fangjia.dal.mongo.tool.model.ApiVisitCount;
|
||||
import com.fangjia.dal.mongo.tool.model.OpenUriAnaly;
|
||||
import com.fangjia.dal.sql.model.ApiUser;
|
||||
import com.fangjia.open.HttpStatusCodeEnum;
|
||||
import com.fangjia.open.interceptors.AuthenticationBean;
|
||||
import com.fangjia.open.model.*;
|
||||
import com.fangjia.open.model.weixin.SendCodeJsonModel;
|
||||
import com.fangjia.open.model.weixin.SendCodeModel;
|
||||
import com.fangjia.service.mongo.bkoff.ApiInvokeStatisticalService;
|
||||
import com.fangjia.service.open.*;
|
||||
import com.fangjia.service.sql.ApiUserService;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.sothis.web.mvc.ActionContext;
|
||||
import org.sothis.web.mvc.ActionInvocation;
|
||||
import org.sothis.web.mvc.annotation.Param;
|
||||
@@ -41,6 +48,8 @@ public class UsersController {
|
||||
private ApiUserAuthorityService apiUserAuthorityService;
|
||||
private OpenResourceService openResourceService;
|
||||
private OpenUriAnalyService openUriAnalyService;
|
||||
private ApiUserService apiUserService;
|
||||
private ApiInvokeStatisticalService apiInvokeStatisticalService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -125,58 +134,305 @@ public class UsersController {
|
||||
return json.toString();
|
||||
}
|
||||
|
||||
public Object surplusCallCountAction() throws IllegalAccessException {
|
||||
public Object surplusCallCountAction(ApiUserModel model) throws IllegalAccessException {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
ActionContext context = ActionContext.getContext();
|
||||
HttpServletRequest request = context.getRequest();
|
||||
AuthenticationBean instance = (AuthenticationBean) request.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
|
||||
User user = null;
|
||||
if (model.getUserId() != null && model.getUserId() > 0) {
|
||||
user = userService.findById(model.getUserId());
|
||||
}
|
||||
if (null != instance) {
|
||||
User user = instance.user;
|
||||
List<OpenResource> openResourceList = openResourceService.findAll();
|
||||
List<ApiMonitorInfo> list = new ArrayList<ApiMonitorInfo>();
|
||||
long id = user.getId();
|
||||
ApiUserAuthority authority = apiUserAuthorityService.findByUserId(id);
|
||||
if (null != authority) {
|
||||
// 用户有的uri
|
||||
List<OpenResource> userResources = new ArrayList<OpenResource>();
|
||||
for (OpenResource openResource : openResourceList) {
|
||||
if (authority.getOpenResourseUris().contains(openResource.getUri())) {
|
||||
userResources.add(openResource);
|
||||
}
|
||||
user = instance.user;
|
||||
}
|
||||
if (null == instance && user == null) {
|
||||
mav.setModel(new BasicModel(HttpStatusCodeEnum.BAD_REQUEST_ERROR_KEY));
|
||||
return mav;
|
||||
}
|
||||
List<OpenResource> openResourceList = openResourceService.findAll();
|
||||
List<ApiMonitorInfo> list = new ArrayList<ApiMonitorInfo>();
|
||||
long id = user.getId();
|
||||
ApiUserAuthority authority = apiUserAuthorityService.findByUserId(id);
|
||||
if (null != authority) {
|
||||
// 用户有的uri
|
||||
List<OpenResource> userResources = new ArrayList<OpenResource>();
|
||||
for (OpenResource openResource : openResourceList) {
|
||||
if (authority.getOpenResourseUris().contains(openResource.getUri())) {
|
||||
userResources.add(openResource);
|
||||
}
|
||||
Map<String, Integer> countMap = authority.getTotalCountMap();
|
||||
if (null != countMap) {
|
||||
// 改成遍历用户有的uri
|
||||
for (OpenResource openResource : userResources) {
|
||||
String uri = openResource.getUri();
|
||||
ApiMonitorInfo info = new ApiMonitorInfo();
|
||||
info.setApiUri(uri);
|
||||
info.setApiName(openResource.getName());
|
||||
info.setUserId((int) id);
|
||||
info.setUsername(user.getUserName());
|
||||
if (null != countMap.get(uri) && countMap.get(uri) > 0) {
|
||||
long curVistedCount = apiVisitCountService.findApiVisitCountByDay(id, uri, DateUtil.truncateDay(new Date()));
|
||||
long historyCount = apiVisitCountService.findApiVisitAllCount(id, uri, DateUtil.truncateDay(new Date()));
|
||||
Integer totalCount = countMap.get(uri);
|
||||
info.setTotalCallCount(Long.valueOf(totalCount));
|
||||
long usedCount = curVistedCount + historyCount;
|
||||
info.setSurplusCallCount(totalCount - usedCount);
|
||||
info.setUsedCallCount(usedCount);
|
||||
}
|
||||
list.add(info);
|
||||
}
|
||||
Map<String, Integer> countMap = authority.getTotalCountMap();
|
||||
if (null != countMap) {
|
||||
// 改成遍历用户有的uri
|
||||
for (OpenResource openResource : userResources) {
|
||||
String uri = openResource.getUri();
|
||||
ApiMonitorInfo info = new ApiMonitorInfo();
|
||||
info.setApiUri(uri);
|
||||
info.setApiName(openResource.getName());
|
||||
info.setUserId((int) id);
|
||||
info.setUsername(user.getUserName());
|
||||
if (null != countMap.get(uri) && countMap.get(uri) > 0) {
|
||||
long curVistedCount = apiVisitCountService.findApiVisitCountByDay(id, uri, DateUtil.truncateDay(new Date()));
|
||||
long historyCount = apiVisitCountService.findApiVisitAllCount(id, uri, DateUtil.truncateDay(new Date()));
|
||||
Integer totalCount = countMap.get(uri);
|
||||
info.setTotalCallCount(Long.valueOf(totalCount));
|
||||
long usedCount = curVistedCount + historyCount;
|
||||
info.setSurplusCallCount(totalCount - usedCount);
|
||||
info.setUsedCallCount(usedCount);
|
||||
}
|
||||
list.add(info);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
BasicModel basicModel = new BasicModel(200, "ok");
|
||||
basicModel.setResult(list);
|
||||
mav.setModel(basicModel);
|
||||
return mav;
|
||||
}
|
||||
|
||||
public Object callDetailAction(ApiUserModel model) throws IllegalAccessException {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
Date startDate = null;
|
||||
Date endDate = null;
|
||||
if (StringUtils.isNotBlank(model.getBegDateStr())) {
|
||||
startDate = DateUtil.parseStringToDate(model.getBegDateStr());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getEndDateStr())) {
|
||||
endDate = DateUtil.parseStringToDate(model.getEndDateStr());
|
||||
}
|
||||
List<OpenUriAnaly> analys = openUriAnalyService.findOpenUriAnalyLogs(model.getUserId(), model.getUri(), startDate, endDate);
|
||||
List<StatAnalyBo> bos = null;
|
||||
model.setQuery("uri");
|
||||
|
||||
Long userId = model.getUserId();
|
||||
ApiUserAuthority authority = apiUserAuthorityService.findByUserId(userId);
|
||||
Map<String, Integer> countMap = authority.getTotalCountMap();
|
||||
ApiUser apiUser = apiUserService.findApiUserById(userId);
|
||||
User user = userService.findById(userId);
|
||||
if (user != null) {
|
||||
model.setUserName(user.getDisplayName());
|
||||
}
|
||||
|
||||
if (model.getQuery().equals("uri")) {
|
||||
bos = createAnalyBosByLink(analys);
|
||||
model.setChartSeries(toChartString(bos));
|
||||
}
|
||||
|
||||
long date = DateUtil.parseStringToDate("2016-11-23").getTime();
|
||||
if ("uri".equals(model.getQuery()) && startDate.getTime() >= date && endDate.getTime() > date) {
|
||||
List<ApiInvokeStatistical> apiInvokeStatisticalList = apiInvokeStatisticalService.findApiInvokeStatisticalList(model.getUserId(), startDate, endDate);
|
||||
if (bos != null && apiInvokeStatisticalList.size() > 0) {
|
||||
Map<String, Map<String, Integer>> resultMap = getCountByUri(apiInvokeStatisticalList);
|
||||
for (StatAnalyBo boTemp : bos) {
|
||||
String url = boTemp.getKey();
|
||||
boTemp.setSuccessEffectiveTime(resultMap.get(url).get("successEffectiveCount"));
|
||||
boTemp.setSuccessInvalidTime(resultMap.get(url).get("successInvalidCount"));
|
||||
boTemp.setDefeatTime(resultMap.get(url).get("defeatCount"));
|
||||
if (apiUser != null) {
|
||||
boTemp.setDeadline(apiUser.getDeadTime());
|
||||
}
|
||||
long curVistedCount = apiVisitCountService.findApiVisitCountByDay(userId, url, DateUtil.truncateDay(new Date()));
|
||||
long historyCount = apiVisitCountService.findApiVisitAllCount(userId, url, DateUtil.truncateDay(new Date()));
|
||||
if (countMap != null && countMap.containsKey(url)) {
|
||||
Integer totalCount = countMap.get(url);
|
||||
long usedCount = curVistedCount + historyCount;
|
||||
boTemp.setSurplusCallCount(Integer.valueOf((int) (totalCount - usedCount)));
|
||||
}
|
||||
}
|
||||
}
|
||||
BasicModel basicModel = new BasicModel(200, "ok");
|
||||
basicModel.setResult(list);
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
mav.setModel(new BasicModel(HttpStatusCodeEnum.BAD_REQUEST_ERROR_KEY));
|
||||
}
|
||||
List<OpenResource> resources = openResourceService.findOpenResource(null);
|
||||
Map<String, String> urlMap = converMapData(resources);
|
||||
for (StatAnalyBo boTemp : bos) {
|
||||
List<ApiVisitCount> apiVisitCounts = apiVisitCountService.findAllApiVisitCount(model.getUserId(), boTemp.getKey(), startDate, endDate);
|
||||
int total = 0;
|
||||
for (ApiVisitCount apiVisitCount : apiVisitCounts) {
|
||||
total += apiVisitCount.getVisitCount();
|
||||
}
|
||||
boTemp.setBillingCount(total);
|
||||
boTemp.setUrlName(urlMap.get(boTemp.getKey()));
|
||||
boTemp.setUrl(boTemp.getKey());
|
||||
boTemp.setKey(null);
|
||||
}
|
||||
|
||||
// model.setResourceMap(converMapData(resources));
|
||||
model.setStatAnalyBoList(sortStatAnaly(bos));
|
||||
BasicModel basicModel = new BasicModel(200, "ok");
|
||||
basicModel.setResult(model);
|
||||
mav.setModel(basicModel);
|
||||
return mav;
|
||||
}
|
||||
|
||||
private List<StatAnalyBo> createAnalyBosByLink(List<OpenUriAnaly> analys) {
|
||||
|
||||
|
||||
Map<String, Integer> ret = new HashMap<String, Integer>();
|
||||
Map<String, Map<String, Integer>> urlCodeMap = new HashMap<String, Map<String, Integer>>();
|
||||
int total = 0;
|
||||
for (OpenUriAnaly openUriAnaly : analys) {
|
||||
Integer temp = ret.get(openUriAnaly.getUrl());
|
||||
if (temp == null) {
|
||||
ret.put(openUriAnaly.getUrl(), openUriAnaly.getUrlClickCount());
|
||||
} else {
|
||||
ret.put(openUriAnaly.getUrl(), temp + openUriAnaly.getUrlClickCount());
|
||||
}
|
||||
Map<String, Integer> codeMap = urlCodeMap.get(openUriAnaly.getUrl());
|
||||
if (codeMap == null) {
|
||||
codeMap = new HashMap<String, Integer>();
|
||||
urlCodeMap.put(openUriAnaly.getUrl(), codeMap);
|
||||
}
|
||||
Map<String, Object> analyCodeMap = openUriAnaly.getCodeMap();
|
||||
for (String code : analyCodeMap.keySet()) {
|
||||
Integer count = (Integer) analyCodeMap.get(code);
|
||||
if ("200".equals(code)) {
|
||||
Integer successCount = codeMap.get("successCount");
|
||||
if (successCount == null) {
|
||||
codeMap.put("successCount", count);
|
||||
} else {
|
||||
codeMap.put("successCount", successCount + count);
|
||||
}
|
||||
} else {
|
||||
Integer defeatCount = codeMap.get("defeatCount");
|
||||
if (defeatCount == null) {
|
||||
codeMap.put("defeatCount", count);
|
||||
} else {
|
||||
codeMap.put("defeatCount", defeatCount + count);
|
||||
}
|
||||
}
|
||||
}
|
||||
total = total + openUriAnaly.getUrlClickCount();
|
||||
}
|
||||
|
||||
List<StatAnalyBo> bos = new ArrayList<StatAnalyBo>();
|
||||
int index = 0;
|
||||
double totalPercent = 0;
|
||||
for (String url : ret.keySet()) {
|
||||
Integer count = ret.get(url);
|
||||
double percent = 0;
|
||||
if (index + 1 == ret.size()) {
|
||||
percent = 100 - totalPercent;
|
||||
} else {
|
||||
double a1 = count;
|
||||
double val = a1 * 10000 / (double) total;
|
||||
percent = DataUtil.roundDouble(val / 100, 2);
|
||||
totalPercent = totalPercent + percent;
|
||||
}
|
||||
StatAnalyBo bo = new StatAnalyBo();
|
||||
bo.setKey(url);
|
||||
bo.setCount(count);
|
||||
bo.setPercent(percent);
|
||||
Map<String, Integer> codeMap = urlCodeMap.get(url);
|
||||
bo.setSuccessTime(codeMap.get("successCount"));
|
||||
bo.setDefeatTime(codeMap.get("defeatCount"));
|
||||
if (codeMap.get("successCount") != null) {
|
||||
bo.setSuccessRate(DataUtil.roundDouble((codeMap.get("successCount") * 100) / (double) count, 2));
|
||||
}
|
||||
bos.add(bo);
|
||||
|
||||
}
|
||||
return bos;
|
||||
}
|
||||
|
||||
private List<StatAnalyBo> sortStatAnaly(List<StatAnalyBo> bos) {
|
||||
Collections.sort(bos, new Comparator<StatAnalyBo>() {
|
||||
@Override
|
||||
public int compare(StatAnalyBo o1, StatAnalyBo o2) {
|
||||
if (o1.getCount() > o2.getCount()) {
|
||||
return -1;
|
||||
} else if (o1.getCount() < o2.getCount()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
return bos;
|
||||
}
|
||||
|
||||
private Map<String, String> converMapData(List<OpenResource> resources) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for (OpenResource resource : resources) {
|
||||
map.put(resource.getUri(), resource.getName());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Map<String, Integer>> getCountByUri(List<ApiInvokeStatistical> apiInvokeStatisticalList) {
|
||||
Map<String, Map<String, Integer>> resultMap = new HashMap<String, Map<String, Integer>>();
|
||||
for (ApiInvokeStatistical apiInvokeStatistical : apiInvokeStatisticalList) {
|
||||
Map<String, Integer> detailMap = resultMap.get(apiInvokeStatistical.getRequestURI());
|
||||
if (detailMap == null) {
|
||||
detailMap = new HashMap<String, Integer>();
|
||||
resultMap.put(apiInvokeStatistical.getRequestURI(), detailMap);
|
||||
}
|
||||
Integer successEffectiveCount = detailMap.get("successEffectiveCount");
|
||||
Integer successInvalidCount = detailMap.get("successInvalidCount");
|
||||
Integer defeatCount = detailMap.get("defeatCount");
|
||||
Integer totalCount = detailMap.get("totalCount");
|
||||
if (successEffectiveCount != null) {
|
||||
successEffectiveCount = successEffectiveCount + apiInvokeStatistical.getSuccessEffectiveTime();
|
||||
} else {
|
||||
successEffectiveCount = apiInvokeStatistical.getSuccessEffectiveTime();
|
||||
}
|
||||
if (successInvalidCount != null) {
|
||||
successInvalidCount = successInvalidCount + apiInvokeStatistical.getSuccessInvalidTime();
|
||||
} else {
|
||||
successInvalidCount = apiInvokeStatistical.getSuccessInvalidTime();
|
||||
;
|
||||
}
|
||||
if (defeatCount != null) {
|
||||
defeatCount = defeatCount + apiInvokeStatistical.getDefeatTime();
|
||||
} else {
|
||||
defeatCount = apiInvokeStatistical.getDefeatTime();
|
||||
}
|
||||
if (totalCount != null) {
|
||||
totalCount = totalCount + apiInvokeStatistical.getTotalTime();
|
||||
} else {
|
||||
totalCount = apiInvokeStatistical.getTotalTime();
|
||||
}
|
||||
|
||||
detailMap.put("successEffectiveCount", successEffectiveCount);
|
||||
detailMap.put("successInvalidCount", successInvalidCount);
|
||||
detailMap.put("defeatCount", defeatCount);
|
||||
detailMap.put("totalCount", totalCount);
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private String toChartString(List<StatAnalyBo> bos) {
|
||||
JSONArray ja = new JSONArray();
|
||||
for (StatAnalyBo bo : bos) {
|
||||
JSONArray array = new JSONArray();
|
||||
if (StringUtils.isNotBlank(bo.getKey())) {
|
||||
if (bo.getKey().equals("level_0")) {
|
||||
array.put("0s");
|
||||
} else if (bo.getKey().equals("level_1")) {
|
||||
array.put("1s以下");
|
||||
} else if (bo.getKey().equals("level_2")) {
|
||||
array.put("1-2s以下");
|
||||
} else if (bo.getKey().equals("level_3")) {
|
||||
array.put("2-3s以下");
|
||||
} else if (bo.getKey().equals("level_4")) {
|
||||
array.put("3s以上");
|
||||
} else if (bo.getKey().equals("level_100")) {
|
||||
array.put("暂无数据");
|
||||
} else {
|
||||
array.put(bo.getKey());
|
||||
}
|
||||
} else {
|
||||
array.put(bo.getUserId());
|
||||
}
|
||||
|
||||
array.put(bo.getPercent());
|
||||
ja.put(array);
|
||||
}
|
||||
return ja.toString();
|
||||
}
|
||||
|
||||
public void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
@@ -200,4 +456,12 @@ public class UsersController {
|
||||
public void setOpenUriAnalyService(OpenUriAnalyService openUriAnalyService) {
|
||||
this.openUriAnalyService = openUriAnalyService;
|
||||
}
|
||||
|
||||
public void setApiUserService(ApiUserService apiUserService) {
|
||||
this.apiUserService = apiUserService;
|
||||
}
|
||||
|
||||
public void setApiInvokeStatisticalService(ApiInvokeStatisticalService apiInvokeStatisticalService) {
|
||||
this.apiInvokeStatisticalService = apiInvokeStatisticalService;
|
||||
}
|
||||
}
|
||||
|
||||
+41
-1
@@ -1,14 +1,21 @@
|
||||
package com.fangjia.open.exceptionhander;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.fangjia.core.util.DingDingMessageUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.sothis.web.mvc.ActionContext;
|
||||
import org.sothis.web.mvc.ExceptionHandler;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
public class FangjiaOpenExceptionHandler implements ExceptionHandler {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FangjiaOpenExceptionHandler.class);
|
||||
|
||||
@@ -17,9 +24,42 @@ public class FangjiaOpenExceptionHandler implements ExceptionHandler {
|
||||
LOGGER.error("", e);
|
||||
}
|
||||
ActionContext context = ActionContext.getContext();
|
||||
|
||||
String ip = getLocalHostIP();
|
||||
String token = "2307d2fec8314b3e8b4b83dd1d42da2e2051638e3e668f21e77ca01258bf682c";
|
||||
try {
|
||||
DingDingMessageUtil.sendTextMessage(token, "[OpenApi] "+ip+"服务器内部错误,请及时关注!");
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
context.getResponse().setStatus(500);
|
||||
context.getResponse().setCharacterEncoding("UTF-8");
|
||||
context.getResponse().setContentType("application/json;charset=UTF-8");
|
||||
context.getResponse().getWriter().println("{\"code\":500, \"msg\":\"·þÎñÆ÷ÄÚ²¿´íÎó\"}");
|
||||
}
|
||||
|
||||
public static String getLocalHostIP() {
|
||||
/*k8s系统上运行时,使用hostname区分*/
|
||||
if ("true".equalsIgnoreCase(System.getenv("ON_K8S"))) {
|
||||
return System.getenv("HOSTNAME");
|
||||
}
|
||||
String result = null;
|
||||
try {
|
||||
Enumeration<?> enumeration = NetworkInterface.getNetworkInterfaces();
|
||||
InetAddress ip;
|
||||
while (enumeration.hasMoreElements()) {
|
||||
NetworkInterface netInterface = (NetworkInterface) enumeration.nextElement();
|
||||
Enumeration<?> addresses = netInterface.getInetAddresses();
|
||||
while (addresses.hasMoreElements()) {
|
||||
ip = (InetAddress) addresses.nextElement();
|
||||
if (ip != null && ip instanceof Inet4Address && (ip.getHostAddress().contains("192.168.0") || ip.getHostAddress().contains("192.168.10"))) {
|
||||
result = ip.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result == null ? "192.168.20.6" : result;
|
||||
}
|
||||
}
|
||||
|
||||
+477
-395
@@ -3,6 +3,7 @@ package com.fangjia.open.interceptors;
|
||||
import com.fangjia.core.RegionData;
|
||||
import com.fangjia.core.util.AnalyticsUtil;
|
||||
import com.fangjia.core.util.DateUtil;
|
||||
import com.fangjia.core.util.DingDingMessageUtil;
|
||||
import com.fangjia.dal.common.ServerAreaData;
|
||||
import com.fangjia.dal.mongo.fangjia.model.ServerArea;
|
||||
import com.fangjia.dal.mongo.open.model.ApiUserAuthority;
|
||||
@@ -14,6 +15,7 @@ import com.fangjia.open.model.RestfulModelAndView;
|
||||
import com.fangjia.service.open.ApiUserAuthorityService;
|
||||
import com.fangjia.service.open.ApiVisitCountService;
|
||||
import com.fangjia.service.sql.ApiUserService;
|
||||
import com.fangjia.service.util.kafka.KafkaProducerUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -24,428 +26,508 @@ import org.sothis.web.mvc.Interceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* APIÀ¹½ØÆ÷
|
||||
*
|
||||
* @author
|
||||
*
|
||||
*/
|
||||
public class AuthenticationInterceptor implements Interceptor {
|
||||
|
||||
|
||||
private ApiUserService apiUserService;
|
||||
private ApiUserAuthorityService apiUserAuthorityService;
|
||||
private ApiVisitCountService apiVisitCountService;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationInterceptor.class);
|
||||
private static final Date OLD_USER_SPLITTED_DATE = DateUtil.parseFormatDate("2016-06-06");
|
||||
private static final List<String> HAS_SUB_SERVICE_URIS = new ArrayList<String>();
|
||||
private static final String SUB_SERVICE_SEPARATOR = "#";
|
||||
private static final String SERVICE_CODE_PARAM_NAME = "serviceCode";
|
||||
static {
|
||||
HAS_SUB_SERVICE_URIS.add("/property/transaction");
|
||||
}
|
||||
/**
|
||||
* token过期时间 单位:s
|
||||
*/
|
||||
private static final long TOKEN_EXPIRED_TIME = 60 * 60 * 2;
|
||||
private ApiUserService apiUserService;
|
||||
|
||||
private KafkaProducerUtils kafkaProducerUtils;
|
||||
private ApiUserAuthorityService apiUserAuthorityService;
|
||||
private ApiVisitCountService apiVisitCountService;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationInterceptor.class);
|
||||
private static final Date OLD_USER_SPLITTED_DATE = DateUtil.parseFormatDate("2016-06-06");
|
||||
private static final List<String> HAS_SUB_SERVICE_URIS = new ArrayList<String>();
|
||||
private static final String SUB_SERVICE_SEPARATOR = "#";
|
||||
private static final String SERVICE_CODE_PARAM_NAME = "serviceCode";
|
||||
private static final String SMS_DATA_TOPIC = "sms-data-topic";
|
||||
private static final String SMS_DATA_TOPIC_PROFIX = "sendSms90-";
|
||||
|
||||
public Object intercept(ActionInvocation invocation) throws ActionInvocationException {
|
||||
static {
|
||||
HAS_SUB_SERVICE_URIS.add("/property/transaction");
|
||||
}
|
||||
|
||||
Authority authority = getAuthority(invocation);
|
||||
ActionContext context = invocation.getActionContext();
|
||||
HttpServletRequest request = context.getRequest();
|
||||
RestfulModelAndView ret = new RestfulModelAndView();
|
||||
ret.setViewType("rest");
|
||||
|
||||
try {
|
||||
HttpCode httpCode = null;
|
||||
if(!OpenConfig.getConfig().isOpenAllAuthority()) {
|
||||
String token = request.getParameter("token");
|
||||
if(isNeedToken(authority)){
|
||||
httpCode = authorized(token, request);
|
||||
}else if(StringUtils.isNotBlank(token)){
|
||||
ApiUser apiUser = parseApiUserByToken(FangjiaApiUtil.parse2Token(token));
|
||||
if(apiUser != null){
|
||||
User user = apiUserService.findUserById(apiUser.getId());
|
||||
AuthenticationBean.get(request, apiUser, user, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
//功能方法没有设置权限或者有该方法权限
|
||||
if (authority == null || authority.role() == Role.NONE || null == httpCode) {
|
||||
Object obj;
|
||||
try{
|
||||
obj = invocation.invoke();
|
||||
}catch (Exception e){
|
||||
throw e;
|
||||
}
|
||||
return obj;
|
||||
}else {
|
||||
if(httpCode.getErrorCode() == 4003){
|
||||
BasicModel basicModel = BasicModel.buildBadRequestModel(httpCode.getErrorMessage().toString());
|
||||
ret.setModel(basicModel);
|
||||
return ret;
|
||||
}else{
|
||||
String msg = httpCode.getMessage() + "(" + httpCode.getErrorMessage() + ")";
|
||||
BasicModel basicModel = BasicModel.buildUnAuthorizedModel().setMsg(msg);
|
||||
ret.setModel(basicModel);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Authentication error : ", e);
|
||||
ret.setModel(BasicModel.buildServerErrorModel());
|
||||
ret.setViewParam("code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isNeedToken(Authority authority){
|
||||
return authority != null && authority.role() != null && authority.role() != Role.NONE;
|
||||
}
|
||||
|
||||
private boolean isReachUpperLimit(ApiUserAuthority auth, String uri, String serviceCode) {
|
||||
|
||||
if (auth == null || auth.getLimitCountMap() == null) {
|
||||
return false;
|
||||
}
|
||||
Date visitDate = DateUtil.truncateDay(new Date());
|
||||
Integer upperLimit = auth.getLimitCountMap().get(uri);
|
||||
Long apiVisitCount;
|
||||
if (upperLimit != null && upperLimit > 0) {
|
||||
apiVisitCount = apiVisitCountService.findApiVisitCount(auth.getUserId(), uri, null, visitDate);
|
||||
if(apiVisitCount >= upperLimit){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(hasSubService(uri) && StringUtils.isNotBlank(serviceCode)){
|
||||
upperLimit = auth.getLimitCountMap().get(uri + SUB_SERVICE_SEPARATOR + serviceCode);
|
||||
if (upperLimit != null && upperLimit > 0) {
|
||||
apiVisitCount = apiVisitCountService.findApiVisitCount(auth.getUserId(), uri, serviceCode, visitDate);
|
||||
if(apiVisitCount >= upperLimit){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isReachDeadline(ApiUserAuthority auth, String uri, String serviceCode){
|
||||
|
||||
if(auth.getDeadlineMap() == null){
|
||||
return false;
|
||||
}
|
||||
Date deadline = auth.getDeadlineMap().get(uri);
|
||||
if(null != deadline && deadline.before(new Date())){
|
||||
return true;
|
||||
}
|
||||
if(hasSubService(uri) && StringUtils.isNotBlank(serviceCode)){
|
||||
deadline = auth.getDeadlineMap().get(uri + SUB_SERVICE_SEPARATOR + serviceCode);
|
||||
if(null != deadline && deadline.before(new Date())){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isReachSumLimit(ApiUserAuthority auth, String uri, String serviceCode) {
|
||||
|
||||
if (auth == null || auth.getTotalCountMap() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(auth.getTotalCountMap() != null && auth.getTotalCountMap().get(uri) != null){
|
||||
Integer totalLimit = auth.getTotalCountMap().get(uri);
|
||||
Long totalApiVisitCount;
|
||||
if(totalLimit != null && totalLimit > 0){
|
||||
totalApiVisitCount = apiVisitCountService.findApiVisitTotalCount(auth.getUserId(), uri, serviceCode);
|
||||
if(totalApiVisitCount >= totalLimit){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hasSubService(uri) && StringUtils.isNotBlank(serviceCode)){
|
||||
Integer totalLimit = auth.getTotalCountMap().get(uri + SUB_SERVICE_SEPARATOR + serviceCode);
|
||||
if(totalLimit != null && totalLimit > 0){
|
||||
Long totalApiVisitCount = apiVisitCountService.findApiVisitTotalCount(auth.getUserId(), uri, serviceCode);
|
||||
if(totalApiVisitCount >= totalLimit){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Authority getAuthority(ActionInvocation invocation) {
|
||||
Authority authority;
|
||||
// 获取方法上的权限注解
|
||||
authority = invocation.getAction().getActionMethod().getAnnotation(Authority.class);
|
||||
if (null != authority) {
|
||||
return authority;
|
||||
}
|
||||
// 获取类上的权限注解
|
||||
authority = invocation.getControllerInstance().getClass().getAnnotation(Authority.class);
|
||||
return authority;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检验是否有访问该Action的权限
|
||||
*
|
||||
* @param tokenStr
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private HttpCode authorized(String tokenStr, HttpServletRequest request) throws Exception {
|
||||
|
||||
// 检查是否为api用户
|
||||
HttpCode ret = new HttpCode(OpenHttpCodeEnum.AUTH_FAILD);
|
||||
Token token = FangjiaApiUtil.parse2Token(tokenStr);
|
||||
ApiUser apiUser = parseApiUserByToken(token);
|
||||
if (null == apiUser) {
|
||||
return ret;
|
||||
}
|
||||
if(apiUser.getDeadTime() != null && DateUtil.truncateDay(new Date()).after(apiUser.getDeadTime())){
|
||||
return new HttpCode(OpenHttpCodeEnum.USER_EXPIRED);
|
||||
}
|
||||
if(!isOldUser(apiUser) && isExpired(token)){
|
||||
return new HttpCode(OpenHttpCodeEnum.TOKEN_EXPIRED);
|
||||
}
|
||||
if (1 == apiUser.getStatus()) {
|
||||
return new HttpCode(OpenHttpCodeEnum.AUTH_FAILD, "你的账户已失效");
|
||||
}
|
||||
if(StringUtils.isNotBlank(apiUser.getIp())){
|
||||
String ip = AnalyticsUtil.getIpAddress(request);
|
||||
if(!isAuthIp(ip,apiUser)){
|
||||
ret = new HttpCode(OpenHttpCodeEnum.AUTH_FAILD,"ip[" + ip + "]无权限访问API");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
ApiUserAuthority auth = this.apiUserAuthorityService.findByUserId(apiUser.getId());
|
||||
if(auth != null){
|
||||
User user = apiUserService.findUserById(apiUser.getId());
|
||||
AuthenticationBean.get(request, apiUser, user, auth);
|
||||
}
|
||||
uri = OpenConfig.getConfig().isDevelopmentEnvironment() ? uri.replace("/fangjia-open", "") : uri;
|
||||
// 检查是否有访问该Action的权限
|
||||
boolean authAction = null != auth && auth.getOpenResourseUris().contains(uri);
|
||||
String cityName = request.getParameter("city");
|
||||
if(StringUtils.isBlank(cityName)){
|
||||
cityName = request.getParameter("cityName");
|
||||
}
|
||||
if (StringUtils.isNotBlank(cityName)) {
|
||||
boolean authCity = StringUtils.isNotBlank(apiUser.getCity()) && !StringUtils.equalsIgnoreCase(apiUser.getCity(), "all");
|
||||
if(authCity){
|
||||
cityName = request.getParameter("city");
|
||||
cityName = RegionData.formatCity(cityName);
|
||||
if(!RegionData.isCity(cityName)){
|
||||
ret = new HttpCode(OpenHttpCodeEnum.ARGUMENT_INVALID);
|
||||
ret.setErrorMessage("城市非法");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean authCity = isAuthCity(cityName, apiUser);
|
||||
if (!authCity) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.AUTH_FAILD, "您未开通城市" + (StringUtils.isNotBlank(cityName) ? cityName : StringUtils.EMPTY) + "的权限");
|
||||
}
|
||||
if (authAction && authCity) {
|
||||
if(hasSubService(uri)){
|
||||
List<String> serviceCodes = getServiceCode(request);
|
||||
for(String serviceCode : serviceCodes){
|
||||
if(!auth.getOpenResourseUris().contains(uri + SUB_SERVICE_SEPARATOR + serviceCode)){
|
||||
ret = new HttpCode(OpenHttpCodeEnum.AUTH_FAILD ,"无权限访问服务:" + serviceCode);
|
||||
return ret;
|
||||
}
|
||||
if(isReachDeadline(auth, uri, serviceCode)){
|
||||
ret = new HttpCode(OpenHttpCodeEnum.SERVICE_EXPIRED, serviceCode + "服务已过期");
|
||||
return ret;
|
||||
}
|
||||
if(isReachUpperLimit(auth, uri, serviceCode)){
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT ,serviceCode + "今日已达到配额上限");
|
||||
return ret;
|
||||
}
|
||||
// 检测是否达到总数访问上限
|
||||
if (isReachSumLimit(auth, uri, serviceCode)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT, serviceCode + "已达到配额上限");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
if(isReachDeadline(auth, uri, null)){
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT, "服务已过期");
|
||||
return ret;
|
||||
}
|
||||
// 检测是否达到今天访问上限
|
||||
if (isReachUpperLimit(auth, uri, null)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT, "今日已达到配额上限");
|
||||
return ret;
|
||||
}
|
||||
// 检测是否达到总数访问上限
|
||||
if (isReachSumLimit(auth, uri, null)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT, "已达到配额上限");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
/**
|
||||
* token过期时间 单位:s
|
||||
*/
|
||||
private List<String> getServiceCode(HttpServletRequest request){
|
||||
private static final long TOKEN_EXPIRED_TIME = 60 * 60 * 2;
|
||||
|
||||
String serviceCode = request.getParameter(SERVICE_CODE_PARAM_NAME);
|
||||
if(StringUtils.isBlank(serviceCode)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.asList(serviceCode.split(",|,"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断该API是否拥有子权限
|
||||
* @param uri
|
||||
* @return
|
||||
public Object intercept(ActionInvocation invocation) throws ActionInvocationException {
|
||||
|
||||
Authority authority = getAuthority(invocation);
|
||||
ActionContext context = invocation.getActionContext();
|
||||
HttpServletRequest request = context.getRequest();
|
||||
RestfulModelAndView ret = new RestfulModelAndView();
|
||||
ret.setViewType("rest");
|
||||
|
||||
try {
|
||||
HttpCode httpCode = null;
|
||||
if (!OpenConfig.getConfig().isOpenAllAuthority()) {
|
||||
String token = request.getParameter("token");
|
||||
if (isNeedToken(authority)) {
|
||||
httpCode = authorized(token, request);
|
||||
} else if (StringUtils.isNotBlank(token)) {
|
||||
ApiUser apiUser = parseApiUserByToken(FangjiaApiUtil.parse2Token(token));
|
||||
if (apiUser != null) {
|
||||
User user = apiUserService.findUserById(apiUser.getId());
|
||||
AuthenticationBean.get(request, apiUser, user, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
//功能方法没有设置权限或者有该方法权限
|
||||
if (authority == null || authority.role() == Role.NONE || null == httpCode) {
|
||||
Object obj;
|
||||
try {
|
||||
obj = invocation.invoke();
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
return obj;
|
||||
} else {
|
||||
if (httpCode.getErrorCode() == 4003) {
|
||||
BasicModel basicModel = BasicModel.buildBadRequestModel(httpCode.getErrorMessage().toString());
|
||||
ret.setModel(basicModel);
|
||||
return ret;
|
||||
} else {
|
||||
String msg = httpCode.getMessage() + "(" + httpCode.getErrorMessage() + ")";
|
||||
BasicModel basicModel = BasicModel.buildUnAuthorizedModel().setMsg(msg);
|
||||
ret.setModel(basicModel);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String ip = getLocalHostIP();
|
||||
String token = "2307d2fec8314b3e8b4b83dd1d42da2e2051638e3e668f21e77ca01258bf682c";
|
||||
try {
|
||||
DingDingMessageUtil.sendTextMessage(token, "[OpenApi] "+ip+"服务器内部错误,请及时关注!");
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
LOGGER.error("Authentication error : ", e);
|
||||
ret.setModel(BasicModel.buildServerErrorModel());
|
||||
ret.setViewParam("code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLocalHostIP() {
|
||||
/*k8s系统上运行时,使用hostname区分*/
|
||||
if ("true".equalsIgnoreCase(System.getenv("ON_K8S"))) {
|
||||
return System.getenv("HOSTNAME");
|
||||
}
|
||||
String result = null;
|
||||
try {
|
||||
Enumeration<?> enumeration = NetworkInterface.getNetworkInterfaces();
|
||||
InetAddress ip;
|
||||
while (enumeration.hasMoreElements()) {
|
||||
NetworkInterface netInterface = (NetworkInterface) enumeration.nextElement();
|
||||
Enumeration<?> addresses = netInterface.getInetAddresses();
|
||||
while (addresses.hasMoreElements()) {
|
||||
ip = (InetAddress) addresses.nextElement();
|
||||
if (ip != null && ip instanceof Inet4Address && (ip.getHostAddress().contains("192.168.0") || ip.getHostAddress().contains("192.168.10"))) {
|
||||
result = ip.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result == null ? "192.168.20.6" : result;
|
||||
}
|
||||
|
||||
private boolean isNeedToken(Authority authority) {
|
||||
return authority != null && authority.role() != null && authority.role() != Role.NONE;
|
||||
}
|
||||
|
||||
private boolean isReachUpperLimit(ApiUserAuthority auth, String uri, String serviceCode) {
|
||||
|
||||
if (auth == null || auth.getLimitCountMap() == null) {
|
||||
return false;
|
||||
}
|
||||
Date visitDate = DateUtil.truncateDay(new Date());
|
||||
Integer upperLimit = auth.getLimitCountMap().get(uri);
|
||||
Long apiVisitCount;
|
||||
if (upperLimit != null && upperLimit > 0) {
|
||||
apiVisitCount = apiVisitCountService.findApiVisitCount(auth.getUserId(), uri, null, visitDate);
|
||||
if (apiVisitCount >= upperLimit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (hasSubService(uri) && StringUtils.isNotBlank(serviceCode)) {
|
||||
upperLimit = auth.getLimitCountMap().get(uri + SUB_SERVICE_SEPARATOR + serviceCode);
|
||||
if (upperLimit != null && upperLimit > 0) {
|
||||
apiVisitCount = apiVisitCountService.findApiVisitCount(auth.getUserId(), uri, serviceCode, visitDate);
|
||||
if (apiVisitCount >= upperLimit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isReachDeadline(ApiUserAuthority auth, String uri, String serviceCode) {
|
||||
|
||||
if (auth.getDeadlineMap() == null) {
|
||||
return false;
|
||||
}
|
||||
Date deadline = auth.getDeadlineMap().get(uri);
|
||||
if (null != deadline && deadline.before(new Date())) {
|
||||
return true;
|
||||
}
|
||||
if (hasSubService(uri) && StringUtils.isNotBlank(serviceCode)) {
|
||||
deadline = auth.getDeadlineMap().get(uri + SUB_SERVICE_SEPARATOR + serviceCode);
|
||||
if (null != deadline && deadline.before(new Date())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isReachSumLimit(ApiUserAuthority auth, String uri, String serviceCode) {
|
||||
|
||||
if (auth == null || auth.getTotalCountMap() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auth.getTotalCountMap() != null && auth.getTotalCountMap().get(uri) != null) {
|
||||
Integer totalLimit = auth.getTotalCountMap().get(uri);
|
||||
Long totalApiVisitCount;
|
||||
if (totalLimit != null && totalLimit > 0) {
|
||||
totalApiVisitCount = apiVisitCountService.findApiVisitTotalCount(auth.getUserId(), uri, serviceCode);
|
||||
if (totalApiVisitCount >= totalLimit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasSubService(uri) && StringUtils.isNotBlank(serviceCode)) {
|
||||
Integer totalLimit = auth.getTotalCountMap().get(uri + SUB_SERVICE_SEPARATOR + serviceCode);
|
||||
if (totalLimit != null && totalLimit > 0) {
|
||||
Long totalApiVisitCount = apiVisitCountService.findApiVisitTotalCount(auth.getUserId(), uri, serviceCode);
|
||||
if (totalApiVisitCount >= totalLimit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isReach90SumLimit(ApiUserAuthority auth, String uri, String serviceCode) {
|
||||
|
||||
if (auth == null || auth.getTotalCountMap() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auth.getTotalCountMap() != null && auth.getTotalCountMap().get(uri) != null) {
|
||||
Integer totalLimit = auth.getTotalCountMap().get(uri);
|
||||
Long totalApiVisitCount;
|
||||
if (totalLimit != null && totalLimit > 0) {
|
||||
totalApiVisitCount = apiVisitCountService.findApiVisitTotalCount(auth.getUserId(), uri, serviceCode);
|
||||
if (totalApiVisitCount.intValue() == (int) (totalLimit * 0.9)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasSubService(uri) && StringUtils.isNotBlank(serviceCode)) {
|
||||
Integer totalLimit = auth.getTotalCountMap().get(uri + SUB_SERVICE_SEPARATOR + serviceCode);
|
||||
if (totalLimit != null && totalLimit > 0) {
|
||||
Long totalApiVisitCount = apiVisitCountService.findApiVisitTotalCount(auth.getUserId(), uri, serviceCode);
|
||||
if (totalApiVisitCount.intValue() == (int) (totalLimit * 0.9)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Authority getAuthority(ActionInvocation invocation) {
|
||||
Authority authority;
|
||||
// 获取方法上的权限注解
|
||||
authority = invocation.getAction().getActionMethod().getAnnotation(Authority.class);
|
||||
if (null != authority) {
|
||||
return authority;
|
||||
}
|
||||
// 获取类上的权限注解
|
||||
authority = invocation.getControllerInstance().getClass().getAnnotation(Authority.class);
|
||||
return authority;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检验是否有访问该Action的权限
|
||||
*
|
||||
* @param tokenStr
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private boolean hasSubService(String uri){
|
||||
return HAS_SUB_SERVICE_URIS.contains(uri);
|
||||
}
|
||||
private HttpCode authorized(String tokenStr, HttpServletRequest request) throws Exception {
|
||||
|
||||
/**
|
||||
* 2016年06月06日以前的用户是老用户,token不过期
|
||||
* @param apiUser
|
||||
* @return
|
||||
*/
|
||||
private boolean isOldUser(ApiUser apiUser){
|
||||
return OLD_USER_SPLITTED_DATE.after(apiUser.getCreationDate());
|
||||
}
|
||||
// 检查是否为api用户
|
||||
HttpCode ret = new HttpCode(OpenHttpCodeEnum.AUTH_FAILD);
|
||||
Token token = FangjiaApiUtil.parse2Token(tokenStr);
|
||||
ApiUser apiUser = parseApiUserByToken(token);
|
||||
if (null == apiUser) {
|
||||
return ret;
|
||||
}
|
||||
if (apiUser.getDeadTime() != null && DateUtil.truncateDay(new Date()).after(apiUser.getDeadTime())) {
|
||||
return new HttpCode(OpenHttpCodeEnum.USER_EXPIRED);
|
||||
}
|
||||
if (!isOldUser(apiUser) && isExpired(token)) {
|
||||
return new HttpCode(OpenHttpCodeEnum.TOKEN_EXPIRED);
|
||||
}
|
||||
if (1 == apiUser.getStatus()) {
|
||||
return new HttpCode(OpenHttpCodeEnum.AUTH_FAILD, "你的账户已失效");
|
||||
}
|
||||
if (StringUtils.isNotBlank(apiUser.getIp())) {
|
||||
String ip = AnalyticsUtil.getIpAddress(request);
|
||||
if (!isAuthIp(ip, apiUser)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.AUTH_FAILD, "ip[" + ip + "]无权限访问API");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Token是否过期
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
private boolean isExpired(Token token){
|
||||
return System.currentTimeMillis() / 1000 - token.getTimestamp() > TOKEN_EXPIRED_TIME;
|
||||
}
|
||||
String uri = request.getRequestURI();
|
||||
ApiUserAuthority auth = this.apiUserAuthorityService.findByUserId(apiUser.getId());
|
||||
User user = apiUserService.findUserById(apiUser.getId());
|
||||
if (auth != null) {
|
||||
AuthenticationBean.get(request, apiUser, user, auth);
|
||||
}
|
||||
uri = OpenConfig.getConfig().isDevelopmentEnvironment() ? uri.replace("/fangjia-open", "") : uri;
|
||||
// 检查是否有访问该Action的权限
|
||||
boolean authAction = null != auth && auth.getOpenResourseUris().contains(uri);
|
||||
String cityName = request.getParameter("city");
|
||||
if (StringUtils.isBlank(cityName)) {
|
||||
cityName = request.getParameter("cityName");
|
||||
}
|
||||
if (StringUtils.isNotBlank(cityName)) {
|
||||
boolean authCity = StringUtils.isNotBlank(apiUser.getCity()) && !StringUtils.equalsIgnoreCase(apiUser.getCity(), "all");
|
||||
if (authCity) {
|
||||
cityName = request.getParameter("city");
|
||||
cityName = RegionData.formatCity(cityName);
|
||||
if (!RegionData.isCity(cityName)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.ARGUMENT_INVALID);
|
||||
ret.setErrorMessage("城市非法");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean authCity = isAuthCity(cityName, apiUser);
|
||||
if (!authCity) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.AUTH_FAILD, "您未开通城市" + (StringUtils.isNotBlank(cityName) ? cityName : StringUtils.EMPTY) + "的权限");
|
||||
}
|
||||
if (authAction && authCity) {
|
||||
if (hasSubService(uri)) {
|
||||
List<String> serviceCodes = getServiceCode(request);
|
||||
for (String serviceCode : serviceCodes) {
|
||||
if (!auth.getOpenResourseUris().contains(uri + SUB_SERVICE_SEPARATOR + serviceCode)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.AUTH_FAILD, "无权限访问服务:" + serviceCode);
|
||||
return ret;
|
||||
}
|
||||
if (isReachDeadline(auth, uri, serviceCode)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.SERVICE_EXPIRED, serviceCode + "服务已过期");
|
||||
return ret;
|
||||
}
|
||||
if (isReachUpperLimit(auth, uri, serviceCode)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT, serviceCode + "今日已达到配额上限");
|
||||
return ret;
|
||||
}
|
||||
// 检测是否达到总数访问上限
|
||||
if (isReachSumLimit(auth, uri, serviceCode)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT, serviceCode + "已达到配额上限");
|
||||
return ret;
|
||||
}
|
||||
// 检测是否达到总数的90%
|
||||
if (isReach90SumLimit(auth, uri, serviceCode)) {
|
||||
kafkaProducerUtils.send(SMS_DATA_TOPIC, SMS_DATA_TOPIC_PROFIX + apiUser.getPhone() + "-" + user.getUserName() + "-" + uri);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ip 验证客户IP是否在注册的白名单中
|
||||
* @param apiUser
|
||||
* @return
|
||||
*/
|
||||
private boolean isAuthIp(String ip,ApiUser apiUser){
|
||||
if(StringUtils.isBlank(ip) || StringUtils.isBlank(apiUser.getIp())){
|
||||
return false;
|
||||
}
|
||||
String[] ips = apiUser.getIp().split("\n");
|
||||
for(String authIp:ips){
|
||||
if(StringUtils.isNotBlank(authIp) && ip.startsWith(authIp.replaceAll("\\s", ""))){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (isReachDeadline(auth, uri, null)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT, "服务已过期");
|
||||
return ret;
|
||||
}
|
||||
// 检测是否达到今天访问上限
|
||||
if (isReachUpperLimit(auth, uri, null)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT, "今日已达到配额上限");
|
||||
return ret;
|
||||
}
|
||||
// 检测是否达到总数访问上限
|
||||
if (isReachSumLimit(auth, uri, null)) {
|
||||
ret = new HttpCode(OpenHttpCodeEnum.UPPER_LIMIT, "已达到配额上限");
|
||||
return ret;
|
||||
}
|
||||
// 检测是否达到总数的90%
|
||||
if (isReach90SumLimit(auth, uri, null)) {
|
||||
kafkaProducerUtils.send(SMS_DATA_TOPIC, SMS_DATA_TOPIC_PROFIX + apiUser.getPhone() + "-" + user.getUserName() + "-" + uri);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有权限访问该城市
|
||||
*
|
||||
* @param cityName
|
||||
* @param apiUser
|
||||
* @return
|
||||
*/
|
||||
private boolean isAuthCity(String cityName, ApiUser apiUser) {
|
||||
// 若访问当前接口不需要城市参数,则返回true
|
||||
if (StringUtils.isBlank(cityName)) {
|
||||
return true;
|
||||
}
|
||||
if(!RegionData.isCity(cityName)){
|
||||
String city = RegionData.formatCity(cityName);
|
||||
if(null != city){
|
||||
cityName = city;
|
||||
}
|
||||
}
|
||||
// 若当前接口需要城市,检查是否有访问当前城市的权限
|
||||
boolean authCity = StringUtils.isNotBlank(apiUser.getCity()) && !StringUtils.equalsIgnoreCase(apiUser.getCity(), "all");
|
||||
if (authCity) {
|
||||
ServerArea city = ServerAreaData.getServerAreaByDisplayDefaultNull(cityName);
|
||||
if (null != city) {
|
||||
return apiUser.getCity().contains(city.getSpell());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private ApiUser parseApiUserByToken(Token token){
|
||||
|
||||
if(token == null){
|
||||
return null;
|
||||
}
|
||||
ApiUser apiUser = apiUserService.findApiUserById(token.getUserId());
|
||||
if(apiUser == null){
|
||||
return null;
|
||||
}
|
||||
if(!apiUser.getAppKey().equals(token.getAppKey())){
|
||||
return null;
|
||||
}
|
||||
return apiUser;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新版token验证
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
private ApiUser checkNewAuthorized(String token) {
|
||||
/**
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private List<String> getServiceCode(HttpServletRequest request) {
|
||||
|
||||
Map<String, String> tokenMap = FangjiaApiUtil.parseToken(token);
|
||||
if (tokenMap == null) {
|
||||
return null;
|
||||
}
|
||||
// token验证后,拿取出的字段再去数据库验证一遍
|
||||
if (StringUtils.isNotBlank(tokenMap.get("userid")) && !"null".equals(tokenMap.get("userid"))) {
|
||||
ApiUser apiUser = apiUserService.findApiUserById(Long.parseLong(tokenMap.get("userid")));
|
||||
if (apiUser != null) {
|
||||
if (tokenMap.get("appKey").equals(apiUser.getAppKey())) {
|
||||
return apiUser;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
String serviceCode = request.getParameter(SERVICE_CODE_PARAM_NAME);
|
||||
if (StringUtils.isBlank(serviceCode)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.asList(serviceCode.split(",|,"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断该API是否拥有子权限
|
||||
*
|
||||
* @param uri
|
||||
* @return
|
||||
*/
|
||||
private boolean hasSubService(String uri) {
|
||||
return HAS_SUB_SERVICE_URIS.contains(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2016年06月06日以前的用户是老用户,token不过期
|
||||
*
|
||||
* @param apiUser
|
||||
* @return
|
||||
*/
|
||||
private boolean isOldUser(ApiUser apiUser) {
|
||||
return OLD_USER_SPLITTED_DATE.after(apiUser.getCreationDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Token是否过期
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
private boolean isExpired(Token token) {
|
||||
return System.currentTimeMillis() / 1000 - token.getTimestamp() > TOKEN_EXPIRED_TIME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ip 验证客户IP是否在注册的白名单中
|
||||
* @param apiUser
|
||||
* @return
|
||||
*/
|
||||
private boolean isAuthIp(String ip, ApiUser apiUser) {
|
||||
if (StringUtils.isBlank(ip) || StringUtils.isBlank(apiUser.getIp())) {
|
||||
return false;
|
||||
}
|
||||
String[] ips = apiUser.getIp().split("\n");
|
||||
for (String authIp : ips) {
|
||||
if (StringUtils.isNotBlank(authIp) && ip.startsWith(authIp.replaceAll("\\s", ""))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有权限访问该城市
|
||||
*
|
||||
* @param cityName
|
||||
* @param apiUser
|
||||
* @return
|
||||
*/
|
||||
private boolean isAuthCity(String cityName, ApiUser apiUser) {
|
||||
// 若访问当前接口不需要城市参数,则返回true
|
||||
if (StringUtils.isBlank(cityName)) {
|
||||
return true;
|
||||
}
|
||||
if (!RegionData.isCity(cityName)) {
|
||||
String city = RegionData.formatCity(cityName);
|
||||
if (null != city) {
|
||||
cityName = city;
|
||||
}
|
||||
}
|
||||
// 若当前接口需要城市,检查是否有访问当前城市的权限
|
||||
boolean authCity = StringUtils.isNotBlank(apiUser.getCity()) && !StringUtils.equalsIgnoreCase(apiUser.getCity(), "all");
|
||||
if (authCity) {
|
||||
ServerArea city = ServerAreaData.getServerAreaByDisplayDefaultNull(cityName);
|
||||
if (null != city) {
|
||||
return apiUser.getCity().contains(city.getSpell());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private ApiUser parseApiUserByToken(Token token) {
|
||||
|
||||
if (token == null) {
|
||||
return null;
|
||||
}
|
||||
ApiUser apiUser = apiUserService.findApiUserById(token.getUserId());
|
||||
if (apiUser == null) {
|
||||
return null;
|
||||
}
|
||||
if (!apiUser.getAppKey().equals(token.getAppKey())) {
|
||||
return null;
|
||||
}
|
||||
return apiUser;
|
||||
}
|
||||
|
||||
|
||||
public void setApiUserService(ApiUserService apiUserService) {
|
||||
this.apiUserService = apiUserService;
|
||||
}
|
||||
/**
|
||||
* 新版token验证
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
private ApiUser checkNewAuthorized(String token) {
|
||||
|
||||
public void setApiUserAuthorityService(ApiUserAuthorityService apiUserAuthorityService) {
|
||||
this.apiUserAuthorityService = apiUserAuthorityService;
|
||||
}
|
||||
Map<String, String> tokenMap = FangjiaApiUtil.parseToken(token);
|
||||
if (tokenMap == null) {
|
||||
return null;
|
||||
}
|
||||
// token验证后,拿取出的字段再去数据库验证一遍
|
||||
if (StringUtils.isNotBlank(tokenMap.get("userid")) && !"null".equals(tokenMap.get("userid"))) {
|
||||
ApiUser apiUser = apiUserService.findApiUserById(Long.parseLong(tokenMap.get("userid")));
|
||||
if (apiUser != null) {
|
||||
if (tokenMap.get("appKey").equals(apiUser.getAppKey())) {
|
||||
return apiUser;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setApiVisitCountService(ApiVisitCountService apiVisitCountService) {
|
||||
this.apiVisitCountService = apiVisitCountService;
|
||||
}
|
||||
|
||||
public void setApiUserService(ApiUserService apiUserService) {
|
||||
this.apiUserService = apiUserService;
|
||||
}
|
||||
|
||||
public void setApiUserAuthorityService(ApiUserAuthorityService apiUserAuthorityService) {
|
||||
this.apiUserAuthorityService = apiUserAuthorityService;
|
||||
}
|
||||
|
||||
public void setApiVisitCountService(ApiVisitCountService apiVisitCountService) {
|
||||
this.apiVisitCountService = apiVisitCountService;
|
||||
}
|
||||
|
||||
public void setKafkaProducerUtils(KafkaProducerUtils kafkaProducerUtils) {
|
||||
this.kafkaProducerUtils = kafkaProducerUtils;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package com.fangjia.open.model;
|
||||
|
||||
import com.fangjia.dal.mongo.model.ApiInvokeStatistical;
|
||||
import com.fangjia.dal.mongo.open.model.ApiUserAuthority;
|
||||
import com.fangjia.service.open.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* API用户管理Model
|
||||
@@ -12,6 +18,620 @@ public class ApiUserModel extends FangjiaApiModel{
|
||||
private Date endDate;
|
||||
private String uri;
|
||||
|
||||
private static final long serialVersionUID = 7044341510628330454L;
|
||||
|
||||
private String begDateStr;// 查询开始日期
|
||||
private String endDateStr;// 查询结束日期
|
||||
private String statDate;
|
||||
private String appKey;
|
||||
private String userName;
|
||||
private String displayName;
|
||||
private String siteName;
|
||||
private String password;
|
||||
private String email;
|
||||
private String ip;
|
||||
private Integer isTest;
|
||||
private Integer purpose;
|
||||
private String msg;
|
||||
private Long userId;
|
||||
private String company;
|
||||
private List<ApiUserBo> apiUserBoList;
|
||||
private List<EachCityBo> eachCityBoList;
|
||||
private String limitCountMap;
|
||||
private String totalCountMap;
|
||||
private Integer creditLevelStatus;
|
||||
private String priceType;
|
||||
private Map<String,Double> priceRatingMap;
|
||||
private Integer isMonitor;
|
||||
|
||||
private String contact;
|
||||
|
||||
private String phone;
|
||||
|
||||
public String getPriceType() {
|
||||
return priceType;
|
||||
}
|
||||
|
||||
public void setPriceType(String priceType) {
|
||||
this.priceType = priceType;
|
||||
}
|
||||
|
||||
public List<EachCityBo> getEachCityBoList() {
|
||||
return eachCityBoList;
|
||||
}
|
||||
|
||||
public void setEachCityBoList(List<EachCityBo> eachCityBoList) {
|
||||
this.eachCityBoList = eachCityBoList;
|
||||
}
|
||||
|
||||
private Integer sum;
|
||||
private Integer limit;
|
||||
/*** 权限控制相关 **/
|
||||
private ApiUserBo apiUserBo;
|
||||
private List<ApiUserAuthority> authorityList;
|
||||
private ApiUserAuthority authority;
|
||||
private List<AuthorityBo> authorityBoList;
|
||||
//private List<ServerArea> serverAreaList;
|
||||
private List<Map<String,Object>> serverAreaList;
|
||||
private String openCitys;// 汉字说明
|
||||
private List<String> cityFirstLetters;// 城市拼音首字母
|
||||
private String type;
|
||||
private String citys;// spell
|
||||
private String unCheckCitys;// 页面反选的city
|
||||
private Integer status;
|
||||
private boolean hasAuth;
|
||||
private boolean supportLatLng;
|
||||
private Integer maxFrequency;
|
||||
private String frequencyPeriod;
|
||||
private Integer maximum;
|
||||
|
||||
private ApiInvokeStatistical apiInvokeStatistical;
|
||||
private Double one;
|
||||
private Double newOne;
|
||||
private Double two;
|
||||
private Double three;
|
||||
private Double four;
|
||||
private Double five;
|
||||
private Date deadTime;
|
||||
private String manager;
|
||||
private Double evaluateRate;
|
||||
|
||||
private String data;
|
||||
|
||||
private Integer isCheckCount;
|
||||
|
||||
private String openResourseUrisMap;
|
||||
|
||||
public String getOpenResourseUrisMap() {
|
||||
return openResourseUrisMap;
|
||||
}
|
||||
|
||||
public void setOpenResourseUrisMap(String openResourseUrisMap) {
|
||||
this.openResourseUrisMap = openResourseUrisMap;
|
||||
}
|
||||
|
||||
public Integer getIsCheckCount() {
|
||||
return isCheckCount;
|
||||
}
|
||||
|
||||
public void setIsCheckCount(Integer isCheckCount) {
|
||||
this.isCheckCount = isCheckCount;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
private String chartSeries;
|
||||
|
||||
private List<OpenUriAnalyBo> OpenUriAnalyBoList;
|
||||
private List<StatAnalyBo> statAnalyBoList;
|
||||
private Integer way;
|
||||
private Map<String, String> resourceMap;
|
||||
private String query;
|
||||
private Integer totalCount;
|
||||
private String xAxis;
|
||||
private String credits;
|
||||
private String uncitys;
|
||||
|
||||
public String getUncitys() {
|
||||
return uncitys;
|
||||
}
|
||||
|
||||
public void setUncitys(String uncitys) {
|
||||
this.uncitys = uncitys;
|
||||
}
|
||||
|
||||
public String getCredits() {
|
||||
return credits;
|
||||
}
|
||||
|
||||
public void setCredits(String credits) {
|
||||
this.credits = credits;
|
||||
}
|
||||
|
||||
public String getxAxis() {
|
||||
return xAxis;
|
||||
}
|
||||
|
||||
public void setxAxis(String xAxis) {
|
||||
this.xAxis = xAxis;
|
||||
}
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getSiteName() {
|
||||
return siteName;
|
||||
}
|
||||
|
||||
public void setSiteName(String siteName) {
|
||||
this.siteName = siteName;
|
||||
}
|
||||
|
||||
public String getAppKey() {
|
||||
return appKey;
|
||||
}
|
||||
|
||||
public void setAppKey(String appKey) {
|
||||
this.appKey = appKey;
|
||||
}
|
||||
|
||||
public String getBegDateStr() {
|
||||
return begDateStr;
|
||||
}
|
||||
|
||||
public void setBegDateStr(String begDateStr) {
|
||||
this.begDateStr = begDateStr;
|
||||
}
|
||||
|
||||
public String getEndDateStr() {
|
||||
return endDateStr;
|
||||
}
|
||||
|
||||
public void setEndDateStr(String endDateStr) {
|
||||
this.endDateStr = endDateStr;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public List<ApiUserBo> getApiUserBoList() {
|
||||
return apiUserBoList;
|
||||
}
|
||||
|
||||
public void setApiUserBoList(List<ApiUserBo> apiUserBoList) {
|
||||
this.apiUserBoList = apiUserBoList;
|
||||
}
|
||||
|
||||
public ApiUserBo getApiUserBo() {
|
||||
return apiUserBo;
|
||||
}
|
||||
|
||||
public void setApiUserBo(ApiUserBo apiUserBo) {
|
||||
this.apiUserBo = apiUserBo;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public List<ApiUserAuthority> getAuthorityList() {
|
||||
return authorityList;
|
||||
}
|
||||
|
||||
public void setAuthorityList(List<ApiUserAuthority> authorityList) {
|
||||
this.authorityList = authorityList;
|
||||
}
|
||||
|
||||
public ApiUserAuthority getAuthority() {
|
||||
return authority;
|
||||
}
|
||||
|
||||
public void setAuthority(ApiUserAuthority authority) {
|
||||
this.authority = authority;
|
||||
}
|
||||
|
||||
|
||||
public boolean isHasAuth() {
|
||||
return hasAuth;
|
||||
}
|
||||
|
||||
public void setHasAuth(boolean hasAuth) {
|
||||
this.hasAuth = hasAuth;
|
||||
}
|
||||
|
||||
public boolean isSupportLatLng() {
|
||||
return supportLatLng;
|
||||
}
|
||||
|
||||
public void setSupportLatLng(boolean supportLatLng) {
|
||||
this.supportLatLng = supportLatLng;
|
||||
}
|
||||
|
||||
public List<AuthorityBo> getAuthorityBoList() {
|
||||
return authorityBoList;
|
||||
}
|
||||
|
||||
public void setAuthorityBoList(List<AuthorityBo> authorityBoList) {
|
||||
this.authorityBoList = authorityBoList;
|
||||
}
|
||||
|
||||
public List<String> getCityFirstLetters() {
|
||||
return cityFirstLetters;
|
||||
}
|
||||
|
||||
public void setCityFirstLetters(List<String> cityFirstLetters) {
|
||||
this.cityFirstLetters = cityFirstLetters;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/*public List<ServerArea> getServerAreaList() {
|
||||
return serverAreaList;
|
||||
}
|
||||
|
||||
public void setServerAreaList(List<ServerArea> serverAreaList) {
|
||||
this.serverAreaList = serverAreaList;
|
||||
}*/
|
||||
public List<Map<String, Object>> getServerAreaList() {
|
||||
return serverAreaList;
|
||||
}
|
||||
|
||||
public void setServerAreaList(List<Map<String,Object>> serverAreaList) {
|
||||
this.serverAreaList = serverAreaList;
|
||||
}
|
||||
|
||||
public String getCitys() {
|
||||
return citys;
|
||||
}
|
||||
|
||||
public void setCitys(String citys) {
|
||||
this.citys = citys;
|
||||
}
|
||||
|
||||
public String getOpenCitys() {
|
||||
return openCitys;
|
||||
}
|
||||
|
||||
public void setOpenCitys(String openCitys) {
|
||||
this.openCitys = openCitys;
|
||||
}
|
||||
|
||||
public String getUnCheckCitys() {
|
||||
return unCheckCitys;
|
||||
}
|
||||
|
||||
public void setUnCheckCitys(String unCheckCitys) {
|
||||
this.unCheckCitys = unCheckCitys;
|
||||
}
|
||||
|
||||
public Integer getSum() {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public void setSum(Integer sum) {
|
||||
this.sum = sum;
|
||||
}
|
||||
|
||||
|
||||
public Integer getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(Integer limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(String company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public Integer getMaximum() {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
public void setMaximum(Integer maximum) {
|
||||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
public String getFrequencyPeriod() {
|
||||
return frequencyPeriod;
|
||||
}
|
||||
|
||||
public void setFrequencyPeriod(String frequencyPeriod) {
|
||||
this.frequencyPeriod = frequencyPeriod;
|
||||
}
|
||||
|
||||
public Integer getMaxFrequency() {
|
||||
return maxFrequency;
|
||||
}
|
||||
|
||||
public void setMaxFrequency(Integer maxFrequency) {
|
||||
this.maxFrequency = maxFrequency;
|
||||
}
|
||||
public List<OpenUriAnalyBo> getOpenUriAnalyBoList() {
|
||||
return OpenUriAnalyBoList;
|
||||
}
|
||||
|
||||
public void setOpenUriAnalyBoList(List<OpenUriAnalyBo> openUriAnalyBoList) {
|
||||
OpenUriAnalyBoList = openUriAnalyBoList;
|
||||
}
|
||||
|
||||
public String getChartSeries() {
|
||||
return chartSeries;
|
||||
}
|
||||
|
||||
public void setChartSeries(String chartSeries) {
|
||||
this.chartSeries = chartSeries;
|
||||
}
|
||||
|
||||
public String getStatDate() {
|
||||
return statDate;
|
||||
}
|
||||
|
||||
public void setStatDate(String statDate) {
|
||||
this.statDate = statDate;
|
||||
}
|
||||
|
||||
public Integer getWay() {
|
||||
return way;
|
||||
}
|
||||
|
||||
public void setWay(Integer way) {
|
||||
this.way = way;
|
||||
}
|
||||
|
||||
public Map<String, String> getResourceMap() {
|
||||
return resourceMap;
|
||||
}
|
||||
|
||||
public void setResourceMap(Map<String, String> resourceMap) {
|
||||
this.resourceMap = resourceMap;
|
||||
}
|
||||
|
||||
public List<StatAnalyBo> getStatAnalyBoList() {
|
||||
return statAnalyBoList;
|
||||
}
|
||||
|
||||
public void setStatAnalyBoList(List<StatAnalyBo> statAnalyBoList) {
|
||||
this.statAnalyBoList = statAnalyBoList;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public Integer getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(Integer totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
public ApiInvokeStatistical getApiInvokeStatistical() {
|
||||
return apiInvokeStatistical;
|
||||
}
|
||||
|
||||
public void setApiInvokeStatistical(ApiInvokeStatistical apiInvokeStatistical) {
|
||||
this.apiInvokeStatistical = apiInvokeStatistical;
|
||||
}
|
||||
public Double getEvaluateRate() {
|
||||
return evaluateRate;
|
||||
}
|
||||
|
||||
public void setEvaluateRate(Double evaluateRate) {
|
||||
this.evaluateRate = evaluateRate;
|
||||
}
|
||||
|
||||
public Integer getIsTest() {
|
||||
return isTest;
|
||||
}
|
||||
|
||||
public void setIsTest(Integer isTest) {
|
||||
this.isTest = isTest;
|
||||
}
|
||||
|
||||
public String getLimitCountMap() {
|
||||
return limitCountMap;
|
||||
}
|
||||
|
||||
public void setLimitCountMap(String limitCountMap) {
|
||||
this.limitCountMap = limitCountMap;
|
||||
}
|
||||
|
||||
public String getTotalCountMap() {
|
||||
return totalCountMap;
|
||||
}
|
||||
|
||||
public void setTotalCountMap(String totalCountMap) {
|
||||
this.totalCountMap = totalCountMap;
|
||||
}
|
||||
|
||||
public Integer getPurpose() {
|
||||
return purpose;
|
||||
}
|
||||
|
||||
public void setPurpose(Integer purpose) {
|
||||
this.purpose = purpose;
|
||||
}
|
||||
|
||||
public Map<String, Double> getPriceRatingMap() {
|
||||
return priceRatingMap;
|
||||
}
|
||||
|
||||
public void setPriceRatingMap(Map<String, Double> priceRatingMap) {
|
||||
this.priceRatingMap = priceRatingMap;
|
||||
}
|
||||
|
||||
public Double getOne() {
|
||||
return one;
|
||||
}
|
||||
|
||||
public void setOne(Double one) {
|
||||
this.one = one;
|
||||
}
|
||||
|
||||
public Double getNewOne() {
|
||||
return newOne;
|
||||
}
|
||||
|
||||
public void setNewOne(Double newOne) {
|
||||
this.newOne = newOne;
|
||||
}
|
||||
|
||||
public Double getTwo() {
|
||||
return two;
|
||||
}
|
||||
|
||||
public void setTwo(Double two) {
|
||||
this.two = two;
|
||||
}
|
||||
|
||||
public Double getThree() {
|
||||
return three;
|
||||
}
|
||||
|
||||
public void setThree(Double three) {
|
||||
this.three = three;
|
||||
}
|
||||
|
||||
public Double getFour() {
|
||||
return four;
|
||||
}
|
||||
|
||||
public void setFour(Double four) {
|
||||
this.four = four;
|
||||
}
|
||||
|
||||
public Double getFive() {
|
||||
return five;
|
||||
}
|
||||
|
||||
public void setFive(Double five) {
|
||||
this.five = five;
|
||||
}
|
||||
|
||||
public Integer getCreditLevelStatus() {
|
||||
return creditLevelStatus;
|
||||
}
|
||||
|
||||
public void setCreditLevelStatus(Integer creditLevelStatus) {
|
||||
this.creditLevelStatus = creditLevelStatus;
|
||||
}
|
||||
|
||||
public Date getDeadTime() {
|
||||
return deadTime;
|
||||
}
|
||||
|
||||
public void setDeadTime(Date deadTime) {
|
||||
this.deadTime = deadTime;
|
||||
}
|
||||
|
||||
public String getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
public void setManager(String manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public Integer getIsMonitor() {
|
||||
return isMonitor;
|
||||
}
|
||||
|
||||
public void setIsMonitor(Integer isMonitor) {
|
||||
this.isMonitor = isMonitor;
|
||||
}
|
||||
|
||||
public String getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact(String contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,11 @@ public class StatsIndexModel {
|
||||
private String id;
|
||||
|
||||
private String city;
|
||||
|
||||
private String yearmonth;
|
||||
private String district;
|
||||
private String name;
|
||||
private String type;
|
||||
|
||||
private Integer yearmonth;
|
||||
|
||||
private Integer source;
|
||||
|
||||
@@ -65,11 +68,11 @@ public class StatsIndexModel {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getYearmonth() {
|
||||
public Integer getYearmonth() {
|
||||
return yearmonth;
|
||||
}
|
||||
|
||||
public void setYearmonth(String yearmonth) {
|
||||
public void setYearmonth(Integer yearmonth) {
|
||||
this.yearmonth = yearmonth;
|
||||
}
|
||||
|
||||
@@ -216,7 +219,28 @@ public class StatsIndexModel {
|
||||
public void setIfNew(Integer ifNew) {
|
||||
this.ifNew = ifNew;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getDistrict() {
|
||||
return district;
|
||||
}
|
||||
|
||||
public void setDistrict(String district) {
|
||||
this.district = district;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ public class FileDao {
|
||||
IMPORTANT_CATEGORY = Arrays.asList(System.getProperty("fangjia.important.category", "data_file,district,shop,office,avatar,flash,user_house,upload").split(","));
|
||||
|
||||
try {
|
||||
filesCollection = new Mongo("fs.mongo.db.fangjia.com", 27000).getDB("fangjia_fs").getCollection("files");
|
||||
gridFs = new GridFS(filesCollection.getDB(), "fangjia_fs");
|
||||
filesCollection = new Mongo("fs.mongo.db.fangjia.com", 27000).getDB("fangjia").getCollection("files");
|
||||
gridFs = new GridFS(filesCollection.getDB(), "fangjia");
|
||||
cappedCollection = new Mongo("capped.mongo.db.fangjia.com", Integer.getInteger("capped.mongo.port", 27000)).getDB("fangjia_fs").getCollection("files_capped");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user