订单菜品限购

This commit is contained in:
gaowdong 2025-06-23 16:38:02 +08:00
parent 5c74391993
commit 87bc3002ab
5 changed files with 13 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package com.bonus.canteen.core.cook.service;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
@ -68,7 +69,7 @@ public interface ICookRecipeDishesService {
* @return 结果
*/
public int reduceMenuRecipeDishesSupplyNum(CookRecipeDishes cookRecipeDishes, CookRecipeDetail menuRecipeDetail,
Integer quantity, Long userId, Date orderTime);
Integer quantity, Long userId, LocalDate orderDate);
public int addMenuRecipeDishesSupplyNum(CookRecipeDishes cookRecipeDishes, Integer quantity);

View File

@ -1,5 +1,6 @@
package com.bonus.canteen.core.cook.service.impl;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@ -116,7 +117,7 @@ public class CookRecipeDishesServiceImpl implements ICookRecipeDishesService {
@Override
public int reduceMenuRecipeDishesSupplyNum(CookRecipeDishes cookRecipeDishes, CookRecipeDetail menuRecipeDetail,
Integer quantity, Long userId, Date orderTime) {
Integer quantity, Long userId, LocalDate orderDate) {
log.info("扣减库存入参:{},数量:{}", JacksonUtil.writeValueAsString(cookRecipeDishes), quantity);
if(cookRecipeDishes == null || cookRecipeDishes.getRecipeDetailId() == null || cookRecipeDishes.getDishesId() == null) {
throw new ServiceException("参数错误");
@ -135,7 +136,7 @@ public class CookRecipeDishesServiceImpl implements ICookRecipeDishesService {
if(cookRecipeDishes.getRemanentNum() < quantity) {
throw new ServiceException("菜品供应量不足");
}
Long sellNumCount = orderInfoMapper.goodsSellNumCount(menuRecipeDetail, userId, orderTime, cookRecipeDishes.getDishesId());
Long sellNumCount = orderInfoMapper.goodsSellNumCount(menuRecipeDetail, userId, orderDate, cookRecipeDishes.getDishesId());
log.info("菜品销售数量:{}", sellNumCount);
if(Objects.nonNull(cookRecipeDishes.getLimitNum()) && (sellNumCount > cookRecipeDishes.getLimitNum())) {
throw new ServiceException("菜品超过个人限购数量");

View File

@ -48,6 +48,7 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
@ -84,13 +85,13 @@ public class OrderBusiness {
List<OrderDetail> orderDetailList = orderInfo.getOrderDetailList();
orderDetailList.forEach(orderDetail -> orderDetail.setOrderId(orderInfo.getOrderId()));
orderDetailService.batchInsertOrderDetail(orderDetailList);
reduceMenuDishSupplyNum(orderDetailList, orderInfo.getUserId(), orderInfo.getOrderTime());
reduceMenuDishSupplyNum(orderDetailList, orderInfo.getUserId(), orderInfo.getOrderDate());
});
}
return orderInfoList;
}
public void reduceMenuDishSupplyNum(List<OrderDetail> orderDetailList, Long userId, Date orderTime) {
public void reduceMenuDishSupplyNum(List<OrderDetail> orderDetailList, Long userId, LocalDate orderDate) {
log.info("订单扣减库存入参:{}", JacksonUtil.writeValueAsString(orderDetailList));
for(OrderDetail orderDetail : orderDetailList) {
if(OrderDetailTypeEnum.KEYAMOUNT.getKey().equals(orderDetail.getDetailType())) {
@ -111,7 +112,7 @@ public class OrderBusiness {
menuRecipeDishes.setRecipeDetailId(cookRecipeDetails.get(0).getRecipeDetailId());
menuRecipeDishes.setDishesId(orderDetail.getGoodsId());
cookRecipeDishesService.reduceMenuRecipeDishesSupplyNum(menuRecipeDishes, menuRecipeDetail,
orderDetail.getQuantity(), userId , orderTime);
orderDetail.getQuantity(), userId , orderDate);
}
}

View File

@ -10,6 +10,7 @@ import com.bonus.canteen.core.order.domain.param.OrderSellNumCountParam;
import com.bonus.canteen.core.order.domain.param.OrderWriteOffParam;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
@ -78,7 +79,7 @@ public interface OrderInfoMapper
public Long goodsSellNumCount(@Param("param") CookRecipeDetail param,
@Param("userId")Long userId,
@Param("orderTime")Date orderTime,
@Param("orderDate")LocalDate orderDate,
@Param("dishesId")Long dishesId);
}

View File

@ -478,7 +478,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and od.order_date = #{param.applyDate}
and oi.mealtime_type = #{param.mealtimeType}
and od.goods_id = #{dishesId}
and oi.order_time >= #{orderTime ,jdbcType=TIMESTAMP} - 7
and oi.order_state != 3
and oi.order_time <![CDATA[ >= ]]> DATE_SUB(#{orderDate}, INTERVAL 7 DAY)
</select>
</mapper>