...
|
...
|
@@ -38,7 +38,7 @@ public class AreaService { |
|
|
@Value("${erp-gateway.url}")
|
|
|
private String erpGatewayUrl;
|
|
|
|
|
|
private static final String GET_HIDDEN_ADDRESS = "/erp/passport/gethiddenAddress"; //根据uid获取地址信息
|
|
|
private static final String GETPROVINCES = "/erp/passport/getProvinces"; //根据地址父id查询子集合
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
...
|
...
|
@@ -49,12 +49,14 @@ public class AreaService { |
|
|
@Autowired
|
|
|
private ConfigReader configReader;
|
|
|
|
|
|
public Map<Integer, String> selectByCodeList(Integer uid, List<Integer> codeList) {
|
|
|
private boolean areaByErp() {
|
|
|
return configReader.getBoolean("ufo.platform.queryAreaCode", false);
|
|
|
}
|
|
|
|
|
|
String hasSecondHandSorts = configReader.getString("ufo.platform.queryAreaCode", "true");
|
|
|
|
|
|
if (StringUtils.equals(hasSecondHandSorts, "true")) {
|
|
|
return getAddressInfo(uid, codeList.get(3), codeList);
|
|
|
public Map<Integer, String> selectByCodeList(Integer uid, List<Integer> codeList) {
|
|
|
if (areaByErp()) {
|
|
|
//return getAddressInfoByErp(uid, codeList.get(3), codeList);
|
|
|
}
|
|
|
|
|
|
List<Area> areaList = areaMapper.selectByCodeList(codeList);
|
...
|
...
|
@@ -62,87 +64,41 @@ public class AreaService { |
|
|
return areaMap;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, String> getAddressInfo(int uid, Integer areaCodeEx, List<Integer> codeList) {
|
|
|
LOGGER.info("method getAddressInfo in, uid : {}, codeList : {}", uid, codeList);
|
|
|
|
|
|
AddressInfo addressInfoWithUrl = getAddressInfoWithUrl(uid, areaCodeEx);
|
|
|
String area = addressInfoWithUrl.getArea();
|
|
|
|
|
|
String[] split = area.split(" ");
|
|
|
if (split.length != 4) {
|
|
|
throw new ServiceException(ServiceError.ADDRESS_NULL);
|
|
|
}
|
|
|
|
|
|
Map<Integer, String> areaMap = new HashMap<>();
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
areaMap.put(codeList.get(i), split[i]);
|
|
|
public Map<Integer, String> selectByParentCode(String parentCode) {
|
|
|
if (areaByErp()) {
|
|
|
return selectByErp(parentCode);
|
|
|
}
|
|
|
|
|
|
return areaMap;
|
|
|
List<Area> areaList = areaMapper.selectByParentCode(parentCode);
|
|
|
return areaList.stream().collect(Collectors.toMap(Area::getId, Area::getCaption));
|
|
|
}
|
|
|
|
|
|
|
|
|
private AddressInfo getAddressInfoWithUrl(int uid, Integer areaCodeEx) {
|
|
|
String url = erpGatewayUrl + GET_HIDDEN_ADDRESS;
|
|
|
|
|
|
// 收货地址信息, 入口参数:uid, address_id
|
|
|
UserAddressReqBO userAddressReqBO = new UserAddressReqBO();
|
|
|
userAddressReqBO.setUid(uid);
|
|
|
|
|
|
//超时,使用默认地址,后续需要手动补充地址
|
|
|
ApiResponse defaultResponse = new ApiResponse();
|
|
|
|
|
|
|
|
|
private Map<Integer, String> selectByErp(String parentCode) {
|
|
|
Map<String,Object> params = Maps.newHashMap();
|
|
|
params.put("uid", uid);
|
|
|
params.put("id", parentCode);
|
|
|
params.put("debug", "XYZ");
|
|
|
|
|
|
AddressInfo addressInfo ;
|
|
|
ApiResponse userAddressBO ;
|
|
|
try {
|
|
|
userAddressBO = serviceCaller.get("users.getAddress", url, params,
|
|
|
ApiResponse.class, defaultResponse).get(500, TimeUnit.MILLISECONDS);
|
|
|
userAddressBO = serviceCaller.get("users.getProvinces", erpGatewayUrl + GETPROVINCES, params, ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
|
|
|
|
|
|
}catch (Exception ex){
|
|
|
LOGGER.warn("in getAddressInfo fail, uid {}", uid, ex);
|
|
|
LOGGER.warn("in getProvinces fail, parentCode {}", parentCode, ex);
|
|
|
throw new ServiceException(ServiceError.ADDRESS_NULL);
|
|
|
}
|
|
|
JSONArray addressArray ;
|
|
|
if (userAddressBO == null || (addressArray = (JSONArray)userAddressBO.getData()) == null){
|
|
|
LOGGER.warn("in getAddressInfo fail, uid {}", uid);
|
|
|
LOGGER.warn("in getProvinces fail, parentCode {}", parentCode);
|
|
|
throw new ServiceException(ServiceError.ADDRESS_NULL);
|
|
|
}
|
|
|
|
|
|
LOGGER.info("method users.getAddress result is {}", addressArray);
|
|
|
|
|
|
JSONObject addressJsonObj = (JSONObject) addressArray.parallelStream().filter(addressJson -> {
|
|
|
Integer areaCode = ((JSONObject)addressJson).getInteger("area_code");
|
|
|
return Objects.nonNull(areaCodeEx) && areaCodeEx.equals(areaCode);
|
|
|
}).findFirst().orElse(null);
|
|
|
if (addressJsonObj == null){
|
|
|
LOGGER.warn("in getAddressInfo fail, uid {}, addressArray {}", uid, addressArray);
|
|
|
throw new ServiceException(ServiceError.ADDRESS_NULL);
|
|
|
}
|
|
|
addressInfo = userAddressRsp2AddressInfo(addressJsonObj);
|
|
|
return addressInfo;
|
|
|
}
|
|
|
Map<Integer, String> result = new HashMap<>();
|
|
|
addressArray.parallelStream().forEach(item -> {
|
|
|
result.put(((JSONObject)item).getInteger("id"), ((JSONObject)item).getString("caption"));
|
|
|
});
|
|
|
|
|
|
public Map<Integer, String> selectByParentCode(String parentCode) {
|
|
|
List<Area> areaList = areaMapper.selectByParentCode(parentCode);
|
|
|
return areaList.stream().collect(Collectors.toMap(Area::getId, Area::getCaption));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private static AddressInfo userAddressRsp2AddressInfo(JSONObject resp){
|
|
|
AddressInfo addressInfo = new AddressInfo();
|
|
|
addressInfo.setAddress_id(resp.getInteger("address_id"));
|
|
|
addressInfo.setAreaCode(resp.getString("area_code"));
|
|
|
addressInfo.setArea(resp.getString("area"));
|
|
|
addressInfo.setAddress(resp.getString("address"));
|
|
|
addressInfo.setConsignee(resp.getString("consignee"));
|
|
|
addressInfo.setPhone(resp.getString("phone"));
|
|
|
addressInfo.setMobile(resp.getString("mobile"));
|
|
|
addressInfo.setZipCode(resp.getString("zip_code"));
|
|
|
addressInfo.setIsUpdate(resp.getString("is_update"));
|
|
|
return addressInfo;
|
|
|
}
|
|
|
} |
...
|
...
|
|