Merge remote-tracking branch 'origin/master'

This commit is contained in:
Tankaikai
2025-02-26 16:57:54 +08:00
24 changed files with 544 additions and 77 deletions

View File

@@ -6,6 +6,7 @@ import com.czg.account.service.PermissionService;
import com.czg.account.vo.LoginVO;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaStaffCheckPermission;
import com.czg.config.RabbitPublisher;
import com.czg.mq.PrintMqListener;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
@@ -54,9 +55,12 @@ public class AuthorizationController {
@Resource
PrintMqListener printMqListener;
@Resource
RabbitPublisher rabbitPublisher;
@GetMapping("test")
public CzgResult<?> login() {
printMqListener.orderPrint("1");
rabbitPublisher.sendOrderPrintMsg("1");
// printMqListener.orderPrint("1");
// return CzgResult.success(Map.of("token", StpKit.USER.getShopId()));
return CzgResult.success();
}

View File

@@ -0,0 +1,91 @@
package com.czg.controller.admin;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.ad.ShopAdDTO;
import com.czg.account.entity.ShopAd;
import com.czg.account.service.ShopAdService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.exception.ApiNotPrintException;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 小程序广告管理
* @author Administrator
*/
@RestController
@RequestMapping("/admin/shopAd")
public class ShopAdController {
@Resource
private ShopAdService shopAdService;
/**
* 小程序广告列表
* @param showPosition 展示位置 home首页make_order点餐页
* @param status 状态 0未启用1已启用
* @return 列表
*/
@SaAdminCheckPermission(value = "shopAd:list", name = "小程序广告列表")
@GetMapping
public CzgResult<List<ShopAd>> list(String showPosition, Integer status) {
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopAd::getShopId, StpKit.USER.getShopId());
if (StrUtil.isNotBlank(showPosition)) {
queryWrapper.eq(ShopAd::getShowPosition, showPosition);
}
queryWrapper.eq(ShopAd::getStatus, status);
return CzgResult.success(shopAdService.list(queryWrapper));
}
/**
* 小程序广告详情
* @param id adId
* @return 详情
*/
@SaAdminCheckPermission(value = "shopAd:detail", name = "小程序广告详情")
@GetMapping("/detail")
public CzgResult<ShopAd> detail(@RequestParam Integer id) {
return CzgResult.success(shopAdService.getOne(new QueryWrapper().eq(ShopAd::getId, id).eq(ShopAd::getShopId, StpKit.USER.getShopId())));
}
/**
* 小程序广告编辑
* @return 是否成功
*/
@SaAdminCheckPermission(value = "shopAd:list", name = "小程序广告编辑")
@PutMapping
public CzgResult<Boolean> edit(@RequestBody @Validated(UpdateGroup.class) ShopAdDTO shopAdEditDTO) {
ShopAd shopAd = BeanUtil.copyProperties(shopAdEditDTO, ShopAd.class);
long count = shopAdService.count(new QueryWrapper().eq(ShopAd::getShopId, StpKit.USER.getShopId()).like(ShopAd::getShowPosition, shopAdEditDTO.getShowPosition()).ne(ShopAd::getId, shopAdEditDTO.getId()));
if (count > 0) {
return CzgResult.failure("小程序此位置已存在广告");
}
return CzgResult.success(shopAdService.update(shopAd, new QueryWrapper().eq(ShopAd::getId, shopAdEditDTO.getId()).eq(ShopAd::getShopId, StpKit.USER.getShopId())));
}
/**
* 小程序广告添加
* @return 是否成功
*/
@SaAdminCheckPermission(value = "shopAd:add", name = "小程序广告添加")
@PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated(InsertGroup.class) ShopAdDTO shopAdEditDTO) {
long count = shopAdService.count(new QueryWrapper().eq(ShopAd::getShopId, StpKit.USER.getShopId()).like(ShopAd::getShowPosition, shopAdEditDTO.getShowPosition()));
if (count > 0) {
return CzgResult.failure("小程序此位置已存在广告");
}
ShopAd shopAd = BeanUtil.copyProperties(shopAdEditDTO, ShopAd.class);
shopAd.setShopId(StpKit.USER.getShopId());
return CzgResult.success(shopAdService.save(shopAd));
}
}

View File

@@ -15,7 +15,9 @@ import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@@ -40,7 +42,7 @@ public class PrintMqListener {
@Resource
private PrinterHandler printerHandler;
// @RabbitListener(queues = {RabbitConstants.Queue.ORDER_PRINT_QUEUE})
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE})
public void orderPrint(String orderId) {
long startTime = DateUtil.date().getTime();
log.info("接收到订单打印消息:{}", orderId);
@@ -52,18 +54,17 @@ public class PrintMqListener {
throw new RuntimeException("订单信息不存在");
}
getPrintMachine(1L, "cash", "one", "order").forEach(machine -> {
getPrintMachine(orderInfo.getShopId(), "cash", "all", "order").forEach(machine -> {
printerHandler.handleRequest(machine, orderInfo, null);
// printPlaceTicket(isReturn, machine, orderInfo, shopInfo);
});
}catch (Exception e) {
log.error("订单打印失败", e);
mqLog.setErrInfo(JSONObject.toJSONString(e));
mqLog.setDuration(DateUtil.date().getTime() - startTime);
mqLog.setFailTime(DateUtil.date().toLocalDateTime());
// mqLogService.save(mqLog);
mqLogService.save(mqLog);
}
}

View File

@@ -0,0 +1,35 @@
package com.czg.config;
import cn.hutool.core.date.DateUtil;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderInfoService;
import com.czg.service.order.enums.OrderStatusEnums;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* 订单定时任务
*
* @author ww
* @description
*/
@Slf4j
@Component
public class OTimeTask {
@Resource
private OrderInfoService orderInfoService;
/**
* order 过期
*/
@Scheduled(cron = "0 0 1 * * ? ")
public void run() {
orderInfoService.updateChain()
.set(OrderInfo::getStatus, OrderStatusEnums.CANCELLED.getCode())
.eq(OrderInfo::getStatus, OrderStatusEnums.UNPAID.getCode())
.lt(OrderInfo::getTradeDay, DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd"))
.update();
}
}

View File

@@ -0,0 +1,51 @@
package com.czg.config;
import com.czg.order.service.OrderInfoService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
/**
* redis key过期监听
*
* @author ww
*/
@Slf4j
@Configuration
public class RedisKeyExpirationListener implements MessageListener {
@Value("${spring.data.redis.database}")
private String database;
@Resource
private OrderInfoService tbOrderInfoService;
//redis key失效监听
@Bean
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
// 监听特定键的过期事件
container.addMessageListener(this, new PatternTopic("__keyevent@" + database + "__:expired"));
return container;
}
@Override
public void onMessage(Message message, byte[] pattern) {
String expiredKey = new String(message.getBody());
// 检查过期的键是否以特定前缀开头
if (expiredKey.startsWith(RedisCst.classKeyExpired.EXPIRED_ORDER)) {
log.info("监听到订单过期,订单Id: {}", expiredKey);
String orderId = expiredKey.substring(RedisCst.classKeyExpired.EXPIRED_ORDER.length());
tbOrderInfoService.expired(Long.parseLong(orderId));
}
}
}

View File

@@ -42,8 +42,10 @@ public class AdminOrderController {
}
@GetMapping("/historyOrder")
public CzgResult<HistoryOrderVo> historyOrder(Long orderId) {
return CzgResult.success(orderInfoService.historyOrder(orderId));
public CzgResult<HistoryOrderVo> historyOrder(
@RequestParam(required = false) Long orderId,
@RequestParam(required = false) String tableCode) {
return CzgResult.success(orderInfoService.historyOrder(orderId, tableCode));
}
@PostMapping("/createOrder")
@@ -58,7 +60,6 @@ public class AdminOrderController {
/**
* 订单全额退款 只传订单id
* 部分退款 传参refundDetailMap {"详情id":"数量","详情id":"数量"}
*
*/
@PostMapping("/refundOrder")
public CzgResult<Object> refundOrder(@Validated @RequestBody OrderInfoRefundDTO refundDTO) {

View File

@@ -39,8 +39,10 @@ public class UserOrderController {
}
@GetMapping("/historyOrder")
public CzgResult<HistoryOrderVo> historyOrder(Long orderId) {
return CzgResult.success(orderInfoService.historyOrder(orderId));
public CzgResult<HistoryOrderVo> historyOrder(
@RequestParam(required = false) Long orderId,
@RequestParam(required = false) String tableCode) {
return CzgResult.success(orderInfoService.historyOrder(orderId, tableCode));
}
/**