feat: 商品、规格删除改造

This commit is contained in:
DataCall 2024-07-24 14:20:40 +08:00
parent a99f1837c2
commit e660c2befe
9 changed files with 62 additions and 45 deletions

View file

@ -95,9 +95,8 @@ public class ItemController extends BaseController {
*/ */
@Log(title = "物料", businessType = BusinessType.DELETE) @Log(title = "物料", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public R<Void> remove(@NotEmpty(message = "主键不能为空") public R<Boolean> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ids) { @PathVariable Long[] ids) {
itemService.deleteByIds(List.of(ids)); return R.ok(itemService.deleteByIds(List.of(ids)));
return R.ok();
} }
} }

View file

@ -89,12 +89,12 @@ public class ItemSkuController extends BaseController {
/** /**
* 删除sku信息 * 删除sku信息
* *
* @param ids 主键 * @param id 主键
*/ */
@Log(title = "sku信息", businessType = BusinessType.DELETE) @Log(title = "sku信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{id}")
public R<Void> remove(@NotEmpty(message = "主键不能为空") public R<Boolean> remove(@NotNull(message = "主键不能为空")
@PathVariable Long[] ids) { @PathVariable Long id) {
return toAjax(itemSkuService.deleteByIds(List.of(ids))); return R.ok(itemSkuService.deleteById(id));
} }
} }

View file

@ -48,13 +48,6 @@ public class Item extends BaseEntity {
*/ */
private String itemBrand; private String itemBrand;
/**
* 删除标识
*/
@TableLogic
private Integer delFlag;
/** /**
* 备注 * 备注
*/ */

View file

@ -59,12 +59,4 @@ public class ItemSku extends BaseEntity {
* 重量(kg) * 重量(kg)
*/ */
private BigDecimal weight; private BigDecimal weight;
/**
* 删除标识
*/
@TableLogic
private Integer delFlag;
} }

View file

@ -92,8 +92,6 @@ public class ItemSkuVo implements Serializable {
@ExcelProperty(value = "商品品牌") @ExcelProperty(value = "商品品牌")
private String itemBrand; private String itemBrand;
private Integer delFlag;
private Long itemCategoryId; private Long itemCategoryId;
} }

View file

@ -133,4 +133,19 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
inventoryMapper.updateQuantity(updateList); inventoryMapper.updateQuantity(updateList);
} }
} }
/**
* 校验规格是否有库存
* @param skuIds
* @return
*/
public boolean checkInventoryBySkuIds(Collection<Long> skuIds) {
if (CollUtil.isEmpty(skuIds)) {
return false;
}
LambdaQueryWrapper<Inventory> lqw = Wrappers.lambdaQuery();
lqw.in(Inventory::getSkuId, skuIds);
Long count = inventoryMapper.selectCount(lqw);
return count != null && count > 0;
}
} }

View file

@ -39,6 +39,7 @@ public class ItemService {
private final ItemSkuService itemSkuService; private final ItemSkuService itemSkuService;
private final ItemSkuMapper itemSkuMapper; private final ItemSkuMapper itemSkuMapper;
private final ItemCategoryMapper itemCategoryMapper; private final ItemCategoryMapper itemCategoryMapper;
private final InventoryService inventoryService;
/** /**
* 查询物料 * 查询物料
@ -175,11 +176,13 @@ public class ItemService {
* 批量删除物料 * 批量删除物料
*/ */
@Transactional @Transactional
public void deleteByIds(Collection<Long> ids) { public Boolean deleteByIds(Collection<Long> ids) {
List<Long> skuIds = itemSkuService.queryByItemIds(ids).stream().map(ItemSku::getId).toList();
if (inventoryService.checkInventoryBySkuIds(skuIds)) {
return false;
}
itemMapper.deleteBatchIds(ids); itemMapper.deleteBatchIds(ids);
LambdaQueryWrapper<ItemSku> wrapper = new LambdaQueryWrapper<>(); itemSkuService.deleteByIds(skuIds);
wrapper.in(ItemSku::getItemId, ids); return true;
List<Long> skuIds = itemSkuMapper.selectList(wrapper).stream().map(ItemSku::getId).toList();
itemSkuService.batchUpdateDelFlag(skuIds);
} }
} }

View file

@ -1,6 +1,7 @@
package com.ruoyi.wms.service; package com.ruoyi.wms.service;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -20,6 +21,7 @@ import com.ruoyi.wms.domain.vo.ItemVo;
import com.ruoyi.wms.mapper.ItemCategoryMapper; import com.ruoyi.wms.mapper.ItemCategoryMapper;
import com.ruoyi.wms.mapper.ItemSkuMapper; import com.ruoyi.wms.mapper.ItemSkuMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -30,12 +32,14 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor(onConstructor_ = {@Lazy}) @RequiredArgsConstructor(onConstructor_ = {@Lazy})
@Service @Service
@Slf4j
public class ItemSkuService extends ServiceImpl<ItemSkuMapper, ItemSku> { public class ItemSkuService extends ServiceImpl<ItemSkuMapper, ItemSku> {
private final ItemSkuMapper itemSkuMapper; private final ItemSkuMapper itemSkuMapper;
private final ItemService itemService; private final ItemService itemService;
private final ItemCategoryMapper itemCategoryMapper; private final ItemCategoryMapper itemCategoryMapper;
private final InventoryService inventoryService;
/** /**
* 查询sku信息 * 查询sku信息
@ -155,13 +159,33 @@ public class ItemSkuService extends ServiceImpl<ItemSkuMapper, ItemSku> {
return itemSkuMapper.updateById(update) > 0; return itemSkuMapper.updateById(update) > 0;
} }
public Boolean deleteById(Long id) {
// 只有一个不能删除
ItemSku itemSku = itemSkuMapper.selectById(id);
Assert.notNull(itemSku, "规格不存在");
Assert.state(queryListByItemId(itemSku.getItemId()).size() > 1, "至少包含一个商品规格");
// 校验库存是否已关联
if (inventoryService.checkInventoryBySkuIds(Arrays.asList(id))) {
log.info("规格{}已有业务关联,无法删除!", id);
return false;
}
// 删除
itemSkuMapper.deleteById(id);
return true;
}
/** /**
* 批量删除sku信息 * 批量删除sku信息
*/ */
public Boolean deleteByIds(Collection<Long> ids) { public Boolean deleteByIds(Collection<Long> ids) {
return itemSkuMapper.deleteBatchIds(ids) > 0; // 校验库存是否已关联
if (inventoryService.checkInventoryBySkuIds(ids)) {
return false;
}
// 删除
itemSkuMapper.deleteBatchIds(ids);
return true;
} }
/** /**
@ -203,18 +227,12 @@ public class ItemSkuService extends ServiceImpl<ItemSkuMapper, ItemSku> {
return itemSkuMapper.selectVoList(lqw); return itemSkuMapper.selectVoList(lqw);
} }
/** public List<ItemSku> queryByItemIds(Collection<Long> itemIds) {
* 批量软删除sku if (CollUtil.isEmpty(itemIds)) {
* return Collections.emptyList();
* @param itemSkuIds
*/
public void batchUpdateDelFlag(Collection<Long> itemSkuIds) {
if (CollUtil.isEmpty(itemSkuIds)) {
return;
} }
LambdaUpdateWrapper<ItemSku> wrapper = new LambdaUpdateWrapper<>(); LambdaQueryWrapper<ItemSku> lqw = Wrappers.lambdaQuery();
wrapper.in(ItemSku::getId, itemSkuIds); lqw.in(ItemSku::getItemId, itemIds);
wrapper.set(ItemSku::getDelFlag, 2); return itemSkuMapper.selectList(lqw);
itemSkuMapper.update(null, wrapper);
} }
} }

View file

@ -21,7 +21,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
a.sku_name, a.sku_name,
a.item_id, a.item_id,
a.out_sku_id, a.out_sku_id,
a.del_flag,
a.length, a.length,
a.width, a.width,
a.height, a.height,
@ -39,7 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from wms_item_sku a from wms_item_sku a
inner join wms_item b on a.item_id=b.id inner join wms_item b on a.item_id=b.id
inner join wms_item_category c on b.item_category=c.id inner join wms_item_category c on b.item_category=c.id
where a.del_flag=0 and b.del_flag=0 where 1=1
<if test="bo.itemName != null and bo.itemName != ''"> <if test="bo.itemName != null and bo.itemName != ''">
and b.item_name like concat('%', #{bo.itemName}, '%') and b.item_name like concat('%', #{bo.itemName}, '%')
</if> </if>