1、规格属性功能级联删除

2、属性分组删除判断是否可以删除
3、新增自定义商城业务异常类
pull/254/head
xjs 4 years ago
parent 627af3e26f
commit 366685379a

@ -0,0 +1,24 @@
package com.xjs.exception;
import lombok.extern.log4j.Log4j2;
/**
*
* @author xiejs
* @since 2022-03-17
*/
@Log4j2
public class MallException extends RuntimeException{
public MallException() {
super();
}
public MallException(String message) {
super(message);
log.error("商城业务异常----{}",message);
}
public MallException(String message, Throwable cause) {
super(message, cause);
}
}

@ -84,7 +84,7 @@ public class AttrController {
@ApiOperation("删除") @ApiOperation("删除")
@Log(title = "规格参数", businessType = BusinessType.DELETE) @Log(title = "规格参数", businessType = BusinessType.DELETE)
public R delete(@RequestBody Long[] attrIds) { public R delete(@RequestBody Long[] attrIds) {
attrService.removeByIds(Arrays.asList(attrIds)); attrService.removeAttr(Arrays.asList(attrIds));
return R.ok(); return R.ok();
} }

@ -97,7 +97,7 @@ public class AttrGroupController {
@ApiOperation("删除") @ApiOperation("删除")
@Log(title = "属性分组", businessType = BusinessType.DELETE) @Log(title = "属性分组", businessType = BusinessType.DELETE)
public R delete(@RequestBody Long[] attrGroupIds) { public R delete(@RequestBody Long[] attrGroupIds) {
attrGroupService.removeByIds(Arrays.asList(attrGroupIds)); attrGroupService.removeAttrGroup(Arrays.asList(attrGroupIds));
return R.ok(); return R.ok();
} }

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.xjs.mall.product.entity.AttrGroupEntity; import com.xjs.mall.product.entity.AttrGroupEntity;
import com.xjs.utils.PageUtils; import com.xjs.utils.PageUtils;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -17,12 +18,20 @@ public interface AttrGroupService extends IService<AttrGroupEntity> {
/** /**
* *
* @param params *
* @param params
* @param categoryId id * @param categoryId id
* @return pageUtils * @return pageUtils
*/ */
PageUtils queryPage(Map<String, Object> params, Long categoryId); PageUtils queryPage(Map<String, Object> params, Long categoryId);
/**
*
*
* @param ids id
*/
void removeAttrGroup(List<Long> ids);
/** /**
* id * id
* @param categoryId id * @param categoryId id

@ -6,6 +6,7 @@ import com.xjs.mall.product.vo.AttrVo;
import com.xjs.utils.PageUtils; import com.xjs.utils.PageUtils;
import com.xjs.mall.product.entity.AttrEntity; import com.xjs.mall.product.entity.AttrEntity;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -43,5 +44,11 @@ public interface AttrService extends IService<AttrEntity> {
* @param attr * @param attr
*/ */
void updateAttr(AttrVo attr); void updateAttr(AttrVo attr);
/**
*
* @param asList ids
*/
void removeAttr(List<Long> asList);
} }

@ -1,11 +1,15 @@
package com.xjs.mall.product.service.impl; package com.xjs.mall.product.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjs.exception.MallException;
import com.xjs.mall.product.dao.AttrGroupDao; import com.xjs.mall.product.dao.AttrGroupDao;
import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity;
import com.xjs.mall.product.entity.AttrGroupEntity; import com.xjs.mall.product.entity.AttrGroupEntity;
import com.xjs.mall.product.entity.CategoryEntity; import com.xjs.mall.product.entity.CategoryEntity;
import com.xjs.mall.product.service.AttrAttrgroupRelationService;
import com.xjs.mall.product.service.AttrGroupService; import com.xjs.mall.product.service.AttrGroupService;
import com.xjs.mall.product.service.CategoryService; import com.xjs.mall.product.service.CategoryService;
import com.xjs.mall.product.vo.AttrGroupResponseVo; import com.xjs.mall.product.vo.AttrGroupResponseVo;
@ -29,6 +33,9 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEnt
@Autowired @Autowired
private CategoryService categoryService; private CategoryService categoryService;
@Autowired
private AttrAttrgroupRelationService attrAttrgroupRelationService;
@Override @Override
public PageUtils queryPage(Map<String, Object> params, Long categoryId) { public PageUtils queryPage(Map<String, Object> params, Long categoryId) {
String key = (String) params.get(Query.KEY_NAME); String key = (String) params.get(Query.KEY_NAME);
@ -63,6 +70,22 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEnt
} }
@Override
public void removeAttrGroup(List<Long> ids) {
for (Long id : ids) {
//先查询中间表是否有数据,有数据代表该数据被引用,则不能删除
List<AttrAttrgroupRelationEntity> relationEntityList = attrAttrgroupRelationService
.list(new LambdaQueryWrapper<AttrAttrgroupRelationEntity>()
.eq(AttrAttrgroupRelationEntity::getAttrGroupId, id));
if (CollUtil.isEmpty(relationEntityList)) {
super.removeById(id);
}else {
throw new MallException("含有被引用的规格参数未删除,请先删除规格参数");
}
}
}
private List<AttrGroupResponseVo> setList(List<AttrGroupEntity> records) { private List<AttrGroupResponseVo> setList(List<AttrGroupEntity> records) {
return records.stream().map(attrGroupEntity -> { return records.stream().map(attrGroupEntity -> {

@ -169,4 +169,15 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
} }
@Override
public void removeAttr(List<Long> asList) {
//删除自身
super.removeByIds(asList);
//级联删除中间表数据
for (Long id : asList) {
attrAttrgroupRelationService.remove(new LambdaUpdateWrapper<AttrAttrgroupRelationEntity>()
.eq(AttrAttrgroupRelationEntity::getAttrId,id));
}
}
} }

Loading…
Cancel
Save