添加高德同步代码

This commit is contained in:
lulz1 2024-04-24 16:31:15 +08:00
parent f6b2ffd1ee
commit e55ad8fe83
4 changed files with 53 additions and 3 deletions

View File

@ -1,10 +1,16 @@
package com.chint.interfaces.rest.amap;
import com.chint.interfaces.rest.amap.dto.location.LocationRequestParam;
import com.chint.interfaces.rest.amap.dto.location.LocationResponse;
import com.chint.interfaces.rest.amap.request.AmapRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Optional;
import static com.chint.infrastructure.constant.AmapConstant.AMAP_LOCATION_PATH;
@Service
public class AmapLocationRequest {
@ -15,5 +21,15 @@ public class AmapLocationRequest {
private String BaseUrl;
// public
public LocationResponse locationQuery(String keyWords) {
LocationRequestParam param = LocationRequestParam.of(keyWords);
return amapRequest.post(BaseUrl + AMAP_LOCATION_PATH, param, LocationResponse.class);
}
public String getACodeByLocationName(String locationName) {
LocationResponse locationQuery = locationQuery(locationName);
Optional<LocationResponse.AmapCityInfo> amapCityInfo = Optional.ofNullable(locationQuery.getData())
.flatMap(it -> Optional.ofNullable(it.get(0)));
return amapCityInfo.map(LocationResponse.AmapCityInfo::getName).orElse(null);
}
}

View File

@ -1,8 +1,16 @@
package com.chint.interfaces.rest.amap.dto.location;
import com.chint.interfaces.rest.amap.BaseRequestParam;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestParam;
@Data
public class LocationRequestParam {
public class LocationRequestParam extends BaseRequestParam {
private String keywords;
public static LocationRequestParam of(String keywords) {
LocationRequestParam param = new LocationRequestParam();
param.keywords = keywords;
return param;
}
}

View File

@ -1,4 +1,18 @@
package com.chint.interfaces.rest.amap.dto.location;
public class LocationResponse {
import com.chint.interfaces.rest.amap.BaseResponse;
import lombok.Data;
import java.util.List;
@Data
public class LocationResponse extends BaseResponse {
private List<AmapCityInfo> data;
@Data
public static class AmapCityInfo {
private String adcode; //城市adcode
private String name; //城市名称
private String namePinyin; //城市名称拼音
private String initialLetter; //城市名称拼音首字母大写
}
}

View File

@ -1,11 +1,13 @@
package com.chint;
import com.chint.domain.aggregates.user.User;
import com.chint.interfaces.rest.amap.AmapLocationRequest;
import com.chint.interfaces.rest.amap.AmapLoginRequest;
import com.chint.interfaces.rest.amap.AmapUserRequest;
import com.chint.interfaces.rest.amap.BaseResponse;
import com.chint.interfaces.rest.amap.dto.UserQueryResponse;
import com.chint.interfaces.rest.amap.dto.detail.OrderDetailResponse;
import com.chint.interfaces.rest.amap.dto.location.LocationResponse;
import com.chint.interfaces.rest.amap.dto.token.TokenDto;
import com.chint.interfaces.rest.amap.dto.token.TokenResponse;
import com.chint.interfaces.rest.amap.request.OrderDetailRequest;
@ -27,6 +29,9 @@ public class AmapTest {
@Autowired
private AmapLoginRequest amapLoginRequest;
@Autowired
private AmapLocationRequest amapLocationRequest;
private Gson gson = new Gson();
private User user = new User(1L, "230615020", 1, "卢麟哲", "lulz1@chint.com", "15857193365", "A30000001");
@ -56,6 +61,11 @@ public class AmapTest {
System.out.println(gson.toJson(h5LoginResponse.getRedirectUrl()));
}
@Test
public void queryLocation(){
LocationResponse locationQuery = amapLocationRequest.locationQuery("北京");
System.out.println(gson.toJson(locationQuery.getData()));
}
@Autowired
private TokenRequest tokenRequest;
@ -104,4 +114,6 @@ public class AmapTest {
public void cancelOrder() {
takeCarRequest.cancelOrder("20240301", "行程变更");
}
}