同步代码

This commit is contained in:
lulz1 2024-02-29 15:33:39 +08:00
parent 5f6a7103f7
commit bae2199a7a
11 changed files with 181 additions and 7 deletions

View File

@ -10,8 +10,19 @@ public class LocationRes {
@Id @Id
private Long locationId; private Long locationId;
private String locationName; private String locationName;
private String continent;
private String country;
private String province;
public static LocationRes copyFrom(Location location) { 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;
} }
} }

View File

@ -76,7 +76,7 @@ public class LocationController {
if (locations != null && !locations.isEmpty()) { if (locations != null && !locations.isEmpty()) {
locationRes = locations locationRes = locations
.stream() .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()) { if (internationalLocations != null && !internationalLocations.isEmpty()) {
internationalLocationRes = internationalLocations internationalLocationRes = internationalLocations
.stream() .stream()
.map(location -> BeanUtil.copyProperties(location, LocationRes.class)).toList(); .map(LocationRes::copyFrom).toList();
} }
HotCityResponseDto dto = new HotCityResponseDto(); HotCityResponseDto dto = new HotCityResponseDto();

View File

@ -131,7 +131,7 @@ public class LoginController {
return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult);
} }
@ApiOperation("商旅平台单点") @ApiOperation("商旅平台移动端单点")
@Transactional @Transactional
@PostMapping("/login/sso/mobile") @PostMapping("/login/sso/mobile")
public Result<UserLoginResult> loginSSOMobile(@RequestBody UserLoginParam userLoginParam){ public Result<UserLoginResult> loginSSOMobile(@RequestBody UserLoginParam userLoginParam){

View File

@ -1,5 +1,6 @@
package com.chint.domain.aggregates.location; package com.chint.domain.aggregates.location;
import com.chint.interfaces.rest.ctrip.dto.city.FlightCitySearchResponse;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table; import org.springframework.data.relational.core.mapping.Table;
@ -19,4 +20,16 @@ public class CityEntity {
private String province; private String province;
private String provinceename; private String provinceename;
private String provinceName; 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;
}
} }

View File

@ -27,6 +27,7 @@ public class CTripConstant {
public static final String C_TRIP_AUTH_LOGIN = "/corpservice/authorize/login"; 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_SINGLE_LOGIN = "/m/SingleSignOn/H5SignInfo";
public static final String C_TRIP_AUDIT_PATH = "/corpservice/AuditService/Audit"; 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_REQUEST_SECRET = "zhengtai2024_nEbmKfOo";
public static final String C_TRIP_AUDIT_ACTION_SUCCESS = "T"; public static final String C_TRIP_AUDIT_ACTION_SUCCESS = "T";
public static final String C_TRIP_AUDIT_ACTION_FAIL = "F"; public static final String C_TRIP_AUDIT_ACTION_FAIL = "F";

View File

@ -1,12 +1,18 @@
package com.chint.infrastructure.repository; package com.chint.infrastructure.repository;
import com.chint.domain.aggregates.location.CityEntity; import com.chint.domain.aggregates.location.CityEntity;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.CityRepository; import com.chint.domain.repository.CityRepository;
import com.chint.infrastructure.repository.jdbc.JdbcCityRepository; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
@Repository @Repository
public class CityRepositoryImpl implements CityRepository { public class CityRepositoryImpl implements CityRepository {
@ -14,6 +20,9 @@ public class CityRepositoryImpl implements CityRepository {
@Autowired @Autowired
private JdbcCityRepository jdbcCityRepository; private JdbcCityRepository jdbcCityRepository;
@Autowired
private CTripFlightCitySearchRequest cTripFlightCitySearchRequest;
@Override @Override
public void saveAll(List<CityEntity> cities) { public void saveAll(List<CityEntity> cities) {
jdbcCityRepository.save(cities.get(0)); jdbcCityRepository.save(cities.get(0));
@ -22,7 +31,22 @@ public class CityRepositoryImpl implements CityRepository {
@Override @Override
public CityEntity findByCityName(String name) { 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;}
} }

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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
}
}

View File

@ -6,6 +6,7 @@ import com.chint.domain.service.supplier.SupplierService;
import com.chint.domain.value_object.SupplierCallbackData; import com.chint.domain.value_object.SupplierCallbackData;
import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.ctrip.*; 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.BookingRelatedApiRequest;
import com.chint.interfaces.rest.ctrip.dto.estimate.request.FlightProductInfo; import com.chint.interfaces.rest.ctrip.dto.estimate.request.FlightProductInfo;
import com.chint.interfaces.rest.ctrip.dto.estimate.request.RouteInfo; import com.chint.interfaces.rest.ctrip.dto.estimate.request.RouteInfo;
@ -54,6 +55,9 @@ public class CTripTest {
@Autowired @Autowired
private CTripNoteController cTripNoteController; private CTripNoteController cTripNoteController;
@Autowired
private CTripFlightCitySearchRequest cTripFlightCitySearchRequest;
private User user = new User(1L, "230615020", 1, "卢麟哲", "1033719135@qq.com", "15857193365"); private User user = new User(1L, "230615020", 1, "卢麟哲", "1033719135@qq.com", "15857193365");
//@Test //@Test
@ -168,4 +172,10 @@ public class CTripTest {
BaseContext.setCurrentUser(user); BaseContext.setCurrentUser(user);
cTripNoteController.handlerData("30607415392","Paid","HotelContract"); cTripNoteController.handlerData("30607415392","Paid","HotelContract");
} }
@Test
void queryFlightCity(){
FlightCitySearchResponse flightCity = cTripFlightCitySearchRequest.getFlightCity("杭州", 2);
System.out.println(flightCity);
}
} }

View File

@ -130,6 +130,5 @@ class RouteApplicationTests {
void arrayToStr(){ void arrayToStr(){
List<Long> ids = List.of(1L,2L,3L,4L); List<Long> ids = List.of(1L,2L,3L,4L);
System.out.println(Arrays.toString(ids.toArray())); System.out.println(Arrays.toString(ids.toArray()));
} }
} }