Authored by mali

地址的调整

@@ -38,7 +38,7 @@ public class AreaService { @@ -38,7 +38,7 @@ public class AreaService {
38 @Value("${erp-gateway.url}") 38 @Value("${erp-gateway.url}")
39 private String erpGatewayUrl; 39 private String erpGatewayUrl;
40 40
41 - private static final String GET_HIDDEN_ADDRESS = "/erp/passport/gethiddenAddress"; //根据uid获取地址信息 41 + private static final String GETPROVINCES = "/erp/passport/getProvinces"; //根据地址父id查询子集合
42 42
43 @Autowired 43 @Autowired
44 private ServiceCaller serviceCaller; 44 private ServiceCaller serviceCaller;
@@ -49,12 +49,14 @@ public class AreaService { @@ -49,12 +49,14 @@ public class AreaService {
49 @Autowired 49 @Autowired
50 private ConfigReader configReader; 50 private ConfigReader configReader;
51 51
52 - public Map<Integer, String> selectByCodeList(Integer uid, List<Integer> codeList) { 52 + private boolean areaByErp() {
  53 + return configReader.getBoolean("ufo.platform.queryAreaCode", false);
  54 + }
53 55
54 - String hasSecondHandSorts = configReader.getString("ufo.platform.queryAreaCode", "true");  
55 56
56 - if (StringUtils.equals(hasSecondHandSorts, "true")) {  
57 - return getAddressInfo(uid, codeList.get(3), codeList); 57 + public Map<Integer, String> selectByCodeList(Integer uid, List<Integer> codeList) {
  58 + if (areaByErp()) {
  59 + //return getAddressInfoByErp(uid, codeList.get(3), codeList);
58 } 60 }
59 61
60 List<Area> areaList = areaMapper.selectByCodeList(codeList); 62 List<Area> areaList = areaMapper.selectByCodeList(codeList);
@@ -62,87 +64,41 @@ public class AreaService { @@ -62,87 +64,41 @@ public class AreaService {
62 return areaMap; 64 return areaMap;
63 } 65 }
64 66
65 - private Map<Integer, String> getAddressInfo(int uid, Integer areaCodeEx, List<Integer> codeList) {  
66 - LOGGER.info("method getAddressInfo in, uid : {}, codeList : {}", uid, codeList);  
67 -  
68 - AddressInfo addressInfoWithUrl = getAddressInfoWithUrl(uid, areaCodeEx);  
69 - String area = addressInfoWithUrl.getArea();  
70 -  
71 - String[] split = area.split(" ");  
72 - if (split.length != 4) {  
73 - throw new ServiceException(ServiceError.ADDRESS_NULL);  
74 - }  
75 67
76 - Map<Integer, String> areaMap = new HashMap<>();  
77 - for (int i = 0; i < 4; i++) {  
78 - areaMap.put(codeList.get(i), split[i]); 68 + public Map<Integer, String> selectByParentCode(String parentCode) {
  69 + if (areaByErp()) {
  70 + return selectByErp(parentCode);
79 } 71 }
80 72
81 - return areaMap; 73 + List<Area> areaList = areaMapper.selectByParentCode(parentCode);
  74 + return areaList.stream().collect(Collectors.toMap(Area::getId, Area::getCaption));
82 } 75 }
83 76
84 -  
85 - private AddressInfo getAddressInfoWithUrl(int uid, Integer areaCodeEx) {  
86 - String url = erpGatewayUrl + GET_HIDDEN_ADDRESS;  
87 -  
88 - // 收货地址信息, 入口参数:uid, address_id  
89 - UserAddressReqBO userAddressReqBO = new UserAddressReqBO();  
90 - userAddressReqBO.setUid(uid);  
91 -  
92 - //超时,使用默认地址,后续需要手动补充地址  
93 - ApiResponse defaultResponse = new ApiResponse();  
94 -  
95 - 77 + private Map<Integer, String> selectByErp(String parentCode) {
96 Map<String,Object> params = Maps.newHashMap(); 78 Map<String,Object> params = Maps.newHashMap();
97 - params.put("uid", uid); 79 + params.put("id", parentCode);
98 params.put("debug", "XYZ"); 80 params.put("debug", "XYZ");
99 -  
100 AddressInfo addressInfo ; 81 AddressInfo addressInfo ;
101 ApiResponse userAddressBO ; 82 ApiResponse userAddressBO ;
102 try { 83 try {
103 - userAddressBO = serviceCaller.get("users.getAddress", url, params,  
104 - ApiResponse.class, defaultResponse).get(500, TimeUnit.MILLISECONDS); 84 + userAddressBO = serviceCaller.get("users.getProvinces", erpGatewayUrl + GETPROVINCES, params, ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
105 85
106 }catch (Exception ex){ 86 }catch (Exception ex){
107 - LOGGER.warn("in getAddressInfo fail, uid {}", uid, ex); 87 + LOGGER.warn("in getProvinces fail, parentCode {}", parentCode, ex);
108 throw new ServiceException(ServiceError.ADDRESS_NULL); 88 throw new ServiceException(ServiceError.ADDRESS_NULL);
109 } 89 }
110 JSONArray addressArray ; 90 JSONArray addressArray ;
111 if (userAddressBO == null || (addressArray = (JSONArray)userAddressBO.getData()) == null){ 91 if (userAddressBO == null || (addressArray = (JSONArray)userAddressBO.getData()) == null){
112 - LOGGER.warn("in getAddressInfo fail, uid {}", uid); 92 + LOGGER.warn("in getProvinces fail, parentCode {}", parentCode);
113 throw new ServiceException(ServiceError.ADDRESS_NULL); 93 throw new ServiceException(ServiceError.ADDRESS_NULL);
114 } 94 }
115 95
116 - LOGGER.info("method users.getAddress result is {}", addressArray);  
117 -  
118 - JSONObject addressJsonObj = (JSONObject) addressArray.parallelStream().filter(addressJson -> {  
119 - Integer areaCode = ((JSONObject)addressJson).getInteger("area_code");  
120 - return Objects.nonNull(areaCodeEx) && areaCodeEx.equals(areaCode);  
121 - }).findFirst().orElse(null);  
122 - if (addressJsonObj == null){  
123 - LOGGER.warn("in getAddressInfo fail, uid {}, addressArray {}", uid, addressArray);  
124 - throw new ServiceException(ServiceError.ADDRESS_NULL);  
125 - }  
126 - addressInfo = userAddressRsp2AddressInfo(addressJsonObj);  
127 - return addressInfo;  
128 - } 96 + Map<Integer, String> result = new HashMap<>();
  97 + addressArray.parallelStream().forEach(item -> {
  98 + result.put(((JSONObject)item).getInteger("id"), ((JSONObject)item).getString("caption"));
  99 + });
129 100
130 - public Map<Integer, String> selectByParentCode(String parentCode) {  
131 - List<Area> areaList = areaMapper.selectByParentCode(parentCode);  
132 - return areaList.stream().collect(Collectors.toMap(Area::getId, Area::getCaption)); 101 + return result;
133 } 102 }
134 103
135 - private static AddressInfo userAddressRsp2AddressInfo(JSONObject resp){  
136 - AddressInfo addressInfo = new AddressInfo();  
137 - addressInfo.setAddress_id(resp.getInteger("address_id"));  
138 - addressInfo.setAreaCode(resp.getString("area_code"));  
139 - addressInfo.setArea(resp.getString("area"));  
140 - addressInfo.setAddress(resp.getString("address"));  
141 - addressInfo.setConsignee(resp.getString("consignee"));  
142 - addressInfo.setPhone(resp.getString("phone"));  
143 - addressInfo.setMobile(resp.getString("mobile"));  
144 - addressInfo.setZipCode(resp.getString("zip_code"));  
145 - addressInfo.setIsUpdate(resp.getString("is_update"));  
146 - return addressInfo;  
147 - }  
148 } 104 }