预定餐下单,mq无法连接时提示错误
This commit is contained in:
parent
90458aa6d3
commit
31d2c32952
|
|
@ -5,6 +5,8 @@ import cn.hutool.core.map.MapUtil;
|
|||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.bonus.canteen.core.common.constant.OrderConstant;
|
||||
import com.bonus.canteen.core.common.redis.RedisUtil;
|
||||
import com.bonus.canteen.core.common.utils.TenantContextHolder;
|
||||
import com.bonus.canteen.core.order.common.constants.*;
|
||||
import com.bonus.canteen.core.order.common.service.OrderAmountChangeService;
|
||||
import com.bonus.canteen.core.order.common.service.OrderDeliveryService;
|
||||
|
|
@ -68,18 +70,19 @@ import com.bonus.common.houqin.i18n.I18n;
|
|||
import com.bonus.common.houqin.utils.id.Id;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.rabbit.connection.Connection;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
|
@ -142,6 +145,8 @@ public class OrderPlaceMobileBusinessImplV3 implements OrderPlaceMobileBusiness
|
|||
@Lazy
|
||||
@Autowired
|
||||
private AllocHolidayApi allocHolidayApi;
|
||||
@Autowired
|
||||
private ConnectionFactory connectionFactory;
|
||||
|
||||
// public OrderPayMobileVO addCurrentMealOrder(RequestHeaderDTO headerDTO, OrderCurrMealTotalDTO currMealTotalDTO) {
|
||||
// LogUtil.info("当餐点餐|入参", currMealTotalDTO);
|
||||
|
|
@ -175,8 +180,51 @@ public class OrderPlaceMobileBusinessImplV3 implements OrderPlaceMobileBusiness
|
|||
// }
|
||||
// }
|
||||
|
||||
public boolean isRabbitMqAvailable() {
|
||||
String mqResultKey = "yst:" + TenantContextHolder.getTenantId() + ":order:reserve:checkMQResult";
|
||||
String redisValue = RedisUtil.getString(mqResultKey);
|
||||
LogUtil.info("MQ检测结果,redis值 : ", redisValue);
|
||||
if (redisValue != null) {
|
||||
return "1".equals(redisValue);
|
||||
}
|
||||
String lockKey = "yst:" + TenantContextHolder.getTenantId() + ":order:reserve:checkMQ";
|
||||
long timeOut = 5 * 60;
|
||||
Connection connection = null;
|
||||
try {
|
||||
if (!RedisUtil.tryLock(lockKey, 10, 15)) {
|
||||
throw new ServiceException("系统异常,请联系管理员");
|
||||
}
|
||||
redisValue = RedisUtil.getString(mqResultKey);
|
||||
LogUtil.info("MQ二次检测结果,redis值 : ", redisValue);
|
||||
if (redisValue != null) {
|
||||
return "1".equals(redisValue);
|
||||
}
|
||||
connection = connectionFactory.createConnection();
|
||||
boolean isConnected = connection.isOpen();
|
||||
RedisUtil.setString(mqResultKey, isConnected ? "1" : "0", timeOut);
|
||||
LogUtil.info("MQ连接检测结果 : ", isConnected ? "正常" : "异常");
|
||||
return isConnected;
|
||||
} catch (Exception e) {
|
||||
LogUtil.info("RabbitMQ 连接检测异常:" + e);
|
||||
RedisUtil.setString(mqResultKey, "0", timeOut);
|
||||
return false;
|
||||
}finally {
|
||||
RedisUtil.safeUnLock(lockKey);
|
||||
if(Objects.nonNull(connection)) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (Exception ex) {
|
||||
LogUtil.info("关闭 RabbitMQ 连接异常", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public OrderPayMobileVO addReserveMealOrder(RequestHeaderDTO headerDTO, OrderReserveMealTotalDTO reserveMealDTO) {
|
||||
LogUtil.info("预定餐点餐|入参", reserveMealDTO);
|
||||
if(!isRabbitMqAvailable()) {
|
||||
throw new ServiceException("系统异常,请联系管理员");
|
||||
}
|
||||
JavaxValidateUtils.validate(reserveMealDTO);
|
||||
CustPayVO custInfo = this.getCustInfo(reserveMealDTO.getCustId(), headerDTO.getSourceType());
|
||||
if (!LeConstants.COMMON_YES.equals(reserveMealDTO.getIfTrial())) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue