增加订单详情接口

This commit is contained in:
2024-09-25 13:53:47 +08:00
parent 373870c65b
commit 84eaaed716
4 changed files with 106 additions and 140 deletions

View File

@@ -1,11 +1,17 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
@@ -25,11 +31,10 @@ import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
/**
* @author 12847
@@ -78,6 +83,13 @@ public class OrderService {
@Autowired
private TbOrderInfoMapper tbOrderInfoMapper;
@Autowired
private MpCashierCartMapper mpCashierCartMapper;
@Autowired
private MpOrderDetailMapper mpOrderDetailMapper;
@Autowired
private MpOrderInfoMapper mpOrderInfoMapper;
/**
* 创建订单
*
@@ -432,4 +444,51 @@ public class OrderService {
}
return Result.success(CodeEnum.SUCCESS);
}
public Object orderDetail(Integer shopId, Integer orderId) {
TbOrderInfo orderInfo = mpOrderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, orderId)
.eq(TbOrderInfo::getShopId, shopId));
if (orderInfo == null) {
return Result.fail("订单不存在");
}
if (!"unpaid".equals(orderInfo.getStatus())) {
return Result.fail("订单不处于待支付状态");
}
LambdaQueryWrapper<TbOrderDetail> queryWrapper = new LambdaQueryWrapper<TbOrderDetail>()
.eq(TbOrderDetail::getShopId, shopId)
.eq(TbOrderDetail::getOrderId, orderId);
List<TbOrderDetail> list = mpOrderDetailMapper.selectList(queryWrapper);
AtomicReference<TbOrderDetail> mealCashierCart = new AtomicReference<>();
list.forEach(item -> {
item.setPlaceNum(item.getPlaceNum() == null ? 0 : item.getPlaceNum());
if (item.getProductId() == -999) {
mealCashierCart.set(item);
}
});
// 根据placeNum进行分组
Map<Integer, List<TbOrderDetail>> groupedByPlaceNum = list.stream()
.collect(Collectors.groupingBy(TbOrderDetail::getPlaceNum));
ArrayList<HashMap<String, Object>> dataList = new ArrayList<>();
groupedByPlaceNum.forEach((k, v) -> {
HashMap<String, Object> item = new HashMap<>();
item.put("placeNum", k);
item.put("info", v);
dataList.add(item);
});
Map<String, Object> map = new HashMap<>();
// 餐位费
map.put("seatFee", mealCashierCart);
map.put("detailList", dataList);
map.put("orderInfo", orderInfo);
return map;
}
}

View File

@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.Enum.PlatformTypeEnum;
@@ -18,6 +19,7 @@ import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
import com.chaozhanggui.system.cashierservice.entity.vo.*;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpShopTableMapper;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
@@ -95,11 +97,28 @@ public class ProductService {
private MpShopTableMapper mpShopTableMapper;
@Autowired
private MpCashierCartMapper mpCashierCartMapper;
@Autowired
private MpOrderInfoMapper mpOrderInfoMapper;
public ProductService(ShopUtils shopUtils) {
this.shopUtils = shopUtils;
}
private TbOrderInfo getCurrentOrder(ShopEatTypeInfoDTO eatTypeInfoDTO, String tableId, Object shopId) {
// 获取当前台桌最新订单,先付款模式不获取
if (eatTypeInfoDTO.isDineInBefore()) {
return null;
}
List<TbOrderInfo> orderInfoList = mpOrderInfoMapper.selectPage(new Page<>(1, 1), new LambdaQueryWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getStatus, "unpaid")
.eq(TbOrderInfo::getUseType, eatTypeInfoDTO.getUseType())
.eq(TbOrderInfo::getShopId, shopId)
.eq(TbOrderInfo::getTableId, tableId)
.eq(TbOrderInfo::getTradeDay, DateUtils.getDay())
.orderByDesc(TbOrderInfo::getId)).getRecords();
return orderInfoList.isEmpty() ? null : orderInfoList.get(0);
}
public Result queryShopIdByTableCode(String userId, String openId, String code, String lat, String lng) {
if (StringUtils.isBlank(code)) return Result.fail("桌码信息为空");
if (StringUtils.isBlank(lat) || lat.equals("undefined")) {
@@ -115,6 +134,11 @@ public class ProductService {
Double.parseDouble(lng), Double.parseDouble(lat),
Double.parseDouble(shopInfo.getLng()), Double.parseDouble(shopInfo.getLat()));
ConcurrentMap<String, Object> concurrentMap = new ConcurrentHashMap<>();
// 获取当前台桌最新订单id
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(code, shopInfo.getId());
TbOrderInfo order = getCurrentOrder(shopEatTypeInfoDTO, code, shopInfo.getId());
tbShopTable.setOrderId(order == null ? null : order.getId());
concurrentMap.put("shopTableInfo", tbShopTable);
concurrentMap.put("storeInfo", shopInfo);
concurrentMap.put("distance", distance);