连带删除

zhc4dev
赵玉瑞 2 years ago
parent e7290a25d1
commit 4c86dee4b0
  1. 9
      jeecg-boot/jeecg-boot-module-process/src/main/java/org/jeecg/modules/demo/base/controller/ZyClothsTypeController.java
  2. 3
      jeecg-boot/jeecg-boot-module-process/src/main/java/org/jeecg/modules/demo/base/mapper/ZyClothsTypeMapper.java

@ -1,5 +1,6 @@
package org.jeecg.modules.demo.base.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -24,6 +25,7 @@ import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Description: zy_cloths_type
@ -147,6 +149,13 @@ public class ZyClothsTypeController extends JeecgController<ZyClothsType, IZyClo
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
zyClothsTypeService.removeById(id);
//如果这是父级 连带子集一起删除
String parentId = zyClothsTypeMapper.getParentId(id);
if (StringUtils.isEmpty(parentId)){
List<ZyClothsType> zyClothsTypeList = zyClothsTypeService.list(new LambdaQueryWrapper<ZyClothsType>().eq(ZyClothsType::getTypeId,id));
List<String> collect = zyClothsTypeList.stream().map(ZyClothsType::getId).collect(Collectors.toList());
zyClothsTypeService.removeByIds(collect);
}
return Result.OK("删除成功!");
}

@ -43,4 +43,7 @@ public interface ZyClothsTypeMapper extends BaseMapper<ZyClothsType> {
/**根据type_id拿到类型名称*/
@Select("select type_name from zy_cloths_type where id = #{id} ")
String getNameByTypeId(String id);
@Select("select type_id from zy_cloths_type where id = #{id} ")
String getParentId(String id);
}

Loading…
Cancel
Save