From 22023afef95c052712076d607e7fd88bc5d3b160 Mon Sep 17 00:00:00 2001 From: Mauve Date: Tue, 22 Sep 2026 17:15:07 +0800 Subject: [PATCH] update code and update esb proxy function --- .../common/listener/ConfigListener.java | 29 ++++++- .../daylight/common/services/HttpService.java | 75 ++++++------------ .../CompRuleLimitsExceededChangedHandler.java | 19 ++--- .../impl/ReservationNotificationHandler.java | 38 ++++++++-- .../NotificationProxyController.java | 2 +- .../proxy/controllers/WebProxyController.java | 76 +++++++++++++------ .../reservation/repositories/BookingDao.java | 2 + .../reservation/services/BookingService.java | 52 ++++++------- 8 files changed, 171 insertions(+), 122 deletions(-) diff --git a/src/main/java/com/mgm/mcrm/apigateway/common/listener/ConfigListener.java b/src/main/java/com/mgm/mcrm/apigateway/common/listener/ConfigListener.java index ac91fa6..1f038a0 100644 --- a/src/main/java/com/mgm/mcrm/apigateway/common/listener/ConfigListener.java +++ b/src/main/java/com/mgm/mcrm/apigateway/common/listener/ConfigListener.java @@ -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,7 +28,17 @@ public class ConfigListener implements ApplicationListener 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 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 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 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 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; +// } } diff --git a/src/main/java/com/mgm/mcrm/apigateway/daylight/webhook/eventhandlers/impl/CompRuleLimitsExceededChangedHandler.java b/src/main/java/com/mgm/mcrm/apigateway/daylight/webhook/eventhandlers/impl/CompRuleLimitsExceededChangedHandler.java index 941326a..751a29a 100644 --- a/src/main/java/com/mgm/mcrm/apigateway/daylight/webhook/eventhandlers/impl/CompRuleLimitsExceededChangedHandler.java +++ b/src/main/java/com/mgm/mcrm/apigateway/daylight/webhook/eventhandlers/impl/CompRuleLimitsExceededChangedHandler.java @@ -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 handle(String payload, Map headers) { diff --git a/src/main/java/com/mgm/mcrm/apigateway/daylight/webhook/eventhandlers/impl/ReservationNotificationHandler.java b/src/main/java/com/mgm/mcrm/apigateway/daylight/webhook/eventhandlers/impl/ReservationNotificationHandler.java index 2e1957b..f1fa444 100644 --- a/src/main/java/com/mgm/mcrm/apigateway/daylight/webhook/eventhandlers/impl/ReservationNotificationHandler.java +++ b/src/main/java/com/mgm/mcrm/apigateway/daylight/webhook/eventhandlers/impl/ReservationNotificationHandler.java @@ -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 handle(String payload, Map headers) throws Exception { BaseApiResponse 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,10 +67,16 @@ 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()) { - result.setDlExternalNo(eventData.getExternalSystemIds().getFirst().getValue()); + 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())); @@ -128,10 +136,24 @@ public class ReservationNotificationHandler implements DaylightWebhookHandler { } } - JSONArray jsonArray = response.getData().getJSONArray("externalIds"); - if (!CollectionUtils.isEmpty(jsonArray)) { - String dlExternalNo = jsonArray.getJSONObject(0).getString("number"); - result.setDlExternalNo(dlExternalNo); + 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); + } + } } } diff --git a/src/main/java/com/mgm/mcrm/apigateway/proxy/controllers/NotificationProxyController.java b/src/main/java/com/mgm/mcrm/apigateway/proxy/controllers/NotificationProxyController.java index 1a332f4..6dd5910 100644 --- a/src/main/java/com/mgm/mcrm/apigateway/proxy/controllers/NotificationProxyController.java +++ b/src/main/java/com/mgm/mcrm/apigateway/proxy/controllers/NotificationProxyController.java @@ -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; diff --git a/src/main/java/com/mgm/mcrm/apigateway/proxy/controllers/WebProxyController.java b/src/main/java/com/mgm/mcrm/apigateway/proxy/controllers/WebProxyController.java index 5d7a74e..fa00ce0 100644 --- a/src/main/java/com/mgm/mcrm/apigateway/proxy/controllers/WebProxyController.java +++ b/src/main/java/com/mgm/mcrm/apigateway/proxy/controllers/WebProxyController.java @@ -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 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 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 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> sanitizeHeaders(HttpHeaders headers) { + Map> 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) { diff --git a/src/main/java/com/mgm/mcrm/apigateway/reservation/repositories/BookingDao.java b/src/main/java/com/mgm/mcrm/apigateway/reservation/repositories/BookingDao.java index 74764e8..f803572 100644 --- a/src/main/java/com/mgm/mcrm/apigateway/reservation/repositories/BookingDao.java +++ b/src/main/java/com/mgm/mcrm/apigateway/reservation/repositories/BookingDao.java @@ -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 findFirstByDlProfileIdAndPlayerIdIsNotNull(String dlProfileId); + @Query(value = "select * from bookings where dl_external_no = ?1", nativeQuery = true) List findByDlExternalNo(String dlExternalNo); } diff --git a/src/main/java/com/mgm/mcrm/apigateway/reservation/services/BookingService.java b/src/main/java/com/mgm/mcrm/apigateway/reservation/services/BookingService.java index 1b7dc48..a34cfb6 100644 --- a/src/main/java/com/mgm/mcrm/apigateway/reservation/services/BookingService.java +++ b/src/main/java/com/mgm/mcrm/apigateway/reservation/services/BookingService.java @@ -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 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 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());