diff --git a/src/main/java/com/chint/application/dtos/AuthenticationDto.java b/src/main/java/com/chint/application/dtos/AuthenticationDto.java new file mode 100644 index 00000000..4eecdeaf --- /dev/null +++ b/src/main/java/com/chint/application/dtos/AuthenticationDto.java @@ -0,0 +1,12 @@ +package com.chint.application.dtos; + + +import com.chint.domain.value_object.BaseQuery; +import com.chint.domain.value_object.LegData; +import lombok.Data; + +@Data +public class AuthenticationDto extends BaseQuery { + private String clientid ; + private String secretkey; +} diff --git a/src/main/java/com/chint/application/dtos/AuthenticationSignDto.java b/src/main/java/com/chint/application/dtos/AuthenticationSignDto.java new file mode 100644 index 00000000..b3872d5e --- /dev/null +++ b/src/main/java/com/chint/application/dtos/AuthenticationSignDto.java @@ -0,0 +1,16 @@ +package com.chint.application.dtos; + + +import com.chint.domain.value_object.BaseQuery; +import lombok.Data; + +@Data +public class AuthenticationSignDto extends BaseQuery { + + private Integer productType; //机票1 、酒店2、火车3、打车4 + private String systemType; + private String startTime; + private String endTime; + + private String sign; +} diff --git a/src/main/java/com/chint/application/dtos/HotCityResponseDto.java b/src/main/java/com/chint/application/dtos/HotCityResponseDto.java new file mode 100644 index 00000000..f6444c29 --- /dev/null +++ b/src/main/java/com/chint/application/dtos/HotCityResponseDto.java @@ -0,0 +1,15 @@ +package com.chint.application.dtos; + +import com.chint.application.dtos.response.LocationRes; +import lombok.Data; + +import java.util.List; + +@Data +public class HotCityResponseDto { + + private List internationalCitys; //热门国际城市 + + private List internalCitys; //热门国内城市 + +} diff --git a/src/main/java/com/chint/application/dtos/OrderDetailQueryParam.java b/src/main/java/com/chint/application/dtos/OrderDetailQueryParam.java new file mode 100644 index 00000000..80769d99 --- /dev/null +++ b/src/main/java/com/chint/application/dtos/OrderDetailQueryParam.java @@ -0,0 +1,6 @@ +package com.chint.application.dtos; + +import com.chint.domain.value_object.BaseQuery; + +public class OrderDetailQueryParam extends BaseQuery { +} diff --git a/src/main/java/com/chint/application/dtos/OrderSearchResult.java b/src/main/java/com/chint/application/dtos/OrderSearchResult.java new file mode 100644 index 00000000..b65d8c3b --- /dev/null +++ b/src/main/java/com/chint/application/dtos/OrderSearchResult.java @@ -0,0 +1,10 @@ +package com.chint.application.dtos; + + +import com.chint.infrastructure.util.Token; +import lombok.Data; + +@Data +public class OrderSearchResult { + private Token token; +} diff --git a/src/main/java/com/chint/application/dtos/response/LegRes.java b/src/main/java/com/chint/application/dtos/response/LegRes.java index 786e0654..618a48e0 100644 --- a/src/main/java/com/chint/application/dtos/response/LegRes.java +++ b/src/main/java/com/chint/application/dtos/response/LegRes.java @@ -4,12 +4,14 @@ package com.chint.application.dtos.response; import cn.hutool.core.bean.BeanUtil; import com.chint.domain.aggregates.order.Leg; import com.chint.domain.aggregates.order.LegExtensionField; +import com.chint.domain.aggregates.order.Location; import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.value_object.enums.CurrencyType; import lombok.Data; import org.springframework.data.annotation.Id; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.List; @Data @@ -37,6 +39,8 @@ public class LegRes { private CurrencyType currencyType; + private List otherLocationList; + private List orderDetails; //这个属性不做持久化保存 ,根据下单事件进行获取 public static LegRes copyFrom(Leg leg) { @@ -50,9 +54,19 @@ public class LegRes { legRes.setAmountType(legExtensionField.getAmountType()); legRes.setAmountTypeName(legExtensionField.getAmountTypeName()); legRes.setAmountTypeEnName(legExtensionField.getAmountTypeEnName()); + + if (legExtensionField.getLocationIds() != null) { + List locationResList = new ArrayList<>(); + List locationList = legExtensionField.getLocationList(); + for (Location location : locationList) { + locationResList.add(LocationRes.copyFrom(location)); + } + legRes.setOtherLocationList(locationResList); + } } legRes.setOriginLocation(LocationRes.copyFrom(leg.getOriginLocation())); legRes.setDestinationLocation(LocationRes.copyFrom(leg.getDestinationLocation())); + return legRes; } } diff --git a/src/main/java/com/chint/application/dtos/response/LocationRes.java b/src/main/java/com/chint/application/dtos/response/LocationRes.java index 485a838c..18b331fd 100644 --- a/src/main/java/com/chint/application/dtos/response/LocationRes.java +++ b/src/main/java/com/chint/application/dtos/response/LocationRes.java @@ -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; } } diff --git a/src/main/java/com/chint/application/dtos/response/RouteOrderPageRes.java b/src/main/java/com/chint/application/dtos/response/RouteOrderPageRes.java index f2c05870..4b4b7a09 100644 --- a/src/main/java/com/chint/application/dtos/response/RouteOrderPageRes.java +++ b/src/main/java/com/chint/application/dtos/response/RouteOrderPageRes.java @@ -34,6 +34,7 @@ public class RouteOrderPageRes { private String amount; private String estimateAmount; private Integer orderStatus; + private Integer approvalStatusCode; private String approvalStatus; private String orderStatusName; private String startTime; diff --git a/src/main/java/com/chint/application/in/OrderController.java b/src/main/java/com/chint/application/in/OrderController.java index 943b5630..9e0f0f4a 100644 --- a/src/main/java/com/chint/application/in/OrderController.java +++ b/src/main/java/com/chint/application/in/OrderController.java @@ -6,7 +6,9 @@ import com.chint.application.queryies.OrderQuery; import com.chint.application.services.OrderApplicationService; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.service.OrderDetailDomainService; -import com.chint.domain.value_object.*; +import com.chint.domain.value_object.OrderSaveData; +import com.chint.domain.value_object.SyncLegData; +import com.chint.domain.value_object.UpdateLegData; import com.chint.infrastructure.util.Result; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; @@ -41,7 +43,6 @@ public class OrderController { } - @Transactional @ApiOperation("同步行程规划单到供应商") @PostMapping("/sync") @@ -50,6 +51,19 @@ public class OrderController { return Result.Success(SUCCESS); } + @Transactional + @ApiOperation("批量同步行程规划单到供应商") + @PostMapping("/sync/batch") + public Result syncOrderBatch(@RequestBody SyncLegData syncLegData) { + syncLegData.getRouteIds().stream().map(routeId -> { + SyncLegData syncLegDataItem = new SyncLegData(); + syncLegDataItem.setRouteId(routeId); + syncLegDataItem.setSupplierName(syncLegData.getSupplierName()); + return syncLegDataItem; + }).toList().forEach(data -> orderApplicationService.sync(data)); + return Result.Success(SUCCESS); + } + @Transactional @ApiOperation("修改规划节点关联的订单") @PostMapping("/leg/update") @@ -66,6 +80,15 @@ public class OrderController { return Result.Success(SUCCESS); } + @Transactional + @ApiOperation("修改行程节点") + @PostMapping("/leg/change/") + public Result changeLeg(@RequestBody AddLegData addLegData) { + orderApplicationService.changeLeg(addLegData); + return Result.Success(SUCCESS); + } + + @Transactional @ApiOperation("删除行程节点") @PostMapping("/leg/delete") diff --git a/src/main/java/com/chint/application/out/LocationController.java b/src/main/java/com/chint/application/out/LocationController.java index 33a720d5..0cbdbef6 100644 --- a/src/main/java/com/chint/application/out/LocationController.java +++ b/src/main/java/com/chint/application/out/LocationController.java @@ -1,21 +1,28 @@ package com.chint.application.out; import cn.hutool.core.bean.BeanUtil; +import com.chint.application.dtos.HotCityResponseDto; import com.chint.application.dtos.LocationParam; import com.chint.application.dtos.response.LocationRes; import com.chint.domain.aggregates.order.Location; +import com.chint.domain.aggregates.standards.CityTag; +import com.chint.domain.aggregates.standards.HotCityTag; import com.chint.domain.repository.LocationRepository; import com.chint.domain.service.LocationDomainService; import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.Result; import com.chint.infrastructure.util.StringCheck; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.List; import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; @@ -51,8 +58,43 @@ public class LocationController { if (locations != null && !locations.isEmpty()) { locationRes = locations .stream() - .map(location -> BeanUtil.copyProperties(location, LocationRes.class)).toList(); + .map(LocationRes::copyFrom).toList(); } return Result.Success(SUCCESS, locationRes); } + + @ApiOperation("获取热门城市") + @PostMapping("/getHotCities") + public Result getHotCities() { + + List city = HotCityTag.citys; + + List locations = null; + List locationRes = null; + + locations = locationRepository.findHotCitiesByCityName(city); + if (locations != null && !locations.isEmpty()) { + locationRes = locations + .stream() + .map(LocationRes::copyFrom).toList(); + } + + + List internationalCitys = HotCityTag.internationalCitys; + List internationalLocationRes = null; + + List internationalLocations = locationRepository.findHotIntnationalCitiesByCityName(internationalCitys); + if (internationalLocations != null && !internationalLocations.isEmpty()) { + internationalLocationRes = internationalLocations + .stream() + .map(LocationRes::copyFrom).toList(); + } + + HotCityResponseDto dto = new HotCityResponseDto(); + dto.setInternalCitys(locationRes); + dto.setInternationalCitys(internationalLocationRes); + + return Result.Success(SUCCESS, dto); + + } } \ No newline at end of file diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index f2adef3e..3b8c00a7 100644 --- a/src/main/java/com/chint/application/out/LoginController.java +++ b/src/main/java/com/chint/application/out/LoginController.java @@ -130,4 +130,35 @@ public class LoginController { userLoginResult.getUser().setManaLevel(null); return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } + + @ApiOperation("商旅平台移动端单点") + @Transactional + @PostMapping("/login/sso/mobile") + public Result loginSSOMobile(@RequestBody UserLoginParam userLoginParam){ + + String employeeNo = pailaLoginStrategy.login(userLoginParam.getCode()); + + userLoginParam.setSfno(employeeNo); + UserLoginResult userLoginResult = authenticateService + .authenticateEmployeeNo(userLoginParam); + + //异步执行更新用户信息到同程 + User currentUser = userLoginResult.getUser(); + CompletableFuture.runAsync(() -> { + BaseContext.setCurrentUser(currentUser); + lyUserRequest.saveCurrentUser(); + BaseContext.removeCurrentUser(); + }); + //异步执行更新用户信息到携程 + CompletableFuture.runAsync(() -> { + BaseContext.setCurrentUser(currentUser); + cTripUserSaveRequest.saveUserToCTrip(); + BaseContext.removeCurrentUser(); + }); + + //清除职级信息 + userLoginResult.getUser().setProfLevel(null); + userLoginResult.getUser().setManaLevel(null); + return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); + } } diff --git a/src/main/java/com/chint/application/out/OrderDetailController.java b/src/main/java/com/chint/application/out/OrderDetailController.java new file mode 100644 index 00000000..7bec88be --- /dev/null +++ b/src/main/java/com/chint/application/out/OrderDetailController.java @@ -0,0 +1,91 @@ +package com.chint.application.out; + +import cn.hutool.core.bean.BeanUtil; +import com.chint.application.dtos.*; +import com.chint.application.dtos.response.LocationRes; +import com.chint.application.dtos.response.OrderDetailRes; +import com.chint.domain.aggregates.order.Location; +import com.chint.domain.repository.ClientRepository; +import com.chint.domain.repository.LocationRepository; +import com.chint.domain.service.LocationDomainService; +import com.chint.domain.service.auth.AuthenticateService; +import com.chint.infrastructure.util.Digest; +import com.chint.infrastructure.util.PageResult; +import com.chint.infrastructure.util.Result; +import com.chint.infrastructure.util.StringCheck; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Calendar; +import java.util.List; + +import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; + +@RestController +@RequestMapping("/OrderDetail") +public class OrderDetailController { + +// @Autowired +// private LocationRepository locationRepository; +// +// @Autowired +// private LocationDomainService locationDomainService; + + @Autowired + private AuthenticateService authenticateService; + + @Autowired + private ClientRepository clientRepository; + + @ApiOperation("订单明细认证接口") + @PostMapping("/pubilc/authentication") + public Result queryAuthentication(@RequestBody AuthenticationDto authenticationDto) { + + OrderSearchResult orderSearchResult = null; + try { + orderSearchResult = authenticateService.authenticateClient(authenticationDto); + if (orderSearchResult != null){ + return Result.Success(SUCCESS, orderSearchResult); + }else { + return Result.error("认证失败"); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + @ApiOperation("订单明细查询接口") + @PostMapping("/query") + public Result query(@RequestBody AuthenticationSignDto authenticationDto) { + + String productType = authenticationDto.getProductType().toString(); + String systemType = authenticationDto.getSystemType(); + String startTime = authenticationDto.getStartTime(); + String endTime = authenticationDto.getEndTime(); + String pageSize = authenticationDto.getPageSize().toString(); + String pageNum = authenticationDto.getPageNum().toString(); + String orgsign = authenticationDto.getSign(); + String sign = Digest.md5(productType + systemType + startTime + endTime + pageSize + pageNum); + System.out.println(sign); + + + if (StringUtils.isNotBlank(orgsign) && orgsign.equals(sign)) { + return Result.Success(SUCCESS,sign); + } else { + return Result.error("签名错误"); + } + } + + @ApiOperation("查询我的订单") + @PostMapping("/query/page") + public Result query(@RequestBody OrderDetailQueryParam orderDetailQueryParam){ + + return null; + } +} \ No newline at end of file diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index 50025e9f..a7559d63 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; @Slf4j @@ -86,4 +88,11 @@ public class OrderOutController { return Result.Success(SUCCESS, tripCallback); } + + @ApiOperation("分页查询行程规划订单") + @PostMapping("/query/not/submit") + public Result> queryNotSubmit(@RequestBody OrderQueryData queryData) { + return Result.Success(SUCCESS, orderQuery.queryNotSubmit(queryData)); + } + } diff --git a/src/main/java/com/chint/application/queryies/OrderDetailQuery.java b/src/main/java/com/chint/application/queryies/OrderDetailQuery.java new file mode 100644 index 00000000..dc02678e --- /dev/null +++ b/src/main/java/com/chint/application/queryies/OrderDetailQuery.java @@ -0,0 +1,22 @@ +package com.chint.application.queryies; + + +import com.chint.application.dtos.OrderDetailQueryParam; +import com.chint.application.dtos.response.OrderDetailRes; +import com.chint.domain.repository.OrderDetailRepository; +import com.chint.infrastructure.util.PageResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class OrderDetailQuery { + + @Autowired + private OrderDetailRepository orderDetailRepository; + + + public PageResult orderDetailPageQuery(OrderDetailQueryParam orderDetailQueryParam) { + + return null; + } +} diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index 35c555c8..a2ac90e6 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -26,6 +26,7 @@ import org.springframework.stereotype.Service; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -33,6 +34,7 @@ import java.util.stream.Stream; import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_CANCEL_NAME; import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_PREPARE_NAME; +import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_APPROVAL; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; @Service @@ -59,6 +61,7 @@ public class OrderQuery { @Autowired private EstimateAdapter estimateAdapter; + public RouteOrder queryByOrderId(OrderQueryData queryData) { return routeRepository.queryById(queryData.getRouteId()).reloadStatus(); } @@ -89,6 +92,7 @@ public class OrderQuery { int total = routeOrders.size(); List orders = routeOrders .stream() + .sorted(Comparator.comparing(RouteOrder::getUpdateTime)) .skip((long) (pageNum - 1) * pageSize) .limit(pageSize) .map(OrderQuery::getRouteOrderPageRes) @@ -138,7 +142,8 @@ public class OrderQuery { private static RouteOrderPageRes getRouteOrderPageRes(RouteOrder routeOrder) { User currentUser = BaseContext.getCurrentUser(); RouteOrderPageRes res = BeanUtil.copyProperties(routeOrder.reloadStatus(), RouteOrderPageRes.class); - List locationRes = routeOrder.getLegItems() + List legItems = routeOrder.getLegItems(); + List locationRes = legItems .stream() .flatMap(leg -> Stream.of(leg.getOriginLocation(), leg.getDestinationLocation())) .map(LocationRes::copyFrom) @@ -297,7 +302,7 @@ public class OrderQuery { }; } - public RouteOrderRes queryRouteRes(RouteOrder routeOrder){ + public RouteOrderRes queryRouteRes(RouteOrder routeOrder) { RouteOrderRes routeOrderRes = RouteOrderRes.copyFrom(routeOrder); List legItems = routeOrder.getLegItems(); orderDomainService.queryLocation(legItems); @@ -318,4 +323,12 @@ public class OrderQuery { .toList()); return routeOrderRes; } + + public List queryNotSubmit(OrderQueryData queryData) { + List routeOrders = routeRepository.findByActualOrderNoNotNull(queryData); + routeOrders.forEach(route -> orderDomainService.queryLocation(route.getLegItems())); + return routeOrders.stream().filter(order -> order.reloadStatus().getOrderStatus().equals(ORDER_STATUS_APPROVAL)) + .map(OrderQuery::getRouteOrderPageRes) + .toList(); + } } diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index 07550796..6a923445 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -9,25 +9,25 @@ import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.exceptions.OrderException; import com.chint.domain.factoriy.leg.LegFactory; import com.chint.domain.factoriy.order.OrderFactory; +import com.chint.domain.repository.LegRepository; import com.chint.domain.repository.RouteRepository; import com.chint.domain.service.OrderDomainService; import com.chint.domain.value_object.*; import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.DataMessageConstant; import com.chint.infrastructure.constant.LegConstant; -import com.chint.infrastructure.constant.RouteConstant; import com.chint.infrastructure.echo_framework.command.Command; -import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Collections; import java.util.List; import java.util.Optional; import static com.chint.infrastructure.constant.CommonMessageConstant.ORDER_STATUS_ERROR; -import static com.chint.infrastructure.constant.LegConstant.LEG_STATUS_PREPARE; import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE; @Service @@ -45,6 +45,8 @@ public class OrderApplicationService { @Autowired private LegFactory legFactory; + @Autowired + private LegRepository legRepository; @Transactional @@ -149,4 +151,20 @@ public class OrderApplicationService { public void reloadOrderDetail(SyncLegData syncLegData) { } + + @Transactional + public void updateLegToOrder(AddLegData addLegData) { + } + + @Transactional + public void changeLeg(AddLegData addLegData) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); + LegData legData = addLegData.getLegData(); + Leg byLegId = legRepository.findByLegId(legData.getLegId()); + byLegId.setStartTime(LocalDateTime.parse(legData.getStartTime(), formatter)); + byLegId.setEndTime(LocalDateTime.parse(legData.getEndTime(), formatter)); + byLegId.setOriginId(legData.getOriginId()); + byLegId.setDestinationId(legData.getDestinationId()); + legRepository.save(byLegId); + } } diff --git a/src/main/java/com/chint/application/services/login/LoginStrategy.java b/src/main/java/com/chint/application/services/login/LoginStrategy.java index c7855ea4..e83fde3f 100644 --- a/src/main/java/com/chint/application/services/login/LoginStrategy.java +++ b/src/main/java/com/chint/application/services/login/LoginStrategy.java @@ -4,6 +4,7 @@ package com.chint.application.services.login; import com.chint.domain.aggregates.user.User; import com.chint.domain.exceptions.AuthException; +import com.chint.domain.exceptions.SSOLoginException; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; @@ -22,7 +23,7 @@ public interface LoginStrategy { default String login(String code) { Optional accessToken = getAccessToken(code); - return getUserInfo(accessToken.orElseThrow(()-> new AuthException("Failed to obtain access token"))); + return getUserInfo(accessToken.orElseThrow(()-> new SSOLoginException("Failed to obtain access token"))); } Optional getAccessToken(String code); diff --git a/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java b/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java index 99b764be..2b228be9 100644 --- a/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java +++ b/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.chint.application.dtos.UserDTO; import com.chint.application.services.login.LoginStrategy; import com.chint.domain.exceptions.NotFoundException; +import com.chint.domain.exceptions.SSOLoginException; import com.chint.domain.factoriy.user.UserFactory; import com.chint.domain.repository.UserRepository; import com.chint.interfaces.rest.user.UserHttpRequest; @@ -65,7 +66,6 @@ public class PailaLoginStrategy implements LoginStrategy { new BasicNameValuePair("client_secret", clientSecret), new BasicNameValuePair("code", code), new BasicNameValuePair("redirect_uri", redirectUri) - ); HttpPost getMethod = postRequest("/esc-sso/oauth2.0/accessToken", parameters); @@ -92,7 +92,7 @@ public class PailaLoginStrategy implements LoginStrategy { } UserDTO userDTO = JSON.parseObject(userInfoResBody, UserDTO.class); if (userDTO == null) { - throw new NotFoundException(NOT_FOUND); + throw new SSOLoginException(NOT_FOUND); } return userDTO.getAttributes().getAccount_no(); } diff --git a/src/main/java/com/chint/application/services/login/strategy/PailaMobileLoginStrategy.java b/src/main/java/com/chint/application/services/login/strategy/PailaMobileLoginStrategy.java new file mode 100644 index 00000000..c375938c --- /dev/null +++ b/src/main/java/com/chint/application/services/login/strategy/PailaMobileLoginStrategy.java @@ -0,0 +1,125 @@ +package com.chint.application.services.login.strategy; + +import com.alibaba.fastjson.JSON; +import com.chint.application.dtos.UserDTO; +import com.chint.application.services.login.LoginStrategy; +import com.chint.domain.exceptions.SSOLoginException; +import com.chint.domain.factoriy.user.UserFactory; +import com.chint.domain.repository.UserRepository; +import com.chint.interfaces.rest.user.UserHttpRequest; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; + + +@Slf4j +@Component +public class PailaMobileLoginStrategy implements LoginStrategy { + + @Value("${paila.base-url}") + private String baseUrl; + + @Value("${paila.client-mobile-id}") + private String clientId; + + @Value("${paila.client-mobile-secret}") + private String clientSecret; + + @Value("${paila.redirect-mobile-url}") + private String redirectUri; + + @Autowired + private UserRepository userRepository; + + @Autowired + private UserHttpRequest userHttpRequest; + + @Autowired + private UserFactory userFactory; + + @Override + public Optional getAccessToken(String code) { + + log.info("开始执行登录"); + List parameters = Arrays.asList( + new BasicNameValuePair("grant_type", "authorization_code"), + new BasicNameValuePair("client_id", clientId), + new BasicNameValuePair("client_secret", clientSecret), + new BasicNameValuePair("code", code), + new BasicNameValuePair("redirect_uri", redirectUri) + ); + + HttpPost getMethod = postRequest("/esc-sso/oauth2.0/accessToken", parameters); + return LoginStrategy.getAccessTokenMethod(getMethod, "access_token"); + } + + @Override + public String getUserInfo(String accessToken) { + + + List userInfoParams = Collections.singletonList( + new BasicNameValuePair("access_token", accessToken) + ); + + HttpGet getMethodUserInfo = getRequest("/esc-sso/oauth2.0/profile", userInfoParams); + + String userInfoResBody = null; + HttpClient client = HttpClients.createDefault(); + try { + HttpResponse userInfoRes = client.execute(getMethodUserInfo); + userInfoResBody = EntityUtils.toString(userInfoRes.getEntity(), "UTF-8"); + } catch (IOException e) { + log.error(e.getMessage()); + } + UserDTO userDTO = JSON.parseObject(userInfoResBody, UserDTO.class); + if (userDTO == null) { + throw new SSOLoginException(NOT_FOUND); + } + return userDTO.getAttributes().getAccount_no(); + } + + private HttpGet getRequest(String path, List parameters) { + String userInfoUrl = null; + try { + userInfoUrl = new URIBuilder(baseUrl).setPath(path) + .setParameters(parameters).build().toString(); + } catch (URISyntaxException e) { + log.error(e.getMessage()); + } + HttpGet request = new HttpGet(userInfoUrl); + request.setHeader("Content-Type", "application/json"); + return request; + } + + private HttpPost postRequest(String path, List parameters) { + String userInfoUrl = null; + try { + userInfoUrl = new URIBuilder(baseUrl).setPath(path) + .setParameters(parameters).build().toString(); + } catch (URISyntaxException e) { + log.error(e.getMessage()); + } + HttpPost request = new HttpPost(userInfoUrl); + request.setHeader("Content-Type", "application/json"); + return request; + } +} diff --git a/src/main/java/com/chint/domain/aggregates/location/CityEntity.java b/src/main/java/com/chint/domain/aggregates/location/CityEntity.java index 08a1b6d9..8cd08c5a 100644 --- a/src/main/java/com/chint/domain/aggregates/location/CityEntity.java +++ b/src/main/java/com/chint/domain/aggregates/location/CityEntity.java @@ -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; + } } diff --git a/src/main/java/com/chint/domain/aggregates/order/Client.java b/src/main/java/com/chint/domain/aggregates/order/Client.java new file mode 100644 index 00000000..36918efc --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/order/Client.java @@ -0,0 +1,18 @@ +package com.chint.domain.aggregates.order; + +import lombok.Data; +import org.springframework.data.relational.core.mapping.Table; + +/** + * @author wanglf3 + * @date 2024-02-28 + * @vsrsion 1.0 + **/ + +@Data +@Table("client") +public class Client { + private Long id; + private String clientId; + private String clientSecret; +} diff --git a/src/main/java/com/chint/domain/aggregates/order/LegExtensionField.java b/src/main/java/com/chint/domain/aggregates/order/LegExtensionField.java index ebe3810c..e8e1fdbe 100644 --- a/src/main/java/com/chint/domain/aggregates/order/LegExtensionField.java +++ b/src/main/java/com/chint/domain/aggregates/order/LegExtensionField.java @@ -6,6 +6,10 @@ import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Transient; import org.springframework.data.relational.core.mapping.Table; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + @Data @Table("leg_extension_field") public class LegExtensionField { @@ -13,6 +17,9 @@ public class LegExtensionField { private Long id; private Long legId; private Integer amountType; + private String locationIds; + @Transient + private List locationList; @Transient private String amountTypeName; @Transient @@ -23,6 +30,26 @@ public class LegExtensionField { private String estimatedAmount; + public LegExtensionField addLocationIdsAsString(List locationIds) { + this.locationIds = Arrays.toString(locationIds.toArray()); + return this; + } + + public List getLocationIdsAsLong() { + // 去除字符串开头和结尾的方括号 + this.locationIds = this.locationIds.substring(1, this.locationIds.length() - 1); + // 根据逗号分割字符串 + String[] items = this.locationIds.split(","); + // 创建一个Long类型的列表 + List result = new ArrayList<>(); + // 将每个分割后的字符串转换为Long并添加到列表中 + for (String item : items) { + result.add(Long.parseLong(item.trim())); + } + return result; + } + + public LegExtensionField reloadStatus() { this.amountTypeName = translateLegOtherAmountTypeToChineseName(this.amountType); this.amountTypeEnName = translateLegOtherAmountTypeToEnglishName(this.amountType); diff --git a/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java b/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java index 943e4206..80881c49 100644 --- a/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java +++ b/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java @@ -32,6 +32,7 @@ public class OrderDetail { private CurrencyType currencyType; //货币类型 private Long destinationId; private Long originId; + private String employeeNo; private LocalDateTime orderDate; private LocalDateTime startTime; private LocalDateTime endTime; @@ -69,7 +70,10 @@ public class OrderDetail { orderDetail.setUpdateTime(LocalDateTime.now()); return orderDetail; } - + public OrderDetail employeeNo(String employeeNo) { + this.setEmployeeNo(employeeNo); + return this; + } public OrderDetail productType(Integer productType) { this.setProductType(productType); return this; diff --git a/src/main/java/com/chint/domain/aggregates/standards/CityTag.java b/src/main/java/com/chint/domain/aggregates/standards/CityTag.java index 7d195c71..3ca7e0f0 100644 --- a/src/main/java/com/chint/domain/aggregates/standards/CityTag.java +++ b/src/main/java/com/chint/domain/aggregates/standards/CityTag.java @@ -3,7 +3,6 @@ package com.chint.domain.aggregates.standards; import java.util.HashMap; public class CityTag { - public static final HashMap cityMap; static { diff --git a/src/main/java/com/chint/domain/aggregates/standards/HotCityTag.java b/src/main/java/com/chint/domain/aggregates/standards/HotCityTag.java new file mode 100644 index 00000000..c3a297ca --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/standards/HotCityTag.java @@ -0,0 +1,49 @@ +package com.chint.domain.aggregates.standards; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class HotCityTag { + + public static final List citys; + + public static final List internationalCitys; + + static { + citys = new ArrayList<>(); + + citys.add("上海"); + citys.add("北京"); + citys.add("广州"); + citys.add("深圳"); + citys.add("天津"); + citys.add("重庆"); + citys.add("苏州"); + citys.add("武汉"); + citys.add("成都"); + citys.add("杭州"); + citys.add("温州"); + + internationalCitys = new ArrayList<>(); + internationalCitys.add("北美洲_美国_纽约州_纽约_"); + internationalCitys.add("北美洲_美国_内华达州_拉斯维加斯_"); + internationalCitys.add("北美洲_美国_伊利诺伊州_芝加哥_"); + internationalCitys.add("北美洲_美国_华盛顿哥伦比亚特区_华盛顿_"); + internationalCitys.add("欧洲_英国_英格兰_伦敦_"); + internationalCitys.add("欧洲_德国_拜恩(巴伐利亚)_慕尼黑_"); + internationalCitys.add("欧洲_西班牙_加泰罗尼亚_巴塞罗那_"); + internationalCitys.add("欧洲_德国_柏林_柏林_"); + internationalCitys.add("北美洲_美国_纽约州_阿姆斯特丹_"); + internationalCitys.add("欧洲_法国_法兰西岛_巴黎_"); + internationalCitys.add("欧洲_西班牙_马德里_马德里_"); + internationalCitys.add("欧洲_葡萄牙_特茹河谷里斯本_里斯本_"); + internationalCitys.add("欧洲_奥地利_维也纳_维也纳_"); + internationalCitys.add("亚洲_日本_东京都_东京_"); + internationalCitys.add("欧洲_挪威_奥斯陆市_奥斯陆_"); + internationalCitys.add("北美洲_美国_加利福尼亚州_旧金山_"); + internationalCitys.add("亚洲_新加坡_新加坡_新加坡_"); + + } + +} diff --git a/src/main/java/com/chint/domain/event/LegEventListener.java b/src/main/java/com/chint/domain/event/LegEventListener.java index 9d27f696..5e527c3e 100644 --- a/src/main/java/com/chint/domain/event/LegEventListener.java +++ b/src/main/java/com/chint/domain/event/LegEventListener.java @@ -21,7 +21,7 @@ public class LegEventListener { // @TransitionTo(command = "LegPrepareCommand", order = 0) public void onLegStatusChange(LegPrepareCommand command) { - Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); + Leg leg = legRepository.findByLegId(command.getLegId()); LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType()); leg.addEvent(legEvent); legRepository.save(leg); diff --git a/src/main/java/com/chint/domain/exceptions/SSOLoginException.java b/src/main/java/com/chint/domain/exceptions/SSOLoginException.java new file mode 100644 index 00000000..1fde6f7e --- /dev/null +++ b/src/main/java/com/chint/domain/exceptions/SSOLoginException.java @@ -0,0 +1,7 @@ +package com.chint.domain.exceptions; + +public class SSOLoginException extends BaseException{ + public SSOLoginException(String msg) { + super(msg); + } +} diff --git a/src/main/java/com/chint/domain/factoriy/leg/RouteLegFactory.java b/src/main/java/com/chint/domain/factoriy/leg/RouteLegFactory.java index d15a1d69..9afb0c7e 100644 --- a/src/main/java/com/chint/domain/factoriy/leg/RouteLegFactory.java +++ b/src/main/java/com/chint/domain/factoriy/leg/RouteLegFactory.java @@ -126,6 +126,10 @@ public class RouteLegFactory implements LegFactory { private static LegExtensionField getLegExtensionField(LegData data) { LegExtensionFieldData legExtensionFieldData = data.getLegExtensionFieldData(); - return BeanUtil.copyProperties(legExtensionFieldData, LegExtensionField.class); + LegExtensionField legExtensionField = BeanUtil.copyProperties(legExtensionFieldData, LegExtensionField.class); + if (legExtensionFieldData.getLocationIds() != null && !legExtensionFieldData.getLocationIds().isEmpty()) { + legExtensionField.addLocationIdsAsString(legExtensionFieldData.getLocationIds()); + } + return legExtensionField; } } diff --git a/src/main/java/com/chint/domain/repository/ClientRepository.java b/src/main/java/com/chint/domain/repository/ClientRepository.java new file mode 100644 index 00000000..c8c2fb35 --- /dev/null +++ b/src/main/java/com/chint/domain/repository/ClientRepository.java @@ -0,0 +1,16 @@ +package com.chint.domain.repository; + +import com.chint.application.dtos.AuthenticationDto; +import com.chint.domain.aggregates.order.Client; + +/** + * @author wanglf3 + * @date 2024-02-28 + * @vsrsion 1.0 + **/ + +public interface ClientRepository { + Client save(Client client); + + Client findByClientId(String clientId); +} diff --git a/src/main/java/com/chint/domain/repository/LegRepository.java b/src/main/java/com/chint/domain/repository/LegRepository.java index 9ddd9cfe..7e31c8db 100644 --- a/src/main/java/com/chint/domain/repository/LegRepository.java +++ b/src/main/java/com/chint/domain/repository/LegRepository.java @@ -14,5 +14,7 @@ public interface LegRepository { void saveAll(List legs); - Leg findByLegId(Leg leg); + Leg findByLegId(Long legId); + + } \ No newline at end of file diff --git a/src/main/java/com/chint/domain/repository/LocationRepository.java b/src/main/java/com/chint/domain/repository/LocationRepository.java index c8034d09..25cfa2e9 100644 --- a/src/main/java/com/chint/domain/repository/LocationRepository.java +++ b/src/main/java/com/chint/domain/repository/LocationRepository.java @@ -22,4 +22,12 @@ public interface LocationRepository { List findByName(String localName); String locationPathByName(String localName); + + List findHotCitiesByCityName(List locationNames); + + List findHotIntnationalCitiesByCityName(List locationNames); + + List findByNameList(List locationIds); + + } \ No newline at end of file diff --git a/src/main/java/com/chint/domain/repository/OrderDetailRepository.java b/src/main/java/com/chint/domain/repository/OrderDetailRepository.java index c441d947..c4ada0a8 100644 --- a/src/main/java/com/chint/domain/repository/OrderDetailRepository.java +++ b/src/main/java/com/chint/domain/repository/OrderDetailRepository.java @@ -1,11 +1,15 @@ package com.chint.domain.repository; +import com.chint.application.dtos.OrderDetailQueryParam; import com.chint.domain.aggregates.order.OrderDetail; +import org.springframework.data.domain.Page; import java.util.List; import java.util.Optional; public interface OrderDetailRepository { + + Page pageQuery(OrderDetailQueryParam orderDetailQueryParam); OrderDetail findById(Long orderDetailId); List findByLegId(Long legId); diff --git a/src/main/java/com/chint/domain/service/OrderDomainService.java b/src/main/java/com/chint/domain/service/OrderDomainService.java index 8d5ca9d8..1d2ef3c3 100644 --- a/src/main/java/com/chint/domain/service/OrderDomainService.java +++ b/src/main/java/com/chint/domain/service/OrderDomainService.java @@ -68,6 +68,12 @@ public class OrderDomainService { public List queryLocation(List list) { list.forEach(leg -> { + LegExtensionField legExtensionField = leg.getLegExtensionField(); + if (legExtensionField != null && legExtensionField.getLocationIds() != null) { + List locationIdsAsLong = legExtensionField.getLocationIdsAsLong(); + List byNameList = locationRepository.findByNameList(locationIdsAsLong); + legExtensionField.setLocationList(byNameList); + } leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); }); @@ -122,7 +128,8 @@ public class OrderDomainService { .productType(orderDetail.getProductType()) .extensionData(orderDetail.getExtensionDataByProductType()) .sendToQueue(); - }; + } + ; } @ListenTo(command = "BPMAuditCommand", order = 0) diff --git a/src/main/java/com/chint/domain/service/auth/AuthenticateService.java b/src/main/java/com/chint/domain/service/auth/AuthenticateService.java index e1597e14..01f58296 100644 --- a/src/main/java/com/chint/domain/service/auth/AuthenticateService.java +++ b/src/main/java/com/chint/domain/service/auth/AuthenticateService.java @@ -1,8 +1,12 @@ package com.chint.domain.service.auth; +import com.chint.application.dtos.AuthenticationDto; +import com.chint.application.dtos.OrderSearchResult; import com.chint.domain.value_object.UserLoginParam; import com.chint.domain.value_object.UserLoginResult; public interface AuthenticateService { UserLoginResult authenticateEmployeeNo(UserLoginParam userLoginParam); + + OrderSearchResult authenticateClient(AuthenticationDto authenticationDto)throws Exception; } diff --git a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java index 89da197c..f3b02909 100644 --- a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java +++ b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java @@ -1,7 +1,12 @@ package com.chint.domain.service.auth; +import com.chint.application.dtos.AuthenticationDto; +import com.chint.application.dtos.OrderSearchResult; +import com.chint.domain.aggregates.order.Client; import com.chint.domain.aggregates.user.User; +import com.chint.domain.exceptions.AuthException; import com.chint.domain.factoriy.user.UserFactory; +import com.chint.domain.repository.ClientRepository; import com.chint.domain.repository.UserRepository; import com.chint.domain.value_object.UserLoginParam; import com.chint.domain.value_object.UserLoginResult; @@ -23,6 +28,9 @@ public class AuthenticateServiceImpl implements AuthenticateService { private final UserRepository userRepository; private final UserHttpRequest httpRequest; + @Autowired + private ClientRepository clientRepository; + @Autowired private UserFactory userFactory; @@ -74,4 +82,26 @@ public class AuthenticateServiceImpl implements AuthenticateService { return authenticateEmployeeNo(userLoginParam); } } + + @Override + public OrderSearchResult authenticateClient(AuthenticationDto authenticationDto) throws Exception{ + + Client client = clientRepository.findByClientId(authenticationDto.getClientid()); + + if (client != null){ + Map claims = new HashMap<>(); + claims.put(AuthMessageConstant.CLIENT_ID, client.getClientId()); + claims.put(AuthMessageConstant.CLIENT_SECRET,client.getClientSecret()); + + String jwt = JWTUtil.createJWT(AuthMessageConstant.SECRET,AuthMessageConstant.EXPIRATION_CLIENT_TIME_MS, + AuthMessageConstant.SUBJECT,claims); + + OrderSearchResult result = new OrderSearchResult(); + result.setToken(Token.of(jwt)); + return result; + + }else { + throw new AuthException(AuthMessageConstant.JWT_INVALID); + } + } } \ No newline at end of file diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java index 5ef1b178..dd6cf0a5 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java @@ -62,7 +62,7 @@ public class LegEventHandler implements LegEventService { @Transactional @Override public void prepareLeg(LegPrepareCommand command) { - Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); + Leg leg = legRepository.findByLegId(command.getLegId()); if (leg.getEventList().isEmpty()) { LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType()); leg.addEvent(legEvent); @@ -153,7 +153,8 @@ public class LegEventHandler implements LegEventService { if (byOrderNo.isEmpty()) { //否则创建新的订单添加到routeOrder orderDetail = orderDetailFactory.create(data) - .price(data.getPrice()).productType(data.getProductType()); + .price(data.getPrice()).productType(data.getProductType()) + .employeeNo(routeOrder.getUserId()); routeOrder.addOrderDetail(orderDetail); routeOrder = routeRepository.save(routeOrder); // OrderDetail orderDetail = routeOrder @@ -173,7 +174,7 @@ public class LegEventHandler implements LegEventService { @Override public ResultContainer orderLeg(LegOrderedCommand command) { //如果筛选事件可能会是错误,需要用户手动添加并修改事件 , 因此会进行额外出发修改下单事件。 - Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); + Leg leg = legRepository.findByLegId(command.getLegId()); //因为orderDetail已经进行持久化保存 ,只需要从数据库进行查询 OrderDetail orderDetail = orderDetailRepository.findById(command.getOrderDetailId()); LegEvent legEvent = legEventFactory @@ -189,7 +190,7 @@ public class LegEventHandler implements LegEventService { @Override public void payForLeg(LegPayedCommand command) { // PayLegData data = command.getData(); - Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); + Leg leg = legRepository.findByLegId(command.getLegId()); LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType()); leg.addEvent(legEvent); legRepository.save(leg); @@ -198,7 +199,7 @@ public class LegEventHandler implements LegEventService { @Transactional @Override public void finishLeg(LegFinishedCommand command) { - Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); + Leg leg = legRepository.findByLegId(command.getLegId()); LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType()); leg.addEvent(legEvent); legRepository.save(leg); diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java b/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java index 5f1e4ef0..2bf4328f 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java @@ -59,7 +59,7 @@ public class LegEventServiceImpl implements LegEventService { @Override @ListenTo(command = "LegFinishedCommand", order = 0) public void finishLeg(LegFinishedCommand command) { - + legEventHandler.finishLeg(command); } @Override diff --git a/src/main/java/com/chint/domain/value_object/LegExtensionFieldData.java b/src/main/java/com/chint/domain/value_object/LegExtensionFieldData.java index 1d8a3991..c404989d 100644 --- a/src/main/java/com/chint/domain/value_object/LegExtensionFieldData.java +++ b/src/main/java/com/chint/domain/value_object/LegExtensionFieldData.java @@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.data.annotation.Transient; +import java.util.List; + @Data public class LegExtensionFieldData { @ApiModelProperty("其他费用类型") @@ -16,4 +18,6 @@ public class LegExtensionFieldData { private String destinationDescription; @ApiModelProperty("预估金额") private String estimatedAmount; + @ApiModelProperty("地理位置id列表") + private List locationIds; } diff --git a/src/main/java/com/chint/domain/value_object/SyncLegData.java b/src/main/java/com/chint/domain/value_object/SyncLegData.java index 56ae6543..d3664a4a 100644 --- a/src/main/java/com/chint/domain/value_object/SyncLegData.java +++ b/src/main/java/com/chint/domain/value_object/SyncLegData.java @@ -2,8 +2,11 @@ package com.chint.domain.value_object; import lombok.Data; +import java.util.List; + @Data public class SyncLegData { private Long routeId; + private List routeIds; private String supplierName; } diff --git a/src/main/java/com/chint/infrastructure/constant/AuthMessageConstant.java b/src/main/java/com/chint/infrastructure/constant/AuthMessageConstant.java index dc5e0a50..05af1979 100644 --- a/src/main/java/com/chint/infrastructure/constant/AuthMessageConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/AuthMessageConstant.java @@ -35,4 +35,12 @@ public class AuthMessageConstant { public static final long EXPIRATION_TIME_MS = 3600000L; // 1小时过期时间 public static final String HEADER_TOKEN = "token"; public static final String HEADER_TOKEN_UP_CASE = "Token"; + + public static final String CLIENT_ID = "有效的 CLIENT_id "; + + public static final String CLIENT_SECRET = "有效的 CLIENT_SECRET"; + + public static final String HEADER_CLIENT_CASE = "Client"; + public static final long EXPIRATION_CLIENT_TIME_MS = 10800000L; // 3小时过期时间 + } diff --git a/src/main/java/com/chint/infrastructure/constant/CTripConstant.java b/src/main/java/com/chint/infrastructure/constant/CTripConstant.java index 0ebb34ed..96ae6616 100644 --- a/src/main/java/com/chint/infrastructure/constant/CTripConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/CTripConstant.java @@ -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"; diff --git a/src/main/java/com/chint/infrastructure/constant/LegConstant.java b/src/main/java/com/chint/infrastructure/constant/LegConstant.java index 2cb774bd..ca566a0a 100644 --- a/src/main/java/com/chint/infrastructure/constant/LegConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/LegConstant.java @@ -10,9 +10,9 @@ public class LegConstant { public static final String LEG_STATUS_NOT_ORDERED_NAME = "未下单"; public static final int LEG_STATUS_ORDERED = 3; public static final String LEG_STATUS_ORDERED_NAME = "已下单"; - public static final int LEG_STATUS_PAYED = 4; + public static final int LEG_STATUS_PAYED = 5; public static final String LEG_STATUS_PAYED_NAME = "已付款"; - public static final int LEG_STATUS_FINISH = 5; + public static final int LEG_STATUS_FINISH = -2; public static final String LEG_STATUS_FINISH_NAME = "已结束"; public static final int LEG_STATUS_REJECT = -1; public static final String LEG_STATUS_REJECT_NAME = "审批未通过"; @@ -56,9 +56,9 @@ public class LegConstant { public static final String LEG_EVENT_NOT_ORDERED_NAME = "同步事件"; public static final int LEG_EVENT_ORDERED = 3; public static final String LEG_EVENT_ORDERED_NAME = "下单事件"; - public static final int LEG_EVENT_PAYED = 4; + public static final int LEG_EVENT_PAYED = 5; public static final String LEG_EVENT_PAYED_NAME = "付款事件"; - public static final int LEG_EVENT_FINISH = 5; + public static final int LEG_EVENT_FINISH = -2; public static final String LEG_EVENT_FINISH_NAME = "结束事件"; public static final int LEG_EVENT_REJECT = -1; public static final String LEG_EVENT_REJECT_NAME = "拒绝事件"; diff --git a/src/main/java/com/chint/infrastructure/handler/GlobalExceptionHandler.java b/src/main/java/com/chint/infrastructure/handler/GlobalExceptionHandler.java index edddf647..0f1516d3 100644 --- a/src/main/java/com/chint/infrastructure/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/chint/infrastructure/handler/GlobalExceptionHandler.java @@ -47,6 +47,11 @@ public class GlobalExceptionHandler { return Result.tokenExpired(e.getMessage()); } + @ExceptionHandler(SSOLoginException.class) + public Result handleSSOLoginException(HttpServletRequest request, SSOLoginException e) { + return Result.ssoLoginFail(e.getMessage()); + } + @ExceptionHandler(value = Exception.class) public Result handleException(Exception ex) { Throwable rootCause = ex; diff --git a/src/main/java/com/chint/infrastructure/repository/CityRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/CityRepositoryImpl.java index 12223a1d..b347806c 100644 --- a/src/main/java/com/chint/infrastructure/repository/CityRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/CityRepositoryImpl.java @@ -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 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 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;} } diff --git a/src/main/java/com/chint/infrastructure/repository/ClientRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/ClientRepositoryImpl.java new file mode 100644 index 00000000..58537a60 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/ClientRepositoryImpl.java @@ -0,0 +1,32 @@ +package com.chint.infrastructure.repository; + +import com.chint.application.dtos.AuthenticationDto; +import com.chint.domain.aggregates.order.Client; +import com.chint.domain.repository.ClientRepository; +import com.chint.infrastructure.repository.jdbc.JdbcClientRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +/** + * @author wanglf3 + * @date 2024-02-28 + * @vsrsion 1.0 + **/ + +@Repository +public class ClientRepositoryImpl implements ClientRepository { + + @Autowired + private JdbcClientRepository jdbcClientRepository; + @Override + public Client save(Client client) { + return jdbcClientRepository.save(client); + } + + @Override + public Client findByClientId(String clientId){ + return jdbcClientRepository.findByClientId(clientId); + } + + +} diff --git a/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java index ef99b946..2abbeda2 100644 --- a/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java @@ -39,7 +39,7 @@ public class LegRepositoryImpl implements LegRepository { } @Override - public Leg findByLegId(Leg leg) { - return legRepository.findById(leg.getLegId()).orElseThrow(()->new NotFoundException(NOT_FOUND)); + public Leg findByLegId(Long legId) { + return legRepository.findById(legId).orElseThrow(()->new NotFoundException(NOT_FOUND)); } } diff --git a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java index 3e6ab08c..9bb51a57 100644 --- a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java @@ -76,4 +76,30 @@ public class LocationRepositoryImpl implements LocationRepository { Location byLocationName = jdbcLocationRepository.findByLocationName(localName); return byLocationName.getLocationPathName().replace("_", "、"); } + + @Override + public List findByNameList(List locationIds) { + return jdbcLocationRepository.findByLocationIdIn(locationIds); + } + + + @Override + public List findHotCitiesByCityName(List locationNames) { + return jdbcLocationRepository.findByLocationNameInAndLocationPathContainingAndLevel(locationNames,"3106_1_",3); + } + + + @Override + public List findHotIntnationalCitiesByCityName(List locationNames){ + List hotCities = + jdbcLocationRepository.findByLocationPathNameInAndLevel(locationNames,3); + return hotCities; + } + + +// public List findHotIntnationalCitiesByCityName(List locationNames) { +// List hotCities = +// jdbcLocationRepository.findByLocationPathNameAndLevel(locationNames,3); +// return hotCities; +// } } diff --git a/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java index 9a3856fc..c4164f72 100644 --- a/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java @@ -1,10 +1,15 @@ package com.chint.infrastructure.repository; +import com.chint.application.dtos.OrderDetailQueryParam; import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.repository.OrderDetailRepository; import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository; +import com.chint.infrastructure.util.BaseContext; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Repository; import java.util.List; @@ -17,6 +22,14 @@ public class OrderDetailRepositoryImpl implements OrderDetailRepository { @Autowired private JdbcOrderDetailRepository orderDetailRepository; + @Override + public Page pageQuery(OrderDetailQueryParam orderDetailQueryParam) { + PageRequest pageRequest = PageRequest + .of(orderDetailQueryParam.getPageNum() - 1, orderDetailQueryParam.getPageSize(), Sort.by("updateTime")); + String employeeNo = BaseContext.getCurrentUser().getEmployeeNo(); + return orderDetailRepository.findByEmployeeNo(employeeNo, pageRequest); + } + @Override public OrderDetail findById(Long orderDetailId) { return orderDetailRepository.findById(orderDetailId).orElseThrow(() -> new NotFoundException(NOT_FOUND)); diff --git a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java index ae8fbb42..b84816b7 100644 --- a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java @@ -49,7 +49,7 @@ public class RouteRepositoryImpl implements RouteRepository { @Override public Page findByOrderNoFuzzy(OrderQueryData orderQueryData) { PageRequest sort = PageRequest - .of(orderQueryData.getPageNum() - 1, orderQueryData.getPageSize(), Sort.by("sort")); + .of(orderQueryData.getPageNum() - 1, orderQueryData.getPageSize(), Sort.by("updateTime")); String employeeNo = BaseContext.getCurrentUser().getEmployeeNo().toString(); return jdbcRouteRepository .findByUserIdAndRouteOrderNoContainingOrApproveOrderNo_CreatorAndRouteOrderNoContaining( @@ -63,7 +63,7 @@ public class RouteRepositoryImpl implements RouteRepository { @Override public Page findByInstructions(OrderQueryData orderQueryData) { PageRequest sort = PageRequest - .of(orderQueryData.getPageNum() - 1, orderQueryData.getPageSize(), Sort.by("sort")); + .of(orderQueryData.getPageNum() - 1, orderQueryData.getPageSize(), Sort.by("updateTime")); String employeeNo = BaseContext.getCurrentUser().getEmployeeNo().toString(); return jdbcRouteRepository.findByUserIdAndApproveOrderNo_InstructionsContainingOrApproveOrderNo_CreatorAndApproveOrderNo_InstructionsContaining( Long.valueOf(employeeNo), @@ -81,7 +81,7 @@ public class RouteRepositoryImpl implements RouteRepository { @Override public PageResult pageQuery(OrderQueryData orderQueryData) { PageRequest sort = PageRequest - .of(orderQueryData.getPageNum() - 1, orderQueryData.getPageSize(), Sort.by("sort")); + .of(orderQueryData.getPageNum() - 1, orderQueryData.getPageSize(), Sort.by("updateTime")); String employeeNo = BaseContext.getCurrentUser().getEmployeeNo().toString(); Page byUserId = jdbcRouteRepository .findByUserIdAndApproveOrderNo_ActualOrderNoNotNullOrApproveOrderNo_CreatorAndApproveOrderNo_ActualOrderNoNotNull(Long.valueOf(employeeNo), employeeNo, sort); diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcClientRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcClientRepository.java new file mode 100644 index 00000000..05362686 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcClientRepository.java @@ -0,0 +1,17 @@ +package com.chint.infrastructure.repository.jdbc; + +import com.chint.domain.aggregates.order.Client; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +/** + * @author wanglf3 + * @date 2024-02-28 + * @vsrsion 1.0 + **/ + +@Repository +public interface JdbcClientRepository extends CrudRepository { + + Client findByClientId(String clientId); +} diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java index 849bb9ab..f289cd07 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; +import java.util.Collection; import java.util.List; @Repository @@ -23,4 +24,16 @@ public interface JdbcLocationRepository extends CrudRepository { List findByLocationNameContaining(String locationName); Location findByLocationName(String locationName); + + List findByLocationNameIn(Collection locationName); + + + List findByLocationIdIn(Collection locationId); + + List findByLocationNameInAndLocationPathContainingAndLevel(Collection locationName, + String locationPath, + Integer level); + + List findByLocationPathNameInAndLevel(Collection locationPathName,Integer level); + } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java index 05b8df02..7349cee2 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java @@ -1,6 +1,8 @@ package com.chint.infrastructure.repository.jdbc; import com.chint.domain.aggregates.order.OrderDetail; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @@ -12,4 +14,6 @@ public interface JdbcOrderDetailRepository extends CrudRepository findByLegId(Long legId); + + Page findByEmployeeNo(String employeeNo, Pageable pageable); } diff --git a/src/main/java/com/chint/infrastructure/util/Result.java b/src/main/java/com/chint/infrastructure/util/Result.java index 9117f680..3631dc1e 100644 --- a/src/main/java/com/chint/infrastructure/util/Result.java +++ b/src/main/java/com/chint/infrastructure/util/Result.java @@ -52,6 +52,9 @@ public class Result implements Serializable { public static Result tokenExpired(String msg) { return new Result(msg, "-1"); } + public static Result ssoLoginFail(String msg) { + return new Result(msg, "-2"); + } @Override public boolean equals(Object o) { diff --git a/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java b/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java index b2ce91aa..3fc6cdb7 100644 --- a/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java +++ b/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java @@ -16,29 +16,49 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - String token = request.getHeader(AuthMessageConstant.HEADER_TOKEN); - - if (token == null) { - token = request.getHeader(AuthMessageConstant.HEADER_TOKEN_UP_CASE); - } - if (request.getRequestURI().contains("/pubilc")) { - return true; - } - - if (token == null) { - throw new AuthException(AuthMessageConstant.JWT_REQUIRED); - } - try { - JWTUtil.verifyJWT(AuthMessageConstant.SECRET, token); - var parseJWT = JWTUtil.parseJWT(AuthMessageConstant.SECRET, token); - var withJwt = User.withJwt(parseJWT); - BaseContext.setCurrentUser(withJwt); - return true; // If verification succeeds, continue processing the request + String token = null; + token = request.getHeader(AuthMessageConstant.HEADER_TOKEN); + if (token != null) { + return dealWithTokenInfo(token); + } + + if (token == null) { + token = request.getHeader(AuthMessageConstant.HEADER_TOKEN_UP_CASE); + if (token != null) { + return dealWithTokenInfo(token); + } + } + if (token == null) { + token = request.getHeader(AuthMessageConstant.HEADER_CLIENT_CASE); + if (token != null) { + return dealWithClientInfo(token); + } + } + if (request.getRequestURI().contains("/pubilc")) { + return true; + } + if (token == null) { + throw new AuthException(AuthMessageConstant.JWT_REQUIRED); + } } catch (TokenExpiredException e) { throw new JwtExpiredException(AuthMessageConstant.JWT_EXPIRED); } catch (Exception e) { throw new AuthException(AuthMessageConstant.JWT_INVALID); } + return false; + } + + private boolean dealWithTokenInfo(String token) { + JWTUtil.verifyJWT(AuthMessageConstant.SECRET, token); + var parseJWT = JWTUtil.parseJWT(AuthMessageConstant.SECRET, token); + var withJwt = User.withJwt(parseJWT); + BaseContext.setCurrentUser(withJwt); + return true; // If verification succeeds, continue processing the request + } + + private boolean dealWithClientInfo(String token) { + JWTUtil.verifyJWT(AuthMessageConstant.SECRET, token); + return true; // If verification succeeds, continue processing the request } } \ No newline at end of file diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/CTripFlightCitySearchRequest.java b/src/main/java/com/chint/interfaces/rest/ctrip/CTripFlightCitySearchRequest.java new file mode 100644 index 00000000..e5e6112a --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/ctrip/CTripFlightCitySearchRequest.java @@ -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; + } + +} diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/dto/city/FlightCitySearchRequest.java b/src/main/java/com/chint/interfaces/rest/ctrip/dto/city/FlightCitySearchRequest.java new file mode 100644 index 00000000..a1166534 --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/ctrip/dto/city/FlightCitySearchRequest.java @@ -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; +} diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/dto/city/FlightCitySearchResponse.java b/src/main/java/com/chint/interfaces/rest/ctrip/dto/city/FlightCitySearchResponse.java new file mode 100644 index 00000000..8f37ebce --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/ctrip/dto/city/FlightCitySearchResponse.java @@ -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 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 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 + } +} \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 1fee43ff..622493fd 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -57,6 +57,9 @@ paila: client-id: 0053df85723db94491e8 client-secret: 7368bcec4c0f004c40585f6ed1087d887897 redirect-url: https://gxdev03.chint.com/businesstravelhome/#/ + client-mobile-id: 9b24c91ead42ee4b6918 + client-mobile-secret: e54494f1272ffd41b818980f1f8524fd68ef + redirect-mobile-url: https://gxdev03.chint.com/businesstravelmhome/#/ base-url: https://signin-test.chint.com token-name: token diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index acbeb3a9..b44eb244 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -27,5 +27,8 @@ paila: client-id: 0053df85723db94491e8 client-secret: 7368bcec4c0f004c40585f6ed1087d887897 redirect-url: https://gxdev03.chint.com/businesstravelhome/#/ + client-mobile-id: 9b24c91ead42ee4b6918 + client-mobile-secret: e54494f1272ffd41b818980f1f8524fd68ef + redirect-mobile-url: https://gxdev03.chint.com/businesstravelmhome/#/ base-url: https://signin-test.chint.com token-name: token diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 7cd44706..36b48380 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -46,6 +46,9 @@ paila: client-id: 0053df85723db94491e8 client-secret: 7368bcec4c0f004c40585f6ed1087d887897 redirect-url: https://gxdev03.chint.com/businesstravelhome/#/ + client-mobile-id: 9b24c91ead42ee4b6918 + client-mobile-secret: e54494f1272ffd41b818980f1f8524fd68ef + redirect-mobile-url: https://gxdev03.chint.com/businesstravelmhome/#/ base-url: https://signin-test.chint.com token-name: token diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 6ece2f6a..4d0f5145 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -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); + } } diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 05d230ab..4562179d 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -17,6 +17,7 @@ import org.springframework.boot.test.context.SpringBootTest; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Arrays; import java.util.List; @Slf4j @@ -124,4 +125,10 @@ class RouteApplicationTests { String login = pailaLoginStrategy.login("OC-5909-zRqrWjZGNThNXJiAV1kA7dPXTojGzVxK3nE"); System.out.println(login); } + +// @Test + void arrayToStr(){ + List ids = List.of(1L,2L,3L,4L); + System.out.println(Arrays.toString(ids.toArray())); + } }