修改口味
This commit is contained in:
1 parent
1e3ac51869
commit
3cc5cf1925
2 files changed
+102
-71
No files matched your search
+3
-14
@@ -45,7 +45,8 @@ public class SmErpTasteStockController {
|
||||
*/
|
||||
@Operation(summary = "分页查询" , description = "分页查询" )
|
||||
@GetMapping("/page" )
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_smErpTasteStock_view')" )
|
||||
// @PreAuthorize("@pms.hasPermission('supermarket_smErpTasteStock_view')" )
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_supermarketSpu_view')" )
|
||||
public R getSmErpTasteStockPage(@ParameterObject Page page, @ParameterObject SmErpTasteStockEntity smErpTasteStock) {
|
||||
LambdaQueryWrapper<SmErpTasteStockEntity> wrapper = Wrappers.lambdaQuery();
|
||||
return R.ok(smErpTasteStockService.page(page, wrapper));
|
||||
@@ -59,7 +60,7 @@ public class SmErpTasteStockController {
|
||||
*/
|
||||
@Operation(summary = "通过id查询" , description = "通过id查询" )
|
||||
@GetMapping("/{id}" )
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_smErpTasteStock_view')" )
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_supermarketSpu_view')" )
|
||||
public R getById(@PathVariable("id" ) Long id) {
|
||||
return R.ok(smErpTasteStockService.getById(id));
|
||||
}
|
||||
@@ -104,16 +105,4 @@ public class SmErpTasteStockController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出excel 表格
|
||||
* @param smErpTasteStock 查询条件
|
||||
* @param ids 导出指定ID
|
||||
* @return excel 文件流
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_smErpTasteStock_export')" )
|
||||
public List<SmErpTasteStockEntity> export(SmErpTasteStockEntity smErpTasteStock,Long[] ids) {
|
||||
return smErpTasteStockService.list(Wrappers.lambdaQuery(smErpTasteStock).in(ArrayUtil.isNotEmpty(ids), SmErpTasteStockEntity::getId, ids));
|
||||
}
|
||||
}
|
||||
+99
-57
@@ -162,7 +162,32 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
return R.failed("包装类型内装数.量不能小于等于0!");
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(smErpUnitEntityList)) {
|
||||
smErpUnitEntityList.forEach(supermarketUnitEntity -> supermarketUnitEntity.setSpuId(supermarketSpu.getId()));
|
||||
// 建立口味名称到ID的映射
|
||||
final Map<String, Long> tasteNameToIdMap;
|
||||
if (CollectionUtils.isNotEmpty(tasteList)) {
|
||||
tasteNameToIdMap = tasteList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
taste -> taste.getTasteName() != null ? taste.getTasteName() : "",
|
||||
SmErpTasteStockEntity::getId,
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
} else {
|
||||
tasteNameToIdMap = new HashMap<>();
|
||||
}
|
||||
|
||||
// 在循环中直接设置SPU ID和口味ID,然后保存
|
||||
smErpUnitEntityList.forEach(supermarketUnitEntity -> {
|
||||
supermarketUnitEntity.setSpuId(supermarketSpu.getId());
|
||||
|
||||
// 根据口味名称设置口味ID
|
||||
if (supermarketUnitEntity.getTaste() != null && !supermarketUnitEntity.getTaste().trim().isEmpty() && !tasteNameToIdMap.isEmpty()) {
|
||||
Long tasteId = tasteNameToIdMap.get(supermarketUnitEntity.getTaste().trim());
|
||||
if (tasteId != null) {
|
||||
supermarketUnitEntity.setTasteId(tasteId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
smErpUnitService.saveBatch(smErpUnitEntityList);
|
||||
} else {
|
||||
return R.failed("包装类型不能为空");
|
||||
@@ -207,6 +232,39 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
smErpStockEntity.setInventoryUpperLimit(supermarketSpu.getInventoryUpperLimit());
|
||||
smErpStockMapper.update(smErpStockEntity, smErpStockEntityLambdaQueryWrapper);
|
||||
|
||||
// 处理口味集合(先处理,获取ID)
|
||||
List<SmErpTasteStockEntity> tasteList = supermarketSpu.getSmErpTasteStockEntityList();
|
||||
if (CollectionUtils.isNotEmpty(tasteList)) {
|
||||
// 分离新增和更新的口味
|
||||
List<SmErpTasteStockEntity> insertTastes = tasteList.stream()
|
||||
.filter(taste -> taste.getId() == null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<SmErpTasteStockEntity> updateTastes = tasteList.stream()
|
||||
.filter(taste -> taste.getId() != null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 处理新增口味
|
||||
if (CollectionUtils.isNotEmpty(insertTastes)) {
|
||||
insertTastes.forEach(taste -> {
|
||||
taste.setSpuId(supermarketSpu.getId());
|
||||
// 设置默认库存为0
|
||||
if (taste.getStock() == null) {
|
||||
taste.setStock(0.0);
|
||||
}
|
||||
});
|
||||
smErpTasteStockService.saveBatch(insertTastes);
|
||||
}
|
||||
|
||||
// 处理更新口味
|
||||
if (CollectionUtils.isNotEmpty(updateTastes)) {
|
||||
updateTastes.forEach(taste -> {
|
||||
taste.setSpuId(supermarketSpu.getId());
|
||||
});
|
||||
smErpTasteStockService.updateBatchById(updateTastes);
|
||||
}
|
||||
}
|
||||
|
||||
//新增包装类型
|
||||
List<SmErpUnitEntity> smErpUnitEntityList = supermarketSpu.getSmErpUnitEntityList();
|
||||
List<SmErpUnitEntity> insertUnits= new ArrayList<>();
|
||||
@@ -222,12 +280,50 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
return R.failed("必须且只能指定一个基础包装单位!");
|
||||
}
|
||||
|
||||
// 建立口味名称到ID的映射
|
||||
final Map<String, Long> tasteNameToIdMap;
|
||||
if (CollectionUtils.isNotEmpty(tasteList)) {
|
||||
tasteNameToIdMap = tasteList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
taste -> taste.getTasteName() != null ? taste.getTasteName() : "",
|
||||
SmErpTasteStockEntity::getId,
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
} else {
|
||||
tasteNameToIdMap = new HashMap<>();
|
||||
}
|
||||
|
||||
//id为null新增
|
||||
insertUnits = smErpUnitEntityList.stream()
|
||||
.filter(supermarketUnitEntity -> supermarketUnitEntity.getId() == null).collect(Collectors.toList());
|
||||
insertUnits.forEach(supermarketUnitEntity -> supermarketUnitEntity.setSpuId(supermarketSpu.getId()));
|
||||
updateUnits = smErpUnitEntityList.stream()
|
||||
|
||||
// 为新增的包装单位设置SPU ID和口味ID
|
||||
insertUnits.forEach(supermarketUnitEntity -> {
|
||||
supermarketUnitEntity.setSpuId(supermarketSpu.getId());
|
||||
|
||||
// 根据口味名称设置口味ID
|
||||
if (supermarketUnitEntity.getTaste() != null && !supermarketUnitEntity.getTaste().trim().isEmpty() && !tasteNameToIdMap.isEmpty()) {
|
||||
Long tasteId = tasteNameToIdMap.get(supermarketUnitEntity.getTaste().trim());
|
||||
if (tasteId != null) {
|
||||
supermarketUnitEntity.setTasteId(tasteId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
updateUnits = smErpUnitEntityList.stream()
|
||||
.filter(supermarketUnitEntity -> supermarketUnitEntity.getId() != null).collect(Collectors.toList());
|
||||
|
||||
// 为更新的包装单位设置口味ID
|
||||
updateUnits.forEach(supermarketUnitEntity -> {
|
||||
// 根据口味名称设置口味ID
|
||||
if (supermarketUnitEntity.getTaste() != null && !supermarketUnitEntity.getTaste().trim().isEmpty() && !tasteNameToIdMap.isEmpty()) {
|
||||
Long tasteId = tasteNameToIdMap.get(supermarketUnitEntity.getTaste().trim());
|
||||
if (tasteId != null) {
|
||||
supermarketUnitEntity.setTasteId(tasteId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
smErpUnitService.updateBatchById(updateUnits);
|
||||
smErpUnitService.saveBatch(insertUnits);
|
||||
//判断是否修改了基础包装单位,如果修改了基础包装单位的类型,其他的要变成false
|
||||
@@ -361,60 +457,6 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
}
|
||||
}
|
||||
|
||||
// 处理口味集合
|
||||
List<SmErpTasteStockEntity> tasteList = supermarketSpu.getSmErpTasteStockEntityList();
|
||||
if (CollectionUtils.isNotEmpty(tasteList)) {
|
||||
// 分离新增和更新的口味
|
||||
List<SmErpTasteStockEntity> insertTastes = tasteList.stream()
|
||||
.filter(taste -> taste.getId() == null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<SmErpTasteStockEntity> updateTastes = tasteList.stream()
|
||||
.filter(taste -> taste.getId() != null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 处理新增口味
|
||||
if (CollectionUtils.isNotEmpty(insertTastes)) {
|
||||
insertTastes.forEach(taste -> {
|
||||
taste.setSpuId(supermarketSpu.getId());
|
||||
// 设置默认库存为0
|
||||
if (taste.getStock() == null) {
|
||||
taste.setStock(0.0);
|
||||
}
|
||||
});
|
||||
smErpTasteStockService.saveBatch(insertTastes);
|
||||
}
|
||||
|
||||
// 处理更新口味
|
||||
if (CollectionUtils.isNotEmpty(updateTastes)) {
|
||||
updateTastes.forEach(taste -> {
|
||||
taste.setSpuId(supermarketSpu.getId());
|
||||
});
|
||||
smErpTasteStockService.updateBatchById(updateTastes);
|
||||
}
|
||||
|
||||
// 获取现有所有口味ID
|
||||
List<Long> existingTasteIds = smErpTasteStockService.list(
|
||||
new LambdaQueryWrapper<SmErpTasteStockEntity>()
|
||||
.eq(SmErpTasteStockEntity::getSpuId, supermarketSpu.getId())
|
||||
).stream().map(SmErpTasteStockEntity::getId).collect(Collectors.toList());
|
||||
|
||||
// 收集本次提交的口味ID(排除新增的)
|
||||
List<Long> submittedTasteIds = tasteList.stream()
|
||||
.map(SmErpTasteStockEntity::getId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 计算需要删除的口味ID
|
||||
List<Long> toDeleteTasteIds = existingTasteIds.stream()
|
||||
.filter(id -> !submittedTasteIds.contains(id))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 批量删除失效口味
|
||||
if (!toDeleteTasteIds.isEmpty()) {
|
||||
smErpTasteStockService.removeByIds(toDeleteTasteIds);
|
||||
}
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user