携程统一回推数据的返回格式
This commit is contained in:
parent
a8c18e89ec
commit
93fd53b8a6
|
@ -0,0 +1,21 @@
|
|||
package com.chint.domain.aggregates.location.basedata;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@Table("c_trip_district_info")
|
||||
public class DistrictPOIInfoEntity implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -3622189228854599876L;
|
||||
@Id
|
||||
private Long id;
|
||||
private Long districtId;
|
||||
private String districtName;
|
||||
private String districtEnName;
|
||||
}
|
|
@ -44,12 +44,25 @@ public class PrefectureLevelCityInfoEntity implements Serializable {
|
|||
@MappedCollection(idColumn = "pre_level_city_id", keyColumn = "pre_level_city_key")
|
||||
private List<CountryLevelInfoEntity> countryLevelInfoEntities;
|
||||
|
||||
@MappedCollection(idColumn = "pre_level_city_id", keyColumn = "pre_level_city_key")
|
||||
private List<DistrictPOIInfoEntity> districtPOIInfoEntities;
|
||||
|
||||
public static PrefectureLevelCityInfoEntity of(PrefectureLevelCityInfo prefectureLevelCityInfo) {
|
||||
PrefectureLevelCityInfoEntity poiDataInfoEntity = BeanUtil
|
||||
.copyProperties(prefectureLevelCityInfo, PrefectureLevelCityInfoEntity.class);
|
||||
return poiDataInfoEntity;
|
||||
}
|
||||
|
||||
public PrefectureLevelCityInfoEntity addDistrict(DistrictPOIInfoEntity districtPOIInfoEntity) {
|
||||
if (this.districtPOIInfoEntities == null) {
|
||||
this.districtPOIInfoEntities = new ArrayList<>();
|
||||
}
|
||||
this.districtPOIInfoEntities.add(districtPOIInfoEntity);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public PrefectureLevelCityInfoEntity addAirportPOIInfoEntity(AirportPOIInfoEntity airportPOIInfoEntity) {
|
||||
if (this.airportPOIInfoEntities == null) {
|
||||
this.airportPOIInfoEntities = new ArrayList<>();
|
||||
|
|
|
@ -25,4 +25,6 @@ public interface CountryInfoEntityRepository {
|
|||
List<CountryInfoEntity> findByCountryId(Long id);
|
||||
|
||||
CountryInfoEntity findById(Long id);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.chint.infrastructure.config.webconfig;
|
||||
|
||||
import com.chint.infrastructure.util.Result;
|
||||
import com.chint.interfaces.rest.ctrip.dto.put.CTripNoteResponse;
|
||||
import com.google.gson.Gson;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.util.ContentCachingResponseWrapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static com.chint.infrastructure.constant.CommonMessageConstant.RESULT_ERROR_CODE;
|
||||
import static com.chint.infrastructure.constant.CommonMessageConstant.RESULT_SUCCESS_CODE;
|
||||
|
||||
public class SupplierResponseInterceptor implements HandlerInterceptor {
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws IOException {
|
||||
|
||||
if(request.getRequestURI().contains("/public/CTrip/status")){
|
||||
ContentCachingResponseWrapper responseWrapper = (ContentCachingResponseWrapper) response;
|
||||
byte[] contentAsByteArray = ((ContentCachingResponseWrapper) response).getContentAsByteArray();
|
||||
String responseJson = new String(contentAsByteArray, StandardCharsets.UTF_8);
|
||||
|
||||
Result result = gson.fromJson(responseJson, Result.class);
|
||||
String cTripResContent;
|
||||
if(result.getCode().equals(RESULT_ERROR_CODE)){
|
||||
CTripNoteResponse error = CTripNoteResponse.error(result.getMsg());
|
||||
cTripResContent = gson.toJson(error);
|
||||
} else if(result.getCode().equals(RESULT_SUCCESS_CODE)){
|
||||
CTripNoteResponse success = CTripNoteResponse.success(result.getMsg());
|
||||
cTripResContent = gson.toJson(success);
|
||||
} else {
|
||||
CTripNoteResponse error = CTripNoteResponse.error("未知消息");
|
||||
cTripResContent = gson.toJson(error);
|
||||
}
|
||||
|
||||
// 清除原始响应体并写入修改后的内容
|
||||
responseWrapper.resetBuffer();
|
||||
responseWrapper.getOutputStream().write(cTripResContent.getBytes());
|
||||
responseWrapper.setContentLength(cTripResContent.getBytes().length);
|
||||
|
||||
// 必须调用此方法以确保响应被正确处理
|
||||
responseWrapper.copyBodyToResponse();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -33,6 +33,9 @@ public class WebConfig implements WebMvcConfigurer {
|
|||
registry.addInterceptor(getMyRequestLoggingInterceptor())
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/public/log/pageQuery", "/order/pageQuery", "/OrderDetail/query/page", "/order/query/**", "/location/**");
|
||||
registry.addInterceptor(new SupplierResponseInterceptor())
|
||||
.addPathPatterns("/public/CTrip/status");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,13 +37,10 @@ public class CTripConstant {
|
|||
public static final String C_TRIP_AUDIT_ACTION_SUCCESS = "T";
|
||||
public static final String C_TRIP_AUDIT_ACTION_FAIL = "F";
|
||||
|
||||
|
||||
public static final String C_TRIP_ORDER_FLIGHT_PATH = "/switchapi/FlightOrderSettlement/GetCorpAccountFlightOrderSettlements?type=json";
|
||||
|
||||
public static final String C_TRIP_ORDER_HOTEL_PATH = "/switchapi/SettlementHltOrder/SearchSettlementHltOrderDetail";
|
||||
|
||||
public static final String C_TRIP_ORDER_TRAIN_PATH = "/switchapi/SettlementTrainOrder/SearchSettlementTrainOrderDetail";
|
||||
|
||||
|
||||
public static final String C_TRIP_ORDER_CAR_PATH = "/switchapi/CarOrderSettlement/SearchSettlementCarOrderDetail";
|
||||
}
|
||||
|
|
|
@ -19,5 +19,10 @@ public class CommonMessageConstant {
|
|||
public static final String LEG_CHANGE_MAX_ERROR = "最多支持变更两次";
|
||||
public static final String NO_PRICE_ERROR = "无估算价格";
|
||||
|
||||
public static final String RESULT_SUCCESS_CODE = "1";
|
||||
public static final String RESULT_ERROR_CODE = "0";
|
||||
public static final String RESULT_SSO_LOGIN_ERROR_CODE = "-2";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.chint.infrastructure.util;
|
|||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.chint.infrastructure.constant.CommonMessageConstant.*;
|
||||
|
||||
public class Result<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -39,21 +41,21 @@ public class Result<T> implements Serializable {
|
|||
}
|
||||
|
||||
public static <T> Result<T> Success(String msg, T data) {
|
||||
return new Result<T>(msg, "1", data);
|
||||
return new Result<T>(msg, RESULT_SUCCESS_CODE, data);
|
||||
}
|
||||
|
||||
public static <T> Result<T> Success(String msg) {
|
||||
return new Result<T>(msg, "1");
|
||||
return new Result<T>(msg, RESULT_SUCCESS_CODE);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(String msg) {
|
||||
return new Result<T>(msg, "0");
|
||||
return new Result<T>(msg, RESULT_ERROR_CODE);
|
||||
}
|
||||
public static <T> Result<T> tokenExpired(String msg) {
|
||||
return new Result<T>(msg, "-1");
|
||||
}
|
||||
public static <T> Result<T> ssoLoginFail(String msg) {
|
||||
return new Result<T>(msg, "-2");
|
||||
return new Result<T>(msg, RESULT_SSO_LOGIN_ERROR_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,4 +11,18 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
public class CTripNoteResponse {
|
||||
private String errorCode;
|
||||
private String errorMessage;
|
||||
|
||||
public static CTripNoteResponse error(String message){
|
||||
CTripNoteResponse cTripNoteResponse = new CTripNoteResponse();
|
||||
cTripNoteResponse.setErrorCode("1");
|
||||
cTripNoteResponse.setErrorMessage(message);
|
||||
return cTripNoteResponse;
|
||||
}
|
||||
|
||||
public static CTripNoteResponse success(String message){
|
||||
CTripNoteResponse cTripNoteResponse = new CTripNoteResponse();
|
||||
cTripNoteResponse.setErrorCode("0");
|
||||
cTripNoteResponse.setErrorMessage(message);
|
||||
return cTripNoteResponse;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.chint.domain.value_object.SupplierCallbackData;
|
|||
import com.chint.infrastructure.constant.OrderConstant;
|
||||
import com.chint.infrastructure.echo_framework.command.Command;
|
||||
import com.chint.infrastructure.util.Digest;
|
||||
import com.chint.infrastructure.util.Result;
|
||||
import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest;
|
||||
import com.chint.interfaces.rest.ctrip.dto.put.CTripStatusNotification;
|
||||
import com.chint.interfaces.rest.ctrip.dto.put.CTripStatusResponse;
|
||||
|
@ -67,7 +68,7 @@ public class CTripNoteController {
|
|||
|
||||
@Transactional
|
||||
@PostMapping("/status")
|
||||
public CTripStatusResponse statusEvent(@RequestBody CTripStatusNotification cTripStatusNotification) {
|
||||
public Result<String> statusEvent(@RequestBody CTripStatusNotification cTripStatusNotification) {
|
||||
String json = gson.toJson(cTripStatusNotification);
|
||||
log.info(json);
|
||||
|
||||
|
@ -84,16 +85,16 @@ public class CTripNoteController {
|
|||
String orderId = cTripStatusNotification.getOrderId();
|
||||
String putCTripSign = Digest.getPutCTripStatusSign(cTripStatusNotification.getCorpId(), productType, orderStatus, orderId, C_TRIP_REQUEST_SECRET);
|
||||
if (!putCTripSign.equals(cTripStatusNotification.getSign())) {
|
||||
return new CTripStatusResponse("1", "sign错误");
|
||||
return Result.error("sign错误");
|
||||
}
|
||||
if (orderStatus != null && orderId != null) {
|
||||
return handlerData(orderId, orderStatus, productType);
|
||||
}
|
||||
return new CTripStatusResponse("1", "未收到消息");
|
||||
return Result.error("未收到消息");
|
||||
}
|
||||
|
||||
|
||||
public CTripStatusResponse handlerData(String orderId, String orderStatus, String productType) {
|
||||
public Result<String> handlerData(String orderId, String orderStatus, String productType) {
|
||||
SupplierCallbackData supplierCallbackData =
|
||||
SupplierCallbackData.of(SUPPLIER_C_TRIP);
|
||||
SearchOrderResponse response = cTripOrderSearchRequest
|
||||
|
@ -128,7 +129,7 @@ public class CTripNoteController {
|
|||
break;
|
||||
}
|
||||
command.sendToQueue();
|
||||
return new CTripStatusResponse("0", "成功收到消息");
|
||||
return Result.Success("成功收到消息");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ package com.chint.interfaces.rest.ly.in;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chint.domain.aggregates.order.OrderTravel;
|
||||
import com.chint.domain.aggregates.system.SupplierCallBackLog;
|
||||
import com.chint.domain.repository.SupplierCallBackLogRepository;
|
||||
import com.chint.infrastructure.repository.jdbc.JdbcOrderTravelRepository;
|
||||
import com.chint.interfaces.rest.ly.LYNoteResponse;
|
||||
|
@ -32,8 +31,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/public/common")
|
||||
|
@ -71,24 +68,14 @@ public class CommonController {
|
|||
String json = gson.toJson(notification);
|
||||
log.info(json);
|
||||
|
||||
//创建回推日志
|
||||
// SupplierCallBackLog supplierCallBackLog = SupplierCallBackLog
|
||||
// .start()
|
||||
// .supplier(SUPPLIER_C_TRIP)
|
||||
// .callBackJson(json);
|
||||
// supplierCallBackLogRepository.save(supplierCallBackLog);
|
||||
|
||||
|
||||
int notifyType = notification.getNotifyType();
|
||||
return switch (notifyType) {
|
||||
|
||||
case 1 -> getOrderTicket(notification);
|
||||
case 1 -> getOrderFlight(notification);
|
||||
case 3 -> getOrderHotel(notification);
|
||||
case 5 -> getOrderTrain(notification);
|
||||
case 6 -> getOrderCar(notification);
|
||||
case 50 -> getOrderType(notification);
|
||||
default -> new LYNoteResponse("100", "OK");
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -192,14 +179,13 @@ public class CommonController {
|
|||
* @param notification
|
||||
* @return
|
||||
*/
|
||||
public LYNoteResponse getOrderTicket(Notification notification) {
|
||||
public LYNoteResponse getOrderFlight(Notification notification) {
|
||||
Object notifyData = notification.notifyData;
|
||||
int subNotifyType = notification.getSubNotifyType();
|
||||
if (Objects.nonNull(notifyData)) {
|
||||
JSONObject jsonObj = JSON.parseObject(notifyData.toString());
|
||||
ResultBackFly resultBackFly = jsonObj.toJavaObject(ResultBackFly.class);
|
||||
ResultBackFly.DataObject dataObject = resultBackFly.getData();
|
||||
|
||||
OrderTravel orderTravel = new OrderTravel();
|
||||
orderTravel.setOrderNo(dataObject.getOrderDetails().getOrderSerialNo());
|
||||
orderTravel.setTravelNo(dataObject.getOrderDetails().getTravelOrderNo());
|
||||
|
@ -269,7 +255,6 @@ public class CommonController {
|
|||
|
||||
} else if (emptyCar) {
|
||||
NotifyData.CarOrderList.Order orderCar = common.getTravelBizOrderList().getCarOrderList().get(0).getOrder();
|
||||
|
||||
OrderTravel orderTravel = new OrderTravel();
|
||||
orderTravel.setOrderNo(orderCar.getOrderSerialNo());
|
||||
orderTravel.setTravelNo(common.getTravelBizOrder().getTravelOrderNo());
|
||||
|
@ -346,6 +331,4 @@ public class CommonController {
|
|||
}
|
||||
return new LYNoteResponse("100", "OK");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue