同步代码
This commit is contained in:
parent
5f6a7103f7
commit
bae2199a7a
|
@ -10,8 +10,19 @@ public class LocationRes {
|
|||
@Id
|
||||
private Long locationId;
|
||||
private String locationName;
|
||||
private String continent;
|
||||
private String country;
|
||||
private String province;
|
||||
|
||||
public static LocationRes copyFrom(Location location) {
|
||||
return BeanUtil.copyProperties(location, LocationRes.class);
|
||||
LocationRes locationRes = BeanUtil.copyProperties(location, LocationRes.class);
|
||||
String[] parts = location.getLocationPathName().split("_");
|
||||
if (parts.length != 4) {
|
||||
throw new IllegalArgumentException("Invalid loclocationation string format");
|
||||
}
|
||||
locationRes.setContinent(parts[0]);
|
||||
locationRes.setCountry(parts[1]);
|
||||
locationRes.setProvince(parts[2]);
|
||||
return locationRes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class LocationController {
|
|||
if (locations != null && !locations.isEmpty()) {
|
||||
locationRes = locations
|
||||
.stream()
|
||||
.map(location -> BeanUtil.copyProperties(location, LocationRes.class)).toList();
|
||||
.map(LocationRes::copyFrom).toList();
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class LocationController {
|
|||
if (internationalLocations != null && !internationalLocations.isEmpty()) {
|
||||
internationalLocationRes = internationalLocations
|
||||
.stream()
|
||||
.map(location -> BeanUtil.copyProperties(location, LocationRes.class)).toList();
|
||||
.map(LocationRes::copyFrom).toList();
|
||||
}
|
||||
|
||||
HotCityResponseDto dto = new HotCityResponseDto();
|
||||
|
|
|
@ -131,7 +131,7 @@ public class LoginController {
|
|||
return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult);
|
||||
}
|
||||
|
||||
@ApiOperation("商旅平台单点")
|
||||
@ApiOperation("商旅平台移动端单点")
|
||||
@Transactional
|
||||
@PostMapping("/login/sso/mobile")
|
||||
public Result<UserLoginResult> loginSSOMobile(@RequestBody UserLoginParam userLoginParam){
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.chint.domain.aggregates.location;
|
||||
|
||||
import com.chint.interfaces.rest.ctrip.dto.city.FlightCitySearchResponse;
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
@ -19,4 +20,16 @@ public class CityEntity {
|
|||
private String province;
|
||||
private String provinceename;
|
||||
private String provinceName;
|
||||
|
||||
public static CityEntity copyFrom(FlightCitySearchResponse.DataItem dataItem) {
|
||||
CityEntity cityEntity = new CityEntity();
|
||||
cityEntity.setCity(String.valueOf(dataItem.getCityId()));
|
||||
cityEntity.setCityename(dataItem.getEName());
|
||||
cityEntity.setCityName(dataItem.getName());
|
||||
cityEntity.setCountryName(dataItem.getCountry());
|
||||
cityEntity.setCountryename(dataItem.getEName());
|
||||
cityEntity.setJianPin(dataItem.getCode());
|
||||
cityEntity.setProvinceName(dataItem.getProvince());
|
||||
return cityEntity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public class CTripConstant {
|
|||
public static final String C_TRIP_AUTH_LOGIN = "/corpservice/authorize/login";
|
||||
public static final String C_TRIP_SINGLE_LOGIN = "/m/SingleSignOn/H5SignInfo";
|
||||
public static final String C_TRIP_AUDIT_PATH = "/corpservice/AuditService/Audit";
|
||||
public static final String C_TRIP_FLIGHT_CITY_PATH = "/CorpOpenapi/Position/SearchFlightCityInfo";
|
||||
public static final String C_TRIP_REQUEST_SECRET = "zhengtai2024_nEbmKfOo";
|
||||
public static final String C_TRIP_AUDIT_ACTION_SUCCESS = "T";
|
||||
public static final String C_TRIP_AUDIT_ACTION_FAIL = "F";
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
package com.chint.infrastructure.repository;
|
||||
|
||||
import com.chint.domain.aggregates.location.CityEntity;
|
||||
import com.chint.domain.exceptions.NotFoundException;
|
||||
import com.chint.domain.repository.CityRepository;
|
||||
import com.chint.infrastructure.repository.jdbc.JdbcCityRepository;
|
||||
import com.chint.interfaces.rest.ctrip.CTripFlightCitySearchRequest;
|
||||
import com.chint.interfaces.rest.ctrip.dto.city.FlightCitySearchResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
|
||||
|
||||
@Repository
|
||||
public class CityRepositoryImpl implements CityRepository {
|
||||
|
@ -14,6 +20,9 @@ public class CityRepositoryImpl implements CityRepository {
|
|||
@Autowired
|
||||
private JdbcCityRepository jdbcCityRepository;
|
||||
|
||||
@Autowired
|
||||
private CTripFlightCitySearchRequest cTripFlightCitySearchRequest;
|
||||
|
||||
@Override
|
||||
public void saveAll(List<CityEntity> cities) {
|
||||
jdbcCityRepository.save(cities.get(0));
|
||||
|
@ -22,7 +31,22 @@ public class CityRepositoryImpl implements CityRepository {
|
|||
|
||||
@Override
|
||||
public CityEntity findByCityName(String name) {
|
||||
return jdbcCityRepository.findByCityName(name);
|
||||
}
|
||||
CityEntity byCityName = jdbcCityRepository.findByCityName(name);
|
||||
if (byCityName == null) {
|
||||
Optional<FlightCitySearchResponse.DataItem> optional = Optional.ofNullable(
|
||||
cTripFlightCitySearchRequest.getFlightCity(name, 1).getData()
|
||||
.stream()
|
||||
.filter(dataItem -> dataItem.getType() == 5 || dataItem.getType() == 4)
|
||||
.toList()
|
||||
.get(0));
|
||||
if (optional.isPresent()) {
|
||||
FlightCitySearchResponse.DataItem dataItem = optional.get();
|
||||
CityEntity cityEntity = CityEntity.copyFrom(dataItem);
|
||||
jdbcCityRepository.save(cityEntity);
|
||||
return cityEntity;
|
||||
} else {
|
||||
throw new NotFoundException(NOT_FOUND);
|
||||
}
|
||||
}return byCityName;}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.chint.interfaces.rest.ctrip;
|
||||
|
||||
import com.chint.interfaces.rest.base.PostRequest;
|
||||
import com.chint.interfaces.rest.ctrip.dto.Authentification;
|
||||
import com.chint.interfaces.rest.ctrip.dto.city.FlightCitySearchRequest;
|
||||
import com.chint.interfaces.rest.ctrip.dto.city.FlightCitySearchResponse;
|
||||
import com.google.gson.Gson;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.chint.infrastructure.constant.CTripConstant.C_TRIP_FLIGHT_CITY_PATH;
|
||||
import static com.chint.infrastructure.constant.CTripConstant.LANGUAGE_CN;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CTripFlightCitySearchRequest {
|
||||
|
||||
|
||||
@Value("${cTrip.baseUrl}")
|
||||
public String C_TRIP_BASE_URL;
|
||||
|
||||
@Value("${cTrip.appKey}")
|
||||
private String C_TRIP_APP_KEY;
|
||||
|
||||
@Autowired
|
||||
private PostRequest postRequest;
|
||||
|
||||
@Autowired
|
||||
private CTripTicketRequest ticketRequest;
|
||||
private String flightCityUrl;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
this.flightCityUrl = C_TRIP_BASE_URL + C_TRIP_FLIGHT_CITY_PATH;
|
||||
}
|
||||
|
||||
|
||||
public FlightCitySearchResponse getFlightCity(String Keyword, Integer AreaType) {
|
||||
Gson gson = new Gson();
|
||||
Authentification auth = new Authentification(C_TRIP_APP_KEY, ticketRequest.loadTicket());
|
||||
FlightCitySearchRequest flightCitySearchRequest = new FlightCitySearchRequest();
|
||||
flightCitySearchRequest.setAuth(auth);
|
||||
flightCitySearchRequest.setKeyword(Keyword);
|
||||
flightCitySearchRequest.setAreaType(AreaType);
|
||||
flightCitySearchRequest.setLanguage(LANGUAGE_CN);
|
||||
FlightCitySearchResponse flightCitySearchResponse = postRequest.post(flightCityUrl, flightCitySearchRequest, FlightCitySearchResponse.class);
|
||||
log.info(gson.toJson(flightCitySearchResponse.getData().get(0)));
|
||||
return flightCitySearchResponse;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.chint.interfaces.rest.ctrip.dto.city;
|
||||
|
||||
import com.chint.interfaces.rest.ctrip.dto.Authentification;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FlightCitySearchRequest {
|
||||
private String Keyword;
|
||||
private Integer AreaType;
|
||||
private String Language;
|
||||
private Authentification auth;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.chint.interfaces.rest.ctrip.dto.city;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FlightCitySearchResponse {
|
||||
private String Keyword;
|
||||
private List<DataItem> Data;
|
||||
private Status Status;
|
||||
|
||||
// Getters and setters
|
||||
@Data
|
||||
public static class DataItem {
|
||||
private String Name;
|
||||
private int Type;
|
||||
private String EName;
|
||||
private String Spell;
|
||||
private String ShortSpell;
|
||||
private String Country;
|
||||
private String Province;
|
||||
private String Code;
|
||||
private int CityId;
|
||||
private String TimeZone;
|
||||
private int POIID;
|
||||
private List<DatasItem> Datas;
|
||||
|
||||
// Getters and setters
|
||||
}
|
||||
@Data
|
||||
public static class DatasItem {
|
||||
private String Name;
|
||||
private int Type;
|
||||
private String EName;
|
||||
private String Country;
|
||||
private String Province;
|
||||
private String Code;
|
||||
private int POIID;
|
||||
|
||||
// Getters and setters
|
||||
}
|
||||
@Data
|
||||
public static class Status {
|
||||
private int ErrorCode;
|
||||
private boolean Success;
|
||||
|
||||
// Getters and setters
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.chint.domain.service.supplier.SupplierService;
|
|||
import com.chint.domain.value_object.SupplierCallbackData;
|
||||
import com.chint.infrastructure.util.BaseContext;
|
||||
import com.chint.interfaces.rest.ctrip.*;
|
||||
import com.chint.interfaces.rest.ctrip.dto.city.FlightCitySearchResponse;
|
||||
import com.chint.interfaces.rest.ctrip.dto.estimate.request.BookingRelatedApiRequest;
|
||||
import com.chint.interfaces.rest.ctrip.dto.estimate.request.FlightProductInfo;
|
||||
import com.chint.interfaces.rest.ctrip.dto.estimate.request.RouteInfo;
|
||||
|
@ -54,6 +55,9 @@ public class CTripTest {
|
|||
@Autowired
|
||||
private CTripNoteController cTripNoteController;
|
||||
|
||||
@Autowired
|
||||
private CTripFlightCitySearchRequest cTripFlightCitySearchRequest;
|
||||
|
||||
private User user = new User(1L, "230615020", 1, "卢麟哲", "1033719135@qq.com", "15857193365");
|
||||
|
||||
//@Test
|
||||
|
@ -168,4 +172,10 @@ public class CTripTest {
|
|||
BaseContext.setCurrentUser(user);
|
||||
cTripNoteController.handlerData("30607415392","Paid","HotelContract");
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryFlightCity(){
|
||||
FlightCitySearchResponse flightCity = cTripFlightCitySearchRequest.getFlightCity("杭州", 2);
|
||||
System.out.println(flightCity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,6 +130,5 @@ class RouteApplicationTests {
|
|||
void arrayToStr(){
|
||||
List<Long> ids = List.of(1L,2L,3L,4L);
|
||||
System.out.println(Arrays.toString(ids.toArray()));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue