This commit is contained in:
Mauve
2026-09-08 15:12:29 +08:00
commit 078ba3c713
672 changed files with 56677 additions and 0 deletions
@@ -0,0 +1,58 @@
package com.mgm.mcrm.common.jms;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.Strings;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson2.JSONObject;
import com.mgm.mcrm.common.constants.SysCommon;
import com.mgm.mcrm.common.dtos.msg.AppSettingMsgData;
import com.mgm.mcrm.common.dtos.msg.JMSTextMessage;
import com.mgm.mcrm.common.dtos.system.AppServerState;
import com.mgm.mcrm.common.services.SysServerStateService;
@Slf4j
@Component
public class AppControlMsgConsumer {
@Resource
private SysServerStateService serverStateService;
@JmsListener(destination = "${app_ctrl_topic}", containerFactory = "jmsTopicListenerCF")
public void receive(String msg){
JMSTextMessage msgObject = null;
try {
msgObject = JSONObject.parseObject(msg, JMSTextMessage.class);
if(Strings.CS.equals("SYNC_SERVER_STATE", msgObject.getMsgType())) {
AppServerState serverInfo =
JSONObject.parseObject(msgObject.getMsgContent(), AppServerState.class);
if(serverInfo != null) {
SysCommon.registerServerInfo(serverInfo);
}
} else if(Strings.CS.equals("UPD_MOBILE_CFG", msgObject.getMsgType())) {
AppSettingMsgData updateRequest =
JSONObject.parseObject(msgObject.getMsgContent(), AppSettingMsgData.class);
serverStateService.updateCfgByRequest(updateRequest);
} else if(Strings.CS.equals("REQ_SYNC_SERVER_STATE", msgObject.getMsgType())) {
serverStateService.notifyCurrentState();
}
} catch(Exception err) {
log.error("Process JMS message failed. msgType={}, message={}", msgObject != null ? msgObject.getMsgType() : "UNKNOWN", msg, err);
}
}
}
@@ -0,0 +1,47 @@
package com.mgm.mcrm.common.jms;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson2.JSON;
import com.mgm.mcrm.common.dtos.msg.JMSTextMessage;
import com.mgm.mcrm.common.utils.LogUtil;
@Component
public class AppControlMsgSender {
@Value("${app_ctrl_topic}")
private String ctrlTopicName;
private ActiveMQTopic ctrlTopic=null;
@Autowired
private JmsTemplate jmsTemplate;
private ActiveMQTopic getTopic() {
return this.ctrlTopic==null?new ActiveMQTopic(ctrlTopicName):this.ctrlTopic;
}
public void sendMessage(String message) {
jmsTemplate.convertAndSend(getTopic(), message);
}
public boolean sendMessage(String msgType, Object msgData) {
boolean result =false;
try {
JMSTextMessage msg = new JMSTextMessage();
msg.setMsgType(msgType);
msg.setMsgContent(msgData==null?"":JSON.toJSONString(msgData));
String message = JSON.toJSONString(msg);
jmsTemplate.convertAndSend(getTopic(), message);
result=true;
}catch(Exception err) {
LogUtil.error(AppControlMsgSender.class, "Send JMS Failed:"+err.getMessage());
result=false;
}
return result;
}
}
@@ -0,0 +1,97 @@
package com.mgm.mcrm.common.jms;
import com.alibaba.fastjson2.JSON;
import com.mgm.mcrm.booking.dtos.BookingDto;
import com.mgm.mcrm.booking.models.Bookings;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson2.JSONObject;
import com.mgm.mcrm.booking.repositories.BookingDao;
import com.mgm.mcrm.common.dtos.msg.JMSTextMessage;
import com.mgm.mcrm.booking.services.BookingService;
import java.util.List;
@Slf4j
@Component
public class BookingControlMsgConsumer {
@Resource
private BookingService bookingService;
@Resource
private BookingDao bookingDao;
@JmsListener(destination = "${book_ctrl_queue}", containerFactory = "jmsQueueListenerCF")
public void receive(String msg){
JMSTextMessage msgObject = null;
try {
msgObject = JSONObject.parseObject(msg, JMSTextMessage.class);
String msgType = msgObject.getMsgType();
if("CREATE_DAYLIGHT_BOOKING".equals(msgType)) {
Bookings booking =
JSONObject.parseObject(msgObject.getMsgContent(), Bookings.class);
bookingService.callDaylightUpsertReservation(
booking,
"CREATE_BOOKING"
);
} else if("CREATE_OPERA_BOOKING".equals(msgType)) {
Bookings booking =
JSONObject.parseObject(msgObject.getMsgContent(), Bookings.class);
bookingService.callOWSCreateBooking(booking);
} else if("EDIT_BOOKING".equals(msgType)) {
Bookings booking =
JSONObject.parseObject(msgObject.getMsgContent(), Bookings.class);
bookingService.callOWSEditBooking(booking);
} else if("WAITLIST_BOOKING".equals(msgType)) {
bookingService.finishWaitlistBooking();
} else if("SYNC_MERGE_BOOKING".equals(msgType)) {
List<BookingDto> syncBookings = null;
try {
syncBookings =
JSON.parseArray(
msgObject.getMsgContent(),
BookingDto.class
);
} catch(Exception err){
log.error("Convert sync booking data error", err);
}
bookingService.updateMergeBookingToDb_Optimize(syncBookings);
}
} catch(Exception err) {
try {
if(msgObject != null
&& "CREATE_DAYLIGHT_BOOKING".equals(msgObject.getMsgType())) {
Bookings booking =
JSONObject.parseObject(
msgObject.getMsgContent(),
Bookings.class
);
bookingDao.updateProcessStatus(
booking.getId(),
0
);
}
} catch(Exception updateErr){
log.error("Update booking process status failed", updateErr);
}
log.error("Process booking JMS message failed. msgType={}, message={}", msgObject != null ? msgObject.getMsgType() : "UNKNOWN", msg, err);
}
}
}
@@ -0,0 +1,51 @@
package com.mgm.mcrm.common.jms;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson2.JSON;
import com.mgm.mcrm.common.dtos.msg.JMSTextMessage;
import com.mgm.mcrm.common.utils.LogUtil;
@Component
public class BookingControlMsgSender {
@Value("${book_ctrl_queue}")
private String ctrlQueueName;
private ActiveMQQueue ctrlQueue = null;
@Autowired
private JmsTemplate jmsTemplate;
private ActiveMQQueue getQueue() {
if (ctrlQueue == null) {
ctrlQueue = new ActiveMQQueue(ctrlQueueName);
}
return ctrlQueue;
}
public void sendMessage(String message) {
jmsTemplate.convertAndSend(getQueue(), message);
}
public boolean sendMessage(String msgType, Object msgData) {
try {
JMSTextMessage msg = new JMSTextMessage();
msg.setMsgType(msgType);
msg.setMsgContent(msgData == null ? "" : JSON.toJSONString(msgData));
String message = JSON.toJSONString(msg);
jmsTemplate.convertAndSend(getQueue(), message);
return true;
}catch(Exception err) {
LogUtil.error(BookingControlMsgSender.class, "Send JMS Failed:" + err.getMessage());
return false;
}
}
}