退菜接口,sku mapper结构修改

This commit is contained in:
2024-10-08 11:27:42 +08:00
parent 6f0ff52897
commit 44fc9927b4
8 changed files with 182 additions and 26 deletions

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.OrderVo;
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnCartDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.UpdateVipDTO;
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
import com.chaozhanggui.system.cashierservice.service.OrderService;
@@ -202,14 +203,26 @@ public class OrderController {
return orderService.getOutNumber(shopId, page, pageSize);
}
@GetMapping("getOrderById")
public Result getOrderById(@RequestParam("orderId") Integer orderId) {
return orderService.getOrder(orderId);
}
/**
* 就餐人数选择
*/
@PutMapping("/choseCount")
public Result choseCount(@Validated @RequestBody ChoseCountDTO choseCountDTO) {
return Result.success(CodeEnum.SUCCESS, orderService.choseCount(choseCountDTO));
}
/**
* 退菜
* @param returnCartDTO 退菜信息
* @return 是否成功
*/
@PostMapping("/returnCart")
public Result returnCart(@Validated @RequestBody ReturnCartDTO returnCartDTO) {
return Result.success(CodeEnum.SUCCESS, orderService.returnCart(returnCartDTO));
}
}

View File

@@ -111,6 +111,8 @@ public class TbOrderInfo implements Serializable {
private String useType;
private Integer placeNum;
private Integer seatCount;
private BigDecimal seatAmount;
private static final long serialVersionUID = 1L;

View File

@@ -0,0 +1,7 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
@Data
public class PrintDTO {
}

View File

@@ -0,0 +1,15 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class ReturnCartDTO {
@NotNull
private Integer cartId;
@NotNull
private Integer shopId;
@NotNull
private Long tableId;
}

View File

@@ -1,6 +1,5 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil;
@@ -15,6 +14,7 @@ import com.chaozhanggui.system.cashierservice.bean.*;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnCartDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.UpdateVipDTO;
import com.chaozhanggui.system.cashierservice.entity.po.*;
@@ -41,7 +41,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@@ -87,31 +86,18 @@ public class OrderService {
@Autowired
RabbitProducer producer;
private final WechatUtil wechatUtil;
private final TbUserShopMsgMapper tbUserShopMsgMapper;
private final TbShopOpenIdMapper shopOpenIdMapper;
private final MpShopTableMapper mpShopTableMapper;
@Autowired
private TbProskuConMapper tbProskuConMapper;
@Autowired
TbConsInfoMapper tbConsInfoMapper;
private final TbCashierCartMapper tbCashierCartMapper;
private static ConcurrentHashMap<String, HashSet<Integer>> codeMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, HashSet<String>> userMap = new ConcurrentHashMap<>();
@Autowired
private ProductService productService;
@Qualifier("printMechineConsumer")
@Autowired
private PrintMechineConsumer printMechineConsumer;
@Qualifier("tbOrderDetailMapper")
@Autowired
private TbOrderDetailMapper tbOrderDetailMapper;
@Autowired
private MPOrderDetailMapper mPOrderDetailMapper;
@Autowired
@@ -127,13 +113,15 @@ public class OrderService {
@Qualifier("stringRedisTemplate")
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private RabbitMsgUtils rabbitMsgUtils;
public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper, WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper, TbCashierCartMapper tbCashierCartMapper, MpCashierCartService mpCashierCartService) {
public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper,
TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper,
TbCashierCartMapper tbCashierCartMapper, MpCashierCartService mpCashierCartService) {
this.wxAccountUtil = wxAccountUtil;
this.mpCashierCartMapper = mpCashierCartMapper;
this.wechatUtil = wechatUtil;
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
this.shopOpenIdMapper = shopOpenIdMapper;
this.mpShopTableMapper = mpShopTableMapper;
this.tbCashierCartMapper = tbCashierCartMapper;
@@ -275,7 +263,7 @@ public class OrderService {
if (StringUtils.isEmpty(masterId)) {
boolean flag = redisUtil.exists("SHOP:CODE:" + clientType + ":" + shopId);
if (flag) {
String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId).toString();
String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId);
Integer foodCode = Integer.parseInt(code) + 1;
code = "#" + String.format("%03d", foodCode);
redisUtil.saveMessage("SHOP:CODE:" + clientType + ":" + shopId, foodCode.toString());
@@ -476,10 +464,8 @@ public class OrderService {
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine()
) {
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType());
shopOpenIds.forEach(item -> {
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num), item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopId);
});
shopOpenIds.forEach(item -> wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num), item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopId));
}
}
@@ -1769,4 +1755,59 @@ public class OrderService {
}, stringRedisTemplate, RedisCst.getLockKey(RedisCst.CHOSE_TABLE_COUNT, choseCountDTO.getShopId(), choseCountDTO.getTableId()));
}
public Object returnCart(ReturnCartDTO removeCartDTO) {
// 会员点单
TbCashierCart cashierCart = mpCashierCartMapper.selectOne(new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, removeCartDTO.getShopId())
.in(TbCashierCart::getStatus, "create", "refund")
.eq(TbCashierCart::getId, removeCartDTO.getCartId()));
if (cashierCart == null) {
throw new MsgException("购物车商品不存在或已退单");
}
TbOrderDetail tbOrderDetail = mPOrderDetailMapper.selectOne(new LambdaQueryWrapper<TbOrderDetail>()
.eq(TbOrderDetail::getShopId, removeCartDTO.getShopId())
.eq(TbOrderDetail::getCartId, cashierCart.getId())
.eq(TbOrderDetail::getProductId, cashierCart.getProductId())
.eq(TbOrderDetail::getProductSkuId, cashierCart.getSkuId())
.eq(TbOrderDetail::getOrderId, cashierCart.getOrderId()));
if (tbOrderDetail == null) {
throw new MsgException("购物车商品不存在或已退单");
}
if (cashierCart.getOrderId() == null) {
throw new MsgException("此商品还未下单,无需退单");
}
// 餐位费直接删除
if (cashierCart.getId() == -999) {
mpCashierCartMapper.deleteById(cashierCart.getId());
if (cashierCart.getOrderId() != null) {
mPOrderDetailMapper.delete(new LambdaQueryWrapper<TbOrderDetail>()
.eq(TbOrderDetail::getCartId, cashierCart.getId()));
mPOrderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, cashierCart.getOrderId())
.eq(TbOrderInfo::getShopId, removeCartDTO.getShopId())
.set(TbOrderInfo::getSeatCount, null)
.set(TbOrderInfo::getSeatAmount, null));
}
} else {
mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
.eq(TbCashierCart::getId, cashierCart.getId())
.set(TbCashierCart::getStatus, "return"));
mPOrderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
.eq(TbOrderDetail::getId, tbOrderDetail.getId())
.set(TbOrderDetail::getUpdateTime, DateUtil.date())
.set(TbOrderDetail::getStatus, "return"));
rabbitMsgUtils.printDishesTicket(tbOrderDetail.getOrderId(), true, tbOrderDetail);
}
return true;
}
}

View File

@@ -1240,7 +1240,9 @@ public class PayService {
} else {
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(String.valueOf(orderId));
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(),
newOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款",
newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
if ("000000".equals(publicResp.getCode())) {

View File

@@ -0,0 +1,76 @@
package com.chaozhanggui.system.cashierservice.util;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Slf4j
public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
private final RabbitTemplate rabbitTemplate;
public RabbitMsgUtils(RabbitTemplate rabbitTemplate) {
this.rabbitTemplate = rabbitTemplate;
}
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
log.info(" 回调id:{}", correlationData);
if (ack) {
log.info("消息成功消费");
} else {
log.info("消息消费失败:{}", cause);
}
}
private <T> void sendMsg(String exchange, String routingKey, T data, String note, boolean isJson) {
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
log.info("开始发送{}mq消息, msgId: {}, exchange: {}, routingKey: {}, data: {}", note, correlationId.getId(), exchange, routingKey, data);
rabbitTemplate.convertAndSend(exchange, routingKey, isJson ? JSONObject.toJSONString(data) : data, correlationId);
}
public <T> void sendOrderCollectMsg(T data) {
sendMsg(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, data, "订单信息收集", true);
}
public void printTicket(String orderId){
sendMsg(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, orderId, "打印票", false);
}
public <T> void sendStockMsg(T mqData) {
// 发送库存记录mq消息
sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData, "库存记录", true);
}
public void printDishesReturnTicket(Integer orderId, Integer... orderIds) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("orderId", orderId);
jsonObject.put("orderDetailIds", orderIds);
jsonObject.put("isReturn", true);
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品退单", true);
}
public void printDishesTicket(Integer orderId, boolean isReturn, TbOrderDetail... detailOrderIds) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("orderId", orderId);
jsonObject.put("orderDetailIds", detailOrderIds);
jsonObject.put("isReturn", isReturn);
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品打印", true);
}
public void printPlaceTicket(Integer id, boolean isReturn) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("orderId", id);
jsonObject.put("isReturn", isReturn);
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_PLACE, jsonObject, "订单打印", true);
}
}

View File

@@ -31,7 +31,7 @@
</resultMap>
<sql id="Base_Column_List">
id, shop_id, bar_code, product_id, origin_price, cost_price, member_price, meal_price,
sale_price, guide_price, strategy_price, stock_number, cover_img, warn_line, weight,
sale_price, guide_price, strategy_price, stock_number, cover_img, weight,
volume, real_sales_number, first_shared, second_shared, created_at, updated_at,suit
</sql>
<sql id="Blob_Column_List">