库存,菜品详情,
This commit is contained in:
1 parent
f12fe00e0c
commit
0ef48ae331
4 files changed
+82
-5
No files matched your search
+6
@@ -50,6 +50,12 @@ public interface RemoteCanteenSpuService {
|
||||
@GetMapping("/canteenSpu/ad/getCanteenSpuList")
|
||||
R getCanteenSpuList(@RequestParam(value = "categoryId",required = false)String categoryId);
|
||||
|
||||
/**
|
||||
* 获取菜品详情(含详情富文本、套餐组成)
|
||||
*/
|
||||
@GetMapping("/canteenSpu/ad/getCanteenSpuDetails")
|
||||
R getCanteenSpuDetails(@RequestParam("id") Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 扣减菜品库存
|
||||
|
||||
+24
@@ -24,6 +24,18 @@ public class ADCanteenSpuListVO {
|
||||
@Schema(description="商品名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 商品简介
|
||||
*/
|
||||
@Schema(description = "商品简介")
|
||||
private String introduction;
|
||||
|
||||
/**
|
||||
* 商品详情
|
||||
*/
|
||||
@Schema(description = "商品详情")
|
||||
private String description;
|
||||
|
||||
|
||||
/**
|
||||
* 商品分类编号
|
||||
@@ -82,4 +94,16 @@ public class ADCanteenSpuListVO {
|
||||
|
||||
@Schema(description="餐段类型")
|
||||
private String categoryType;
|
||||
|
||||
/**
|
||||
* 商品类型:1单品 2套餐
|
||||
*/
|
||||
@Schema(description = "商品类型:1单品 2套餐")
|
||||
private Integer spuType;
|
||||
|
||||
/**
|
||||
* 套餐组成(仅套餐时有值)
|
||||
*/
|
||||
@Schema(description = "套餐组成")
|
||||
private java.util.List<com.bsd.pjcloud.canteen.vo.app.OnlineSpuComboItemVO> comboItems;
|
||||
}
|
||||
+27
@@ -15,8 +15,10 @@ import com.bsd.pjcloud.canteen.entity.CanteenOnlineSpuEntity;
|
||||
import com.bsd.pjcloud.canteen.entity.CanteenStockEntity;
|
||||
import com.bsd.pjcloud.canteen.mapper.CanteenStockMapper;
|
||||
import com.bsd.pjcloud.canteen.service.CanteenStockService;
|
||||
import com.bsd.pjcloud.canteen.vo.ADCanteenSpuListVO;
|
||||
import com.bsd.pjcloud.canteen.vo.erp.CanteenSpuSimpleVO;
|
||||
import com.bsd.pjcloud.canteen.vo.erp.CanteenSpuStockVO;
|
||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity;
|
||||
@@ -33,6 +35,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -242,6 +245,30 @@ public class CanteenSpuController {
|
||||
return canteenSpuService.getCanteenSpuList(categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜品详情(含详情富文本、套餐组成)
|
||||
*/
|
||||
@GetMapping("/ad/getCanteenSpuDetails")
|
||||
public R getCanteenSpuDetails(@RequestParam("id") Long id) {
|
||||
CanteenSpuEntity detail = canteenSpuService.getDetail(id);
|
||||
if (detail == null) {
|
||||
return R.failed("商品不存在");
|
||||
}
|
||||
ADCanteenSpuListVO vo = BeanUtils.toBean(detail, ADCanteenSpuListVO.class);
|
||||
vo.setIntroduction(detail.getIntroduction());
|
||||
vo.setDescription(detail.getDescription());
|
||||
int type = detail.getSpuType() == null ? 1 : detail.getSpuType();
|
||||
vo.setSpuType(type);
|
||||
if (type == 2) {
|
||||
vo.setComboItems(canteenSpuService.loadComboItemVos(Collections.singletonList(id))
|
||||
.getOrDefault(id, Collections.emptyList()));
|
||||
}
|
||||
else {
|
||||
vo.setComboItems(Collections.emptyList());
|
||||
}
|
||||
return R.ok(vo);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/ad/updateSkuStock")
|
||||
@SysLog("更新菜品库存")
|
||||
|
||||
+25
-5
@@ -92,11 +92,31 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
|
||||
List<CanteenCategoryEntity> canteenCategoryEntities = canteenCategoryMapper.selectList(new LambdaQueryWrapper<CanteenCategoryEntity>().in(CanteenCategoryEntity::getId, cIds));
|
||||
Map<Long, List<CanteenCategoryEntity>> listMap = canteenCategoryEntities.stream().collect(Collectors.groupingBy(CanteenCategoryEntity::getId));
|
||||
|
||||
bean.forEach(item -> {
|
||||
if (null != listMap.get(item.getCategoryId()).get(0).getCategoryType()) {
|
||||
List<Long> comboIds = canteenSpuEntities.stream()
|
||||
.filter(e -> Objects.equals(e.getSpuType(), 2) && e.getId() != null)
|
||||
.map(CanteenSpuEntity::getId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, List<OnlineSpuComboItemVO>> comboMap = loadComboItemVos(comboIds);
|
||||
|
||||
for (int i = 0; i < bean.size() && i < canteenSpuEntities.size(); i++) {
|
||||
ADCanteenSpuListVO item = bean.get(i);
|
||||
CanteenSpuEntity entity = canteenSpuEntities.get(i);
|
||||
item.setIntroduction(entity.getIntroduction());
|
||||
item.setDescription(entity.getDescription());
|
||||
int type = entity.getSpuType() == null ? 1 : entity.getSpuType();
|
||||
item.setSpuType(type);
|
||||
if (type == 2) {
|
||||
item.setComboItems(comboMap.getOrDefault(entity.getId(), Collections.emptyList()));
|
||||
}
|
||||
else {
|
||||
item.setComboItems(Collections.emptyList());
|
||||
}
|
||||
if (item.getCategoryId() != null && listMap.get(item.getCategoryId()) != null
|
||||
&& listMap.get(item.getCategoryId()).get(0).getCategoryType() != null) {
|
||||
item.setCategoryType(listMap.get(item.getCategoryId()).get(0).getCategoryType());
|
||||
}
|
||||
});
|
||||
}
|
||||
return R.ok(bean);
|
||||
}
|
||||
|
||||
@@ -321,8 +341,8 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
|
||||
return;
|
||||
}
|
||||
List<CanteenSpuComboItemEntity> items = entity.getComboItems();
|
||||
if (CollUtil.isEmpty(items) || items.stream().filter(i -> i.getChildSpuId() != null).count() < 2) {
|
||||
throw new IllegalArgumentException("套餐至少选择 2 个组成菜品");
|
||||
if (CollUtil.isEmpty(items) || items.stream().filter(i -> i.getChildSpuId() != null).count() < 1) {
|
||||
throw new IllegalArgumentException("套餐至少选择 1 个组成菜品");
|
||||
}
|
||||
Set<Long> childIds = new HashSet<>();
|
||||
for (CanteenSpuComboItemEntity item : items) {
|
||||
|
||||
Reference in new issue
Block a user