购物车修改

This commit is contained in:
gaowdong 2025-02-21 10:17:22 +08:00
parent 4a6b44d2cb
commit 97167a7bd9
7 changed files with 143 additions and 99 deletions

View File

@ -74,10 +74,10 @@ public class AllocCanteenApi {
// return (AllocArea)this.allocAreaService.getOne((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(AllocArea.class).eq(AllocArea::getAreaNum, "99")).last(" limit 1 "));
// }
// }
//
// public AllocCanteen getAllocCanteen(Long canteenId) {
// return this.allocCanteenService.getAllocCanteenCache(canteenId);
// }
public AllocCanteen getAllocCanteen(Long canteenId) {
return this.allocCanteenService.getAllocCanteenCache(canteenId);
}
//
// public void checkCanteenBusinessState(Long canteenId, LocalTime checkTime) {
// if (!LeNumUtil.isValidId(canteenId)) {

View File

@ -15,4 +15,6 @@ public interface AllocCanteenService extends IService<AllocCanteen> {
List<AllocCanteenStallVO> listAllCanteenStall();
void checkAndDelReserveCanteen(List<AppletReserveCanteenVO> reserveCanteenList);
AllocCanteen getAllocCanteenCache(Long canteenId);
}

View File

@ -1,6 +1,9 @@
package com.bonus.core.allocation.canteen.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
@ -15,6 +18,8 @@ import com.bonus.core.allocation.canteen.service.AllocAreaService;
import com.bonus.core.allocation.canteen.service.AllocCanteenService;
import com.bonus.core.allocation.canteen.vo.AllocCanteenStallVO;
import com.bonus.core.common.enums.AllocCanteenTypeEnum;
import com.bonus.core.common.redis.RedisUtil;
import com.bonus.core.common.utils.TenantContextHolder;
import com.bonus.core.menu.vo.AppletReserveCanteenVO;
import com.bonus.core.menu.vo.AppletReserveStallVO;
import org.slf4j.Logger;
@ -133,4 +138,26 @@ public class AllocCanteenServiceImpl extends ServiceImpl<AllocCanteenMapper, All
}
}
}
public AllocCanteen getAllocCanteenCache(Long canteenId) {
if (ObjectUtil.isNull(canteenId)) {
return null;
} else {
String cacheKey = this.getCacheKey(canteenId);
String allocCanteenStr = RedisUtil.getString(cacheKey);
if (CharSequenceUtil.isNotBlank(allocCanteenStr)) {
return (AllocCanteen) JSONUtil.toBean(allocCanteenStr, AllocCanteen.class);
} else {
AllocCanteen allocCanteen = (AllocCanteen)this.getOne((Wrapper)Wrappers.lambdaQuery(AllocCanteen.class).eq(AllocCanteen::getCanteenId, canteenId));
allocCanteenStr = JSONUtil.toJsonStr(allocCanteen);
RedisUtil.setString(cacheKey, allocCanteenStr, 3600L);
return allocCanteen;
}
}
}
private String getCacheKey(Long canteenId) {
Long var10000 = TenantContextHolder.getTenantId();
return "yst:" + var10000 + ":alloc-canteen:" + canteenId;
}
}

View File

@ -2,16 +2,23 @@ package com.bonus.core.order.mobile.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.core.allocation.api.AllocCanteenApi;
import com.bonus.core.allocation.api.AllocStallApi;
import com.bonus.core.allocation.canteen.model.AllocCanteen;
import com.bonus.core.allocation.canteen.model.AllocStall;
import com.bonus.core.common.enums.AllocMealtimeTypeEnum;
import com.bonus.core.common.redis.RedisUtil;
import com.bonus.core.common.utils.JavaxValidateUtils;
import com.bonus.core.common.utils.LogUtil;
import com.bonus.core.menu.api.MenuRecipeApi;
import com.bonus.core.menu.dto.CheckDishesDto;
import com.bonus.core.menu.model.AllocMealtimeModel;
import com.bonus.core.menu.vo.CheckDishesVo;
import com.bonus.core.order.client.OrderModuleClient;
import com.bonus.core.order.client.po.MealtimeQueryParam;
import com.bonus.core.order.common.constants.DetailTypeEnum;
import com.bonus.core.order.common.constants.OrderCacheConstants;
import com.bonus.core.order.common.constants.OrderTips;
import com.bonus.core.order.common.constants.OrderTypeEnum;
import com.bonus.core.order.common.dto.OrderDetailPayDTO;
@ -32,6 +39,7 @@ import com.bonus.core.supermarket.model.SupermarketInfo;
import com.bonus.core.supermarket.vo.SupermarketNotRemovedProductListVO;
import com.bonus.i18n.I18n;
import com.bonus.utils.id.Id;
import org.redisson.api.RLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -39,8 +47,10 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.function.Function;
@Service
public class ShoppingCartBusinessImpl implements ShoppingCartBusiness {
@ -58,6 +68,14 @@ public class ShoppingCartBusinessImpl implements ShoppingCartBusiness {
@Autowired
@Lazy
protected MenuRecipeApi menuRecipeApi;
@Autowired
@Lazy
protected AllocCanteenApi allocCanteenApi;
@Autowired
@Lazy
protected AllocStallApi allocStallApi;
@Autowired
protected OrderModuleClient orderModuleClient;
@Override
public OrderShoppingCartAddResultVO add(OrderShoppingCartAddDTO addDTO) {
@ -65,12 +83,9 @@ public class ShoppingCartBusinessImpl implements ShoppingCartBusiness {
if (customVO != null) {
return customVO;
} else {
try{
this.checkSubmitParam(addDTO);
}catch (Exception e){
this.checkSubmitParam(addDTO);
RLock lock = RedisUtil.getLock(OrderCacheConstants.shoppingCartLockKey(addDTO.getCustId()));
}
// RLock lock = RedisUtil.getLock(OrderCacheConstants.shoppingCartLockKey(addDTO.getCustId()));
OrderShoppingCart entity;
try {
OrderShoppingCart sameShoppingCart = (OrderShoppingCart)this.orderShoppingCartService.listByCust((new OrderShoppingSearchDTO()).setCustId(addDTO.getCustId()).setOrderType(addDTO.getOrderType())).stream().filter((s) -> {
@ -89,13 +104,14 @@ public class ShoppingCartBusinessImpl implements ShoppingCartBusiness {
addDTO.setOrderDate((LocalDate)null);
addDTO.setMealtimeType((Integer)null);
}
this.orderShoppingCartService.insert(entity);
}
} finally {
try {
// if (lock.isHeldByCurrentThread() && lock.isLocked()) {
// lock.unlock();
// }
if (lock.isHeldByCurrentThread() && lock.isLocked()) {
lock.unlock();
}
} catch (Exception var11) {
log.error("解锁异常", var11);
}
@ -134,7 +150,7 @@ public class ShoppingCartBusinessImpl implements ShoppingCartBusiness {
JavaxValidateUtils.validate(searchDTO);
List<OrderShoppingCart> orderShoppingCarts = this.orderShoppingCartService.listByCust(searchDTO);
LogUtil.infoFieldsX("查询购物车_结果", orderShoppingCarts, OrderShoppingCart.logFields());
List<OrderShoppingCartListMobileVO> voList = (List)orderShoppingCarts.stream().map(OrderShoppingCartListMobileVO::of).collect(Collectors.toList());
List<OrderShoppingCartListMobileVO> voList = orderShoppingCarts.stream().map(OrderShoppingCartListMobileVO::of).collect(Collectors.toList());
if (CollUtil.isEmpty(voList)) {
return voList;
} else {
@ -146,24 +162,22 @@ public class ShoppingCartBusinessImpl implements ShoppingCartBusiness {
protected void fillVo(List<OrderShoppingCartListMobileVO> voList, Integer orderType, Long custId) {
if (!CollUtil.isEmpty(voList)) {
if (OrderTypeEnum.isShopCategory(orderType)) {
Map<Long, List<OrderShoppingCartListMobileVO>> voGroupBySupermarket = (Map)voList.stream().collect(Collectors.groupingBy(OrderShoppingCartListMobileVO::getCanteenId));
Map<Long, List<OrderShoppingCartListMobileVO>> voGroupBySupermarket = voList.stream().collect(Collectors.groupingBy(OrderShoppingCartListMobileVO::getCanteenId));
voGroupBySupermarket.forEach((supermarketId, vos) -> {
List<Long> goodsIds = (List)vos.stream().map(OrderShoppingCartListMobileVO::getGoodsDishesId).collect(Collectors.toList());
List<Long> goodsIds = vos.stream().map(OrderShoppingCartListMobileVO::getGoodsDishesId).collect(Collectors.toList());
SupermarketNotRemovedProductListDTO dto = new SupermarketNotRemovedProductListDTO();
dto.setSupermarketId(supermarketId);
dto.setMaterialIdList(goodsIds);
dto.setCustId(custId);
Map<Long, SupermarketNotRemovedProductListVO> productMap =null;
// (Map)this.supermarketApi.listNotRemovedProduct(dto).stream().collect(Collectors.toMap(SupermarketNotRemovedProductListVO::getMaterialId, Function.identity()));
Map<Long, SupermarketNotRemovedProductListVO> productMap = this.supermarketApi.listNotRemovedProduct(dto).stream().collect(Collectors.toMap(SupermarketNotRemovedProductListVO::getMaterialId, Function.identity()));
vos.forEach((s) -> {
s.fillSupermarketProductInfo((SupermarketNotRemovedProductListVO)productMap.get(s.getGoodsDishesId()));
s.fillSupermarketProductInfo(productMap.get(s.getGoodsDishesId()));
});
});
} else if (OrderTypeEnum.isCanteenCategory(orderType)) {
if (OrderTypeEnum.isCurrMealType(orderType)) {
voList.forEach((s) -> {
AllocMealtimeModel nowMealtime = null;
// this.orderModuleClient.mealtimeQuery(MealtimeQueryParam.ofAssignTime(LocalTime.now(), s.getCanteenId(), s.getStallId()));
AllocMealtimeModel nowMealtime = this.orderModuleClient.mealtimeQuery(MealtimeQueryParam.ofAssignTime(LocalTime.now(), s.getCanteenId(), s.getStallId()));
if (nowMealtime != null) {
s.setOrderDate(LocalDate.now());
s.setMealtimeType(nowMealtime.getMealtimeType());
@ -221,14 +235,12 @@ public class ShoppingCartBusinessImpl implements ShoppingCartBusiness {
if (LeNumUtil.isValidId(vo.getCanteenId())) {
if (!canteenNameMapById.containsKey(vo.getCanteenId())) {
if (OrderTypeEnum.isShopCategory(vo.getOrderType())) {
SupermarketInfo supermarketInfo = null;
// this.supermarketApi.getSupermarketInfoById(vo.getCanteenId());
SupermarketInfo supermarketInfo = this.supermarketApi.getSupermarketInfoById(vo.getCanteenId());
if (supermarketInfo != null) {
canteenNameMapById.put(vo.getCanteenId(), supermarketInfo.getSupermarketName());
}
} else {
AllocCanteen allocCanteen = null;
// this.allocCanteenApi.getAllocCanteen(vo.getCanteenId());
AllocCanteen allocCanteen = this.allocCanteenApi.getAllocCanteen(vo.getCanteenId());
if (allocCanteen != null) {
canteenNameMapById.put(vo.getCanteenId(), allocCanteen.getCanteenName());
}
@ -241,53 +253,52 @@ public class ShoppingCartBusinessImpl implements ShoppingCartBusiness {
if (LeNumUtil.isValidId(vo.getStallId())) {
AllocStall allocStall;
if (stallMapById.containsKey(vo.getStallId())) {
allocStall =null;
// this.allocStallApi.getAllocStall(vo.getStallId());
allocStall = this.allocStallApi.getAllocStall(vo.getStallId());
if (allocStall != null) {
stallMapById.put(vo.getStallId(), allocStall);
}
}
allocStall =null;
// this.allocStallApi.getAllocStall(vo.getStallId());
allocStall = this.allocStallApi.getAllocStall(vo.getStallId());
if (allocStall != null) {
vo.setStallName(allocStall.getStallName());
}
}
}
}
protected void checkSubmitParam(OrderShoppingCartAddDTO addDTO) throws Exception {
protected void checkSubmitParam(OrderShoppingCartAddDTO addDTO) {
JavaxValidateUtils.validate(addDTO);
if (!this.supportOrderTypes().contains(addDTO.getOrderType())) {
throw new Exception(I18n.getMessage("order.un-support-order-type", new Object[0]));
throw new ServiceException(I18n.getMessage("order.un-support-order-type", new Object[0]));
} else {
if (OrderTypeEnum.isCanteenCategory(addDTO.getOrderType())) {
if (addDTO.getOrderDate() == null || !LeNumUtil.isValidId(addDTO.getMealtimeType())) {
throw new Exception(I18n.getMessage("order.mobile.cart-need-date-mealtime", new Object[0]));
throw new ServiceException(I18n.getMessage("order.mobile.cart-need-date-mealtime", new Object[0]));
}
if (!DetailTypeEnum.isDishesCategory(addDTO.getDetailType())) {
throw new Exception(I18n.getMessage("order.un-support-detail-type", new Object[0]));
throw new ServiceException(I18n.getMessage("order.un-support-detail-type", new Object[0]));
}
if (!LeNumUtil.isValidId(addDTO.getMenuId())) {
throw new Exception(OrderTips.paramIllegal("menuId菜谱id"));
throw new ServiceException(OrderTips.paramIllegal("menuId菜谱id"));
}
if (!LeNumUtil.isValidId(addDTO.getCanteenId())) {
throw new Exception(OrderTips.paramIllegal("canteenId食堂id"));
throw new ServiceException(OrderTips.paramIllegal("canteenId食堂id"));
}
if (!LeNumUtil.isValidId(addDTO.getStallId())) {
throw new Exception(OrderTips.paramIllegal("stallId档口id"));
throw new ServiceException(OrderTips.paramIllegal("stallId档口id"));
}
} else if (OrderTypeEnum.isShopCategory(addDTO.getOrderType())) {
if (!DetailTypeEnum.isProductType(addDTO.getDetailType())) {
throw new Exception(I18n.getMessage("order.un-support-detail-type", new Object[0]));
throw new ServiceException(I18n.getMessage("order.un-support-detail-type", new Object[0]));
}
if (!LeNumUtil.isValidId(addDTO.getCanteenId())) {
throw new Exception(OrderTips.paramIllegal("canteenId超市id"));
throw new ServiceException(OrderTips.paramIllegal("canteenId超市id"));
}
}

View File

@ -21,6 +21,7 @@ import com.bonus.core.supermarket.mapper.SupermarketProductMapper;
import com.bonus.core.supermarket.model.SupermarketInfo;
import com.bonus.core.supermarket.po.GoodsBuyLimitModel;
import com.bonus.core.supermarket.po.WarehouseModel;
import com.bonus.core.supermarket.vo.SupermarketNotRemovedProductListVO;
import com.bonus.core.supermarket.vo.SupermarketProductInfoImageVO;
import com.bonus.core.supermarket.vo.SupermarketQueryProductInfoVO;
import com.bonus.i18n.I18n;
@ -32,6 +33,7 @@ import org.springframework.data.redis.core.RedisTemplate;
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.Iterator;
@ -321,29 +323,29 @@ public class SupermarketApi {
return this.supermarketProductMapper.getProductImg(goodsIdList);
}
// public List<SupermarketNotRemovedProductListVO> listNotRemovedProduct(SupermarketNotRemovedProductListDTO content) {
// log.info("[商超]_购物车_获取上架商品_入参:{}", content);
// if (!ObjectUtil.isEmpty(content.getSupermarketId()) && !CollUtil.isEmpty(content.getMaterialIdList())) {
// boolean ifRelateDrp = this.ifRelateDrp(content.getSupermarketId());
// List resultList;
// if (ifRelateDrp) {
// resultList = this.supermarketProductMapper.listNotRemovedProduct(content, 1);
// } else {
// resultList = this.supermarketProductMapper.listNotRemovedProduct(content, (Integer)null);
// }
//
// boolean ifSupermarketMember = this.ifSupermarketMember(content.getCustId(), content.getSupermarketId());
// if (!ifSupermarketMember) {
// resultList.forEach((s) -> {
// s.setPrefPrice((BigDecimal)null);
// });
// }
//
// return resultList;
// } else {
// throw new LeException(I18n.getMessage("supermarket.shop-cert-material-not-null", new Object[0]));
// }
// }
public List<SupermarketNotRemovedProductListVO> listNotRemovedProduct(SupermarketNotRemovedProductListDTO content) {
log.info("[商超]_购物车_获取上架商品_入参:{}", content);
if (!ObjectUtil.isEmpty(content.getSupermarketId()) && !CollUtil.isEmpty(content.getMaterialIdList())) {
boolean ifRelateDrp = this.ifRelateDrp(content.getSupermarketId());
List<SupermarketNotRemovedProductListVO> resultList;
if (ifRelateDrp) {
resultList = this.supermarketProductMapper.listNotRemovedProduct(content, 1);
} else {
resultList = this.supermarketProductMapper.listNotRemovedProduct(content, (Integer)null);
}
boolean ifSupermarketMember = this.ifSupermarketMember(content.getCustId(), content.getSupermarketId());
if (!ifSupermarketMember) {
resultList.forEach((s) -> {
s.setPrefPrice((BigDecimal)null);
});
}
return resultList;
} else {
throw new ServiceException(I18n.getMessage("supermarket.shop-cert-material-not-null", new Object[0]));
}
}
public void checkProductLimitBuy(SmtCheckProductLimitBuyDTO content) {
log.info("[商超]_限购校验_入参{}", content);

View File

@ -2,10 +2,12 @@ package com.bonus.core.supermarket.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.core.supermarket.dto.SupermarketNotRemovedProductListDTO;
import com.bonus.core.supermarket.dto.SupermarketQueryProductInfoDTO;
import com.bonus.core.supermarket.model.SupermarketProduct;
import com.bonus.core.supermarket.po.GoodsBuyLimitModel;
import com.bonus.core.supermarket.po.InventoryNumModel;
import com.bonus.core.supermarket.vo.SupermarketNotRemovedProductListVO;
import com.bonus.core.supermarket.vo.SupermarketProductInfoImageVO;
import com.bonus.core.supermarket.vo.SupermarketQueryProductInfoVO;
import org.apache.ibatis.annotations.Mapper;
@ -59,8 +61,8 @@ public interface SupermarketProductMapper extends BaseMapper<SupermarketProduct>
InventoryNumModel getProductInventory(@Param("supermarketId") Long supermarketId, @Param("supermarketDetailId") Long supermarketDetailId);
//
// List<PriceByMaterialIdVO> getPriceByMaterialIds(@Param("materialIds") List<Long> materialIds, @Param("warehouseId") Long warehouseId);
//
// List<SupermarketNotRemovedProductListVO> listNotRemovedProduct(@Param("content") SupermarketNotRemovedProductListDTO content, @Param("ifRelateDrp") Integer ifRelateDrp);
List<SupermarketNotRemovedProductListVO> listNotRemovedProduct(@Param("content") SupermarketNotRemovedProductListDTO content, @Param("ifRelateDrp") Integer ifRelateDrp);
List<SupermarketProductInfoImageVO> getProductImg(@Param("goodsIdList") List<Long> goodsIdList);

View File

@ -526,43 +526,43 @@
<!-- </if>-->
<!-- </where>-->
<!-- </select>-->
<!-- <select id="listNotRemovedProduct"-->
<!-- resultType="net.xnzn.core.supermarket.vo.SupermarketNotRemovedProductListVO">-->
<!-- SELECT-->
<!-- a.supermarket_detail_id,-->
<!-- a.material_id,-->
<!-- b.material_name,-->
<!-- b.unit_id,-->
<!-- c.unit_name,-->
<!-- a.sale_price,-->
<!-- a.pref_price,-->
<!-- b.sales_mode,-->
<!-- a.putaway_state,-->
<!-- a.if_online,-->
<!-- <if test="ifRelateDrp != null">-->
<!-- e.inventory_id,-->
<!-- IFNULL(e.material_num,0) inventoryNum,-->
<!-- </if>-->
<!-- <if test="ifRelateDrp == null">-->
<!-- a.inventory_num,-->
<!-- </if>-->
<!-- a.person_limit,-->
<!-- b.image_url-->
<!-- FROM-->
<!-- supermarket_product a-->
<!-- LEFT JOIN menu_material b ON b.material_id = a.material_id-->
<!-- LEFT JOIN drp_unit c ON c.unit_id = b.unit_id-->
<!-- <if test="ifRelateDrp != null">-->
<!-- LEFT JOIN supermarket_info d on d.supermarket_id = a.supermarket_id-->
<!-- LEFT JOIN drp_inventory e on e.warehouse_id = d.warehouse_id and e.material_id = b.material_id-->
<!-- </if>-->
<!-- WHERE-->
<!-- a.supermarket_id = #{content.supermarketId}-->
<!-- AND a.material_id IN-->
<!-- <foreach collection="content.materialIdList" item="materialId" separator="," open="(" close=")">-->
<!-- #{materialId}-->
<!-- </foreach>-->
<!-- </select>-->
<select id="listNotRemovedProduct"
resultType="com.bonus.core.supermarket.vo.SupermarketNotRemovedProductListVO">
SELECT
a.supermarket_detail_id,
a.material_id,
b.material_name,
b.unit_id,
c.unit_name,
a.sale_price,
a.pref_price,
b.sales_mode,
a.putaway_state,
a.if_online,
<if test="ifRelateDrp != null">
e.inventory_id,
IFNULL(e.material_num,0) inventoryNum,
</if>
<if test="ifRelateDrp == null">
a.inventory_num,
</if>
a.person_limit,
b.image_url
FROM
supermarket_product a
LEFT JOIN menu_material b ON b.material_id = a.material_id
LEFT JOIN drp_unit c ON c.unit_id = b.unit_id
<if test="ifRelateDrp != null">
LEFT JOIN supermarket_info d on d.supermarket_id = a.supermarket_id
LEFT JOIN drp_inventory e on e.warehouse_id = d.warehouse_id and e.material_id = b.material_id
</if>
WHERE
a.supermarket_id = #{content.supermarketId}
AND a.material_id IN
<foreach collection="content.materialIdList" item="materialId" separator="," open="(" close=")">
#{materialId}
</foreach>
</select>
<select id="getProductImg" resultType="com.bonus.core.supermarket.vo.SupermarketProductInfoImageVO">
SELECT
a.material_id,