update code and update esb proxy function
This commit is contained in:
@@ -2,11 +2,17 @@ package com.mgm.mcrm.apigateway.common.listener;
|
||||
|
||||
import com.mgm.mcrm.apigateway.allotment.services.RoomCriteriaDaylightService;
|
||||
import com.mgm.mcrm.apigateway.common.constants.SysCommon;
|
||||
import com.mgm.mcrm.apigateway.common.utils.NotificationUtil;
|
||||
import com.mgm.mcrm.apigateway.daylight.repositories.CfgCompRuleDao;
|
||||
import com.mgm.mcrm.apigateway.daylight.services.DaylightApiService;
|
||||
import com.mgm.mcrm.apigateway.daylight.webhook.eventhandlers.impl.AvailableRoomCountUpdatedHandler;
|
||||
import com.mgm.mcrm.apigateway.daylight.webhook.eventhandlers.impl.CompRuleLimitsExceededChangedHandler;
|
||||
import com.mgm.mcrm.apigateway.daylight.webhook.eventhandlers.impl.ReservationNotificationHandler;
|
||||
import com.mgm.mcrm.apigateway.daylight.webhook.eventhandlers.impl.RoomTypeDateAvailabilityChangedHandler;
|
||||
import com.mgm.mcrm.apigateway.daylight.webhook.services.DaylightWebhookFactory;
|
||||
import com.mgm.mcrm.apigateway.logging.dao.SysLogDeviceTokenRepository;
|
||||
import com.mgm.mcrm.apigateway.notification.services.ApnNotificationService;
|
||||
import com.mgm.mcrm.apigateway.reservation.repositories.BookingDao;
|
||||
import com.mgm.mcrm.apigateway.reservation.services.BookingService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
@@ -22,6 +28,16 @@ public class ConfigListener implements ApplicationListener<ApplicationStartedEve
|
||||
private BookingService bookingService;
|
||||
@Resource
|
||||
private DaylightApiService daylightApiService;
|
||||
@Resource
|
||||
private CfgCompRuleDao cfgCompRuleDao;
|
||||
@Resource
|
||||
private BookingDao bookingDao;
|
||||
@Resource
|
||||
private SysLogDeviceTokenRepository sysLogDeviceTokenRepository;
|
||||
@Resource
|
||||
private NotificationUtil notificationUtil;
|
||||
@Resource
|
||||
private ApnNotificationService apnNotificationService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||
@@ -32,5 +48,16 @@ public class ConfigListener implements ApplicationListener<ApplicationStartedEve
|
||||
DaylightWebhookFactory.registerHandler("AvailableRoomCountUpdated", new AvailableRoomCountUpdatedHandler(roomCriteriaDaylightService));
|
||||
//--Register Reservation Notification handlers
|
||||
DaylightWebhookFactory.registerHandler("ReservationNotification", new ReservationNotificationHandler(bookingService, daylightApiService));
|
||||
DaylightWebhookFactory.registerHandler(
|
||||
"ComplimentaryRuleLimitsExceededChangedNotification",
|
||||
new CompRuleLimitsExceededChangedHandler(
|
||||
cfgCompRuleDao,
|
||||
bookingDao,
|
||||
sysLogDeviceTokenRepository,
|
||||
notificationUtil,
|
||||
apnNotificationService,
|
||||
daylightApiService
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,25 +41,8 @@ public class HttpService {
|
||||
|
||||
public String sslGet(String url, Header[] headers, Map<String, Object> map) throws Exception {
|
||||
|
||||
log.info("======sslGet======url:{}===========headers:{} =============== map:{}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(map));
|
||||
// 使用 HttpConfig 配置 GET 请求(带参数)
|
||||
HttpRequestOptions getConfig = HttpRequestOptions.create()
|
||||
.url(daylightUrl + url)
|
||||
.timeout(requestConfig)
|
||||
.map(map)
|
||||
.encoding("utf-8")
|
||||
.client(httpClient);
|
||||
|
||||
String result = HttpClientExecutor.get(getConfig, headers);
|
||||
log.info("====== GET request result size:{}", result.length());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String sslGetNoLog(String url, Header[] headers, Map<String, Object> map) throws Exception {
|
||||
|
||||
// todo 在這裏需要把請求頭的信息插入到數據庫裏
|
||||
log.info("======sslGet======url:{}===========headers:{} =============== map:{}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(map));
|
||||
log.info("GET method, url={}, headers={}, map={}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(map));
|
||||
// 使用 HttpConfig 配置 GET 请求(带参数)
|
||||
HttpRequestOptions getConfig = HttpRequestOptions.create()
|
||||
.url(daylightUrl + url)
|
||||
@@ -69,7 +52,7 @@ public class HttpService {
|
||||
.client(httpClient);
|
||||
|
||||
String result = HttpClientExecutor.get(getConfig, headers);
|
||||
log.info("====== GET request result size={}", result.length());
|
||||
log.info("GET request result size={}", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -77,7 +60,7 @@ public class HttpService {
|
||||
public HttpResult sslGetHttpResult(String url, Header[] headers, Map<String, Object> map) throws Exception {
|
||||
|
||||
// todo 在這裏需要把請求頭的信息插入到數據庫裏
|
||||
log.info("======sslGet======url:{}===========headers:{} =============== map:{}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(map));
|
||||
log.info("GET method, url={}, headers={}, map={}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(map));
|
||||
// 使用 HttpConfig 配置 GET 请求(带参数)
|
||||
HttpRequestOptions getConfig = HttpRequestOptions.create()
|
||||
.url(daylightUrl + url)
|
||||
@@ -87,7 +70,7 @@ public class HttpService {
|
||||
.client(httpClient);
|
||||
|
||||
HttpResult result = HttpClientExecutor.sendAndGetResp(getConfig, headers);
|
||||
log.info("====== GET request result:{}", result.getResult());
|
||||
log.info("GET request result size={}", result.getResult().length());
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -102,7 +85,7 @@ public class HttpService {
|
||||
* @throws Exception 異常
|
||||
*/
|
||||
public String sslPut(String url, Header[] headers, Map<String, Object> map) throws Exception {
|
||||
log.info("======sslPut======url:{}===========headers:{} =============== map:{}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(map));
|
||||
log.info("PUT method, url={}, headers={}, map={}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(map));
|
||||
HttpRequestOptions putConfig = HttpRequestOptions.create()
|
||||
.url(daylightUrl + url)
|
||||
.timeout(requestConfig)
|
||||
@@ -111,7 +94,7 @@ public class HttpService {
|
||||
.encoding("utf-8")
|
||||
.client(httpClient);
|
||||
String result = HttpClientExecutor.send(putConfig, headers);
|
||||
log.info("====== PUT request result:{}", result);
|
||||
log.info("PUT request result={}", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -126,7 +109,7 @@ public class HttpService {
|
||||
* @throws Exception 異常
|
||||
*/
|
||||
public String sslDelete(String url, Header[] headers, Object requestBody) throws Exception {
|
||||
log.info("======sslDelete======url:{}===========headers:{} =============== map:{}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(requestBody));
|
||||
log.info("DELETE method, url={}, headers={}, map={}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(requestBody));
|
||||
HttpRequestOptions deleteConfig = HttpRequestOptions.create()
|
||||
.url(daylightUrl + url)
|
||||
.timeout(requestConfig)
|
||||
@@ -134,7 +117,7 @@ public class HttpService {
|
||||
.method(HttpMethods.DELETE)
|
||||
.client(httpClient);
|
||||
String result = HttpClientExecutor.send(deleteConfig, headers);
|
||||
log.info("====== DELETE request result:{}", result);
|
||||
log.info("DELETE request result={}", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -148,7 +131,7 @@ public class HttpService {
|
||||
* @throws Exception 異常
|
||||
*/
|
||||
public HttpResult sslPost(String url, Header[] headers, Object requestBody) throws Exception {
|
||||
log.info("======sslCreatePost======url:{}===========headers:{}", daylightUrl + url, JSON.toJSONString(headers));
|
||||
log.info("POST method, url={}, headers={}, map={}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(requestBody));
|
||||
HttpRequestOptions postConfig = HttpRequestOptions.create()
|
||||
.url(daylightUrl + url)
|
||||
.timeout(requestConfig)
|
||||
@@ -157,7 +140,7 @@ public class HttpService {
|
||||
.client(httpClient);
|
||||
HttpResult result = HttpClientExecutor.sendAndPostResp(postConfig, headers);
|
||||
// System.out.println("POST 请求结果:\n" + result);
|
||||
log.info("====== POST request result:{}", result);
|
||||
log.info("POST request result={}", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -171,7 +154,7 @@ public class HttpService {
|
||||
* @throws Exception 異常
|
||||
*/
|
||||
public HttpResult sslPatch(String url, Header[] headers, Object requestBody) throws Exception {
|
||||
log.info("======sslCreatePatch======url:{}===========headers:{}", daylightUrl + url, JSON.toJSONString(headers));
|
||||
log.info("PATCH method, url={}, headers={}, map={}", daylightUrl + url, JSON.toJSONString(headers), JSON.toJSONString(requestBody));
|
||||
HttpRequestOptions patchConfig = HttpRequestOptions.create()
|
||||
.url(daylightUrl + url)
|
||||
.timeout(requestConfig)
|
||||
@@ -180,30 +163,20 @@ public class HttpService {
|
||||
.encoding("utf-8")
|
||||
.client(httpClient);
|
||||
HttpResult result = HttpClientExecutor.sendAndPatchResp(patchConfig, headers);
|
||||
log.info("====== PATCH request result:{}", result);
|
||||
log.info("PATCH request result={}", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 HttpConfig 配置 Delete 请求
|
||||
*
|
||||
* @param url 請求路徑
|
||||
* @param headers 請求頭
|
||||
* @param map Cancel数据
|
||||
* @return 接口結果的json數據
|
||||
* @throws Exception 異常
|
||||
*/
|
||||
public HttpResult sslCancelPost(String url, Header[] headers, Map<String, Object> map) throws Exception {
|
||||
log.info("======sslCancelPost======url:{}===========headers:{}", daylightUrl + url, JSON.toJSONString(headers));
|
||||
HttpRequestOptions postConfig = HttpRequestOptions.create()
|
||||
.url(daylightUrl + url)
|
||||
.timeout(requestConfig)
|
||||
.json(JSON.toJSONString(map))
|
||||
.method(HttpMethods.POST)
|
||||
.client(httpClient);
|
||||
HttpResult result = HttpClientExecutor.sendAndPostResp(postConfig, headers);
|
||||
// System.out.println("POST 请求结果:\n" + result);
|
||||
log.info("====== POST request result:{}", result);
|
||||
return result;
|
||||
}
|
||||
// public HttpResult sslSendNotification(String url, Header[] headers, SendNotificationRequest request) throws Exception {
|
||||
// log.info("POST method, send notification, url={}, headers={}, map={}", notificationProxyUrl + url, JSON.toJSONString(headers), JSON.toJSONString(request));
|
||||
// HttpRequestOptions postConfig = HttpRequestOptions.create()
|
||||
// .url(notificationProxyUrl + url)
|
||||
// .timeout(requestConfig)
|
||||
// .json(JSON.toJSONString(request))
|
||||
// .method(HttpMethods.POST)
|
||||
// .client(httpClient);
|
||||
// HttpResult result = HttpClientExecutor.sendAndPostResp(postConfig, headers);
|
||||
// log.info("POST request result={}", result);
|
||||
// return result;
|
||||
// }
|
||||
}
|
||||
|
||||
+6
-13
@@ -32,19 +32,12 @@ import java.util.Map;
|
||||
@RequiredArgsConstructor
|
||||
public class CompRuleLimitsExceededChangedHandler implements DaylightWebhookHandler {
|
||||
|
||||
@Resource
|
||||
private CfgCompRuleDao cfgCompRuleDao;
|
||||
@Resource
|
||||
private BookingDao bookingDao;
|
||||
@Resource
|
||||
private SysLogDeviceTokenRepository sysLogDeviceTokenRepository;
|
||||
@Resource
|
||||
private NotificationUtil notificationUtil;
|
||||
@Resource
|
||||
private ApnNotificationService apnNotificationService;
|
||||
|
||||
@Resource
|
||||
private DaylightApiService daylightApiService;
|
||||
private final CfgCompRuleDao cfgCompRuleDao;
|
||||
private final BookingDao bookingDao;
|
||||
private final SysLogDeviceTokenRepository sysLogDeviceTokenRepository;
|
||||
private final NotificationUtil notificationUtil;
|
||||
private final ApnNotificationService apnNotificationService;
|
||||
private final DaylightApiService daylightApiService;
|
||||
|
||||
@Override
|
||||
public BaseApiResponse<Void> handle(String payload, Map<String, String> headers) {
|
||||
|
||||
+25
-3
@@ -15,6 +15,7 @@ import com.mgm.mcrm.apigateway.reservation.services.BookingService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -31,6 +32,9 @@ public class ReservationNotificationHandler implements DaylightWebhookHandler {
|
||||
|
||||
private final DaylightApiService daylightApiService;
|
||||
|
||||
@Value("${daylight.system-id}")
|
||||
private String systemId;
|
||||
|
||||
@Override
|
||||
public BaseApiResponse<Void> handle(String payload, Map<String, String> headers) throws Exception {
|
||||
BaseApiResponse<Void> result = new BaseApiResponse<>();
|
||||
@@ -51,8 +55,6 @@ public class ReservationNotificationHandler implements DaylightWebhookHandler {
|
||||
}
|
||||
|
||||
private Bookings convertEventToBooking(ReservationNotificationEvent eventData) {
|
||||
|
||||
|
||||
log.info("Reservation Notification Event Data: {}", JSON.toJSONString(eventData));
|
||||
|
||||
Bookings result = new Bookings();
|
||||
@@ -65,11 +67,17 @@ public class ReservationNotificationHandler implements DaylightWebhookHandler {
|
||||
result.setDlChannelId(eventData.getChannelId());
|
||||
result.setDlAccountId(eventData.getAccountId());
|
||||
result.setDlBlockId(eventData.getBlockId());
|
||||
result.setDlExternalNo(eventData.getDlExternalNo());
|
||||
// result.setDlExternalNo(eventData.getDlExternalNo());
|
||||
if (eventData.getExternalSystemIds() != null
|
||||
&& !eventData.getExternalSystemIds().isEmpty()) {
|
||||
eventData.getExternalSystemIds().stream()
|
||||
.filter(t -> t.getId().equalsIgnoreCase(systemId))
|
||||
.forEach(t -> result.setDlExternalNo(t.getValue()));
|
||||
|
||||
if (StringUtils.isEmpty(result.getDlExternalNo())) {
|
||||
result.setDlExternalNo(eventData.getExternalSystemIds().getFirst().getValue());
|
||||
}
|
||||
}
|
||||
result.setCreatedAt(parseDateTime(eventData.getCreatedAt()));
|
||||
result.setUpdatedAt(parseDateTime(eventData.getUpdatedAt()));
|
||||
result.setCheckinDate(DateTimeUtil.getDateFromString(eventData.getArrivalDate(),"yyyy-MM-dd"));
|
||||
@@ -128,12 +136,26 @@ public class ReservationNotificationHandler implements DaylightWebhookHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(result.getDlExternalNo())) {
|
||||
JSONArray jsonArray = response.getData().getJSONArray("externalIds");
|
||||
if (!CollectionUtils.isEmpty(jsonArray)) {
|
||||
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
|
||||
if (jsonObject.getString("systemId").equals(systemId)) {
|
||||
result.setDlExternalNo(jsonObject.getString("number"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(result.getDlExternalNo())) {
|
||||
String dlExternalNo = jsonArray.getJSONObject(0).getString("number");
|
||||
result.setDlExternalNo(dlExternalNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ import java.util.Collections;
|
||||
@RestController
|
||||
public class NotificationProxyController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(WebProxyController.class);
|
||||
private final Logger logger = LoggerFactory.getLogger(NotificationProxyController.class);
|
||||
@Resource
|
||||
private NotificationProxyService notificationProxyService;
|
||||
|
||||
|
||||
@@ -25,12 +25,18 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
@Tag(name = "Proxy", description = "Controller for API proxy")
|
||||
@RestController
|
||||
public class WebProxyController {
|
||||
private static final int LOG_BODY_PREVIEW_LIMIT = 4096;
|
||||
private static final Set<String> SENSITIVE_HEADERS = Set.of(
|
||||
"authorization", "proxy-authorization", "cookie", "set-cookie",
|
||||
"x-api-key", "api-key"
|
||||
);
|
||||
private final Logger logger = LoggerFactory.getLogger(WebProxyController.class);
|
||||
private final HttpProxyErrorHandler httpErrorHandler= new HttpProxyErrorHandler();
|
||||
private final SoapProxyErrorHandler soapProxyErrorHandler = new SoapProxyErrorHandler();
|
||||
@@ -77,24 +83,11 @@ public class WebProxyController {
|
||||
}
|
||||
@RequestMapping("/api/esb/proxy/**")
|
||||
public ResponseEntity<byte[]> invokeEsbApiProxy(HttpServletRequest request) throws Exception {
|
||||
logger.info("invokeEsbApiProxy start, method={}, uri={}, query={}",
|
||||
request.getMethod(), request.getRequestURI(), request.getQueryString());
|
||||
HttpMethod method = HttpMethod.valueOf(request.getMethod());
|
||||
String apiUrl = esbApiSetting.getServerUrl() + request.getRequestURI().replace("/api/esb/proxy", "");
|
||||
logger.info("invokeEsbApiProxy target apiUrl={}", apiUrl);
|
||||
String queryString = request.getQueryString();
|
||||
HttpHeaders headers = this.extractHeaders(request);
|
||||
|
||||
if (isMockFromDb()) {
|
||||
return webProxyService.invokeMockRequest(
|
||||
WebProxyService.ESB_API,
|
||||
HttpMethod.valueOf(request.getMethod()),
|
||||
apiUrl,
|
||||
request.getQueryString(),
|
||||
extractHeaders(request),
|
||||
getRequestBody(request),
|
||||
Duration.ofSeconds(esbApiSetting.getApiRequestTimeout()),
|
||||
httpErrorHandler
|
||||
).block();
|
||||
}
|
||||
byte[] requestBody = getRequestBody(request);
|
||||
|
||||
EsbToken esbToken = esbTokenService.getApiAccessToken();
|
||||
if(esbToken==null || StringUtils.isBlank(esbToken.getAccessToken())){
|
||||
@@ -105,16 +98,32 @@ public class WebProxyController {
|
||||
|
||||
ResponseEntity<byte[]> response = webProxyService.invokeRequest(
|
||||
WebProxyService.ESB_API,
|
||||
HttpMethod.valueOf(request.getMethod()),
|
||||
method,
|
||||
apiUrl,
|
||||
request.getQueryString(),
|
||||
extractHeaders(request),
|
||||
getRequestBody(request),
|
||||
queryString,
|
||||
headers,
|
||||
requestBody,
|
||||
Duration.ofSeconds(esbApiSetting.getApiRequestTimeout()),
|
||||
httpErrorHandler
|
||||
).block();
|
||||
logger.info("invokeEsbApiProxy end, uri={}, status={}",
|
||||
request.getRequestURI(), response == null ? null : response.getStatusCode());
|
||||
if (response == null) {
|
||||
logger.error("invokeEsbApiProxy received a null response: method={}, apiUrl={}, query={}",
|
||||
method, apiUrl, queryString);
|
||||
} else if (response.getStatusCode().isError()) {
|
||||
byte[] responseBody = response.getBody();
|
||||
logger.warn("invokeEsbApiProxy error response: method={}, apiUrl={}, query={}, status={}, headers={}, bodyLength={}, bodyPreview={}",
|
||||
method,
|
||||
apiUrl,
|
||||
queryString,
|
||||
|
||||
response.getStatusCode(),
|
||||
sanitizeHeaders(response.getHeaders()),
|
||||
responseBody == null ? 0 : responseBody.length,
|
||||
bodyPreview(responseBody));
|
||||
} else {
|
||||
logger.info("invokeEsbApiProxy completed: method={}, apiUrl={}, query={}, status={}",
|
||||
method, apiUrl, queryString, response.getStatusCode());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -156,6 +165,29 @@ public class WebProxyController {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, List<String>> sanitizeHeaders(HttpHeaders headers) {
|
||||
Map<String, List<String>> sanitizedHeaders = new LinkedHashMap<>();
|
||||
headers.forEach((name, values) -> sanitizedHeaders.put(
|
||||
name,
|
||||
SENSITIVE_HEADERS.contains(name.toLowerCase(Locale.ROOT))
|
||||
? List.of("[REDACTED]")
|
||||
: values
|
||||
));
|
||||
return sanitizedHeaders;
|
||||
}
|
||||
|
||||
private String bodyPreview(byte[] body) {
|
||||
if (body == null || body.length == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String content = new String(body, StandardCharsets.UTF_8);
|
||||
if (content.length() <= LOG_BODY_PREVIEW_LIMIT) {
|
||||
return content;
|
||||
}
|
||||
return content.substring(0, LOG_BODY_PREVIEW_LIMIT) + "...[truncated]";
|
||||
}
|
||||
|
||||
private boolean isMockFromDb() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastMockCheckTime > MOCK_CHECK_INTERVAL_MS) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mgm.mcrm.apigateway.reservation.repositories;
|
||||
|
||||
import com.mgm.mcrm.apigateway.reservation.models.Bookings;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,5 +14,6 @@ public interface BookingDao extends JpaRepository<Bookings, Long> {
|
||||
|
||||
Bookings findFirstByDlProfileIdAndPlayerIdIsNotNull(String dlProfileId);
|
||||
|
||||
@Query(value = "select * from bookings where dl_external_no = ?1", nativeQuery = true)
|
||||
List<Bookings> findByDlExternalNo(String dlExternalNo);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.mgm.mcrm.apigateway.player.services.PlayerService;
|
||||
import com.mgm.mcrm.apigateway.reservation.models.Bookings;
|
||||
import com.mgm.mcrm.apigateway.reservation.repositories.BookingDao;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Strings;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -43,6 +44,7 @@ import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class BookingService {
|
||||
|
||||
@@ -85,17 +87,32 @@ public class BookingService {
|
||||
|
||||
List<Bookings> dbBookings = null;
|
||||
if (StringUtils.isNotEmpty(dlExternalNo)) {
|
||||
log.info("Find booking by dlExternalNo={}", dlExternalNo);
|
||||
TimeUnit.SECONDS.sleep(5);
|
||||
dbBookings = bookingDao.findByDlExternalNo(dlExternalNo);
|
||||
|
||||
log.info("bookings isEmpty={}", dbBookings.isEmpty());
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(dbBookings) && StringUtils.isNotEmpty(dlReservationId)) {
|
||||
log.info("Find booking by dlReservationId={}", dlReservationId);
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
dbBookings = bookingDao.findByDlReservationId(dlReservationId);
|
||||
log.info("bookings isEmpty={}", dbBookings.isEmpty());
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(dbBookings) && StringUtils.isNotEmpty(confirmNo)) {
|
||||
log.info("Find booking by confirmNo={}", confirmNo);
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
dbBookings = bookingDao.findByConfirmationNo(confirmNo);
|
||||
log.info("bookings isEmpty={}", dbBookings.isEmpty());
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(dbBookings) && StringUtils.isNotEmpty(dlExternalNo)) {
|
||||
log.info("Find booking again by dlExternalNo={}", dlExternalNo);
|
||||
TimeUnit.SECONDS.sleep(3);
|
||||
dbBookings = bookingDao.findByDlExternalNo(dlExternalNo);
|
||||
log.info("bookings isEmpty={}", dbBookings.isEmpty());
|
||||
}
|
||||
|
||||
Bookings dbBooking = null;
|
||||
@@ -104,7 +121,7 @@ public class BookingService {
|
||||
String dbBookingStatus = null;
|
||||
if(!CollectionUtils.isEmpty(dbBookings)) {
|
||||
for(Bookings booking:dbBookings){
|
||||
if("N".equalsIgnoreCase(booking.getApproveStatus())) {
|
||||
if("N".equalsIgnoreCase(booking.getApproveStatus()) || "PN".equalsIgnoreCase(booking.getApproveStatus())) {
|
||||
dbBooking = booking;
|
||||
dbBookingStatus = dbBooking.getLastOperaStatus();
|
||||
checkInDate = dbBooking.getCheckinDate();
|
||||
@@ -122,13 +139,9 @@ public class BookingService {
|
||||
}
|
||||
bookingDao.save(dbBooking);
|
||||
|
||||
CfgProperties property = propertyDao.findByDlPropertyId(dbBooking.getDlPropertyId());
|
||||
CfgProperties property = propertyDao.findById(dbBooking.getPropertyId()).orElse(null);
|
||||
|
||||
//Send Notification to Booker when booking lastOpera status Changed
|
||||
|
||||
LogUtil.info(BookingService.class,"Daylight webhook updated, prepare send notification");
|
||||
LogUtil.info(BookingService.class,"DaylightBooking status=" + daylightBooking.getLastOperaStatus());
|
||||
LogUtil.info(BookingService.class,"Db booking status=" + dbBookingStatus);
|
||||
if (Strings.CS.equals(daylightBooking.getLastOperaStatus(),"RESERVED") && !Strings.CS.equals(dbBookingStatus,daylightBooking.getLastOperaStatus())){
|
||||
LogUtil.info(BookingService.class,"Booking last opera status changed, DB Record status:"+dbBookingStatus+", DlBooking status:"+daylightBooking.getLastOperaStatus());
|
||||
//设置Notification 内容
|
||||
@@ -165,6 +178,10 @@ public class BookingService {
|
||||
apnNotificationService.pushApnMessage(transactionId,deviceTokenValue,finalTitle,notificationContent,true);
|
||||
}
|
||||
|
||||
LogUtil.info(BookingService.class,"Daylight webhook updated, prepare send notification");
|
||||
log.info("dbBooking checkin={}, checkout={}", checkInDate, checkOutDate);
|
||||
log.info("dlBooking checkin={}, checkout={}", daylightBooking.getCheckinDate(), daylightBooking.getCheckoutDate());
|
||||
LogUtil.info(BookingService.class,"Db booking status=" + dbBookingStatus);
|
||||
//Send notification to Booker when Booking C/I | C/O date changed
|
||||
if ((checkInDate != null && !checkInDate.equals(daylightBooking.getCheckinDate()))||
|
||||
(checkOutDate != null && !checkOutDate.equals(daylightBooking.getCheckoutDate()))) {
|
||||
@@ -315,24 +332,6 @@ public class BookingService {
|
||||
}
|
||||
|
||||
public Bookings createBookingFromDaylight(Bookings daylightBooking) throws Exception {
|
||||
String dlReservationId = daylightBooking.getDlReservationId();
|
||||
|
||||
List<Bookings> dbBookings = bookingDao.findByDlReservationId(dlReservationId);
|
||||
|
||||
if (!dbBookings.isEmpty()) {
|
||||
Bookings dbBooking = null;
|
||||
for (Bookings booking : dbBookings) {
|
||||
if ("N".equalsIgnoreCase(booking.getApproveStatus())) {
|
||||
dbBooking = booking;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dbBooking != null) {
|
||||
mergeDaylightToDbBooking(daylightBooking, dbBooking);
|
||||
return dbBooking;
|
||||
}
|
||||
}
|
||||
|
||||
Bookings dbBooking = new Bookings();
|
||||
CfgProperties daylightProperty = propertyDao.findByDlPropertyId(daylightBooking.getDlPropertyId());
|
||||
@@ -411,8 +410,9 @@ public class BookingService {
|
||||
dbBooking.setDlReservationId(daylightBooking.getDlReservationId());
|
||||
|
||||
//get player info
|
||||
if(StringUtils.isNotEmpty(dbBooking.getPlayerId())) {
|
||||
ServiceResult serviceResult = playerService.findWebPlayerProfileByPlayerId(dbBooking.getPlayerId());
|
||||
if(StringUtils.isNotEmpty(daylightBooking.getPlayerId())) {
|
||||
dbBooking.setPlayerId(daylightBooking.getPlayerId());
|
||||
ServiceResult serviceResult = playerService.findWebPlayerProfileByPlayerId(daylightBooking.getPlayerId());
|
||||
if(serviceResult.isSuccess()) {
|
||||
PlayerProfileApiResult profile = (PlayerProfileApiResult) serviceResult.getReturnData();
|
||||
dbBooking.setMemberLastName(profile.getName());
|
||||
|
||||
Reference in New Issue
Block a user