基础包装单位效验
This commit is contained in:
1 parent
cec65bc424
commit
58ed6f8383
6 files changed
+48
-12
No files matched your search
+1
-1
@@ -21,7 +21,7 @@ public class SmErpCgDdVo {
|
||||
private String code;
|
||||
|
||||
|
||||
@Schema(description="据日期")
|
||||
@Schema(description="单据日期")
|
||||
private LocalDate ddDate;
|
||||
|
||||
/**
|
||||
|
||||
-1
@@ -207,7 +207,6 @@ public class SmErpInventoryRecordsController {
|
||||
@Operation(summary = "获取出入库订单分页" , description = "关联订单" )
|
||||
@GetMapping("/inventory/page" )
|
||||
public R getInventoryPage(@ParameterObject Page page, @ParameterObject InventoryLinkQueryDTO inventoryLinkQueryDTO) {
|
||||
|
||||
LambdaQueryWrapper<SmErpInventoryRecordsEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.like(StrUtil.isNotBlank(inventoryLinkQueryDTO.getCode()),SmErpInventoryRecordsEntity::getInventoryCode,inventoryLinkQueryDTO.getCode());
|
||||
wrapper.eq(Objects.nonNull(inventoryLinkQueryDTO.getDdDate()),SmErpInventoryRecordsEntity::getInventoryDate,inventoryLinkQueryDTO.getDdDate());
|
||||
|
||||
+3
-1
@@ -107,7 +107,9 @@ public class SmErpCgDdServiceImpl extends ServiceImpl<SmErpCgDdMapper, SmErpCgDd
|
||||
// 1. 查询主表分页数据
|
||||
Page<SmErpCgDdEntity> pageData = baseMapper.selectPageByScope(page, wrapper, DataScope.of());
|
||||
List<SmErpCgDdEntity> records = pageData.getRecords();
|
||||
|
||||
if (CollectionUtils.isEmpty(records)){
|
||||
return pageData;
|
||||
}
|
||||
// 2. 提前收集所有主表ID(去重处理)
|
||||
Set<Long> planIds = records.stream()
|
||||
.map(SmErpCgDdEntity::getId)
|
||||
|
||||
+5
-3
@@ -162,11 +162,13 @@ public class SmErpInventoryRecordsServiceImpl extends ServiceImpl<SmErpInventory
|
||||
public Object pageInventoryScope(Page page, LambdaQueryWrapper<SmErpInventoryRecordsEntity> wrapper) {
|
||||
Page pageData = baseMapper.selectPageByScope(page, wrapper, DataScope.of());
|
||||
|
||||
List<SmErpCgPlanEntity> records = pageData.getRecords();
|
||||
|
||||
List<SmErpInventoryRecordsEntity> records = pageData.getRecords();
|
||||
if (CollectionUtils.isEmpty(records)){
|
||||
return pageData;
|
||||
}
|
||||
// 2. 提前收集所有主表ID(去重处理)
|
||||
Set<Long> planIds = records.stream()
|
||||
.map(SmErpCgPlanEntity::getId)
|
||||
.map(SmErpInventoryRecordsEntity::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 3. 批量查询所有子表数据(仅1次数据库查询)
|
||||
|
||||
+38
-5
@@ -109,6 +109,10 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
|
||||
//新增包装类型
|
||||
List<SmErpUnitEntity> smErpUnitEntityList = supermarketSpu.getSmErpUnitEntityList();
|
||||
List<SmErpUnitEntity> isBaseNum = smErpUnitEntityList.stream().filter(smErpUnitEntity -> smErpUnitEntity.getIsBase() == true).collect(Collectors.toList());
|
||||
if (isBaseNum.size()!=1){
|
||||
return R.failed("必须且只能指定一个基础包装单位!");
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(smErpUnitEntityList)) {
|
||||
smErpUnitEntityList.forEach(supermarketUnitEntity -> supermarketUnitEntity.setSpuId(supermarketSpu.getId()));
|
||||
smErpUnitService.saveBatch(smErpUnitEntityList);
|
||||
@@ -153,15 +157,44 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
|
||||
//新增包装类型
|
||||
List<SmErpUnitEntity> smErpUnitEntityList = supermarketSpu.getSmErpUnitEntityList();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(smErpUnitEntityList)) {
|
||||
|
||||
List<SmErpUnitEntity> baseUnits = smErpUnitEntityList.stream()
|
||||
.filter(unit -> Boolean.TRUE.equals(unit.getIsBase()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 检查基础单位数量
|
||||
if ( baseUnits.size() != 1) {
|
||||
return R.failed("必须且只能指定一个基础包装单位!");
|
||||
}
|
||||
|
||||
//id为null新增
|
||||
List<SmErpUnitEntity> insertCollect = smErpUnitEntityList.stream()
|
||||
List<SmErpUnitEntity> insertUnits = smErpUnitEntityList.stream()
|
||||
.filter(supermarketUnitEntity -> supermarketUnitEntity.getId() == null).collect(Collectors.toList());
|
||||
insertCollect.forEach(supermarketUnitEntity -> supermarketUnitEntity.setSpuId(supermarketSpu.getId()));
|
||||
List<SmErpUnitEntity> updateCollect = smErpUnitEntityList.stream()
|
||||
insertUnits.forEach(supermarketUnitEntity -> supermarketUnitEntity.setSpuId(supermarketSpu.getId()));
|
||||
List<SmErpUnitEntity> updateUnits = smErpUnitEntityList.stream()
|
||||
.filter(supermarketUnitEntity -> supermarketUnitEntity.getId() != null).collect(Collectors.toList());
|
||||
smErpUnitService.updateBatchById(updateCollect);
|
||||
smErpUnitService.saveBatch(insertCollect);
|
||||
smErpUnitService.updateBatchById(updateUnits);
|
||||
smErpUnitService.saveBatch(insertUnits);
|
||||
//判断是否修改了基础包装单位,如果修改了基础包装单位的类型,其他的要变成false
|
||||
// 获取当前有效的基础单位ID(处理新增单位的情况)
|
||||
Long currentBaseUnitId = baseUnits.get(0).getId() != null ?
|
||||
baseUnits.get(0).getId() :
|
||||
insertUnits.stream()
|
||||
.filter(SmErpUnitEntity::getIsBase)
|
||||
.findFirst()
|
||||
.map(SmErpUnitEntity::getId)
|
||||
.orElse(null);
|
||||
// 更新其他单位为非基础
|
||||
if (currentBaseUnitId != null) {
|
||||
LambdaUpdateWrapper<SmErpUnitEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper
|
||||
.eq(SmErpUnitEntity::getSpuId, supermarketSpu.getId())
|
||||
.ne(SmErpUnitEntity::getId, currentBaseUnitId)
|
||||
.set(SmErpUnitEntity::getIsBase, false);
|
||||
smErpUnitService.update(updateWrapper);
|
||||
}
|
||||
} else {
|
||||
return R.failed("包装类型不能为空");
|
||||
}
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@
|
||||
LEFT JOIN sm_erp_spu esp
|
||||
on sp.erp_spu_id = esp.id
|
||||
LEFT JOIN sm_erp_unit u
|
||||
on esp.id=u.spu_id
|
||||
on esp.id=u.spu_id and u.is_base=1
|
||||
LEFT JOIN sm_erp_stock stock
|
||||
on esp.id = stock.erp_spu_id
|
||||
<where>
|
||||
|
||||
Reference in new issue
Block a user