From 6b33590553a3548e775cf7f135b1a15413a755a5 Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Wed, 28 Feb 2024 19:56:16 +0800 Subject: [PATCH 01/21] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=98=8E=E7=BB=86=E8=AE=A4=E8=AF=81=E6=8E=A5=E5=8F=A3=E5=92=8C?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=98=8E=E7=BB=86=E8=AE=A4=E8=AF=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dtos/AuthenticationDto.java | 12 +++ .../application/dtos/OrderSearchResult.java | 10 +++ .../out/OrderDetailController.java | 74 +++++++++++++++++++ .../chint/domain/aggregates/order/Client.java | 18 +++++ .../domain/repository/ClientRepository.java | 16 ++++ .../service/auth/AuthenticateService.java | 4 + .../service/auth/AuthenticateServiceImpl.java | 32 ++++++++ .../constant/AuthMessageConstant.java | 8 ++ .../repository/ClientRepositoryImpl.java | 32 ++++++++ .../repository/jdbc/JdbcClientRepository.java | 17 +++++ .../webconfig/JwtTokenAdminInterceptor.java | 49 +++++++----- 11 files changed, 254 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/chint/application/dtos/AuthenticationDto.java create mode 100644 src/main/java/com/chint/application/dtos/OrderSearchResult.java create mode 100644 src/main/java/com/chint/application/out/OrderDetailController.java create mode 100644 src/main/java/com/chint/domain/aggregates/order/Client.java create mode 100644 src/main/java/com/chint/domain/repository/ClientRepository.java create mode 100644 src/main/java/com/chint/infrastructure/repository/ClientRepositoryImpl.java create mode 100644 src/main/java/com/chint/infrastructure/repository/jdbc/JdbcClientRepository.java 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/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/out/OrderDetailController.java b/src/main/java/com/chint/application/out/OrderDetailController.java new file mode 100644 index 00000000..dd1a5b10 --- /dev/null +++ b/src/main/java/com/chint/application/out/OrderDetailController.java @@ -0,0 +1,74 @@ +package com.chint.application.out; + +import cn.hutool.core.bean.BeanUtil; +import com.chint.application.dtos.AuthenticationDto; +import com.chint.application.dtos.AuthenticationSignDto; +import com.chint.application.dtos.LocationParam; +import com.chint.application.dtos.OrderSearchResult; +import com.chint.application.dtos.response.LocationRes; +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.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) { +// Calendar calendar = Calendar.getInstance(); +// long timestamp = calendar.getTimeInMillis(); + OrderSearchResult orderSearchResult = authenticateService.authenticateClient(authenticationDto); + return Result.Success(SUCCESS, orderSearchResult); + } + + @ApiOperation("订单明细查询接口") + @PostMapping("/query") + public Result query(@RequestBody AuthenticationSignDto authenticationDto) { + + String systemType = authenticationDto.getSystemType(); + String startTime = authenticationDto.getStartTime(); + String endTime = authenticationDto.getEndTime(); + String pageSize = authenticationDto.getEndTime().toString(); + String pageNum = authenticationDto.getPageNum().toString(); + String orgsign = authenticationDto.getSign(); + String sign = Digest.md5(systemType + startTime + endTime + pageSize + pageNum); + System.out.println(sign); + + if (orgsign.equals(sign)) { + return Result.Success(SUCCESS,sign); + } else { + return Result.error("签名错误"); + } + } +} \ No newline at end of file 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/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/service/auth/AuthenticateService.java b/src/main/java/com/chint/domain/service/auth/AuthenticateService.java index e1597e14..e0089bc1 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); } 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..13ca6b71 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,11 @@ 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.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 +27,9 @@ public class AuthenticateServiceImpl implements AuthenticateService { private final UserRepository userRepository; private final UserHttpRequest httpRequest; + @Autowired + private ClientRepository clientRepository; + @Autowired private UserFactory userFactory; @@ -74,4 +81,29 @@ public class AuthenticateServiceImpl implements AuthenticateService { return authenticateEmployeeNo(userLoginParam); } } + + @Override + public OrderSearchResult authenticateClient(AuthenticationDto authenticationDto) { + + 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 { + + } + + return null; + } } \ No newline at end of file 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/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/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/webconfig/JwtTokenAdminInterceptor.java b/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java index b2ce91aa..05f281ed 100644 --- a/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java +++ b/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java @@ -16,29 +16,42 @@ 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 = request.getHeader(AuthMessageConstant.HEADER_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 From f264f9c7a56c5dc752590d5648d9d5cc3bbf141e Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Wed, 28 Feb 2024 19:57:57 +0800 Subject: [PATCH 02/21] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=98=8E=E7=BB=86=E8=AE=A4=E8=AF=81=E6=8E=A5=E5=8F=A3=E5=92=8C?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=98=8E=E7=BB=86=E8=AE=A4=E8=AF=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dtos/AuthenticationSignDto.java | 14 ++++++++++++++ .../application/out/OrderOutController.java | 18 +++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/chint/application/dtos/AuthenticationSignDto.java 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..f0ab3dfe --- /dev/null +++ b/src/main/java/com/chint/application/dtos/AuthenticationSignDto.java @@ -0,0 +1,14 @@ +package com.chint.application.dtos; + + +import com.chint.domain.value_object.BaseQuery; +import lombok.Data; + +@Data +public class AuthenticationSignDto extends BaseQuery { + private String systemType; + private String startTime; + private String endTime; + + private String sign; +} diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index 50025e9f..e357f6bd 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -76,14 +76,14 @@ public class OrderOutController { } - @ApiOperation("根据Id查询行程规划单-元年数据") - @PostMapping("/query/tripCallback") - public Result queryTripCallbackData(@RequestBody OrderQueryData queryData) { - TripCallback tripCallback = orderQuery.queryTripCallbackData(queryData); - Gson gson = new Gson(); - String json = gson.toJson(tripCallback); - log.info(json); - return Result.Success(SUCCESS, tripCallback); - } +// @ApiOperation("根据Id查询行程规划单-元年数据") +// @PostMapping("/query/tripCallback") +// public Result queryTripCallbackData(@RequestBody OrderQueryData queryData) { +// TripCallback tripCallback = orderQuery.queryTripCallbackData(queryData); +// Gson gson = new Gson(); +// String json = gson.toJson(tripCallback); +// log.info(json); +// return Result.Success(SUCCESS, tripCallback); +// } } From aa86243ec08e07005e6dd2f5705ddfa2dbb70d86 Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Wed, 28 Feb 2024 20:00:40 +0800 Subject: [PATCH 03/21] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/out/OrderOutController.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index e357f6bd..50025e9f 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -76,14 +76,14 @@ public class OrderOutController { } -// @ApiOperation("根据Id查询行程规划单-元年数据") -// @PostMapping("/query/tripCallback") -// public Result queryTripCallbackData(@RequestBody OrderQueryData queryData) { -// TripCallback tripCallback = orderQuery.queryTripCallbackData(queryData); -// Gson gson = new Gson(); -// String json = gson.toJson(tripCallback); -// log.info(json); -// return Result.Success(SUCCESS, tripCallback); -// } + @ApiOperation("根据Id查询行程规划单-元年数据") + @PostMapping("/query/tripCallback") + public Result queryTripCallbackData(@RequestBody OrderQueryData queryData) { + TripCallback tripCallback = orderQuery.queryTripCallbackData(queryData); + Gson gson = new Gson(); + String json = gson.toJson(tripCallback); + log.info(json); + return Result.Success(SUCCESS, tripCallback); + } } From e563cffe37c86857993be846361baf1653c0dbcf Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 08:27:06 +0800 Subject: [PATCH 04/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chint/application/in/OrderController.java | 18 ++++++++++++++++-- .../leg_event/LegEventServiceImpl.java | 2 +- .../domain/value_object/SyncLegData.java | 3 +++ .../infrastructure/constant/LegConstant.java | 8 ++++---- .../webconfig/JwtTokenAdminInterceptor.java | 19 +++++++++++++------ 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/chint/application/in/OrderController.java b/src/main/java/com/chint/application/in/OrderController.java index 943b5630..1ba1dec0 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") 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/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/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/webconfig/JwtTokenAdminInterceptor.java b/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java index 05f281ed..3fc6cdb7 100644 --- a/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java +++ b/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java @@ -17,16 +17,21 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { try { - String token = request.getHeader(AuthMessageConstant.HEADER_TOKEN); + 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){ + if (token != null) { return dealWithTokenInfo(token); } } - if (token == null){ + if (token == null) { token = request.getHeader(AuthMessageConstant.HEADER_CLIENT_CASE); - if (token != null){ + if (token != null) { return dealWithClientInfo(token); } } @@ -43,14 +48,16 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor { } return false; } - private boolean dealWithTokenInfo(String token){ + + 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){ + + private boolean dealWithClientInfo(String token) { JWTUtil.verifyJWT(AuthMessageConstant.SECRET, token); return true; // If verification succeeds, continue processing the request } From fc6a2821d524f8bea4d7b710294adce909e1ead6 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 08:42:06 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/chint/application/queryies/OrderQuery.java | 2 ++ .../chint/application/services/login/LoginStrategy.java | 3 ++- .../services/login/strategy/PailaLoginStrategy.java | 3 ++- .../com/chint/domain/exceptions/SSOLoginException.java | 7 +++++++ .../infrastructure/handler/GlobalExceptionHandler.java | 5 +++++ .../infrastructure/repository/RouteRepositoryImpl.java | 6 +++--- src/main/java/com/chint/infrastructure/util/Result.java | 3 +++ 7 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/chint/domain/exceptions/SSOLoginException.java diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index 35c555c8..2cf6b502 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; @@ -89,6 +90,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) 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..658c7355 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; @@ -92,7 +93,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/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/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/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/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) { From cb98f347b5181a8be0db6e2129ba0fb36647dcf0 Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Thu, 29 Feb 2024 08:44:50 +0800 Subject: [PATCH 06/21] =?UTF-8?q?1.=E8=AE=A2=E5=8D=95=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=BC=98=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../out/OrderDetailController.java | 23 ++++++++++++++----- .../service/auth/AuthenticateService.java | 2 +- .../service/auth/AuthenticateServiceImpl.java | 8 +++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/chint/application/out/OrderDetailController.java b/src/main/java/com/chint/application/out/OrderDetailController.java index dd1a5b10..ea85a6bc 100644 --- a/src/main/java/com/chint/application/out/OrderDetailController.java +++ b/src/main/java/com/chint/application/out/OrderDetailController.java @@ -16,6 +16,7 @@ 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; @@ -46,10 +47,19 @@ public class OrderDetailController { @ApiOperation("订单明细认证接口") @PostMapping("/pubilc/authentication") public Result queryAuthentication(@RequestBody AuthenticationDto authenticationDto) { -// Calendar calendar = Calendar.getInstance(); -// long timestamp = calendar.getTimeInMillis(); - OrderSearchResult orderSearchResult = authenticateService.authenticateClient(authenticationDto); - return Result.Success(SUCCESS, orderSearchResult); + + 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("订单明细查询接口") @@ -59,13 +69,14 @@ public class OrderDetailController { String systemType = authenticationDto.getSystemType(); String startTime = authenticationDto.getStartTime(); String endTime = authenticationDto.getEndTime(); - String pageSize = authenticationDto.getEndTime().toString(); + String pageSize = authenticationDto.getPageSize().toString(); String pageNum = authenticationDto.getPageNum().toString(); String orgsign = authenticationDto.getSign(); String sign = Digest.md5(systemType + startTime + endTime + pageSize + pageNum); System.out.println(sign); - if (orgsign.equals(sign)) { + + if (StringUtils.isNotBlank(orgsign) && orgsign.equals(sign)) { return Result.Success(SUCCESS,sign); } else { return Result.error("签名错误"); 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 e0089bc1..01f58296 100644 --- a/src/main/java/com/chint/domain/service/auth/AuthenticateService.java +++ b/src/main/java/com/chint/domain/service/auth/AuthenticateService.java @@ -8,5 +8,5 @@ import com.chint.domain.value_object.UserLoginResult; public interface AuthenticateService { UserLoginResult authenticateEmployeeNo(UserLoginParam userLoginParam); - OrderSearchResult authenticateClient(AuthenticationDto authenticationDto); + 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 13ca6b71..f3b02909 100644 --- a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java +++ b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java @@ -4,6 +4,7 @@ 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; @@ -83,7 +84,7 @@ public class AuthenticateServiceImpl implements AuthenticateService { } @Override - public OrderSearchResult authenticateClient(AuthenticationDto authenticationDto) { + public OrderSearchResult authenticateClient(AuthenticationDto authenticationDto) throws Exception{ Client client = clientRepository.findByClientId(authenticationDto.getClientid()); @@ -95,15 +96,12 @@ public class AuthenticateServiceImpl implements AuthenticateService { 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); } - - return null; } } \ No newline at end of file From a0ef0eef9980cbc87a10764aeb46690c977d6c5d Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 09:28:18 +0800 Subject: [PATCH 07/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dtos/OrderDetailQueryParam.java | 6 +++++ .../dtos/response/RouteOrderPageRes.java | 1 + .../chint/application/in/OrderController.java | 9 ++++++++ .../out/OrderDetailController.java | 13 +++++++---- .../queryies/OrderDetailQuery.java | 22 +++++++++++++++++++ .../services/OrderApplicationService.java | 4 ++++ .../domain/aggregates/order/OrderDetail.java | 6 ++++- .../repository/OrderDetailRepository.java | 4 ++++ .../service/leg_event/LegEventHandler.java | 3 ++- .../repository/OrderDetailRepositoryImpl.java | 13 +++++++++++ .../jdbc/JdbcOrderDetailRepository.java | 4 ++++ 11 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/chint/application/dtos/OrderDetailQueryParam.java create mode 100644 src/main/java/com/chint/application/queryies/OrderDetailQuery.java 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/response/RouteOrderPageRes.java b/src/main/java/com/chint/application/dtos/response/RouteOrderPageRes.java index f2c05870..b8d9b9af 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 String 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 1ba1dec0..ffa7874a 100644 --- a/src/main/java/com/chint/application/in/OrderController.java +++ b/src/main/java/com/chint/application/in/OrderController.java @@ -80,6 +80,15 @@ public class OrderController { return Result.Success(SUCCESS); } + @Transactional + @ApiOperation("修改行程节点") + @PostMapping("/leg/update") + public Result updateLeg(@RequestBody AddLegData addLegData) { + orderApplicationService.updateLegToOrder(addLegData); + return Result.Success(SUCCESS); + } + + @Transactional @ApiOperation("删除行程节点") @PostMapping("/leg/delete") diff --git a/src/main/java/com/chint/application/out/OrderDetailController.java b/src/main/java/com/chint/application/out/OrderDetailController.java index dd1a5b10..b84f7c47 100644 --- a/src/main/java/com/chint/application/out/OrderDetailController.java +++ b/src/main/java/com/chint/application/out/OrderDetailController.java @@ -1,11 +1,9 @@ package com.chint.application.out; import cn.hutool.core.bean.BeanUtil; -import com.chint.application.dtos.AuthenticationDto; -import com.chint.application.dtos.AuthenticationSignDto; -import com.chint.application.dtos.LocationParam; -import com.chint.application.dtos.OrderSearchResult; +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; @@ -71,4 +69,11 @@ public class OrderDetailController { 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/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/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index 07550796..29a25522 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -149,4 +149,8 @@ public class OrderApplicationService { public void reloadOrderDetail(SyncLegData syncLegData) { } + + @Transactional + public void updateLegToOrder(AddLegData addLegData) { + } } 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/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/leg_event/LegEventHandler.java b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java index 5ef1b178..4990c620 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 @@ -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 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/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); } From 3748fe0e6e06cbf843d9e0111cd1976b4fe45443 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 09:33:39 +0800 Subject: [PATCH 08/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/chint/application/in/OrderController.java | 6 +++--- .../chint/application/services/OrderApplicationService.java | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/chint/application/in/OrderController.java b/src/main/java/com/chint/application/in/OrderController.java index ffa7874a..9e0f0f4a 100644 --- a/src/main/java/com/chint/application/in/OrderController.java +++ b/src/main/java/com/chint/application/in/OrderController.java @@ -82,9 +82,9 @@ public class OrderController { @Transactional @ApiOperation("修改行程节点") - @PostMapping("/leg/update") - public Result updateLeg(@RequestBody AddLegData addLegData) { - orderApplicationService.updateLegToOrder(addLegData); + @PostMapping("/leg/change/") + public Result changeLeg(@RequestBody AddLegData addLegData) { + orderApplicationService.changeLeg(addLegData); return Result.Success(SUCCESS); } diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index 29a25522..f2fae889 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -153,4 +153,8 @@ public class OrderApplicationService { @Transactional public void updateLegToOrder(AddLegData addLegData) { } + + @Transactional + public void changeLeg(AddLegData addLegData) { + } } From 824bcc98cfc838ce4c203522bc3dc3a94284bd39 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 10:08:28 +0800 Subject: [PATCH 09/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/out/OrderOutController.java | 8 ++++++++ .../chint/application/queryies/OrderQuery.java | 11 ++++++++++- .../services/OrderApplicationService.java | 16 +++++++++++++--- .../aggregates/order/LegExtensionField.java | 5 +++++ .../com/chint/domain/event/LegEventListener.java | 2 +- .../chint/domain/repository/LegRepository.java | 4 +++- .../service/leg_event/LegEventHandler.java | 8 ++++---- .../repository/LegRepositoryImpl.java | 4 ++-- 8 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index 50025e9f..746e199d 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,10 @@ 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/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index 2cf6b502..1a128e95 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -34,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 @@ -60,6 +61,7 @@ public class OrderQuery { @Autowired private EstimateAdapter estimateAdapter; + public RouteOrder queryByOrderId(OrderQueryData queryData) { return routeRepository.queryById(queryData.getRouteId()).reloadStatus(); } @@ -299,7 +301,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); @@ -320,4 +322,11 @@ public class OrderQuery { .toList()); return routeOrderRes; } + + public List queryNotSubmit(OrderQueryData queryData) { + List byActualOrderNoNotNull = routeRepository.findByActualOrderNoNotNull(queryData); + return byActualOrderNoNotNull.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 f2fae889..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 @@ -156,5 +158,13 @@ public class OrderApplicationService { @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/domain/aggregates/order/LegExtensionField.java b/src/main/java/com/chint/domain/aggregates/order/LegExtensionField.java index ebe3810c..f62a8413 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,8 @@ import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Transient; import org.springframework.data.relational.core.mapping.Table; +import java.util.List; + @Data @Table("leg_extension_field") public class LegExtensionField { @@ -13,6 +15,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 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/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/service/leg_event/LegEventHandler.java b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java index 4990c620..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); @@ -174,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 @@ -190,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); @@ -199,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/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)); } } From 5e119950e113420056da58b826db6d3e2f54dfae Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 10:22:07 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/chint/application/out/OrderOutController.java | 1 + .../java/com/chint/application/queryies/OrderQuery.java | 8 +++++--- .../repository/jdbc/JdbcLocationRepository.java | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index 746e199d..a7559d63 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -94,4 +94,5 @@ public class OrderOutController { public Result> queryNotSubmit(@RequestBody OrderQueryData queryData) { return Result.Success(SUCCESS, orderQuery.queryNotSubmit(queryData)); } + } diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index 1a128e95..a2ac90e6 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -142,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) @@ -324,8 +325,9 @@ public class OrderQuery { } public List queryNotSubmit(OrderQueryData queryData) { - List byActualOrderNoNotNull = routeRepository.findByActualOrderNoNotNull(queryData); - return byActualOrderNoNotNull.stream().filter(order -> order.reloadStatus().getOrderStatus().equals(ORDER_STATUS_APPROVAL)) + 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/infrastructure/repository/jdbc/JdbcLocationRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java index 849bb9ab..4695cc40 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,5 @@ public interface JdbcLocationRepository extends CrudRepository { List findByLocationNameContaining(String locationName); Location findByLocationName(String locationName); + } From 627ff7317c6bde7161aec35f88f14bc0465c2980 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 12:51:06 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dtos/response/LegRes.java | 14 ++++++++++++ .../dtos/response/RouteOrderPageRes.java | 2 +- .../aggregates/order/LegExtensionField.java | 22 +++++++++++++++++++ .../domain/aggregates/standards/CityTag.java | 1 - .../domain/factoriy/leg/RouteLegFactory.java | 6 ++++- .../domain/repository/LocationRepository.java | 2 ++ .../domain/service/OrderDomainService.java | 9 +++++++- .../value_object/LegExtensionFieldData.java | 4 ++++ .../repository/LocationRepositoryImpl.java | 5 +++++ .../jdbc/JdbcLocationRepository.java | 3 +++ .../java/com/chint/RouteApplicationTests.java | 8 +++++++ 11 files changed, 72 insertions(+), 4 deletions(-) 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/RouteOrderPageRes.java b/src/main/java/com/chint/application/dtos/response/RouteOrderPageRes.java index b8d9b9af..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,7 +34,7 @@ public class RouteOrderPageRes { private String amount; private String estimateAmount; private Integer orderStatus; - private String approvalStatusCode; + private Integer approvalStatusCode; private String approvalStatus; private String orderStatusName; private String startTime; 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 f62a8413..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,8 @@ 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 @@ -28,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/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/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/LocationRepository.java b/src/main/java/com/chint/domain/repository/LocationRepository.java index c8034d09..a45e5d59 100644 --- a/src/main/java/com/chint/domain/repository/LocationRepository.java +++ b/src/main/java/com/chint/domain/repository/LocationRepository.java @@ -22,4 +22,6 @@ public interface LocationRepository { List findByName(String localName); String locationPathByName(String localName); + + List findByNameList(List locationIds); } \ No newline at end of file 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/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/infrastructure/repository/LocationRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java index 3e6ab08c..65418e05 100644 --- a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java @@ -76,4 +76,9 @@ public class LocationRepositoryImpl implements LocationRepository { Location byLocationName = jdbcLocationRepository.findByLocationName(localName); return byLocationName.getLocationPathName().replace("_", "、"); } + + @Override + public List findByNameList(List locationIds) { + return jdbcLocationRepository.findByLocationIdIn(locationIds); + } } 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 4695cc40..7a1a4841 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java @@ -25,4 +25,7 @@ public interface JdbcLocationRepository extends CrudRepository { Location findByLocationName(String locationName); + List findByLocationNameIn(Collection locationName); + + List findByLocationIdIn(Collection locationId); } diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 05d230ab..4a5bec2e 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,11 @@ 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())); + + } } From 6abb2643a9aea67faace9959f326c8c08ff478b2 Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Thu, 29 Feb 2024 13:22:51 +0800 Subject: [PATCH 12/21] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=83=AD=E9=97=A8=E5=9F=8E=E5=B8=82=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/out/LocationController.java | 53 +++++++++++++++++++ .../aggregates/standards/HotCityTag.java | 29 ++++++++++ .../domain/repository/LocationRepository.java | 2 + .../repository/LocationRepositoryImpl.java | 8 +++ .../jdbc/JdbcLocationRepository.java | 7 ++- .../java/com/chint/RouteApplicationTests.java | 2 +- 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/chint/domain/aggregates/standards/HotCityTag.java diff --git a/src/main/java/com/chint/application/out/LocationController.java b/src/main/java/com/chint/application/out/LocationController.java index 33a720d5..57937020 100644 --- a/src/main/java/com/chint/application/out/LocationController.java +++ b/src/main/java/com/chint/application/out/LocationController.java @@ -4,18 +4,24 @@ import cn.hutool.core.bean.BeanUtil; 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; @@ -55,4 +61,51 @@ public class LocationController { } return Result.Success(SUCCESS, locationRes); } + +// @ApiOperation("获取热门城市") +// @PostMapping("/getHotCities") +// public Result> getHotCities() { +// List city = new ArrayList<>(); +// city.add("上海"); +// city.add("北京"); +// city.add("广州"); +// city.add("深圳"); +// city.add("天津"); +// city.add("重庆"); +// city.add("苏州"); +// city.add("武汉"); +// city.add("成都"); +// city.add("杭州"); +// city.add("温州"); +// HashMap cityMap = HotCityTag.cityMap; +// Collection hotCity = cityMap.values(); +// List list = new ArrayList<>(hotCity); +// return Result.Success(SUCCESS, locationRepository.findHotCitiesByCityName(city)); +// +// +//// return Result.Success(SUCCESS, locationRepository.findHotCitiesByCityName(cityMap.values())); +// +// } + + @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(location -> BeanUtil.copyProperties(location, LocationRes.class)).toList(); + } + return Result.Success(SUCCESS, locationRes); + + +// return Result.Success(SUCCESS, locationRepository.findHotCitiesByCityName(cityMap.values())); + + } } \ No newline at end of file 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..1995908b --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/standards/HotCityTag.java @@ -0,0 +1,29 @@ +package com.chint.domain.aggregates.standards; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class HotCityTag { + +// public static final HashMap cityMap; + public static final List citys; + + 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("温州"); + + } + +} diff --git a/src/main/java/com/chint/domain/repository/LocationRepository.java b/src/main/java/com/chint/domain/repository/LocationRepository.java index a45e5d59..3b330a1d 100644 --- a/src/main/java/com/chint/domain/repository/LocationRepository.java +++ b/src/main/java/com/chint/domain/repository/LocationRepository.java @@ -23,5 +23,7 @@ public interface LocationRepository { String locationPathByName(String localName); + List findHotCitiesByCityName(List locationNames); + List findByNameList(List locationIds); } \ No newline at end of file diff --git a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java index 65418e05..11dfb069 100644 --- a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java @@ -81,4 +81,12 @@ public class LocationRepositoryImpl implements LocationRepository { public List findByNameList(List locationIds) { return jdbcLocationRepository.findByLocationIdIn(locationIds); } + + + @Override + public List findHotCitiesByCityName(List locationNames) { + List hotCities = + jdbcLocationRepository.findByLocationNameInAndLocationPathContainingAndLevel(locationNames,"3106_1_",3); + return hotCities; + } } 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 7a1a4841..c5d16d68 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java @@ -25,7 +25,10 @@ public interface JdbcLocationRepository extends CrudRepository { Location findByLocationName(String locationName); - List findByLocationNameIn(Collection locationName); - List findByLocationIdIn(Collection locationId); + + List findByLocationNameInAndLocationPathContainingAndLevel(Collection locationName, + String locationPath, + Integer level); + } diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 4a5bec2e..d7d68120 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -56,7 +56,7 @@ class RouteApplicationTests { } @Test void loginSign() { - String sfno = "230615020"; + String sfno = "220407068"; String syscode = "FSSC"; String billcode = "CLSQ240226000100"; String companycode = "正泰集团股份有限公司"; From e16271e5195566b7c57ae483042ccb0644dcf731 Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Thu, 29 Feb 2024 13:24:14 +0800 Subject: [PATCH 13/21] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=83=AD=E9=97=A8=E5=9F=8E=E5=B8=82=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/chint/RouteApplicationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index d7d68120..4a5bec2e 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -56,7 +56,7 @@ class RouteApplicationTests { } @Test void loginSign() { - String sfno = "220407068"; + String sfno = "230615020"; String syscode = "FSSC"; String billcode = "CLSQ240226000100"; String companycode = "正泰集团股份有限公司"; From 71a44f4588b6839da90dca8085ef9ea16d76dbcd Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Thu, 29 Feb 2024 13:26:39 +0800 Subject: [PATCH 14/21] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=83=AD=E9=97=A8=E5=9F=8E=E5=B8=82=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/out/LocationController.java | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/src/main/java/com/chint/application/out/LocationController.java b/src/main/java/com/chint/application/out/LocationController.java index 57937020..cd960083 100644 --- a/src/main/java/com/chint/application/out/LocationController.java +++ b/src/main/java/com/chint/application/out/LocationController.java @@ -62,31 +62,6 @@ public class LocationController { return Result.Success(SUCCESS, locationRes); } -// @ApiOperation("获取热门城市") -// @PostMapping("/getHotCities") -// public Result> getHotCities() { -// List city = new ArrayList<>(); -// city.add("上海"); -// city.add("北京"); -// city.add("广州"); -// city.add("深圳"); -// city.add("天津"); -// city.add("重庆"); -// city.add("苏州"); -// city.add("武汉"); -// city.add("成都"); -// city.add("杭州"); -// city.add("温州"); -// HashMap cityMap = HotCityTag.cityMap; -// Collection hotCity = cityMap.values(); -// List list = new ArrayList<>(hotCity); -// return Result.Success(SUCCESS, locationRepository.findHotCitiesByCityName(city)); -// -// -//// return Result.Success(SUCCESS, locationRepository.findHotCitiesByCityName(cityMap.values())); -// -// } - @ApiOperation("获取热门城市") @PostMapping("/getHotCities") public Result> getHotCities() { @@ -104,8 +79,5 @@ public class LocationController { } return Result.Success(SUCCESS, locationRes); - -// return Result.Success(SUCCESS, locationRepository.findHotCitiesByCityName(cityMap.values())); - } } \ No newline at end of file From ee0abe3fbfadeddb19cc49b4b09cdd9e8c48f0fa Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 13:27:31 +0800 Subject: [PATCH 15/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/out/LoginController.java | 31 +++++ .../login/strategy/PailaLoginStrategy.java | 1 - .../strategy/PailaMobileLoginStrategy.java | 125 ++++++++++++++++++ .../jdbc/JdbcLocationRepository.java | 7 +- src/main/resources/application-dev.yml | 3 + src/main/resources/application-prod.yml | 3 + src/main/resources/application-test.yml | 3 + .../java/com/chint/RouteApplicationTests.java | 2 +- 8 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/chint/application/services/login/strategy/PailaMobileLoginStrategy.java diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index f2adef3e..8be57fe9 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/services/login/strategy/PailaLoginStrategy.java b/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java index 658c7355..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 @@ -66,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); 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/infrastructure/repository/jdbc/JdbcLocationRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java index c5d16d68..7a1a4841 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java @@ -25,10 +25,7 @@ public interface JdbcLocationRepository extends CrudRepository { Location findByLocationName(String locationName); + List findByLocationNameIn(Collection locationName); + List findByLocationIdIn(Collection locationId); - - List findByLocationNameInAndLocationPathContainingAndLevel(Collection locationName, - String locationPath, - Integer level); - } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 58d1ae82..0e182bf0 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 bdad94d4..97082d48 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/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 4a5bec2e..433838ca 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -126,7 +126,7 @@ class RouteApplicationTests { System.out.println(login); } - @Test +// @Test void arrayToStr(){ List ids = List.of(1L,2L,3L,4L); System.out.println(Arrays.toString(ids.toArray())); From e4ba73bbf1afde635cd4aa0eaa014cb52951be4d Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 13:32:13 +0800 Subject: [PATCH 16/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + .../infrastructure/repository/LocationRepositoryImpl.java | 4 +--- .../repository/jdbc/JdbcLocationRepository.java | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d15f09e8..9424ed41 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,7 @@ knife4j-spring-boot-starter 3.0.3 + diff --git a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java index 11dfb069..ebd2b9ae 100644 --- a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java @@ -85,8 +85,6 @@ public class LocationRepositoryImpl implements LocationRepository { @Override public List findHotCitiesByCityName(List locationNames) { - List hotCities = - jdbcLocationRepository.findByLocationNameInAndLocationPathContainingAndLevel(locationNames,"3106_1_",3); - return hotCities; + return jdbcLocationRepository.findByLocationNameInAndLocationPathContainingAndLevel(locationNames,"3106_1_",3); } } 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 7a1a4841..3cfdb05b 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java @@ -27,5 +27,7 @@ public interface JdbcLocationRepository extends CrudRepository { List findByLocationNameIn(Collection locationName); + List findByLocationNameInAndLocationPathContainingAndLevel(Collection locationName, String locationPath, Integer level) + List findByLocationIdIn(Collection locationId); } From faf24581d92bb126ab4aad8d6fda6cb78ff62b63 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 13:32:38 +0800 Subject: [PATCH 17/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/repository/jdbc/JdbcLocationRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3cfdb05b..4a265b1d 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java @@ -27,7 +27,7 @@ public interface JdbcLocationRepository extends CrudRepository { List findByLocationNameIn(Collection locationName); - List findByLocationNameInAndLocationPathContainingAndLevel(Collection locationName, String locationPath, Integer level) + List findByLocationNameInAndLocationPathContainingAndLevel(Collection locationName, String locationPath, Integer level); List findByLocationIdIn(Collection locationId); } From 5f6a7103f7628f4edacfe554b5ad5e37c20438c2 Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Thu, 29 Feb 2024 15:20:13 +0800 Subject: [PATCH 18/21] =?UTF-8?q?1.=E7=83=AD=E9=97=A8=E5=9F=8E=E5=B8=82?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=BF=A1=E6=81=AF=E6=B7=BB=E5=8A=A0=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E7=83=AD=E9=97=A8=E5=9F=8E=E5=B8=82=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dtos/HotCityResponseDto.java | 15 +++++++++++++ .../application/out/LocationController.java | 21 ++++++++++++++++-- .../aggregates/standards/HotCityTag.java | 22 ++++++++++++++++++- .../domain/repository/LocationRepository.java | 4 ++++ .../repository/LocationRepositoryImpl.java | 15 +++++++++++++ .../jdbc/JdbcLocationRepository.java | 8 ++++++- 6 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/chint/application/dtos/HotCityResponseDto.java 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/out/LocationController.java b/src/main/java/com/chint/application/out/LocationController.java index cd960083..c107d949 100644 --- a/src/main/java/com/chint/application/out/LocationController.java +++ b/src/main/java/com/chint/application/out/LocationController.java @@ -1,6 +1,7 @@ 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; @@ -64,7 +65,7 @@ public class LocationController { @ApiOperation("获取热门城市") @PostMapping("/getHotCities") - public Result> getHotCities() { + public Result getHotCities() { List city = HotCityTag.citys; @@ -77,7 +78,23 @@ public class LocationController { .stream() .map(location -> BeanUtil.copyProperties(location, LocationRes.class)).toList(); } - return Result.Success(SUCCESS, locationRes); + + + List internationalCitys = HotCityTag.internationalCitys; + List internationalLocationRes = null; + + List internationalLocations = locationRepository.findHotIntnationalCitiesByCityName(internationalCitys); + if (internationalLocations != null && !internationalLocations.isEmpty()) { + internationalLocationRes = internationalLocations + .stream() + .map(location -> BeanUtil.copyProperties(location, LocationRes.class)).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/domain/aggregates/standards/HotCityTag.java b/src/main/java/com/chint/domain/aggregates/standards/HotCityTag.java index 1995908b..c3a297ca 100644 --- a/src/main/java/com/chint/domain/aggregates/standards/HotCityTag.java +++ b/src/main/java/com/chint/domain/aggregates/standards/HotCityTag.java @@ -6,9 +6,10 @@ import java.util.List; public class HotCityTag { -// public static final HashMap cityMap; public static final List citys; + public static final List internationalCitys; + static { citys = new ArrayList<>(); @@ -24,6 +25,25 @@ public class HotCityTag { 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/repository/LocationRepository.java b/src/main/java/com/chint/domain/repository/LocationRepository.java index 3b330a1d..25cfa2e9 100644 --- a/src/main/java/com/chint/domain/repository/LocationRepository.java +++ b/src/main/java/com/chint/domain/repository/LocationRepository.java @@ -25,5 +25,9 @@ public interface LocationRepository { 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/infrastructure/repository/LocationRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java index ebd2b9ae..9bb51a57 100644 --- a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java @@ -87,4 +87,19 @@ public class LocationRepositoryImpl implements LocationRepository { 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/jdbc/JdbcLocationRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java index 4a265b1d..f289cd07 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java @@ -27,7 +27,13 @@ public interface JdbcLocationRepository extends CrudRepository { List findByLocationNameIn(Collection locationName); - List findByLocationNameInAndLocationPathContainingAndLevel(Collection locationName, String locationPath, Integer level); List findByLocationIdIn(Collection locationId); + + List findByLocationNameInAndLocationPathContainingAndLevel(Collection locationName, + String locationPath, + Integer level); + + List findByLocationPathNameInAndLevel(Collection locationPathName,Integer level); + } From bae2199a7ab0fcf74f00bcec46bb46859efd7fa5 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 15:33:39 +0800 Subject: [PATCH 19/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dtos/response/LocationRes.java | 13 ++++- .../application/out/LocationController.java | 4 +- .../application/out/LoginController.java | 2 +- .../aggregates/location/CityEntity.java | 13 +++++ .../constant/CTripConstant.java | 1 + .../repository/CityRepositoryImpl.java | 28 +++++++++- .../ctrip/CTripFlightCitySearchRequest.java | 54 +++++++++++++++++++ .../dto/city/FlightCitySearchRequest.java | 12 +++++ .../dto/city/FlightCitySearchResponse.java | 50 +++++++++++++++++ src/test/java/com/chint/CTripTest.java | 10 ++++ .../java/com/chint/RouteApplicationTests.java | 1 - 11 files changed, 181 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/chint/interfaces/rest/ctrip/CTripFlightCitySearchRequest.java create mode 100644 src/main/java/com/chint/interfaces/rest/ctrip/dto/city/FlightCitySearchRequest.java create mode 100644 src/main/java/com/chint/interfaces/rest/ctrip/dto/city/FlightCitySearchResponse.java 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/out/LocationController.java b/src/main/java/com/chint/application/out/LocationController.java index c107d949..9ff0a362 100644 --- a/src/main/java/com/chint/application/out/LocationController.java +++ b/src/main/java/com/chint/application/out/LocationController.java @@ -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(); diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index 8be57fe9..3b8c00a7 100644 --- a/src/main/java/com/chint/application/out/LoginController.java +++ b/src/main/java/com/chint/application/out/LoginController.java @@ -131,7 +131,7 @@ public class LoginController { return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } - @ApiOperation("商旅平台单点") + @ApiOperation("商旅平台移动端单点") @Transactional @PostMapping("/login/sso/mobile") public Result loginSSOMobile(@RequestBody UserLoginParam userLoginParam){ 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/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/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/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/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 433838ca..4562179d 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -130,6 +130,5 @@ class RouteApplicationTests { void arrayToStr(){ List ids = List.of(1L,2L,3L,4L); System.out.println(Arrays.toString(ids.toArray())); - } } From 69a42c9b5e30a906de16354f46a692e4245ef101 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 29 Feb 2024 15:47:59 +0800 Subject: [PATCH 20/21] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/chint/application/out/LocationController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chint/application/out/LocationController.java b/src/main/java/com/chint/application/out/LocationController.java index 9ff0a362..0cbdbef6 100644 --- a/src/main/java/com/chint/application/out/LocationController.java +++ b/src/main/java/com/chint/application/out/LocationController.java @@ -58,7 +58,7 @@ 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); } From cdad882e066c9d1c3a50e04a6167cdc4faf9e74a Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Thu, 29 Feb 2024 16:53:46 +0800 Subject: [PATCH 21/21] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=98=8E=E7=BB=86=E6=B7=BB=E5=8A=A0=E5=AD=97=E6=AE=B5=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E5=95=86=E5=93=81=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/chint/application/dtos/AuthenticationSignDto.java | 2 ++ .../java/com/chint/application/out/OrderDetailController.java | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chint/application/dtos/AuthenticationSignDto.java b/src/main/java/com/chint/application/dtos/AuthenticationSignDto.java index f0ab3dfe..b3872d5e 100644 --- a/src/main/java/com/chint/application/dtos/AuthenticationSignDto.java +++ b/src/main/java/com/chint/application/dtos/AuthenticationSignDto.java @@ -6,6 +6,8 @@ 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; diff --git a/src/main/java/com/chint/application/out/OrderDetailController.java b/src/main/java/com/chint/application/out/OrderDetailController.java index 768cd07e..7bec88be 100644 --- a/src/main/java/com/chint/application/out/OrderDetailController.java +++ b/src/main/java/com/chint/application/out/OrderDetailController.java @@ -64,13 +64,14 @@ public class OrderDetailController { @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(systemType + startTime + endTime + pageSize + pageNum); + String sign = Digest.md5(productType + systemType + startTime + endTime + pageSize + pageNum); System.out.println(sign);