optimize codes
This commit is contained in:
@@ -56,7 +56,9 @@ import org.apache.commons.lang3.Strings;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -162,53 +164,84 @@ public class TodoService {
|
||||
TodoDetailResult resultObj = JSONObject.parseObject(httpResult.getResponseContent(), TodoDetailResult.class, Feature.SupportNonPublicField, Feature.IgnoreNotMatch);
|
||||
if (Strings.CI.equals(resultObj.getStatusCode(), "OK")) {
|
||||
|
||||
|
||||
// TODO daylight专用,后面要改 by Mauve
|
||||
if (1 == 1) {
|
||||
if (resultObj.getDescriptions() != null) {
|
||||
for (TodoDetailDescription detailRecord : resultObj.getDescriptions()) {
|
||||
if ("Room".equalsIgnoreCase(detailRecord.getItemRecordType())) {
|
||||
String recordDesc = detailRecord.getItemRecordDescription();
|
||||
if (StringUtils.isNotBlank(recordDesc)) {
|
||||
String confNum = null;
|
||||
int index = recordDesc.indexOf("Conf#");
|
||||
if (index != -1) {
|
||||
String sub = recordDesc.substring(index + 5);
|
||||
int pipeIndex = sub.indexOf("|");
|
||||
if (pipeIndex != -1) {
|
||||
confNum = sub.substring(0, pipeIndex).trim();
|
||||
} else {
|
||||
confNum = sub.trim();
|
||||
}
|
||||
if (resultObj.getDescriptions() != null) {
|
||||
for (TodoDetailDescription detailRecord : resultObj.getDescriptions()) {
|
||||
if ("Room".equalsIgnoreCase(detailRecord.getItemRecordType())) {
|
||||
String recordDesc = detailRecord.getItemRecordDescription();
|
||||
if (StringUtils.isNotBlank(recordDesc)) {
|
||||
String confNum = null;
|
||||
int index = recordDesc.indexOf("Conf#");
|
||||
if (index != -1) {
|
||||
String sub = recordDesc.substring(index + 5);
|
||||
int pipeIndex = sub.indexOf("|");
|
||||
if (pipeIndex != -1) {
|
||||
confNum = sub.substring(0, pipeIndex).trim();
|
||||
} else {
|
||||
confNum = sub.trim();
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(confNum)) {
|
||||
if ("Inhouse".equalsIgnoreCase(todoCategory) || "Arrival".equalsIgnoreCase(todoCategory)) {
|
||||
List<CfgProperties> daylightProperties = propertyDao.findByCategory("DAYLIGHT");
|
||||
if (CollectionUtils.isNotEmpty(daylightProperties)) {
|
||||
CfgProperties property = daylightProperties.get(0);
|
||||
|
||||
if ("Inhouse".equalsIgnoreCase(todoCategory)) {
|
||||
// Parse checkinDate from recordDesc (e.g., "Jun 25 – Jul 1 ...")
|
||||
LocalDate ciDate = null;
|
||||
try {
|
||||
String ciDatePart = recordDesc.split("–")[0].trim();
|
||||
// Use the year from the 'date' parameter
|
||||
int year = Integer.parseInt(date.substring(0, 4));
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy", Locale.US);
|
||||
ciDate = LocalDate.parse(ciDatePart + " " + year, formatter);
|
||||
} catch (Exception e) {
|
||||
LogUtil.warn(TodoService.class, "Parse checkinDate error: " + e.getMessage() + ", recordDesc: " + recordDesc);
|
||||
}
|
||||
|
||||
if (ciDate != null) {
|
||||
LocalDate today = LocalDate.now();
|
||||
if (ciDate.isAfter(today)) {
|
||||
// 当checkindate大于今天不用拿room number 和room ready
|
||||
continue;
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(confNum)) {
|
||||
if ("Inhouse".equalsIgnoreCase(todoCategory) || "Arrival".equalsIgnoreCase(todoCategory)) {
|
||||
List<CfgProperties> daylightProperties = propertyDao.findByCategory("DAYLIGHT");
|
||||
if (CollectionUtils.isNotEmpty(daylightProperties)) {
|
||||
CfgProperties property = daylightProperties.get(0);
|
||||
if ("Inhouse".equalsIgnoreCase(todoCategory)) {
|
||||
BaseApiResponse<ReservationDoorKeyResponse> doorKeyResult =
|
||||
dlService.getReservationDoorKeyByConfirmationNumber(property.getDlPropertyId(), confNum);
|
||||
ReservationDoorKeyResponse doorKeyData = doorKeyResult.getData();
|
||||
boolean isRoomReady = doorKeyResult.isSuccess()
|
||||
&& doorKeyData != null
|
||||
&& StringUtils.isNotBlank(doorKeyData.getId())
|
||||
&& !doorKeyData.isHasKey();
|
||||
if (isRoomReady) {
|
||||
detailRecord.setItemRecordDescription(recordDesc.replace("Conf#" + confNum, "Conf#" + confNum + " [Rm Ready]"));
|
||||
}
|
||||
} else {
|
||||
BaseApiResponse<ReservationQueueResponse> queueResult =
|
||||
dlService.getReservationQueueByConfirmationNumber(property.getDlPropertyId(), confNum);
|
||||
ReservationQueueResponse queueData = queueResult.getData();
|
||||
boolean isQueue = queueResult.isSuccess()
|
||||
&& queueData != null
|
||||
&& queueData.isQueue();
|
||||
if (isQueue) {
|
||||
detailRecord.setItemRecordDescription(recordDesc.replace("Conf#" + confNum, "Conf#" + confNum + " [In Queue]"));
|
||||
|
||||
if (doorKeyResult.isSuccess() && doorKeyData != null) {
|
||||
String replaceStr = "Conf#" + confNum;
|
||||
if (StringUtils.isNotBlank(doorKeyData.getRoomNumber())) {
|
||||
detailRecord.setRoomNumber(doorKeyData.getRoomNumber());
|
||||
replaceStr += " [Rm #" + doorKeyData.getRoomNumber() + "]";
|
||||
}
|
||||
|
||||
if (ciDate.isEqual(today)) {
|
||||
// 当今天的时候要检查room ready
|
||||
boolean isRoomReady = StringUtils.isNotBlank(doorKeyData.getId())
|
||||
&& !doorKeyData.isHasKey();
|
||||
if (isRoomReady) {
|
||||
replaceStr += " [Rm Ready]";
|
||||
}
|
||||
}
|
||||
|
||||
if (!replaceStr.equals("Conf#" + confNum)) {
|
||||
detailRecord.setItemRecordDescription(recordDesc.replace("Conf#" + confNum, replaceStr));
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
BaseApiResponse<ReservationQueueResponse> queueResult =
|
||||
dlService.getReservationQueueByConfirmationNumber(property.getDlPropertyId(), confNum);
|
||||
ReservationQueueResponse queueData = queueResult.getData();
|
||||
boolean isQueue = queueResult.isSuccess()
|
||||
&& queueData != null
|
||||
&& queueData.isQueue();
|
||||
if (isQueue) {
|
||||
detailRecord.setItemRecordDescription(recordDesc.replace("Conf#" + confNum, "Conf#" + confNum + " [In Queue]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,7 +250,6 @@ public class TodoService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.setSuccess(true);
|
||||
result.setReturnData(resultObj);
|
||||
} else {
|
||||
@@ -478,15 +510,58 @@ public class TodoService {
|
||||
List<TodoListRecord> dateRecords = todoDateListRecord.getDateRecords();
|
||||
|
||||
for (TodoListRecord record : dateRecords) {
|
||||
String daylightConfirmationNo = record.getOperaConfirmationNo();
|
||||
List<String> descriptions = record.getDescriptions();
|
||||
if (CollectionUtils.isEmpty(descriptions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
String[] split = daylightConfirmationNo.split(",");
|
||||
for (String description : descriptions) {
|
||||
if (StringUtils.isBlank(description)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String temp2 : split) {
|
||||
String[] split1 = temp2.split(";");
|
||||
int confIndex = description.indexOf("Conf#");
|
||||
if (confIndex == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String confNum = split1[split1.length - 1];
|
||||
String confPart = description.substring(confIndex + 5);
|
||||
int pipeIndex = confPart.indexOf("|");
|
||||
String confNum = (pipeIndex == -1 ? confPart : confPart.substring(0, pipeIndex)).trim();
|
||||
|
||||
if (StringUtils.isNotBlank(confNum)) {
|
||||
if ("Inhouse".equalsIgnoreCase(category) || "Arrival".equalsIgnoreCase(category)) {
|
||||
List<CfgProperties> daylightProperties = propertyDao.findByCategory("DAYLIGHT");
|
||||
if (CollectionUtils.isNotEmpty(daylightProperties)) {
|
||||
CfgProperties property = daylightProperties.get(0);
|
||||
if ("Inhouse".equalsIgnoreCase(category)) {
|
||||
BaseApiResponse<ReservationDoorKeyResponse> doorKeyResult =
|
||||
dlService.getReservationDoorKeyByConfirmationNumber(property.getDlPropertyId(), confNum);
|
||||
ReservationDoorKeyResponse doorKeyData = doorKeyResult.getData();
|
||||
boolean isRoomReady = doorKeyResult.isSuccess()
|
||||
&& doorKeyData != null
|
||||
&& StringUtils.isNotBlank(doorKeyData.getId())
|
||||
&& !doorKeyData.isHasKey();
|
||||
if (isRoomReady) {
|
||||
record.setRoomReady(true);
|
||||
updateTodoRecordDescription(record, confNum, "[Rm Ready]");
|
||||
}
|
||||
} else {
|
||||
BaseApiResponse<ReservationQueueResponse> queueResult =
|
||||
dlService.getReservationQueueByConfirmationNumber(property.getDlPropertyId(), confNum);
|
||||
ReservationQueueResponse queueData = queueResult.getData();
|
||||
boolean isQueue = queueResult.isSuccess()
|
||||
&& queueData != null
|
||||
&& queueData.isQueue();
|
||||
if (isQueue) {
|
||||
record.setIsQueue(true);
|
||||
updateTodoRecordDescription(record, confNum, "[In Queue]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<BookingsView> bookingByConfirmationNo = bookingService.getBookingByDaylightConf(confNum);
|
||||
|
||||
@@ -498,7 +573,7 @@ public class TodoService {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to set ETA, operaConfirmationNo={}", daylightConfirmationNo, e);
|
||||
log.warn("Failed to process todo descriptions={}", descriptions, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -987,5 +1062,17 @@ public class TodoService {
|
||||
return isPass;
|
||||
}
|
||||
|
||||
private void updateTodoRecordDescription(TodoListRecord record, String confNum, String tag) {
|
||||
List<String> descriptions = record.getDescriptions();
|
||||
if (CollectionUtils.isNotEmpty(descriptions)) {
|
||||
for (int i = 0; i < descriptions.size(); i++) {
|
||||
String desc = descriptions.get(i);
|
||||
if (StringUtils.isNotBlank(desc) && desc.contains("Conf#" + confNum)) {
|
||||
descriptions.set(i, desc.replace("Conf#" + confNum, "Conf#" + confNum + " " + tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user