Commit b503abae by Jony.L

spu和sku的状态联动更新 以及 联动删除

parent ff2c5b32
......@@ -39,4 +39,14 @@ public interface ResourceSkuMapper extends BaseMapperX<ResourceSkuDO> {
int updateStatusBySpuId(@org.apache.ibatis.annotations.Param("spuId") Long spuId,
@org.apache.ibatis.annotations.Param("status") Integer status);
/**
* 根据SPU ID删除SKU表数据
*
* @param spuId 关联的 SPU ID
* @return 受影响行数
*/
default int deleteBySpuId(Long spuId) {
return delete(new LambdaQueryWrapperX<ResourceSkuDO>().eq(ResourceSkuDO::getSpuId, spuId));
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.luhu.computility.module.compute.service.resourcespu;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.luhu.computility.module.compute.dal.mysql.resourcesku.ResourceSkuMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
......@@ -35,6 +36,9 @@ public class ResourceSpuServiceImpl implements ResourceSpuService {
@Resource
private ResourceSpuMapper resourceSpuMapper;
@Resource
private ResourceSkuMapper resourceSkuMapper;
@Override
public Long createResourceSpu(ResourceSpuSaveReqVO createReqVO) {
// 插入
......@@ -46,18 +50,31 @@ public class ResourceSpuServiceImpl implements ResourceSpuService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateResourceSpu(ResourceSpuSaveReqVO updateReqVO) {
// 校验存在
validateResourceSpuExists(updateReqVO.getId());
// 更新
// 获取更新前的状态
ResourceSpuDO existingSpu = resourceSpuMapper.selectById(updateReqVO.getId());
Integer oldStatus = existingSpu.getStatus();
// 更新SPU
ResourceSpuDO updateObj = BeanUtils.toBean(updateReqVO, ResourceSpuDO.class);
resourceSpuMapper.updateById(updateObj);
// 如果状态发生变化,同步更新关联的SKU状态
Integer newStatus = updateObj.getStatus();
if (!Objects.equals(oldStatus, newStatus)) {
resourceSkuMapper.updateStatusBySpuId(updateReqVO.getId(), newStatus);
}
}
@Override
public void deleteResourceSpu(Long id) {
// 校验存在
validateResourceSpuExists(id);
resourceSkuMapper.deleteBySpuId(id);
// 删除
resourceSpuMapper.deleteById(id);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment