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("删除")
|
||||
@Log(title = "规格参数", businessType = BusinessType.DELETE)
|
||||
public R delete(@RequestBody Long[] attrIds) {
|
||||
attrService.removeByIds(Arrays.asList(attrIds));
|
||||
attrService.removeAttr(Arrays.asList(attrIds));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class AttrGroupController {
|
|||
@ApiOperation("删除")
|
||||
@Log(title = "属性分组", businessType = BusinessType.DELETE)
|
||||
public R delete(@RequestBody Long[] attrGroupIds) {
|
||||
attrGroupService.removeByIds(Arrays.asList(attrGroupIds));
|
||||
attrGroupService.removeAttrGroup(Arrays.asList(attrGroupIds));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
import com.xjs.mall.product.entity.AttrGroupEntity;
|
||||
import com.xjs.utils.PageUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -17,12 +18,20 @@ public interface AttrGroupService extends IService<AttrGroupEntity> {
|
|||
|
||||
/**
|
||||
* 分页
|
||||
* @param params 条件
|
||||
*
|
||||
* @param params 条件
|
||||
* @param categoryId 类别id
|
||||
* @return pageUtils
|
||||
*/
|
||||
PageUtils queryPage(Map<String, Object> params, Long categoryId);
|
||||
|
||||
/**
|
||||
* 删除属性分组,校验,被引用则不删除
|
||||
*
|
||||
* @param ids id
|
||||
*/
|
||||
void removeAttrGroup(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据分类id查出所有的分组以及这些组里面的属性
|
||||
* @param categoryId 分类id
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.xjs.mall.product.vo.AttrVo;
|
|||
import com.xjs.utils.PageUtils;
|
||||
import com.xjs.mall.product.entity.AttrEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -43,5 +44,11 @@ public interface AttrService extends IService<AttrEntity> {
|
|||
* @param attr 实体类
|
||||
*/
|
||||
void updateAttr(AttrVo attr);
|
||||
|
||||
/**
|
||||
* 删除规格参数及关联信息
|
||||
* @param asList ids
|
||||
*/
|
||||
void removeAttr(List<Long> asList);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
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.metadata.IPage;
|
||||
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.entity.AttrAttrgroupRelationEntity;
|
||||
import com.xjs.mall.product.entity.AttrGroupEntity;
|
||||
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.CategoryService;
|
||||
import com.xjs.mall.product.vo.AttrGroupResponseVo;
|
||||
|
|
@ -29,6 +33,9 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEnt
|
|||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private AttrAttrgroupRelationService attrAttrgroupRelationService;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params, Long categoryId) {
|
||||
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) {
|
||||
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…
Reference in New Issue