菜品库存
This commit is contained in:
1 parent
64cbf18a75
commit
e1f343c2b4
3 files changed
+41
-11
No files matched your search
+3
-1
@@ -126,9 +126,11 @@ public class CanteenSpuController {
|
|||||||
@SysLog("新增菜品spu")
|
@SysLog("新增菜品spu")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@PreAuthorize("@pms.hasPermission('canteen_canteenSpu_add')")
|
@PreAuthorize("@pms.hasPermission('canteen_canteenSpu_add')")
|
||||||
|
@Transactional
|
||||||
public R save(@RequestBody CanteenSpuEntity canteenSpu) {
|
public R save(@RequestBody CanteenSpuEntity canteenSpu) {
|
||||||
Long deptId = SecurityUtils.getUser().getDeptId();
|
Long deptId = SecurityUtils.getUser().getDeptId();
|
||||||
canteenSpu.setDeptId(deptId);
|
canteenSpu.setDeptId(deptId);
|
||||||
|
boolean save = canteenSpuService.save(canteenSpu);
|
||||||
CanteenStockEntity canteenStockEntity = new CanteenStockEntity();
|
CanteenStockEntity canteenStockEntity = new CanteenStockEntity();
|
||||||
canteenStockEntity.setItemId(canteenSpu.getId());
|
canteenStockEntity.setItemId(canteenSpu.getId());
|
||||||
canteenStockEntity.setItemType(StockTypeEnum.DISH.getType());
|
canteenStockEntity.setItemType(StockTypeEnum.DISH.getType());
|
||||||
@@ -138,7 +140,7 @@ public class CanteenSpuController {
|
|||||||
canteenStockEntity.setCurrentStock(0D);
|
canteenStockEntity.setCurrentStock(0D);
|
||||||
canteenStockEntity.setDeptId(deptId);
|
canteenStockEntity.setDeptId(deptId);
|
||||||
canteenStockService.save(canteenStockEntity);
|
canteenStockService.save(canteenStockEntity);
|
||||||
return R.ok(canteenSpuService.save(canteenSpu));
|
return R.ok(save);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+36
-10
@@ -24,6 +24,8 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 库存表
|
* 库存表
|
||||||
@@ -127,18 +129,42 @@ public class CanteenStockController {
|
|||||||
@PreAuthorize("@pms.hasPermission('canteen_canteenStock_add')" )
|
@PreAuthorize("@pms.hasPermission('canteen_canteenStock_add')" )
|
||||||
public R ansyncStock() {
|
public R ansyncStock() {
|
||||||
|
|
||||||
|
// 获取所有SPU列表
|
||||||
List<CanteenSpuEntity> list = canteenSpuService.list();
|
List<CanteenSpuEntity> list = canteenSpuService.list();
|
||||||
|
|
||||||
for (CanteenSpuEntity canteenSpuEntity : list) {
|
// 提取所有SPU ID
|
||||||
CanteenStockEntity canteenStockEntity = new CanteenStockEntity();
|
List<Long> skuIds = list.stream()
|
||||||
canteenStockEntity.setCurrentStock(0D);
|
.map(CanteenSpuEntity::getId)
|
||||||
canteenStockEntity.setBaseStock(0D);
|
.collect(Collectors.toList());
|
||||||
canteenStockEntity.setItemType("2");
|
|
||||||
canteenStockEntity.setItemId(canteenSpuEntity.getId());
|
// 查询已存在的库存记录
|
||||||
canteenStockEntity.setDeptId(canteenSpuEntity.getDeptId());
|
LambdaQueryWrapper<CanteenStockEntity> wrapper = Wrappers.lambdaQuery();
|
||||||
canteenStockEntity.setInventoryUpperLimit(0);
|
wrapper.in(CanteenStockEntity::getItemId, skuIds);
|
||||||
canteenStockEntity.setInventoryLowerLimit(0);
|
List<CanteenStockEntity> existingStocks = canteenStockService.list(wrapper);
|
||||||
canteenStockService.save(canteenStockEntity);
|
|
||||||
|
// 将已存在的itemId存入Set用于快速查找
|
||||||
|
Set<Long> existingItemIds = existingStocks.stream()
|
||||||
|
.map(CanteenStockEntity::getItemId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// 过滤出需要新增的SPU
|
||||||
|
List<CanteenStockEntity> toSaveList = list.stream()
|
||||||
|
.filter(spu -> !existingItemIds.contains(spu.getId()))
|
||||||
|
.map(spu -> {
|
||||||
|
CanteenStockEntity entity = new CanteenStockEntity();
|
||||||
|
entity.setCurrentStock(0D);
|
||||||
|
entity.setBaseStock(0D);
|
||||||
|
entity.setItemType("2");
|
||||||
|
entity.setItemId(spu.getId());
|
||||||
|
entity.setDeptId(spu.getDeptId());
|
||||||
|
entity.setInventoryUpperLimit(0);
|
||||||
|
entity.setInventoryLowerLimit(0);
|
||||||
|
return entity;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 批量保存新数据
|
||||||
|
if (CollUtil.isNotEmpty(toSaveList)) {
|
||||||
|
canteenStockService.saveBatch(toSaveList);
|
||||||
}
|
}
|
||||||
|
|
||||||
return R.ok();
|
return R.ok();
|
||||||
|
|||||||
+2
@@ -203,6 +203,8 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
|
|||||||
// 如果没有对应的库存记录,则设置默认值
|
// 如果没有对应的库存记录,则设置默认值
|
||||||
vo.setBaseStock(0.0);
|
vo.setBaseStock(0.0);
|
||||||
vo.setCurrentStock(0.0);
|
vo.setCurrentStock(0.0);
|
||||||
|
vo.setInventoryUpperLimit(0);
|
||||||
|
vo.setInventoryLowerLimit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
resultList.add(vo);
|
resultList.add(vo);
|
||||||
|
|||||||
Reference in new issue
Block a user