From 933189384d5022b2324e40501f49caa5c66d649f Mon Sep 17 00:00:00 2001 From: lulz1 Date: Wed, 17 Apr 2024 13:57:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=A2=E5=8D=95=E5=9B=9E?= =?UTF-8?q?=E6=8E=A8=E7=9A=84=E5=8D=95=E5=8F=B7=E5=86=99=E5=8D=95=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../out/SupplierLoginController.java | 10 ++- .../queryies/OrderDetailQuery.java | 20 ++--- .../application/queryies/util/QueryUtil.java | 17 ++++ .../services/SupplierLoginService.java | 10 ++- .../aggregates/system/SystemAnnouncement.java | 1 - .../infrastructure/constant/AmapConstant.java | 4 +- .../OrderCarRecordRepositoryImpl.java | 2 + .../OrderFlightRecordRepositoryImpl.java | 4 +- .../OrderHotelRecordRepositoryImpl.java | 6 +- .../OrderTrainRecordRepositoryImpl.java | 2 + .../rest/amap/AmapLoginRequest.java | 12 +++ .../interfaces/rest/amap/AmapUserRequest.java | 71 +++++++++++---- .../rest/amap/BaseRequestParam.java | 15 ++++ .../rest/amap/dto/UserQueryResponse.java | 35 ++++++++ .../interfaces/rest/amap/util/ParamUtil.java | 89 +++++++++++++++++++ .../interfaces/rest/base/PostRequest.java | 64 +++---------- .../rest/base/dto/H5LoginResponse.java | 10 +++ .../rest/base/dto/PCLoginResponse.java | 10 +++ .../rest/ctrip/CTripLoginRequest.java | 18 ++-- .../rest/ctrip/dto/ResponseStatus.java | 2 - .../rest/user/UserHttpRequestImpl.java | 2 - src/test/java/com/chint/AmapTest.java | 24 +++-- src/test/java/com/chint/CTripTest.java | 3 +- src/test/java/com/chint/LYTest.java | 4 +- .../java/com/chint/RouteApplicationTests.java | 25 +++--- 25 files changed, 329 insertions(+), 131 deletions(-) create mode 100644 src/main/java/com/chint/application/queryies/util/QueryUtil.java create mode 100644 src/main/java/com/chint/interfaces/rest/amap/AmapLoginRequest.java create mode 100644 src/main/java/com/chint/interfaces/rest/amap/dto/UserQueryResponse.java create mode 100644 src/main/java/com/chint/interfaces/rest/amap/util/ParamUtil.java create mode 100644 src/main/java/com/chint/interfaces/rest/base/dto/H5LoginResponse.java create mode 100644 src/main/java/com/chint/interfaces/rest/base/dto/PCLoginResponse.java diff --git a/src/main/java/com/chint/application/out/SupplierLoginController.java b/src/main/java/com/chint/application/out/SupplierLoginController.java index 74a8fe4b..39341740 100644 --- a/src/main/java/com/chint/application/out/SupplierLoginController.java +++ b/src/main/java/com/chint/application/out/SupplierLoginController.java @@ -4,6 +4,8 @@ package com.chint.application.out; import com.chint.application.dtos.SupplierLoginParam; import com.chint.application.services.SupplierLoginService; import com.chint.infrastructure.util.Result; +import com.chint.interfaces.rest.base.dto.H5LoginResponse; +import com.chint.interfaces.rest.base.dto.PCLoginResponse; import com.chint.interfaces.rest.ctrip.dto.login.H5Response; import com.chint.interfaces.rest.ctrip.dto.login.PCResponse; import com.chint.interfaces.rest.ly.dto.login.LYRedirectUrlResponse; @@ -41,26 +43,26 @@ public class SupplierLoginController { @ApiOperation("单点登录携程-移动") @PostMapping("/CTrip/login") - public Result cTripLogin(@RequestBody SupplierLoginParam supplierLoginParam) { + public Result cTripLogin(@RequestBody SupplierLoginParam supplierLoginParam) { return Result.Success(SUCCESS, supplierLoginService.cTripLogin(supplierLoginParam)); } @ApiOperation("单点登录携程-PC") @PostMapping("/CTrip/login/pc") - public Result cTripLoginPC(@RequestBody SupplierLoginParam supplierLoginParam) { + public Result cTripLoginPC(@RequestBody SupplierLoginParam supplierLoginParam) { return Result.Success(SUCCESS, supplierLoginService.cTripLoginPC(supplierLoginParam)); } @ApiOperation("单点登录携程-移动-Html") @PostMapping("/CTrip/login/ht") - public Result cTripLoginHtml(@RequestBody SupplierLoginParam supplierLoginParam) { + public Result cTripLoginHtml(@RequestBody SupplierLoginParam supplierLoginParam) { return Result.Success(SUCCESS, supplierLoginService.cTripLoginHtml(supplierLoginParam)); } @ApiOperation("单点登录携程-PC-Html") @PostMapping("/CTrip/login/pc/ht") - public Result cTripLoginPCHtml(@RequestBody SupplierLoginParam supplierLoginParam) { + public Result cTripLoginPCHtml(@RequestBody SupplierLoginParam supplierLoginParam) { return Result.Success(SUCCESS, supplierLoginService.cTripLoginPCHtml(supplierLoginParam)); } diff --git a/src/main/java/com/chint/application/queryies/OrderDetailQuery.java b/src/main/java/com/chint/application/queryies/OrderDetailQuery.java index 2e8bb384..d5892990 100644 --- a/src/main/java/com/chint/application/queryies/OrderDetailQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderDetailQuery.java @@ -18,7 +18,6 @@ import com.chint.interfaces.rest.bpm.dto.orderdetail.FlightOrderDetailDto; import com.chint.interfaces.rest.bpm.dto.orderdetail.HotelOrderDetailDto; import com.chint.interfaces.rest.bpm.dto.orderdetail.TrainOrderDetailDto; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.stereotype.Component; import java.time.LocalDateTime; @@ -26,9 +25,9 @@ import java.time.format.DateTimeFormatter; import java.util.Comparator; import java.util.List; import java.util.Objects; -import java.util.StringJoiner; import java.util.stream.Stream; +import static com.chint.application.queryies.util.QueryUtil.reGetReceiptsNum; import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; import static com.chint.infrastructure.constant.FSSCConstant.FSSC_ORDER_STATUS_CANCEL; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_L_Y; @@ -107,7 +106,7 @@ public class OrderDetailQuery { String receiptsNum = hotelOrderDetail.getReceiptsNum(); if (receiptsNum != null) { - hotelOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum)); + hotelOrderDetail.setReceiptsNum(reGetReceiptsNum(receiptsNum)); } // 仅当订单是“临时订单数据”时,不加入结果列表 if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y) && @@ -137,7 +136,7 @@ public class OrderDetailQuery { String receiptsNum = trainOrderDetail.getReceiptsNum(); if (receiptsNum != null) { - trainOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum)); + trainOrderDetail.setReceiptsNum(reGetReceiptsNum(receiptsNum)); } TrainOrderDetailDto orderDetailDto = TrainOrderDetailDto.copyFrom(trainOrderDetail); RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId()); @@ -168,7 +167,7 @@ public class OrderDetailQuery { String receiptsNum = carOrderDetail.getReceiptsNum(); if (receiptsNum != null) { - carOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum)); + carOrderDetail.setReceiptsNum(reGetReceiptsNum(receiptsNum)); } //如果订单的状态处于开始时间有, 结束时间无的状态 ,那么该订单处于进行中,暂时返回null @@ -198,7 +197,7 @@ public class OrderDetailQuery { String receiptsNum = flightOrderDetail.getReceiptsNum(); if (receiptsNum != null) { - flightOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum)); + flightOrderDetail.setReceiptsNum(reGetReceiptsNum(receiptsNum)); } FlightOrderDetailDto orderDetailDto = FlightOrderDetailDto.copyFrom(flightOrderDetail); @@ -243,12 +242,5 @@ public class OrderDetailQuery { return new PageResult<>(total, OrderDetailResList); } - private String regetReceiptsNum(String receiptsNum) { - if (receiptsNum.contains("-")) { - String[] parts = receiptsNum.split("-"); - return parts[1]; - } else { - return receiptsNum; - } - } + } diff --git a/src/main/java/com/chint/application/queryies/util/QueryUtil.java b/src/main/java/com/chint/application/queryies/util/QueryUtil.java new file mode 100644 index 00000000..87db7cb3 --- /dev/null +++ b/src/main/java/com/chint/application/queryies/util/QueryUtil.java @@ -0,0 +1,17 @@ +package com.chint.application.queryies.util; + +public class QueryUtil { + + public static String reGetReceiptsNum(String receiptsNum) { + if (receiptsNum.contains("-")) { + String[] split = receiptsNum.split("-"); + receiptsNum = split[1]; + } + if(receiptsNum.contains("#")){ + String[] split1 = receiptsNum.split("#"); + receiptsNum = split1[0]; + } + return receiptsNum; + } + +} diff --git a/src/main/java/com/chint/application/services/SupplierLoginService.java b/src/main/java/com/chint/application/services/SupplierLoginService.java index b2e8bcf7..cb4630e0 100644 --- a/src/main/java/com/chint/application/services/SupplierLoginService.java +++ b/src/main/java/com/chint/application/services/SupplierLoginService.java @@ -5,6 +5,8 @@ import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.RouteRepository; import com.chint.infrastructure.util.BaseContext; +import com.chint.interfaces.rest.base.dto.H5LoginResponse; +import com.chint.interfaces.rest.base.dto.PCLoginResponse; import com.chint.interfaces.rest.ctrip.CTripLoginRequest; import com.chint.interfaces.rest.ctrip.dto.login.H5Response; import com.chint.interfaces.rest.ctrip.dto.login.PCResponse; @@ -38,19 +40,19 @@ public class SupplierLoginService { return lyLoginRequest.loginPC(L_Y_ENTRANCE_HOME, getEmployeeNo(supplierLoginParam.getRouteId())); } - public H5Response cTripLogin(SupplierLoginParam supplierLoginParam) { + public H5LoginResponse cTripLogin(SupplierLoginParam supplierLoginParam) { return cTripLoginRequest.hSingleLogin(getEmployeeNo(supplierLoginParam.getRouteId())); } - public PCResponse cTripLoginPC(SupplierLoginParam supplierLoginParam) { + public PCLoginResponse cTripLoginPC(SupplierLoginParam supplierLoginParam) { return cTripLoginRequest.authLogin(getEmployeeNo(supplierLoginParam.getRouteId())); } - public H5Response cTripLoginHtml(SupplierLoginParam supplierLoginParam) { + public H5LoginResponse cTripLoginHtml(SupplierLoginParam supplierLoginParam) { return cTripLoginRequest.hSingleLoginHtml(getEmployeeNo(supplierLoginParam.getRouteId())); } - public PCResponse cTripLoginPCHtml(SupplierLoginParam supplierLoginParam) { + public PCLoginResponse cTripLoginPCHtml(SupplierLoginParam supplierLoginParam) { return cTripLoginRequest.authLoginHtml(getEmployeeNo(supplierLoginParam.getRouteId())); } diff --git a/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java b/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java index eabb9238..4c3e916c 100644 --- a/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java +++ b/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java @@ -71,7 +71,6 @@ public class SystemAnnouncement implements Serializable { if (expiryDate.isBefore(LocalDateTime.now())) { this.setStatus("0"); } - return this; } diff --git a/src/main/java/com/chint/infrastructure/constant/AmapConstant.java b/src/main/java/com/chint/infrastructure/constant/AmapConstant.java index 7482065c..9fed6c26 100644 --- a/src/main/java/com/chint/infrastructure/constant/AmapConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/AmapConstant.java @@ -2,8 +2,8 @@ package com.chint.infrastructure.constant; public class AmapConstant { public static final String USER_CREATE_PATH = "/ws/boss/enterprise/openapi/employee/create"; - public static final String USER_UPDATE_PATH = "/ws/boss/enterprise/openapi/employee/query"; - public static final String USER_QUERY_PATH = "/ws/boss/enterprise/openapi/employee/update"; + public static final String USER_UPDATE_PATH = "/ws/boss/enterprise/openapi/employee/update"; + public static final String USER_QUERY_PATH = "/ws/boss/enterprise/openapi/employee/query"; public static final String USER_DELETE_PATH = "/ws/boss/enterprise/openapi/employee/delete"; //token地址 diff --git a/src/main/java/com/chint/infrastructure/repository/OrderCarRecordRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/OrderCarRecordRepositoryImpl.java index b241e644..a318990e 100644 --- a/src/main/java/com/chint/infrastructure/repository/OrderCarRecordRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/OrderCarRecordRepositoryImpl.java @@ -1,6 +1,7 @@ package com.chint.infrastructure.repository; import com.chint.application.dtos.OrderRecordQueryDTO; +import com.chint.application.queryies.util.QueryUtil; import com.chint.domain.aggregates.order.order_record.OrderCarRecord; import com.chint.domain.repository.OrderCarRecordRepository; import com.chint.infrastructure.repository.jdbc.JdbcOrderCarRecordRepository; @@ -142,6 +143,7 @@ public class OrderCarRecordRepositoryImpl implements OrderCarRecordRepository { record.setBelongDepart(rs.getString("belong_depart")); return record; }); + orderCarRecords.forEach(it->it.setReceiptsNum(QueryUtil.reGetReceiptsNum(it.getReceiptsNum()))); return PageResult.totalPageNum(totalRecords == null ? 0 : totalRecords, orderCarRecords); } } diff --git a/src/main/java/com/chint/infrastructure/repository/OrderFlightRecordRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/OrderFlightRecordRepositoryImpl.java index bddd787b..6eae871b 100644 --- a/src/main/java/com/chint/infrastructure/repository/OrderFlightRecordRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/OrderFlightRecordRepositoryImpl.java @@ -1,6 +1,7 @@ package com.chint.infrastructure.repository; import com.chint.application.dtos.OrderRecordQueryDTO; +import com.chint.application.queryies.util.QueryUtil; import com.chint.domain.aggregates.order.order_record.OrderFlightRecord; import com.chint.domain.repository.OrderFlightRecordRepository; import com.chint.infrastructure.repository.jdbc.JdbcOrderFlightRecordRepository; @@ -73,7 +74,7 @@ public class OrderFlightRecordRepositoryImpl implements OrderFlightRecordReposit public PageResult findByRecordParam(OrderRecordQueryDTO queryDTO) { StringJoiner whereClause = new StringJoiner(" AND ", " WHERE ", ""); MapSqlParameterSource parameters = new MapSqlParameterSource(); - loadQuerySql(whereClause,parameters,queryDTO); + loadQuerySql(whereClause, parameters, queryDTO); // 计算OFFSET(跳过的行数) int offset = (queryDTO.getPageNum() - 1) * queryDTO.getPageSize(); String sql = "SELECT * FROM order_flight_record" + whereClause + " ORDER BY detail_id ASC LIMIT :limit OFFSET :offset"; @@ -155,6 +156,7 @@ public class OrderFlightRecordRepositoryImpl implements OrderFlightRecordReposit record.setBelongDepart(rs.getString("belong_depart")); return record; }); + orderFlightRecords.forEach(it->it.setReceiptsNum(QueryUtil.reGetReceiptsNum(it.getReceiptsNum()))); return PageResult.totalPageNum(totalRecords == null ? 0 : totalRecords, orderFlightRecords); } } diff --git a/src/main/java/com/chint/infrastructure/repository/OrderHotelRecordRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/OrderHotelRecordRepositoryImpl.java index fed3ac0c..a46bdb84 100644 --- a/src/main/java/com/chint/infrastructure/repository/OrderHotelRecordRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/OrderHotelRecordRepositoryImpl.java @@ -1,6 +1,7 @@ package com.chint.infrastructure.repository; import com.chint.application.dtos.OrderRecordQueryDTO; +import com.chint.application.queryies.util.QueryUtil; import com.chint.domain.aggregates.order.order_record.OrderFlightRecord; import com.chint.domain.aggregates.order.order_record.OrderHotelRecord; import com.chint.domain.repository.OrderHotelRecordRepository; @@ -85,7 +86,7 @@ public class OrderHotelRecordRepositoryImpl implements OrderHotelRecordRepositor String countSql = "SELECT COUNT(*) FROM order_hotel_record" + whereClause; Integer totalRecords = jdbcTemplate.queryForObject(countSql, parameters, Integer.class); - List orderFlightRecords = jdbcTemplate.query(sql, parameters, (rs, rowNum) -> { + List orderHotelRecords = jdbcTemplate.query(sql, parameters, (rs, rowNum) -> { OrderHotelRecord record = new OrderHotelRecord(); // 基本类型 record.setId(rs.getLong("id")); @@ -154,6 +155,7 @@ public class OrderHotelRecordRepositoryImpl implements OrderHotelRecordRepositor record.setBelongDepart(rs.getString("belong_depart")); return record; }); - return PageResult.totalPageNum(totalRecords == null ? 0 : totalRecords, orderFlightRecords); + orderHotelRecords.forEach(it->it.setReceiptsNum(QueryUtil.reGetReceiptsNum(it.getReceiptsNum()))); + return PageResult.totalPageNum(totalRecords == null ? 0 : totalRecords, orderHotelRecords); } } diff --git a/src/main/java/com/chint/infrastructure/repository/OrderTrainRecordRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/OrderTrainRecordRepositoryImpl.java index 08679b4d..14e5dad9 100644 --- a/src/main/java/com/chint/infrastructure/repository/OrderTrainRecordRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/OrderTrainRecordRepositoryImpl.java @@ -1,6 +1,7 @@ package com.chint.infrastructure.repository; import com.chint.application.dtos.OrderRecordQueryDTO; +import com.chint.application.queryies.util.QueryUtil; import com.chint.domain.aggregates.order.order_record.OrderHotelRecord; import com.chint.domain.aggregates.order.order_record.OrderTrainRecord; import com.chint.domain.repository.OrderTrainRecordRepository; @@ -151,6 +152,7 @@ public class OrderTrainRecordRepositoryImpl implements OrderTrainRecordRepositor record.setBelongDepart(rs.getString("belong_depart")); return record; }); + orderTrainRecords.forEach(it->it.setReceiptsNum(QueryUtil.reGetReceiptsNum(it.getReceiptsNum()))); return PageResult.totalPageNum(totalRecords == null ? 0 : totalRecords, orderTrainRecords); } } diff --git a/src/main/java/com/chint/interfaces/rest/amap/AmapLoginRequest.java b/src/main/java/com/chint/interfaces/rest/amap/AmapLoginRequest.java new file mode 100644 index 00000000..60e5bcf5 --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/amap/AmapLoginRequest.java @@ -0,0 +1,12 @@ +package com.chint.interfaces.rest.amap; + +import com.chint.interfaces.rest.amap.request.TokenRequest; +import org.springframework.stereotype.Component; + +@Component +public class AmapLoginRequest { + + private TokenRequest tokenRequest; + + +} diff --git a/src/main/java/com/chint/interfaces/rest/amap/AmapUserRequest.java b/src/main/java/com/chint/interfaces/rest/amap/AmapUserRequest.java index fbcf2f17..e738cc75 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/AmapUserRequest.java +++ b/src/main/java/com/chint/interfaces/rest/amap/AmapUserRequest.java @@ -2,20 +2,23 @@ package com.chint.interfaces.rest.amap; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.UserNameRepository; -import com.chint.interfaces.rest.base.PostRequest; +import com.chint.interfaces.rest.amap.dto.UserQueryResponse; +import com.chint.interfaces.rest.amap.request.AmapRequest; import com.chint.interfaces.rest.user.UserHttpRequest; import lombok.Data; 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.AmapConstant.USER_CREATE_PATH; +import java.util.List; + +import static com.chint.infrastructure.constant.AmapConstant.*; @Component public class AmapUserRequest { @Autowired - private PostRequest postRequest; + private AmapRequest amapRequest; @Autowired private UserNameRepository userNameRepository; @@ -23,25 +26,38 @@ public class AmapUserRequest { @Autowired private UserHttpRequest userHttpRequest; - //应用ID - @Value("${amap.appId}") - private String appId; - - @Value("${amap.eId}") - private String eId; @Value("${amap.baseUrl}") private String BaseUrl; - @Value("${amap.signKey}") - private String signKey; + public BaseResponse syncUser(User user) { + UserQueryResponse userQueryResponse = queryUser(user); + List data = userQueryResponse.getData(); + if (data == null || data.isEmpty()) { + return createUser(user); + } else { + return updateUser(user); + } + } public BaseResponse createUser(User user) { String createUserUrl = BaseUrl + USER_CREATE_PATH; - BaseRequestParam baseRequestParam = createUserParamByUser(user).generateSign(signKey); - return postRequest.postSend(createUserUrl, baseRequestParam, BaseResponse.class); + BaseRequestParam baseRequestParam = createUserParamByUser(user); + return amapRequest.post(createUserUrl, baseRequestParam, BaseResponse.class); } + public UserQueryResponse queryUser(User user) { + String queryUserUrl = BaseUrl + USER_QUERY_PATH; + UserQueryParam userQueryParam = new UserQueryParam(); + userQueryParam.setUserId(user.getEmployeeNo()); + return amapRequest.post(queryUserUrl, userQueryParam, UserQueryResponse.class); + } + + public BaseResponse updateUser(User user) { + String updateUserUrl = BaseUrl + USER_UPDATE_PATH; + BaseRequestParam baseRequestParam = createUserParamByUser(user); + return amapRequest.post(updateUserUrl, baseRequestParam, BaseResponse.class); + } @Data public static class UserParam extends BaseRequestParam { @@ -61,12 +77,33 @@ public class AmapUserRequest { private String projectIdList; } + @Data + public static class UserQueryParam extends BaseRequestParam { + private String userId; // 用户Id + private String mobile; // 手机号 + } + + @Data + public static class UserInfo extends BaseRequestParam { + private UserInfo userInfo; + private String userId; // 用户Id + private String mobile; // 手机号 + // The rest of the fields as defined in your request body image + private String cardId; + private String realName; + private String departmentId; + private String immediateSuperiorUserId; + private String email; + private Integer status; + private String extInfo; + private String baseAdCode; + private String employeeGroupName; + private String regulationList; + private String projectIdList; + } + public UserParam createUserParamByUser(User user) { UserParam userParam = new UserParam(); - userParam.setAppId(appId); - userParam.setEnt(4); - userParam.setTimestamp(String.valueOf(System.currentTimeMillis())); - userParam.setEid(eId); userParam.setUserId(user.getEmployeeNo()); userParam.setEmail(user.getEmail()); userParam.setMobile(user.getPhoneNumber()); diff --git a/src/main/java/com/chint/interfaces/rest/amap/BaseRequestParam.java b/src/main/java/com/chint/interfaces/rest/amap/BaseRequestParam.java index b86842f6..319fd9ad 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/BaseRequestParam.java +++ b/src/main/java/com/chint/interfaces/rest/amap/BaseRequestParam.java @@ -3,6 +3,9 @@ package com.chint.interfaces.rest.amap; import com.chint.infrastructure.util.SignUtils; import lombok.Data; +import java.time.LocalDateTime; +import java.time.ZoneId; + @Data public class BaseRequestParam { // 应用ID,根据业务场景填写 @@ -16,6 +19,18 @@ public class BaseRequestParam { // 时间戳,标记请求发送时间 private String timestamp; + public BaseRequestParam generateSign(String appId, Integer eid, Integer ent, String signKey) { + this.appId = appId; + this.timestamp = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toString(); + try { + String sign = SignUtils.generateSignature(this, signKey); + this.sign = sign; + return this; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + public BaseRequestParam generateSign(String signKey) { try { String sign = SignUtils.generateSignature(this, signKey); diff --git a/src/main/java/com/chint/interfaces/rest/amap/dto/UserQueryResponse.java b/src/main/java/com/chint/interfaces/rest/amap/dto/UserQueryResponse.java new file mode 100644 index 00000000..9486a514 --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/amap/dto/UserQueryResponse.java @@ -0,0 +1,35 @@ +package com.chint.interfaces.rest.amap.dto; + +import lombok.Data; + +import java.util.List; + +@Data +public class UserQueryResponse { + public Boolean result; + public String traceId; + public Integer code; + public List data; + public String message; + public String version; + public Long timestamp; + + @lombok.Data + public static class UserDate { + public String baseAdCode; + public String baseCityName; + public String departmentId; + public Integer eid; + public String email; + public String employeeGroupCode; + public String extInfo; + public Integer gdUserId; + public String immediateSuperiorUserId; + public String mobile; + public String realName; + public List regulationIdList; + public String remark; + public Integer totalQuota; + public String userId; + } +} diff --git a/src/main/java/com/chint/interfaces/rest/amap/util/ParamUtil.java b/src/main/java/com/chint/interfaces/rest/amap/util/ParamUtil.java new file mode 100644 index 00000000..66833f5e --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/amap/util/ParamUtil.java @@ -0,0 +1,89 @@ +package com.chint.interfaces.rest.amap.util; + +import com.chint.interfaces.rest.amap.BaseRequestParam; +import com.google.common.base.Charsets; +import com.google.common.hash.Hashing; +import com.google.gson.Gson; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.message.BasicNameValuePair; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.StringJoiner; + +public class ParamUtil { + + private final static Gson gson = new Gson(); + + public static UrlEncodedFormEntity convertObjectToUrlEncodedFormEntity(BaseRequestParam obj, String charset, String signKey) throws Exception { + List formParams = new ArrayList<>(); + Class clazz = obj.getClass(); + Class superclass = clazz.getSuperclass(); + Field[] declaredFields = superclass.getDeclaredFields(); + Field[] fields = clazz.getDeclaredFields(); + + // 创建一个新数组,长度为两个原始数组长度之和 + Field[] combinedArray = new Field[declaredFields.length + fields.length]; + + // 复制第一个数组到新数组 + System.arraycopy(declaredFields, 0, combinedArray, 0, declaredFields.length); + // 复制第二个数组到新数组,开始位置是第一个数组长度 + System.arraycopy(fields, 0, combinedArray, declaredFields.length, fields.length); + + for (Field field : combinedArray) { + try { + field.setAccessible(true); + Object value = field.get(obj); + if (value != null) { + // 检查字段类型是否为基本类型或字符串 + if (isPrimitiveOrWrapper(value.getClass()) || value instanceof String) { + formParams.add(new BasicNameValuePair(field.getName(), value.toString())); + } else { + // 将复杂类型对象转换为JSON字符串 + String json = gson.toJson(value); + formParams.add(new BasicNameValuePair(field.getName(), json)); + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + StringJoiner joiner = new StringJoiner("&"); + List fieldList = Arrays.asList(fields); + for (Field field : fieldList) { + field.setAccessible(true); + String fieldName = field.getName(); + String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); + Method method; + try { + method = clazz.getMethod(methodName); + } catch (NoSuchMethodException e) { + continue; // If there's no getter method, skip this field + } + Object value = method.invoke(obj); + if (value != null && !fieldName.equals("sign")) { // Skip the 'sign' field + joiner.add(fieldName + "=" + value); + } + } + + String res = joiner + "@" + signKey; + String sign = Hashing.md5().hashString(res, Charsets.UTF_8).toString().toUpperCase(); + formParams.add(new BasicNameValuePair("sign", sign)); + try { + return new UrlEncodedFormEntity(formParams, charset); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + private static boolean isPrimitiveOrWrapper(Class type) { + return type.isPrimitive() || type == Double.class || type == Float.class || type == Long.class || + type == Integer.class || type == Short.class || type == Character.class || type == Byte.class || + type == Boolean.class || type == String.class; + } +} diff --git a/src/main/java/com/chint/interfaces/rest/base/PostRequest.java b/src/main/java/com/chint/interfaces/rest/base/PostRequest.java index a7e22e3b..5ad41d8a 100644 --- a/src/main/java/com/chint/interfaces/rest/base/PostRequest.java +++ b/src/main/java/com/chint/interfaces/rest/base/PostRequest.java @@ -52,38 +52,23 @@ public class PostRequest { String json = gson.toJson(jsonRequest); log.info(json); post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); - String responseBody = null; - HttpEntity responseEntity = null; - HttpResponse response = null; - try { - response = client.execute(post); - responseEntity = response.getEntity(); - responseBody = EntityUtils.toString(responseEntity, "UTF-8"); - log.info(responseBody); - } catch (IOException e) { - throw new RuntimeException(e); - } - return gson.fromJson(responseBody, responseType); + return post(post, responseType); } + public T post(String url, UrlEncodedFormEntity entity, Class responseType) { + HttpPost post = new HttpPost(url); + post.setEntity(entity); + return post(post, responseType); + } + + public T post(String headName, String headValue, String url, Object jsonRequest, Class responseType) { HttpPost post = new HttpPost(url); post.addHeader(headName, headValue); String json = gson.toJson(jsonRequest); log.info(json); post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); - String responseBody = null; - HttpEntity responseEntity = null; - HttpResponse response = null; - try { - response = client.execute(post); - responseEntity = response.getEntity(); - responseBody = EntityUtils.toString(responseEntity, "UTF-8"); - log.info(responseBody); - } catch (IOException e) { - throw new RuntimeException(e); - } - return gson.fromJson(responseBody, responseType); + return post(post, responseType); } public T post(HttpPost post, Class responseType) { @@ -196,41 +181,19 @@ public class PostRequest { public T postANBPM(String url, Object jsonRequest, Class responseType) { HttpPost post = new HttpPost(url); - String json = JSON.toJSONString(jsonRequest); + String json = gson.toJson(jsonRequest); log.info(json); post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); - String responseBody = null; - HttpEntity responseEntity = null; - HttpResponse response = null; - try { - response = client.execute(post); - responseEntity = response.getEntity(); - responseBody = EntityUtils.toString(responseEntity, "UTF-8"); - log.info(responseBody); - } catch (IOException e) { - throw new RuntimeException(e); - } - return gson.fromJson(responseBody, responseType); + return post(post, responseType); } public T postJSON(String url, Object jsonRequest, Class responseType) { HttpPost post = new HttpPost(url); - String json = JSON.toJSONString(jsonRequest); + String json = gson.toJson(jsonRequest); log.info(json); post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); - String responseBody = null; - HttpEntity responseEntity = null; - HttpResponse response = null; - try { - response = client.execute(post); - responseEntity = response.getEntity(); - responseBody = EntityUtils.toString(responseEntity, "UTF-8"); - log.info(responseBody); - } catch (IOException e) { - throw new RuntimeException(e); - } - return JSON.parseObject(responseBody, responseType); + return post(post, responseType); } public Gson gson() { @@ -241,7 +204,6 @@ public class PostRequest { return client; } - public String getReDirectUrl(String url) { CloseableHttpClient client = HttpClients.createDefault(); diff --git a/src/main/java/com/chint/interfaces/rest/base/dto/H5LoginResponse.java b/src/main/java/com/chint/interfaces/rest/base/dto/H5LoginResponse.java new file mode 100644 index 00000000..5f7efd49 --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/base/dto/H5LoginResponse.java @@ -0,0 +1,10 @@ +package com.chint.interfaces.rest.base.dto; + +import lombok.Data; + +@Data +public class H5LoginResponse { + private String redirectUrl; + private String htmlContent; + private boolean success; +} diff --git a/src/main/java/com/chint/interfaces/rest/base/dto/PCLoginResponse.java b/src/main/java/com/chint/interfaces/rest/base/dto/PCLoginResponse.java new file mode 100644 index 00000000..e5f8f160 --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/base/dto/PCLoginResponse.java @@ -0,0 +1,10 @@ +package com.chint.interfaces.rest.base.dto; + +import lombok.Data; + +@Data +public class PCLoginResponse { + private String redirectUrl; + private String htmlContent; + private boolean success; +} diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/CTripLoginRequest.java b/src/main/java/com/chint/interfaces/rest/ctrip/CTripLoginRequest.java index 59ec0600..60c6d8d2 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/CTripLoginRequest.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/CTripLoginRequest.java @@ -7,6 +7,8 @@ import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.Digest; import com.chint.interfaces.rest.base.PostRequest; +import com.chint.interfaces.rest.base.dto.H5LoginResponse; +import com.chint.interfaces.rest.base.dto.PCLoginResponse; import com.chint.interfaces.rest.ctrip.dto.login.*; import jakarta.annotation.PostConstruct; import org.apache.commons.lang3.StringUtils; @@ -100,9 +102,9 @@ public class CTripLoginRequest { return postRequest.post(loginUrl + IDPEntityID, loginParam, String.class); } - public PCResponse authLoginHtml(String employeeNo) { + public PCLoginResponse authLoginHtml(String employeeNo) { String html = cTripPCLoginRequest(employeeNo); - PCResponse pcResponse = new PCResponse(); + PCLoginResponse pcResponse = new PCLoginResponse(); pcResponse.setHtmlContent(html); String url = getPCUrlFromHtml(html); pcResponse.setSuccess(true); @@ -110,10 +112,10 @@ public class CTripLoginRequest { return pcResponse; } - public PCResponse authLogin(String employeeNo) { + public PCLoginResponse authLogin(String employeeNo) { String body = cTripPCLoginRequest(employeeNo); String url = getPCUrlFromHtml(body); - PCResponse pcResponse = new PCResponse(); + PCLoginResponse pcResponse = new PCLoginResponse(); pcResponse.setRedirectUrl(url); pcResponse.setSuccess(true); return pcResponse; @@ -185,19 +187,19 @@ public class CTripLoginRequest { return h5TokenResponse.getToken(); } - public H5Response hSingleLoginHtml(String employeeNo){ + public H5LoginResponse hSingleLoginHtml(String employeeNo){ String html = cTripLoginRequest(employeeNo); String url = getUrlFromHtml(cTripLoginRequest(employeeNo)); - H5Response h5Response = new H5Response(); + H5LoginResponse h5Response = new H5LoginResponse(); h5Response.setSuccess(true); h5Response.setHtmlContent(html); h5Response.setRedirectUrl(url); return h5Response; } - public H5Response hSingleLogin(String employeeNo) { + public H5LoginResponse hSingleLogin(String employeeNo) { String url = getUrlFromHtml(cTripLoginRequest(employeeNo)); - H5Response h5Response = new H5Response(); + H5LoginResponse h5Response = new H5LoginResponse(); h5Response.setSuccess(true); h5Response.setRedirectUrl(url); return h5Response; diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/dto/ResponseStatus.java b/src/main/java/com/chint/interfaces/rest/ctrip/dto/ResponseStatus.java index 4f72ab89..8e725cc9 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/dto/ResponseStatus.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/dto/ResponseStatus.java @@ -7,6 +7,4 @@ public class ResponseStatus { private Boolean Success; private int ErrorCode; private String Message; - - // Constructors, getters, and setters } \ No newline at end of file diff --git a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java index fd02710d..d906f512 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -281,8 +281,6 @@ public class UserHttpRequestImpl implements UserHttpRequest { public String belongDeport(String employeeNo, String accountCompanyName) { User user = userRepository.findByUserEmployeeNo(employeeNo); - - if (user == null) { user = loadUserBaseInfo(User.withEmployeeNo(employeeNo)); if (user == null) { diff --git a/src/test/java/com/chint/AmapTest.java b/src/test/java/com/chint/AmapTest.java index 24944f90..91798be3 100644 --- a/src/test/java/com/chint/AmapTest.java +++ b/src/test/java/com/chint/AmapTest.java @@ -3,10 +3,8 @@ package com.chint; import com.chint.domain.aggregates.user.User; import com.chint.interfaces.rest.amap.AmapUserRequest; import com.chint.interfaces.rest.amap.BaseResponse; -import com.chint.interfaces.rest.amap.dto.detail.OrderDetailResponse; -import com.chint.interfaces.rest.amap.dto.token.TokenDto; -import com.chint.interfaces.rest.amap.dto.token.TokenResponse; -import com.chint.interfaces.rest.amap.request.OrderDetailRequest; +import com.chint.interfaces.rest.amap.token.TokenDto; +import com.chint.interfaces.rest.amap.token.TokenResponse; import com.chint.interfaces.rest.amap.request.TokenRequest; import com.google.gson.Gson; import org.junit.jupiter.api.Test; @@ -21,15 +19,27 @@ public class AmapTest { private Gson gson = new Gson(); - private User user = new User(1L, "230615020", 1, "卢麟哲", "1033719135@qq.com", "15857193365", "A30000001"); + private User user = new User(1L, "230615020", 1, "卢麟哲", "lulz1@chint.com", "15857193365", "A30000001"); -// @Test + @Test public void createUser(){ BaseResponse baseResponse = amapUserRequest.createUser(user); System.out.println(gson.toJson(baseResponse)); } - + @Test + public void queryUser(){ + UserQueryResponse userQueryResponse = amapUserRequest.queryUser(user); + System.out.println(gson.toJson(userQueryResponse)); + } + + @Test + public void updateUser(){ + BaseResponse baseResponse = amapUserRequest.updateUser(user); + System.out.println(gson.toJson(baseResponse)); + } + + @Autowired private TokenRequest tokenRequest; diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 395c2091..2cb3bb42 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -18,6 +18,7 @@ import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.Digest; import com.chint.infrastructure.util.PinyinUtil; import com.chint.interfaces.rest.base.PostRequest; +import com.chint.interfaces.rest.base.dto.PCLoginResponse; import com.chint.interfaces.rest.ctrip.*; import com.chint.interfaces.rest.ctrip.dto.city.FlightCitySearchResponse; import com.chint.interfaces.rest.ctrip.dto.country.CountryResponse; @@ -181,7 +182,7 @@ public class CTripTest { //@Test void authLogin() { BaseContext.setCurrentUser(user); - PCResponse response = loginRequest.authLogin(null); + PCLoginResponse response = loginRequest.authLogin(null); System.out.println(response.getRedirectUrl()); } diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index ac6f9743..7ffb3489 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -821,9 +821,9 @@ public class LYTest { System.out.println(json); } - // @Test + @Test void searchTrain() { - TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24032768188401512"); + TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24033168626574219"); Gson gson = new Gson(); String json = gson.toJson(trainOrderDetail); System.out.println(json); diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 6a38834b..49aaa80b 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -280,7 +280,7 @@ class RouteApplicationTests { // @Test void loginSignProd() { - String sfno = "240412063"; + String sfno = "231008023"; String syscode = "FSSC"; String billcode = "CLSQ240225000099"; String companycode = "正泰集团股份有限公司"; @@ -347,7 +347,7 @@ class RouteApplicationTests { System.out.println(Arrays.toString(ids.toArray())); } - // @Test + @Test void deleteRouteByEmployeeNo() { List byEmployeeNo = routeRepository.findByEmployeeNo("230615020"); for (RouteOrder routeOrder : byEmployeeNo) { @@ -1259,18 +1259,17 @@ class RouteApplicationTests { System.out.println(lastMonthStr()); } -// @Test + @Test void testsplit2(){ - String inputOrderNo = "FSSC-CLSQ240409000001dev#NBWSAW"; - String orderNo = null; - if (inputOrderNo.contains("-")) { - String[] split = inputOrderNo.split("-"); - orderNo = split[1]; - if(orderNo.contains("#")){ - String[] split1 = orderNo.split("#"); - orderNo = split1[0]; - } + String receiptsNum = "FSSC-CLSQ240409000001dev#NBWSAW"; + if (receiptsNum.contains("-")) { + String[] split = receiptsNum.split("-"); + receiptsNum = split[1]; } - System.out.println(orderNo); + if(receiptsNum.contains("#")){ + String[] split1 = receiptsNum.split("#"); + receiptsNum = split1[0]; + } + System.out.println(receiptsNum); } }