fix(shop): 添加商店模式修改时的商品绑定检查逻辑
在更新商店模式时,新增检查逻辑确保商店下的柜子没有绑定商品时才允许修改模式为3
This commit is contained in:
parent
4a9e6d8d1c
commit
065912f2c7
|
@ -1,6 +1,10 @@
|
|||
package com.agileboot.domain.shop.shop;
|
||||
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellEntity;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellService;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetEntity;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetService;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.shop.shop.command.AddShopCommand;
|
||||
import com.agileboot.domain.shop.shop.command.UpdateShopCommand;
|
||||
|
@ -10,6 +14,7 @@ import com.agileboot.domain.shop.shop.dto.ShopDTO;
|
|||
import com.agileboot.domain.shop.shop.model.ShopModel;
|
||||
import com.agileboot.domain.shop.shop.model.ShopModelFactory;
|
||||
import com.agileboot.domain.shop.shop.query.SearchShopQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -23,6 +28,8 @@ import org.springframework.stereotype.Service;
|
|||
public class ShopApplicationService {
|
||||
private final ShopService shopService;
|
||||
private final ShopModelFactory shopModelFactory;
|
||||
private final SmartCabinetService smartCabinetService;
|
||||
private final CabinetCellService cabinetCellService;
|
||||
|
||||
public PageDTO<ShopDTO> getShopPage(SearchShopQuery<ShopEntity> query) {
|
||||
Page<ShopEntity> page = shopService.getShopList(query.toPage(), query.toQueryWrapper());
|
||||
|
@ -56,6 +63,29 @@ public class ShopApplicationService {
|
|||
|
||||
public void updateShop(UpdateShopCommand command) {
|
||||
ShopModel model = shopModelFactory.loadById(command.getShopId());
|
||||
|
||||
if (command.getMode() != null && !command.getMode().equals(model.getMode())) {
|
||||
if (command.getMode().equals(3)) {
|
||||
QueryWrapper<SmartCabinetEntity> smartCabinetQueryWrapper = new QueryWrapper<>();
|
||||
smartCabinetQueryWrapper.eq("shop_id", command.getShopId())
|
||||
.eq("deleted", false);
|
||||
List<SmartCabinetEntity> cabinetEntities = smartCabinetService.list(smartCabinetQueryWrapper);
|
||||
|
||||
if (cabinetEntities != null && !cabinetEntities.isEmpty()) {
|
||||
QueryWrapper<CabinetCellEntity> cabinetCellQueryWrapper = new QueryWrapper<>();
|
||||
cabinetCellQueryWrapper.in("cabinet_id", cabinetEntities.stream()
|
||||
.map(SmartCabinetEntity::getCabinetId)
|
||||
.collect(Collectors.toList()))
|
||||
.isNotNull("goods_id")
|
||||
.eq("deleted", false);
|
||||
List<CabinetCellEntity> cells = cabinetCellService.list(cabinetCellQueryWrapper);
|
||||
if (cells!= null && !cells.isEmpty()) {
|
||||
throw new RuntimeException("该商店下存在已绑定商品的柜子,请先解绑商品后再修改模式");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model.loadUpdateCommand(command);
|
||||
model.updateById();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue