This commit is contained in:
gaowdong 2025-04-16 17:57:24 +08:00
parent 65a862121e
commit d39356eddb
19 changed files with 490 additions and 38 deletions

View File

@ -3,6 +3,7 @@ package com.bonus.canteen.core.menu.mapper;
import java.util.List;
import com.bonus.canteen.core.menu.domain.MenuRecipeDishes;
import org.apache.ibatis.annotations.Param;
/**
* 菜品计划菜品关联Mapper接口
@ -43,6 +44,10 @@ public interface MenuRecipeDishesMapper {
*/
public int updateMenuRecipeDishes(MenuRecipeDishes menuRecipeDishes);
public int reduceMenuRecipeDishesSupplyNum(@Param("dish") MenuRecipeDishes menuRecipeDishes, @Param("quantity") Integer quantity);
public int addMenuRecipeDishesSupplyNum(@Param("dish")MenuRecipeDishes menuRecipeDishes, @Param("quantity") Integer quantity);
/**
* 删除菜品计划菜品关联
*

View File

@ -42,6 +42,17 @@ public interface IMenuRecipeDishesService {
*/
public int updateMenuRecipeDishes(MenuRecipeDishes menuRecipeDishes);
/**
* 修改菜品计划菜品关联供应量
*
* @param menuRecipeDishes 菜品计划菜品关联
* @return 结果
*/
public int reduceMenuRecipeDishesSupplyNum(MenuRecipeDishes menuRecipeDishes, Integer quantity);
public int addMenuRecipeDishesSupplyNum(MenuRecipeDishes menuRecipeDishes, Integer quantity);
/**
* 批量删除菜品计划菜品关联
*

View File

@ -2,8 +2,14 @@ package com.bonus.canteen.core.menu.service.impl;
import java.time.LocalDateTime;
import java.util.List;
import com.bonus.canteen.core.account.service.impl.AccSubServiceImpl;
import com.bonus.canteen.core.common.utils.RedisUtil;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.houqin.constant.GlobalConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.menu.mapper.MenuRecipeDishesMapper;
@ -18,6 +24,8 @@ import com.bonus.canteen.core.menu.service.IMenuRecipeDishesService;
*/
@Service
public class MenuRecipeDishesServiceImpl implements IMenuRecipeDishesService {
private static final Logger log = LoggerFactory.getLogger(MenuRecipeDishesServiceImpl.class);
@Autowired
private MenuRecipeDishesMapper menuRecipeDishesMapper;
@ -75,6 +83,62 @@ public class MenuRecipeDishesServiceImpl implements IMenuRecipeDishesService {
}
}
@Override
public int reduceMenuRecipeDishesSupplyNum(MenuRecipeDishes menuRecipeDishes, Integer quantity) {
if(menuRecipeDishes == null || menuRecipeDishes.getDetailId() == null || menuRecipeDishes.getDishesId() == null) {
throw new ServiceException("参数错误");
}
String lockKey = String.format("sc:menu_recipe_dishes_supply_num_tenant_%s_detailed_%s_dishes_id_%s",
GlobalConstants.TENANT_ID, menuRecipeDishes.getDetailId(), menuRecipeDishes.getDishesId());
try {
if (!RedisUtil.tryLock(lockKey, 10, 15)) {
throw new ServiceException("修改库存失败");
}
List<MenuRecipeDishes> menuRecipeDishesList = selectMenuRecipeDishesList(menuRecipeDishes);
if (menuRecipeDishesList == null || menuRecipeDishesList.isEmpty()) {
throw new ServiceException("菜品计划菜品关联不存在");
}
menuRecipeDishes = menuRecipeDishesList.get(0);
if(menuRecipeDishes.getSurplusNum() < quantity) {
throw new ServiceException("菜品供应量不足");
}
return menuRecipeDishesMapper.reduceMenuRecipeDishesSupplyNum(menuRecipeDishes, quantity);
} catch (Exception e) {
log.error("修改菜谱菜品供应量失败", e);
throw new ServiceException("修改菜谱菜品供应量失败");
}finally {
try {
RedisUtil.safeUnLock(lockKey);
} catch (Exception ex) {
log.error("账户操作解锁异常", ex);
}
}
}
@Override
public int addMenuRecipeDishesSupplyNum(MenuRecipeDishes menuRecipeDishes, Integer quantity) {
if(menuRecipeDishes == null || menuRecipeDishes.getDetailId() == null || menuRecipeDishes.getDishesId() == null) {
throw new ServiceException("参数错误");
}
String lockKey = String.format("sc:menu_recipe_dishes_supply_num_tenant_%s_detailed_%s_dishes_id_%s",
GlobalConstants.TENANT_ID, menuRecipeDishes.getDetailId(), menuRecipeDishes.getDishesId());
try {
if (!RedisUtil.tryLock(lockKey, 10, 15)) {
throw new ServiceException("账户有交易正在进行中");
}
return menuRecipeDishesMapper.addMenuRecipeDishesSupplyNum(menuRecipeDishes, quantity);
} catch (Exception e) {
log.error("修改菜谱菜品供应量失败", e);
throw new ServiceException("修改菜谱菜品供应量失败");
}finally {
try {
RedisUtil.safeUnLock(lockKey);
} catch (Exception ex) {
log.error("账户操作解锁异常", ex);
}
}
}
/**
* 批量删除菜品计划菜品关联
*

View File

@ -3,6 +3,8 @@ package com.bonus.canteen.core.order.business;
import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.account.domain.vo.AccInfoDetailsVO;
import com.bonus.canteen.core.account.service.IAccInfoService;
import com.bonus.canteen.core.menu.domain.MenuRecipeDishes;
import com.bonus.canteen.core.menu.service.IMenuRecipeDishesService;
import com.bonus.canteen.core.order.domain.OrderDetail;
import com.bonus.canteen.core.order.domain.OrderInfo;
import com.bonus.canteen.core.order.domain.param.OrderAddParam;
@ -23,6 +25,9 @@ public class OrderBusiness {
private IOrderDetailService orderDetailService;
@Autowired
private OrderInfoMapper orderInfoMapper;
@Autowired
private IMenuRecipeDishesService menuRecipeDishesService;
@Transactional(rollbackFor = Exception.class)
public List<OrderInfo> orderPlaceHandler(OrderAddParam orderAddParam) {
AccInfoDetailsVO accInfoVO = this.accInfoService.queryAccInfoByUserId(orderAddParam.getUserId());
@ -35,7 +40,26 @@ public class OrderBusiness {
orderInfoList.forEach(orderInfo -> {
List<OrderDetail> orderDetailList = orderInfo.getOrderDetailList();
orderDetailService.batchInsertOrderDetail(orderDetailList);
reduceMenuDishSupplyNum(orderDetailList);
});
return orderInfoList;
}
public void reduceMenuDishSupplyNum(List<OrderDetail> orderDetailList) {
for(OrderDetail orderDetail : orderDetailList) {
MenuRecipeDishes menuRecipeDishes = new MenuRecipeDishes();
menuRecipeDishes.setDetailId(orderDetail.getDetailId());
menuRecipeDishes.setDishesId(orderDetail.getGoodsId());
menuRecipeDishesService.reduceMenuRecipeDishesSupplyNum(menuRecipeDishes, orderDetail.getQuantity());
}
}
public void addMenuDishSupplyNum(List<OrderDetail> orderDetailList) {
for(OrderDetail orderDetail : orderDetailList) {
MenuRecipeDishes menuRecipeDishes = new MenuRecipeDishes();
menuRecipeDishes.setDetailId(orderDetail.getDetailId());
menuRecipeDishes.setDishesId(orderDetail.getGoodsId());
menuRecipeDishesService.addMenuRecipeDishesSupplyNum(menuRecipeDishes, orderDetail.getQuantity());
}
}
}

View File

@ -77,7 +77,7 @@ public class OrderInfoController extends BaseController
/**
* 新增保存订单
*/
@SysLog(title = "", module = "订单", businessType = OperaType.INSERT)
@SysLog(title = "", module = "订单", businessType = OperaType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(OrderAddParam orderAddParam)
@ -94,6 +94,15 @@ public class OrderInfoController extends BaseController
return AjaxResult.success();
}
@SysLog(title = "付款", module = "订单", businessType = OperaType.INSERT)
@PostMapping("/pay/{orderId}")
@ResponseBody
public AjaxResult pay(@PathVariable Long orderId)
{
orderInfoService.pay(orderId);
return AjaxResult.success();
}
/**
* 修改订单
*/

View File

@ -1,9 +1,13 @@
package com.bonus.canteen.core.order.controller;
import java.util.List;
import java.util.Objects;
import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.order.domain.OrderShoppingCart;
import com.bonus.canteen.core.order.domain.param.OrderShoppingCartQueryParam;
import com.bonus.canteen.core.order.domain.param.ShoppingCartDelParam;
import com.bonus.canteen.core.order.domain.vo.OrderShoppingCartVO;
import com.bonus.canteen.core.order.service.IOrderShoppingCartService;
import com.bonus.canteen.core.order.utils.ShoppingCartParamChecker;
import com.bonus.common.core.exception.ServiceException;
@ -21,6 +25,7 @@ import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
/**
* 订单购物车Controller
@ -40,11 +45,11 @@ public class OrderShoppingCartController extends BaseController
*/
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(@RequestBody OrderShoppingCart orderShoppingCart)
public TableDataInfo list(@RequestBody OrderShoppingCartQueryParam orderShoppingCart)
{
ShoppingCartParamChecker.listCheck(orderShoppingCart);
startPage();
List<OrderShoppingCart> list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart);
List<OrderShoppingCartVO> list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart);
return getDataTable(list);
}
@ -54,10 +59,10 @@ public class OrderShoppingCartController extends BaseController
@SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.EXPORT)
@PostMapping("/export")
@ResponseBody
public void export(OrderShoppingCart orderShoppingCart, HttpServletResponse response)
public void export(OrderShoppingCartQueryParam orderShoppingCart, HttpServletResponse response)
{
List<OrderShoppingCart> list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart);
ExcelUtil<OrderShoppingCart> util = new ExcelUtil<OrderShoppingCart>(OrderShoppingCart.class);
List<OrderShoppingCartVO> list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart);
ExcelUtil<OrderShoppingCartVO> util = new ExcelUtil<OrderShoppingCartVO>(OrderShoppingCartVO.class);
util.exportExcel(response, list, "订单购物车数据");
}
@ -97,14 +102,14 @@ public class OrderShoppingCartController extends BaseController
/**
* 删除订单购物车
*/
@SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.DELETE)
@SysLog(title = "订单购物车删除", module = "订单-订单详情", businessType = OperaType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(@RequestBody List<Long> shoppingCartIds)
public AjaxResult remove(@RequestBody ShoppingCartDelParam param)
{
if(CollUtil.isEmpty(shoppingCartIds)) {
if(Objects.isNull(param) || CollUtil.isEmpty(param.getShoppingCartIds())) {
throw new ServiceException("购物车餐品ID为空");
}
return toAjax(orderShoppingCartService.deleteOrderShoppingCartByShoppingCartIds(shoppingCartIds));
return toAjax(orderShoppingCartService.deleteOrderShoppingCartByShoppingCartIds(param.getShoppingCartIds()));
}
}

View File

@ -0,0 +1,18 @@
package com.bonus.canteen.core.order.domain;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class MenuDishCheckDTO {
/** 食堂id */
private Long canteenId;
/** 档口id */
private Long stallId;
/** 供应日期 */
private String applyDate;
/** 适用类型 */
private String applyType;
}

View File

@ -68,7 +68,7 @@ public class OrderShoppingCart extends BaseEntity
/** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */
@Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵")
private Long mealtimeType;
private Integer mealtimeType;
public void setShoppingCartId(Long shoppingCartId)
{
@ -190,12 +190,12 @@ public class OrderShoppingCart extends BaseEntity
return orderDate;
}
public void setMealtimeType(Long mealtimeType)
public void setMealtimeType(Integer mealtimeType)
{
this.mealtimeType = mealtimeType;
}
public Long getMealtimeType()
public Integer getMealtimeType()
{
return mealtimeType;
}

View File

@ -0,0 +1,34 @@
package com.bonus.canteen.core.order.domain.param;
import com.bonus.common.core.annotation.Excel;
import com.bonus.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
import java.util.List;
/**
* 订单购物车对象 order_shopping_cart
*
* @author ruoyi
* @date 2025-04-14
*/
@Data
public class OrderShoppingCartQueryParam
{
/** 食堂id */
private Long canteenId;
/** 档口id */
private Long stallId;
/** 订单类型 */
private Integer orderType;
/** 菜谱日期 yyyy-MM-dd */
private List<String> menuDateList;
}

View File

@ -0,0 +1,10 @@
package com.bonus.canteen.core.order.domain.param;
import lombok.Data;
import java.util.List;
@Data
public class ShoppingCartDelParam {
private List<Long> shoppingCartIds;
}

View File

@ -0,0 +1,76 @@
package com.bonus.canteen.core.order.domain.vo;
import com.bonus.common.core.annotation.Excel;
import com.bonus.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
/**
* 订单购物车对象 order_shopping_cart
*
* @author ruoyi
* @date 2025-04-14
*/
@Data
public class OrderShoppingCartVO extends BaseEntity
{
/** 主键 */
private Long shoppingCartId;
/** 人员id */
@Excel(name = "人员id")
private Long userId;
/** 菜谱id */
@Excel(name = "菜谱id")
private Long menuId;
/** 食堂id */
@Excel(name = "食堂id")
private Long canteenId;
/** 档口id */
@Excel(name = "档口id")
private Long stallId;
/** 商品菜品id */
@Excel(name = "商品菜品id")
private Long goodsId;
/** 商品菜品名称 */
@Excel(name = "商品菜品名称")
private String goodsName;
/** 商品菜品图片路径 */
@Excel(name = "商品菜品图片路径")
private String goodsImgUrl;
/** 数量/重量 */
@Excel(name = "数量/重量")
private Integer quantity;
/** 订单类型 */
@Excel(name = "订单类型")
private Integer orderType;
/** 明细类别 1 菜品 2 套餐 3 商品 4 按键 5 补扣 6 报餐 */
@Excel(name = "明细类别 1 菜品 2 套餐 3 商品 4 按键 5 补扣 6 报餐")
private Integer detailType;
/** 订单日期 yyyy-MM-dd */
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Excel(name = "订单日期 yyyy-MM-dd", width = 30, dateFormat = "yyyy-MM-dd")
private Date orderDate;
/** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */
@Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵")
private Integer mealtimeType;
@Excel(name = "餐次类型 0-已失效 1-未失效")
private Integer isValid;
}

View File

@ -0,0 +1,58 @@
package com.bonus.canteen.core.order.module;
import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.menu.domain.MenuRecipe;
import com.bonus.canteen.core.menu.enums.MenuRecipeSortEnum;
import com.bonus.canteen.core.menu.service.IMenuRecipeService;
import com.bonus.canteen.core.menu.vo.MenuRecipeDetailsVO;
import com.bonus.canteen.core.menu.vo.MenuRecipeDishesVO;
import com.bonus.canteen.core.menu.vo.MenuRecipeMealtimeTypeVO;
import com.bonus.canteen.core.menu.vo.MenuRecipeVO;
import com.bonus.canteen.core.order.domain.MenuDishCheckDTO;
import com.bonus.common.core.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class MenuModule {
@Autowired
private IMenuRecipeService menuRecipeService;
public Map<Integer, List<MenuRecipeDishesVO>> getMenuRecipeDish(MenuDishCheckDTO menuDishCheckDTO) {
MenuRecipe menuRecipe = new MenuRecipe();
menuRecipe.setApplyDate(menuDishCheckDTO.getApplyDate());
menuRecipe.setCanteenId(menuDishCheckDTO.getCanteenId());
menuRecipe.setStallId(menuDishCheckDTO.getStallId());
menuRecipe.setKey(menuDishCheckDTO.getApplyType());
Map<Integer, List<MenuRecipeDishesVO>> mealTimeTypeMap = new HashMap<>();
List<MenuRecipeVO> menuRecipeList = menuRecipeService.selectMenuRecipeList(menuRecipe);
if (CollUtil.isNotEmpty(menuRecipeList) && menuRecipeList.size() == 1) {
List<MenuRecipeDetailsVO> menuRecipeDetailsVOList = menuRecipeList.get(0).getDetail();
if(CollUtil.isNotEmpty(menuRecipeDetailsVOList) && menuRecipeDetailsVOList.size() == 1) {
List<MenuRecipeMealtimeTypeVO> menuRecipeMealtimeTypeVOS = menuRecipeDetailsVOList.get(0).getDetails();
if(CollUtil.isNotEmpty(menuRecipeMealtimeTypeVOS)) {
Integer mealType = null;
List<MenuRecipeDishesVO> dishsIdList = new ArrayList<>();
for (MenuRecipeMealtimeTypeVO menuRecipeMealtimeTypeVO : menuRecipeMealtimeTypeVOS) {
mealType = menuRecipeMealtimeTypeVO.getMealtimeType();
if(CollUtil.isNotEmpty(menuRecipeMealtimeTypeVO.getDishesList())) {
dishsIdList.addAll(menuRecipeMealtimeTypeVO.getDishesList());
}
}
if(Objects.nonNull(mealType)) {
mealTimeTypeMap.put(mealType, dishsIdList);
}
}else {
throw new ServiceException("菜谱信息异常");
}
}else {
throw new ServiceException("菜谱信息异常");
}
}else {
throw new ServiceException("菜谱信息异常");
}
return mealTimeTypeMap;
}
}

View File

@ -63,4 +63,5 @@ public interface IOrderInfoService
public int deleteOrderInfoByOrderId(Long orderId);
public void refund(Long orderId);
public void pay(Long orderId);
}

View File

@ -1,6 +1,8 @@
package com.bonus.canteen.core.order.service;
import com.bonus.canteen.core.order.domain.OrderShoppingCart;
import com.bonus.canteen.core.order.domain.param.OrderShoppingCartQueryParam;
import com.bonus.canteen.core.order.domain.vo.OrderShoppingCartVO;
import java.util.List;
@ -26,7 +28,7 @@ public interface IOrderShoppingCartService
* @param orderShoppingCart 订单购物车
* @return 订单购物车集合
*/
public List<OrderShoppingCart> selectOrderShoppingCartList(OrderShoppingCart orderShoppingCart);
public List<OrderShoppingCartVO> selectOrderShoppingCartList(OrderShoppingCartQueryParam orderShoppingCart);
/**
* 新增订单购物车

View File

@ -42,6 +42,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@ -108,6 +109,33 @@ public class OrderInfoServiceImpl implements IOrderInfoService
throw new ServiceException("请勿重复提交订单");
}
List<OrderInfo> orderInfoList = orderBusiness.orderPlaceHandler(orderAddParam);
orderPay(orderInfoList);
return 1;
}
@Override
public void pay(Long orderId) {
if(Objects.isNull(orderId) || orderId <= 0) {
throw new ServiceException("订单ID不能为空");
}
OrderInfo orderInfo = selectOrderInfoByOrderId(orderId);
if(Objects.isNull(orderInfo)) {
throw new ServiceException("订单不存在");
}
String payOrderKey = String.format("sc:order_pay_orderId_%s", orderId);
if (!RedisUtil.setNx(payOrderKey, 1, 2)) {
log.info("退单处理中:{}", payOrderKey);
throw new ServiceException("退单处理中");
}
if(orderInfo.getOrderState().equals(OrderRefundStateEnum.FINISH.getKey())) {
throw new ServiceException("订单已退");
}
if(PayStateEnum.isUnPay(orderInfo.getPayState())) {
List<OrderInfo> orderInfoList = new ArrayList<>();
orderInfoList.add(orderInfo);
orderPay(orderInfoList);
}
}
private void orderPay(List<OrderInfo> orderInfoList) {
OrderPayDTO orderPayDTO = buildOrderPayDTO(orderInfoList);
try {
List<AccWalletInfo> walletInfoList = accWalletInfoService.selectAccWalletInfoByUserId(orderPayDTO.getUserId());
@ -140,14 +168,13 @@ public class OrderInfoServiceImpl implements IOrderInfoService
orderPayResultDTO.setUpdateBy(SecurityUtils.getUsername());
orderInfoMapper.updateOrderPayResult(orderPayResultDTO);
try {
DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(Math.toIntExact(orderAddParam.getUserId()),"update");
DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(Math.toIntExact(orderInfoList.get(0).getUserId()),"update");
String jsonString = JacksonUtil.writeValueAsString(bean);
log.info("账户变动发送mq内容{}", jsonString);
MqUtil.pushToTenantAllDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_PERSONAL_CONFIG_V4);
} catch (Exception e) {
log.error("发送MQ消息失败", e);
}
return 1;
}
private BigDecimal getWalletBalance(List<AccWalletInfo> walletInfoList, AccWalletIdEnum walletIdEnum) {
@ -233,6 +260,7 @@ public class OrderInfoServiceImpl implements IOrderInfoService
}
@Override
@Transactional(rollbackFor = {Exception.class})
public void refund(Long orderId) {
if(Objects.isNull(orderId) || orderId <= 0) {
throw new ServiceException("订单ID不能为空");
@ -287,6 +315,7 @@ public class OrderInfoServiceImpl implements IOrderInfoService
orderDetail.setDetailState(OrderDetailStateEnum.REFUNDED.getKey());
orderDetailService.updateOrderDetail(orderDetail);
}
orderBusiness.addMenuDishSupplyNum(orderDetailList);
try {
DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(Math.toIntExact(orderInfo.getUserId()),"update");
String jsonString = JacksonUtil.writeValueAsString(bean);
@ -295,6 +324,14 @@ public class OrderInfoServiceImpl implements IOrderInfoService
} catch (Exception e) {
log.error("发送MQ消息失败", e);
}
}else {
OrderInfo refundOrderInfo = new OrderInfo();
refundOrderInfo.setOrderId(orderId);
refundOrderInfo.setOrderRefundState(OrderRefundStateEnum.FINISH.getKey());
refundOrderInfo.setOrderState(OrderStateEnum.CANCEL.getKey());
refundOrderInfo.setUpdateBy(SecurityUtils.getUsername());
refundOrderInfo.setUpdateTime(DateUtils.getNowDate());
orderInfoMapper.updateOrderInfo(refundOrderInfo);
}
}
}

View File

@ -1,12 +1,25 @@
package com.bonus.canteen.core.order.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.bonus.canteen.core.menu.enums.MenuRecipeSortEnum;
import com.bonus.canteen.core.menu.service.IMenuRecipeService;
import com.bonus.canteen.core.menu.vo.MenuRecipeDishesVO;
import com.bonus.canteen.core.order.domain.MenuDishCheckDTO;
import com.bonus.canteen.core.order.domain.OrderShoppingCart;
import com.bonus.canteen.core.order.domain.param.OrderShoppingCartQueryParam;
import com.bonus.canteen.core.order.domain.vo.OrderShoppingCartVO;
import com.bonus.canteen.core.order.mapper.OrderShoppingCartMapper;
import com.bonus.canteen.core.order.module.MenuModule;
import com.bonus.canteen.core.order.service.IOrderShoppingCartService;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.security.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -21,6 +34,8 @@ public class OrderShoppingCartServiceImpl implements IOrderShoppingCartService
{
@Autowired
private OrderShoppingCartMapper orderShoppingCartMapper;
@Autowired
private MenuModule menuModule;
/**
* 查询订单购物车
@ -41,11 +56,68 @@ public class OrderShoppingCartServiceImpl implements IOrderShoppingCartService
* @return 订单购物车
*/
@Override
public List<OrderShoppingCart> selectOrderShoppingCartList(OrderShoppingCart orderShoppingCart)
{
return orderShoppingCartMapper.selectOrderShoppingCartList(orderShoppingCart);
public List<OrderShoppingCartVO> selectOrderShoppingCartList(OrderShoppingCartQueryParam orderShoppingCart) {
OrderShoppingCart orderShoppingCartQuery = new OrderShoppingCart();
orderShoppingCartQuery.setCanteenId(orderShoppingCart.getCanteenId());
orderShoppingCartQuery.setStallId(orderShoppingCart.getStallId());
orderShoppingCartQuery.setOrderType(orderShoppingCart.getOrderType());
orderShoppingCartQuery.setUserId(SecurityUtils.getUserId());
List<OrderShoppingCart> orderShoppingCartList = orderShoppingCartMapper.selectOrderShoppingCartList(orderShoppingCartQuery);
if (CollUtil.isEmpty(orderShoppingCartList)) {
return new ArrayList<>();
}
MenuDishCheckDTO menuDishCheckDTO = new MenuDishCheckDTO();
menuDishCheckDTO.setCanteenId(orderShoppingCart.getCanteenId());
menuDishCheckDTO.setStallId(orderShoppingCart.getStallId());
menuDishCheckDTO.setApplyType(MenuRecipeSortEnum.MOBILE_RESERVE.getKey().toString());
Map<String, List<OrderShoppingCart>> groupedByOrderDate = orderShoppingCartList.stream()
.collect(Collectors.groupingBy(cart -> DateUtil.format(cart.getOrderDate(), "yyyy-MM-dd")));
List<OrderShoppingCartVO> orderShoppingCartVOList = new ArrayList<>();
for (Map.Entry<String, List<OrderShoppingCart>> entry : groupedByOrderDate.entrySet()) {
String orderDateStr = entry.getKey();
List<OrderShoppingCart> carts = entry.getValue();
String filteredOrderDate = orderShoppingCart.getMenuDateList().stream().filter(orderDate -> orderDate.equals(orderDateStr))
.findFirst().orElse(null);
menuDishCheckDTO.setApplyDate(orderDateStr);
Map<Integer, List<MenuRecipeDishesVO>> menuRecipeDishMap = menuModule.getMenuRecipeDish(menuDishCheckDTO);
for (OrderShoppingCart shoppingCart : carts) {
OrderShoppingCartVO shoppingCartVO = convertToOrderShoppingCartVO(shoppingCart, menuRecipeDishMap);
if(filteredOrderDate == null) {
shoppingCartVO.setIsValid(0);
}
orderShoppingCartVOList.add(shoppingCartVO);
}
}
return orderShoppingCartVOList;
}
private OrderShoppingCartVO convertToOrderShoppingCartVO(OrderShoppingCart shoppingCart,
Map<Integer, List<MenuRecipeDishesVO>> menuRecipeDishMap) {
OrderShoppingCartVO shoppingCartVO = new OrderShoppingCartVO();
BeanUtils.copyProperties(shoppingCart, shoppingCartVO);
shoppingCartVO.setIsValid(0);
List<MenuRecipeDishesVO> menuRecipeDishes = menuRecipeDishMap.get(shoppingCart.getMealtimeType());
if (CollUtil.isNotEmpty(menuRecipeDishes)) {
for (MenuRecipeDishesVO menuRecipeDishesVO : menuRecipeDishes) {
if (shoppingCart.getGoodsId().toString().equals(menuRecipeDishesVO.getDishesId())) {
shoppingCartVO.setIsValid(1);
break;
}
}
}
return shoppingCartVO;
}
/**
* 新增订单购物车
*

View File

@ -1,25 +1,29 @@
package com.bonus.canteen.core.order.utils;
import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.order.constants.OrderDetailTypeEnum;
import com.bonus.canteen.core.order.constants.OrderTypeEnum;
import com.bonus.canteen.core.order.domain.OrderShoppingCart;
import com.bonus.canteen.core.order.domain.param.OrderShoppingCartQueryParam;
import com.bonus.common.core.exception.ServiceException;
import java.util.List;
public class ShoppingCartParamChecker {
public static void listCheck(OrderShoppingCart orderShoppingCart) {
public static void listCheck(OrderShoppingCartQueryParam orderShoppingCart) {
checkOrderShoppingCart(orderShoppingCart);
checkUserId(orderShoppingCart);
checkCanteenId(orderShoppingCart);
checkStallId(orderShoppingCart);
checkOrderType(orderShoppingCart);
checkCanteenId(orderShoppingCart.getCanteenId());
checkStallId(orderShoppingCart.getStallId());
checkOrderType(orderShoppingCart.getOrderType());
checkMenuDateList(orderShoppingCart.getMenuDateList());
}
public static void addCheck(OrderShoppingCart orderShoppingCart) {
checkOrderShoppingCart(orderShoppingCart);
checkUserId(orderShoppingCart);
checkGoodsId(orderShoppingCart);
checkQuantity(orderShoppingCart);
checkCanteenId(orderShoppingCart);
checkStallId(orderShoppingCart);
checkCanteenId(orderShoppingCart.getCanteenId());
checkStallId(orderShoppingCart.getStallId());
checkOrderDate(orderShoppingCart);
checkMealtimeType(orderShoppingCart);
checkDetailType(orderShoppingCart);
@ -32,7 +36,7 @@ public class ShoppingCartParamChecker {
checkQuantity(orderShoppingCart);
}
private static void checkOrderShoppingCart(OrderShoppingCart orderShoppingCart) {
private static void checkOrderShoppingCart(Object orderShoppingCart) {
if (orderShoppingCart == null) {
throw new ServiceException("订单购物车对象为空");
}
@ -61,14 +65,14 @@ public class ShoppingCartParamChecker {
}
}
private static void checkCanteenId(OrderShoppingCart orderShoppingCart) {
if (orderShoppingCart.getCanteenId() == null) {
private static void checkCanteenId(Long canteenId) {
if (canteenId == null) {
throw new ServiceException("食堂ID为空");
}
}
private static void checkStallId(OrderShoppingCart orderShoppingCart) {
if (orderShoppingCart.getStallId() == null) {
private static void checkStallId(Long stallId) {
if (stallId == null) {
throw new ServiceException("档口ID为空");
}
}
@ -99,13 +103,18 @@ public class ShoppingCartParamChecker {
throw new ServiceException("菜谱ID为空");
}
}
private static void checkOrderType(OrderShoppingCart orderShoppingCart) {
if (orderShoppingCart.getOrderType() == null) {
private static void checkOrderType(Integer orderType) {
if (orderType == null) {
throw new ServiceException("订单类型为空");
}
if(OrderTypeEnum.isValidKey(orderShoppingCart.getOrderType())) {
if(OrderTypeEnum.isValidKey(orderType)) {
throw new ServiceException("订单类型错误");
}
}
private static void checkMenuDateList(List<String> menuDateList) {
if (CollUtil.isEmpty(menuDateList)) {
throw new ServiceException("菜谱日期列表为空");
}
}
}

View File

@ -24,5 +24,8 @@ public enum PayStateEnum {
public String getDesc() {
return this.desc;
}
public static boolean isUnPay(Integer key) {
return !UN_PAY.getKey().equals(key);
}
}

View File

@ -14,9 +14,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="surplusNum" column="surplus_num" />
<result property="restrictNum" column="restrict_num" />
<result property="salePrice" column="sale_price" />
<result property="saleStart" column="sale_start" />
<result property="saleEnd" column="sale_end" />
<result property="chefId" column="chef_id" />
<!-- <result property="saleStart" column="sale_start" />-->
<!-- <result property="saleEnd" column="sale_end" />-->
<!-- <result property="chefId" column="chef_id" />-->
<result property="recommendFlag" column="recommend_flag" />
<result property="sortNum" column="sort_num" />
<result property="revision" column="revision" />
@ -24,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<!-- <result property="remark" column="remark" />-->
</resultMap>
<sql id="selectMenuRecipeDishesVo">
@ -132,6 +132,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</update>
<update id="reduceMenuRecipeDishesSupplyNum">
update menu_recipe_dishes set
sale_num = sale_num + #{quantity},
surplus_num = surplus_num - #{quantity}
where detail_id = #{dish.detailId} and dishes_id = #{dish.dishesId}
</update>
<update id="addMenuRecipeDishesSupplyNum">
update menu_recipe_dishes set
sale_num = sale_num - #{quantity},
surplus_num = surplus_num + #{quantity}
where detail_id = #{dish.detailId} and dishes_id = #{dish.dishesId}
</update>
<delete id="deleteMenuRecipeDishesById" parameterType="Long">
delete from menu_recipe_dishes where id = #{id}
</delete>