Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -51,11 +51,13 @@ public class MenuController {
|
||||
* 获取所有菜单
|
||||
* @return 菜单结构
|
||||
*/
|
||||
@SaAdminCheckRole("管理员")
|
||||
@SaAdminCheckPermission(value = "menu:list", name = "菜单列表")
|
||||
@GetMapping("/list")
|
||||
public CzgResult<List<MenuVO>> all(String title, String startTime, String endTime) {
|
||||
if (StpKit.USER.isAdmin()) {
|
||||
return CzgResult.success(menuService.getAll(title, startTime, endTime));
|
||||
}
|
||||
return CzgResult.success(menuService.getMenu());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.czg.config.RabbitConstants;
|
||||
import com.czg.order.entity.MqLog;
|
||||
import com.czg.order.service.MqLogService;
|
||||
import com.czg.order.service.OrderInfoRpcService;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.service.order.utils.FunUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
@@ -26,6 +28,30 @@ public class OrderMqListener {
|
||||
private OrderInfoRpcService orderInfoRpcService;
|
||||
@Resource
|
||||
private MqLogService mqLogService;
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
@Resource
|
||||
private FunUtil funUtil;
|
||||
|
||||
/**
|
||||
* 订单上菜
|
||||
*/
|
||||
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_PRODUCT_STATUS_QUEUE})
|
||||
public void orderDetailUp(String info) {
|
||||
if (!info.contains("UP_ORDER_DETAIL:")) {
|
||||
return;
|
||||
}
|
||||
info = info.replace("UP_ORDER_DETAIL:", "");
|
||||
log.info("接收到修改菜品状态mq, info: {}", info);
|
||||
String finalInfo = info;
|
||||
funUtil.debounce("UP_ORDER_DETAIL:" + info, 5, () -> {
|
||||
orderInfoService.updateOrderDetailStatus(Long.valueOf(finalInfo));
|
||||
|
||||
});
|
||||
info = info.replace("UP_ORDER_DETAIL:", "");
|
||||
System.out.println(info);
|
||||
|
||||
}
|
||||
|
||||
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_STOCK_QUEUE})
|
||||
public void orderStockSubtract(String orderId) {
|
||||
@@ -80,4 +106,7 @@ public class OrderMqListener {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ public class OrderDetail implements Serializable {
|
||||
* 状态: in-production 制作中;wait_out 待取餐;refunding 退款中; part_refund 部分退单; refund-退单; done 完成;
|
||||
*/
|
||||
private String status;
|
||||
private String subStatus;
|
||||
|
||||
/**
|
||||
* 当前下单次数
|
||||
|
||||
@@ -68,4 +68,7 @@ public interface OrderInfoService extends IService<OrderInfo> {
|
||||
|
||||
|
||||
Boolean updatePayOrderId(Long orderId, Long paymentId, String payType, String remark);
|
||||
|
||||
void updateOrderDetailStatus(Long orderDetailId);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,23 @@ import lombok.Getter;
|
||||
* @author Administrator
|
||||
*/
|
||||
public interface TableValueConstant {
|
||||
interface OrderDetail {
|
||||
@Getter
|
||||
enum SubStatus {
|
||||
PENDING_PREP("PENDING_PREP", "待起菜"),
|
||||
READY_TO_SERVE("READY_TO_SERVE", "待出菜"),
|
||||
SENT_OUT("SENT_OUT", "已出菜"),
|
||||
DELIVERED("DELIVERED", "已上菜"),
|
||||
EXPIRED("EXPIRED", "已超时");
|
||||
private final String code;
|
||||
private final String msg;
|
||||
|
||||
SubStatus(String code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
interface MemberExpFlow {
|
||||
@Getter
|
||||
enum Type {
|
||||
|
||||
@@ -1722,4 +1722,31 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
mapper.updatePayOrderId(orderId, paymentId, payType, remark);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOrderDetailStatus(Long orderDetailId) {
|
||||
OrderDetail orderDetail = orderDetailService.getById(orderDetailId);
|
||||
if (orderDetail == null) {
|
||||
log.warn("订单详情不存在");
|
||||
}
|
||||
|
||||
if (!orderDetail.getSubStatus().equals(TableValueConstant.OrderDetail.SubStatus.READY_TO_SERVE.getCode())
|
||||
&& !orderDetail.getSubStatus().equals(TableValueConstant.OrderDetail.SubStatus.SENT_OUT.getCode())) {
|
||||
log.warn("订单详情状态不正确");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (EnumUtil.fromString(TableValueConstant.OrderDetail.SubStatus.class, orderDetail.getSubStatus())) {
|
||||
case TableValueConstant.OrderDetail.SubStatus.READY_TO_SERVE:
|
||||
orderDetail.setSubStatus(TableValueConstant.OrderDetail.SubStatus.SENT_OUT.getCode());
|
||||
break;
|
||||
case TableValueConstant.OrderDetail.SubStatus.SENT_OUT:
|
||||
orderDetail.setSubStatus(TableValueConstant.OrderDetail.SubStatus.DELIVERED.getCode());
|
||||
|
||||
}
|
||||
orderDetailService.updateById(orderDetail);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,5 +99,27 @@ public class FunUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 防抖函数:在指定秒数内相同 Key 的任务只会执行一次
|
||||
* @param key 防抖使用的 Redis Key
|
||||
* @param seconds 防抖时间(秒)
|
||||
* @param task 要执行的业务逻辑
|
||||
* @return true 执行了任务;false 在防抖期内被拦截
|
||||
*/
|
||||
public boolean debounce(String key, long seconds, Runnable task) {
|
||||
try {
|
||||
Boolean success = redisTemplate.opsForValue().setIfAbsent(
|
||||
key, "1", seconds, TimeUnit.SECONDS
|
||||
);
|
||||
|
||||
if (Boolean.TRUE.equals(success)) {
|
||||
task.run();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.error("防抖函数执行失败 key={} err={}", key, e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user